Skip to content

Commit

Permalink
Merge pull request #95 from mercurial-finance/isLst-flag
Browse files Browse the repository at this point in the history
Feat/lst getter
  • Loading branch information
00xSam authored Jul 24, 2023
2 parents 9579e74 + 9125231 commit 1084138
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 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.4",
"version": "0.4.6",
"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
4 changes: 3 additions & 1 deletion ts-client/src/amm/curve/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { PublicKey } from '@solana/web3.js';
import { BN } from '@project-serum/anchor';
import Decimal from 'decimal.js';
import { PoolFees } from '../types';
import { Depeg, PoolFees } from '../types';

export interface OutResult {
outAmount: BN;
priceImpact: Decimal;
}

export interface SwapCurve {
depeg?: Depeg;

computeOutAmount(
sourceAmount: BN,
swapSourceAmount: BN,
Expand Down
2 changes: 1 addition & 1 deletion ts-client/src/amm/curve/stable-swap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export class StableSwap implements SwapCurve {
constructor(
private amp: number,
private tokenMultiplier: TokenMultiplier,
private depeg: Depeg,
public depeg: Depeg,
private extraAccounts: Map<String, AccountInfo<Buffer>>,
private onChainTime: BN,
private stakePoolPubkey: PublicKey,
Expand Down
19 changes: 10 additions & 9 deletions ts-client/src/amm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ import {
} from '@solana/web3.js';
import { TokenInfo } from '@solana/spl-token-registry';
import { AccountLayout, ASSOCIATED_TOKEN_PROGRAM_ID, MintLayout, TOKEN_PROGRAM_ID, u64 } from '@solana/spl-token';
import VaultImpl, {
PROGRAM_ID as VAULT_PROGRAM_ID,
calculateWithdrawableAmount,
getVaultPdas,
} from '@mercurial-finance/vault-sdk';
import VaultImpl, { calculateWithdrawableAmount, getVaultPdas } from '@mercurial-finance/vault-sdk';
import invariant from 'invariant';
import {
AccountType,
Expand Down Expand Up @@ -51,7 +47,6 @@ import {
chunkedGetMultipleAccountInfos,
generateCurveType,
derivePoolAddress,
chunks,
chunkedFetchMultiplePoolAccount,
} from './utils';

Expand Down Expand Up @@ -620,16 +615,22 @@ export default class AmmImpl implements AmmImplementation {
return 'stable' in this.poolState.curveType;
}

get isLST(): boolean {
if (!this.isStablePool || !this.swapCurve.depeg?.depegType) return false;

return !Object.keys(this.swapCurve.depeg.depegType).includes('none');
}

get feeBps(): BN {
return this.poolState.fees.tradeFeeNumerator.mul(new BN(10000)).div(this.poolState.fees.tradeFeeDenominator);
}

get depegToken(): TokenInfo | null {
if (!this.isStablePool) return null;
const { tokenMultiplier } = this.poolState.curveType['stable'] as any;
const totalTokenBalance = this.poolInfo.tokenAAmount
.mul(tokenMultiplier.tokenAMultiplier)
.add(this.poolInfo.tokenBAmount.mul(tokenMultiplier.tokenBMultiplier));
const tokenABalance = this.poolInfo.tokenAAmount.mul(tokenMultiplier.tokenAMultiplier);
const tokenBBalance = this.poolInfo.tokenBAmount.mul(tokenMultiplier.tokenBMultiplier);
const totalTokenBalance = tokenABalance.add(tokenBBalance);

if (totalTokenBalance.isZero()) return null;

Expand Down
6 changes: 6 additions & 0 deletions ts-client/src/amm/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,12 @@ describe('Interact with Mainnet pool', () => {
expect(stablePool.getPoolTokenMint()).toBeDefined();
});

test('LST Flag', () => {
expect(cpPool.isLST).toBe(false);
expect(depegPool.isLST).toBe(true);
expect(stablePool.isLST).toBe(false);
});

test('Cpamm price impact', async () => {
const inTokenMint = new PublicKey(cpPool.tokenA.address);
const onePercentAmount = cpPool.poolInfo.tokenAAmount.div(new BN(100));
Expand Down

0 comments on commit 1084138

Please sign in to comment.