From 6655259f3dabab65c720e672045c968d48a580e1 Mon Sep 17 00:00:00 2001 From: McSam Date: Thu, 4 Jan 2024 15:48:46 +0800 Subject: [PATCH] fix: update state not updating correctly --- ts-client/package.json | 2 +- ts-client/src/amm/index.ts | 17 ++++++++--------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ts-client/package.json b/ts-client/package.json index a4a0467e..054914c8 100644 --- a/ts-client/package.json +++ b/ts-client/package.json @@ -1,6 +1,6 @@ { "name": "@mercurial-finance/dynamic-amm-sdk", - "version": "0.4.16", + "version": "0.4.17", "description": "Mercurial Vaults SDK is a typescript library that allows you to interact with Mercurial v2's AMM.", "main": "dist/cjs/index.js", "module": "dist/esm/index.js", diff --git a/ts-client/src/amm/index.ts b/ts-client/src/amm/index.ts index 0bc7d6bf..af8eb2c6 100644 --- a/ts-client/src/amm/index.ts +++ b/ts-client/src/amm/index.ts @@ -657,6 +657,7 @@ export default class AmmImpl implements AmmImplementation { this.vaultA.refreshVaultState(), this.vaultB.refreshVaultState(), ]); + this.poolState = poolState; const accountsBufferMap = await getAccountsBuffer(this.program.provider.connection, [ { pubkey: this.vaultA.vaultState.tokenVault, type: AccountType.VAULT_A_RESERVE }, @@ -691,7 +692,7 @@ export default class AmmImpl implements AmmImplementation { 'Account Info not found', ); - const accountsInfo = { + this.accountsInfo = { currentTime, poolVaultALp, poolVaultBLp, @@ -701,14 +702,11 @@ export default class AmmImpl implements AmmImplementation { vaultBReserve, poolLpSupply, }; - this.accountsInfo = accountsInfo; - const depegAccounts = await getDepegAccounts(this.program.provider.connection, [poolState]); - this.depegAccounts = depegAccounts; + this.depegAccounts = await getDepegAccounts(this.program.provider.connection, [poolState]); - if (this.isStablePool) { - // update swap curve - const { amp, depeg, tokenMultiplier } = poolState.curveType['stable']; + if ('stable' in poolState.curveType) { + const { amp, depeg, tokenMultiplier } = poolState.curveType['stable'] as any; this.swapCurve = new StableSwap( amp.toNumber(), tokenMultiplier, @@ -717,9 +715,11 @@ export default class AmmImpl implements AmmImplementation { currentTime, poolState.stake, ); + } else { + this.swapCurve = new ConstantProductSwap(); } - const poolInfo = calculatePoolInfo( + this.poolInfo = calculatePoolInfo( currentTime, poolVaultALp, poolVaultBLp, @@ -730,7 +730,6 @@ export default class AmmImpl implements AmmImplementation { this.vaultA.vaultState, this.vaultB.vaultState, ); - this.poolState = { ...poolState, ...poolInfo }; } /**