Skip to content

Commit

Permalink
feat: add cw20 option to simulateAstroportSinglePoolSwap
Browse files Browse the repository at this point in the history
  • Loading branch information
AaronCQL committed Dec 20, 2023
1 parent f74c301 commit a2817ca
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## `v0.0.45`

### Improvements

- Included `isCW20` option for `simulateAstroportSinglePoolSwap` function to handle swapping from CW20 assets

## `v0.0.44`

### Fixes
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.44",
"version": "0.0.45",
"private": false,
"packageManager": "[email protected]",
"sideEffects": false,
Expand Down
17 changes: 11 additions & 6 deletions src/client/apis/simulateAstroportSinglePoolSwap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export type SimulateAstroportSinglePoolSwapParams = {
poolId: string;
fromAsset: string;
fromAmount: bigint;
isCW20?: boolean | undefined;
};

type Response = {
Expand All @@ -15,22 +16,26 @@ type Response = {
/**
* Simulates the amount of assets that would be received by swapping
* `fromAmount` amount of `fromAsset` assets via the `poolId` pool.
* If `fromAsset` is a CW20 token, `isCW20` must be set to `true`.
*/
export async function simulateAstroportSinglePoolSwap(
endpoint: string,
{ poolId, fromAsset, fromAmount }: SimulateAstroportSinglePoolSwapParams
{
poolId,
fromAsset,
fromAmount,
isCW20,
}: SimulateAstroportSinglePoolSwapParams
): Promise<bigint> {
try {
const { return_amount } = await queryContract<Response>(endpoint, {
address: poolId,
query: {
simulation: {
offer_asset: {
info: {
native_token: {
denom: fromAsset,
},
},
info: isCW20
? { token: { contract_addr: fromAsset } }
: { native_token: { denom: fromAsset } },
amount: fromAmount.toString(),
},
},
Expand Down

0 comments on commit a2817ca

Please sign in to comment.