@lavarage/sdk 6.4.6 → 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, getAccount, getAssociatedTokenAddressSync, TOKEN_PROGRAM_ID, TokenAccountNotFoundError, TokenInvalidAccountOwnerError } 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,41 +2697,927 @@ 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);
2693
- try {
2694
- const tokenAccount = yield getAccount(lavarageProgram.provider.connection, associatedTokenAddress, "finalized", tokenProgram);
2695
- return { account: tokenAccount, instruction: null };
2696
- } catch (error) {
2697
- if (error instanceof TokenAccountNotFoundError || error instanceof TokenInvalidAccountOwnerError) {
2698
- const instruction = createAssociatedTokenAccountInstruction(
2699
- lavarageProgram.provider.publicKey,
2700
- associatedTokenAddress,
2701
- ownerPublicKey,
2702
- tokenAddress,
2703
- tokenProgram,
2704
- ASSOCIATED_TOKEN_PROGRAM_ID
2705
- );
2706
- return {
2707
- account: {
2708
- address: associatedTokenAddress
2709
- },
2710
- instruction
2711
- };
2712
- } else {
2713
- console.error("Error in getTokenAccountOrCreateIfNotExists: ", error);
2714
- return { account: null, instruction: null };
2715
- }
2716
- }
3600
+ const associatedTokenAddress = getAssociatedTokenAddressSync(
3601
+ tokenAddress,
3602
+ ownerPublicKey,
3603
+ true,
3604
+ tokenProgram,
3605
+ ASSOCIATED_TOKEN_PROGRAM_ID
3606
+ );
3607
+ const instruction = createAssociatedTokenAccountIdempotentInstruction(
3608
+ lavarageProgram.provider.publicKey,
3609
+ associatedTokenAddress,
3610
+ ownerPublicKey,
3611
+ tokenAddress,
3612
+ tokenProgram,
3613
+ ASSOCIATED_TOKEN_PROGRAM_ID
3614
+ );
3615
+ return {
3616
+ account: {
3617
+ address: associatedTokenAddress
3618
+ },
3619
+ instruction
3620
+ };
2717
3621
  });
2718
3622
  }
2719
3623
  var getOffers = (lavarageProgram) => {
@@ -2748,23 +3652,27 @@ var getClosedPositions = (lavarageProgram) => __async(void 0, null, function* ()
2748
3652
  bytes: bs58.encode(Uint8Array.from(valueBuffer))
2749
3653
  }
2750
3654
  }
2751
- ])).concat(yield lavarageProgram.account.position.all([
2752
- { dataSize: 178 },
2753
- {
2754
- memcmp: {
2755
- offset: 40,
2756
- 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
+ }
2757
3663
  }
2758
- }
2759
- ])).concat(yield lavarageProgram.account.position.all([
2760
- { dataSize: 178 },
2761
- {
2762
- memcmp: {
2763
- offset: 40,
2764
- 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
+ }
2765
3673
  }
2766
- }
2767
- ]));
3674
+ ])
3675
+ );
2768
3676
  });
2769
3677
  var getLiquidatedPositions = (lavarageProgram) => {
2770
3678
  const value = BigInt(9999);
@@ -2781,9 +3689,7 @@ var getLiquidatedPositions = (lavarageProgram) => {
2781
3689
  ]);
2782
3690
  };
2783
3691
  var getAllPositions = (lavarageProgram) => {
2784
- return lavarageProgram.account.position.all([
2785
- { dataSize: 178 }
2786
- ]);
3692
+ return lavarageProgram.account.position.all([{ dataSize: 178 }]);
2787
3693
  };
2788
3694
  var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
2789
3695
  let partnerFeeMarkupAsPkey;
@@ -2794,11 +3700,27 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2794
3700
  feeBuffer32.set(feeBuffer, 0);
2795
3701
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
2796
3702
  }
2797
- const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2798
- 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
+ );
2799
3711
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2800
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType, tokenProgram);
2801
- 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
+ );
2802
3724
  const tokenAccountCreationTx = new Transaction();
