@lavarage/sdk 4.5.1 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js ADDED
@@ -0,0 +1,3276 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var __async = (__this, __arguments, generator) => {
30
+ return new Promise((resolve, reject) => {
31
+ var fulfilled = (value) => {
32
+ try {
33
+ step(generator.next(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var rejected = (value) => {
39
+ try {
40
+ step(generator.throw(value));
41
+ } catch (e) {
42
+ reject(e);
43
+ }
44
+ };
45
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
46
+ step((generator = generator.apply(__this, __arguments)).next());
47
+ });
48
+ };
49
+
50
+ // index.ts
51
+ var index_exports = {};
52
+ __export(index_exports, {
53
+ IDL: () => IDL,
54
+ IDLV2: () => lavaragev2_exports,
55
+ closeTradeV1: () => closeTradeV1,
56
+ closeTradeV2: () => closeTradeV2,
57
+ createTpDelegate: () => createTpDelegate,
58
+ getAllPositions: () => getAllPositions,
59
+ getClosedPositions: () => getClosedPositions,
60
+ getLiquidatedPositions: () => getLiquidatedPositions,
61
+ getOffers: () => getOffers,
62
+ getOpenPositions: () => getOpenPositions,
63
+ getPda: () => getPda,
64
+ getPositionAccountPDA: () => getPositionAccountPDA,
65
+ modifyTpDelegate: () => modifyTpDelegate,
66
+ openTradeV1: () => openTradeV1,
67
+ openTradeV2: () => openTradeV2,
68
+ removeTpDelegate: () => removeTpDelegate
69
+ });
70
+ module.exports = __toCommonJS(index_exports);
71
+ var import_anchor = require("@coral-xyz/anchor");
72
+ var import_bs58 = __toESM(require("bs58"));
73
+ var import_web3 = require("@solana/web3.js");
74
+ var import_spl_token = require("@solana/spl-token");
75
+
76
+ // idl/lavarage.ts
77
+ var IDL = {
78
+ "version": "0.1.0",
79
+ "name": "lavarage",
80
+ "instructions": [
81
+ {
82
+ "name": "lpOperatorCreateTradingPool",
83
+ "accounts": [
84
+ {
85
+ "name": "tradingPool",
86
+ "isMut": true,
87
+ "isSigner": false
88
+ },
89
+ {
90
+ "name": "operator",
91
+ "isMut": true,
92
+ "isSigner": true
93
+ },
94
+ {
95
+ "name": "nodeWallet",
96
+ "isMut": false,
97
+ "isSigner": false
98
+ },
99
+ {
100
+ "name": "mint",
101
+ "isMut": false,
102
+ "isSigner": false
103
+ },
104
+ {
105
+ "name": "systemProgram",
106
+ "isMut": false,
107
+ "isSigner": false
108
+ }
109
+ ],
110
+ "args": [
111
+ {
112
+ "name": "interestRate",
113
+ "type": "u8"
114
+ }
115
+ ]
116
+ },
117
+ {
118
+ "name": "lpOperatorCreateNodeWallet",
119
+ "accounts": [
120
+ {
121
+ "name": "nodeWallet",
122
+ "isMut": true,
123
+ "isSigner": true
124
+ },
125
+ {
126
+ "name": "operator",
127
+ "isMut": true,
128
+ "isSigner": true
129
+ },
130
+ {
131
+ "name": "systemProgram",
132
+ "isMut": false,
133
+ "isSigner": false
134
+ }
135
+ ],
136
+ "args": []
137
+ },
138
+ {
139
+ "name": "lpOperatorFundNodeWallet",
140
+ "accounts": [
141
+ {
142
+ "name": "nodeWallet",
143
+ "isMut": true,
144
+ "isSigner": false
145
+ },
146
+ {
147
+ "name": "funder",
148
+ "isMut": true,
149
+ "isSigner": true
150
+ },
151
+ {
152
+ "name": "systemProgram",
153
+ "isMut": false,
154
+ "isSigner": false
155
+ }
156
+ ],
157
+ "args": [
158
+ {
159
+ "name": "amount",
160
+ "type": "u64"
161
+ }
162
+ ]
163
+ },
164
+ {
165
+ "name": "lpOperatorWithdrawFromNodeWallet",
166
+ "accounts": [
167
+ {
168
+ "name": "nodeWallet",
169
+ "isMut": true,
170
+ "isSigner": false
171
+ },
172
+ {
173
+ "name": "funder",
174
+ "isMut": true,
175
+ "isSigner": true
176
+ },
177
+ {
178
+ "name": "systemProgram",
179
+ "isMut": false,
180
+ "isSigner": false
181
+ }
182
+ ],
183
+ "args": [
184
+ {
185
+ "name": "amount",
186
+ "type": "u64"
187
+ }
188
+ ]
189
+ },
190
+ {
191
+ "name": "lpOperatorUpdateMaxBorrow",
192
+ "accounts": [
193
+ {
194
+ "name": "tradingPool",
195
+ "isMut": true,
196
+ "isSigner": false
197
+ },
198
+ {
199
+ "name": "nodeWallet",
200
+ "isMut": false,
201
+ "isSigner": false
202
+ },
203
+ {
204
+ "name": "operator",
205
+ "isMut": true,
206
+ "isSigner": true
207
+ },
208
+ {
209
+ "name": "systemProgram",
210
+ "isMut": false,
211
+ "isSigner": false
212
+ }
213
+ ],
214
+ "args": [
215
+ {
216
+ "name": "amount",
217
+ "type": "u64"
218
+ }
219
+ ]
220
+ },
221
+ {
222
+ "name": "lpOperatorUpdateMaxExposure",
223
+ "accounts": [
224
+ {
225
+ "name": "tradingPool",
226
+ "isMut": true,
227
+ "isSigner": false
228
+ },
229
+ {
230
+ "name": "nodeWallet",
231
+ "isMut": false,
232
+ "isSigner": false
233
+ },
234
+ {
235
+ "name": "operator",
236
+ "isMut": true,
237
+ "isSigner": true
238
+ },
239
+ {
240
+ "name": "systemProgram",
241
+ "isMut": false,
242
+ "isSigner": false
243
+ }
244
+ ],
245
+ "args": [
246
+ {
247
+ "name": "amount",
248
+ "type": "u64"
249
+ }
250
+ ]
251
+ },
252
+ {
253
+ "name": "lpOperatorUpdateInterestRate",
254
+ "accounts": [
255
+ {
256
+ "name": "tradingPool",
257
+ "isMut": true,
258
+ "isSigner": false
259
+ },
260
+ {
261
+ "name": "nodeWallet",
262
+ "isMut": false,
263
+ "isSigner": false
264
+ },
265
+ {
266
+ "name": "operator",
267
+ "isMut": true,
268
+ "isSigner": true
269
+ },
270
+ {
271
+ "name": "systemProgram",
272
+ "isMut": false,
273
+ "isSigner": false
274
+ }
275
+ ],
276
+ "args": [
277
+ {
278
+ "name": "amount",
279
+ "type": "u8"
280
+ }
281
+ ]
282
+ },
283
+ {
284
+ "name": "lpLiquidate",
285
+ "accounts": [
286
+ {
287
+ "name": "mint",
288
+ "isMut": false,
289
+ "isSigner": false
290
+ },
291
+ {
292
+ "name": "positionAccount",
293
+ "isMut": true,
294
+ "isSigner": false
295
+ },
296
+ {
297
+ "name": "trader",
298
+ "isMut": true,
299
+ "isSigner": false
300
+ },
301
+ {
302
+ "name": "tradingPool",
303
+ "isMut": true,
304
+ "isSigner": false
305
+ },
306
+ {
307
+ "name": "fromTokenAccount",
308
+ "isMut": true,
309
+ "isSigner": false
310
+ },
311
+ {
312
+ "name": "toTokenAccount",
313
+ "isMut": true,
314
+ "isSigner": false
315
+ },
316
+ {
317
+ "name": "nodeWallet",
318
+ "isMut": true,
319
+ "isSigner": false
320
+ },
321
+ {
322
+ "name": "tokenProgram",
323
+ "isMut": false,
324
+ "isSigner": false
325
+ },
326
+ {
327
+ "name": "randomAccountAsId",
328
+ "isMut": false,
329
+ "isSigner": false
330
+ },
331
+ {
332
+ "name": "clock",
333
+ "isMut": false,
334
+ "isSigner": false
335
+ },
336
+ {
337
+ "name": "operator",
338
+ "isMut": false,
339
+ "isSigner": true
340
+ },
341
+ {
342
+ "name": "oracle",
343
+ "isMut": false,
344
+ "isSigner": true
345
+ }
346
+ ],
347
+ "args": [
348
+ {
349
+ "name": "positionSize",
350
+ "type": "u64"
351
+ }
352
+ ]
353
+ },
354
+ {
355
+ "name": "lpCollectInterest",
356
+ "accounts": [
357
+ {
358
+ "name": "mint",
359
+ "isMut": false,
360
+ "isSigner": false
361
+ },
362
+ {
363
+ "name": "positionAccount",
364
+ "isMut": true,
365
+ "isSigner": false
366
+ },
367
+ {
368
+ "name": "trader",
369
+ "isMut": true,
370
+ "isSigner": false
371
+ },
372
+ {
373
+ "name": "tradingPool",
374
+ "isMut": true,
375
+ "isSigner": false
376
+ },
377
+ {
378
+ "name": "fromTokenAccount",
379
+ "isMut": true,
380
+ "isSigner": false
381
+ },
382
+ {
383
+ "name": "toTokenAccount",
384
+ "isMut": true,
385
+ "isSigner": false
386
+ },
387
+ {
388
+ "name": "nodeWallet",
389
+ "isMut": true,
390
+ "isSigner": false
391
+ },
392
+ {
393
+ "name": "tokenProgram",
394
+ "isMut": false,
395
+ "isSigner": false
396
+ },
397
+ {
398
+ "name": "randomAccountAsId",
399
+ "isMut": false,
400
+ "isSigner": false
401
+ },
402
+ {
403
+ "name": "clock",
404
+ "isMut": false,
405
+ "isSigner": false
406
+ },
407
+ {
408
+ "name": "operator",
409
+ "isMut": false,
410
+ "isSigner": true
411
+ },
412
+ {
413
+ "name": "oracle",
414
+ "isMut": false,
415
+ "isSigner": true
416
+ }
417
+ ],
418
+ "args": [
419
+ {
420
+ "name": "price",
421
+ "type": "u128"
422
+ }
423
+ ]
424
+ },
425
+ {
426
+ "name": "tradingOpenBorrow",
427
+ "accounts": [
428
+ {
429
+ "name": "positionAccount",
430
+ "isMut": true,
431
+ "isSigner": false
432
+ },
433
+ {
434
+ "name": "trader",
435
+ "isMut": true,
436
+ "isSigner": true
437
+ },
438
+ {
439
+ "name": "tradingPool",
440
+ "isMut": true,
441
+ "isSigner": false
442
+ },
443
+ {
444
+ "name": "nodeWallet",
445
+ "isMut": true,
446
+ "isSigner": false
447
+ },
448
+ {
449
+ "name": "instructions",
450
+ "isMut": false,
451
+ "isSigner": false
452
+ },
453
+ {
454
+ "name": "systemProgram",
455
+ "isMut": false,
456
+ "isSigner": false
457
+ },
458
+ {
459
+ "name": "clock",
460
+ "isMut": false,
461
+ "isSigner": false
462
+ },
463
+ {
464
+ "name": "randomAccountAsId",
465
+ "isMut": false,
466
+ "isSigner": false
467
+ },
468
+ {
469
+ "name": "feeReceipient",
470
+ "isMut": true,
471
+ "isSigner": false
472
+ }
473
+ ],
474
+ "args": [
475
+ {
476
+ "name": "positionSize",
477
+ "type": "u64"
478
+ },
479
+ {
480
+ "name": "userPays",
481
+ "type": "u64"
482
+ }
483
+ ]
484
+ },
485
+ {
486
+ "name": "tradingOpenAddCollateral",
487
+ "accounts": [
488
+ {
489
+ "name": "positionAccount",
490
+ "isMut": true,
491
+ "isSigner": false
492
+ },
493
+ {
494
+ "name": "trader",
495
+ "isMut": true,
496
+ "isSigner": true
497
+ },
498
+ {
499
+ "name": "tradingPool",
500
+ "isMut": true,
501
+ "isSigner": false
502
+ },
503
+ {
504
+ "name": "systemProgram",
505
+ "isMut": false,
506
+ "isSigner": false
507
+ },
508
+ {
509
+ "name": "mint",
510
+ "isMut": false,
511
+ "isSigner": false
512
+ },
513
+ {
514
+ "name": "toTokenAccount",
515
+ "isMut": false,
516
+ "isSigner": false
517
+ },
518
+ {
519
+ "name": "randomAccountAsId",
520
+ "isMut": false,
521
+ "isSigner": false
522
+ }
523
+ ],
524
+ "args": [
525
+ {
526
+ "name": "maxInterestRate",
527
+ "type": "u8"
528
+ }
529
+ ]
530
+ },
531
+ {
532
+ "name": "tradingCloseBorrowCollateral",
533
+ "accounts": [
534
+ {
535
+ "name": "positionAccount",
536
+ "isMut": true,
537
+ "isSigner": false
538
+ },
539
+ {
540
+ "name": "trader",
541
+ "isMut": true,
542
+ "isSigner": true
543
+ },
544
+ {
545
+ "name": "tradingPool",
546
+ "isMut": true,
547
+ "isSigner": false
548
+ },
549
+ {
550
+ "name": "instructions",
551
+ "isMut": false,
552
+ "isSigner": false
553
+ },
554
+ {
555
+ "name": "systemProgram",
556
+ "isMut": false,
557
+ "isSigner": false
558
+ },
559
+ {
560
+ "name": "mint",
561
+ "isMut": false,
562
+ "isSigner": false
563
+ },
564
+ {
565
+ "name": "fromTokenAccount",
566
+ "isMut": true,
567
+ "isSigner": false
568
+ },
569
+ {
570
+ "name": "toTokenAccount",
571
+ "isMut": true,
572
+ "isSigner": false
573
+ },
574
+ {
575
+ "name": "tokenProgram",
576
+ "isMut": false,
577
+ "isSigner": false
578
+ },
579
+ {
580
+ "name": "clock",
581
+ "isMut": false,
582
+ "isSigner": false
583
+ },
584
+ {
585
+ "name": "randomAccountAsId",
586
+ "isMut": false,
587
+ "isSigner": false
588
+ }
589
+ ],
590
+ "args": []
591
+ },
592
+ {
593
+ "name": "tradingDataAccruedInterest",
594
+ "accounts": [
595
+ {
596
+ "name": "positionAccount",
597
+ "isMut": true,
598
+ "isSigner": false
599
+ },
600
+ {
601
+ "name": "trader",
602
+ "isMut": true,
603
+ "isSigner": true
604
+ },
605
+ {
606
+ "name": "tradingPool",
607
+ "isMut": true,
608
+ "isSigner": false
609
+ },
610
+ {
611
+ "name": "nodeWallet",
612
+ "isMut": true,
613
+ "isSigner": false
614
+ },
615
+ {
616
+ "name": "systemProgram",
617
+ "isMut": false,
618
+ "isSigner": false
619
+ },
620
+ {
621
+ "name": "clock",
622
+ "isMut": false,
623
+ "isSigner": false
624
+ },
625
+ {
626
+ "name": "randomAccountAsId",
627
+ "isMut": false,
628
+ "isSigner": false
629
+ },
630
+ {
631
+ "name": "feeReceipient",
632
+ "isMut": true,
633
+ "isSigner": false
634
+ }
635
+ ],
636
+ "args": [],
637
+ "returns": "u64"
638
+ },
639
+ {
640
+ "name": "tradingCloseRepaySol",
641
+ "accounts": [
642
+ {
643
+ "name": "positionAccount",
644
+ "isMut": true,
645
+ "isSigner": false
646
+ },
647
+ {
648
+ "name": "trader",
649
+ "isMut": true,
650
+ "isSigner": true
651
+ },
652
+ {
653
+ "name": "tradingPool",
654
+ "isMut": true,
655
+ "isSigner": false
656
+ },
657
+ {
658
+ "name": "nodeWallet",
659
+ "isMut": true,
660
+ "isSigner": false
661
+ },
662
+ {
663
+ "name": "systemProgram",
664
+ "isMut": false,
665
+ "isSigner": false
666
+ },
667
+ {
668
+ "name": "clock",
669
+ "isMut": false,
670
+ "isSigner": false
671
+ },
672
+ {
673
+ "name": "randomAccountAsId",
674
+ "isMut": false,
675
+ "isSigner": false
676
+ },
677
+ {
678
+ "name": "feeReceipient",
679
+ "isMut": true,
680
+ "isSigner": false
681
+ }
682
+ ],
683
+ "args": [
684
+ {
685
+ "name": "closingPositionSize",
686
+ "type": "u64"
687
+ },
688
+ {
689
+ "name": "closeType",
690
+ "type": "u64"
691
+ }
692
+ ]
693
+ },
694
+ {
695
+ "name": "tradingClosePartialRepaySol",
696
+ "accounts": [
697
+ {
698
+ "name": "positionAccount",
699
+ "isMut": true,
700
+ "isSigner": false
701
+ },
702
+ {
703
+ "name": "trader",
704
+ "isMut": true,
705
+ "isSigner": true
706
+ },
707
+ {
708
+ "name": "tradingPool",
709
+ "isMut": true,
710
+ "isSigner": false
711
+ },
712
+ {
713
+ "name": "nodeWallet",
714
+ "isMut": true,
715
+ "isSigner": false
716
+ },
717
+ {
718
+ "name": "systemProgram",
719
+ "isMut": false,
720
+ "isSigner": false
721
+ },
722
+ {
723
+ "name": "clock",
724
+ "isMut": false,
725
+ "isSigner": false
726
+ },
727
+ {
728
+ "name": "randomAccountAsId",
729
+ "isMut": false,
730
+ "isSigner": false
731
+ },
732
+ {
733
+ "name": "feeReceipient",
734
+ "isMut": true,
735
+ "isSigner": false
736
+ }
737
+ ],
738
+ "args": [
739
+ {
740
+ "name": "repayPercentage",
741
+ "type": "u64"
742
+ }
743
+ ]
744
+ },
745
+ {
746
+ "name": "syncNodeWallet",
747
+ "accounts": [
748
+ {
749
+ "name": "nodeWallet",
750
+ "isMut": true,
751
+ "isSigner": false
752
+ },
753
+ {
754
+ "name": "funder",
755
+ "isMut": true,
756
+ "isSigner": true
757
+ },
758
+ {
759
+ "name": "systemProgram",
760
+ "isMut": false,
761
+ "isSigner": false
762
+ }
763
+ ],
764
+ "args": []
765
+ },
766
+ {
767
+ "name": "tradingCreateTpDelegate",
768
+ "accounts": [
769
+ {
770
+ "name": "delegate",
771
+ "isMut": true,
772
+ "isSigner": false
773
+ },
774
+ {
775
+ "name": "originalOperator",
776
+ "isMut": true,
777
+ "isSigner": true
778
+ },
779
+ {
780
+ "name": "delegatedAccount",
781
+ "isMut": false,
782
+ "isSigner": false
783
+ },
784
+ {
785
+ "name": "systemProgram",
786
+ "isMut": false,
787
+ "isSigner": false
788
+ }
789
+ ],
790
+ "args": [
791
+ {
792
+ "name": "price",
793
+ "type": "u64"
794
+ },
795
+ {
796
+ "name": "lowerThreshold",
797
+ "type": "u64"
798
+ },
799
+ {
800
+ "name": "delegateOperator",
801
+ "type": "publicKey"
802
+ },
803
+ {
804
+ "name": "partialPercentage",
805
+ "type": "u64"
806
+ }
807
+ ]
808
+ },
809
+ {
810
+ "name": "tradingRemoveTpDelegate",
811
+ "accounts": [
812
+ {
813
+ "name": "delegate",
814
+ "isMut": true,
815
+ "isSigner": false
816
+ },
817
+ {
818
+ "name": "originalOperator",
819
+ "isMut": true,
820
+ "isSigner": true
821
+ },
822
+ {
823
+ "name": "delegatedAccount",
824
+ "isMut": false,
825
+ "isSigner": false
826
+ },
827
+ {
828
+ "name": "systemProgram",
829
+ "isMut": false,
830
+ "isSigner": false
831
+ }
832
+ ],
833
+ "args": []
834
+ },
835
+ {
836
+ "name": "delegateExecuteTp",
837
+ "accounts": [
838
+ {
839
+ "name": "delegate",
840
+ "isMut": true,
841
+ "isSigner": false
842
+ },
843
+ {
844
+ "name": "delegateOperator",
845
+ "isMut": false,
846
+ "isSigner": true
847
+ },
848
+ {
849
+ "name": "account",
850
+ "isMut": true,
851
+ "isSigner": false
852
+ },
853
+ {
854
+ "name": "tradingPool",
855
+ "isMut": true,
856
+ "isSigner": false
857
+ },
858
+ {
859
+ "name": "tokenProgram",
860
+ "isMut": false,
861
+ "isSigner": false
862
+ },
863
+ {
864
+ "name": "positionTokenAccount",
865
+ "isMut": true,
866
+ "isSigner": false
867
+ },
868
+ {
869
+ "name": "delegateTokenAccount",
870
+ "isMut": true,
871
+ "isSigner": false
872
+ },
873
+ {
874
+ "name": "systemProgram",
875
+ "isMut": false,
876
+ "isSigner": false
877
+ }
878
+ ],
879
+ "args": [
880
+ {
881
+ "name": "seed",
882
+ "type": "publicKey"
883
+ }
884
+ ]
885
+ },
886
+ {
887
+ "name": "delegateClosePosition",
888
+ "accounts": [
889
+ {
890
+ "name": "delegate",
891
+ "isMut": true,
892
+ "isSigner": false
893
+ },
894
+ {
895
+ "name": "delegateOperator",
896
+ "isMut": false,
897
+ "isSigner": true
898
+ },
899
+ {
900
+ "name": "account",
901
+ "isMut": true,
902
+ "isSigner": false
903
+ },
904
+ {
905
+ "name": "tradingPool",
906
+ "isMut": true,
907
+ "isSigner": false
908
+ },
909
+ {
910
+ "name": "nodeWallet",
911
+ "isMut": true,
912
+ "isSigner": false
913
+ },
914
+ {
915
+ "name": "tokenProgram",
916
+ "isMut": false,
917
+ "isSigner": false
918
+ },
919
+ {
920
+ "name": "nodeWalletTokenAccount",
921
+ "isMut": true,
922
+ "isSigner": false
923
+ },
924
+ {
925
+ "name": "delegateTokenAccount",
926
+ "isMut": true,
927
+ "isSigner": false
928
+ },
929
+ {
930
+ "name": "feeTokenAccount",
931
+ "isMut": true,
932
+ "isSigner": false
933
+ },
934
+ {
935
+ "name": "profitTokenAccount",
936
+ "isMut": true,
937
+ "isSigner": false
938
+ },
939
+ {
940
+ "name": "systemProgram",
941
+ "isMut": false,
942
+ "isSigner": false
943
+ }
944
+ ],
945
+ "args": [
946
+ {
947
+ "name": "closingPositionSize",
948
+ "type": "u64"
949
+ }
950
+ ]
951
+ }
952
+ ],
953
+ "accounts": [
954
+ {
955
+ "name": "delegate",
956
+ "type": {
957
+ "kind": "struct",
958
+ "fields": [
959
+ {
960
+ "name": "delegateType",
961
+ "type": "u8"
962
+ },
963
+ {
964
+ "name": "field1",
965
+ "type": "u64"
966
+ },
967
+ {
968
+ "name": "field2",
969
+ "type": "u64"
970
+ },
971
+ {
972
+ "name": "field3",
973
+ "type": "u64"
974
+ },
975
+ {
976
+ "name": "field4",
977
+ "type": "publicKey"
978
+ },
979
+ {
980
+ "name": "field5",
981
+ "type": "publicKey"
982
+ },
983
+ {
984
+ "name": "originalOperator",
985
+ "type": "publicKey"
986
+ },
987
+ {
988
+ "name": "delegateOperator",
989
+ "type": "publicKey"
990
+ },
991
+ {
992
+ "name": "account",
993
+ "type": "publicKey"
994
+ }
995
+ ]
996
+ }
997
+ },
998
+ {
999
+ "name": "nodeWallet",
1000
+ "type": {
1001
+ "kind": "struct",
1002
+ "fields": [
1003
+ {
1004
+ "name": "totalFunds",
1005
+ "type": "u64"
1006
+ },
1007
+ {
1008
+ "name": "totalBorrowed",
1009
+ "type": "u64"
1010
+ },
1011
+ {
1012
+ "name": "maintenanceLtv",
1013
+ "type": "u8"
1014
+ },
1015
+ {
1016
+ "name": "liquidationLtv",
1017
+ "type": "u8"
1018
+ },
1019
+ {
1020
+ "name": "nodeOperator",
1021
+ "type": "publicKey"
1022
+ }
1023
+ ]
1024
+ }
1025
+ },
1026
+ {
1027
+ "name": "pool",
1028
+ "type": {
1029
+ "kind": "struct",
1030
+ "fields": [
1031
+ {
1032
+ "name": "interestRate",
1033
+ "type": "u8"
1034
+ },
1035
+ {
1036
+ "name": "collateralType",
1037
+ "type": "publicKey"
1038
+ },
1039
+ {
1040
+ "name": "maxBorrow",
1041
+ "type": "u64"
1042
+ },
1043
+ {
1044
+ "name": "nodeWallet",
1045
+ "type": "publicKey"
1046
+ },
1047
+ {
1048
+ "name": "maxExposure",
1049
+ "type": "u64"
1050
+ },
1051
+ {
1052
+ "name": "currentExposure",
1053
+ "type": "u64"
1054
+ }
1055
+ ]
1056
+ }
1057
+ },
1058
+ {
1059
+ "name": "position",
1060
+ "type": {
1061
+ "kind": "struct",
1062
+ "fields": [
1063
+ {
1064
+ "name": "pool",
1065
+ "type": "publicKey"
1066
+ },
1067
+ {
1068
+ "name": "closeStatusRecallTimestamp",
1069
+ "type": "u64"
1070
+ },
1071
+ {
1072
+ "name": "amount",
1073
+ "type": "u64"
1074
+ },
1075
+ {
1076
+ "name": "userPaid",
1077
+ "type": "u64"
1078
+ },
1079
+ {
1080
+ "name": "collateralAmount",
1081
+ "type": "u64"
1082
+ },
1083
+ {
1084
+ "name": "timestamp",
1085
+ "type": "i64"
1086
+ },
1087
+ {
1088
+ "name": "trader",
1089
+ "type": "publicKey"
1090
+ },
1091
+ {
1092
+ "name": "seed",
1093
+ "type": "publicKey"
1094
+ },
1095
+ {
1096
+ "name": "closeTimestamp",
1097
+ "type": "i64"
1098
+ },
1099
+ {
1100
+ "name": "closingPositionSize",
1101
+ "type": "u64"
1102
+ },
1103
+ {
1104
+ "name": "interestRate",
1105
+ "type": "u8"
1106
+ },
1107
+ {
1108
+ "name": "lastInterestCollect",
1109
+ "type": "i64"
1110
+ }
1111
+ ]
1112
+ }
1113
+ }
1114
+ ],
1115
+ "types": [
1116
+ {
1117
+ "name": "LendingErrors",
1118
+ "docs": [
1119
+ "Errors for this program"
1120
+ ],
1121
+ "type": {
1122
+ "kind": "enum",
1123
+ "variants": [
1124
+ {
1125
+ "name": "AddressMismatch"
1126
+ },
1127
+ {
1128
+ "name": "ProgramMismatch"
1129
+ },
1130
+ {
1131
+ "name": "MissingRepay"
1132
+ },
1133
+ {
1134
+ "name": "IncorrectOwner"
1135
+ },
1136
+ {
1137
+ "name": "IncorrectProgramAuthority"
1138
+ },
1139
+ {
1140
+ "name": "CannotBorrowBeforeRepay"
1141
+ },
1142
+ {
1143
+ "name": "UnknownInstruction"
1144
+ },
1145
+ {
1146
+ "name": "ExpectedCollateralNotEnough"
1147
+ }
1148
+ ]
1149
+ }
1150
+ },
1151
+ {
1152
+ "name": "ErrorCode",
1153
+ "type": {
1154
+ "kind": "enum",
1155
+ "variants": [
1156
+ {
1157
+ "name": "InvalidSignature"
1158
+ },
1159
+ {
1160
+ "name": "InvalidOracle"
1161
+ }
1162
+ ]
1163
+ }
1164
+ },
1165
+ {
1166
+ "name": "ErrorCode",
1167
+ "type": {
1168
+ "kind": "enum",
1169
+ "variants": [
1170
+ {
1171
+ "name": "OnlyDelegateOperator"
1172
+ },
1173
+ {
1174
+ "name": "AddressMismatch"
1175
+ },
1176
+ {
1177
+ "name": "InvalidDelegateType"
1178
+ }
1179
+ ]
1180
+ }
1181
+ },
1182
+ {
1183
+ "name": "PositionCloseType",
1184
+ "type": {
1185
+ "kind": "enum",
1186
+ "variants": [
1187
+ {
1188
+ "name": "ClosedByUser"
1189
+ },
1190
+ {
1191
+ "name": "Liquidated"
1192
+ }
1193
+ ]
1194
+ }
1195
+ }
1196
+ ],
1197
+ "events": [
1198
+ {
1199
+ "name": "PositionCloseEvent",
1200
+ "fields": [
1201
+ {
1202
+ "name": "pool",
1203
+ "type": "publicKey",
1204
+ "index": false
1205
+ },
1206
+ {
1207
+ "name": "amount",
1208
+ "type": "u64",
1209
+ "index": false
1210
+ },
1211
+ {
1212
+ "name": "userPaid",
1213
+ "type": "u64",
1214
+ "index": false
1215
+ },
1216
+ {
1217
+ "name": "collateralAmount",
1218
+ "type": "u64",
1219
+ "index": false
1220
+ },
1221
+ {
1222
+ "name": "openTimestamp",
1223
+ "type": "i64",
1224
+ "index": false
1225
+ },
1226
+ {
1227
+ "name": "trader",
1228
+ "type": "publicKey",
1229
+ "index": false
1230
+ },
1231
+ {
1232
+ "name": "closeType",
1233
+ "type": "u8",
1234
+ "index": false
1235
+ },
1236
+ {
1237
+ "name": "closeTimestamp",
1238
+ "type": "i64",
1239
+ "index": false
1240
+ },
1241
+ {
1242
+ "name": "closingPositionSize",
1243
+ "type": "u64",
1244
+ "index": false
1245
+ }
1246
+ ]
1247
+ },
1248
+ {
1249
+ "name": "PositionOpenEvent",
1250
+ "fields": [
1251
+ {
1252
+ "name": "pool",
1253
+ "type": "publicKey",
1254
+ "index": false
1255
+ },
1256
+ {
1257
+ "name": "amount",
1258
+ "type": "u64",
1259
+ "index": false
1260
+ },
1261
+ {
1262
+ "name": "userPaid",
1263
+ "type": "u64",
1264
+ "index": false
1265
+ },
1266
+ {
1267
+ "name": "collateralAmount",
1268
+ "type": "u64",
1269
+ "index": false
1270
+ },
1271
+ {
1272
+ "name": "openTimestamp",
1273
+ "type": "i64",
1274
+ "index": false
1275
+ },
1276
+ {
1277
+ "name": "trader",
1278
+ "type": "publicKey",
1279
+ "index": false
1280
+ }
1281
+ ]
1282
+ }
1283
+ ],
1284
+ "errors": [
1285
+ {
1286
+ "code": 6e3,
1287
+ "name": "AddressMismatch",
1288
+ "msg": "Address Mismatch"
1289
+ },
1290
+ {
1291
+ "code": 6001,
1292
+ "name": "ProgramMismatch",
1293
+ "msg": "Program Mismatch"
1294
+ },
1295
+ {
1296
+ "code": 6002,
1297
+ "name": "MissingRepay",
1298
+ "msg": "Missing Repay"
1299
+ },
1300
+ {
1301
+ "code": 6003,
1302
+ "name": "IncorrectOwner",
1303
+ "msg": "Incorrect Owner"
1304
+ },
1305
+ {
1306
+ "code": 6004,
1307
+ "name": "IncorrectProgramAuthority",
1308
+ "msg": "Incorrect Program Authority"
1309
+ },
1310
+ {
1311
+ "code": 6005,
1312
+ "name": "CannotBorrowBeforeRepay",
1313
+ "msg": "Cannot Borrow Before Repay"
1314
+ },
1315
+ {
1316
+ "code": 6006,
1317
+ "name": "UnknownInstruction",
1318
+ "msg": "Unknown Instruction"
1319
+ },
1320
+ {
1321
+ "code": 6007,
1322
+ "name": "ExpectedCollateralNotEnough",
1323
+ "msg": "Expected collateral not enough"
1324
+ },
1325
+ {
1326
+ "code": 6008,
1327
+ "name": "ForTesting",
1328
+ "msg": "TestError"
1329
+ }
1330
+ ]
1331
+ };
1332
+
1333
+ // idl/lavaragev2.ts
1334
+ var lavaragev2_exports = {};
1335
+ __export(lavaragev2_exports, {
1336
+ IDL: () => IDL2
1337
+ });
1338
+ var IDL2 = {
1339
+ "version": "0.1.0",
1340
+ "name": "lavarage",
1341
+ "instructions": [
1342
+ {
1343
+ "name": "lpOperatorCreateTradingPool",
1344
+ "accounts": [
1345
+ {
1346
+ "name": "tradingPool",
1347
+ "isMut": true,
1348
+ "isSigner": false
1349
+ },
1350
+ {
1351
+ "name": "operator",
1352
+ "isMut": true,
1353
+ "isSigner": true
1354
+ },
1355
+ {
1356
+ "name": "nodeWallet",
1357
+ "isMut": false,
1358
+ "isSigner": false
1359
+ },
1360
+ {
1361
+ "name": "mint",
1362
+ "isMut": false,
1363
+ "isSigner": false
1364
+ },
1365
+ {
1366
+ "name": "systemProgram",
1367
+ "isMut": false,
1368
+ "isSigner": false
1369
+ }
1370
+ ],
1371
+ "args": [
1372
+ {
1373
+ "name": "interestRate",
1374
+ "type": "u8"
1375
+ }
1376
+ ]
1377
+ },
1378
+ {
1379
+ "name": "lpOperatorCreateNodeWallet",
1380
+ "accounts": [
1381
+ {
1382
+ "name": "nodeWallet",
1383
+ "isMut": true,
1384
+ "isSigner": false
1385
+ },
1386
+ {
1387
+ "name": "operator",
1388
+ "isMut": true,
1389
+ "isSigner": true
1390
+ },
1391
+ {
1392
+ "name": "systemProgram",
1393
+ "isMut": false,
1394
+ "isSigner": false
1395
+ },
1396
+ {
1397
+ "name": "mint",
1398
+ "isMut": false,
1399
+ "isSigner": false
1400
+ }
1401
+ ],
1402
+ "args": [
1403
+ {
1404
+ "name": "liquidationLtv",
1405
+ "type": "u16"
1406
+ }
1407
+ ]
1408
+ },
1409
+ {
1410
+ "name": "lpOperatorWithdrawFromNodeWallet",
1411
+ "accounts": [
1412
+ {
1413
+ "name": "nodeWallet",
1414
+ "isMut": true,
1415
+ "isSigner": false
1416
+ },
1417
+ {
1418
+ "name": "funder",
1419
+ "isMut": true,
1420
+ "isSigner": true
1421
+ },
1422
+ {
1423
+ "name": "systemProgram",
1424
+ "isMut": false,
1425
+ "isSigner": false
1426
+ },
1427
+ {
1428
+ "name": "mint",
1429
+ "isMut": false,
1430
+ "isSigner": false
1431
+ },
1432
+ {
1433
+ "name": "fromTokenAccount",
1434
+ "isMut": true,
1435
+ "isSigner": false
1436
+ },
1437
+ {
1438
+ "name": "toTokenAccount",
1439
+ "isMut": true,
1440
+ "isSigner": false
1441
+ },
1442
+ {
1443
+ "name": "tokenProgram",
1444
+ "isMut": false,
1445
+ "isSigner": false
1446
+ }
1447
+ ],
1448
+ "args": [
1449
+ {
1450
+ "name": "amount",
1451
+ "type": "u64"
1452
+ }
1453
+ ]
1454
+ },
1455
+ {
1456
+ "name": "lpOperatorUpdateMaxBorrow",
1457
+ "accounts": [
1458
+ {
1459
+ "name": "tradingPool",
1460
+ "isMut": true,
1461
+ "isSigner": false
1462
+ },
1463
+ {
1464
+ "name": "nodeWallet",
1465
+ "isMut": false,
1466
+ "isSigner": false
1467
+ },
1468
+ {
1469
+ "name": "operator",
1470
+ "isMut": true,
1471
+ "isSigner": true
1472
+ },
1473
+ {
1474
+ "name": "systemProgram",
1475
+ "isMut": false,
1476
+ "isSigner": false
1477
+ }
1478
+ ],
1479
+ "args": [
1480
+ {
1481
+ "name": "amount",
1482
+ "type": "u64"
1483
+ }
1484
+ ]
1485
+ },
1486
+ {
1487
+ "name": "lpOperatorUpdateMaxExposure",
1488
+ "accounts": [
1489
+ {
1490
+ "name": "tradingPool",
1491
+ "isMut": true,
1492
+ "isSigner": false
1493
+ },
1494
+ {
1495
+ "name": "nodeWallet",
1496
+ "isMut": false,
1497
+ "isSigner": false
1498
+ },
1499
+ {
1500
+ "name": "operator",
1501
+ "isMut": true,
1502
+ "isSigner": true
1503
+ },
1504
+ {
1505
+ "name": "systemProgram",
1506
+ "isMut": false,
1507
+ "isSigner": false
1508
+ }
1509
+ ],
1510
+ "args": [
1511
+ {
1512
+ "name": "amount",
1513
+ "type": "u64"
1514
+ }
1515
+ ]
1516
+ },
1517
+ {
1518
+ "name": "lpOperatorUpdateInterestRate",
1519
+ "accounts": [
1520
+ {
1521
+ "name": "tradingPool",
1522
+ "isMut": true,
1523
+ "isSigner": false
1524
+ },
1525
+ {
1526
+ "name": "nodeWallet",
1527
+ "isMut": false,
1528
+ "isSigner": false
1529
+ },
1530
+ {
1531
+ "name": "operator",
1532
+ "isMut": true,
1533
+ "isSigner": true
1534
+ },
1535
+ {
1536
+ "name": "systemProgram",
1537
+ "isMut": false,
1538
+ "isSigner": false
1539
+ }
1540
+ ],
1541
+ "args": [
1542
+ {
1543
+ "name": "amount",
1544
+ "type": "u8"
1545
+ }
1546
+ ]
1547
+ },
1548
+ {
1549
+ "name": "lpLiquidate",
1550
+ "accounts": [
1551
+ {
1552
+ "name": "mint",
1553
+ "isMut": false,
1554
+ "isSigner": false
1555
+ },
1556
+ {
1557
+ "name": "positionAccount",
1558
+ "isMut": true,
1559
+ "isSigner": false
1560
+ },
1561
+ {
1562
+ "name": "trader",
1563
+ "isMut": true,
1564
+ "isSigner": false
1565
+ },
1566
+ {
1567
+ "name": "tradingPool",
1568
+ "isMut": true,
1569
+ "isSigner": false
1570
+ },
1571
+ {
1572
+ "name": "fromTokenAccount",
1573
+ "isMut": true,
1574
+ "isSigner": false
1575
+ },
1576
+ {
1577
+ "name": "toTokenAccount",
1578
+ "isMut": true,
1579
+ "isSigner": false
1580
+ },
1581
+ {
1582
+ "name": "nodeWallet",
1583
+ "isMut": true,
1584
+ "isSigner": false
1585
+ },
1586
+ {
1587
+ "name": "tokenProgram",
1588
+ "isMut": false,
1589
+ "isSigner": false
1590
+ },
1591
+ {
1592
+ "name": "randomAccountAsId",
1593
+ "isMut": false,
1594
+ "isSigner": false
1595
+ },
1596
+ {
1597
+ "name": "clock",
1598
+ "isMut": false,
1599
+ "isSigner": false
1600
+ },
1601
+ {
1602
+ "name": "operator",
1603
+ "isMut": true,
1604
+ "isSigner": true
1605
+ },
1606
+ {
1607
+ "name": "oracle",
1608
+ "isMut": false,
1609
+ "isSigner": true
1610
+ },
1611
+ {
1612
+ "name": "systemProgram",
1613
+ "isMut": false,
1614
+ "isSigner": false
1615
+ }
1616
+ ],
1617
+ "args": [
1618
+ {
1619
+ "name": "positionSize",
1620
+ "type": "u64"
1621
+ }
1622
+ ]
1623
+ },
1624
+ {
1625
+ "name": "lpCollectInterest",
1626
+ "accounts": [
1627
+ {
1628
+ "name": "mint",
1629
+ "isMut": false,
1630
+ "isSigner": false
1631
+ },
1632
+ {
1633
+ "name": "positionAccount",
1634
+ "isMut": true,
1635
+ "isSigner": false
1636
+ },
1637
+ {
1638
+ "name": "trader",
1639
+ "isMut": true,
1640
+ "isSigner": false
1641
+ },
1642
+ {
1643
+ "name": "tradingPool",
1644
+ "isMut": true,
1645
+ "isSigner": false
1646
+ },
1647
+ {
1648
+ "name": "fromTokenAccount",
1649
+ "isMut": true,
1650
+ "isSigner": false
1651
+ },
1652
+ {
1653
+ "name": "toTokenAccount",
1654
+ "isMut": true,
1655
+ "isSigner": false
1656
+ },
1657
+ {
1658
+ "name": "nodeWallet",
1659
+ "isMut": true,
1660
+ "isSigner": false
1661
+ },
1662
+ {
1663
+ "name": "tokenProgram",
1664
+ "isMut": false,
1665
+ "isSigner": false
1666
+ },
1667
+ {
1668
+ "name": "randomAccountAsId",
1669
+ "isMut": false,
1670
+ "isSigner": false
1671
+ },
1672
+ {
1673
+ "name": "clock",
1674
+ "isMut": false,
1675
+ "isSigner": false
1676
+ },
1677
+ {
1678
+ "name": "operator",
1679
+ "isMut": true,
1680
+ "isSigner": true
1681
+ },
1682
+ {
1683
+ "name": "oracle",
1684
+ "isMut": false,
1685
+ "isSigner": true
1686
+ },
1687
+ {
1688
+ "name": "systemProgram",
1689
+ "isMut": false,
1690
+ "isSigner": false
1691
+ }
1692
+ ],
1693
+ "args": [
1694
+ {
1695
+ "name": "price",
1696
+ "type": "u128"
1697
+ }
1698
+ ]
1699
+ },
1700
+ {
1701
+ "name": "tradingOpenBorrow",
1702
+ "accounts": [
1703
+ {
1704
+ "name": "positionAccount",
1705
+ "isMut": true,
1706
+ "isSigner": false
1707
+ },
1708
+ {
1709
+ "name": "trader",
1710
+ "isMut": true,
1711
+ "isSigner": true
1712
+ },
1713
+ {
1714
+ "name": "tradingPool",
1715
+ "isMut": true,
1716
+ "isSigner": false
1717
+ },
1718
+ {
1719
+ "name": "nodeWallet",
1720
+ "isMut": true,
1721
+ "isSigner": false
1722
+ },
1723
+ {
1724
+ "name": "instructions",
1725
+ "isMut": false,
1726
+ "isSigner": false
1727
+ },
1728
+ {
1729
+ "name": "systemProgram",
1730
+ "isMut": false,
1731
+ "isSigner": false
1732
+ },
1733
+ {
1734
+ "name": "clock",
1735
+ "isMut": false,
1736
+ "isSigner": false
1737
+ },
1738
+ {
1739
+ "name": "randomAccountAsId",
1740
+ "isMut": false,
1741
+ "isSigner": false
1742
+ },
1743
+ {
1744
+ "name": "feeTokenAccount",
1745
+ "isMut": true,
1746
+ "isSigner": false
1747
+ },
1748
+ {
1749
+ "name": "fromTokenAccount",
1750
+ "isMut": true,
1751
+ "isSigner": false
1752
+ },
1753
+ {
1754
+ "name": "toTokenAccount",
1755
+ "isMut": true,
1756
+ "isSigner": false
1757
+ },
1758
+ {
1759
+ "name": "tokenProgram",
1760
+ "isMut": false,
1761
+ "isSigner": false
1762
+ }
1763
+ ],
1764
+ "args": [
1765
+ {
1766
+ "name": "positionSize",
1767
+ "type": "u64"
1768
+ },
1769
+ {
1770
+ "name": "userPays",
1771
+ "type": "u64"
1772
+ }
1773
+ ]
1774
+ },
1775
+ {
1776
+ "name": "tradingOpenAddCollateral",
1777
+ "accounts": [
1778
+ {
1779
+ "name": "positionAccount",
1780
+ "isMut": true,
1781
+ "isSigner": false
1782
+ },
1783
+ {
1784
+ "name": "trader",
1785
+ "isMut": true,
1786
+ "isSigner": true
1787
+ },
1788
+ {
1789
+ "name": "tradingPool",
1790
+ "isMut": true,
1791
+ "isSigner": false
1792
+ },
1793
+ {
1794
+ "name": "systemProgram",
1795
+ "isMut": false,
1796
+ "isSigner": false
1797
+ },
1798
+ {
1799
+ "name": "mint",
1800
+ "isMut": false,
1801
+ "isSigner": false
1802
+ },
1803
+ {
1804
+ "name": "toTokenAccount",
1805
+ "isMut": false,
1806
+ "isSigner": false
1807
+ },
1808
+ {
1809
+ "name": "randomAccountAsId",
1810
+ "isMut": false,
1811
+ "isSigner": false
1812
+ }
1813
+ ],
1814
+ "args": [
1815
+ {
1816
+ "name": "maxInterestRate",
1817
+ "type": "u8"
1818
+ }
1819
+ ]
1820
+ },
1821
+ {
1822
+ "name": "tradingCloseBorrowCollateral",
1823
+ "accounts": [
1824
+ {
1825
+ "name": "positionAccount",
1826
+ "isMut": true,
1827
+ "isSigner": false
1828
+ },
1829
+ {
1830
+ "name": "trader",
1831
+ "isMut": true,
1832
+ "isSigner": true
1833
+ },
1834
+ {
1835
+ "name": "tradingPool",
1836
+ "isMut": true,
1837
+ "isSigner": false
1838
+ },
1839
+ {
1840
+ "name": "instructions",
1841
+ "isMut": false,
1842
+ "isSigner": false
1843
+ },
1844
+ {
1845
+ "name": "systemProgram",
1846
+ "isMut": false,
1847
+ "isSigner": false
1848
+ },
1849
+ {
1850
+ "name": "mint",
1851
+ "isMut": false,
1852
+ "isSigner": false
1853
+ },
1854
+ {
1855
+ "name": "fromTokenAccount",
1856
+ "isMut": true,
1857
+ "isSigner": false
1858
+ },
1859
+ {
1860
+ "name": "toTokenAccount",
1861
+ "isMut": true,
1862
+ "isSigner": false
1863
+ },
1864
+ {
1865
+ "name": "tokenProgram",
1866
+ "isMut": false,
1867
+ "isSigner": false
1868
+ },
1869
+ {
1870
+ "name": "clock",
1871
+ "isMut": false,
1872
+ "isSigner": false
1873
+ },
1874
+ {
1875
+ "name": "randomAccountAsId",
1876
+ "isMut": false,
1877
+ "isSigner": false
1878
+ }
1879
+ ],
1880
+ "args": []
1881
+ },
1882
+ {
1883
+ "name": "tradingDataAccruedInterest",
1884
+ "accounts": [
1885
+ {
1886
+ "name": "positionAccount",
1887
+ "isMut": true,
1888
+ "isSigner": false
1889
+ },
1890
+ {
1891
+ "name": "trader",
1892
+ "isMut": true,
1893
+ "isSigner": true
1894
+ },
1895
+ {
1896
+ "name": "tradingPool",
1897
+ "isMut": true,
1898
+ "isSigner": false
1899
+ },
1900
+ {
1901
+ "name": "nodeWallet",
1902
+ "isMut": true,
1903
+ "isSigner": false
1904
+ },
1905
+ {
1906
+ "name": "systemProgram",
1907
+ "isMut": false,
1908
+ "isSigner": false
1909
+ },
1910
+ {
1911
+ "name": "clock",
1912
+ "isMut": false,
1913
+ "isSigner": false
1914
+ },
1915
+ {
1916
+ "name": "randomAccountAsId",
1917
+ "isMut": false,
1918
+ "isSigner": false
1919
+ },
1920
+ {
1921
+ "name": "mint",
1922
+ "isMut": false,
1923
+ "isSigner": false
1924
+ },
1925
+ {
1926
+ "name": "fromTokenAccount",
1927
+ "isMut": true,
1928
+ "isSigner": false
1929
+ },
1930
+ {
1931
+ "name": "toTokenAccount",
1932
+ "isMut": true,
1933
+ "isSigner": false
1934
+ },
1935
+ {
1936
+ "name": "feeTokenAccount",
1937
+ "isMut": true,
1938
+ "isSigner": false
1939
+ },
1940
+ {
1941
+ "name": "tokenProgram",
1942
+ "isMut": false,
1943
+ "isSigner": false
1944
+ }
1945
+ ],
1946
+ "args": [],
1947
+ "returns": "u64"
1948
+ },
1949
+ {
1950
+ "name": "tradingCloseRepaySol",
1951
+ "accounts": [
1952
+ {
1953
+ "name": "positionAccount",
1954
+ "isMut": true,
1955
+ "isSigner": false
1956
+ },
1957
+ {
1958
+ "name": "trader",
1959
+ "isMut": true,
1960
+ "isSigner": true
1961
+ },
1962
+ {
1963
+ "name": "tradingPool",
1964
+ "isMut": true,
1965
+ "isSigner": false
1966
+ },
1967
+ {
1968
+ "name": "nodeWallet",
1969
+ "isMut": true,
1970
+ "isSigner": false
1971
+ },
1972
+ {
1973
+ "name": "systemProgram",
1974
+ "isMut": false,
1975
+ "isSigner": false
1976
+ },
1977
+ {
1978
+ "name": "clock",
1979
+ "isMut": false,
1980
+ "isSigner": false
1981
+ },
1982
+ {
1983
+ "name": "randomAccountAsId",
1984
+ "isMut": false,
1985
+ "isSigner": false
1986
+ },
1987
+ {
1988
+ "name": "mint",
1989
+ "isMut": false,
1990
+ "isSigner": false
1991
+ },
1992
+ {
1993
+ "name": "fromTokenAccount",
1994
+ "isMut": true,
1995
+ "isSigner": false
1996
+ },
1997
+ {
1998
+ "name": "toTokenAccount",
1999
+ "isMut": true,
2000
+ "isSigner": false
2001
+ },
2002
+ {
2003
+ "name": "feeTokenAccount",
2004
+ "isMut": true,
2005
+ "isSigner": false
2006
+ },
2007
+ {
2008
+ "name": "tokenProgram",
2009
+ "isMut": false,
2010
+ "isSigner": false
2011
+ }
2012
+ ],
2013
+ "args": [
2014
+ {
2015
+ "name": "closingPositionSize",
2016
+ "type": "u64"
2017
+ },
2018
+ {
2019
+ "name": "closeType",
2020
+ "type": "u64"
2021
+ }
2022
+ ]
2023
+ },
2024
+ {
2025
+ "name": "tradingPartialRepaySol",
2026
+ "accounts": [
2027
+ {
2028
+ "name": "positionAccount",
2029
+ "isMut": true,
2030
+ "isSigner": false
2031
+ },
2032
+ {
2033
+ "name": "trader",
2034
+ "isMut": true,
2035
+ "isSigner": true
2036
+ },
2037
+ {
2038
+ "name": "tradingPool",
2039
+ "isMut": true,
2040
+ "isSigner": false
2041
+ },
2042
+ {
2043
+ "name": "nodeWallet",
2044
+ "isMut": true,
2045
+ "isSigner": false
2046
+ },
2047
+ {
2048
+ "name": "systemProgram",
2049
+ "isMut": false,
2050
+ "isSigner": false
2051
+ },
2052
+ {
2053
+ "name": "clock",
2054
+ "isMut": false,
2055
+ "isSigner": false
2056
+ },
2057
+ {
2058
+ "name": "randomAccountAsId",
2059
+ "isMut": false,
2060
+ "isSigner": false
2061
+ },
2062
+ {
2063
+ "name": "mint",
2064
+ "isMut": false,
2065
+ "isSigner": false
2066
+ },
2067
+ {
2068
+ "name": "fromTokenAccount",
2069
+ "isMut": true,
2070
+ "isSigner": false
2071
+ },
2072
+ {
2073
+ "name": "toTokenAccount",
2074
+ "isMut": true,
2075
+ "isSigner": false
2076
+ },
2077
+ {
2078
+ "name": "feeTokenAccount",
2079
+ "isMut": true,
2080
+ "isSigner": false
2081
+ },
2082
+ {
2083
+ "name": "tokenProgram",
2084
+ "isMut": false,
2085
+ "isSigner": false
2086
+ }
2087
+ ],
2088
+ "args": [
2089
+ {
2090
+ "name": "percentage",
2091
+ "type": "u64"
2092
+ }
2093
+ ]
2094
+ },
2095
+ {
2096
+ "name": "tradingCreateTpDelegate",
2097
+ "accounts": [
2098
+ {
2099
+ "name": "delegate",
2100
+ "isMut": true,
2101
+ "isSigner": false
2102
+ },
2103
+ {
2104
+ "name": "originalOperator",
2105
+ "isMut": true,
2106
+ "isSigner": true
2107
+ },
2108
+ {
2109
+ "name": "delegatedAccount",
2110
+ "isMut": false,
2111
+ "isSigner": false
2112
+ },
2113
+ {
2114
+ "name": "systemProgram",
2115
+ "isMut": false,
2116
+ "isSigner": false
2117
+ }
2118
+ ],
2119
+ "args": [
2120
+ {
2121
+ "name": "price",
2122
+ "type": "u64"
2123
+ },
2124
+ {
2125
+ "name": "lowerThreshold",
2126
+ "type": "u64"
2127
+ },
2128
+ {
2129
+ "name": "delegateOperator",
2130
+ "type": "publicKey"
2131
+ },
2132
+ {
2133
+ "name": "partialPercentage",
2134
+ "type": "u64"
2135
+ }
2136
+ ]
2137
+ },
2138
+ {
2139
+ "name": "delegateExecuteTp",
2140
+ "accounts": [
2141
+ {
2142
+ "name": "delegate",
2143
+ "isMut": true,
2144
+ "isSigner": false
2145
+ },
2146
+ {
2147
+ "name": "delegateOperator",
2148
+ "isMut": false,
2149
+ "isSigner": true
2150
+ },
2151
+ {
2152
+ "name": "account",
2153
+ "isMut": true,
2154
+ "isSigner": false
2155
+ },
2156
+ {
2157
+ "name": "tradingPool",
2158
+ "isMut": true,
2159
+ "isSigner": false
2160
+ },
2161
+ {
2162
+ "name": "tokenProgram",
2163
+ "isMut": false,
2164
+ "isSigner": false
2165
+ },
2166
+ {
2167
+ "name": "positionTokenAccount",
2168
+ "isMut": true,
2169
+ "isSigner": false
2170
+ },
2171
+ {
2172
+ "name": "delegateTokenAccount",
2173
+ "isMut": true,
2174
+ "isSigner": false
2175
+ },
2176
+ {
2177
+ "name": "systemProgram",
2178
+ "isMut": false,
2179
+ "isSigner": false
2180
+ }
2181
+ ],
2182
+ "args": [
2183
+ {
2184
+ "name": "seed",
2185
+ "type": "publicKey"
2186
+ }
2187
+ ]
2188
+ },
2189
+ {
2190
+ "name": "delegateClosePosition",
2191
+ "accounts": [
2192
+ {
2193
+ "name": "delegate",
2194
+ "isMut": true,
2195
+ "isSigner": false
2196
+ },
2197
+ {
2198
+ "name": "delegateOperator",
2199
+ "isMut": false,
2200
+ "isSigner": true
2201
+ },
2202
+ {
2203
+ "name": "account",
2204
+ "isMut": true,
2205
+ "isSigner": false
2206
+ },
2207
+ {
2208
+ "name": "tradingPool",
2209
+ "isMut": true,
2210
+ "isSigner": false
2211
+ },
2212
+ {
2213
+ "name": "nodeWallet",
2214
+ "isMut": true,
2215
+ "isSigner": false
2216
+ },
2217
+ {
2218
+ "name": "tokenProgram",
2219
+ "isMut": false,
2220
+ "isSigner": false
2221
+ },
2222
+ {
2223
+ "name": "nodeWalletTokenAccount",
2224
+ "isMut": true,
2225
+ "isSigner": false
2226
+ },
2227
+ {
2228
+ "name": "delegateTokenAccount",
2229
+ "isMut": true,
2230
+ "isSigner": false
2231
+ },
2232
+ {
2233
+ "name": "feeTokenAccount",
2234
+ "isMut": true,
2235
+ "isSigner": false
2236
+ },
2237
+ {
2238
+ "name": "profitTokenAccount",
2239
+ "isMut": true,
2240
+ "isSigner": false
2241
+ },
2242
+ {
2243
+ "name": "systemProgram",
2244
+ "isMut": false,
2245
+ "isSigner": false
2246
+ }
2247
+ ],
2248
+ "args": [
2249
+ {
2250
+ "name": "closingPositionSize",
2251
+ "type": "u64"
2252
+ }
2253
+ ]
2254
+ },
2255
+ {
2256
+ "name": "tradingRemoveTpDelegate",
2257
+ "accounts": [
2258
+ {
2259
+ "name": "delegate",
2260
+ "isMut": true,
2261
+ "isSigner": false
2262
+ },
2263
+ {
2264
+ "name": "originalOperator",
2265
+ "isMut": true,
2266
+ "isSigner": true
2267
+ },
2268
+ {
2269
+ "name": "delegatedAccount",
2270
+ "isMut": false,
2271
+ "isSigner": false
2272
+ },
2273
+ {
2274
+ "name": "systemProgram",
2275
+ "isMut": false,
2276
+ "isSigner": false
2277
+ }
2278
+ ],
2279
+ "args": []
2280
+ }
2281
+ ],
2282
+ "accounts": [
2283
+ {
2284
+ "name": "delegate",
2285
+ "type": {
2286
+ "kind": "struct",
2287
+ "fields": [
2288
+ {
2289
+ "name": "delegateType",
2290
+ "type": "u8"
2291
+ },
2292
+ {
2293
+ "name": "field1",
2294
+ "type": "u64"
2295
+ },
2296
+ {
2297
+ "name": "field2",
2298
+ "type": "u64"
2299
+ },
2300
+ {
2301
+ "name": "field3",
2302
+ "type": "u64"
2303
+ },
2304
+ {
2305
+ "name": "field4",
2306
+ "type": "publicKey"
2307
+ },
2308
+ {
2309
+ "name": "field5",
2310
+ "type": "publicKey"
2311
+ },
2312
+ {
2313
+ "name": "originalOperator",
2314
+ "type": "publicKey"
2315
+ },
2316
+ {
2317
+ "name": "delegateOperator",
2318
+ "type": "publicKey"
2319
+ },
2320
+ {
2321
+ "name": "account",
2322
+ "type": "publicKey"
2323
+ }
2324
+ ]
2325
+ }
2326
+ },
2327
+ {
2328
+ "name": "nodeWallet",
2329
+ "type": {
2330
+ "kind": "struct",
2331
+ "fields": [
2332
+ {
2333
+ "name": "totalFunds",
2334
+ "type": "u64"
2335
+ },
2336
+ {
2337
+ "name": "totalBorrowed",
2338
+ "type": "u64"
2339
+ },
2340
+ {
2341
+ "name": "maintenanceLtv",
2342
+ "type": "u8"
2343
+ },
2344
+ {
2345
+ "name": "liquidationLtv",
2346
+ "type": "u16"
2347
+ },
2348
+ {
2349
+ "name": "nodeOperator",
2350
+ "type": "publicKey"
2351
+ },
2352
+ {
2353
+ "name": "mint",
2354
+ "type": "publicKey"
2355
+ }
2356
+ ]
2357
+ }
2358
+ },
2359
+ {
2360
+ "name": "pool",
2361
+ "type": {
2362
+ "kind": "struct",
2363
+ "fields": [
2364
+ {
2365
+ "name": "interestRate",
2366
+ "type": "u8"
2367
+ },
2368
+ {
2369
+ "name": "collateralType",
2370
+ "type": "publicKey"
2371
+ },
2372
+ {
2373
+ "name": "maxBorrow",
2374
+ "type": "u64"
2375
+ },
2376
+ {
2377
+ "name": "nodeWallet",
2378
+ "type": "publicKey"
2379
+ },
2380
+ {
2381
+ "name": "maxExposure",
2382
+ "type": "u64"
2383
+ },
2384
+ {
2385
+ "name": "currentExposure",
2386
+ "type": "u64"
2387
+ },
2388
+ {
2389
+ "name": "qtType",
2390
+ "type": "publicKey"
2391
+ }
2392
+ ]
2393
+ }
2394
+ },
2395
+ {
2396
+ "name": "position",
2397
+ "type": {
2398
+ "kind": "struct",
2399
+ "fields": [
2400
+ {
2401
+ "name": "pool",
2402
+ "type": "publicKey"
2403
+ },
2404
+ {
2405
+ "name": "closeStatusRecallTimestamp",
2406
+ "type": "u64"
2407
+ },
2408
+ {
2409
+ "name": "amount",
2410
+ "type": "u64"
2411
+ },
2412
+ {
2413
+ "name": "userPaid",
2414
+ "type": "u64"
2415
+ },
2416
+ {
2417
+ "name": "collateralAmount",
2418
+ "type": "u64"
2419
+ },
2420
+ {
2421
+ "name": "timestamp",
2422
+ "type": "i64"
2423
+ },
2424
+ {
2425
+ "name": "trader",
2426
+ "type": "publicKey"
2427
+ },
2428
+ {
2429
+ "name": "seed",
2430
+ "type": "publicKey"
2431
+ },
2432
+ {
2433
+ "name": "closeTimestamp",
2434
+ "type": "i64"
2435
+ },
2436
+ {
2437
+ "name": "closingPositionSize",
2438
+ "type": "u64"
2439
+ },
2440
+ {
2441
+ "name": "interestRate",
2442
+ "type": "u8"
2443
+ },
2444
+ {
2445
+ "name": "lastInterestCollect",
2446
+ "type": "i64"
2447
+ }
2448
+ ]
2449
+ }
2450
+ }
2451
+ ],
2452
+ "types": [
2453
+ {
2454
+ "name": "LendingErrors",
2455
+ "docs": [
2456
+ "Errors for this program"
2457
+ ],
2458
+ "type": {
2459
+ "kind": "enum",
2460
+ "variants": [
2461
+ {
2462
+ "name": "AddressMismatch"
2463
+ },
2464
+ {
2465
+ "name": "ProgramMismatch"
2466
+ },
2467
+ {
2468
+ "name": "MissingRepay"
2469
+ },
2470
+ {
2471
+ "name": "IncorrectOwner"
2472
+ },
2473
+ {
2474
+ "name": "IncorrectProgramAuthority"
2475
+ },
2476
+ {
2477
+ "name": "CannotBorrowBeforeRepay"
2478
+ },
2479
+ {
2480
+ "name": "UnknownInstruction"
2481
+ },
2482
+ {
2483
+ "name": "ExpectedCollateralNotEnough"
2484
+ }
2485
+ ]
2486
+ }
2487
+ },
2488
+ {
2489
+ "name": "ErrorCode",
2490
+ "type": {
2491
+ "kind": "enum",
2492
+ "variants": [
2493
+ {
2494
+ "name": "InvalidSignature"
2495
+ },
2496
+ {
2497
+ "name": "InvalidOracle"
2498
+ }
2499
+ ]
2500
+ }
2501
+ },
2502
+ {
2503
+ "name": "ErrorCode",
2504
+ "type": {
2505
+ "kind": "enum",
2506
+ "variants": [
2507
+ {
2508
+ "name": "OnlyDelegateOperator"
2509
+ },
2510
+ {
2511
+ "name": "AddressMismatch"
2512
+ },
2513
+ {
2514
+ "name": "InvalidDelegateType"
2515
+ }
2516
+ ]
2517
+ }
2518
+ },
2519
+ {
2520
+ "name": "PositionCloseType",
2521
+ "type": {
2522
+ "kind": "enum",
2523
+ "variants": [
2524
+ {
2525
+ "name": "ClosedByUser"
2526
+ },
2527
+ {
2528
+ "name": "Liquidated"
2529
+ }
2530
+ ]
2531
+ }
2532
+ }
2533
+ ],
2534
+ "events": [
2535
+ {
2536
+ "name": "PositionCloseEvent",
2537
+ "fields": [
2538
+ {
2539
+ "name": "pool",
2540
+ "type": "publicKey",
2541
+ "index": false
2542
+ },
2543
+ {
2544
+ "name": "amount",
2545
+ "type": "u64",
2546
+ "index": false
2547
+ },
2548
+ {
2549
+ "name": "userPaid",
2550
+ "type": "u64",
2551
+ "index": false
2552
+ },
2553
+ {
2554
+ "name": "collateralAmount",
2555
+ "type": "u64",
2556
+ "index": false
2557
+ },
2558
+ {
2559
+ "name": "openTimestamp",
2560
+ "type": "i64",
2561
+ "index": false
2562
+ },
2563
+ {
2564
+ "name": "trader",
2565
+ "type": "publicKey",
2566
+ "index": false
2567
+ },
2568
+ {
2569
+ "name": "closeType",
2570
+ "type": "u8",
2571
+ "index": false
2572
+ },
2573
+ {
2574
+ "name": "closeTimestamp",
2575
+ "type": "i64",
2576
+ "index": false
2577
+ },
2578
+ {
2579
+ "name": "closingPositionSize",
2580
+ "type": "u64",
2581
+ "index": false
2582
+ }
2583
+ ]
2584
+ },
2585
+ {
2586
+ "name": "PositionOpenEvent",
2587
+ "fields": [
2588
+ {
2589
+ "name": "pool",
2590
+ "type": "publicKey",
2591
+ "index": false
2592
+ },
2593
+ {
2594
+ "name": "amount",
2595
+ "type": "u64",
2596
+ "index": false
2597
+ },
2598
+ {
2599
+ "name": "userPaid",
2600
+ "type": "u64",
2601
+ "index": false
2602
+ },
2603
+ {
2604
+ "name": "collateralAmount",
2605
+ "type": "u64",
2606
+ "index": false
2607
+ },
2608
+ {
2609
+ "name": "openTimestamp",
2610
+ "type": "i64",
2611
+ "index": false
2612
+ },
2613
+ {
2614
+ "name": "trader",
2615
+ "type": "publicKey",
2616
+ "index": false
2617
+ }
2618
+ ]
2619
+ }
2620
+ ],
2621
+ "errors": [
2622
+ {
2623
+ "code": 6e3,
2624
+ "name": "AddressMismatch",
2625
+ "msg": "Address Mismatch"
2626
+ },
2627
+ {
2628
+ "code": 6001,
2629
+ "name": "ProgramMismatch",
2630
+ "msg": "Program Mismatch"
2631
+ },
2632
+ {
2633
+ "code": 6002,
2634
+ "name": "MissingRepay",
2635
+ "msg": "Missing Repay"
2636
+ },
2637
+ {
2638
+ "code": 6003,
2639
+ "name": "IncorrectOwner",
2640
+ "msg": "Incorrect Owner"
2641
+ },
2642
+ {
2643
+ "code": 6004,
2644
+ "name": "IncorrectProgramAuthority",
2645
+ "msg": "Incorrect Program Authority"
2646
+ },
2647
+ {
2648
+ "code": 6005,
2649
+ "name": "CannotBorrowBeforeRepay",
2650
+ "msg": "Cannot Borrow Before Repay"
2651
+ },
2652
+ {
2653
+ "code": 6006,
2654
+ "name": "UnknownInstruction",
2655
+ "msg": "Unknown Instruction"
2656
+ },
2657
+ {
2658
+ "code": 6007,
2659
+ "name": "ExpectedCollateralNotEnough",
2660
+ "msg": "Expected collateral not enough"
2661
+ },
2662
+ {
2663
+ "code": 6008,
2664
+ "name": "ForTesting",
2665
+ "msg": "TestError"
2666
+ }
2667
+ ]
2668
+ };
2669
+
2670
+ // index.ts
2671
+ function getPda(seed, programId) {
2672
+ const seedsBuffer = Array.isArray(seed) ? seed : [seed];
2673
+ return import_web3.PublicKey.findProgramAddressSync(seedsBuffer, programId)[0];
2674
+ }
2675
+ function getPositionAccountPDA(lavarageProgram, offer, seed) {
2676
+ return getPda([Buffer.from("position"), lavarageProgram.provider.publicKey.toBuffer(), offer.publicKey.toBuffer(), seed.toBuffer()], lavarageProgram.programId);
2677
+ }
2678
+ function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress) {
2679
+ return __async(this, null, function* () {
2680
+ const associatedTokenAddress = (0, import_spl_token.getAssociatedTokenAddressSync)(tokenAddress, ownerPublicKey, true, import_spl_token.TOKEN_PROGRAM_ID, import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID);
2681
+ try {
2682
+ const tokenAccount = yield (0, import_spl_token.getAccount)(lavarageProgram.provider.connection, associatedTokenAddress, "finalized");
2683
+ return { account: tokenAccount, instruction: null };
2684
+ } catch (error) {
2685
+ if (error instanceof import_spl_token.TokenAccountNotFoundError || error instanceof import_spl_token.TokenInvalidAccountOwnerError) {
2686
+ const instruction = (0, import_spl_token.createAssociatedTokenAccountInstruction)(
2687
+ lavarageProgram.provider.publicKey,
2688
+ associatedTokenAddress,
2689
+ ownerPublicKey,
2690
+ tokenAddress,
2691
+ import_spl_token.TOKEN_PROGRAM_ID,
2692
+ import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID
2693
+ );
2694
+ return {
2695
+ account: {
2696
+ address: associatedTokenAddress
2697
+ },
2698
+ instruction
2699
+ };
2700
+ } else {
2701
+ console.error("Error in getTokenAccountOrCreateIfNotExists: ", error);
2702
+ return { account: null, instruction: null };
2703
+ }
2704
+ }
2705
+ });
2706
+ }
2707
+ var getOffers = (lavarageProgram) => {
2708
+ return lavarageProgram.account.pool.all();
2709
+ };
2710
+ var getOpenPositions = (lavarageProgram) => {
2711
+ return lavarageProgram.account.position.all([
2712
+ { dataSize: 178 },
2713
+ {
2714
+ memcmp: {
2715
+ offset: 40,
2716
+ bytes: import_bs58.default.encode(new Uint8Array(8))
2717
+ }
2718
+ }
2719
+ ]);
2720
+ };
2721
+ var getClosedPositions = (lavarageProgram) => __async(void 0, null, function* () {
2722
+ const value = BigInt(9997);
2723
+ const valueBuffer = Buffer.alloc(8);
2724
+ valueBuffer.writeBigUInt64LE(value);
2725
+ const value2 = BigInt(9998);
2726
+ const valueBuffer2 = Buffer.alloc(8);
2727
+ valueBuffer2.writeBigUInt64LE(value2);
2728
+ const value3 = BigInt(9996);
2729
+ const valueBuffer3 = Buffer.alloc(8);
2730
+ valueBuffer3.writeBigUInt64LE(value3);
2731
+ return (yield lavarageProgram.account.position.all([
2732
+ { dataSize: 178 },
2733
+ {
2734
+ memcmp: {
2735
+ offset: 40,
2736
+ bytes: import_bs58.default.encode(Uint8Array.from(valueBuffer))
2737
+ }
2738
+ }
2739
+ ])).concat(yield lavarageProgram.account.position.all([
2740
+ { dataSize: 178 },
2741
+ {
2742
+ memcmp: {
2743
+ offset: 40,
2744
+ bytes: import_bs58.default.encode(Uint8Array.from(valueBuffer2))
2745
+ }
2746
+ }
2747
+ ])).concat(yield lavarageProgram.account.position.all([
2748
+ { dataSize: 178 },
2749
+ {
2750
+ memcmp: {
2751
+ offset: 40,
2752
+ bytes: import_bs58.default.encode(Uint8Array.from(valueBuffer3))
2753
+ }
2754
+ }
2755
+ ]));
2756
+ });
2757
+ var getLiquidatedPositions = (lavarageProgram) => {
2758
+ const value = BigInt(9999);
2759
+ const valueBuffer = Buffer.alloc(8);
2760
+ valueBuffer.writeBigUInt64LE(value);
2761
+ return lavarageProgram.account.position.all([
2762
+ { dataSize: 178 },
2763
+ {
2764
+ memcmp: {
2765
+ offset: 40,
2766
+ bytes: import_bs58.default.encode(Uint8Array.from(valueBuffer))
2767
+ }
2768
+ }
2769
+ ]);
2770
+ };
2771
+ var getAllPositions = (lavarageProgram) => {
2772
+ return lavarageProgram.account.position.all([
2773
+ { dataSize: 178 }
2774
+ ]);
2775
+ };
2776
+ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient) => __async(void 0, null, function* () {
2777
+ const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2778
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType);
2779
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType);
2780
+ const tokenAccountCreationTx = new import_web3.Transaction();
2781
+ if (fromTokenAccount.instruction) {
2782
+ tokenAccountCreationTx.add(fromTokenAccount.instruction);
2783
+ }
2784
+ if (toTokenAccount.instruction) {
2785
+ tokenAccountCreationTx.add(toTokenAccount.instruction);
2786
+ }
2787
+ const instructionsJup = jupInstruction.instructions;
2788
+ const { setupInstructions, swapInstruction: swapInstructionPayload, addressLookupTableAddresses } = instructionsJup;
2789
+ const deserializeInstruction = (instruction) => {
2790
+ return new import_web3.TransactionInstruction({
2791
+ programId: new import_web3.PublicKey(instruction.programId),
2792
+ keys: instruction.accounts.map((key) => ({
2793
+ pubkey: new import_web3.PublicKey(key.pubkey),
2794
+ isSigner: key.isSigner,
2795
+ isWritable: key.isWritable
2796
+ })),
2797
+ data: Buffer.from(instruction.data, "base64")
2798
+ });
2799
+ };
2800
+ const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
2801
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new import_web3.PublicKey(key)));
2802
+ return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
2803
+ const addressLookupTableAddress = keys[index];
2804
+ if (accountInfo) {
2805
+ const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
2806
+ key: new import_web3.PublicKey(addressLookupTableAddress),
2807
+ state: import_web3.AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
2808
+ });
2809
+ acc.push(addressLookupTableAccount);
2810
+ }
2811
+ return acc;
2812
+ }, new Array());
2813
+ });
2814
+ const addressLookupTableAccounts = [];
2815
+ addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(addressLookupTableAddresses));
2816
+ const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2817
+ const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(new import_anchor.BN((marginSOL.toNumber() * leverage).toFixed(0)), marginSOL).accountsStrict({
2818
+ nodeWallet: offer.account.nodeWallet,
2819
+ instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
2820
+ tradingPool: offer.publicKey,
2821
+ positionAccount,
2822
+ trader: lavarageProgram.provider.publicKey,
2823
+ systemProgram: import_web3.SystemProgram.programId,
2824
+ clock: import_web3.SYSVAR_CLOCK_PUBKEY,
2825
+ randomAccountAsId: randomSeed.publicKey.toBase58(),
2826
+ feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
2827
+ }).remainingAccounts(partnerFeeRecipient ? [{
2828
+ pubkey: partnerFeeRecipient,
2829
+ isSigner: false,
2830
+ isWritable: true
2831
+ }] : []).instruction();
2832
+ const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
2833
+ tradingPool: offer.publicKey,
2834
+ trader: lavarageProgram.provider.publicKey,
2835
+ mint: offer.account.collateralType,
2836
+ toTokenAccount: toTokenAccount.account.address,
2837
+ systemProgram: import_web3.SystemProgram.programId,
2838
+ positionAccount,
2839
+ randomAccountAsId: randomSeed.publicKey.toBase58()
2840
+ }).instruction();
2841
+ const jupiterIxs = [
2842
+ ...setupInstructions.map(deserializeInstruction),
2843
+ deserializeInstruction(swapInstructionPayload)
2844
+ ];
2845
+ const allInstructions = [
2846
+ fromTokenAccount.instruction,
2847
+ toTokenAccount.instruction,
2848
+ tradingOpenBorrowInstruction,
2849
+ ...jupiterIxs,
2850
+ openAddCollateralInstruction
2851
+ ].filter(Boolean);
2852
+ const messageV0 = new import_web3.TransactionMessage({
2853
+ payerKey: lavarageProgram.provider.publicKey,
2854
+ recentBlockhash: blockhash,
2855
+ instructions: allInstructions
2856
+ }).compileToV0Message(addressLookupTableAccounts);
2857
+ const tx = new import_web3.VersionedTransaction(messageV0);
2858
+ return tx;
2859
+ });
2860
+ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
2861
+ const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2862
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType);
2863
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType);
2864
+ const tokenAccountCreationTx = new import_web3.Transaction();
2865
+ if (fromTokenAccount.instruction) {
2866
+ tokenAccountCreationTx.add(fromTokenAccount.instruction);
2867
+ }
2868
+ if (toTokenAccount.instruction) {
2869
+ tokenAccountCreationTx.add(toTokenAccount.instruction);
2870
+ }
2871
+ const instructionsJup = jupInstruction.instructions;
2872
+ const { setupInstructions, swapInstruction: swapInstructionPayload, addressLookupTableAddresses } = instructionsJup;
2873
+ const deserializeInstruction = (instruction) => {
2874
+ return new import_web3.TransactionInstruction({
2875
+ programId: new import_web3.PublicKey(instruction.programId),
2876
+ keys: instruction.accounts.map((key) => ({
2877
+ pubkey: new import_web3.PublicKey(key.pubkey),
2878
+ isSigner: key.isSigner,
2879
+ isWritable: key.isWritable
2880
+ })),
2881
+ data: Buffer.from(instruction.data, "base64")
2882
+ });
2883
+ };
2884
+ const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
2885
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new import_web3.PublicKey(key)));
2886
+ return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
2887
+ const addressLookupTableAddress = keys[index];
2888
+ if (accountInfo) {
2889
+ const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
2890
+ key: new import_web3.PublicKey(addressLookupTableAddress),
2891
+ state: import_web3.AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
2892
+ });
2893
+ acc.push(addressLookupTableAccount);
2894
+ }
2895
+ return acc;
2896
+ }, new Array());
2897
+ });
2898
+ const addressLookupTableAccounts = [];
2899
+ addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(addressLookupTableAddresses));
2900
+ const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2901
+ const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(new import_anchor.BN((marginSOL.toNumber() * leverage).toFixed(0)), marginSOL).accountsStrict({
2902
+ nodeWallet: offer.account.nodeWallet,
2903
+ instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
2904
+ tradingPool: offer.publicKey,
2905
+ positionAccount,
2906
+ trader: lavarageProgram.provider.publicKey,
2907
+ systemProgram: import_web3.SystemProgram.programId,
2908
+ clock: import_web3.SYSVAR_CLOCK_PUBKEY,
2909
+ randomAccountAsId: randomSeed.publicKey.toBase58(),
2910
+ feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
2911
+ toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey),
2912
+ tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
2913
+ fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, offer.account.nodeWallet)
2914
+ }).remainingAccounts(partnerFeeRecipient ? [{
2915
+ pubkey: partnerFeeRecipient,
2916
+ isSigner: false,
2917
+ isWritable: true
2918
+ }] : []).instruction();
2919
+ const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
2920
+ tradingPool: offer.publicKey,
2921
+ trader: lavarageProgram.provider.publicKey,
2922
+ mint: offer.account.collateralType,
2923
+ toTokenAccount: toTokenAccount.account.address,
2924
+ systemProgram: import_web3.SystemProgram.programId,
2925
+ positionAccount,
2926
+ randomAccountAsId: randomSeed.publicKey.toBase58()
2927
+ }).instruction();
2928
+ const jupiterIxs = [
2929
+ ...setupInstructions.map(deserializeInstruction),
2930
+ deserializeInstruction(swapInstructionPayload)
2931
+ ];
2932
+ const allInstructions = [
2933
+ fromTokenAccount.instruction,
2934
+ toTokenAccount.instruction,
2935
+ tradingOpenBorrowInstruction,
2936
+ ...jupiterIxs,
2937
+ openAddCollateralInstruction
2938
+ ].filter(Boolean);
2939
+ const messageV0 = new import_web3.TransactionMessage({
2940
+ payerKey: lavarageProgram.provider.publicKey,
2941
+ recentBlockhash: blockhash,
2942
+ instructions: allInstructions
2943
+ }).compileToV0Message(addressLookupTableAccounts);
2944
+ const tx = new import_web3.VersionedTransaction(messageV0);
2945
+ return tx;
2946
+ });
2947
+ var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
2948
+ const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2949
+ const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(tpPrice, tpTolerence, new import_web3.PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"), new import_anchor.BN(1e4)).accountsStrict({
2950
+ delegate: getPda([Buffer.from("delegate"), position.publicKey.toBuffer()], lavarageProgram.programId),
2951
+ originalOperator: lavarageProgram.provider.publicKey,
2952
+ delegatedAccount: position.publicKey,
2953
+ systemProgram: import_web3.SystemProgram.programId
2954
+ }).remainingAccounts(partnerFeeRecipient ? [{
2955
+ pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, partnerFeeRecipient, true),
2956
+ isSigner: false,
2957
+ isWritable: true
2958
+ }] : []).instruction();
2959
+ const computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
2960
+ microLamports: prioFee.toNumber()
2961
+ });
2962
+ const messageV0 = new import_web3.TransactionMessage({
2963
+ payerKey: lavarageProgram.provider.publicKey,
2964
+ recentBlockhash: blockhash,
2965
+ instructions: [
2966
+ ix,
2967
+ computeFeeIx
2968
+ ].filter(Boolean)
2969
+ }).compileToV0Message();
2970
+ return new import_web3.VersionedTransaction(messageV0);
2971
+ });
2972
+ var modifyTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
2973
+ const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2974
+ const delegatePda = getPda([Buffer.from("delegate"), position.publicKey.toBuffer()], lavarageProgram.programId);
2975
+ const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
2976
+ delegate: delegatePda,
2977
+ originalOperator: lavarageProgram.provider.publicKey,
2978
+ delegatedAccount: position.publicKey,
2979
+ systemProgram: import_web3.SystemProgram.programId
2980
+ }).instruction();
2981
+ const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(tpPrice, tpTolerence, new import_web3.PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"), new import_anchor.BN(1e4)).accountsStrict({
2982
+ delegate: delegatePda,
2983
+ originalOperator: lavarageProgram.provider.publicKey,
2984
+ delegatedAccount: position.publicKey,
2985
+ systemProgram: import_web3.SystemProgram.programId
2986
+ }).remainingAccounts(partnerFeeRecipient ? [{
2987
+ pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, partnerFeeRecipient, true),
2988
+ isSigner: false,
2989
+ isWritable: true
2990
+ }] : []).instruction();
2991
+ const computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
2992
+ microLamports: prioFee.toNumber()
2993
+ });
2994
+ const messageV0 = new import_web3.TransactionMessage({
2995
+ payerKey: lavarageProgram.provider.publicKey,
2996
+ recentBlockhash: blockhash,
2997
+ instructions: [
2998
+ removeIx,
2999
+ ix,
3000
+ computeFeeIx
3001
+ ].filter(Boolean)
3002
+ }).compileToV0Message();
3003
+ return new import_web3.VersionedTransaction(messageV0);
3004
+ });
3005
+ var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, null, function* () {
3006
+ const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3007
+ const delegatePda = getPda([Buffer.from("delegate"), position.publicKey.toBuffer()], lavarageProgram.programId);
3008
+ const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
3009
+ delegate: delegatePda,
3010
+ originalOperator: lavarageProgram.provider.publicKey,
3011
+ delegatedAccount: position.publicKey,
3012
+ systemProgram: import_web3.SystemProgram.programId
3013
+ }).instruction();
3014
+ const computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
3015
+ microLamports: prioFee.toNumber()
3016
+ });
3017
+ const messageV0 = new import_web3.TransactionMessage({
3018
+ payerKey: lavarageProgram.provider.publicKey,
3019
+ recentBlockhash: blockhash,
3020
+ instructions: [
3021
+ removeIx,
3022
+ computeFeeIx
3023
+ ].filter(Boolean)
3024
+ }).compileToV0Message();
3025
+ return new import_web3.VersionedTransaction(messageV0);
3026
+ });
3027
+ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFeeRecipient, profitFeeMarkup) => __async(void 0, null, function* () {
3028
+ if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
3029
+ const pool = offer;
3030
+ const poolPubKey = offer.publicKey;
3031
+ const tokenAddressPubKey = new import_web3.PublicKey(offer.account.collateralType);
3032
+ const positionAccountPDA = position.publicKey;
3033
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey);
3034
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey);
3035
+ const jupiterSellIx = jupInstruction.instructions;
3036
+ const deserializeInstruction = (instruction) => {
3037
+ return new import_web3.TransactionInstruction({
3038
+ programId: new import_web3.PublicKey(instruction.programId),
3039
+ keys: instruction.accounts.map((key) => ({
3040
+ pubkey: new import_web3.PublicKey(key.pubkey),
3041
+ isSigner: key.isSigner,
3042
+ isWritable: key.isWritable
3043
+ })),
3044
+ data: Buffer.from(instruction.data, "base64")
3045
+ });
3046
+ };
3047
+ const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
3048
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new import_web3.PublicKey(key)));
3049
+ return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
3050
+ const addressLookupTableAddress = keys[index];
3051
+ if (accountInfo) {
3052
+ const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
3053
+ key: new import_web3.PublicKey(addressLookupTableAddress),
3054
+ state: import_web3.AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
3055
+ });
3056
+ acc.push(addressLookupTableAccount);
3057
+ }
3058
+ return acc;
3059
+ }, new Array());
3060
+ });
3061
+ const addressLookupTableAccounts = [];
3062
+ const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3063
+ const closePositionIx = yield lavarageProgram.methods.tradingCloseBorrowCollateral().accountsStrict({
3064
+ tradingPool: poolPubKey,
3065
+ instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
3066
+ mint: offer.account.collateralType,
3067
+ fromTokenAccount: fromTokenAccount.account.address,
3068
+ toTokenAccount: toTokenAccount.account.address,
3069
+ positionAccount: positionAccountPDA,
3070
+ clock: import_web3.SYSVAR_CLOCK_PUBKEY,
3071
+ systemProgram: import_web3.SystemProgram.programId,
3072
+ trader: lavarageProgram.provider.publicKey,
3073
+ tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
3074
+ randomAccountAsId: position.account.seed
3075
+ }).instruction();
3076
+ let repaySolIx = null;
3077
+ let jupiterIxs = [];
3078
+ if (jupInstruction.instructions == null) {
3079
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new import_anchor.BN(jupInstruction.quoteResponse.outAmount), new import_anchor.BN(9997)).accountsStrict({
3080
+ nodeWallet: pool.account.nodeWallet,
3081
+ positionAccount: positionAccountPDA,
3082
+ tradingPool: poolPubKey,
3083
+ trader: lavarageProgram.provider.publicKey,
3084
+ systemProgram: import_web3.SystemProgram.programId,
3085
+ clock: import_web3.SYSVAR_CLOCK_PUBKEY,
3086
+ randomAccountAsId: position.account.seed,
3087
+ feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
3088
+ }).remainingAccounts(partnerFeeRecipient ? [{
3089
+ pubkey: partnerFeeRecipient,
3090
+ isSigner: false,
3091
+ isWritable: true
3092
+ }] : []).instruction();
3093
+ } else {
3094
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new import_anchor.BN(jupInstruction.quoteResponse.outAmount), new import_anchor.BN(9998)).accountsStrict({
3095
+ nodeWallet: pool.account.nodeWallet,
3096
+ positionAccount: positionAccountPDA,
3097
+ tradingPool: poolPubKey,
3098
+ trader: lavarageProgram.provider.publicKey,
3099
+ systemProgram: import_web3.SystemProgram.programId,
3100
+ clock: import_web3.SYSVAR_CLOCK_PUBKEY,
3101
+ randomAccountAsId: position.account.seed,
3102
+ feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
3103
+ }).remainingAccounts(partnerFeeRecipient ? [{
3104
+ pubkey: partnerFeeRecipient,
3105
+ isSigner: false,
3106
+ isWritable: true
3107
+ }] : []).instruction();
3108
+ const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx;
3109
+ jupiterIxs = [
3110
+ ...setupInstructions.map(deserializeInstruction),
3111
+ deserializeInstruction(swapInstructionPayload),
3112
+ deserializeInstruction(cleanupInstruction)
3113
+ ];
3114
+ addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(addressLookupTableAddresses));
3115
+ }
3116
+ const profit = new import_anchor.BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3117
+ const allInstructions = [
3118
+ toTokenAccount.instruction,
3119
+ closePositionIx,
3120
+ ...jupiterIxs,
3121
+ repaySolIx,
3122
+ profitFeeMarkup && partnerFeeRecipient ? import_web3.SystemProgram.transfer(
3123
+ {
3124
+ fromPubkey: lavarageProgram.provider.publicKey,
3125
+ toPubkey: partnerFeeRecipient,
3126
+ lamports: profit.toNumber() > 0 ? profit.mul(new import_anchor.BN(profitFeeMarkup * 1e4)).div(new import_anchor.BN(1e4)).toNumber() : 0
3127
+ }
3128
+ ) : null
3129
+ ].filter((i) => !!i);
3130
+ const messageV0 = new import_web3.TransactionMessage({
3131
+ payerKey: lavarageProgram.provider.publicKey,
3132
+ recentBlockhash: blockhash,
3133
+ instructions: allInstructions
3134
+ }).compileToV0Message(addressLookupTableAccounts);
3135
+ const tx = new import_web3.VersionedTransaction(messageV0);
3136
+ return tx;
3137
+ });
3138
+ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken, partnerFeeRecipient, profitFeeMarkup) => __async(void 0, null, function* () {
3139
+ if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
3140
+ const pool = offer;
3141
+ const poolPubKey = offer.publicKey;
3142
+ const tokenAddressPubKey = new import_web3.PublicKey(offer.account.collateralType);
3143
+ const positionAccountPDA = position.publicKey;
3144
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey);
3145
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey);
3146
+ const jupiterSellIx = jupInstruction.instructions;
3147
+ const deserializeInstruction = (instruction) => {
3148
+ return new import_web3.TransactionInstruction({
3149
+ programId: new import_web3.PublicKey(instruction.programId),
3150
+ keys: instruction.accounts.map((key) => ({
3151
+ pubkey: new import_web3.PublicKey(key.pubkey),
3152
+ isSigner: key.isSigner,
3153
+ isWritable: key.isWritable
3154
+ })),
3155
+ data: Buffer.from(instruction.data, "base64")
3156
+ });
3157
+ };
3158
+ const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
3159
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new import_web3.PublicKey(key)));
3160
+ return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
3161
+ const addressLookupTableAddress = keys[index];
3162
+ if (accountInfo) {
3163
+ const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
3164
+ key: new import_web3.PublicKey(addressLookupTableAddress),
3165
+ state: import_web3.AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
3166
+ });
3167
+ acc.push(addressLookupTableAccount);
3168
+ }
3169
+ return acc;
3170
+ }, new Array());
3171
+ });
3172
+ const addressLookupTableAccounts = [];
3173
+ const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3174
+ const closePositionIx = yield lavarageProgram.methods.tradingCloseBorrowCollateral().accountsStrict({
3175
+ tradingPool: poolPubKey,
3176
+ instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
3177
+ mint: offer.account.collateralType,
3178
+ fromTokenAccount: fromTokenAccount.account.address,
3179
+ toTokenAccount: toTokenAccount.account.address,
3180
+ positionAccount: positionAccountPDA,
3181
+ clock: import_web3.SYSVAR_CLOCK_PUBKEY,
3182
+ systemProgram: import_web3.SystemProgram.programId,
3183
+ trader: lavarageProgram.provider.publicKey,
3184
+ tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
3185
+ randomAccountAsId: position.account.seed
3186
+ }).instruction();
3187
+ let repaySolIx = null;
3188
+ let jupiterIxs = [];
3189
+ if (jupInstruction.instructions == null) {
3190
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new import_anchor.BN(jupInstruction.quoteResponse.outAmount), new import_anchor.BN(9997)).accountsStrict({
3191
+ nodeWallet: pool.account.nodeWallet,
3192
+ positionAccount: positionAccountPDA,
3193
+ tradingPool: poolPubKey,
3194
+ trader: lavarageProgram.provider.publicKey,
3195
+ systemProgram: import_web3.SystemProgram.programId,
3196
+ clock: import_web3.SYSVAR_CLOCK_PUBKEY,
3197
+ randomAccountAsId: position.account.seed,
3198
+ feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
3199
+ fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey),
3200
+ tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
3201
+ toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, pool.account.nodeWallet),
3202
+ mint: quoteToken
3203
+ }).remainingAccounts(partnerFeeRecipient ? [{
3204
+ pubkey: partnerFeeRecipient,
3205
+ isSigner: false,
3206
+ isWritable: true
3207
+ }] : []).instruction();
3208
+ } else {
3209
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new import_anchor.BN(jupInstruction.quoteResponse.outAmount), new import_anchor.BN(9998)).accountsStrict({
3210
+ nodeWallet: pool.account.nodeWallet,
3211
+ positionAccount: positionAccountPDA,
3212
+ tradingPool: poolPubKey,
3213
+ trader: lavarageProgram.provider.publicKey,
3214
+ systemProgram: import_web3.SystemProgram.programId,
3215
+ clock: import_web3.SYSVAR_CLOCK_PUBKEY,
3216
+ randomAccountAsId: position.account.seed,
3217
+ feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
3218
+ fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, lavarageProgram.provider.publicKey),
3219
+ tokenProgram: import_spl_token.TOKEN_PROGRAM_ID,
3220
+ toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(quoteToken, pool.account.nodeWallet),
3221
+ mint: quoteToken
3222
+ }).remainingAccounts(partnerFeeRecipient ? [{
3223
+ pubkey: partnerFeeRecipient,
3224
+ isSigner: false,
3225
+ isWritable: true
3226
+ }] : []).instruction();
3227
+ const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx;
3228
+ jupiterIxs = [
3229
+ ...setupInstructions.map(deserializeInstruction),
3230
+ deserializeInstruction(swapInstructionPayload),
3231
+ deserializeInstruction(cleanupInstruction)
3232
+ ];
3233
+ addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(addressLookupTableAddresses));
3234
+ }
3235
+ const profit = new import_anchor.BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3236
+ const allInstructions = [
3237
+ toTokenAccount.instruction,
3238
+ closePositionIx,
3239
+ ...jupiterIxs,
3240
+ repaySolIx,
3241
+ profitFeeMarkup && partnerFeeRecipient ? import_web3.SystemProgram.transfer(
3242
+ {
3243
+ fromPubkey: lavarageProgram.provider.publicKey,
3244
+ toPubkey: partnerFeeRecipient,
3245
+ lamports: profit.toNumber() > 0 ? profit.mul(new import_anchor.BN(profitFeeMarkup * 1e3)).div(new import_anchor.BN(1e3)).toNumber() : 0
3246
+ }
3247
+ ) : null
3248
+ ].filter((i) => !!i);
3249
+ const messageV0 = new import_web3.TransactionMessage({
3250
+ payerKey: lavarageProgram.provider.publicKey,
3251
+ recentBlockhash: blockhash,
3252
+ instructions: allInstructions
3253
+ }).compileToV0Message(addressLookupTableAccounts);
3254
+ const tx = new import_web3.VersionedTransaction(messageV0);
3255
+ return tx;
3256
+ });
3257
+ // Annotate the CommonJS export names for ESM import in node:
3258
+ 0 && (module.exports = {
3259
+ IDL,
3260
+ IDLV2,
3261
+ closeTradeV1,
3262
+ closeTradeV2,
3263
+ createTpDelegate,
3264
+ getAllPositions,
3265
+ getClosedPositions,
3266
+ getLiquidatedPositions,
3267
+ getOffers,
3268
+ getOpenPositions,
3269
+ getPda,
3270
+ getPositionAccountPDA,
3271
+ modifyTpDelegate,
3272
+ openTradeV1,
3273
+ openTradeV2,
3274
+ removeTpDelegate
3275
+ });
3276
+ //# sourceMappingURL=index.js.map