@lavarage/sdk 6.4.7 → 6.6.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,932 @@ 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* (provider, borrowerOpsContractAddress, {
3403
+ buyingCode,
3404
+ tokenCollateral,
3405
+ borrowAmount,
3406
+ tokenHolder,
3407
+ inchRouter,
3408
+ integratorFeeAddress = ZeroAddress,
3409
+ buyerContribution,
3410
+ gasLimit,
3411
+ gasPrice
3412
+ }) {
3413
+ const contract = new Contract(
3414
+ borrowerOpsContractAddress,
3415
+ borrowerOperationsAbi,
3416
+ provider
3417
+ );
3418
+ const txOptions = {
3419
+ value: buyerContribution
3420
+ };
3421
+ if (gasLimit) txOptions.gasLimit = gasLimit;
3422
+ if (gasPrice) txOptions.gasPrice = gasPrice;
3423
+ return contract.buy.populateTransaction(
3424
+ buyingCode,
3425
+ tokenCollateral,
3426
+ borrowAmount,
3427
+ tokenHolder,
3428
+ inchRouter,
3429
+ integratorFeeAddress,
3430
+ txOptions
3431
+ );
3432
+ });
3433
+ var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (provider, borrowerOpsContractAddress, {
3434
+ loanId,
3435
+ sellingCode,
3436
+ tokenHolder,
3437
+ inchRouter,
3438
+ integratorFeeAddress = ZeroAddress,
3439
+ gasLimit,
3440
+ gasPrice
3441
+ }) {
3442
+ const contract = new Contract(
3443
+ borrowerOpsContractAddress,
3444
+ borrowerOperationsAbi,
3445
+ provider
3446
+ );
3447
+ const txOptions = {};
3448
+ if (gasLimit) txOptions.gasLimit = gasLimit;
3449
+ if (gasPrice) txOptions.gasPrice = gasPrice;
3450
+ return contract.sell.populateTransaction(
3451
+ loanId,
3452
+ sellingCode,
3453
+ tokenHolder,
3454
+ inchRouter,
3455
+ integratorFeeAddress,
3456
+ Object.keys(txOptions).length > 0 ? txOptions : {}
3457
+ );
3458
+ });
3459
+ function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
3460
+ return __async(this, null, function* () {
3461
+ const contract = new Contract(
3462
+ borrowerOpsContractAddress,
3463
+ borrowerOperationsAbi,
3464
+ provider
3465
+ );
3466
+ const filter = contract.filters.Buy();
3467
+ const events = yield contract.queryFilter(filter, fromBlock);
3468
+ return events.map((event) => {
3469
+ const {
3470
+ buyer,
3471
+ tokenCollateral,
3472
+ loanId,
3473
+ openingPositionSize,
3474
+ collateralAmount,
3475
+ initialMargin
3476
+ } = event.args;
3477
+ return {
3478
+ trader: buyer,
3479
+ tokenCollateral,
3480
+ loanId,
3481
+ openingPositionSize,
3482
+ collateralAmount,
3483
+ initialMargin
3484
+ };
3485
+ });
3486
+ });
3487
+ }
3488
+ function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
3489
+ return __async(this, null, function* () {
3490
+ const contract = new Contract(
3491
+ borrowerOpsContractAddress,
3492
+ borrowerOperationsAbi,
3493
+ provider
3494
+ );
3495
+ const filter = contract.filters.Sell();
3496
+ const events = yield contract.queryFilter(filter, fromBlock);
3497
+ return events.map((event) => {
3498
+ const {
3499
+ buyer,
3500
+ tokenCollateral,
3501
+ loanId,
3502
+ closingPositionSize,
3503
+ profit
3504
+ } = event.args;
3505
+ return {
3506
+ trader: buyer,
3507
+ tokenCollateral,
3508
+ loanId,
3509
+ closingPositionSize,
3510
+ profit
3511
+ };
3512
+ });
3513
+ });
3514
+ }
3515
+ function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
3516
+ return __async(this, null, function* () {
3517
+ const contract = new Contract(
3518
+ borrowerOpsContractAddress,
3519
+ borrowerOperationsAbi,
3520
+ provider
3521
+ );
3522
+ const filter = contract.filters.Liquidation();
3523
+ const events = yield contract.queryFilter(filter, fromBlock);
3524
+ return events.map((event) => {
3525
+ const {
3526
+ borrower,
3527
+ tokenCollateral,
3528
+ loanId,
3529
+ closingPositionSize,
3530
+ liquidatorRepaidAmount
3531
+ } = event.args;
3532
+ return {
3533
+ trader: borrower,
3534
+ tokenCollateral,
3535
+ loanId,
3536
+ closingPositionSize,
3537
+ liquidatorRepaidAmount
3538
+ };
3539
+ });
3540
+ });
3541
+ }
3542
+ function getLoanEvm(provider, tokenHolderContractAddress, loanId) {
3543
+ return __async(this, null, function* () {
3544
+ const contract = new Contract(
3545
+ tokenHolderContractAddress,
3546
+ tokenHolderAbi,
3547
+ provider
3548
+ );
3549
+ return contract.loans(loanId);
3550
+ });
3551
+ }
3552
+ function getUserLoansEvm(provider, tokenHolderContractAddress, userAddress) {
3553
+ return __async(this, null, function* () {
3554
+ const contract = new Contract(
3555
+ tokenHolderContractAddress,
3556
+ tokenHolderAbi,
3557
+ provider
3558
+ );
3559
+ const nextLoanId = yield contract.nextLoanId();
3560
+ const userLoans = [];
3561
+ for (let i = 0; i < nextLoanId; i++) {
3562
+ const loan = yield contract.loans(i);
3563
+ if (loan.borrower.toLowerCase() === userAddress.toLowerCase()) {
3564
+ userLoans.push(loan);
3565
+ }
3566
+ }
3567
+ return userLoans;
3568
+ });
3569
+ }
3570
+ function getCollateralInfoEvm(provider, tokenHolderContractAddress, collateralAddress) {
3571
+ return __async(this, null, function* () {
3572
+ const contract = new Contract(
3573
+ tokenHolderContractAddress,
3574
+ tokenHolderAbi,
3575
+ provider
3576
+ );
3577
+ return contract.collateralMapping(collateralAddress);
3578
+ });
3579
+ }
3580
+ function getOffersEvm(provider, tokenHolderContractAddress, collateralAddresses) {
3581
+ return __async(this, null, function* () {
3582
+ const contract = new Contract(
3583
+ tokenHolderContractAddress,
3584
+ tokenHolderAbi,
3585
+ provider
3586
+ );
3587
+ const activeCollaterals = [];
3588
+ for (const address of collateralAddresses) {
3589
+ const collateral = yield contract.collateralMapping(address);
3590
+ if (collateral.active) {
3591
+ activeCollaterals.push({
3592
+ address,
3593
+ collateral
3594
+ });
3595
+ }
3596
+ }
3597
+ return activeCollaterals;
3598
+ });
3599
+ }
3600
+
2682
3601
  // index.ts
