@lavarage/sdk 6.7.0 → 6.7.2
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 +1 -1
- package/abi/tokenHolderAbi.ts +216 -0
- package/dist/index.d.mts +70 -1
- package/dist/index.d.ts +70 -1
- package/dist/index.js +377 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +369 -50
- package/dist/index.mjs.map +1 -1
- package/evm.ts +223 -51
- package/interfaces/evm.ts +10 -0
- package/package.json +1 -1
package/evm.ts
CHANGED
|
@@ -145,26 +145,32 @@ export async function getPositionsEvm(
|
|
|
145
145
|
const filter = contract.filters.Buy();
|
|
146
146
|
const events = await contract.queryFilter(filter, fromBlock);
|
|
147
147
|
|
|
148
|
-
return
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
148
|
+
return Promise.all(
|
|
149
|
+
events.map(async (event: any) => {
|
|
150
|
+
const {
|
|
151
|
+
buyer,
|
|
152
|
+
tokenCollateral,
|
|
153
|
+
loanId,
|
|
154
|
+
openingPositionSize,
|
|
155
|
+
collateralAmount,
|
|
156
|
+
initialMargin,
|
|
157
|
+
} = event.args as unknown as any;
|
|
158
|
+
|
|
159
|
+
const block = await provider.getBlock(event.blockNumber);
|
|
160
|
+
const timestamp = Number(block?.timestamp) || 0;
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
trader: buyer,
|
|
164
|
+
tokenCollateral,
|
|
165
|
+
loanId,
|
|
166
|
+
openingPositionSize,
|
|
167
|
+
collateralAmount,
|
|
168
|
+
initialMargin,
|
|
169
|
+
transactionHash: event.transactionHash,
|
|
170
|
+
timestamp,
|
|
171
|
+
};
|
|
172
|
+
})
|
|
173
|
+
);
|
|
168
174
|
}
|
|
169
175
|
|
|
170
176
|
/**
|
|
@@ -188,19 +194,25 @@ export async function getClosedPositionsEvm(
|
|
|
188
194
|
const filter = contract.filters.Sell();
|
|
189
195
|
const events = await contract.queryFilter(filter, fromBlock);
|
|
190
196
|
|
|
191
|
-
return
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
return Promise.all(
|
|
198
|
+
events.map(async (event: any) => {
|
|
199
|
+
const { buyer, tokenCollateral, loanId, closingPositionSize, profit } =
|
|
200
|
+
event.args as unknown as any;
|
|
201
|
+
|
|
202
|
+
const block = await provider.getBlock(event.blockNumber);
|
|
203
|
+
const timestamp = block ? Number(block.timestamp) : 0;
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
trader: buyer,
|
|
207
|
+
tokenCollateral,
|
|
208
|
+
loanId,
|
|
209
|
+
closingPositionSize,
|
|
210
|
+
profit,
|
|
211
|
+
transactionHash: event.transactionHash,
|
|
212
|
+
timestamp,
|
|
213
|
+
};
|
|
214
|
+
})
|
|
215
|
+
);
|
|
204
216
|
}
|
|
205
217
|
|
|
206
218
|
/**
|
|
@@ -224,24 +236,30 @@ export async function getLiquidatedPositionsEvm(
|
|
|
224
236
|
const filter = contract.filters.Liquidation();
|
|
225
237
|
const events = await contract.queryFilter(filter, fromBlock);
|
|
226
238
|
|
|
227
|
-
return
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
239
|
+
return Promise.all(
|
|
240
|
+
events.map(async (event: any) => {
|
|
241
|
+
const {
|
|
242
|
+
borrower,
|
|
243
|
+
tokenCollateral,
|
|
244
|
+
loanId,
|
|
245
|
+
closingPositionSize,
|
|
246
|
+
liquidatorRepaidAmount,
|
|
247
|
+
} = event.args as unknown as any;
|
|
248
|
+
|
|
249
|
+
const block = await provider.getBlock(event.blockNumber);
|
|
250
|
+
const timestamp = block ? Number(block.timestamp) : 0;
|
|
251
|
+
|
|
252
|
+
return {
|
|
253
|
+
trader: borrower,
|
|
254
|
+
tokenCollateral,
|
|
255
|
+
loanId,
|
|
256
|
+
closingPositionSize,
|
|
257
|
+
liquidatorRepaidAmount,
|
|
258
|
+
transactionHash: event.transactionHash,
|
|
259
|
+
timestamp,
|
|
260
|
+
};
|
|
261
|
+
})
|
|
262
|
+
);
|
|
245
263
|
}
|
|
246
264
|
|
|
247
265
|
/**
|
|
@@ -346,3 +364,157 @@ export async function getOffersEvm(
|
|
|
346
364
|
|
|
347
365
|
return activeCollaterals;
|
|
348
366
|
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Get the opening fee percentage
|
|
370
|
+
* @param provider - Ethers provider
|
|
371
|
+
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
372
|
+
* @returns Opening fee as a BigNumber
|
|
373
|
+
*/
|
|
374
|
+
export async function getOpeningFeeEvm(
|
|
375
|
+
provider: Provider,
|
|
376
|
+
borrowerOpsContractAddress: string
|
|
377
|
+
): Promise<bigint> {
|
|
378
|
+
const contract = new Contract(
|
|
379
|
+
borrowerOpsContractAddress,
|
|
380
|
+
borrowerOperationsAbi,
|
|
381
|
+
provider
|
|
382
|
+
);
|
|
383
|
+
return contract.openingFee();
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
/**
|
|
387
|
+
* Get the profit fee percentage
|
|
388
|
+
* @param provider - Ethers provider
|
|
389
|
+
* @param borrowerOpsContractAddress - BorrowerOperations contract address
|
|
390
|
+
* @returns Profit fee as a BigNumber
|
|
391
|
+
*/
|
|
392
|
+
export async function getProfitFeeEvm(
|
|
393
|
+
provider: Provider,
|
|
394
|
+
borrowerOpsContractAddress: string
|
|
395
|
+
): Promise<bigint> {
|
|
396
|
+
const contract = new Contract(
|
|
397
|
+
borrowerOpsContractAddress,
|
|
398
|
+
borrowerOperationsAbi,
|
|
399
|
+
provider
|
|
400
|
+
);
|
|
401
|
+
return contract.profitFee();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
/**
|
|
405
|
+
* Get the token balance of the token holder contract
|
|
406
|
+
* @param provider - Ethers provider
|
|
407
|
+
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
408
|
+
* @returns Token balance as a BigNumber
|
|
409
|
+
*/
|
|
410
|
+
export async function getTokenBalanceEvm(
|
|
411
|
+
provider: Provider,
|
|
412
|
+
tokenHolderContractAddress: string
|
|
413
|
+
): Promise<bigint> {
|
|
414
|
+
const contract = new Contract(
|
|
415
|
+
tokenHolderContractAddress,
|
|
416
|
+
tokenHolderAbi,
|
|
417
|
+
provider
|
|
418
|
+
);
|
|
419
|
+
return contract.getBalance();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Get the active loan count
|
|
424
|
+
* @param provider - Ethers provider
|
|
425
|
+
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
426
|
+
* @returns Number of active loans
|
|
427
|
+
*/
|
|
428
|
+
export async function getActiveLoanCountEvm(
|
|
429
|
+
provider: Provider,
|
|
430
|
+
tokenHolderContractAddress: string
|
|
431
|
+
): Promise<bigint> {
|
|
432
|
+
const contract = new Contract(
|
|
433
|
+
tokenHolderContractAddress,
|
|
434
|
+
tokenHolderAbi,
|
|
435
|
+
provider
|
|
436
|
+
);
|
|
437
|
+
return contract.getActiveLoanCount();
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* Get a batch of active loans
|
|
442
|
+
* @param provider - Ethers provider
|
|
443
|
+
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
444
|
+
* @param startIndex - Starting index in the activeLoanIds array
|
|
445
|
+
* @param batchSize - Number of loans to retrieve
|
|
446
|
+
* @returns Array of active loans
|
|
447
|
+
*/
|
|
448
|
+
export async function getActiveLoansBatchEvm(
|
|
449
|
+
provider: Provider,
|
|
450
|
+
tokenHolderContractAddress: string,
|
|
451
|
+
startIndex: BigNumberish,
|
|
452
|
+
batchSize: BigNumberish
|
|
453
|
+
): Promise<Loan[]> {
|
|
454
|
+
const contract = new Contract(
|
|
455
|
+
tokenHolderContractAddress,
|
|
456
|
+
tokenHolderAbi,
|
|
457
|
+
provider
|
|
458
|
+
);
|
|
459
|
+
return contract.getActiveLoansBatch(startIndex, batchSize);
|
|
460
|
+
}
|
|
461
|
+
|
|
462
|
+
/**
|
|
463
|
+
* Get all loans for a specific borrower
|
|
464
|
+
* @param provider - Ethers provider
|
|
465
|
+
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
466
|
+
* @param borrowerAddress - Address of the borrower
|
|
467
|
+
* @returns Array of loans belonging to the borrower
|
|
468
|
+
*/
|
|
469
|
+
export async function getLoansByBorrowerEvm(
|
|
470
|
+
provider: Provider,
|
|
471
|
+
tokenHolderContractAddress: string,
|
|
472
|
+
borrowerAddress: string
|
|
473
|
+
): Promise<Loan[]> {
|
|
474
|
+
const contract = new Contract(
|
|
475
|
+
tokenHolderContractAddress,
|
|
476
|
+
tokenHolderAbi,
|
|
477
|
+
provider
|
|
478
|
+
);
|
|
479
|
+
return contract.getLoansByBorrower(borrowerAddress);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* Get current exposure for a collateral
|
|
484
|
+
* @param provider - Ethers provider
|
|
485
|
+
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
486
|
+
* @param collateralAddress - Address of the collateral token
|
|
487
|
+
* @returns Current exposure as a BigNumber
|
|
488
|
+
*/
|
|
489
|
+
export async function getCollateralExposureEvm(
|
|
490
|
+
provider: Provider,
|
|
491
|
+
tokenHolderContractAddress: string,
|
|
492
|
+
collateralAddress: string
|
|
493
|
+
): Promise<bigint> {
|
|
494
|
+
const contract = new Contract(
|
|
495
|
+
tokenHolderContractAddress,
|
|
496
|
+
tokenHolderAbi,
|
|
497
|
+
provider
|
|
498
|
+
);
|
|
499
|
+
return contract.getCollateralExposure(collateralAddress);
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/**
|
|
503
|
+
* Get available exposure for a collateral
|
|
504
|
+
* @param provider - Ethers provider
|
|
505
|
+
* @param tokenHolderContractAddress - Address of the TokenHolder contract
|
|
506
|
+
* @param collateralAddress - Address of the collateral token
|
|
507
|
+
* @returns Available exposure as a BigNumber
|
|
508
|
+
*/
|
|
509
|
+
export async function getAvailableExposureEvm(
|
|
510
|
+
provider: Provider,
|
|
511
|
+
tokenHolderContractAddress: string,
|
|
512
|
+
collateralAddress: string
|
|
513
|
+
): Promise<bigint> {
|
|
514
|
+
const contract = new Contract(
|
|
515
|
+
tokenHolderContractAddress,
|
|
516
|
+
tokenHolderAbi,
|
|
517
|
+
provider
|
|
518
|
+
);
|
|
519
|
+
return contract.getAvailableExposure(collateralAddress);
|
|
520
|
+
}
|
package/interfaces/evm.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
import { Block } from "ethers";
|
|
2
|
+
|
|
1
3
|
export interface Collateral {
|
|
2
4
|
collateralAddress: string;
|
|
3
5
|
maxLendPerToken: bigint;
|
|
4
6
|
interestRate: bigint;
|
|
5
7
|
active: boolean;
|
|
6
8
|
minAmount: bigint;
|
|
9
|
+
maxExposure: bigint;
|
|
10
|
+
currentExposure: bigint;
|
|
7
11
|
}
|
|
8
12
|
|
|
9
13
|
export interface Loan {
|
|
@@ -23,6 +27,8 @@ export interface BuyEvent {
|
|
|
23
27
|
openingPositionSize: bigint;
|
|
24
28
|
collateralAmount: bigint;
|
|
25
29
|
initialMargin: bigint;
|
|
30
|
+
transactionHash: string;
|
|
31
|
+
timestamp: number;
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
export interface SellEvent {
|
|
@@ -31,6 +37,8 @@ export interface SellEvent {
|
|
|
31
37
|
loanId: bigint;
|
|
32
38
|
closingPositionSize: bigint;
|
|
33
39
|
profit: bigint;
|
|
40
|
+
transactionHash: string;
|
|
41
|
+
timestamp: number;
|
|
34
42
|
}
|
|
35
43
|
|
|
36
44
|
export interface LiquidationEvent {
|
|
@@ -39,4 +47,6 @@ export interface LiquidationEvent {
|
|
|
39
47
|
loanId: bigint;
|
|
40
48
|
closingPositionSize: bigint;
|
|
41
49
|
liquidatorRepaidAmount: bigint;
|
|
50
|
+
transactionHash: string;
|
|
51
|
+
timestamp: number;
|
|
42
52
|
}
|