hedge-web3 0.1.27 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/declarations/Constants.d.ts +1 -1
  2. package/declarations/idl/vault.d.ts +277 -126
  3. package/declarations/index.d.ts +3 -0
  4. package/declarations/instructions/claimLiquidationPoolPosition.d.ts +3 -2
  5. package/declarations/instructions/claimStakingPoolPosition.d.ts +3 -2
  6. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +3 -2
  7. package/declarations/instructions/createStakingPool.d.ts +3 -2
  8. package/declarations/instructions/createVault.d.ts +6 -5
  9. package/declarations/instructions/depositLiquidationPool.d.ts +3 -2
  10. package/declarations/instructions/depositStakingPool.d.ts +3 -2
  11. package/declarations/instructions/depositVault.d.ts +3 -2
  12. package/declarations/instructions/initHedgeFoundation.d.ts +3 -2
  13. package/declarations/instructions/liquidateVault.d.ts +3 -2
  14. package/declarations/instructions/loanVault.d.ts +3 -2
  15. package/declarations/instructions/redeemVault.d.ts +3 -2
  16. package/declarations/instructions/refreshOraclePrice.d.ts +3 -2
  17. package/declarations/instructions/repayVault.d.ts +3 -2
  18. package/declarations/instructions/setHalted.d.ts +3 -2
  19. package/declarations/instructions/setVaultTypeStatus.d.ts +5 -0
  20. package/declarations/instructions/withdrawStakingPool.d.ts +3 -2
  21. package/declarations/instructions/withdrawVault.d.ts +3 -2
  22. package/declarations/state/VaultAccount.d.ts +8 -0
  23. package/declarations/utils/getLinkedListAccounts.d.ts +5 -0
  24. package/lib/Constants.js +1 -1
  25. package/lib/idl/vault.js +277 -126
  26. package/lib/index.js +3 -0
  27. package/lib/instructions/claimLiquidationPoolPosition.js +19 -22
  28. package/lib/instructions/claimStakingPoolPosition.js +19 -19
  29. package/lib/instructions/closeLiquidationPoolPosition.js +22 -22
  30. package/lib/instructions/createStakingPool.js +18 -19
  31. package/lib/instructions/createVault.js +28 -31
  32. package/lib/instructions/depositLiquidationPool.js +17 -18
  33. package/lib/instructions/depositStakingPool.js +16 -18
  34. package/lib/instructions/depositVault.js +31 -26
  35. package/lib/instructions/initHedgeFoundation.js +17 -19
  36. package/lib/instructions/initHedgeFoundationTokens.js +15 -15
  37. package/lib/instructions/liquidateVault.js +36 -32
  38. package/lib/instructions/loanVault.js +27 -22
  39. package/lib/instructions/redeemVault.js +28 -23
  40. package/lib/instructions/refreshOraclePrice.js +17 -17
  41. package/lib/instructions/repayVault.js +27 -22
  42. package/lib/instructions/setHalted.js +8 -9
  43. package/lib/instructions/setVaultTypeStatus.js +37 -0
  44. package/lib/instructions/withdrawStakingPool.js +22 -24
  45. package/lib/instructions/withdrawVault.js +30 -25
  46. package/lib/state/LiquidationPoolEra.js +3 -1
  47. package/lib/state/LiquidationPosition.js +0 -7
  48. package/lib/state/StakingPool.js +3 -4
  49. package/lib/state/VaultAccount.js +51 -1
  50. package/lib/utils/getLinkedListAccounts.js +139 -0
  51. package/package.json +4 -2
  52. package/src/Constants.ts +1 -1
  53. package/src/idl/vault.ts +554 -252
  54. package/src/index.ts +4 -0
  55. package/src/instructions/claimLiquidationPoolPosition.ts +39 -29
  56. package/src/instructions/claimStakingPoolPosition.ts +45 -25
  57. package/src/instructions/closeLiquidationPoolPosition.ts +62 -32
  58. package/src/instructions/createStakingPool.ts +38 -37
  59. package/src/instructions/createVault.ts +81 -125
  60. package/src/instructions/depositLiquidationPool.ts +45 -26
  61. package/src/instructions/depositStakingPool.ts +32 -24
  62. package/src/instructions/depositVault.ts +77 -31
  63. package/src/instructions/initHedgeFoundation.ts +42 -43
  64. package/src/instructions/initHedgeFoundationTokens.ts +38 -39
  65. package/src/instructions/liquidateVault.ts +96 -22
  66. package/src/instructions/loanVault.ts +84 -30
  67. package/src/instructions/redeemVault.ts +91 -32
  68. package/src/instructions/refreshOraclePrice.ts +41 -32
  69. package/src/instructions/repayVault.ts +74 -29
  70. package/src/instructions/setHalted.ts +32 -24
  71. package/src/instructions/setVaultTypeStatus.ts +58 -0
  72. package/src/instructions/withdrawStakingPool.ts +44 -30
  73. package/src/instructions/withdrawVault.ts +87 -33
  74. package/src/state/LiquidationPoolEra.ts +4 -3
  75. package/src/state/LiquidationPosition.ts +0 -27
  76. package/src/state/StakingPool.ts +4 -7
  77. package/src/state/StakingPoolPosition.ts +2 -3
  78. package/src/state/VaultAccount.ts +65 -8
  79. package/src/state/VaultHistoryEvent.ts +1 -2
  80. package/src/utils/getLinkedListAccounts.ts +157 -0
