utils.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. const anchor = require("@project-serum/anchor");
  2. const serumCmn = require("@project-serum/common");
  3. async function createBalanceSandbox(provider, r, registrySigner) {
  4. const spt = new anchor.web3.Account();
  5. const vault = new anchor.web3.Account();
  6. const vaultStake = new anchor.web3.Account();
  7. const vaultPw = new anchor.web3.Account();
  8. const lamports = await provider.connection.getMinimumBalanceForRentExemption(
  9. 165
  10. );
  11. const createSptIx = await serumCmn.createTokenAccountInstrs(
  12. provider,
  13. spt.publicKey,
  14. r.poolMint,
  15. registrySigner,
  16. lamports
  17. );
  18. const createVaultIx = await serumCmn.createTokenAccountInstrs(
  19. provider,
  20. vault.publicKey,
  21. r.mint,
  22. registrySigner,
  23. lamports
  24. );
  25. const createVaultStakeIx = await serumCmn.createTokenAccountInstrs(
  26. provider,
  27. vaultStake.publicKey,
  28. r.mint,
  29. registrySigner,
  30. lamports
  31. );
  32. const createVaultPwIx = await serumCmn.createTokenAccountInstrs(
  33. provider,
  34. vaultPw.publicKey,
  35. r.mint,
  36. registrySigner,
  37. lamports
  38. );
  39. let tx0 = new anchor.web3.Transaction();
  40. tx0.add(
  41. ...createSptIx,
  42. ...createVaultIx,
  43. ...createVaultStakeIx,
  44. ...createVaultPwIx
  45. );
  46. let signers0 = [spt, vault, vaultStake, vaultPw];
  47. const tx = { tx: tx0, signers: signers0 };
  48. return [
  49. tx,
  50. {
  51. spt: spt.publicKey,
  52. vault: vault.publicKey,
  53. vaultStake: vaultStake.publicKey,
  54. vaultPw: vaultPw.publicKey,
  55. },
  56. ];
  57. }
  58. module.exports = {
  59. createBalanceSandbox,
  60. };