import { PageRequest, PageResponse } from "../../../cosmos/base/query/v1beta1/pagination"; import { SwapAmountInRoute, SwapAmountOutRoute } from "./tx"; import { Any } from "../../../google/protobuf/any"; import { Coin } from "../../../cosmos/base/v1beta1/coin"; import { LCDClient } from "@osmonauts/lcd"; import { setPaginationParams } from "@osmonauts/helpers"; import { QueryPoolsRequest, QueryPoolsResponse, QueryNumPoolsRequest, QueryNumPoolsResponse, QueryTotalLiquidityRequest, QueryTotalLiquidityResponse, QueryPoolRequest, QueryPoolResponse, QueryPoolParamsRequest, QueryPoolParamsResponse, QueryTotalPoolLiquidityRequest, QueryTotalPoolLiquidityResponse, QueryTotalSharesRequest, QueryTotalSharesResponse, QuerySpotPriceRequest, QuerySpotPriceResponse, QuerySwapExactAmountInRequest, QuerySwapExactAmountInResponse, QuerySwapExactAmountOutRequest, QuerySwapExactAmountOutResponse } from "./query"; export class LCDQueryClient extends LCDClient { constructor({ restEndpoint }: { restEndpoint: string; }) { super({ restEndpoint }); } /* Pools */ async pools(params: QueryPoolsRequest = { pagination: undefined }): Promise { const options: any = { params: {} }; if (typeof params?.pagination !== "undefined") { setPaginationParams(options, params.pagination); } const endpoint = `osmosis/gamm/v1beta1/pools`; return await this.request(endpoint, options); } /* NumPools */ async numPools(_params: QueryNumPoolsRequest = {}): Promise { const endpoint = `osmosis/gamm/v1beta1/num_pools`; return await this.request(endpoint); } /* TotalLiquidity */ async totalLiquidity(_params: QueryTotalLiquidityRequest = {}): Promise { const endpoint = `osmosis/gamm/v1beta1/total_liquidity`; return await this.request(endpoint); } /* Per Pool gRPC Endpoints */ async pool(params: QueryPoolRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}`; return await this.request(endpoint); } /* PoolParams */ async poolParams(params: QueryPoolParamsRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}/params`; return await this.request(endpoint); } /* TotalPoolLiquidity */ async totalPoolLiquidity(params: QueryTotalPoolLiquidityRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}/total_pool_liquidity`; return await this.request(endpoint); } /* TotalShares */ async totalShares(params: QueryTotalSharesRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}/total_shares`; return await this.request(endpoint); } /* SpotPrice defines a gRPC query handler that returns the spot price given a base denomination and a quote denomination. */ async spotPrice(params: QuerySpotPriceRequest): Promise { const options: any = { params: {} }; if (typeof params?.base_asset_denom !== "undefined") { options.params.base_asset_denom = params.base_asset_denom; } if (typeof params?.quote_asset_denom !== "undefined") { options.params.quote_asset_denom = params.quote_asset_denom; } const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}/prices`; return await this.request(endpoint, options); } /* Estimate the swap. */ async estimateSwapExactAmountIn(params: QuerySwapExactAmountInRequest): Promise { const options: any = { params: {} }; if (typeof params?.sender !== "undefined") { options.params.sender = params.sender; } if (typeof params?.tokenIn !== "undefined") { options.params.tokenIn = params.tokenIn; } if (typeof params?.routes !== "undefined") { options.params.routes = params.routes; } const endpoint = `osmosis/gamm/v1beta1/${params.poolId}/estimate/swap_exact_amount_in`; return await this.request(endpoint, options); } /* EstimateSwapExactAmountOut */ async estimateSwapExactAmountOut(params: QuerySwapExactAmountOutRequest): Promise { const options: any = { params: {} }; if (typeof params?.sender !== "undefined") { options.params.sender = params.sender; } if (typeof params?.routes !== "undefined") { options.params.routes = params.routes; } if (typeof params?.tokenOut !== "undefined") { options.params.tokenOut = params.tokenOut; } const endpoint = `osmosis/gamm/v1beta1/${params.poolId}/estimate/swap_exact_amount_out`; return await this.request(endpoint, options); } }