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

dca source realm

Package dca is the GnoSwap DCA (dollar-cost averaging) order realm.

Overview

Package dca is the GnoSwap DCA (dollar-cost averaging) order realm.

Users escrow inputToken and sell amountPerExecution of it for outputToken every interval, executionCount times, at a chosen slot of the interval (e.g. 09:00 UTC daily). Orders of the same pair, interval, and slot form a group that keepers execute in one pool swap per round, on the pair's best whitelisted pool, without the router. Each round's swap output accrues to the orders and is paid by Claim, or by keepers through ClaimGroupOrders; each payout deducts the execution fee at the rate the order snapshotted when it was created.

This package is the permanent entry point. It owns the escrow address, the KV store shared by every version, and the upgrade switch; the business logic lives in a registered implementation (impl/v0).

Files:

  • proxy.gno: state-changing entry points
  • getter.gno: read-only queries
  • store.gno: KV store and store keys
  • state.gno: realm state and the active implementation
  • upgrade.gno: implementation registration and upgrades

Constants 5

const ErrInvalidSwapCallback

1const ErrInvalidSwapCallback = "invalid swap callback"
source

ErrInvalidSwapCallback is returned by a round's swap callback for a call it must not pay: not from the pool, outside a round, a second payment, or a delta that is not the round's exact input (e.g. a pool without liquidity owes nothing).

const ErrNilInitializer

1const ErrNilInitializer = "nil initializer"
source

ErrNilInitializer is raised by RegisterInitializer for a nil factory.

const ErrSpoofedRealm

1const ErrSpoofedRealm = "spoofed realm"
source

ErrSpoofedRealm is returned when a store write gets a non-current realm.

const ErrUpgradeWhileExecuting

1const ErrUpgradeWhileExecuting = "cannot upgrade while a group execution is in progress"
source

ErrUpgradeWhileExecuting is raised by UpgradeImpl during a group swap.

const StoreKeyOrders, StoreKeyOrdersByOwner, StoreKeyGroups, StoreKeyScheduledGroups, StoreKeyNextOrderID, StoreKeyConfig, StoreKeyExecuting, StoreKeyOrdersByGroup, StoreKeyPendingExecutionFees, StoreKeyExecutionLogs, StoreKeyOrderAmountsByGroup, StoreKeyTokenMinAmountsPerExecution, StoreKeyPairPriceLimits

 1const (
 2	StoreKeyOrders               StoreKey = "orders"
 3	StoreKeyOrdersByOwner        StoreKey = "ordersByOwner"
 4	StoreKeyGroups               StoreKey = "groups"
 5	StoreKeyScheduledGroups      StoreKey = "scheduledGroups"
 6	StoreKeyNextOrderID          StoreKey = "nextOrderID"
 7	StoreKeyConfig               StoreKey = "config"
 8	StoreKeyExecuting            StoreKey = "executing"
 9	StoreKeyOrdersByGroup        StoreKey = "ordersByGroup"
10	StoreKeyPendingExecutionFees StoreKey = "pendingExecutionFees"
11	StoreKeyExecutionLogs        StoreKey = "executionLogs"
12	StoreKeyOrderAmountsByGroup  StoreKey = "orderAmountsByGroup"
13
14	StoreKeyTokenMinAmountsPerExecution StoreKey = "tokenMinAmountsPerExecution"
15	StoreKeyPairPriceLimits             StoreKey = "pairPriceLimits"
16)
source

Store layout. Tree keys are built by the pdca key helpers.

Example
 1orders               OrderKey -> *Order
 2ordersByOwner        OwnerOrderKey -> orderID
 3groups               groupID -> *Group
 4scheduledGroups      ScheduleKey -> groupID, groups with orderAmount > 0 only
 5nextOrderID          uint64
 6config               *Config
 7executing            true while ExecuteGroup is inside its pool swap
 8ordersByGroup        GroupOrderKey -> orderID, active orders only
 9pendingExecutionFees  tokenPath -> int64, fees not yet sent to protocol_fee
