@lavarage/sdk 6.4.7 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/abi/borrowerOperations.ts +248 -0
- package/abi/tokenHolderAbi.ts +443 -0
- package/dist/index.d.mts +131 -1
- package/dist/index.d.ts +131 -1
- package/dist/index.js +1395 -172
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1409 -174
- package/dist/index.mjs.map +1 -1
- package/evm.ts +318 -0
- package/index.ts +1210 -669
- package/interfaces/evm.ts +42 -0
- package/package.json +4 -3
package/dist/index.js
CHANGED
|
@@ -69,19 +69,28 @@ var index_exports = {};
|
|
|
69
69
|
__export(index_exports, {
|
|
70
70
|
IDL: () => IDL,
|
|
71
71
|
IDLV2: () => lavaragev2_exports,
|
|
72
|
+
closePositionEvm: () => closePositionEvm,
|
|
72
73
|
closeTradeV1: () => closeTradeV1,
|
|
73
74
|
closeTradeV2: () => closeTradeV2,
|
|
74
75
|
createTpDelegate: () => createTpDelegate,
|
|
75
76
|
getAllPositions: () => getAllPositions,
|
|
76
77
|
getClosedPositions: () => getClosedPositions,
|
|
78
|
+
getClosedPositionsEvm: () => getClosedPositionsEvm,
|
|
79
|
+
getCollateralInfoEvm: () => getCollateralInfoEvm,
|
|
77
80
|
getDelegateAccounts: () => getDelegateAccounts,
|
|
78
81
|
getLiquidatedPositions: () => getLiquidatedPositions,
|
|
82
|
+
getLiquidatedPositionsEvm: () => getLiquidatedPositionsEvm,
|
|
83
|
+
getLoanEvm: () => getLoanEvm,
|
|
79
84
|
getOffers: () => getOffers,
|
|
85
|
+
getOffersEvm: () => getOffersEvm,
|
|
80
86
|
getOpenPositions: () => getOpenPositions,
|
|
81
87
|
getPda: () => getPda,
|
|
82
88
|
getPositionAccountPDA: () => getPositionAccountPDA,
|
|
89
|
+
getPositionsEvm: () => getPositionsEvm,
|
|
90
|
+
getUserLoansEvm: () => getUserLoansEvm,
|
|
83
91
|
mergePositionV2: () => mergePositionV2,
|
|
84
92
|
modifyTpDelegate: () => modifyTpDelegate,
|
|
93
|
+
openPositionEvm: () => openPositionEvm,
|
|
85
94
|
openTradeV1: () => openTradeV1,
|
|
86
95
|
openTradeV2: () => openTradeV2,
|
|
87
96
|
partialRepayV1: () => partialRepayV1,
|
|
@@ -2726,17 +2735,910 @@ var IDL2 = {
|
|
|
2726
2735
|
]
|
|
2727
2736
|
};
|
|
2728
2737
|
|
|
2738
|
+
// evm.ts
|
|
2739
|
+
var import_ethers = require("ethers");
|
|
2740
|
+
|
|
2741
|
+
// abi/borrowerOperations.ts
|
|
2742
|
+
var borrowerOperationsAbi = [
|
|
2743
|
+
{ inputs: [], name: "InvalidInitialization", type: "error" },
|
|
2744
|
+
{ inputs: [], name: "NotInitializing", type: "error" },
|
|
2745
|
+
{ inputs: [], name: "ReentrancyGuardReentrantCall", type: "error" },
|
|
2746
|
+
{
|
|
2747
|
+
anonymous: false,
|
|
2748
|
+
inputs: [
|
|
2749
|
+
{
|
|
2750
|
+
indexed: true,
|
|
2751
|
+
internalType: "address",
|
|
2752
|
+
name: "buyer",
|
|
2753
|
+
type: "address"
|
|
2754
|
+
},
|
|
2755
|
+
{
|
|
2756
|
+
indexed: true,
|
|
2757
|
+
internalType: "address",
|
|
2758
|
+
name: "tokenCollateral",
|
|
2759
|
+
type: "address"
|
|
2760
|
+
},
|
|
2761
|
+
{
|
|
2762
|
+
indexed: true,
|
|
2763
|
+
internalType: "uint256",
|
|
2764
|
+
name: "loanId",
|
|
2765
|
+
type: "uint256"
|
|
2766
|
+
},
|
|
2767
|
+
{
|
|
2768
|
+
indexed: false,
|
|
2769
|
+
internalType: "uint256",
|
|
2770
|
+
name: "openingPositionSize",
|
|
2771
|
+
type: "uint256"
|
|
2772
|
+
},
|
|
2773
|
+
{
|
|
2774
|
+
indexed: false,
|
|
2775
|
+
internalType: "uint256",
|
|
2776
|
+
name: "collateralAmount",
|
|
2777
|
+
type: "uint256"
|
|
2778
|
+
},
|
|
2779
|
+
{
|
|
2780
|
+
indexed: false,
|
|
2781
|
+
internalType: "uint256",
|
|
2782
|
+
name: "initialMargin",
|
|
2783
|
+
type: "uint256"
|
|
2784
|
+
}
|
|
2785
|
+
],
|
|
2786
|
+
name: "Buy",
|
|
2787
|
+
type: "event"
|
|
2788
|
+
},
|
|
2789
|
+
{
|
|
2790
|
+
anonymous: false,
|
|
2791
|
+
inputs: [
|
|
2792
|
+
{
|
|
2793
|
+
indexed: false,
|
|
2794
|
+
internalType: "uint64",
|
|
2795
|
+
name: "version",
|
|
2796
|
+
type: "uint64"
|
|
2797
|
+
}
|
|
2798
|
+
],
|
|
2799
|
+
name: "Initialized",
|
|
2800
|
+
type: "event"
|
|
2801
|
+
},
|
|
2802
|
+
{
|
|
2803
|
+
anonymous: false,
|
|
2804
|
+
inputs: [
|
|
2805
|
+
{
|
|
2806
|
+
indexed: true,
|
|
2807
|
+
internalType: "address",
|
|
2808
|
+
name: "borrower",
|
|
2809
|
+
type: "address"
|
|
2810
|
+
},
|
|
2811
|
+
{
|
|
2812
|
+
indexed: true,
|
|
2813
|
+
internalType: "address",
|
|
2814
|
+
name: "tokenCollateral",
|
|
2815
|
+
type: "address"
|
|
2816
|
+
},
|
|
2817
|
+
{
|
|
2818
|
+
indexed: true,
|
|
2819
|
+
internalType: "uint256",
|
|
2820
|
+
name: "loanId",
|
|
2821
|
+
type: "uint256"
|
|
2822
|
+
},
|
|
2823
|
+
{
|
|
2824
|
+
indexed: false,
|
|
2825
|
+
internalType: "uint256",
|
|
2826
|
+
name: "closingPositionSize",
|
|
2827
|
+
type: "uint256"
|
|
2828
|
+
},
|
|
2829
|
+
{
|
|
2830
|
+
indexed: false,
|
|
2831
|
+
internalType: "uint256",
|
|
2832
|
+
name: "liquidatorRepaidAmount",
|
|
2833
|
+
type: "uint256"
|
|
2834
|
+
}
|
|
2835
|
+
],
|
|
2836
|
+
name: "Liquidation",
|
|
2837
|
+
type: "event"
|
|
2838
|
+
},
|
|
2839
|
+
{
|
|
2840
|
+
anonymous: false,
|
|
2841
|
+
inputs: [
|
|
2842
|
+
{
|
|
2843
|
+
indexed: true,
|
|
2844
|
+
internalType: "address",
|
|
2845
|
+
name: "buyer",
|
|
2846
|
+
type: "address"
|
|
2847
|
+
},
|
|
2848
|
+
{
|
|
2849
|
+
indexed: true,
|
|
2850
|
+
internalType: "address",
|
|
2851
|
+
name: "tokenCollateral",
|
|
2852
|
+
type: "address"
|
|
2853
|
+
},
|
|
2854
|
+
{
|
|
2855
|
+
indexed: true,
|
|
2856
|
+
internalType: "uint256",
|
|
2857
|
+
name: "loanId",
|
|
2858
|
+
type: "uint256"
|
|
2859
|
+
},
|
|
2860
|
+
{
|
|
2861
|
+
indexed: false,
|
|
2862
|
+
internalType: "uint256",
|
|
2863
|
+
name: "closingPositionSize",
|
|
2864
|
+
type: "uint256"
|
|
2865
|
+
},
|
|
2866
|
+
{
|
|
2867
|
+
indexed: false,
|
|
2868
|
+
internalType: "uint256",
|
|
2869
|
+
name: "profit",
|
|
2870
|
+
type: "uint256"
|
|
2871
|
+
}
|
|
2872
|
+
],
|
|
2873
|
+
name: "Sell",
|
|
2874
|
+
type: "event"
|
|
2875
|
+
},
|
|
2876
|
+
{
|
|
2877
|
+
inputs: [],
|
|
2878
|
+
name: "admin",
|
|
2879
|
+
outputs: [{ internalType: "address", name: "", type: "address" }],
|
|
2880
|
+
stateMutability: "view",
|
|
2881
|
+
type: "function"
|
|
2882
|
+
},
|
|
2883
|
+
{
|
|
2884
|
+
inputs: [
|
|
2885
|
+
{ internalType: "bytes", name: "buyingCode", type: "bytes" },
|
|
2886
|
+
{
|
|
2887
|
+
internalType: "contract IERC20",
|
|
2888
|
+
name: "tokenCollateral",
|
|
2889
|
+
type: "address"
|
|
2890
|
+
},
|
|
2891
|
+
{ internalType: "uint256", name: "borrowAmount", type: "uint256" },
|
|
2892
|
+
{
|
|
2893
|
+
internalType: "contract TokenHolder",
|
|
2894
|
+
name: "tokenHolder",
|
|
2895
|
+
type: "address"
|
|
2896
|
+
},
|
|
2897
|
+
{ internalType: "address", name: "inchRouter", type: "address" },
|
|
2898
|
+
{
|
|
2899
|
+
internalType: "address",
|
|
2900
|
+
name: "integratorFeeAddress",
|
|
2901
|
+
type: "address"
|
|
2902
|
+
}
|
|
2903
|
+
],
|
|
2904
|
+
name: "buy",
|
|
2905
|
+
outputs: [],
|
|
2906
|
+
stateMutability: "payable",
|
|
2907
|
+
type: "function"
|
|
2908
|
+
},
|
|
2909
|
+
{
|
|
2910
|
+
inputs: [
|
|
2911
|
+
{ internalType: "contract IERC20", name: "_weth", type: "address" }
|
|
2912
|
+
],
|
|
2913
|
+
name: "initialize",
|
|
2914
|
+
outputs: [],
|
|
2915
|
+
stateMutability: "nonpayable",
|
|
2916
|
+
type: "function"
|
|
2917
|
+
},
|
|
2918
|
+
{
|
|
2919
|
+
inputs: [
|
|
2920
|
+
{ internalType: "uint256", name: "loanId", type: "uint256" },
|
|
2921
|
+
{
|
|
2922
|
+
internalType: "contract TokenHolder",
|
|
2923
|
+
name: "tokenHolder",
|
|
2924
|
+
type: "address"
|
|
2925
|
+
},
|
|
2926
|
+
{ internalType: "uint256", name: "closingPositionSize", type: "uint256" }
|
|
2927
|
+
],
|
|
2928
|
+
name: "liquidate",
|
|
2929
|
+
outputs: [],
|
|
2930
|
+
stateMutability: "nonpayable",
|
|
2931
|
+
type: "function"
|
|
2932
|
+
},
|
|
2933
|
+
{
|
|
2934
|
+
inputs: [],
|
|
2935
|
+
name: "openingFee",
|
|
2936
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
2937
|
+
stateMutability: "view",
|
|
2938
|
+
type: "function"
|
|
2939
|
+
},
|
|
2940
|
+
{
|
|
2941
|
+
inputs: [],
|
|
2942
|
+
name: "profitFee",
|
|
2943
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
2944
|
+
stateMutability: "view",
|
|
2945
|
+
type: "function"
|
|
2946
|
+
},
|
|
2947
|
+
{
|
|
2948
|
+
inputs: [
|
|
2949
|
+
{ internalType: "uint256", name: "loanId", type: "uint256" },
|
|
2950
|
+
{ internalType: "bytes", name: "sellingCode", type: "bytes" },
|
|
2951
|
+
{
|
|
2952
|
+
internalType: "contract TokenHolder",
|
|
2953
|
+
name: "tokenHolder",
|
|
2954
|
+
type: "address"
|
|
2955
|
+
},
|
|
2956
|
+
{ internalType: "address", name: "inchRouter", type: "address" },
|
|
2957
|
+
{
|
|
2958
|
+
internalType: "address",
|
|
2959
|
+
name: "integratorFeeAddress",
|
|
2960
|
+
type: "address"
|
|
2961
|
+
}
|
|
2962
|
+
],
|
|
2963
|
+
name: "sell",
|
|
2964
|
+
outputs: [],
|
|
2965
|
+
stateMutability: "nonpayable",
|
|
2966
|
+
type: "function"
|
|
2967
|
+
},
|
|
2968
|
+
{
|
|
2969
|
+
inputs: [{ internalType: "address", name: "_admin", type: "address" }],
|
|
2970
|
+
name: "setAdmin",
|
|
2971
|
+
outputs: [],
|
|
2972
|
+
stateMutability: "nonpayable",
|
|
2973
|
+
type: "function"
|
|
2974
|
+
},
|
|
2975
|
+
{
|
|
2976
|
+
inputs: [{ internalType: "uint256", name: "_openingFee", type: "uint256" }],
|
|
2977
|
+
name: "setOpeningFee",
|
|
2978
|
+
outputs: [],
|
|
2979
|
+
stateMutability: "nonpayable",
|
|
2980
|
+
type: "function"
|
|
2981
|
+
},
|
|
2982
|
+
{
|
|
2983
|
+
inputs: [{ internalType: "uint256", name: "_profitFee", type: "uint256" }],
|
|
2984
|
+
name: "setProfitFee",
|
|
2985
|
+
outputs: [],
|
|
2986
|
+
stateMutability: "nonpayable",
|
|
2987
|
+
type: "function"
|
|
2988
|
+
}
|
|
2989
|
+
];
|
|
2990
|
+
|
|
2991
|
+
// abi/tokenHolderAbi.ts
|
|
2992
|
+
var tokenHolderAbi = [
|
|
2993
|
+
{ inputs: [], name: "AccessControlBadConfirmation", type: "error" },
|
|
2994
|
+
{
|
|
2995
|
+
inputs: [
|
|
2996
|
+
{ internalType: "address", name: "account", type: "address" },
|
|
2997
|
+
{ internalType: "bytes32", name: "neededRole", type: "bytes32" }
|
|
2998
|
+
],
|
|
2999
|
+
name: "AccessControlUnauthorizedAccount",
|
|
3000
|
+
type: "error"
|
|
3001
|
+
},
|
|
3002
|
+
{ inputs: [], name: "InvalidInitialization", type: "error" },
|
|
3003
|
+
{ inputs: [], name: "NotInitializing", type: "error" },
|
|
3004
|
+
{
|
|
3005
|
+
anonymous: false,
|
|
3006
|
+
inputs: [
|
|
3007
|
+
{
|
|
3008
|
+
indexed: false,
|
|
3009
|
+
internalType: "uint64",
|
|
3010
|
+
name: "version",
|
|
3011
|
+
type: "uint64"
|
|
3012
|
+
}
|
|
3013
|
+
],
|
|
3014
|
+
name: "Initialized",
|
|
3015
|
+
type: "event"
|
|
3016
|
+
},
|
|
3017
|
+
{
|
|
3018
|
+
anonymous: false,
|
|
3019
|
+
inputs: [
|
|
3020
|
+
{
|
|
3021
|
+
indexed: false,
|
|
3022
|
+
internalType: "uint256",
|
|
3023
|
+
name: "newInterestRate",
|
|
3024
|
+
type: "uint256"
|
|
3025
|
+
}
|
|
3026
|
+
],
|
|
3027
|
+
name: "InterestRateSet",
|
|
3028
|
+
type: "event"
|
|
3029
|
+
},
|
|
3030
|
+
{
|
|
3031
|
+
anonymous: false,
|
|
3032
|
+
inputs: [
|
|
3033
|
+
{
|
|
3034
|
+
indexed: false,
|
|
3035
|
+
internalType: "uint256",
|
|
3036
|
+
name: "loanId",
|
|
3037
|
+
type: "uint256"
|
|
3038
|
+
},
|
|
3039
|
+
{
|
|
3040
|
+
indexed: false,
|
|
3041
|
+
internalType: "uint256",
|
|
3042
|
+
name: "amount",
|
|
3043
|
+
type: "uint256"
|
|
3044
|
+
},
|
|
3045
|
+
{
|
|
3046
|
+
indexed: false,
|
|
3047
|
+
internalType: "uint256",
|
|
3048
|
+
name: "timestamp",
|
|
3049
|
+
type: "uint256"
|
|
3050
|
+
},
|
|
3051
|
+
{ indexed: false, internalType: "bool", name: "repaid", type: "bool" }
|
|
3052
|
+
],
|
|
3053
|
+
name: "LoanCreated",
|
|
3054
|
+
type: "event"
|
|
3055
|
+
},
|
|
3056
|
+
{
|
|
3057
|
+
anonymous: false,
|
|
3058
|
+
inputs: [
|
|
3059
|
+
{
|
|
3060
|
+
indexed: false,
|
|
3061
|
+
internalType: "uint256",
|
|
3062
|
+
name: "loanId",
|
|
3063
|
+
type: "uint256"
|
|
3064
|
+
}
|
|
3065
|
+
],
|
|
3066
|
+
name: "LoanRepaid",
|
|
3067
|
+
type: "event"
|
|
3068
|
+
},
|
|
3069
|
+
{
|
|
3070
|
+
anonymous: false,
|
|
3071
|
+
inputs: [
|
|
3072
|
+
{
|
|
3073
|
+
indexed: false,
|
|
3074
|
+
internalType: "address",
|
|
3075
|
+
name: "collateralAddress",
|
|
3076
|
+
type: "address"
|
|
3077
|
+
},
|
|
3078
|
+
{
|
|
3079
|
+
indexed: false,
|
|
3080
|
+
internalType: "uint256",
|
|
3081
|
+
name: "oldValue",
|
|
3082
|
+
type: "uint256"
|
|
3083
|
+
},
|
|
3084
|
+
{
|
|
3085
|
+
indexed: false,
|
|
3086
|
+
internalType: "uint256",
|
|
3087
|
+
name: "newValue",
|
|
3088
|
+
type: "uint256"
|
|
3089
|
+
}
|
|
3090
|
+
],
|
|
3091
|
+
name: "MaxLendPerTokenUpdated",
|
|
3092
|
+
type: "event"
|
|
3093
|
+
},
|
|
3094
|
+
{
|
|
3095
|
+
anonymous: false,
|
|
3096
|
+
inputs: [
|
|
3097
|
+
{
|
|
3098
|
+
indexed: false,
|
|
3099
|
+
internalType: "address",
|
|
3100
|
+
name: "borrower",
|
|
3101
|
+
type: "address"
|
|
3102
|
+
},
|
|
3103
|
+
{
|
|
3104
|
+
indexed: false,
|
|
3105
|
+
internalType: "uint256",
|
|
3106
|
+
name: "amount",
|
|
3107
|
+
type: "uint256"
|
|
3108
|
+
}
|
|
3109
|
+
],
|
|
3110
|
+
name: "PrivilegedLoan",
|
|
3111
|
+
type: "event"
|
|
3112
|
+
},
|
|
3113
|
+
{
|
|
3114
|
+
anonymous: false,
|
|
3115
|
+
inputs: [
|
|
3116
|
+
{
|
|
3117
|
+
indexed: false,
|
|
3118
|
+
internalType: "address",
|
|
3119
|
+
name: "borrower",
|
|
3120
|
+
type: "address"
|
|
3121
|
+
},
|
|
3122
|
+
{
|
|
3123
|
+
indexed: false,
|
|
3124
|
+
internalType: "uint256",
|
|
3125
|
+
name: "amount",
|
|
3126
|
+
type: "uint256"
|
|
3127
|
+
}
|
|
3128
|
+
],
|
|
3129
|
+
name: "PrivilegedLoanRepaid",
|
|
3130
|
+
type: "event"
|
|
3131
|
+
},
|
|
3132
|
+
{
|
|
3133
|
+
anonymous: false,
|
|
3134
|
+
inputs: [
|
|
3135
|
+
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3136
|
+
{
|
|
3137
|
+
indexed: true,
|
|
3138
|
+
internalType: "bytes32",
|
|
3139
|
+
name: "previousAdminRole",
|
|
3140
|
+
type: "bytes32"
|
|
3141
|
+
},
|
|
3142
|
+
{
|
|
3143
|
+
indexed: true,
|
|
3144
|
+
internalType: "bytes32",
|
|
3145
|
+
name: "newAdminRole",
|
|
3146
|
+
type: "bytes32"
|
|
3147
|
+
}
|
|
3148
|
+
],
|
|
3149
|
+
name: "RoleAdminChanged",
|
|
3150
|
+
type: "event"
|
|
3151
|
+
},
|
|
3152
|
+
{
|
|
3153
|
+
anonymous: false,
|
|
3154
|
+
inputs: [
|
|
3155
|
+
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3156
|
+
{
|
|
3157
|
+
indexed: true,
|
|
3158
|
+
internalType: "address",
|
|
3159
|
+
name: "account",
|
|
3160
|
+
type: "address"
|
|
3161
|
+
},
|
|
3162
|
+
{
|
|
3163
|
+
indexed: true,
|
|
3164
|
+
internalType: "address",
|
|
3165
|
+
name: "sender",
|
|
3166
|
+
type: "address"
|
|
3167
|
+
}
|
|
3168
|
+
],
|
|
3169
|
+
name: "RoleGranted",
|
|
3170
|
+
type: "event"
|
|
3171
|
+
},
|
|
3172
|
+
{
|
|
3173
|
+
anonymous: false,
|
|
3174
|
+
inputs: [
|
|
3175
|
+
{ indexed: true, internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3176
|
+
{
|
|
3177
|
+
indexed: true,
|
|
3178
|
+
internalType: "address",
|
|
3179
|
+
name: "account",
|
|
3180
|
+
type: "address"
|
|
3181
|
+
},
|
|
3182
|
+
{
|
|
3183
|
+
indexed: true,
|
|
3184
|
+
internalType: "address",
|
|
3185
|
+
name: "sender",
|
|
3186
|
+
type: "address"
|
|
3187
|
+
}
|
|
3188
|
+
],
|
|
3189
|
+
name: "RoleRevoked",
|
|
3190
|
+
type: "event"
|
|
3191
|
+
},
|
|
3192
|
+
{
|
|
3193
|
+
inputs: [],
|
|
3194
|
+
name: "BORROWER_ROUTER_ROLE",
|
|
3195
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
3196
|
+
stateMutability: "view",
|
|
3197
|
+
type: "function"
|
|
3198
|
+
},
|
|
3199
|
+
{
|
|
3200
|
+
inputs: [],
|
|
3201
|
+
name: "DEFAULT_ADMIN_ROLE",
|
|
3202
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
3203
|
+
stateMutability: "view",
|
|
3204
|
+
type: "function"
|
|
3205
|
+
},
|
|
3206
|
+
{
|
|
3207
|
+
inputs: [
|
|
3208
|
+
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
3209
|
+
{ internalType: "uint256", name: "_interestRate", type: "uint256" },
|
|
3210
|
+
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
3211
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" }
|
|
3212
|
+
],
|
|
3213
|
+
name: "addCollateral",
|
|
3214
|
+
outputs: [],
|
|
3215
|
+
stateMutability: "nonpayable",
|
|
3216
|
+
type: "function"
|
|
3217
|
+
},
|
|
3218
|
+
{
|
|
3219
|
+
inputs: [{ internalType: "address", name: "", type: "address" }],
|
|
3220
|
+
name: "collateralMapping",
|
|
3221
|
+
outputs: [
|
|
3222
|
+
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
3223
|
+
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
3224
|
+
{ internalType: "uint256", name: "interestRate", type: "uint256" },
|
|
3225
|
+
{ internalType: "bool", name: "active", type: "bool" },
|
|
3226
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" }
|
|
3227
|
+
],
|
|
3228
|
+
stateMutability: "view",
|
|
3229
|
+
type: "function"
|
|
3230
|
+
},
|
|
3231
|
+
{
|
|
3232
|
+
inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
|
|
3233
|
+
name: "deposit",
|
|
3234
|
+
outputs: [],
|
|
3235
|
+
stateMutability: "nonpayable",
|
|
3236
|
+
type: "function"
|
|
3237
|
+
},
|
|
3238
|
+
{
|
|
3239
|
+
inputs: [],
|
|
3240
|
+
name: "getBalance",
|
|
3241
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3242
|
+
stateMutability: "view",
|
|
3243
|
+
type: "function"
|
|
3244
|
+
},
|
|
3245
|
+
{
|
|
3246
|
+
inputs: [{ internalType: "bytes32", name: "role", type: "bytes32" }],
|
|
3247
|
+
name: "getRoleAdmin",
|
|
3248
|
+
outputs: [{ internalType: "bytes32", name: "", type: "bytes32" }],
|
|
3249
|
+
stateMutability: "view",
|
|
3250
|
+
type: "function"
|
|
3251
|
+
},
|
|
3252
|
+
{
|
|
3253
|
+
inputs: [{ internalType: "address", name: "account", type: "address" }],
|
|
3254
|
+
name: "grantBorrowerRouterRole",
|
|
3255
|
+
outputs: [],
|
|
3256
|
+
stateMutability: "nonpayable",
|
|
3257
|
+
type: "function"
|
|
3258
|
+
},
|
|
3259
|
+
{
|
|
3260
|
+
inputs: [
|
|
3261
|
+
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3262
|
+
{ internalType: "address", name: "account", type: "address" }
|
|
3263
|
+
],
|
|
3264
|
+
name: "grantRole",
|
|
3265
|
+
outputs: [],
|
|
3266
|
+
stateMutability: "nonpayable",
|
|
3267
|
+
type: "function"
|
|
3268
|
+
},
|
|
3269
|
+
{
|
|
3270
|
+
inputs: [
|
|
3271
|
+
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3272
|
+
{ internalType: "address", name: "account", type: "address" }
|
|
3273
|
+
],
|
|
3274
|
+
name: "hasRole",
|
|
3275
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
3276
|
+
stateMutability: "view",
|
|
3277
|
+
type: "function"
|
|
3278
|
+
},
|
|
3279
|
+
{
|
|
3280
|
+
inputs: [
|
|
3281
|
+
{ internalType: "address", name: "_tokenAddress", type: "address" }
|
|
3282
|
+
],
|
|
3283
|
+
name: "initialize",
|
|
3284
|
+
outputs: [],
|
|
3285
|
+
stateMutability: "nonpayable",
|
|
3286
|
+
type: "function"
|
|
3287
|
+
},
|
|
3288
|
+
{
|
|
3289
|
+
inputs: [
|
|
3290
|
+
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
3291
|
+
{ internalType: "uint256", name: "collateralAmount", type: "uint256" },
|
|
3292
|
+
{ internalType: "address", name: "collateralAddress", type: "address" },
|
|
3293
|
+
{ internalType: "address", name: "borrower", type: "address" },
|
|
3294
|
+
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
3295
|
+
],
|
|
3296
|
+
name: "loanConfirmation",
|
|
3297
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3298
|
+
stateMutability: "nonpayable",
|
|
3299
|
+
type: "function"
|
|
3300
|
+
},
|
|
3301
|
+
{
|
|
3302
|
+
inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3303
|
+
name: "loans",
|
|
3304
|
+
outputs: [
|
|
3305
|
+
{ internalType: "uint256", name: "id", type: "uint256" },
|
|
3306
|
+
{ internalType: "uint256", name: "amount", type: "uint256" },
|
|
3307
|
+
{
|
|
3308
|
+
components: [
|
|
3309
|
+
{
|
|
3310
|
+
internalType: "address",
|
|
3311
|
+
name: "collateralAddress",
|
|
3312
|
+
type: "address"
|
|
3313
|
+
},
|
|
3314
|
+
{ internalType: "uint256", name: "maxLendPerToken", type: "uint256" },
|
|
3315
|
+
{ internalType: "uint256", name: "interestRate", type: "uint256" },
|
|
3316
|
+
{ internalType: "bool", name: "active", type: "bool" },
|
|
3317
|
+
{ internalType: "uint256", name: "minAmount", type: "uint256" }
|
|
3318
|
+
],
|
|
3319
|
+
internalType: "struct Collateral",
|
|
3320
|
+
name: "collateral",
|
|
3321
|
+
type: "tuple"
|
|
3322
|
+
},
|
|
3323
|
+
{ internalType: "uint256", name: "collateralAmount", type: "uint256" },
|
|
3324
|
+
{ internalType: "uint256", name: "timestamp", type: "uint256" },
|
|
3325
|
+
{ internalType: "address", name: "borrower", type: "address" },
|
|
3326
|
+
{ internalType: "uint256", name: "userPaid", type: "uint256" }
|
|
3327
|
+
],
|
|
3328
|
+
stateMutability: "view",
|
|
3329
|
+
type: "function"
|
|
3330
|
+
},
|
|
3331
|
+
{
|
|
3332
|
+
inputs: [],
|
|
3333
|
+
name: "nextLoanId",
|
|
3334
|
+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
|
|
3335
|
+
stateMutability: "view",
|
|
3336
|
+
type: "function"
|
|
3337
|
+
},
|
|
3338
|
+
{
|
|
3339
|
+
inputs: [
|
|
3340
|
+
{
|
|
3341
|
+
internalType: "contract IERC20",
|
|
3342
|
+
name: "flashLoanToken",
|
|
3343
|
+
type: "address"
|
|
3344
|
+
},
|
|
3345
|
+
{ internalType: "uint256", name: "amount", type: "uint256" }
|
|
3346
|
+
],
|
|
3347
|
+
name: "privilegedLoan",
|
|
3348
|
+
outputs: [],
|
|
3349
|
+
stateMutability: "nonpayable",
|
|
3350
|
+
type: "function"
|
|
3351
|
+
},
|
|
3352
|
+
{
|
|
3353
|
+
inputs: [
|
|
3354
|
+
{ internalType: "address", name: "collateralAddress", type: "address" }
|
|
3355
|
+
],
|
|
3356
|
+
name: "removeCollateral",
|
|
3357
|
+
outputs: [],
|
|
3358
|
+
stateMutability: "nonpayable",
|
|
3359
|
+
type: "function"
|
|
3360
|
+
},
|
|
3361
|
+
{
|
|
3362
|
+
inputs: [
|
|
3363
|
+
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3364
|
+
{ internalType: "address", name: "callerConfirmation", type: "address" }
|
|
3365
|
+
],
|
|
3366
|
+
name: "renounceRole",
|
|
3367
|
+
outputs: [],
|
|
3368
|
+
stateMutability: "nonpayable",
|
|
3369
|
+
type: "function"
|
|
3370
|
+
},
|
|
3371
|
+
{
|
|
3372
|
+
inputs: [{ internalType: "uint256", name: "loanId", type: "uint256" }],
|
|
3373
|
+
name: "repayLoan",
|
|
3374
|
+
outputs: [],
|
|
3375
|
+
stateMutability: "nonpayable",
|
|
3376
|
+
type: "function"
|
|
3377
|
+
},
|
|
3378
|
+
{
|
|
3379
|
+
inputs: [{ internalType: "address", name: "account", type: "address" }],
|
|
3380
|
+
name: "revokeBorrowerRouterRole",
|
|
3381
|
+
outputs: [],
|
|
3382
|
+
stateMutability: "nonpayable",
|
|
3383
|
+
type: "function"
|
|
3384
|
+
},
|
|
3385
|
+
{
|
|
3386
|
+
inputs: [
|
|
3387
|
+
{ internalType: "bytes32", name: "role", type: "bytes32" },
|
|
3388
|
+
{ internalType: "address", name: "account", type: "address" }
|
|
3389
|
+
],
|
|
3390
|
+
name: "revokeRole",
|
|
3391
|
+
outputs: [],
|
|
3392
|
+
stateMutability: "nonpayable",
|
|
3393
|
+
type: "function"
|
|
3394
|
+
},
|
|
3395
|
+
{
|
|
3396
|
+
inputs: [{ internalType: "bytes4", name: "interfaceId", type: "bytes4" }],
|
|
3397
|
+
name: "supportsInterface",
|
|
3398
|
+
outputs: [{ internalType: "bool", name: "", type: "bool" }],
|
|
3399
|
+
stateMutability: "view",
|
|
3400
|
+
type: "function"
|
|
3401
|
+
},
|
|
3402
|
+
{
|
|
3403
|
+
inputs: [],
|
|
3404
|
+
name: "tokenHolded",
|
|
3405
|
+
outputs: [{ internalType: "contract IERC20", name: "", type: "address" }],
|
|
3406
|
+
stateMutability: "view",
|
|
3407
|
+
type: "function"
|
|
3408
|
+
},
|
|
3409
|
+
{
|
|
3410
|
+
inputs: [
|
|
3411
|
+
{
|
|
3412
|
+
internalType: "address[]",
|
|
3413
|
+
name: "collateralAddresses",
|
|
3414
|
+
type: "address[]"
|
|
3415
|
+
},
|
|
3416
|
+
{
|
|
3417
|
+
internalType: "uint256[]",
|
|
3418
|
+
name: "newMaxLendPerTokens",
|
|
3419
|
+
type: "uint256[]"
|
|
3420
|
+
}
|
|
3421
|
+
],
|
|
3422
|
+
name: "updateMaxLendPerTokenBulk",
|
|
3423
|
+
outputs: [],
|
|
3424
|
+
stateMutability: "nonpayable",
|
|
3425
|
+
type: "function"
|
|
3426
|
+
},
|
|
3427
|
+
{
|
|
3428
|
+
inputs: [{ internalType: "uint256", name: "amount", type: "uint256" }],
|
|
3429
|
+
name: "withdraw",
|
|
3430
|
+
outputs: [],
|
|
3431
|
+
stateMutability: "nonpayable",
|
|
3432
|
+
type: "function"
|
|
3433
|
+
}
|
|
3434
|
+
];
|
|
3435
|
+
|
|
3436
|
+
// evm.ts
|
|
3437
|
+
var openPositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (signer, borrowerOpsContractAddress, {
|
|
3438
|
+
buyingCode,
|
|
3439
|
+
tokenCollateral,
|
|
3440
|
+
borrowAmount,
|
|
3441
|
+
tokenHolder,
|
|
3442
|
+
inchRouter,
|
|
3443
|
+
integratorFeeAddress = import_ethers.ZeroAddress,
|
|
3444
|
+
buyerContribution
|
|
3445
|
+
}) {
|
|
3446
|
+
const contract = new import_ethers.Contract(
|
|
3447
|
+
borrowerOpsContractAddress,
|
|
3448
|
+
borrowerOperationsAbi,
|
|
3449
|
+
signer
|
|
3450
|
+
);
|
|
3451
|
+
return contract.buy(
|
|
3452
|
+
buyingCode,
|
|
3453
|
+
tokenCollateral,
|
|
3454
|
+
borrowAmount,
|
|
3455
|
+
tokenHolder,
|
|
3456
|
+
inchRouter,
|
|
3457
|
+
integratorFeeAddress,
|
|
3458
|
+
{ value: buyerContribution }
|
|
3459
|
+
);
|
|
3460
|
+
});
|
|
3461
|
+
var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (signer, borrowerOpsContractAddress, {
|
|
3462
|
+
loanId,
|
|
3463
|
+
sellingCode,
|
|
3464
|
+
tokenHolder,
|
|
3465
|
+
inchRouter,
|
|
3466
|
+
integratorFeeAddress = import_ethers.ZeroAddress
|
|
3467
|
+
}) {
|
|
3468
|
+
const contract = new import_ethers.Contract(
|
|
3469
|
+
borrowerOpsContractAddress,
|
|
3470
|
+
borrowerOperationsAbi,
|
|
3471
|
+
signer
|
|
3472
|
+
);
|
|
3473
|
+
return contract.sell(
|
|
3474
|
+
loanId,
|
|
3475
|
+
sellingCode,
|
|
3476
|
+
tokenHolder,
|
|
3477
|
+
inchRouter,
|
|
3478
|
+
integratorFeeAddress
|
|
3479
|
+
);
|
|
3480
|
+
});
|
|
3481
|
+
function getPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
|
|
3482
|
+
return __async(this, null, function* () {
|
|
3483
|
+
const contract = new import_ethers.Contract(
|
|
3484
|
+
borrowerOpsContractAddress,
|
|
3485
|
+
borrowerOperationsAbi,
|
|
3486
|
+
provider
|
|
3487
|
+
);
|
|
3488
|
+
const filter = contract.filters.Buy();
|
|
3489
|
+
const events = yield contract.queryFilter(filter, fromBlock);
|
|
3490
|
+
return events.map((event) => {
|
|
3491
|
+
const {
|
|
3492
|
+
trader,
|
|
3493
|
+
tokenCollateral,
|
|
3494
|
+
loanId,
|
|
3495
|
+
openingPositionSize,
|
|
3496
|
+
collateralAmount,
|
|
3497
|
+
initialMargin
|
|
3498
|
+
} = event.args;
|
|
3499
|
+
return {
|
|
3500
|
+
trader,
|
|
3501
|
+
tokenCollateral,
|
|
3502
|
+
loanId,
|
|
3503
|
+
openingPositionSize,
|
|
3504
|
+
collateralAmount,
|
|
3505
|
+
initialMargin
|
|
3506
|
+
};
|
|
3507
|
+
});
|
|
3508
|
+
});
|
|
3509
|
+
}
|
|
3510
|
+
function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
|
|
3511
|
+
return __async(this, null, function* () {
|
|
3512
|
+
const contract = new import_ethers.Contract(
|
|
3513
|
+
borrowerOpsContractAddress,
|
|
3514
|
+
borrowerOperationsAbi,
|
|
3515
|
+
provider
|
|
3516
|
+
);
|
|
3517
|
+
const filter = contract.filters.Sell();
|
|
3518
|
+
const events = yield contract.queryFilter(filter, fromBlock);
|
|
3519
|
+
return events.map((event) => {
|
|
3520
|
+
const { trader, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
|
|
3521
|
+
return {
|
|
3522
|
+
trader,
|
|
3523
|
+
tokenCollateral,
|
|
3524
|
+
loanId,
|
|
3525
|
+
closingPositionSize,
|
|
3526
|
+
profit
|
|
3527
|
+
};
|
|
3528
|
+
});
|
|
3529
|
+
});
|
|
3530
|
+
}
|
|
3531
|
+
function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 0) {
|
|
3532
|
+
return __async(this, null, function* () {
|
|
3533
|
+
const contract = new import_ethers.Contract(
|
|
3534
|
+
borrowerOpsContractAddress,
|
|
3535
|
+
borrowerOperationsAbi,
|
|
3536
|
+
provider
|
|
3537
|
+
);
|
|
3538
|
+
const filter = contract.filters.Liquidation();
|
|
3539
|
+
const events = yield contract.queryFilter(filter, fromBlock);
|
|
3540
|
+
return events.map((event) => {
|
|
3541
|
+
const {
|
|
3542
|
+
trader,
|
|
3543
|
+
tokenCollateral,
|
|
3544
|
+
loanId,
|
|
3545
|
+
closingPositionSize,
|
|
3546
|
+
liquidatorRepaidAmount
|
|
3547
|
+
} = event.args;
|
|
3548
|
+
return {
|
|
3549
|
+
trader,
|
|
3550
|
+
tokenCollateral,
|
|
3551
|
+
loanId,
|
|
3552
|
+
closingPositionSize,
|
|
3553
|
+
liquidatorRepaidAmount
|
|
3554
|
+
};
|
|
3555
|
+
});
|
|
3556
|
+
});
|
|
3557
|
+
}
|
|
3558
|
+
function getLoanEvm(provider, tokenHolderContractAddress, loanId) {
|
|
3559
|
+
return __async(this, null, function* () {
|
|
3560
|
+
const contract = new import_ethers.Contract(
|
|
3561
|
+
tokenHolderContractAddress,
|
|
3562
|
+
tokenHolderAbi,
|
|
3563
|
+
provider
|
|
3564
|
+
);
|
|
3565
|
+
return contract.loans(loanId);
|
|
3566
|
+
});
|
|
3567
|
+
}
|
|
3568
|
+
function getUserLoansEvm(provider, tokenHolderContractAddress, userAddress) {
|
|
3569
|
+
return __async(this, null, function* () {
|
|
3570
|
+
const contract = new import_ethers.Contract(
|
|
3571
|
+
tokenHolderContractAddress,
|
|
3572
|
+
tokenHolderAbi,
|
|
3573
|
+
provider
|
|
3574
|
+
);
|
|
3575
|
+
const nextLoanId = yield contract.nextLoanId();
|
|
3576
|
+
const userLoans = [];
|
|
3577
|
+
for (let i = 0; i < nextLoanId; i++) {
|
|
3578
|
+
const loan = yield contract.loans(i);
|
|
3579
|
+
if (loan.borrower.toLowerCase() === userAddress.toLowerCase()) {
|
|
3580
|
+
userLoans.push(loan);
|
|
3581
|
+
}
|
|
3582
|
+
}
|
|
3583
|
+
return userLoans;
|
|
3584
|
+
});
|
|
3585
|
+
}
|
|
3586
|
+
function getCollateralInfoEvm(provider, tokenHolderContractAddress, collateralAddress) {
|
|
3587
|
+
return __async(this, null, function* () {
|
|
3588
|
+
const contract = new import_ethers.Contract(
|
|
3589
|
+
tokenHolderContractAddress,
|
|
3590
|
+
tokenHolderAbi,
|
|
3591
|
+
provider
|
|
3592
|
+
);
|
|
3593
|
+
return contract.collateralMapping(collateralAddress);
|
|
3594
|
+
});
|
|
3595
|
+
}
|
|
3596
|
+
function getOffersEvm(provider, tokenHolderContractAddress, collateralAddresses) {
|
|
3597
|
+
return __async(this, null, function* () {
|
|
3598
|
+
const contract = new import_ethers.Contract(
|
|
3599
|
+
tokenHolderContractAddress,
|
|
3600
|
+
tokenHolderAbi,
|
|
3601
|
+
provider
|
|
3602
|
+
);
|
|
3603
|
+
const activeCollaterals = [];
|
|
3604
|
+
for (const address of collateralAddresses) {
|
|
3605
|
+
const collateral = yield contract.collateralMapping(address);
|
|
3606
|
+
if (collateral.active) {
|
|
3607
|
+
activeCollaterals.push({
|
|
3608
|
+
address,
|
|
3609
|
+
collateral
|
|
3610
|
+
});
|
|
3611
|
+
}
|
|
3612
|
+
}
|
|
3613
|
+
return activeCollaterals;
|
|
3614
|
+
});
|
|
3615
|
+
}
|
|
3616
|
+
|
|
2729
3617
|
// index.ts
|
|
2730
3618
|
function getPda(seed, programId) {
|
|
2731
3619
|
const seedsBuffer = Array.isArray(seed) ? seed : [seed];
|
|
2732
3620
|
return import_web3.PublicKey.findProgramAddressSync(seedsBuffer, programId)[0];
|
|
2733
3621
|
}
|
|
2734
3622
|
function getPositionAccountPDA(lavarageProgram, offer, seed) {
|
|
2735
|
-
return getPda(
|
|
3623
|
+
return getPda(
|
|
3624
|
+
[
|
|
3625
|
+
Buffer.from("position"),
|
|
3626
|
+
lavarageProgram.provider.publicKey.toBuffer(),
|
|
3627
|
+
offer.publicKey.toBuffer(),
|
|
3628
|
+
seed.toBuffer()
|
|
3629
|
+
],
|
|
3630
|
+
lavarageProgram.programId
|
|
3631
|
+
);
|
|
2736
3632
|
}
|
|
2737
3633
|
function getTokenAccountOrCreateIfNotExists(lavarageProgram, ownerPublicKey, tokenAddress, tokenProgram) {
|
|
2738
3634
|
return __async(this, null, function* () {
|
|
2739
|
-
const associatedTokenAddress = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3635
|
+
const associatedTokenAddress = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3636
|
+
tokenAddress,
|
|
3637
|
+
ownerPublicKey,
|
|
3638
|
+
true,
|
|
3639
|
+
tokenProgram,
|
|
3640
|
+
import_spl_token.ASSOCIATED_TOKEN_PROGRAM_ID
|
|
3641
|
+
);
|
|
2740
3642
|
const instruction = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
|
|
2741
3643
|
lavarageProgram.provider.publicKey,
|
|
2742
3644
|
associatedTokenAddress,
|
|
@@ -2785,23 +3687,27 @@ var getClosedPositions = (lavarageProgram) => __async(void 0, null, function* ()
|
|
|
2785
3687
|
bytes: import_bs58.default.encode(Uint8Array.from(valueBuffer))
|
|
2786
3688
|
}
|
|
2787
3689
|
}
|
|
2788
|
-
])).concat(
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
3690
|
+
])).concat(
|
|
3691
|
+
yield lavarageProgram.account.position.all([
|
|
3692
|
+
{ dataSize: 178 },
|
|
3693
|
+
{
|
|
3694
|
+
memcmp: {
|
|
3695
|
+
offset: 40,
|
|
3696
|
+
bytes: import_bs58.default.encode(Uint8Array.from(valueBuffer2))
|
|
3697
|
+
}
|
|
2794
3698
|
}
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
3699
|
+
])
|
|
3700
|
+
).concat(
|
|
3701
|
+
yield lavarageProgram.account.position.all([
|
|
3702
|
+
{ dataSize: 178 },
|
|
3703
|
+
{
|
|
3704
|
+
memcmp: {
|
|
3705
|
+
offset: 40,
|
|
3706
|
+
bytes: import_bs58.default.encode(Uint8Array.from(valueBuffer3))
|
|
3707
|
+
}
|
|
2802
3708
|
}
|
|
2803
|
-
|
|
2804
|
-
|
|
3709
|
+
])
|
|
3710
|
+
);
|
|
2805
3711
|
});
|
|
2806
3712
|
var getLiquidatedPositions = (lavarageProgram) => {
|
|
2807
3713
|
const value = BigInt(9999);
|
|
@@ -2818,9 +3724,7 @@ var getLiquidatedPositions = (lavarageProgram) => {
|
|
|
2818
3724
|
]);
|
|
2819
3725
|
};
|
|
2820
3726
|
var getAllPositions = (lavarageProgram) => {
|
|
2821
|
-
return lavarageProgram.account.position.all([
|
|
2822
|
-
{ dataSize: 178 }
|
|
2823
|
-
]);
|
|
3727
|
+
return lavarageProgram.account.position.all([{ dataSize: 178 }]);
|
|
2824
3728
|
};
|
|
2825
3729
|
var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage, randomSeed, partnerFeeRecipient, partnerFeeMarkup) => __async(void 0, null, function* () {
|
|
2826
3730
|
let partnerFeeMarkupAsPkey;
|
|
@@ -2831,11 +3735,27 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2831
3735
|
feeBuffer32.set(feeBuffer, 0);
|
|
2832
3736
|
partnerFeeMarkupAsPkey = new import_web3.PublicKey(feeBuffer32);
|
|
2833
3737
|
}
|
|
2834
|
-
const positionAccount = getPositionAccountPDA(
|
|
2835
|
-
|
|
3738
|
+
const positionAccount = getPositionAccountPDA(
|
|
3739
|
+
lavarageProgram,
|
|
3740
|
+
offer,
|
|
3741
|
+
randomSeed.publicKey
|
|
3742
|
+
);
|
|
3743
|
+
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
3744
|
+
offer.account.collateralType
|
|
3745
|
+
);
|
|
2836
3746
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
2837
|
-
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
2838
|
-
|
|
3747
|
+
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
3748
|
+
lavarageProgram,
|
|
3749
|
+
lavarageProgram.provider.publicKey,
|
|
3750
|
+
offer.account.collateralType,
|
|
3751
|
+
tokenProgram
|
|
3752
|
+
);
|
|
3753
|
+
const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
3754
|
+
lavarageProgram,
|
|
3755
|
+
positionAccount,
|
|
3756
|
+
offer.account.collateralType,
|
|
3757
|
+
tokenProgram
|
|
3758
|
+
);
|
|
2839
3759
|
const tokenAccountCreationTx = new import_web3.Transaction();
|
|
2840
3760
|
if (fromTokenAccount.instruction) {
|
|
2841
3761
|
tokenAccountCreationTx.add(fromTokenAccount.instruction);
|
|
@@ -2844,7 +3764,11 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2844
3764
|
tokenAccountCreationTx.add(toTokenAccount.instruction);
|
|
2845
3765
|
}
|
|
2846
3766
|
const instructionsJup = jupInstruction.instructions;
|
|
2847
|
-
const {
|
|
3767
|
+
const {
|
|
3768
|
+
setupInstructions,
|
|
3769
|
+
swapInstruction: swapInstructionPayload,
|
|
3770
|
+
addressLookupTableAddresses
|
|
3771
|
+
} = instructionsJup;
|
|
2848
3772
|
const deserializeInstruction = (instruction) => {
|
|
2849
3773
|
return new import_web3.TransactionInstruction({
|
|
2850
3774
|
programId: new import_web3.PublicKey(instruction.programId),
|
|
@@ -2857,13 +3781,17 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2857
3781
|
});
|
|
2858
3782
|
};
|
|
2859
3783
|
const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
|
|
2860
|
-
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
3784
|
+
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
3785
|
+
keys.map((key) => new import_web3.PublicKey(key))
|
|
3786
|
+
);
|
|
2861
3787
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
2862
3788
|
const addressLookupTableAddress = keys[index];
|
|
2863
3789
|
if (accountInfo) {
|
|
2864
3790
|
const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
|
|
2865
3791
|
key: new import_web3.PublicKey(addressLookupTableAddress),
|
|
2866
|
-
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
3792
|
+
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
3793
|
+
Uint8Array.from(accountInfo.data)
|
|
3794
|
+
)
|
|
2867
3795
|
});
|
|
2868
3796
|
acc.push(addressLookupTableAccount);
|
|
2869
3797
|
}
|
|
@@ -2871,9 +3799,17 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2871
3799
|
}, new Array());
|
|
2872
3800
|
});
|
|
2873
3801
|
const addressLookupTableAccounts = [];
|
|
2874
|
-
addressLookupTableAccounts.push(
|
|
3802
|
+
addressLookupTableAccounts.push(
|
|
3803
|
+
...yield getAddressLookupTableAccounts([
|
|
3804
|
+
"5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi",
|
|
3805
|
+
...addressLookupTableAddresses
|
|
3806
|
+
])
|
|
3807
|
+
);
|
|
2875
3808
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
2876
|
-
const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
|
|
3809
|
+
const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
|
|
3810
|
+
new import_anchor.BN((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
3811
|
+
marginSOL
|
|
3812
|
+
).accountsStrict({
|
|
2877
3813
|
nodeWallet: offer.account.nodeWallet,
|
|
2878
3814
|
instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2879
3815
|
tradingPool: offer.publicKey,
|
|
@@ -2883,15 +3819,20 @@ var openTradeV1 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2883
3819
|
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
2884
3820
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
2885
3821
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
2886
|
-
}).remainingAccounts(
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
3822
|
+
}).remainingAccounts(
|
|
3823
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
3824
|
+
{
|
|
3825
|
+
pubkey: partnerFeeRecipient,
|
|
3826
|
+
isSigner: false,
|
|
3827
|
+
isWritable: true
|
|
3828
|
+
},
|
|
3829
|
+
{
|
|
3830
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
3831
|
+
isSigner: false,
|
|
3832
|
+
isWritable: false
|
|
3833
|
+
}
|
|
3834
|
+
] : []
|
|
3835
|
+
).instruction();
|
|
2895
3836
|
const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
|
|
2896
3837
|
tradingPool: offer.publicKey,
|
|
2897
3838
|
trader: lavarageProgram.provider.publicKey,
|
|
@@ -2929,13 +3870,29 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2929
3870
|
feeBuffer32.set(feeBuffer, 0);
|
|
2930
3871
|
partnerFeeMarkupAsPkey = new import_web3.PublicKey(feeBuffer32);
|
|
2931
3872
|
}
|
|
2932
|
-
const positionAccount = getPositionAccountPDA(
|
|
2933
|
-
|
|
3873
|
+
const positionAccount = getPositionAccountPDA(
|
|
3874
|
+
lavarageProgram,
|
|
3875
|
+
offer,
|
|
3876
|
+
randomSeed.publicKey
|
|
3877
|
+
);
|
|
3878
|
+
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
3879
|
+
offer.account.collateralType
|
|
3880
|
+
);
|
|
2934
3881
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
2935
3882
|
const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
|
|
2936
3883
|
const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
|
|
2937
|
-
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
2938
|
-
|
|
3884
|
+
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
3885
|
+
lavarageProgram,
|
|
3886
|
+
lavarageProgram.provider.publicKey,
|
|
3887
|
+
offer.account.collateralType,
|
|
3888
|
+
tokenProgram
|
|
3889
|
+
);
|
|
3890
|
+
const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
3891
|
+
lavarageProgram,
|
|
3892
|
+
positionAccount,
|
|
3893
|
+
offer.account.collateralType,
|
|
3894
|
+
tokenProgram
|
|
3895
|
+
);
|
|
2939
3896
|
const tokenAccountCreationTx = new import_web3.Transaction();
|
|
2940
3897
|
if (fromTokenAccount.instruction) {
|
|
2941
3898
|
tokenAccountCreationTx.add(fromTokenAccount.instruction);
|
|
@@ -2944,7 +3901,11 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2944
3901
|
tokenAccountCreationTx.add(toTokenAccount.instruction);
|
|
2945
3902
|
}
|
|
2946
3903
|
const instructionsJup = jupInstruction.instructions;
|
|
2947
|
-
const {
|
|
3904
|
+
const {
|
|
3905
|
+
setupInstructions,
|
|
3906
|
+
swapInstruction: swapInstructionPayload,
|
|
3907
|
+
addressLookupTableAddresses
|
|
3908
|
+
} = instructionsJup;
|
|
2948
3909
|
const deserializeInstruction = (instruction) => {
|
|
2949
3910
|
return new import_web3.TransactionInstruction({
|
|
2950
3911
|
programId: new import_web3.PublicKey(instruction.programId),
|
|
@@ -2957,13 +3918,17 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2957
3918
|
});
|
|
2958
3919
|
};
|
|
2959
3920
|
const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
|
|
2960
|
-
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
3921
|
+
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
3922
|
+
keys.map((key) => new import_web3.PublicKey(key))
|
|
3923
|
+
);
|
|
2961
3924
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
2962
3925
|
const addressLookupTableAddress = keys[index];
|
|
2963
3926
|
if (accountInfo) {
|
|
2964
3927
|
const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
|
|
2965
3928
|
key: new import_web3.PublicKey(addressLookupTableAddress),
|
|
2966
|
-
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
3929
|
+
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
3930
|
+
Uint8Array.from(accountInfo.data)
|
|
3931
|
+
)
|
|
2967
3932
|
});
|
|
2968
3933
|
acc.push(addressLookupTableAccount);
|
|
2969
3934
|
}
|
|
@@ -2971,9 +3936,18 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2971
3936
|
}, new Array());
|
|
2972
3937
|
});
|
|
2973
3938
|
const addressLookupTableAccounts = [];
|
|
2974
|
-
addressLookupTableAccounts.push(
|
|
3939
|
+
addressLookupTableAccounts.push(
|
|
3940
|
+
...yield getAddressLookupTableAccounts([
|
|
3941
|
+
...addressLookupTableAddresses,
|
|
3942
|
+
getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()),
|
|
3943
|
+
"5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"
|
|
3944
|
+
])
|
|
3945
|
+
);
|
|
2975
3946
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
2976
|
-
const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
|
|
3947
|
+
const tradingOpenBorrowInstruction = yield lavarageProgram.methods.tradingOpenBorrow(
|
|
3948
|
+
new import_anchor.BN((marginSOL.toNumber() * leverage).toFixed(0)),
|
|
3949
|
+
marginSOL
|
|
3950
|
+
).accountsStrict({
|
|
2977
3951
|
nodeWallet: offer.account.nodeWallet,
|
|
2978
3952
|
instructions: import_web3.SYSVAR_INSTRUCTIONS_PUBKEY,
|
|
2979
3953
|
tradingPool: offer.publicKey,
|
|
@@ -2982,19 +3956,44 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
2982
3956
|
systemProgram: import_web3.SystemProgram.programId,
|
|
2983
3957
|
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
2984
3958
|
randomAccountAsId: randomSeed.publicKey.toBase58(),
|
|
2985
|
-
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
2986
|
-
|
|
3959
|
+
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3960
|
+
quoteToken,
|
|
3961
|
+
new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
3962
|
+
true,
|
|
3963
|
+
quoteTokenProgram
|
|
3964
|
+
),
|
|
3965
|
+
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3966
|
+
quoteToken,
|
|
3967
|
+
lavarageProgram.provider.publicKey,
|
|
3968
|
+
true,
|
|
3969
|
+
quoteTokenProgram
|
|
3970
|
+
),
|
|
2987
3971
|
tokenProgram: quoteTokenProgram,
|
|
2988
|
-
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
2989
|
-
|
|
2990
|
-
|
|
2991
|
-
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
3972
|
+
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3973
|
+
quoteToken,
|
|
3974
|
+
offer.account.nodeWallet,
|
|
3975
|
+
true,
|
|
3976
|
+
quoteTokenProgram
|
|
3977
|
+
)
|
|
3978
|
+
}).remainingAccounts(
|
|
3979
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
3980
|
+
{
|
|
3981
|
+
pubkey: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3982
|
+
quoteToken,
|
|
3983
|
+
partnerFeeRecipient,
|
|
3984
|
+
false,
|
|
3985
|
+
quoteTokenProgram
|
|
3986
|
+
),
|
|
3987
|
+
isSigner: false,
|
|
3988
|
+
isWritable: true
|
|
3989
|
+
},
|
|
3990
|
+
{
|
|
3991
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
3992
|
+
isSigner: false,
|
|
3993
|
+
isWritable: false
|
|
3994
|
+
}
|
|
3995
|
+
] : []
|
|
3996
|
+
).instruction();
|
|
2998
3997
|
const openAddCollateralInstruction = yield lavarageProgram.methods.tradingOpenAddCollateral(offer.account.interestRate).accountsStrict({
|
|
2999
3998
|
tradingPool: offer.publicKey,
|
|
3000
3999
|
trader: lavarageProgram.provider.publicKey,
|
|
@@ -3025,65 +4024,93 @@ var openTradeV2 = (lavarageProgram, offer, jupInstruction, marginSOL, leverage,
|
|
|
3025
4024
|
});
|
|
3026
4025
|
var createTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
|
|
3027
4026
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
3028
|
-
const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
|
|
3029
|
-
|
|
4027
|
+
const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
|
|
4028
|
+
tpPrice,
|
|
4029
|
+
tpTolerence,
|
|
4030
|
+
new import_web3.PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"),
|
|
4031
|
+
new import_anchor.BN(1e4)
|
|
4032
|
+
).accountsStrict({
|
|
4033
|
+
delegate: getPda(
|
|
4034
|
+
[Buffer.from("delegate"), position.publicKey.toBuffer()],
|
|
4035
|
+
lavarageProgram.programId
|
|
4036
|
+
),
|
|
3030
4037
|
originalOperator: lavarageProgram.provider.publicKey,
|
|
3031
4038
|
delegatedAccount: position.publicKey,
|
|
3032
4039
|
systemProgram: import_web3.SystemProgram.programId
|
|
3033
|
-
}).remainingAccounts(
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
4040
|
+
}).remainingAccounts(
|
|
4041
|
+
partnerFeeRecipient ? [
|
|
4042
|
+
{
|
|
4043
|
+
pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4044
|
+
quoteToken,
|
|
4045
|
+
partnerFeeRecipient,
|
|
4046
|
+
false
|
|
4047
|
+
),
|
|
4048
|
+
isSigner: false,
|
|
4049
|
+
isWritable: true
|
|
4050
|
+
}
|
|
4051
|
+
] : []
|
|
4052
|
+
).instruction();
|
|
3038
4053
|
const computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
3039
4054
|
microLamports: prioFee.toNumber()
|
|
3040
4055
|
});
|
|
3041
4056
|
const messageV0 = new import_web3.TransactionMessage({
|
|
3042
4057
|
payerKey: lavarageProgram.provider.publicKey,
|
|
3043
4058
|
recentBlockhash: blockhash,
|
|
3044
|
-
instructions: [
|
|
3045
|
-
ix,
|
|
3046
|
-
computeFeeIx
|
|
3047
|
-
].filter(Boolean)
|
|
4059
|
+
instructions: [ix, computeFeeIx].filter(Boolean)
|
|
3048
4060
|
}).compileToV0Message();
|
|
3049
4061
|
return new import_web3.VersionedTransaction(messageV0);
|
|
3050
4062
|
});
|
|
3051
4063
|
var modifyTpDelegate = (lavarageProgram, position, tpPrice, tpTolerence, prioFee, quoteToken, partnerFeeRecipient) => __async(void 0, null, function* () {
|
|
3052
4064
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
3053
|
-
const delegatePda = getPda(
|
|
4065
|
+
const delegatePda = getPda(
|
|
4066
|
+
[Buffer.from("delegate"), position.publicKey.toBuffer()],
|
|
4067
|
+
lavarageProgram.programId
|
|
4068
|
+
);
|
|
3054
4069
|
const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
|
|
3055
4070
|
delegate: delegatePda,
|
|
3056
4071
|
originalOperator: lavarageProgram.provider.publicKey,
|
|
3057
4072
|
delegatedAccount: position.publicKey,
|
|
3058
4073
|
systemProgram: import_web3.SystemProgram.programId
|
|
3059
4074
|
}).instruction();
|
|
3060
|
-
const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
|
|
4075
|
+
const ix = yield lavarageProgram.methods.tradingCreateTpDelegate(
|
|
4076
|
+
tpPrice,
|
|
4077
|
+
tpTolerence,
|
|
4078
|
+
new import_web3.PublicKey("6dA5GTDPWxnw3gvjoy3vYBDyY7iETxcTJzt8RqF9i9MV"),
|
|
4079
|
+
new import_anchor.BN(1e4)
|
|
4080
|
+
).accountsStrict({
|
|
3061
4081
|
delegate: delegatePda,
|
|
3062
4082
|
originalOperator: lavarageProgram.provider.publicKey,
|
|
3063
4083
|
delegatedAccount: position.publicKey,
|
|
3064
4084
|
systemProgram: import_web3.SystemProgram.programId
|
|
3065
|
-
}).remainingAccounts(
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
4085
|
+
}).remainingAccounts(
|
|
4086
|
+
partnerFeeRecipient ? [
|
|
4087
|
+
{
|
|
4088
|
+
pubkey: quoteToken.toBase58() == "So11111111111111111111111111111111111111112" ? partnerFeeRecipient : (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4089
|
+
quoteToken,
|
|
4090
|
+
partnerFeeRecipient,
|
|
4091
|
+
false
|
|
4092
|
+
),
|
|
4093
|
+
isSigner: false,
|
|
4094
|
+
isWritable: true
|
|
4095
|
+
}
|
|
4096
|
+
] : []
|
|
4097
|
+
).instruction();
|
|
3070
4098
|
const computeFeeIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
3071
4099
|
microLamports: prioFee.toNumber()
|
|
3072
4100
|
});
|
|
3073
4101
|
const messageV0 = new import_web3.TransactionMessage({
|
|
3074
4102
|
payerKey: lavarageProgram.provider.publicKey,
|
|
3075
4103
|
recentBlockhash: blockhash,
|
|
3076
|
-
instructions: [
|
|
3077
|
-
removeIx,
|
|
3078
|
-
ix,
|
|
3079
|
-
computeFeeIx
|
|
3080
|
-
].filter(Boolean)
|
|
4104
|
+
instructions: [removeIx, ix, computeFeeIx].filter(Boolean)
|
|
3081
4105
|
}).compileToV0Message();
|
|
3082
4106
|
return new import_web3.VersionedTransaction(messageV0);
|
|
3083
4107
|
});
|
|
3084
4108
|
var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, null, function* () {
|
|
3085
4109
|
const { blockhash } = yield lavarageProgram.provider.connection.getLatestBlockhash("finalized");
|
|
3086
|
-
const delegatePda = getPda(
|
|
4110
|
+
const delegatePda = getPda(
|
|
4111
|
+
[Buffer.from("delegate"), position.publicKey.toBuffer()],
|
|
4112
|
+
lavarageProgram.programId
|
|
4113
|
+
);
|
|
3087
4114
|
const removeIx = yield lavarageProgram.methods.tradingRemoveTpDelegate().accountsStrict({
|
|
3088
4115
|
delegate: delegatePda,
|
|
3089
4116
|
originalOperator: lavarageProgram.provider.publicKey,
|
|
@@ -3096,10 +4123,7 @@ var removeTpDelegate = (lavarageProgram, position, prioFee) => __async(void 0, n
|
|
|
3096
4123
|
const messageV0 = new import_web3.TransactionMessage({
|
|
3097
4124
|
payerKey: lavarageProgram.provider.publicKey,
|
|
3098
4125
|
recentBlockhash: blockhash,
|
|
3099
|
-
instructions: [
|
|
3100
|
-
removeIx,
|
|
3101
|
-
computeFeeIx
|
|
3102
|
-
].filter(Boolean)
|
|
4126
|
+
instructions: [removeIx, computeFeeIx].filter(Boolean)
|
|
3103
4127
|
}).compileToV0Message();
|
|
3104
4128
|
return new import_web3.VersionedTransaction(messageV0);
|
|
3105
4129
|
});
|
|
@@ -3136,10 +4160,20 @@ var partialRepayV2 = (lavarageProgram, position, repaymentBps) => __async(void 0
|
|
|
3136
4160
|
trader: lavarageProgram.provider.publicKey,
|
|
3137
4161
|
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
3138
4162
|
randomAccountAsId: position.account.seed,
|
|
3139
|
-
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3140
|
-
|
|
4163
|
+
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4164
|
+
pool.qtType,
|
|
4165
|
+
lavarageProgram.provider.publicKey
|
|
4166
|
+
),
|
|
4167
|
+
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4168
|
+
pool.qtType,
|
|
4169
|
+
pool.nodeWallet,
|
|
4170
|
+
true
|
|
4171
|
+
),
|
|
3141
4172
|
mint: pool.qtType,
|
|
3142
|
-
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4173
|
+
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4174
|
+
pool.qtType,
|
|
4175
|
+
new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF")
|
|
4176
|
+
),
|
|
3143
4177
|
tokenProgram: import_spl_token.TOKEN_PROGRAM_ID
|
|
3144
4178
|
}).instruction();
|
|
3145
4179
|
const messageV0 = new import_web3.TransactionMessage({
|
|
@@ -3159,15 +4193,28 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
3159
4193
|
feeBuffer32.set(feeBuffer, 0);
|
|
3160
4194
|
partnerFeeMarkupAsPkey = new import_web3.PublicKey(feeBuffer32);
|
|
3161
4195
|
}
|
|
3162
|
-
if (position.account.pool.toBase58() != offer.publicKey.toBase58())
|
|
4196
|
+
if (position.account.pool.toBase58() != offer.publicKey.toBase58())
|
|
4197
|
+
throw "Mismatch offer";
|
|
3163
4198
|
const pool = offer;
|
|
3164
4199
|
const poolPubKey = offer.publicKey;
|
|
3165
4200
|
const tokenAddressPubKey = new import_web3.PublicKey(offer.account.collateralType);
|
|
3166
|
-
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
4201
|
+
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
4202
|
+
offer.account.collateralType
|
|
4203
|
+
);
|
|
3167
4204
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
3168
4205
|
const positionAccountPDA = position.publicKey;
|
|
3169
|
-
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
3170
|
-
|
|
4206
|
+
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
4207
|
+
lavarageProgram,
|
|
4208
|
+
positionAccountPDA,
|
|
4209
|
+
tokenAddressPubKey,
|
|
4210
|
+
tokenProgram
|
|
4211
|
+
);
|
|
4212
|
+
const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
4213
|
+
lavarageProgram,
|
|
4214
|
+
lavarageProgram.provider.publicKey,
|
|
4215
|
+
tokenAddressPubKey,
|
|
4216
|
+
tokenProgram
|
|
4217
|
+
);
|
|
3171
4218
|
const jupiterSellIx = jupInstruction.instructions;
|
|
3172
4219
|
const deserializeInstruction = (instruction) => {
|
|
3173
4220
|
return new import_web3.TransactionInstruction({
|
|
@@ -3181,13 +4228,17 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
3181
4228
|
});
|
|
3182
4229
|
};
|
|
3183
4230
|
const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
|
|
3184
|
-
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
4231
|
+
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
4232
|
+
keys.map((key) => new import_web3.PublicKey(key))
|
|
4233
|
+
);
|
|
3185
4234
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
3186
4235
|
const addressLookupTableAddress = keys[index];
|
|
3187
4236
|
if (accountInfo) {
|
|
3188
4237
|
const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
|
|
3189
4238
|
key: new import_web3.PublicKey(addressLookupTableAddress),
|
|
3190
|
-
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
4239
|
+
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
4240
|
+
Uint8Array.from(accountInfo.data)
|
|
4241
|
+
)
|
|
3191
4242
|
});
|
|
3192
4243
|
acc.push(addressLookupTableAccount);
|
|
3193
4244
|
}
|
|
@@ -3212,7 +4263,10 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
3212
4263
|
let repaySolIx = null;
|
|
3213
4264
|
let jupiterIxs = [];
|
|
3214
4265
|
if (jupInstruction.instructions == void 0) {
|
|
3215
|
-
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4266
|
+
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4267
|
+
new import_anchor.BN(jupInstruction.quoteResponse.outAmount),
|
|
4268
|
+
new import_anchor.BN(9997)
|
|
4269
|
+
).accountsStrict({
|
|
3216
4270
|
nodeWallet: pool.account.nodeWallet,
|
|
3217
4271
|
positionAccount: positionAccountPDA,
|
|
3218
4272
|
tradingPool: poolPubKey,
|
|
@@ -3221,17 +4275,25 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
3221
4275
|
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
3222
4276
|
randomAccountAsId: position.account.seed,
|
|
3223
4277
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
3224
|
-
}).remainingAccounts(
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3228
|
-
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
4278
|
+
}).remainingAccounts(
|
|
4279
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
4280
|
+
{
|
|
4281
|
+
pubkey: partnerFeeRecipient,
|
|
4282
|
+
isSigner: false,
|
|
4283
|
+
isWritable: true
|
|
4284
|
+
},
|
|
4285
|
+
{
|
|
4286
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
4287
|
+
isSigner: false,
|
|
4288
|
+
isWritable: false
|
|
4289
|
+
}
|
|
4290
|
+
] : []
|
|
4291
|
+
).instruction();
|
|
3233
4292
|
} else {
|
|
3234
|
-
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4293
|
+
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4294
|
+
new import_anchor.BN(jupInstruction.quoteResponse.outAmount),
|
|
4295
|
+
new import_anchor.BN(9998)
|
|
4296
|
+
).accountsStrict({
|
|
3235
4297
|
nodeWallet: pool.account.nodeWallet,
|
|
3236
4298
|
positionAccount: positionAccountPDA,
|
|
3237
4299
|
tradingPool: poolPubKey,
|
|
@@ -3240,22 +4302,37 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
3240
4302
|
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
3241
4303
|
randomAccountAsId: position.account.seed,
|
|
3242
4304
|
feeReceipient: "6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"
|
|
3243
|
-
}).remainingAccounts(
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
4305
|
+
}).remainingAccounts(
|
|
4306
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
4307
|
+
{
|
|
4308
|
+
pubkey: partnerFeeRecipient,
|
|
4309
|
+
isSigner: false,
|
|
4310
|
+
isWritable: true
|
|
4311
|
+
},
|
|
4312
|
+
{
|
|
4313
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
4314
|
+
isSigner: false,
|
|
4315
|
+
isWritable: false
|
|
4316
|
+
}
|
|
4317
|
+
] : []
|
|
4318
|
+
).instruction();
|
|
4319
|
+
const {
|
|
4320
|
+
setupInstructions,
|
|
4321
|
+
swapInstruction: swapInstructionPayload,
|
|
4322
|
+
cleanupInstruction,
|
|
4323
|
+
addressLookupTableAddresses
|
|
4324
|
+
} = jupiterSellIx;
|
|
3253
4325
|
jupiterIxs = [
|
|
3254
4326
|
...setupInstructions.map(deserializeInstruction),
|
|
3255
4327
|
deserializeInstruction(swapInstructionPayload),
|
|
3256
4328
|
deserializeInstruction(cleanupInstruction)
|
|
3257
4329
|
];
|
|
3258
|
-
addressLookupTableAccounts.push(
|
|
4330
|
+
addressLookupTableAccounts.push(
|
|
4331
|
+
...yield getAddressLookupTableAccounts([
|
|
4332
|
+
"5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi",
|
|
4333
|
+
...addressLookupTableAddresses
|
|
4334
|
+
])
|
|
4335
|
+
);
|
|
3259
4336
|
}
|
|
3260
4337
|
const profit = new import_anchor.BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
|
|
3261
4338
|
let createAssociatedTokenAccountInstruction2 = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
|
|
@@ -3267,7 +4344,9 @@ var closeTradeV1 = (lavarageProgram, position, offer, jupInstruction, partnerFee
|
|
|
3267
4344
|
);
|
|
3268
4345
|
const allInstructions = [
|
|
3269
4346
|
((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
|
|
3270
|
-
((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
|
|
4347
|
+
((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
|
|
4348
|
+
jupInstruction.instructions.tokenLedgerInstruction
|
|
4349
|
+
) : null,
|
|
3271
4350
|
toTokenAccount.instruction,
|
|
3272
4351
|
closePositionIx,
|
|
3273
4352
|
...jupiterIxs,
|
|
@@ -3291,17 +4370,30 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3291
4370
|
feeBuffer32.set(feeBuffer, 0);
|
|
3292
4371
|
partnerFeeMarkupAsPkey = new import_web3.PublicKey(feeBuffer32);
|
|
3293
4372
|
}
|
|
3294
|
-
if (position.account.pool.toBase58() != offer.publicKey.toBase58())
|
|
4373
|
+
if (position.account.pool.toBase58() != offer.publicKey.toBase58())
|
|
4374
|
+
throw "Mismatch offer";
|
|
3295
4375
|
const pool = offer;
|
|
3296
4376
|
const poolPubKey = offer.publicKey;
|
|
3297
4377
|
const tokenAddressPubKey = new import_web3.PublicKey(offer.account.collateralType);
|
|
3298
|
-
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
4378
|
+
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
4379
|
+
offer.account.collateralType
|
|
4380
|
+
);
|
|
3299
4381
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
3300
4382
|
const quoteMintAccount = yield lavarageProgram.provider.connection.getAccountInfo(quoteToken);
|
|
3301
4383
|
const quoteTokenProgram = quoteMintAccount == null ? void 0 : quoteMintAccount.owner;
|
|
3302
4384
|
const positionAccountPDA = position.publicKey;
|
|
3303
|
-
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
3304
|
-
|
|
4385
|
+
const fromTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
4386
|
+
lavarageProgram,
|
|
4387
|
+
positionAccountPDA,
|
|
4388
|
+
tokenAddressPubKey,
|
|
4389
|
+
tokenProgram
|
|
4390
|
+
);
|
|
4391
|
+
const toTokenAccount = yield getTokenAccountOrCreateIfNotExists(
|
|
4392
|
+
lavarageProgram,
|
|
4393
|
+
lavarageProgram.provider.publicKey,
|
|
4394
|
+
tokenAddressPubKey,
|
|
4395
|
+
tokenProgram
|
|
4396
|
+
);
|
|
3305
4397
|
const jupiterSellIx = jupInstruction.instructions;
|
|
3306
4398
|
const deserializeInstruction = (instruction) => {
|
|
3307
4399
|
return new import_web3.TransactionInstruction({
|
|
@@ -3315,13 +4407,17 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3315
4407
|
});
|
|
3316
4408
|
};
|
|
3317
4409
|
const getAddressLookupTableAccounts = (keys) => __async(void 0, null, function* () {
|
|
3318
|
-
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
4410
|
+
const addressLookupTableAccountInfos = yield lavarageProgram.provider.connection.getMultipleAccountsInfo(
|
|
4411
|
+
keys.map((key) => new import_web3.PublicKey(key))
|
|
4412
|
+
);
|
|
3319
4413
|
return addressLookupTableAccountInfos.reduce((acc, accountInfo, index) => {
|
|
3320
4414
|
const addressLookupTableAddress = keys[index];
|
|
3321
4415
|
if (accountInfo) {
|
|
3322
4416
|
const addressLookupTableAccount = new import_web3.AddressLookupTableAccount({
|
|
3323
4417
|
key: new import_web3.PublicKey(addressLookupTableAddress),
|
|
3324
|
-
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
4418
|
+
state: import_web3.AddressLookupTableAccount.deserialize(
|
|
4419
|
+
Uint8Array.from(accountInfo.data)
|
|
4420
|
+
)
|
|
3325
4421
|
});
|
|
3326
4422
|
acc.push(addressLookupTableAccount);
|
|
3327
4423
|
}
|
|
@@ -3346,7 +4442,10 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3346
4442
|
let repaySolIx = null;
|
|
3347
4443
|
let jupiterIxs = [];
|
|
3348
4444
|
if (jupInstruction.instructions == void 0) {
|
|
3349
|
-
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4445
|
+
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4446
|
+
new import_anchor.BN(jupInstruction.quoteResponse.outAmount),
|
|
4447
|
+
new import_anchor.BN(9997)
|
|
4448
|
+
).accountsStrict({
|
|
3350
4449
|
nodeWallet: pool.account.nodeWallet,
|
|
3351
4450
|
positionAccount: positionAccountPDA,
|
|
3352
4451
|
tradingPool: poolPubKey,
|
|
@@ -3354,22 +4453,50 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3354
4453
|
systemProgram: import_web3.SystemProgram.programId,
|
|
3355
4454
|
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
3356
4455
|
randomAccountAsId: position.account.seed,
|
|
3357
|
-
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3358
|
-
|
|
4456
|
+
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4457
|
+
quoteToken,
|
|
4458
|
+
new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
4459
|
+
false,
|
|
4460
|
+
quoteTokenProgram
|
|
4461
|
+
),
|
|
4462
|
+
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4463
|
+
quoteToken,
|
|
4464
|
+
lavarageProgram.provider.publicKey,
|
|
4465
|
+
false,
|
|
4466
|
+
quoteTokenProgram
|
|
4467
|
+
),
|
|
3359
4468
|
tokenProgram: quoteTokenProgram,
|
|
3360
|
-
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4469
|
+
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4470
|
+
quoteToken,
|
|
4471
|
+
pool.account.nodeWallet,
|
|
4472
|
+
true,
|
|
4473
|
+
quoteTokenProgram
|
|
4474
|
+
),
|
|
3361
4475
|
mint: quoteToken
|
|
3362
|
-
}).remainingAccounts(
|
|
3363
|
-
|
|
3364
|
-
|
|
3365
|
-
|
|
3366
|
-
|
|
3367
|
-
|
|
3368
|
-
|
|
3369
|
-
|
|
3370
|
-
|
|
4476
|
+
}).remainingAccounts(
|
|
4477
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
4478
|
+
{
|
|
4479
|
+
pubkey: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4480
|
+
quoteToken,
|
|
4481
|
+
partnerFeeRecipient,
|
|
4482
|
+
false,
|
|
4483
|
+
quoteTokenProgram
|
|
4484
|
+
),
|
|
4485
|
+
isSigner: false,
|
|
4486
|
+
isWritable: true
|
|
4487
|
+
},
|
|
4488
|
+
{
|
|
4489
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
4490
|
+
isSigner: false,
|
|
4491
|
+
isWritable: false
|
|
4492
|
+
}
|
|
4493
|
+
] : []
|
|
4494
|
+
).instruction();
|
|
3371
4495
|
} else {
|
|
3372
|
-
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4496
|
+
repaySolIx = yield lavarageProgram.methods.tradingCloseRepaySol(
|
|
4497
|
+
new import_anchor.BN(jupInstruction.quoteResponse.outAmount),
|
|
4498
|
+
new import_anchor.BN(9998)
|
|
4499
|
+
).accountsStrict({
|
|
3373
4500
|
nodeWallet: pool.account.nodeWallet,
|
|
3374
4501
|
positionAccount: positionAccountPDA,
|
|
3375
4502
|
tradingPool: poolPubKey,
|
|
@@ -3377,27 +4504,58 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3377
4504
|
systemProgram: import_web3.SystemProgram.programId,
|
|
3378
4505
|
clock: import_web3.SYSVAR_CLOCK_PUBKEY,
|
|
3379
4506
|
randomAccountAsId: position.account.seed,
|
|
3380
|
-
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3381
|
-
|
|
4507
|
+
feeTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4508
|
+
quoteToken,
|
|
4509
|
+
new import_web3.PublicKey("6JfTobDvwuwZxZP6FR5JPmjdvQ4h4MovkEVH2FPsMSrF"),
|
|
4510
|
+
false,
|
|
4511
|
+
quoteTokenProgram
|
|
4512
|
+
),
|
|
4513
|
+
fromTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4514
|
+
quoteToken,
|
|
4515
|
+
lavarageProgram.provider.publicKey,
|
|
4516
|
+
false,
|
|
4517
|
+
quoteTokenProgram
|
|
4518
|
+
),
|
|
3382
4519
|
tokenProgram: quoteTokenProgram,
|
|
3383
|
-
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4520
|
+
toTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4521
|
+
quoteToken,
|
|
4522
|
+
pool.account.nodeWallet,
|
|
4523
|
+
true,
|
|
4524
|
+
quoteTokenProgram
|
|
4525
|
+
),
|
|
3384
4526
|
mint: quoteToken
|
|
3385
|
-
}).remainingAccounts(
|
|
3386
|
-
|
|
3387
|
-
|
|
3388
|
-
|
|
3389
|
-
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
4527
|
+
}).remainingAccounts(
|
|
4528
|
+
partnerFeeRecipient && partnerFeeMarkupAsPkey ? [
|
|
4529
|
+
{
|
|
4530
|
+
pubkey: partnerFeeRecipient,
|
|
4531
|
+
isSigner: false,
|
|
4532
|
+
isWritable: true
|
|
4533
|
+
},
|
|
4534
|
+
{
|
|
4535
|
+
pubkey: partnerFeeMarkupAsPkey,
|
|
4536
|
+
isSigner: false,
|
|
4537
|
+
isWritable: false
|
|
4538
|
+
}
|
|
4539
|
+
] : []
|
|
4540
|
+
).instruction();
|
|
4541
|
+
const {
|
|
4542
|
+
setupInstructions,
|
|
4543
|
+
swapInstruction: swapInstructionPayload,
|
|
4544
|
+
cleanupInstruction,
|
|
4545
|
+
addressLookupTableAddresses
|
|
4546
|
+
} = jupiterSellIx;
|
|
3395
4547
|
jupiterIxs = [
|
|
3396
4548
|
...setupInstructions.filter((i) => !!i).map(deserializeInstruction),
|
|
3397
4549
|
swapInstructionPayload ? deserializeInstruction(swapInstructionPayload) : null,
|
|
3398
4550
|
cleanupInstruction ? deserializeInstruction(cleanupInstruction) : null
|
|
3399
4551
|
].filter((i) => !!i);
|
|
3400
|
-
addressLookupTableAccounts.push(
|
|
4552
|
+
addressLookupTableAccounts.push(
|
|
4553
|
+
...yield getAddressLookupTableAccounts([
|
|
4554
|
+
...addressLookupTableAddresses,
|
|
4555
|
+
getQuoteCurrencySpecificAddressLookupTable(quoteToken.toBase58()),
|
|
4556
|
+
"5LEAB3owNUSKvECm7vkr58tDtQpzbngQ2NYpc7qmRFdi"
|
|
4557
|
+
])
|
|
4558
|
+
);
|
|
3401
4559
|
}
|
|
3402
4560
|
const profit = new import_anchor.BN(jupInstruction.quoteResponse.outAmount).sub(position.account.amount).sub(position.account.userPaid);
|
|
3403
4561
|
let createAssociatedTokenAccountInstruction2 = (0, import_spl_token.createAssociatedTokenAccountIdempotentInstruction)(
|
|
@@ -3409,7 +4567,9 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3409
4567
|
);
|
|
3410
4568
|
const allInstructions = [
|
|
3411
4569
|
((_a = jupInstruction.instructions) == null ? void 0 : _a.tokenLedgerInstruction) ? createAssociatedTokenAccountInstruction2 : null,
|
|
3412
|
-
((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
|
|
4570
|
+
((_b = jupInstruction.instructions) == null ? void 0 : _b.tokenLedgerInstruction) ? deserializeInstruction(
|
|
4571
|
+
jupInstruction.instructions.tokenLedgerInstruction
|
|
4572
|
+
) : null,
|
|
3413
4573
|
toTokenAccount.instruction,
|
|
3414
4574
|
closePositionIx,
|
|
3415
4575
|
...jupiterIxs,
|
|
@@ -3424,12 +4584,16 @@ var closeTradeV2 = (lavarageProgram, position, offer, jupInstruction, quoteToken
|
|
|
3424
4584
|
return tx;
|
|
3425
4585
|
});
|
|
3426
4586
|
var getDelegateAccounts = (lavarageProgram, userPubKey) => __async(void 0, null, function* () {
|
|
3427
|
-
const delegateAccounts = yield lavarageProgram.account.delegate.all(
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
4587
|
+
const delegateAccounts = yield lavarageProgram.account.delegate.all(
|
|
4588
|
+
userPubKey ? [
|
|
4589
|
+
{
|
|
4590
|
+
memcmp: {
|
|
4591
|
+
offset: 104,
|
|
4592
|
+
bytes: userPubKey.toBase58()
|
|
4593
|
+
}
|
|
4594
|
+
}
|
|
4595
|
+
] : void 0
|
|
4596
|
+
);
|
|
3433
4597
|
return delegateAccounts.map((d) => __spreadProps(__spreadValues({}, d), {
|
|
3434
4598
|
parsed: {
|
|
3435
4599
|
tpPrice: new import_anchor.BN(d.account.field1),
|
|
@@ -3451,12 +4615,32 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
|
|
|
3451
4615
|
const positionAccountPDA = position.publicKey;
|
|
3452
4616
|
const newPosition1Seed = import_web3.Keypair.generate().publicKey;
|
|
3453
4617
|
const newPosition2Seed = import_web3.Keypair.generate().publicKey;
|
|
3454
|
-
const newPosition1AccountPDA = getPositionAccountPDA(
|
|
3455
|
-
|
|
3456
|
-
|
|
4618
|
+
const newPosition1AccountPDA = getPositionAccountPDA(
|
|
4619
|
+
lavarageProgram,
|
|
4620
|
+
offer,
|
|
4621
|
+
newPosition1Seed
|
|
4622
|
+
);
|
|
4623
|
+
const newPosition2AccountPDA = getPositionAccountPDA(
|
|
4624
|
+
lavarageProgram,
|
|
4625
|
+
offer,
|
|
4626
|
+
newPosition2Seed
|
|
4627
|
+
);
|
|
4628
|
+
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
4629
|
+
offer.account.collateralType
|
|
4630
|
+
);
|
|
3457
4631
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
3458
|
-
const newPosition1TokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3459
|
-
|
|
4632
|
+
const newPosition1TokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4633
|
+
offer.account.collateralType,
|
|
4634
|
+
newPosition1AccountPDA,
|
|
4635
|
+
true,
|
|
4636
|
+
tokenProgram
|
|
4637
|
+
);
|
|
4638
|
+
const newPosition2TokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4639
|
+
offer.account.collateralType,
|
|
4640
|
+
newPosition2AccountPDA,
|
|
4641
|
+
true,
|
|
4642
|
+
tokenProgram
|
|
4643
|
+
);
|
|
3460
4644
|
const createNewPosition1TokenAccountIx = (0, import_spl_token.createAssociatedTokenAccountInstruction)(
|
|
3461
4645
|
lavarageProgram.provider.publicKey,
|
|
3462
4646
|
newPosition1TokenAccount,
|
|
@@ -3471,7 +4655,11 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
|
|
|
3471
4655
|
offer.account.collateralType,
|
|
3472
4656
|
tokenProgram
|
|
3473
4657
|
);
|
|
3474
|
-
const ix = yield lavarageProgram.methods.tradingManagementSplitPosition(
|
|
4658
|
+
const ix = yield lavarageProgram.methods.tradingManagementSplitPosition(
|
|
4659
|
+
new import_anchor.BN(propotionBps),
|
|
4660
|
+
newPosition1Seed,
|
|
4661
|
+
newPosition2Seed
|
|
4662
|
+
).accountsStrict({
|
|
3475
4663
|
originalPosition: positionAccountPDA,
|
|
3476
4664
|
newPositionOne: newPosition1AccountPDA,
|
|
3477
4665
|
newPositionTwo: newPosition2AccountPDA,
|
|
@@ -3479,7 +4667,12 @@ var splitPositionV2 = (lavarageProgram, position, offer, quoteToken, propotionBp
|
|
|
3479
4667
|
systemProgram: import_web3.SystemProgram.programId,
|
|
3480
4668
|
mint: offer.account.collateralType,
|
|
3481
4669
|
tokenProgram,
|
|
3482
|
-
originalPositionTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4670
|
+
originalPositionTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4671
|
+
offer.account.collateralType,
|
|
4672
|
+
positionAccountPDA,
|
|
4673
|
+
true,
|
|
4674
|
+
tokenProgram
|
|
4675
|
+
),
|
|
3483
4676
|
newPositionTokenAccountOne: newPosition1TokenAccount,
|
|
3484
4677
|
newPositionTokenAccountTwo: newPosition2TokenAccount
|
|
3485
4678
|
}).instruction();
|
|
@@ -3505,10 +4698,21 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
3505
4698
|
const positionAccountPDA1 = position1.publicKey;
|
|
3506
4699
|
const positionAccountPDA2 = position2.publicKey;
|
|
3507
4700
|
const newPositionSeed = import_web3.Keypair.generate().publicKey;
|
|
3508
|
-
const newPositionAccountPDA = getPositionAccountPDA(
|
|
3509
|
-
|
|
4701
|
+
const newPositionAccountPDA = getPositionAccountPDA(
|
|
4702
|
+
lavarageProgram,
|
|
4703
|
+
offer,
|
|
4704
|
+
newPositionSeed
|
|
4705
|
+
);
|
|
4706
|
+
const mintAccount = yield lavarageProgram.provider.connection.getAccountInfo(
|
|
4707
|
+
offer.account.collateralType
|
|
4708
|
+
);
|
|
3510
4709
|
const tokenProgram = mintAccount == null ? void 0 : mintAccount.owner;
|
|
3511
|
-
const newPositionTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4710
|
+
const newPositionTokenAccount = (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4711
|
+
offer.account.collateralType,
|
|
4712
|
+
newPositionAccountPDA,
|
|
4713
|
+
true,
|
|
4714
|
+
tokenProgram
|
|
4715
|
+
);
|
|
3512
4716
|
const createNewPositionTokenAccountIx = (0, import_spl_token.createAssociatedTokenAccountInstruction)(
|
|
3513
4717
|
lavarageProgram.provider.publicKey,
|
|
3514
4718
|
newPositionTokenAccount,
|
|
@@ -3524,8 +4728,18 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
3524
4728
|
systemProgram: import_web3.SystemProgram.programId,
|
|
3525
4729
|
mint: offer.account.collateralType,
|
|
3526
4730
|
tokenProgram,
|
|
3527
|
-
positionOneTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
3528
|
-
|
|
4731
|
+
positionOneTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4732
|
+
offer.account.collateralType,
|
|
4733
|
+
positionAccountPDA1,
|
|
4734
|
+
true,
|
|
4735
|
+
tokenProgram
|
|
4736
|
+
),
|
|
4737
|
+
positionTwoTokenAccount: (0, import_spl_token.getAssociatedTokenAddressSync)(
|
|
4738
|
+
offer.account.collateralType,
|
|
4739
|
+
positionAccountPDA2,
|
|
4740
|
+
true,
|
|
4741
|
+
tokenProgram
|
|
4742
|
+
),
|
|
3529
4743
|
mergedPositionTokenAccount: newPositionTokenAccount
|
|
3530
4744
|
}).instruction();
|
|
3531
4745
|
const computeBudgetIx = import_web3.ComputeBudgetProgram.setComputeUnitPrice({
|
|
@@ -3549,19 +4763,28 @@ var mergePositionV2 = (lavarageProgram, position1, position2, offer, quoteToken)
|
|
|
3549
4763
|
0 && (module.exports = {
|
|
3550
4764
|
IDL,
|
|
3551
4765
|
IDLV2,
|
|
4766
|
+
closePositionEvm,
|
|
3552
4767
|
closeTradeV1,
|
|
3553
4768
|
closeTradeV2,
|
|
3554
4769
|
createTpDelegate,
|
|
3555
4770
|
getAllPositions,
|
|
3556
4771
|
getClosedPositions,
|
|
4772
|
+
getClosedPositionsEvm,
|
|
4773
|
+
getCollateralInfoEvm,
|
|
3557
4774
|
getDelegateAccounts,
|
|
3558
4775
|
getLiquidatedPositions,
|
|
4776
|
+
getLiquidatedPositionsEvm,
|
|
4777
|
+
getLoanEvm,
|
|
3559
4778
|
getOffers,
|
|
4779
|
+
getOffersEvm,
|
|
3560
4780
|
getOpenPositions,
|
|
3561
4781
|
getPda,
|
|
3562
4782
|
getPositionAccountPDA,
|
|
4783
|
+
getPositionsEvm,
|
|
4784
|
+
getUserLoansEvm,
|
|
3563
4785
|
mergePositionV2,
|
|
3564
4786
|
modifyTpDelegate,
|
|
4787
|
+
openPositionEvm,
|
|
3565
4788
|
openTradeV1,
|
|
3566
4789
|
openTradeV2,
|
|
3567
4790
|
partialRepayV1,
|