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