2683
3602
  function getPda(seed, programId) {
2684
3603
  const seedsBuffer = Array.isArray(seed) ? seed : [seed];
2685
3604
  return PublicKey.findProgramAddressSync(seedsBuffer, programId)[0];
2686
3605
  }
2687
3606
  function getPositionAccountPDA(lavarageProgram, offer, seed) {
2688
- return getPda([Buffer.from("position"), lavarageProgram.provider.publicKey.toBuffer(), offer.publicKey.toBuffer(), seed.toBuffer()], lavarageProgram.programId);
3607
+ return getPda(
3608
+ [
3609
+ Buffer.from("position"),
3610
+ lavarageProgram.provider.publicKey.toBuffer(),
3611
+ offer.publicKey.toBuffer(),
3612
+ seed.toBuffer()
3613
+ ],
3614
+ lavarageProgram.programId
3615
+ );
2689
3616
  }
2690
3617
  function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress, tokenProgram) {
2691
3618
  return __async(this, null, function* () {
2692
- const associatedTokenAddress = getAssociatedTokenAddressSync(tokenAddress, ownerPublicKey, true, tokenProgram, ASSOCIATED_TOKEN_PROGRAM_ID);
3619
+ const associatedTokenAddress = getAssociatedTokenAddressSync(
3620
+ tokenAddress,
3621
+ ownerPublicKey,
3622
+ true,
3623
+ tokenProgram,
3624
+ ASSOCIATED_TOKEN_PROGRAM_ID
3625
+ );
2693
3626
  const instruction = createAssociatedTokenAccountIdempotentInstruction(
2694
3627
  lavarageProgram.provider.publicKey,
2695
3628
  associatedTokenAddress,
@@ -2738,23 +3671,27 @@ var getClosedPositions = (lavarageProgram) => __async(void 0, null, function* ()
2738
3671
  bytes: bs58.encode(Uint8Array.from(valueBuffer))
2739
3672
  }
2740
3673
  }
2741
- ])).concat(yield lavarageProgram.account.position.all([
2742
- { dataSize: 178 },
2743
- {
2744
- memcmp: {
2745
- offset: 40,
2746
- bytes: bs58.encode(Uint8Array.from(valueBuffer2))
3674
+ ])).concat(
3675
+ yield lavarageProgram.account.position.all([
3676
+ { dataSize: 178 },
3677
+ {
3678
+ memcmp: {
3679
+ offset: 40,
3680
+ bytes: bs58.encode(Uint8Array.from(valueBuffer2))
3681
+ }
2747
3682
  }
2748
- }
2749
- ])).concat(yield lavarageProgram.account.position.all([
2750
- { dataSize: 178 },
2751
- {
2752
- memcmp: {
2753
- offset: 40,
2754
- bytes: bs58.encode(Uint8Array.from(valueBuffer3))
3683
+ ])
3684
+ ).concat(
3685
+ yield lavarageProgram.account.position.all([
3686
+ { dataSize: 178 },
3687
+ {
3688
+ memcmp: {
3689
+ offset: 40,
3690
+ bytes: bs58.encode(Uint8Array.from(valueBuffer3))
3691
+ }
2755
3692
  }
2756
- }
2757
- ]));
3693
+ ])
3694
+ );
2758
3695
  });
2759
3696
  var getLiquidatedPositions = (lavarageProgram) => {
2760
3697
  const value = BigInt(9999);
@@ -2771,9 +3708,7 @@ var getLiquidatedPositions = (lavarageProgram) => {
2771
3708
  ]);
2772
3709
  };
2773
3710
  var getAllPositions = (lavarageProgram) => {
2774
- return lavarageProgram.account.position.all([
2775
- { dataSize: 178 }
2776
- ]);
3711
+ return lavarageProgram.account.position.all([{ dataSize: 178 }]);
2777
3712
  };
2778
3713
  var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
2779
3714
  let partnerFeeMarkupAsPkey;
@@ -2784,11 +3719,27 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2784
3719
  feeBuffer32.set(feeBuffer, 0);
2785
3720
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
2786
3721
  }
2787
- const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2788
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
3722
+ const positionAccount = getPositionAccountPDA(
3723
+ lavarageProgram,
3724
+ offer,
3725
+ randomSeed.publicKey
3726
+ );
3727
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
3728
+ offer.account.collateralType
3729
+ );
2789
3730
  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);
3731
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3732
+ lavarageProgram,
3733
+ lavarageProgram.provider.publicKey,
3734
+ offer.account.collateralType,
3735
+ tokenProgram
3736
+ );
3737
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3738
+ lavarageProgram,
3739
+ positionAccount,
3740
+ offer.account.collateralType,
3741
+ tokenProgram
3742
+ );
2792
3743
  const tokenAccountCreationTx = new Transaction();
2793
3744
  if (fromTokenAccount.instruction) {
2794
3745
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2797,7 +3748,11 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2797
3748
  tokenAccountCreationTx.add(toTokenAccount.instruction);
2798
3749
  }
2799
3750
  const instructionsJup = jupInstruction.instructions;
