Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GSW-1032 feat: ApiGetPool(poolPath) to retrieve single pool information #213

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions pool/_RPC_api.gno
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,56 @@ func ApiGetPools() string {
return string(b)
}

func ApiGetPool(poolPath string) string {
_, exist := pools[poolPath]
if !exist {
return ""
}
rpcPool := rpcMakePool(poolPath)

// STAT NODE
_stat := json.ObjectNode("", map[string]*json.Node{
"height": json.NumberNode("height", float64(std.GetHeight())),
"timestamp": json.NumberNode("timestamp", float64(time.Now().Unix())),
})

// RESPONSE NODE
responseNode := json.ObjectNode("", map[string]*json.Node{
"poolPath": json.StringNode("poolPath", rpcPool.PoolPath),
"token0Path": json.StringNode("token0Path", rpcPool.Token0Path),
"token1Path": json.StringNode("token1Path", rpcPool.Token1Path),
"token0Balance": json.StringNode("token0Balance", rpcPool.Token0Balance),
"token1Balance": json.StringNode("token1Balance", rpcPool.Token1Balance),
"fee": json.NumberNode("fee", float64(rpcPool.Fee)),
"tickSpacing": json.NumberNode("tickSpacing", float64(rpcPool.TickSpacing)),
"maxLiquidityPerTick": json.StringNode("maxLiquidityPerTick", rpcPool.MaxLiquidityPerTick),
"sqrtPriceX96": json.StringNode("sqrtPriceX96", rpcPool.Slot0SqrtPriceX96),
"tick": json.NumberNode("tick", float64(rpcPool.Slot0Tick)),
"feeProtocol": json.NumberNode("feeProtocol", float64(rpcPool.Slot0FeeProtocol)),
"unlocked": json.BoolNode("unlocked", rpcPool.Slot0Unlocked),
"feeGrowthGlobal0X128": json.StringNode("feeGrowthGlobal0X128", rpcPool.FeeGrowthGlobal0X128),
"feeGrowthGlobal1X128": json.StringNode("feeGrowthGlobal1X128", rpcPool.FeeGrowthGlobal1X128),
"token0ProtocolFee": json.StringNode("token0ProtocolFee", rpcPool.Token0ProtocolFee),
"token1ProtocolFee": json.StringNode("token1ProtocolFee", rpcPool.Token1ProtocolFee),
"liquidity": json.StringNode("liquidity", rpcPool.Liquidity),
"ticks": json.ObjectNode("ticks", makeTicksJson(rpcPool.Ticks)),
"tickBitmaps": json.ObjectNode("tickBitmaps", makeRpcTickBitmapsJson(rpcPool.TickBitmaps)),
"positions": json.ArrayNode("positions", makeRpcPositionsArray(rpcPool.Positions)),
})

node := json.ObjectNode("", map[string]*json.Node{
"stat": _stat,
"response": responseNode,
})

b, err := json.Marshal(node)
if err != nil {
panic(ufmt.Sprintf("[POOL] _RPC_api.gno__ApiGetPool(%s) || %s", poolPath, err.Error()))
}

return string(b)
}

func rpcMakePool(poolPath string) RpcPool {
rpcPool := RpcPool{}
pool := GetPoolFromPoolPath(poolPath)
Expand Down
Loading