@lavarage/sdk 6.4.7 → 6.5.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.mjs CHANGED
@@ -45,8 +45,26 @@ var __async = (__this, __arguments, generator) => {
45
45
  // index.ts
46
46
  import { BN } from "@coral-xyz/anchor";
47
47
  import bs58 from "bs58";
48
- import { AddressLookupTableAccount, ComputeBudgetProgram, Keypair, PublicKey, SystemProgram, SYSVAR_CLOCK_PUBKEY, SYSVAR_INSTRUCTIONS_PUBKEY, Transaction, TransactionInstruction, TransactionMessage, VersionedTransaction } from "@solana/web3.js";
49
- import { ASSOCIATED_TOKEN_PROGRAM_ID, createAssociatedTokenAccountIdempotentInstruction, createAssociatedTokenAccountInstruction, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID } from "@solana/spl-token";
48
+ import {
49
+ AddressLookupTableAccount,
50
+ ComputeBudgetProgram,
51
+ Keypair,
52
+ PublicKey,
53
+ SystemProgram,
54
+ SYSVAR_CLOCK_PUBKEY,
55
+ SYSVAR_INSTRUCTIONS_PUBKEY,
56
+ Transaction,
57
+ TransactionInstruction,
58
+ TransactionMessage,
59
+ VersionedTransaction
60
+ } from "@solana/web3.js";
61
+ import {
62
+ ASSOCIATED_TOKEN_PROGRAM_ID,
63
+ createAssociatedTokenAccountIdempotentInstruction,
64
+ createAssociatedTokenAccountInstruction,
65
+ getAssociatedTokenAddressSync,
66
+ TOKEN_PROGRAM_ID
67
+ } from "@solana/spl-token";
50
68
 
51
69
  // idl/lavarage.ts
52
70
  var IDL = {
@@ -2679,17 +2697,913 @@ var IDL2 = {
2679
2697
  ]
2680
2698
  };
2681
2699
 
2700
+ // evm.ts
2701
+ import {
2702
+ Contract,
2703
+ ZeroAddress
2704
+ } from "ethers";
2705
+
2706
+ // abi/borrowerOperations.ts
2707
+ var borrowerOperationsAbi = [
2708
+ { inputs: [], name: "InvalidInitialization", type: "error" },
2709
+ { inputs: [], name: "NotInitializing", type: "error" },
2710
+ { inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
2711
+ {
2712
+ anonymous: false,
2713
+ inputs: [
2714
+ {
2715
+ indexed: true,
2716
+ internalType: "address",
2717
+ name: "buyer",
2718
+ type: "address"
2719
+ },
2720
+ {
2721
+ indexed: true,
2722
+ internalType: "address",
2723
+ name: "tokenCollateral",
2724
+ type: "address"
2725
+ },
2726
+ {
2727
+ indexed: true,
2728
+ internalType: "uint256",
2729
+ name: "loanId",
2730
+ type: "uint256"
2731
+ },
2732
+ {
2733
+ indexed: false,
2734
+ internalType: "uint256",
2735
+ name: "openingPositionSize",
2736
+ type: "uint256"
2737
+ },
2738
+ {
2739
+ indexed: false,
2740
+ internalType: "uint256",
2741
+ name: "collateralAmount",
2742
+ type: "uint256"
2743
+ },
2744
+ {
2745
+ indexed: false,
2746
+ internalType: "uint256",
2747
+ name: "initialMargin",
2748
+ type: "uint256"
2749
+ }
2750
+ ],
2751
+ name: "Buy",
2752
+ type: "event"
2753
+ },
2754
+ {
2755
+ anonymous: false,
2756
+ inputs: [
2757
+ {
2758
+ indexed: false,
2759
+ internalType: "uint64",
2760
+ name: "version",
2761
+ type: "uint64"
2762
+ }
2763
+ ],
2764
+ name: "Initialized",
2765
+ type: "event"
2766
+ },
2767
+ {
2768
+ anonymous: false,
2769
+ inputs: [
2770
+ {
2771
+ indexed: true,
2772
+ internalType: "address",
2773
+ name: "borrower",
2774
+ type: "address"
2775
+ },
2776
+ {
2777
+ indexed: true,
2778
+ internalType: "address",
2779
+ name: "tokenCollateral",
2780
+ type: "address"
2781
+ },
2782
+ {
2783
+ indexed: true,
2784
+ internalType: "uint256",
2785
+ name: "loanId",
2786
+ type: "uint256"
2787
+ },
2788
+ {
2789
+ indexed: false,
2790
+ internalType: "uint256",
2791
+ name: "closingPositionSize",
2792
+ type: "uint256"
2793
+ },
2794
+ {
2795
+ indexed: false,
2796
+ internalType: "uint256",
2797
+ name: "liquidatorRepaidAmount",
2798
+ type: "uint256"
2799
+ }
2800
+ ],
2801
+ name: "Liquidation",
2802
+ type: "event"
2803
+ },
2804
+ {
2805
+ anonymous: false,
2806
+ inputs: [
2807
+ {
2808
+ indexed: true,
2809
+ internalType: "address",
2810
+ name: "buyer",
2811
+ type: "address"
2812
+ },
2813
+ {
2814
+ indexed: true,
2815
+ internalType: "address",
2816
+ name: "tokenCollateral",
2817
+ type: "address"
2818
+ },
2819
+ {
2820
+ indexed: true,
2821
+ internalType: "uint256",
2822
+ name: "loanId",
2823
+ type: "uint256"
2824
+ },
2825
+ {
2826
+ indexed: false,
2827
+ internalType: "uint256",
2828
+ name: "closingPositionSize",
2829
+ type: "uint256"
2830
+ },
2831
+ {
2832
+ indexed: false,
2833
+ internalType: "uint256",
2834
+ name: "profit",
2835
+ type: "uint256"
2836
+ }
2837
+ ],
2838
+ name: "Sell",
2839
+ type: "event"
2840
+ },
2841
+ {
2842
+ inputs: [],
2843
+ name: "admin",
2844
+ outputs: [{ internalType: "address", name: "", type: "address" }],
2845
+ stateMutability: "view",
2846
+ type: "function"
2847
+ },
2848
+ {
2849
+ inputs: [
2850
+ { internalType: "bytes", name: "buyingCode", type: "bytes" },
2851
+ {
2852
+ internalType: "contract IERC20",
2853
+ name: "tokenCollateral",
2854
+ type: "address"
2855
+ },
2856
+ { internalType: "uint256", name: "borrowAmount", type: "uint256" },
2857
+ {
2858
+ internalType: "contract TokenHolder",
2859
+ name: "tokenHolder",
2860
+ type: "address"
2861
+ },
2862
+ { internalType: "address", name: "inchRouter", type: "address" },
2863
+ {
2864
+ internalType: "address",
2865
+ name: "integratorFeeAddress",
2866
+ type: "address"
2867
+ }
2868
+ ],
2869
+ name: "buy",
2870
+ outputs: [],
2871
+ stateMutability: "payable",
2872
+ type: "function"
2873
+ },
2874
+ {
2875
+ inputs: [
2876
+ { internalType: "contract IERC20", name: "_weth", type: "address" }
2877
+ ],
2878
+ name: "initialize",
2879
+ outputs: [],
2880
+ stateMutability: "nonpayable",
2881
+ type: "function"
2882
+ },
2883
+ {
2884
+ inputs: [
2885
+ { internalType: "uint256", name: "loanId", type: "uint256" },
2886
+ {
2887
+ internalType: "contract TokenHolder",
2888
+ name: "tokenHolder",
2889
+ type: "address"
2890
+ },
2891
+ { internalType: "uint256", name: "closingPositionSize", type: "uint256" }
2892
+ ],
2893
+ name: "liquidate",
2894
+ outputs: [],
2895
+ stateMutability: "nonpayable",
2896
+ type: "function"
2897
+ },
2898
+ {
2899
+ inputs: [],
2900
+ name: "openingFee",
2901
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
2902
+ stateMutability: "view",
2903
+ type: "function"
2904
+ },
2905
+ {
2906
+ inputs: [],
2907
+ name: "profitFee",
2908
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
2909
+ stateMutability: "view",
2910
+ type: "function"
2911
+ },
2912
+ {
2913
+ inputs: [
2914
+ { internalType: "uint256", name: "loanId", type: "uint256" },
2915
+ { internalType: "bytes", name: "sellingCode", type: "bytes" },
2916
+ {
2917
+ internalType: "contract TokenHolder",
2918
+ name: "tokenHolder",
2919
+ type: "address"
2920
+ },
2921
+ { internalType: "address", name: "inchRouter", type: "address" },
2922
+ {
2923
+ internalType: "address",
2924
+ name: "integratorFeeAddress",
2925
+ type: "address"
2926
+ }
2927
+ ],
2928
+ name: "sell",
2929
+ outputs: [],
2930
+ stateMutability: "nonpayable",
2931
+ type: "function"
2932
+ },
2933
+ {
2934
+ inputs: [{ internalType: "address", name: "_admin", type: "address" }],
2935
+ name: "setAdmin",
2936
+ outputs: [],
2937
+ stateMutability: "nonpayable",
2938
+ type: "function"
2939
+ },
2940
+ {
2941
+ inputs: [{ internalType: "uint256", name: "_openingFee", type: "uint256" }],
2942
+ name: "setOpeningFee",
2943
+ outputs: [],
2944
+ stateMutability: "nonpayable",
2945
+ type: "function"
2946
+ },
2947
+ {
2948
+ inputs: [{ internalType: "uint256", name: "_profitFee", type: "uint256" }],
2949
+ name: "setProfitFee",
2950
+ outputs: [],
2951
+ stateMutability: "nonpayable",
2952
+ type: "function"
2953
+ }
2954
+ ];
2955
+
2956
+ // abi/tokenHolderAbi.ts
2957
+ var tokenHolderAbi = [
2958
+ { inputs: [], name: "AccessControlBadConfirmation", type: "error" },
2959
+ {
2960
+ inputs: [
2961
+ { internalType: "address", name: "account", type: "address" },
2962
+ { internalType: "bytes32", name: "neededRole", type: "bytes32" }
2963
+ ],
2964
+ name: "AccessControlUnauthorizedAccount",
2965
+ type: "error"
2966
+ },
2967
+ { inputs: [], name: "InvalidInitialization", type: "error" },
2968
+ { inputs: [], name: "NotInitializing", type: "error" },
2969
+ {
2970
+ anonymous: false,
2971
+ inputs: [
2972
+ {
2973
+ indexed: false,
2974
+ internalType: "uint64",
2975
+ name: "version",
2976
+ type: "uint64"
2977
+ }
2978
+ ],
2979
+ name: "Initialized",
2980
+ type: "event"
2981
+ },
2982
+ {
2983
+ anonymous: false,
2984
+ inputs: [
2985
+ {
2986
+ indexed: false,
2987
+ internalType: "uint256",
2988
+ name: "newInterestRate",
2989
+ type: "uint256"
2990
+ }
2991
+ ],
2992
+ name: "InterestRateSet",
2993
+ type: "event"
2994
+ },
2995
+ {
2996
+ anonymous: false,
2997
+ inputs: [
2998
+ {
2999
+ indexed: false,
3000
+ internalType: "uint256",
3001
+ name: "loanId",
3002
+ type: "uint256"
3003
+ },
3004
+ {
3005
+ indexed: false,
3006
+ internalType: "uint256",
3007
+ name: "amount",
3008
+ type: "uint256"
3009
+ },
3010
+ {
3011
+ indexed: false,
3012
+ internalType: "uint256",
3013
+ name: "timestamp",
3014
+ type: "uint256"
3015
+ },
3016
+ { indexed: false, internalType: "bool", name: "repaid", type: "bool" }
3017
+ ],
3018
+ name: "LoanCreated",
3019
+ type: "event"
3020
+ },
3021
+ {
3022
+ anonymous: false,
3023
+ inputs: [
3024
+ {
3025
+ indexed: false,
3026
+ internalType: "uint256",
3027
+ name: "loanId",
3028
+ type: "uint256"
3029
+ }
3030
+ ],
3031
+ name: "LoanRepaid",
3032
+ type: "event"
3033
+ },
3034
+ {
3035
+ anonymous: false,
3036
+ inputs: [
3037
+ {
3038
+ indexed: false,
3039
+ internalType: "address",
3040
+ name: "collateralAddress",
3041
+ type: "address"
3042
+ },
3043
+ {
3044
+ indexed: false,
3045
+ internalType: "uint256",
3046
+ name: "oldValue",
3047
+ type: "uint256"
3048
+ },
3049
+ {
3050
+ indexed: false,
3051
+ internalType: "uint256",
3052
+ name: "newValue",
3053
+ type: "uint256"
3054
+ }
3055
+ ],
3056
+ name: "MaxLendPerTokenUpdated",
3057
+ type: "event"
3058
+ },
3059
+ {
3060
+ anonymous: false,
3061
+ inputs: [
3062
+ {
3063
+ indexed: false,
3064
+ internalType: "address",
3065
+ name: "borrower",
3066
+ type: "address"
3067
+ },
3068
+ {
3069
+ indexed: false,
3070
+ internalType: "uint256",
3071
+ name: "amount",
3072
+ type: "uint256"
3073
+ }
3074
+ ],
3075
+ name: "PrivilegedLoan",
3076
+ type: "event"
3077
+ },
3078
+ {
3079
+ anonymous: false,
3080
+ inputs: [
3081
+ {
3082
+ indexed: false,
3083
+ internalType: "address",
3084
+ name: "borrower",
3085
+ type: "address"
3086
+ },
3087
+ {
3088
+ indexed: false,
3089
+ internalType: "uint256",
3090
+ name: "amount",
3091
+ type: "uint256"
3092
+ }
3093
+ ],
3094
+ name: "PrivilegedLoanRepaid",
3095
+ type: "event"
3096
+ },
3097
+ {
3098
+ anonymous: false,
3099
+ inputs: [
3100
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
3101
+ {
3102
+ indexed: true,
3103
+ internalType: "bytes32",
3104
+ name: "previousAdminRole",
3105
+ type: "bytes32"
3106
+ },
3107
+ {
3108
+ indexed: true,
3109
+ internalType: "bytes32",
3110
+ name: "newAdminRole",
3111
+ type: "bytes32"
3112
+ }
3113
+ ],
3114
+ name: "RoleAdminChanged",
3115
+ type: "event"
3116
+ },
3117
+ {
3118
+ anonymous: false,
3119
+ inputs: [
3120
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
3121
+ {
3122
+ indexed: true,
3123
+ internalType: "address",
3124
+ name: "account",
3125
+ type: "address"
3126
+ },
3127
+ {
3128
+ indexed: true,
3129
+ internalType: "address",
3130
+ name: "sender",
3131
+ type: "address"
3132
+ }
3133
+ ],
3134
+ name: "RoleGranted",
3135
+ type: "event"
3136
+ },
3137
+ {
3138
+ anonymous: false,
3139
+ inputs: [
3140
+ { indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
3141
+ {
3142
+ indexed: true,
3143
+ internalType: "address",
3144
+ name: "account",
3145
+ type: "address"
3146
+ },
3147
+ {
3148
+ indexed: true,
3149
+ internalType: "address",
3150
+ name: "sender",
3151
+ type: "address"
3152
+ }
3153
+ ],
3154
+ name: "RoleRevoked",
3155
+ type: "event"
3156
+ },
3157
+ {
3158
+ inputs: [],
3159
+ name: "BORROWER_ROUTER_ROLE",
3160
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
3161
+ stateMutability: "view",
3162
+ type: "function"
3163
+ },
3164
+ {
3165
+ inputs: [],
3166
+ name: "DEFAULT_ADMIN_ROLE",
3167
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
3168
+ stateMutability: "view",
3169
+ type: "function"
3170
+ },
3171
+ {
3172
+ inputs: [
3173
+ { internalType: "address", name: "collateralAddress", type: "address" },
3174
+ { internalType: "uint256", name: "_interestRate", type: "uint256" },
3175
+ { internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
3176
+ { internalType: "uint256", name: "minAmount", type: "uint256" }
3177
+ ],
3178
+ name: "addCollateral",
3179
+ outputs: [],
3180
+ stateMutability: "nonpayable",
3181
+ type: "function"
3182
+ },
3183
+ {
3184
+ inputs: [{ internalType: "address", name: "", type: "address" }],
3185
+ name: "collateralMapping",
3186
+ outputs: [
3187
+ { internalType: "address", name: "collateralAddress", type: "address" },
3188
+ { internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
3189
+ { internalType: "uint256", name: "interestRate", type: "uint256" },
3190
+ { internalType: "bool", name: "active", type: "bool" },
3191
+ { internalType: "uint256", name: "minAmount", type: "uint256" }
3192
+ ],
3193
+ stateMutability: "view",
3194
+ type: "function"
3195
+ },
3196
+ {
3197
+ inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
3198
+ name: "deposit",
3199
+ outputs: [],
3200
+ stateMutability: "nonpayable",
3201
+ type: "function"
3202
+ },
3203
+ {
3204
+ inputs: [],
3205
+ name: "getBalance",
3206
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3207
+ stateMutability: "view",
3208
+ type: "function"
3209
+ },
3210
+ {
3211
+ inputs: [{ internalType: "bytes32", name: "role", type: "bytes32" }],
3212
+ name: "getRoleAdmin",
3213
+ outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
3214
+ stateMutability: "view",
3215
+ type: "function"
3216
+ },
3217
+ {
3218
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
3219
+ name: "grantBorrowerRouterRole",
3220
+ outputs: [],
3221
+ stateMutability: "nonpayable",
3222
+ type: "function"
3223
+ },
3224
+ {
3225
+ inputs: [
3226
+ { internalType: "bytes32", name: "role", type: "bytes32" },
3227
+ { internalType: "address", name: "account", type: "address" }
3228
+ ],
3229
+ name: "grantRole",
3230
+ outputs: [],
3231
+ stateMutability: "nonpayable",
3232
+ type: "function"
3233
+ },
3234
+ {
3235
+ inputs: [
3236
+ { internalType: "bytes32", name: "role", type: "bytes32" },
3237
+ { internalType: "address", name: "account", type: "address" }
3238
+ ],
3239
+ name: "hasRole",
3240
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
3241
+ stateMutability: "view",
3242
+ type: "function"
3243
+ },
3244
+ {
3245
+ inputs: [
3246
+ { internalType: "address", name: "_tokenAddress", type: "address" }
3247
+ ],
3248
+ name: "initialize",
3249
+ outputs: [],
3250
+ stateMutability: "nonpayable",
3251
+ type: "function"
3252
+ },
3253
+ {
3254
+ inputs: [
3255
+ { internalType: "uint256", name: "amount", type: "uint256" },
3256
+ { internalType: "uint256", name: "collateralAmount", type: "uint256" },
3257
+ { internalType: "address", name: "collateralAddress", type: "address" },
3258
+ { internalType: "address", name: "borrower", type: "address" },
3259
+ { internalType: "uint256", name: "userPaid", type: "uint256" }
3260
+ ],
3261
+ name: "loanConfirmation",
3262
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3263
+ stateMutability: "nonpayable",
3264
+ type: "function"
3265
+ },
3266
+ {
3267
+ inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3268
+ name: "loans",
3269
+ outputs: [
3270
+ { internalType: "uint256", name: "id", type: "uint256" },
3271
+ { internalType: "uint256", name: "amount", type: "uint256" },
3272
+ {
3273
+ components: [
3274
+ {
3275
+ internalType: "address",
3276
+ name: "collateralAddress",
3277
+ type: "address"
3278
+ },
3279
+ { internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
3280
+ { internalType: "uint256", name: "interestRate", type: "uint256" },
3281
+ { internalType: "bool", name: "active", type: "bool" },
3282
+ { internalType: "uint256", name: "minAmount", type: "uint256" }
3283
+ ],
3284
+ internalType: "struct Collateral",
3285
+ name: "collateral",
3286
+ type: "tuple"
3287
+ },
3288
+ { internalType: "uint256", name: "collateralAmount", type: "uint256" },
3289
+ { internalType: "uint256", name: "timestamp", type: "uint256" },
3290
+ { internalType: "address", name: "borrower", type: "address" },
3291
+ { internalType: "uint256", name: "userPaid", type: "uint256" }
3292
+ ],
3293
+ stateMutability: "view",
3294
+ type: "function"
3295
+ },
3296
+ {
3297
+ inputs: [],
3298
+ name: "nextLoanId",
3299
+ outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
3300
+ stateMutability: "view",
3301
+ type: "function"
3302
+ },
3303
+ {
3304
+ inputs: [
3305
+ {
3306
+ internalType: "contract IERC20",
3307
+ name: "flashLoanToken",
3308
+ type: "address"
3309
+ },
3310
+ { internalType: "uint256", name: "amount", type: "uint256" }
3311
+ ],
3312
+ name: "privilegedLoan",
3313
+ outputs: [],
3314
+ stateMutability: "nonpayable",
3315
+ type: "function"
3316
+ },
3317
+ {
3318
+ inputs: [
3319
+ { internalType: "address", name: "collateralAddress", type: "address" }
3320
+ ],
3321
+ name: "removeCollateral",
3322
+ outputs: [],
3323
+ stateMutability: "nonpayable",
3324
+ type: "function"
3325
+ },
3326
+ {
3327
+ inputs: [
3328
+ { internalType: "bytes32", name: "role", type: "bytes32" },
3329
+ { internalType: "address", name: "callerConfirmation", type: "address" }
3330
+ ],
3331
+ name: "renounceRole",
3332
+ outputs: [],
3333
+ stateMutability: "nonpayable",
3334
+ type: "function"
3335
+ },
3336
+ {
3337
+ inputs: [{ internalType: "uint256", name: "loanId", type: "uint256" }],
3338
+ name: "repayLoan",
3339
+ outputs: [],
3340
+ stateMutability: "nonpayable",
3341
+ type: "function"
3342
+ },
3343
+ {
3344
+ inputs: [{ internalType: "address", name: "account", type: "address" }],
3345
+ name: "revokeBorrowerRouterRole",
3346
+ outputs: [],
3347
+ stateMutability: "nonpayable",
3348
+ type: "function"
3349
+ },
3350
+ {
3351
+ inputs: [
3352
+ { internalType: "bytes32", name: "role", type: "bytes32" },
3353
+ { internalType: "address", name: "account", type: "address" }
3354
+ ],
3355
+ name: "revokeRole",
3356
+ outputs: [],
3357
+ stateMutability: "nonpayable",
3358
+ type: "function"
3359
+ },
3360
+ {
3361
+ inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
3362
+ name: "supportsInterface",
3363
+ outputs: [{ internalType: "bool", name: "", type: "bool" }],
3364
+ stateMutability: "view",
3365
+ type: "function"
3366
+ },
3367
+ {
3368
+ inputs: [],
3369
+ name: "tokenHolded",
3370
+ outputs: [{ internalType: "contract IERC20", name: "", type: "address" }],
3371
+ stateMutability: "view",
3372
+ type: "function"
3373
+ },
3374
+ {
3375
+ inputs: [
3376
+ {
3377
+ internalType: "address[]",
3378
+ name: "collateralAddresses",
3379
+ type: "address[]"
3380
+ },
3381
+ {
3382
+ internalType: "uint256[]",
3383
+ name: "newMaxLendPerTokens",
3384
+ type: "uint256[]"
3385
+ }
3386
+ ],
3387
+ name: "updateMaxLendPerTokenBulk",
3388
+ outputs: [],
3389
+ stateMutability: "nonpayable",
3390
+ type: "function"
3391
+ },
3392
+ {
3393
+ inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
3394
+ name: "withdraw",
3395
+ outputs: [],
3396
+ stateMutability: "nonpayable",
3397
+ type: "function"
3398
+ }
3399
+ ];
3400
+
3401
+ // evm.ts
3402
+ var openPositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (signer, borrowerOpsContractAddress, {
3403
+ buyingCode,
3404
+ tokenCollateral,
3405
+ borrowAmount,
3406
+ tokenHolder,
3407
+ inchRouter,
3408
+ integratorFeeAddress = ZeroAddress,
3409
+ buyerContribution
3410
+ }) {
3411
+ const contract = new Contract(
3412
+ borrowerOpsContractAddress,
3413
+ borrowerOperationsAbi,
3414
+ signer
3415
+ );
3416
+ return contract.buy(
3417
+ buyingCode,
3418
+ tokenCollateral,
3419
+ borrowAmount,
3420
+ tokenHolder,
3421
+ inchRouter,
3422
+ integratorFeeAddress,
3423
+ { value: buyerContribution }
3424
+ );
3425
+ });
3426
+ var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (signer, borrowerOpsContractAddress, {
3427
+ loanId,
3428
+ sellingCode,
3429
+ tokenHolder,
3430
+ inchRouter,
3431
+ integratorFeeAddress = ZeroAddress
3432
+ }) {
3433
+ const contract = new Contract(
3434
+ borrowerOpsContractAddress,
3435
+ borrowerOperationsAbi,
3436
+ signer
3437
+ );
3438
+ return contract.sell(
3439
+ loanId,
3440
+ sellingCode,
3441
+ tokenHolder,
3442
+ inchRouter,
3443
+ integratorFeeAddress
3444
+ );
3445
+ });
3446
+ function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
3447
+ return __async(this, null, function* () {
3448
+ const contract = new Contract(
3449
+ borrowerOpsContractAddress,
3450
+ borrowerOperationsAbi,
3451
+ provider
3452
+ );
3453
+ const filter = contract.filters.Buy();
3454
+ const events = yield contract.queryFilter(filter, fromBlock);
3455
+ return events.map((event) => {
3456
+ const {
3457
+ trader,
3458
+ tokenCollateral,
3459
+ loanId,
3460
+ openingPositionSize,
3461
+ collateralAmount,
3462
+ initialMargin
3463
+ } = event.args;
3464
+ return {
3465
+ trader,
3466
+ tokenCollateral,
3467
+ loanId,
3468
+ openingPositionSize,
3469
+ collateralAmount,
3470
+ initialMargin
3471
+ };
3472
+ });
3473
+ });
3474
+ }
3475
+ function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
3476
+ return __async(this, null, function* () {
3477
+ const contract = new Contract(
3478
+ borrowerOpsContractAddress,
3479
+ borrowerOperationsAbi,
3480
+ provider
3481
+ );
3482
+ const filter = contract.filters.Sell();
3483
+ const events = yield contract.queryFilter(filter, fromBlock);
3484
+ return events.map((event) => {
3485
+ const { trader, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
3486
+ return {
3487
+ trader,
3488
+ tokenCollateral,
3489
+ loanId,
3490
+ closingPositionSize,
3491
+ profit
3492
+ };
3493
+ });
3494
+ });
3495
+ }
3496
+ function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
3497
+ return __async(this, null, function* () {
3498
+ const contract = new Contract(
3499
+ borrowerOpsContractAddress,
3500
+ borrowerOperationsAbi,
3501
+ provider
3502
+ );
3503
+ const filter = contract.filters.Liquidation();
3504
+ const events = yield contract.queryFilter(filter, fromBlock);
3505
+ return events.map((event) => {
3506
+ const {
3507
+ trader,
3508
+ tokenCollateral,
3509
+ loanId,
3510
+ closingPositionSize,
3511
+ liquidatorRepaidAmount
3512
+ } = event.args;
3513
+ return {
3514
+ trader,
3515
+ tokenCollateral,
3516
+ loanId,
3517
+ closingPositionSize,
3518
+ liquidatorRepaidAmount
3519
+ };
3520
+ });
3521
+ });
3522
+ }
3523
+ function getLoanEvm(provider, tokenHolderContractAddress, loanId) {
3524
+ return __async(this, null, function* () {
3525
+ const contract = new Contract(
3526
+ tokenHolderContractAddress,
3527
+ tokenHolderAbi,
3528
+ provider
3529
+ );
3530
+ return contract.loans(loanId);
3531
+ });
3532
+ }
3533
+ function getUserLoansEvm(provider, tokenHolderContractAddress, userAddress) {
3534
+ return __async(this, null, function* () {
3535
+ const contract = new Contract(
3536
+ tokenHolderContractAddress,
3537
+ tokenHolderAbi,
3538
+ provider
3539
+ );
3540
+ const nextLoanId = yield contract.nextLoanId();
3541
+ const userLoans = [];
3542
+ for (let i = 0; i < nextLoanId; i++) {
3543
+ const loan = yield contract.loans(i);
3544
+ if (loan.borrower.toLowerCase() === userAddress.toLowerCase()) {
3545
+ userLoans.push(loan);
3546
+ }
3547
+ }
3548
+ return userLoans;
3549
+ });
3550
+ }
3551
+ function getCollateralInfoEvm(provider, tokenHolderContractAddress, collateralAddress) {
3552
+ return __async(this, null, function* () {
3553
+ const contract = new Contract(
3554
+ tokenHolderContractAddress,
3555
+ tokenHolderAbi,
3556
+ provider
3557
+ );
3558
+ return contract.collateralMapping(collateralAddress);
3559
+ });
3560
+ }
3561
+ function getOffersEvm(provider, tokenHolderContractAddress, collateralAddresses) {
3562
+ return __async(this, null, function* () {
3563
+ const contract = new Contract(
3564
+ tokenHolderContractAddress,
3565
+ tokenHolderAbi,
3566
+ provider
3567
+ );
3568
+ const activeCollaterals = [];
3569
+ for (const address of collateralAddresses) {
3570
+ const collateral = yield contract.collateralMapping(address);
3571
+ if (collateral.active) {
3572
+ activeCollaterals.push({
3573
+ address,
3574
+ collateral
3575
+ });
3576
+ }
3577
+ }
3578
+ return activeCollaterals;
3579
+ });
3580
+ }
3581
+
2682
3582
  // index.ts
2683
3583
  function getPda(seed, programId) {
2684
3584
  const seedsBuffer = Array.isArray(seed) ? seed : [seed];
2685
3585
  return PublicKey.findProgramAddressSync(seedsBuffer, programId)[0];
2686
3586
  }
2687
3587
  function getPositionAccountPDA(lavarageProgram, offer, seed) {
2688
- return getPda([Buffer.from("position"), lavarageProgram.provider.publicKey.toBuffer(), offer.publicKey.toBuffer(), seed.toBuffer()], lavarageProgram.programId);
3588
+ return getPda(
3589
+ [
3590
+ Buffer.from("position"),
3591
+ lavarageProgram.provider.publicKey.toBuffer(),
3592
+ offer.publicKey.toBuffer(),
3593
+ seed.toBuffer()
3594
+ ],
3595
+ lavarageProgram.programId
3596
+ );
2689
3597
  }
2690
3598
  function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress, tokenProgram) {
2691
3599
  return __async(this, null, function* () {
2692
- const associatedTokenAddress = getAssociatedTokenAddressSync(tokenAddress, ownerPublicKey, true, tokenProgram, ASSOCIATED_TOKEN_PROGRAM_ID);
3600
+ const associatedTokenAddress = getAssociatedTokenAddressSync(
3601
+ tokenAddress,
3602
+ ownerPublicKey,
3603
+ true,
3604
+ tokenProgram,
3605
+ ASSOCIATED_TOKEN_PROGRAM_ID
3606
+ );
2693
3607
  const instruction = createAssociatedTokenAccountIdempotentInstruction(
2694
3608
  lavarageProgram.provider.publicKey,
2695
3609
  associatedTokenAddress,
@@ -2738,23 +3652,27 @@ var getClosedPositions = (lavarageProgram) => __async(void 0, null, function* ()
2738
3652
  bytes: bs58.encode(Uint8Array.from(valueBuffer))
2739
3653
  }
2740
3654
  }
2741
- ])).concat(yield lavarageProgram.account.position.all([
2742
- { dataSize: 178 },
2743
- {
2744
- memcmp: {
2745
- offset: 40,
2746
- bytes: bs58.encode(Uint8Array.from(valueBuffer2))
3655
+ ])).concat(
3656
+ yield lavarageProgram.account.position.all([
3657
+ { dataSize: 178 },
3658
+ {
3659
+ memcmp: {
3660
+ offset: 40,
3661
+ bytes: bs58.encode(Uint8Array.from(valueBuffer2))
3662
+ }
2747
3663
  }
2748
- }
2749
- ])).concat(yield lavarageProgram.account.position.all([
2750
- { dataSize: 178 },
2751
- {
2752
- memcmp: {
2753
- offset: 40,
2754
- bytes: bs58.encode(Uint8Array.from(valueBuffer3))
3664
+ ])
3665
+ ).concat(
3666
+ yield lavarageProgram.account.position.all([
3667
+ { dataSize: 178 },
3668
+ {
3669
+ memcmp: {
3670
+ offset: 40,
3671
+ bytes: bs58.encode(Uint8Array.from(valueBuffer3))
3672
+ }
2755
3673
  }
2756
- }
2757
- ]));
3674
+ ])
3675
+ );
2758
3676
  });
