hedge-web3 0.1.14 → 0.1.15
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/{lib/types/src → declarations}/Constants.d.ts +1 -2
- package/{lib/types/src → declarations}/HedgeDecimal.d.ts +0 -1
- package/{lib/types/src → declarations}/StakingPools.d.ts +0 -1
- package/{lib/types/src → declarations}/Vaults.d.ts +0 -1
- package/{lib/types/src → declarations}/idl/idl.d.ts +0 -1
- package/declarations/idl/vault.d.ts +2283 -0
- package/{lib/types/src → declarations}/index.d.ts +2 -1
- package/{lib/types/src → declarations}/instructions/claimLiquidationPoolPosition.d.ts +1 -2
- package/{lib/types/src → declarations}/instructions/closeLiquidationPoolPosition.d.ts +0 -1
- package/{lib/types/src → declarations}/instructions/createStakingPool.d.ts +0 -1
- package/{lib/types/src → declarations}/instructions/createVault.d.ts +2 -3
- package/{lib/types/src → declarations}/instructions/depositLiquidationPool.d.ts +0 -1
- package/{lib/types/src → declarations}/instructions/depositStakingPool.d.ts +0 -1
- package/{lib/types/src → declarations}/instructions/depositVault.d.ts +2 -3
- package/declarations/instructions/initHedgeFoundation.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/liquidateVault.d.ts +2 -3
- package/{lib/types/src → declarations}/instructions/loanVault.d.ts +2 -3
- package/{lib/types/src → declarations}/instructions/redeemVault.d.ts +1 -2
- package/{lib/types/src → declarations}/instructions/refreshOraclePrice.d.ts +0 -1
- package/{lib/types/src → declarations}/instructions/repayVault.d.ts +2 -3
- package/declarations/instructions/setHalted.d.ts +4 -0
- package/{lib/types/src → declarations}/instructions/withdrawStakingPool.d.ts +0 -1
- package/{lib/types/src → declarations}/instructions/withdrawVault.d.ts +2 -3
- package/{lib/types/src → declarations}/state/LiquidationPoolEra.d.ts +0 -1
- package/{lib/types/src → declarations}/state/LiquidationPoolState.d.ts +0 -1
- package/{lib/types/src → declarations}/state/LiquidationPosition.d.ts +1 -2
- package/{lib/types/src → declarations}/state/StakingPool.d.ts +0 -1
- package/{lib/types/src → declarations}/state/StakingPoolPosition.d.ts +0 -1
- package/{lib/types/src → declarations}/state/VaultAccount.d.ts +0 -1
- package/{lib/types/src → declarations}/state/VaultHistoryEvent.d.ts +0 -1
- package/{lib/types/src → declarations}/utils/Errors.d.ts +0 -1
- package/lib/Constants.js +86 -0
- package/lib/HedgeDecimal.js +24 -0
- package/lib/StakingPools.js +15 -0
- package/lib/Vaults.js +20 -0
- package/lib/idl/idl.js +1475 -0
- package/lib/idl/vault.js +2285 -0
- package/lib/index.js +36 -2382
- package/lib/instructions/claimLiquidationPoolPosition.js +53 -0
- package/lib/instructions/closeLiquidationPoolPosition.js +60 -0
- package/lib/instructions/createStakingPool.js +52 -0
- package/lib/instructions/createVault.js +92 -0
- package/lib/instructions/depositLiquidationPool.js +55 -0
- package/lib/instructions/depositStakingPool.js +52 -0
- package/lib/instructions/depositVault.js +87 -0
- package/lib/instructions/initHedgeFoundation.js +55 -0
- package/lib/instructions/liquidateVault.js +80 -0
- package/lib/instructions/loanVault.js +61 -0
- package/lib/instructions/redeemVault.js +65 -0
- package/lib/instructions/refreshOraclePrice.js +65 -0
- package/lib/instructions/repayVault.js +62 -0
- package/lib/instructions/setHalted.js +37 -0
- package/lib/instructions/withdrawStakingPool.js +64 -0
- package/lib/instructions/withdrawVault.js +62 -0
- package/lib/state/LiquidationPoolEra.js +19 -0
- package/lib/state/LiquidationPoolState.js +12 -0
- package/lib/state/LiquidationPosition.js +39 -0
- package/lib/state/StakingPool.js +22 -0
- package/lib/state/StakingPoolPosition.js +28 -0
- package/lib/state/VaultAccount.js +52 -0
- package/lib/state/VaultHistoryEvent.js +45 -0
- package/lib/utils/Errors.js +14 -0
- package/package.json +8 -6
- package/src/Constants.ts +4 -3
- package/src/HedgeDecimal.ts +1 -1
- package/src/idl/vault.ts +4565 -0
- package/src/index.ts +2 -0
- package/src/instructions/claimLiquidationPoolPosition.ts +19 -11
- package/src/instructions/closeLiquidationPoolPosition.ts +7 -13
- package/src/instructions/createVault.ts +39 -29
- package/src/instructions/depositLiquidationPool.ts +6 -9
- package/src/instructions/depositStakingPool.ts +3 -1
- package/src/instructions/depositVault.ts +41 -29
- package/src/instructions/initHedgeFoundation.ts +64 -0
- package/src/instructions/liquidateVault.ts +30 -33
- package/src/instructions/loanVault.ts +22 -24
- package/src/instructions/redeemVault.ts +15 -28
- package/src/instructions/refreshOraclePrice.ts +2 -2
- package/src/instructions/repayVault.ts +20 -22
- package/src/instructions/setHalted.ts +48 -0
- package/src/instructions/withdrawVault.ts +36 -26
- package/src/state/LiquidationPosition.ts +2 -2
- package/tsconfig.json +3 -2
- package/.github/workflows/npm-publish.yml +0 -34
- package/README.md +0 -44
- package/jsconfig.json +0 -12
- package/lib/index.js.map +0 -1
- package/lib/types/src/Constants.d.ts.map +0 -1
- package/lib/types/src/HedgeDecimal.d.ts.map +0 -1
- package/lib/types/src/StakingPools.d.ts.map +0 -1
- package/lib/types/src/Vaults.d.ts.map +0 -1
- package/lib/types/src/idl/idl.d.ts.map +0 -1
- package/lib/types/src/index.d.ts.map +0 -1
- package/lib/types/src/instructions/claimLiquidationPoolPosition.d.ts.map +0 -1
- package/lib/types/src/instructions/closeLiquidationPoolPosition.d.ts.map +0 -1
- package/lib/types/src/instructions/createStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/createVault.d.ts.map +0 -1
- package/lib/types/src/instructions/depositLiquidationPool.d.ts.map +0 -1
- package/lib/types/src/instructions/depositStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/depositVault.d.ts.map +0 -1
- package/lib/types/src/instructions/liquidateVault.d.ts.map +0 -1
- package/lib/types/src/instructions/loanVault.d.ts.map +0 -1
- package/lib/types/src/instructions/redeemVault.d.ts.map +0 -1
- package/lib/types/src/instructions/refreshOraclePrice.d.ts.map +0 -1
- package/lib/types/src/instructions/repayVault.d.ts.map +0 -1
- package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +0 -1
- package/lib/types/src/instructions/withdrawVault.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPoolEra.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPoolState.d.ts.map +0 -1
- package/lib/types/src/state/LiquidationPosition.d.ts.map +0 -1
- package/lib/types/src/state/StakingPool.d.ts.map +0 -1
- package/lib/types/src/state/StakingPoolPosition.d.ts.map +0 -1
- package/lib/types/src/state/VaultAccount.d.ts.map +0 -1
- package/lib/types/src/state/VaultHistoryEvent.d.ts.map +0 -1
- package/lib/types/src/utils/Errors.d.ts.map +0 -1
- package/lib/types/tsconfig.base.tsbuildinfo +0 -1
- package/rollup.config.js +0 -42
package/lib/index.js
CHANGED
@@ -1,2383 +1,37 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
var
|
10
|
-
var
|
11
|
-
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
13
|
-
|
14
|
-
var Decimal__default = /*#__PURE__*/_interopDefaultLegacy(Decimal);
|
15
|
-
|
16
|
-
const vaultIdl = {
|
17
|
-
version: '0.1.0',
|
18
|
-
name: 'vault',
|
19
|
-
instructions: [
|
20
|
-
{
|
21
|
-
name: 'initHedgeFoundation',
|
22
|
-
accounts: [
|
23
|
-
{
|
24
|
-
name: 'vaultSystemState',
|
25
|
-
isMut: true,
|
26
|
-
isSigner: false
|
27
|
-
},
|
28
|
-
{
|
29
|
-
name: 'poolState',
|
30
|
-
isMut: true,
|
31
|
-
isSigner: false
|
32
|
-
},
|
33
|
-
{
|
34
|
-
name: 'poolEra',
|
35
|
-
isMut: true,
|
36
|
-
isSigner: true
|
37
|
-
},
|
38
|
-
{
|
39
|
-
name: 'poolUsdhAccount',
|
40
|
-
isMut: true,
|
41
|
-
isSigner: false
|
42
|
-
},
|
43
|
-
{
|
44
|
-
name: 'founder',
|
45
|
-
isMut: true,
|
46
|
-
isSigner: true
|
47
|
-
},
|
48
|
-
{
|
49
|
-
name: 'usdhMint',
|
50
|
-
isMut: true,
|
51
|
-
isSigner: false
|
52
|
-
},
|
53
|
-
{
|
54
|
-
name: 'hedgeMint',
|
55
|
-
isMut: true,
|
56
|
-
isSigner: false
|
57
|
-
},
|
58
|
-
{
|
59
|
-
name: 'founderAssociatedHedgeTokenAccount',
|
60
|
-
isMut: true,
|
61
|
-
isSigner: false
|
62
|
-
},
|
63
|
-
{
|
64
|
-
name: 'oracleChainlink',
|
65
|
-
isMut: false,
|
66
|
-
isSigner: false
|
67
|
-
},
|
68
|
-
{
|
69
|
-
name: 'oraclePyth',
|
70
|
-
isMut: false,
|
71
|
-
isSigner: false
|
72
|
-
},
|
73
|
-
{
|
74
|
-
name: 'oracleSwitchboard',
|
75
|
-
isMut: false,
|
76
|
-
isSigner: false
|
77
|
-
},
|
78
|
-
{
|
79
|
-
name: 'rent',
|
80
|
-
isMut: false,
|
81
|
-
isSigner: false
|
82
|
-
},
|
83
|
-
{
|
84
|
-
name: 'tokenProgram',
|
85
|
-
isMut: false,
|
86
|
-
isSigner: false
|
87
|
-
},
|
88
|
-
{
|
89
|
-
name: 'associatedTokenProgram',
|
90
|
-
isMut: false,
|
91
|
-
isSigner: false
|
92
|
-
},
|
93
|
-
{
|
94
|
-
name: 'systemProgram',
|
95
|
-
isMut: false,
|
96
|
-
isSigner: false
|
97
|
-
}
|
98
|
-
],
|
99
|
-
args: [
|
100
|
-
{
|
101
|
-
name: 'bump1',
|
102
|
-
type: 'u8'
|
103
|
-
},
|
104
|
-
{
|
105
|
-
name: 'bump2',
|
106
|
-
type: 'u8'
|
107
|
-
}
|
108
|
-
]
|
109
|
-
},
|
110
|
-
{
|
111
|
-
name: 'createStakingPool',
|
112
|
-
accounts: [
|
113
|
-
{
|
114
|
-
name: 'signer',
|
115
|
-
isMut: true,
|
116
|
-
isSigner: true
|
117
|
-
},
|
118
|
-
{
|
119
|
-
name: 'vaultSystemState',
|
120
|
-
isMut: true,
|
121
|
-
isSigner: false
|
122
|
-
},
|
123
|
-
{
|
124
|
-
name: 'pool',
|
125
|
-
isMut: true,
|
126
|
-
isSigner: false
|
127
|
-
},
|
128
|
-
{
|
129
|
-
name: 'stakedTokenMintInfo',
|
130
|
-
isMut: false,
|
131
|
-
isSigner: false
|
132
|
-
},
|
133
|
-
{
|
134
|
-
name: 'usdhMint',
|
135
|
-
isMut: false,
|
136
|
-
isSigner: false
|
137
|
-
},
|
138
|
-
{
|
139
|
-
name: 'poolAssociatedStakedTokenAccount',
|
140
|
-
isMut: true,
|
141
|
-
isSigner: false
|
142
|
-
},
|
143
|
-
{
|
144
|
-
name: 'poolAssociatedUsdhTokenAccount',
|
145
|
-
isMut: true,
|
146
|
-
isSigner: false
|
147
|
-
},
|
148
|
-
{
|
149
|
-
name: 'rent',
|
150
|
-
isMut: false,
|
151
|
-
isSigner: false
|
152
|
-
},
|
153
|
-
{
|
154
|
-
name: 'tokenProgram',
|
155
|
-
isMut: false,
|
156
|
-
isSigner: false
|
157
|
-
},
|
158
|
-
{
|
159
|
-
name: 'associatedTokenProgram',
|
160
|
-
isMut: false,
|
161
|
-
isSigner: false
|
162
|
-
},
|
163
|
-
{
|
164
|
-
name: 'systemProgram',
|
165
|
-
isMut: false,
|
166
|
-
isSigner: false
|
167
|
-
}
|
168
|
-
],
|
169
|
-
args: [
|
170
|
-
{
|
171
|
-
name: 'bump1',
|
172
|
-
type: 'u8'
|
173
|
-
},
|
174
|
-
{
|
175
|
-
name: 'poolSeedPhraseInput',
|
176
|
-
type: 'string'
|
177
|
-
},
|
178
|
-
{
|
179
|
-
name: 'totalRewards',
|
180
|
-
type: 'u64'
|
181
|
-
},
|
182
|
-
{
|
183
|
-
name: 'overrideCurrentTime',
|
184
|
-
type: 'i64'
|
185
|
-
}
|
186
|
-
]
|
187
|
-
},
|
188
|
-
{
|
189
|
-
name: 'depositStakingPool',
|
190
|
-
accounts: [
|
191
|
-
{
|
192
|
-
name: 'payer',
|
193
|
-
isMut: true,
|
194
|
-
isSigner: true
|
195
|
-
},
|
196
|
-
{
|
197
|
-
name: 'pool',
|
198
|
-
isMut: true,
|
199
|
-
isSigner: false
|
200
|
-
},
|
201
|
-
{
|
202
|
-
name: 'poolPosition',
|
203
|
-
isMut: true,
|
204
|
-
isSigner: true
|
205
|
-
},
|
206
|
-
{
|
207
|
-
name: 'payerAssociatedStakedTokenAccount',
|
208
|
-
isMut: true,
|
209
|
-
isSigner: false
|
210
|
-
},
|
211
|
-
{
|
212
|
-
name: 'poolAssociatedStakedTokenAccount',
|
213
|
-
isMut: true,
|
214
|
-
isSigner: false
|
215
|
-
},
|
216
|
-
{
|
217
|
-
name: 'tokenProgram',
|
218
|
-
isMut: false,
|
219
|
-
isSigner: false
|
220
|
-
},
|
221
|
-
{
|
222
|
-
name: 'systemProgram',
|
223
|
-
isMut: false,
|
224
|
-
isSigner: false
|
225
|
-
}
|
226
|
-
],
|
227
|
-
args: [
|
228
|
-
{
|
229
|
-
name: 'stakeAmount',
|
230
|
-
type: 'u64'
|
231
|
-
},
|
232
|
-
{
|
233
|
-
name: 'overrideCurrentTime',
|
234
|
-
type: 'i64'
|
235
|
-
}
|
236
|
-
]
|
237
|
-
},
|
238
|
-
{
|
239
|
-
name: 'withdrawStakingPool',
|
240
|
-
accounts: [
|
241
|
-
{
|
242
|
-
name: 'payer',
|
243
|
-
isMut: true,
|
244
|
-
isSigner: true
|
245
|
-
},
|
246
|
-
{
|
247
|
-
name: 'vaultSystemState',
|
248
|
-
isMut: true,
|
249
|
-
isSigner: false
|
250
|
-
},
|
251
|
-
{
|
252
|
-
name: 'pool',
|
253
|
-
isMut: true,
|
254
|
-
isSigner: false
|
255
|
-
},
|
256
|
-
{
|
257
|
-
name: 'poolPosition',
|
258
|
-
isMut: true,
|
259
|
-
isSigner: false
|
260
|
-
},
|
261
|
-
{
|
262
|
-
name: 'hedgeMint',
|
263
|
-
isMut: true,
|
264
|
-
isSigner: false
|
265
|
-
},
|
266
|
-
{
|
267
|
-
name: 'stakedTokenMint',
|
268
|
-
isMut: true,
|
269
|
-
isSigner: false
|
270
|
-
},
|
271
|
-
{
|
272
|
-
name: 'usdhMint',
|
273
|
-
isMut: false,
|
274
|
-
isSigner: false
|
275
|
-
},
|
276
|
-
{
|
277
|
-
name: 'payerAssociatedStakedTokenAccount',
|
278
|
-
isMut: true,
|
279
|
-
isSigner: false
|
280
|
-
},
|
281
|
-
{
|
282
|
-
name: 'payerAssociatedHedgeAccount',
|
283
|
-
isMut: true,
|
284
|
-
isSigner: false
|
285
|
-
},
|
286
|
-
{
|
287
|
-
name: 'payerAssociatedUsdhAccount',
|
288
|
-
isMut: true,
|
289
|
-
isSigner: false
|
290
|
-
},
|
291
|
-
{
|
292
|
-
name: 'poolAssociatedStakedTokenAccount',
|
293
|
-
isMut: true,
|
294
|
-
isSigner: false
|
295
|
-
},
|
296
|
-
{
|
297
|
-
name: 'poolAssociatedUsdhTokenAccount',
|
298
|
-
isMut: true,
|
299
|
-
isSigner: false
|
300
|
-
},
|
301
|
-
{
|
302
|
-
name: 'tokenProgram',
|
303
|
-
isMut: false,
|
304
|
-
isSigner: false
|
305
|
-
},
|
306
|
-
{
|
307
|
-
name: 'systemProgram',
|
308
|
-
isMut: false,
|
309
|
-
isSigner: false
|
310
|
-
}
|
311
|
-
],
|
312
|
-
args: [
|
313
|
-
{
|
314
|
-
name: 'overrideCurrentTime',
|
315
|
-
type: 'i64'
|
316
|
-
}
|
317
|
-
]
|
318
|
-
},
|
319
|
-
{
|
320
|
-
name: 'createVault',
|
321
|
-
accounts: [
|
322
|
-
{
|
323
|
-
name: 'vaultSystemState',
|
324
|
-
isMut: true,
|
325
|
-
isSigner: false
|
326
|
-
},
|
327
|
-
{
|
328
|
-
name: 'vault',
|
329
|
-
isMut: true,
|
330
|
-
isSigner: true
|
331
|
-
},
|
332
|
-
{
|
333
|
-
name: 'history',
|
334
|
-
isMut: true,
|
335
|
-
isSigner: true
|
336
|
-
},
|
337
|
-
{
|
338
|
-
name: 'payer',
|
339
|
-
isMut: true,
|
340
|
-
isSigner: true
|
341
|
-
},
|
342
|
-
{
|
343
|
-
name: 'systemProgram',
|
344
|
-
isMut: false,
|
345
|
-
isSigner: false
|
346
|
-
}
|
347
|
-
],
|
348
|
-
args: [
|
349
|
-
{
|
350
|
-
name: 'depositAmount',
|
351
|
-
type: 'u64'
|
352
|
-
},
|
353
|
-
{
|
354
|
-
name: 'minCollateralRatio',
|
355
|
-
type: 'u64'
|
356
|
-
}
|
357
|
-
]
|
358
|
-
},
|
359
|
-
{
|
360
|
-
name: 'depositVault',
|
361
|
-
accounts: [
|
362
|
-
{
|
363
|
-
name: 'vaultSystemState',
|
364
|
-
isMut: true,
|
365
|
-
isSigner: false
|
366
|
-
},
|
367
|
-
{
|
368
|
-
name: 'vaultAccount',
|
369
|
-
isMut: true,
|
370
|
-
isSigner: false
|
371
|
-
},
|
372
|
-
{
|
373
|
-
name: 'history',
|
374
|
-
isMut: true,
|
375
|
-
isSigner: true
|
376
|
-
},
|
377
|
-
{
|
378
|
-
name: 'vaultOwner',
|
379
|
-
isMut: true,
|
380
|
-
isSigner: true
|
381
|
-
},
|
382
|
-
{
|
383
|
-
name: 'systemProgram',
|
384
|
-
isMut: false,
|
385
|
-
isSigner: false
|
386
|
-
}
|
387
|
-
],
|
388
|
-
args: [
|
389
|
-
{
|
390
|
-
name: 'depositAmount',
|
391
|
-
type: 'u64'
|
392
|
-
}
|
393
|
-
]
|
394
|
-
},
|
395
|
-
{
|
396
|
-
name: 'withdrawVault',
|
397
|
-
accounts: [
|
398
|
-
{
|
399
|
-
name: 'vaultSystemState',
|
400
|
-
isMut: true,
|
401
|
-
isSigner: false
|
402
|
-
},
|
403
|
-
{
|
404
|
-
name: 'vaultAccount',
|
405
|
-
isMut: true,
|
406
|
-
isSigner: false
|
407
|
-
},
|
408
|
-
{
|
409
|
-
name: 'history',
|
410
|
-
isMut: true,
|
411
|
-
isSigner: true
|
412
|
-
},
|
413
|
-
{
|
414
|
-
name: 'chainlinkFeedAccount',
|
415
|
-
isMut: false,
|
416
|
-
isSigner: false
|
417
|
-
},
|
418
|
-
{
|
419
|
-
name: 'vaultOwner',
|
420
|
-
isMut: true,
|
421
|
-
isSigner: true
|
422
|
-
},
|
423
|
-
{
|
424
|
-
name: 'systemProgram',
|
425
|
-
isMut: false,
|
426
|
-
isSigner: false
|
427
|
-
}
|
428
|
-
],
|
429
|
-
args: [
|
430
|
-
{
|
431
|
-
name: 'withdrawAmount',
|
432
|
-
type: 'u64'
|
433
|
-
},
|
434
|
-
{
|
435
|
-
name: 'overrideSolPrice',
|
436
|
-
type: 'u64'
|
437
|
-
}
|
438
|
-
]
|
439
|
-
},
|
440
|
-
{
|
441
|
-
name: 'loanVault',
|
442
|
-
accounts: [
|
443
|
-
{
|
444
|
-
name: 'vaultSystemState',
|
445
|
-
isMut: true,
|
446
|
-
isSigner: false
|
447
|
-
},
|
448
|
-
{
|
449
|
-
name: 'vaultAccount',
|
450
|
-
isMut: true,
|
451
|
-
isSigner: false
|
452
|
-
},
|
453
|
-
{
|
454
|
-
name: 'history',
|
455
|
-
isMut: true,
|
456
|
-
isSigner: true
|
457
|
-
},
|
458
|
-
{
|
459
|
-
name: 'feePool',
|
460
|
-
isMut: true,
|
461
|
-
isSigner: false
|
462
|
-
},
|
463
|
-
{
|
464
|
-
name: 'feePoolAssociatedUsdhTokenAccount',
|
465
|
-
isMut: true,
|
466
|
-
isSigner: false
|
467
|
-
},
|
468
|
-
{
|
469
|
-
name: 'usdhMint',
|
470
|
-
isMut: true,
|
471
|
-
isSigner: false
|
472
|
-
},
|
473
|
-
{
|
474
|
-
name: 'vaultOwner',
|
475
|
-
isMut: true,
|
476
|
-
isSigner: true
|
477
|
-
},
|
478
|
-
{
|
479
|
-
name: 'ownerUsdhAccount',
|
480
|
-
isMut: true,
|
481
|
-
isSigner: false
|
482
|
-
},
|
483
|
-
{
|
484
|
-
name: 'chainlinkFeedAccount',
|
485
|
-
isMut: false,
|
486
|
-
isSigner: false
|
487
|
-
},
|
488
|
-
{
|
489
|
-
name: 'tokenProgram',
|
490
|
-
isMut: false,
|
491
|
-
isSigner: false
|
492
|
-
},
|
493
|
-
{
|
494
|
-
name: 'systemProgram',
|
495
|
-
isMut: false,
|
496
|
-
isSigner: false
|
497
|
-
}
|
498
|
-
],
|
499
|
-
args: [
|
500
|
-
{
|
501
|
-
name: 'loanAmount',
|
502
|
-
type: 'u64'
|
503
|
-
},
|
504
|
-
{
|
505
|
-
name: 'overrideSolPrice',
|
506
|
-
type: 'u64'
|
507
|
-
}
|
508
|
-
]
|
509
|
-
},
|
510
|
-
{
|
511
|
-
name: 'repayVault',
|
512
|
-
accounts: [
|
513
|
-
{
|
514
|
-
name: 'vaultSystemState',
|
515
|
-
isMut: true,
|
516
|
-
isSigner: false
|
517
|
-
},
|
518
|
-
{
|
519
|
-
name: 'vaultAccount',
|
520
|
-
isMut: true,
|
521
|
-
isSigner: false
|
522
|
-
},
|
523
|
-
{
|
524
|
-
name: 'history',
|
525
|
-
isMut: true,
|
526
|
-
isSigner: true
|
527
|
-
},
|
528
|
-
{
|
529
|
-
name: 'usdhMint',
|
530
|
-
isMut: true,
|
531
|
-
isSigner: false
|
532
|
-
},
|
533
|
-
{
|
534
|
-
name: 'vaultOwner',
|
535
|
-
isMut: true,
|
536
|
-
isSigner: true
|
537
|
-
},
|
538
|
-
{
|
539
|
-
name: 'ownerUsdhAccount',
|
540
|
-
isMut: true,
|
541
|
-
isSigner: false
|
542
|
-
},
|
543
|
-
{
|
544
|
-
name: 'tokenProgram',
|
545
|
-
isMut: false,
|
546
|
-
isSigner: false
|
547
|
-
},
|
548
|
-
{
|
549
|
-
name: 'systemProgram',
|
550
|
-
isMut: false,
|
551
|
-
isSigner: false
|
552
|
-
}
|
553
|
-
],
|
554
|
-
args: [
|
555
|
-
{
|
556
|
-
name: 'repayAmount',
|
557
|
-
type: 'u64'
|
558
|
-
}
|
559
|
-
]
|
560
|
-
},
|
561
|
-
{
|
562
|
-
name: 'redeemVault',
|
563
|
-
accounts: [
|
564
|
-
{
|
565
|
-
name: 'vaultSystemState',
|
566
|
-
isMut: true,
|
567
|
-
isSigner: false
|
568
|
-
},
|
569
|
-
{
|
570
|
-
name: 'vaultAccount',
|
571
|
-
isMut: true,
|
572
|
-
isSigner: false
|
573
|
-
},
|
574
|
-
{
|
575
|
-
name: 'history',
|
576
|
-
isMut: true,
|
577
|
-
isSigner: true
|
578
|
-
},
|
579
|
-
{
|
580
|
-
name: 'usdhMint',
|
581
|
-
isMut: true,
|
582
|
-
isSigner: false
|
583
|
-
},
|
584
|
-
{
|
585
|
-
name: 'feePool',
|
586
|
-
isMut: true,
|
587
|
-
isSigner: false
|
588
|
-
},
|
589
|
-
{
|
590
|
-
name: 'feePoolAssociatedUsdhTokenAccount',
|
591
|
-
isMut: true,
|
592
|
-
isSigner: false
|
593
|
-
},
|
594
|
-
{
|
595
|
-
name: 'payer',
|
596
|
-
isMut: true,
|
597
|
-
isSigner: true
|
598
|
-
},
|
599
|
-
{
|
600
|
-
name: 'payerUsdhAccount',
|
601
|
-
isMut: true,
|
602
|
-
isSigner: false
|
603
|
-
},
|
604
|
-
{
|
605
|
-
name: 'chainlinkFeedAccount',
|
606
|
-
isMut: false,
|
607
|
-
isSigner: false
|
608
|
-
},
|
609
|
-
{
|
610
|
-
name: 'tokenProgram',
|
611
|
-
isMut: false,
|
612
|
-
isSigner: false
|
613
|
-
},
|
614
|
-
{
|
615
|
-
name: 'systemProgram',
|
616
|
-
isMut: false,
|
617
|
-
isSigner: false
|
618
|
-
}
|
619
|
-
],
|
620
|
-
args: [
|
621
|
-
{
|
622
|
-
name: 'redeemPayUsdh',
|
623
|
-
type: 'u64'
|
624
|
-
},
|
625
|
-
{
|
626
|
-
name: 'overrideSolPrice',
|
627
|
-
type: 'u64'
|
628
|
-
},
|
629
|
-
{
|
630
|
-
name: 'overrideCurrentTime',
|
631
|
-
type: 'i64'
|
632
|
-
}
|
633
|
-
]
|
634
|
-
},
|
635
|
-
{
|
636
|
-
name: 'depositLiquidityPool',
|
637
|
-
accounts: [
|
638
|
-
{
|
639
|
-
name: 'poolState',
|
640
|
-
isMut: true,
|
641
|
-
isSigner: false
|
642
|
-
},
|
643
|
-
{
|
644
|
-
name: 'poolUsdhAccount',
|
645
|
-
isMut: true,
|
646
|
-
isSigner: false
|
647
|
-
},
|
648
|
-
{
|
649
|
-
name: 'poolEra',
|
650
|
-
isMut: true,
|
651
|
-
isSigner: false
|
652
|
-
},
|
653
|
-
{
|
654
|
-
name: 'poolPosition',
|
655
|
-
isMut: true,
|
656
|
-
isSigner: true
|
657
|
-
},
|
658
|
-
{
|
659
|
-
name: 'payer',
|
660
|
-
isMut: true,
|
661
|
-
isSigner: true
|
662
|
-
},
|
663
|
-
{
|
664
|
-
name: 'ownerUsdhAccount',
|
665
|
-
isMut: true,
|
666
|
-
isSigner: false
|
667
|
-
},
|
668
|
-
{
|
669
|
-
name: 'tokenProgram',
|
670
|
-
isMut: false,
|
671
|
-
isSigner: false
|
672
|
-
},
|
673
|
-
{
|
674
|
-
name: 'systemProgram',
|
675
|
-
isMut: false,
|
676
|
-
isSigner: false
|
677
|
-
}
|
678
|
-
],
|
679
|
-
args: [
|
680
|
-
{
|
681
|
-
name: 'depositAmount',
|
682
|
-
type: 'u64'
|
683
|
-
},
|
684
|
-
{
|
685
|
-
name: 'overrideCurrentTime',
|
686
|
-
type: 'i64'
|
687
|
-
}
|
688
|
-
]
|
689
|
-
},
|
690
|
-
{
|
691
|
-
name: 'liquidateVault',
|
692
|
-
accounts: [
|
693
|
-
{
|
694
|
-
name: 'vaultSystemState',
|
695
|
-
isMut: true,
|
696
|
-
isSigner: false
|
697
|
-
},
|
698
|
-
{
|
699
|
-
name: 'vaultAccount',
|
700
|
-
isMut: true,
|
701
|
-
isSigner: false
|
702
|
-
},
|
703
|
-
{
|
704
|
-
name: 'poolState',
|
705
|
-
isMut: true,
|
706
|
-
isSigner: false
|
707
|
-
},
|
708
|
-
{
|
709
|
-
name: 'feePool',
|
710
|
-
isMut: true,
|
711
|
-
isSigner: false
|
712
|
-
},
|
713
|
-
{
|
714
|
-
name: 'poolUsdhAccount',
|
715
|
-
isMut: true,
|
716
|
-
isSigner: false
|
717
|
-
},
|
718
|
-
{
|
719
|
-
name: 'usdhMint',
|
720
|
-
isMut: true,
|
721
|
-
isSigner: false
|
722
|
-
},
|
723
|
-
{
|
724
|
-
name: 'poolEra',
|
725
|
-
isMut: true,
|
726
|
-
isSigner: false
|
727
|
-
},
|
728
|
-
{
|
729
|
-
name: 'newEra',
|
730
|
-
isMut: true,
|
731
|
-
isSigner: true
|
732
|
-
},
|
733
|
-
{
|
734
|
-
name: 'chainlinkFeedAccount',
|
735
|
-
isMut: false,
|
736
|
-
isSigner: false
|
737
|
-
},
|
738
|
-
{
|
739
|
-
name: 'history',
|
740
|
-
isMut: true,
|
741
|
-
isSigner: true
|
742
|
-
},
|
743
|
-
{
|
744
|
-
name: 'payer',
|
745
|
-
isMut: true,
|
746
|
-
isSigner: true
|
747
|
-
},
|
748
|
-
{
|
749
|
-
name: 'tokenProgram',
|
750
|
-
isMut: false,
|
751
|
-
isSigner: false
|
752
|
-
},
|
753
|
-
{
|
754
|
-
name: 'systemProgram',
|
755
|
-
isMut: false,
|
756
|
-
isSigner: false
|
757
|
-
}
|
758
|
-
],
|
759
|
-
args: [
|
760
|
-
{
|
761
|
-
name: 'overrideSolPrice',
|
762
|
-
type: 'u64'
|
763
|
-
}
|
764
|
-
]
|
765
|
-
},
|
766
|
-
{
|
767
|
-
name: 'withdrawLiquidity',
|
768
|
-
accounts: [
|
769
|
-
{
|
770
|
-
name: 'poolState',
|
771
|
-
isMut: true,
|
772
|
-
isSigner: false
|
773
|
-
},
|
774
|
-
{
|
775
|
-
name: 'poolEra',
|
776
|
-
isMut: true,
|
777
|
-
isSigner: false
|
778
|
-
},
|
779
|
-
{
|
780
|
-
name: 'poolPosition',
|
781
|
-
isMut: true,
|
782
|
-
isSigner: false
|
783
|
-
},
|
784
|
-
{
|
785
|
-
name: 'poolUsdhAccount',
|
786
|
-
isMut: true,
|
787
|
-
isSigner: false
|
788
|
-
},
|
789
|
-
{
|
790
|
-
name: 'payer',
|
791
|
-
isMut: true,
|
792
|
-
isSigner: true
|
793
|
-
},
|
794
|
-
{
|
795
|
-
name: 'ownerUsdhAccount',
|
796
|
-
isMut: true,
|
797
|
-
isSigner: false
|
798
|
-
},
|
799
|
-
{
|
800
|
-
name: 'hedgeMint',
|
801
|
-
isMut: true,
|
802
|
-
isSigner: false
|
803
|
-
},
|
804
|
-
{
|
805
|
-
name: 'payerAssociatedHedgeAccount',
|
806
|
-
isMut: true,
|
807
|
-
isSigner: false
|
808
|
-
},
|
809
|
-
{
|
810
|
-
name: 'rent',
|
811
|
-
isMut: false,
|
812
|
-
isSigner: false
|
813
|
-
},
|
814
|
-
{
|
815
|
-
name: 'tokenProgram',
|
816
|
-
isMut: false,
|
817
|
-
isSigner: false
|
818
|
-
},
|
819
|
-
{
|
820
|
-
name: 'associatedTokenProgram',
|
821
|
-
isMut: false,
|
822
|
-
isSigner: false
|
823
|
-
},
|
824
|
-
{
|
825
|
-
name: 'systemProgram',
|
826
|
-
isMut: false,
|
827
|
-
isSigner: false
|
828
|
-
}
|
829
|
-
],
|
830
|
-
args: [
|
831
|
-
{
|
832
|
-
name: 'overrideCurrentTime',
|
833
|
-
type: 'i64'
|
834
|
-
}
|
835
|
-
]
|
836
|
-
}
|
837
|
-
],
|
838
|
-
accounts: [
|
839
|
-
{
|
840
|
-
name: 'StakingPool',
|
841
|
-
type: {
|
842
|
-
kind: 'struct',
|
843
|
-
fields: [
|
844
|
-
{
|
845
|
-
name: 'deposits',
|
846
|
-
type: 'u64'
|
847
|
-
},
|
848
|
-
{
|
849
|
-
name: 'bump',
|
850
|
-
type: 'u8'
|
851
|
-
},
|
852
|
-
{
|
853
|
-
name: 'seedPhrase',
|
854
|
-
type: 'string'
|
855
|
-
},
|
856
|
-
{
|
857
|
-
name: 'hedgeRewardAccumulator',
|
858
|
-
type: 'u128'
|
859
|
-
},
|
860
|
-
{
|
861
|
-
name: 'usdhFeeAccumulator',
|
862
|
-
type: 'u128'
|
863
|
-
},
|
864
|
-
{
|
865
|
-
name: 'solFeeAccumulator',
|
866
|
-
type: 'u128'
|
867
|
-
},
|
868
|
-
{
|
869
|
-
name: 'startTime',
|
870
|
-
type: 'i64'
|
871
|
-
},
|
872
|
-
{
|
873
|
-
name: 'lastTransactionTime',
|
874
|
-
type: 'i64'
|
875
|
-
},
|
876
|
-
{
|
877
|
-
name: 'halfLifeInDays',
|
878
|
-
type: 'u64'
|
879
|
-
},
|
880
|
-
{
|
881
|
-
name: 'totalHedgeReward',
|
882
|
-
type: 'u64'
|
883
|
-
},
|
884
|
-
{
|
885
|
-
name: 'stakedTokenMint',
|
886
|
-
type: 'publicKey'
|
887
|
-
}
|
888
|
-
]
|
889
|
-
}
|
890
|
-
},
|
891
|
-
{
|
892
|
-
name: 'StakingPoolPosition',
|
893
|
-
type: {
|
894
|
-
kind: 'struct',
|
895
|
-
fields: [
|
896
|
-
{
|
897
|
-
name: 'state',
|
898
|
-
type: {
|
899
|
-
defined: 'PositionState'
|
900
|
-
}
|
901
|
-
},
|
902
|
-
{
|
903
|
-
name: 'owner',
|
904
|
-
type: 'publicKey'
|
905
|
-
},
|
906
|
-
{
|
907
|
-
name: 'pool',
|
908
|
-
type: 'publicKey'
|
909
|
-
},
|
910
|
-
{
|
911
|
-
name: 'deposited',
|
912
|
-
type: 'u64'
|
913
|
-
},
|
914
|
-
{
|
915
|
-
name: 'startHedgeRewardAccumulator',
|
916
|
-
type: 'u128'
|
917
|
-
},
|
918
|
-
{
|
919
|
-
name: 'startUsdhFeeAccumulator',
|
920
|
-
type: 'u128'
|
921
|
-
},
|
922
|
-
{
|
923
|
-
name: 'startSolFeeAccumulator',
|
924
|
-
type: 'u128'
|
925
|
-
},
|
926
|
-
{
|
927
|
-
name: 'timestampOpened',
|
928
|
-
type: 'i64'
|
929
|
-
},
|
930
|
-
{
|
931
|
-
name: 'timestampClosed',
|
932
|
-
type: 'i64'
|
933
|
-
},
|
934
|
-
{
|
935
|
-
name: 'closedRewardedTokens',
|
936
|
-
type: 'u64'
|
937
|
-
}
|
938
|
-
]
|
939
|
-
}
|
940
|
-
},
|
941
|
-
{
|
942
|
-
name: 'VaultSystemState',
|
943
|
-
type: {
|
944
|
-
kind: 'struct',
|
945
|
-
fields: [
|
946
|
-
{
|
947
|
-
name: 'lastRedeemFeeBytes',
|
948
|
-
type: 'u128'
|
949
|
-
},
|
950
|
-
{
|
951
|
-
name: 'lastRedeemTimestamp',
|
952
|
-
type: 'i64'
|
953
|
-
},
|
954
|
-
{
|
955
|
-
name: 'totalCollateral',
|
956
|
-
type: 'u64'
|
957
|
-
},
|
958
|
-
{
|
959
|
-
name: 'totalUsdhSupply',
|
960
|
-
type: 'u64'
|
961
|
-
},
|
962
|
-
{
|
963
|
-
name: 'totalVaults',
|
964
|
-
type: 'u64'
|
965
|
-
},
|
966
|
-
{
|
967
|
-
name: 'totalVaultsClosed',
|
968
|
-
type: 'u64'
|
969
|
-
},
|
970
|
-
{
|
971
|
-
name: 'debtRedistributionProduct',
|
972
|
-
type: 'u128'
|
973
|
-
},
|
974
|
-
{
|
975
|
-
name: 'collateralRedistributionAccumulator',
|
976
|
-
type: 'u128'
|
977
|
-
},
|
978
|
-
{
|
979
|
-
name: 'debtRedistributionError',
|
980
|
-
type: 'u64'
|
981
|
-
},
|
982
|
-
{
|
983
|
-
name: 'bumpVaultState',
|
984
|
-
type: 'u8'
|
985
|
-
},
|
986
|
-
{
|
987
|
-
name: 'bumpPoolState',
|
988
|
-
type: 'u8'
|
989
|
-
},
|
990
|
-
{
|
991
|
-
name: 'bumpMint',
|
992
|
-
type: 'u8'
|
993
|
-
},
|
994
|
-
{
|
995
|
-
name: 'bumpUsdhPoolAccount',
|
996
|
-
type: 'u8'
|
997
|
-
},
|
998
|
-
{
|
999
|
-
name: 'authority',
|
1000
|
-
type: 'publicKey'
|
1001
|
-
},
|
1002
|
-
{
|
1003
|
-
name: 'oracleChainlink',
|
1004
|
-
type: 'publicKey'
|
1005
|
-
},
|
1006
|
-
{
|
1007
|
-
name: 'oraclePyth',
|
1008
|
-
type: 'publicKey'
|
1009
|
-
},
|
1010
|
-
{
|
1011
|
-
name: 'oracleSwitchboard',
|
1012
|
-
type: 'publicKey'
|
1013
|
-
},
|
1014
|
-
{
|
1015
|
-
name: 'hedgeStakingPool',
|
1016
|
-
type: 'publicKey'
|
1017
|
-
}
|
1018
|
-
]
|
1019
|
-
}
|
1020
|
-
},
|
1021
|
-
{
|
1022
|
-
name: 'Vault',
|
1023
|
-
type: {
|
1024
|
-
kind: 'struct',
|
1025
|
-
fields: [
|
1026
|
-
{
|
1027
|
-
name: 'vaultOwner',
|
1028
|
-
type: 'publicKey'
|
1029
|
-
},
|
1030
|
-
{
|
1031
|
-
name: 'deposited',
|
1032
|
-
type: 'u64'
|
1033
|
-
},
|
1034
|
-
{
|
1035
|
-
name: 'debt',
|
1036
|
-
type: 'u64'
|
1037
|
-
},
|
1038
|
-
{
|
1039
|
-
name: 'vaultVersion',
|
1040
|
-
type: 'u64'
|
1041
|
-
},
|
1042
|
-
{
|
1043
|
-
name: 'liquidationPrice',
|
1044
|
-
type: 'u64'
|
1045
|
-
},
|
1046
|
-
{
|
1047
|
-
name: 'minCollateralRatio',
|
1048
|
-
type: 'u128'
|
1049
|
-
},
|
1050
|
-
{
|
1051
|
-
name: 'debtProductSnapshotBytes',
|
1052
|
-
type: 'u128'
|
1053
|
-
},
|
1054
|
-
{
|
1055
|
-
name: 'collateralAccumulatorSnapshotBytes',
|
1056
|
-
type: 'u128'
|
1057
|
-
},
|
1058
|
-
{
|
1059
|
-
name: 'collateralType',
|
1060
|
-
type: {
|
1061
|
-
defined: 'CurrencyType'
|
1062
|
-
}
|
1063
|
-
},
|
1064
|
-
{
|
1065
|
-
name: 'debtType',
|
1066
|
-
type: {
|
1067
|
-
defined: 'CurrencyType'
|
1068
|
-
}
|
1069
|
-
},
|
1070
|
-
{
|
1071
|
-
name: 'vaultStatus',
|
1072
|
-
type: {
|
1073
|
-
defined: 'VaultStatus'
|
1074
|
-
}
|
1075
|
-
}
|
1076
|
-
]
|
1077
|
-
}
|
1078
|
-
},
|
1079
|
-
{
|
1080
|
-
name: 'VaultHistoryEvent',
|
1081
|
-
type: {
|
1082
|
-
kind: 'struct',
|
1083
|
-
fields: [
|
1084
|
-
{
|
1085
|
-
name: 'vaultAccount',
|
1086
|
-
type: 'publicKey'
|
1087
|
-
},
|
1088
|
-
{
|
1089
|
-
name: 'actorAccount',
|
1090
|
-
type: 'publicKey'
|
1091
|
-
},
|
1092
|
-
{
|
1093
|
-
name: 'usdSolPrice',
|
1094
|
-
type: 'u128'
|
1095
|
-
},
|
1096
|
-
{
|
1097
|
-
name: 'usdhDebtBefore',
|
1098
|
-
type: 'u64'
|
1099
|
-
},
|
1100
|
-
{
|
1101
|
-
name: 'usdhDebtAfter',
|
1102
|
-
type: 'u64'
|
1103
|
-
},
|
1104
|
-
{
|
1105
|
-
name: 'solBalanceBefore',
|
1106
|
-
type: 'u64'
|
1107
|
-
},
|
1108
|
-
{
|
1109
|
-
name: 'solBalanceAfter',
|
1110
|
-
type: 'u64'
|
1111
|
-
},
|
1112
|
-
{
|
1113
|
-
name: 'minCollateralRatioBefore',
|
1114
|
-
type: 'u128'
|
1115
|
-
},
|
1116
|
-
{
|
1117
|
-
name: 'minCollateralRatioAfter',
|
1118
|
-
type: 'u128'
|
1119
|
-
},
|
1120
|
-
{
|
1121
|
-
name: 'vaultStateBefore',
|
1122
|
-
type: {
|
1123
|
-
defined: 'VaultStatus'
|
1124
|
-
}
|
1125
|
-
},
|
1126
|
-
{
|
1127
|
-
name: 'vaultStateAfter',
|
1128
|
-
type: {
|
1129
|
-
defined: 'VaultStatus'
|
1130
|
-
}
|
1131
|
-
},
|
1132
|
-
{
|
1133
|
-
name: 'timestamp',
|
1134
|
-
type: 'i64'
|
1135
|
-
},
|
1136
|
-
{
|
1137
|
-
name: 'action',
|
1138
|
-
type: {
|
1139
|
-
defined: 'VaultHistoryAction'
|
1140
|
-
}
|
1141
|
-
}
|
1142
|
-
]
|
1143
|
-
}
|
1144
|
-
},
|
1145
|
-
{
|
1146
|
-
name: 'LiquidationPoolState',
|
1147
|
-
type: {
|
1148
|
-
kind: 'struct',
|
1149
|
-
fields: [
|
1150
|
-
{
|
1151
|
-
name: 'currentEra',
|
1152
|
-
type: 'publicKey'
|
1153
|
-
},
|
1154
|
-
{
|
1155
|
-
name: 'lifetimeDeposits',
|
1156
|
-
type: 'u64'
|
1157
|
-
},
|
1158
|
-
{
|
1159
|
-
name: 'lifetimeOpenedPositions',
|
1160
|
-
type: 'u64'
|
1161
|
-
},
|
1162
|
-
{
|
1163
|
-
name: 'lifetimeClosedPositions',
|
1164
|
-
type: 'u64'
|
1165
|
-
},
|
1166
|
-
{
|
1167
|
-
name: 'lifetimeVaultsLiquidated',
|
1168
|
-
type: 'u64'
|
1169
|
-
},
|
1170
|
-
{
|
1171
|
-
name: 'lifetimeVaultsRedistributed',
|
1172
|
-
type: 'u64'
|
1173
|
-
},
|
1174
|
-
{
|
1175
|
-
name: 'lifetimeSolPurchased',
|
1176
|
-
type: 'u64'
|
1177
|
-
},
|
1178
|
-
{
|
1179
|
-
name: 'lifetimeSolClaimed',
|
1180
|
-
type: 'u64'
|
1181
|
-
},
|
1182
|
-
{
|
1183
|
-
name: 'hedgeInitRewardsTimestamp',
|
1184
|
-
type: 'i64'
|
1185
|
-
}
|
1186
|
-
]
|
1187
|
-
}
|
1188
|
-
},
|
1189
|
-
{
|
1190
|
-
name: 'LiquidationPoolEra',
|
1191
|
-
type: {
|
1192
|
-
kind: 'struct',
|
1193
|
-
fields: [
|
1194
|
-
{
|
1195
|
-
name: 'totalDeposits',
|
1196
|
-
type: 'u64'
|
1197
|
-
},
|
1198
|
-
{
|
1199
|
-
name: 'productBytes',
|
1200
|
-
type: 'u128'
|
1201
|
-
},
|
1202
|
-
{
|
1203
|
-
name: 'sumBytes',
|
1204
|
-
type: 'u128'
|
1205
|
-
},
|
1206
|
-
{
|
1207
|
-
name: 'hedgeRewardsAccumulatorBytes',
|
1208
|
-
type: 'u128'
|
1209
|
-
},
|
1210
|
-
{
|
1211
|
-
name: 'hedgeRewardsTimestamp',
|
1212
|
-
type: 'i64'
|
1213
|
-
}
|
1214
|
-
]
|
1215
|
-
}
|
1216
|
-
},
|
1217
|
-
{
|
1218
|
-
name: 'LiquidationPosition',
|
1219
|
-
type: {
|
1220
|
-
kind: 'struct',
|
1221
|
-
fields: [
|
1222
|
-
{
|
1223
|
-
name: 'state',
|
1224
|
-
type: {
|
1225
|
-
defined: 'PositionState'
|
1226
|
-
}
|
1227
|
-
},
|
1228
|
-
{
|
1229
|
-
name: 'era',
|
1230
|
-
type: 'publicKey'
|
1231
|
-
},
|
1232
|
-
{
|
1233
|
-
name: 'ownerAccount',
|
1234
|
-
type: 'publicKey'
|
1235
|
-
},
|
1236
|
-
{
|
1237
|
-
name: 'deposit',
|
1238
|
-
type: 'u64'
|
1239
|
-
},
|
1240
|
-
{
|
1241
|
-
name: 'closedSol',
|
1242
|
-
type: 'u64'
|
1243
|
-
},
|
1244
|
-
{
|
1245
|
-
name: 'closedUsdh',
|
1246
|
-
type: 'u64'
|
1247
|
-
},
|
1248
|
-
{
|
1249
|
-
name: 'productSnapshotBytes',
|
1250
|
-
type: 'u128'
|
1251
|
-
},
|
1252
|
-
{
|
1253
|
-
name: 'sumSnapshotBytes',
|
1254
|
-
type: 'u128'
|
1255
|
-
},
|
1256
|
-
{
|
1257
|
-
name: 'hedgeRewardsSnapshotAccum',
|
1258
|
-
type: 'u128'
|
1259
|
-
},
|
1260
|
-
{
|
1261
|
-
name: 'timestampOpened',
|
1262
|
-
type: 'i64'
|
1263
|
-
},
|
1264
|
-
{
|
1265
|
-
name: 'timestampClosed',
|
1266
|
-
type: 'i64'
|
1267
|
-
}
|
1268
|
-
]
|
1269
|
-
}
|
1270
|
-
},
|
1271
|
-
{
|
1272
|
-
name: 'Aggregator',
|
1273
|
-
type: {
|
1274
|
-
kind: 'struct',
|
1275
|
-
fields: [
|
1276
|
-
{
|
1277
|
-
name: 'isInitialized',
|
1278
|
-
type: 'bool'
|
1279
|
-
},
|
1280
|
-
{
|
1281
|
-
name: 'version',
|
1282
|
-
type: 'u32'
|
1283
|
-
},
|
1284
|
-
{
|
1285
|
-
name: 'config',
|
1286
|
-
type: {
|
1287
|
-
defined: 'Config'
|
1288
|
-
}
|
1289
|
-
},
|
1290
|
-
{
|
1291
|
-
name: 'updatedAt',
|
1292
|
-
type: 'i64'
|
1293
|
-
},
|
1294
|
-
{
|
1295
|
-
name: 'owner',
|
1296
|
-
type: 'publicKey'
|
1297
|
-
},
|
1298
|
-
{
|
1299
|
-
name: 'submissions',
|
1300
|
-
type: {
|
1301
|
-
array: [
|
1302
|
-
{
|
1303
|
-
defined: 'Submission'
|
1304
|
-
},
|
1305
|
-
8
|
1306
|
-
]
|
1307
|
-
}
|
1308
|
-
},
|
1309
|
-
{
|
1310
|
-
name: 'answer',
|
1311
|
-
type: {
|
1312
|
-
option: 'u128'
|
1313
|
-
}
|
1314
|
-
}
|
1315
|
-
]
|
1316
|
-
}
|
1317
|
-
}
|
1318
|
-
],
|
1319
|
-
types: [
|
1320
|
-
{
|
1321
|
-
name: 'Config',
|
1322
|
-
type: {
|
1323
|
-
kind: 'struct',
|
1324
|
-
fields: [
|
1325
|
-
{
|
1326
|
-
name: 'oracles',
|
1327
|
-
type: {
|
1328
|
-
vec: 'publicKey'
|
1329
|
-
}
|
1330
|
-
},
|
1331
|
-
{
|
1332
|
-
name: 'minAnswerThreshold',
|
1333
|
-
type: 'u8'
|
1334
|
-
},
|
1335
|
-
{
|
1336
|
-
name: 'stalenessThreshold',
|
1337
|
-
type: 'u8'
|
1338
|
-
},
|
1339
|
-
{
|
1340
|
-
name: 'decimals',
|
1341
|
-
type: 'u8'
|
1342
|
-
}
|
1343
|
-
]
|
1344
|
-
}
|
1345
|
-
},
|
1346
|
-
{
|
1347
|
-
name: 'Submission',
|
1348
|
-
type: {
|
1349
|
-
kind: 'struct',
|
1350
|
-
fields: [
|
1351
|
-
{
|
1352
|
-
name: 'timestamp',
|
1353
|
-
type: 'i64'
|
1354
|
-
},
|
1355
|
-
{
|
1356
|
-
name: 'value',
|
1357
|
-
type: 'u128'
|
1358
|
-
}
|
1359
|
-
]
|
1360
|
-
}
|
1361
|
-
},
|
1362
|
-
{
|
1363
|
-
name: 'PositionState',
|
1364
|
-
type: {
|
1365
|
-
kind: 'enum',
|
1366
|
-
variants: [
|
1367
|
-
{
|
1368
|
-
name: 'Open'
|
1369
|
-
},
|
1370
|
-
{
|
1371
|
-
name: 'Closed'
|
1372
|
-
}
|
1373
|
-
]
|
1374
|
-
}
|
1375
|
-
},
|
1376
|
-
{
|
1377
|
-
name: 'CurrencyType',
|
1378
|
-
type: {
|
1379
|
-
kind: 'enum',
|
1380
|
-
variants: [
|
1381
|
-
{
|
1382
|
-
name: 'Solana'
|
1383
|
-
},
|
1384
|
-
{
|
1385
|
-
name: 'Usdh'
|
1386
|
-
}
|
1387
|
-
]
|
1388
|
-
}
|
1389
|
-
},
|
1390
|
-
{
|
1391
|
-
name: 'VaultStatus',
|
1392
|
-
type: {
|
1393
|
-
kind: 'enum',
|
1394
|
-
variants: [
|
1395
|
-
{
|
1396
|
-
name: 'Open'
|
1397
|
-
},
|
1398
|
-
{
|
1399
|
-
name: 'Closed'
|
1400
|
-
},
|
1401
|
-
{
|
1402
|
-
name: 'Liquidated'
|
1403
|
-
},
|
1404
|
-
{
|
1405
|
-
name: 'Distributed'
|
1406
|
-
},
|
1407
|
-
{
|
1408
|
-
name: 'Redeemed'
|
1409
|
-
}
|
1410
|
-
]
|
1411
|
-
}
|
1412
|
-
},
|
1413
|
-
{
|
1414
|
-
name: 'VaultHistoryAction',
|
1415
|
-
type: {
|
1416
|
-
kind: 'enum',
|
1417
|
-
variants: [
|
1418
|
-
{
|
1419
|
-
name: 'Create'
|
1420
|
-
},
|
1421
|
-
{
|
1422
|
-
name: 'Close'
|
1423
|
-
},
|
1424
|
-
{
|
1425
|
-
name: 'Liquidate'
|
1426
|
-
},
|
1427
|
-
{
|
1428
|
-
name: 'PartialLiquidate'
|
1429
|
-
},
|
1430
|
-
{
|
1431
|
-
name: 'Distributed'
|
1432
|
-
},
|
1433
|
-
{
|
1434
|
-
name: 'Redeem'
|
1435
|
-
},
|
1436
|
-
{
|
1437
|
-
name: 'TransferOwnership'
|
1438
|
-
},
|
1439
|
-
{
|
1440
|
-
name: 'Deposit'
|
1441
|
-
},
|
1442
|
-
{
|
1443
|
-
name: 'Withdraw'
|
1444
|
-
},
|
1445
|
-
{
|
1446
|
-
name: 'Loan'
|
1447
|
-
},
|
1448
|
-
{
|
1449
|
-
name: 'RepayCredit'
|
1450
|
-
}
|
1451
|
-
]
|
1452
|
-
}
|
1453
|
-
}
|
1454
|
-
],
|
1455
|
-
errors: [
|
1456
|
-
{
|
1457
|
-
code: 6000,
|
1458
|
-
name: 'AlreadyInitialized',
|
1459
|
-
msg: 'This vault was already initialized'
|
1460
|
-
},
|
1461
|
-
{
|
1462
|
-
code: 6001,
|
1463
|
-
name: 'NotInitialized',
|
1464
|
-
msg: 'This vault was not initialized'
|
1465
|
-
},
|
1466
|
-
{
|
1467
|
-
code: 6002,
|
1468
|
-
name: 'Overdraw',
|
1469
|
-
msg: 'Cannot withdraw more than deposited'
|
1470
|
-
},
|
1471
|
-
{
|
1472
|
-
code: 6003,
|
1473
|
-
name: 'Overpaid',
|
1474
|
-
msg: 'Cannot repay more than loaned'
|
1475
|
-
},
|
1476
|
-
{
|
1477
|
-
code: 6004,
|
1478
|
-
name: 'NotAuthorizedToCreateStakingPools',
|
1479
|
-
msg: 'Signer not authorized to create new staking pools'
|
1480
|
-
},
|
1481
|
-
{
|
1482
|
-
code: 6005,
|
1483
|
-
name: 'BadSeed',
|
1484
|
-
msg: 'Bad Seed'
|
1485
|
-
}
|
1486
|
-
]
|
1
|
+
"use strict";
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
3
|
+
if (k2 === undefined) k2 = k;
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
5
|
+
}) : (function(o, m, k, k2) {
|
6
|
+
if (k2 === undefined) k2 = k;
|
7
|
+
o[k2] = m[k];
|
8
|
+
}));
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
1487
11
|
};
|
1488
|
-
|
1489
|
-
|
1490
|
-
|
1491
|
-
|
1492
|
-
|
1493
|
-
|
1494
|
-
|
1495
|
-
|
1496
|
-
|
1497
|
-
|
1498
|
-
|
1499
|
-
|
1500
|
-
|
1501
|
-
|
1502
|
-
|
1503
|
-
|
1504
|
-
|
1505
|
-
|
1506
|
-
|
1507
|
-
|
1508
|
-
|
1509
|
-
|
1510
|
-
|
1511
|
-
|
1512
|
-
|
1513
|
-
|
1514
|
-
}
|
1515
|
-
async function getVaultSystemStatePublicKey() {
|
1516
|
-
const [publicKey] = await web3_js.PublicKey.findProgramAddress([enc.encode('VaultSystemStateV1')], HEDGE_PROGRAM_PUBLICKEY);
|
1517
|
-
return publicKey;
|
1518
|
-
}
|
1519
|
-
async function getHedgeMintPublicKey() {
|
1520
|
-
const [publicKey] = await web3_js.PublicKey.findProgramAddress([enc.encode('HEDGEMintV1')], HEDGE_PROGRAM_PUBLICKEY);
|
1521
|
-
return publicKey;
|
1522
|
-
}
|
1523
|
-
async function getPoolPublicKeyForMint(mintPublicKey) {
|
1524
|
-
const strToEncode = (mintPublicKey.toString().substring(0, 12));
|
1525
|
-
const [publicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode(strToEncode)], HEDGE_PROGRAM_PUBLICKEY);
|
1526
|
-
return [publicKey, bump, strToEncode];
|
1527
|
-
}
|
1528
|
-
async function getCollateralStateAccountPublicKey(collateralType) {
|
1529
|
-
const [collateralStateAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY);
|
1530
|
-
return collateralStateAccount;
|
1531
|
-
}
|
1532
|
-
async function findVaultAddress(vaultSalt) {
|
1533
|
-
const [vaultAddress] = await web3_js.PublicKey.findProgramAddress([enc.encode('Vault'), enc.encode(vaultSalt)], HEDGE_PROGRAM_PUBLICKEY);
|
1534
|
-
return vaultAddress;
|
1535
|
-
}
|
1536
|
-
async function findAssociatedTokenAddress(walletAddress, tokenMintAddress) {
|
1537
|
-
return (await web3_js.PublicKey.findProgramAddress([
|
1538
|
-
walletAddress.toBuffer(),
|
1539
|
-
splToken.TOKEN_PROGRAM_ID.toBuffer(),
|
1540
|
-
tokenMintAddress.toBuffer()
|
1541
|
-
], splToken.ASSOCIATED_TOKEN_PROGRAM_ID))[0];
|
1542
|
-
}
|
1543
|
-
|
1544
|
-
async function createStakingPool(program, provider, payer, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
1545
|
-
const transaction = new web3_js.Transaction().add(await createStakingPoolInstruction(program, payer.publicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime));
|
1546
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors);
|
1547
|
-
const [poolPublickey] = await getPoolPublicKeyForMint(mintPublicKey);
|
1548
|
-
return poolPublickey;
|
1549
|
-
}
|
1550
|
-
async function createStakingPoolInstruction(program, payerPublicKey, mintPublicKey, hedgeTokensToBeMinted, overrideStartTime) {
|
1551
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
1552
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1553
|
-
const [poolPublickey, poolBump, poolSeedPhrase] = await getPoolPublicKeyForMint(mintPublicKey);
|
1554
|
-
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, mintPublicKey);
|
1555
|
-
const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey);
|
1556
|
-
return program.instruction.createStakingPool(poolBump, poolSeedPhrase, new anchor.BN(hedgeTokensToBeMinted), new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), {
|
1557
|
-
accounts: {
|
1558
|
-
signer: payerPublicKey,
|
1559
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
1560
|
-
pool: poolPublickey,
|
1561
|
-
stakedTokenMintInfo: mintPublicKey,
|
1562
|
-
usdhMint: usdhMintPublickey,
|
1563
|
-
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
1564
|
-
poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
|
1565
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
1566
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1567
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1568
|
-
systemProgram: web3_js.SystemProgram.programId
|
1569
|
-
},
|
1570
|
-
signers: []
|
1571
|
-
});
|
1572
|
-
}
|
1573
|
-
|
1574
|
-
async function depositStakingPool(program, provider, payer, mintPublicKey, depositAmount, overrideStartTime) {
|
1575
|
-
const poolPosition = web3_js.Keypair.generate();
|
1576
|
-
const transaction = new web3_js.Transaction().add(await depositStakingPoolInstruction(program, payer.publicKey, poolPosition.publicKey, mintPublicKey, depositAmount, overrideStartTime));
|
1577
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition], provider.opts).catch(parseAnchorErrors);
|
1578
|
-
return poolPosition.publicKey;
|
1579
|
-
}
|
1580
|
-
async function depositStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, depositAmount, overrideStartTime) {
|
1581
|
-
const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey);
|
1582
|
-
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey);
|
1583
|
-
const payersArbitraryTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey);
|
1584
|
-
return program.instruction.depositStakingPool(new anchor.BN(depositAmount), new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
1585
|
-
{
|
1586
|
-
accounts: {
|
1587
|
-
payer: payerPublicKey,
|
1588
|
-
pool: poolPublickey,
|
1589
|
-
poolPosition: poolPositionPublicKey,
|
1590
|
-
stakedTokenMintInfo: stakedTokenMintPublicKey,
|
1591
|
-
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
1592
|
-
payerAssociatedStakedTokenAccount: payersArbitraryTokenAccount,
|
1593
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
1594
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1595
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1596
|
-
systemProgram: web3_js.SystemProgram.programId
|
1597
|
-
},
|
1598
|
-
signers: []
|
1599
|
-
});
|
1600
|
-
}
|
1601
|
-
|
1602
|
-
async function withdrawStakingPool(program, provider, payer, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
|
1603
|
-
const poolPosition = web3_js.Keypair.generate();
|
1604
|
-
const transaction = new web3_js.Transaction().add(await withdrawStakingPoolInstruction(program, payer.publicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime));
|
1605
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors);
|
1606
|
-
return poolPosition.publicKey;
|
1607
|
-
}
|
1608
|
-
async function withdrawStakingPoolInstruction(program, payerPublicKey, poolPositionPublicKey, stakedTokenMintPublicKey, overrideStartTime) {
|
1609
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
1610
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1611
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey();
|
1612
|
-
const [poolPublickey] = await getPoolPublicKeyForMint(stakedTokenMintPublicKey);
|
1613
|
-
const poolAssociatedStakedTokenAccount = await findAssociatedTokenAddress(poolPublickey, stakedTokenMintPublicKey);
|
1614
|
-
const poolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(poolPublickey, usdhMintPublickey);
|
1615
|
-
const payerAssociatedStakedTokenAccount = await findAssociatedTokenAddress(payerPublicKey, stakedTokenMintPublicKey);
|
1616
|
-
const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payerPublicKey, hedgeMintPublickey);
|
1617
|
-
const payerAssociatedUsdhAccount = await findAssociatedTokenAddress(payerPublicKey, usdhMintPublickey);
|
1618
|
-
const communityHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMintPublickey);
|
1619
|
-
return program.instruction.withdrawStakingPool(new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
1620
|
-
{
|
1621
|
-
accounts: {
|
1622
|
-
payer: payerPublicKey,
|
1623
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
1624
|
-
pool: poolPublickey,
|
1625
|
-
poolPosition: poolPositionPublicKey,
|
1626
|
-
poolAssociatedStakedTokenAccount: poolAssociatedStakedTokenAccount,
|
1627
|
-
poolAssociatedUsdhTokenAccount: poolAssociatedUsdhTokenAccount,
|
1628
|
-
payerAssociatedStakedTokenAccount: payerAssociatedStakedTokenAccount,
|
1629
|
-
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
1630
|
-
payerAssociatedUsdhAccount: payerAssociatedUsdhAccount,
|
1631
|
-
communityAssociatedHedgeTokenAccount: communityHedgeTokenAccount,
|
1632
|
-
hedgeMint: hedgeMintPublickey,
|
1633
|
-
stakedTokenMint: stakedTokenMintPublicKey,
|
1634
|
-
usdhMint: usdhMintPublickey,
|
1635
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY,
|
1636
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1637
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1638
|
-
systemProgram: web3_js.SystemProgram.programId
|
1639
|
-
},
|
1640
|
-
signers: []
|
1641
|
-
});
|
1642
|
-
}
|
1643
|
-
|
1644
|
-
async function depositLiquidationPool(program, provider, payer, depositAmount, overrideStartTime) {
|
1645
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1646
|
-
const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1647
|
-
const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1648
|
-
const poolPosition = web3_js.Keypair.generate();
|
1649
|
-
const transaction = new web3_js.Transaction().add(await depositLiquidationPoolInstruction(program, payer.publicKey, payerUsdhAccount.address, poolPosition.publicKey, depositAmount, overrideStartTime));
|
1650
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, poolPosition], provider.opts).catch(parseAnchorErrors);
|
1651
|
-
return poolPosition.publicKey;
|
1652
|
-
}
|
1653
|
-
async function depositLiquidationPoolInstruction(program, payerPublicKey, payerUsdhAccount, poolPositionPublicKey, depositAmount, overrideStartTime) {
|
1654
|
-
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey();
|
1655
|
-
const liquidationPoolState = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
1656
|
-
const poolUSDHAccount = await getLiquidationPoolUsdhAccountPublicKey();
|
1657
|
-
const usdhMint = await getUsdhMintPublicKey();
|
1658
|
-
return program.instruction.depositLiquidationPool(new anchor.BN(depositAmount), new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
1659
|
-
{
|
1660
|
-
accounts: {
|
1661
|
-
poolState: liquidationPoolStatePublicKey,
|
1662
|
-
poolEra: liquidationPoolState.currentEra,
|
1663
|
-
poolPosition: poolPositionPublicKey,
|
1664
|
-
poolUsdhAccount: poolUSDHAccount,
|
1665
|
-
usdhMint: usdhMint,
|
1666
|
-
payer: payerPublicKey,
|
1667
|
-
ownerUsdhAccount: payerUsdhAccount,
|
1668
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1669
|
-
systemProgram: web3_js.SystemProgram.programId,
|
1670
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY
|
1671
|
-
},
|
1672
|
-
signers: []
|
1673
|
-
});
|
1674
|
-
}
|
1675
|
-
|
1676
|
-
async function closeLiquidationPoolPosition(program, provider, poolPosition, payer, overrideStartTime) {
|
1677
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1678
|
-
const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1679
|
-
const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1680
|
-
const poolState = await getLiquidationPoolStatePublicKey();
|
1681
|
-
const liquidationPositionAccount = await program.account.liquidationPosition.fetch(poolPosition);
|
1682
|
-
const poolEra = liquidationPositionAccount.era;
|
1683
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
1684
|
-
const poolUsdhAccount = await getLiquidationPoolUsdhAccountPublicKey();
|
1685
|
-
const hedgeMint = await getHedgeMintPublicKey();
|
1686
|
-
const payerAssociatedHedgeAccount = await findAssociatedTokenAddress(payer.publicKey, hedgeMint);
|
1687
|
-
const communityAssociatedHedgeTokenAccount = await findAssociatedTokenAddress(vaultSystemStatePublicKey, hedgeMint);
|
1688
|
-
const transaction = new web3_js.Transaction().add(await closeLiquidationPoolPositionInstruction(program, vaultSystemStatePublicKey, poolState, poolEra, poolPosition, poolUsdhAccount, payer.publicKey, payerUsdhAccount.address, hedgeMint, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime));
|
1689
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors);
|
1690
|
-
return poolPosition;
|
1691
|
-
}
|
1692
|
-
async function closeLiquidationPoolPositionInstruction(program, vaultSystemState, poolState, poolEra, poolPosition, poolUsdhAccount, payerPublicKey, payerUsdhAccount, hedgeMint, payerAssociatedHedgeAccount, communityAssociatedHedgeTokenAccount, overrideStartTime) {
|
1693
|
-
return program.instruction.closeLiquidationPoolPosition(new anchor.BN(overrideStartTime !== null && overrideStartTime !== void 0 ? overrideStartTime : Date.now() / 1000), // override current time
|
1694
|
-
{
|
1695
|
-
accounts: {
|
1696
|
-
vaultSystemState: vaultSystemState,
|
1697
|
-
poolState: poolState,
|
1698
|
-
poolEra: poolEra,
|
1699
|
-
poolPosition: poolPosition,
|
1700
|
-
poolUsdhAccount: poolUsdhAccount,
|
1701
|
-
payer: payerPublicKey,
|
1702
|
-
ownerUsdhAccount: payerUsdhAccount,
|
1703
|
-
hedgeMint: hedgeMint,
|
1704
|
-
payerAssociatedHedgeAccount: payerAssociatedHedgeAccount,
|
1705
|
-
communityAssociatedHedgeTokenAccount: communityAssociatedHedgeTokenAccount,
|
1706
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1707
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1708
|
-
systemProgram: web3_js.SystemProgram.programId,
|
1709
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY
|
1710
|
-
},
|
1711
|
-
signers: []
|
1712
|
-
});
|
1713
|
-
}
|
1714
|
-
|
1715
|
-
async function claimLiquidationPoolPosition(program, provider, poolPosition, payer, collateralType, overrideStartTime) {
|
1716
|
-
const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(collateralType);
|
1717
|
-
const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
|
1718
|
-
const collateralMint = collateralStateAccountInfo.collateralMint;
|
1719
|
-
const poolStatePublicKey = await getLiquidationPoolStatePublicKey();
|
1720
|
-
const poolAssociatedTokenAccount = await findAssociatedTokenAddress(poolStatePublicKey, collateralMint);
|
1721
|
-
const payerAssociatedTokenAccount = await findAssociatedTokenAddress(payer.publicKey, collateralMint);
|
1722
|
-
const transaction = new web3_js.Transaction().add(await claimLiquidationPoolPositionInstruction(program, poolStatePublicKey, poolAssociatedTokenAccount, collateralStateAccountPublicKey, collateralMint, poolPosition, payer.publicKey, payerAssociatedTokenAccount));
|
1723
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts).catch(parseAnchorErrors);
|
1724
|
-
return payerAssociatedTokenAccount;
|
1725
|
-
}
|
1726
|
-
async function claimLiquidationPoolPositionInstruction(program, poolState, poolAssociatedTokenAccount, collateralStateAccount, collateralMint, poolPosition, payer, payerAssociatedTokenAccount, overrideStartTime) {
|
1727
|
-
return program.instruction.claimLiquidationPoolPosition({
|
1728
|
-
accounts: {
|
1729
|
-
poolState: poolState,
|
1730
|
-
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
1731
|
-
collateralStateAccount: collateralStateAccount,
|
1732
|
-
collateralMint: collateralMint,
|
1733
|
-
poolPosition: poolPosition,
|
1734
|
-
payer: payer,
|
1735
|
-
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
1736
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1737
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1738
|
-
systemProgram: web3_js.SystemProgram.programId,
|
1739
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY
|
1740
|
-
},
|
1741
|
-
signers: []
|
1742
|
-
});
|
1743
|
-
}
|
1744
|
-
|
1745
|
-
async function createVault(program, provider, payer, collateralType, depositAmount, collateralRatio) {
|
1746
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1747
|
-
const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1748
|
-
const salt = uuid.v4().substring(0, 8);
|
1749
|
-
const newVaultPublicKey = await findVaultAddress(salt);
|
1750
|
-
const history = web3_js.Keypair.generate();
|
1751
|
-
// Prep the user to get USDH back out at some point
|
1752
|
-
await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1753
|
-
const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(collateralType);
|
1754
|
-
const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
|
1755
|
-
const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, collateralStateAccountInfo.collateralMint);
|
1756
|
-
const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(newVaultPublicKey, collateralStateAccountInfo.collateralMint);
|
1757
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
1758
|
-
const wrappedSolAccount = web3_js.Keypair.generate();
|
1759
|
-
const transaction = new web3_js.Transaction();
|
1760
|
-
const signers = [payer, history];
|
1761
|
-
if (collateralType === 'SOL') {
|
1762
|
-
transaction.add(web3_js.SystemProgram.createAccount({
|
1763
|
-
fromPubkey: payer.publicKey,
|
1764
|
-
lamports: depositAmount + 2.04e6,
|
1765
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
1766
|
-
programId: splToken.TOKEN_PROGRAM_ID,
|
1767
|
-
space: 165
|
1768
|
-
}), serum.TokenInstructions.initializeAccount({
|
1769
|
-
account: wrappedSolAccount.publicKey,
|
1770
|
-
mint: serum.TokenInstructions.WRAPPED_SOL_MINT,
|
1771
|
-
owner: payer.publicKey
|
1772
|
-
}));
|
1773
|
-
signers.push(wrappedSolAccount);
|
1774
|
-
}
|
1775
|
-
transaction.add(await createVaultInstruction(program, salt, vaultSystemStatePublicKey, payer.publicKey, collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount, newVaultPublicKey, vaultAssociatedCollateralAccountPublicKey, collateralStateAccountPublicKey, collateralStateAccountInfo.collateralMint, history.publicKey, depositAmount, collateralRatio));
|
1776
|
-
if (collateralType === 'SOL') {
|
1777
|
-
transaction.add(serum.TokenInstructions.closeAccount({
|
1778
|
-
source: wrappedSolAccount.publicKey,
|
1779
|
-
destination: payer.publicKey,
|
1780
|
-
owner: payer.publicKey
|
1781
|
-
}));
|
1782
|
-
}
|
1783
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, signers, provider === null || provider === void 0 ? void 0 : provider.opts).catch(parseAnchorErrors);
|
1784
|
-
return newVaultPublicKey;
|
1785
|
-
}
|
1786
|
-
async function createVaultInstruction(program, salt, vaultSystemStatePublicKey, payerPublicKey, payerTokenAccountPublicKey, vaultPublicKey, vaultAssociatedCollateralPublicKey, collateralStateAccount, collateralMint, historyPublicKey, depositAmount, collateralRatio) {
|
1787
|
-
const ix = program.instruction.createVault(salt, new anchor.BN(depositAmount), new anchor.BN(collateralRatio), {
|
1788
|
-
accounts: {
|
1789
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
1790
|
-
collateralStateAccount: collateralStateAccount,
|
1791
|
-
vault: vaultPublicKey,
|
1792
|
-
vaultAssociatedTokenAccount: vaultAssociatedCollateralPublicKey,
|
1793
|
-
history: historyPublicKey,
|
1794
|
-
payer: payerPublicKey,
|
1795
|
-
payerTokenAccount: payerTokenAccountPublicKey,
|
1796
|
-
collateralMint: collateralMint,
|
1797
|
-
systemProgram: web3_js.SystemProgram.programId,
|
1798
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1799
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
1800
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY
|
1801
|
-
},
|
1802
|
-
signers: []
|
1803
|
-
});
|
1804
|
-
return ix;
|
1805
|
-
}
|
1806
|
-
|
1807
|
-
async function depositVault(program, provider, payer, vaultPublicKey,
|
1808
|
-
// collateralType: string,
|
1809
|
-
depositAmount) {
|
1810
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1811
|
-
const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1812
|
-
// Prep the user to get USDH back out at some point
|
1813
|
-
await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1814
|
-
const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
|
1815
|
-
const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
|
1816
|
-
const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
|
1817
|
-
const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralStateAccountInfo.collateralMint);
|
1818
|
-
const payerTokenAccount = await findAssociatedTokenAddress(payer.publicKey, collateralStateAccountInfo.collateralMint);
|
1819
|
-
const vaultAssociatedCollateralAccountPublicKey = await findAssociatedTokenAddress(vaultPublicKey, collateralStateAccountInfo.collateralMint);
|
1820
|
-
const history = web3_js.Keypair.generate();
|
1821
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
1822
|
-
const wrappedSolAccount = web3_js.Keypair.generate();
|
1823
|
-
const transaction = new web3_js.Transaction();
|
1824
|
-
const signers = [payer, history];
|
1825
|
-
if (vaultAccount.collateralType === 'SOL') {
|
1826
|
-
transaction.add(web3_js.SystemProgram.createAccount({
|
1827
|
-
fromPubkey: payer.publicKey,
|
1828
|
-
lamports: depositAmount + 2.04e6,
|
1829
|
-
newAccountPubkey: wrappedSolAccount.publicKey,
|
1830
|
-
programId: splToken.TOKEN_PROGRAM_ID,
|
1831
|
-
space: 165
|
1832
|
-
}), serum.TokenInstructions.initializeAccount({
|
1833
|
-
account: wrappedSolAccount.publicKey,
|
1834
|
-
mint: serum.TokenInstructions.WRAPPED_SOL_MINT,
|
1835
|
-
owner: payer.publicKey
|
1836
|
-
}));
|
1837
|
-
signers.push(wrappedSolAccount);
|
1838
|
-
}
|
1839
|
-
transaction.add(await depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultAccount.collateralType === 'SOL' ? wrappedSolAccount.publicKey : payerTokenAccount, vaultPublicKey, vaultAssociatedCollateralAccountPublicKey, history.publicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, collateralStateAccountInfo.collateralMint, depositAmount));
|
1840
|
-
if (vaultAccount.collateralType === 'SOL') {
|
1841
|
-
transaction.add(serum.TokenInstructions.closeAccount({
|
1842
|
-
source: wrappedSolAccount.publicKey,
|
1843
|
-
destination: payer.publicKey,
|
1844
|
-
owner: payer.publicKey
|
1845
|
-
}));
|
1846
|
-
}
|
1847
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, signers, provider.opts);
|
1848
|
-
return vaultPublicKey;
|
1849
|
-
}
|
1850
|
-
async function depositVaultInstruction(program, vaultSystemStatePublicKey, vaultOwner, vaultOwnerTokenAccount, vaultPublicKey, vaultAssociatedTokenAccount, historyPublicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, collateralMint, depositAmount) {
|
1851
|
-
return program.instruction.depositVault(new anchor.BN(depositAmount), {
|
1852
|
-
accounts: {
|
1853
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
1854
|
-
collateralStateAccount: collateralStateAccountPublicKey,
|
1855
|
-
collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
|
1856
|
-
collateralTokenMint: collateralMint,
|
1857
|
-
vault: vaultPublicKey,
|
1858
|
-
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
1859
|
-
history: historyPublicKey,
|
1860
|
-
vaultOwner: vaultOwner,
|
1861
|
-
vaultOwnerTokenAccount: vaultOwnerTokenAccount,
|
1862
|
-
systemProgram: web3_js.SystemProgram.programId,
|
1863
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID
|
1864
|
-
},
|
1865
|
-
signers: []
|
1866
|
-
});
|
1867
|
-
}
|
1868
|
-
|
1869
|
-
async function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount) {
|
1870
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1871
|
-
const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1872
|
-
// Prep the user to get USDH back out at some point
|
1873
|
-
await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1874
|
-
const history = web3_js.Keypair.generate();
|
1875
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
1876
|
-
const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
|
1877
|
-
const collateralStateAccount = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
|
1878
|
-
const vaultAssociatedCollateralAccount = await findAssociatedTokenAddress(vaultPublicKey, serum.TokenInstructions.WRAPPED_SOL_MINT);
|
1879
|
-
const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccount);
|
1880
|
-
const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccount, collateralStateAccountInfo.collateralMint);
|
1881
|
-
const token = new splToken.Token(provider.connection, collateralStateAccountInfo.collateralMint, splToken.TOKEN_PROGRAM_ID, payer);
|
1882
|
-
const destinationTokenAccount = await token.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1883
|
-
const transaction = new web3_js.Transaction().add(await withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, destinationTokenAccount.address, vaultPublicKey, vaultAssociatedCollateralAccount, collateralStateAccount, collateralAssociatedTokenAccount, history.publicKey, withdrawAmount));
|
1884
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
|
1885
|
-
return vaultPublicKey;
|
1886
|
-
}
|
1887
|
-
async function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, destinationTokenAccount, vaultPublickey, vaultAssociatedCollateralPublicKey, collateralStateAccount, collateralAssociatedTokenAccount, historyPublicKey, withdrawAmount) {
|
1888
|
-
return program.instruction.withdrawVault(new anchor.BN(withdrawAmount), {
|
1889
|
-
accounts: {
|
1890
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
1891
|
-
collateralStateAccount: collateralStateAccount,
|
1892
|
-
collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
|
1893
|
-
vault: vaultPublickey,
|
1894
|
-
vaultAssociatedTokenAccount: vaultAssociatedCollateralPublicKey,
|
1895
|
-
history: historyPublicKey,
|
1896
|
-
vaultOwner: payerPublicKey,
|
1897
|
-
destinationTokenAccount: destinationTokenAccount,
|
1898
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1899
|
-
systemProgram: web3_js.SystemProgram.programId
|
1900
|
-
},
|
1901
|
-
signers: []
|
1902
|
-
});
|
1903
|
-
}
|
1904
|
-
|
1905
|
-
async function loanVault(program, provider, payer, vaultPublicKey, loanAmount) {
|
1906
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1907
|
-
const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1908
|
-
// Prep the user to get USDH back out at some point
|
1909
|
-
const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1910
|
-
const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
|
1911
|
-
const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
|
1912
|
-
const collateralStateAccount = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
|
1913
|
-
const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralStateAccount.collateralMint);
|
1914
|
-
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, collateralStateAccount.collateralMint);
|
1915
|
-
const history = web3_js.Keypair.generate();
|
1916
|
-
const transaction = new web3_js.Transaction().add(await loanVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, loanAmount));
|
1917
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
|
1918
|
-
return vaultPublicKey;
|
1919
|
-
}
|
1920
|
-
async function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, collateralStateAccount, collateralAssociatedTokenAccount, loanAmount) {
|
1921
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
1922
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1923
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey();
|
1924
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
|
1925
|
-
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
1926
|
-
return program.instruction.loanVault(new anchor.BN(loanAmount), {
|
1927
|
-
accounts: {
|
1928
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
1929
|
-
collateralStateAccount: collateralStateAccount,
|
1930
|
-
collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
|
1931
|
-
vaultAccount: vaultPublickey,
|
1932
|
-
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
1933
|
-
history: historyPublicKey,
|
1934
|
-
feePool: hedgeStakingPoolPublicKey,
|
1935
|
-
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
1936
|
-
usdhMint: usdhMintPublickey,
|
1937
|
-
vaultOwner: payerPublicKey,
|
1938
|
-
ownerUsdhAccount: ownerUsdhAccount,
|
1939
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1940
|
-
systemProgram: web3_js.SystemProgram.programId
|
1941
|
-
},
|
1942
|
-
signers: []
|
1943
|
-
});
|
1944
|
-
}
|
1945
|
-
|
1946
|
-
async function repayVault(program, provider, payer, vaultPublicKey, repayAmount) {
|
1947
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1948
|
-
const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1949
|
-
// Prep the user to get USDH back out at some point
|
1950
|
-
const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1951
|
-
const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
|
1952
|
-
const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
|
1953
|
-
const collateralStateAccount = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
|
1954
|
-
const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralStateAccount.collateralMint);
|
1955
|
-
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, collateralStateAccount.collateralMint);
|
1956
|
-
const history = web3_js.Keypair.generate();
|
1957
|
-
const transaction = new web3_js.Transaction().add(await repayVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, repayAmount));
|
1958
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
|
1959
|
-
return vaultPublicKey;
|
1960
|
-
}
|
1961
|
-
async function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, collateralStateAccount, collateralAssociatedTokenAccount, repayAmount) {
|
1962
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
1963
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1964
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey();
|
1965
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
|
1966
|
-
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
1967
|
-
return program.instruction.repayVault(new anchor.BN(repayAmount), {
|
1968
|
-
accounts: {
|
1969
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
1970
|
-
collateralStateAccount: collateralStateAccount,
|
1971
|
-
collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
|
1972
|
-
vaultAccount: vaultPublickey,
|
1973
|
-
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
1974
|
-
history: historyPublicKey,
|
1975
|
-
feePool: hedgeStakingPoolPublicKey,
|
1976
|
-
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
1977
|
-
usdhMint: usdhMintPublickey,
|
1978
|
-
vaultOwner: payerPublicKey,
|
1979
|
-
ownerUsdhAccount: ownerUsdhAccount,
|
1980
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
1981
|
-
systemProgram: web3_js.SystemProgram.programId
|
1982
|
-
},
|
1983
|
-
signers: []
|
1984
|
-
});
|
1985
|
-
}
|
1986
|
-
|
1987
|
-
async function redeemVault(program, provider, payer, vaultPublicKey, redeemAmount, transactionOverrideTime) {
|
1988
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
1989
|
-
const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
|
1990
|
-
// Prep the user to get USDH back out at some point
|
1991
|
-
const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1992
|
-
const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
|
1993
|
-
const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
|
1994
|
-
const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
|
1995
|
-
const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralStateAccountInfo.collateralMint);
|
1996
|
-
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, collateralStateAccountInfo.collateralMint);
|
1997
|
-
const token = new splToken.Token(provider.connection, collateralStateAccountInfo.collateralMint, splToken.TOKEN_PROGRAM_ID, payer);
|
1998
|
-
const payerTokenAccount = await token.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
1999
|
-
const history = web3_js.Keypair.generate();
|
2000
|
-
const transaction = new web3_js.Transaction().add(await redeemVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, payerTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, history.publicKey, collateralStateAccountPublicKey, collateralAssociatedTokenAccount, redeemAmount, transactionOverrideTime));
|
2001
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
|
2002
|
-
return vaultPublicKey;
|
2003
|
-
}
|
2004
|
-
async function redeemVaultInstruction(program, payerPublicKey, payerUsdhAccount, destinationTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, historyPublicKey, collateralStateAccount, collateralAssociatedTokenAccount, redeemAmount, transactionOverrideTime) {
|
2005
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
2006
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
2007
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey();
|
2008
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
|
2009
|
-
const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
|
2010
|
-
return program.instruction.redeemVault(new anchor.BN(redeemAmount), new anchor.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
|
2011
|
-
{
|
2012
|
-
accounts: {
|
2013
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
2014
|
-
collateralStateAccount: collateralStateAccount,
|
2015
|
-
collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
|
2016
|
-
vault: vaultPublickey,
|
2017
|
-
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
2018
|
-
history: historyPublicKey,
|
2019
|
-
feePool: hedgeStakingPoolPublicKey,
|
2020
|
-
feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
|
2021
|
-
usdhMint: usdhMintPublickey,
|
2022
|
-
payer: payerPublicKey,
|
2023
|
-
payerUsdhAccount: payerUsdhAccount,
|
2024
|
-
destinationTokenAccount: destinationTokenAccount,
|
2025
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
2026
|
-
systemProgram: web3_js.SystemProgram.programId
|
2027
|
-
},
|
2028
|
-
signers: []
|
2029
|
-
});
|
2030
|
-
}
|
2031
|
-
|
2032
|
-
async function liquidateVault(program, provider, payer, vaultPublicKey, preload) {
|
2033
|
-
const vaultAccount = await program.account.vault.fetch(vaultPublicKey);
|
2034
|
-
const collateralStateAccountPublicKey = await getCollateralStateAccountPublicKey(vaultAccount.collateralType);
|
2035
|
-
const collateralStateAccountInfo = await program.account.collateralState.fetch(collateralStateAccountPublicKey);
|
2036
|
-
const collateralMint = collateralStateAccountInfo.collateralMint;
|
2037
|
-
const token = new splToken.Token(provider.connection, collateralMint, splToken.TOKEN_PROGRAM_ID, payer);
|
2038
|
-
const hedgeMintPublickey = await getHedgeMintPublicKey();
|
2039
|
-
const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
|
2040
|
-
const liquidationPoolStatePublicKey = await getLiquidationPoolStatePublicKey();
|
2041
|
-
const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
|
2042
|
-
const payerAssociatedTokenAccount = await token.getOrCreateAssociatedAccountInfo(payer.publicKey);
|
2043
|
-
const feePoolAssociatedTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, collateralMint);
|
2044
|
-
const vaultAssociatedTokenAccount = await findAssociatedTokenAddress(vaultPublicKey, collateralMint);
|
2045
|
-
const poolAssociatedTokenAccount = await findAssociatedTokenAddress(liquidationPoolStatePublicKey, collateralMint);
|
2046
|
-
const collateralAssociatedTokenAccount = await findAssociatedTokenAddress(collateralStateAccountPublicKey, collateralMint);
|
2047
|
-
const history = web3_js.Keypair.generate();
|
2048
|
-
const newEra = web3_js.Keypair.generate();
|
2049
|
-
const transaction = new web3_js.Transaction();
|
2050
|
-
transaction.add(await liquidateVaultInstruction(program, payer.publicKey, payerAssociatedTokenAccount.address, vaultPublicKey, vaultAssociatedTokenAccount, liquidationPoolStatePublicKey, poolStateInfo.currentEra, poolAssociatedTokenAccount, history.publicKey, newEra.publicKey, hedgeStakingPoolPublicKey, feePoolAssociatedTokenAccount, collateralMint, collateralAssociatedTokenAccount, vaultAccount.collateralType, preload));
|
2051
|
-
await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history, newEra], provider.opts);
|
2052
|
-
return vaultPublicKey;
|
2053
|
-
}
|
2054
|
-
async function liquidateVaultInstruction(program, payerPublicKey, payerAssociatedTokenAccount, vaultPublickey, vaultAssociatedTokenAccount, poolState, poolEra, poolAssociatedTokenAccount, historyPublicKey, newEraPublicKey, feePool, feePoolAssociatedTokenAccount, collateralMint, collateralAssociatedTokenAccount, collateralType, preload) {
|
2055
|
-
const vaultSystemStatePublicKey = await getVaultSystemStatePublicKey();
|
2056
|
-
const usdhMintPublickey = await getUsdhMintPublicKey();
|
2057
|
-
const liquidationPoolUsdhAccountPublickey = await getLiquidationPoolUsdhAccountPublicKey();
|
2058
|
-
const collateralStateAccount = await getCollateralStateAccountPublicKey(collateralType);
|
2059
|
-
const payload = {
|
2060
|
-
accounts: {
|
2061
|
-
vaultSystemState: vaultSystemStatePublicKey,
|
2062
|
-
collateralStateAccount: collateralStateAccount,
|
2063
|
-
collateralAssociatedTokenAccount: collateralAssociatedTokenAccount,
|
2064
|
-
collateralMint: collateralMint,
|
2065
|
-
poolEra: poolEra,
|
2066
|
-
vaultAccount: vaultPublickey,
|
2067
|
-
vaultAssociatedTokenAccount: vaultAssociatedTokenAccount,
|
2068
|
-
poolState: poolState,
|
2069
|
-
poolAssociatedTokenAccount: poolAssociatedTokenAccount,
|
2070
|
-
usdhMint: usdhMintPublickey,
|
2071
|
-
history: historyPublicKey,
|
2072
|
-
payer: payerPublicKey,
|
2073
|
-
payerAssociatedTokenAccount: payerAssociatedTokenAccount,
|
2074
|
-
feePool: feePool,
|
2075
|
-
feePoolAssociatedTokenAccount: feePoolAssociatedTokenAccount,
|
2076
|
-
liquidationPoolUsdhAccount: liquidationPoolUsdhAccountPublickey,
|
2077
|
-
newEra: newEraPublicKey,
|
2078
|
-
tokenProgram: splToken.TOKEN_PROGRAM_ID,
|
2079
|
-
systemProgram: web3_js.SystemProgram.programId,
|
2080
|
-
associatedTokenProgram: splToken.ASSOCIATED_TOKEN_PROGRAM_ID,
|
2081
|
-
rent: web3_js.SYSVAR_RENT_PUBKEY
|
2082
|
-
},
|
2083
|
-
signers: []
|
2084
|
-
};
|
2085
|
-
if (preload) {
|
2086
|
-
return program.instruction.liquidateVaultPrepAccounts(payload);
|
2087
|
-
}
|
2088
|
-
return program.instruction.liquidateVault(payload);
|
2089
|
-
}
|
2090
|
-
|
2091
|
-
async function refreshOraclePrice(program, provider, payer, collateralType, network, overridePrice, overrideTime) {
|
2092
|
-
const transaction = new web3_js.Transaction().add(await refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime));
|
2093
|
-
return await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts);
|
2094
|
-
}
|
2095
|
-
async function refreshOraclePriceInstruction(program, collateralType, network, overridePrice, overrideTime) {
|
2096
|
-
const enc = new TextEncoder();
|
2097
|
-
const [oracleInfoAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY);
|
2098
|
-
const [collateralStateAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode(collateralType), enc.encode('State')], HEDGE_PROGRAM_PUBLICKEY);
|
2099
|
-
return program.instruction.refreshOraclePrice(new anchor.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js.LAMPORTS_PER_SOL * 150), // override usd/sol price
|
2100
|
-
new anchor.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
|
2101
|
-
{
|
2102
|
-
accounts: {
|
2103
|
-
oracleInfoAccount: oracleInfoAccount,
|
2104
|
-
collateralStateAccount: collateralStateAccount,
|
2105
|
-
oracleChainlink: chainlinkAccunts[network],
|
2106
|
-
oraclePyth: pythAccounts[network],
|
2107
|
-
oracleSwitchboard: switchboardAccounts[network],
|
2108
|
-
systemProgram: web3_js.SystemProgram.programId
|
2109
|
-
},
|
2110
|
-
signers: []
|
2111
|
-
});
|
2112
|
-
}
|
2113
|
-
var Cluster;
|
2114
|
-
(function (Cluster) {
|
2115
|
-
Cluster["Testing"] = "Testing";
|
2116
|
-
Cluster["Devnet"] = "Devnet";
|
2117
|
-
Cluster["MainnetBeta"] = "MainnetBeta";
|
2118
|
-
})(Cluster || (Cluster = {}));
|
2119
|
-
const pythAccounts = {
|
2120
|
-
Testing: web3_js.SystemProgram.programId,
|
2121
|
-
Devnet: new web3_js.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
|
2122
|
-
MainnetBeta: new web3_js.PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')
|
2123
|
-
};
|
2124
|
-
const chainlinkAccunts = {
|
2125
|
-
Testing: web3_js.SystemProgram.programId,
|
2126
|
-
Devnet: new web3_js.PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
|
2127
|
-
MainnetBeta: web3_js.SystemProgram.programId // CHAINLINK NOT ON MAINNET YET
|
2128
|
-
};
|
2129
|
-
const switchboardAccounts = {
|
2130
|
-
Testing: web3_js.SystemProgram.programId,
|
2131
|
-
// Devnet: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
|
2132
|
-
Devnet: new web3_js.PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'),
|
2133
|
-
MainnetBeta: web3_js.SystemProgram.programId // Switchboard V2 NOT ON MAINNET YET
|
2134
|
-
};
|
2135
|
-
|
2136
|
-
/**
|
2137
|
-
* Convert a U128 to a Decimal
|
2138
|
-
*
|
2139
|
-
* On chain, u128s are used to store Decimal numbers. These values
|
2140
|
-
* are simply stored as u128 where the actual value is divided by
|
2141
|
-
* 1.0e+24. This gives 24 digits of percision on decimal numbers.
|
2142
|
-
*
|
2143
|
-
* Example: the number 1.5 is stored as a u128: 1.5 * 10^24
|
2144
|
-
*
|
2145
|
-
* @param value the value to be converted to Decimal
|
2146
|
-
* @returns the converted value as a decimal.js object
|
2147
|
-
*/
|
2148
|
-
function DecimalFromU128(value) {
|
2149
|
-
const adjustedValue = new Decimal__default["default"](value.toString());
|
2150
|
-
return adjustedValue.div(new Decimal__default["default"]('1e+24'));
|
2151
|
-
}
|
2152
|
-
|
2153
|
-
/**
|
2154
|
-
* A class that represents an on-chian vault.
|
2155
|
-
*/
|
2156
|
-
class VaultAccount {
|
2157
|
-
constructor(vault, publicKey) {
|
2158
|
-
this.publicKey = publicKey;
|
2159
|
-
this.vaultOwner = vault.vaultOwner;
|
2160
|
-
this.debt = vault.debt.toNumber();
|
2161
|
-
this.deposited = vault.deposited.toNumber();
|
2162
|
-
this.minCollateralRatio = DecimalFromU128(vault.minCollateralRatio);
|
2163
|
-
this.vaultStatus = Object.keys(vault.vaultStatus)[0];
|
2164
|
-
}
|
2165
|
-
/**
|
2166
|
-
* Check if some `PublicKey` is the owner
|
2167
|
-
*
|
2168
|
-
* @param publicKey the publicKey to check against the vault owner
|
2169
|
-
* @returns true if publicKey matches the owner publicKey
|
2170
|
-
*/
|
2171
|
-
isOwnedBy(publicKey) {
|
2172
|
-
return publicKey.toString() === this.vaultOwner.toString();
|
2173
|
-
}
|
2174
|
-
/**
|
2175
|
-
* Get the collateral value in SOL
|
2176
|
-
*
|
2177
|
-
* @returns collateral value in SOL
|
2178
|
-
*/
|
2179
|
-
inSol() {
|
2180
|
-
return this.deposited / web3_js.LAMPORTS_PER_SOL;
|
2181
|
-
}
|
2182
|
-
/**
|
2183
|
-
* Get the debt value in USDH
|
2184
|
-
*
|
2185
|
-
* @returns debt value in USDH
|
2186
|
-
*/
|
2187
|
-
inUsd() {
|
2188
|
-
return this.debt / web3_js.LAMPORTS_PER_SOL;
|
2189
|
-
}
|
2190
|
-
/**
|
2191
|
-
* Pretty print the vault publickey for easy display
|
2192
|
-
*
|
2193
|
-
* @returns example: `1b6ca...azy71s`
|
2194
|
-
*/
|
2195
|
-
toDisplayString() {
|
2196
|
-
return `${this.publicKey.toString().substring(0, 6)}...${this.publicKey.toString().substring(this.publicKey.toString().length - 6)}`;
|
2197
|
-
}
|
2198
|
-
}
|
2199
|
-
|
2200
|
-
class VaultHistoryEvent {
|
2201
|
-
constructor(account, publicKey) {
|
2202
|
-
this.account = account;
|
2203
|
-
this.publicKey = publicKey;
|
2204
|
-
this.actorAccount = account.actorAccount;
|
2205
|
-
this.usdSolPrice = DecimalFromU128(account.usdSolPrice.toString());
|
2206
|
-
this.usdhDebtBefore = account.usdhDebtBefore.toNumber();
|
2207
|
-
this.usdhDebtAfter = account.usdhDebtAfter.toNumber();
|
2208
|
-
this.solBalanceBefore = account.solBalanceBefore.toNumber();
|
2209
|
-
this.solBalanceAfter = account.solBalanceAfter.toNumber();
|
2210
|
-
this.minCollateralRatioBefore = DecimalFromU128(account.minCollateralRatioBefore);
|
2211
|
-
this.minCollateralRatioAfter = DecimalFromU128(account.minCollateralRatioAfter);
|
2212
|
-
this.vaultStateBefore = account.vaultStateBefore;
|
2213
|
-
this.vaultStateAfter = account.vaultStateAfter;
|
2214
|
-
this.timestamp = account.timestamp.toNumber();
|
2215
|
-
this.action = account.action;
|
2216
|
-
}
|
2217
|
-
}
|
2218
|
-
exports.VaultStatus = void 0;
|
2219
|
-
(function (VaultStatus) {
|
2220
|
-
VaultStatus[VaultStatus["Open"] = 0] = "Open";
|
2221
|
-
VaultStatus[VaultStatus["Closed"] = 1] = "Closed";
|
2222
|
-
VaultStatus[VaultStatus["Liquidated"] = 2] = "Liquidated";
|
2223
|
-
VaultStatus[VaultStatus["Distributed"] = 3] = "Distributed";
|
2224
|
-
VaultStatus[VaultStatus["Redeemed"] = 4] = "Redeemed";
|
2225
|
-
})(exports.VaultStatus || (exports.VaultStatus = {}));
|
2226
|
-
exports.VaultHistoryAction = void 0;
|
2227
|
-
(function (VaultHistoryAction) {
|
2228
|
-
VaultHistoryAction[VaultHistoryAction["Create"] = 0] = "Create";
|
2229
|
-
VaultHistoryAction[VaultHistoryAction["Close"] = 1] = "Close";
|
2230
|
-
VaultHistoryAction[VaultHistoryAction["Liquidate"] = 2] = "Liquidate";
|
2231
|
-
VaultHistoryAction[VaultHistoryAction["PartialLiquidate"] = 3] = "PartialLiquidate";
|
2232
|
-
VaultHistoryAction[VaultHistoryAction["Distributed"] = 4] = "Distributed";
|
2233
|
-
VaultHistoryAction[VaultHistoryAction["Redeem"] = 5] = "Redeem";
|
2234
|
-
VaultHistoryAction[VaultHistoryAction["TransferOwnership"] = 6] = "TransferOwnership";
|
2235
|
-
VaultHistoryAction[VaultHistoryAction["Deposit"] = 7] = "Deposit";
|
2236
|
-
VaultHistoryAction[VaultHistoryAction["Withdraw"] = 8] = "Withdraw";
|
2237
|
-
VaultHistoryAction[VaultHistoryAction["Loan"] = 9] = "Loan";
|
2238
|
-
VaultHistoryAction[VaultHistoryAction["RepayCredit"] = 10] = "RepayCredit";
|
2239
|
-
})(exports.VaultHistoryAction || (exports.VaultHistoryAction = {}));
|
2240
|
-
|
2241
|
-
class StakingPool {
|
2242
|
-
constructor(poolInfo, publicKey) {
|
2243
|
-
this.poolInfo = poolInfo;
|
2244
|
-
this.publicKey = publicKey;
|
2245
|
-
this.deposits = poolInfo.deposits.toNumber();
|
2246
|
-
// this.totalFeesNow = poolInfo.totalFeesNow.toNumber()
|
2247
|
-
// this.totalFeesPrevious = poolInfo.totalFeesPrevious.toNumber()
|
2248
|
-
this.lastTransactionTime = poolInfo.lastTransactionTime.toNumber();
|
2249
|
-
this.startTime = poolInfo.startTime.toNumber();
|
2250
|
-
this.halfLifeInDays = poolInfo.halfLifeInDays.toNumber();
|
2251
|
-
this.totalHedgeReward = poolInfo.totalHedgeReward.toNumber();
|
2252
|
-
this.hedgeRewardAccumulator = DecimalFromU128(poolInfo.hedgeRewardAccumulator);
|
2253
|
-
this.usdhFeeAccumulator = DecimalFromU128(poolInfo.usdhFeeAccumulator);
|
2254
|
-
this.solFeeAccumulator = DecimalFromU128(poolInfo.solFeeAccumulator);
|
2255
|
-
// this.currentRewardsPerDay = DecimalFromU128(poolInfo.currentRewardsPerDay)
|
2256
|
-
}
|
2257
|
-
}
|
2258
|
-
|
2259
|
-
class StakingPoolPosition {
|
2260
|
-
constructor(poolPositionInfo, key, stakingPool) {
|
2261
|
-
this.poolPositionInfo = poolPositionInfo;
|
2262
|
-
this.publicKey = key;
|
2263
|
-
this.pool = stakingPool;
|
2264
|
-
this.owner = poolPositionInfo.owner;
|
2265
|
-
this.deposited = poolPositionInfo.deposited.toNumber();
|
2266
|
-
this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
|
2267
|
-
this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
|
2268
|
-
this.closedRewardedTokens = poolPositionInfo.closedRewardedTokens.toNumber();
|
2269
|
-
this.startHedgeRewardAccumulator = DecimalFromU128(poolPositionInfo.startHedgeRewardAccumulator);
|
2270
|
-
this.startUsdhFeeAccumulator = DecimalFromU128(poolPositionInfo.startUsdhFeeAccumulator);
|
2271
|
-
this.startSolFeeAccumulator = DecimalFromU128(poolPositionInfo.startSolFeeAccumulator);
|
2272
|
-
this.open = poolPositionInfo.state.open !== undefined;
|
2273
|
-
}
|
2274
|
-
getCurrentUsdhFeeReward() {
|
2275
|
-
return this.pool.usdhFeeAccumulator.minus(this.startUsdhFeeAccumulator).times(new Decimal__default["default"](this.deposited));
|
2276
|
-
}
|
2277
|
-
}
|
2278
|
-
|
2279
|
-
/**
|
2280
|
-
* Represents an on-chian pool era. In the event an era is depleted of deposits, a new era is
|
2281
|
-
* created to maintain each users contribution to the pool.
|
2282
|
-
*/
|
2283
|
-
class LiquidationPoolEra {
|
2284
|
-
constructor(liquidyPoolEra) {
|
2285
|
-
this.liquidyPoolEra = liquidyPoolEra;
|
2286
|
-
this.totalDeposits = liquidyPoolEra.totalDeposits.toNumber();
|
2287
|
-
this.product = DecimalFromU128(liquidyPoolEra.productBytes);
|
2288
|
-
this.sum = liquidyPoolEra.sumBytes.map((sumBytes) => { return DecimalFromU128(sumBytes); });
|
2289
|
-
this.hedgeRewardsAccumulator = DecimalFromU128(liquidyPoolEra.hedgeRewardsAccumulatorBytes);
|
2290
|
-
this.hedgeRewardsTimestamp = liquidyPoolEra.hedgeRewardsTimestamp.toNumber();
|
2291
|
-
}
|
2292
|
-
}
|
2293
|
-
|
2294
|
-
class LiquidationPoolState {
|
2295
|
-
constructor(liquidationPoolState) {
|
2296
|
-
this.liquidationPoolState = liquidationPoolState;
|
2297
|
-
this.lifetimeDeposits = liquidationPoolState.lifetimeDeposits.toNumber();
|
2298
|
-
this.hedgeInitRewardsTimestamp = liquidationPoolState.hedgeInitRewardsTimestamp.toNumber();
|
2299
|
-
// TODO Add the rest that are missing. Do we need them?
|
2300
|
-
}
|
2301
|
-
}
|
2302
|
-
|
2303
|
-
class LiquidationPosition {
|
2304
|
-
constructor(poolPositionInfo, key) {
|
2305
|
-
this.publicKey = key;
|
2306
|
-
this.eraPublicKey = poolPositionInfo.era;
|
2307
|
-
this.ownerAccount = poolPositionInfo.ownerAccount;
|
2308
|
-
this.deposit = poolPositionInfo.deposit.toNumber();
|
2309
|
-
this.closedUsdh = poolPositionInfo.closedUsdh.toNumber();
|
2310
|
-
this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
|
2311
|
-
this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
|
2312
|
-
this.productSnapshotEntry = DecimalFromU128(poolPositionInfo.productSnapshotEntry);
|
2313
|
-
this.productSnapshotClosed = DecimalFromU128(poolPositionInfo.productSnapshotClosed);
|
2314
|
-
this.sumSnapshotsEntry = poolPositionInfo.sumSnapshotsEntry.map((sum) => { return DecimalFromU128(sum); });
|
2315
|
-
this.sumSnapshotsClosed = poolPositionInfo.sumSnapshotsClosed.map((sum) => { return DecimalFromU128(sum); });
|
2316
|
-
this.hedgeRewardsSnapshot = DecimalFromU128(poolPositionInfo.hedgeRewardsSnapshotAccum);
|
2317
|
-
this.open = poolPositionInfo.state.open !== undefined;
|
2318
|
-
}
|
2319
|
-
getUsdhAvailable(era) {
|
2320
|
-
return (era.product.div(this.productSnapshotEntry)).mul(new Decimal__default["default"](this.deposit));
|
2321
|
-
}
|
2322
|
-
getSolAvailable(era) {
|
2323
|
-
return era.sum[0].minus(this.sumSnapshotsEntry[0]).div(this.productSnapshotEntry).mul(new Decimal__default["default"](this.deposit)).floor();
|
2324
|
-
}
|
2325
|
-
}
|
2326
|
-
// function hedgeRewardsDecay (supply: number, birthTime: number, timeIn: number, timeOut: number, halfLifeInDays: number): number {
|
2327
|
-
// const timeInOffsetStart = timeIn - birthTime
|
2328
|
-
// const timeOutOffsetStart = timeOut - birthTime
|
2329
|
-
// const halfLife = -1 * Math.log(2) / (halfLifeInDays * 60 * 60 * 24)
|
2330
|
-
// const awardedTokens = supply * (Math.pow(Math.E, halfLife * timeInOffsetStart) - Math.pow(Math.E, halfLife * timeOutOffsetStart))
|
2331
|
-
// return awardedTokens
|
2332
|
-
// }
|
2333
|
-
|
2334
|
-
exports.CHAINLINK_SOL_USD_ID = CHAINLINK_SOL_USD_ID;
|
2335
|
-
exports.CHAINLINK_SOL_USD_PUBLICKEY = CHAINLINK_SOL_USD_PUBLICKEY;
|
2336
|
-
exports.DecimalFromU128 = DecimalFromU128;
|
2337
|
-
exports.HEDGE_PROGRAM_ID = HEDGE_PROGRAM_ID;
|
2338
|
-
exports.HEDGE_PROGRAM_PUBLICKEY = HEDGE_PROGRAM_PUBLICKEY;
|
2339
|
-
exports.LiquidationPoolEra = LiquidationPoolEra;
|
2340
|
-
exports.LiquidationPoolState = LiquidationPoolState;
|
2341
|
-
exports.LiquidationPosition = LiquidationPosition;
|
2342
|
-
exports.StakingPool = StakingPool;
|
2343
|
-
exports.StakingPoolPosition = StakingPoolPosition;
|
2344
|
-
exports.VaultAccount = VaultAccount;
|
2345
|
-
exports.VaultHistoryEvent = VaultHistoryEvent;
|
2346
|
-
exports.claimLiquidationPoolPosition = claimLiquidationPoolPosition;
|
2347
|
-
exports.claimLiquidationPoolPositionInstruction = claimLiquidationPoolPositionInstruction;
|
2348
|
-
exports.closeLiquidationPoolPosition = closeLiquidationPoolPosition;
|
2349
|
-
exports.closeLiquidationPoolPositionInstruction = closeLiquidationPoolPositionInstruction;
|
2350
|
-
exports.createStakingPool = createStakingPool;
|
2351
|
-
exports.createStakingPoolInstruction = createStakingPoolInstruction;
|
2352
|
-
exports.createVault = createVault;
|
2353
|
-
exports.createVaultInstruction = createVaultInstruction;
|
2354
|
-
exports.depositLiquidationPool = depositLiquidationPool;
|
2355
|
-
exports.depositLiquidationPoolInstruction = depositLiquidationPoolInstruction;
|
2356
|
-
exports.depositStakingPool = depositStakingPool;
|
2357
|
-
exports.depositStakingPoolInstruction = depositStakingPoolInstruction;
|
2358
|
-
exports.depositVault = depositVault;
|
2359
|
-
exports.depositVaultInstruction = depositVaultInstruction;
|
2360
|
-
exports.findAssociatedTokenAddress = findAssociatedTokenAddress;
|
2361
|
-
exports.findVaultAddress = findVaultAddress;
|
2362
|
-
exports.getCollateralStateAccountPublicKey = getCollateralStateAccountPublicKey;
|
2363
|
-
exports.getHedgeMintPublicKey = getHedgeMintPublicKey;
|
2364
|
-
exports.getLiquidationPoolStatePublicKey = getLiquidationPoolStatePublicKey;
|
2365
|
-
exports.getLiquidationPoolUsdhAccountPublicKey = getLiquidationPoolUsdhAccountPublicKey;
|
2366
|
-
exports.getPoolPublicKeyForMint = getPoolPublicKeyForMint;
|
2367
|
-
exports.getUsdhMintPublicKey = getUsdhMintPublicKey;
|
2368
|
-
exports.getVaultSystemStatePublicKey = getVaultSystemStatePublicKey;
|
2369
|
-
exports.liquidateVault = liquidateVault;
|
2370
|
-
exports.liquidateVaultInstruction = liquidateVaultInstruction;
|
2371
|
-
exports.loanVault = loanVault;
|
2372
|
-
exports.loanVaultInstruction = loanVaultInstruction;
|
2373
|
-
exports.redeemVault = redeemVault;
|
2374
|
-
exports.redeemVaultInstruction = redeemVaultInstruction;
|
2375
|
-
exports.refreshOraclePrice = refreshOraclePrice;
|
2376
|
-
exports.refreshOraclePriceInstruction = refreshOraclePriceInstruction;
|
2377
|
-
exports.repayVault = repayVault;
|
2378
|
-
exports.repayVaultInstruction = repayVaultInstruction;
|
2379
|
-
exports.withdrawStakingPool = withdrawStakingPool;
|
2380
|
-
exports.withdrawStakingPoolInstruction = withdrawStakingPoolInstruction;
|
2381
|
-
exports.withdrawVault = withdrawVault;
|
2382
|
-
exports.withdrawVaultInstruction = withdrawVaultInstruction;
|
2383
|
-
//# sourceMappingURL=index.js.map
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
13
|
+
__exportStar(require("./instructions/createStakingPool"), exports);
|
14
|
+
__exportStar(require("./instructions/depositStakingPool"), exports);
|
15
|
+
__exportStar(require("./instructions/withdrawStakingPool"), exports);
|
16
|
+
__exportStar(require("./instructions/depositLiquidationPool"), exports);
|
17
|
+
__exportStar(require("./instructions/closeLiquidationPoolPosition"), exports);
|
18
|
+
__exportStar(require("./instructions/claimLiquidationPoolPosition"), exports);
|
19
|
+
__exportStar(require("./instructions/createVault"), exports);
|
20
|
+
__exportStar(require("./instructions/depositVault"), exports);
|
21
|
+
__exportStar(require("./instructions/withdrawVault"), exports);
|
22
|
+
__exportStar(require("./instructions/loanVault"), exports);
|
23
|
+
__exportStar(require("./instructions/repayVault"), exports);
|
24
|
+
__exportStar(require("./instructions/redeemVault"), exports);
|
25
|
+
__exportStar(require("./instructions/liquidateVault"), exports);
|
26
|
+
__exportStar(require("./instructions/refreshOraclePrice"), exports);
|
27
|
+
__exportStar(require("./instructions/initHedgeFoundation"), exports);
|
28
|
+
__exportStar(require("./instructions/setHalted"), exports);
|
29
|
+
__exportStar(require("./HedgeDecimal"), exports);
|
30
|
+
__exportStar(require("./Constants"), exports);
|
31
|
+
__exportStar(require("./state/VaultAccount"), exports);
|
32
|
+
__exportStar(require("./state/VaultHistoryEvent"), exports);
|
33
|
+
__exportStar(require("./state/StakingPool"), exports);
|
34
|
+
__exportStar(require("./state/StakingPoolPosition"), exports);
|
35
|
+
__exportStar(require("./state/LiquidationPoolEra"), exports);
|
36
|
+
__exportStar(require("./state/LiquidationPoolState"), exports);
|
37
|
+
__exportStar(require("./state/LiquidationPosition"), exports);
|