2800
- const { setupInstructions, swapInstruction: swapInstructionPayload, addressLookupTableAddresses } = instructionsJup;
3751
+ const {
3752
+ setupInstructions,
3753
+ swapInstruction: swapInstructionPayload,
3754
+ addressLookupTableAddresses
3755
+ } = instructionsJup;
2801
3756
  const deserializeInstruction = (instruction) => {
2802
3757
  return new TransactionInstruction({
2803
3758
  programId: new PublicKey(instruction.programId),
@@ -2810,13 +3765,17 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2810
3765
  });
2811
3766
  };
2812
3767
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
2813
- const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new PublicKey(key)));
3768
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
3769
+ keys.map((key) => new PublicKey(key))
3770
+ );
2814
3771
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
2815
3772
  const addressLookupTableAddress = keys[index];
2816
3773
  if (accountInfo) {
2817
3774
  const addressLookupTableAccount = new AddressLookupTableAccount({
2818
3775
  key: new PublicKey(addressLookupTableAddress),
2819
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
3776
+ state: AddressLookupTableAccount.deserialize(
3777
+ Uint8Array.from(accountInfo.data)
3778
+ )
2820
3779
  });
2821
3780
  acc.push(addressLookupTableAccount);
2822
3781
  }
@@ -2824,9 +3783,17 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2824
3783
  }, new Array());
2825
3784
  });
2826
3785
  const addressLookupTableAccounts = [];
2827
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(["5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi", ...addressLookupTableAddresses]));
3786
+ addressLookupTableAccounts.push(
3787
+ ...yield getAddressLookupTableAccounts([
3788
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi",
3789
+ ...addressLookupTableAddresses
3790
+ ])
3791
+ );
2828
3792
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2829
- const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(new BN((marginSOL.toNumber() * leverage).toFixed(0)), marginSOL).accountsStrict({
3793
+ const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
3794
+ new BN((marginSOL.toNumber() * leverage).toFixed(0)),
3795
+ marginSOL
3796
+ ).accountsStrict({
2830
3797
  nodeWallet: offer.account.nodeWallet,
2831
3798
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
2832
3799
  tradingPool: offer.publicKey,
@@ -2836,15 +3803,20 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2836
3803
  clock: SYSVAR_CLOCK_PUBKEY,
2837
3804
  randomAccountAsId: randomSeed.publicKey.toBase58(),
2838
3805
  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();
3806
+ }).remainingAccounts(
3807
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
3808
+ {
3809
+ pubkey: partnerFeeRecipient,
3810
+ isSigner: false,
3811
+ isWritable: true
3812
+ },
3813
+ {
3814
+ pubkey: partnerFeeMarkupAsPkey,
3815
+ isSigner: false,
3816
+ isWritable: false
3817
+ }
3818
+ ] : []
3819
+ ).instruction();
2848
3820
  const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
2849
3821
  tradingPool: offer.publicKey,
2850
3822
  trader: lavarageProgram.provider.publicKey,
@@ -2882,13 +3854,29 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2882
3854
  feeBuffer32.set(feeBuffer, 0);
2883
3855
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
2884
3856
  }
2885
- const positionAccount = getPositionAccountPDA(lavarageProgram, offer, randomSeed.publicKey);
2886
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
3857
+ const positionAccount = getPositionAccountPDA(
3858
+ lavarageProgram,
3859
+ offer,
3860
+ randomSeed.publicKey
3861
+ );
3862
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
3863
+ offer.account.collateralType
3864
+ );
2887
3865
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
2888
3866
  const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
2889
3867
  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);
3868
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3869
+ lavarageProgram,
3870
+ lavarageProgram.provider.publicKey,
3871
+ offer.account.collateralType,
3872
+ tokenProgram
3873
+ );
3874
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
3875
+ lavarageProgram,
3876
+ positionAccount,
3877
+ offer.account.collateralType,
3878
+ tokenProgram
3879
+ );
2892
3880
  const tokenAccountCreationTx = new Transaction();
2893
3881
  if (fromTokenAccount.instruction) {
2894
3882
  tokenAccountCreationTx.add(fromTokenAccount.instruction);
@@ -2897,7 +3885,11 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2897
3885
  tokenAccountCreationTx.add(toTokenAccount.instruction);
2898
3886
  }
2899
3887
  const instructionsJup = jupInstruction.instructions;
2900
- const { setupInstructions, swapInstruction: swapInstructionPayload, addressLookupTableAddresses } = instructionsJup;
3888
+ const {
3889
+ setupInstructions,
3890
+ swapInstruction: swapInstructionPayload,
3891
+ addressLookupTableAddresses
3892
+ } = instructionsJup;
2901
3893
  const deserializeInstruction = (instruction) => {
2902
3894
  return new TransactionInstruction({
2903
3895
  programId: new PublicKey(instruction.programId),
@@ -2910,13 +3902,17 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2910
3902
  });
2911
3903
  };
2912
3904
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
2913
- const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new PublicKey(key)));
3905
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
3906
+ keys.map((key) => new PublicKey(key))
3907
+ );
2914
3908
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
2915
3909
  const addressLookupTableAddress = keys[index];
2916
3910
  if (accountInfo) {
2917
3911
  const addressLookupTableAccount = new AddressLookupTableAccount({
2918
3912
  key: new PublicKey(addressLookupTableAddress),
2919
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
3913
+ state: AddressLookupTableAccount.deserialize(
3914
+ Uint8Array.from(accountInfo.data)
3915
+ )
2920
3916
  });
2921
3917
  acc.push(addressLookupTableAccount);
2922
3918
  }
@@ -2924,9 +3920,18 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2924
3920
  }, new Array());
2925
3921
  });
2926
3922
  const addressLookupTableAccounts = [];
