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

price_limit.gno

1.60 Kb · 46 lines
 1package dca
 2
 3import (
 4	u256 "gno.land/p/gnoswap/uint256/v1"
 5)
 6
 7// PairPriceLimit is the minimum pool output a round of one pair direction
 8// accepts per unit of input, set by the pool manager from an oracle price.
 9//
10// minOutputPerInputX128 is raw outputToken units, before the execution fee,
11// per raw inputToken unit, in Q128 fixed point.
12// Rounds use it as the pool swap price limit, so it bounds both the price
13// and the ticks a quote or swap may cross.
14// updatedAt is the unix time it was set; a limit older than
15// Config.MaxPairPriceLimitAge leaves no pool eligible.
16type PairPriceLimit struct {
17	minOutputPerInputX128 *u256.Uint
18	updatedAt             int64
19}
20
21// NewPairPriceLimit returns a limit of minOutputPerInputX128, set at updatedAt.
22func NewPairPriceLimit(minOutputPerInputX128 *u256.Uint, updatedAt int64) *PairPriceLimit {
23	return &PairPriceLimit{
24		minOutputPerInputX128: minOutputPerInputX128.Clone(),
25		updatedAt:             updatedAt,
26	}
27}
28
29// MinOutputPerInputX128 returns a copy of the limit.
30func (l *PairPriceLimit) MinOutputPerInputX128() *u256.Uint {
31	return l.minOutputPerInputX128.Clone()
32}
33
34// UpdatedAt returns the unix time the limit was set.
35func (l *PairPriceLimit) UpdatedAt() int64 { return l.updatedAt }
36
37// Update replaces the limit and its update time in place.
38func (l *PairPriceLimit) Update(minOutputPerInputX128 *u256.Uint, updatedAt int64) {
39	l.minOutputPerInputX128 = minOutputPerInputX128.Clone()
40	l.updatedAt = updatedAt
41}
42
43// Clone returns a copy of the limit.
44func (l *PairPriceLimit) Clone() *PairPriceLimit {
45	return NewPairPriceLimit(l.minOutputPerInputX128, l.updatedAt)
46}