hedge-web3 0.1.28 → 0.1.32
Sign up to get free protection for your applications and to get access to all the features.
- package/declarations/idl/vault.d.ts +277 -126
- 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 +277 -126
- 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 +1 -1
- package/src/idl/vault.ts +554 -252
- 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
@@ -24,7 +24,7 @@ function claimStakingPoolPosition(program, provider, poolPosition, payer, collat
|
|
24
24
|
const feePoolAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, feePool, true);
|
25
25
|
const payerAssociatedTokenAccount = yield (0, spl_token_1.getOrCreateAssociatedTokenAccount)(provider.connection, payer, collateralMint, payer.publicKey);
|
26
26
|
const transaction = new web3_js_1.Transaction().add(yield claimStakingPoolPositionInstruction(program, feePool, feePoolAssociatedTokenAccount.address, stakedTokenMint, vaultTypeAccount, collateralMint, poolPosition, payer.publicKey, payerAssociatedTokenAccount.address));
|
27
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]
|
27
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
28
28
|
return payerAssociatedTokenAccount.address;
|
29
29
|
});
|
30
30
|
}
|
@@ -32,24 +32,24 @@ exports.claimStakingPoolPosition = claimStakingPoolPosition;
|
|
32
32
|
function claimStakingPoolPositionInstruction(program, feePool, feePoolAssociatedTokenAccount, stakedTokenMint, vaultTypeAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount) {
|
33
33
|
return __awaiter(this, void 0, void 0, function* () {
|
34
34
|
const vaultSystemState = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
35
|
-
return program.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
35
|
+
return yield program.methods
|
36
|
+
.claimStakingPoolPosition()
|
37
|
+
.accounts({
|
38
|
+
vaultSystemState: vaultSystemState,
|
39
|
+
feePool: feePool,
|
40
|
+
stakedTokenMint: stakedTokenMint,
|
41
|
+
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
42
|
+
vaultTypeAccount: vaultTypeAccount,
|
43
|
+
collateralMint: collateralMint,
|
44
|
+
poolPosition: poolPosition,
|
45
|
+
payer: payer,
|
46
|
+
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
47
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
48
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
49
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
50
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
51
|
+
})
|
52
|
+
.instruction();
|
53
53
|
});
|
54
54
|
}
|
55
55
|
exports.claimStakingPoolPositionInstruction = claimStakingPoolPositionInstruction;
|
@@ -26,7 +26,7 @@ function closeLiquidationPoolPosition(program, provider, poolPosition, payer, ov
|
|
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
28
|
const transaction = new web3_js_1.Transaction().add(yield closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition, payer.publicKey, payerUshAccount.address, payerAssociatedHedgeAccount.address, communityAssociatedHedgeTokenAccount.address, overrideStartTime));
|
29
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]
|
29
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, [payer]).catch(Errors_1.parseAnchorErrors);
|
30
30
|
return poolPosition;
|
31
31
|
});
|
32
32
|
}
|
@@ -38,27 +38,27 @@ function closeLiquidationPoolPositionInstruction(program, poolEra, poolPosition,
|
|
38
38
|
const hedgeMint = yield (0, Constants_1.getHedgeMintPublicKey)();
|
39
39
|
const poolUshAccount = yield (0, Constants_1.getLiquidationPoolUshAccountPublicKey)();
|
40
40
|
const poolState = yield (0, Constants_1.getLiquidationPoolStatePublicKey)();
|
41
|
-
return program.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
41
|
+
return yield program.methods
|
42
|
+
.closeLiquidationPoolPosition(new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)) // override current time
|
43
|
+
)
|
44
|
+
.accounts({
|
45
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
46
|
+
poolState: poolState,
|
47
|
+
poolEra: poolEra,
|
48
|
+
poolPosition: poolPosition,
|
49
|
+
poolUshAccount: poolUshAccount,
|
50
|
+
payer: payerPublicKey,
|
51
|
+
ownerUshAccount: payerUshAccount,
|
52
|
+
hedgeMint: hedgeMint,
|
53
|
+
ushMint: ushMint,
|
54
|
+
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
55
|
+
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
56
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
57
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
58
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
59
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
60
|
+
})
|
61
|
+
.instruction();
|
62
62
|
});
|
63
63
|
}
|
64
64
|
exports.closeLiquidationPoolPositionInstruction = closeLiquidationPoolPositionInstruction;
|
@@ -18,7 +18,7 @@ const Constants_1 = require("../Constants");
|
|
18
18
|
function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
19
19
|
return __awaiter(this, void 0, void 0, function* () {
|
20
20
|
const transaction = new web3_js_1.Transaction().add(yield createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime));
|
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
|
const [poolPublickey] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
23
23
|
return poolPublickey;
|
24
24
|
});
|
@@ -26,28 +26,27 @@ function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensT
|
|
26
26
|
exports.createStakingPool = createStakingPool;
|
27
27
|
function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
29
|
-
console.log("createStakingPoolInstruction program ID", program.programId.toString());
|
30
29
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
31
30
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
32
31
|
const [poolPublickey, poolBump] = yield (0, Constants_1.getPoolPublicKeyForMint)(mintPublicKey);
|
33
32
|
const poolAssociatedStakedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, mintPublicKey);
|
34
33
|
const poolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(poolPublickey, ushMintPublickey);
|
35
|
-
return program.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
34
|
+
return yield program.methods
|
35
|
+
.createStakingPool(poolBump, new anchor_1.BN(hedgeTokensToBeMinted), new anchor_1.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Math.floor(Date.now() / 1000)))
|
36
|
+
.accounts({
|
37
|
+
signer: payerPublicKey,
|
38
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
39
|
+
pool: poolPublickey,
|
40
|
+
stakedTokenMintInfo: mintPublicKey,
|
41
|
+
ushMint: ushMintPublickey,
|
42
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
43
|
+
poolAssociatedUshTokenAccount: poolAssociatedUshTokenAccount,
|
44
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
45
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
46
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
47
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
48
|
+
})
|
49
|
+
.instruction();
|
51
50
|
});
|
52
51
|
}
|
53
52
|
exports.createStakingPoolInstruction = createStakingPoolInstruction;
|
@@ -32,8 +32,7 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
|
|
32
32
|
const wrappedSolAccount = web3_js_1.Keypair.generate();
|
33
33
|
const transaction = new web3_js_1.Transaction();
|
34
34
|
const signers = [payer, history];
|
35
|
-
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
36
|
-
serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
35
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
37
36
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
38
37
|
const feePoolAssociatedUshTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(hedgeStakingPoolPublicKey, ushMintPublickey);
|
39
38
|
if (isWrappedSol) {
|
@@ -58,16 +57,15 @@ function createVault(program, provider, payer, collateralType, depositAmount, ov
|
|
58
57
|
owner: payer.publicKey,
|
59
58
|
}));
|
60
59
|
}
|
61
|
-
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, signers
|
60
|
+
yield (0, web3_js_1.sendAndConfirmTransaction)(provider.connection, transaction, signers).catch(Errors_1.parseAnchorErrors);
|
62
61
|
return newVaultPublicKey;
|
63
62
|
});
|
64
63
|
}
|
65
64
|
exports.createVault = createVault;
|
66
|
-
function buildCreateVaultTransaction(program, collateralType, depositAmount, overrideTime) {
|
65
|
+
function buildCreateVaultTransaction(program, payerPublicKey, collateralType, depositAmount, overrideTime) {
|
67
66
|
return __awaiter(this, void 0, void 0, function* () {
|
68
|
-
console.log(
|
67
|
+
console.log('HEDGE SDK: buildCreateVaultTransaction');
|
69
68
|
const ushMintPublickey = yield (0, Constants_1.getUshMintPublicKey)();
|
70
|
-
const payerPublicKey = program.provider.wallet.publicKey;
|
71
69
|
const salt = (0, uuid_1.v4)().substring(0, 8);
|
72
70
|
const newVaultPublicKey = yield (0, Constants_1.findVaultAddress)(salt);
|
73
71
|
const history = web3_js_1.Keypair.generate();
|
@@ -84,8 +82,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
|
|
84
82
|
console.log('Lookup vaultTypeAccountPublicKey', vaultTypeAccountPublicKey.toString());
|
85
83
|
const vaultTypeAccountInfo = yield program.account.vaultType.fetch(vaultTypeAccountPublicKey);
|
86
84
|
console.log('Lookup vaultTypeAccountInfo', vaultTypeAccountInfo);
|
87
|
-
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() ===
|
88
|
-
serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
85
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === serum_1.TokenInstructions.WRAPPED_SOL_MINT.toString();
|
89
86
|
const payerTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(payerPublicKey, vaultTypeAccountInfo.collateralMint);
|
90
87
|
const vaultAssociatedTokenAccount = yield (0, Constants_1.findAssociatedTokenAddress)(newVaultPublicKey, vaultTypeAccountInfo.collateralMint);
|
91
88
|
const [hedgeStakingPoolPublicKey] = yield (0, Constants_1.getPoolPublicKeyForMint)(yield (0, Constants_1.getHedgeMintPublicKey)());
|
@@ -106,7 +103,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
|
|
106
103
|
}));
|
107
104
|
signers.push(wrappedSolAccount);
|
108
105
|
}
|
109
|
-
console.log(
|
106
|
+
console.log('hedgeStakingPoolPublicKey', hedgeStakingPoolPublicKey.toString());
|
110
107
|
transaction.add(yield createVaultInstruction(program, salt, payerPublicKey, isWrappedSol ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedTokenAccount, hedgeStakingPoolPublicKey, feePoolAssociatedUshTokenAccount, vaultTypeAccountPublicKey, vaultTypeAccountInfo.collateralMint, history.publicKey, ushMintPublickey, depositAmount, overrideTime));
|
111
108
|
if (isWrappedSol) {
|
112
109
|
transaction.add(serum_1.TokenInstructions.closeAccount({
|
@@ -117,7 +114,7 @@ function buildCreateVaultTransaction(program, collateralType, depositAmount, ove
|
|
117
114
|
transaction.partialSign(wrappedSolAccount);
|
118
115
|
}
|
119
116
|
transaction.partialSign(history);
|
120
|
-
console.log(
|
117
|
+
console.log('transaction', transaction);
|
121
118
|
return [transaction, signers, newVaultPublicKey];
|
122
119
|
});
|
123
120
|
}
|
@@ -125,27 +122,27 @@ exports.buildCreateVaultTransaction = buildCreateVaultTransaction;
|
|
125
122
|
function createVaultInstruction(program, salt, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedTokenAccount, feePool, feePoolAssociatedUshTokenAccount, vaultTypeAccount, collateralMint, historyPublicKey, ushMintPublickey, depositAmount, overrideTime) {
|
126
123
|
return __awaiter(this, void 0, void 0, function* () {
|
127
124
|
const vaultSystemStatePublicKey = yield (0, Constants_1.getVaultSystemStatePublicKey)();
|
128
|
-
const ix = program.
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
125
|
+
const ix = program.methods
|
126
|
+
.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
|
127
|
+
)
|
128
|
+
.accounts({
|
129
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
130
|
+
vaultTypeAccount: vaultTypeAccount,
|
131
|
+
vault: vaultPublicKey,
|
132
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
133
|
+
feePool: feePool,
|
134
|
+
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
135
|
+
history: historyPublicKey,
|
136
|
+
payer: payerPublicKey,
|
137
|
+
payerTokenAccount: payerTokenAccountPublicKey,
|
138
|
+
collateralMint: collateralMint,
|
139
|
+
ushMint: ushMintPublickey,
|
140
|
+
systemProgram: web3_js_1.SystemProgram.programId,
|
141
|
+
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
142
|
+
associatedTokenProgram: spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID,
|
143
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
144
|
+
})
|
145
|
+
.instruction();
|
149
146
|
return ix;
|
150
147
|
});
|
151
148
|
}
|
@@ -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;
|