@@ -13,6 +13,7 @@ exports.liquidateVaultInstruction = exports.liquidateVault = void 0;
13
13
  const anchor_1 = require("@project-serum/anchor");
14
14
  const spl_token_1 = require("@solana/spl-token");
15
15
  const web3_js_1 = require("@solana/web3.js");
16
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
16
17
  const Constants_1 = require("../Constants");
17
18
  function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -31,50 +32,53 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
31
32
  const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
32
33
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true);
33
34
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true);
35
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, false, true);
34
36
  const history = web3_js_1.Keypair.generate();
35
37
  const newEra = web3_js_1.Keypair.generate();
36
38
  const transaction = new web3_js_1.Transaction();
37
- transaction.add(yield liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount.address, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount.address, hedgeStakingPoolAssociatedUshTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, vaultAccount.collateralType, overrideTime));
38
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra], provider.opts);
39
+ transaction.add(yield liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount.address, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount.address, hedgeStakingPoolAssociatedUshTokenAccount.address, collateralMint, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultAccount.collateralType, overrideTime));
40
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra]);
39
41
  return vaultPublicKey;
40
42
  });
41
43
  }
42
44
  exports.liquidateVault = liquidateVault;
43
- function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, collateralType, overrideTime) {
45
+ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, collateralType, overrideTime) {
44
46
  return __awaiter(this, void 0, void 0, function* () {
45
47
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
46
48
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
47
49
  const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
48
50
  const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
49
- const payload = {
50
- accounts: {
51
- vaultSystemState: vaultSystemStatePublicKey,
52
- vaultTypeAccount: vaultTypeAccount,
53
- vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
54
- collateralMint: collateralMint,
55
- poolEra: poolEra,
56
- vaultAccount: vaultPublickey,
57
- vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
58
- poolState: poolState,
59
- poolAssociatedTokenAccount: poolAssociatedTokenAccount,
60
- ushMint: ushMintPublickey,
61
- history: historyPublicKey,
62
- payer: payerPublicKey,
63
- payerAssociatedTokenAccount: payerAssociatedTokenAccount,
64
- feePool: feePool,
65
- feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
66
- feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
67
- liquidationPoolUshAccount: liquidationPoolUshAccountPublickey,
68
- newEra: newEraPublicKey,
69
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
70
- systemProgram: web3_js_1.SystemProgram.programId,
71
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
72
- rent: web3_js_1.SYSVAR_RENT_PUBKEY
73
- },
74
- signers: []
75
- };
76
- return program.instruction.liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
77
- payload);
51
+ return program.methods
52
+ .liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
53
+ )
54
+ .accounts({
55
+ vaultSystemState: vaultSystemStatePublicKey,
56
+ vaultTypeAccount: vaultTypeAccount,
57
+ vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
58
+ collateralMint: collateralMint,
59
+ poolEra: poolEra,
60
+ vaultAccount: vaultPublickey,
61
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
62
+ poolState: poolState,
63
+ poolAssociatedTokenAccount: poolAssociatedTokenAccount,
64
+ ushMint: ushMintPublickey,
65
+ history: historyPublicKey,
66
+ payer: payerPublicKey,
67
+ payerAssociatedTokenAccount: payerAssociatedTokenAccount,
68
+ feePool: feePool,
69
+ feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
70
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
71
+ liquidationPoolUshAccount: liquidationPoolUshAccountPublickey,
72
+ newEra: newEraPublicKey,
73
+ oldSmallerVaultInfo: oldSmallerPublicKey,
74
+ newSmallerVaultInfo: newSmallerPublicKey,
75
+ newLargerVaultInfo: newLargerPublicKey,
76
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
77
+ systemProgram: web3_js_1.SystemProgram.programId,
78
+ associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
79
+ rent: web3_js_1.SYSVAR_RENT_PUBKEY,
80
+ })
81
+ .instruction();
78
82
  });
