Skip to content

Commit

Permalink
feat: add support for dymension gamm module
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCQL committed Feb 23, 2024
1 parent c6c5d0d commit 3839477
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 16 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cosmes",
"version": "0.0.55",
"version": "0.0.56",
"private": false,
"packageManager": "[email protected]",
"sideEffects": false,
Expand Down
36 changes: 36 additions & 0 deletions src/client/apis/simulateDymensionSinglePoolSwap.ts
Original file line number Diff line number Diff line change
@@ -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<bigint> {
const { tokenOutAmount } = await RpcClient.query(endpoint, SwapService, {
poolId,
tokenIn: fromAmount.toString() + fromAsset,
routes: [
{
poolId,
tokenOutDenom: toAsset,
},
],
});
return BigInt(tokenOutAmount);
}
26 changes: 11 additions & 15 deletions src/client/apis/simulateOsmosisSinglePoolSwap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OsmosisGammV1beta1QueryEstimateSwapExactAmountInService as SwapService } from "cosmes/protobufs";
import { OsmosisPoolmanagerV1beta1QueryEstimateSwapExactAmountInService as SwapService } from "cosmes/protobufs";

import { RpcClient } from "../clients/RpcClient";

Expand All @@ -22,19 +22,15 @@ export async function simulateOsmosisSinglePoolSwap(
toAsset,
}: SimulateOsmosisSinglePoolSwapParams
): Promise<bigint> {
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);
}
4 changes: 4 additions & 0 deletions src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export {
simulateAstroportSinglePoolSwap,
type SimulateAstroportSinglePoolSwapParams,
} from "./apis/simulateAstroportSinglePoolSwap";
export {
simulateDymensionSinglePoolSwap,
type SimulateDymensionSinglePoolSwapParams,
} from "./apis/simulateDymensionSinglePoolSwap";
export {
simulateKujiraSinglePoolSwap,
type SimulateKujiraSinglePoolSwapParams,
Expand Down

0 comments on commit 3839477

Please sign in to comment.