hedge-web3 0.2.31 → 0.3.0

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 (144) 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 +60 -744
  6. package/declarations/index.d.ts +1 -10
  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 +3 -3
  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 +3 -3
  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/lib/Constants.js +27 -54
  39. package/lib/HedgeConstants.js +170 -0
  40. package/lib/HedgeDecimal.js +1 -2
  41. package/lib/StakingPools.js +5 -1
  42. package/lib/Vaults.js +5 -1
  43. package/lib/idl/vault.js +60 -744
  44. package/lib/index.js +6 -11
  45. package/lib/instructions/claimLiquidationPoolPosition.js +7 -8
  46. package/lib/instructions/claimStakingPoolPosition.js +7 -8
  47. package/lib/instructions/closeClaimedLiquidationPoolPosition.js +2 -3
  48. package/lib/instructions/closeLiquidationPoolPosition.js +16 -17
  49. package/lib/instructions/createReferralAccount.js +13 -17
  50. package/lib/instructions/createStakingPool.js +10 -11
  51. package/lib/instructions/createUserReferralAccount.js +9 -10
  52. package/lib/instructions/createVault.js +20 -21
  53. package/lib/instructions/depositLiquidationPool.js +12 -13
  54. package/lib/instructions/depositStakingPool.js +8 -9
  55. package/lib/instructions/depositVault.js +10 -11
  56. package/lib/instructions/initHedgeFoundation.js +10 -11
  57. package/lib/instructions/initHedgeFoundationTokens.js +7 -8
  58. package/lib/instructions/liquidateVault.js +12 -19
  59. package/lib/instructions/loanVault.js +16 -23
  60. package/lib/instructions/psmEditAccount.js +11 -11
  61. package/lib/instructions/psmMintUsh.js +18 -19
  62. package/lib/instructions/psmRedeemUsh.js +18 -19
  63. package/lib/instructions/redeemVault.js +10 -11
  64. package/lib/instructions/referralClaimFees.js +12 -16
  65. package/lib/instructions/refreshOraclePrice.js +9 -9
  66. package/lib/instructions/repayVault.js +12 -13
  67. package/lib/instructions/setHalted.js +4 -5
  68. package/lib/instructions/transferVault.js +2 -3
  69. package/lib/instructions/updateReferralAccount.js +6 -7
  70. package/lib/instructions/updateReferralState.js +6 -7
  71. package/lib/instructions/updateVaultType.js +5 -6
  72. package/lib/instructions/withdrawStakingPool.js +14 -15
  73. package/lib/instructions/withdrawVault.js +8 -9
  74. package/lib/state/VaultAccount.js +22 -8
  75. package/lib/state/VaultHistoryEvent.js +2 -2
  76. package/lib/utils/Errors.js +2 -3
  77. package/lib/utils/getLinkedListAccounts.js +2 -3
  78. package/lib/utils/sendAndConfirmWithDebug.js +1 -1
  79. package/package.json +9 -8
  80. package/src/{Constants.ts → HedgeConstants.ts} +13 -43
  81. package/src/idl/vault.ts +2382 -3750
  82. package/src/index.ts +3 -10
  83. package/src/instructions/claimLiquidationPoolPosition.ts +2 -2
  84. package/src/instructions/claimStakingPoolPosition.ts +2 -2
  85. package/src/instructions/closeClaimedLiquidationPoolPosition.ts +1 -1
  86. package/src/instructions/closeLiquidationPoolPosition.ts +2 -2
  87. package/src/instructions/createReferralAccount.ts +11 -15
  88. package/src/instructions/createStakingPool.ts +11 -4
  89. package/src/instructions/createUserReferralAccount.ts +2 -2
  90. package/src/instructions/createVault.ts +2 -2
  91. package/src/instructions/depositLiquidationPool.ts +2 -2
  92. package/src/instructions/depositStakingPool.ts +2 -2
  93. package/src/instructions/depositVault.ts +2 -2
  94. package/src/instructions/initHedgeFoundation.ts +2 -2
  95. package/src/instructions/initHedgeFoundationTokens.ts +2 -2
  96. package/src/instructions/liquidateVault.ts +29 -39
  97. package/src/instructions/loanVault.ts +23 -36
  98. package/src/instructions/psmEditAccount.ts +3 -3
  99. package/src/instructions/psmMintUsh.ts +3 -3
  100. package/src/instructions/psmRedeemUsh.ts +3 -3
  101. package/src/instructions/redeemVault.ts +2 -2
  102. package/src/instructions/referralClaimFees.ts +12 -18
  103. package/src/instructions/refreshOraclePrice.ts +4 -4
  104. package/src/instructions/repayVault.ts +2 -2
  105. package/src/instructions/setHalted.ts +2 -2
  106. package/src/instructions/transferVault.ts +1 -1
  107. package/src/instructions/updateReferralAccount.ts +2 -2
  108. package/src/instructions/updateReferralState.ts +2 -2
  109. package/src/instructions/updateVaultType.ts +2 -2
  110. package/src/instructions/withdrawStakingPool.ts +2 -2
  111. package/src/instructions/withdrawVault.ts +2 -2
  112. package/src/utils/Errors.ts +1 -1
  113. package/src/utils/getLinkedListAccounts.ts +1 -1
  114. package/declarations/instructions/adminWithdrawCol.d.ts +0 -5
  115. package/declarations/instructions/adminWithdrawUsh.d.ts +0 -5
  116. package/declarations/instructions/createCompoundStakingPool.d.ts +0 -5
  117. package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +0 -6
  118. package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +0 -6
  119. package/declarations/instructions/depositRewardsToCompoundPool.d.ts +0 -6
  120. package/declarations/instructions/setCompoundPoolActive.d.ts +0 -5
  121. package/declarations/instructions/setDelegateWallet.d.ts +0 -5
  122. package/declarations/instructions/setVaultTypeStatus.d.ts +0 -4
  123. package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +0 -6
  124. package/declarations/utils/Sender.d.ts +0 -2
  125. package/lib/instructions/adminWithdrawCol.js +0 -60
  126. package/lib/instructions/adminWithdrawUsh.js +0 -57
  127. package/lib/instructions/createCompoundStakingPool.js +0 -58
  128. package/lib/instructions/createCompoundStakingPoolPosition.js +0 -56
  129. package/lib/instructions/depositCompoundStakingPoolPosition.js +0 -55
  130. package/lib/instructions/depositRewardsToCompoundPool.js +0 -64
  131. package/lib/instructions/setCompoundPoolActive.js +0 -43
  132. package/lib/instructions/setDelegateWallet.js +0 -43
  133. package/lib/instructions/setVaultTypeStatus.js +0 -38
  134. package/lib/instructions/withdrawCompoundStakingPoolPosition.js +0 -64
  135. package/lib/utils/Sender.js +0 -32
  136. package/src/instructions/adminWithdrawCol.ts +0 -87
  137. package/src/instructions/adminWithdrawUsh.ts +0 -78
  138. package/src/instructions/createCompoundStakingPool.ts +0 -63
  139. package/src/instructions/createCompoundStakingPoolPosition.ts +0 -85
  140. package/src/instructions/depositCompoundStakingPoolPosition.ts +0 -78
  141. package/src/instructions/depositRewardsToCompoundPool.ts +0 -110
  142. package/src/instructions/setCompoundPoolActive.ts +0 -51
  143. package/src/instructions/setDelegateWallet.ts +0 -51
  144. package/src/instructions/withdrawCompoundStakingPoolPosition.ts +0 -100
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.setCompoundPoolActiveInstruction = exports.setCompoundPoolActive = void 0;
16
- const web3_js_1 = require("@solana/web3.js");
17
- const Constants_1 = require("../Constants");
18
- const Errors_1 = require("../utils/Errors");
19
- const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
20
- function setCompoundPoolActive(program, provider, payer, mintPublicKey, setActive) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
23
- const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
24
- const transaction = new web3_js_1.Transaction().add(yield setCompoundPoolActiveInstruction(program, vaultSystemStatePublicKey, payer.publicKey, poolPublickey, mintPublicKey, setActive));
25
- yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
26
- return poolPublickey;
27
- });
28
- }
29
- exports.setCompoundPoolActive = setCompoundPoolActive;
30
- function setCompoundPoolActiveInstruction(program, vaultSystemStatePublicKey, payerPublicKey, poolPublicKey, stakedTokenMintPublicKey, setActive) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- return yield program.methods
33
- .setCompoundPoolActive(setActive)
34
- .accounts({
35
- payer: payerPublicKey,
36
- vaultSystemState: vaultSystemStatePublicKey,
37
- pool: poolPublicKey,
38
- stakedTokenMint: stakedTokenMintPublicKey,
39
- })
40
- .instruction();
41
- });
42
- }
43
- exports.setCompoundPoolActiveInstruction = setCompoundPoolActiveInstruction;
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.setDelegateWalletInstruction = exports.setDelegateWallet = void 0;
16
- const web3_js_1 = require("@solana/web3.js");
17
- const Constants_1 = require("../Constants");
18
- const Errors_1 = require("../utils/Errors");
19
- const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
20
- function setDelegateWallet(program, provider, payer, mintPublicKey, delegateWallet) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
23
- const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(program.programId, mintPublicKey);
24
- const transaction = new web3_js_1.Transaction().add(yield setDelegateWalletInstruction(program, vaultSystemStatePublicKey, payer.publicKey, poolPublickey, mintPublicKey, delegateWallet));
25
- yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
26
- return delegateWallet;
27
- });
28
- }
29
- exports.setDelegateWallet = setDelegateWallet;
30
- function setDelegateWalletInstruction(program, vaultSystemStatePublicKey, payerPublicKey, poolPublicKey, stakedTokenMintPublicKey, delegateWallet) {
31
- return __awaiter(this, void 0, void 0, function* () {
32
- return yield program.methods
33
- .setDelegateWallet(delegateWallet)
34
- .accounts({
35
- payer: payerPublicKey,
36
- vaultSystemState: vaultSystemStatePublicKey,
37
- pool: poolPublicKey,
38
- stakedTokenMint: stakedTokenMintPublicKey,
39
- })
40
- .instruction();
41
- });
42
- }
43
- exports.setDelegateWalletInstruction = setDelegateWalletInstruction;
@@ -1,38 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.setVaultTypeStatusInstruction = exports.setVaultTypeStatus = void 0;
13
- const web3_js_1 = require("@solana/web3.js");
14
- const Constants_1 = require("../Constants");
15
- const Errors_1 = require("../utils/Errors");
16
- function setVaultTypeStatus(program, provider, payer, vaultTypeAccount, deprecated) {
17
- return __awaiter(this, void 0, void 0, function* () {
18
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
19
- const transaction = new web3_js_1.Transaction().add(yield setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, deprecated));
20
- yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider === null || provider === void 0 ? void 0 : provider.opts).catch(Errors_1.parseAnchorErrors);
21
- return vaultSystemStatePublicKey;
22
- });
23
- }
24
- exports.setVaultTypeStatus = setVaultTypeStatus;
25
- function setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, deprecated) {
26
- return __awaiter(this, void 0, void 0, function* () {
27
- const ix = program.instruction.setVaultTypeStatus(deprecated, {
28
- accounts: {
29
- payer: payerPublicKey,
30
- vaultSystemState: vaultSystemStatePublicKey,
31
- vaultType: vaultTypeAccount,
32
- },
33
- signers: []
34
- });
35
- return ix;
36
- });
37
- }
38
- exports.setVaultTypeStatusInstruction = setVaultTypeStatusInstruction;
@@ -1,64 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.withdrawCompoundStakingPoolPositionInstruction = exports.withdrawCompoundStakingPoolPosition = void 0;
16
- const anchor_1 = require("@project-serum/anchor");
17
- const spl_token_1 = require("@solana/spl-token");
18
- const web3_js_1 = require("@solana/web3.js");
19
- const Constants_1 = require("../Constants");
20
- const Errors_1 = require("../utils/Errors");
21
- const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
22
- function withdrawCompoundStakingPoolPosition(program, provider, payer, poolPositionPublicKey, stakedTokenMintPublicKey, claimAmount, overrideStartTime) {
23
- return __awaiter(this, void 0, void 0, function* () {
24
- const [poolPublickey, poolBump] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
25
- const poolPosition = yield (0, Constants_1.getCompoundPoolPositionAddress)(program.programId, poolPublickey, payer.publicKey);
26
- const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, stakedTokenMintPublicKey, payer.publicKey);
27
- const transaction = new web3_js_1.Transaction().add(yield withdrawCompoundStakingPoolPositionInstruction(program, payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, new anchor_1.BN(claimAmount), overrideStartTime));
28
- yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
29
- return payerAssociatedTokenAccount.address;
30
- });
31
- }
32
- exports.withdrawCompoundStakingPoolPosition = withdrawCompoundStakingPoolPosition;
33
- function withdrawCompoundStakingPoolPositionInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, claimAmount, overrideStartTime) {
34
- return __awaiter(this, void 0, void 0, function* () {
35
- const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)(program.programId);
36
- const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)(program.programId);
37
- const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)(program.programId);
38
- const [poolPublickey, poolBump] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
39
- const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, stakedTokenMintPublicKey);
40
- const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, poolPublickey, ushMintPublickey);
41
- const payerAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, stakedTokenMintPublicKey);
42
- const payerAssociatedHedgeAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
43
- const payerAssociatedUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, ushMintPublickey);
44
- const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
45
- return yield program.methods
46
- .withdrawCompoundStakingPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
47
- claimAmount //amount to be claimed
48
- )
49
- .accounts({
50
- payer: payerPublicKey,
51
- vaultSystemState: vaultSystemStatePublicKey,
52
- pool: poolPublickey,
53
- poolPosition: poolPositionPublicKey,
54
- poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
55
- payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
56
- hedgeMint: hedgeMintPublickey,
57
- stakedTokenMint: stakedTokenMintPublicKey,
58
- tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
59
- systemProgram: web3_js_1.SystemProgram.programId,
60
- })
61
- .instruction();
62
- });
63
- }
64
- exports.withdrawCompoundStakingPoolPositionInstruction = withdrawCompoundStakingPoolPositionInstruction;
@@ -1,32 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.sendAndConfirmWithDebug = void 0;
13
- function sendAndConfirmWithDebug(connection, transaction, signers) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- return connection
16
- .sendTransaction(transaction, signers)
17
- .then((signature) => {
18
- return connection
19
- .confirmTransaction(signature)
20
- .then((signatureContext) => {
21
- return signature;
22
- })
23
- .catch((error) => {
24
- console.log('There was an error confirming the transaction', error);
25
- });
26
- })
27
- .catch((error) => {
28
- console.log('There was an error sending the transaction', error);
29
- });
30
- });
31
- }
32
- exports.sendAndConfirmWithDebug = sendAndConfirmWithDebug;
@@ -1,87 +0,0 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
- import {
5
- findAssociatedTokenAddress,
6
- getPoolPublicKeyForMint,
7
- getVaultSystemStatePublicKey,
8
- getVaultTypeAccountPublicKey,
9
- } from '../Constants'
10
- import { Vault } from '../idl/vault'
11
- import { parseAnchorErrors } from '../utils/Errors'
12
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
13
-
14
- export async function adminWithdrawCollateral(
15
- program: Program<Vault>,
16
- provider: Provider,
17
- payer: Signer,
18
- mintPublicKey: PublicKey,
19
- collateralType: string
20
- ): Promise<PublicKey> {
21
- const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
22
- const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(program.programId, collateralType)
23
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
24
- const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
25
-
26
- const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
27
- provider.connection,
28
- payer,
29
- vaultTypeAccountInfo.collateralMint,
30
- stakingPoolAccountObject.compoundPoolDelegateWallet
31
- )
32
-
33
- const poolAssociatedTokenAccount = await findAssociatedTokenAddress(
34
- program.programId,
35
- poolPublickey,
36
- vaultTypeAccountInfo.collateralMint
37
- )
38
-
39
- const transaction = new Transaction().add(
40
- await adminWithdrawCollateralInstruction(program, payer.publicKey, mintPublicKey, vaultTypeAccountPublicKey)
41
- )
42
- await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
43
-
44
- return poolPublickey
45
- }
46
-
47
- export async function adminWithdrawCollateralInstruction(
48
- program: Program<Vault>,
49
- payerPublicKey: PublicKey,
50
- stakedTokenMintPublicKey: PublicKey,
51
- vaultTypeAccountPublicKey: PublicKey
52
- ): Promise<TransactionInstruction> {
53
- const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
54
-
55
- const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
56
- const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
57
-
58
- const poolAssociatedTokenAccount = await findAssociatedTokenAddress(
59
- program.programId,
60
- poolPublickey,
61
- vaultTypeAccountInfo.collateralMint
62
- )
63
-
64
- const delegateAssociatedTokenAccount = await findAssociatedTokenAddress(
65
- program.programId,
66
- stakingPoolAccountObject.compoundPoolDelegateWallet,
67
- vaultTypeAccountInfo.collateralMint
68
- )
69
-
70
- const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
71
-
72
- return await program.methods
73
- .adminWithdrawColAta()
74
- .accounts({
75
- payer: payerPublicKey,
76
- vaultSystemState: vaultSystemState,
77
- pool: poolPublickey,
78
- vaultTypeAccount: vaultTypeAccountPublicKey,
79
- stakedTokenMint: stakedTokenMintPublicKey,
80
- poolAssociatedTokenAccount: poolAssociatedTokenAccount,
81
- delegateAssociatedColAccount: delegateAssociatedTokenAccount,
82
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
83
- tokenProgram: TOKEN_PROGRAM_ID,
84
- systemProgram: SystemProgram.programId,
85
- })
86
- .instruction()
87
- }
@@ -1,78 +0,0 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { ASSOCIATED_TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
- import {
5
- findAssociatedTokenAddress,
6
- getPoolPublicKeyForMint,
7
- getUshMintPublicKey,
8
- getVaultSystemStatePublicKey,
9
- } from '../Constants'
10
- import { Vault } from '../idl/vault'
11
- import { parseAnchorErrors } from '../utils/Errors'
12
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
13
-
14
- export async function adminWithdrawUsh(
15
- program: Program<Vault>,
16
- provider: Provider,
17
- payer: Signer,
18
- mintPublicKey: PublicKey
19
- ): Promise<PublicKey> {
20
- const [poolPublickey] = await getPoolPublicKeyForMint(program.programId, mintPublicKey)
21
-
22
- const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
23
-
24
- const ushMintPublickey = await getUshMintPublicKey(program.programId)
25
-
26
- const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
27
- provider.connection,
28
- payer,
29
- ushMintPublickey,
30
- stakingPoolAccountObject.compoundPoolDelegateWallet
31
- )
32
-
33
- const transaction = new Transaction().add(
34
- await adminWithdrawUshInstruction(program, payer.publicKey, mintPublicKey, poolPublickey)
35
- )
36
- await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
37
- return poolPublickey
38
- }
39
-
40
- export async function adminWithdrawUshInstruction(
41
- program: Program<Vault>,
42
- payerPublicKey: PublicKey,
43
- stakedTokenMintPublicKey: PublicKey,
44
- poolPublickey: PublicKey
45
- ): Promise<TransactionInstruction> {
46
- const ushMintPublickey = await getUshMintPublicKey(program.programId)
47
- const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
48
-
49
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
50
- program.programId,
51
- poolPublickey,
52
- ushMintPublickey
53
- )
54
-
55
- const stakingPoolAccountObject = await program.account.stakingPool.fetch(poolPublickey)
56
-
57
- const delegateWalletAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
58
- program.programId,
59
- stakingPoolAccountObject.compoundPoolDelegateWallet,
60
- ushMintPublickey
61
- )
62
-
63
- return await program.methods
64
- .adminWithdrawUshAta()
65
- .accounts({
66
- payer: payerPublicKey,
67
- vaultSystemState: vaultSystemState,
68
- pool: poolPublickey,
69
- ushMint: ushMintPublickey,
70
- stakedTokenMint: stakedTokenMintPublicKey,
71
- poolAssociatedTokenAccount: poolAssociatedStakedTokenAccount,
72
- delegateAssociatedUshAccount: delegateWalletAssociatedStakedTokenAccount,
73
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
74
- tokenProgram: TOKEN_PROGRAM_ID,
75
- systemProgram: SystemProgram.programId,
76
- })
77
- .instruction()
78
- }
@@ -1,63 +0,0 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { PublicKey, Signer, SystemProgram, SYSVAR_RENT_PUBKEY, Transaction, TransactionInstruction } from '@solana/web3.js'
4
- import {
5
- findAssociatedTokenAddress,
6
- getCompoundPoolPublicKeyForMint,
7
- getHedgeMintPublicKey,
8
- getPoolPublicKeyForMint,
9
- getUshMintPublicKey,
10
- getVaultSystemStatePublicKey,
11
- } from '../Constants'
12
- import { Vault } from '../idl/vault'
13
- import { parseAnchorErrors } from '../utils/Errors'
14
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
15
-
16
- export async function createCompoundStakingPool(
17
- program: Program<Vault>,
18
- provider: Provider,
19
- payer: Signer,
20
- mintPublicKey: PublicKey,
21
- overrideStartTime?: number
22
- ): Promise<PublicKey> {
23
- const transaction = new Transaction().add(
24
- await createCompoundStakingPoolInstruction(program, payer.publicKey, mintPublicKey, overrideStartTime)
25
- )
26
- await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
27
- const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
28
- return poolPublickey
29
- }
30
-
31
- export async function createCompoundStakingPoolInstruction(
32
- program: Program<Vault>,
33
- payerPublicKey: PublicKey,
34
- mintPublicKey: PublicKey,
35
- overrideStartTime?: number
36
- ): Promise<TransactionInstruction> {
37
- const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey(program.programId)
38
- const ushMintPublickey = await getUshMintPublicKey(program.programId)
39
- const hedgeMintPublickey = await getHedgeMintPublicKey(program.programId)
40
-
41
- const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
42
-
43
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, mintPublicKey)
44
- const poolAssociatedUshTokenAccount = await findAssociatedTokenAddress(program.programId, poolPublickey, ushMintPublickey)
45
-
46
- return await program.methods
47
- .createCompoundStakingPool(new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)))
48
- .accounts({
49
- signer: payerPublicKey,
50
- vaultSystemState: vaultSystemStatePublicKey,
51
- pool: poolPublickey,
52
- stakedTokenMint: mintPublicKey,
53
- ushMint: ushMintPublickey,
54
- hedgeMint: hedgeMintPublickey,
55
- poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
56
- poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
57
- rent: SYSVAR_RENT_PUBKEY,
58
- tokenProgram: TOKEN_PROGRAM_ID,
59
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
60
- systemProgram: SystemProgram.programId,
61
- })
62
- .instruction()
63
- }
@@ -1,85 +0,0 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
- import {
5
- findAssociatedTokenAddress,
6
- getCompoundPoolPositionAddress,
7
- getCompoundPoolPublicKeyForMint,
8
- getPoolPublicKeyForMint,
9
- getVaultSystemStatePublicKey,
10
- } from '../Constants'
11
- import { Vault } from '../idl/vault'
12
- import { parseAnchorErrors } from '../utils/Errors'
13
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
14
-
15
- export async function createCompoundStakingPoolPosition(
16
- program: Program<Vault>,
17
- provider: Provider,
18
- payer: Signer,
19
- mintPublicKey: PublicKey,
20
- depositAmount: number,
21
- overrideStartTime?: number
22
- ): Promise<PublicKey> {
23
- const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
24
- const poolPosition = await getCompoundPoolPositionAddress(program.programId, poolPublickey, payer.publicKey)
25
-
26
- const payerAssociatedTokenAccount = await getOrCreateAssociatedTokenAccount(
27
- provider.connection,
28
- payer,
29
- mintPublicKey,
30
- payer.publicKey
31
- )
32
-
33
- const transaction = new Transaction().add(
34
- await createCompoundStakingPoolPositionInstruction(
35
- program,
36
- payer.publicKey,
37
- poolPosition,
38
- mintPublicKey,
39
- new BN(depositAmount),
40
- overrideStartTime
41
- )
42
- )
43
- await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
44
- return poolPosition
45
- }
46
- export async function createCompoundStakingPoolPositionInstruction(
47
- program: Program<Vault>,
48
- payerPublicKey: PublicKey,
49
- poolPositionPublicKey: PublicKey,
50
- stakedTokenMintPublicKey: PublicKey,
51
- depositAmount: BN,
52
- overrideStartTime?: number
53
- ): Promise<TransactionInstruction> {
54
- const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
55
-
56
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
57
- program.programId,
58
- poolPublickey,
59
- stakedTokenMintPublicKey
60
- )
61
- const payersArbitraryTokenAccount = await findAssociatedTokenAddress(
62
- program.programId,
63
- payerPublicKey,
64
- stakedTokenMintPublicKey
65
- )
66
- const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
67
-
68
- return await program.methods
69
- .createCompoundStakingPoolPosition(
70
- depositAmount,
71
- new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
72
- )
73
- .accounts({
74
- payer: payerPublicKey,
75
- vaultSystemState: vaultSystemState,
76
- pool: poolPublickey,
77
- poolPosition: poolPositionPublicKey,
78
- stakedTokenMint: stakedTokenMintPublicKey,
79
- poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
80
- payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
81
- tokenProgram: TOKEN_PROGRAM_ID,
82
- systemProgram: SystemProgram.programId,
83
- })
84
- .instruction()
85
- }
@@ -1,78 +0,0 @@
1
- import { BN, Program, Provider } from '@project-serum/anchor'
2
- import { TOKEN_PROGRAM_ID } from '@solana/spl-token'
3
- import { Keypair, PublicKey, Signer, SystemProgram, Transaction, TransactionInstruction } from '@solana/web3.js'
4
- import {
5
- findAssociatedTokenAddress,
6
- getCompoundPoolPositionAddress,
7
- getCompoundPoolPublicKeyForMint,
8
- getPoolPublicKeyForMint,
9
- getVaultSystemStatePublicKey,
10
- } from '../Constants'
11
- import { Vault } from '../idl/vault'
12
- import { parseAnchorErrors } from '../utils/Errors'
13
- import sendAndConfirmWithDebug from '../utils/sendAndConfirmWithDebug'
14
-
15
- export async function depositCompoundStakingPoolPosition(
16
- program: Program<Vault>,
17
- provider: Provider,
18
- payer: Signer,
19
- mintPublicKey: PublicKey,
20
- depositAmount: number,
21
- overrideStartTime?: number
22
- ): Promise<PublicKey> {
23
- const [poolPublickey, poolBump] = await getCompoundPoolPublicKeyForMint(program.programId, mintPublicKey)
24
-
25
- const poolPosition = await getCompoundPoolPositionAddress(program.programId, poolPublickey, payer.publicKey)
26
- const transaction = new Transaction().add(
27
- await depositCompoundStakingPoolPositionInstruction(
28
- program,
29
- payer.publicKey,
30
- poolPosition,
31
- mintPublicKey,
32
- new BN(depositAmount),
33
- overrideStartTime
34
- )
35
- )
36
- await sendAndConfirmWithDebug(provider.connection, transaction, [payer]).catch(parseAnchorErrors)
37
- return poolPosition
38
- }
39
-
40
- export async function depositCompoundStakingPoolPositionInstruction(
41
- program: Program<Vault>,
42
- payerPublicKey: PublicKey,
43
- poolPositionPublicKey: PublicKey,
44
- stakedTokenMintPublicKey: PublicKey,
45
- depositAmount: BN,
46
- overrideStartTime?: number
47
- ): Promise<TransactionInstruction> {
48
- const [poolPublickey] = await getCompoundPoolPublicKeyForMint(program.programId, stakedTokenMintPublicKey)
49
- const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(
50
- program.programId,
51
- poolPublickey,
52
- stakedTokenMintPublicKey
53
- )
54
- const payersArbitraryTokenAccount = await findAssociatedTokenAddress(
55
- program.programId,
56
- payerPublicKey,
57
- stakedTokenMintPublicKey
58
- )
59
- const vaultSystemState = await getVaultSystemStatePublicKey(program.programId)
60
-
61
- return await program.methods
62
- .depositCompoundStakingPoolPosition(
63
- depositAmount,
64
- new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
65
- )
66
- .accounts({
67
- payer: payerPublicKey,
68
- vaultSystemState: vaultSystemState,
69
- pool: poolPublickey,
70
- poolPosition: poolPositionPublicKey,
71
- stakedTokenMint: stakedTokenMintPublicKey,
72
- poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
73
- payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
74
- tokenProgram: TOKEN_PROGRAM_ID,
75
- systemProgram: SystemProgram.programId,
76
- })
77
- .instruction()
78
- }