2759
3677
  var getLiquidatedPositions = (lavarageProgram) => {
2760
3678
  const value = BigInt(9999);
@@ -2771,9 +3689,7 @@ var getLiquidatedPositions = (lavarageProgram) => {
2771
3689
  ]);
2772
3690
  };
2773
3691
  var getAllPositions = (lavarageProgram) => {
2774
- return lavarageProgram.account.position.all([
2775
- { dataSize: 178 }
2776
- ]);
3692
+ return lavarageProgram.account.position.all([{ dataSize: 178 }]);
2777
3693
  };
2778
3694
  var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
2779
3695
  let partnerFeeMarkupAsPkey;
@@ -2784,11 +3700,27 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2784
3700
  feeBuffer32.set(feeBuffer, 0);
2785
3701
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
2786
3702
  }
2787
- const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2788
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
3703
+ const positionAccount = getPositionAccountPDA(
3704
+ lavarageProgram,
3705
+ offer,
3706
+ randomSeed.publicKey
3707
+ );
3708
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
3709
+ offer.account.collateralType
3710
+ );
2789
3711
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2790
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType, tokenProgram);
2791
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType, tokenProgram);
3712
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3713
+ lavarageProgram,
3714
+ lavarageProgram.provider.publicKey,
3715
+ offer.account.collateralType,
3716
+ tokenProgram
3717
+ );
3718
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3719
+ lavarageProgram,
3720
+ positionAccount,
3721
+ offer.account.collateralType,
3722
+ tokenProgram
3723
+ );
2792
3724
  const tokenAccountCreationTx = new Transaction();