79
83
  }
80
84
  exports.liquidateVaultInstruction = liquidateVaultInstruction;
@@ -13,6 +13,7 @@ exports.loanVaultInstruction = exports.loanVault = void 0;
13
13
  const anchor_1 = require("@project-serum/anchor");
14
14
  const spl_token_1 = require("@solana/spl-token");
15
15
  const web3_js_1 = require("@solana/web3.js");
16
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
16
17
  const Constants_1 = require("../Constants");
17
18
  function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -23,39 +24,43 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
23
24
  const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
24
25
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultTypeAccountPublicKey, true);
25
26
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
27
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, loanAmount, false, false);
26
28
  const history = web3_js_1.Keypair.generate();
27
- const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, loanAmount, overrideTime));
28
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
29
+ const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime));
30
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
29
31
  return vaultPublicKey;
30
32
  });
31
33
  }
32
34
  exports.loanVault = loanVault;
33
- function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, loanAmount, overrideTime) {
35
+ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, overrideTime) {
34
36
  return __awaiter(this, void 0, void 0, function* () {
35
37
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
36
38
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
37
39
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
38
40
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
39
41
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
40
- return program.instruction.loanVault(new anchor_1.BN(loanAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
41
- {
42
- accounts: {
43
- vaultSystemState: vaultSystemStatePublicKey,
44
- vaultTypeAccount: vaultTypeAccount,
45
- vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
46
- vaultAccount: vaultPublickey,
47
- vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
48
- history: historyPublicKey,
49
- feePool: hedgeStakingPoolPublicKey,
50
- feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
51
- ushMint: ushMintPublickey,
52
- vaultOwner: payerPublicKey,
53
- ownerUshAccount: ownerUshAccount,
54
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
55
- systemProgram: web3_js_1.SystemProgram.programId
56
- },
57
- signers: []
58
- });
42
+ return program.methods
43
+ .loanVault(new anchor_1.BN(loanAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
44
+ )
45
+ .accounts({
46
+ vaultSystemState: vaultSystemStatePublicKey,
47
+ vaultTypeAccount: vaultTypeAccount,
48
+ vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
49
+ vaultAccount: vaultPublickey,
50
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
51
+ history: historyPublicKey,
52
+ feePool: hedgeStakingPoolPublicKey,
53
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
54
+ ushMint: ushMintPublickey,
55
+ vaultOwner: payerPublicKey,
56
+ ownerUshAccount: ownerUshAccount,
57
+ oldSmallerVaultInfo: oldSmallerPublicKey,
58
+ newSmallerVaultInfo: newSmallerPublicKey,
59
+ newLargerVaultInfo: newLargerPublicKey,
60
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
61
+ systemProgram: web3_js_1.SystemProgram.programId,
62
+ })
63
+ .instruction();
59
64
  });
60
65
  }
61
66
  exports.loanVaultInstruction = loanVaultInstruction;
@@ -14,6 +14,7 @@ const anchor_1 = require("@project-serum/anchor");
14
14
  const spl_token_1 = require("@solana/spl-token");
15
15
  // import { TokenInstructions } from '@project-serum/serum'
16
16
  const web3_js_1 = require("@solana/web3.js");
17
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
17
18
  const Constants_1 = require("../Constants");
18
19
  function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
@@ -26,40 +27,44 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
26
27
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
27
28
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true);
28
29
  const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
30
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, true, false);
29
31
  const history = web3_js_1.Keypair.generate();
30
- const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, redeemAmount, transactionOverrideTime));
31
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
32
+ const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey, payerUshAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime));
33
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
32
34
  return vaultPublicKey;
33
35
  });
34
36
  }
