Skip to content

Commit

Permalink
Merge pull request #107 from mercurial-finance/fix-update-state
Browse files Browse the repository at this point in the history
FIx/pool update state
  • Loading branch information
00xSam authored Jan 3, 2024
2 parents b2cdc9e + f3b3dea commit 779401f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 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.12",
"version": "0.4.13",
"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
18 changes: 14 additions & 4 deletions ts-client/src/amm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export default class AmmImpl implements AmmImplementation {
public poolInfo: PoolInformation,
public vaultA: VaultImpl,
public vaultB: VaultImpl,
private accountsBufferMap: Map<string, AccountTypeInfo>,
private accountsInfo: AccountsInfo,
private swapCurve: SwapCurve,
private depegAccounts: Map<String, AccountInfo<Buffer>>,
Expand Down Expand Up @@ -456,7 +455,6 @@ export default class AmmImpl implements AmmImplementation {
poolInfo,
vaultA,
vaultB,
accountsBufferMap,
accountsInfo,
swapCurve,
depegAccounts,
Expand Down Expand Up @@ -590,7 +588,6 @@ export default class AmmImpl implements AmmImplementation {
poolInfo,
vaultA,
vaultB,
accountsBufferMap,
accountsInfo,
swapCurve,
depegAccounts,
Expand Down Expand Up @@ -661,7 +658,17 @@ export default class AmmImpl implements AmmImplementation {
this.vaultB.refreshVaultState(),
]);

const accountsInfoMap = deserializeAccountsBuffer(this.accountsBufferMap);
const accountsBufferMap = await getAccountsBuffer(this.program.provider.connection, [
{ pubkey: this.vaultA.vaultState.tokenVault, type: AccountType.VAULT_A_RESERVE },
{ pubkey: this.vaultB.vaultState.tokenVault, type: AccountType.VAULT_B_RESERVE },
{ pubkey: this.vaultA.vaultState.lpMint, type: AccountType.VAULT_A_LP },
{ pubkey: this.vaultB.vaultState.lpMint, type: AccountType.VAULT_B_LP },
{ pubkey: poolState.aVaultLp, type: AccountType.POOL_VAULT_A_LP },
{ pubkey: poolState.bVaultLp, type: AccountType.POOL_VAULT_B_LP },
{ pubkey: poolState.lpMint, type: AccountType.POOL_LP_MINT },
{ pubkey: SYSVAR_CLOCK_PUBKEY, type: AccountType.SYSVAR_CLOCK },
]);
const accountsInfoMap = deserializeAccountsBuffer(accountsBufferMap);

const currentTime = accountsInfoMap.get(SYSVAR_CLOCK_PUBKEY.toBase58()) as BN;
const poolVaultALp = accountsInfoMap.get(poolState.aVaultLp.toBase58()) as BN;
Expand Down Expand Up @@ -696,6 +703,9 @@ export default class AmmImpl implements AmmImplementation {
};
this.accountsInfo = accountsInfo;

const depegAccounts = await getDepegAccounts(this.program.provider.connection, [poolState]);
this.depegAccounts = depegAccounts;

if (this.isStablePool) {
// update swap curve
const { amp, depeg, tokenMultiplier } = poolState.curveType['stable'];
Expand Down

0 comments on commit 779401f

Please sign in to comment.