@lavarage/sdk 6.7.3 → 6.7.5
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 +4 -5
- package/dist/index.d.ts +4 -5
- package/dist/index.js +40 -33
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -33
- package/dist/index.mjs.map +1 -1
- package/evm.ts +50 -40
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -2717,13 +2717,12 @@ declare const closePositionEvm: (provider: Provider, borrowerOpsContractAddress:
|
|
|
2717
2717
|
gasPrice?: string | number;
|
|
2718
2718
|
}) => Promise<ContractTransaction>;
|
|
2719
2719
|
/**
|
|
2720
|
-
* Get all positions from
|
|
2720
|
+
* Get all positions from active loans
|
|
2721
2721
|
* @param provider - Ethers provider
|
|
2722
|
-
* @param
|
|
2723
|
-
* @
|
|
2724
|
-
* @returns Array of Buy events representing positions
|
|
2722
|
+
* @param tokenHolderContractAddress - TokenHolder contract address
|
|
2723
|
+
* @returns Array of active positions
|
|
2725
2724
|
*/
|
|
2726
|
-
declare function getPositionsEvm(provider: Provider,
|
|
2725
|
+
declare function getPositionsEvm(provider: Provider, tokenHolderContractAddress: string): Promise<BuyEvent[]>;
|
|
2727
2726
|
/**
|
|
2728
2727
|
* Get closed positions from events
|
|
2729
2728
|
* @param provider - Ethers provider
|
package/dist/index.d.ts
CHANGED
|
@@ -2717,13 +2717,12 @@ declare const closePositionEvm: (provider: Provider, borrowerOpsContractAddress:
|
|
|
2717
2717
|
gasPrice?: string | number;
|
|
2718
2718
|
}) => Promise<ContractTransaction>;
|
|
2719
2719
|
/**
|
|
2720
|
-
* Get all positions from
|
|
2720
|
+
* Get all positions from active loans
|
|
2721
2721
|
* @param provider - Ethers provider
|
|
2722
|
-
* @param
|
|
2723
|
-
* @
|
|
2724
|
-
* @returns Array of Buy events representing positions
|
|
2722
|
+
* @param tokenHolderContractAddress - TokenHolder contract address
|
|
2723
|
+
* @returns Array of active positions
|
|
2725
2724
|
*/
|
|
2726
|
-
declare function getPositionsEvm(provider: Provider,
|
|
2725
|
+
declare function getPositionsEvm(provider: Provider, tokenHolderContractAddress: string): Promise<BuyEvent[]>;
|
|
2727
2726
|
/**
|
|
2728
2727
|
* Get closed positions from events
|
|
2729
2728
|
* @param provider - Ethers provider
|
package/dist/index.js
CHANGED
|
@@ -3715,39 +3715,34 @@ var closePositionEvm = (_0, _1, _2) => __async(void 0, [_0, _1, _2], function* (
|
|
|
3715
3715
|
Object.keys(txOptions).length > 0 ? txOptions : {}
|
|
3716
3716
|
);
|
|
3717
3717
|
});
|
|
3718
|
-
function getPositionsEvm(provider,
|
|
3718
|
+
function getPositionsEvm(provider, tokenHolderContractAddress) {
|
|
3719
3719
|
return __async(this, null, function* () {
|
|
3720
3720
|
const contract = new import_ethers.Contract(
|
|
3721
|
-
|
|
3722
|
-
|
|
3721
|
+
tokenHolderContractAddress,
|
|
3722
|
+
tokenHolderAbi,
|
|
3723
3723
|
provider
|
|
3724
3724
|
);
|
|
3725
|
-
const
|
|
3726
|
-
const
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
3737
|
-
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
transactionHash: event.transactionHash,
|
|
3747
|
-
timestamp
|
|
3748
|
-
};
|
|
3749
|
-
}))
|
|
3750
|
-
);
|
|
3725
|
+
const activeLoanCount = yield contract.getActiveLoanCount();
|
|
3726
|
+
const batchSize = 100;
|
|
3727
|
+
const positions = [];
|
|
3728
|
+
for (let i = 0; i < activeLoanCount; i += batchSize) {
|
|
3729
|
+
const currentBatchSize = Math.min(Number(activeLoanCount) - i, batchSize);
|
|
3730
|
+
const loans = yield contract.getActiveLoansBatch(i, currentBatchSize);
|
|
3731
|
+
for (const loan of loans) {
|
|
3732
|
+
positions.push({
|
|
3733
|
+
trader: loan.borrower,
|
|
3734
|
+
tokenCollateral: loan.collateral.collateralAddress,
|
|
3735
|
+
loanId: loan.id,
|
|
3736
|
+
openingPositionSize: loan.amount,
|
|
3737
|
+
collateralAmount: loan.collateralAmount,
|
|
3738
|
+
initialMargin: loan.userPaid,
|
|
3739
|
+
transactionHash: "",
|
|
3740
|
+
// Not available from loan data
|
|
3741
|
+
timestamp: Number(loan.timestamp)
|
|
3742
|
+
});
|
|
3743
|
+
}
|
|
3744
|
+
}
|
|
3745
|
+
return positions;
|
|
3751
3746
|
});
|
|
3752
3747
|
}
|
|
3753
3748
|
function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock = 42960845) {
|
|
@@ -3757,10 +3752,16 @@ function getClosedPositionsEvm(provider, borrowerOpsContractAddress, fromBlock =
|
|
|
3757
3752
|
borrowerOperationsAbi,
|
|
3758
3753
|
provider
|
|
3759
3754
|
);
|
|
3755
|
+
const currentBlock = yield provider.getBlockNumber();
|
|
3760
3756
|
const filter = contract.filters.Sell();
|
|
3761
|
-
const
|
|
3757
|
+
const allEvents = [];
|
|
3758
|
+
for (let start = fromBlock; start <= currentBlock; start += 1e4) {
|
|
3759
|
+
const end = Math.min(start + 9999, currentBlock);
|
|
3760
|
+
const events = yield contract.queryFilter(filter, start, end);
|
|
3761
|
+
allEvents.push(...events);
|
|
3762
|
+
}
|
|
3762
3763
|
return Promise.all(
|
|
3763
|
-
|
|
3764
|
+
allEvents.map((event) => __async(this, null, function* () {
|
|
3764
3765
|
const { buyer, tokenCollateral, loanId, closingPositionSize, profit } = event.args;
|
|
3765
3766
|
const block = yield provider.getBlock(event.blockNumber);
|
|
3766
3767
|
const timestamp = block ? Number(block.timestamp) : 0;
|
|
@@ -3784,10 +3785,16 @@ function getLiquidatedPositionsEvm(provider, borrowerOpsContractAddress, fromBlo
|
|
|
3784
3785
|
borrowerOperationsAbi,
|
|
3785
3786
|
provider
|
|
3786
3787
|
);
|
|
3788
|
+
const currentBlock = yield provider.getBlockNumber();
|
|
3787
3789
|
const filter = contract.filters.Liquidation();
|
|
3788
|
-
const
|
|
3790
|
+
const allEvents = [];
|
|
3791
|
+
for (let start = fromBlock; start <= currentBlock; start += 1e4) {
|
|
3792
|
+
const end = Math.min(start + 9999, currentBlock);
|
|
3793
|
+
const events = yield contract.queryFilter(filter, start, end);
|
|
3794
|
+
allEvents.push(...events);
|
|
3795
|
+
}
|
|
3789
3796
|
return Promise.all(
|
|
3790
|
-
|
|
3797
|
+
allEvents.map((event) => __async(this, null, function* () {
|
|
3791
3798
|
const {
|
|
3792
3799
|
borrower,
|
|
3793
3800
|
tokenCollateral,
|