35
37
  exports.redeemVault = redeemVault;
36
- function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, redeemAmount, transactionOverrideTime) {
38
+ function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime) {
37
39
  return __awaiter(this, void 0, void 0, function* () {
38
40
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
39
41
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
40
42
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
41
43
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
42
44
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
43
- return program.instruction.redeemVault(new anchor_1.BN(redeemAmount), new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
44
- {
45
- accounts: {
46
- vaultSystemState: vaultSystemStatePublicKey,
47
- vaultTypeAccount: vaultTypeAccount,
48
- vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
49
- vault: vaultPublickey,
50
- vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
51
- history: historyPublicKey,
52
- feePool: hedgeStakingPoolPublicKey,
53
- feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
54
- ushMint: ushMintPublickey,
55
- payer: payerPublicKey,
56
- payerUshAccount: payerUshAccount,
57
- destinationTokenAccount: destinationTokenAccount,
58
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
59
- systemProgram: web3_js_1.SystemProgram.programId
60
- },
61
- signers: []
62
- });
45
+ return yield program.methods
46
+ .redeemVault(new anchor_1.BN(redeemAmount), new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : Date.now() / 1000) // override start time
47
+ )
48
+ .accounts({
49
+ vaultSystemState: vaultSystemStatePublicKey,
50
+ vaultTypeAccount: vaultTypeAccount,
51
+ vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
52
+ vault: vaultPublickey,
53
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
54
+ history: historyPublicKey,
55
+ feePool: hedgeStakingPoolPublicKey,
56
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
57
+ ushMint: ushMintPublickey,
58
+ payer: payerPublicKey,
59
+ payerUshAccount: payerUshAccount,
60
+ destinationTokenAccount: destinationTokenAccount,
61
+ oldSmallerVaultInfo: oldSmallerPublicKey,
62
+ newSmallerVaultInfo: newSmallerPublicKey,
63
+ newLargerVaultInfo: newLargerPublicKey,
64
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
65
+ systemProgram: web3_js_1.SystemProgram.programId,
66
+ })
67
+ .instruction();
63
68
  });
64
69
  }
65
70
  exports.redeemVaultInstruction = redeemVaultInstruction;
@@ -16,7 +16,7 @@ const Constants_1 = require("../Constants");
16
16
  function refreshOraclePrice(program, provider, payer, collateralType, network, overridePrice, overrideTime) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  const transaction = new web3_js_1.Transaction().add(yield refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime));
19
- return yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider.opts);
19
+ return yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]);
20
20
  });
21
21
  }
22
22
  exports.refreshOraclePrice = refreshOraclePrice;
@@ -25,19 +25,19 @@ function refreshOraclePriceInstruction(program, collateralType, network, overrid
25
25
  const enc = new TextEncoder();
26
26
  const [oracleInfoAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
27
27
  const [vaultTypeAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
28
- return program.instruction.refreshOraclePrice(new anchor_1.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js_1.LAMPORTS_PER_SOL * 150), // override usd/sol price
29
- new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000) - 1), // override override time
30
- {
31
- accounts: {
32
- oracleInfoAccount: oracleInfoAccount,
33
- vaultTypeAccount: vaultTypeAccount,
34
- oracleChainlink: chainlinkAccunts[network],
35
- oraclePyth: pythAccounts[network],
36
- oracleSwitchboard: switchboardAccounts[network],
37
- systemProgram: web3_js_1.SystemProgram.programId
38
- },
39
- signers: []
40
- });
28
+ return yield program.methods
29
+ .refreshOraclePrice(new anchor_1.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js_1.LAMPORTS_PER_SOL * 150), // override usd/sol price
30
+ new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000) - 1) // override override time
31
+ )
32
+ .accounts({
33
+ oracleInfoAccount: oracleInfoAccount,
34
+ vaultTypeAccount: vaultTypeAccount,
35
+ oracleChainlink: chainlinkAccunts[network],
36
+ oraclePyth: pythAccounts[network],
37
+ oracleSwitchboard: switchboardAccounts[network],
38
+ systemProgram: web3_js_1.SystemProgram.programId,
39
+ })
40
+ .instruction();
41
41
  });
42
42
  }
43
43
  exports.refreshOraclePriceInstruction = refreshOraclePriceInstruction;