2803
3725
  if (fromTokenAccount.instruction) {
2804
3726
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2807,7 +3729,11 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2807
3729
  tokenAccountCreationTx.add(toTokenAccount.instruction);
2808
3730
  }
2809
3731
  const instructionsJup = jupInstruction.instructions;
2810
- const { setupInstructions, swapInstruction: swapInstructionPayload, addressLookupTableAddresses } = instructionsJup;
3732
+ const {
3733
+ setupInstructions,
3734
+ swapInstruction: swapInstructionPayload,
3735
+ addressLookupTableAddresses
3736
+ } = instructionsJup;
2811
3737
  const deserializeInstruction = (instruction) => {
2812
3738
  return new TransactionInstruction({
2813
3739
  programId: new PublicKey(instruction.programId),
@@ -2820,13 +3746,17 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2820
3746
  });
2821
3747
  };
2822
3748
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
2823
- 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
+ );
2824
3752
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
2825
3753
  const addressLookupTableAddress = keys[index];
2826
3754
  if (accountInfo) {
2827
3755
  const addressLookupTableAccount = new AddressLookupTableAccount({
2828
3756
  key: new PublicKey(addressLookupTableAddress),
2829
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
3757
+ state: AddressLookupTableAccount.deserialize(
3758
+ Uint8Array.from(accountInfo.data)
3759
+ )
2830
3760
  });
2831
3761
  acc.push(addressLookupTableAccount);
2832
3762
  }
@@ -2834,9 +3764,17 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2834
3764
  }, new Array());
2835
3765
  });
2836
3766
  const addressLookupTableAccounts = [];
2837
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(["5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi", ...addressLookupTableAddresses]));
3767
+ addressLookupTableAccounts.push(
3768
+ ...yield getAddressLookupTableAccounts([
3769
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi",
3770
+ ...addressLookupTableAddresses
3771
+ ])
3772
+ );
2838
3773
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2839
- 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({
2840
3778
  nodeWallet: offer.account.nodeWallet,
2841
3779
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
2842
3780
  tradingPool: offer.publicKey,
@@ -2846,15 +3784,20 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2846
3784
  clock: SYSVAR_CLOCK_PUBKEY,
2847
3785
  randomAccountAsId: randomSeed.publicKey.toBase58(),
2848
3786
  feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
2849
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
2850
- pubkey: partnerFeeRecipient,
2851
- isSigner: false,
2852
- isWritable: true
2853
- }, {
2854
- pubkey: partnerFeeMarkupAsPkey,
2855
- isSigner: false,
2856
- isWritable: false
2857
- }] : []).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();
2858
3801
  const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
2859
3802
  tradingPool: offer.publicKey,
2860
3803
  trader: lavarageProgram.provider.publicKey,
@@ -2892,13 +3835,29 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2892
3835
  feeBuffer32.set(feeBuffer, 0);
2893
3836
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
2894
3837
  }
2895
- const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2896
- 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
+ );
2897
3846
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2898
3847
  const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
2899
3848
  const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
2900
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, offer.account.collateralType, tokenProgram);
2901
- 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
+ );
2902
3861
  const tokenAccountCreationTx = new Transaction();
2903
3862
  if (fromTokenAccount.instruction) {
2904
3863
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2907,7 +3866,11 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2907
3866
  tokenAccountCreationTx.add(toTokenAccount.instruction);
2908
3867
  }
2909
3868
  const instructionsJup = jupInstruction.instructions;
2910
- const { setupInstructions, swapInstruction: swapInstructionPayload, addressLookupTableAddresses } = instructionsJup;
3869
+ const {
3870
+ setupInstructions,
3871
+ swapInstruction: swapInstructionPayload,
3872
+ addressLookupTableAddresses
3873
+ } = instructionsJup;
2911
3874
  const deserializeInstruction = (instruction) => {
2912
3875
  return new TransactionInstruction({
2913
3876
  programId: new PublicKey(instruction.programId),
@@ -2920,13 +3883,17 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2920
3883
  });
2921
3884
  };
2922
3885
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
2923
- 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
+ );
2924
3889
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
2925
3890
  const addressLookupTableAddress = keys[index];
