hedge-web3 0.2.33 → 0.3.2

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 (153) hide show
  1. package/declarations/Constants.d.ts +0 -12
  2. package/declarations/HedgeConstants.d.ts +76 -0
  3. package/declarations/idl/pyth.d.ts +1 -1
  4. package/declarations/idl/switchboard.d.ts +1 -1
  5. package/declarations/idl/vault.d.ts +278 -1259
  6. package/declarations/index.d.ts +1 -12
  7. package/declarations/instructions/claimLiquidationPoolPosition.d.ts +1 -1
  8. package/declarations/instructions/claimStakingPoolPosition.d.ts +1 -1
  9. package/declarations/instructions/closeClaimedLiquidationPoolPosition.d.ts +1 -1
  10. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
  11. package/declarations/instructions/createReferralAccount.d.ts +1 -1
  12. package/declarations/instructions/createStakingPool.d.ts +1 -1
  13. package/declarations/instructions/createUserReferralAccount.d.ts +1 -1
  14. package/declarations/instructions/createVault.d.ts +1 -2
  15. package/declarations/instructions/depositLiquidationPool.d.ts +1 -2
  16. package/declarations/instructions/depositStakingPool.d.ts +1 -2
  17. package/declarations/instructions/depositVault.d.ts +1 -2
  18. package/declarations/instructions/initHedgeFoundation.d.ts +1 -1
  19. package/declarations/instructions/initHedgeFoundationTokens.d.ts +1 -1
  20. package/declarations/instructions/liquidateVault.d.ts +1 -1
  21. package/declarations/instructions/loanVault.d.ts +1 -2
  22. package/declarations/instructions/psmEditAccount.d.ts +1 -2
  23. package/declarations/instructions/psmMintUsh.d.ts +1 -2
  24. package/declarations/instructions/psmRedeemUsh.d.ts +1 -2
  25. package/declarations/instructions/redeemVault.d.ts +1 -2
  26. package/declarations/instructions/referralClaimFees.d.ts +1 -1
  27. package/declarations/instructions/refreshOraclePrice.d.ts +1 -1
  28. package/declarations/instructions/repayVault.d.ts +1 -2
  29. package/declarations/instructions/setHalted.d.ts +1 -1
  30. package/declarations/instructions/transferVault.d.ts +1 -1
  31. package/declarations/instructions/updateReferralAccount.d.ts +1 -2
  32. package/declarations/instructions/updateReferralState.d.ts +1 -2
  33. package/declarations/instructions/updateVaultType.d.ts +1 -2
  34. package/declarations/instructions/withdrawStakingPool.d.ts +1 -1
  35. package/declarations/instructions/withdrawVault.d.ts +1 -2
  36. package/declarations/state/VaultAccount.d.ts +2 -3
  37. package/declarations/utils/getLinkedListAccounts.d.ts +1 -2
  38. package/declarations/utils/sendAndConfirmWithDebug.d.ts +2 -2
  39. package/lib/Constants.js +14 -41
  40. package/lib/HedgeConstants.js +170 -0
  41. package/lib/HedgeDecimal.js +1 -2
  42. package/lib/StakingPools.js +5 -1
  43. package/lib/Vaults.js +5 -1
  44. package/lib/idl/vault.js +277 -1258
  45. package/lib/index.js +6 -13
  46. package/lib/instructions/claimLiquidationPoolPosition.js +7 -8
  47. package/lib/instructions/claimStakingPoolPosition.js +7 -8
  48. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +2 -3
  49. package/lib/instructions/closeLiquidationPoolPosition.js +16 -17
  50. package/lib/instructions/createReferralAccount.js +10 -11
  51. package/lib/instructions/createStakingPool.js +10 -11
  52. package/lib/instructions/createUserReferralAccount.js +9 -10
  53. package/lib/instructions/createVault.js +35 -50
  54. package/lib/instructions/depositLiquidationPool.js +12 -13
  55. package/lib/instructions/depositStakingPool.js +8 -9
  56. package/lib/instructions/depositVault.js +15 -26
  57. package/lib/instructions/initHedgeFoundation.js +24 -13
  58. package/lib/instructions/initHedgeFoundationTokens.js +7 -8
  59. package/lib/instructions/liquidateVault.js +12 -19
  60. package/lib/instructions/loanVault.js +17 -24
  61. package/lib/instructions/psmEditAccount.js +11 -11
  62. package/lib/instructions/psmMintUsh.js +18 -19
  63. package/lib/instructions/psmRedeemUsh.js +18 -19
  64. package/lib/instructions/redeemVault.js +10 -12
  65. package/lib/instructions/referralClaimFees.js +9 -10
  66. package/lib/instructions/refreshOraclePrice.js +10 -10
  67. package/lib/instructions/repayVault.js +12 -13
  68. package/lib/instructions/setHalted.js +4 -5
  69. package/lib/instructions/transferVault.js +2 -3
  70. package/lib/instructions/updateReferralAccount.js +6 -7
  71. package/lib/instructions/updateReferralState.js +6 -7
  72. package/lib/instructions/updateVaultType.js +5 -6
  73. package/lib/instructions/withdrawStakingPool.js +14 -15
  74. package/lib/instructions/withdrawVault.js +10 -11
  75. package/lib/state/VaultAccount.js +23 -9
  76. package/lib/state/VaultHistoryEvent.js +2 -2
  77. package/lib/utils/Errors.js +2 -3
  78. package/lib/utils/getLinkedListAccounts.js +2 -3
  79. package/lib/utils/sendAndConfirmWithDebug.js +50 -14
  80. package/package.json +9 -8
  81. package/src/{Constants.ts → HedgeConstants.ts} +13 -43
  82. package/src/idl/vault.ts +2004 -3966
  83. package/src/index.ts +3 -12
  84. package/src/instructions/claimLiquidationPoolPosition.ts +2 -2
  85. package/src/instructions/claimStakingPoolPosition.ts +2 -2
  86. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +1 -1
  87. package/src/instructions/closeLiquidationPoolPosition.ts +2 -2
  88. package/src/instructions/createReferralAccount.ts +11 -8
  89. package/src/instructions/createStakingPool.ts +11 -4
  90. package/src/instructions/createUserReferralAccount.ts +2 -2
  91. package/src/instructions/createVault.ts +26 -37
  92. package/src/instructions/depositLiquidationPool.ts +2 -2
  93. package/src/instructions/depositStakingPool.ts +2 -2
  94. package/src/instructions/depositVault.ts +24 -18
  95. package/src/instructions/initHedgeFoundation.ts +19 -4
  96. package/src/instructions/initHedgeFoundationTokens.ts +2 -2
  97. package/src/instructions/liquidateVault.ts +29 -39
  98. package/src/instructions/loanVault.ts +24 -37
  99. package/src/instructions/psmEditAccount.ts +3 -3
  100. package/src/instructions/psmMintUsh.ts +3 -3
  101. package/src/instructions/psmRedeemUsh.ts +3 -3
  102. package/src/instructions/redeemVault.ts +2 -3
  103. package/src/instructions/referralClaimFees.ts +11 -9
  104. package/src/instructions/refreshOraclePrice.ts +5 -5
  105. package/src/instructions/repayVault.ts +2 -2
  106. package/src/instructions/setHalted.ts +2 -2
  107. package/src/instructions/transferVault.ts +1 -1
  108. package/src/instructions/updateReferralAccount.ts +2 -2
  109. package/src/instructions/updateReferralState.ts +2 -2
  110. package/src/instructions/updateVaultType.ts +2 -2
  111. package/src/instructions/withdrawStakingPool.ts +2 -2
  112. package/src/instructions/withdrawVault.ts +4 -4
  113. package/src/state/VaultAccount.ts +1 -1
  114. package/src/utils/Errors.ts +1 -1
  115. package/src/utils/getLinkedListAccounts.ts +1 -1
  116. package/src/utils/sendAndConfirmWithDebug.ts +72 -23
  117. package/declarations/instructions/adminWithdrawCol.d.ts +0 -5
  118. package/declarations/instructions/adminWithdrawUsh.d.ts +0 -5
  119. package/declarations/instructions/compoundCreateReferralAccount.d.ts +0 -17
  120. package/declarations/instructions/compoundReferralClaimFees.d.ts +0 -16
  121. package/declarations/instructions/createCompoundStakingPool.d.ts +0 -5
  122. package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +0 -6
  123. package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +0 -6
  124. package/declarations/instructions/depositRewardsToCompoundPool.d.ts +0 -6
  125. package/declarations/instructions/setCompoundPoolActive.d.ts +0 -5
  126. package/declarations/instructions/setDelegateWallet.d.ts +0 -5
  127. package/declarations/instructions/setVaultTypeStatus.d.ts +0 -4
  128. package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +0 -6
  129. package/declarations/utils/Sender.d.ts +0 -2
  130. package/lib/instructions/adminWithdrawCol.js +0 -60
  131. package/lib/instructions/adminWithdrawUsh.js +0 -57
  132. package/lib/instructions/compoundCreateReferralAccount.js +0 -83
  133. package/lib/instructions/compoundReferralClaimFees.js +0 -87
  134. package/lib/instructions/createCompoundStakingPool.js +0 -58
  135. package/lib/instructions/createCompoundStakingPoolPosition.js +0 -56
  136. package/lib/instructions/depositCompoundStakingPoolPosition.js +0 -55
  137. package/lib/instructions/depositRewardsToCompoundPool.js +0 -64
  138. package/lib/instructions/setCompoundPoolActive.js +0 -43
  139. package/lib/instructions/setDelegateWallet.js +0 -43
  140. package/lib/instructions/setVaultTypeStatus.js +0 -38
  141. package/lib/instructions/withdrawCompoundStakingPoolPosition.js +0 -64
  142. package/lib/utils/Sender.js +0 -32
  143. package/src/instructions/adminWithdrawCol.ts +0 -87
  144. package/src/instructions/adminWithdrawUsh.ts +0 -78
  145. package/src/instructions/compoundCreateReferralAccount.ts +0 -119
  146. package/src/instructions/compoundReferralClaimFees.ts +0 -151
  147. package/src/instructions/createCompoundStakingPool.ts +0 -63
  148. package/src/instructions/createCompoundStakingPoolPosition.ts +0 -85
  149. package/src/instructions/depositCompoundStakingPoolPosition.ts +0 -78
  150. package/src/instructions/depositRewardsToCompoundPool.ts +0 -110
  151. package/src/instructions/setCompoundPoolActive.ts +0 -51
  152. package/src/instructions/setDelegateWallet.ts +0 -51
  153. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +0 -100
