diff --git a/package.json b/package.json index 38f2bf01..29a21fc0 100644 --- a/package.json +++ b/package.json @@ -31,5 +31,6 @@ "anchor-bankrun": "^0.4.0", "chai": "^5.1.1", "solana-bankrun": "^0.3.0" - } + }, + "packageManager": "pnpm@9.14.2+sha512.6e2baf77d06b9362294152c851c4f278ede37ab1eba3a55fda317a4a17b209f4dbb973fb250a77abc463a341fcb1f17f17cfa24091c4eb319cda0d9b84278387" } diff --git a/tokens/token-swap/anchor/tests/deposit-liquidity.ts b/tokens/token-swap/anchor/tests/deposit-liquidity.ts index 166cdf05..29377e42 100644 --- a/tokens/token-swap/anchor/tests/deposit-liquidity.ts +++ b/tokens/token-swap/anchor/tests/deposit-liquidity.ts @@ -1,9 +1,9 @@ import * as anchor from '@coral-xyz/anchor'; import type { Program } from '@coral-xyz/anchor'; +import { BN } from 'bn.js'; import { expect } from 'chai'; import type { SwapExample } from '../target/types/swap_example'; import { type TestValues, createValues, mintingTokens } from './utils'; -import { BN } from 'bn.js'; describe('Deposit liquidity', () => { const provider = anchor.AnchorProvider.env(); @@ -66,7 +66,7 @@ describe('Deposit liquidity', () => { expect(depositTokenAccountA.value.amount).to.equal(values.defaultHolderAccountSupply.sub(values.depositAmountA).toString()); const depositTokenAccountB = await connection.getTokenAccountBalance(values.holderAccountB); expect(depositTokenAccountB.value.amount).to.equal(values.defaultHolderAccountSupply.sub(values.depositAmountA).toString()); - + await program.methods .depositLiquidity(values.depositAmountB, values.depositAmountB) .accounts({ @@ -87,20 +87,18 @@ describe('Deposit liquidity', () => { const depositTokenAccountLiquidity2 = await connection.getTokenAccountBalance(values.liquidityAccount); // No minimumLiquidity subtraction since it's not the first deposit - expect(depositTokenAccountLiquidity2.value.amount).to.equal(new BN(depositTokenAccountLiquidity.value.amount) - .add(values.depositAmountB).toString()); + expect(depositTokenAccountLiquidity2.value.amount).to.equal( + new BN(depositTokenAccountLiquidity.value.amount).add(values.depositAmountB).toString(), + ); const depositTokenAccountA2 = await connection.getTokenAccountBalance(values.holderAccountA); - expect(depositTokenAccountA2.value.amount).to.equal(new BN(depositTokenAccountA.value.amount) - .sub(values.depositAmountB).toString()); + expect(depositTokenAccountA2.value.amount).to.equal(new BN(depositTokenAccountA.value.amount).sub(values.depositAmountB).toString()); const depositTokenAccountB2 = await connection.getTokenAccountBalance(values.holderAccountB); - expect(depositTokenAccountB2.value.amount).to.equal(new BN(depositTokenAccountB.value.amount) - .sub(values.depositAmountB).toString()); + expect(depositTokenAccountB2.value.amount).to.equal(new BN(depositTokenAccountB.value.amount).sub(values.depositAmountB).toString()); }); - it('Deposit amounts a > b, then a < b', async () => { - var depositAmountA = new BN(9 * 10 ** 6) - var depositAmountB = new BN(4 * 10 ** 6) + const depositAmountA = new BN(9 * 10 ** 6); + const depositAmountB = new BN(4 * 10 ** 6); await program.methods .depositLiquidity(depositAmountA, depositAmountB) .accounts({ @@ -120,8 +118,7 @@ describe('Deposit liquidity', () => { .rpc({ skipPreflight: true }); const depositTokenAccountLiquidity = await connection.getTokenAccountBalance(values.liquidityAccount); - expect(depositTokenAccountLiquidity.value.amount).to.equal(new BN(6 * 10 ** 6) - .sub(values.minimumLiquidity).toString()); + expect(depositTokenAccountLiquidity.value.amount).to.equal(new BN(6 * 10 ** 6).sub(values.minimumLiquidity).toString()); const depositTokenAccountA = await connection.getTokenAccountBalance(values.holderAccountA); expect(depositTokenAccountA.value.amount).to.equal(values.defaultHolderAccountSupply.sub(depositAmountA).toString()); const depositTokenAccountB = await connection.getTokenAccountBalance(values.holderAccountB); @@ -130,10 +127,10 @@ describe('Deposit liquidity', () => { // Expected behavior is that depositAmountA gets increased to // (27 * 10 ** 6) * (9/4) = 60.75 * 10 ** 6 // to maintain the ratio established in the above deposit - depositAmountA = new BN(18 * 10 ** 6) - depositAmountB = new BN(27 * 10 ** 6) + const depositAmountA2 = new BN(18 * 10 ** 6); + const depositAmountB2 = new BN(27 * 10 ** 6); await program.methods - .depositLiquidity(depositAmountA, depositAmountB) + .depositLiquidity(depositAmountA2, depositAmountB2) .accounts({ pool: values.poolKey, poolAuthority: values.poolAuthority, @@ -151,20 +148,18 @@ describe('Deposit liquidity', () => { .rpc({ skipPreflight: true }); const depositTokenAccountLiquidity2 = await connection.getTokenAccountBalance(values.liquidityAccount); - expect(depositTokenAccountLiquidity2.value.amount).to.equal(new BN(40.5 * 10 ** 6) - .add(new BN(depositTokenAccountLiquidity.value.amount)) - .toString()); + expect(depositTokenAccountLiquidity2.value.amount).to.equal( + new BN(40.5 * 10 ** 6).add(new BN(depositTokenAccountLiquidity.value.amount)).toString(), + ); const depositTokenAccountA2 = await connection.getTokenAccountBalance(values.holderAccountA); - expect(depositTokenAccountA2.value.amount).to.equal(new BN (depositTokenAccountA.value.amount) - .sub(new BN(60.75 * 10 ** 6)).toString()); + expect(depositTokenAccountA2.value.amount).to.equal(new BN(depositTokenAccountA.value.amount).sub(new BN(60.75 * 10 ** 6)).toString()); const depositTokenAccountB2 = await connection.getTokenAccountBalance(values.holderAccountB); - expect(depositTokenAccountB2.value.amount).to.equal(new BN (depositTokenAccountB.value.amount) - .sub(depositAmountB).toString()); + expect(depositTokenAccountB2.value.amount).to.equal(new BN(depositTokenAccountB.value.amount).sub(depositAmountB2).toString()); }); it('Deposit amounts a < b, then a > b', async () => { - var depositAmountA = new BN(4 * 10 ** 6) - var depositAmountB = new BN(9 * 10 ** 6) + const depositAmountA = new BN(4 * 10 ** 6); + const depositAmountB = new BN(9 * 10 ** 6); await program.methods .depositLiquidity(depositAmountA, depositAmountB) .accounts({ @@ -184,20 +179,19 @@ describe('Deposit liquidity', () => { .rpc({ skipPreflight: true }); const depositTokenAccountLiquidity = await connection.getTokenAccountBalance(values.liquidityAccount); - expect(depositTokenAccountLiquidity.value.amount).to.equal(new BN(6 * 10 ** 6) - .sub(values.minimumLiquidity).toString()); + expect(depositTokenAccountLiquidity.value.amount).to.equal(new BN(6 * 10 ** 6).sub(values.minimumLiquidity).toString()); const depositTokenAccountA = await connection.getTokenAccountBalance(values.holderAccountA); expect(depositTokenAccountA.value.amount).to.equal(values.defaultHolderAccountSupply.sub(depositAmountA).toString()); const depositTokenAccountB = await connection.getTokenAccountBalance(values.holderAccountB); expect(depositTokenAccountB.value.amount).to.equal(values.defaultHolderAccountSupply.sub(depositAmountB).toString()); - + // Expected behavior is that depositAmountB gets increased to // (27 * 10 ** 6) * (9/4) = 60.75 * 10 ** 6 // to maintain the ratio established in the above deposit - depositAmountA = new BN(27 * 10 ** 6) - depositAmountB = new BN(18 * 10 ** 6) + const depositAmountA2 = new BN(27 * 10 ** 6); + const depositAmountB2 = new BN(18 * 10 ** 6); await program.methods - .depositLiquidity(depositAmountA, depositAmountB) + .depositLiquidity(depositAmountA2, depositAmountB2) .accounts({ pool: values.poolKey, poolAuthority: values.poolAuthority, @@ -215,14 +209,12 @@ describe('Deposit liquidity', () => { .rpc({ skipPreflight: true }); const depositTokenAccountLiquidity2 = await connection.getTokenAccountBalance(values.liquidityAccount); - expect(depositTokenAccountLiquidity2.value.amount).to.equal(new BN(40.5 * 10 ** 6) - .add(new BN(depositTokenAccountLiquidity.value.amount)) - .toString()); + expect(depositTokenAccountLiquidity2.value.amount).to.equal( + new BN(40.5 * 10 ** 6).add(new BN(depositTokenAccountLiquidity.value.amount)).toString(), + ); const depositTokenAccountA2 = await connection.getTokenAccountBalance(values.holderAccountA); - expect(depositTokenAccountA2.value.amount).to.equal(new BN (depositTokenAccountA.value.amount) - .sub(depositAmountA).toString()); + expect(depositTokenAccountA2.value.amount).to.equal(new BN(depositTokenAccountA.value.amount).sub(depositAmountA2).toString()); const depositTokenAccountB2 = await connection.getTokenAccountBalance(values.holderAccountB); - expect(depositTokenAccountB2.value.amount).to.equal(new BN (depositTokenAccountB.value.amount) - .sub(new BN(60.75 * 10 ** 6)).toString()); - }) + expect(depositTokenAccountB2.value.amount).to.equal(new BN(depositTokenAccountB.value.amount).sub(new BN(60.75 * 10 ** 6)).toString()); + }); }); diff --git a/tokens/token-swap/anchor/tests/swap.ts b/tokens/token-swap/anchor/tests/swap.ts index e1e3486a..e23dd972 100644 --- a/tokens/token-swap/anchor/tests/swap.ts +++ b/tokens/token-swap/anchor/tests/swap.ts @@ -39,7 +39,6 @@ describe('Swap', () => { poolAccountB: values.poolAccountB, }) .rpc(); - }); it('Swap from a to b, initial deposit a > b', async () => { @@ -80,19 +79,16 @@ describe('Swap', () => { const traderTokenAccountA = await connection.getTokenAccountBalance(values.holderAccountA); const traderTokenAccountB = await connection.getTokenAccountBalance(values.holderAccountB); - expect(traderTokenAccountA.value.amount).to.equal(values.defaultHolderAccountSupply - .sub(values.depositAmountA) - .sub(input).toString()); - expect(Number(traderTokenAccountB.value.amount)).to.be.greaterThan(values.defaultHolderAccountSupply - .sub(values.depositAmountB).toNumber()); - expect(Number(traderTokenAccountB.value.amount)).to.be.lessThan(values.defaultHolderAccountSupply - .sub(values.depositAmountB) - .add(input).toNumber()); + expect(traderTokenAccountA.value.amount).to.equal(values.defaultHolderAccountSupply.sub(values.depositAmountA).sub(input).toString()); + expect(Number(traderTokenAccountB.value.amount)).to.be.greaterThan(values.defaultHolderAccountSupply.sub(values.depositAmountB).toNumber()); + expect(Number(traderTokenAccountB.value.amount)).to.be.lessThan( + values.defaultHolderAccountSupply.sub(values.depositAmountB).add(input).toNumber(), + ); }); - + it('Swap from a to b, initial deposit a < b', async () => { - const depositAmountA = new BN(10 * 10 ** 6) - const depositAmountB = new BN(30 * 10 ** 6) + const depositAmountA = new BN(10 * 10 ** 6); + const depositAmountB = new BN(30 * 10 ** 6); await program.methods .depositLiquidity(depositAmountA, depositAmountB) .accounts({ @@ -130,11 +126,7 @@ describe('Swap', () => { const traderTokenAccountA = await connection.getTokenAccountBalance(values.holderAccountA); const traderTokenAccountB = await connection.getTokenAccountBalance(values.holderAccountB); - expect(traderTokenAccountA.value.amount).to.equal(values.defaultHolderAccountSupply - .sub(depositAmountA) - .sub(input).toString()); - expect(Number(traderTokenAccountB.value.amount)).to.be.greaterThan(values.defaultHolderAccountSupply - .sub(depositAmountB) - .add(input).toNumber()); + expect(traderTokenAccountA.value.amount).to.equal(values.defaultHolderAccountSupply.sub(depositAmountA).sub(input).toString()); + expect(Number(traderTokenAccountB.value.amount)).to.be.greaterThan(values.defaultHolderAccountSupply.sub(depositAmountB).add(input).toNumber()); }); }); diff --git a/tokens/token-swap/anchor/tests/utils.ts b/tokens/token-swap/anchor/tests/utils.ts index 917d48a1..a9f2b9a0 100644 --- a/tokens/token-swap/anchor/tests/utils.ts +++ b/tokens/token-swap/anchor/tests/utils.ts @@ -20,8 +20,8 @@ export const expectRevert = async (promise: Promise) => { } }; -const defaultMintedAmount = 100 -const defaultDecimals = 6 +const defaultMintedAmount = 100; +const defaultDecimals = 6; export const mintingTokens = async ({ connection, creator,