2926
3891
  if (accountInfo) {
2927
3892
  const addressLookupTableAccount = new AddressLookupTableAccount({
2928
3893
  key: new PublicKey(addressLookupTableAddress),
2929
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
3894
+ state: AddressLookupTableAccount.deserialize(
3895
+ Uint8Array.from(accountInfo.data)
3896
+ )
2930
3897
  });
2931
3898
  acc.push(addressLookupTableAccount);
2932
3899
  }
@@ -2934,9 +3901,18 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2934
3901
  }, new Array());
2935
3902
  });
2936
3903
  const addressLookupTableAccounts = [];
2937
- 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
+ );
2938
3911
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2939
- 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({
2940
3916
  nodeWallet: offer.account.nodeWallet,
2941
3917
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
2942
3918
  tradingPool: offer.publicKey,
@@ -2945,19 +3921,44 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2945
3921
  systemProgram: SystemProgram.programId,
2946
3922
  clock: SYSVAR_CLOCK_PUBKEY,
2947
3923
  randomAccountAsId: randomSeed.publicKey.toBase58(),
2948
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), true, quoteTokenProgram),
2949
- 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
+ ),
2950
3936
  tokenProgram: quoteTokenProgram,
2951
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, offer.account.nodeWallet, true, quoteTokenProgram)
2952
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
2953
- pubkey: getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false, quoteTokenProgram),
2954
- isSigner: false,
2955
- isWritable: true
2956
- }, {
2957
- pubkey: partnerFeeMarkupAsPkey,
2958
- isSigner: false,
2959
- isWritable: false
2960
- }] : []).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();
2961
3962
  const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
2962
3963
  tradingPool: offer.publicKey,
2963
3964
  trader: lavarageProgram.provider.publicKey,
@@ -2988,65 +3989,93 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2988
3989
  });
2989
3990
  var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
2990
3991
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2991
- const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(tpPrice, tpTolerence, new PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"), new BN(1e4)).accountsStrict({
2992
- 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
+ ),
2993
4002
  originalOperator: lavarageProgram.provider.publicKey,
2994
4003
  delegatedAccount: position.publicKey,
2995
4004
  systemProgram: SystemProgram.programId
2996
- }).remainingAccounts(partnerFeeRecipient ? [{
2997
- pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false),
2998
- isSigner: false,
2999
- isWritable: true
3000
- }] : []).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();
3001
4018
  const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
3002
4019
  microLamports: prioFee.toNumber()
3003
4020
  });
3004
4021
  const messageV0 = new TransactionMessage({
3005
4022
  payerKey: lavarageProgram.provider.publicKey,
3006
4023
  recentBlockhash: blockhash,
3007
- instructions: [
3008
- ix,
3009
- computeFeeIx
3010
- ].filter(Boolean)
4024
+ instructions: [ix, computeFeeIx].filter(Boolean)
3011
4025
  }).compileToV0Message();
3012
4026
  return new VersionedTransaction(messageV0);
3013
4027
  });
3014
4028
  var modifyTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
3015
4029
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3016
- 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
+ );
3017
4034
  const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
3018
4035
  delegate: delegatePda,
3019
4036
  originalOperator: lavarageProgram.provider.publicKey,
3020
4037
  delegatedAccount: position.publicKey,
3021
4038
  systemProgram: SystemProgram.programId
3022
4039
  }).instruction();
3023
- 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({
3024
4046
  delegate: delegatePda,
3025
4047
  originalOperator: lavarageProgram.provider.publicKey,
3026
4048
  delegatedAccount: position.publicKey,
3027
4049
  systemProgram: SystemProgram.programId
3028
- }).remainingAccounts(partnerFeeRecipient ? [{
3029
- pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false),
3030
- isSigner: false,
3031
- isWritable: true
3032
- }] : []).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();
3033
4063
  const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
3034
4064
  microLamports: prioFee.toNumber()
3035
4065
  });
3036
4066
  const messageV0 = new TransactionMessage({
3037
4067
  payerKey: lavarageProgram.provider.publicKey,
3038
4068
  recentBlockhash: blockhash,
3039
- instructions: [
3040
- removeIx,
3041
- ix,
3042
- computeFeeIx
3043
- ].filter(Boolean)
4069
+ instructions: [removeIx, ix, computeFeeIx].filter(Boolean)
3044
4070
  }).compileToV0Message();