2927
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts([...addressLookupTableAddresses, getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()), "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"]));
3923
+ addressLookupTableAccounts.push(
3924
+ ...yield getAddressLookupTableAccounts([
3925
+ ...addressLookupTableAddresses,
3926
+ getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()),
3927
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"
3928
+ ])
3929
+ );
2928
3930
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
2929
- const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(new BN((marginSOL.toNumber() * leverage).toFixed(0)), marginSOL).accountsStrict({
3931
+ const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
3932
+ new BN((marginSOL.toNumber() * leverage).toFixed(0)),
3933
+ marginSOL
3934
+ ).accountsStrict({
2930
3935
  nodeWallet: offer.account.nodeWallet,
2931
3936
  instructions: SYSVAR_INSTRUCTIONS_PUBKEY,
2932
3937
  tradingPool: offer.publicKey,
@@ -2935,19 +3940,44 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2935
3940
  systemProgram: SystemProgram.programId,
2936
3941
  clock: SYSVAR_CLOCK_PUBKEY,
2937
3942
  randomAccountAsId: randomSeed.publicKey.toBase58(),
2938
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), true, quoteTokenProgram),
2939
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, true, quoteTokenProgram),
3943
+ feeTokenAccount: getAssociatedTokenAddressSync(
3944
+ quoteToken,
3945
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
3946
+ true,
3947
+ quoteTokenProgram
3948
+ ),
3949
+ toTokenAccount: getAssociatedTokenAddressSync(
3950
+ quoteToken,
3951
+ lavarageProgram.provider.publicKey,
3952
+ true,
3953
+ quoteTokenProgram
3954
+ ),
2940
3955
  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();
3956
+ fromTokenAccount: getAssociatedTokenAddressSync(
3957
+ quoteToken,
3958
+ offer.account.nodeWallet,
3959
+ true,
3960
+ quoteTokenProgram
3961
+ )
3962
+ }).remainingAccounts(
3963
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
3964
+ {
3965
+ pubkey: getAssociatedTokenAddressSync(
3966
+ quoteToken,
3967
+ partnerFeeRecipient,
3968
+ false,
3969
+ quoteTokenProgram
3970
+ ),
3971
+ isSigner: false,
3972
+ isWritable: true
3973
+ },
3974
+ {
3975
+ pubkey: partnerFeeMarkupAsPkey,
3976
+ isSigner: false,
3977
+ isWritable: false
3978
+ }
3979
+ ] : []
3980
+ ).instruction();
2951
3981
  const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
2952
3982
  tradingPool: offer.publicKey,
2953
3983
  trader: lavarageProgram.provider.publicKey,
@@ -2978,65 +4008,93 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
2978
4008
  });
2979
4009
  var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
2980
4010
  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),
4011
+ const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
4012
+ tpPrice,
4013
+ tpTolerence,
4014
+ new PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"),
4015
+ new BN(1e4)
4016
+ ).accountsStrict({
4017
+ delegate: getPda(
4018
+ [Buffer.from("delegate"), position.publicKey.toBuffer()],
4019
+ lavarageProgram.programId
4020
+ ),
2983
4021
  originalOperator: lavarageProgram.provider.publicKey,
2984
4022
  delegatedAccount: position.publicKey,
2985
4023
  systemProgram: SystemProgram.programId
2986
- }).remainingAccounts(partnerFeeRecipient ? [{
2987
- pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false),
2988
- isSigner: false,
2989
- isWritable: true
2990
- }] : []).instruction();
4024
+ }).remainingAccounts(
4025
+ partnerFeeRecipient ? [
4026
+ {
4027
+ pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(
4028
+ quoteToken,
4029
+ partnerFeeRecipient,
4030
+ false
4031
+ ),
4032
+ isSigner: false,
4033
+ isWritable: true
4034
+ }
4035
+ ] : []
4036
+ ).instruction();
2991
4037
  const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
2992
4038
  microLamports: prioFee.toNumber()
2993
4039
  });
2994
4040
  const messageV0 = new TransactionMessage({
2995
4041
  payerKey: lavarageProgram.provider.publicKey,
2996
4042
  recentBlockhash: blockhash,
2997
- instructions: [
2998
- ix,
2999
- computeFeeIx
3000
- ].filter(Boolean)
4043
+ instructions: [ix, computeFeeIx].filter(Boolean)
3001
4044
  }).compileToV0Message();
3002
4045
  return new VersionedTransaction(messageV0);
3003
4046
  });
3004
4047
  var modifyTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
3005
4048
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3006
- const delegatePda = getPda([Buffer.from("delegate"), position.publicKey.toBuffer()], lavarageProgram.programId);
4049
+ const delegatePda = getPda(
4050
+ [Buffer.from("delegate"), position.publicKey.toBuffer()],
4051
+ lavarageProgram.programId
4052
+ );
3007
4053
  const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
3008
4054
  delegate: delegatePda,
3009
4055
  originalOperator: lavarageProgram.provider.publicKey,
3010
4056
  delegatedAccount: position.publicKey,
3011
4057
  systemProgram: SystemProgram.programId
3012
4058
  }).instruction();
3013
- const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(tpPrice, tpTolerence, new PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"), new BN(1e4)).accountsStrict({
4059
+ const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
4060
+ tpPrice,
4061
+ tpTolerence,
4062
+ new PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"),
4063
+ new BN(1e4)
4064
+ ).accountsStrict({
3014
4065
  delegate: delegatePda,
3015
4066
  originalOperator: lavarageProgram.provider.publicKey,
3016
4067
  delegatedAccount: position.publicKey,
3017
4068
  systemProgram: SystemProgram.programId
3018
- }).remainingAccounts(partnerFeeRecipient ? [{
3019
- pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(quoteToken, partnerFeeRecipient, false),
3020
- isSigner: false,
3021
- isWritable: true
3022
- }] : []).instruction();
4069
+ }).remainingAccounts(
4070
+ partnerFeeRecipient ? [
4071
+ {
4072
+ pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : getAssociatedTokenAddressSync(
4073
+ quoteToken,
4074
+ partnerFeeRecipient,
4075
+ false
4076
+ ),
4077
+ isSigner: false,
4078
+ isWritable: true
4079
+ }
4080
+ ] : []
4081
+ ).instruction();
3023
4082
  const computeFeeIx = ComputeBudgetProgram.setComputeUnitPrice({
3024
4083
  microLamports: prioFee.toNumber()
3025
4084
  });
