hedge-web3 0.2.24 → 0.2.26

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 (73) hide show
  1. package/declarations/Constants.d.ts +13 -15
  2. package/declarations/idl/vault.d.ts +36 -0
  3. package/declarations/instructions/createReferralAccount.d.ts +1 -1
  4. package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
  5. package/declarations/instructions/referralClaimFees.d.ts +1 -1
  6. package/declarations/state/VaultAccount.d.ts +15 -2
  7. package/declarations/utils/getLinkedListAccounts.d.ts +2 -2
  8. package/lib/Constants.js +28 -34
  9. package/lib/idl/vault.js +36 -0
  10. package/lib/instructions/claimLiquidationPoolPosition.js +10 -7
  11. package/lib/instructions/claimStakingPoolPosition.js +5 -5
  12. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +1 -1
  13. package/lib/instructions/closeLiquidationPoolPosition.js +13 -13
  14. package/lib/instructions/createReferralAccount.js +8 -8
  15. package/lib/instructions/createStakingPool.js +7 -7
  16. package/lib/instructions/createUserReferralAccount.js +6 -6
  17. package/lib/instructions/createVault.js +16 -16
  18. package/lib/instructions/depositLiquidationPool.js +9 -9
  19. package/lib/instructions/depositStakingPool.js +5 -5
  20. package/lib/instructions/depositVault.js +11 -9
  21. package/lib/instructions/initHedgeFoundation.js +8 -8
  22. package/lib/instructions/initHedgeFoundationTokens.js +5 -5
  23. package/lib/instructions/liquidateVault.js +8 -8
  24. package/lib/instructions/loanVault.js +12 -12
  25. package/lib/instructions/psmEditAccount.js +5 -5
  26. package/lib/instructions/psmMintUsh.js +14 -14
  27. package/lib/instructions/psmRedeemUsh.js +14 -14
  28. package/lib/instructions/redeemVault.js +7 -7
  29. package/lib/instructions/referralClaimFees.js +8 -8
  30. package/lib/instructions/refreshOraclePrice.js +3 -3
  31. package/lib/instructions/repayVault.js +9 -9
  32. package/lib/instructions/setHalted.js +1 -1
  33. package/lib/instructions/updateReferralAccount.js +2 -2
  34. package/lib/instructions/updateReferralState.js +2 -2
  35. package/lib/instructions/updateVaultType.js +1 -1
  36. package/lib/instructions/withdrawStakingPool.js +11 -11
  37. package/lib/instructions/withdrawVault.js +5 -5
  38. package/lib/state/VaultAccount.js +16 -16
  39. package/lib/utils/getLinkedListAccounts.js +20 -4
  40. package/package.json +1 -1
  41. package/src/Constants.ts +44 -85
  42. package/src/idl/vault.ts +72 -0
  43. package/src/instructions/claimLiquidationPoolPosition.ts +31 -29
  44. package/src/instructions/claimStakingPoolPosition.ts +10 -15
  45. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +4 -2
  46. package/src/instructions/closeLiquidationPoolPosition.ts +18 -24
  47. package/src/instructions/createReferralAccount.ts +17 -29
  48. package/src/instructions/createStakingPool.ts +11 -13
  49. package/src/instructions/createUserReferralAccount.ts +13 -24
  50. package/src/instructions/createVault.ts +44 -21
  51. package/src/instructions/depositLiquidationPool.ts +16 -23
  52. package/src/instructions/depositStakingPool.ts +18 -14
  53. package/src/instructions/depositVault.ts +23 -18
  54. package/src/instructions/initHedgeFoundation.ts +16 -14
  55. package/src/instructions/initHedgeFoundationTokens.ts +12 -14
  56. package/src/instructions/liquidateVault.ts +15 -20
  57. package/src/instructions/loanVault.ts +18 -27
  58. package/src/instructions/psmEditAccount.ts +10 -18
  59. package/src/instructions/psmMintUsh.ts +19 -41
  60. package/src/instructions/psmRedeemUsh.ts +21 -45
  61. package/src/instructions/redeemVault.ts +12 -15
  62. package/src/instructions/referralClaimFees.ts +17 -31
  63. package/src/instructions/refreshOraclePrice.ts +6 -8
  64. package/src/instructions/repayVault.ts +18 -16
  65. package/src/instructions/setHalted.ts +5 -24
  66. package/src/instructions/transferVault.ts +4 -9
  67. package/src/instructions/updateReferralAccount.ts +7 -14
  68. package/src/instructions/updateReferralState.ts +7 -14
  69. package/src/instructions/updateVaultType.ts +9 -23
  70. package/src/instructions/withdrawStakingPool.ts +17 -21
  71. package/src/instructions/withdrawVault.ts +10 -16
  72. package/src/state/VaultAccount.ts +31 -17
  73. package/src/utils/getLinkedListAccounts.ts +20 -7