@@ -50,16 +50,16 @@ var Cluster;
50
50
  const pythAccounts = {
51
51
  Testing: web3_js_1.SystemProgram.programId,
52
52
  Devnet: new web3_js_1.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
53
- MainnetBeta: new web3_js_1.PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')
53
+ MainnetBeta: new web3_js_1.PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG'),
54
54
  };
55
55
  const chainlinkAccunts = {
56
56
  Testing: web3_js_1.SystemProgram.programId,
57
57
  Devnet: new web3_js_1.PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
58
- MainnetBeta: web3_js_1.SystemProgram.programId // CHAINLINK NOT ON MAINNET YET
58
+ MainnetBeta: web3_js_1.SystemProgram.programId, // CHAINLINK NOT ON MAINNET YET
59
59
  };
60
60
  const switchboardAccounts = {
61
61
  Testing: web3_js_1.SystemProgram.programId,
62
62
  // Devnet: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
63
63
  Devnet: new web3_js_1.PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'),
64
- MainnetBeta: web3_js_1.SystemProgram.programId // Switchboard V2 NOT ON MAINNET YET
64
+ MainnetBeta: web3_js_1.SystemProgram.programId, // Switchboard V2 NOT ON MAINNET YET
65
65
  };
@@ -13,6 +13,7 @@ exports.repayVaultInstruction = exports.repayVault = void 0;
13
13
  const anchor_1 = require("@project-serum/anchor");
14
14
  const spl_token_1 = require("@solana/spl-token");
15
15
  const web3_js_1 = require("@solana/web3.js");
16
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
16
17
  const Constants_1 = require("../Constants");
17
18
  function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overrideTime) {
18
19
  return __awaiter(this, void 0, void 0, function* () {
@@ -24,39 +25,43 @@ function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overr
24
25
  const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
25
26
  const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultTypeAccountPublicKey, vaultTypeAccount.collateralMint);
26
27
  const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
28
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, repayAmount * -1, false, false);
27
29
  const history = web3_js_1.Keypair.generate();
28
- const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime));
29
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
30
+ const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime));
31
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
30
32
  return vaultPublicKey;
31
33
  });
32
34
  }
33
35
  exports.repayVault = repayVault;
34
- function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime) {
36
+ function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, repayAmount, overrideTime) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
38
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
37
39
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
38
40
  const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
39
41
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
40
42
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
41
- return program.instruction.repayVault(new anchor_1.BN(repayAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
42
- {
43
- accounts: {
44
- vaultSystemState: vaultSystemStatePublicKey,
45
- vaultTypeAccount: vaultTypeAccount,
46
- vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
47
- vaultAccount: vaultPublickey,
48
- vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
49
- history: historyPublicKey,
50
- feePool: hedgeStakingPoolPublicKey,
51
- feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
52
- ushMint: ushMintPublickey,
53
- vaultOwner: payerPublicKey,
54
- ownerUshAccount: ownerUshAccount,
55
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
56
- systemProgram: web3_js_1.SystemProgram.programId
57
- },
58
- signers: []
59
- });
43
+ return yield program.methods
44
+ .repayVault(new anchor_1.BN(repayAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
45
+ )
46
+ .accounts({
47
+ vaultSystemState: vaultSystemStatePublicKey,
48
+ vaultTypeAccount: vaultTypeAccount,
49
+ vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
50
+ vaultAccount: vaultPublickey,
51
+ vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
52
+ history: historyPublicKey,
53
+ feePool: hedgeStakingPoolPublicKey,
54
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
55
+ ushMint: ushMintPublickey,
56
+ vaultOwner: payerPublicKey,
57
+ oldSmallerVaultInfo: oldSmallerPublicKey,
58
+ newSmallerVaultInfo: newSmallerPublicKey,
59
+ newLargerVaultInfo: newLargerPublicKey,
60
+ ownerUshAccount: ownerUshAccount,
61
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
62
+ systemProgram: web3_js_1.SystemProgram.programId,
63
+ })
64
+ .instruction();
60
65
  });
61
66
  }
62
67
  exports.repayVaultInstruction = repayVaultInstruction;
@@ -17,21 +17,20 @@ function setHalted(program, provider, payer, halted) {
17
17
  return __awaiter(this, void 0, void 0, function* () {
18
18
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
19
19
  const transaction = new web3_js_1.Transaction().add(yield setHaltedInstruction(program, vaultSystemStatePublicKey, payer.publicKey, halted));
20
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider === null || provider === void 0 ? void 0 : provider.opts).catch(Errors_1.parseAnchorErrors);
20
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
21
21
  return vaultSystemStatePublicKey;
22
22
  });
