hedge-web3 0.1.12 → 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.
Files changed (123) hide show
  1. package/{lib/types/src → declarations}/Constants.d.ts +7 -7
  2. package/{lib/types/src → declarations}/HedgeDecimal.d.ts +0 -1
  3. package/{lib/types/src → declarations}/StakingPools.d.ts +0 -1
  4. package/{lib/types/src → declarations}/Vaults.d.ts +0 -1
  5. package/{lib/types/src → declarations}/idl/idl.d.ts +0 -1
  6. package/declarations/idl/vault.d.ts +2283 -0
  7. package/{lib/types/src → declarations}/index.d.ts +5 -1
  8. package/declarations/instructions/claimLiquidationPoolPosition.d.ts +4 -0
  9. package/declarations/instructions/closeLiquidationPoolPosition.d.ts +4 -0
  10. package/{lib/types/src → declarations}/instructions/createStakingPool.d.ts +0 -1
  11. package/declarations/instructions/createVault.d.ts +4 -0
  12. package/declarations/instructions/depositLiquidationPool.d.ts +4 -0
  13. package/{lib/types/src → declarations}/instructions/depositStakingPool.d.ts +0 -1
  14. package/declarations/instructions/depositVault.d.ts +4 -0
  15. package/declarations/instructions/initHedgeFoundation.d.ts +4 -0
  16. package/declarations/instructions/liquidateVault.d.ts +4 -0
  17. package/{lib/types/src → declarations}/instructions/loanVault.d.ts +2 -3
  18. package/declarations/instructions/redeemVault.d.ts +4 -0
  19. package/{lib/types/src → declarations}/instructions/refreshOraclePrice.d.ts +2 -3
  20. package/{lib/types/src → declarations}/instructions/repayVault.d.ts +2 -3
  21. package/declarations/instructions/setHalted.d.ts +4 -0
  22. package/{lib/types/src → declarations}/instructions/withdrawStakingPool.d.ts +0 -1
  23. package/declarations/instructions/withdrawVault.d.ts +4 -0
  24. package/{lib/types/src → declarations}/state/LiquidationPoolEra.d.ts +1 -2
  25. package/{lib/types/src → declarations}/state/LiquidationPoolState.d.ts +0 -1
  26. package/{lib/types/src → declarations}/state/LiquidationPosition.d.ts +8 -10
  27. package/{lib/types/src → declarations}/state/StakingPool.d.ts +0 -1
  28. package/{lib/types/src → declarations}/state/StakingPoolPosition.d.ts +0 -1
  29. package/{lib/types/src → declarations}/state/VaultAccount.d.ts +0 -1
  30. package/{lib/types/src → declarations}/state/VaultHistoryEvent.d.ts +0 -1
  31. package/{lib/types/src → declarations}/utils/Errors.d.ts +0 -1
  32. package/lib/Constants.js +86 -0
  33. package/lib/HedgeDecimal.js +24 -0
  34. package/lib/StakingPools.js +15 -0
  35. package/lib/Vaults.js +20 -0
  36. package/lib/idl/idl.js +1475 -0
  37. package/lib/idl/vault.js +2285 -0
  38. package/lib/index.js +36 -2150
  39. package/lib/instructions/claimLiquidationPoolPosition.js +53 -0
  40. package/lib/instructions/closeLiquidationPoolPosition.js +60 -0
  41. package/lib/instructions/createStakingPool.js +52 -0
  42. package/lib/instructions/createVault.js +92 -0
  43. package/lib/instructions/depositLiquidationPool.js +55 -0
  44. package/lib/instructions/depositStakingPool.js +52 -0
  45. package/lib/instructions/depositVault.js +87 -0
  46. package/lib/instructions/initHedgeFoundation.js +55 -0
  47. package/lib/instructions/liquidateVault.js +80 -0
  48. package/lib/instructions/loanVault.js +61 -0
  49. package/lib/instructions/redeemVault.js +65 -0
  50. package/lib/instructions/refreshOraclePrice.js +65 -0
  51. package/lib/instructions/repayVault.js +62 -0
  52. package/lib/instructions/setHalted.js +37 -0
  53. package/lib/instructions/withdrawStakingPool.js +64 -0
  54. package/lib/instructions/withdrawVault.js +62 -0
  55. package/lib/state/LiquidationPoolEra.js +19 -0
  56. package/lib/state/LiquidationPoolState.js +12 -0
  57. package/lib/state/LiquidationPosition.js +39 -0
  58. package/lib/state/StakingPool.js +22 -0
  59. package/lib/state/StakingPoolPosition.js +28 -0
  60. package/lib/state/VaultAccount.js +52 -0
  61. package/lib/state/VaultHistoryEvent.js +45 -0
  62. package/lib/utils/Errors.js +14 -0
  63. package/package.json +13 -7
  64. package/src/Constants.ts +23 -18
  65. package/src/HedgeDecimal.ts +1 -1
  66. package/src/idl/idl.ts +13 -13
  67. package/src/idl/vault.ts +4565 -0
  68. package/src/index.ts +5 -0
  69. package/src/instructions/claimLiquidationPoolPosition.ts +76 -0
  70. package/src/instructions/closeLiquidationPoolPosition.ts +82 -0
  71. package/src/instructions/createStakingPool.ts +4 -4
  72. package/src/instructions/createVault.ts +101 -27
  73. package/src/instructions/depositLiquidationPool.ts +67 -0
  74. package/src/instructions/depositStakingPool.ts +5 -3
  75. package/src/instructions/depositVault.ts +97 -26
  76. package/src/instructions/initHedgeFoundation.ts +64 -0
  77. package/src/instructions/liquidateVault.ts +87 -35
  78. package/src/instructions/loanVault.ts +30 -20
  79. package/src/instructions/redeemVault.ts +37 -24
  80. package/src/instructions/refreshOraclePrice.ts +6 -3
  81. package/src/instructions/repayVault.ts +30 -17
  82. package/src/instructions/setHalted.ts +48 -0
  83. package/src/instructions/withdrawStakingPool.ts +6 -6
  84. package/src/instructions/withdrawVault.ts +50 -17
  85. package/src/state/LiquidationPoolEra.ts +2 -8
  86. package/src/state/LiquidationPosition.ts +38 -39
  87. package/tsconfig.json +3 -2
  88. package/.github/workflows/npm-publish.yml +0 -34
  89. package/README.md +0 -44
  90. package/jsconfig.json +0 -12
  91. package/lib/index.js.map +0 -1
  92. package/lib/types/src/Constants.d.ts.map +0 -1
  93. package/lib/types/src/HedgeDecimal.d.ts.map +0 -1
  94. package/lib/types/src/StakingPools.d.ts.map +0 -1
  95. package/lib/types/src/Vaults.d.ts.map +0 -1
  96. package/lib/types/src/idl/idl.d.ts.map +0 -1
  97. package/lib/types/src/index.d.ts.map +0 -1
  98. package/lib/types/src/instructions/createStakingPool.d.ts.map +0 -1
  99. package/lib/types/src/instructions/createVault.d.ts +0 -5
  100. package/lib/types/src/instructions/createVault.d.ts.map +0 -1
  101. package/lib/types/src/instructions/depositStakingPool.d.ts.map +0 -1
  102. package/lib/types/src/instructions/depositVault.d.ts +0 -5
  103. package/lib/types/src/instructions/depositVault.d.ts.map +0 -1
  104. package/lib/types/src/instructions/liquidateVault.d.ts +0 -5
  105. package/lib/types/src/instructions/liquidateVault.d.ts.map +0 -1
  106. package/lib/types/src/instructions/loanVault.d.ts.map +0 -1
  107. package/lib/types/src/instructions/redeemVault.d.ts +0 -5
  108. package/lib/types/src/instructions/redeemVault.d.ts.map +0 -1
  109. package/lib/types/src/instructions/refreshOraclePrice.d.ts.map +0 -1
  110. package/lib/types/src/instructions/repayVault.d.ts.map +0 -1
  111. package/lib/types/src/instructions/withdrawStakingPool.d.ts.map +0 -1
  112. package/lib/types/src/instructions/withdrawVault.d.ts +0 -5
  113. package/lib/types/src/instructions/withdrawVault.d.ts.map +0 -1
  114. package/lib/types/src/state/LiquidationPoolEra.d.ts.map +0 -1
  115. package/lib/types/src/state/LiquidationPoolState.d.ts.map +0 -1
  116. package/lib/types/src/state/LiquidationPosition.d.ts.map +0 -1
  117. package/lib/types/src/state/StakingPool.d.ts.map +0 -1
  118. package/lib/types/src/state/StakingPoolPosition.d.ts.map +0 -1
  119. package/lib/types/src/state/VaultAccount.d.ts.map +0 -1
  120. package/lib/types/src/state/VaultHistoryEvent.d.ts.map +0 -1
  121. package/lib/types/src/utils/Errors.d.ts.map +0 -1
  122. package/lib/types/tsconfig.base.tsbuildinfo +0 -1
  123. package/rollup.config.js +0 -40
