Skip to content

Commit 03dbf7b

Browse files
authored
Merge pull request #146 from gnoswap-labs/GSW-794-feat-more-rpc-data-to-simulate-dry-swap-externally
GSW-794 feat: more rpc data to simulate dry swap externally
2 parents 5e00770 + e873d3a commit 03dbf7b

File tree

3 files changed

+112
-1
lines changed

3 files changed

+112
-1
lines changed

pool/_RPC_call.gno

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,115 @@ func RpcGetPools() string {
1616

1717
rr, err := json.Marshal(poolsDetail)
1818
if err != nil {
19-
panic(ufmt.Sprintf("[POOL] getter_api.gno__ApiGetPools() || %v", err))
19+
panic(ufmt.Sprintf("[POOL] getter_api.gno__RpcGetPools() || %v", err))
2020
}
2121

2222
return string(rr)
2323
}
24+
25+
func RpcMakePool(poolKey string) string {
26+
rpcPool := RpcPool{}
27+
pool := GetPoolFromPoolKey(poolKey)
28+
29+
rpcPool.Token0Path = pool.token0Path
30+
rpcPool.Token1Path = pool.token1Path
31+
32+
rpcPool.BalancesToken0 = pool.balances.token0
33+
rpcPool.BalancesToken1 = pool.balances.token1
34+
35+
rpcPool.Fee = pool.fee
36+
37+
rpcPool.TickSpacing = pool.tickSpacing
38+
39+
rpcPool.MaxLiquidityPerTick = pool.maxLiquidityPerTick
40+
41+
rpcPool.Slot0SqrtPriceX96 = pool.slot0.sqrtPriceX96
42+
rpcPool.Slot0Tick = pool.slot0.tick
43+
rpcPool.Slot0FeeProtocol = pool.slot0.feeProtocol
44+
rpcPool.Slot0Unlocked = pool.slot0.unlocked
45+
46+
rpcPool.FeeGrowthGlobal0X128 = pool.feeGrowthGlobal0X128
47+
rpcPool.FeeGrowthGlobal1X128 = pool.feeGrowthGlobal1X128
48+
49+
rpcPool.ProtocolFeesToken0 = pool.protocolFees.token0
50+
rpcPool.ProtocolFeesToken1 = pool.protocolFees.token1
51+
52+
rpcPool.Liquidity = pool.liquidity
53+
54+
rpcPool.Ticks = RpcTicks{}
55+
for tick, tickInfo := range pool.ticks {
56+
rpcPool.Ticks[tick] = RpcTickInfo{
57+
LiquidityGross: tickInfo.liquidityGross,
58+
LiquidityNet: tickInfo.liquidityNet,
59+
FeeGrowthOutside0X128: tickInfo.feeGrowthOutside0X128,
60+
FeeGrowthOutside1X128: tickInfo.feeGrowthOutside1X128,
61+
TickCumulativeOutside: tickInfo.tickCumulativeOutside,
62+
SecondsPerLiquidityOutsideX: tickInfo.secondsPerLiquidityOutsideX128,
63+
SecondsOutside: tickInfo.secondsOutside,
64+
Initialized: tickInfo.initialized,
65+
}
66+
}
67+
68+
rpcPool.TickBitmaps = pool.tickBitmaps
69+
70+
rr, err := json.Marshal(rpcPool)
71+
if err != nil {
72+
panic(ufmt.Sprintf("[POOL] getter_api.gno__RpcMakePool() || %v", err))
73+
}
74+
75+
return string(rr)
76+
}
77+
78+
type RpcPool struct {
79+
Token0Path string `json:"token0_path"`
80+
Token1Path string `json:"token1_path"`
81+
82+
BalancesToken0 bigint `json:"token0_balance"`
83+
BalancesToken1 bigint `json:"token1_balance"`
84+
85+
// fee is the fee tier of the pool
86+
Fee uint16 `json:"fee"`
87+
88+
// tickSpacing is the spacing between ticks
89+
TickSpacing int32 `json:"tick_spacing"`
90+
91+
// maxLiquidityPerTick is the maximum amount of liquidity that can be added per tick
92+
MaxLiquidityPerTick bigint `json:"max_liquidity_per_tick"`
93+
94+
// slot0 is the current tick and price of the pool
95+
Slot0SqrtPriceX96 bigint `json:"sqrt_price_x96"`
96+
Slot0Tick int32 `json:"tick"`
97+
Slot0FeeProtocol uint8 `json:"fee_protocol"`
98+
Slot0Unlocked bool `json:"unlocked"`
99+
100+
FeeGrowthGlobal0X128 bigint `json:"global0_fee_growth_x128"`
101+
FeeGrowthGlobal1X128 bigint `json:"global1_fee_growth_x128"`
102+
103+
ProtocolFeesToken0 bigint `json:"token0_protocol_fee"`
104+
ProtocolFeesToken1 bigint `json:"token1_protocol_fee"`
105+
106+
// liquidity is the total amount of liquidity in the pool
107+
Liquidity bigint `json:"liquidity"`
108+
109+
// ticks is a mapping from tick index to tick
110+
Ticks RpcTicks `json:"ticks"`
111+
112+
// tickBitmaps is a mapping from tick index to tick bitmap
113+
TickBitmaps TickBitmaps `json:"tick_bitmaps"`
114+
}
115+
116+
type RpcTicks map[int32]RpcTickInfo // tick => RpcTickInfo
117+
type RpcTickInfo struct {
118+
LiquidityGross bigint `json:"liquidity_gross"`
119+
LiquidityNet bigint `json:"liquidity_net"`
120+
121+
FeeGrowthOutside0X128 bigint `json:"outside0_fee_growth_x128"`
122+
FeeGrowthOutside1X128 bigint `json:"outside1_fee_growth_x128"`
123+
124+
TickCumulativeOutside bigint `json:"tick_cumulative_outside"`
125+
126+
SecondsPerLiquidityOutsideX bigint `json:"seconds_per_liquidity_outside_x"`
127+
SecondsOutside bigint `json:"seconds_outside"`
128+
129+
Initialized bool `json:"initialized"`
130+
}
File renamed without changes.

pool/_TEST_rpc_test.gnoa renamed to pool/_TEST_rpc_test.gno

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,7 @@ func TestApiGetPool(t *testing.T) {
8787
func TestRpcGetPools(t *testing.T) {
8888
RpcGetPools()
8989
}
90+
91+
func TestRpcMakePool(t *testing.T) {
92+
RpcMakePool("gno.land/r/demo/bar:gno.land/r/demo/baz:500")
93+
}

0 commit comments

Comments
 (0)