utils.js 1.6 KB

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