@@ -12,11 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.depositStakingPoolInstruction = exports.depositStakingPool = void 0;
16
- const anchor_1 = require("@project-serum/anchor");
15
+ exports.depositStakingPool = depositStakingPool;
16
+ exports.depositStakingPoolInstruction = depositStakingPoolInstruction;
17
+ const anchor_1 = require("@coral-xyz/anchor");
17
18
  const spl_token_1 = require("@solana/spl-token");
18
19
  const web3_js_1 = require("@solana/web3.js");
19
- const Constants_1 = require("../Constants");
20
+ const HedgeConstants_1 = require("../HedgeConstants");
20
21
  const Errors_1 = require("../utils/Errors");
21
22
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
23
  function depositStakingPool(program, provider, payer, mintPublicKey, depositAmount, overrideStartTime) {
@@ -27,13 +28,12 @@ function depositStakingPool(program, provider, payer, mintPublicKey, depositAmou
27
28
  return poolPosition.publicKey;
28
29
  });
29
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)(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);
33
+ const [poolPublickey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
34
+ const poolAssociatedStakedTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, stakedTokenMintPublicKey);
35
+ const payersArbitraryTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, stakedTokenMintPublicKey);
36
+ const vaultSystemState = yield (0, HedgeConstants_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
  )
@@ -51,4 +51,3 @@ function depositStakingPoolInstruction(program, payerPublicKey, poolPositionPubl
51
51
  .instruction();
52
52
  });
