@lavarage/sdk 6.5.0 → 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.d.mts +13 -9
- package/dist/index.d.ts +13 -9
- package/dist/index.js +38 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -19
- package/dist/index.mjs.map +1 -1
- package/evm.ts +60 -28
- package/package.json +1 -1
package/evm.ts
CHANGED
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
Contract,
|
|
4
4
|
ContractTransaction,
|
|
5
5
|
Provider,
|
|
6
|
-
Signer,
|
|
7
6
|
ZeroAddress,
|
|
8
7
|
} from "ethers";
|
|
9
8
|
import { borrowerOperationsAbi } from "./abi/borrowerOperations";
|
|
@@ -17,14 +16,14 @@ import {
|
|
|
17
16
|
} from "./interfaces/evm";
|
|
18
17
|
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
21
|
-
* @param
|
|
19
|
+
* Creates an unsigned transaction to open a trading position on EVM chain
|
|
20
|
+
* @param provider - Ethers provider
|
|
22
21
|
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
23
22
|
* @param params - Trading parameters
|
|
24
|
-
* @returns
|
|
23
|
+
* @returns Unsigned transaction object
|
|
25
24
|
*/
|
|
26
25
|
export const openPositionEvm = async (
|
|
27
|
-
|
|
26
|
+
provider: Provider,
|
|
28
27
|
borrowerOpsContractAddress: string,
|
|
29
28
|
{
|
|
30
29
|
buyingCode,
|
|
@@ -34,6 +33,8 @@ export const openPositionEvm = async (
|
|
|
34
33
|
inchRouter,
|
|
35
34
|
integratorFeeAddress = ZeroAddress,
|
|
36
35
|
buyerContribution,
|
|
36
|
+
gasLimit,
|
|
37
|
+
gasPrice,
|
|
37
38
|
}: {
|
|
38
39
|
buyingCode: string;
|
|
39
40
|
tokenCollateral: string;
|
|
@@ -42,34 +43,47 @@ export const openPositionEvm = async (
|
|
|
42
43
|
inchRouter: string;
|
|
43
44
|
integratorFeeAddress?: string;
|
|
44
45
|
buyerContribution: BigNumberish;
|
|
46
|
+
gasLimit?: string | number;
|
|
47
|
+
gasPrice?: string | number;
|
|
45
48
|
}
|
|
46
49
|
): Promise<ContractTransaction> => {
|
|
47
50
|
const contract = new Contract(
|
|
48
51
|
borrowerOpsContractAddress,
|
|
49
52
|
borrowerOperationsAbi,
|
|
50
|
-
|
|
53
|
+
provider
|
|
51
54
|
);
|
|
52
55
|
|
|
53
|
-
|
|
56
|
+
const txOptions: {
|
|
57
|
+
value: BigNumberish;
|
|
58
|
+
gasLimit?: BigNumberish;
|
|
59
|
+
gasPrice?: BigNumberish;
|
|
60
|
+
} = {
|
|
61
|
+
value: buyerContribution,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
if (gasLimit) txOptions.gasLimit = gasLimit;
|
|
65
|
+
if (gasPrice) txOptions.gasPrice = gasPrice;
|
|
66
|
+
|
|
67
|
+
return contract.buy.populateTransaction(
|
|
54
68
|
buyingCode,
|
|
55
69
|
tokenCollateral,
|
|
56
70
|
borrowAmount,
|
|
57
71
|
tokenHolder,
|
|
58
72
|
inchRouter,
|
|
59
73
|
integratorFeeAddress,
|
|
60
|
-
|
|
74
|
+
txOptions
|
|
61
75
|
);
|
|
62
76
|
};
|
|
63
77
|
|
|
64
78
|
/**
|
|
65
|
-
*
|
|
66
|
-
* @param
|
|
79
|
+
* Creates an unsigned transaction to close a trading position on EVM chain
|
|
80
|
+
* @param provider - Ethers provider
|
|
67
81
|
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
68
82
|
* @param params - Trading parameters
|
|
69
|
-
* @returns
|
|
83
|
+
* @returns Unsigned transaction object
|
|
70
84
|
*/
|
|
71
85
|
export const closePositionEvm = async (
|
|
72
|
-
|
|
86
|
+
provider: Provider,
|
|
73
87
|
borrowerOpsContractAddress: string,
|
|
74
88
|
{
|
|
75
89
|
loanId,
|
|
@@ -77,26 +91,36 @@ export const closePositionEvm = async (
|
|
|
77
91
|
tokenHolder,
|
|
78
92
|
inchRouter,
|
|
79
93
|
integratorFeeAddress = ZeroAddress,
|
|
94
|
+
gasLimit,
|
|
95
|
+
gasPrice,
|
|
80
96
|
}: {
|
|
81
97
|
loanId: BigNumberish;
|
|
82
98
|
sellingCode: string;
|
|
83
99
|
tokenHolder: string;
|
|
84
100
|
inchRouter: string;
|
|
85
101
|
integratorFeeAddress?: string;
|
|
102
|
+
gasLimit?: string | number;
|
|
103
|
+
gasPrice?: string | number;
|
|
86
104
|
}
|
|
87
105
|
): Promise<ContractTransaction> => {
|
|
88
106
|
const contract = new Contract(
|
|
89
107
|
borrowerOpsContractAddress,
|
|
90
108
|
borrowerOperationsAbi,
|
|
91
|
-
|
|
109
|
+
provider
|
|
92
110
|
);
|
|
93
111
|
|
|
94
|
-
|
|
112
|
+
const txOptions: { gasLimit?: BigNumberish; gasPrice?: BigNumberish } = {};
|
|
113
|
+
|
|
114
|
+
if (gasLimit) txOptions.gasLimit = gasLimit;
|
|
115
|
+
if (gasPrice) txOptions.gasPrice = gasPrice;
|
|
116
|
+
|
|
117
|
+
return contract.sell.populateTransaction(
|
|
95
118
|
loanId,
|
|
96
119
|
sellingCode,
|
|
97
120
|
tokenHolder,
|
|
98
121
|
inchRouter,
|
|
99
|
-
integratorFeeAddress
|
|
122
|
+
integratorFeeAddress,
|
|
123
|
+
Object.keys(txOptions).length > 0 ? txOptions : {}
|
|
100
124
|
);
|
|
101
125
|
};
|
|
102
126
|
|
|
@@ -110,7 +134,7 @@ export const closePositionEvm = async (
|
|
|
110
134
|
export async function getPositionsEvm(
|
|
111
135
|
provider: Provider,
|
|
112
136
|
borrowerOpsContractAddress: string,
|
|
113
|
-
fromBlock: number =
|
|
137
|
+
fromBlock: number = 42960845 // block contract was initialized
|
|
114
138
|
): Promise<BuyEvent[]> {
|
|
115
139
|
const contract = new Contract(
|
|
116
140
|
borrowerOpsContractAddress,
|
|
@@ -123,15 +147,16 @@ export async function getPositionsEvm(
|
|
|
123
147
|
|
|
124
148
|
return events.map((event: any) => {
|
|
125
149
|
const {
|
|
126
|
-
|
|
150
|
+
buyer,
|
|
127
151
|
tokenCollateral,
|
|
128
152
|
loanId,
|
|
129
153
|
openingPositionSize,
|
|
130
154
|
collateralAmount,
|
|
131
155
|
initialMargin,
|
|
132
|
-
} = event.args as unknown as
|
|
156
|
+
} = event.args as unknown as any;
|
|
157
|
+
|
|
133
158
|
return {
|
|
134
|
-
trader,
|
|
159
|
+
trader: buyer,
|
|
135
160
|
tokenCollateral,
|
|
136
161
|
loanId,
|
|
137
162
|
openingPositionSize,
|
|
@@ -151,7 +176,7 @@ export async function getPositionsEvm(
|
|
|
151
176
|
export async function getClosedPositionsEvm(
|
|
152
177
|
provider: Provider,
|
|
153
178
|
borrowerOpsContractAddress: string,
|
|
154
|
-
fromBlock: number =
|
|
179
|
+
fromBlock: number = 42960845 // block contract was initialized
|
|
155
180
|
): Promise<SellEvent[]> {
|
|
156
181
|
const contract = new Contract(
|
|
157
182
|
borrowerOpsContractAddress,
|
|
@@ -163,10 +188,16 @@ export async function getClosedPositionsEvm(
|
|
|
163
188
|
const events = await contract.queryFilter(filter, fromBlock);
|
|
164
189
|
|
|
165
190
|
return events.map((event: any) => {
|
|
166
|
-
const {
|
|
167
|
-
|
|
191
|
+
const {
|
|
192
|
+
buyer,
|
|
193
|
+
tokenCollateral,
|
|
194
|
+
loanId,
|
|
195
|
+
closingPositionSize,
|
|
196
|
+
profit
|
|
197
|
+
} = event.args as unknown as any;
|
|
198
|
+
|
|
168
199
|
return {
|
|
169
|
-
trader,
|
|
200
|
+
trader: buyer,
|
|
170
201
|
tokenCollateral,
|
|
171
202
|
loanId,
|
|
172
203
|
closingPositionSize,
|
|
@@ -185,7 +216,7 @@ export async function getClosedPositionsEvm(
|
|
|
185
216
|
export async function getLiquidatedPositionsEvm(
|
|
186
217
|
provider: Provider,
|
|
187
218
|
borrowerOpsContractAddress: string,
|
|
188
|
-
fromBlock: number =
|
|
219
|
+
fromBlock: number = 42960845 // block contract was initialized
|
|
189
220
|
): Promise<LiquidationEvent[]> {
|
|
190
221
|
const contract = new Contract(
|
|
191
222
|
borrowerOpsContractAddress,
|
|
@@ -198,14 +229,15 @@ export async function getLiquidatedPositionsEvm(
|
|
|
198
229
|
|
|
199
230
|
return events.map((event: any) => {
|
|
200
231
|
const {
|
|
201
|
-
|
|
232
|
+
borrower,
|
|
202
233
|
tokenCollateral,
|
|
203
234
|
loanId,
|
|
204
235
|
closingPositionSize,
|
|
205
236
|
liquidatorRepaidAmount,
|
|
206
|
-
} = event.args as unknown as
|
|
237
|
+
} = event.args as unknown as any;
|
|
238
|
+
|
|
207
239
|
return {
|
|
208
|
-
trader,
|
|
240
|
+
trader: borrower,
|
|
209
241
|
tokenCollateral,
|
|
210
242
|
loanId,
|
|
211
243
|
closingPositionSize,
|
|
@@ -315,4 +347,4 @@ export async function getOffersEvm(
|
|
|
315
347
|
}
|
|
316
348
|
|
|
317
349
|
return activeCollaterals;
|
|
318
|
-
}
|
|
350
|
+
}
|