Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

proxy.gno

5.24 Kb · 120 lines
  1package limit
  2
  3type expiredOrderCleanup interface {
  4	CleanupExpiredOrdersByIDs(_ int, rlm realm, orderIDs string) (expired int, retryOrderIDs string)
  5}
  6
  7type pendingExecutionFeeCollector interface {
  8	CollectPendingExecutionFee(_ int, rlm realm, tokenPath string) (int64, int64)
  9}
 10
 11// CreateOrder escrows makingAmount of tokenIn for takingAmount of tokenOut.
 12// Each fill supplies its pool fee tier and price limit.
 13// slippageBps=0 enforces the making/taking ratio or better.
 14// expiresAt must be positive and within the configured duration bounds.
 15// The execution fee rate is snapshotted into each new order.
 16// baseToken must be tokenIn (Sell) or tokenOut (Buy); it is emitted only as
 17// creation metadata and does not affect the order's execution terms.
 18// The caller must first approve Address() for makingAmount.
 19// Reverts while execution is halted for Limit orders.
 20func CreateOrder(
 21	cur realm,
 22	tokenIn string,
 23	tokenOut string,
 24	makingAmount int64,
 25	takingAmount int64,
 26	slippageBps int64,
 27	expiresAt int64,
 28	baseToken string,
 29) uint64 {
 30	return getImplementation().CreateOrder(0, cur, tokenIn, tokenOut, makingAmount, takingAmount, slippageBps, expiresAt, baseToken)
 31}
 32
 33// CancelOrder refunds the remaining input and removes the order from the indexes.
 34// A past-deadline refund uses the expired event.
 35// It returns the refunded input.
 36//
 37// Owner only. Reverts while withdrawals are halted for limit orders.
 38func CancelOrder(cur realm, orderID uint64) int64 {
 39	return getImplementation().CancelOrder(0, cur, orderID)
 40}
 41
 42// ExecuteOrder fills up to maxAmountIn through the order's token pair at poolFee.
 43// A nonzero sqrtPriceLimitX96 stops at that pool price and may leave input
 44// unspent in escrow. Zero requires maxAmountIn to be consumed in full.
 45// The order's minimum owner-net output is enforced on the actual input.
 46// Returns actual input and pool output before the order's execution fee;
 47// the owner is paid immediately after that fee is deducted.
 48// The immediate caller must be authorized for ExecuteOrder by the shared
 49// keeper policy. Reverts while execution or withdrawals are halted for limit orders.
 50func ExecuteOrder(cur realm, orderID uint64, maxAmountIn int64, poolFee uint32, sqrtPriceLimitX96 string) (int64, int64) {
 51	return getImplementation().ExecuteOrder(0, cur, orderID, maxAmountIn, poolFee, sqrtPriceLimitX96)
 52}
 53
 54// CollectPendingExecutionFee forwards fees pending for tokenPath to the protocol
 55// fee realm without another fill. Anyone may call it; the caller receives nothing.
 56// Returns the amount forwarded and the amount left pending.
 57// Reverts while withdrawals are halted for Limit orders.
 58func CollectPendingExecutionFee(cur realm, tokenPath string) (int64, int64) {
 59	collector, ok := getImplementation().(pendingExecutionFeeCollector)
 60	if !ok {
 61		panic(errImplDoesNotSupportFeeCollection)
 62	}
 63
 64	return collector.CollectPendingExecutionFee(0, cur, tokenPath)
 65}
 66
 67// CleanupExpiredOrders refunds pending orders after their deadline.
 68// Anyone may call it.
 69//
 70// One call examines at most min(maxOrders, maxCleanupBatchSize) orders after
 71// startAfterOrderID, in ID order. It returns the number of orders expired and
 72// the cursor for the next call; repeat until the cursor is 0.
 73// Reverts while withdrawals are halted for limit orders.
 74func CleanupExpiredOrders(cur realm, startAfterOrderID uint64, maxOrders int) (int, uint64) {
 75	return getImplementation().CleanupExpiredOrders(0, cur, startAfterOrderID, maxOrders)
 76}
 77
 78// CleanupExpiredOrdersByIDs refunds only the named expired orders.
 79// orderIDs is a strictly increasing comma-separated list of positive decimal
 80// order IDs. Existing unexpired or underfunded orders are returned for retry.
 81// Reverts while withdrawals are halted for limit orders.
 82func CleanupExpiredOrdersByIDs(cur realm, orderIDs string) (int, string) {
 83	cleanup, ok := getImplementation().(expiredOrderCleanup)
 84	if !ok {
 85		panic(errImplDoesNotSupportTargetedCleanup)
 86	}
 87
 88	return cleanup.CleanupExpiredOrdersByIDs(0, cur, orderIDs)
 89}
 90
 91// SetExecutionFeeRate sets the execution fee rate snapshotted into new orders,
 92// in basis points of gross output.
 93// Admin or governance only.
 94func SetExecutionFeeRate(cur realm, executionFeeRate int64) {
 95	getImplementation().SetExecutionFeeRate(0, cur, executionFeeRate)
 96}
 97
 98// SetMinMakingAmount sets the minimum input amount for new orders, in raw token units.
 99// Existing orders are unaffected. Admin or governance only.
100func SetMinMakingAmount(cur realm, minMakingAmount int64) {
101	getImplementation().SetMinMakingAmount(0, cur, minMakingAmount)
102}
103
104// SetOrderDeadlines sets the allowed order duration range for new orders,
105// in seconds. Admin or governance only.
106func SetOrderDeadlines(cur realm, minDuration int64, maxDuration int64) {
107	getImplementation().SetOrderDeadlines(0, cur, minDuration, maxDuration)
108}
109
110// SetMaxCleanupBatchSize caps the orders one CleanupExpiredOrders call examines,
111// bounding its gas. Admin or governance only.
112func SetMaxCleanupBatchSize(cur realm, maxCleanupBatchSize int64) {
113	getImplementation().SetMaxCleanupBatchSize(0, cur, maxCleanupBatchSize)
114}
115
116// SetMaxSlippageBps sets the slippage cap for new orders in [0, 10000] bps.
117// Existing orders keep their slippage. Admin or governance only.
118func SetMaxSlippageBps(cur realm, maxSlippageBps int64) {
119	getImplementation().SetMaxSlippageBps(0, cur, maxSlippageBps)
120}