import { setPaginationParams } from "../../../helpers"; import { LCDClient } from "@osmonauts/lcd"; import { QueryPoolsRequest, QueryPoolsResponseSDKType, QueryNumPoolsRequest, QueryNumPoolsResponseSDKType, QueryTotalLiquidityRequest, QueryTotalLiquidityResponseSDKType, QueryPoolRequest, QueryPoolResponseSDKType, QueryPoolTypeRequest, QueryPoolTypeResponseSDKType, QueryPoolParamsRequest, QueryPoolParamsResponseSDKType, QueryTotalPoolLiquidityRequest, QueryTotalPoolLiquidityResponseSDKType, QueryTotalSharesRequest, QueryTotalSharesResponseSDKType, QuerySpotPriceRequest, QuerySpotPriceResponseSDKType, QuerySwapExactAmountInRequest, QuerySwapExactAmountInResponseSDKType, QuerySwapExactAmountOutRequest, QuerySwapExactAmountOutResponseSDKType } from "./query"; export class LCDQueryClient { req: LCDClient; constructor({ requestClient }: { requestClient: LCDClient; }) { this.req = requestClient; this.pools = this.pools.bind(this); this.numPools = this.numPools.bind(this); this.totalLiquidity = this.totalLiquidity.bind(this); this.pool = this.pool.bind(this); this.poolType = this.poolType.bind(this); this.poolParams = this.poolParams.bind(this); this.totalPoolLiquidity = this.totalPoolLiquidity.bind(this); this.totalShares = this.totalShares.bind(this); this.spotPrice = this.spotPrice.bind(this); this.estimateSwapExactAmountIn = this.estimateSwapExactAmountIn.bind(this); this.estimateSwapExactAmountOut = this.estimateSwapExactAmountOut.bind(this); } /* 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.req.get(endpoint, options); } /* NumPools */ async numPools(_params: QueryNumPoolsRequest = {}): Promise { const endpoint = `osmosis/gamm/v1beta1/num_pools`; return await this.req.get(endpoint); } /* TotalLiquidity */ async totalLiquidity(_params: QueryTotalLiquidityRequest = {}): Promise { const endpoint = `osmosis/gamm/v1beta1/total_liquidity`; return await this.req.get(endpoint); } /* Per Pool gRPC Endpoints */ async pool(params: QueryPoolRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}`; return await this.req.get(endpoint); } /* PoolType returns the type of the pool. Returns "Balancer" as a string literal when the pool is a balancer pool. Errors if the pool is failed to be type caseted. */ async poolType(params: QueryPoolTypeRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pool_type/${params.poolId}`; return await this.req.get(endpoint); } /* PoolParams */ async poolParams(params: QueryPoolParamsRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}/params`; return await this.req.get(endpoint); } /* TotalPoolLiquidity */ async totalPoolLiquidity(params: QueryTotalPoolLiquidityRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}/total_pool_liquidity`; return await this.req.get(endpoint); } /* TotalShares */ async totalShares(params: QueryTotalSharesRequest): Promise { const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}/total_shares`; return await this.req.get(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?.baseAssetDenom !== "undefined") { options.params.base_asset_denom = params.baseAssetDenom; } if (typeof params?.quoteAssetDenom !== "undefined") { options.params.quote_asset_denom = params.quoteAssetDenom; } const endpoint = `osmosis/gamm/v1beta1/pools/${params.poolId}/prices`; return await this.req.get(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.token_in = 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.req.get(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.token_out = params.tokenOut; } const endpoint = `osmosis/gamm/v1beta1/${params.poolId}/estimate/swap_exact_amount_out`; return await this.req.get(endpoint, options); } }