hedge-web3 0.1.29 → 0.1.31
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/idl/vault.d.ts +99 -99
- package/declarations/index.d.ts +1 -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 +3 -2
- package/declarations/instructions/withdrawStakingPool.d.ts +3 -2
- package/declarations/instructions/withdrawVault.d.ts +3 -2
- package/declarations/state/VaultAccount.d.ts +1 -1
- package/declarations/utils/getLinkedListAccounts.d.ts +3 -1
- package/lib/idl/vault.js +99 -99
- package/lib/index.js +1 -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 +17 -18
- 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 +25 -27
- package/lib/instructions/initHedgeFoundation.js +17 -19
- package/lib/instructions/initHedgeFoundationTokens.js +15 -15
- package/lib/instructions/liquidateVault.js +32 -33
- package/lib/instructions/loanVault.js +23 -23
- package/lib/instructions/redeemVault.js +24 -24
- package/lib/instructions/refreshOraclePrice.js +17 -17
- package/lib/instructions/repayVault.js +23 -23
- package/lib/instructions/setHalted.js +8 -9
- package/lib/instructions/setVaultTypeStatus.js +9 -10
- package/lib/instructions/withdrawStakingPool.js +22 -24
- package/lib/instructions/withdrawVault.js +23 -23
- 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 +2 -5
- package/lib/utils/getLinkedListAccounts.js +24 -16
- package/package.json +2 -2
- package/src/idl/vault.ts +198 -198
- package/src/index.ts +1 -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 +37 -35
- 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 +57 -86
- package/src/instructions/initHedgeFoundation.ts +42 -43
- package/src/instructions/initHedgeFoundationTokens.ts +38 -39
- package/src/instructions/liquidateVault.ts +42 -65
- package/src/instructions/loanVault.ts +51 -69
- package/src/instructions/redeemVault.ts +83 -47
- package/src/instructions/refreshOraclePrice.ts +41 -32
- package/src/instructions/repayVault.ts +45 -65
- package/src/instructions/setHalted.ts +32 -24
- package/src/instructions/setVaultTypeStatus.ts +32 -24
- package/src/instructions/withdrawStakingPool.ts +44 -30
- package/src/instructions/withdrawVault.ts +58 -82
- 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 +9 -28
- package/src/state/VaultHistoryEvent.ts +1 -2
- package/src/utils/getLinkedListAccounts.ts +31 -30
@@ -19,7 +19,7 @@ function depositStakingPool(program, provider, payer, mintPublicKey, depositAmou
|
|
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 depositStakingPoolInstruction(program, payer.publicKey, poolPosition.publicKey, mintPublicKey, depositAmount, overrideStartTime));
|
22
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolPosition]
|
22
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolPosition]).catch(Errors_1.parseAnchorErrors);
|
23
23
|
return poolPosition.publicKey;
|
24
24
|
});
|
25
25
|
}
|
@@ -30,23 +30,21 @@ function depositStakingPoolInstruction(program, payerPublicKey, poolPositionPubl
|
|
30
30
|
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, stakedTokenMintPublicKey);
|
31
31
|
const payersArbitraryTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, stakedTokenMintPublicKey);
|
32
32
|
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
33
|
-
return program.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
signers: []
|
49
|
-
});
|
33
|
+
return yield program.methods
|
34
|
+
.depositStakingPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
35
|
+
)
|
36
|
+
.accounts({
|
37
|
+
payer: payerPublicKey,
|
38
|
+
vaultSystemState: vaultSystemState,
|
39
|
+
pool: poolPublickey,
|
40
|
+
poolPosition: poolPositionPublicKey,
|
41
|
+
stakedTokenMintInfo: stakedTokenMintPublicKey,
|
42
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
43
|
+
payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
|
44
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
45
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
46
|
+
})
|
47
|
+
.instruction();
|
50
48
|
});
|
51
49
|
}
|
52
50
|
exports.depositStakingPoolInstruction = depositStakingPoolInstruction;
|
@@ -49,9 +49,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
49
49
|
}));
|
50
50
|
signers.push(wrappedSolAccount);
|
51
51
|
}
|
52
|
-
transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL'
|
53
|
-
? wrappedSolAccount.publicKey
|
54
|
-
: payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime));
|
52
|
+
transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, vaultTypeAccountInfo.collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime));
|
55
53
|
if (vaultAccount.collateralType === 'SOL') {
|
56
54
|
transaction.add(serum_1.TokenInstructions.closeAccount({
|
57
55
|
source: wrappedSolAccount.publicKey,
|
@@ -59,36 +57,36 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
59
57
|
owner: payer.publicKey,
|
60
58
|
}));
|
61
59
|
}
|
62
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, signers
|
60
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, signers);
|
63
61
|
return vaultPublicKey;
|
64
62
|
});
|
65
63
|
}
|
66
64
|
exports.depositVault = depositVault;
|
67
65
|
function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, ushMintPublickey, oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey, depositAmount, overrideTime) {
|
68
66
|
return __awaiter(this, void 0, void 0, function* () {
|
69
|
-
return program.
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
67
|
+
return yield program.methods
|
68
|
+
.depositVault(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)) // override override time
|
69
|
+
)
|
70
|
+
.accounts({
|
71
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
72
|
+
vaultTypeAccount: vaultTypeAccountPublicKey,
|
73
|
+
vaultTypeAssociatedTokenAccount: vaultTypeAssociatedTokenAccount,
|
74
|
+
collateralTokenMint: collateralMint,
|
75
|
+
vault: vaultPublicKey,
|
76
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
77
|
+
feePool: hedgeStakingPoolPublicKey,
|
78
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
79
|
+
history: historyPublicKey,
|
80
|
+
vaultOwner: vaultOwner,
|
81
|
+
vaultOwnerTokenAccount: vaultOwnerTokenAccount,
|
82
|
+
ushMint: ushMintPublickey,
|
83
|
+
oldSmallerVaultInfo: oldSmallerPublicKey,
|
84
|
+
newSmallerVaultInfo: newSmallerPublicKey,
|
85
|
+
newLargerVaultInfo: newLargerPublicKey,
|
86
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
87
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
88
|
+
})
|
89
|
+
.instruction();
|
92
90
|
});
|
93
91
|
}
|
94
92
|
exports.depositVaultInstruction = depositVaultInstruction;
|
@@ -18,7 +18,7 @@ function initHedgeFoundation(program, provider, payer) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
19
19
|
const poolEra = web3_js_1.Keypair.generate();
|
20
20
|
const transaction = new web3_js_1.Transaction().add(yield initHedgeFoundationInstruction(program, poolEra.publicKey, payer.publicKey));
|
21
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolEra]
|
21
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolEra]).catch(Errors_1.parseAnchorErrors);
|
22
22
|
return payer.publicKey;
|
23
23
|
});
|
24
24
|
}
|
@@ -32,24 +32,22 @@ function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKe
|
|
32
32
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
33
33
|
const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
|
34
34
|
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
|
35
|
-
return program.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
signers: []
|
52
|
-
});
|
35
|
+
return yield program.methods
|
36
|
+
.initHedgeFoundation()
|
37
|
+
.accounts({
|
38
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
39
|
+
poolState: poolStatePublickey,
|
40
|
+
poolEra: poolEraPublicKey,
|
41
|
+
poolUshAccount: poolUshTokenAccount,
|
42
|
+
founder: payerPublicKey,
|
43
|
+
ushMint: ushMintPublickey,
|
44
|
+
hedgeMint: hedgeMintPublickey,
|
45
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
46
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
47
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
48
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
49
|
+
})
|
50
|
+
.instruction();
|
53
51
|
});
|
54
52
|
}
|
55
53
|
exports.initHedgeFoundationInstruction = initHedgeFoundationInstruction;
|
@@ -18,7 +18,7 @@ function initHedgeFoundationTokens(program, provider, payer) {
|
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
19
19
|
const poolEra = web3_js_1.Keypair.generate();
|
20
20
|
const transaction = new web3_js_1.Transaction().add(yield initHedgeFoundationTokensInstruction(program, payer.publicKey));
|
21
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]
|
21
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
22
22
|
return payer.publicKey;
|
23
23
|
});
|
24
24
|
}
|
@@ -29,20 +29,20 @@ function initHedgeFoundationTokensInstruction(program, payerPublicKey) {
|
|
29
29
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
30
30
|
const founderHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
|
31
31
|
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
|
32
|
-
return program.
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
32
|
+
return yield program.methods
|
33
|
+
.initHedgeFoundationTokens()
|
34
|
+
.accounts({
|
35
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
36
|
+
founder: payerPublicKey,
|
37
|
+
hedgeMint: hedgeMintPublickey,
|
38
|
+
founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
|
39
|
+
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
40
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
41
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
42
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
43
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
44
|
+
})
|
45
|
+
.instruction();
|
46
46
|
});
|
47
47
|
}
|
48
48
|
exports.initHedgeFoundationTokensInstruction = initHedgeFoundationTokensInstruction;
|
@@ -37,7 +37,7 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
|
|
37
37
|
const newEra = web3_js_1.Keypair.generate();
|
38
38
|
const transaction = new web3_js_1.Transaction();
|
39
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]
|
40
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra]);
|
41
41
|
return vaultPublicKey;
|
42
42
|
});
|
43
43
|
}
|
@@ -48,38 +48,37 @@ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedToken
|
|
48
48
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
49
49
|
const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
50
50
|
const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
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
|
-
|
78
|
-
|
79
|
-
|
80
|
-
}
|
81
|
-
|
82
|
-
payload);
|
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();
|
83
82
|
});
|
84
83
|
}
|
85
84
|
exports.liquidateVaultInstruction = liquidateVaultInstruction;
|
@@ -27,7 +27,7 @@ function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrid
|
|
27
27
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, loanAmount, false, false);
|
28
28
|
const history = web3_js_1.Keypair.generate();
|
29
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]
|
30
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
|
31
31
|
return vaultPublicKey;
|
32
32
|
});
|
33
33
|
}
|
@@ -39,28 +39,28 @@ function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPub
|
|
39
39
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
40
40
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
41
41
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
42
|
-
return program.
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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();
|
64
64
|
});
|
65
65
|
}
|
66
66
|
exports.loanVaultInstruction = loanVaultInstruction;
|
@@ -30,7 +30,7 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
|
|
30
30
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, 0, true, false);
|
31
31
|
const history = web3_js_1.Keypair.generate();
|
32
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]
|
33
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
|
34
34
|
return vaultPublicKey;
|
35
35
|
});
|
36
36
|
}
|
@@ -42,29 +42,29 @@ function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destin
|
|
42
42
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
43
43
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
44
44
|
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
45
|
-
return program.
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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();
|
68
68
|
});
|
69
69
|
}
|
70
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
|
};
|
@@ -28,7 +28,7 @@ function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overr
|
|
28
28
|
const [oldSmallerPublicKey, newSmallerPublicKey, newLargerPublicKey] = yield (0, getLinkedListAccounts_1.getLinkedListAccounts)(program, provider, vaultTypeAccountPublicKey, vaultPublicKey, 0, repayAmount * -1, false, false);
|
29
29
|
const history = web3_js_1.Keypair.generate();
|
30
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]
|
31
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history]);
|
32
32
|
return vaultPublicKey;
|
33
33
|
});
|
34
34
|
}
|
@@ -40,28 +40,28 @@ function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPu
|
|
40
40
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
41
41
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
42
42
|
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
|
-
|
63
|
-
|
64
|
-
|
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();
|
65
65
|
});
|
66
66
|
}
|
67
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;
|
@@ -17,22 +17,21 @@ function setVaultTypeStatus(program, provider, payer, vaultTypeAccount, deprecat
|
|
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 setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultTypeAccount, deprecated));
|
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.setVaultTypeStatus = setVaultTypeStatus;
|
25
25
|
function setVaultTypeStatusInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultTypeAccount, deprecated) {
|
26
26
|
return __awaiter(this, void 0, void 0, function* () {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
return ix;
|
27
|
+
return yield program.methods
|
28
|
+
.setVaultTypeStatus(deprecated)
|
29
|
+
.accounts({
|
30
|
+
payer: payerPublicKey,
|
31
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
32
|
+
vaultType: vaultTypeAccount,
|
33
|
+
})
|
34
|
+
.instruction();
|
36
35
|
});
|
37
36
|
}
|
38
37
|
exports.setVaultTypeStatusInstruction = setVaultTypeStatusInstruction;
|