3045
4071
  return new VersionedTransaction(messageV0);
3046
4072
  });
3047
4073
  var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, null, function* () {
3048
4074
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3049
- 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
+ );
3050
4079
  const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
3051
4080
  delegate: delegatePda,
3052
4081
  originalOperator: lavarageProgram.provider.publicKey,
@@ -3059,10 +4088,7 @@ var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, n
3059
4088
  const messageV0 = new TransactionMessage({
3060
4089
  payerKey: lavarageProgram.provider.publicKey,
3061
4090
  recentBlockhash: blockhash,
3062
- instructions: [
3063
- removeIx,
3064
- computeFeeIx
3065
- ].filter(Boolean)
4091
+ instructions: [removeIx, computeFeeIx].filter(Boolean)
3066
4092
  }).compileToV0Message();
3067
4093
  return new VersionedTransaction(messageV0);
3068
4094
  });
@@ -3099,10 +4125,20 @@ var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0
3099
4125
  trader: lavarageProgram.provider.publicKey,
3100
4126
  clock: SYSVAR_CLOCK_PUBKEY,
3101
4127
  randomAccountAsId: position.account.seed,
3102
- fromTokenAccount: getAssociatedTokenAddressSync(pool.qtType, lavarageProgram.provider.publicKey),
3103
- 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
+ ),
3104
4137
  mint: pool.qtType,
3105
- feeTokenAccount: getAssociatedTokenAddressSync(pool.qtType, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
4138
+ feeTokenAccount: getAssociatedTokenAddressSync(
4139
+ pool.qtType,
4140
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")
4141
+ ),
3106
4142
  tokenProgram: TOKEN_PROGRAM_ID
3107
4143
  }).instruction();
3108
4144
  const messageV0 = new TransactionMessage({
@@ -3122,15 +4158,28 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3122
4158
  feeBuffer32.set(feeBuffer, 0);
3123
4159
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
3124
4160
  }
3125
- if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
4161
+ if (position.account.pool.toBase58() != offer.publicKey.toBase58())
4162
+ throw "Mismatch offer";
3126
4163
  const pool = offer;
3127
4164
  const poolPubKey = offer.publicKey;
3128
4165
  const tokenAddressPubKey = new PublicKey(offer.account.collateralType);
3129
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4166
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4167
+ offer.account.collateralType
4168
+ );
3130
4169
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3131
4170
  const positionAccountPDA = position.publicKey;
3132
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
3133
- 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
+ );
3134
4183
  const jupiterSellIx = jupInstruction.instructions;
3135
4184
  const deserializeInstruction = (instruction) => {
3136
4185
  return new TransactionInstruction({
@@ -3144,13 +4193,17 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3144
4193
  });
3145
4194
  };
3146
4195
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
3147
- 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
+ );
3148
4199
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
3149
4200
  const addressLookupTableAddress = keys[index];
3150
4201
  if (accountInfo) {
3151
4202
  const addressLookupTableAccount = new AddressLookupTableAccount({
3152
4203
  key: new PublicKey(addressLookupTableAddress),
3153
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
4204
+ state: AddressLookupTableAccount.deserialize(
4205
+ Uint8Array.from(accountInfo.data)
4206
+ )
3154
4207
  });
3155
4208
  acc.push(addressLookupTableAccount);
3156
4209
  }
@@ -3175,7 +4228,10 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3175
4228
  let repaySolIx = null;
3176
4229
  let jupiterIxs = [];
