hedge-web3 0.1.21 → 0.1.26
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 +3 -3
- package/declarations/idl/vault.d.ts +43 -43
- package/declarations/index.d.ts +1 -0
- package/declarations/instructions/claimStakingPoolPosition.d.ts +4 -0
- package/declarations/instructions/closeLiquidationPoolPosition.d.ts +1 -1
- package/declarations/instructions/createVault.d.ts +1 -1
- package/declarations/instructions/depositLiquidationPool.d.ts +1 -1
- package/declarations/instructions/depositVault.d.ts +1 -1
- package/declarations/instructions/liquidateVault.d.ts +1 -1
- package/declarations/instructions/loanVault.d.ts +1 -1
- package/declarations/instructions/redeemVault.d.ts +1 -1
- package/declarations/instructions/repayVault.d.ts +1 -1
- package/declarations/instructions/withdrawVault.d.ts +1 -1
- package/declarations/state/LiquidationPosition.d.ts +2 -2
- package/declarations/state/StakingPool.d.ts +2 -2
- package/declarations/state/StakingPoolPosition.d.ts +2 -2
- package/declarations/state/VaultAccount.d.ts +3 -3
- package/declarations/state/VaultHistoryEvent.d.ts +4 -4
- package/lib/Constants.js +8 -8
- package/lib/idl/idl.js +30 -30
- package/lib/idl/vault.js +43 -43
- package/lib/index.js +1 -0
- package/lib/instructions/claimStakingPoolPosition.js +55 -0
- package/lib/instructions/closeLiquidationPoolPosition.js +10 -10
- package/lib/instructions/createStakingPool.js +5 -5
- package/lib/instructions/createVault.js +12 -12
- package/lib/instructions/depositLiquidationPool.js +10 -10
- package/lib/instructions/depositStakingPool.js +1 -1
- package/lib/instructions/depositVault.js +8 -8
- package/lib/instructions/initHedgeFoundation.js +4 -4
- package/lib/instructions/liquidateVault.js +9 -9
- package/lib/instructions/loanVault.js +9 -9
- package/lib/instructions/redeemVault.js +10 -10
- package/lib/instructions/refreshOraclePrice.js +1 -1
- package/lib/instructions/repayVault.js +10 -10
- package/lib/instructions/withdrawStakingPool.js +7 -7
- package/lib/instructions/withdrawVault.js +8 -8
- package/lib/state/LiquidationPosition.js +2 -2
- package/lib/state/StakingPool.js +2 -2
- package/lib/state/StakingPoolPosition.js +3 -3
- package/lib/state/VaultAccount.js +2 -2
- package/lib/state/VaultHistoryEvent.js +4 -4
- package/package.json +9 -9
- package/src/Constants.ts +5 -5
- package/src/idl/idl.ts +30 -30
- package/src/idl/vault.ts +86 -86
- package/src/index.ts +1 -0
- package/src/instructions/claimStakingPoolPosition.ts +76 -0
- package/src/instructions/closeLiquidationPoolPosition.ts +11 -11
- package/src/instructions/createStakingPool.ts +6 -6
- package/src/instructions/createVault.ts +19 -18
- package/src/instructions/depositLiquidationPool.ts +11 -11
- package/src/instructions/depositStakingPool.ts +1 -1
- package/src/instructions/depositVault.ts +12 -12
- package/src/instructions/initHedgeFoundation.ts +5 -5
- package/src/instructions/initHedgeFoundationTokens.ts +1 -1
- package/src/instructions/liquidateVault.ts +10 -10
- package/src/instructions/loanVault.ts +11 -11
- package/src/instructions/redeemVault.ts +12 -12
- package/src/instructions/refreshOraclePrice.ts +1 -1
- package/src/instructions/repayVault.ts +12 -12
- package/src/instructions/setHalted.ts +1 -1
- package/src/instructions/withdrawStakingPool.ts +8 -8
- package/src/instructions/withdrawVault.ts +12 -12
- package/src/state/LiquidationPosition.ts +3 -3
- package/src/state/StakingPool.ts +4 -4
- package/src/state/StakingPoolPosition.ts +4 -4
- package/src/state/VaultAccount.ts +3 -3
- package/src/state/VaultHistoryEvent.ts +8 -8
@@ -17,39 +17,39 @@ const Errors_1 = require("../utils/Errors");
|
|
17
17
|
const Constants_1 = require("../Constants");
|
18
18
|
function closeLiquidationPoolPosition(program, provider, poolPosition, payer, overrideStartTime) {
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
20
|
-
const
|
21
|
-
const
|
20
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
21
|
+
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
22
22
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
23
23
|
const liquidationPositionAccount = yield program.account.liquidationPosition.fetch(poolPosition);
|
24
24
|
const poolEra = liquidationPositionAccount.era;
|
25
25
|
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
26
26
|
const payerAssociatedHedgeAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, payer.publicKey);
|
27
27
|
const communityAssociatedHedgeTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, hedgeMint, vaultSystemStatePublicKey, true);
|
28
|
-
const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey,
|
28
|
+
const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey, payerUshAccount.address, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, overrideStartTime));
|
29
29
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer], provider.opts).catch(Errors_1.parseAnchorErrors);
|
30
30
|
return poolPosition;
|
31
31
|
});
|
32
32
|
}
|
33
33
|
exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
|
34
|
-
function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey,
|
34
|
+
function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payerPublicKey, payerUshAccount, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime) {
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
36
36
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
37
|
-
const
|
37
|
+
const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
|
38
38
|
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
39
|
-
const
|
39
|
+
const poolUshAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
40
40
|
const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
41
|
-
return program.instruction.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
41
|
+
return program.instruction.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
|
42
42
|
{
|
43
43
|
accounts: {
|
44
44
|
vaultSystemState: vaultSystemStatePublicKey,
|
45
45
|
poolState: poolState,
|
46
46
|
poolEra: poolEra,
|
47
47
|
poolPosition: poolPosition,
|
48
|
-
|
48
|
+
poolUshAccount: poolUshAccount,
|
49
49
|
payer: payerPublicKey,
|
50
|
-
|
50
|
+
ownerUshAccount: payerUshAccount,
|
51
51
|
hedgeMint: hedgeMint,
|
52
|
-
|
52
|
+
ushMint: ushMint,
|
53
53
|
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
54
54
|
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
55
55
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -28,19 +28,19 @@ function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, he
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
29
29
|
console.log("createStakingPoolInstruction program ID", program.programId.toString());
|
30
30
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
31
|
-
const
|
31
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
32
32
|
const [poolPublickey, poolBump, poolSeedPhrase] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
33
33
|
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, mintPublicKey);
|
34
|
-
const
|
35
|
-
return program.instruction.createStakingPool(poolBump, poolSeedPhrase, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), {
|
34
|
+
const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
|
35
|
+
return program.instruction.createStakingPool(poolBump, poolSeedPhrase, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), {
|
36
36
|
accounts: {
|
37
37
|
signer: payerPublicKey,
|
38
38
|
vaultSystemState: vaultSystemStatePublicKey,
|
39
39
|
pool: poolPublickey,
|
40
40
|
stakedTokenMintInfo: mintPublicKey,
|
41
|
-
|
41
|
+
ushMint: ushMintPublickey,
|
42
42
|
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
43
|
-
|
43
|
+
poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
|
44
44
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
45
45
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
46
46
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -19,12 +19,12 @@ const uuid_1 = require("uuid");
|
|
19
19
|
const Errors_1 = require("../utils/Errors");
|
20
20
|
function createVault(program, provider, payer, collateralType, depositAmount, overrideTime) {
|
21
21
|
return __awaiter(this, void 0, void 0, function* () {
|
22
|
-
const
|
22
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
23
23
|
const salt = (0, uuid_1.v4)().substring(0, 8);
|
24
24
|
const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
|
25
25
|
const history = web3_js_1.Keypair.generate();
|
26
|
-
// Prep the user to get
|
27
|
-
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer,
|
26
|
+
// Prep the user to get USH back out at some point
|
27
|
+
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
28
28
|
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
29
29
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
30
30
|
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payer.publicKey, vaultTypeAccountInfo.collateralMint);
|
@@ -35,7 +35,7 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
|
|
35
35
|
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
36
36
|
serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
37
37
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
38
|
-
const
|
38
|
+
const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
39
39
|
if (isWrappedSol) {
|
40
40
|
transaction.add(web3_js_1.SystemProgram.createAccount({
|
41
41
|
fromPubkey: payer.publicKey,
|
@@ -50,7 +50,7 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
|
|
50
50
|
}));
|
51
51
|
signers.push(wrappedSolAccount);
|
52
52
|
}
|
53
|
-
transaction.add(yield createVaultInstruction(program, salt, payer.publicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey,
|
53
|
+
transaction.add(yield createVaultInstruction(program, salt, payer.publicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, depositAmount, overrideTime));
|
54
54
|
if (isWrappedSol) {
|
55
55
|
transaction.add(serum_1.TokenInstructions.closeAccount({
|
56
56
|
source: wrappedSolAccount.publicKey,
|
@@ -66,7 +66,7 @@ exports.createVault = createVault;
|
|
66
66
|
function buildCreateVaultTransaction(program, collateralType, depositAmount, overrideTime) {
|
67
67
|
return __awaiter(this, void 0, void 0, function* () {
|
68
68
|
console.log("HEDGE SDK: buildCreateVaultTransaction");
|
69
|
-
const
|
69
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
70
70
|
const payerPublicKey = program.provider.wallet.publicKey;
|
71
71
|
const salt = (0, uuid_1.v4)().substring(0, 8);
|
72
72
|
const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
|
@@ -89,7 +89,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
|
|
89
89
|
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, vaultTypeAccountInfo.collateralMint);
|
90
90
|
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
91
91
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
92
|
-
const
|
92
|
+
const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
93
93
|
console.log('about to start building transaction');
|
94
94
|
// If wrapped SOL collateral, we convert the SOL to wSOL to use in the instruction
|
95
95
|
if (isWrappedSol) {
|
@@ -107,22 +107,22 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
|
|
107
107
|
signers.push(wrappedSolAccount);
|
108
108
|
}
|
109
109
|
console.log("hedgeStakingPoolPublicKey", hedgeStakingPoolPublicKey.toString());
|
110
|
-
transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey,
|
110
|
+
transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, depositAmount, overrideTime));
|
111
111
|
if (isWrappedSol) {
|
112
112
|
transaction.add(serum_1.TokenInstructions.closeAccount({
|
113
113
|
source: wrappedSolAccount.publicKey,
|
114
114
|
destination: payerPublicKey,
|
115
115
|
owner: payerPublicKey,
|
116
116
|
}));
|
117
|
+
transaction.partialSign(wrappedSolAccount);
|
117
118
|
}
|
118
|
-
transaction.partialSign(wrappedSolAccount);
|
119
119
|
transaction.partialSign(history);
|
120
120
|
console.log("transaction", transaction);
|
121
121
|
return [transaction, signers, newVaultPublicKey];
|
122
122
|
});
|
123
123
|
}
|
124
124
|
exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
|
125
|
-
function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool,
|
125
|
+
function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUshTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, ushMintPublickey, depositAmount, overrideTime) {
|
126
126
|
return __awaiter(this, void 0, void 0, function* () {
|
127
127
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
128
128
|
const ix = program.instruction.createVault(salt, new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
@@ -133,12 +133,12 @@ function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccount
|
|
133
133
|
vault: vaultPublicKey,
|
134
134
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
135
135
|
feePool: feePool,
|
136
|
-
|
136
|
+
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
137
137
|
history: historyPublicKey,
|
138
138
|
payer: payerPublicKey,
|
139
139
|
payerTokenAccount: payerTokenAccountPublicKey,
|
140
140
|
collateralMint: collateralMint,
|
141
|
-
|
141
|
+
ushMint: ushMintPublickey,
|
142
142
|
systemProgram: web3_js_1.SystemProgram.programId,
|
143
143
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
144
144
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
@@ -17,33 +17,33 @@ const Errors_1 = require("../utils/Errors");
|
|
17
17
|
const Constants_1 = require("../Constants");
|
18
18
|
function depositLiquidationPool(program, provider, payer, depositAmount, overrideStartTime) {
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
20
|
-
const
|
21
|
-
const
|
20
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
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
|
-
const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey,
|
23
|
+
const transaction = new web3_js_1.Transaction().add(yield depositLiquidationPoolInstruction(program, payer.publicKey, payerUshAccount.address, poolPosition.publicKey, depositAmount, overrideStartTime));
|
24
24
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, poolPosition], provider.opts).catch(Errors_1.parseAnchorErrors);
|
25
25
|
return poolPosition.publicKey;
|
26
26
|
});
|
27
27
|
}
|
28
28
|
exports.depositLiquidationPool = depositLiquidationPool;
|
29
|
-
function depositLiquidationPoolInstruction(program, payerPublicKey,
|
29
|
+
function depositLiquidationPoolInstruction(program, payerPublicKey, payerUshAccount, poolPositionPublicKey, depositAmount, overrideStartTime) {
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
31
31
|
const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
32
32
|
const liquidationPoolState = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
33
|
-
const
|
34
|
-
const
|
33
|
+
const poolUSHAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
34
|
+
const ushMint = yield (0, Constants_1.getUshMintPublicKey)();
|
35
35
|
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
36
|
-
return program.instruction.depositLiquidationPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
36
|
+
return program.instruction.depositLiquidationPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
|
37
37
|
{
|
38
38
|
accounts: {
|
39
39
|
vaultSystemState: vaultSystemState,
|
40
40
|
poolState: liquidationPoolStatePublicKey,
|
41
41
|
poolEra: liquidationPoolState.currentEra,
|
42
42
|
poolPosition: poolPositionPublicKey,
|
43
|
-
|
44
|
-
|
43
|
+
poolUshAccount: poolUSHAccount,
|
44
|
+
ushMint: ushMint,
|
45
45
|
payer: payerPublicKey,
|
46
|
-
|
46
|
+
ownerUshAccount: payerUshAccount,
|
47
47
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
48
48
|
systemProgram: web3_js_1.SystemProgram.programId,
|
49
49
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY
|
@@ -30,7 +30,7 @@ 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.instruction.depositStakingPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
33
|
+
return program.instruction.depositStakingPool(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
|
34
34
|
{
|
35
35
|
accounts: {
|
36
36
|
payer: payerPublicKey,
|
@@ -17,9 +17,9 @@ const web3_js_1 = require("@solana/web3.js");
|
|
17
17
|
const Constants_1 = require("../Constants");
|
18
18
|
function depositVault(program, provider, payer, vaultPublicKey, depositAmount, overrideTime) {
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
20
|
-
const
|
21
|
-
// Prep the user to get
|
22
|
-
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer,
|
20
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
21
|
+
// Prep the user to get USH back out at some point
|
22
|
+
yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
23
23
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
24
24
|
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
25
25
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
@@ -30,7 +30,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
30
30
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
31
31
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
32
32
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
33
|
-
const
|
33
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
34
34
|
const transaction = new web3_js_1.Transaction();
|
35
35
|
const signers = [payer, history];
|
36
36
|
if (vaultAccount.collateralType === 'SOL') {
|
@@ -47,7 +47,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
47
47
|
}));
|
48
48
|
signers.push(wrappedSolAccount);
|
49
49
|
}
|
50
|
-
transaction.add(yield depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount.address, hedgeStakingPoolPublicKey,
|
50
|
+
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, depositAmount, overrideTime));
|
51
51
|
if (vaultAccount.collateralType === 'SOL') {
|
52
52
|
transaction.add(serum_1.TokenInstructions.closeAccount({
|
53
53
|
source: wrappedSolAccount.publicKey,
|
@@ -60,7 +60,7 @@ function depositVault(program, provider, payer, vaultPublicKey, depositAmount, o
|
|
60
60
|
});
|
61
61
|
}
|
62
62
|
exports.depositVault = depositVault;
|
63
|
-
function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey,
|
63
|
+
function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccountPublicKey, vaultTypeAssociatedTokenAccount, hedgeStakingPoolPublicKey, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, ushMintPublickey, depositAmount, overrideTime) {
|
64
64
|
return __awaiter(this, void 0, void 0, function* () {
|
65
65
|
return program.instruction.depositVault(new anchor_1.BN(depositAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
66
66
|
{
|
@@ -72,11 +72,11 @@ function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner,
|
|
72
72
|
vault: vaultPublicKey,
|
73
73
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
74
74
|
feePool: hedgeStakingPoolPublicKey,
|
75
|
-
|
75
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
76
76
|
history: historyPublicKey,
|
77
77
|
vaultOwner: vaultOwner,
|
78
78
|
vaultOwnerTokenAccount: vaultOwnerTokenAccount,
|
79
|
-
|
79
|
+
ushMint: ushMintPublickey,
|
80
80
|
systemProgram: web3_js_1.SystemProgram.programId,
|
81
81
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID
|
82
82
|
},
|
@@ -27,8 +27,8 @@ function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKe
|
|
27
27
|
return __awaiter(this, void 0, void 0, function* () {
|
28
28
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
29
29
|
const poolStatePublickey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
30
|
-
const
|
31
|
-
const
|
30
|
+
const poolUshTokenAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
31
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
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);
|
@@ -37,9 +37,9 @@ function initHedgeFoundationInstruction(program, poolEraPublicKey, payerPublicKe
|
|
37
37
|
vaultSystemState: vaultSystemStatePublicKey,
|
38
38
|
poolState: poolStatePublickey,
|
39
39
|
poolEra: poolEraPublicKey,
|
40
|
-
|
40
|
+
poolUshAccount: poolUshTokenAccount,
|
41
41
|
founder: payerPublicKey,
|
42
|
-
|
42
|
+
ushMint: ushMintPublickey,
|
43
43
|
hedgeMint: hedgeMintPublickey,
|
44
44
|
founderAssociatedHedgeTokenAccount: founderHedgeTokenAccount,
|
45
45
|
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
@@ -21,7 +21,7 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
|
|
21
21
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
22
22
|
const collateralMint = vaultTypeAccountInfo.collateralMint;
|
23
23
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
24
|
-
const
|
24
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
25
25
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
26
26
|
const liquidationPoolStatePublicKey = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
27
27
|
const poolStateInfo = yield program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
@@ -30,21 +30,21 @@ function liquidateVault(program, provider, payer, vaultPublicKey, overrideTime)
|
|
30
30
|
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultPublicKey, true);
|
31
31
|
const poolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, liquidationPoolStatePublicKey, true);
|
32
32
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, vaultTypeAccountPublicKey, true);
|
33
|
-
const
|
33
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, hedgeStakingPoolPublicKey, true);
|
34
34
|
const history = web3_js_1.Keypair.generate();
|
35
35
|
const newEra = web3_js_1.Keypair.generate();
|
36
36
|
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,
|
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
38
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history, newEra], provider.opts);
|
39
39
|
return vaultPublicKey;
|
40
40
|
});
|
41
41
|
}
|
42
42
|
exports.liquidateVault = liquidateVault;
|
43
|
-
function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount,
|
43
|
+
function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, hedgeStakingPoolAssociatedUshTokenAccount, collateralMint, vaultTypeAssociatedTokenAccount, collateralType, overrideTime) {
|
44
44
|
return __awaiter(this, void 0, void 0, function* () {
|
45
45
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
46
|
-
const
|
47
|
-
const
|
46
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
47
|
+
const liquidationPoolUshAccountPublickey = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
48
48
|
const vaultTypeAccount = yield (0, Constants_1.getVaultTypeAccountPublicKey)(collateralType);
|
49
49
|
const payload = {
|
50
50
|
accounts: {
|
@@ -57,14 +57,14 @@ function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedToken
|
|
57
57
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
58
58
|
poolState: poolState,
|
59
59
|
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
60
|
-
|
60
|
+
ushMint: ushMintPublickey,
|
61
61
|
history: historyPublicKey,
|
62
62
|
payer: payerPublicKey,
|
63
63
|
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
64
64
|
feePool: feePool,
|
65
65
|
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
66
|
-
|
67
|
-
|
66
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
67
|
+
liquidationPoolUshAccount: liquidationPoolUshAccountPublickey,
|
68
68
|
newEra: newEraPublicKey,
|
69
69
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
70
70
|
systemProgram: web3_js_1.SystemProgram.programId,
|
@@ -16,27 +16,27 @@ const web3_js_1 = require("@solana/web3.js");
|
|
16
16
|
const Constants_1 = require("../Constants");
|
17
17
|
function loanVault(program, provider, payer, vaultPublicKey, loanAmount, overrideTime) {
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
19
|
-
const
|
20
|
-
const
|
19
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
20
|
+
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
21
21
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
22
22
|
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
23
23
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
24
24
|
const vaultTypeAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultTypeAccountPublicKey, true);
|
25
25
|
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccount.collateralMint, vaultPublicKey, true);
|
26
26
|
const history = web3_js_1.Keypair.generate();
|
27
|
-
const transaction = new web3_js_1.Transaction().add(yield loanVaultInstruction(program, payer.publicKey,
|
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
28
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
29
29
|
return vaultPublicKey;
|
30
30
|
});
|
31
31
|
}
|
32
32
|
exports.loanVault = loanVault;
|
33
|
-
function loanVaultInstruction(program, payerPublicKey,
|
33
|
+
function loanVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, loanAmount, overrideTime) {
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
35
35
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
36
|
-
const
|
36
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
37
37
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
38
38
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
39
|
-
const
|
39
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
40
40
|
return program.instruction.loanVault(new anchor_1.BN(loanAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
41
41
|
{
|
42
42
|
accounts: {
|
@@ -47,10 +47,10 @@ function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPu
|
|
47
47
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
48
48
|
history: historyPublicKey,
|
49
49
|
feePool: hedgeStakingPoolPublicKey,
|
50
|
-
|
51
|
-
|
50
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
51
|
+
ushMint: ushMintPublickey,
|
52
52
|
vaultOwner: payerPublicKey,
|
53
|
-
|
53
|
+
ownerUshAccount: ownerUshAccount,
|
54
54
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
55
55
|
systemProgram: web3_js_1.SystemProgram.programId
|
56
56
|
},
|
@@ -17,9 +17,9 @@ const web3_js_1 = require("@solana/web3.js");
|
|
17
17
|
const Constants_1 = require("../Constants");
|
18
18
|
function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
20
|
-
const
|
21
|
-
// Prep the user to get
|
22
|
-
const
|
20
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
21
|
+
// Prep the user to get USH back out at some point
|
22
|
+
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
23
23
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
24
24
|
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
25
25
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
@@ -27,19 +27,19 @@ function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, tra
|
|
27
27
|
const vaultAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, vaultPublicKey, true);
|
28
28
|
const payerTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, vaultTypeAccountInfo.collateralMint, payer.publicKey);
|
29
29
|
const history = web3_js_1.Keypair.generate();
|
30
|
-
const transaction = new web3_js_1.Transaction().add(yield redeemVaultInstruction(program, payer.publicKey,
|
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
31
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
32
32
|
return vaultPublicKey;
|
33
33
|
});
|
34
34
|
}
|
35
35
|
exports.redeemVault = redeemVault;
|
36
|
-
function redeemVaultInstruction(program, payerPublicKey,
|
36
|
+
function redeemVaultInstruction(program, payerPublicKey, payerUshAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, redeemAmount, transactionOverrideTime) {
|
37
37
|
return __awaiter(this, void 0, void 0, function* () {
|
38
38
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
39
|
-
const
|
39
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
40
40
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
41
41
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
42
|
-
const
|
42
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
43
43
|
return program.instruction.redeemVault(new anchor_1.BN(redeemAmount), new anchor_1.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
|
44
44
|
{
|
45
45
|
accounts: {
|
@@ -50,10 +50,10 @@ function redeemVaultInstruction(program, payerPublicKey, payerUsdhAccount, desti
|
|
50
50
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
51
51
|
history: historyPublicKey,
|
52
52
|
feePool: hedgeStakingPoolPublicKey,
|
53
|
-
|
54
|
-
|
53
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
54
|
+
ushMint: ushMintPublickey,
|
55
55
|
payer: payerPublicKey,
|
56
|
-
|
56
|
+
payerUshAccount: payerUshAccount,
|
57
57
|
destinationTokenAccount: destinationTokenAccount,
|
58
58
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
59
59
|
systemProgram: web3_js_1.SystemProgram.programId
|
@@ -26,7 +26,7 @@ function refreshOraclePriceInstruction(program, collateralType, network, overrid
|
|
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
28
|
return program.instruction.refreshOraclePrice(new anchor_1.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js_1.LAMPORTS_PER_SOL * 150), // override usd/sol price
|
29
|
-
new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
29
|
+
new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000) - 1), // override override time
|
30
30
|
{
|
31
31
|
accounts: {
|
32
32
|
oracleInfoAccount: oracleInfoAccount,
|
@@ -16,28 +16,28 @@ const web3_js_1 = require("@solana/web3.js");
|
|
16
16
|
const Constants_1 = require("../Constants");
|
17
17
|
function repayVault(program, provider, payer, vaultPublicKey, repayAmount, overrideTime) {
|
18
18
|
return __awaiter(this, void 0, void 0, function* () {
|
19
|
-
const
|
20
|
-
// Prep the user to get
|
21
|
-
const
|
19
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
20
|
+
// Prep the user to get USH back out at some point
|
21
|
+
const payerUshAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, ushMintPublickey, payer.publicKey);
|
22
22
|
const vaultAccount = yield program.account.vault.fetch(vaultPublicKey);
|
23
23
|
const vaultTypeAccountPublicKey = yield (0, Constants_1.getVaultTypeAccountPublicKey)(vaultAccount.collateralType);
|
24
24
|
const vaultTypeAccount = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
25
25
|
const vaultTypeAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultTypeAccountPublicKey, vaultTypeAccount.collateralMint);
|
26
26
|
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultPublicKey, vaultTypeAccount.collateralMint);
|
27
27
|
const history = web3_js_1.Keypair.generate();
|
28
|
-
const transaction = new web3_js_1.Transaction().add(yield repayVaultInstruction(program, payer.publicKey,
|
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
29
|
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer, history], provider.opts);
|
30
30
|
return vaultPublicKey;
|
31
31
|
});
|
32
32
|
}
|
33
33
|
exports.repayVault = repayVault;
|
34
|
-
function repayVaultInstruction(program, payerPublicKey,
|
34
|
+
function repayVaultInstruction(program, payerPublicKey, ownerUshAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, vaultTypeAccount, vaultTypeAssociatedTokenAccount, repayAmount, overrideTime) {
|
35
35
|
return __awaiter(this, void 0, void 0, function* () {
|
36
36
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
37
|
-
const
|
37
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
38
38
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
39
39
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(hedgeMintPublickey);
|
40
|
-
const
|
40
|
+
const hedgeStakingPoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
41
41
|
return program.instruction.repayVault(new anchor_1.BN(repayAmount), new anchor_1.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
42
42
|
{
|
43
43
|
accounts: {
|
@@ -48,10 +48,10 @@ function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultP
|
|
48
48
|
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
49
49
|
history: historyPublicKey,
|
50
50
|
feePool: hedgeStakingPoolPublicKey,
|
51
|
-
|
52
|
-
|
51
|
+
feePoolAssociatedUshTokenAccount: hedgeStakingPoolAssociatedUshTokenAccount,
|
52
|
+
ushMint: ushMintPublickey,
|
53
53
|
vaultOwner: payerPublicKey,
|
54
|
-
|
54
|
+
ownerUshAccount: ownerUshAccount,
|
55
55
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
56
56
|
systemProgram: web3_js_1.SystemProgram.programId
|
57
57
|
},
|
@@ -27,16 +27,16 @@ exports.withdrawStakingPool = withdrawStakingPool;
|
|
27
27
|
function withdrawStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
29
29
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
30
|
-
const
|
30
|
+
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
31
31
|
const hedgeMintPublickey = yield (0, Constants_1.getHedgeMintPublicKey)();
|
32
32
|
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(stakedTokenMintPublicKey);
|
33
33
|
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, stakedTokenMintPublicKey);
|
34
|
-
const
|
34
|
+
const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
|
35
35
|
const payerAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, stakedTokenMintPublicKey);
|
36
36
|
const payerAssociatedHedgeAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, hedgeMintPublickey);
|
37
|
-
const
|
37
|
+
const payerAssociatedUshAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, ushMintPublickey);
|
38
38
|
const communityHedgeTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(vaultSystemStatePublicKey, hedgeMintPublickey);
|
39
|
-
return program.instruction.withdrawStakingPool(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
39
|
+
return program.instruction.withdrawStakingPool(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)), // override current time
|
40
40
|
{
|
41
41
|
accounts: {
|
42
42
|
payer: payerPublicKey,
|
@@ -44,14 +44,14 @@ function withdrawStakingPoolInstruction(program, payerPublicKey, poolPositionPub
|
|
44
44
|
pool: poolPublickey,
|
45
45
|
poolPosition: poolPositionPublicKey,
|
46
46
|
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
47
|
-
|
47
|
+
poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
|
48
48
|
payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
|
49
49
|
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
50
|
-
|
50
|
+
payerAssociatedUshAccount: payerAssociatedUshAccount,
|
51
51
|
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
52
52
|
hedgeMint: hedgeMintPublickey,
|
53
53
|
stakedTokenMint: stakedTokenMintPublicKey,
|
54
|
-
|
54
|
+
ushMint: ushMintPublickey,
|
55
55
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
56
56
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
57
57
|
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|