53
53
  }
54
- exports.depositStakingPoolInstruction = depositStakingPoolInstruction;
@@ -12,62 +12,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.depositVaultInstruction = exports.depositVault = void 0;
16
- const anchor_1 = require("@project-serum/anchor");
17
- const serum_1 = require("@project-serum/serum");
18
- const token_instructions_1 = require("@project-serum/serum/lib/token-instructions");
15
+ exports.depositVault = depositVault;
16
+ exports.depositVaultInstruction = depositVaultInstruction;
17
+ const anchor_1 = require("@coral-xyz/anchor");
19
18
  const spl_token_1 = require("@solana/spl-token");
20
19
  const web3_js_1 = require("@solana/web3.js");
21
- const Constants_1 = require("../Constants");
20
+ const HedgeConstants_1 = require("../HedgeConstants");
22
21
  const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
23
22
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
24
23
  function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
25
24
  return __awaiter(this, void 0, void 0, function* () {
26
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
25
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
27
26
  // Prep the user to get USH back out at some point
28
27
  yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
29
28
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
30
29
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
31
30
  const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
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);
31
+ const payerTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payer.publicKey, vaultTypeAccountInfo.collateralMint);
32
+ const vaultAssociatedCollateralAccountPublicKey = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, vaultPublicKey, vaultTypeAccountInfo.collateralMint);
34
33
  const history = web3_js_1.Keypair.generate();