3177
4230
  if (jupInstruction.instructions == void 0) {
3178
- 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({
3179
4235
  nodeWallet: pool.account.nodeWallet,
3180
4236
  positionAccount: positionAccountPDA,
3181
4237
  tradingPool: poolPubKey,
@@ -3184,17 +4240,25 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3184
4240
  clock: SYSVAR_CLOCK_PUBKEY,
3185
4241
  randomAccountAsId: position.account.seed,
3186
4242
  feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
3187
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
3188
- pubkey: partnerFeeRecipient,
3189
- isSigner: false,
3190
- isWritable: true
3191
- }, {
3192
- pubkey: partnerFeeMarkupAsPkey,
3193
- isSigner: false,
3194
- isWritable: false
3195
- }] : []).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();
3196
4257
  } else {
3197
- 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({
3198
4262
  nodeWallet: pool.account.nodeWallet,
3199
4263
  positionAccount: positionAccountPDA,
3200
4264
  tradingPool: poolPubKey,
@@ -3203,22 +4267,37 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3203
4267
  clock: SYSVAR_CLOCK_PUBKEY,
3204
4268
  randomAccountAsId: position.account.seed,
3205
4269
  feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
3206
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
3207
- pubkey: partnerFeeRecipient,
3208
- isSigner: false,
3209
- isWritable: true
3210
- }, {
3211
- pubkey: partnerFeeMarkupAsPkey,
3212
- isSigner: false,
3213
- isWritable: false
3214
- }] : []).instruction();
3215
- 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;
3216
4290
  jupiterIxs = [
3217
4291
  ...setupInstructions.map(deserializeInstruction),
3218
4292
  deserializeInstruction(swapInstructionPayload),
3219
4293
  deserializeInstruction(cleanupInstruction)
3220
4294
  ];
3221
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(["5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi", ...addressLookupTableAddresses]));
4295
+ addressLookupTableAccounts.push(
4296
+ ...yield getAddressLookupTableAccounts([
4297
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi",
4298
+ ...addressLookupTableAddresses
4299
+ ])
4300
+ );
3222
4301
  }
3223
4302
  const profit = new BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3224
4303
  let createAssociatedTokenAccountInstruction2 = createAssociatedTokenAccountIdempotentInstruction(
@@ -3230,7 +4309,9 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3230
4309
  );
3231
4310
  const allInstructions = [
3232
4311
  ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
3233
- ((_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,
3234
4315
  toTokenAccount.instruction,
3235
4316
  closePositionIx,
3236
4317
  ...jupiterIxs,
@@ -3254,17 +4335,30 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3254
4335
  feeBuffer32.set(feeBuffer, 0);
3255
4336
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
3256
4337
  }
3257
- if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
4338
+ if (position.account.pool.toBase58() != offer.publicKey.toBase58())
4339
+ throw "Mismatch offer";
3258
4340
  const pool = offer;
3259
4341
  const poolPubKey = offer.publicKey;
3260
4342
  const tokenAddressPubKey = new PublicKey(offer.account.collateralType);
3261
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4343
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4344
+ offer.account.collateralType
4345
+ );
3262
4346
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3263
4347
  const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
3264
4348
  const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
3265
4349
  const positionAccountPDA = position.publicKey;
3266
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
3267
- 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
+ );
3268
4362
  const jupiterSellIx = jupInstruction.instructions;
3269
4363
  const deserializeInstruction = (instruction) => {
3270
4364
  return new TransactionInstruction({
@@ -3278,13 +4372,17 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3278
4372
  });
3279
4373
  };
3280
4374
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
3281
- 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
+ );
3282
4378
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
3283
4379
  const addressLookupTableAddress = keys[index];
3284
4380
  if (accountInfo) {
3285
4381
  const addressLookupTableAccount = new AddressLookupTableAccount({
3286
4382
  key: new PublicKey(addressLookupTableAddress),
3287
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
4383
+ state: AddressLookupTableAccount.deserialize(
4384
+ Uint8Array.from(accountInfo.data)
4385
+ )
3288
4386
  });
3289
4387
  acc.push(addressLookupTableAccount);
3290
4388
  }
@@ -3309,7 +4407,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3309
4407
  let repaySolIx = null;
3310
4408
  let jupiterIxs = [];
