@jup-ag/lend 0.2.0-beta.1 → 0.2.0-beta.3

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.
@@ -1,2176 +1,11 @@
1
- import { PublicKey, SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram } from '@solana/web3.js';
2
- import { getAssociatedTokenAddress, getAccount, createAssociatedTokenAccountInstruction, ASSOCIATED_TOKEN_PROGRAM_ID, getAssociatedTokenAddressSync } from '@solana/spl-token';
3
- import { Program } from '@coral-xyz/anchor';
4
- import BN$1, { BN } from 'bn.js';
1
+ import { SYSVAR_INSTRUCTIONS_PUBKEY, SystemProgram, PublicKey } from '@solana/web3.js';
2
+ import { getAssociatedTokenAddressSync } from '@solana/spl-token';
3
+ import { g as getAccountOwner, a as getLiquidityProgramId, b as getLendingProgram, c as getOrCreateATAInstruction } from '../shared/lend.B80NmXTG.mjs';
4
+ export { M as MAX_DEPOSIT, d as MAX_WITHDRAW, U as U64_MAX } from '../shared/lend.B80NmXTG.mjs';
5
5
  import { g as getLendingToken, a as getLending, b as getLendingRewardsRateModel, c as getClaimAccount, d as getLendingAdmin } from '../shared/lend.BQkL9C4i.mjs';
6
6
  import { a as getLiquidity, d as getRateModel, b as getUserBorrowPosition, c as getUserSupplyPosition, f as getTokenReserveFromAsset, e as getReserve } from '../shared/lend.C3XdrR6R.mjs';