35
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
34
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
36
35
  const wrappedSolAccount = web3_js_1.Keypair.generate();
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);
36
+ const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId));
37
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
39
38
  const transaction = new web3_js_1.Transaction();
40
39
  const signers = [payer, history];
41
40
  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);
42
- if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
41
+ if (vaultTypeAccountInfo.collateralMint.toString() === spl_token_1.NATIVE_MINT.toString()) {
43
42
  transaction.add(web3_js_1.SystemProgram.createAccount({
44
43
  fromPubkey: payer.publicKey,
45
44
  lamports: depositAmount + 2.04e6,
46
45
  newAccountPubkey: wrappedSolAccount.publicKey,
47
46
  programId: spl_token_1.TOKEN_PROGRAM_ID,
48
47
  space: 165,
49
- }), serum_1.TokenInstructions.initializeAccount({
50
- account: wrappedSolAccount.publicKey,
51
- mint: serum_1.TokenInstructions.WRAPPED_SOL_MINT,
52
- owner: payer.publicKey,
53
- }));
48
+ }), (0, spl_token_1.createInitializeAccountInstruction)(wrappedSolAccount.publicKey, spl_token_1.NATIVE_MINT, payer.publicKey));
54
49
  signers.push(wrappedSolAccount);
55
50
  }
56
- transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()
51
+ transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccountInfo.collateralMint.toString() === spl_token_1.NATIVE_MINT.toString()
57
52
  ? wrappedSolAccount.publicKey
58
53
  : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultAccount.vaultType, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, new anchor_1.BN(depositAmount), overrideTime));
59
- if (vaultTypeAccountInfo.collateralMint.toString() === token_instructions_1.WRAPPED_SOL_MINT.toString()) {
60
- transaction.add(serum_1.TokenInstructions.closeAccount({
61
- source: wrappedSolAccount.publicKey,
62
- destination: payer.publicKey,
63
- owner: payer.publicKey,
64
- }));
54
+ if (vaultTypeAccountInfo.collateralMint.toString() === spl_token_1.NATIVE_MINT.toString()) {
55
+ transaction.add((0, spl_token_1.createCloseAccountInstruction)(wrappedSolAccount.publicKey, payer.publicKey, payer.publicKey, []));
65
56
  }
66
57
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers);
67
58
  return vaultPublicKey;
68
59
  });
69
60
  }
70
- exports.depositVault = depositVault;
71
61
  function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime) {
72
62
  return __awaiter(this, void 0, void 0, function* () {
73
63
  return yield program.methods
@@ -95,4 +85,3 @@ function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner,
95
85
  .instruction();
96
86
  });
97
87
  }
98
- exports.depositVaultInstruction = depositVaultInstruction;
@@ -12,30 +12,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.initHedgeFoundationInstruction = exports.initHedgeFoundation = void 0;
15
+ exports.initHedgeFoundation = initHedgeFoundation;
16
+ exports.initHedgeFoundationInstruction = initHedgeFoundationInstruction;
16
17
  const spl_token_1 = require("@solana/spl-token");
17
18
  const web3_js_1 = require("@solana/web3.js");
18
- const Constants_1 = require("../Constants");
19
+ const HedgeConstants_1 = require("../HedgeConstants");
19
20
  const Errors_1 = require("../utils/Errors");
20
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
21
22
  function initHedgeFoundation(program, provider, payer) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
24
+ console.log('Initializing Hedge Foundation...');
23
25
  const poolEra = web3_js_1.Keypair.generate();