3026
4085
  const messageV0 = new TransactionMessage({
3027
4086
  payerKey: lavarageProgram.provider.publicKey,
3028
4087
  recentBlockhash: blockhash,
3029
- instructions: [
3030
- removeIx,
3031
- ix,
3032
- computeFeeIx
3033
- ].filter(Boolean)
4088
+ instructions: [removeIx, ix, computeFeeIx].filter(Boolean)
3034
4089
  }).compileToV0Message();
3035
4090
  return new VersionedTransaction(messageV0);
3036
4091
  });
3037
4092
  var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, null, function* () {
3038
4093
  const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
3039
- const delegatePda = getPda([Buffer.from("delegate"), position.publicKey.toBuffer()], lavarageProgram.programId);
4094
+ const delegatePda = getPda(
4095
+ [Buffer.from("delegate"), position.publicKey.toBuffer()],
4096
+ lavarageProgram.programId
4097
+ );
3040
4098
  const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
3041
4099
  delegate: delegatePda,
3042
4100
  originalOperator: lavarageProgram.provider.publicKey,
@@ -3049,10 +4107,7 @@ var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, n
3049
4107
  const messageV0 = new TransactionMessage({
3050
4108
  payerKey: lavarageProgram.provider.publicKey,
3051
4109
  recentBlockhash: blockhash,
3052
- instructions: [
3053
- removeIx,
3054
- computeFeeIx
3055
- ].filter(Boolean)
4110
+ instructions: [removeIx, computeFeeIx].filter(Boolean)
3056
4111
  }).compileToV0Message();
3057
4112
  return new VersionedTransaction(messageV0);
3058
4113
  });
@@ -3089,10 +4144,20 @@ var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0
3089
4144
  trader: lavarageProgram.provider.publicKey,
3090
4145
  clock: SYSVAR_CLOCK_PUBKEY,
3091
4146
  randomAccountAsId: position.account.seed,
3092
- fromTokenAccount: getAssociatedTokenAddressSync(pool.qtType, lavarageProgram.provider.publicKey),
3093
- toTokenAccount: getAssociatedTokenAddressSync(pool.qtType, pool.nodeWallet, true),
4147
+ fromTokenAccount: getAssociatedTokenAddressSync(
4148
+ pool.qtType,
4149
+ lavarageProgram.provider.publicKey
4150
+ ),
4151
+ toTokenAccount: getAssociatedTokenAddressSync(
4152
+ pool.qtType,
4153
+ pool.nodeWallet,
4154
+ true
4155
+ ),
3094
4156
  mint: pool.qtType,
3095
- feeTokenAccount: getAssociatedTokenAddressSync(pool.qtType, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")),
4157
+ feeTokenAccount: getAssociatedTokenAddressSync(
4158
+ pool.qtType,
4159
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")
4160
+ ),
3096
4161
  tokenProgram: TOKEN_PROGRAM_ID
3097
4162
  }).instruction();
3098
4163
  const messageV0 = new TransactionMessage({
@@ -3112,15 +4177,28 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3112
4177
  feeBuffer32.set(feeBuffer, 0);
3113
4178
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
3114
4179
  }
3115
- if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
4180
+ if (position.account.pool.toBase58() != offer.publicKey.toBase58())
4181
+ throw "Mismatch offer";
3116
4182
  const pool = offer;
3117
4183
  const poolPubKey = offer.publicKey;
3118
4184
  const tokenAddressPubKey = new PublicKey(offer.account.collateralType);
3119
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4185
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4186
+ offer.account.collateralType
4187
+ );
3120
4188
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3121
4189
  const positionAccountPDA = position.publicKey;
3122
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
3123
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey, tokenProgram);
4190
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
4191
+ lavarageProgram,
4192
+ positionAccountPDA,
4193
+ tokenAddressPubKey,
4194
+ tokenProgram
4195
+ );
4196
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
4197
+ lavarageProgram,
4198
+ lavarageProgram.provider.publicKey,
4199
+ tokenAddressPubKey,
4200
+ tokenProgram
4201
+ );
3124
4202
  const jupiterSellIx = jupInstruction.instructions;
3125
4203
  const deserializeInstruction = (instruction) => {
3126
4204
  return new TransactionInstruction({
@@ -3134,13 +4212,17 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3134
4212
  });
3135
4213
  };
3136
4214
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
3137
- const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new PublicKey(key)));
4215
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
4216
+ keys.map((key) => new PublicKey(key))
4217
+ );
3138
4218
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
3139
4219
  const addressLookupTableAddress = keys[index];
3140
4220
  if (accountInfo) {
3141
4221
  const addressLookupTableAccount = new AddressLookupTableAccount({
3142
4222
  key: new PublicKey(addressLookupTableAddress),
3143
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
4223
+ state: AddressLookupTableAccount.deserialize(
4224
+ Uint8Array.from(accountInfo.data)
4225
+ )
3144
4226
  });
3145
4227
  acc.push(addressLookupTableAccount);
3146
4228
  }
@@ -3165,7 +4247,10 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3165
4247
  let repaySolIx = null;
3166
4248
  let jupiterIxs = [];