10executionLogs        ExecutionLogKey -> lastRound uint64, unreleased logs of active orders
11orderAmountsByGroup  GroupOrderAmountKey -> endRound, orders by executionFeeRate, then amountPerExecution
12tokenMinAmountsPerExecution  tokenPath -> int64, per-token minimum input per execution
13pairPriceLimits      PairKey -> *PairPriceLimit, minimum pool output per input of a pair direction

Functions 60

func AddAllowedInterval

crossing Action
1func AddAllowedInterval(cur realm, interval int64)
source

AddAllowedInterval allows new orders to use interval, in seconds (one minute to one year). The interval starts with a single slot, offset 0 (see SetSlotStep). Admin or governance only.

func CancelOrder

crossing Action
1func CancelOrder(cur realm, orderID uint64) (int64, int64)
source

CancelOrder pays accrued output, refunds unsold input, and closes the order. It returns the refunded input and the output paid by this call.

Owner only. Reverts while the withdraw operation is halted.

func Claim

crossing Action
1func Claim(cur realm, orderID uint64) int64
source

Claim pays accrued output to the order owner and returns the amount. Anyone may call it, e.g. a keeper delivering output; proceeds always go to the owner. The order's execution logs whose rounds all executed are released, and their storage deposit is refunded to the caller.

Reverts while the withdraw operation is halted.

func ClaimGroupOrders

crossing Action
1func ClaimGroupOrders(cur realm, groupID string, startAfterOrderID uint64, maxOrderCount int) (int, uint64)
source

ClaimGroupOrders pays accrued output to the owners of a group's active orders, as Claim does, so owners receive output without claiming. Anyone may call it; output always goes to the order owner.

One call examines at most min(maxOrderCount, maxClaimBatchSize) orders after startAfterOrderID, in ID order. It returns the number of orders paid or completed and the cursor for the next call; repeat until the cursor is 0.

Each order's execution logs whose rounds all executed are released and finished orders are deleted; the freed storage deposit is refunded to the caller, so the reward grows with the orders and rounds claimed.

Reverts while the withdraw operation is halted.

func CollectPendingExecutionFee

crossing Action
1func CollectPendingExecutionFee(cur realm, tokenPath string) (int64, int64)
source

CollectPendingExecutionFee forwards the execution fee pending for tokenPath (see GetPendingExecutionFeeAmount) to the protocol fee realm and returns the amount forwarded and the amount left pending. Payouts keep each order's execution fee as pending, and every round forwards the pending fee of its output token; this forwards it when no round of that output token runs. If the protocol fee realm rejects it, for example while its collection is halted, the fee stays pending. Anyone may call it: the fee only moves to the protocol fee realm.

Reverts while the withdraw operation is halted.

func CreateOrder

crossing Action
1func CreateOrder(
2	cur realm,
3	inputToken string,
4	outputToken string,
5	interval int64,
6	slotOffset int64,
7	amountPerExecution int64,
8	executionCount int64,
9) uint64
source

CreateOrder creates an order that sells amountPerExecution of inputToken for outputToken every interval seconds, executionCount times, and returns its ID.

The caller must first approve Address() for amountPerExecution*executionCount. amountPerExecution must be at least GetMinAmountPerExecution(inputToken), and the pair direction needs a price limit (see SetPairPriceLimit). The order snapshots the execution fee rate in effect (see GetExecutionFeeRate) for its lifetime: the fee is that share of the order's output, deducted when the output is paid out. Later rate changes apply only to orders created afterwards. Orders with the same inputToken, outputToken, interval, and slotOffset share one group and execute together. Each round trades on the pair's best whitelisted pool, chosen at execution time (see GetExecutionQuote).

The caller also pays the storage deposit of the order's execution logs, one per three rounds; each is refunded to whoever releases it after all of its rounds execute (see ClaimGroupOrders).

