getter.gno
15.43 Kb · 456 lines
1package dca
2
3import (
4 pdca "gno.land/p/gnoswap/order/dca/v0"
5 rotree "gno.land/p/nt/bptree/rotree/v0"
6)
7
8// Getters return copies of stored values. Store trees are returned as
9// read-only views keyed as in the store layout (see store.gno); views whose
10// entries are pointers copy every entry they return. Callers page a view
11// themselves through Iterate, IterateByOffset, or their reverse forms.
12
13// ==================================
14// Config Getters
15// ==================================
16
17// GetConfig returns a copy of the configuration.
18//
19// Returns:
20// - *pdca.Config: copy of the stored configuration
21func GetConfig() *pdca.Config {
22 return getImplementation().GetConfig()
23}
24
25// GetExecutionFeeRate returns the execution fee rate new orders snapshot:
26// the share of an order's output sent to the protocol fee realm.
27// An existing order's rate is pdca.Order.ExecutionFeeRate (see GetOrder).
28//
29// Returns:
30// - int64: execution fee rate, in basis points
31func GetExecutionFeeRate() int64 {
32 return GetConfig().ExecutionFeeRate()
33}
34
35// GetMaxPoolPriceDeviationRate returns how far, in basis points of price, a
36// pool's price may sit on the favorable side of its swap price limit and still
37// be quoted (see SetMaxPoolPriceDeviationRate); 0 means the check is off.
38//
39// Returns:
40// - int64: rate in basis points
41func GetMaxPoolPriceDeviationRate() int64 {
42 return GetConfig().MaxPoolPriceDeviationRate()
43}
44
45// GetMaxPairPriceLimitAge returns how long, in seconds, a pair price limit
46// stays usable after it was set (see SetMaxPairPriceLimitAge).
47//
48// Returns:
49// - int64: maximum age in seconds
50func GetMaxPairPriceLimitAge() int64 {
51 return GetConfig().MaxPairPriceLimitAge()
52}
53
54// GetMaxExecutionCount returns the maximum executions of a new order.
55//
56// Returns:
57// - int64: maximum executionCount
58func GetMaxExecutionCount() int64 {
59 return GetConfig().MaxExecutionCount()
60}
61
62// GetAllowedIntervals returns the intervals new orders may use.
63//
64// Returns:
65// - []int64: allowed intervals in seconds, ascending
66func GetAllowedIntervals() []int64 {
67 return GetConfig().AllowedIntervals()
68}
69
70// IsAllowedInterval reports whether new orders may use interval.
71//
72// Parameters:
73// - interval: round interval, in seconds
74//
75// Returns:
76// - bool: true when interval is allowed
77func IsAllowedInterval(interval int64) bool {
78 return GetConfig().IsAllowedInterval(interval)
79}
80
81// GetSlotStep returns the spacing of the slot offsets new orders may use at interval.
82//
83// Parameters:
84// - interval: round interval, in seconds
85//
86// Returns:
87// - int64: slot step in seconds; 0 when interval is not allowed
88func GetSlotStep(interval int64) int64 {
89 return GetConfig().SlotStep(interval)
90}
91
92// GetMinExecutionGapRate returns the minimum gap between a group's executions.
93//
94// Returns:
95// - int64: minimum gap, in basis points of the group interval
96func GetMinExecutionGapRate() int64 {
97 return GetConfig().MinExecutionGapRate()
98}
99
100// GetMaxClaimBatchSize returns the most orders one ClaimGroupOrders call examines.
101//
102// Returns:
103// - int64: maximum claim batch size
104func GetMaxClaimBatchSize() int64 {
105 return GetConfig().MaxClaimBatchSize()
106}
107
108// ==================================
109// Order Getters
110// ==================================
111
112// GetNextOrderID returns the ID the next created order receives.
113//
114// Returns:
115// - uint64: next order ID
116func GetNextOrderID() uint64 {
117 return getImplementation().GetNextOrderID()
118}
119
120// ExistsOrder reports whether an order is active.
121// Finished orders are deleted.
122//
123// Parameters:
124// - orderID: order to look up
125//
126// Returns:
127// - bool: true while the order is active
128func ExistsOrder(orderID uint64) bool {
129 return getImplementation().ExistsOrder(orderID)
130}
131
132// GetOrder returns a copy of an active order.
133// Finished orders are deleted and return an error.
134//
135// Parameters:
136// - orderID: order to look up
137//
138// Returns:
139// - *pdca.Order: copy of the order
140// - error: non-nil when the order is not active
141func GetOrder(orderID uint64) (*pdca.Order, error) {
142 return getImplementation().GetOrder(orderID)
143}
144
145// GetOrders returns a read-only view of active orders.
146//
147// Returns:
148// - *rotree.ReadOnlyTree: pdca.OrderKey(orderID) -> *pdca.Order;
149// each order read from the view is a copy
150func GetOrders() *rotree.ReadOnlyTree {
151 return getImplementation().GetOrders()
152}
153
154// GetOrdersByOwner returns the read-only owner index of active orders.
155// Iterate the [pdca.OwnerOrderPrefix(owner), pdca.PrefixEnd(prefix)) range
156// for one owner's orders in ID order.
157//
158// Returns:
159// - *rotree.ReadOnlyTree: pdca.OwnerOrderKey(owner, orderID) -> uint64 orderID
160func GetOrdersByOwner() *rotree.ReadOnlyTree {
161 return getImplementation().GetOrdersByOwner()
162}
163
164// GetOrderIDsByOwner returns up to count active order IDs of owner,
165// ascending and greater than startAfterID (0 starts from the first).
166// Page by passing the last returned ID.
167//
168// Parameters:
169// - owner: order owner
170// - startAfterID: exclusive lower bound of the returned IDs
171// - count: maximum number of IDs returned
172//
173// Returns:
174// - []uint64: active order IDs, ascending
175func GetOrderIDsByOwner(owner address, startAfterID uint64, count int) []uint64 {
176 return getImplementation().GetOrderIDsByOwner(owner, startAfterID, count)
177}
178
179// GetClaimableAmount returns the output an order can claim now,
180// net of the order's execution fee.
181//
182// Parameters:
183// - orderID: order to look up
184//
185// Returns:
186// - int64: output the next Claim pays the owner; 0 when the order is not active
187func GetClaimableAmount(orderID uint64) int64 {
188 return getImplementation().GetClaimableAmount(orderID)
189}
190
191// GetOrderExecutionLogs returns copies of up to count of an active order's
192// unreleased execution logs, oldest first: each covers up to three rounds,
193// [FirstRound, LastRound], and the input the order sells in each. A log is
194// released once all of its rounds executed and the order is claimed;
195// the rounds' swap results are in the DCAGroupExecuted events.
196//
197// Parameters:
198// - orderID: order to look up
199// - count: maximum number of logs returned
200//
201// Returns:
202// - []*pdca.ExecutionLog: copies of the order's unreleased logs
203// - error: non-nil when the order is not active
204func GetOrderExecutionLogs(orderID uint64, count int) ([]*pdca.ExecutionLog, error) {
205 return getImplementation().GetOrderExecutionLogs(orderID, count)
206}
207
208// GetExecutionLogs returns the read-only index of unreleased execution logs.
209// Iterate the [pdca.ExecutionLogPrefix(orderID), pdca.PrefixEnd(prefix))
210// range for one order's logs; the key suffix decodes to the first round.
211//
212// Returns:
213// - *rotree.ReadOnlyTree: pdca.ExecutionLogKey(orderID, firstRound) -> uint64 lastRound
214func GetExecutionLogs() *rotree.ReadOnlyTree {
215 return getImplementation().GetExecutionLogs()
216}
217
218// ==================================
219// Group Getters
220// ==================================
221
222// ExistsGroup reports whether a group is stored.
223//
224// Parameters:
225// - groupID: pdca.MakeGroupID(inputToken, outputToken, interval, slotOffset)
226//
227// Returns:
228// - bool: true when the group exists
229func ExistsGroup(groupID string) bool {
230 return getImplementation().ExistsGroup(groupID)
231}
232
233// GetGroup returns a copy of a group without its round marks.
234// The copy's round mark tree is empty; read the marks through GetGroupRoundMarks.
235//
236// Parameters:
237// - groupID: group to look up
238//
239// Returns:
240// - *pdca.Group: copy of the group's fields
241// - error: non-nil when the group does not exist
242func GetGroup(groupID string) (*pdca.Group, error) {
243 return getImplementation().GetGroup(groupID)
244}
245
246// GetGroups returns a read-only view of every group.
247//
248// Returns:
249// - *rotree.ReadOnlyTree: groupID -> *pdca.Group; each group read from
250// the view is a copy without its round marks, as GetGroup returns
251func GetGroups() *rotree.ReadOnlyTree {
252 return getImplementation().GetGroups()
253}
254
255// GetGroupRoundMarks returns a read-only view of a group's round marks:
256// one per round at which an unfinalized order ends.
257//
258// Parameters:
259// - groupID: group to look up
260//
261// Returns:
262// - *rotree.ReadOnlyTree: pdca.RoundKey(round) -> *pdca.RoundMark; each
263// mark read from the view is a copy. nil when the group does not exist
264func GetGroupRoundMarks(groupID string) *rotree.ReadOnlyTree {
265 return getImplementation().GetGroupRoundMarks(groupID)
266}
267
268// GetOrdersByGroup returns the read-only group index of active orders.
269// Iterate the [pdca.GroupOrderPrefix(groupID), pdca.PrefixEnd(prefix))
270// range for one group's orders in ID order.
271//
272// Returns:
273// - *rotree.ReadOnlyTree: pdca.GroupOrderKey(groupID, orderID) -> uint64 orderID
274func GetOrdersByGroup() *rotree.ReadOnlyTree {
275 return getImplementation().GetOrdersByGroup()
276}
277
278// GetOrderAmountsByGroup returns the read-only group index of orders by
279// executionFeeRate, then amountPerExecution, which a round reads for the
280// smallest order of each fee rate.
281// Iterate the [pdca.GroupOrderPrefix(groupID), pdca.PrefixEnd(prefix))
282// range for one group's orders by ascending executionFeeRate,
283// amountPerExecution, then ID, or the
284// [pdca.GroupOrderFeeRatePrefix(groupID, rate), pdca.PrefixEnd(prefix))
285// range for the orders of one fee rate.
286// A finished order's entry stays until the order is paid out
287// or a later round of its group removes it.
288//
289// Returns:
290// - *rotree.ReadOnlyTree: pdca.GroupOrderAmountKey(groupID, executionFeeRate, amountPerExecution, orderID) -> uint64 endRound
291func GetOrderAmountsByGroup() *rotree.ReadOnlyTree {
292 return getImplementation().GetOrderAmountsByGroup()
293}
294
295// GetOrderIDsByGroup returns up to count active order IDs of a group,
296// ascending and greater than startAfterID. Page as GetOrderIDsByOwner.
297//
298// Parameters:
299// - groupID: group to look up
300// - startAfterID: exclusive lower bound of the returned IDs
301// - count: maximum number of IDs returned
302//
303// Returns:
304// - []uint64: active order IDs, ascending
305func GetOrderIDsByGroup(groupID string, startAfterID uint64, count int) []uint64 {
306 return getImplementation().GetOrderIDsByGroup(groupID, startAfterID, count)
307}
308
309// GetScheduledGroups returns the read-only schedule of groups with input to
310// sell, ordered by next execution timestamp, then group ID.
311// pdca.ScheduleKeyTimestamp decodes a key's timestamp.
312//
313// Returns:
314// - *rotree.ReadOnlyTree: pdca.ScheduleKey(nextExecutionTimestamp, groupID) -> string groupID
315func GetScheduledGroups() *rotree.ReadOnlyTree {
316 return getImplementation().GetScheduledGroups()
317}
318
319// GetExecutableGroups returns copies of up to count groups due now,
320// oldest first.
321//
322// Paging: start with cursor "",
323// then pass pdca.FormatScheduleCursor of the last group back
324// until fewer than count groups return.
325// The cursor is a fixed schedule position,
326// so groups executed between pages do not shift it.
327//
328// Parameters:
329// - cursor: "" or "<nextExecutionTimestamp>|<groupID>" of the last group seen
330// - count: maximum number of groups returned
331//
332// Returns:
333// - []*pdca.Group: copies of due groups without their round marks;
334// empty while execution is halted
335// - error: non-nil when cursor is malformed
336func GetExecutableGroups(cursor string, count int) ([]*pdca.Group, error) {
337 return getImplementation().GetExecutableGroups(cursor, count)
338}
339
340// GetExecutionQuote returns, as JSON, how the group's next round would trade
341// now: its input, the selected pool, the expected pool output, an estimate
342// of the orders' execution fees on that output and of what is left for the
343// orders, and every candidate pool's quote or ineligibility reason.
344// Orders pay their own snapshotted fee rates when paid out, each rounding
345// its own cumulative fee. The fee and order output totals instead charge
346// executionFeeRate, the highest rate of the orders the round sells (0 when
347// none does), once on the whole output, so they are estimates, not bounds:
348// the fees the orders pay can exceed expectedExecutionFeeAmount by rounding.
349// minAmountsByExecutionFeeRate lists, by ascending fee rate, the smallest
350// order of each rate the round sells. The round reverts unless every listed
351// order is credited at least max(1, minOrderAmountOut) net of its rate;
352// expectedMinOrderAmountOut is the least such output at expectedAmountOut,
353// and minAmountPerExecution the smallest order overall.
354// Keepers set amountOutMin from expectedAmountOut
355// and pass amountIn as expectedAmountIn.
356//
357// Parameters:
358// - groupID: group to quote
359//
360// Returns:
361// - string: JSON quote; "" when the group does not exist
362func GetExecutionQuote(groupID string) string {
363 return getImplementation().GetExecutionQuote(groupID)
364}
365
366// ==================================
367// Manager Setting Getters
368// ==================================
369
370// GetTokenMinAmountPerExecution returns the minimum input per execution the
371// manager set for tokenPath (see SetTokenMinAmountPerExecution).
372//
373// Parameters:
374// - tokenPath: input token path
375//
376// Returns:
377// - int64: minimum in raw token units; 0 when none is set
378func GetTokenMinAmountPerExecution(tokenPath string) int64 {
379 return getImplementation().GetTokenMinAmountPerExecution(tokenPath)
380}
381
382// GetMinAmountPerExecution returns the minimum input per execution a new
383// order selling tokenPath needs: the larger of GetConfig().MinAmountPerExecution()
384// and GetTokenMinAmountPerExecution(tokenPath).
385//
386// Parameters:
387// - tokenPath: input token path
388//
389// Returns:
390// - int64: effective minimum, in raw token units
391func GetMinAmountPerExecution(tokenPath string) int64 {
392 return getImplementation().GetMinAmountPerExecution(tokenPath)
393}
394
395// GetTokenMinAmountsPerExecution returns the read-only index of per-token
396// minimums, in key order.
397//
398// Returns:
399// - *rotree.ReadOnlyTree: tokenPath -> int64
400func GetTokenMinAmountsPerExecution() *rotree.ReadOnlyTree {
401 return getImplementation().GetTokenMinAmountsPerExecution()
402}
403
404// GetPairPriceLimit returns the price limit of selling inputToken for
405// outputToken (see SetPairPriceLimit).
406//
407// Parameters:
408// - inputToken, outputToken: the pair direction
409//
410// Returns:
411// - string: minOutputPerInputX128, decimal Q128; "0" when none is set
412// - int64: unix time the limit was set; 0 when none is set
413func GetPairPriceLimit(inputToken string, outputToken string) (string, int64) {
414 limit, found := getImplementation().GetPairPriceLimit(inputToken, outputToken)
415 if !found {
416 return "0", 0
417 }
418
419 return limit.MinOutputPerInputX128().ToString(), limit.UpdatedAt()
420}
421
422// GetPairPriceLimits returns a read-only view of the pair price limits,
423// in key order. Entries are copies.
424//
425// Returns:
426// - *rotree.ReadOnlyTree: "inputToken:outputToken" -> *pdca.PairPriceLimit
427func GetPairPriceLimits() *rotree.ReadOnlyTree {
428 return getImplementation().GetPairPriceLimits()
429}
430
431// ==================================
432// Execution Fee Getters
433// ==================================
434
435// GetPendingExecutionFeeAmount returns the execution fee of tokenPath held
436// by this realm: fees payouts charged, and fees the protocol fee realm could
437// not accept yet. It is forwarded by the next round whose output token is
438// tokenPath, or by CollectPendingExecutionFee.
439//
440// Parameters:
441// - tokenPath: fee token path
442//
443// Returns:
444// - int64: pending execution fee, in raw token units
445func GetPendingExecutionFeeAmount(tokenPath string) int64 {
446 return getImplementation().GetPendingExecutionFeeAmount(tokenPath)
447}
448
449// GetPendingExecutionFees returns the read-only index of pending execution fees.
450// A token whose pending fee was forwarded keeps its entry at 0.
451//
452// Returns:
453// - *rotree.ReadOnlyTree: tokenPath -> int64 pending amount
454func GetPendingExecutionFees() *rotree.ReadOnlyTree {
455 return getImplementation().GetPendingExecutionFees()
456}