3167
4249
  if (jupInstruction.instructions == void 0) {
3168
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9997)).accountsStrict({
4250
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
4251
+ new BN(jupInstruction.quoteResponse.outAmount),
4252
+ new BN(9997)
4253
+ ).accountsStrict({
3169
4254
  nodeWallet: pool.account.nodeWallet,
3170
4255
  positionAccount: positionAccountPDA,
3171
4256
  tradingPool: poolPubKey,
@@ -3174,17 +4259,25 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3174
4259
  clock: SYSVAR_CLOCK_PUBKEY,
3175
4260
  randomAccountAsId: position.account.seed,
3176
4261
  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();
4262
+ }).remainingAccounts(
4263
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
4264
+ {
4265
+ pubkey: partnerFeeRecipient,
4266
+ isSigner: false,
4267
+ isWritable: true
4268
+ },
4269
+ {
4270
+ pubkey: partnerFeeMarkupAsPkey,
4271
+ isSigner: false,
4272
+ isWritable: false
4273
+ }
4274
+ ] : []
4275
+ ).instruction();
3186
4276
  } else {
3187
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9998)).accountsStrict({
4277
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
4278
+ new BN(jupInstruction.quoteResponse.outAmount),
4279
+ new BN(9998)
4280
+ ).accountsStrict({
3188
4281
  nodeWallet: pool.account.nodeWallet,
3189
4282
  positionAccount: positionAccountPDA,
3190
4283
  tradingPool: poolPubKey,
@@ -3193,22 +4286,37 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3193
4286
  clock: SYSVAR_CLOCK_PUBKEY,
3194
4287
  randomAccountAsId: position.account.seed,
3195
4288
  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;
4289
+ }).remainingAccounts(
4290
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
4291
+ {
4292
+ pubkey: partnerFeeRecipient,
4293
+ isSigner: false,
4294
+ isWritable: true
4295
+ },
4296
+ {
4297
+ pubkey: partnerFeeMarkupAsPkey,
4298
+ isSigner: false,
4299
+ isWritable: false
4300
+ }
4301
+ ] : []
4302
+ ).instruction();
4303
+ const {
4304
+ setupInstructions,
4305
+ swapInstruction: swapInstructionPayload,
4306
+ cleanupInstruction,
4307
+ addressLookupTableAddresses
4308
+ } = jupiterSellIx;
3206
4309
  jupiterIxs = [
3207
4310
  ...setupInstructions.map(deserializeInstruction),
3208
4311
  deserializeInstruction(swapInstructionPayload),
3209
4312
  deserializeInstruction(cleanupInstruction)
3210
4313
  ];
3211
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts(["5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi", ...addressLookupTableAddresses]));
4314
+ addressLookupTableAccounts.push(
4315
+ ...yield getAddressLookupTableAccounts([
4316
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi",
4317
+ ...addressLookupTableAddresses
4318
+ ])
4319
+ );
3212
4320
  }
3213
4321
  const profit = new BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3214
4322
  let createAssociatedTokenAccountInstruction2 = createAssociatedTokenAccountIdempotentInstruction(
@@ -3220,7 +4328,9 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
3220
4328
  );
3221
4329
  const allInstructions = [
3222
4330
  ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
3223
- ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(jupInstruction.instructions.tokenLedgerInstruction) : null,
4331
+ ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
4332
+ jupInstruction.instructions.tokenLedgerInstruction
4333
+ ) : null,
3224
4334
  toTokenAccount.instruction,
3225
4335
  closePositionIx,
3226
4336
  ...jupiterIxs,
@@ -3244,17 +4354,30 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3244
4354
  feeBuffer32.set(feeBuffer, 0);
3245
4355
  partnerFeeMarkupAsPkey = new PublicKey(feeBuffer32);
3246
4356
  }
3247
- if (position.account.pool.toBase58() != offer.publicKey.toBase58()) throw "Mismatch offer";
4357
+ if (position.account.pool.toBase58() != offer.publicKey.toBase58())
4358
+ throw "Mismatch offer";
3248
4359
  const pool = offer;
3249
4360
  const poolPubKey = offer.publicKey;
3250
4361
  const tokenAddressPubKey = new PublicKey(offer.account.collateralType);
3251
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4362
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4363
+ offer.account.collateralType
4364
+ );
3252
4365
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3253
4366
  const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
3254
4367
  const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
3255
4368
  const positionAccountPDA = position.publicKey;
3256
- const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, positionAccountPDA, tokenAddressPubKey, tokenProgram);
3257
- const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(lavarageProgram, lavarageProgram.provider.publicKey, tokenAddressPubKey, tokenProgram);
4369
+ const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
4370
+ lavarageProgram,
4371
+ positionAccountPDA,
4372
+ tokenAddressPubKey,
4373
+ tokenProgram
4374
+ );
4375
+ const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
4376
+ lavarageProgram,
4377
+ lavarageProgram.provider.publicKey,
4378
+ tokenAddressPubKey,
4379
+ tokenProgram
4380
+ );
3258
4381
  const jupiterSellIx = jupInstruction.instructions;
3259
4382
  const deserializeInstruction = (instruction) => {
3260
4383
  return new TransactionInstruction({
@@ -3268,13 +4391,17 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3268
4391
  });
3269
4392
  };
3270
4393
  const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
3271
- const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(keys.map((key) => new PublicKey(key)));
4394
+ const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
4395
+ keys.map((key) => new PublicKey(key))
4396
+ );
3272
4397
  return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
3273
4398
  const addressLookupTableAddress = keys[index];
3274
4399
  if (accountInfo) {
3275
4400
  const addressLookupTableAccount = new AddressLookupTableAccount({
3276
4401
  key: new PublicKey(addressLookupTableAddress),
3277
- state: AddressLookupTableAccount.deserialize(Uint8Array.from(accountInfo.data))
4402
+ state: AddressLookupTableAccount.deserialize(
4403
+ Uint8Array.from(accountInfo.data)
4404
+ )
3278
4405
  });
3279
4406
  acc.push(addressLookupTableAccount);
3280
4407
  }
@@ -3299,7 +4426,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3299
4426
  let repaySolIx = null;
3300
4427
  let jupiterIxs = [];