@@ -16,29 +16,29 @@ exports.closeLiquidationPoolPositionInstruction = exports.closeLiquidationPoolPo
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const spl_token_1 = require("@solana/spl-token");
18
18
  const web3_js_1 = require("@solana/web3.js");
19
- const Errors_1 = require("../utils/Errors");
20
19
  const Constants_1 = require("../Constants");
20
+ const Errors_1 = require("../utils/Errors");
21
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
22
  function closeLiquidationPoolPosition(program, provider, poolPosition, payer, overrideStartTime, referrer) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
24
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
25
25
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
26
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
27
- const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)();
26
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
27
+ const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
28
28
  const liquidationPositionAccount = yield program.account.liquidationPosition.fetch(poolPosition);
29
29
  const poolEra = liquidationPositionAccount.era;
30
- const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
30
+ const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
31
31
  const payerAssociatedHedgeAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, payer.publicKey);
32
32
  const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, vaultSystemStatePublicKey, true);
33
33
  let referralAccountPublicKey = null;
34
34
  if (typeof referrer === 'undefined') {
35
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(vaultSystemStatePublicKey);
35
+ referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
36
36
  }
37
37
  else {
38
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(referrer);
38
+ referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
39
39
  }
40
40
  // Derive the user referral account public key
41
- const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(payer.publicKey);
41
+ const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
42
42
  const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey, payerUshAccount.address, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, userReferralAccountPublicKey, referralAccountPublicKey, referralStatePublicKey, overrideStartTime));
43
43
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
44
44
  return poolPosition;
