types.gno
4.31 Kb · 112 lines
1package limit
2
3import (
4 rotree "gno.land/p/nt/bptree/rotree/v0"
5 bptree "gno.land/p/nt/bptree/v0"
6)
7
8// These interfaces are the contract between the proxy realm
9// gno.land/r/gnoswap/order/limit and its implementations.
10// Keeping them in an immutable package lets every implementation version
11// compile against the same definitions.
12
13// ILimitOrder is the implementation interface behind the limit proxy.
14type ILimitOrder interface {
15 ILimitOrderManager
16 ILimitOrderExecutor
17 ILimitOrderAdmin
18 ILimitOrderGetter
19}
20
21// ILimitOrderManager covers owner-facing order operations.
22type ILimitOrderManager interface {
23 // CreateOrder escrows makingAmount of tokenIn for takingAmount of tokenOut.
24 // slippageBps=0 enforces the making/taking ratio or better.
25 // expiresAt must be positive and within the configured duration bounds.
26 // The execution fee rate is snapshotted from configuration.
27 // baseToken must be tokenIn or tokenOut and is emitted as history metadata.
28 CreateOrder(
29 _ int,
30 rlm realm,
31 tokenIn string,
32 tokenOut string,
33 makingAmount int64,
34 takingAmount int64,
35 slippageBps int64,
36 expiresAt int64,
37 baseToken string,
38 ) uint64
39
40 // CancelOrder refunds the remaining input to the owner. Owner only.
41 // After the deadline, the refund is emitted as an expired refund.
42 CancelOrder(_ int, rlm realm, orderID uint64) (refundIn int64)
43}
44
45// ILimitOrderExecutor covers keeper-authorized execution and public cleanup.
46type ILimitOrderExecutor interface {
47 // ExecuteOrder swaps at most maxAmountIn through the order's token pair
48 // at poolFee. A nonzero sqrtPriceLimitX96 permits partial consumption; each fill
49 // must still satisfy the order's owner-net minimum on its actual input.
50 // Returns actual input and pool output before the order fee.
51 ExecuteOrder(_ int, rlm realm, orderID uint64, maxAmountIn int64, poolFee uint32, sqrtPriceLimitX96 string) (actualInput int64, poolOutput int64)
52
53 // CleanupExpiredOrders examines at most min(maxOrders, MaxCleanupBatchSize)
54 // orders after startAfterOrderID in ID order and refunds expired ones.
55 // It returns the number expired and the last examined ID while more
56 // remain, or 0 when the scan is exhausted.
57 CleanupExpiredOrders(_ int, rlm realm, startAfterOrderID uint64, maxOrders int) (expired int, nextCursor uint64)
58}
59
60// ILimitOrderAdmin covers admin/governance configuration.
61// Changes apply to later operations, except where a method states otherwise.
62type ILimitOrderAdmin interface {
63 // SetExecutionFeeRate sets the execution fee rate snapshotted into new orders,
64 // in basis points of gross output.
65 SetExecutionFeeRate(_ int, rlm realm, executionFeeRate int64)
66 // SetMaxSlippageBps sets the slippage cap for new orders, in [0, 10000] bps.
67 SetMaxSlippageBps(_ int, rlm realm, maxSlippageBps int64)
68 // SetMinMakingAmount sets the minimum input amount accepted for new orders.
69 SetMinMakingAmount(_ int, rlm realm, minMakingAmount int64)
70 // SetOrderDeadlines sets the allowed order duration range, in seconds.
71 SetOrderDeadlines(_ int, rlm realm, minDuration int64, maxDuration int64)
72 // SetMaxCleanupBatchSize caps the orders one CleanupExpiredOrders call examines.
73 SetMaxCleanupBatchSize(_ int, rlm realm, maxCleanupBatchSize int64)
74}
75
76// ILimitOrderGetter exposes detached pending orders and read-only indexes.
77type ILimitOrderGetter interface {
78 GetConfig() *Config
79 GetNextOrderID() uint64
80
81 ExistsOrder(orderID uint64) bool
82 // GetOrder returns a detached copy while pending, or nil after settlement.
83 GetOrder(orderID uint64) *Order
84 GetOrders() *rotree.ReadOnlyTree
85 GetOrdersByOwner() *rotree.ReadOnlyTree
86
87 GetPendingExecutionFeeAmount(tokenPath string) int64
88 GetPendingExecutionFees() *rotree.ReadOnlyTree
89}
90
91// ILimitOrderStore is the persistent storage shared by all versions.
92type ILimitOrderStore interface {
93 HasOrders() bool
94 GetOrders() *bptree.BPTree
95 SetOrders(_ int, rlm realm, orders *bptree.BPTree) error
96
97 HasOrdersByOwner() bool
98 GetOrdersByOwner() *bptree.BPTree
99 SetOrdersByOwner(_ int, rlm realm, ordersByOwner *bptree.BPTree) error
100
101 HasPendingExecutionFees() bool
102 GetPendingExecutionFees() *bptree.BPTree
103 SetPendingExecutionFees(_ int, rlm realm, pendingExecutionFees *bptree.BPTree) error
104
105 HasNextOrderID() bool
106 GetNextOrderID() uint64
107 SetNextOrderID(_ int, rlm realm, id uint64) error
108
109 HasConfig() bool
110 GetConfig() *Config
111 SetConfig(_ int, rlm realm, config *Config) error
112}