Skip to content

Commit

Permalink
Merge pull request #101 from mercurial-finance/fix-constant
Browse files Browse the repository at this point in the history
Fix/pool constant public key
  • Loading branch information
00xSam authored Oct 26, 2023
2 parents ffd589f + 746e6c6 commit 99d377a
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 89 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.9",
"version": "0.4.10",
"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
12 changes: 6 additions & 6 deletions ts-client/src/amm/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ export const DEVNET_COIN: Array<TokenInfo> = [
];

export const DEVNET_POOL = Object.freeze({
USDT_USDC: 'BAHscmu1NncGS7t4rc5gSBPv1UFEMkvLaon1Ahdd5rHi',
USDT_SOL: 'Bgf1Sy5kfeDgib4go4NgzHuZwek8wE8NZus56z6uizzi',
SOL_MSOL: '2rkn2yM4wJcHPV57T8fPWeBksrfSpiNZoEjRgjtxNDEQ',
USDT_USDC: new PublicKey('BAHscmu1NncGS7t4rc5gSBPv1UFEMkvLaon1Ahdd5rHi'),
USDT_SOL: new PublicKey('Bgf1Sy5kfeDgib4go4NgzHuZwek8wE8NZus56z6uizzi'),
SOL_MSOL: new PublicKey('2rkn2yM4wJcHPV57T8fPWeBksrfSpiNZoEjRgjtxNDEQ'),
});

export const MAINNET_POOL = Object.freeze({
USDT_USDC: '32D4zRxNc1EssbJieVHfPhZM3rH6CzfUPrWUuWxD9prG',
USDC_SOL: '5yuefgbJJpmFNK2iiYbLSpv1aZXq7F9AUKkZKErTYCvs',
SOL_STSOL: '7EJSgV2pthhDfb4UiER9vzTqe2eojei9GEQAQnkqJ96e',
USDT_USDC: new PublicKey('32D4zRxNc1EssbJieVHfPhZM3rH6CzfUPrWUuWxD9prG'),
USDC_SOL: new PublicKey('5yuefgbJJpmFNK2iiYbLSpv1aZXq7F9AUKkZKErTYCvs'),
SOL_STSOL: new PublicKey('7EJSgV2pthhDfb4UiER9vzTqe2eojei9GEQAQnkqJ96e'),
});