Parameters:

  • inputToken, outputToken: at least one whitelisted direct pool must connect them (see gno.land/r/gnoswap/order/whitelist.AddWhitelistedPool).
  • interval: one of GetConfig().AllowedIntervals().
  • slotOffset: seconds after each interval boundary of the unix epoch at which rounds run, a multiple of GetConfig().SlotStep(interval) in [0, interval). Boundaries are UTC midnights for daily intervals; weekly boundaries fall on Thursdays 00:00 UTC (1970-01-01 was one), so a Monday slot is 4 days. The first round waits for the next slot, or runs now if it is due.

Reverts while the execute operation is halted for DCA in gno.land/r/gnoswap/order/halt.

func ExecuteGroup

crossing Action
1func ExecuteGroup(cur realm, groupID string, expectedAmountIn int64, amountOutMin int64, minOrderAmountOut int64) (int64, int64)
source

ExecuteGroup runs the next round of a group once it is due. Only accounts holding the DCA keeper role in gno.land/r/gnoswap/order/keeper may call it: the ExecuteGroup selector is assigned to DCAKeeperRole at deployment, and admin or governance grants the role or reassigns it. It returns the round input and the output credited to the orders, before their execution fees, which each order pays when paid out.

Parameters:

  • groupID: see GetExecutableGroups.
  • amountOutMin: minimum pool output, before the execution fee; 0 disables it.
  • expectedAmountIn: the group orderAmount amountOutMin was quoted for. The round reverts if the orderAmount differs; 0 is accepted only with amountOutMin 0.
  • minOrderAmountOut: the least output every order of the round must be credited after its own execution fee rate (see GetExecutionQuote), in the output token's smallest unit; 0 means 1. The round reverts when its smallest order would receive less.

Pool selection: among the pair's whitelisted pools (one per fee tier), the pool with the best quote for the full round is used. The round swaps on that pool directly through gno.land/r/gnoswap/pool, without the router, so no router fee is charged. The swap's price limit comes from the pair price limit (see SetPairPriceLimit), so no unit of input is sold below it, whatever amountOutMin is. The round reverts when no whitelisted pool can fill it within the limit.

Reverts while the execute or withdraw operation is halted.

func ExistsGroup

Action
1func ExistsGroup(groupID string) bool
source

ExistsGroup reports whether a group is stored.

Parameters:

  • groupID: pdca.MakeGroupID(inputToken, outputToken, interval, slotOffset)

Returns:

  • bool: true when the group exists

func ExistsOrder

Action
1func ExistsOrder(orderID uint64) bool
source

ExistsOrder reports whether an order is active. Finished orders are deleted.

Parameters:

  • orderID: order to look up

Returns:

  • bool: true while the order is active

func ForceCancelOrder

crossing Action
1func ForceCancelOrder(cur realm, orderID uint64) (int64, int64)
source

ForceCancelOrder closes an order that blocks its group's rounds. As with CancelOrder, accrued output and unsold input go to the order owner; the caller receives nothing but the freed storage deposit of the order's execution logs. It returns the refunded input and the output paid.

The order must have rounds left and be, as checked on-chain:

  • below the minimum per execution a new order of its token needs now (reason below_min_amount), or
  • in a due round that, as quoted now, credits it less than one output unit after its execution fee (no_order_output), or
  • the largest order (by amountPerExecution, ties included) of a due round that no pool can fill as quoted now while a pool fills part of it, with some output, within the price limit (exceeds_pool_capacity). A round that needs several orders gone is shrunk one largest order per call.

Any other order reverts with "order does not block its group". DCAOrderForceCancelled reports the reason.

Only accounts holding the role assigned to the ForceCancelOrder selector in gno.land/r/gnoswap/order/keeper (DCAKeeperRole at deployment). Reverts while the withdraw operation is halted.

func GetAllowedIntervals

Action
1func GetAllowedIntervals() []int64
source

GetAllowedIntervals returns the intervals new orders may use.

Returns:

  • []int64: allowed intervals in seconds, ascending

func GetClaimableAmount

Action
1func GetClaimableAmount(orderID uint64) int64
source

GetClaimableAmount returns the output an order can claim now, net of the order's execution fee.