3301
4428
  if (jupInstruction.instructions == void 0) {
3302
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9997)).accountsStrict({
4429
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
4430
+ new BN(jupInstruction.quoteResponse.outAmount),
4431
+ new BN(9997)
4432
+ ).accountsStrict({
3303
4433
  nodeWallet: pool.account.nodeWallet,
3304
4434
  positionAccount: positionAccountPDA,
3305
4435
  tradingPool: poolPubKey,
@@ -3307,22 +4437,50 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3307
4437
  systemProgram: SystemProgram.programId,
3308
4438
  clock: SYSVAR_CLOCK_PUBKEY,
3309
4439
  randomAccountAsId: position.account.seed,
3310
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
3311
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
4440
+ feeTokenAccount: getAssociatedTokenAddressSync(
4441
+ quoteToken,
4442
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
4443
+ false,
4444
+ quoteTokenProgram
4445
+ ),
4446
+ fromTokenAccount: getAssociatedTokenAddressSync(
4447
+ quoteToken,
4448
+ lavarageProgram.provider.publicKey,
4449
+ false,
4450
+ quoteTokenProgram
4451
+ ),
3312
4452
  tokenProgram: quoteTokenProgram,
3313
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
4453
+ toTokenAccount: getAssociatedTokenAddressSync(
4454
+ quoteToken,
4455
+ pool.account.nodeWallet,
4456
+ true,
4457
+ quoteTokenProgram
4458
+ ),
3314
4459
  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();
4460
+ }).remainingAccounts(
4461
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
4462
+ {
4463
+ pubkey: getAssociatedTokenAddressSync(
4464
+ quoteToken,
4465
+ partnerFeeRecipient,
4466
+ false,
4467
+ quoteTokenProgram
4468
+ ),
4469
+ isSigner: false,
4470
+ isWritable: true
4471
+ },
4472
+ {
4473
+ pubkey: partnerFeeMarkupAsPkey,
4474
+ isSigner: false,
4475
+ isWritable: false
4476
+ }
4477
+ ] : []
4478
+ ).instruction();
3324
4479
  } else {
3325
- repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(new BN(jupInstruction.quoteResponse.outAmount), new BN(9998)).accountsStrict({
4480
+ repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
4481
+ new BN(jupInstruction.quoteResponse.outAmount),
4482
+ new BN(9998)
4483
+ ).accountsStrict({
3326
4484
  nodeWallet: pool.account.nodeWallet,
3327
4485
  positionAccount: positionAccountPDA,
3328
4486
  tradingPool: poolPubKey,
@@ -3330,27 +4488,58 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3330
4488
  systemProgram: SystemProgram.programId,
3331
4489
  clock: SYSVAR_CLOCK_PUBKEY,
3332
4490
  randomAccountAsId: position.account.seed,
3333
- feeTokenAccount: getAssociatedTokenAddressSync(quoteToken, new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"), false, quoteTokenProgram),
3334
- fromTokenAccount: getAssociatedTokenAddressSync(quoteToken, lavarageProgram.provider.publicKey, false, quoteTokenProgram),
4491
+ feeTokenAccount: getAssociatedTokenAddressSync(
4492
+ quoteToken,
4493
+ new PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
4494
+ false,
4495
+ quoteTokenProgram
4496
+ ),
4497
+ fromTokenAccount: getAssociatedTokenAddressSync(
4498
+ quoteToken,
4499
+ lavarageProgram.provider.publicKey,
4500
+ false,
4501
+ quoteTokenProgram
4502
+ ),
3335
4503
  tokenProgram: quoteTokenProgram,
3336
- toTokenAccount: getAssociatedTokenAddressSync(quoteToken, pool.account.nodeWallet, true, quoteTokenProgram),
4504
+ toTokenAccount: getAssociatedTokenAddressSync(
4505
+ quoteToken,
4506
+ pool.account.nodeWallet,
4507
+ true,
4508
+ quoteTokenProgram
4509
+ ),
3337
4510
  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;
4511
+ }).remainingAccounts(
4512
+ partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
4513
+ {
4514
+ pubkey: partnerFeeRecipient,
4515
+ isSigner: false,
4516
+ isWritable: true
4517
+ },
4518
+ {
4519
+ pubkey: partnerFeeMarkupAsPkey,
4520
+ isSigner: false,
4521
+ isWritable: false
4522
+ }
4523
+ ] : []
4524
+ ).instruction();
4525
+ const {
4526
+ setupInstructions,
4527
+ swapInstruction: swapInstructionPayload,
4528
+ cleanupInstruction,
4529
+ addressLookupTableAddresses
4530
+ } = jupiterSellIx;
3348
4531
  jupiterIxs = [
3349
4532
  ...setupInstructions.filter((i) => !!i).map(deserializeInstruction),
3350
4533
  swapInstructionPayload ? deserializeInstruction(swapInstructionPayload) : null,
3351
4534
  cleanupInstruction ? deserializeInstruction(cleanupInstruction) : null
3352
4535
  ].filter((i) => !!i);
3353
- addressLookupTableAccounts.push(...yield getAddressLookupTableAccounts([...addressLookupTableAddresses, getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()), "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"]));
4536
+ addressLookupTableAccounts.push(
4537
+ ...yield getAddressLookupTableAccounts([
4538
+ ...addressLookupTableAddresses,
4539
+ getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()),
4540
+ "5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"
4541
+ ])
4542
+ );
3354
4543
  }
3355
4544
  const profit = new BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
3356
4545
  let createAssociatedTokenAccountInstruction2 = createAssociatedTokenAccountIdempotentInstruction(
@@ -3362,7 +4551,9 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3362
4551
  );