24
- const transaction = new web3_js_1.Transaction().add(yield initHedgeFoundationInstruction(program, poolEra.publicKey, payer.publicKey));
25
- yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, poolEra]).catch(Errors_1.parseAnchorErrors);
26
+ console.log('Generated poolEra:', poolEra.publicKey.toBase58());
27
+ const transaction = new web3_js_1.Transaction();
28
+ transaction.feePayer = payer.publicKey;
29
+ transaction.add(yield initHedgeFoundationInstruction(program, poolEra.publicKey, payer.publicKey));
30
+ console.log('Created transaction with initHedgeFoundationInstruction');
31
+ console.log('Payer public key:', payer.publicKey.toBase58());
32
+ console.log('Sending transaction...');
33
+ yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, poolEra])
34
+ .catch(err => {
35
+ console.error('Failed to initialize Hedge Foundation:', err);
36
+ throw (0, Errors_1.parseAnchorErrors)(err);
37
+ });
38
+ console.log('Successfully initialized Hedge Foundation');
26
39
  return payer.publicKey;
27
40
  });
28
41
  }
29
- exports.initHedgeFoundation = initHedgeFoundation;
30
42
  function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKey) {
31
43
  return __awaiter(this, void 0, void 0, function* () {
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);
44
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
45
+ const poolStatePublickey = yield (0, HedgeConstants_1.getLiquidationPoolStatePublicKey)(program.programId);
46
+ const poolUshTokenAccount = yield (0, HedgeConstants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
47
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
48
+ const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
49
+ const founderHedgeTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
50
+ const communityHedgeTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
39
51
  return yield program.methods
40
52
  .initHedgeFoundation()
41
53
  .accounts({
@@ -54,4 +66,3 @@ function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKe
54
66
  .instruction();
55
67
  });
56
68
  }
57
- exports.initHedgeFoundationInstruction = initHedgeFoundationInstruction;
@@ -12,10 +12,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.initHedgeFoundationTokensInstruction = exports.initHedgeFoundationTokens = void 0;
15
+ exports.initHedgeFoundationTokens = initHedgeFoundationTokens;
16
+ exports.initHedgeFoundationTokensInstruction = initHedgeFoundationTokensInstruction;
16
17
  const spl_token_1 = require("@solana/spl-token");
17
18
  const web3_js_1 = require("@solana/web3.js");
18
- const Constants_1 = require("../Constants");
19
+ const HedgeConstants_1 = require("../HedgeConstants");
19
20
  const Errors_1 = require("../utils/Errors");
20
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
21
22
  function initHedgeFoundationTokens(program, provider, payer) {
@@ -26,13 +27,12 @@ function initHedgeFoundationTokens(program, provider, payer) {
26
27
  return payer.publicKey;
27
28
  });
28
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)(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);
32
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
33
+ const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
34
+ const founderHedgeTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
35
+ const communityHedgeTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
36
36
  return yield program.methods
37
37
  .initHedgeFoundationTokens()
38
38
  .accounts({
@@ -49,4 +49,3 @@ function initHedgeFoundationTokensInstruction(program, payerPublicKey) {
49
49
  .instruction();
50
50
  });
51
51
  }
52
- exports.initHedgeFoundationTokensInstruction = initHedgeFoundationTokensInstruction;
@@ -12,11 +12,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.liquidateVaultInstruction = exports.liquidateVault = void 0;
16
- const anchor_1 = require("@project-serum/anchor");
15
+ exports.liquidateVault = liquidateVault;
16
+ exports.liquidateVaultInstruction = liquidateVaultInstruction;
17
+ const anchor_1 = require("@coral-xyz/anchor");
17
18
  const spl_token_1 = require("@solana/spl-token");
18
19
  const web3_js_1 = require("@solana/web3.js");
19
- const Constants_1 = require("../Constants");
20
+ const HedgeConstants_1 = require("../HedgeConstants");
20
21
  const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
21
22
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
23
  function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime) {
@@ -24,15 +25,11 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
24
25
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
25
26
  const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
26
27
  const collateralMint = vaultTypeAccountInfo.collateralMint;
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);
28
+ const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
29
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
30
+ const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
31
+ const liquidationPoolStatePublicKey = yield (0, HedgeConstants_1.getLiquidationPoolStatePublicKey)(program.programId);
31
32
  const poolStateInfo = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