Parameters:

  • orderID: order to look up

Returns:

  • int64: output the next Claim pays the owner; 0 when the order is not active

func GetConfig

Action
1func GetConfig() *pdca.Config
source

GetConfig returns a copy of the configuration.

Returns:

  • *pdca.Config: copy of the stored configuration

func GetExecutableGroups

Action
1func GetExecutableGroups(cursor string, count int) ([]*pdca.Group, error)
source

GetExecutableGroups returns copies of up to count groups due now, oldest first.

Paging: start with cursor "", then pass pdca.FormatScheduleCursor of the last group back until fewer than count groups return. The cursor is a fixed schedule position, so groups executed between pages do not shift it.

Parameters:

  • cursor: "" or "<nextExecutionTimestamp>|<groupID>" of the last group seen
  • count: maximum number of groups returned

Returns:

  • []*pdca.Group: copies of due groups without their round marks; empty while execution is halted
  • error: non-nil when cursor is malformed

func GetExecutionFeeRate

Action
1func GetExecutionFeeRate() int64
source

GetExecutionFeeRate returns the execution fee rate new orders snapshot: the share of an order's output sent to the protocol fee realm. An existing order's rate is pdca.Order.ExecutionFeeRate (see GetOrder).

Returns:

  • int64: execution fee rate, in basis points

func GetExecutionLogs

Action
1func GetExecutionLogs() *rotree.ReadOnlyTree
source

GetExecutionLogs returns the read-only index of unreleased execution logs. Iterate the [pdca.ExecutionLogPrefix(orderID), pdca.PrefixEnd(prefix)) range for one order's logs; the key suffix decodes to the first round.

Returns:

  • *rotree.ReadOnlyTree: pdca.ExecutionLogKey(orderID, firstRound) -> uint64 lastRound

func GetExecutionQuote

Action
1func GetExecutionQuote(groupID string) string
source

GetExecutionQuote returns, as JSON, how the group's next round would trade now: its input, the selected pool, the expected pool output, an estimate of the orders' execution fees on that output and of what is left for the orders, and every candidate pool's quote or ineligibility reason. Orders pay their own snapshotted fee rates when paid out, each rounding its own cumulative fee. The fee and order output totals instead charge executionFeeRate, the highest rate of the orders the round sells (0 when none does), once on the whole output, so they are estimates, not bounds: the fees the orders pay can exceed expectedExecutionFeeAmount by rounding. minAmountsByExecutionFeeRate lists, by ascending fee rate, the smallest order of each rate the round sells. The round reverts unless every listed order is credited at least max(1, minOrderAmountOut) net of its rate; expectedMinOrderAmountOut is the least such output at expectedAmountOut, and minAmountPerExecution the smallest order overall. Keepers set amountOutMin from expectedAmountOut and pass amountIn as expectedAmountIn.

Parameters:

  • groupID: group to quote

Returns:

  • string: JSON quote; "" when the group does not exist

func GetGroup

Action
1func GetGroup(groupID string) (*pdca.Group, error)
source

GetGroup returns a copy of a group without its round marks. The copy's round mark tree is empty; read the marks through GetGroupRoundMarks.

Parameters:

  • groupID: group to look up

Returns:

  • *pdca.Group: copy of the group's fields
  • error: non-nil when the group does not exist

func GetGroupRoundMarks

Action
1func GetGroupRoundMarks(groupID string) *rotree.ReadOnlyTree
source

GetGroupRoundMarks returns a read-only view of a group's round marks: one per round at which an unfinalized order ends.

Parameters:

  • groupID: group to look up

Returns:

  • *rotree.ReadOnlyTree: pdca.RoundKey(round) -> *pdca.RoundMark; each mark read from the view is a copy. nil when the group does not exist

func GetGroups

Action
1func GetGroups() *rotree.ReadOnlyTree
source

GetGroups returns a read-only view of every group.

Returns:

  • *rotree.ReadOnlyTree: groupID -> *pdca.Group; each group read from the view is a copy without its round marks, as GetGroup returns

