hedge-web3 0.1.29 → 0.1.33
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/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 +4 -4
- 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 +22 -24
- 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 -32
- 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 +19 -19
- 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 +42 -34
- 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 +80 -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 +42 -33
- 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
- package/tsconfig.json +1 -1
@@ -21,7 +21,7 @@ function depositLiquidationPool(program, provider, payer, depositAmount, overrid
|
|
21
21
|
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
22
22
|
const poolPosition = web3_js_1.Keypair.generate();
|
23
23
|
const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, payerUshAccount.address, poolPosition.publicKey, depositAmount, overrideStartTime));
|
24
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolPosition]
|
24
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolPosition]).catch(Errors_1.parseAnchorErrors);
|
25
25
|
return poolPosition.publicKey;
|
26
26
|
});
|
27
27
|
}
|
@@ -33,23 +33,22 @@ function depositLiquidationPoolInstruction(program, payerPublicKey, payerUshAcco
|
|
33
33
|
const poolUSHAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
34
34
|
const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
|
35
35
|
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
36
|
-
return program.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
});
|
36
|
+
return yield program.methods
|
37
|
+
.depositLiquidationPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
38
|
+
)
|
39
|
+
.accounts({
|
40
|
+
vaultSystemState: vaultSystemState,
|
41
|
+
poolState: liquidationPoolStatePublicKey,
|
42
|
+
poolUshAccount: poolUSHAccount,
|
43
|
+
poolEra: liquidationPoolState.currentEra,
|
44
|
+
poolPosition: poolPositionPublicKey,
|
45
|
+
ushMint: ushMint,
|
46
|
+
payer: payerPublicKey,
|
47
|
+
ownerUshAccount: payerUshAccount,
|
48
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
49
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
50
|
+
})
|
51
|
+
.instruction();
|
53
52
|
});
|
54
53
|
}
|
55
54
|
exports.depositLiquidationPoolInstruction = depositLiquidationPoolInstruction;
|
@@ -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 yield 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 yield 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;
|
@@ -9,14 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
9
9
|
});
|
10
10
|
};
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
|
-
exports.refreshOraclePriceInstruction = exports.refreshOraclePrice = void 0;
|
12
|
+
exports.Cluster = exports.refreshOraclePriceInstruction = exports.refreshOraclePrice = void 0;
|
13
13
|
const anchor_1 = require("@project-serum/anchor");
|
14
14
|
const web3_js_1 = require("@solana/web3.js");
|
15
15
|
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;
|
@@ -46,20 +46,20 @@ var Cluster;
|
|
46
46
|
Cluster["Testing"] = "Testing";
|
47
47
|
Cluster["Devnet"] = "Devnet";
|
48
48
|
Cluster["MainnetBeta"] = "MainnetBeta";
|
49
|
-
})(Cluster || (Cluster = {}));
|
49
|
+
})(Cluster = exports.Cluster || (exports.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;
|