Skip to content

Commit ad4d41a

Browse files
authored
Merge pull request #149 from gnoswap-labs/GSW-835-feat-make-rpc-pool-s-to-return-positions
GSW-835 feat: `MakeRpcPool(s)` to return position info
2 parents af47203 + 0b4e7f3 commit ad4d41a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

pool/_RPC_call.gno

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,23 @@ func RpcMakePoolStruct(poolKey string) RpcPool {
8484
}
8585

8686
rpcPool.TickBitmaps = pool.tickBitmaps
87+
88+
_positions := pool.positions
89+
rpcPositions := []RpcPosition{}
90+
for posKey, posInfo := range _positions {
91+
owner, tickLower, tickUpper := posKeyDivide(posKey)
92+
93+
rpcPositions = append(rpcPositions, RpcPosition{
94+
Owner: owner,
95+
TickLower: tickLower,
96+
TickUpper: tickUpper,
97+
Liquidity: posInfo.liquidity,
98+
Token0Owed: posInfo.tokensOwed0,
99+
Token1Owed: posInfo.tokensOwed1,
100+
})
101+
}
102+
rpcPool.Positions = rpcPositions
103+
87104
return rpcPool
88105
}
89106

@@ -134,6 +151,22 @@ func RpcMakePool(poolKey string) string {
134151

135152
rpcPool.TickBitmaps = pool.tickBitmaps
136153

154+
_positions := pool.positions
155+
rpcPositions := []RpcPosition{}
156+
for posKey, posInfo := range _positions {
157+
owner, tickLower, tickUpper := posKeyDivide(posKey)
158+
159+
rpcPositions = append(rpcPositions, RpcPosition{
160+
Owner: owner,
161+
TickLower: tickLower,
162+
TickUpper: tickUpper,
163+
Liquidity: posInfo.liquidity,
164+
Token0Owed: posInfo.tokensOwed0,
165+
Token1Owed: posInfo.tokensOwed1,
166+
})
167+
}
168+
rpcPool.Positions = rpcPositions
169+
137170
rr, err := json.Marshal(rpcPool)
138171
if err != nil {
139172
panic(ufmt.Sprintf("[POOL] getter_api.gno__RpcMakePool() || %v", err))
@@ -142,6 +175,7 @@ func RpcMakePool(poolKey string) string {
142175
return string(rr)
143176
}
144177

178+
// TYPEs
145179
type RpcPool struct {
146180
PoolPath string `json:"pool_path"`
147181

@@ -180,6 +214,8 @@ type RpcPool struct {
180214

181215
// tickBitmaps is a mapping from tick index to tick bitmap
182216
TickBitmaps TickBitmaps `json:"tick_bitmaps"`
217+
218+
Positions []RpcPosition
183219
}
184220

185221
type RpcTicks map[int32]RpcTickInfo // tick => RpcTickInfo
@@ -197,3 +233,15 @@ type RpcTickInfo struct {
197233

198234
Initialized bool `json:"initialized"`
199235
}
236+
237+
type RpcPosition struct {
238+
Owner string `json:"owner"`
239+
240+
TickLower bigint `json:"tick_lower"`
241+
TickUpper bigint `json:"tick_upper"`
242+
243+
Liquidity bigint `json:"liquidity"`
244+
245+
Token0Owed bigint `json:"token0_owed"`
246+
Token1Owed bigint `json:"token1_owed"`
247+
}

0 commit comments

Comments
 (0)