32
- const additionalComputationBudget = web3_js_1.ComputeBudgetProgram.requestUnits({
33
- units: 300000,
34
- additionalFee: 0,
35
- });
36
33
  const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey, true);
37
34
  const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, hedgeStakingPoolPublicKey, true);
38
35
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultPublicKey, true);
@@ -43,19 +40,16 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
43
40
  const history = web3_js_1.Keypair.generate();
44
41
  const newEra = web3_js_1.Keypair.generate();
45
42
  const transaction = new web3_js_1.Transaction();
46
- transaction
47
- .add(additionalComputationBudget)
48
- .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.vaultType, overrideTime));
43
+ 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.vaultType, overrideTime));
49
44
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history, newEra]);
50
45
  return vaultPublicKey;
51
46
  });
52
47
  }
53
- exports.liquidateVault = liquidateVault;
54
48
  function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, vaultTypeAccount, overrideTime) {
55
49
  return __awaiter(this, void 0, void 0, function* () {
56
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
57
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
58
- const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
50
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
51
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
52
+ const liquidationPoolUshAccountPublickey = yield (0, HedgeConstants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
59
53
  return yield program.methods
60
54
  .liquidateVault(new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
61
55
  )
@@ -89,4 +83,3 @@ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedToken
89
83
  .instruction();
90
84
  });
91
85
  }
92
- exports.liquidateVaultInstruction = liquidateVaultInstruction;
@@ -12,20 +12,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.loanVaultInstruction = exports.loanVault = void 0;
16
- const anchor_1 = require("@project-serum/anchor");
15
+ exports.loanVault = loanVault;
16
+ exports.loanVaultInstruction = loanVaultInstruction;
17
+ const anchor_1 = require("@coral-xyz/anchor");
17
18
  const spl_token_1 = require("@solana/spl-token");
18
19
  const web3_js_1 = require("@solana/web3.js");
19
- const Constants_1 = require("../Constants");
20
+ const HedgeConstants_1 = require("../HedgeConstants");
20
21
  const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
21
22
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
23
  function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime, referrer) {
23
24
  return __awaiter(this, void 0, void 0, function* () {
24
- const additionalComputationBudget = web3_js_1.ComputeBudgetProgram.requestUnits({
25
- units: 300000,
26
- additionalFee: 0,
27
- });
28
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
25
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
29
26
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
30
27
  const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
31
28
  const vaultTypeAccount = yield program.account.vaultType.fetch(vaultAccount.vaultType);
@@ -33,31 +30,28 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
33
30
  const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
34
31
  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);
35
32
  let referralAccountPublicKey = null;
36
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
33
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
37
34
  if (typeof referrer === 'undefined') {
38
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
35
+ referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
39
36
  }
40
37
  else {
41
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
38
+ referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
42
39
  }
43
40
  const history = web3_js_1.Keypair.generate();
44
- const transaction = new web3_js_1.Transaction()
45
- .add(additionalComputationBudget)
46
- .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));
47
- yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
41
+ 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));
42
+ yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history], 300000);
48
43
  return vaultPublicKey;
49
44
  });
50
45
  }
51
- exports.loanVault = loanVault;
52
46
  function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, loanAmount, referralAccountPublicKey, overrideTime) {
53
47
  return __awaiter(this, void 0, void 0, function* () {
54
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
55
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
56
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
57
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
58
- const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
59
- const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
60
- const userReferralAccountPublicKey = yield (0, Constants_1.getUserReferralAccountPublicKey)(program.programId, payerPublicKey);
48
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
49
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
50
+ const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
51
+ const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
52
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
53
+ const referralStatePublicKey = yield (0, HedgeConstants_1.getReferralStatePublicKey)(program.programId);
54
+ const userReferralAccountPublicKey = yield (0, HedgeConstants_1.getUserReferralAccountPublicKey)(program.programId, payerPublicKey);
61
55
  return yield program.methods
62
56
  .loanVault(loanAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
63
57
  )
@@ -85,4 +79,3 @@ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPub
85
79
  .instruction();
86
80
  });
87
81
  }
