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.
- package/declarations/Constants.d.ts +0 -12
- package/declarations/HedgeConstants.d.ts +76 -0
- package/declarations/idl/pyth.d.ts +1 -1
- package/declarations/idl/switchboard.d.ts +1 -1
- package/declarations/idl/vault.d.ts +60 -744
- package/declarations/index.d.ts +1 -10
- package/declarations/instructions/claimLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/claimStakingPoolPosition.d.ts +1 -1
- package/declarations/instructions/closeClaimedLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/createReferralAccount.d.ts +3 -3
- package/declarations/instructions/createStakingPool.d.ts +1 -1
- package/declarations/instructions/createUserReferralAccount.d.ts +1 -1
- package/declarations/instructions/createVault.d.ts +1 -2
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -2
- package/declarations/instructions/depositStakingPool.d.ts +1 -2
- package/declarations/instructions/depositVault.d.ts +1 -2
- package/declarations/instructions/initHedgeFoundation.d.ts +1 -1
- package/declarations/instructions/initHedgeFoundationTokens.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/loanVault.d.ts +1 -2
- package/declarations/instructions/psmEditAccount.d.ts +1 -2
- package/declarations/instructions/psmMintUsh.d.ts +1 -2
- package/declarations/instructions/psmRedeemUsh.d.ts +1 -2
- package/declarations/instructions/redeemVault.d.ts +1 -2
- package/declarations/instructions/referralClaimFees.d.ts +3 -3
- package/declarations/instructions/refreshOraclePrice.d.ts +1 -1
- package/declarations/instructions/repayVault.d.ts +1 -2
- package/declarations/instructions/setHalted.d.ts +1 -1
- package/declarations/instructions/transferVault.d.ts +1 -1
- package/declarations/instructions/updateReferralAccount.d.ts +1 -2
- package/declarations/instructions/updateReferralState.d.ts +1 -2
- package/declarations/instructions/updateVaultType.d.ts +1 -2
- package/declarations/instructions/withdrawStakingPool.d.ts +1 -1
- package/declarations/instructions/withdrawVault.d.ts +1 -2
- package/declarations/state/VaultAccount.d.ts +2 -3
- package/declarations/utils/getLinkedListAccounts.d.ts +1 -2
- package/lib/Constants.js +27 -54
- package/lib/HedgeConstants.js +170 -0
- package/lib/HedgeDecimal.js +1 -2
- package/lib/StakingPools.js +5 -1
- package/lib/Vaults.js +5 -1
- package/lib/idl/vault.js +60 -744
- package/lib/index.js +6 -11
- package/lib/instructions/claimLiquidationPoolPosition.js +7 -8
- package/lib/instructions/claimStakingPoolPosition.js +7 -8
- package/lib/instructions/closeClaimedLiquidationPoolPosition.js +2 -3
- package/lib/instructions/closeLiquidationPoolPosition.js +16 -17
- package/lib/instructions/createReferralAccount.js +13 -17
- package/lib/instructions/createStakingPool.js +10 -11
- package/lib/instructions/createUserReferralAccount.js +9 -10
- package/lib/instructions/createVault.js +20 -21
- package/lib/instructions/depositLiquidationPool.js +12 -13
- package/lib/instructions/depositStakingPool.js +8 -9
- package/lib/instructions/depositVault.js +10 -11
- package/lib/instructions/initHedgeFoundation.js +10 -11
- package/lib/instructions/initHedgeFoundationTokens.js +7 -8
- package/lib/instructions/liquidateVault.js +12 -19
- package/lib/instructions/loanVault.js +16 -23
- package/lib/instructions/psmEditAccount.js +11 -11
- package/lib/instructions/psmMintUsh.js +18 -19
- package/lib/instructions/psmRedeemUsh.js +18 -19
- package/lib/instructions/redeemVault.js +10 -11
- package/lib/instructions/referralClaimFees.js +12 -16
- package/lib/instructions/refreshOraclePrice.js +9 -9
- package/lib/instructions/repayVault.js +12 -13
- package/lib/instructions/setHalted.js +4 -5
- package/lib/instructions/transferVault.js +2 -3
- package/lib/instructions/updateReferralAccount.js +6 -7
- package/lib/instructions/updateReferralState.js +6 -7
- package/lib/instructions/updateVaultType.js +5 -6
- package/lib/instructions/withdrawStakingPool.js +14 -15
- package/lib/instructions/withdrawVault.js +8 -9
- package/lib/state/VaultAccount.js +22 -8
- package/lib/state/VaultHistoryEvent.js +2 -2
- package/lib/utils/Errors.js +2 -3
- package/lib/utils/getLinkedListAccounts.js +2 -3
- package/lib/utils/sendAndConfirmWithDebug.js +1 -1
- package/package.json +9 -8
- package/src/{Constants.ts → HedgeConstants.ts} +13 -43
- package/src/idl/vault.ts +2382 -3750
- package/src/index.ts +3 -10
- package/src/instructions/claimLiquidationPoolPosition.ts +2 -2
- package/src/instructions/claimStakingPoolPosition.ts +2 -2
- package/src/instructions/closeClaimedLiquidationPoolPosition.ts +1 -1
- package/src/instructions/closeLiquidationPoolPosition.ts +2 -2
- package/src/instructions/createReferralAccount.ts +11 -15
- package/src/instructions/createStakingPool.ts +11 -4
- package/src/instructions/createUserReferralAccount.ts +2 -2
- package/src/instructions/createVault.ts +2 -2
- package/src/instructions/depositLiquidationPool.ts +2 -2
- package/src/instructions/depositStakingPool.ts +2 -2
- package/src/instructions/depositVault.ts +2 -2
- package/src/instructions/initHedgeFoundation.ts +2 -2
- package/src/instructions/initHedgeFoundationTokens.ts +2 -2
- package/src/instructions/liquidateVault.ts +29 -39
- package/src/instructions/loanVault.ts +23 -36
- package/src/instructions/psmEditAccount.ts +3 -3
- package/src/instructions/psmMintUsh.ts +3 -3
- package/src/instructions/psmRedeemUsh.ts +3 -3
- package/src/instructions/redeemVault.ts +2 -2
- package/src/instructions/referralClaimFees.ts +12 -18
- package/src/instructions/refreshOraclePrice.ts +4 -4
- package/src/instructions/repayVault.ts +2 -2
- package/src/instructions/setHalted.ts +2 -2
- package/src/instructions/transferVault.ts +1 -1
- package/src/instructions/updateReferralAccount.ts +2 -2
- package/src/instructions/updateReferralState.ts +2 -2
- package/src/instructions/updateVaultType.ts +2 -2
- package/src/instructions/withdrawStakingPool.ts +2 -2
- package/src/instructions/withdrawVault.ts +2 -2
- package/src/utils/Errors.ts +1 -1
- package/src/utils/getLinkedListAccounts.ts +1 -1
- package/declarations/instructions/adminWithdrawCol.d.ts +0 -5
- package/declarations/instructions/adminWithdrawUsh.d.ts +0 -5
- package/declarations/instructions/createCompoundStakingPool.d.ts +0 -5
- package/declarations/instructions/createCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/instructions/depositCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/instructions/depositRewardsToCompoundPool.d.ts +0 -6
- package/declarations/instructions/setCompoundPoolActive.d.ts +0 -5
- package/declarations/instructions/setDelegateWallet.d.ts +0 -5
- package/declarations/instructions/setVaultTypeStatus.d.ts +0 -4
- package/declarations/instructions/withdrawCompoundStakingPoolPosition.d.ts +0 -6
- package/declarations/utils/Sender.d.ts +0 -2
- package/lib/instructions/adminWithdrawCol.js +0 -60
- package/lib/instructions/adminWithdrawUsh.js +0 -57
- package/lib/instructions/createCompoundStakingPool.js +0 -58
- package/lib/instructions/createCompoundStakingPoolPosition.js +0 -56
- package/lib/instructions/depositCompoundStakingPoolPosition.js +0 -55
- package/lib/instructions/depositRewardsToCompoundPool.js +0 -64
- package/lib/instructions/setCompoundPoolActive.js +0 -43
- package/lib/instructions/setDelegateWallet.js +0 -43
- package/lib/instructions/setVaultTypeStatus.js +0 -38
- package/lib/instructions/withdrawCompoundStakingPoolPosition.js +0 -64
- package/lib/utils/Sender.js +0 -32
- package/src/instructions/adminWithdrawCol.ts +0 -87
- package/src/instructions/adminWithdrawUsh.ts +0 -78
- package/src/instructions/createCompoundStakingPool.ts +0 -63
- package/src/instructions/createCompoundStakingPoolPosition.ts +0 -85
- package/src/instructions/depositCompoundStakingPoolPosition.ts +0 -78
- package/src/instructions/depositRewardsToCompoundPool.ts +0 -110
- package/src/instructions/setCompoundPoolActive.ts +0 -51
- package/src/instructions/setDelegateWallet.ts +0 -51
- package/src/instructions/withdrawCompoundStakingPoolPosition.ts +0 -100
@@ -12,30 +12,31 @@ 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.
|
16
|
-
|
15
|
+
exports.depositVault = depositVault;
|
16
|
+
exports.depositVaultInstruction = depositVaultInstruction;
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
17
18
|
const serum_1 = require("@project-serum/serum");
|
18
19
|
const token_instructions_1 = require("@project-serum/serum/lib/token-instructions");
|
19
20
|
const spl_token_1 = require("@solana/spl-token");
|
20
21
|
const web3_js_1 = require("@solana/web3.js");
|
21
|
-
const
|
22
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
22
23
|
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
23
24
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
24
25
|
function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
|
25
26
|
return __awaiter(this, void 0, void 0, function* () {
|
26
|
-
const ushMintPublickey = yield (0,
|
27
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
27
28
|
// Prep the user to get USH back out at some point
|
28
29
|
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
29
30
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
30
31
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultAccount.vaultType);
|
31
32
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultAccount.vaultType, true);
|
32
|
-
const payerTokenAccount = yield (0,
|
33
|
-
const vaultAssociatedCollateralAccountPublicKey = yield (0,
|
33
|
+
const payerTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payer.publicKey, vaultTypeAccountInfo.collateralMint);
|
34
|
+
const vaultAssociatedCollateralAccountPublicKey = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, vaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
34
35
|
const history = web3_js_1.Keypair.generate();
|
35
|
-
const vaultSystemStatePublicKey = yield (0,
|
36
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
36
37
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
37
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
38
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0,
|
38
|
+
const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId));
|
39
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
39
40
|
const transaction = new web3_js_1.Transaction();
|
40
41
|
const signers = [payer, history];
|
41
42
|
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);
|
@@ -67,7 +68,6 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
67
68
|
return vaultPublicKey;
|
68
69
|
});
|
69
70
|
}
|
70
|
-
exports.depositVault = depositVault;
|
71
71
|
function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime) {
|
72
72
|
return __awaiter(this, void 0, void 0, function* () {
|
73
73
|
return yield program.methods
|
@@ -95,4 +95,3 @@ function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner,
|
|
95
95
|
.instruction();
|
96
96
|
});
|
97
97
|
}
|
98
|
-
exports.depositVaultInstruction = depositVaultInstruction;
|
@@ -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.
|
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
|
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) {
|
@@ -26,16 +27,15 @@ function initHedgeFoundation(program, provider, payer) {
|
|
26
27
|
return payer.publicKey;
|
27
28
|
});
|
28
29
|
}
|
29
|
-
exports.initHedgeFoundation = initHedgeFoundation;
|
30
30
|
function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKey) {
|
31
31
|
return __awaiter(this, void 0, void 0, function* () {
|
32
|
-
const vaultSystemStatePublicKey = yield (0,
|
33
|
-
const poolStatePublickey = yield (0,
|
34
|
-
const poolUshTokenAccount = yield (0,
|
35
|
-
const ushMintPublickey = yield (0,
|
36
|
-
const hedgeMintPublickey = yield (0,
|
37
|
-
const founderHedgeTokenAccount = yield (0,
|
38
|
-
const communityHedgeTokenAccount = yield (0,
|
32
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
33
|
+
const poolStatePublickey = yield (0, HedgeConstants_1.getLiquidationPoolStatePublicKey)(program.programId);
|
34
|
+
const poolUshTokenAccount = yield (0, HedgeConstants_1.getLiquidationPoolUshAccountPublicKey)(program.programId);
|
35
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
36
|
+
const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
|
37
|
+
const founderHedgeTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, payerPublicKey, hedgeMintPublickey);
|
38
|
+
const communityHedgeTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, vaultSystemStatePublicKey, hedgeMintPublickey);
|
39
39
|
return yield program.methods
|
40
40
|
.initHedgeFoundation()
|
41
41
|
.accounts({
|
@@ -54,4 +54,3 @@ function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKe
|
|
54
54
|
.instruction();
|
55
55
|
});
|
56
56
|
}
|
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.
|
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
|
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,
|
33
|
-
const hedgeMintPublickey = yield (0,
|
34
|
-
const founderHedgeTokenAccount = yield (0,
|
35
|
-
const communityHedgeTokenAccount = yield (0,
|
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.
|
16
|
-
|
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
|
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,
|
28
|
-
const ushMintPublickey = yield (0,
|
29
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
30
|
-
const liquidationPoolStatePublicKey = yield (0,
|
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,
|
57
|
-
const ushMintPublickey = yield (0,
|
58
|
-
const liquidationPoolUshAccountPublickey = yield (0,
|
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.
|
16
|
-
|
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
|
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
|
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,
|
33
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
37
34
|
if (typeof referrer === 'undefined') {
|
38
|
-
referralAccountPublicKey = yield (0,
|
35
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
39
36
|
}
|
40
37
|
else {
|
41
|
-
referralAccountPublicKey = yield (0,
|
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));
|
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));
|
47
42
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, [payer, history]);
|
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,
|
55
|
-
const ushMintPublickey = yield (0,
|
56
|
-
const hedgeMintPublickey = yield (0,
|
57
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
58
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0,
|
59
|
-
const referralStatePublicKey = yield (0,
|
60
|
-
const userReferralAccountPublicKey = yield (0,
|
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.
|
16
|
-
|
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
|
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
|
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,
|
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.
|
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,
|
45
|
-
const hedgeMintPublickey = yield (0,
|
46
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
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.
|
16
|
-
|
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
|
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,
|
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.
|
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,
|
31
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
31
32
|
if (!referrer) {
|
32
|
-
referralAccountPublicKey = yield (0,
|
33
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
33
34
|
}
|
34
35
|
else {
|
35
|
-
referralAccountPublicKey = yield (0,
|
36
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
36
37
|
}
|
37
|
-
const referralStatePublicKey = yield (0,
|
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,
|
47
|
-
const ushMintPublickey = yield (0,
|
48
|
-
const hedgeMintPublickey = yield (0,
|
49
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
50
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0,
|
51
|
-
const psmAccountAta = yield (0,
|
52
|
-
const ownerCollateralAccount = yield (0,
|
53
|
-
const ownerUshAccount = yield (0,
|
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.
|
16
|
-
|
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
|
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,
|
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.
|
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,
|
31
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
31
32
|
if (!referrer) {
|
32
|
-
referralAccountPublicKey = yield (0,
|
33
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, vaultSystemStatePublicKey);
|
33
34
|
}
|
34
35
|
else {
|
35
|
-
referralAccountPublicKey = yield (0,
|
36
|
+
referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
36
37
|
}
|
37
|
-
const referralStatePublicKey = yield (0,
|
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,
|
47
|
-
const ushMintPublickey = yield (0,
|
48
|
-
const hedgeMintPublickey = yield (0,
|
49
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
50
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0,
|
51
|
-
const psmAccountAta = yield (0,
|
52
|
-
const ownerCollateralAccount = yield (0,
|
53
|
-
const ownerUshAccount = yield (0,
|
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;
|
@@ -12,17 +12,18 @@ 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.
|
16
|
-
|
15
|
+
exports.redeemVault = redeemVault;
|
16
|
+
exports.redeemVaultInstruction = redeemVaultInstruction;
|
17
|
+
const anchor_1 = require("@coral-xyz/anchor");
|
17
18
|
const spl_token_1 = require("@solana/spl-token");
|
18
19
|
// import { TokenInstructions } from '@project-serum/serum'
|
19
20
|
const web3_js_1 = require("@solana/web3.js");
|
20
|
-
const
|
21
|
+
const HedgeConstants_1 = require("../HedgeConstants");
|
21
22
|
const getLinkedListAccounts_1 = require("../utils/getLinkedListAccounts");
|
22
23
|
const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfirmWithDebug"));
|
23
24
|
function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
|
24
25
|
return __awaiter(this, void 0, void 0, function* () {
|
25
|
-
const ushMintPublickey = yield (0,
|
26
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
26
27
|
// Prep the user to get USH back out at some point
|
27
28
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
28
29
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
@@ -37,14 +38,13 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
|
|
37
38
|
return vaultPublicKey;
|
38
39
|
});
|
39
40
|
}
|
40
|
-
exports.redeemVault = redeemVault;
|
41
41
|
function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, redeemAmount, transactionOverrideTime) {
|
42
42
|
return __awaiter(this, void 0, void 0, function* () {
|
43
|
-
const vaultSystemStatePublicKey = yield (0,
|
44
|
-
const ushMintPublickey = yield (0,
|
45
|
-
const hedgeMintPublickey = yield (0,
|
46
|
-
const [hedgeStakingPoolPublicKey] = yield (0,
|
47
|
-
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0,
|
43
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
44
|
+
const ushMintPublickey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
45
|
+
const hedgeMintPublickey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
|
46
|
+
const [hedgeStakingPoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublickey);
|
47
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, HedgeConstants_1.findAssociatedTokenAddress)(program.programId, hedgeStakingPoolPublicKey, ushMintPublickey);
|
48
48
|
return yield program.methods
|
49
49
|
.redeemVault(redeemAmount, new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : Date.now() / 1000) // override start time
|
50
50
|
)
|
@@ -70,4 +70,3 @@ function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destin
|
|
70
70
|
.instruction();
|
71
71
|
});
|
72
72
|
}
|
73
|
-
exports.redeemVaultInstruction = redeemVaultInstruction;
|
@@ -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.
|
15
|
+
exports.referralClaimFees = referralClaimFees;
|
16
|
+
exports.referralClaimFeesInstruction = referralClaimFeesInstruction;
|
16
17
|
const spl_token_1 = require("@solana/spl-token");
|
17
18
|
const web3_js_1 = require("@solana/web3.js");
|
18
|
-
const
|
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
|
/** @type {Function} - Allows a referrer to claims their fees.
|
@@ -29,37 +30,35 @@ const sendAndConfirmWithDebug_1 = __importDefault(require("../utils/sendAndConfi
|
|
29
30
|
* - poolPublicKey: PublicKey : a key to a pool position. If the position is closed or does not belong to the signer it will be ignored
|
30
31
|
* - referrer: PublicKey
|
31
32
|
*/
|
32
|
-
function referralClaimFees(program, provider, payer, poolPosition
|
33
|
+
function referralClaimFees(program, provider, payer, poolPosition) {
|
33
34
|
return __awaiter(this, void 0, void 0, function* () {
|
34
35
|
// setup transaction
|
35
36
|
const transaction = new web3_js_1.Transaction();
|
36
37
|
const signers = [payer];
|
37
38
|
// General variables
|
38
|
-
const vaultSystemStatePublicKey = yield (0,
|
39
|
+
const vaultSystemStatePublicKey = yield (0, HedgeConstants_1.getVaultSystemStatePublicKey)(program.programId);
|
39
40
|
// Find referrer account
|
40
41
|
const referrer = yield payer.publicKey;
|
41
|
-
const referralAccountPublicKey = yield (0,
|
42
|
+
const referralAccountPublicKey = yield (0, HedgeConstants_1.getReferralAccountPublicKey)(program.programId, referrer);
|
42
43
|
// Derive the user referral account public key
|
43
|
-
const referallStatePublicKey = yield (0,
|
44
|
-
const hedgeMintPublicKey = yield (0,
|
44
|
+
const referallStatePublicKey = yield (0, HedgeConstants_1.getReferralStatePublicKey)(program.programId);
|
45
|
+
const hedgeMintPublicKey = yield (0, HedgeConstants_1.getHedgeMintPublicKey)(program.programId);
|
45
46
|
// Get HDG account of signer
|
46
47
|
const payerHdgAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMintPublicKey, payer.publicKey);
|
47
|
-
const ushMintPublicKey = yield (0,
|
48
|
+
const ushMintPublicKey = yield (0, HedgeConstants_1.getUshMintPublicKey)(program.programId);
|
48
49
|
// Get USH account of signer
|
49
50
|
const payerUshAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublicKey, payer.publicKey);
|
50
51
|
// Get community_associated_hedge_token_account
|
51
52
|
const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMintPublicKey, vaultSystemStatePublicKey, true);
|
52
|
-
const [feePoolPublicKey] = yield (0,
|
53
|
+
const [feePoolPublicKey] = yield (0, HedgeConstants_1.getPoolPublicKeyForMint)(program.programId, hedgeMintPublicKey);
|
53
54
|
const feePoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublicKey, feePoolPublicKey, true);
|
54
|
-
transaction.add(yield referralClaimFeesInstruction(program, payer.publicKey, vaultSystemStatePublicKey, poolPosition,
|
55
|
+
transaction.add(yield referralClaimFeesInstruction(program, payer.publicKey, vaultSystemStatePublicKey, poolPosition, referralAccountPublicKey, referallStatePublicKey, hedgeMintPublicKey, payerHdgAssociatedTokenAccount.address, ushMintPublicKey, payerUshAssociatedTokenAccount.address, communityAssociatedHedgeTokenAccount.address, feePoolPublicKey, feePoolAssociatedUshTokenAccount.address));
|
55
56
|
yield (0, sendAndConfirmWithDebug_1.default)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
56
57
|
return referralAccountPublicKey;
|
57
58
|
});
|
58
59
|
}
|
59
|
-
|
60
|
-
function referralClaimFeesInstruction(program, payerPublicKey, vaultSystemStatePublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, referralAccountPublicKey, referralStatePublicKey, hedgeMintPublicKey, hdgAssociatedTokenAccountPublicKey, ushMintPublicKey, ushAssociatedTokenAccountPublicKey, communityAssociatedHedgeTokenAccountPublicKey, feePoolPublicKey, feePoolAssociatedUshTokenAccountPublicKey) {
|
60
|
+
function referralClaimFeesInstruction(program, payerPublicKey, vaultSystemStatePublicKey, poolPositionPublicKey, referralAccountPublicKey, referralStatePublicKey, hedgeMintPublicKey, hdgAssociatedTokenAccountPublicKey, ushMintPublicKey, ushAssociatedTokenAccountPublicKey, communityAssociatedHedgeTokenAccountPublicKey, feePoolPublicKey, feePoolAssociatedUshTokenAccountPublicKey) {
|
61
61
|
return __awaiter(this, void 0, void 0, function* () {
|
62
|
-
const [poolPublickey] = yield (0, Constants_1.getCompoundPoolPublicKeyForMint)(program.programId, stakedTokenMintPublicKey);
|
63
62
|
return yield program.methods
|
64
63
|
.referralClaimFees()
|
65
64
|
.accounts({
|
@@ -73,8 +72,6 @@ function referralClaimFeesInstruction(program, payerPublicKey, vaultSystemStateP
|
|
73
72
|
ushMint: ushMintPublicKey,
|
74
73
|
signerUshAta: ushAssociatedTokenAccountPublicKey,
|
75
74
|
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccountPublicKey,
|
76
|
-
pool: poolPublickey,
|
77
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
78
75
|
feePool: feePoolPublicKey,
|
79
76
|
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccountPublicKey,
|
80
77
|
systemProgram: web3_js_1.SystemProgram.programId,
|
@@ -84,4 +81,3 @@ function referralClaimFeesInstruction(program, payerPublicKey, vaultSystemStateP
|
|
84
81
|
.instruction();
|
85
82
|
});
|
86
83
|
}
|
87
|
-
exports.referralClaimFeesInstruction = referralClaimFeesInstruction;
|