@@ -47,11 +47,11 @@ function closeLiquidationPoolPosition(program, provider, poolPosition, payer, ov
47
47
  exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
48
48
  function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey, payerUshAccount, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, userReferralAccountPublicKey, referralAccountPublicKey, referralStatePublicKey, overrideStartTime) {
49
49
  return __awaiter(this, void 0, void 0, function* () {
50
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
51
- const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
52
- const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
53
- const poolUshAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
54
- const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
50
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
51
+ const ushMint = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
52
+ const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
53
+ const poolUshAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
54
+ const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
55
55
  return yield program.methods
56
56
  .closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
57
57
  )
@@ -30,25 +30,25 @@ const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfi
30
30
  * - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
31
31
  * - referrer: PublicKey
32
32
  * - overrideTime?: number
33
- */
33
+ */
34
34
  function createReferralAccount(program, provider, payer, poolPosition, overrideTime) {
35
35
  return __awaiter(this, void 0, void 0, function* () {
36
- // setup transaction
36
+ // setup transaction
37
37
  const transaction = new web3_js_1.Transaction();
38
38
  const signers = [payer];
39
39
  const referrer = payer.publicKey;
40
40
  // Setup public keys
41
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
41
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
42
42
  // Find referral account
43
- let referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(referrer);
43
+ let referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
44
44
  // Get the referral state PDA
45
- const referallStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)();
45
+ const referallStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
46
46
  // Get HDG mint public key
47
- const hedgeMintPublicKey = yield (0, Constants_1.getHedgeMintPublicKey)();
47
+ const hedgeMintPublicKey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
48
48
  // Get HDG account of signer
49
49
  const payerHdgAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMintPublicKey, payer.publicKey);
50
50
  // Derive the user referral account public key
51
- const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(payer.publicKey);
51
+ const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
52
52
  transaction.add(yield createReferralAccountInstruction(program, payer.publicKey, poolPosition, referralAccountPublicKey, referallStatePublicKey, hedgeMintPublicKey, payerHdgAssociatedTokenAccount.address, userReferralAccountPublicKey, overrideTime));
53
53
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
54
54
  return referralAccountPublicKey;
@@ -57,7 +57,7 @@ function createReferralAccount(program, provider, payer, poolPosition, overrideT
57
57
  exports.createReferralAccount = createReferralAccount;
58
58
  function createReferralAccountInstruction(program, payerPublicKey, poolPositionPublicKey, referralAccountPublicKey, referralStatePublicKey, hedgeMintPublicKey, hdgAssociatedTokenAccountPublicKey, userReferralAccountPublicKey, overrideTime) {
59
59
  return __awaiter(this, void 0, void 0, function* () {
60
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
60
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
61
61
  return yield program.methods
62
62
  .createReferralAccount(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override times
63
63
  )
@@ -16,25 +16,25 @@ exports.createStakingPoolInstruction = exports.createStakingPool = void 0;
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const spl_token_1 = require("@solana/spl-token");
18
18
  const web3_js_1 = require("@solana/web3.js");
19
- const Errors_1 = require("../utils/Errors");
20
19
  const Constants_1 = require("../Constants");
20
+ const Errors_1 = require("../utils/Errors");
21
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
22
  function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  const transaction = new web3_js_1.Transaction().add(yield createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime));
25
25
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
26
- const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
26
+ const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
27
27
  return poolPublickey;
28
28
  });
29
29
  }
30
30
  exports.createStakingPool = createStakingPool;
31
31
  function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
34
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
35
- const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
36
- const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, mintPublicKey);
37
- const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
33
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
34
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
35
+ const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
36
+ const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, mintPublicKey);
37
+ const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, ushMintPublickey);
38
38
  return yield program.methods
39
39
  .createStakingPool(poolBump, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)))
