@lavarage/sdk 6.6.0 → 6.7.1
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 -248
- package/abi/tokenHolderAbi.ts +1 -443
- package/dist/index.d.mts +30 -3
- package/dist/index.d.ts +30 -3
- package/dist/index.js +102 -751
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +99 -751
- package/dist/index.mjs.map +1 -1
- package/evm.ts +124 -54
- package/index.ts +2 -10
- package/interfaces/evm.ts +8 -0
- package/package.json +1 -1
package/evm.ts
CHANGED
|
@@ -145,25 +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
|
-
|
|
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
|
+
);
|
|
167
174
|
}
|
|
168
175
|
|
|
169
176
|
/**
|
|
@@ -187,23 +194,25 @@ export async function getClosedPositionsEvm(
|
|
|
187
194
|
const filter = contract.filters.Sell();
|
|
188
195
|
const events = await contract.queryFilter(filter, fromBlock);
|
|
189
196
|
|
|
190
|
-
return
|
|
191
|
-
|
|
192
|
-
buyer,
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
+
);
|
|
207
216
|
}
|
|
208
217
|
|
|
209
218
|
/**
|
|
@@ -227,23 +236,30 @@ export async function getLiquidatedPositionsEvm(
|
|
|
227
236
|
const filter = contract.filters.Liquidation();
|
|
228
237
|
const events = await contract.queryFilter(filter, fromBlock);
|
|
229
238
|
|
|
230
|
-
return
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
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
|
+
);
|
|
247
263
|
}
|
|
248
264
|
|
|
249
265
|
/**
|
|
@@ -347,4 +363,58 @@ export async function getOffersEvm(
|
|
|
347
363
|
}
|
|
348
364
|
|
|
349
365
|
return activeCollaterals;
|
|
350
|
-
}
|
|
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
|
+
}
|
package/index.ts
CHANGED
|
@@ -190,6 +190,7 @@ export const openTradeV1 = async (
|
|
|
190
190
|
marginSOL: BN,
|
|
191
191
|
leverage: number,
|
|
192
192
|
randomSeed: Keypair,
|
|
193
|
+
tokenProgram: PublicKey,
|
|
193
194
|
partnerFeeRecipient?: PublicKey,
|
|
194
195
|
partnerFeeMarkup?: number
|
|
195
196
|
) => {
|
|
@@ -208,11 +209,6 @@ export const openTradeV1 = async (
|
|
|
208
209
|
randomSeed.publicKey
|
|
209
210
|
);
|
|
210
211
|
|
|
211
|
-
const mintAccount = await lavarageProgram.provider.connection.getAccountInfo(
|
|
212
|
-
offer.account.collateralType
|
|
213
|
-
);
|
|
214
|
-
const tokenProgram = mintAccount?.owner;
|
|
215
|
-
|
|
216
212
|
const fromTokenAccount = await getTokenAccountOrCreateIfNotExists(
|
|
217
213
|
lavarageProgram,
|
|
218
214
|
lavarageProgram.provider.publicKey!,
|
|
@@ -383,6 +379,7 @@ export const openTradeV2 = async (
|
|
|
383
379
|
leverage: number,
|
|
384
380
|
randomSeed: Keypair,
|
|
385
381
|
quoteToken: PublicKey,
|
|
382
|
+
tokenProgram: PublicKey,
|
|
386
383
|
partnerFeeRecipient?: PublicKey,
|
|
387
384
|
partnerFeeMarkup?: number
|
|
388
385
|
) => {
|
|
@@ -401,11 +398,6 @@ export const openTradeV2 = async (
|
|
|
401
398
|
randomSeed.publicKey
|
|
402
399
|
);
|
|
403
400
|
|
|
404
|
-
const mintAccount = await lavarageProgram.provider.connection.getAccountInfo(
|
|
405
|
-
offer.account.collateralType
|
|
406
|
-
);
|
|
407
|
-
const tokenProgram = mintAccount?.owner;
|
|
408
|
-
|
|
409
401
|
const quoteMintAccount =
|
|
410
402
|
await lavarageProgram.provider.connection.getAccountInfo(quoteToken);
|
|
411
403
|
const quoteTokenProgram = quoteMintAccount?.owner;
|
package/interfaces/evm.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { Block } from "ethers";
|
|
2
|
+
|
|
1
3
|
export interface Collateral {
|
|
2
4
|
collateralAddress: string;
|
|
3
5
|
maxLendPerToken: bigint;
|
|
@@ -23,6 +25,8 @@ export interface BuyEvent {
|
|
|
23
25
|
openingPositionSize: bigint;
|
|
24
26
|
collateralAmount: bigint;
|
|
25
27
|
initialMargin: bigint;
|
|
28
|
+
transactionHash: string;
|
|
29
|
+
timestamp: number;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
export interface SellEvent {
|
|
@@ -31,6 +35,8 @@ export interface SellEvent {
|
|
|
31
35
|
loanId: bigint;
|
|
32
36
|
closingPositionSize: bigint;
|
|
33
37
|
profit: bigint;
|
|
38
|
+
transactionHash: string;
|
|
39
|
+
timestamp: number;
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
export interface LiquidationEvent {
|
|
@@ -39,4 +45,6 @@ export interface LiquidationEvent {
|
|
|
39
45
|
loanId: bigint;
|
|
40
46
|
closingPositionSize: bigint;
|
|
41
47
|
liquidatorRepaidAmount: bigint;
|
|
48
|
+
transactionHash: string;
|
|
49
|
+
timestamp: number;
|
|
42
50
|
}
|