import { Rpc } from "../../../helpers"; import * as _m0 from "protobufjs/minimal"; import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate"; import { QueryPoolsRequest, QueryPoolsResponse, QueryNumPoolsRequest, QueryNumPoolsResponse, QueryTotalLiquidityRequest, QueryTotalLiquidityResponse, QueryPoolRequest, QueryPoolResponse, QueryPoolTypeRequest, QueryPoolTypeResponse, QueryPoolParamsRequest, QueryPoolParamsResponse, QueryTotalPoolLiquidityRequest, QueryTotalPoolLiquidityResponse, QueryTotalSharesRequest, QueryTotalSharesResponse, QuerySpotPriceRequest, QuerySpotPriceResponse, QuerySwapExactAmountInRequest, QuerySwapExactAmountInResponse, QuerySwapExactAmountOutRequest, QuerySwapExactAmountOutResponse } from "./query"; export interface Query { pools(request?: QueryPoolsRequest): Promise; numPools(request?: QueryNumPoolsRequest): Promise; totalLiquidity(request?: QueryTotalLiquidityRequest): Promise; /** Per Pool gRPC Endpoints */ pool(request: QueryPoolRequest): Promise; /** * 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. */ poolType(request: QueryPoolTypeRequest): Promise; poolParams(request: QueryPoolParamsRequest): Promise; totalPoolLiquidity(request: QueryTotalPoolLiquidityRequest): Promise; totalShares(request: QueryTotalSharesRequest): Promise; /** * SpotPrice defines a gRPC query handler that returns the spot price given * a base denomination and a quote denomination. */ spotPrice(request: QuerySpotPriceRequest): Promise; /** Estimate the swap. */ estimateSwapExactAmountIn(request: QuerySwapExactAmountInRequest): Promise; estimateSwapExactAmountOut(request: QuerySwapExactAmountOutRequest): Promise; } export class QueryClientImpl implements Query { private readonly rpc: Rpc; constructor(rpc: Rpc) { this.rpc = rpc; 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(request: QueryPoolsRequest = { pagination: undefined }): Promise { const data = QueryPoolsRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "Pools", data); return promise.then(data => QueryPoolsResponse.decode(new _m0.Reader(data))); } numPools(request: QueryNumPoolsRequest = {}): Promise { const data = QueryNumPoolsRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "NumPools", data); return promise.then(data => QueryNumPoolsResponse.decode(new _m0.Reader(data))); } totalLiquidity(request: QueryTotalLiquidityRequest = {}): Promise { const data = QueryTotalLiquidityRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "TotalLiquidity", data); return promise.then(data => QueryTotalLiquidityResponse.decode(new _m0.Reader(data))); } pool(request: QueryPoolRequest): Promise { const data = QueryPoolRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "Pool", data); return promise.then(data => QueryPoolResponse.decode(new _m0.Reader(data))); } poolType(request: QueryPoolTypeRequest): Promise { const data = QueryPoolTypeRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "PoolType", data); return promise.then(data => QueryPoolTypeResponse.decode(new _m0.Reader(data))); } poolParams(request: QueryPoolParamsRequest): Promise { const data = QueryPoolParamsRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "PoolParams", data); return promise.then(data => QueryPoolParamsResponse.decode(new _m0.Reader(data))); } totalPoolLiquidity(request: QueryTotalPoolLiquidityRequest): Promise { const data = QueryTotalPoolLiquidityRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "TotalPoolLiquidity", data); return promise.then(data => QueryTotalPoolLiquidityResponse.decode(new _m0.Reader(data))); } totalShares(request: QueryTotalSharesRequest): Promise { const data = QueryTotalSharesRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "TotalShares", data); return promise.then(data => QueryTotalSharesResponse.decode(new _m0.Reader(data))); } spotPrice(request: QuerySpotPriceRequest): Promise { const data = QuerySpotPriceRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "SpotPrice", data); return promise.then(data => QuerySpotPriceResponse.decode(new _m0.Reader(data))); } estimateSwapExactAmountIn(request: QuerySwapExactAmountInRequest): Promise { const data = QuerySwapExactAmountInRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "EstimateSwapExactAmountIn", data); return promise.then(data => QuerySwapExactAmountInResponse.decode(new _m0.Reader(data))); } estimateSwapExactAmountOut(request: QuerySwapExactAmountOutRequest): Promise { const data = QuerySwapExactAmountOutRequest.encode(request).finish(); const promise = this.rpc.request("osmosis.gamm.v1beta1.Query", "EstimateSwapExactAmountOut", data); return promise.then(data => QuerySwapExactAmountOutResponse.decode(new _m0.Reader(data))); } } export const createRpcQueryExtension = (base: QueryClient) => { const rpc = createProtobufRpcClient(base); const queryService = new QueryClientImpl(rpc); return { pools(request?: QueryPoolsRequest): Promise { return queryService.pools(request); }, numPools(request?: QueryNumPoolsRequest): Promise { return queryService.numPools(request); }, totalLiquidity(request?: QueryTotalLiquidityRequest): Promise { return queryService.totalLiquidity(request); }, pool(request: QueryPoolRequest): Promise { return queryService.pool(request); }, poolType(request: QueryPoolTypeRequest): Promise { return queryService.poolType(request); }, poolParams(request: QueryPoolParamsRequest): Promise { return queryService.poolParams(request); }, totalPoolLiquidity(request: QueryTotalPoolLiquidityRequest): Promise { return queryService.totalPoolLiquidity(request); }, totalShares(request: QueryTotalSharesRequest): Promise { return queryService.totalShares(request); }, spotPrice(request: QuerySpotPriceRequest): Promise { return queryService.spotPrice(request); }, estimateSwapExactAmountIn(request: QuerySwapExactAmountInRequest): Promise { return queryService.estimateSwapExactAmountIn(request); }, estimateSwapExactAmountOut(request: QuerySwapExactAmountOutRequest): Promise { return queryService.estimateSwapExactAmountOut(request); } }; };