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