deposit-liquidity.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import * as anchor from '@coral-xyz/anchor';
  2. import type { Program } from '@coral-xyz/anchor';
  3. import { expect } from 'chai';
  4. import type { SwapExample } from '../target/types/swap_example';
  5. import { type TestValues, createValues, mintingTokens } from './utils';
  6. describe('Deposit liquidity', () => {
  7. const provider = anchor.AnchorProvider.env();
  8. const connection = provider.connection;
  9. anchor.setProvider(provider);
  10. const program = anchor.workspace.SwapExample as Program<SwapExample>;
  11. let values: TestValues;
  12. beforeEach(async () => {
  13. values = createValues();
  14. await program.methods.createAmm(values.id, values.fee).accounts({ amm: values.ammKey, admin: values.admin.publicKey }).rpc();
  15. await mintingTokens({
  16. connection,
  17. creator: values.admin,
  18. mintAKeypair: values.mintAKeypair,
  19. mintBKeypair: values.mintBKeypair,
  20. });
  21. await program.methods
  22. .createPool()
  23. .accounts({
  24. amm: values.ammKey,
  25. pool: values.poolKey,
  26. poolAuthority: values.poolAuthority,
  27. mintLiquidity: values.mintLiquidity,
  28. mintA: values.mintAKeypair.publicKey,
  29. mintB: values.mintBKeypair.publicKey,
  30. poolAccountA: values.poolAccountA,
  31. poolAccountB: values.poolAccountB,
  32. })
  33. .rpc();
  34. });
  35. it('Deposit equal amounts', async () => {
  36. await program.methods
  37. .depositLiquidity(values.depositAmountA, values.depositAmountA)
  38. .accounts({
  39. pool: values.poolKey,
  40. poolAuthority: values.poolAuthority,
  41. depositor: values.admin.publicKey,
  42. mintLiquidity: values.mintLiquidity,
  43. mintA: values.mintAKeypair.publicKey,
  44. mintB: values.mintBKeypair.publicKey,
  45. poolAccountA: values.poolAccountA,
  46. poolAccountB: values.poolAccountB,
  47. depositorAccountLiquidity: values.liquidityAccount,
  48. depositorAccountA: values.holderAccountA,
  49. depositorAccountB: values.holderAccountB,
  50. })
  51. .signers([values.admin])
  52. .rpc({ skipPreflight: true });
  53. const depositTokenAccountLiquditiy = await connection.getTokenAccountBalance(values.liquidityAccount);
  54. expect(depositTokenAccountLiquditiy.value.amount).to.equal(values.depositAmountA.sub(values.minimumLiquidity).toString());
  55. const depositTokenAccountA = await connection.getTokenAccountBalance(values.holderAccountA);
  56. expect(depositTokenAccountA.value.amount).to.equal(values.defaultSupply.sub(values.depositAmountA).toString());
  57. const depositTokenAccountB = await connection.getTokenAccountBalance(values.holderAccountB);
  58. expect(depositTokenAccountB.value.amount).to.equal(values.defaultSupply.sub(values.depositAmountA).toString());
  59. });
  60. });