7
-
8
- const address = "jup3YeL8QhtSx1e253b2FDvsMNC87fDrgQZivbrndc9";
9
- const metadata = {
10
- name: "lending",
11
- version: "0.1.0",
12
- spec: "0.1.0",
13
- description: "Created with Anchor"
14
- };
15
- const instructions = [
16
- {
17
- name: "deposit",
18
- discriminator: [
19
- 242,
20
- 35,
21
- 198,
22
- 137,
23
- 82,
24
- 225,
25
- 242,
26
- 182
27
- ],
28
- accounts: [
29
- {
30
- name: "signer",
31
- writable: true,
32
- signer: true
33
- },
34
- {
35
- name: "depositor_token_account",
36
- writable: true
37
- },
38
- {
39
- name: "recipient_token_account",
40
- writable: true
41
- },
42
- {
43
- name: "mint",
44
- relations: [
45
- "lending",
46
- "rewards_rate_model"
47
- ]
48
- },
49
- {
50
- name: "lending_admin"
51
- },
52
- {
53
- name: "lending",
54
- writable: true
55
- },
56
- {
57
- name: "f_token_mint",
58
- writable: true,
59
- relations: [
60
- "lending"
61
- ]
62
- },
63
- {
64
- name: "supply_token_reserves_liquidity",
65
- writable: true
66
- },
67
- {
68
- name: "lending_supply_position_on_liquidity",
69
- writable: true
70
- },
71
- {
72
- name: "rate_model"
73
- },
74
- {
75
- name: "vault",
76
- writable: true
77
- },
78
- {
79
- name: "liquidity",
80
- writable: true
81
- },
82
- {
83
- name: "liquidity_program",
84
- writable: true,
85
- relations: [
86
- "lending_admin"
87
- ]
88
- },
89
- {
90
- name: "rewards_rate_model"
91
- },
92
- {
93
- name: "token_program"
94
- },
95
- {
96
- name: "associated_token_program",
97
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
98
- },
99
- {
100
- name: "system_program",
101
- address: "11111111111111111111111111111111"
102
- }
103
- ],
104
- args: [
105
- {
106
- name: "assets",
107
- type: "u64"
108
- }
109
- ],
110
- returns: "u64"
111
- },
112
- {
113
- name: "deposit_with_min_amount_out",
114
- discriminator: [
115
- 116,
116
- 144,
117
- 16,
118
- 97,
119
- 118,
120
- 109,
121
- 40,
122
- 119
123
- ],
124
- accounts: [
125
- {
126
- name: "signer",
127
- writable: true,
128
- signer: true
129
- },
130
- {
131
- name: "depositor_token_account",
132
- writable: true
133
- },
134
- {
135
- name: "recipient_token_account",
136
- writable: true
137
- },
138
- {
139
- name: "mint",
140
- relations: [
141
- "lending",
142
- "rewards_rate_model"
143
- ]
144
- },
145
- {
146
- name: "lending_admin"
147
- },
148
- {
149
- name: "lending",
150
- writable: true
151
- },
152
- {
153
- name: "f_token_mint",
154
- writable: true,
155
- relations: [
156
- "lending"
157
- ]
158
- },
159
- {
160
- name: "supply_token_reserves_liquidity",
161
- writable: true
162
- },
163
- {
164
- name: "lending_supply_position_on_liquidity",
165
- writable: true
166
- },
167
- {
168
- name: "rate_model"
169
- },
170
- {
171
- name: "vault",
172
- writable: true
173
- },
174
- {
175
- name: "liquidity",
176
- writable: true
177
- },
178
- {
179
- name: "liquidity_program",
180
- writable: true,
181
- relations: [
182
- "lending_admin"
183
- ]
184
- },
185
- {
186
- name: "rewards_rate_model"
187
- },
188
- {
189
- name: "token_program"
190
- },
191
- {
192
- name: "associated_token_program",
193
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
194
- },
195
- {
196
- name: "system_program",
197
- address: "11111111111111111111111111111111"
198
- }
199
- ],
200
- args: [
201
- {
202
- name: "assets",
203
- type: "u64"
204
- },
205
- {
206
- name: "min_amount_out",
207
- type: "u64"
208
- }
209
- ]
210
- },
211
- {
212
- name: "init_lending",
213
- discriminator: [
214
- 156,
215
- 224,
216
- 67,
217
- 46,
218
- 89,
219
- 189,
220
- 157,
221
- 209
222
- ],
223
- accounts: [
224
- {
225
- name: "signer",
226
- writable: true,
227
- signer: true
228
- },
229
- {
230
- name: "lending_admin",
231
- writable: true
232
- },
233
- {
234
- name: "mint",
235
- relations: [
236
- "token_reserves_liquidity"
237
- ]
238
- },
239
- {
240
- name: "f_token_mint",
241
- writable: true,
242
- pda: {
243
- seeds: [
244
- {
245
- kind: "const",
246
- value: [
247
- 102,
248
- 95,
249
- 116,
250
- 111,
251
- 107,
252
- 101,
253
- 110,
254
- 95,
255
- 109,
256
- 105,
257
- 110,
258
- 116
259
- ]
260
- },
261
- {
262
- kind: "account",
263
- path: "mint"
264
- }
265
- ]
266
- }
267
- },
268
- {
269
- name: "metadata_account",
270
- writable: true,
271
- pda: {
272
- seeds: [
273
- {
274
- kind: "const",
275
- value: [
276
- 109,
277
- 101,
278
- 116,
279
- 97,
280
- 100,
281
- 97,
282
- 116,
283
- 97
284
- ]
285
- },
286
- {
287
- kind: "const",
288
- value: [
289
- 11,
290
- 112,
291
- 101,
292
- 177,
293
- 227,
294
- 209,
295
- 124,
296
- 69,
297
- 56,
298
- 157,
299
- 82,
300
- 127,
301
- 107,
302
- 4,
303
- 195,
304
- 205,
305
- 88,
306
- 184,
307
- 108,
308
- 115,
309
- 26,
310
- 160,
311
- 253,
312
- 181,
313
- 73,
314
- 182,
315
- 209,
316
- 188,
317
- 3,
318
- 248,
319
- 41,
320
- 70
321
- ]
322
- },
323
- {
324
- kind: "account",
325
- path: "f_token_mint"
326
- }
327
- ],
328
- program: {
329
- kind: "const",
330
- value: [
331
- 11,
332
- 112,
333
- 101,
334
- 177,
335
- 227,
336
- 209,
337
- 124,
338
- 69,
339
- 56,
340
- 157,
341
- 82,
342
- 127,
343
- 107,
344
- 4,
345
- 195,
346
- 205,
347
- 88,
348
- 184,
349
- 108,
350
- 115,
351
- 26,
352
- 160,
353
- 253,
354
- 181,
355
- 73,
356
- 182,
357
- 209,
358
- 188,
359
- 3,
360
- 248,
361
- 41,
362
- 70
363
- ]
364
- }
365
- }
366
- },
367
- {
368
- name: "lending",
369
- writable: true,
370
- pda: {
371
- seeds: [
372
- {
373
- kind: "const",
374
- value: [
375
- 108,
376
- 101,
377
- 110,
378
- 100,
379
- 105,
380
- 110,
381
- 103
382
- ]
383
- },
384
- {
385
- kind: "account",
386
- path: "mint"
387
- },
388
- {
389
- kind: "account",
390
- path: "f_token_mint"
391
- }
392
- ]
393
- }
394
- },
395
- {
396
- name: "token_reserves_liquidity"
397
- },
398
- {
399
- name: "token_program"
400
- },
401
- {
402
- name: "system_program",
403
- address: "11111111111111111111111111111111"
404
- },
405
- {
406
- name: "sysvar_instruction",
407
- address: "Sysvar1nstructions1111111111111111111111111"
408
- },
409
- {
410
- name: "metadata_program",
411
- address: "metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s"
412
- },
413
- {
414
- name: "rent",
415
- address: "SysvarRent111111111111111111111111111111111"
416
- }
417
- ],
418
- args: [
419
- {
420
- name: "symbol",
421
- type: "string"
422
- },
423
- {
424
- name: "liquidity_program",
425
- type: "pubkey"
426
- }
427
- ]
428
- },
429
- {
430
- name: "init_lending_admin",
431
- discriminator: [
432
- 203,
433
- 185,
434
- 241,
435
- 165,
436
- 56,
437
- 254,
438
- 33,
439
- 9
440
- ],
441
- accounts: [
442
- {
443
- name: "authority",
444
- writable: true,
445
- signer: true
446
- },
447
- {
448
- name: "lending_admin",
449
- writable: true,
450
- pda: {
451
- seeds: [
452
- {
453
- kind: "const",
454
- value: [
455
- 108,
456
- 101,
457
- 110,
458
- 100,
459
- 105,
460
- 110,
461
- 103,
462
- 95,
463
- 97,
464
- 100,
465
- 109,
466
- 105,
467
- 110
468
- ]
469
- }
470
- ]
471
- }
472
- },
473
- {
474
- name: "system_program",
475
- address: "11111111111111111111111111111111"
476
- }
477
- ],
478
- args: [
479
- {
480
- name: "liquidity_program",
481
- type: "pubkey"
482
- },
483
- {
484
- name: "rebalancer",
485
- type: "pubkey"
486
- },
487
- {
488
- name: "authority",
489
- type: "pubkey"
490
- }
491
- ]
492
- },
493
- {
494
- name: "mint",
495
- discriminator: [
496
- 51,
497
- 57,
498
- 225,
499
- 47,
500
- 182,
501
- 146,
502
- 137,
503
- 166
504
- ],
505
- accounts: [
506
- {
507
- name: "signer",
508
- writable: true,
509
- signer: true
510
- },
511
- {
512
- name: "depositor_token_account",
513
- writable: true
514
- },
515
- {
516
- name: "recipient_token_account",
517
- writable: true
518
- },
519
- {
520
- name: "mint",
521
- relations: [
522
- "lending",
523
- "rewards_rate_model"
524
- ]
525
- },
526
- {
527
- name: "lending_admin"
528
- },
529
- {
530
- name: "lending",
531
- writable: true
532
- },
533
- {
534
- name: "f_token_mint",
535
- writable: true,
536
- relations: [
537
- "lending"
538
- ]
539
- },
540
- {
541
- name: "supply_token_reserves_liquidity",
542
- writable: true
543
- },
544
- {
545
- name: "lending_supply_position_on_liquidity",
546
- writable: true
547
- },
548
- {
549
- name: "rate_model"
550
- },
551
- {
552
- name: "vault",
553
- writable: true
554
- },
555
- {
556
- name: "liquidity",
557
- writable: true
558
- },
559
- {
560
- name: "liquidity_program",
561
- writable: true,
562
- relations: [
563
- "lending_admin"
564
- ]
565
- },
566
- {
567
- name: "rewards_rate_model"
568
- },
569
- {
570
- name: "token_program"
571
- },
572
- {
573
- name: "associated_token_program",
574
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
575
- },
576
- {
577
- name: "system_program",
578
- address: "11111111111111111111111111111111"
579
- }
580
- ],
581
- args: [
582
- {
583
- name: "shares",
584
- type: "u64"
585
- }
586
- ],
587
- returns: "u64"
588
- },
589
- {
590
- name: "mint_with_max_assets",
591
- discriminator: [
592
- 6,
593
- 94,
594
- 69,
595
- 122,
596
- 30,
597
- 179,
598
- 146,
599
- 171
600
- ],
601
- accounts: [
602
- {
603
- name: "signer",
604
- writable: true,
605
- signer: true
606
- },
607
- {
608
- name: "depositor_token_account",
609
- writable: true
610
- },
611
- {
612
- name: "recipient_token_account",
613
- writable: true
614
- },
615
- {
616
- name: "mint",
617
- relations: [
618
- "lending",
619
- "rewards_rate_model"
620
- ]
621
- },
622
- {
623
- name: "lending_admin"
624
- },
625
- {
626
- name: "lending",
627
- writable: true
628
- },
629
- {
630
- name: "f_token_mint",
631
- writable: true,
632
- relations: [
633
- "lending"
634
- ]
635
- },
636
- {
637
- name: "supply_token_reserves_liquidity",
638
- writable: true
639
- },
640
- {
641
- name: "lending_supply_position_on_liquidity",
642
- writable: true
643
- },
644
- {
645
- name: "rate_model"
646
- },
647
- {
648
- name: "vault",
649
- writable: true
650
- },
651
- {
652
- name: "liquidity",
653
- writable: true
654
- },
655
- {
656
- name: "liquidity_program",
657
- writable: true,
658
- relations: [
659
- "lending_admin"
660
- ]
661
- },
662
- {
663
- name: "rewards_rate_model"
664
- },
665
- {
666
- name: "token_program"
667
- },
668
- {
669
- name: "associated_token_program",
670
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
671
- },
672
- {
673
- name: "system_program",
674
- address: "11111111111111111111111111111111"
675
- }
676
- ],
677
- args: [
678
- {
679
- name: "shares",
680
- type: "u64"
681
- },
682
- {
683
- name: "max_assets",
684
- type: "u64"
685
- }
686
- ],
687
- returns: "u64"
688
- },
689
- {
690
- name: "rebalance",
691
- discriminator: [
692
- 108,
693
- 158,
694
- 77,
695
- 9,
696
- 210,
697
- 52,
698
- 88,
699
- 62
700
- ],
701
- accounts: [
702
- {
703
- name: "signer",
704
- writable: true,
705
- signer: true
706
- },
707
- {
708
- name: "depositor_token_account",
709
- writable: true,
710
- pda: {
711
- seeds: [
712
- {
713
- kind: "account",
714
- path: "signer"
715
- },
716
- {
717
- kind: "account",
718
- path: "token_program"
719
- },
720
- {
721
- kind: "account",
722
- path: "mint"
723
- }
724
- ],
725
- program: {
726
- kind: "const",
727
- value: [
728
- 140,
729
- 151,
730
- 37,
731
- 143,
732
- 78,
733
- 36,
734
- 137,
735
- 241,
736
- 187,
737
- 61,
738
- 16,
739
- 41,
740
- 20,
741
- 142,
742
- 13,
743
- 131,
744
- 11,
745
- 90,
746
- 19,
747
- 153,
748
- 218,
749
- 255,
750
- 16,
751
- 132,
752
- 4,
753
- 142,
754
- 123,
755
- 216,
756
- 219,
757
- 233,
758
- 248,
759
- 89
760
- ]
761
- }
762
- }
763
- },
764
- {
765
- name: "lending_admin"
766
- },
767
- {
768
- name: "lending",
769
- writable: true
770
- },
771
- {
772
- name: "mint",
773
- relations: [
774
- "lending",
775
- "rewards_rate_model"
776
- ]
777
- },
778
- {
779
- name: "f_token_mint",
780
- writable: true,
781
- relations: [
782
- "lending"
783
- ]
784
- },
785
- {
786
- name: "supply_token_reserves_liquidity",
787
- writable: true
788
- },
789
- {
790
- name: "lending_supply_position_on_liquidity",
791
- writable: true
792
- },
793
- {
794
- name: "rate_model",
795
- writable: true
796
- },
797
- {
798
- name: "vault",
799
- writable: true
800
- },
801
- {
802
- name: "liquidity",
803
- writable: true
804
- },
805
- {
806
- name: "liquidity_program",
807
- writable: true,
808
- relations: [
809
- "lending_admin"
810
- ]
811
- },
812
- {
813
- name: "rewards_rate_model"
814
- },
815
- {
816
- name: "token_program"
817
- },
818
- {
819
- name: "associated_token_program",
820
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
821
- },
822
- {
823
- name: "system_program",
824
- address: "11111111111111111111111111111111"
825
- }
826
- ],
827
- args: [
828
- ]
829
- },
830
- {
831
- name: "redeem",
832
- discriminator: [
833
- 184,
834
- 12,
835
- 86,
836
- 149,
837
- 70,
838
- 196,
839
- 97,
840
- 225
841
- ],
842
- accounts: [
843
- {
844
- name: "signer",
845
- writable: true,
846
- signer: true
847
- },
848
- {
849
- name: "owner_token_account",
850
- writable: true
851
- },
852
- {
853
- name: "recipient_token_account",
854
- writable: true
855
- },
856
- {
857
- name: "lending_admin"
858
- },
859
- {
860
- name: "lending",
861
- writable: true
862
- },
863
- {
864
- name: "mint",
865
- relations: [
866
- "lending",
867
- "rewards_rate_model"
868
- ]
869
- },
870
- {
871
- name: "f_token_mint",
872
- writable: true,
873
- relations: [
874
- "lending"
875
- ]
876
- },
877
- {
878
- name: "supply_token_reserves_liquidity",
879
- writable: true
880
- },
881
- {
882
- name: "lending_supply_position_on_liquidity",
883
- writable: true
884
- },
885
- {
886
- name: "rate_model"
887
- },
888
- {
889
- name: "vault",
890
- writable: true
891
- },
892
- {
893
- name: "claim_account",
894
- writable: true
895
- },
896
- {
897
- name: "liquidity",
898
- writable: true
899
- },
900
- {
901
- name: "liquidity_program",
902
- writable: true,
903
- relations: [
904
- "lending_admin"
905
- ]
906
- },
907
- {
908
- name: "rewards_rate_model"
909
- },
910
- {
911
- name: "token_program"
912
- },
913
- {
914
- name: "associated_token_program",
915
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
916
- },
917
- {
918
- name: "system_program",
919
- address: "11111111111111111111111111111111"
920
- }
921
- ],
922
- args: [
923
- {
924
- name: "shares",
925
- type: "u64"
926
- }
927
- ],
928
- returns: "u64"
929
- },
930
- {
931
- name: "redeem_with_min_amount_out",
932
- discriminator: [
933
- 235,
934
- 189,
935
- 237,
936
- 56,
937
- 166,
938
- 180,
939
- 184,
940
- 149
941
- ],
942
- accounts: [
943
- {
944
- name: "signer",
945
- writable: true,
946
- signer: true
947
- },
948
- {
949
- name: "owner_token_account",
950
- writable: true
951
- },
952
- {
953
- name: "recipient_token_account",
954
- writable: true
955
- },
956
- {
957
- name: "lending_admin"
958
- },
959
- {
960
- name: "lending",
961
- writable: true
962
- },
963
- {
964
- name: "mint",
965
- relations: [
966
- "lending",
967
- "rewards_rate_model"
968
- ]
969
- },
970
- {
971
- name: "f_token_mint",
972
- writable: true,
973
- relations: [
974
- "lending"
975
- ]
976
- },
977
- {
978
- name: "supply_token_reserves_liquidity",
979
- writable: true
980
- },
981
- {
982
- name: "lending_supply_position_on_liquidity",
983
- writable: true
984
- },
985
- {
986
- name: "rate_model"
987
- },
988
- {
989
- name: "vault",
990
- writable: true
991
- },
992
- {
993
- name: "claim_account",
994
- writable: true
995
- },
996
- {
997
- name: "liquidity",
998
- writable: true
999
- },
1000
- {
1001
- name: "liquidity_program",
1002
- writable: true,
1003
- relations: [
1004
- "lending_admin"
1005
- ]
1006
- },
1007
- {
1008
- name: "rewards_rate_model"
1009
- },
1010
- {
1011
- name: "token_program"
1012
- },
1013
- {
1014
- name: "associated_token_program",
1015
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1016
- },
1017
- {
1018
- name: "system_program",
1019
- address: "11111111111111111111111111111111"
1020
- }
1021
- ],
1022
- args: [
1023
- {
1024
- name: "shares",
1025
- type: "u64"
1026
- },
1027
- {
1028
- name: "min_amount_out",
1029
- type: "u64"
1030
- }
1031
- ]
1032
- },
1033
- {
1034
- name: "set_rewards_rate_model",
1035
- discriminator: [
1036
- 174,
1037
- 231,
1038
- 116,
1039
- 203,
1040
- 8,
1041
- 58,
1042
- 143,
1043
- 203
1044
- ],
1045
- accounts: [
1046
- {
1047
- name: "signer",
1048
- signer: true
1049
- },
1050
- {
1051
- name: "lending_admin"
1052
- },
1053
- {
1054
- name: "lending",
1055
- writable: true
1056
- },
1057
- {
1058
- name: "f_token_mint",
1059
- relations: [
1060
- "lending"
1061
- ]
1062
- },
1063
- {
1064
- name: "new_rewards_rate_model"
1065
- },
1066
- {
1067
- name: "supply_token_reserves_liquidity"
1068
- }
1069
- ],
1070
- args: [
1071
- {
1072
- name: "mint",
1073
- type: "pubkey"
1074
- }
1075
- ]
1076
- },
1077
- {
1078
- name: "update_authority",
1079
- discriminator: [
1080
- 32,
1081
- 46,
1082
- 64,
1083
- 28,
1084
- 149,
1085
- 75,
1086
- 243,
1087
- 88
1088
- ],
1089
- accounts: [
1090
- {
1091
- name: "signer",
1092
- signer: true
1093
- },
1094
- {
1095
- name: "lending_admin",
1096
- writable: true
1097
- }
1098
- ],
1099
- args: [
1100
- {
1101
- name: "new_authority",
1102
- type: "pubkey"
1103
- }
1104
- ]
1105
- },
1106
- {
1107
- name: "update_auths",
1108
- discriminator: [
1109
- 93,
1110
- 96,
1111
- 178,
1112
- 156,
1113
- 57,
1114
- 117,
1115
- 253,
1116
- 209
1117
- ],
1118
- accounts: [
1119
- {
1120
- name: "signer",
1121
- signer: true
1122
- },
1123
- {
1124
- name: "lending_admin",
1125
- writable: true
1126
- }
1127
- ],
1128
- args: [
1129
- {
1130
- name: "auth_status",
1131
- type: {
1132
- vec: {
1133
- defined: {
1134
- name: "AddressBool"
1135
- }
1136
- }
1137
- }
1138
- }
1139
- ]
1140
- },
1141
- {
1142
- name: "update_rate",
1143
- discriminator: [
1144
- 24,
1145
- 225,
1146
- 53,
1147
- 189,
1148
- 72,
1149
- 212,
1150
- 225,
1151
- 178
1152
- ],
1153
- accounts: [
1154
- {
1155
- name: "lending",
1156
- writable: true
1157
- },
1158
- {
1159
- name: "mint",
1160
- relations: [
1161
- "lending",
1162
- "supply_token_reserves_liquidity"
1163
- ]
1164
- },
1165
- {
1166
- name: "f_token_mint",
1167
- relations: [
1168
- "lending"
1169
- ]
1170
- },
1171
- {
1172
- name: "supply_token_reserves_liquidity"
1173
- },
1174
- {
1175
- name: "rewards_rate_model"
1176
- }
1177
- ],
1178
- args: [
1179
- ]
1180
- },
1181
- {
1182
- name: "update_rebalancer",
1183
- discriminator: [
1184
- 206,
1185
- 187,
1186
- 54,
1187
- 228,
1188
- 145,
1189
- 8,
1190
- 203,
1191
- 111
1192
- ],
1193
- accounts: [
1194
- {
1195
- name: "signer",
1196
- signer: true
1197
- },
1198
- {
1199
- name: "lending_admin",
1200
- writable: true
1201
- }
1202
- ],
1203
- args: [
1204
- {
1205
- name: "new_rebalancer",
1206
- type: "pubkey"
1207
- }
1208
- ]
1209
- },
1210
- {
1211
- name: "withdraw",
1212
- discriminator: [
1213
- 183,
1214
- 18,
1215
- 70,
1216
- 156,
1217
- 148,
1218
- 109,
1219
- 161,
1220
- 34
1221
- ],
1222
- accounts: [
1223
- {
1224
- name: "signer",
1225
- writable: true,
1226
- signer: true
1227
- },
1228
- {
1229
- name: "owner_token_account",
1230
- writable: true
1231
- },
1232
- {
1233
- name: "recipient_token_account",
1234
- writable: true
1235
- },
1236
- {
1237
- name: "lending_admin"
1238
- },
1239
- {
1240
- name: "lending",
1241
- writable: true
1242
- },
1243
- {
1244
- name: "mint",
1245
- relations: [
1246
- "lending",
1247
- "rewards_rate_model"
1248
- ]
1249
- },
1250
- {
1251
- name: "f_token_mint",
1252
- writable: true,
1253
- relations: [
1254
- "lending"
1255
- ]
1256
- },
1257
- {
1258
- name: "supply_token_reserves_liquidity",
1259
- writable: true
1260
- },
1261
- {
1262
- name: "lending_supply_position_on_liquidity",
1263
- writable: true
1264
- },
1265
- {
1266
- name: "rate_model"
1267
- },
1268
- {
1269
- name: "vault",
1270
- writable: true
1271
- },
1272
- {
1273
- name: "claim_account",
1274
- writable: true
1275
- },
1276
- {
1277
- name: "liquidity",
1278
- writable: true
1279
- },
1280
- {
1281
- name: "liquidity_program",
1282
- writable: true,
1283
- relations: [
1284
- "lending_admin"
1285
- ]
1286
- },
1287
- {
1288
- name: "rewards_rate_model"
1289
- },
1290
- {
1291
- name: "token_program"
1292
- },
1293
- {
1294
- name: "associated_token_program",
1295
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1296
- },
1297
- {
1298
- name: "system_program",
1299
- address: "11111111111111111111111111111111"
1300
- }
1301
- ],
1302
- args: [
1303
- {
1304
- name: "amount",
1305
- type: "u64"
1306
- }
1307
- ],
1308
- returns: "u64"
1309
- },
1310
- {
1311
- name: "withdraw_with_max_shares_burn",
1312
- discriminator: [
1313
- 47,
1314
- 197,
1315
- 183,
1316
- 171,
1317
- 239,
1318
- 18,
1319
- 245,
1320
- 171
1321
- ],
1322
- accounts: [
1323
- {
1324
- name: "signer",
1325
- writable: true,
1326
- signer: true
1327
- },
1328
- {
1329
- name: "owner_token_account",
1330
- writable: true
1331
- },
1332
- {
1333
- name: "recipient_token_account",
1334
- writable: true
1335
- },
1336
- {
1337
- name: "lending_admin"
1338
- },
1339
- {
1340
- name: "lending",
1341
- writable: true
1342
- },
1343
- {
1344
- name: "mint",
1345
- relations: [
1346
- "lending",
1347
- "rewards_rate_model"
1348
- ]
1349
- },
1350
- {
1351
- name: "f_token_mint",
1352
- writable: true,
1353
- relations: [
1354
- "lending"
1355
- ]
1356
- },
1357
- {
1358
- name: "supply_token_reserves_liquidity",
1359
- writable: true
1360
- },
1361
- {
1362
- name: "lending_supply_position_on_liquidity",
1363
- writable: true
1364
- },
1365
- {
1366
- name: "rate_model"
1367
- },
1368
- {
1369
- name: "vault",
1370
- writable: true
1371
- },
1372
- {
1373
- name: "claim_account",
1374
- writable: true
1375
- },
1376
- {
1377
- name: "liquidity",
1378
- writable: true
1379
- },
1380
- {
1381
- name: "liquidity_program",
1382
- writable: true,
1383
- relations: [
1384
- "lending_admin"
1385
- ]
1386
- },
1387
- {
1388
- name: "rewards_rate_model"
1389
- },
1390
- {
1391
- name: "token_program"
1392
- },
1393
- {
1394
- name: "associated_token_program",
1395
- address: "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL"
1396
- },
1397
- {
1398
- name: "system_program",
1399
- address: "11111111111111111111111111111111"
1400
- }
1401
- ],
1402
- args: [
1403
- {
1404
- name: "amount",
1405
- type: "u64"
1406
- },
1407
- {
1408
- name: "max_shares_burn",
1409
- type: "u64"
1410
- }
1411
- ],
1412
- returns: "u64"
1413
- }
1414
- ];
1415
- const accounts = [
1416
- {
1417
- name: "Lending",
1418
- discriminator: [
1419
- 135,
1420
- 199,
1421
- 82,
1422
- 16,
1423
- 249,
1424
- 131,
1425
- 182,
1426
- 241
1427
- ]
1428
- },
1429
- {
1430
- name: "LendingAdmin",
1431
- discriminator: [
1432
- 42,
1433
- 8,
1434
- 33,
1435
- 220,
1436
- 163,
1437
- 40,
1438
- 210,
1439
- 5
1440
- ]
1441
- },
1442
- {
1443
- name: "LendingRewardsRateModel",
1444
- discriminator: [
1445
- 166,
1446
- 72,
1447
- 71,
1448
- 131,
1449
- 172,
1450
- 74,
1451
- 166,
1452
- 181
1453
- ]
1454
- },
1455
- {
1456
- name: "TokenReserve",
1457
- discriminator: [
1458
- 21,
1459
- 18,
1460
- 59,
1461
- 135,
1462
- 120,
1463
- 20,
1464
- 31,
1465
- 12
1466
- ]
1467
- },
1468
- {
1469
- name: "UserSupplyPosition",
1470
- discriminator: [
1471
- 202,
1472
- 219,
1473
- 136,
1474
- 118,
1475
- 61,
1476
- 177,
1477
- 21,
1478
- 146
1479
- ]
1480
- }
1481
- ];
1482
- const events = [
1483
- {
1484
- name: "LogDeposit",
1485
- discriminator: [
1486
- 176,
1487
- 243,
1488
- 1,
1489
- 56,
1490
- 142,
1491
- 206,
1492
- 1,
1493
- 106
1494
- ]
1495
- },
1496
- {
1497
- name: "LogRebalance",
1498
- discriminator: [
1499
- 90,
1500
- 67,
1501
- 219,
1502
- 41,
1503
- 181,
1504
- 118,
1505
- 132,
1506
- 9
1507
- ]
1508
- },
1509
- {
1510
- name: "LogUpdateAuthority",
1511
- discriminator: [
1512
- 150,
1513
- 152,
1514
- 157,
1515
- 143,
1516
- 6,
1517
- 135,
1518
- 193,
1519
- 101
1520
- ]
1521
- },
1522
- {
1523
- name: "LogUpdateAuths",
1524
- discriminator: [
1525
- 88,
1526
- 80,
1527
- 109,
1528
- 48,
1529
- 111,
1530
- 203,
1531
- 76,
1532
- 251
1533
- ]
1534
- },
1535
- {
1536
- name: "LogUpdateRates",
1537
- discriminator: [
1538
- 222,
1539
- 11,
1540
- 113,
1541
- 60,
1542
- 147,
1543
- 15,
1544
- 68,
1545
- 217
1546
- ]
1547
- },
1548
- {
1549
- name: "LogUpdateRebalancer",
1550
- discriminator: [
1551
- 66,
1552
- 79,
1553
- 144,
1554
- 204,
1555
- 26,
1556
- 217,
1557
- 153,
1558
- 225
1559
- ]
1560
- },
1561
- {
1562
- name: "LogUpdateRewards",
1563
- discriminator: [
1564
- 37,
1565
- 13,
1566
- 111,
1567
- 186,
1568
- 47,
1569
- 245,
1570
- 162,
1571
- 121
1572
- ]
1573
- },
1574
- {
1575
- name: "LogWithdraw",
1576
- discriminator: [
1577
- 49,
1578
- 9,
1579
- 176,
1580
- 179,
1581
- 222,
1582
- 190,
1583
- 6,
1584
- 117
1585
- ]
1586
- }
1587
- ];
1588
- const errors = [
1589
- {
1590
- code: 6000,
1591
- name: "FTokenDepositInsignificant",
1592
- msg: "F_TOKEN_DEPOSIT_INSIGNIFICANT"
1593
- },
1594
- {
1595
- code: 6001,
1596
- name: "FTokenMinAmountOut",
1597
- msg: "F_TOKEN_MIN_AMOUNT_OUT"
1598
- },
1599
- {
1600
- code: 6002,
1601
- name: "FTokenMaxAmount",
1602
- msg: "F_TOKEN_MAX_AMOUNT"
1603
- },
1604
- {
1605
- code: 6003,
1606
- name: "FTokenInvalidParams",
1607
- msg: "F_TOKEN_INVALID_PARAMS"
1608
- },
1609
- {
1610
- code: 6004,
1611
- name: "FTokenRewardsRateModelAlreadySet",
1612
- msg: "F_TOKEN_REWARDS_RATE_MODEL_ALREADY_SET"
1613
- },
1614
- {
1615
- code: 6005,
1616
- name: "FTokenMaxAuthCountReached",
1617
- msg: "F_TOKEN_MAX_AUTH_COUNT"
1618
- },
1619
- {
1620
- code: 6006,
1621
- name: "FTokenLiquidityExchangePriceUnexpected",
1622
- msg: "F_TOKEN_LIQUIDITY_EXCHANGE_PRICE_UNEXPECTED"
1623
- },
1624
- {
1625
- code: 6007,
1626
- name: "FTokenCpiToLiquidityFailed",
1627
- msg: "F_TOKEN_CPI_TO_LIQUIDITY_FAILED"
1628
- },
1629
- {
1630
- code: 6008,
1631
- name: "FTokenOnlyAuth",
1632
- msg: "F_TOKEN_ONLY_AUTH"
1633
- },
1634
- {
1635
- code: 6009,
1636
- name: "FTokenOnlyAuthority",
1637
- msg: "F_TOKEN_ONLY_AUTHORITY"
1638
- },
1639
- {
1640
- code: 6010,
1641
- name: "FTokenOnlyRebalancer",
1642
- msg: "F_TOKEN_ONLY_REBALANCER"
1643
- },
1644
- {
1645
- code: 6011,
1646
- name: "FTokenUserSupplyPositionRequired",
1647
- msg: "F_TOKEN_USER_SUPPLY_POSITION_REQUIRED"
1648
- },
1649
- {
1650
- code: 6012,
1651
- name: "FTokenLiquidityProgramMismatch",
1652
- msg: "F_TOKEN_LIQUIDITY_PROGRAM_MISMATCH"
1653
- }
1654
- ];
1655
- const types = [
1656
- {
1657
- name: "AddressBool",
1658
- type: {
1659
- kind: "struct",
1660
- fields: [
1661
- {
1662
- name: "addr",
1663
- type: "pubkey"
1664
- },
1665
- {
1666
- name: "value",
1667
- type: "bool"
1668
- }
1669
- ]
1670
- }
1671
- },
1672
- {
1673
- name: "Lending",
1674
- type: {
1675
- kind: "struct",
1676
- fields: [
1677
- {
1678
- name: "mint",
1679
- type: "pubkey"
1680
- },
1681
- {
1682
- name: "f_token_mint",
1683
- type: "pubkey"
1684
- },
1685
- {
1686
- name: "lending_id",
1687
- type: "u16"
1688
- },
1689
- {
1690
- name: "decimals",
1691
- docs: [
1692
- "@dev number of decimals for the fToken, same as ASSET"
1693
- ],
1694
- type: "u8"
1695
- },
1696
- {
1697
- name: "rewards_rate_model",
1698
- docs: [
1699
- "@dev To read PDA of rewards rate model to get_rate instruction"
1700
- ],
1701
- type: "pubkey"
1702
- },
1703
- {
1704
- name: "liquidity_exchange_price",
1705
- docs: [
1706
- "@dev exchange price for the underlying asset in the liquidity protocol (without rewards)"
1707
- ],
1708
- type: "u64"
1709
- },
1710
- {
1711
- name: "token_exchange_price",
1712
- docs: [
1713
- "@dev exchange price between fToken and the underlying asset (with rewards)"
1714
- ],
1715
- type: "u64"
1716
- },
1717
- {
1718
- name: "last_update_timestamp",
1719
- docs: [
1720
- "@dev timestamp when exchange prices were updated the last time"
1721
- ],
1722
- type: "u64"
1723
- },
1724
- {
1725
- name: "token_reserves_liquidity",
1726
- type: "pubkey"
1727
- },
1728
- {
1729
- name: "supply_position_on_liquidity",
1730
- type: "pubkey"
1731
- },
1732
- {
1733
- name: "bump",
1734
- type: "u8"
1735
- }
1736
- ]
1737
- }
1738
- },
1739
- {
1740
- name: "LendingAdmin",
1741
- type: {
1742
- kind: "struct",
1743
- fields: [
1744
- {
1745
- name: "authority",
1746
- type: "pubkey"
1747
- },
1748
- {
1749
- name: "liquidity_program",
1750
- type: "pubkey"
1751
- },
1752
- {
1753
- name: "rebalancer",
1754
- type: "pubkey"
1755
- },
1756
- {
1757
- name: "next_lending_id",
1758
- type: "u16"
1759
- },
1760
- {
1761
- name: "auths",
1762
- type: {
1763
- vec: "pubkey"
1764
- }
1765
- },
1766
- {
1767
- name: "bump",
1768
- type: "u8"
1769
- }
1770
- ]
1771
- }
1772
- },
1773
- {
1774
- name: "LendingRewardsRateModel",
1775
- type: {
1776
- kind: "struct",
1777
- fields: [
1778
- {
1779
- name: "mint",
1780
- docs: [
1781
- "@dev mint address"
1782
- ],
1783
- type: "pubkey"
1784
- },
1785
- {
1786
- name: "start_tvl",
1787
- docs: [
1788
- "@dev tvl below which rewards rate is 0. If current TVL is below this value, triggering `update_rate()` on the fToken",
1789
- "might bring the total TVL above this cut-off."
1790
- ],
1791
- type: "u64"
1792
- },
1793
- {
1794
- name: "duration",
1795
- docs: [
1796
- "@dev for how long current rewards should run"
1797
- ],
1798
- type: "u64"
1799
- },
1800
- {
1801
- name: "start_time",
1802
- docs: [
1803
- "@dev when current rewards got started"
1804
- ],
1805
- type: "u64"
1806
- },
1807
- {
1808
- name: "yearly_reward",
1809
- docs: [
1810
- "@dev current annualized reward based on input params (duration, rewardAmount)"
1811
- ],
1812
- type: "u64"
1813
- },
1814
- {
1815
- name: "next_duration",
1816
- docs: [
1817
- "@dev Duration for the next rewards phase"
1818
- ],
1819
- type: "u64"
1820
- },
1821
- {
1822
- name: "next_reward_amount",
1823
- docs: [
1824
- "@dev Amount of rewards for the next phase"
1825
- ],
1826
- type: "u64"
1827
- },
1828
- {
1829
- name: "bump",
1830
- type: "u8"
1831
- }
1832
- ]
1833
- }
1834
- },
1835
- {
1836
- name: "LogDeposit",
1837
- type: {
1838
- kind: "struct",
1839
- fields: [
1840
- {
1841
- name: "sender",
1842
- type: "pubkey"
1843
- },
1844
- {
1845
- name: "receiver",
1846
- type: "pubkey"
1847
- },
1848
- {
1849
- name: "assets",
1850
- type: "u64"
1851
- },
1852
- {
1853
- name: "shares_minted",
1854
- type: "u64"
1855
- }
1856
- ]
1857
- }
1858
- },
1859
- {
1860
- name: "LogRebalance",
1861
- type: {
1862
- kind: "struct",
1863
- fields: [
1864
- {
1865
- name: "assets",
1866
- type: "u64"
1867
- }
1868
- ]
1869
- }
1870
- },
1871
- {
1872
- name: "LogUpdateAuthority",
1873
- type: {
1874
- kind: "struct",
1875
- fields: [
1876
- {
1877
- name: "new_authority",
1878
- type: "pubkey"
1879
- }
1880
- ]
1881
- }
1882
- },
1883
- {
1884
- name: "LogUpdateAuths",
1885
- type: {
1886
- kind: "struct",
1887
- fields: [
1888
- {
1889
- name: "auth_status",
1890
- type: {
1891
- vec: {
1892
- defined: {
1893
- name: "AddressBool"
1894
- }
1895
- }
1896
- }
1897
- }
1898
- ]
1899
- }
1900
- },
1901
- {
1902
- name: "LogUpdateRates",
1903
- type: {
1904
- kind: "struct",
1905
- fields: [
1906
- {
1907
- name: "token_exchange_price",
1908
- type: "u64"
1909
- },
1910
- {
1911
- name: "liquidity_exchange_price",
1912
- type: "u64"
1913
- }
1914
- ]
1915
- }
1916
- },
1917
- {
1918
- name: "LogUpdateRebalancer",
1919
- type: {
1920
- kind: "struct",
1921
- fields: [
1922
- {
1923
- name: "new_rebalancer",
1924
- type: "pubkey"
1925
- }
1926
- ]
1927
- }
1928
- },
1929
- {
1930
- name: "LogUpdateRewards",
1931
- type: {
1932
- kind: "struct",
1933
- fields: [
1934
- {
1935
- name: "rewards_rate_model",
1936
- type: "pubkey"
1937
- }
1938
- ]
1939
- }
1940
- },
1941
- {
1942
- name: "LogWithdraw",
1943
- type: {
1944
- kind: "struct",
1945
- fields: [
1946
- {
1947
- name: "sender",
1948
- type: "pubkey"
1949
- },
1950
- {
1951
- name: "receiver",
1952
- type: "pubkey"
1953
- },
1954
- {
1955
- name: "owner",
1956
- type: "pubkey"
1957
- },
1958
- {
1959
- name: "assets",
1960
- type: "u64"
1961
- },
1962
- {
1963
- name: "shares_burned",
1964
- type: "u64"
1965
- }
1966
- ]
1967
- }
1968
- },
1969
- {
1970
- name: "TokenReserve",
1971
- docs: [
1972
- "Token configuration and exchange prices"
1973
- ],
1974
- serialization: "bytemuck",
1975
- repr: {
1976
- kind: "c",
1977
- packed: true
1978
- },
1979
- type: {
1980
- kind: "struct",
1981
- fields: [
1982
- {
1983
- name: "mint",
1984
- type: "pubkey"
1985
- },
1986
- {
1987
- name: "vault",
1988
- type: "pubkey"
1989
- },
1990
- {
1991
- name: "borrow_rate",
1992
- type: "u16"
1993
- },
1994
- {
1995
- name: "fee_on_interest",
1996
- type: "u16"
1997
- },
1998
- {
1999
- name: "last_utilization",
2000
- type: "u16"
2001
- },
2002
- {
2003
- name: "last_update_timestamp",
2004
- type: "u64"
2005
- },
2006
- {
2007
- name: "supply_exchange_price",
2008
- type: "u64"
2009
- },
2010
- {
2011
- name: "borrow_exchange_price",
2012
- type: "u64"
2013
- },
2014
- {
2015
- name: "max_utilization",
2016
- type: "u16"
2017
- },
2018
- {
2019
- name: "total_supply_with_interest",
2020
- type: "u64"
2021
- },
2022
- {
2023
- name: "total_supply_interest_free",
2024
- type: "u64"
2025
- },
2026
- {
2027
- name: "total_borrow_with_interest",
2028
- type: "u64"
2029
- },
2030
- {
2031
- name: "total_borrow_interest_free",
2032
- type: "u64"
2033
- },
2034
- {
2035
- name: "total_claim_amount",
2036
- type: "u64"
2037
- },
2038
- {
2039
- name: "interacting_protocol",
2040
- type: "pubkey"
2041
- },
2042
- {
2043
- name: "interacting_timestamp",
2044
- type: "u64"
2045
- },
2046
- {
2047
- name: "interacting_balance",
2048
- type: "u64"
2049
- }
2050
- ]
2051
- }
2052
- },
2053
- {
2054
- name: "UserSupplyPosition",
2055
- docs: [
2056
- "User supply position"
2057
- ],
2058
- serialization: "bytemuck",
2059
- repr: {
2060
- kind: "c",
2061
- packed: true
2062
- },
2063
- type: {
2064
- kind: "struct",
2065
- fields: [
2066
- {
2067
- name: "protocol",
2068
- type: "pubkey"
2069
- },
2070
- {
2071
- name: "mint",
2072
- type: "pubkey"
2073
- },
2074
- {
2075
- name: "with_interest",
2076
- type: "u8"
2077
- },
2078
- {
2079
- name: "amount",
2080
- type: "u64"
2081
- },
2082
- {
2083
- name: "withdrawal_limit",
2084
- type: "u128"
2085
- },
2086
- {
2087
- name: "last_update",
2088
- type: "u64"
2089
- },
2090
- {
2091
- name: "expand_pct",
2092
- type: "u16"
2093
- },
2094
- {
2095
- name: "expand_duration",
2096
- type: "u64"
2097
- },
2098
- {
2099
- name: "base_withdrawal_limit",
2100
- type: "u64"
2101
- },
2102
- {
2103
- name: "status",
2104
- type: "u8"
2105
- }
2106
- ]
2107
- }
2108
- }
2109
- ];
2110
- const lending = {
2111
- address: address,
2112
- metadata: metadata,
2113
- instructions: instructions,
2114
- accounts: accounts,
2115
- events: events,
2116
- errors: errors,
2117
- types: types
2118
- };
2119
-
2120
- const U64_MAX = new BN("18446744073709551615");
2121
- const MAX_DEPOSIT = U64_MAX;
2122
- const MAX_WITHDRAW = U64_MAX;
2123
- const getLendingProgram = ({
2124
- connection,
2125
- signer,
2126
- market
2127
- }) => {
2128
- let idl = { ...lending };
2129
- if (market === "ethena")
2130
- idl.address = "jup97Zx1NixM8UJMQFw8TtKzqTiRT3ETAJR7cVx3PfQ";
2131
- return new Program(idl, {
2132
- connection,
2133
- publicKey: signer
2134
- });
2135
- };
2136
- const getAccountOwner = async (account, connection) => {
2137
- const info = await connection.getAccountInfo(account);
2138
- if (!info)
2139
- throw new Error(`Account info not found for ${account.toString()}`);
2140
- return info.owner;
2141
- };
2142
- const getOrCreateATAInstruction = async (owner, mint, connection) => {
2143
- const tokenProgram = await getAccountOwner(mint, connection);
2144
- const associatedTokenAccount = await getAssociatedTokenAddress(
2145
- mint,
2146
- owner,
2147
- true,
2148
- // allowOwnerOffCurve - supports PDA owners
2149
- tokenProgram
2150
- );
2151
- const account = await getAccount(
2152
- connection,
2153
- associatedTokenAccount,
2154
- "confirmed",
2155
- tokenProgram
2156
- ).catch(() => null);
2157
- const ixs = [];
2158
- if (!account) {
2159
- ixs.push(
2160
- createAssociatedTokenAccountInstruction(
2161
- owner,
2162
- associatedTokenAccount,
2163
- owner,
2164
- mint,
2165
- tokenProgram
2166
- )
2167
- );
2168
- }
2169
- return ixs;
2170
- };
2171
- const getLiquidityProgramId = (market) => {
2172
- return market === "ethena" ? new PublicKey("jup6QF1sNDGpkkcu6F4qaFHcRBmnSS1VgyB4uFbBvNS") : new PublicKey("jupeiUmn818Jg1ekPURTpr4mFo29p46vygyykFJ3wZC");
2173
- };
7
+ import BN from 'bn.js';
8
+ import '@coral-xyz/anchor';
2174
9
 