23
23
  }
24
24
  exports.setHalted = setHalted;
25
25
  function setHaltedInstruction(program, vaultSystemStatePublicKey, payerPublicKey, halted) {
26
26
  return __awaiter(this, void 0, void 0, function* () {
27
- const ix = program.instruction.setHalted(halted, {
28
- accounts: {
29
- payer: payerPublicKey,
30
- vaultSystemState: vaultSystemStatePublicKey,
31
- },
32
- signers: []
33
- });
34
- return ix;
27
+ return yield program.methods
28
+ .setHalted(halted)
29
+ .accounts({
30
+ payer: payerPublicKey,
31
+ vaultSystemState: vaultSystemStatePublicKey,
32
+ })
33
+ .instruction();
35
34
  });
36
35
  }
37
36
  exports.setHaltedInstruction = setHaltedInstruction;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.setVaultTypeStatusInstruction = exports.setVaultTypeStatus = void 0;
13
+ const web3_js_1 = require("@solana/web3.js");
14
+ const Constants_1 = require("../Constants");
15
+ const Errors_1 = require("../utils/Errors");
16
+ function setVaultTypeStatus(program, provider, payer, vaultTypeAccount, deprecated) {
17
+ return __awaiter(this, void 0, void 0, function* () {
18
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
19
+ const transaction = new web3_js_1.Transaction().add(yield setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, deprecated));
20
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
21
+ return vaultSystemStatePublicKey;
22
+ });
23
+ }
24
+ exports.setVaultTypeStatus = setVaultTypeStatus;
25
+ function setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, deprecated) {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ return yield program.methods
28
+ .setVaultTypeStatus(deprecated)
29
+ .accounts({
30
+ payer: payerPublicKey,
31
+ vaultSystemState: vaultSystemStatePublicKey,
32
+ vaultType: vaultTypeAccount,
33
+ })
34
+ .instruction();
35
+ });
36
+ }
37
+ exports.setVaultTypeStatusInstruction = setVaultTypeStatusInstruction;
@@ -19,7 +19,7 @@ function withdrawStakingPool(program, provider, payer, poolPositionPublicKey, st
19
19
  return __awaiter(this, void 0, void 0, function* () {
20
20
  const poolPosition = web3_js_1.Keypair.generate();
21
21
  const transaction = new web3_js_1.Transaction().add(yield withdrawStakingPoolInstruction(program, payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime));
22
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider.opts).catch(Errors_1.parseAnchorErrors);
22
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
23
23
  return poolPosition.publicKey;
24
24
  });
25
25
  }
@@ -36,29 +36,27 @@ function withdrawStakingPoolInstruction(program, payerPublicKey, poolPositionPub
36
36
  const payerAssociatedHedgeAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
37
37
  const payerAssociatedUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, ushMintPublickey);
38
38
  const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
39
- return program.instruction.withdrawStakingPool(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
40
- {
41
- accounts: {
42
- payer: payerPublicKey,
43
- vaultSystemState: vaultSystemStatePublicKey,
44
- pool: poolPublickey,
45
- poolPosition: poolPositionPublicKey,
46
- poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
47
- poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
48
- payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
49
- payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
50
- payerAssociatedUshAccount: payerAssociatedUshAccount,
51
- communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
52
- hedgeMint: hedgeMintPublickey,
53
- stakedTokenMint: stakedTokenMintPublicKey,
54
- ushMint: ushMintPublickey,
55
- rent: web3_js_1.SYSVAR_RENT_PUBKEY,
56
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
57
- associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
58
- systemProgram: web3_js_1.SystemProgram.programId
59
- },
60
- signers: []
61
- });
39
+ return yield program.methods
40
+ .withdrawStakingPool(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
41
+ )
42
+ .accounts({
43
+ payer: payerPublicKey,
44
+ vaultSystemState: vaultSystemStatePublicKey,
45
+ pool: poolPublickey,
46
+ poolPosition: poolPositionPublicKey,
47
+ poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
48
+ poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
49
+ payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
50
+ payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
51
+ payerAssociatedUshAccount: payerAssociatedUshAccount,
52
+ communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
53
+ hedgeMint: hedgeMintPublickey,
54
+ stakedTokenMint: stakedTokenMintPublicKey,
55
+ ushMint: ushMintPublickey,
56
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
57
+ systemProgram: web3_js_1.SystemProgram.programId,
58
+ })
59
+ .instruction();
62
60
  });