88
- exports.loanVaultInstruction = loanVaultInstruction;
@@ -12,11 +12,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.psmEditAccountInstruction = exports.psmEditAccount = exports.psmStatus = void 0;
16
- const anchor_1 = require("@project-serum/anchor");
15
+ exports.psmStatus = void 0;
16
+ exports.psmEditAccount = psmEditAccount;
17
+ exports.psmEditAccountInstruction = psmEditAccountInstruction;
18
+ const anchor_1 = require("@coral-xyz/anchor");
17
19
  const spl_token_1 = require("@solana/spl-token");
18
20
  const web3_js_1 = require("@solana/web3.js");
19
- const Constants_1 = require("../Constants");
21
+ const HedgeConstants_1 = require("../HedgeConstants");
20
22
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
21
23
  var psmStatus;
22
24
  (function (psmStatus) {
@@ -24,26 +26,25 @@ var psmStatus;
24
26
  psmStatus[psmStatus["PsmDisabled"] = 1] = "PsmDisabled";
25
27
  psmStatus[psmStatus["MintOnly"] = 2] = "MintOnly";
26
28
  psmStatus[psmStatus["RedeemOnly"] = 3] = "RedeemOnly";
27
- })(psmStatus = exports.psmStatus || (exports.psmStatus = {}));
29
+ })(psmStatus || (exports.psmStatus = psmStatus = {}));
28
30
  function psmEditAccount(program, provider, payer, collateralMint, mintFee, redeemFee, debtLimit, minSwap, overrideTime) {
29
31
  return __awaiter(this, void 0, void 0, function* () {
30
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
32
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
31
33
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
32
34
  const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
33
35
  const enc = new TextEncoder();
34
- const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
36
+ const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
35
37
  const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
36
38
  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
39
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
38
40
  return payer.publicKey;
39
41
  });
40
42
  }
41
- exports.psmEditAccount = psmEditAccount;
42
43
  function psmEditAccountInstruction(program, payerPublicKey, psmAccount, collateralMint, mintFee, redeemFee, debtLimit, minSwap, overrideTime) {
43
44
  return __awaiter(this, void 0, void 0, function* () {
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);
45
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
46
+ const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
47
+ const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
47
48
  return yield program.methods
48
49
  .psmEditAccount(mintFee, redeemFee, debtLimit, minSwap, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
49
50
  )
@@ -57,4 +58,3 @@ function psmEditAccountInstruction(program, payerPublicKey, psmAccount, collater
57
58
  .instruction();
58
59
  });
59
60
  }
60
- exports.psmEditAccountInstruction = psmEditAccountInstruction;
@@ -12,45 +12,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.psmMintUshInstruction = exports.psmMintUsh = void 0;
16
- const anchor_1 = require("@project-serum/anchor");
15
+ exports.psmMintUsh = psmMintUsh;
16
+ exports.psmMintUshInstruction = psmMintUshInstruction;
17
+ const anchor_1 = require("@coral-xyz/anchor");
17
18
  const spl_token_1 = require("@solana/spl-token");
18
19
  const web3_js_1 = require("@solana/web3.js");
19
- const Constants_1 = require("../Constants");
20
+ const HedgeConstants_1 = require("../HedgeConstants");
20
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
21
22
  function psmMintUsh(program, provider, payer, collateralMint, collateralAmount, overrideTime, referrer) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
24
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
24
25
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
25
26
  const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
26
27
  const enc = new TextEncoder();
27
- const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
28
+ const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
28
29
  const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
29
30
  let referralAccountPublicKey;
30
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
31
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
31
32
  if (!referrer) {
32
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
33
+ referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
33
34
  }
34
35
  else {
35
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
36
+ referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
36
37
  }
37
- const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
38
+ const referralStatePublicKey = yield (0, HedgeConstants_1.getReferralStatePublicKey)(program.programId);
38
39
  const transaction = new web3_js_1.Transaction().add(yield psmMintUshInstruction(program, payer.publicKey, psmAccount, collateralMint, new anchor_1.BN(collateralAmount), referralStatePublicKey, referralAccountPublicKey, overrideTime));
39
40
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
40
41
  return payer.publicKey;
41
42
  });
42
43
  }