func GetMaxClaimBatchSize

Action
1func GetMaxClaimBatchSize() int64
source

GetMaxClaimBatchSize returns the most orders one ClaimGroupOrders call examines.

Returns:

  • int64: maximum claim batch size

func GetMaxExecutionCount

Action
1func GetMaxExecutionCount() int64
source

GetMaxExecutionCount returns the maximum executions of a new order.

Returns:

  • int64: maximum executionCount

func GetMaxPairPriceLimitAge

Action
1func GetMaxPairPriceLimitAge() int64
source

GetMaxPairPriceLimitAge returns how long, in seconds, a pair price limit stays usable after it was set (see SetMaxPairPriceLimitAge).

Returns:

  • int64: maximum age in seconds

func GetMaxPoolPriceDeviationRate

Action
1func GetMaxPoolPriceDeviationRate() int64
source

GetMaxPoolPriceDeviationRate returns how far, in basis points of price, a pool's price may sit on the favorable side of its swap price limit and still be quoted (see SetMaxPoolPriceDeviationRate); 0 means the check is off.

Returns:

  • int64: rate in basis points

func GetMinAmountPerExecution

Action
1func GetMinAmountPerExecution(tokenPath string) int64
source

GetMinAmountPerExecution returns the minimum input per execution a new order selling tokenPath needs: the larger of GetConfig().MinAmountPerExecution() and GetTokenMinAmountPerExecution(tokenPath).

Parameters:

  • tokenPath: input token path

Returns:

  • int64: effective minimum, in raw token units

func GetMinExecutionGapRate

Action
1func GetMinExecutionGapRate() int64
source

GetMinExecutionGapRate returns the minimum gap between a group's executions.

Returns:

  • int64: minimum gap, in basis points of the group interval

func GetNextOrderID

Action
1func GetNextOrderID() uint64
source

GetNextOrderID returns the ID the next created order receives.

Returns:

  • uint64: next order ID

func GetOrder

Action
1func GetOrder(orderID uint64) (*pdca.Order, error)
source

GetOrder returns a copy of an active order. Finished orders are deleted and return an error.

Parameters:

  • orderID: order to look up

Returns:

  • *pdca.Order: copy of the order
  • error: non-nil when the order is not active

func GetOrderAmountsByGroup

Action
1func GetOrderAmountsByGroup() *rotree.ReadOnlyTree
source

GetOrderAmountsByGroup returns the read-only group index of orders by executionFeeRate, then amountPerExecution, which a round reads for the smallest order of each fee rate. Iterate the [pdca.GroupOrderPrefix(groupID), pdca.PrefixEnd(prefix)) range for one group's orders by ascending executionFeeRate, amountPerExecution, then ID, or the [pdca.GroupOrderFeeRatePrefix(groupID, rate), pdca.PrefixEnd(prefix)) range for the orders of one fee rate. A finished order's entry stays until the order is paid out or a later round of its group removes it.

Returns:

  • *rotree.ReadOnlyTree: pdca.GroupOrderAmountKey(groupID, executionFeeRate, amountPerExecution, orderID) -> uint64 endRound

func GetOrderExecutionLogs

Action
1func GetOrderExecutionLogs(orderID uint64, count int) ([]*pdca.ExecutionLog, error)
source

GetOrderExecutionLogs returns copies of up to count of an active order's unreleased execution logs, oldest first: each covers up to three rounds, [FirstRound, LastRound], and the input the order sells in each. A log is released once all of its rounds executed and the order is claimed; the rounds' swap results are in the DCAGroupExecuted events.

Parameters:

  • orderID: order to look up
  • count: maximum number of logs returned

Returns:

  • []*pdca.ExecutionLog: copies of the order's unreleased logs
  • error: non-nil when the order is not active

func GetOrderIDsByGroup

Action
1func GetOrderIDsByGroup(groupID string, startAfterID uint64, count int) []uint64
source