// Extra accounts for depeg pools. Might add more addresses in the future when more different types of pools are being added
Expand Down
6 changes: 3 additions & 3 deletions ts-client/src/amm/tests/error.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ describe('Interact with Mainnet pool', () => {
const MSOL = DEVNET_COIN.find((token) => token.address === 'mSoLzYCxHdYgdzU16g5QSh3i5K3z3KZK7ytfqcJm7So');

const pools = [
{ pool: new PublicKey(DEVNET_POOL.USDT_SOL), tokenInfoA: USDT!, tokenInfoB: SOL! },
{ pool: new PublicKey(DEVNET_POOL.SOL_MSOL), tokenInfoA: SOL!, tokenInfoB: MSOL! },
{ pool: new PublicKey(DEVNET_POOL.USDT_USDC), tokenInfoA: USDT!, tokenInfoB: USDC! },
{ pool: DEVNET_POOL.USDT_SOL, tokenInfoA: USDT!, tokenInfoB: SOL! },
{ pool: DEVNET_POOL.SOL_MSOL, tokenInfoA: SOL!, tokenInfoB: MSOL! },
{ pool: DEVNET_POOL.USDT_USDC, tokenInfoA: USDT!, tokenInfoB: USDC! },
];

const [pool1, pool2, pool3] = await AmmImpl.createMultiple(DEVNET.connection, pools, {
Expand Down
160 changes: 81 additions & 79 deletions ts-client/src/amm/tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,44 +91,45 @@ describe('Interact with Devnet pool', () => {
}
});

test('Swap SOL → USDT with referrer fee', async () => {
const referrerSolAta = await getOrCreateATA(provider.connection, NATIVE_MINT, referrer.publicKey, mockWallet.payer);
const inAmountLamport = new BN(0.1 * 10 ** cpPool.tokenB.decimals);

const { swapOutAmount, minSwapOutAmount } = cpPool.getSwapQuote(
new PublicKey(cpPool.tokenB.address),
inAmountLamport,
DEFAULT_SLIPPAGE,
);
expect(swapOutAmount.toNumber()).toBeGreaterThan(0);

const swapTx = await cpPool.swap(
mockWallet.publicKey,
new PublicKey(cpPool.tokenB.address),
inAmountLamport,
minSwapOutAmount,
referrerSolAta,
);

try {
const beforeReferrerTokenBalance = await provider.connection
.getTokenAccountBalance(referrerSolAta)
.then((r) => r.value.uiAmount);

const swapResult = await provider.sendAndConfirm(swapTx);
console.log('Swap Result of SOL → USDT', swapResult);
expect(typeof swapResult).toBe('string');

const afterReferrerTokenBalance = await provider.connection
.getTokenAccountBalance(referrerSolAta)
.then((r) => r.value.uiAmount);

expect(afterReferrerTokenBalance!).toBeGreaterThan(beforeReferrerTokenBalance!);
} catch (error: any) {
console.trace(error);
throw new Error(error.message);
}
});
// zero protocol fee campaign
// test('Swap SOL → USDT with referrer fee', async () => {
// const referrerSolAta = await getOrCreateATA(provider.connection, NATIVE_MINT, referrer.publicKey, mockWallet.payer);
// const inAmountLamport = new BN(0.1 * 10 ** cpPool.tokenB.decimals);

// const { swapOutAmount, minSwapOutAmount } = cpPool.getSwapQuote(
// new PublicKey(cpPool.tokenB.address),
// inAmountLamport,
// DEFAULT_SLIPPAGE,
// );
// expect(swapOutAmount.toNumber()).toBeGreaterThan(0);

// const swapTx = await cpPool.swap(
// mockWallet.publicKey,
// new PublicKey(cpPool.tokenB.address),
// inAmountLamport,
// minSwapOutAmount,
// referrerSolAta,
// );

// try {
// const beforeReferrerTokenBalance = await provider.connection
// .getTokenAccountBalance(referrerSolAta)
// .then((r) => r.value.uiAmount);

// const swapResult = await provider.sendAndConfirm(swapTx);
// console.log('Swap Result of SOL → USDT', swapResult);
// expect(typeof swapResult).toBe('string');

// const afterReferrerTokenBalance = await provider.connection
// .getTokenAccountBalance(referrerSolAta)
// .then((r) => r.value.uiAmount);

// expect(afterReferrerTokenBalance!).toBeGreaterThan(beforeReferrerTokenBalance!);
// } catch (error: any) {
// console.trace(error);
// throw new Error(error.message);
// }
// });

test('Swap USDT → SOL', async () => {
const inAmountLamport = new BN(0.1 * 10 ** cpPool.tokenA.decimals);
Expand Down Expand Up @@ -236,44 +237,45 @@ describe('Interact with Devnet pool', () => {
}
});

test('Swap SOL → mSOL with referrer fee', async () => {
const referrerSolAta = await getOrCreateATA(provider.connection, NATIVE_MINT, referrer.publicKey, mockWallet.payer);
const inAmountLamport = new BN(0.01 * 10 ** depegPool.tokenA.decimals);

const { swapOutAmount, minSwapOutAmount } = depegPool.getSwapQuote(
new PublicKey(depegPool.tokenA.address),
inAmountLamport,
DEFAULT_SLIPPAGE,
);
expect(swapOutAmount.toNumber()).toBeGreaterThan(0);

const swapTx = await depegPool.swap(
mockWallet.publicKey,
new PublicKey(depegPool.tokenA.address),
inAmountLamport,
minSwapOutAmount,
referrerSolAta,
);

try {
const beforeReferrerTokenBalance = await provider.connection
.getTokenAccountBalance(referrerSolAta)
.then((r) => r.value.uiAmount);

const swapResult = await provider.sendAndConfirm(swapTx);
console.log('Swap Result of SOL → mSOL', swapResult);
expect(typeof swapResult).toBe('string');

const afterReferrerTokenBalance = await provider.connection
.getTokenAccountBalance(referrerSolAta)
.then((r) => r.value.uiAmount);

expect(afterReferrerTokenBalance!).toBeGreaterThan(beforeReferrerTokenBalance!);
} catch (error: any) {
console.trace(error);
throw new Error(error.message);
}
});
// zero protocol fee campaign
// test('Swap SOL → mSOL with referrer fee', async () => {
// const referrerSolAta = await getOrCreateATA(provider.connection, NATIVE_MINT, referrer.publicKey, mockWallet.payer);
// const inAmountLamport = new BN(0.01 * 10 ** depegPool.tokenA.decimals);

// const { swapOutAmount, minSwapOutAmount } = depegPool.getSwapQuote(
// new PublicKey(depegPool.tokenA.address),
// inAmountLamport,
// DEFAULT_SLIPPAGE,
// );
// expect(swapOutAmount.toNumber()).toBeGreaterThan(0);

// const swapTx = await depegPool.swap(
// mockWallet.publicKey,
// new PublicKey(depegPool.tokenA.address),
// inAmountLamport,
// minSwapOutAmount,
// referrerSolAta,
// );

// try {
// const beforeReferrerTokenBalance = await provider.connection
// .getTokenAccountBalance(referrerSolAta)
// .then((r) => r.value.uiAmount);

// const swapResult = await provider.sendAndConfirm(swapTx);
// console.log('Swap Result of SOL → mSOL', swapResult);
// expect(typeof swapResult).toBe('string');

// const afterReferrerTokenBalance = await provider.connection
// .getTokenAccountBalance(referrerSolAta)
// .then((r) => r.value.uiAmount);

// expect(afterReferrerTokenBalance!).toBeGreaterThan(beforeReferrerTokenBalance!);
// } catch (error: any) {
// console.trace(error);
// throw new Error(error.message);
// }
// });

test('Swap mSOL → SOL', async () => {
const inAmountLamport = new BN(0.01 * 10 ** depegPool.tokenB.decimals);
Expand Down Expand Up @@ -731,9 +733,9 @@ describe('Interact with Mainnet pool', () => {
const STSOL = tokenMap.find((token) => token.address === '7dHbWXmci3dT8UFYWYZweBLXgycu7Y3iL6trKn1Y7ARj');

const pools = [
{ pool: new PublicKey(MAINNET_POOL.USDC_SOL), tokenInfoA: USDC!, tokenInfoB: SOL! },
{ pool: new PublicKey(MAINNET_POOL.SOL_STSOL), tokenInfoA: SOL!, tokenInfoB: STSOL! },
{ pool: new PublicKey(MAINNET_POOL.USDT_USDC), tokenInfoA: USDC!, tokenInfoB: USDT! },
{ pool: MAINNET_POOL.USDC_SOL, tokenInfoA: USDC!, tokenInfoB: SOL! },
{ pool: MAINNET_POOL.SOL_STSOL, tokenInfoA: SOL!, tokenInfoB: STSOL! },
{ pool: MAINNET_POOL.USDT_USDC, tokenInfoA: USDC!, tokenInfoB: USDT! },
];
const [pool1, pool2, pool3] = await AmmImpl.createMultiple(MAINNET.connection, pools, {
cluster: MAINNET.cluster as Cluster,
Expand Down

0 comments on commit 99d377a

Please sign in to comment.