40
40
  .accounts({
@@ -21,20 +21,20 @@ const Errors_1 = require("../utils/Errors");
21
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
22
  function createUserReferralAccount(program, provider, payer, referrer, overrideTime) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
- // setup transaction
24
+ // setup transaction
25
25
  const transaction = new web3_js_1.Transaction();
26
26
  const signers = [payer];
27
27
  // Find referrer account
28
28
  let referralAccountPublicKey = null;
29
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
29
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
30
30
  if (typeof referrer === 'undefined') {
31
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(vaultSystemStatePublicKey);
31
+ referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
32
32
  }
33
33
  else {
34
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(referrer);
34
+ referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
35
35
  }
36
36
  // Derive the user referral account public key
37
- const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(payer.publicKey);
37
+ const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
38
38
  transaction.add(yield createUserReferralAccountInstruction(program, payer.publicKey, referralAccountPublicKey, userReferralAccountPublicKey, overrideTime));
39
39
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
40
40
  return userReferralAccountPublicKey;
@@ -43,7 +43,7 @@ function createUserReferralAccount(program, provider, payer, referrer, overrideT
43
43
  exports.createUserReferralAccount = createUserReferralAccount;
44
44
  function createUserReferralAccountInstruction(program, payerPublicKey, referralAccount, userReferralAccount, overrideTime) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
46
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
47
47
  return yield program.methods
48
48
  .createUserReferralAccount(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
49
49
  )
@@ -23,22 +23,22 @@ const Errors_1 = require("../utils/Errors");
23
23
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
24
24
  function createVault(program, provider, payer, collateralType, depositAmount, overrideTime) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
26
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
27
27
  const salt = (0, uuid_1.v4)().substring(0, 8);
28
- const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
28
+ const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(program.programId, salt);
29
29
  const history = web3_js_1.Keypair.generate();
30
30
  // Prep the user to get USH back out at some point
31
31
  yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
32
- const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
32
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
33
33
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
34
- const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payer.publicKey, vaultTypeAccountInfo.collateralMint);
35
- const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
34
+ const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payer.publicKey, vaultTypeAccountInfo.collateralMint);
35
+ const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
36
36
  const wrappedSolAccount = web3_js_1.Keypair.generate();
37
37
  const transaction = new web3_js_1.Transaction();
38
38
  const signers = [payer, history];
39
39
  const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
40
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
41
- const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
40
+ const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, yield (0, Constants_1.getHedgeMintPublicKey)(program.programId));
41
+ const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
42
42
  if (isWrappedSol) {
43
43
  transaction.add(web3_js_1.SystemProgram.createAccount({
44
44
  fromPubkey: payer.publicKey,
@@ -69,11 +69,11 @@ exports.createVault = createVault;
69
69
  function buildCreateVaultTransaction(program, payerPublicKey, collateralType, depositAmount, overrideTime) {
70
70
  return __awaiter(this, void 0, void 0, function* () {
71
71
  console.log('HEDGE SDK: buildCreateVaultTransaction');
72
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
72
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
73
73
  const salt = (0, uuid_1.v4)().substring(0, 8);
74
- const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
74
+ const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(program.programId, salt);
75
75
  const history = web3_js_1.Keypair.generate();
76
- const { blockhash } = yield program.provider.connection.getLatestBlockhash();
76
+ const { blockhash, lastValidBlockHeight } = yield program.provider.connection.getLatestBlockhash();
77
77
  const transaction = new web3_js_1.Transaction({
78
78
  feePayer: payerPublicKey,
79
79
  recentBlockhash: blockhash,
@@ -82,15 +82,15 @@ function buildCreateVaultTransaction(program, payerPublicKey, collateralType, de
82
82
  const wrappedSolAccount = web3_js_1.Keypair.generate();
83
83
  console.log('Lookup getVaultTypeAccountPublicKey', collateralType);
84
84
  // Lookup the vault type info
85
- const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
85
+ const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(program.programId, collateralType);
86
86
  console.log('Lookup vaultTypeAccountPublicKey', vaultTypeAccountPublicKey.toString());
87
87
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
88
88
  console.log('Lookup vaultTypeAccountInfo', vaultTypeAccountInfo);
89
89
  const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
90
- const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, vaultTypeAccountInfo.collateralMint);
91
- const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
92
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
93
- const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
90
+ const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, vaultTypeAccountInfo.collateralMint);
91
+ const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
92
+ const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, yield (0, Constants_1.getHedgeMintPublicKey)(program.programId));
93
+ const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
94
94
  console.log('about to start building transaction');
95
95
  // If wrapped SOL collateral, we convert the SOL to wSOL to use in the instruction
96
96
  if (isWrappedSol) {
@@ -125,7 +125,7 @@ function buildCreateVaultTransaction(program, payerPublicKey, collateralType, de
125
125
  exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
126
126
  function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUshTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, ushMintPublickey, depositAmount, overrideTime) {
127
127
  return __awaiter(this, void 0, void 0, function* () {
128
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
128
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
129
129
  return yield program.methods
130
130
  .createVault(salt, new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
131
131
  )
@@ -16,23 +16,23 @@ exports.depositLiquidationPoolInstruction = exports.depositLiquidationPool = voi
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const spl_token_1 = require("@solana/spl-token");
18
18
  const web3_js_1 = require("@solana/web3.js");
19
- const Errors_1 = require("../utils/Errors");
20
19
  const Constants_1 = require("../Constants");
20
+ const Errors_1 = require("../utils/Errors");
21
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
22
  function depositLiquidationPool(program, provider, payer, depositAmount, overrideStartTime, referrer) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
24
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
25
25
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
26
26
  let referralAccountPublicKey = null;
27
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
27
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
28
28
  if (typeof referrer === 'undefined') {
29
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(vaultSystemStatePublicKey);
29
+ referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
30
30
  }
31
31
  else {
32
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(referrer);
32
+ referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
33
33
  }
34
34
  // Derive the user referral account public key
35
- const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(payer.publicKey);
35
+ const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payer.publicKey);
36
36
  const poolPosition = web3_js_1.Keypair.generate();
37
37
  const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, vaultSystemStatePublicKey, payerUshAccount.address, poolPosition.publicKey, new anchor_1.BN(depositAmount), userReferralAccountPublicKey, referralAccountPublicKey, overrideStartTime));
38
38
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, poolPosition]).catch(Errors_1.parseAnchorErrors);
@@ -42,10 +42,10 @@ function depositLiquidationPool(program, provider, payer, depositAmount, overrid
42
42
  exports.depositLiquidationPool = depositLiquidationPool;
43
43
  function depositLiquidationPoolInstruction(program, payerPublicKey, vaultSystemStatePublicKey, payerUshAccount, poolPositionPublicKey, depositAmount, userReferralAccountPublicKey, referralAccountPublicKey, overrideStartTime) {
44
44
  return __awaiter(this, void 0, void 0, function* () {
45
- const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
45
+ const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
46
46
  const liquidationPoolState = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
47
- const poolUSHAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
48
- const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
47
+ const poolUSHAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
48
+ const ushMint = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
49
49
  return yield program.methods
50
50
  .depositLiquidationPool(depositAmount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
51
51
  )
@@ -16,8 +16,8 @@ exports.depositStakingPoolInstruction = exports.depositStakingPool = void 0;
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const spl_token_1 = require("@solana/spl-token");
18
18
  const web3_js_1 = require("@solana/web3.js");
19
- const Errors_1 = require("../utils/Errors");
20
19
  const Constants_1 = require("../Constants");
20
+ const Errors_1 = require("../utils/Errors");
21
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
22
  function depositStakingPool(program, provider, payer, mintPublicKey, depositAmount, overrideStartTime) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
@@ -30,10 +30,10 @@ function depositStakingPool(program, provider, payer, mintPublicKey, depositAmou
30
30
  exports.depositStakingPool = depositStakingPool;
31
31
  function depositStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, depositAmount, overrideStartTime) {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(stakedTokenMintPublicKey);
34
- const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, stakedTokenMintPublicKey);
35
- const payersArbitraryTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, stakedTokenMintPublicKey);
36
- const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
33
+ const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
34
+ const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, stakedTokenMintPublicKey);
35
+ const payersArbitraryTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, stakedTokenMintPublicKey);
36
+ const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
37
37
  return yield program.methods
38
38
  .depositStakingPool(depositAmount, new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
39
39
  )
@@ -15,27 +15,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.depositVaultInstruction = exports.depositVault = void 0;
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const serum_1 = require("@project-serum/serum");
18
+ const token_instructions_1 = require("@project-serum/serum/lib/token-instructions");
18
19
  const spl_token_1 = require("@solana/spl-token");
19
20
  const web3_js_1 = require("@solana/web3.js");
20
- const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
21
21
  const Constants_1 = require("../Constants");
22
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
22
23
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
23
- const token_instructions_1 = require("@project-serum/serum/lib/token-instructions");
24
24
  function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
26
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
27
27
  // Prep the user to get USH back out at some point
28
28
  yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
29
29
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
30
30
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
31
31
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
32
- const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payer.publicKey, vaultTypeAccountInfo.collateralMint);
33
- const vaultAssociatedCollateralAccountPublicKey = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccountInfo.collateralMint);
32
+ const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payer.publicKey, vaultTypeAccountInfo.collateralMint);
33
+ const vaultAssociatedCollateralAccountPublicKey = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultPublicKey, vaultTypeAccountInfo.collateralMint);
34
34
  const history = web3_js_1.Keypair.generate();
35
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
35
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
36
36
  const wrappedSolAccount = web3_js_1.Keypair.generate();
37
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
38
- const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
37
+ const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, yield (0, Constants_1.getHedgeMintPublicKey)(program.programId));
38
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
39
39
  const transaction = new web3_js_1.Transaction();
40
40
  const signers = [payer, history];
41
41
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(depositAmount), new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(0), false, false);
@@ -53,7 +53,9 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
53
53
  }));