2793
3725
  if (fromTokenAccount.instruction) {
2794
3726
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2797,7 +3729,11 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2797
3729
  tokenAccountCreationTx.add(toTokenAccount.instruction);
2798
3730
  }
2799
3731
  const instructionsJup = jupInstruction.instructions;
2800
- const { setupInstructions, swapInstruction: swapInstructionPayload, addressLookupTableAddresses } = instructionsJup;
3732
+ const {
3733
+ setupInstructions,
3734
+ swapInstruction: swapInstructionPayload,
3735
+ addressLookupTableAddresses
3736
+ } = instructionsJup;
2801
3737
  const deserializeInstruction = (instruction) => {
2802
3738
  return new TransactionInstruction({
2803
3739
  programId: new PublicKey(instruction.programId),
@@ -2810,13 +3746,17 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2810
3746
  });
2811
3747
  };
2812
3748
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
2813
- const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new PublicKey(key)));
3749
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
3750
+ keys.map((key) => new PublicKey(key))
3751
+ );
2814
3752
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
2815
3753
  const addressLookupTableAddress = keys[index];
2816
3754
  if (accountInfo) {
2817
3755
  const addressLookupTableAccount = new AddressLookupTableAccount({
2818
3756
  key: new PublicKey(addressLookupTableAddress),
2819
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
3757
+ state: AddressLookupTableAccount.deserialize(
3758
+ Uint8Array.from(accountInfo.data)
3759
+ )
2820
3760
  });
2821
3761
  acc.push(addressLookupTableAccount);
2822
3762
  }