GetOrderIDsByGroup returns up to count active order IDs of a group, ascending and greater than startAfterID. Page as GetOrderIDsByOwner.

Parameters:

  • groupID: group to look up
  • startAfterID: exclusive lower bound of the returned IDs
  • count: maximum number of IDs returned

Returns:

  • []uint64: active order IDs, ascending

func GetOrderIDsByOwner

Action
1func GetOrderIDsByOwner(owner address, startAfterID uint64, count int) []uint64
source

GetOrderIDsByOwner returns up to count active order IDs of owner, ascending and greater than startAfterID (0 starts from the first). Page by passing the last returned ID.

Parameters:

  • owner: order owner
  • startAfterID: exclusive lower bound of the returned IDs
  • count: maximum number of IDs returned

Returns:

  • []uint64: active order IDs, ascending

func GetOrders

Action
1func GetOrders() *rotree.ReadOnlyTree
source

GetOrders returns a read-only view of active orders.

Returns:

  • *rotree.ReadOnlyTree: pdca.OrderKey(orderID) -> *pdca.Order; each order read from the view is a copy

func GetOrdersByGroup

Action
1func GetOrdersByGroup() *rotree.ReadOnlyTree
source

GetOrdersByGroup returns the read-only group index of active orders. Iterate the [pdca.GroupOrderPrefix(groupID), pdca.PrefixEnd(prefix)) range for one group's orders in ID order.

Returns:

  • *rotree.ReadOnlyTree: pdca.GroupOrderKey(groupID, orderID) -> uint64 orderID

func GetOrdersByOwner

Action
1func GetOrdersByOwner() *rotree.ReadOnlyTree
source

GetOrdersByOwner returns the read-only owner index of active orders. Iterate the [pdca.OwnerOrderPrefix(owner), pdca.PrefixEnd(prefix)) range for one owner's orders in ID order.

Returns:

  • *rotree.ReadOnlyTree: pdca.OwnerOrderKey(owner, orderID) -> uint64 orderID

func GetPairPriceLimit

Action
1func GetPairPriceLimit(inputToken string, outputToken string) (string, int64)
source

GetPairPriceLimit returns the price limit of selling inputToken for outputToken (see SetPairPriceLimit).

Parameters:

  • inputToken, outputToken: the pair direction

Returns:

  • string: minOutputPerInputX128, decimal Q128; "0" when none is set
  • int64: unix time the limit was set; 0 when none is set

func GetPairPriceLimits

Action
1func GetPairPriceLimits() *rotree.ReadOnlyTree
source

GetPairPriceLimits returns a read-only view of the pair price limits, in key order. Entries are copies.

Returns:

  • *rotree.ReadOnlyTree: "inputToken:outputToken" -> *pdca.PairPriceLimit

func GetPendingExecutionFeeAmount

Action
1func GetPendingExecutionFeeAmount(tokenPath string) int64
source

GetPendingExecutionFeeAmount returns the execution fee of tokenPath held by this realm: fees payouts charged, and fees the protocol fee realm could not accept yet. It is forwarded by the next round whose output token is tokenPath, or by CollectPendingExecutionFee.

Parameters:

  • tokenPath: fee token path

Returns:

  • int64: pending execution fee, in raw token units

func GetPendingExecutionFees

Action
1func GetPendingExecutionFees() *rotree.ReadOnlyTree
source

GetPendingExecutionFees returns the read-only index of pending execution fees. A token whose pending fee was forwarded keeps its entry at 0.

Returns:

  • *rotree.ReadOnlyTree: tokenPath -> int64 pending amount

func GetScheduledGroups

Action
1func GetScheduledGroups() *rotree.ReadOnlyTree
source

GetScheduledGroups returns the read-only schedule of groups with input to sell, ordered by next execution timestamp, then group ID. pdca.ScheduleKeyTimestamp decodes a key's timestamp.

Returns:

  • *rotree.ReadOnlyTree: pdca.ScheduleKey(nextExecutionTimestamp, groupID) -> string groupID

func GetSlotStep