package/lib/index.js CHANGED
@@ -1,2151 +1,37 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var anchor = require('@project-serum/anchor');
6
- var splToken = require('@solana/spl-token');
7
- var web3_js = require('@solana/web3.js');
8
- var Decimal = require('decimal.js');
9
-
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
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
- function parseAnchorErrors(error) {
1488
- const idlErrors = anchor.parseIdlErrors(vaultIdl);
1489
- const parsedError = anchor.ProgramError.parse(error, idlErrors);
1490
- if (parsedError !== null) {
1491
- throw parsedError;
1492
- }
1493
- throw error;
1494
- }
1495
-
1496
- const HEDGE_PROGRAM_ID = 'kkkBajjjT3rKjB3uGzSN83aLoQmaRwfXxbbBj8VLbtH';
1497
- const HEDGE_PROGRAM_PUBLICKEY = new web3_js.PublicKey(HEDGE_PROGRAM_ID);
1498
- const CHAINLINK_SOL_USD_ID = 'FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf';
1499
- const CHAINLINK_SOL_USD_PUBLICKEY = new web3_js.PublicKey(CHAINLINK_SOL_USD_ID);
1500
- const enc = new TextEncoder();
1501
- async function getLiquidationPoolStatePublicKey() {
1502
- const [poolPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolStateV1')], HEDGE_PROGRAM_PUBLICKEY);
1503
- return [poolPublicKey, bump];
1504
- }
1505
- async function getLiquidationPoolUsdhAccountPublicKey() {
1506
- const [poolPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('LiquidationPoolUSDHAccountV1')], HEDGE_PROGRAM_PUBLICKEY);
1507
- return [poolPublicKey, bump];
1508
- }
1509
- async function getUsdhMintPublicKey() {
1510
- const [findMintPublicKey, bump] = await web3_js.PublicKey.findProgramAddress([enc.encode('UsdhMintV1')], HEDGE_PROGRAM_PUBLICKEY);
1511
- return [findMintPublicKey, bump];
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 getSolCollateralPriceAccountPublicKey() {
1527
- const [collateralPriceAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode('SOL'), enc.encode('Price')], HEDGE_PROGRAM_PUBLICKEY);
1528
- return collateralPriceAccount;
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(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
- function createVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount, collateralRatio) {
1651
- const ix = program.instruction.createVault(new anchor.BN(depositAmount), new anchor.BN(collateralRatio), {
1652
- accounts: {
1653
- vaultSystemState: vaultSystemStatePublicKey,
1654
- vault: vaultPublicKey,
1655
- history: historyPublicKey,
1656
- payer: payerPublicKey,
1657
- systemProgram: web3_js.SystemProgram.programId
1658
- },
1659
- signers: []
1660
- });
1661
- return ix;
1662
- }
1663
-
1664
- async function depositVault(program, provider, payer, vaultPublicKey, depositAmount) {
1665
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1666
- const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1667
- // Prep the user to get USDH back out at some point
1668
- await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1669
- const history = web3_js.Keypair.generate();
1670
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1671
- const transaction = new web3_js.Transaction().add(depositVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, depositAmount));
1672
- await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1673
- return vaultPublicKey;
1674
- }
1675
- function depositVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublicKey, historyPublicKey, depositAmount) {
1676
- return program.instruction.depositVault(new anchor.BN(depositAmount), {
1677
- accounts: {
1678
- vaultSystemState: vaultSystemStatePublicKey,
1679
- vaultAccount: vaultPublicKey,
1680
- history: historyPublicKey,
1681
- vaultOwner: payerPublicKey,
1682
- systemProgram: web3_js.SystemProgram.programId
1683
- },
1684
- signers: []
1685
- });
1686
- }
1687
-
1688
- async function withdrawVault(program, provider, payer, vaultPublicKey, withdrawAmount) {
1689
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1690
- const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1691
- // Prep the user to get USDH back out at some point
1692
- await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1693
- const history = web3_js.Keypair.generate();
1694
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1695
- const transaction = new web3_js.Transaction().add(await withdrawVaultInstruction(program, vaultSystemStatePublicKey, payer.publicKey, vaultPublicKey, history.publicKey, withdrawAmount));
1696
- await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1697
- return vaultPublicKey;
1698
- }
1699
- async function withdrawVaultInstruction(program, vaultSystemStatePublicKey, payerPublicKey, vaultPublickey, historyPublicKey, withdrawAmount) {
1700
- const solPriceAccount = await getSolCollateralPriceAccountPublicKey();
1701
- return program.instruction.withdrawVault(new anchor.BN(withdrawAmount), {
1702
- accounts: {
1703
- vaultSystemState: vaultSystemStatePublicKey,
1704
- vaultAccount: vaultPublickey,
1705
- history: historyPublicKey,
1706
- vaultOwner: payerPublicKey,
1707
- priceForCollateral: solPriceAccount,
1708
- systemProgram: web3_js.SystemProgram.programId
1709
- },
1710
- signers: []
1711
- });
1712
- }
1713
-
1714
- async function loanVault(program, provider, payer, vaultPublicKey, loanAmount) {
1715
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1716
- const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1717
- // Prep the user to get USDH back out at some point
1718
- const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1719
- const history = web3_js.Keypair.generate();
1720
- const transaction = new web3_js.Transaction().add(await loanVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, loanAmount));
1721
- await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1722
- return vaultPublicKey;
1723
- }
1724
- async function loanVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, loanAmount) {
1725
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1726
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1727
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1728
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
1729
- const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
1730
- const solPriceAccount = await getSolCollateralPriceAccountPublicKey();
1731
- return program.instruction.loanVault(new anchor.BN(loanAmount), {
1732
- accounts: {
1733
- vaultSystemState: vaultSystemStatePublicKey,
1734
- vaultAccount: vaultPublickey,
1735
- history: historyPublicKey,
1736
- feePool: hedgeStakingPoolPublicKey,
1737
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
1738
- usdhMint: usdhMintPublickey,
1739
- vaultOwner: payerPublicKey,
1740
- ownerUsdhAccount: ownerUsdhAccount,
1741
- priceForCollateral: solPriceAccount,
1742
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1743
- systemProgram: web3_js.SystemProgram.programId
1744
- },
1745
- signers: []
1746
- });
1747
- }
1748
-
1749
- async function repayVault(program, provider, payer, vaultPublicKey, repayAmount) {
1750
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1751
- const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1752
- // Prep the user to get USDH back out at some point
1753
- const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1754
- const history = web3_js.Keypair.generate();
1755
- const transaction = new web3_js.Transaction().add(await repayVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount));
1756
- await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1757
- return vaultPublicKey;
1758
- }
1759
- async function repayVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount) {
1760
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1761
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1762
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1763
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
1764
- const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
1765
- return program.instruction.repayVault(new anchor.BN(repayAmount), {
1766
- accounts: {
1767
- vaultSystemState: vaultSystemStatePublicKey,
1768
- vaultAccount: vaultPublickey,
1769
- history: historyPublicKey,
1770
- feePool: hedgeStakingPoolPublicKey,
1771
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
1772
- usdhMint: usdhMintPublickey,
1773
- vaultOwner: payerPublicKey,
1774
- ownerUsdhAccount: ownerUsdhAccount,
1775
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1776
- systemProgram: web3_js.SystemProgram.programId
1777
- },
1778
- signers: []
1779
- });
1780
- }
1781
-
1782
- async function redeemVault(program, provider, payer, vaultPublicKey, repayAmount, transactionOverrideTime) {
1783
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1784
- const USDH = new splToken.Token(provider.connection, usdhMintPublickey, splToken.TOKEN_PROGRAM_ID, payer);
1785
- // Prep the user to get USDH back out at some point
1786
- const payerUsdhAccount = await USDH.getOrCreateAssociatedAccountInfo(payer.publicKey);
1787
- const history = web3_js.Keypair.generate();
1788
- const transaction = new web3_js.Transaction().add(await redeemVaultInstruction(program, payer.publicKey, payerUsdhAccount.address, vaultPublicKey, history.publicKey, repayAmount, transactionOverrideTime));
1789
- await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history], provider.opts);
1790
- return vaultPublicKey;
1791
- }
1792
- async function redeemVaultInstruction(program, payerPublicKey, ownerUsdhAccount, vaultPublickey, historyPublicKey, repayAmount, transactionOverrideTime) {
1793
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1794
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1795
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1796
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
1797
- const hedgeStakingPoolAssociatedUsdhTokenAccount = await findAssociatedTokenAddress(hedgeStakingPoolPublicKey, usdhMintPublickey);
1798
- const solPriceAccount = await getSolCollateralPriceAccountPublicKey();
1799
- return program.instruction.redeemVault(new anchor.BN(repayAmount), new anchor.BN(transactionOverrideTime !== null && transactionOverrideTime !== void 0 ? transactionOverrideTime : (Date.now() / 1000)), // override start time
1800
- {
1801
- accounts: {
1802
- vaultSystemState: vaultSystemStatePublicKey,
1803
- vaultAccount: vaultPublickey,
1804
- history: historyPublicKey,
1805
- feePool: hedgeStakingPoolPublicKey,
1806
- feePoolAssociatedUsdhTokenAccount: hedgeStakingPoolAssociatedUsdhTokenAccount,
1807
- usdhMint: usdhMintPublickey,
1808
- payer: payerPublicKey,
1809
- payerUsdhAccount: ownerUsdhAccount,
1810
- priceForCollateral: solPriceAccount,
1811
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1812
- systemProgram: web3_js.SystemProgram.programId
1813
- },
1814
- signers: []
1815
- });
1816
- }
1817
-
1818
- async function liquidateVault(program, provider, payer, vaultPublicKey) {
1819
- const history = web3_js.Keypair.generate();
1820
- const newEra = web3_js.Keypair.generate();
1821
- const transaction = new web3_js.Transaction().add(await liquidateVaultInstruction(program, payer.publicKey, vaultPublicKey, history.publicKey, newEra.publicKey));
1822
- await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer, history, newEra], provider.opts);
1823
- return vaultPublicKey;
1824
- }
1825
- async function liquidateVaultInstruction(program, payerPublicKey, vaultPublickey, historyPublicKey, newEraPublicKey) {
1826
- const [vaultSystemStatePublicKey] = await getVaultSystemStatePublicKey();
1827
- const [usdhMintPublickey] = await getUsdhMintPublicKey();
1828
- const [hedgeMintPublickey] = await getHedgeMintPublicKey();
1829
- const [hedgeStakingPoolPublicKey] = await getPoolPublicKeyForMint(hedgeMintPublickey);
1830
- const [liquidationPoolStatePublicKey] = await getLiquidationPoolStatePublicKey();
1831
- const [liquidationPoolUsdhAccountPublickey] = await getLiquidationPoolUsdhAccountPublicKey();
1832
- const solPriceAccount = await getSolCollateralPriceAccountPublicKey();
1833
- const poolStateInfo = await program.account.liquidationPoolState.fetch(liquidationPoolStatePublicKey);
1834
- return program.instruction.liquidateVault({
1835
- accounts: {
1836
- vaultSystemState: vaultSystemStatePublicKey,
1837
- poolEra: poolStateInfo.currentEra,
1838
- vaultAccount: vaultPublickey,
1839
- poolState: liquidationPoolStatePublicKey,
1840
- usdhMint: usdhMintPublickey,
1841
- priceForCollateral: solPriceAccount,
1842
- history: historyPublicKey,
1843
- payer: payerPublicKey,
1844
- splTokenProgramInfo: splToken.TOKEN_PROGRAM_ID,
1845
- systemProgram: web3_js.SystemProgram.programId,
1846
- feePool: hedgeStakingPoolPublicKey,
1847
- liquidationPoolUsdhAccount: liquidationPoolUsdhAccountPublickey,
1848
- newEra: newEraPublicKey
1849
- },
1850
- signers: []
1851
- });
1852
- }
1853
-
1854
- async function refreshOraclePrice(program, provider, payer, network, overridePrice, overrideTime) {
1855
- const transaction = new web3_js.Transaction().add(await refreshOraclePriceInstruction(program, network, overridePrice, overrideTime));
1856
- return await web3_js.sendAndConfirmTransaction(provider.connection, transaction, [payer], provider.opts);
1857
- }
1858
- async function refreshOraclePriceInstruction(program, network, overridePrice, overrideTime) {
1859
- const enc = new TextEncoder();
1860
- const [oracleInfoAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode('SOL'), enc.encode('Oracle')], HEDGE_PROGRAM_PUBLICKEY);
1861
- const [collateralPriceAccount] = await web3_js.PublicKey.findProgramAddress([enc.encode('SOL'), enc.encode('Price')], HEDGE_PROGRAM_PUBLICKEY);
1862
- return program.instruction.refreshOraclePrice(new anchor.BN(overridePrice !== null && overridePrice !== void 0 ? overridePrice : web3_js.LAMPORTS_PER_SOL * 150), // override usd/sol price
1863
- new anchor.BN(overrideTime !== null && overrideTime !== void 0 ? overrideTime : Math.floor(Date.now() / 1000)), // override override time
1864
- {
1865
- accounts: {
1866
- oracleInfoAccount: oracleInfoAccount,
1867
- collateralPriceAccount: collateralPriceAccount,
1868
- oracleChainlink: chainlinkAccunts[network],
1869
- oraclePyth: pythAccounts[network],
1870
- oracleSwitchboard: switchboardAccounts[network],
1871
- systemProgram: web3_js.SystemProgram.programId
1872
- },
1873
- signers: []
1874
- });
1875
- }
1876
- var Cluster;
1877
- (function (Cluster) {
1878
- Cluster["Testing"] = "Testing";
1879
- Cluster["Devnet"] = "Devnet";
1880
- Cluster["MainnetBeta"] = "MainnetBeta";
1881
- })(Cluster || (Cluster = {}));
1882
- const pythAccounts = {
1883
- Testing: web3_js.SystemProgram.programId,
1884
- Devnet: new web3_js.PublicKey('J83w4HKfqxwcq3BEMMkPFSppX3gqekLyLJBexebFVkix'),
1885
- MainnetBeta: new web3_js.PublicKey('H6ARHf6YXhGYeQfUzQNGk6rDNnLBQKrenN712K4AQJEG')
1886
- };
1887
- const chainlinkAccunts = {
1888
- Testing: web3_js.SystemProgram.programId,
1889
- Devnet: new web3_js.PublicKey('FmAmfoyPXiA8Vhhe6MZTr3U6rZfEZ1ctEHay1ysqCqcf'),
1890
- MainnetBeta: web3_js.SystemProgram.programId // CHAINLINK NOT ON MAINNET YET
1891
- };
1892
- const switchboardAccounts = {
1893
- Testing: web3_js.SystemProgram.programId,
1894
- // Devnet: new PublicKey('GvDMxPzN1sCj7L26YDK2HnMRXEQmQ2aemov8YBtPS7vR'),
1895
- Devnet: new web3_js.PublicKey('DpoK8Zz69APV9ntjuY9C4LZCxANYMV56M2cbXEdkjxME'),
1896
- MainnetBeta: web3_js.SystemProgram.programId // Switchboard V2 NOT ON MAINNET YET
1897
- };
1898
-
1899
- /**
1900
- * Convert a U128 to a Decimal
1901
- *
1902
- * On chain, u128s are used to store Decimal numbers. These values
1903
- * are simply stored as u128 where the actual value is divided by
1904
- * 1.0e+24. This gives 24 digits of percision on decimal numbers.
1905
- *
1906
- * Example: the number 1.5 is stored as a u128: 1.5 * 10^24
1907
- *
1908
- * @param value the value to be converted to Decimal
1909
- * @returns the converted value as a decimal.js object
1910
- */
1911
- function DecimalFromU128(value) {
1912
- const adjustedValue = new Decimal__default["default"](value.toString());
1913
- return adjustedValue.div(new Decimal__default["default"]('1e+24'));
1914
- }
1915
-
1916
- /**
1917
- * A class that represents an on-chian vault.
1918
- */
1919
- class VaultAccount {
1920
- constructor(vault, publicKey) {
1921
- this.publicKey = publicKey;
1922
- this.vaultOwner = vault.vaultOwner;
1923
- this.debt = vault.debt.toNumber();
1924
- this.deposited = vault.deposited.toNumber();
1925
- this.minCollateralRatio = DecimalFromU128(vault.minCollateralRatio);
1926
- this.vaultStatus = Object.keys(vault.vaultStatus)[0];
1927
- }
1928
- /**
1929
- * Check if some `PublicKey` is the owner
1930
- *
1931
- * @param publicKey the publicKey to check against the vault owner
1932
- * @returns true if publicKey matches the owner publicKey
1933
- */
1934
- isOwnedBy(publicKey) {
1935
- return publicKey.toString() === this.vaultOwner.toString();
1936
- }
1937
- /**
1938
- * Get the collateral value in SOL
1939
- *
1940
- * @returns collateral value in SOL
1941
- */
1942
- inSol() {
1943
- return this.deposited / web3_js.LAMPORTS_PER_SOL;
1944
- }
1945
- /**
1946
- * Get the debt value in USDH
1947
- *
1948
- * @returns debt value in USDH
1949
- */
1950
- inUsd() {
1951
- return this.debt / web3_js.LAMPORTS_PER_SOL;
1952
- }
1953
- /**
1954
- * Pretty print the vault publickey for easy display
1955
- *
1956
- * @returns example: `1b6ca...azy71s`
1957
- */
1958
- toDisplayString() {
1959
- return `${this.publicKey.toString().substring(0, 6)}...${this.publicKey.toString().substring(this.publicKey.toString().length - 6)}`;
1960
- }
1961
- }
1962
-
1963
- class VaultHistoryEvent {
1964
- constructor(account, publicKey) {
1965
- this.account = account;
1966
- this.publicKey = publicKey;
1967
- this.actorAccount = account.actorAccount;
1968
- this.usdSolPrice = DecimalFromU128(account.usdSolPrice.toString());
1969
- this.usdhDebtBefore = account.usdhDebtBefore.toNumber();
1970
- this.usdhDebtAfter = account.usdhDebtAfter.toNumber();
1971
- this.solBalanceBefore = account.solBalanceBefore.toNumber();
1972
- this.solBalanceAfter = account.solBalanceAfter.toNumber();
1973
- this.minCollateralRatioBefore = DecimalFromU128(account.minCollateralRatioBefore);
1974
- this.minCollateralRatioAfter = DecimalFromU128(account.minCollateralRatioAfter);
1975
- this.vaultStateBefore = account.vaultStateBefore;
1976
- this.vaultStateAfter = account.vaultStateAfter;
1977
- this.timestamp = account.timestamp.toNumber();
1978
- this.action = account.action;
1979
- }
1980
- }
1981
- exports.VaultStatus = void 0;
1982
- (function (VaultStatus) {
1983
- VaultStatus[VaultStatus["Open"] = 0] = "Open";
1984
- VaultStatus[VaultStatus["Closed"] = 1] = "Closed";
1985
- VaultStatus[VaultStatus["Liquidated"] = 2] = "Liquidated";
1986
- VaultStatus[VaultStatus["Distributed"] = 3] = "Distributed";
1987
- VaultStatus[VaultStatus["Redeemed"] = 4] = "Redeemed";
1988
- })(exports.VaultStatus || (exports.VaultStatus = {}));
1989
- exports.VaultHistoryAction = void 0;
1990
- (function (VaultHistoryAction) {
1991
- VaultHistoryAction[VaultHistoryAction["Create"] = 0] = "Create";
1992
- VaultHistoryAction[VaultHistoryAction["Close"] = 1] = "Close";
1993
- VaultHistoryAction[VaultHistoryAction["Liquidate"] = 2] = "Liquidate";
1994
- VaultHistoryAction[VaultHistoryAction["PartialLiquidate"] = 3] = "PartialLiquidate";
1995
- VaultHistoryAction[VaultHistoryAction["Distributed"] = 4] = "Distributed";
1996
- VaultHistoryAction[VaultHistoryAction["Redeem"] = 5] = "Redeem";
1997
- VaultHistoryAction[VaultHistoryAction["TransferOwnership"] = 6] = "TransferOwnership";
1998
- VaultHistoryAction[VaultHistoryAction["Deposit"] = 7] = "Deposit";
1999
- VaultHistoryAction[VaultHistoryAction["Withdraw"] = 8] = "Withdraw";
2000
- VaultHistoryAction[VaultHistoryAction["Loan"] = 9] = "Loan";
2001
- VaultHistoryAction[VaultHistoryAction["RepayCredit"] = 10] = "RepayCredit";
2002
- })(exports.VaultHistoryAction || (exports.VaultHistoryAction = {}));
2003
-
2004
- class StakingPool {
2005
- constructor(poolInfo, publicKey) {
2006
- this.poolInfo = poolInfo;
2007
- this.publicKey = publicKey;
2008
- this.deposits = poolInfo.deposits.toNumber();
2009
- // this.totalFeesNow = poolInfo.totalFeesNow.toNumber()
2010
- // this.totalFeesPrevious = poolInfo.totalFeesPrevious.toNumber()
2011
- this.lastTransactionTime = poolInfo.lastTransactionTime.toNumber();
2012
- this.startTime = poolInfo.startTime.toNumber();
2013
- this.halfLifeInDays = poolInfo.halfLifeInDays.toNumber();
2014
- this.totalHedgeReward = poolInfo.totalHedgeReward.toNumber();
2015
- this.hedgeRewardAccumulator = DecimalFromU128(poolInfo.hedgeRewardAccumulator);
2016
- this.usdhFeeAccumulator = DecimalFromU128(poolInfo.usdhFeeAccumulator);
2017
- this.solFeeAccumulator = DecimalFromU128(poolInfo.solFeeAccumulator);
2018
- // this.currentRewardsPerDay = DecimalFromU128(poolInfo.currentRewardsPerDay)
2019
- }
2020
- }
2021
-
2022
- class StakingPoolPosition {
2023
- constructor(poolPositionInfo, key, stakingPool) {
2024
- this.poolPositionInfo = poolPositionInfo;
2025
- this.publicKey = key;
2026
- this.pool = stakingPool;
2027
- this.owner = poolPositionInfo.owner;
2028
- this.deposited = poolPositionInfo.deposited.toNumber();
2029
- this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
2030
- this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
2031
- this.closedRewardedTokens = poolPositionInfo.closedRewardedTokens.toNumber();
2032
- this.startHedgeRewardAccumulator = DecimalFromU128(poolPositionInfo.startHedgeRewardAccumulator);
2033
- this.startUsdhFeeAccumulator = DecimalFromU128(poolPositionInfo.startUsdhFeeAccumulator);
2034
- this.startSolFeeAccumulator = DecimalFromU128(poolPositionInfo.startSolFeeAccumulator);
2035
- this.open = poolPositionInfo.state.open !== undefined;
2036
- }
2037
- getCurrentUsdhFeeReward() {
2038
- return this.pool.usdhFeeAccumulator.minus(this.startUsdhFeeAccumulator).times(new Decimal__default["default"](this.deposited));
2039
- }
2040
- }
2041
-
2042
- /**
2043
- * Represents an on-chian pool era. In the event an era is depleted of deposits, a new era is
2044
- * created to maintain each users contribution to the pool.
2045
- */
2046
- class LiquidationPoolEra {
2047
- constructor(liquidyPoolEra) {
2048
- this.liquidyPoolEra = liquidyPoolEra;
2049
- this.totalDeposits = liquidyPoolEra.totalDeposits.toNumber();
2050
- this.product = DecimalFromU128(liquidyPoolEra.productBytes);
2051
- this.sum = DecimalFromU128(liquidyPoolEra.sumBytes);
2052
- this.hedgeRewardsAccumulator = DecimalFromU128(liquidyPoolEra.hedgeRewardsAccumulatorBytes);
2053
- this.hedgeRewardsTimestamp = liquidyPoolEra.hedgeRewardsTimestamp.toNumber();
2054
- }
2055
- }
2056
-
2057
- class LiquidationPoolState {
2058
- constructor(liquidationPoolState) {
2059
- this.liquidationPoolState = liquidationPoolState;
2060
- this.lifetimeDeposits = liquidationPoolState.lifetimeDeposits.toNumber();
2061
- this.hedgeInitRewardsTimestamp = liquidationPoolState.hedgeInitRewardsTimestamp.toNumber();
2062
- // TODO Add the rest that are missing. Do we need them?
2063
- }
2064
- }
2065
-
2066
- class LiquidationPosition {
2067
- constructor(poolPositionInfo, key, era, liquidationPoolState) {
2068
- this.publicKey = key;
2069
- this.eraPublicKey = poolPositionInfo.era;
2070
- this.era = era;
2071
- this.liquidationPoolState = liquidationPoolState;
2072
- this.ownerAccount = poolPositionInfo.ownerAccount;
2073
- this.deposit = poolPositionInfo.deposit.toNumber();
2074
- this.closedUsdh = poolPositionInfo.closedUsdh.toNumber();
2075
- this.closedSol = poolPositionInfo.closedSol.toNumber();
2076
- this.timestampOpened = poolPositionInfo.timestampOpened.toNumber();
2077
- this.timestampClosed = poolPositionInfo.timestampClosed.toNumber();
2078
- this.productSnapshot = DecimalFromU128(poolPositionInfo.productSnapshotBytes);
2079
- this.sumSnapshot = DecimalFromU128(poolPositionInfo.sumSnapshotBytes);
2080
- this.hedgeRewardsSnapshot = DecimalFromU128(poolPositionInfo.hedgeRewardsSnapshotAccum);
2081
- this.open = poolPositionInfo.state.open !== undefined;
2082
- }
2083
- getUsdhAvailable() {
2084
- return (this.era.product.div(this.productSnapshot)).mul(new Decimal__default["default"](this.deposit));
2085
- }
2086
- getSolAvailable() {
2087
- return this.era.sum.minus(this.sumSnapshot).div(this.productSnapshot).mul(new Decimal__default["default"](this.deposit)).floor();
2088
- }
2089
- getHedgeAvailable() {
2090
- const LiquidationPoolTotalSupply = 2000000.0 * web3_js.LAMPORTS_PER_SOL;
2091
- const hedgeRewardsSinceLastUpdate = hedgeRewardsDecay(LiquidationPoolTotalSupply, this.liquidationPoolState.hedgeInitRewardsTimestamp * 1000, this.era.hedgeRewardsTimestamp * 1000, Date.now(), 365 * 1000);
2092
- if (this.era.totalDeposits === 0) {
2093
- return new Decimal__default["default"](0);
2094
- }
2095
- const rewardsPerToken = this.era.product.mul(new Decimal__default["default"](hedgeRewardsSinceLastUpdate / this.era.totalDeposits));
2096
- const newAccumulator = rewardsPerToken.add(new Decimal__default["default"](this.era.hedgeRewardsAccumulator));
2097
- const hedgeAvailable = (newAccumulator.minus(this.hedgeRewardsSnapshot)).mul(new Decimal__default["default"](this.deposit)).div(new Decimal__default["default"](this.productSnapshot));
2098
- return hedgeAvailable;
2099
- }
2100
- }
2101
- function hedgeRewardsDecay(supply, birthTime, timeIn, timeOut, halfLifeInDays) {
2102
- const timeInOffsetStart = timeIn - birthTime;
2103
- const timeOutOffsetStart = timeOut - birthTime;
2104
- const halfLife = -1 * Math.log(2) / (halfLifeInDays * 60 * 60 * 24);
2105
- const awardedTokens = supply * (Math.pow(Math.E, halfLife * timeInOffsetStart) - Math.pow(Math.E, halfLife * timeOutOffsetStart));
2106
- return awardedTokens;
2107
- }
2108
-
2109
- exports.CHAINLINK_SOL_USD_ID = CHAINLINK_SOL_USD_ID;
2110
- exports.CHAINLINK_SOL_USD_PUBLICKEY = CHAINLINK_SOL_USD_PUBLICKEY;
2111
- exports.DecimalFromU128 = DecimalFromU128;
2112
- exports.HEDGE_PROGRAM_ID = HEDGE_PROGRAM_ID;
2113
- exports.HEDGE_PROGRAM_PUBLICKEY = HEDGE_PROGRAM_PUBLICKEY;
2114
- exports.LiquidationPoolEra = LiquidationPoolEra;
2115
- exports.LiquidationPoolState = LiquidationPoolState;
2116
- exports.LiquidationPosition = LiquidationPosition;
2117
- exports.StakingPool = StakingPool;
2118
- exports.StakingPoolPosition = StakingPoolPosition;
2119
- exports.VaultAccount = VaultAccount;
2120
- exports.VaultHistoryEvent = VaultHistoryEvent;
2121
- exports.createStakingPool = createStakingPool;
2122
- exports.createStakingPoolInstruction = createStakingPoolInstruction;
2123
- exports.createVault = createVault;
2124
- exports.createVaultInstruction = createVaultInstruction;
2125
- exports.depositStakingPool = depositStakingPool;
2126
- exports.depositStakingPoolInstruction = depositStakingPoolInstruction;
2127
- exports.depositVault = depositVault;
2128
- exports.depositVaultInstruction = depositVaultInstruction;
2129
- exports.findAssociatedTokenAddress = findAssociatedTokenAddress;
2130
- exports.getHedgeMintPublicKey = getHedgeMintPublicKey;
2131
- exports.getLiquidationPoolStatePublicKey = getLiquidationPoolStatePublicKey;
2132
- exports.getLiquidationPoolUsdhAccountPublicKey = getLiquidationPoolUsdhAccountPublicKey;
2133
- exports.getPoolPublicKeyForMint = getPoolPublicKeyForMint;
2134
- exports.getSolCollateralPriceAccountPublicKey = getSolCollateralPriceAccountPublicKey;
2135
- exports.getUsdhMintPublicKey = getUsdhMintPublicKey;
2136
- exports.getVaultSystemStatePublicKey = getVaultSystemStatePublicKey;
2137
- exports.liquidateVault = liquidateVault;
2138
- exports.liquidateVaultInstruction = liquidateVaultInstruction;
2139
- exports.loanVault = loanVault;
2140
- exports.loanVaultInstruction = loanVaultInstruction;
2141
- exports.redeemVault = redeemVault;
2142
- exports.redeemVaultInstruction = redeemVaultInstruction;
2143
- exports.refreshOraclePrice = refreshOraclePrice;
2144
- exports.refreshOraclePriceInstruction = refreshOraclePriceInstruction;
2145
- exports.repayVault = repayVault;
2146
- exports.repayVaultInstruction = repayVaultInstruction;
2147
- exports.withdrawStakingPool = withdrawStakingPool;
2148
- exports.withdrawStakingPoolInstruction = withdrawStakingPoolInstruction;
2149
- exports.withdrawVault = withdrawVault;
2150
- exports.withdrawVaultInstruction = withdrawVaultInstruction;
2151
- //# 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);