Search Apps Documentation Source Content File Folder Download Copy Actions Download

position.gno

3.96 Kb ยท 154 lines
  1package position
  2
  3import u256 "gno.land/p/gnoswap/uint256"
  4
  5// Position represents a liquidity position in a pool.
  6// Each position tracks the amount of liquidity, fee growth, and tokens owed to the position owner.
  7type Position struct {
  8	operator  address    // address that is approved for spending this token
  9	poolKey   string     // poolPath of the pool which this has lp token
 10	tickLower int32      // the lower tick of the position, bounds are included
 11	tickUpper int32      // the upper tick of the position
 12	liquidity *u256.Uint // liquidity of the position
 13
 14	// fee growth of the aggregate position as of the last action on the individual position
 15	feeGrowthInside0LastX128 *u256.Uint
 16	feeGrowthInside1LastX128 *u256.Uint
 17
 18	// how many uncollected tokens are owed to the position, as of the last computation
 19	tokensOwed0 *u256.Uint
 20	tokensOwed1 *u256.Uint
 21
 22	token0Balance *u256.Uint // token0 balance of the position
 23	token1Balance *u256.Uint // token1 balance of the position
 24
 25	burned bool // whether the position has been burned (we don't burn the NFT, just mark as burned)
 26}
 27
 28func (p *Position) PoolKey() string {
 29	return p.poolKey
 30}
 31
 32func (p *Position) SetPoolKey(poolKey string) {
 33	p.poolKey = poolKey
 34}
 35
 36func (p *Position) Liquidity() *u256.Uint {
 37	return p.liquidity
 38}
 39
 40func (p *Position) SetLiquidity(liquidity *u256.Uint) {
 41	p.liquidity = liquidity
 42}
 43
 44func (p *Position) TickLower() int32 {
 45	return p.tickLower
 46}
 47
 48func (p *Position) SetTickLower(tickLower int32) {
 49	p.tickLower = tickLower
 50}
 51
 52func (p *Position) TickUpper() int32 {
 53	return p.tickUpper
 54}
 55
 56func (p *Position) SetTickUpper(tickUpper int32) {
 57	p.tickUpper = tickUpper
 58}
 59
 60func (p *Position) TokensOwed0() *u256.Uint {
 61	return p.tokensOwed0
 62}
 63
 64func (p *Position) SetTokensOwed0(tokensOwed0 *u256.Uint) {
 65	p.tokensOwed0 = tokensOwed0
 66}
 67
 68func (p *Position) TokensOwed1() *u256.Uint {
 69	return p.tokensOwed1
 70}
 71
 72func (p *Position) SetTokensOwed1(tokensOwed1 *u256.Uint) {
 73	p.tokensOwed1 = tokensOwed1
 74}
 75
 76func (p *Position) Token0Balance() *u256.Uint {
 77	return p.token0Balance
 78}
 79
 80func (p *Position) SetToken0Balance(token0Balance *u256.Uint) {
 81	p.token0Balance = token0Balance
 82}
 83
 84func (p *Position) Token1Balance() *u256.Uint {
 85	return p.token1Balance
 86}
 87
 88func (p *Position) SetToken1Balance(token1Balance *u256.Uint) {
 89	p.token1Balance = token1Balance
 90}
 91
 92func (p *Position) FeeGrowthInside0LastX128() *u256.Uint {
 93	return p.feeGrowthInside0LastX128
 94}
 95
 96func (p *Position) SetFeeGrowthInside0LastX128(feeGrowthInside0LastX128 *u256.Uint) {
 97	p.feeGrowthInside0LastX128 = feeGrowthInside0LastX128
 98}
 99
100func (p *Position) FeeGrowthInside1LastX128() *u256.Uint {
101	return p.feeGrowthInside1LastX128
102}
103
104func (p *Position) SetFeeGrowthInside1LastX128(feeGrowthInside1LastX128 *u256.Uint) {
105	p.feeGrowthInside1LastX128 = feeGrowthInside1LastX128
106}
107
108func (p *Position) Burned() bool {
109	return p.burned
110}
111
112func (p *Position) SetBurned(burned bool) {
113	p.burned = burned
114}
115
116func (p *Position) Operator() address {
117	return p.operator
118}
119
120func (p *Position) SetOperator(operator address) {
121	p.operator = operator
122}
123
124// isClear reports whether the position is empty
125func (p *Position) IsClear() bool {
126	return p.liquidity.IsZero() && p.tokensOwed0.IsZero() && p.tokensOwed1.IsZero()
127}
128
129func NewPosition(
130	poolKey string,
131	tickLower int32,
132	tickUpper int32,
133	liquidity *u256.Uint,
134	feeGrowthInside0LastX128, feeGrowthInside1LastX128 *u256.Uint,
135	tokensOwed0, tokensOwed1 *u256.Uint,
136	token0Balance, token1Balance *u256.Uint,
137	burned bool,
138	operator address,
139) *Position {
140	return &Position{
141		poolKey:                  poolKey,
142		tickLower:                tickLower,
143		tickUpper:                tickUpper,
144		liquidity:                liquidity,
145		feeGrowthInside0LastX128: feeGrowthInside0LastX128,
146		feeGrowthInside1LastX128: feeGrowthInside1LastX128,
147		tokensOwed0:              tokensOwed0,
148		tokensOwed1:              tokensOwed1,
149		token0Balance:            token0Balance,
150		token1Balance:            token1Balance,
151		burned:                   burned,
152		operator:                 operator,
153	}
154}