Action
1func GetSlotStep(interval int64) int64
source

GetSlotStep returns the spacing of the slot offsets new orders may use at interval.

Parameters:

  • interval: round interval, in seconds

Returns:

  • int64: slot step in seconds; 0 when interval is not allowed

func GetTokenMinAmountPerExecution

Action
1func GetTokenMinAmountPerExecution(tokenPath string) int64
source

GetTokenMinAmountPerExecution returns the minimum input per execution the manager set for tokenPath (see SetTokenMinAmountPerExecution).

Parameters:

  • tokenPath: input token path

Returns:

  • int64: minimum in raw token units; 0 when none is set

func GetTokenMinAmountsPerExecution

Action
1func GetTokenMinAmountsPerExecution() *rotree.ReadOnlyTree
source

GetTokenMinAmountsPerExecution returns the read-only index of per-token minimums, in key order.

Returns:

  • *rotree.ReadOnlyTree: tokenPath -> int64

func IsAllowedInterval

Action
1func IsAllowedInterval(interval int64) bool
source

IsAllowedInterval reports whether new orders may use interval.

Parameters:

  • interval: round interval, in seconds

Returns:

  • bool: true when interval is allowed

func NewBPTreeN

Action
1func NewBPTreeN(fanout int) *bptree.BPTree
source

NewBPTreeN allocates an empty B+tree in the order/dca realm. Implementations create the store trees through it, so the trees are owned by the realm that stores them.

func NewSwapCallback

Action
1func NewSwapCallback(_ int, rlm realm, tokenIn string, zeroForOne bool, maxAmountIn int64) func(cur realm, amount0Delta, amount1Delta int64, _ *pool.CallbackMarker) error
source

NewSwapCallback returns the callback of one round's pool.Swap. It pays the pool the round input, at most maxAmountIn of tokenIn, from the escrow.

The callback is declared in this realm, so it transfers as the escrow itself: the escrow never grants an allowance for a swap. That makes the callback a payment capability, so it is guarded on creation and on use:

  • only the escrow's own current realm can create one, so only code the proxy hands its realm to (the active implementation) can;
  • only the pool can invoke it (cur.Previous()); the pool's swap lock admits no other swap while a round's swap runs;
  • it pays only while a round is executing, once, and only an exact-input delta of the sold token: positive input, no positive output, at most maxAmountIn.

zeroForOne is the swap direction: it selects which pool delta is tokenIn.

func RegisterInitializer

crossing Action
1func RegisterInitializer(cur realm, initializer func(_ int, rlm realm, dcaStore pdca.IDCAOrderStore) pdca.IDCAOrder)
source

RegisterInitializer registers an implementation version. Each version calls it from init with a factory that receives the shared store. Only packages under this realm's path may register, and the first registration becomes active. A nil initializer is rejected here, instead of panicking later when the version is activated.

func RemoveAllowedInterval

crossing Action
1func RemoveAllowedInterval(cur realm, interval int64)
source

RemoveAllowedInterval stops new orders from using interval. Existing orders and groups of that interval keep running until they finish; its slot step is dropped, and re-adding it starts from a single slot. At least one interval must stay allowed. Admin or governance only.

func SetExecutionFeeRate

crossing Action
1func SetExecutionFeeRate(cur realm, executionFeeRate int64)
source

SetExecutionFeeRate sets the share of an order's output, in basis points (0 to 1000, at most 10%), sent to the protocol fee realm. Orders created afterwards snapshot it; existing orders keep their rate.

Admin or governance only.

func SetMaxClaimBatchSize

crossing Action
1func SetMaxClaimBatchSize(cur realm, maxClaimBatchSize int64)
source

SetMaxClaimBatchSize caps the orders one ClaimGroupOrders call examines, bounding its gas. Admin or governance only.

func SetMaxPairPriceLimitAge

crossing Action
1func SetMaxPairPriceLimitAge(cur realm, maxPairPriceLimitAge int64)
source

