diff --git a/CHANGELOG.md b/CHANGELOG.md index b33c64e5..9471b815 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## `v0.0.56` + +### Features + +- Added Dymension's GAMM protobufs + +### Miscellaneous + +- Pinned Cosmos SDK protobuf to `v0.47.9` + ## `v0.0.55` ### Features diff --git a/package.json b/package.json index 1421ee76..613efa83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cosmes", - "version": "0.0.55", + "version": "0.0.56", "private": false, "packageManager": "pnpm@8.3.0", "sideEffects": false, diff --git a/src/client/apis/simulateDymensionSinglePoolSwap.ts b/src/client/apis/simulateDymensionSinglePoolSwap.ts new file mode 100644 index 00000000..59bdf5fd --- /dev/null +++ b/src/client/apis/simulateDymensionSinglePoolSwap.ts @@ -0,0 +1,36 @@ +import { DymensionGammV1beta1QueryEstimateSwapExactAmountInService as SwapService } from "cosmes/protobufs"; + +import { RpcClient } from "../clients/RpcClient"; + +export type SimulateDymensionSinglePoolSwapParams = { + poolId: bigint; + fromAsset: string; + fromAmount: bigint; + toAsset: string; +}; + +/** + * Simulates the amount of `toAsset` assets that would be received by swapping + * `fromAmount` amount of `fromAsset` assets via the `poolId` pool. + */ +export async function simulateDymensionSinglePoolSwap( + endpoint: string, + { + poolId, + fromAsset, + fromAmount, + toAsset, + }: SimulateDymensionSinglePoolSwapParams +): Promise { + const { tokenOutAmount } = await RpcClient.query(endpoint, SwapService, { + poolId, + tokenIn: fromAmount.toString() + fromAsset, + routes: [ + { + poolId, + tokenOutDenom: toAsset, + }, + ], + }); + return BigInt(tokenOutAmount); +} diff --git a/src/client/apis/simulateOsmosisSinglePoolSwap.ts b/src/client/apis/simulateOsmosisSinglePoolSwap.ts index bca30623..b346d8cd 100644 --- a/src/client/apis/simulateOsmosisSinglePoolSwap.ts +++ b/src/client/apis/simulateOsmosisSinglePoolSwap.ts @@ -1,4 +1,4 @@ -import { OsmosisGammV1beta1QueryEstimateSwapExactAmountInService as SwapService } from "cosmes/protobufs"; +import { OsmosisPoolmanagerV1beta1QueryEstimateSwapExactAmountInService as SwapService } from "cosmes/protobufs"; import { RpcClient } from "../clients/RpcClient"; @@ -22,19 +22,15 @@ export async function simulateOsmosisSinglePoolSwap( toAsset, }: SimulateOsmosisSinglePoolSwapParams ): Promise { - const { tokenOutAmount } = await RpcClient.query( - endpoint, - SwapService, // TODO: migrate to poolmanager once it's ready - { - poolId, - tokenIn: fromAmount.toString() + fromAsset, - routes: [ - { - poolId, - tokenOutDenom: toAsset, - }, - ], - } - ); + const { tokenOutAmount } = await RpcClient.query(endpoint, SwapService, { + poolId, + tokenIn: fromAmount.toString() + fromAsset, + routes: [ + { + poolId, + tokenOutDenom: toAsset, + }, + ], + }); return BigInt(tokenOutAmount); } diff --git a/src/client/index.ts b/src/client/index.ts index 860946b5..c2d3b403 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -15,6 +15,10 @@ export { simulateAstroportSinglePoolSwap, type SimulateAstroportSinglePoolSwapParams, } from "./apis/simulateAstroportSinglePoolSwap"; +export { + simulateDymensionSinglePoolSwap, + type SimulateDymensionSinglePoolSwapParams, +} from "./apis/simulateDymensionSinglePoolSwap"; export { simulateKujiraSinglePoolSwap, type SimulateKujiraSinglePoolSwapParams,