@@ -2824,9 +3764,17 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2824
3764
  }, new Array());
2825
3765
  });
2826
3766
  const addressLookupTableAccounts = [];
2827
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(["5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi", ...addressLookupTableAddresses]));
3767
+ addressLookupTableAccounts.push(
3768
+ ...yield getAddressLookupTableAccounts([
3769
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi",
3770
+ ...addressLookupTableAddresses
3771
+ ])
3772
+ );
2828
3773
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2829
- const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(new BN((marginSOL.toNumber() * leverage).toFixed(0)), marginSOL).accountsStrict({
3774
+ const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
3775
+ new BN((marginSOL.toNumber() * leverage).toFixed(0)),
3776
+ marginSOL
3777
+ ).accountsStrict({
2830
3778
  nodeWallet: offer.account.nodeWallet,
2831
3779
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
2832
3780
  tradingPool: offer.publicKey,
@@ -2836,15 +3784,20 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2836
3784
  clock: SYSVAR_CLOCK_PUBKEY,
2837
3785
  randomAccountAsId: randomSeed.publicKey.toBase58(),
2838
3786
  feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
2839
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
2840
- pubkey: partnerFeeRecipient,
2841
- isSigner: false,
2842
- isWritable: true
2843
- }, {
2844
- pubkey: partnerFeeMarkupAsPkey,
2845
- isSigner: false,
2846
- isWritable: false
2847
- }] : []).instruction();
3787
+ }).remainingAccounts(
3788
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
3789
+ {
3790
+ pubkey: partnerFeeRecipient,
3791
+ isSigner: false,
3792
+ isWritable: true
3793
+ },
3794
+ {
3795
+ pubkey: partnerFeeMarkupAsPkey,
3796
+ isSigner: false,
3797
+ isWritable: false
3798
+ }
3799
+ ] : []
3800
+ ).instruction();
2848
3801
  const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