3363
4552
  const allInstructions = [
3364
4553
  ((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
3365
- ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(jupInstruction.instructions.tokenLedgerInstruction) : null,
4554
+ ((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
4555
+ jupInstruction.instructions.tokenLedgerInstruction
4556
+ ) : null,
3366
4557
  toTokenAccount.instruction,
3367
4558
  closePositionIx,
3368
4559
  ...jupiterIxs,
@@ -3377,12 +4568,16 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
3377
4568
  return tx;
3378
4569
  });
3379
4570
  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);
4571
+ const delegateAccounts = yield lavarageProgram.account.delegate.all(
4572
+ userPubKey ? [
4573
+ {
4574
+ memcmp: {
4575
+ offset: 104,
4576
+ bytes: userPubKey.toBase58()
4577
+ }
4578
+ }
4579
+ ] : void 0
4580
+ );
3386
4581
  return delegateAccounts.map((d) => __spreadProps(__spreadValues({}, d), {
3387
4582
  parsed: {
3388
4583
  tpPrice: new BN(d.account.field1),
@@ -3404,12 +4599,32 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3404
4599
  const positionAccountPDA = position.publicKey;
3405
4600
  const newPosition1Seed = Keypair.generate().publicKey;
3406
4601
  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);
4602
+ const newPosition1AccountPDA = getPositionAccountPDA(
4603
+ lavarageProgram,
4604
+ offer,
4605
+ newPosition1Seed
4606
+ );
4607
+ const newPosition2AccountPDA = getPositionAccountPDA(
4608
+ lavarageProgram,
4609
+ offer,
4610
+ newPosition2Seed
4611
+ );
4612
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4613
+ offer.account.collateralType
4614
+ );
3410
4615
  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);
4616
+ const newPosition1TokenAccount = getAssociatedTokenAddressSync(
4617
+ offer.account.collateralType,
4618
+ newPosition1AccountPDA,
4619
+ true,
4620
+ tokenProgram
4621
+ );
4622
+ const newPosition2TokenAccount = getAssociatedTokenAddressSync(
4623
+ offer.account.collateralType,
4624
+ newPosition2AccountPDA,
4625
+ true,
4626
+ tokenProgram
4627
+ );
3413
4628
  const createNewPosition1TokenAccountIx = createAssociatedTokenAccountInstruction(
3414
4629
  lavarageProgram.provider.publicKey,
3415
4630
  newPosition1TokenAccount,
@@ -3424,7 +4639,11 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3424
4639
  offer.account.collateralType,
3425
4640
  tokenProgram
3426
4641
  );
3427
- const ix = yield lavarageProgram.methods.tradingManagementSplitPosition(new BN(propotionBps), newPosition1Seed, newPosition2Seed).accountsStrict({
4642
+ const ix = yield lavarageProgram.methods.tradingManagementSplitPosition(
4643
+ new BN(propotionBps),
4644
+ newPosition1Seed,
4645
+ newPosition2Seed
4646
+ ).accountsStrict({
3428
4647
  originalPosition: positionAccountPDA,
3429
4648
  newPositionOne: newPosition1AccountPDA,
3430
4649
  newPositionTwo: newPosition2AccountPDA,
@@ -3432,7 +4651,12 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
3432
4651
  systemProgram: SystemProgram.programId,
3433
4652
  mint: offer.account.collateralType,
3434
4653
  tokenProgram,
3435
- originalPositionTokenAccount: getAssociatedTokenAddressSync(offer.account.collateralType, positionAccountPDA, true, tokenProgram),
4654
+ originalPositionTokenAccount: getAssociatedTokenAddressSync(
4655
+ offer.account.collateralType,
4656
+ positionAccountPDA,
4657
+ true,
4658
+ tokenProgram
4659
+ ),
3436
4660
  newPositionTokenAccountOne: newPosition1TokenAccount,
3437
4661
  newPositionTokenAccountTwo: newPosition2TokenAccount
3438
4662
  }).instruction();
@@ -3458,10 +4682,21 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3458
4682
  const positionAccountPDA1 = position1.publicKey;
3459
4683
  const positionAccountPDA2 = position2.publicKey;
3460
4684
  const newPositionSeed = Keypair.generate().publicKey;
3461
- const newPositionAccountPDA = getPositionAccountPDA(lavarageProgram, offer, newPositionSeed);
3462
- const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(offer.account.collateralType);
4685
+ const newPositionAccountPDA = getPositionAccountPDA(
4686
+ lavarageProgram,
4687
+ offer,
4688
+ newPositionSeed
4689
+ );
4690
+ const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
4691
+ offer.account.collateralType
4692
+ );
3463
4693
  const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
3464
- const newPositionTokenAccount = getAssociatedTokenAddressSync(offer.account.collateralType, newPositionAccountPDA, true, tokenProgram);
4694
+ const newPositionTokenAccount = getAssociatedTokenAddressSync(
4695
+ offer.account.collateralType,
4696
+ newPositionAccountPDA,
4697
+ true,
4698
+ tokenProgram
4699
+ );
3465
4700
  const createNewPositionTokenAccountIx = createAssociatedTokenAccountInstruction(
3466
4701
  lavarageProgram.provider.publicKey,
3467
4702
  newPositionTokenAccount,
@@ -3477,8 +4712,18 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3477
4712
  systemProgram: SystemProgram.programId,
3478
4713
  mint: offer.account.collateralType,
3479
4714
  tokenProgram,
3480
- positionOneTokenAccount: getAssociatedTokenAddressSync(offer.account.collateralType, positionAccountPDA1, true, tokenProgram),
3481
- positionTwoTokenAccount: getAssociatedTokenAddressSync(offer.account.collateralType, positionAccountPDA2, true, tokenProgram),
4715
+ positionOneTokenAccount: getAssociatedTokenAddressSync(
4716
+ offer.account.collateralType,
4717
+ positionAccountPDA1,
4718
+ true,
4719
+ tokenProgram
4720
+ ),
4721
+ positionTwoTokenAccount: getAssociatedTokenAddressSync(
4722
+ offer.account.collateralType,
4723
+ positionAccountPDA2,
4724
+ true,
4725
+ tokenProgram
4726
+ ),
3482
4727
  mergedPositionTokenAccount: newPositionTokenAccount
3483
4728
  }).instruction();
3484
4729
  const computeBudgetIx = ComputeBudgetProgram.setComputeUnitPrice({
@@ -3501,19 +4746,28 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
3501
4746
  export {
3502
4747
  IDL,
3503
4748
  lavaragev2_exports as IDLV2,
4749
+ closePositionEvm,
3504
4750
  closeTradeV1,
3505
4751
  closeTradeV2,
3506
4752
  createTpDelegate,
3507
4753
  getAllPositions,
3508
4754
  getClosedPositions,
4755
+ getClosedPositionsEvm,
4756
+ getCollateralInfoEvm,
3509
4757
  getDelegateAccounts,
3510
4758
  getLiquidatedPositions,
4759
+ getLiquidatedPositionsEvm,
4760
+ getLoanEvm,
3511
4761
  getOffers,
4762
+ getOffersEvm,
3512
4763
  getOpenPositions,
3513
4764
  getPda,
3514
4765
  getPositionAccountPDA,
4766
+ getPositionsEvm,
4767
+ getUserLoansEvm,
3515
4768
  mergePositionV2,
3516
4769
  modifyTpDelegate,
4770
+ openPositionEvm,
3517
4771
  openTradeV1,
3518
4772
  openTradeV2,
3519
4773
  partialRepayV1,