43
- exports.psmMintUsh = psmMintUsh;
44
44
  function psmMintUshInstruction(program, payerPublicKey, psmAccount, collateralMint, collateralAmount, referralStatePublicKey, referralAccountPublicKey, overrideTime) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
47
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
48
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
49
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
50
- const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
51
- const psmAccountAta = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, psmAccount, collateralMint);
52
- const ownerCollateralAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, collateralMint);
53
- const ownerUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
46
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
47
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
48
+ const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
49
+ const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
50
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
51
+ const psmAccountAta = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, psmAccount, collateralMint);
52
+ const ownerCollateralAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, collateralMint);
53
+ const ownerUshAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
54
54
  return yield program.methods
55
55
  .psmMintUsh(collateralAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
56
56
  )
@@ -73,4 +73,3 @@ function psmMintUshInstruction(program, payerPublicKey, psmAccount, collateralMi
73
73
  .instruction();
74
74
  });
75
75
  }
76
- exports.psmMintUshInstruction = psmMintUshInstruction;
@@ -12,45 +12,45 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.psmRedeemUshInstruction = exports.psmRedeemUsh = void 0;
16
- const anchor_1 = require("@project-serum/anchor");
15
+ exports.psmRedeemUsh = psmRedeemUsh;
16
+ exports.psmRedeemUshInstruction = psmRedeemUshInstruction;
17
+ const anchor_1 = require("@coral-xyz/anchor");
17
18
  const spl_token_1 = require("@solana/spl-token");
18
19
  const web3_js_1 = require("@solana/web3.js");
19
- const Constants_1 = require("../Constants");
20
+ const HedgeConstants_1 = require("../HedgeConstants");
20
21
  const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
21
22
  function psmRedeemUsh(program, provider, payer, collateralMint, ushAmount, overrideTime, referrer) {
22
23
  return __awaiter(this, void 0, void 0, function* () {
23
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
24
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
24
25
  const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
25
26
  const payerCollateralAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
26
27
  const enc = new TextEncoder();
27
- const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddress([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
28
+ const [psmAccount] = yield web3_js_1.PublicKey.findProgramAddressSync([enc.encode(collateralMint.toString().slice(0, 12)), enc.encode('PSM')], program.programId);
28
29
  const psmAccountAta = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, psmAccount, true);
29
30
  let referralAccountPublicKey;
30
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
31
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
31
32
  if (!referrer) {
32
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
33
+ referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
33
34
  }
34
35
  else {
35
- referralAccountPublicKey = yield (0, Constants_1.getReferralAccountPublicKey)(program.programId, referrer);
36
+ referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
36
37
  }
37
- const referralStatePublicKey = yield (0, Constants_1.getReferralStatePublicKey)(program.programId);
38
+ const referralStatePublicKey = yield (0, HedgeConstants_1.getReferralStatePublicKey)(program.programId);
38
39
  const transaction = new web3_js_1.Transaction().add(yield psmRedeemUshInstruction(program, payer.publicKey, psmAccount, collateralMint, new anchor_1.BN(ushAmount), referralStatePublicKey, referralAccountPublicKey, overrideTime));
39
40
  yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]);
40
41
  return payer.publicKey;
41
42
  });
42
43
  }
43
- exports.psmRedeemUsh = psmRedeemUsh;
44
44
  function psmRedeemUshInstruction(program, payerPublicKey, psmAccount, collateralMint, ushAmount, referralStatePublicKey, referralAccountPublicKey, overrideTime) {
45
45
  return __awaiter(this, void 0, void 0, function* () {
46
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
47
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
48
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
49
- const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
50
- const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
51
- const psmAccountAta = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, psmAccount, collateralMint);
52
- const ownerCollateralAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, collateralMint);
53
- const ownerUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
46
+ const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
47
+ const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
48
+ const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
49
+ const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
50
+ const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
51
+ const psmAccountAta = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, psmAccount, collateralMint);
52
+ const ownerCollateralAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, collateralMint);
53
+ const ownerUshAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
54
54
  return yield program.methods
55
55
  .psmRedeemUsh(ushAmount, new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
56
56
  )
@@ -73,4 +73,3 @@ function psmRedeemUshInstruction(program, payerPublicKey, psmAccount, collateral
73
73
  .instruction();
74
74
  });
75
75
  }
76
- exports.psmRedeemUshInstruction = psmRedeemUshInstruction;