@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/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
- * Opens a trading position on EVM chain
21
- * @param signer - Ethers signer
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 Transaction object
23
+ * @returns Unsigned transaction object
25
24
  */
26
25
  export const openPositionEvm = async (
27
- signer: Signer,
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
- signer
53
+ provider
51
54
  );
52
55
 
53
- return contract.buy(
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
- { value: buyerContribution }
74
+ txOptions
61
75
  );
62
76
  };
63
77
 
64
78
  /**
65
- * Closes a trading position on EVM chain
66
- * @param signer - Ethers signer
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 Transaction object
83
+ * @returns Unsigned transaction object
70
84
  */
71
85
  export const closePositionEvm = async (
72
- signer: Signer,
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
- signer
109
+ provider
92
110
  );
93
111
 
94
- return contract.sell(
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 = 0
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
- trader,
150
+ buyer,
127
151
  tokenCollateral,
128
152
  loanId,
129
153
  openingPositionSize,
130
154
  collateralAmount,
131
155
  initialMargin,
132
- } = event.args as unknown as BuyEvent;
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 = 0
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 { trader, tokenCollateral, loanId, closingPositionSize, profit } =
167
- event.args as unknown as SellEvent;
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 = 0
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
- trader,
232
+ borrower,
202
233
  tokenCollateral,
203
234
  loanId,
204
235
  closingPositionSize,
205
236
  liquidatorRepaidAmount,
206
- } = event.args as unknown as LiquidationEvent;
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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lavarage/sdk",
3
- "version": "6.5.0",
3
+ "version": "6.6.0",
4
4
  "description": "Lavarage SDK",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",