3311
4409
  if (jupInstruction.instructions == void 0) {
3312
- 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({
3313
4414
  nodeWallet: pool.account.nodeWallet,
3314
4415
  positionAccount: positionAccountPDA,
3315
4416
  tradingPool: poolPubKey,
@@ -3317,22 +4418,50 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3317
4418
  systemProgram: SystemProgram.programId,
3318
4419
  clock: SYSVAR_CLOCK_PUBKEY,
3319
4420
  randomAccountAsId: position.account.seed,
3320
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
3321
- 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
+ ),
3322
4433
  tokenProgram: quoteTokenProgram,
3323
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
4434
+ toTokenAccount: getAssociatedTokenAddressSync(
4435
+ quoteToken,
4436
+ pool.account.nodeWallet,
4437
+ true,
4438
+ quoteTokenProgram
4439
+ ),
3324
4440
  mint: quoteToken
3325
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
3326
- pubkey: getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false, quoteTokenProgram),
3327
- isSigner: false,
3328
- isWritable: true
3329
- }, {
3330
- pubkey: partnerFeeMarkupAsPkey,
3331
- isSigner: false,
3332
- isWritable: false
3333
- }] : []).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();
3334
4460
  } else {
3335
- 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({
3336
4465
  nodeWallet: pool.account.nodeWallet,
3337
4466
  positionAccount: positionAccountPDA,
3338
4467
  tradingPool: poolPubKey,
@@ -3340,27 +4469,58 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3340
4469
  systemProgram: SystemProgram.programId,
3341
4470
  clock: SYSVAR_CLOCK_PUBKEY,
3342
4471
  randomAccountAsId: position.account.seed,
3343
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
3344
- 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
+ ),
3345
4484
  tokenProgram: quoteTokenProgram,
3346
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
4485
+ toTokenAccount: getAssociatedTokenAddressSync(
4486
+ quoteToken,
4487
+ pool.account.nodeWallet,
4488
+ true,
4489
+ quoteTokenProgram
4490
+ ),
3347
4491
  mint: quoteToken
3348
- }).remainingAccounts(partnerFeeRecipient && partnerFeeMarkupAsPkey ? [{
3349
- pubkey: partnerFeeRecipient,
3350
- isSigner: false,
3351
- isWritable: true
3352
- }, {
3353
- pubkey: partnerFeeMarkupAsPkey,
3354
- isSigner: false,
3355
- isWritable: false
3356
- }] : []).instruction();
3357
- 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;
3358
4512
  jupiterIxs = [
3359
4513
  ...setupInstructions.filter((i) => !!i).map(deserializeInstruction),
3360
4514
  swapInstructionPayload ? deserializeInstruction(swapInstructionPayload) : null,
3361
4515
  cleanupInstruction ? deserializeInstruction(cleanupInstruction) : null
3362
4516
  ].filter((i) => !!i);
3363
- 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
+ );
3364
4524
  }
3365
4525
  const profit = new BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3366
4526
  let createAssociatedTokenAccountInstruction2 = createAssociatedTokenAccountIdempotentInstruction(
@@ -3372,7 +4532,9 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3372
4532
  );