2849
3802
  tradingPool: offer.publicKey,
2850
3803
  trader: lavarageProgram.provider.publicKey,
@@ -2882,13 +3835,29 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2882
3835
  feeBuffer32.set(feeBuffer, 0);
2883
3836
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
2884
3837
  }
2885
- const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2886
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
3838
+ const positionAccount = getPositionAccountPDA(
3839
+ lavarageProgram,
3840
+ offer,
3841
+ randomSeed.publicKey
3842
+ );
3843
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
3844
+ offer.account.collateralType
3845
+ );
2887
3846
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2888
3847
  const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
2889
3848
  const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
2890
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType, tokenProgram);
2891
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccount, offer.account.collateralType, tokenProgram);
3849
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3850
+ lavarageProgram,
3851
+ lavarageProgram.provider.publicKey,
3852
+ offer.account.collateralType,
3853
+ tokenProgram
3854
+ );
3855
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3856
+ lavarageProgram,
3857
+ positionAccount,
3858
+ offer.account.collateralType,
3859
+ tokenProgram
3860
+ );
2892
3861
  const tokenAccountCreationTx = new Transaction();
2893
3862
  if (fromTokenAccount.instruction) {
2894
3863
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2897,7 +3866,11 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2897
3866
  tokenAccountCreationTx.add(toTokenAccount.instruction);
2898
3867
  }
2899
3868
  const instructionsJup = jupInstruction.instructions;
2900
- const { setupInstructions, swapInstruction: swapInstructionPayload, addressLookupTableAddresses } = instructionsJup;
3869
+ const {
3870
+ setupInstructions,
3871
+ swapInstruction: swapInstructionPayload,
3872
+ addressLookupTableAddresses
3873
+ } = instructionsJup;
2901
3874
  const deserializeInstruction = (instruction) => {
2902
3875
  return new TransactionInstruction({
2903
3876
  programId: new PublicKey(instruction.programId),
@@ -2910,13 +3883,17 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2910
3883
  });
2911
3884
  };
2912
3885
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
2913
- const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new PublicKey(key)));
3886
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
3887
+ keys.map((key) => new PublicKey(key))
3888
+ );
2914
3889
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
2915
3890
  const addressLookupTableAddress = keys[index];
2916
3891
  if (accountInfo) {
2917
3892
  const addressLookupTableAccount = new AddressLookupTableAccount({
2918
3893
  key: new PublicKey(addressLookupTableAddress),
2919
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
3894
+ state: AddressLookupTableAccount.deserialize(
3895
+ Uint8Array.from(accountInfo.data)
3896
+ )
2920
3897
  });
2921
3898
  acc.push(addressLookupTableAccount);
2922
3899
  }
@@ -2924,9 +3901,18 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2924
3901
  }, new Array());
2925
3902
  });
2926
3903
  const addressLookupTableAccounts = [];
2927
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts([...addressLookupTableAddresses, getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()), "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"]));
3904
+ addressLookupTableAccounts.push(
3905
+ ...yield getAddressLookupTableAccounts([
3906
+ ...addressLookupTableAddresses,
3907
+ getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()),
3908
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"
3909
+ ])
3910
+ );
2928
3911
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2929
- const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(new BN((marginSOL.toNumber() * leverage).toFixed(0)), marginSOL).accountsStrict({
3912
+ const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
3913
+ new BN((marginSOL.toNumber() * leverage).toFixed(0)),
3914
+ marginSOL
3915
+ ).accountsStrict({
2930
3916
  nodeWallet: offer.account.nodeWallet,
2931
3917
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
2932
3918
  tradingPool: offer.publicKey,
@@ -2935,19 +3921,44 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2935
3921
  systemProgram: SystemProgram.programId,
2936
3922
  clock: SYSVAR_CLOCK_PUBKEY,
2937
3923
  randomAccountAsId: randomSeed.publicKey.toBase58(),
2938
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), true, quoteTokenProgram),
2939
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, true, quoteTokenProgram),
3924
+ feeTokenAccount: getAssociatedTokenAddressSync(
3925
+ quoteToken,
3926
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
3927
+ true,
3928
+ quoteTokenProgram
3929
+ ),
3930
+ toTokenAccount: getAssociatedTokenAddressSync(
3931
+ quoteToken,
3932
+ lavarageProgram.provider.publicKey,
3933
+ true,
3934
+ quoteTokenProgram
3935
+ ),
2940
3936
  tokenProgram: quoteTokenProgram,
2941
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, offer.account.nodeWallet, true, quoteTokenProgram)
2942
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
2943
- pubkey: getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false, quoteTokenProgram),
2944
- isSigner: false,
2945
- isWritable: true
2946
- }, {
2947
- pubkey: partnerFeeMarkupAsPkey,
2948
- isSigner: false,
2949
- isWritable: false
2950
- }] : []).instruction();
3937
+ fromTokenAccount: getAssociatedTokenAddressSync(
3938
+ quoteToken,
3939
+ offer.account.nodeWallet,
3940
+ true,
3941
+ quoteTokenProgram
3942
+ )
3943
+ }).remainingAccounts(
3944
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
3945
+ {
3946
+ pubkey: getAssociatedTokenAddressSync(
3947
+ quoteToken,
3948
+ partnerFeeRecipient,
3949
+ false,
3950
+ quoteTokenProgram
3951
+ ),
3952
+ isSigner: false,
3953
+ isWritable: true
3954
+ },
3955
+ {
3956
+ pubkey: partnerFeeMarkupAsPkey,
3957
+ isSigner: false,
3958
+ isWritable: false
3959
+ }
3960
+ ] : []
3961
+ ).instruction();
2951
3962
  const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
2952
3963
  tradingPool: offer.publicKey,
2953
3964
  trader: lavarageProgram.provider.publicKey,
@@ -2978,65 +3989,93 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2978
3989
  });
2979
3990
  var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
2980
3991
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2981
- const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(tpPrice, tpTolerence, new PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"), new BN(1e4)).accountsStrict({
2982
- delegate: getPda([Buffer.from("delegate"), position.publicKey.toBuffer()], lavarageProgram.programId),
3992
+ const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
3993
+ tpPrice,
3994
+ tpTolerence,
3995
+ new PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"),
3996
+ new BN(1e4)
3997
+ ).accountsStrict({
3998
+ delegate: getPda(
3999
+ [Buffer.from("delegate"), position.publicKey.toBuffer()],
4000
+ lavarageProgram.programId
4001
+ ),
2983
4002
  originalOperator: lavarageProgram.provider.publicKey,
2984
4003
  delegatedAccount: position.publicKey,
2985
4004
  systemProgram: SystemProgram.programId
2986
- }).remainingAccounts(partnerFeeRecipient ? [{
2987
- pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false),
2988
- isSigner: false,
2989
- isWritable: true
2990
- }] : []).instruction();
4005
+ }).remainingAccounts(
4006
+ partnerFeeRecipient ? [
4007
+ {
4008
+ pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(
4009
+ quoteToken,
4010
+ partnerFeeRecipient,
4011
+ false
4012
+ ),
4013
+ isSigner: false,
4014
+ isWritable: true
4015
+ }
4016
+ ] : []
4017
+ ).instruction();
2991
4018
  const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
2992
4019
  microLamports: prioFee.toNumber()
2993
4020
  });