2175
10
  async function getDepositContext({
2176
11
  asset,
@@ -2237,7 +72,6 @@ async function getDepositContext({
2237
72
  market
2238
73
  ),
2239
74
  tokenProgram,
2240
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
2241
75
  systemProgram: SystemProgram.programId,
2242
76
  sysvarInstruction: SYSVAR_INSTRUCTIONS_PUBKEY
2243
77
  };
@@ -2362,7 +196,6 @@ async function getWithdrawContext({
2362
196
  market
2363
197
  ),
2364
198
  tokenProgram,
2365
- associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
2366
199
  systemProgram: SystemProgram.programId,
2367
200
  sysvarInstruction: SYSVAR_INSTRUCTIONS_PUBKEY
2368
201
  };
@@ -2421,10 +254,10 @@ const getRedeemIxs = async ({
2421
254
  };
2422
255
 
2423
256
  const LENDING_CONSTANTS = {
2424
- EXCHANGE_PRICES_PRECISION: new BN$1(1e12),
257
+ EXCHANGE_PRICES_PRECISION: new BN(1e12),
2425
258
  // 1e12
2426
- SECONDS_PER_YEAR: new BN$1(31536e3),
2427
- MAX_REWARDS_RATE: new BN$1(50 * 1e12)
259
+ SECONDS_PER_YEAR: new BN(31536e3),
260
+ MAX_REWARDS_RATE: new BN(50 * 1e12)
2428
261
  // 50%
2429
262
  };
2430
263
  async function getLendingData(address, program) {
@@ -2443,8 +276,8 @@ async function getLendingData(address, program) {
2443
276
  return lendingRes.account;
2444
277
  }
2445
278
  function calculateTotalAssets(lending, totalSupply) {
2446
- const tokenExchangePrice = new BN$1(lending.tokenExchangePrice.toString());
2447
- const totalSupplyBN = typeof totalSupply === "number" || typeof totalSupply === "string" ? new BN$1(String(totalSupply)) : totalSupply;
279
+ const tokenExchangePrice = new BN(lending.tokenExchangePrice.toString());
280
+ const totalSupplyBN = typeof totalSupply === "number" || typeof totalSupply === "string" ? new BN(String(totalSupply)) : totalSupply;
2448
281
  return Number.parseInt(
2449
282
  tokenExchangePrice.mul(totalSupplyBN).div(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION).toString()
2450
283
  );
@@ -2482,7 +315,7 @@ async function getRewardsRate(asset, totalAssets, connection, market) {
2482
315
  );
2483
316
  if (totalAssets.lt(currentRateModel.startTvl)) {
2484
317
  return {
2485
- rate: new BN$1(0),
318
+ rate: new BN(0),
2486
319
  rewardsEnded: false,
2487
320
  rewardsStartTime: currentRateModel.startTime
2488
321
  };
@@ -2510,11 +343,11 @@ async function getLiquidityExchangePricesAndConfig(assetAddress, connection, mar
2510
343
  mint: account.mint,
2511
344
  supplyExchangePrice: account.supplyExchangePrice,
2512
345
  borrowExchangePrice: account.borrowExchangePrice,
2513
- borrowRate: new BN$1(account.borrowRate || 0),
2514
- fee: new BN$1(account.feeOnInterest || 0),
2515
- lastStoredUtilization: new BN$1(account.lastUtilization || 0),
346
+ borrowRate: new BN(account.borrowRate || 0),
347
+ fee: new BN(account.feeOnInterest || 0),
348
+ lastStoredUtilization: new BN(account.lastUtilization || 0),
2516
349
  lastUpdateTimestamp: account.lastUpdateTimestamp,
2517
- maxUtilization: new BN$1(account.maxUtilization || 9500),
350
+ maxUtilization: new BN(account.maxUtilization || 9500),
2518
351
  supplyInterest: account.totalSupplyWithInterest,
2519
352
  supplyInterestFree: account.totalSupplyInterestFree,
2520
353
  borrowInterest: account.totalBorrowWithInterest,
@@ -2527,18 +360,18 @@ async function getLiquidityExchangePricesAndConfig(assetAddress, connection, mar
2527
360
  fee: tokenReserve.fee,
2528
361
  lastStoredUtilization: tokenReserve.lastStoredUtilization,
2529
362
  lastUpdateTimestamp: tokenReserve.lastUpdateTimestamp,
2530
- maxUtilization: tokenReserve.maxUtilization || new BN$1(9500)
363
+ maxUtilization: tokenReserve.maxUtilization || new BN(9500)
2531
364
  };
2532
365
  }
2533
366
  async function getNewExchangePrice(lending, connection, market) {
2534
367
  const { supplyExchangePrice: liquidityExchangePrice } = await getLiquidityExchangePricesAndConfig(lending.mint, connection, market);
2535
- const oldTokenExchangePrice = new BN$1(lending.tokenExchangePrice.toString());
2536
- const oldLiquidityExchangePrice = new BN$1(
368
+ const oldTokenExchangePrice = new BN(lending.tokenExchangePrice.toString());
369
+ const oldLiquidityExchangePrice = new BN(
2537
370
  lending.liquidityExchangePrice.toString()
2538
371
  );
2539
- let totalReturnPercent = new BN$1(0);
372
+ let totalReturnPercent = new BN(0);
2540
373
  const totalSupply = await getTokenTotalSupply(lending.fTokenMint, connection);
2541
- const totalAssets = oldTokenExchangePrice.mul(new BN$1(totalSupply)).div(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION);
374
+ const totalAssets = oldTokenExchangePrice.mul(new BN(totalSupply)).div(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION);
2542
375
  let rewardsRate = await getRewardsRate(
2543
376
  lending.mint,
2544
377
  totalAssets,
@@ -2546,27 +379,27 @@ async function getNewExchangePrice(lending, connection, market) {
2546
379
  market
2547
380
  );
2548
381
  if (rewardsRate.rate.gt(LENDING_CONSTANTS.MAX_REWARDS_RATE)) {
2549
- rewardsRate.rate = new BN$1(0);
382
+ rewardsRate.rate = new BN(0);
2550
383
  }
2551
- let lastUpdateTime = new BN$1(lending.lastUpdateTimestamp.toString());
384
+ let lastUpdateTime = new BN(lending.lastUpdateTimestamp.toString());
2552
385
  if (lastUpdateTime < rewardsRate.rewardsStartTime) {
2553
386
  lastUpdateTime = rewardsRate.rewardsStartTime;
2554
387
  }
2555
- totalReturnPercent = rewardsRate.rate.mul(new BN$1(Math.floor(Date.now() / 1e3)).sub(lastUpdateTime)).div(LENDING_CONSTANTS.SECONDS_PER_YEAR);
2556
- const delta = new BN$1(liquidityExchangePrice).sub(oldLiquidityExchangePrice);
388
+ totalReturnPercent = rewardsRate.rate.mul(new BN(Math.floor(Date.now() / 1e3)).sub(lastUpdateTime)).div(LENDING_CONSTANTS.SECONDS_PER_YEAR);
389
+ const delta = new BN(liquidityExchangePrice).sub(oldLiquidityExchangePrice);
2557
390
  totalReturnPercent = totalReturnPercent.add(
2558
- delta.mul(new BN$1(1e14)).div(oldLiquidityExchangePrice)
391
+ delta.mul(new BN(1e14)).div(oldLiquidityExchangePrice)
2559
392
  );
2560
393
  return oldTokenExchangePrice.add(
2561
- oldTokenExchangePrice.mul(totalReturnPercent).div(new BN$1(1e14))
394
+ oldTokenExchangePrice.mul(totalReturnPercent).div(new BN(1e14))
2562
395
  );
2563
396
  }
2564
397
  async function calculateRewardsRate(currentModel, totalAssets) {
2565
- const currentTimestamp = new BN$1(Math.floor(Date.now() / 1e3));
398
+ const currentTimestamp = new BN(Math.floor(Date.now() / 1e3));
2566
399
  const defaultResult = {
2567
- rewardsRate: new BN$1(0),
400
+ rewardsRate: new BN(0),
2568
401
  rewardsEnded: false,
2569
- rewardsStartTime: new BN$1(currentModel.startTime.toString())
402
+ rewardsStartTime: new BN(currentModel.startTime.toString())
2570
403
  };
2571
404
  if (currentModel.startTime.isZero() || currentModel.duration.isZero()) {
2572
405
  return defaultResult;
@@ -2577,21 +410,21 @@ async function calculateRewardsRate(currentModel, totalAssets) {
2577
410
  rewardsEnded: true
2578
411
  };
2579
412
  }
2580
- if (new BN$1(totalAssets).lt(currentModel.startTvl)) {
413
+ if (new BN(totalAssets).lt(currentModel.startTvl)) {
2581
414
  return defaultResult;
2582
415
  }
2583
- let rewardsRate = new BN$1(currentModel.yearlyReward.toString()).mul(new BN$1(1e4)).div(new BN$1(totalAssets.toString()));
416
+ let rewardsRate = new BN(currentModel.yearlyReward.toString()).mul(new BN(1e4)).div(new BN(totalAssets.toString()));
2584
417
  if (rewardsRate.gt(LENDING_CONSTANTS.MAX_REWARDS_RATE)) {
2585
418
  rewardsRate = LENDING_CONSTANTS.MAX_REWARDS_RATE;
2586
419
  }
2587
420
  return {
2588
421
  rewardsRate,
2589
422
  rewardsEnded: false,
2590
- rewardsStartTime: new BN$1(currentModel.startTime.toString())
423
+ rewardsStartTime: new BN(currentModel.startTime.toString())
2591
424
  };
2592
425
  }
2593
426
  async function getLendingTokenRewards(lending, connection, market) {
2594
- let rewardsRate = new BN$1(0);
427
+ let rewardsRate = new BN(0);
2595
428
  if (!lending.rewardsRateModel.equals(PublicKey.default)) {
2596
429
  try {
2597
430
  const fTokenSupply = await getTokenTotalSupply(
@@ -2653,11 +486,11 @@ async function getTokenReserveAccount(asset, connection, market) {
2653
486
  mint: account.mint,
2654
487
  supplyExchangePrice: account.supplyExchangePrice,
2655
488
  borrowExchangePrice: account.borrowExchangePrice,
2656
- borrowRate: new BN$1(account.borrowRate || 0),
2657
- fee: new BN$1(account.feeOnInterest || 0),
2658
- lastStoredUtilization: new BN$1(account.lastUtilization || 0),
489
+ borrowRate: new BN(account.borrowRate || 0),
490
+ fee: new BN(account.feeOnInterest || 0),
491
+ lastStoredUtilization: new BN(account.lastUtilization || 0),
2659
492
  lastUpdateTimestamp: account.lastUpdateTimestamp,
2660
- maxUtilization: new BN$1(account.maxUtilization || 9500),
493
+ maxUtilization: new BN(account.maxUtilization || 9500),
2661
494
  supplyInterest: account.totalSupplyWithInterest,
2662
495
  supplyInterestFree: account.totalSupplyInterestFree,
2663
496
  borrowInterest: account.totalBorrowWithInterest,
@@ -2684,7 +517,7 @@ async function getLiquidityAssetSupplyRate(asset, connection, market) {
2684
517
  getLiquidityExchangePricesAndConfig(asset, connection, market),
2685
518
  getTotalAmounts(asset, connection, market)
2686
519
  ]);
2687
- let supplyRate = new BN$1(0);
520
+ let supplyRate = new BN(0);
2688
521
  if (!totalAmounts) {
2689
522
  return supplyRate;
2690
523
  }
@@ -2694,7 +527,7 @@ async function getLiquidityAssetSupplyRate(asset, connection, market) {
2694
527
  const borrowWithInterestForRate = totalAmounts.borrowRawInterest.mul(exchangePricesAndConfig.borrowExchangePrice).div(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION);
2695
528
  const supplyWithInterestForRate = totalAmounts.supplyRawInterest.mul(exchangePricesAndConfig.supplyExchangePrice).div(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION);
2696
529
  if (!supplyWithInterestForRate.isZero()) {
2697
- supplyRate = borrowRate.mul(new BN$1(1e4).sub(fee)).mul(borrowWithInterestForRate).div(supplyWithInterestForRate.mul(new BN$1(1e4)));
530
+ supplyRate = borrowRate.mul(new BN(1e4).sub(fee)).mul(borrowWithInterestForRate).div(supplyWithInterestForRate.mul(new BN(1e4)));
2698
531
  }
2699
532
  }
2700
533
  return supplyRate;
@@ -2722,16 +555,16 @@ const getLendingTokenDetails = async ({
2722
555
  getNewExchangePrice(lendingData, connection, market),
2723
556
  getLendingTokenRewards(lendingData, connection, market)
2724
557
  ]);
2725
- const convertToShares = new BN$1(10).pow(new BN$1(lendingData.decimals)).mul(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION).divRound(exchangePrice);
2726
- const convertToAssets2 = new BN$1(10).pow(new BN$1(lendingData.decimals)).mul(exchangePrice).divRound(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION);
558
+ const convertToShares = new BN(10).pow(new BN(lendingData.decimals)).mul(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION).divRound(exchangePrice);
559
+ const convertToAssets2 = new BN(10).pow(new BN(lendingData.decimals)).mul(exchangePrice).divRound(LENDING_CONSTANTS.EXCHANGE_PRICES_PRECISION);
2727
560
  const totalAssets = calculateTotalAssets(lendingData, assetTotalSupply);
2728
561
  return {
2729
562
  id: lendingData.lendingId,
2730
563
  address: lendingData.fTokenMint,
2731
564
  asset: lendingData.mint,
2732
565
  decimals: lendingData.decimals,
2733
- totalAssets: new BN$1(totalAssets.toString()),
2734
- totalSupply: new BN$1(assetTotalSupply),
566
+ totalAssets: new BN(totalAssets.toString()),
567
+ totalSupply: new BN(assetTotalSupply),
2735
568
  convertToShares,
2736
569
  convertToAssets: convertToAssets2,
2737
570
  rewardsRate,
@@ -2752,15 +585,15 @@ const getUserLendingPositionByAsset = async ({
2752
585
  const underlyingBalance = await getTokenBalance(user, asset, connection);
2753
586
  const assets = await convertToAssets(
2754
587
  asset,
2755
- new BN$1(lendingTokenBalance.toString()),
588
+ new BN(lendingTokenBalance.toString()),
2756
589
  connection,
2757
590
  market
2758
591
  );
2759
592
  return {
2760
- lendingTokenShares: new BN$1(lendingTokenBalance.toString()),
593
+ lendingTokenShares: new BN(lendingTokenBalance.toString()),
2761
594
  underlyingAssets: assets,
2762
- underlyingBalance: new BN$1(underlyingBalance.toString())
595
+ underlyingBalance: new BN(underlyingBalance.toString())
2763
596
  };
2764
597
  };
2765
598
 
2766
- export { MAX_DEPOSIT, MAX_WITHDRAW, U64_MAX, getAccountOwner, getDepositContext, getDepositIxs, getLendingProgram, getLendingTokenDetails, getLendingTokens, getLiquidityProgramId, getMintIxs, getOrCreateATAInstruction, getRedeemIxs, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIxs };
599
+ export { getAccountOwner, getDepositContext, getDepositIxs, getLendingProgram, getLendingTokenDetails, getLendingTokens, getLiquidityProgramId, getMintIxs, getOrCreateATAInstruction, getRedeemIxs, getUserLendingPositionByAsset, getWithdrawContext, getWithdrawIxs };