@defisaver/positions-sdk 0.0.199-dev-1 → 0.0.199-dev-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/cjs/liquityV2/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Web3 from 'web3';
|
|
|
2
2
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
|
|
4
4
|
export declare const getLiquityV2MarketData: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3) => Promise<LiquityV2MarketData>;
|
|
5
|
-
export declare const getLiquityV2UserTroveIds: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, account: EthAddress) => Promise<{
|
|
5
|
+
export declare const getLiquityV2UserTroveIds: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress) => Promise<{
|
|
6
6
|
troves: {
|
|
7
7
|
troveId: string;
|
|
8
8
|
}[];
|
package/cjs/liquityV2/index.js
CHANGED
|
@@ -98,12 +98,10 @@ const getUserTroves = (viewContract, account, marketAddress, startIndex = 0, end
|
|
|
98
98
|
return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
|
|
99
99
|
});
|
|
100
100
|
const TransferEventSig = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
101
|
-
const getTransferredTroves = (web3, network, troveNFTAddress, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
101
|
+
const getTransferredTroves = (web3, network, troveNFTAddress, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
102
102
|
const nftContract = (0, contracts_1.createContractWrapper)(web3, network, 'LiquityV2TroveNFT', troveNFTAddress);
|
|
103
103
|
const currentBlock = yield web3.eth.getBlockNumber();
|
|
104
|
-
const events = yield nftContract.getPastEvents(TransferEventSig, {
|
|
105
|
-
fromBlock: currentBlock - 1000,
|
|
106
|
-
});
|
|
104
|
+
const events = yield nftContract.getPastEvents(TransferEventSig, Object.assign({ filter: { to: account } }, (0, utils_1.addToObjectIf)(limitBlocksForEventFetching, { fromBlock: currentBlock - 1000 })));
|
|
107
105
|
const userTransferredTroves = events.filter((event) => !(0, utils_1.compareAddresses)(event.returnValues.from, constants_1.ZERO_ADDRESS) && (0, utils_1.compareAddresses)(event.returnValues.to, account));
|
|
108
106
|
// check if the last know transfer address is the user
|
|
109
107
|
userTransferredTroves.forEach((event, index) => {
|
|
@@ -114,11 +112,11 @@ const getTransferredTroves = (web3, network, troveNFTAddress, account) => __awai
|
|
|
114
112
|
// @ts-ignore
|
|
115
113
|
return userTransferredTroves.filter((event) => !event.invalid).map((event) => ({ troveId: event.returnValues.tokenId }));
|
|
116
114
|
});
|
|
117
|
-
const getLiquityV2UserTroveIds = (web3, network, selectedMarket, troveNFTAddress, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
115
|
+
const getLiquityV2UserTroveIds = (web3, network, selectedMarket, troveNFTAddress, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
116
|
const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
|
|
119
117
|
const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = yield Promise.all([
|
|
120
118
|
getUserTroves(viewContract, account, selectedMarket.marketAddress),
|
|
121
|
-
getTransferredTroves(web3, network, troveNFTAddress, account),
|
|
119
|
+
getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, account),
|
|
122
120
|
]);
|
|
123
121
|
const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
|
|
124
122
|
const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (t.troveId === value.troveId)));
|
package/esm/liquityV2/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import Web3 from 'web3';
|
|
|
2
2
|
import { EthAddress, NetworkNumber } from '../types/common';
|
|
3
3
|
import { InnerLiquityV2MarketData, LiquityV2AssetsData, LiquityV2MarketData, LiquityV2MarketInfo, LiquityV2TroveData } from '../types';
|
|
4
4
|
export declare const getLiquityV2MarketData: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, mainnetWeb3: Web3) => Promise<LiquityV2MarketData>;
|
|
5
|
-
export declare const getLiquityV2UserTroveIds: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, account: EthAddress) => Promise<{
|
|
5
|
+
export declare const getLiquityV2UserTroveIds: (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress) => Promise<{
|
|
6
6
|
troves: {
|
|
7
7
|
troveId: string;
|
|
8
8
|
}[];
|
package/esm/liquityV2/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { createContractWrapper, LiquityV2ViewContract } from '../contracts';
|
|
|
13
13
|
import { LIQUITY_V2_TROVE_STATUS_ENUM, } from '../types';
|
|
14
14
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
15
15
|
import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
|
|
16
|
-
import { compareAddresses, ethToWeth } from '../services/utils';
|
|
16
|
+
import { addToObjectIf, compareAddresses, ethToWeth } from '../services/utils';
|
|
17
17
|
import { ZERO_ADDRESS } from '../constants';
|
|
18
18
|
export const getLiquityV2MarketData = (web3, network, selectedMarket, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
19
|
const viewContract = LiquityV2ViewContract(web3, network);
|
|
@@ -91,12 +91,10 @@ const getUserTroves = (viewContract, account, marketAddress, startIndex = 0, end
|
|
|
91
91
|
return getUserTroves(viewContract, account, marketAddress, newStartIndex, newStartIndex + 100, existingTroves);
|
|
92
92
|
});
|
|
93
93
|
const TransferEventSig = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
94
|
-
const getTransferredTroves = (web3, network, troveNFTAddress, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
+
const getTransferredTroves = (web3, network, troveNFTAddress, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
95
95
|
const nftContract = createContractWrapper(web3, network, 'LiquityV2TroveNFT', troveNFTAddress);
|
|
96
96
|
const currentBlock = yield web3.eth.getBlockNumber();
|
|
97
|
-
const events = yield nftContract.getPastEvents(TransferEventSig, {
|
|
98
|
-
fromBlock: currentBlock - 1000,
|
|
99
|
-
});
|
|
97
|
+
const events = yield nftContract.getPastEvents(TransferEventSig, Object.assign({ filter: { to: account } }, addToObjectIf(limitBlocksForEventFetching, { fromBlock: currentBlock - 1000 })));
|
|
100
98
|
const userTransferredTroves = events.filter((event) => !compareAddresses(event.returnValues.from, ZERO_ADDRESS) && compareAddresses(event.returnValues.to, account));
|
|
101
99
|
// check if the last know transfer address is the user
|
|
102
100
|
userTransferredTroves.forEach((event, index) => {
|
|
@@ -107,11 +105,11 @@ const getTransferredTroves = (web3, network, troveNFTAddress, account) => __awai
|
|
|
107
105
|
// @ts-ignore
|
|
108
106
|
return userTransferredTroves.filter((event) => !event.invalid).map((event) => ({ troveId: event.returnValues.tokenId }));
|
|
109
107
|
});
|
|
110
|
-
export const getLiquityV2UserTroveIds = (web3, network, selectedMarket, troveNFTAddress, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
export const getLiquityV2UserTroveIds = (web3, network, selectedMarket, troveNFTAddress, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
|
|
111
109
|
const viewContract = LiquityV2ViewContract(web3, network);
|
|
112
110
|
const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = yield Promise.all([
|
|
113
111
|
getUserTroves(viewContract, account, selectedMarket.marketAddress),
|
|
114
|
-
getTransferredTroves(web3, network, troveNFTAddress, account),
|
|
112
|
+
getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, account),
|
|
115
113
|
]);
|
|
116
114
|
const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
|
|
117
115
|
const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (t.troveId === value.troveId)));
|
package/package.json
CHANGED
package/src/liquityV2/index.ts
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
} from '../types';
|
|
11
11
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
12
12
|
import { getLiquityV2AggregatedPositionData } from '../helpers/liquityV2Helpers';
|
|
13
|
-
import { compareAddresses, ethToWeth } from '../services/utils';
|
|
13
|
+
import { addToObjectIf, compareAddresses, ethToWeth } from '../services/utils';
|
|
14
14
|
import { LiquityV2View } from '../types/contracts/generated';
|
|
15
15
|
import { ZERO_ADDRESS } from '../constants';
|
|
16
16
|
|
|
@@ -99,13 +99,14 @@ const getUserTroves = async (viewContract: any, account: EthAddress, marketAddre
|
|
|
99
99
|
|
|
100
100
|
const TransferEventSig = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
101
101
|
|
|
102
|
-
const getTransferredTroves = async (web3: Web3, network: NetworkNumber, troveNFTAddress: EthAddress, account: EthAddress): Promise<{ troveId: string }[]> => {
|
|
102
|
+
const getTransferredTroves = async (web3: Web3, network: NetworkNumber, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress): Promise<{ troveId: string }[]> => {
|
|
103
103
|
const nftContract = createContractWrapper(web3, network, 'LiquityV2TroveNFT', troveNFTAddress);
|
|
104
104
|
const currentBlock = await web3.eth.getBlockNumber();
|
|
105
105
|
const events = await nftContract.getPastEvents(
|
|
106
106
|
TransferEventSig,
|
|
107
107
|
{
|
|
108
|
-
|
|
108
|
+
filter: { to: account },
|
|
109
|
+
...addToObjectIf(limitBlocksForEventFetching, { fromBlock: currentBlock - 1000 }),
|
|
109
110
|
},
|
|
110
111
|
);
|
|
111
112
|
const userTransferredTroves = events.filter((event) => !compareAddresses(event.returnValues.from, ZERO_ADDRESS) && compareAddresses(event.returnValues.to, account));
|
|
@@ -120,11 +121,11 @@ const getTransferredTroves = async (web3: Web3, network: NetworkNumber, troveNFT
|
|
|
120
121
|
return userTransferredTroves.filter((event) => !event.invalid).map((event) => ({ troveId: event.returnValues.tokenId }));
|
|
121
122
|
};
|
|
122
123
|
|
|
123
|
-
export const getLiquityV2UserTroveIds = async (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, account: EthAddress): Promise<{ troves: { troveId: string }[], nextFreeTroveIndex: string }> => {
|
|
124
|
+
export const getLiquityV2UserTroveIds = async (web3: Web3, network: NetworkNumber, selectedMarket: LiquityV2MarketInfo, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, account: EthAddress): Promise<{ troves: { troveId: string }[], nextFreeTroveIndex: string }> => {
|
|
124
125
|
const viewContract = LiquityV2ViewContract(web3, network);
|
|
125
126
|
const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = await Promise.all([
|
|
126
127
|
getUserTroves(viewContract, account, selectedMarket.marketAddress),
|
|
127
|
-
getTransferredTroves(web3, network, troveNFTAddress, account),
|
|
128
|
+
getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, account),
|
|
128
129
|
]);
|
|
129
130
|
const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
|
|
130
131
|
const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (
|