2994
4021
  const messageV0 = new TransactionMessage({
2995
4022
  payerKey: lavarageProgram.provider.publicKey,
2996
4023
  recentBlockhash: blockhash,
2997
- instructions: [
2998
- ix,
2999
- computeFeeIx
3000
- ].filter(Boolean)
4024
+ instructions: [ix, computeFeeIx].filter(Boolean)
3001
4025
  }).compileToV0Message();
3002
4026
  return new VersionedTransaction(messageV0);
3003
4027
  });
3004
4028
  var modifyTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
3005
4029
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3006
- const delegatePda = getPda([Buffer.from("delegate"), position.publicKey.toBuffer()], lavarageProgram.programId);
4030
+ const delegatePda = getPda(
4031
+ [Buffer.from("delegate"), position.publicKey.toBuffer()],
4032
+ lavarageProgram.programId
4033
+ );
3007
4034
  const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
3008
4035
  delegate: delegatePda,
3009
4036
  originalOperator: lavarageProgram.provider.publicKey,
3010
4037
  delegatedAccount: position.publicKey,
3011
4038
  systemProgram: SystemProgram.programId
3012
4039
  }).instruction();
3013
- const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(tpPrice, tpTolerence, new PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"), new BN(1e4)).accountsStrict({
4040
+ const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
4041
+ tpPrice,
4042
+ tpTolerence,
4043
+ new PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"),
4044
+ new BN(1e4)
4045
+ ).accountsStrict({
3014
4046
  delegate: delegatePda,
3015
4047
  originalOperator: lavarageProgram.provider.publicKey,
3016
4048
  delegatedAccount: position.publicKey,
3017
4049
  systemProgram: SystemProgram.programId
3018
- }).remainingAccounts(partnerFeeRecipient ? [{
3019
- pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false),
3020
- isSigner: false,
3021
- isWritable: true
3022
- }] : []).instruction();
4050
+ }).remainingAccounts(
4051
+ partnerFeeRecipient ? [
4052
+ {
4053
+ pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(
4054
+ quoteToken,
4055
+ partnerFeeRecipient,
4056
+ false
4057
+ ),
4058
+ isSigner: false,
4059
+ isWritable: true
4060
+ }
4061
+ ] : []
4062
+ ).instruction();
3023
4063
  const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
3024
4064
  microLamports: prioFee.toNumber()
3025
4065
  });
3026
4066
  const messageV0 = new TransactionMessage({
3027
4067
  payerKey: lavarageProgram.provider.publicKey,
3028
4068
  recentBlockhash: blockhash,
3029
- instructions: [
3030
- removeIx,
3031
- ix,
3032
- computeFeeIx
3033
- ].filter(Boolean)
4069
+ instructions: [removeIx, ix, computeFeeIx].filter(Boolean)
3034
4070
  }).compileToV0Message();
3035
4071
  return new VersionedTransaction(messageV0);
3036
4072
  });
3037
4073
  var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, null, function* () {
3038
4074
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3039
- const delegatePda = getPda([Buffer.from("delegate"), position.publicKey.toBuffer()], lavarageProgram.programId);
4075
+ const delegatePda = getPda(
4076
+ [Buffer.from("delegate"), position.publicKey.toBuffer()],
4077
+ lavarageProgram.programId
4078
+ );
3040
4079
  const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
3041
4080
  delegate: delegatePda,
3042
4081
  originalOperator: lavarageProgram.provider.publicKey,
@@ -3049,10 +4088,7 @@ var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, n
3049
4088
  const messageV0 = new TransactionMessage({
3050
4089
  payerKey: lavarageProgram.provider.publicKey,
3051
4090
  recentBlockhash: blockhash,
3052
- instructions: [
3053
- removeIx,
3054
- computeFeeIx
3055
- ].filter(Boolean)
4091
+ instructions: [removeIx, computeFeeIx].filter(Boolean)
3056
4092
  }).compileToV0Message();
3057
4093
  return new VersionedTransaction(messageV0);
3058
4094
  });
@@ -3089,10 +4125,20 @@ var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0
3089
4125
  trader: lavarageProgram.provider.publicKey,
3090
4126
  clock: SYSVAR_CLOCK_PUBKEY,
3091
4127
  randomAccountAsId: position.account.seed,
3092
- fromTokenAccount: getAssociatedTokenAddressSync(pool.qtType, lavarageProgram.provider.publicKey),
3093
- toTokenAccount: getAssociatedTokenAddressSync(pool.qtType, pool.nodeWallet, true),
4128
+ fromTokenAccount: getAssociatedTokenAddressSync(
4129
+ pool.qtType,
4130
+ lavarageProgram.provider.publicKey
4131
+ ),
4132
+ toTokenAccount: getAssociatedTokenAddressSync(
4133
+ pool.qtType,
4134
+ pool.nodeWallet,
4135
+ true
4136
+ ),
3094
4137
  mint: pool.qtType,
3095
- feeTokenAccount: getAssociatedTokenAddressSync(pool.qtType, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
4138
+ feeTokenAccount: getAssociatedTokenAddressSync(
4139
+ pool.qtType,
4140
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")
4141
+ ),
3096
4142
  tokenProgram: TOKEN_PROGRAM_ID
3097
4143
  }).instruction();
3098
4144
  const messageV0 = new TransactionMessage({
@@ -3112,15 +4158,28 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3112
4158
  feeBuffer32.set(feeBuffer, 0);
3113
4159
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
3114
4160
  }
3115
- if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
4161
+ if (position.account.pool.toBase58() != offer.publicKey.toBase58())
4162
+ throw "Mismatch offer";
3116
4163
  const pool = offer;
3117
4164
  const poolPubKey = offer.publicKey;
3118
4165
  const tokenAddressPubKey = new PublicKey(offer.account.collateralType);
3119
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4166
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4167
+ offer.account.collateralType
4168
+ );
3120
4169
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3121
4170
  const positionAccountPDA = position.publicKey;
3122
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
3123
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey, tokenProgram);
4171
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
4172
+ lavarageProgram,
4173
+ positionAccountPDA,
4174
+ tokenAddressPubKey,
4175
+ tokenProgram
4176
+ );
4177
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
4178
+ lavarageProgram,
4179
+ lavarageProgram.provider.publicKey,
4180
+ tokenAddressPubKey,
4181
+ tokenProgram
4182
+ );
3124
4183
  const jupiterSellIx = jupInstruction.instructions;
3125
4184
  const deserializeInstruction = (instruction) => {
3126
4185
  return new TransactionInstruction({
@@ -3134,13 +4193,17 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3134
4193
  });
3135
4194
  };
3136
4195
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
3137
- const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new PublicKey(key)));
4196
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
4197
+ keys.map((key) => new PublicKey(key))
4198
+ );
3138
4199
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
3139
4200
  const addressLookupTableAddress = keys[index];
3140
4201
  if (accountInfo) {
3141
4202
  const addressLookupTableAccount = new AddressLookupTableAccount({
3142
4203
  key: new PublicKey(addressLookupTableAddress),
3143
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
4204
+ state: AddressLookupTableAccount.deserialize(
4205
+ Uint8Array.from(accountInfo.data)
4206
+ )
3144
4207
  });
3145
4208
  acc.push(addressLookupTableAccount);
3146
4209
  }
@@ -3165,7 +4228,10 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3165
4228
  let repaySolIx = null;
3166
4229
  let jupiterIxs = [];
3167
4230
  if (jupInstruction.instructions == void 0) {
3168
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9997)).accountsStrict({
4231
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
4232
+ new BN(jupInstruction.quoteResponse.outAmount),
4233
+ new BN(9997)
4234
+ ).accountsStrict({
3169
4235
  nodeWallet: pool.account.nodeWallet,
3170
4236
  positionAccount: positionAccountPDA,
3171
4237
  tradingPool: poolPubKey,
@@ -3174,17 +4240,25 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3174
4240
  clock: SYSVAR_CLOCK_PUBKEY,
3175
4241
  randomAccountAsId: position.account.seed,
3176
4242
  feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
3177
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
3178
- pubkey: partnerFeeRecipient,
3179
- isSigner: false,
3180
- isWritable: true
3181
- }, {
3182
- pubkey: partnerFeeMarkupAsPkey,
3183
- isSigner: false,
3184
- isWritable: false
3185
- }] : []).instruction();
4243
+ }).remainingAccounts(
4244
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
4245
+ {
4246
+ pubkey: partnerFeeRecipient,
4247
+ isSigner: false,
4248
+ isWritable: true
4249
+ },
4250
+ {
4251
+ pubkey: partnerFeeMarkupAsPkey,
4252
+ isSigner: false,
4253
+ isWritable: false
4254
+ }
4255
+ ] : []
4256
+ ).instruction();
3186
4257
  } else {
3187
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9998)).accountsStrict({
4258
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
4259
+ new BN(jupInstruction.quoteResponse.outAmount),
4260
+ new BN(9998)
4261
+ ).accountsStrict({
3188
4262
  nodeWallet: pool.account.nodeWallet,
3189
4263
  positionAccount: positionAccountPDA,
3190
4264
  tradingPool: poolPubKey,
@@ -3193,22 +4267,37 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3193
4267
  clock: SYSVAR_CLOCK_PUBKEY,
3194
4268
  randomAccountAsId: position.account.seed,
3195
4269
  feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
3196
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
3197
- pubkey: partnerFeeRecipient,
3198
- isSigner: false,
3199
- isWritable: true
3200
- }, {
3201
- pubkey: partnerFeeMarkupAsPkey,
3202
- isSigner: false,
3203
- isWritable: false
3204
- }] : []).instruction();
3205
- const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx;
4270
+ }).remainingAccounts(
4271
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
4272
+ {
4273
+ pubkey: partnerFeeRecipient,
4274
+ isSigner: false,
4275
+ isWritable: true
4276
+ },
4277
+ {
4278
+ pubkey: partnerFeeMarkupAsPkey,
4279
+ isSigner: false,
4280
+ isWritable: false
4281
+ }
4282
+ ] : []
4283
+ ).instruction();
4284
+ const {
4285
+ setupInstructions,
4286
+ swapInstruction: swapInstructionPayload,
4287
+ cleanupInstruction,
4288
+ addressLookupTableAddresses
4289
+ } = jupiterSellIx;
3206
4290
  jupiterIxs = [
3207
4291
  ...setupInstructions.map(deserializeInstruction),
3208
4292
  deserializeInstruction(swapInstructionPayload),
3209
4293
  deserializeInstruction(cleanupInstruction)
3210
4294
  ];