SetMaxPairPriceLimitAge sets how long, in seconds, a pair price limit stays usable after the pool manager set it (see SetPairPriceLimit), 60 to 604800. Under an older limit every pool is ineligible (code price_limit_stale), so rounds stop until the limit is refreshed instead of trading at a stale price. v0 starts at 3600 (one hour). Admin or governance only.

func SetMaxPoolPriceDeviationRate

crossing Action
1func SetMaxPoolPriceDeviationRate(cur realm, maxPoolPriceDeviationRate int64)
source

SetMaxPoolPriceDeviationRate sets how far, in basis points of price, a pool's price may sit on the favorable side of its swap price limit (see SetPairPriceLimit) and still be quoted, 0 to 10000; 0 disables the check. A pool further away is ineligible without a quote: its quote or swap would walk every tick between its price and the limit, which an empty or manipulated pool far from the oracle price makes unbounded. v0 starts at 2000 (20%). Admin or governance only.

func SetMinExecutionGapRate

crossing Action
1func SetMinExecutionGapRate(cur realm, minExecutionGapRate int64)
source

SetMinExecutionGapRate sets the minimum gap between two executions of a group, in basis points of its interval (0 to 10000), so a late execution is not followed right away by the next one. Admin or governance only.

func SetOrderLimits

crossing Action
1func SetOrderLimits(cur realm, minAmountPerExecution int64, maxExecutionCount int64)
source

SetOrderLimits sets the minimum input per execution and the maximum executions per order. Admin or governance only.

func SetPairPriceLimit

crossing Action
1func SetPairPriceLimit(cur realm, inputToken string, outputToken string, minOutputPerInputX128 string)
source

SetPairPriceLimit sets the least pool output, before the execution fee, that rounds selling inputToken for outputToken accept per unit of input: minOutputPerInputX128 is raw outputToken units per raw inputToken unit, in Q128 fixed point, as a decimal string. "0" removes the limit.

Every quote and round of the pair direction passes the limit to the pool as its swap price limit, adjusted for the pool's fee tier, so each unit of input fills at a rate of at least the limit and a swap crosses only the ticks up to it. A pool whose price is past the limit is skipped, and a round that cannot be filled within it reverts. A pair direction without a limit cannot be quoted, executed, or receive new orders. The limit applies from the next quote or round, to existing orders too. Its update time is recorded but not checked on-chain.

Admin, governance, or accounts holding the role assigned to the SetPairPriceLimit selector in gno.land/r/gnoswap/order/keeper (PoolManagerRole at deployment).

func SetSlotStep

crossing Action
1func SetSlotStep(cur realm, interval int64, slotStep int64)
source

SetSlotStep sets the spacing, in seconds, of the slot offsets new orders may use at interval: slotStep must divide the interval, and the interval then has interval/slotStep slots. slotStep == interval allows offset 0 only.

Existing groups keep their slot, even one the new step no longer allows; only new orders are checked. Finer steps split each pair's orders into more groups, so each round sells less in more swaps.

Admin or governance only.

func SetTokenMinAmountPerExecution

crossing Action
1func SetTokenMinAmountPerExecution(cur realm, tokenPath string, minAmountPerExecution int64)
source

SetTokenMinAmountPerExecution sets the minimum input per execution of new orders selling tokenPath, in raw token units, applied on top of the global minimum (see SetOrderLimits); 0 removes it. The pool manager derives it from an oracle price, so every order is worth a set value per round whatever the token's decimals. Existing orders are unaffected.

Admin, governance, or accounts holding the role assigned to the SetTokenMinAmountPerExecution selector in gno.land/r/gnoswap/order/keeper (PoolManagerRole at deployment).

func UpgradeImpl

crossing Action
1func UpgradeImpl(cur realm, packagePath string)
source

UpgradeImpl activates a previously registered version by package path. Admin or governance only.

Types 1

type StoreKey

ident
1type StoreKey string
source

StoreKey is a key of the DCA KV store.

Methods on StoreKey

func String

method on StoreKey
1func (s StoreKey) String() string
source

Dependencies

Source Files 9