Skip to content

Commit

Permalink
Merge pull request #111 from mercurial-finance/debug-single-deposit
Browse files Browse the repository at this point in the history
Fix/update state not updating correctly
  • Loading branch information
00xSam authored Jan 4, 2024
2 parents 04e9faf + 6655259 commit 192cd10
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ts-client/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
17 changes: 8 additions & 9 deletions ts-client/src/amm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down Expand Up @@ -691,7 +692,7 @@ export default class AmmImpl implements AmmImplementation {
'Account Info not found',
);

const accountsInfo = {
this.accountsInfo = {
currentTime,
poolVaultALp,
poolVaultBLp,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -730,7 +730,6 @@ export default class AmmImpl implements AmmImplementation {
this.vaultA.vaultState,
this.vaultB.vaultState,
);
this.poolState = { ...poolState, ...poolInfo };
}

/**
Expand Down

0 comments on commit 192cd10

Please sign in to comment.