3211
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(["5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi", ...addressLookupTableAddresses]));
4295
+ addressLookupTableAccounts.push(
4296
+ ...yield getAddressLookupTableAccounts([
4297
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi",
4298
+ ...addressLookupTableAddresses
4299
+ ])
4300
+ );
3212
4301
  }
3213
4302
  const profit = new BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3214
4303
  let createAssociatedTokenAccountInstruction2 = createAssociatedTokenAccountIdempotentInstruction(
@@ -3220,7 +4309,9 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3220
4309
  );
3221
4310
  const allInstructions = [
3222
4311
  ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
3223
- ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(jupInstruction.instructions.tokenLedgerInstruction) : null,
4312
+ ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
4313
+ jupInstruction.instructions.tokenLedgerInstruction
4314
+ ) : null,
3224
4315
  toTokenAccount.instruction,
3225
4316
  closePositionIx,
3226
4317
  ...jupiterIxs,
@@ -3244,17 +4335,30 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3244
4335
  feeBuffer32.set(feeBuffer, 0);
3245
4336
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
3246
4337
  }
3247
- if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
4338
+ if (position.account.pool.toBase58() != offer.publicKey.toBase58())
4339
+ throw "Mismatch offer";
3248
4340
  const pool = offer;
3249
4341
  const poolPubKey = offer.publicKey;
3250
4342
  const tokenAddressPubKey = new PublicKey(offer.account.collateralType);
3251
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4343
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4344
+ offer.account.collateralType
4345
+ );
3252
4346
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3253
4347
  const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
3254
4348
  const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
3255
4349
  const positionAccountPDA = position.publicKey;
3256
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
3257
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey, tokenProgram);
4350
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
4351
+ lavarageProgram,
4352
+ positionAccountPDA,
4353
+ tokenAddressPubKey,
4354
+ tokenProgram
4355
+ );
4356
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
4357
+ lavarageProgram,
4358
+ lavarageProgram.provider.publicKey,
4359
+ tokenAddressPubKey,
4360
+ tokenProgram
4361
+ );
3258
4362
  const jupiterSellIx = jupInstruction.instructions;
3259
4363
  const deserializeInstruction = (instruction) => {
3260
4364
  return new TransactionInstruction({
@@ -3268,13 +4372,17 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3268
4372
  });
3269
4373
  };
3270
4374
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
3271
- const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new PublicKey(key)));
4375
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
4376
+ keys.map((key) => new PublicKey(key))
4377
+ );
3272
4378
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
3273
4379
  const addressLookupTableAddress = keys[index];
3274
4380
  if (accountInfo) {
3275
4381
  const addressLookupTableAccount = new AddressLookupTableAccount({
3276
4382
  key: new PublicKey(addressLookupTableAddress),
3277
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
4383
+ state: AddressLookupTableAccount.deserialize(
4384
+ Uint8Array.from(accountInfo.data)
4385
+ )
3278
4386
  });
3279
4387
  acc.push(addressLookupTableAccount);
3280
4388
  }
@@ -3299,7 +4407,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3299
4407
  let repaySolIx = null;
3300
4408
  let jupiterIxs = [];
3301
4409
  if (jupInstruction.instructions == void 0) {
3302
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9997)).accountsStrict({
4410
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
4411
+ new BN(jupInstruction.quoteResponse.outAmount),
4412
+ new BN(9997)
4413
+ ).accountsStrict({
3303
4414
  nodeWallet: pool.account.nodeWallet,
3304
4415
  positionAccount: positionAccountPDA,
3305
4416
  tradingPool: poolPubKey,
@@ -3307,22 +4418,50 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3307
4418
  systemProgram: SystemProgram.programId,
3308
4419
  clock: SYSVAR_CLOCK_PUBKEY,
3309
4420
  randomAccountAsId: position.account.seed,
3310
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
3311
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
4421
+ feeTokenAccount: getAssociatedTokenAddressSync(
4422
+ quoteToken,
4423
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
4424
+ false,
4425
+ quoteTokenProgram
4426
+ ),
4427
+ fromTokenAccount: getAssociatedTokenAddressSync(
4428
+ quoteToken,
4429
+ lavarageProgram.provider.publicKey,
4430
+ false,
4431
+ quoteTokenProgram
4432
+ ),
3312
4433
  tokenProgram: quoteTokenProgram,
3313
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
4434
+ toTokenAccount: getAssociatedTokenAddressSync(
4435
+ quoteToken,
4436
+ pool.account.nodeWallet,
4437
+ true,
4438
+ quoteTokenProgram
4439
+ ),
3314
4440
  mint: quoteToken
3315
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
3316
- pubkey: getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false, quoteTokenProgram),
3317
- isSigner: false,
3318
- isWritable: true
3319
- }, {
3320
- pubkey: partnerFeeMarkupAsPkey,
3321
- isSigner: false,
3322
- isWritable: false
3323
- }] : []).instruction();
4441
+ }).remainingAccounts(
4442
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
4443
+ {
4444
+ pubkey: getAssociatedTokenAddressSync(
4445
+ quoteToken,
4446
+ partnerFeeRecipient,
4447
+ false,
4448
+ quoteTokenProgram
4449
+ ),
4450
+ isSigner: false,
4451
+ isWritable: true
4452
+ },
4453
+ {
4454
+ pubkey: partnerFeeMarkupAsPkey,
4455
+ isSigner: false,
4456
+ isWritable: false
4457
+ }
4458
+ ] : []
4459
+ ).instruction();
3324
4460
  } else {
3325
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9998)).accountsStrict({
4461
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
4462
+ new BN(jupInstruction.quoteResponse.outAmount),
4463
+ new BN(9998)
4464
+ ).accountsStrict({
3326
4465
  nodeWallet: pool.account.nodeWallet,
3327
4466
  positionAccount: positionAccountPDA,
3328
4467
  tradingPool: poolPubKey,
@@ -3330,27 +4469,58 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3330
4469
  systemProgram: SystemProgram.programId,
3331
4470
  clock: SYSVAR_CLOCK_PUBKEY,
3332
4471
  randomAccountAsId: position.account.seed,
3333
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
3334
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
4472
+ feeTokenAccount: getAssociatedTokenAddressSync(
4473
+ quoteToken,
4474
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
4475
+ false,
4476
+ quoteTokenProgram
4477
+ ),
4478
+ fromTokenAccount: getAssociatedTokenAddressSync(
4479
+ quoteToken,
4480
+ lavarageProgram.provider.publicKey,
4481
+ false,
4482
+ quoteTokenProgram
4483
+ ),
3335
4484
  tokenProgram: quoteTokenProgram,
3336
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
4485
+ toTokenAccount: getAssociatedTokenAddressSync(
4486
+ quoteToken,
4487
+ pool.account.nodeWallet,
4488
+ true,
4489
+ quoteTokenProgram
4490
+ ),
3337
4491
  mint: quoteToken
3338
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
3339
- pubkey: partnerFeeRecipient,
3340
- isSigner: false,
3341
- isWritable: true
3342
- }, {
3343
- pubkey: partnerFeeMarkupAsPkey,
3344
- isSigner: false,
3345
- isWritable: false
3346
- }] : []).instruction();
3347
- const { setupInstructions, swapInstruction: swapInstructionPayload, cleanupInstruction, addressLookupTableAddresses } = jupiterSellIx;
4492
+ }).remainingAccounts(
4493
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
4494
+ {
4495
+ pubkey: partnerFeeRecipient,
4496
+ isSigner: false,
4497
+ isWritable: true
4498
+ },
4499
+ {
4500
+ pubkey: partnerFeeMarkupAsPkey,
4501
+ isSigner: false,
4502
+ isWritable: false
4503
+ }
4504
+ ] : []
4505
+ ).instruction();
4506
+ const {
4507
+ setupInstructions,
4508
+ swapInstruction: swapInstructionPayload,
4509
+ cleanupInstruction,
4510
+ addressLookupTableAddresses
4511
+ } = jupiterSellIx;
3348
4512
  jupiterIxs = [
3349
4513
  ...setupInstructions.filter((i) => !!i).map(deserializeInstruction),
3350
4514
  swapInstructionPayload ? deserializeInstruction(swapInstructionPayload) : null,
3351
4515
  cleanupInstruction ? deserializeInstruction(cleanupInstruction) : null
3352
4516
  ].filter((i) => !!i);
