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
@@ -1,10 +1,6 @@
|
|
1
|
-
import { BN, Idl, Program, Provider } from
|
2
|
-
import { TokenInstructions } from
|
3
|
-
import {
|
4
|
-
ASSOCIATED_TOKEN_PROGRAM_ID,
|
5
|
-
TOKEN_PROGRAM_ID,
|
6
|
-
getOrCreateAssociatedTokenAccount,
|
7
|
-
} from "@solana/spl-token";
|
1
|
+
import { BN, Idl, Program, Provider } from '@project-serum/anchor'
|
2
|
+
import { TokenInstructions } from '@project-serum/serum'
|
3
|
+
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID, getOrCreateAssociatedTokenAccount } from '@solana/spl-token'
|
8
4
|
import {
|
9
5
|
Keypair,
|
10
6
|
PublicKey,
|
@@ -14,7 +10,7 @@ import {
|
|
14
10
|
SYSVAR_RENT_PUBKEY,
|
15
11
|
Transaction,
|
16
12
|
TransactionInstruction,
|
17
|
-
} from
|
13
|
+
} from '@solana/web3.js'
|
18
14
|
import {
|
19
15
|
findAssociatedTokenAddress,
|
20
16
|
findVaultAddress,
|
@@ -23,65 +19,47 @@ import {
|
|
23
19
|
getVaultSystemStatePublicKey,
|
24
20
|
getPoolPublicKeyForMint,
|
25
21
|
getHedgeMintPublicKey,
|
26
|
-
} from
|
22
|
+
} from '../Constants'
|
27
23
|
|
28
|
-
import { v4 as uuidv4 } from
|
29
|
-
import { parseAnchorErrors } from
|
24
|
+
import { v4 as uuidv4 } from 'uuid'
|
25
|
+
import { parseAnchorErrors } from '../utils/Errors'
|
26
|
+
import { Vault } from 'idl/vault'
|
30
27
|
|
31
28
|
export async function createVault(
|
32
|
-
program: Program
|
29
|
+
program: Program<Vault>,
|
33
30
|
provider: Provider,
|
34
31
|
payer: Signer,
|
35
32
|
collateralType: string,
|
36
33
|
depositAmount: number,
|
37
34
|
overrideTime?: number
|
38
35
|
): Promise<PublicKey> {
|
39
|
-
const ushMintPublickey = await getUshMintPublicKey()
|
36
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
40
37
|
|
41
|
-
const salt = uuidv4().substring(0, 8)
|
42
|
-
const newVaultPublicKey = await findVaultAddress(salt)
|
43
|
-
const history = Keypair.generate()
|
38
|
+
const salt = uuidv4().substring(0, 8)
|
39
|
+
const newVaultPublicKey = await findVaultAddress(salt)
|
40
|
+
const history = Keypair.generate()
|
44
41
|
|
45
42
|
// Prep the user to get USH back out at some point
|
46
|
-
await getOrCreateAssociatedTokenAccount(
|
47
|
-
provider.connection,
|
48
|
-
payer,
|
49
|
-
ushMintPublickey,
|
50
|
-
payer.publicKey
|
51
|
-
);
|
43
|
+
await getOrCreateAssociatedTokenAccount(provider.connection, payer, ushMintPublickey, payer.publicKey)
|
52
44
|
|
53
|
-
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
|
54
|
-
|
55
|
-
);
|
56
|
-
const vaultTypeAccountInfo = await program.account.vaultType.fetch(
|
57
|
-
vaultTypeAccountPublicKey
|
58
|
-
);
|
45
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(collateralType)
|
46
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
59
47
|
|
60
|
-
const payerTokenAccount = await findAssociatedTokenAddress(
|
61
|
-
payer.publicKey,
|
62
|
-
vaultTypeAccountInfo.collateralMint
|
63
|
-
);
|
48
|
+
const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, vaultTypeAccountInfo.collateralMint)
|
64
49
|
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(
|
65
50
|
newVaultPublicKey,
|
66
51
|
vaultTypeAccountInfo.collateralMint
|
67
|
-
)
|
52
|
+
)
|
68
53
|
|
69
|
-
const wrappedSolAccount = Keypair.generate()
|
54
|
+
const wrappedSolAccount = Keypair.generate()
|
70
55
|
|
71
|
-
const transaction = new Transaction()
|
72
|
-
const signers = [payer, history]
|
56
|
+
const transaction = new Transaction()
|
57
|
+
const signers = [payer, history]
|
73
58
|
|
74
|
-
const isWrappedSol =
|
75
|
-
vaultTypeAccountInfo.collateralMint.toString() ===
|
76
|
-
TokenInstructions.WRAPPED_SOL_MINT.toString();
|
59
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === TokenInstructions.WRAPPED_SOL_MINT.toString()
|
77
60
|
|
78
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
79
|
-
|
80
|
-
);
|
81
|
-
const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
82
|
-
hedgeStakingPoolPublicKey,
|
83
|
-
ushMintPublickey
|
84
|
-
);
|
61
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
|
62
|
+
const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, ushMintPublickey)
|
85
63
|
|
86
64
|
if (isWrappedSol) {
|
87
65
|
transaction.add(
|
@@ -97,8 +75,8 @@ export async function createVault(
|
|
97
75
|
mint: TokenInstructions.WRAPPED_SOL_MINT,
|
98
76
|
owner: payer.publicKey,
|
99
77
|
})
|
100
|
-
)
|
101
|
-
signers.push(wrappedSolAccount)
|
78
|
+
)
|
79
|
+
signers.push(wrappedSolAccount)
|
102
80
|
}
|
103
81
|
transaction.add(
|
104
82
|
await createVaultInstruction(
|
@@ -117,7 +95,7 @@ export async function createVault(
|
|
117
95
|
depositAmount,
|
118
96
|
overrideTime
|
119
97
|
)
|
120
|
-
)
|
98
|
+
)
|
121
99
|
if (isWrappedSol) {
|
122
100
|
transaction.add(
|
123
101
|
TokenInstructions.closeAccount({
|
@@ -125,74 +103,53 @@ export async function createVault(
|
|
125
103
|
destination: payer.publicKey,
|
126
104
|
owner: payer.publicKey,
|
127
105
|
})
|
128
|
-
)
|
106
|
+
)
|
129
107
|
}
|
130
108
|
|
131
|
-
await sendAndConfirmTransaction(
|
132
|
-
|
133
|
-
transaction,
|
134
|
-
signers,
|
135
|
-
provider?.opts
|
136
|
-
).catch(parseAnchorErrors);
|
137
|
-
return newVaultPublicKey;
|
109
|
+
await sendAndConfirmTransaction(provider.connection, transaction, signers).catch(parseAnchorErrors)
|
110
|
+
return newVaultPublicKey
|
138
111
|
}
|
139
112
|
|
140
113
|
export async function buildCreateVaultTransaction(
|
141
|
-
program: Program
|
114
|
+
program: Program<Vault>,
|
115
|
+
payerPublicKey: PublicKey,
|
142
116
|
collateralType: string,
|
143
117
|
depositAmount: number,
|
144
118
|
overrideTime?: number
|
145
119
|
): Promise<[Transaction, Signer[], PublicKey]> {
|
146
|
-
|
147
|
-
|
148
|
-
const
|
149
|
-
const
|
150
|
-
|
151
|
-
const salt = uuidv4().substring(0, 8);
|
152
|
-
const newVaultPublicKey = await findVaultAddress(salt);
|
153
|
-
const history = Keypair.generate() as Signer;
|
120
|
+
console.log('HEDGE SDK: buildCreateVaultTransaction')
|
121
|
+
const ushMintPublickey = await getUshMintPublicKey()
|
122
|
+
const salt = uuidv4().substring(0, 8)
|
123
|
+
const newVaultPublicKey = await findVaultAddress(salt)
|
124
|
+
const history = Keypair.generate() as Signer
|
154
125
|
const { blockhash } = await program.provider.connection.getLatestBlockhash()
|
155
126
|
const transaction = new Transaction({
|
156
127
|
feePayer: payerPublicKey,
|
157
128
|
recentBlockhash: blockhash,
|
158
129
|
})
|
159
|
-
const signers = [history]
|
160
|
-
const wrappedSolAccount = Keypair.generate()
|
130
|
+
const signers = [history]
|
131
|
+
const wrappedSolAccount = Keypair.generate()
|
161
132
|
|
162
133
|
console.log('Lookup getVaultTypeAccountPublicKey', collateralType)
|
163
134
|
|
164
135
|
// Lookup the vault type info
|
165
|
-
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(
|
166
|
-
collateralType
|
167
|
-
);
|
136
|
+
const vaultTypeAccountPublicKey = await getVaultTypeAccountPublicKey(collateralType)
|
168
137
|
|
169
138
|
console.log('Lookup vaultTypeAccountPublicKey', vaultTypeAccountPublicKey.toString())
|
170
139
|
|
171
|
-
const vaultTypeAccountInfo = await program.account.vaultType.fetch(
|
172
|
-
vaultTypeAccountPublicKey
|
173
|
-
);
|
140
|
+
const vaultTypeAccountInfo = await program.account.vaultType.fetch(vaultTypeAccountPublicKey)
|
174
141
|
console.log('Lookup vaultTypeAccountInfo', vaultTypeAccountInfo)
|
175
142
|
|
176
|
-
const isWrappedSol =
|
177
|
-
vaultTypeAccountInfo.collateralMint.toString() ===
|
178
|
-
TokenInstructions.WRAPPED_SOL_MINT.toString();
|
143
|
+
const isWrappedSol = vaultTypeAccountInfo.collateralMint.toString() === TokenInstructions.WRAPPED_SOL_MINT.toString()
|
179
144
|
|
180
|
-
const payerTokenAccount = await findAssociatedTokenAddress(
|
181
|
-
payerPublicKey,
|
182
|
-
vaultTypeAccountInfo.collateralMint
|
183
|
-
);
|
145
|
+
const payerTokenAccount = await findAssociatedTokenAddress(payerPublicKey, vaultTypeAccountInfo.collateralMint)
|
184
146
|
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(
|
185
147
|
newVaultPublicKey,
|
186
148
|
vaultTypeAccountInfo.collateralMint
|
187
|
-
)
|
149
|
+
)
|
188
150
|
|
189
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(
|
190
|
-
|
191
|
-
);
|
192
|
-
const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(
|
193
|
-
hedgeStakingPoolPublicKey,
|
194
|
-
ushMintPublickey
|
195
|
-
);
|
151
|
+
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(await getHedgeMintPublicKey())
|
152
|
+
const feePoolAssociatedUshTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, ushMintPublickey)
|
196
153
|
|
197
154
|
console.log('about to start building transaction')
|
198
155
|
|
@@ -211,10 +168,10 @@ export async function buildCreateVaultTransaction(
|
|
211
168
|
mint: TokenInstructions.WRAPPED_SOL_MINT,
|
212
169
|
owner: payerPublicKey,
|
213
170
|
})
|
214
|
-
)
|
215
|
-
signers.push(wrappedSolAccount)
|
171
|
+
)
|
172
|
+
signers.push(wrappedSolAccount)
|
216
173
|
}
|
217
|
-
console.log(
|
174
|
+
console.log('hedgeStakingPoolPublicKey', hedgeStakingPoolPublicKey.toString())
|
218
175
|
transaction.add(
|
219
176
|
await createVaultInstruction(
|
220
177
|
program,
|
@@ -232,7 +189,7 @@ export async function buildCreateVaultTransaction(
|
|
232
189
|
depositAmount,
|
233
190
|
overrideTime
|
234
191
|
)
|
235
|
-
)
|
192
|
+
)
|
236
193
|
if (isWrappedSol) {
|
237
194
|
transaction.add(
|
238
195
|
TokenInstructions.closeAccount({
|
@@ -240,18 +197,18 @@ export async function buildCreateVaultTransaction(
|
|
240
197
|
destination: payerPublicKey,
|
241
198
|
owner: payerPublicKey,
|
242
199
|
})
|
243
|
-
)
|
200
|
+
)
|
244
201
|
transaction.partialSign(wrappedSolAccount)
|
245
202
|
}
|
246
|
-
|
203
|
+
|
247
204
|
transaction.partialSign(history)
|
248
|
-
console.log(
|
205
|
+
console.log('transaction', transaction)
|
249
206
|
|
250
|
-
return [transaction, signers, newVaultPublicKey]
|
207
|
+
return [transaction, signers, newVaultPublicKey]
|
251
208
|
}
|
252
209
|
|
253
210
|
export async function createVaultInstruction(
|
254
|
-
program: Program
|
211
|
+
program: Program<Vault>,
|
255
212
|
salt: string,
|
256
213
|
payerPublicKey: PublicKey,
|
257
214
|
payerTokenAccountPublicKey: PublicKey,
|
@@ -266,32 +223,31 @@ export async function createVaultInstruction(
|
|
266
223
|
depositAmount: number,
|
267
224
|
overrideTime?: number
|
268
225
|
): Promise<TransactionInstruction> {
|
269
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
226
|
+
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey()
|
270
227
|
|
271
|
-
const ix = program.
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
return ix;
|
228
|
+
const ix = program.methods
|
229
|
+
.createVault(
|
230
|
+
salt,
|
231
|
+
new BN(depositAmount),
|
232
|
+
new BN(overrideTime ?? Math.floor(Date.now() / 1000)) // override override time
|
233
|
+
)
|
234
|
+
.accounts({
|
235
|
+
vaultSystemState: vaultSystemStatePublicKey,
|
236
|
+
vaultTypeAccount: vaultTypeAccount,
|
237
|
+
vault: vaultPublicKey,
|
238
|
+
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
239
|
+
feePool: feePool,
|
240
|
+
feePoolAssociatedUshTokenAccount: feePoolAssociatedUshTokenAccount,
|
241
|
+
history: historyPublicKey,
|
242
|
+
payer: payerPublicKey,
|
243
|
+
payerTokenAccount: payerTokenAccountPublicKey,
|
244
|
+
collateralMint: collateralMint,
|
245
|
+
ushMint: ushMintPublickey,
|
246
|
+
systemProgram: SystemProgram.programId,
|
247
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
248
|
+
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
|
249
|
+
rent: SYSVAR_RENT_PUBKEY,
|
250
|
+
})
|
251
|
+
.instruction()
|
252
|
+
return ix
|
297
253
|
}
|
@@ -1,18 +1,38 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { getOrCreateAssociatedTokenAccount, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
Keypair,
|
5
|
+
PublicKey,
|
6
|
+
sendAndConfirmTransaction,
|
7
|
+
Signer,
|
8
|
+
SystemProgram,
|
9
|
+
SYSVAR_RENT_PUBKEY,
|
10
|
+
Transaction,
|
11
|
+
TransactionInstruction,
|
12
|
+
} from '@solana/web3.js'
|
4
13
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
|
-
import {
|
14
|
+
import {
|
15
|
+
getLiquidationPoolStatePublicKey,
|
16
|
+
getLiquidationPoolUshAccountPublicKey,
|
17
|
+
getUshMintPublicKey,
|
18
|
+
getVaultSystemStatePublicKey,
|
19
|
+
} from '../Constants'
|
20
|
+
import { Vault } from 'idl/vault'
|
6
21
|
|
7
|
-
export async function depositLiquidationPool
|
8
|
-
program: Program
|
22
|
+
export async function depositLiquidationPool(
|
23
|
+
program: Program<Vault>,
|
9
24
|
provider: Provider,
|
10
25
|
payer: Signer,
|
11
26
|
depositAmount: number,
|
12
27
|
overrideStartTime?: number
|
13
28
|
): Promise<PublicKey> {
|
14
29
|
const ushMintPublickey = await getUshMintPublicKey()
|
15
|
-
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
30
|
+
const payerUshAccount = await getOrCreateAssociatedTokenAccount(
|
31
|
+
provider.connection,
|
32
|
+
payer,
|
33
|
+
ushMintPublickey,
|
34
|
+
payer.publicKey
|
35
|
+
)
|
16
36
|
|
17
37
|
const poolPosition = Keypair.generate()
|
18
38
|
const transaction = new Transaction().add(
|
@@ -25,12 +45,12 @@ export async function depositLiquidationPool (
|
|
25
45
|
overrideStartTime
|
26
46
|
)
|
27
47
|
)
|
28
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]
|
48
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
|
29
49
|
return poolPosition.publicKey
|
30
50
|
}
|
31
51
|
|
32
|
-
export async function depositLiquidationPoolInstruction
|
33
|
-
program: Program
|
52
|
+
export async function depositLiquidationPoolInstruction(
|
53
|
+
program: Program<Vault>,
|
34
54
|
payerPublicKey: PublicKey,
|
35
55
|
payerUshAccount: PublicKey,
|
36
56
|
poolPositionPublicKey: PublicKey,
|
@@ -45,23 +65,22 @@ export async function depositLiquidationPoolInstruction (
|
|
45
65
|
|
46
66
|
const vaultSystemState = await getVaultSystemStatePublicKey()
|
47
67
|
|
48
|
-
return program.
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
},
|
65
|
-
signers: []
|
68
|
+
return await program.methods
|
69
|
+
.depositLiquidationPool(
|
70
|
+
new BN(depositAmount),
|
71
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
|
72
|
+
)
|
73
|
+
.accounts({
|
74
|
+
vaultSystemState: vaultSystemState,
|
75
|
+
poolState: liquidationPoolStatePublicKey,
|
76
|
+
poolUshAccount: poolUSHAccount,
|
77
|
+
poolEra: liquidationPoolState.currentEra,
|
78
|
+
poolPosition: poolPositionPublicKey,
|
79
|
+
ushMint: ushMint,
|
80
|
+
payer: payerPublicKey,
|
81
|
+
ownerUshAccount: payerUshAccount,
|
82
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
83
|
+
systemProgram: SystemProgram.programId,
|
66
84
|
})
|
85
|
+
.instruction()
|
67
86
|
}
|
@@ -1,11 +1,21 @@
|
|
1
1
|
import { BN, Program, Provider } from '@project-serum/anchor'
|
2
2
|
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'
|
3
|
-
import {
|
3
|
+
import {
|
4
|
+
Keypair,
|
5
|
+
PublicKey,
|
6
|
+
sendAndConfirmTransaction,
|
7
|
+
Signer,
|
8
|
+
SystemProgram,
|
9
|
+
SYSVAR_RENT_PUBKEY,
|
10
|
+
Transaction,
|
11
|
+
TransactionInstruction,
|
12
|
+
} from '@solana/web3.js'
|
4
13
|
import { parseAnchorErrors } from '../utils/Errors'
|
5
14
|
import { findAssociatedTokenAddress, getPoolPublicKeyForMint, getVaultSystemStatePublicKey } from '../Constants'
|
15
|
+
import { Vault } from 'idl/vault'
|
6
16
|
|
7
|
-
export async function depositStakingPool
|
8
|
-
program: Program
|
17
|
+
export async function depositStakingPool(
|
18
|
+
program: Program<Vault>,
|
9
19
|
provider: Provider,
|
10
20
|
payer: Signer,
|
11
21
|
mintPublicKey: PublicKey,
|
@@ -23,12 +33,12 @@ export async function depositStakingPool (
|
|
23
33
|
overrideStartTime
|
24
34
|
)
|
25
35
|
)
|
26
|
-
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]
|
36
|
+
await sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition]).catch(parseAnchorErrors)
|
27
37
|
return poolPosition.publicKey
|
28
38
|
}
|
29
39
|
|
30
|
-
export async function depositStakingPoolInstruction
|
31
|
-
program: Program
|
40
|
+
export async function depositStakingPoolInstruction(
|
41
|
+
program: Program<Vault>,
|
32
42
|
payerPublicKey: PublicKey,
|
33
43
|
poolPositionPublicKey: PublicKey,
|
34
44
|
stakedTokenMintPublicKey: PublicKey,
|
@@ -40,23 +50,21 @@ export async function depositStakingPoolInstruction (
|
|
40
50
|
const payersArbitraryTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey)
|
41
51
|
const vaultSystemState = await getVaultSystemStatePublicKey()
|
42
52
|
|
43
|
-
return program.
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
systemProgram: SystemProgram.programId
|
59
|
-
},
|
60
|
-
signers: []
|
53
|
+
return await program.methods
|
54
|
+
.depositStakingPool(
|
55
|
+
new BN(depositAmount),
|
56
|
+
new BN(overrideStartTime ?? Math.floor(Date.now() / 1000)) // override current time
|
57
|
+
)
|
58
|
+
.accounts({
|
59
|
+
payer: payerPublicKey,
|
60
|
+
vaultSystemState: vaultSystemState,
|
61
|
+
pool: poolPublickey,
|
62
|
+
poolPosition: poolPositionPublicKey,
|
63
|
+
stakedTokenMintInfo: stakedTokenMintPublicKey,
|
64
|
+
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
65
|
+
payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
|
66
|
+
tokenProgram: TOKEN_PROGRAM_ID,
|
67
|
+
systemProgram: SystemProgram.programId,
|
61
68
|
})
|
69
|
+
.instruction()
|
62
70
|
}
|