54
54
  signers.push(wrappedSolAccount);
55
55
  }
56
- transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString() ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(depositAmount), overrideTime));
56
+ transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()
57
+ ? wrappedSolAccount.publicKey
58
+ : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(depositAmount), overrideTime));
57
59
  if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
58
60
  transaction.add(serum_1.TokenInstructions.closeAccount({
59
61
  source: wrappedSolAccount.publicKey,
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.initHedgeFoundationInstruction = exports.initHedgeFoundation = void 0;
16
16
  const spl_token_1 = require("@solana/spl-token");
17
17
  const web3_js_1 = require("@solana/web3.js");
18
- const Errors_1 = require("../utils/Errors");
19
18
  const Constants_1 = require("../Constants");
19
+ const Errors_1 = require("../utils/Errors");
20
20
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
21
21
  function initHedgeFoundation(program, provider, payer) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
@@ -29,13 +29,13 @@ function initHedgeFoundation(program, provider, payer) {
29
29
  exports.initHedgeFoundation = initHedgeFoundation;
30
30
  function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKey) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
33
- const poolStatePublickey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
34
- const poolUshTokenAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
35
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
36
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
37
- const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
38
- const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
32
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
33
+ const poolStatePublickey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
34
+ const poolUshTokenAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
35
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
36
+ const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
37
+ const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
38
+ const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
39
39
  return yield program.methods
40
40
  .initHedgeFoundation()
41
41
  .accounts({
@@ -15,8 +15,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.initHedgeFoundationTokensInstruction = exports.initHedgeFoundationTokens = void 0;
16
16
  const spl_token_1 = require("@solana/spl-token");
17
17
  const web3_js_1 = require("@solana/web3.js");
18
- const Errors_1 = require("../utils/Errors");
19
18
  const Constants_1 = require("../Constants");
19
+ const Errors_1 = require("../utils/Errors");
20
20
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
21
21
  function initHedgeFoundationTokens(program, provider, payer) {
22
22
  return __awaiter(this, void 0, void 0, function* () {
@@ -29,10 +29,10 @@ function initHedgeFoundationTokens(program, provider, payer) {
29
29
  exports.initHedgeFoundationTokens = initHedgeFoundationTokens;
30
30
  function initHedgeFoundationTokensInstruction(program, payerPublicKey) {
31
31
  return __awaiter(this, void 0, void 0, function* () {
32
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
33
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
34
- const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
35
- const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
32
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
33
+ const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
34
+ const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
35
+ const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
36
36
  return yield program.methods
37
37
  .initHedgeFoundationTokens()
38
38
  .accounts({
@@ -16,18 +16,18 @@ exports.liquidateVaultInstruction = exports.liquidateVault = void 0;
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const spl_token_1 = require("@solana/spl-token");
18
18
  const web3_js_1 = require("@solana/web3.js");
19
- const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
20
19
  const Constants_1 = require("../Constants");
20
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
21
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
22
  function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
24
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
25
25
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
26
26
  const collateralMint = vaultTypeAccountInfo.collateralMint;
27
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
28
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
29
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
30
- const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
27
+ const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
28
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
29
+ const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
30
+ const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)(program.programId);
31
31
  const poolStateInfo = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
32
32
  const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey, true);
33
33
  const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, hedgeStakingPoolPublicKey, true);
@@ -47,9 +47,9 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
47
47
  exports.liquidateVault = liquidateVault;
48
48
  function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultTypeAccount, overrideTime) {
49
49
  return __awaiter(this, void 0, void 0, function* () {
50
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
51
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
52
- const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
50
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
51
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
52
+ const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
53
53
  return yield program.methods
54
54
  .liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
55
55
  )
@@ -16,12 +16,12 @@ exports.loanVaultInstruction = exports.loanVault = void 0;
16
16
  const anchor_1 = require("@project-serum/anchor");
17
17
  const spl_token_1 = require("@solana/spl-token");
18
18
  const web3_js_1 = require("@solana/web3.js");
19
- const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
20
19
  const Constants_1 = require("../Constants");
20
+ const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
21
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
22
  function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime, referrer) {
23
23
  return __awaiter(this, void 0, void 0, function* () {
24
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
24
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
25
25
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
26
26
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
27
27
  const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
@@ -29,12 +29,12 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
29
29
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
30
30
  const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, vaultAccount.vaultType, vaultPublicKey, new anchor_1.BN(0), new anchor_1.BN(0), new anchor_1.BN(loanAmount), new anchor_1.BN(0), false, false);
31
31
  let referralAccountPublicKey = null;
32
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
32
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
33
33
  if (typeof referrer === 'undefined') {
34
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(vaultSystemStatePublicKey);
34
+ referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
35
35
  }
36
36
  else {
37
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(referrer);
37
+ referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
38
38
  }
39
39
  const history = web3_js_1.Keypair.generate();
40
40
  const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey, payerUshAccount.address, vaultPublicKey, vaultAssociatedTokenAccount.address, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(loanAmount), referralAccountPublicKey, overrideTime));
@@ -45,13 +45,13 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
45
45
  exports.loanVault = loanVault;
46
46
  function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, referralAccountPublicKey, overrideTime) {
47
47
  return __awaiter(this, void 0, void 0, function* () {
48
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
49
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
50
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
51
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
52
- const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
53
- const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)();
54
- const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(payerPublicKey);
48
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
49
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
50
+ const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
51
+ const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
52
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
53
+ const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
54
+ const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payerPublicKey);
55
55
  return yield program.methods
56
56
  .loanVault(loanAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
57
57
  )
@@ -27,11 +27,11 @@ var psmStatus;
27
27
  })(psmStatus = exports.psmStatus || (exports.psmStatus = {}));
28
28
  function psmEditAccount(program, provider, payer, collateralMint, mintFee, redeemFee, debtLimit, minSwap, overrideTime) {
29
29
  return __awaiter(this, void 0, void 0, function* () {
30
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
30
+ const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
31
31
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
32
32
  const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
33
33
  const enc = new TextEncoder();
34
- const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], Constants_1.HEDGE_PROGRAM_PUBLICKEY);
34
+ const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
35
35
  const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
36
36
  const transaction = new web3_js_1.Transaction().add(yield psmEditAccountInstruction(program, payer.publicKey, psmAccount, collateralMint, new anchor_1.BN(mintFee), new anchor_1.BN(redeemFee), new anchor_1.BN(debtLimit), new anchor_1.BN(minSwap), overrideTime));
37
37
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
@@ -41,9 +41,9 @@ function psmEditAccount(program, provider, payer, collateralMint, mintFee, redee
41
41
  exports.psmEditAccount = psmEditAccount;
42
42
  function psmEditAccountInstruction(program, payerPublicKey, psmAccount, collateralMint, mintFee, redeemFee, debtLimit, minSwap, overrideTime) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
45
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
46
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
44
+ const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
45
+ const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
46
+ const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
47
47
  return yield program.methods
48
48
  .psmEditAccount(mintFee, redeemFee, debtLimit, minSwap, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
49
49
  )