3353
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts([...addressLookupTableAddresses, getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()), "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"]));
4517
+ addressLookupTableAccounts.push(
4518
+ ...yield getAddressLookupTableAccounts([
4519
+ ...addressLookupTableAddresses,
4520
+ getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()),
4521
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"
4522
+ ])
4523
+ );
3354
4524
  }
3355
4525
  const profit = new BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3356
4526
  let createAssociatedTokenAccountInstruction2 = createAssociatedTokenAccountIdempotentInstruction(
@@ -3362,7 +4532,9 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3362
4532
  );
3363
4533
  const allInstructions = [
3364
4534
  ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
3365
- ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(jupInstruction.instructions.tokenLedgerInstruction) : null,
4535
+ ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
4536
+ jupInstruction.instructions.tokenLedgerInstruction
4537
+ ) : null,
3366
4538
  toTokenAccount.instruction,
3367
4539
  closePositionIx,
3368
4540
  ...jupiterIxs,
@@ -3377,12 +4549,16 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3377
4549
  return tx;
3378
4550
  });
3379
4551
  var getDelegateAccounts = (lavarageProgram, userPubKey) => __async(void 0, null, function* () {
3380
- const delegateAccounts = yield lavarageProgram.account.delegate.all(userPubKey ? [{
3381
- memcmp: {
3382
- offset: 104,
3383
- bytes: userPubKey.toBase58()
3384
- }
3385
- }] : void 0);
4552
+ const delegateAccounts = yield lavarageProgram.account.delegate.all(
4553
+ userPubKey ? [
4554
+ {
4555
+ memcmp: {
4556
+ offset: 104,
4557
+ bytes: userPubKey.toBase58()
4558
+ }
4559
+ }
4560
+ ] : void 0
4561
+ );
3386
4562
  return delegateAccounts.map((d) => __spreadProps(__spreadValues({}, d), {
3387
4563
  parsed: {
3388
4564
  tpPrice: new BN(d.account.field1),
@@ -3404,12 +4580,32 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3404
4580
  const positionAccountPDA = position.publicKey;
3405
4581
  const newPosition1Seed = Keypair.generate().publicKey;
3406
4582
  const newPosition2Seed = Keypair.generate().publicKey;
3407
- const newPosition1AccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPosition1Seed);
3408
- const newPosition2AccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPosition2Seed);
3409
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4583
+ const newPosition1AccountPDA = getPositionAccountPDA(
4584
+ lavarageProgram,
4585
+ offer,
4586
+ newPosition1Seed
4587
+ );
4588
+ const newPosition2AccountPDA = getPositionAccountPDA(
4589
+ lavarageProgram,
4590
+ offer,
4591
+ newPosition2Seed
4592
+ );
4593
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4594
+ offer.account.collateralType
4595
+ );
3410
4596
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3411
- const newPosition1TokenAccount = getAssociatedTokenAddressSync(offer.account.collateralType, newPosition1AccountPDA, true, tokenProgram);
3412
- const newPosition2TokenAccount = getAssociatedTokenAddressSync(offer.account.collateralType, newPosition2AccountPDA, true, tokenProgram);
4597
+ const newPosition1TokenAccount = getAssociatedTokenAddressSync(
4598
+ offer.account.collateralType,
4599
+ newPosition1AccountPDA,
4600
+ true,
4601
+ tokenProgram
4602
+ );
4603
+ const newPosition2TokenAccount = getAssociatedTokenAddressSync(
4604
+ offer.account.collateralType,
4605
+ newPosition2AccountPDA,
4606
+ true,
4607
+ tokenProgram
4608
+ );
3413
4609
  const createNewPosition1TokenAccountIx = createAssociatedTokenAccountInstruction(
3414
4610
  lavarageProgram.provider.publicKey,
3415
4611
  newPosition1TokenAccount,
@@ -3424,7 +4620,11 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3424
4620
  offer.account.collateralType,
3425
4621
  tokenProgram
3426
4622
  );
3427
- const ix = yield lavarageProgram.methods.tradingManagementSplitPosition(new BN(propotionBps), newPosition1Seed, newPosition2Seed).accountsStrict({
4623
+ const ix = yield lavarageProgram.methods.tradingManagementSplitPosition(
4624
+ new BN(propotionBps),
4625
+ newPosition1Seed,
4626
+ newPosition2Seed
4627
+ ).accountsStrict({
3428
4628
  originalPosition: positionAccountPDA,
3429
4629
  newPositionOne: newPosition1AccountPDA,
3430
4630
  newPositionTwo: newPosition2AccountPDA,
@@ -3432,7 +4632,12 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3432
4632
  systemProgram: SystemProgram.programId,
3433
4633
  mint: offer.account.collateralType,
3434
4634
  tokenProgram,
3435
- originalPositionTokenAccount: getAssociatedTokenAddressSync(offer.account.collateralType, positionAccountPDA, true, tokenProgram),
4635
+ originalPositionTokenAccount: getAssociatedTokenAddressSync(
4636
+ offer.account.collateralType,
4637
+ positionAccountPDA,
4638
+ true,
4639
+ tokenProgram
4640
+ ),
3436
4641
  newPositionTokenAccountOne: newPosition1TokenAccount,
3437
4642
  newPositionTokenAccountTwo: newPosition2TokenAccount
3438
4643
  }).instruction();
@@ -3458,10 +4663,21 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3458
4663
  const positionAccountPDA1 = position1.publicKey;
3459
4664
  const positionAccountPDA2 = position2.publicKey;
3460
4665
  const newPositionSeed = Keypair.generate().publicKey;
3461
- const newPositionAccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPositionSeed);
3462
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4666
+ const newPositionAccountPDA = getPositionAccountPDA(
4667
+ lavarageProgram,
4668
+ offer,
4669
+ newPositionSeed
4670
+ );
4671
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4672
+ offer.account.collateralType
4673
+ );
3463
4674
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3464
- const newPositionTokenAccount = getAssociatedTokenAddressSync(offer.account.collateralType, newPositionAccountPDA, true, tokenProgram);
4675
+ const newPositionTokenAccount = getAssociatedTokenAddressSync(
4676
+ offer.account.collateralType,
4677
+ newPositionAccountPDA,
4678
+ true,
4679
+ tokenProgram
4680
+ );
3465
4681
  const createNewPositionTokenAccountIx = createAssociatedTokenAccountInstruction(
3466
4682
  lavarageProgram.provider.publicKey,
3467
4683
  newPositionTokenAccount,
@@ -3477,8 +4693,18 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3477
4693
  systemProgram: SystemProgram.programId,
3478
4694
  mint: offer.account.collateralType,
3479
4695
  tokenProgram,
3480
- positionOneTokenAccount: getAssociatedTokenAddressSync(offer.account.collateralType, positionAccountPDA1, true, tokenProgram),
3481
- positionTwoTokenAccount: getAssociatedTokenAddressSync(offer.account.collateralType, positionAccountPDA2, true, tokenProgram),
4696
+ positionOneTokenAccount: getAssociatedTokenAddressSync(
4697
+ offer.account.collateralType,
4698
+ positionAccountPDA1,
4699
+ true,
4700
+ tokenProgram
4701
+ ),
4702
+ positionTwoTokenAccount: getAssociatedTokenAddressSync(
4703
+ offer.account.collateralType,
4704
+ positionAccountPDA2,
4705
+ true,
4706
+ tokenProgram
4707
+ ),
3482
4708
  mergedPositionTokenAccount: newPositionTokenAccount
3483
4709
  }).instruction();
3484
4710
  const computeBudgetIx = ComputeBudgetProgram.setComputeUnitPrice({
@@ -3501,19 +4727,28 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3501
4727
  export {
3502
4728
  IDL,
3503
4729
  lavaragev2_exports as IDLV2,
4730
+ closePositionEvm,
3504
4731
  closeTradeV1,
3505
4732
  closeTradeV2,
3506
4733
  createTpDelegate,
3507
4734
  getAllPositions,
3508
4735
  getClosedPositions,
4736
+ getClosedPositionsEvm,
4737
+ getCollateralInfoEvm,
3509
4738
  getDelegateAccounts,
3510
4739
  getLiquidatedPositions,
4740
+ getLiquidatedPositionsEvm,
4741
+ getLoanEvm,
3511
4742
  getOffers,
4743
+ getOffersEvm,
3512
4744
  getOpenPositions,
3513
4745
  getPda,
3514
4746
  getPositionAccountPDA,
4747
+ getPositionsEvm,
4748
+ getUserLoansEvm,
3515
4749
  mergePositionV2,
3516
4750
  modifyTpDelegate,
4751
+ openPositionEvm,
3517
4752
  openTradeV1,
3518
4753
  openTradeV2,
3519
4754
  partialRepayV1,