63
61
  }
64
62
  exports.withdrawStakingPoolInstruction = withdrawStakingPoolInstruction;
@@ -15,6 +15,7 @@ const spl_token_1 = require("@solana/spl-token");
15
15
  const serum_1 = require("@project-serum/serum");
16
16
  const web3_js_1 = require("@solana/web3.js");
17
17
  const Constants_1 = require("../Constants");
18
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
18
19
  function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount, overrideTime) {
19
20
  return __awaiter(this, void 0, void 0, function* () {
20
21
  const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
@@ -23,40 +24,44 @@ function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount,
23
24
  const history = web3_js_1.Keypair.generate();
24
25
  const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
25
26
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
26
- const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
27
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
27
28
  const vaultAssociatedCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, serum_1.TokenInstructions.WRAPPED_SOL_MINT, vaultPublicKey, true);
28
- const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccount);
29
- const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccount, true);
29
+ const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
30
+ const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultTypeAccountPublicKey, true);
30
31
  const destinationTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
31
32
  const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
32
33
  const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
33
- const transaction = new web3_js_1.Transaction().add(yield withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount.address, vaultTypeAccount, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMintPublickey, history.publicKey, withdrawAmount, overrideTime));
34
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
34
+ const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, withdrawAmount * -1, 0, false, false);
35
+ const transaction = new web3_js_1.Transaction().add(yield withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount.address, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMintPublickey, history.publicKey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, withdrawAmount, overrideTime));
36
+ yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
35
37
  return vaultPublicKey;
36
38
  });
37
39
  }
38
40
  exports.withdrawVault = withdrawVault;
39
- function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, destinationTokenAccount, vaultPublickey, vaultAssociatedCollateralPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMint, historyPublicKey, withdrawAmount, overrideTime) {
41
+ function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, destinationTokenAccount, vaultPublickey, vaultAssociatedCollateralPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, ushMint, historyPublicKey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, withdrawAmount, overrideTime) {
40
42
  return __awaiter(this, void 0, void 0, function* () {
41
- return program.instruction.withdrawVault(new anchor_1.BN(withdrawAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
42
- {
43
- accounts: {
44
- vaultSystemState: vaultSystemStatePublicKey,
45
- vaultTypeAccount: vaultTypeAccount,
46
- vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
47
- vault: vaultPublickey,
48
- vaultAssociatedTokenAccount: vaultAssociatedCollateralPublicKey,
49
- feePool: hedgeStakingPoolPublicKey,
50
- feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
51
- ushMint: ushMint,
52
- history: historyPublicKey,
53
- vaultOwner: payerPublicKey,
54
- destinationTokenAccount: destinationTokenAccount,
55
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
56
- systemProgram: web3_js_1.SystemProgram.programId
57
- },
58
- signers: []
59
- });
43
+ return yield program.methods
44
+ .withdrawVault(new anchor_1.BN(withdrawAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
45
+ )
46
+ .accounts({
47
+ vaultSystemState: vaultSystemStatePublicKey,
48
+ vaultTypeAccount: vaultTypeAccount,
49
+ vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
50
+ vault: vaultPublickey,
51
+ vaultAssociatedTokenAccount: vaultAssociatedCollateralPublicKey,
52
+ feePool: hedgeStakingPoolPublicKey,
53
+ feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
54
+ ushMint: ushMint,
55
+ history: historyPublicKey,
56
+ vaultOwner: payerPublicKey,
57
+ destinationTokenAccount: destinationTokenAccount,
58
+ oldSmallerVaultInfo: oldSmallerPublicKey,
59
+ newSmallerVaultInfo: newSmallerPublicKey,
60
+ newLargerVaultInfo: newLargerPublicKey,
61
+ tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
62
+ systemProgram: web3_js_1.SystemProgram.programId,
63
+ })
64
+ .instruction();
60
65
  });
61
66
  }
62
67
  exports.withdrawVaultInstruction = withdrawVaultInstruction;