3373
4533
  const allInstructions = [
3374
4534
  ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
3375
- ((_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,
3376
4538
  toTokenAccount.instruction,
3377
4539
  closePositionIx,
3378
4540
  ...jupiterIxs,
@@ -3387,12 +4549,16 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3387
4549
  return tx;
3388
4550
  });
3389
4551
  var getDelegateAccounts = (lavarageProgram, userPubKey) => __async(void 0, null, function* () {
3390
- const delegateAccounts = yield lavarageProgram.account.delegate.all(userPubKey ? [{
3391
- memcmp: {
3392
- offset: 104,
3393
- bytes: userPubKey.toBase58()
3394
- }
3395
- }] : 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
+ );
3396
4562
  return delegateAccounts.map((d) => __spreadProps(__spreadValues({}, d), {
3397
4563
  parsed: {
3398
4564
  tpPrice: new BN(d.account.field1),
@@ -3414,12 +4580,32 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3414
4580
  const positionAccountPDA = position.publicKey;
3415
4581
  const newPosition1Seed = Keypair.generate().publicKey;
3416
4582
  const newPosition2Seed = Keypair.generate().publicKey;
3417
- const newPosition1AccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPosition1Seed);
3418
- const newPosition2AccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPosition2Seed);
3419
- 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
+ );
3420
4596
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3421
- const newPosition1TokenAccount = getAssociatedTokenAddressSync(offer.account.collateralType, newPosition1AccountPDA, true, tokenProgram);
3422
- 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
+ );
3423
4609
  const createNewPosition1TokenAccountIx = createAssociatedTokenAccountInstruction(
3424
4610
  lavarageProgram.provider.publicKey,
3425
4611
  newPosition1TokenAccount,
@@ -3434,7 +4620,11 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3434
4620
  offer.account.collateralType,
3435
4621
  tokenProgram
3436
4622
  );
3437
- 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({
3438
4628
  originalPosition: positionAccountPDA,
3439
4629
  newPositionOne: newPosition1AccountPDA,
3440
4630
  newPositionTwo: newPosition2AccountPDA,
@@ -3442,7 +4632,12 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3442
4632
  systemProgram: SystemProgram.programId,
3443
4633
  mint: offer.account.collateralType,
3444
4634
  tokenProgram,
3445
- originalPositionTokenAccount: getAssociatedTokenAddressSync(offer.account.collateralType, positionAccountPDA, true, tokenProgram),
4635
+ originalPositionTokenAccount: getAssociatedTokenAddressSync(
4636
+ offer.account.collateralType,
4637
+ positionAccountPDA,
4638
+ true,
4639
+ tokenProgram
4640
+ ),
3446
4641
  newPositionTokenAccountOne: newPosition1TokenAccount,
3447
4642
  newPositionTokenAccountTwo: newPosition2TokenAccount
3448
4643
  }).instruction();
@@ -3468,10 +4663,21 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3468
4663
  const positionAccountPDA1 = position1.publicKey;
3469
4664
  const positionAccountPDA2 = position2.publicKey;
3470
4665
  const newPositionSeed = Keypair.generate().publicKey;
3471
- const newPositionAccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPositionSeed);
3472
- 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
+ );
3473
4674
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3474
- const newPositionTokenAccount = getAssociatedTokenAddressSync(offer.account.collateralType, newPositionAccountPDA, true, tokenProgram);
4675
+ const newPositionTokenAccount = getAssociatedTokenAddressSync(
4676
+ offer.account.collateralType,
4677
+ newPositionAccountPDA,
4678
+ true,
4679
+ tokenProgram
4680
+ );
3475
4681
  const createNewPositionTokenAccountIx = createAssociatedTokenAccountInstruction(
3476
4682
  lavarageProgram.provider.publicKey,
3477
4683
  newPositionTokenAccount,
@@ -3487,8 +4693,18 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3487
4693
  systemProgram: SystemProgram.programId,
3488
4694
  mint: offer.account.collateralType,
3489
4695
  tokenProgram,
3490
- positionOneTokenAccount: getAssociatedTokenAddressSync(offer.account.collateralType, positionAccountPDA1, true, tokenProgram),
3491
- 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
+ ),
3492
4708
  mergedPositionTokenAccount: newPositionTokenAccount
3493
4709
  }).instruction();
3494
4710
  const computeBudgetIx = ComputeBudgetProgram.setComputeUnitPrice({
@@ -3511,19 +4727,28 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3511
4727
  export {
3512
4728
  IDL,
3513
4729
  lavaragev2_exports as IDLV2,
4730
+ closePositionEvm,
3514
4731
  closeTradeV1,
3515
4732
  closeTradeV2,
3516
4733
  createTpDelegate,
3517
4734
  getAllPositions,
3518
4735
  getClosedPositions,
4736
+ getClosedPositionsEvm,
4737
+ getCollateralInfoEvm,
3519
4738
  getDelegateAccounts,
3520
4739
  getLiquidatedPositions,
4740
+ getLiquidatedPositionsEvm,
4741
+ getLoanEvm,
3521
4742
  getOffers,
4743
+ getOffersEvm,
3522
4744
  getOpenPositions,
3523
4745
  getPda,
3524
4746
  getPositionAccountPDA,
4747
+ getPositionsEvm,
4748
+ getUserLoansEvm,
3525
4749
  mergePositionV2,
3526
4750
  modifyTpDelegate,
4751
+ openPositionEvm,
3527
4752
  openTradeV1,
3528
4753
  openTradeV2,
3529
4754
  partialRepayV1,