@defisaver/positions-sdk 0.0.199-dev-2 → 0.0.200

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.
@@ -1089,7 +1089,7 @@ module.exports = {
1089
1089
  "LiquityV2View": {
1090
1090
  "abi": [{ "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_prevId", "type": "uint256" }, { "internalType": "uint256", "name": "_nextId", "type": "uint256" }], "name": "findInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getApproxHint", "outputs": [{ "internalType": "uint256", "name": "hintId", "type": "uint256" }, { "internalType": "uint256", "name": "diff", "type": "uint256" }, { "internalType": "uint256", "name": "latestRandomSeed", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getDebtInFront", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }, { "internalType": "uint256", "name": "_targetIR", "type": "uint256" }], "name": "getDebtInFrontByInterestRate", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_numTroves", "type": "uint256" }], "name": "getDebtInFrontByTroveNum", "outputs": [{ "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "address", "name": "_depositor", "type": "address" }], "name": "getDepositorInfo", "outputs": [{ "internalType": "uint256", "name": "compoundedBOLD", "type": "uint256" }, { "internalType": "uint256", "name": "collGain", "type": "uint256" }, { "internalType": "uint256", "name": "boldGain", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "getMarketData", "outputs": [{ "components": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "CCR", "type": "uint256" }, { "internalType": "uint256", "name": "MCR", "type": "uint256" }, { "internalType": "uint256", "name": "SCR", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_SP", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_REDISTRIBUTION", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemColl", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemDebt", "type": "uint256" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "troveNFT", "type": "address" }, { "internalType": "address", "name": "borrowerOperations", "type": "address" }, { "internalType": "address", "name": "troveManager", "type": "address" }, { "internalType": "address", "name": "stabilityPool", "type": "address" }, { "internalType": "address", "name": "sortedTroves", "type": "address" }, { "internalType": "address", "name": "collSurplusPool", "type": "address" }, { "internalType": "address", "name": "activePool", "type": "address" }, { "internalType": "address", "name": "hintHelpers", "type": "address" }, { "internalType": "address", "name": "priceFeed", "type": "address" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "bool", "name": "isShutDown", "type": "bool" }], "internalType": "struct LiquityV2View.MarketData", "name": "data", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getNumOfTrovesInFrontOfTrove", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "numTroves", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }], "name": "getTroveInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "enum ITroveManager.Status", "name": "status", "type": "uint8" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "uint256", "name": "TCRatio", "type": "uint256" }, { "internalType": "uint256", "name": "annualInterestRate", "type": "uint256" }, { "internalType": "address", "name": "interestBatchManager", "type": "address" }, { "internalType": "uint256", "name": "batchDebtShares", "type": "uint256" }], "internalType": "struct LiquityV2View.TroveData", "name": "trove", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getTrovePosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }, { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_startIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_endIndex", "type": "uint256" }], "name": "getUserTroves", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "bool", "name": "ownedByUser", "type": "bool" }], "internalType": "struct LiquityV2View.ExistingTrove[]", "name": "troves", "type": "tuple[]" }, { "internalType": "int256", "name": "nextFreeTroveIndex", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "isShutDown", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_debtIncrease", "type": "uint256" }], "name": "predictAdjustTroveUpfrontFee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }],
1091
1091
  "networks": {
1092
- "1": { "address": "0x10B748Dc504C2515Bb6A9e23CB2F686090b6c584" },
1092
+ "1": { "address": "0x9C43F5ED37042Fd4bA7f98aa734026c6C7Fb1Db0" },
1093
1093
  },
1094
1094
  },
1095
1095
  "LiquityV2CollSurplusPool": {
@@ -98,10 +98,20 @@ 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, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
101
+ const nftContractCreationBlockMapping = {
102
+ ETH: 21686215,
103
+ wstETH: 21686238,
104
+ rETH: 21686257,
105
+ };
106
+ const getTransferredTroves = (web3, network, troveNFTAddress, limitBlocksForEventFetching, collAsset, account) => __awaiter(void 0, void 0, void 0, function* () {
102
107
  const nftContract = (0, contracts_1.createContractWrapper)(web3, network, 'LiquityV2TroveNFT', troveNFTAddress);
108
+ // @ts-ignore
109
+ const nftContractCreationBlock = nftContractCreationBlockMapping[collAsset];
103
110
  const currentBlock = yield web3.eth.getBlockNumber();
104
- const events = yield nftContract.getPastEvents(TransferEventSig, Object.assign({ filter: { to: account } }, (0, utils_1.addToObjectIf)(limitBlocksForEventFetching, { fromBlock: currentBlock - 1000 })));
111
+ const events = yield nftContract.getPastEvents(TransferEventSig, {
112
+ filter: { to: account },
113
+ fromBlock: limitBlocksForEventFetching ? (currentBlock - 1000) : nftContractCreationBlock,
114
+ });
105
115
  const userTransferredTroves = events.filter((event) => !(0, utils_1.compareAddresses)(event.returnValues.from, constants_1.ZERO_ADDRESS) && (0, utils_1.compareAddresses)(event.returnValues.to, account));
106
116
  // check if the last know transfer address is the user
107
117
  userTransferredTroves.forEach((event, index) => {
@@ -116,7 +126,7 @@ const getLiquityV2UserTroveIds = (web3, network, selectedMarket, troveNFTAddress
116
126
  const viewContract = (0, contracts_1.LiquityV2ViewContract)(web3, network);
117
127
  const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = yield Promise.all([
118
128
  getUserTroves(viewContract, account, selectedMarket.marketAddress),
119
- getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, account),
129
+ getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, selectedMarket.collateralToken, account),
120
130
  ]);
121
131
  const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
122
132
  const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (t.troveId === value.troveId)));
@@ -11,7 +11,7 @@ const LIQUITY_V2_ETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
11
11
  url: 'eth',
12
12
  debtToken: 'BOLD',
13
13
  collateralToken: 'ETH',
14
- marketAddress: '0xc3fe668b43439525f70fe860f89882f0be312504',
14
+ marketAddress: '0x38e1f07b954cfab7239d7acab49997fbaad96476',
15
15
  protocolName: 'liquity-v2',
16
16
  });
17
17
  exports.LIQUITY_V2_ETH_MARKET = LIQUITY_V2_ETH_MARKET;
@@ -23,7 +23,7 @@ const LIQUITY_V2_WSTETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
23
23
  url: 'wsteth',
24
24
  debtToken: 'BOLD',
25
25
  collateralToken: 'wstETH',
26
- marketAddress: '0x9b27787ff66aa3cea8dbc47772328459a1fa05ac',
26
+ marketAddress: '0x2d4ef56cb626e9a4c90c156018ba9ce269573c61',
27
27
  protocolName: 'liquity-v2',
28
28
  });
29
29
  exports.LIQUITY_V2_WSTETH_MARKET = LIQUITY_V2_WSTETH_MARKET;
@@ -35,7 +35,7 @@ const LIQUITY_V2_RETH_MARKET = (networkId = common_1.NetworkNumber.Eth) => ({
35
35
  url: 'reth',
36
36
  debtToken: 'BOLD',
37
37
  collateralToken: 'rETH',
38
- marketAddress: '0xde524be191de806011e98c8d36d50d7a88391a3e',
38
+ marketAddress: '0x3b48169809dd827f22c9e0f2d71ff12ea7a94a2f',
39
39
  protocolName: 'liquity-v2',
40
40
  });
41
41
  exports.LIQUITY_V2_RETH_MARKET = LIQUITY_V2_RETH_MARKET;
@@ -1088,7 +1088,7 @@ module.exports = {
1088
1088
  "LiquityV2View": {
1089
1089
  "abi": [{ "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_prevId", "type": "uint256" }, { "internalType": "uint256", "name": "_nextId", "type": "uint256" }], "name": "findInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getApproxHint", "outputs": [{ "internalType": "uint256", "name": "hintId", "type": "uint256" }, { "internalType": "uint256", "name": "diff", "type": "uint256" }, { "internalType": "uint256", "name": "latestRandomSeed", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getDebtInFront", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_acc", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }, { "internalType": "uint256", "name": "_targetIR", "type": "uint256" }], "name": "getDebtInFrontByInterestRate", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_numTroves", "type": "uint256" }], "name": "getDebtInFrontByTroveNum", "outputs": [{ "internalType": "uint256", "name": "debt", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "address", "name": "_depositor", "type": "address" }], "name": "getDepositorInfo", "outputs": [{ "internalType": "uint256", "name": "compoundedBOLD", "type": "uint256" }, { "internalType": "uint256", "name": "collGain", "type": "uint256" }, { "internalType": "uint256", "name": "boldGain", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_interestRate", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getInsertPosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "getMarketData", "outputs": [{ "components": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "CCR", "type": "uint256" }, { "internalType": "uint256", "name": "MCR", "type": "uint256" }, { "internalType": "uint256", "name": "SCR", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_SP", "type": "uint256" }, { "internalType": "uint256", "name": "LIQUIDATION_PENALTY_REDISTRIBUTION", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemColl", "type": "uint256" }, { "internalType": "uint256", "name": "entireSystemDebt", "type": "uint256" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "address", "name": "troveNFT", "type": "address" }, { "internalType": "address", "name": "borrowerOperations", "type": "address" }, { "internalType": "address", "name": "troveManager", "type": "address" }, { "internalType": "address", "name": "stabilityPool", "type": "address" }, { "internalType": "address", "name": "sortedTroves", "type": "address" }, { "internalType": "address", "name": "collSurplusPool", "type": "address" }, { "internalType": "address", "name": "activePool", "type": "address" }, { "internalType": "address", "name": "hintHelpers", "type": "address" }, { "internalType": "address", "name": "priceFeed", "type": "address" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "bool", "name": "isShutDown", "type": "bool" }], "internalType": "struct LiquityV2View.MarketData", "name": "data", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_iterations", "type": "uint256" }], "name": "getNumOfTrovesInFrontOfTrove", "outputs": [{ "internalType": "uint256", "name": "next", "type": "uint256" }, { "internalType": "uint256", "name": "numTroves", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }], "name": "getTroveInfo", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address", "name": "collToken", "type": "address" }, { "internalType": "enum ITroveManager.Status", "name": "status", "type": "uint8" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collPrice", "type": "uint256" }, { "internalType": "uint256", "name": "TCRatio", "type": "uint256" }, { "internalType": "uint256", "name": "annualInterestRate", "type": "uint256" }, { "internalType": "address", "name": "interestBatchManager", "type": "address" }, { "internalType": "uint256", "name": "batchDebtShares", "type": "uint256" }], "internalType": "struct LiquityV2View.TroveData", "name": "trove", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_numTrials", "type": "uint256" }, { "internalType": "uint256", "name": "_inputRandomSeed", "type": "uint256" }], "name": "getTrovePosition", "outputs": [{ "internalType": "uint256", "name": "prevId", "type": "uint256" }, { "internalType": "uint256", "name": "nextId", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }, { "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_startIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_endIndex", "type": "uint256" }], "name": "getUserTroves", "outputs": [{ "components": [{ "internalType": "uint256", "name": "troveId", "type": "uint256" }, { "internalType": "bool", "name": "ownedByUser", "type": "bool" }], "internalType": "struct LiquityV2View.ExistingTrove[]", "name": "troves", "type": "tuple[]" }, { "internalType": "int256", "name": "nextFreeTroveIndex", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }], "name": "isShutDown", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_market", "type": "address" }, { "internalType": "uint256", "name": "_collIndex", "type": "uint256" }, { "internalType": "uint256", "name": "_troveId", "type": "uint256" }, { "internalType": "uint256", "name": "_debtIncrease", "type": "uint256" }], "name": "predictAdjustTroveUpfrontFee", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }],
1090
1090
  "networks": {
1091
- "1": { "address": "0x10B748Dc504C2515Bb6A9e23CB2F686090b6c584" },
1091
+ "1": { "address": "0x9C43F5ED37042Fd4bA7f98aa734026c6C7Fb1Db0" },
1092
1092
  },
1093
1093
  },
1094
1094
  "LiquityV2CollSurplusPool": {
@@ -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 { addToObjectIf, compareAddresses, ethToWeth } from '../services/utils';
16
+ import { 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,10 +91,20 @@ 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, limitBlocksForEventFetching, account) => __awaiter(void 0, void 0, void 0, function* () {
94
+ const nftContractCreationBlockMapping = {
95
+ ETH: 21686215,
96
+ wstETH: 21686238,
97
+ rETH: 21686257,
98
+ };
99
+ const getTransferredTroves = (web3, network, troveNFTAddress, limitBlocksForEventFetching, collAsset, account) => __awaiter(void 0, void 0, void 0, function* () {
95
100
  const nftContract = createContractWrapper(web3, network, 'LiquityV2TroveNFT', troveNFTAddress);
101
+ // @ts-ignore
102
+ const nftContractCreationBlock = nftContractCreationBlockMapping[collAsset];
96
103
  const currentBlock = yield web3.eth.getBlockNumber();
97
- const events = yield nftContract.getPastEvents(TransferEventSig, Object.assign({ filter: { to: account } }, addToObjectIf(limitBlocksForEventFetching, { fromBlock: currentBlock - 1000 })));
104
+ const events = yield nftContract.getPastEvents(TransferEventSig, {
105
+ filter: { to: account },
106
+ fromBlock: limitBlocksForEventFetching ? (currentBlock - 1000) : nftContractCreationBlock,
107
+ });
98
108
  const userTransferredTroves = events.filter((event) => !compareAddresses(event.returnValues.from, ZERO_ADDRESS) && compareAddresses(event.returnValues.to, account));
99
109
  // check if the last know transfer address is the user
100
110
  userTransferredTroves.forEach((event, index) => {
@@ -109,7 +119,7 @@ export const getLiquityV2UserTroveIds = (web3, network, selectedMarket, troveNFT
109
119
  const viewContract = LiquityV2ViewContract(web3, network);
110
120
  const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = yield Promise.all([
111
121
  getUserTroves(viewContract, account, selectedMarket.marketAddress),
112
- getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, account),
122
+ getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, selectedMarket.collateralToken, account),
113
123
  ]);
114
124
  const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
115
125
  const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (t.troveId === value.troveId)));
@@ -8,7 +8,7 @@ export const LIQUITY_V2_ETH_MARKET = (networkId = NetworkNumber.Eth) => ({
8
8
  url: 'eth',
9
9
  debtToken: 'BOLD',
10
10
  collateralToken: 'ETH',
11
- marketAddress: '0xc3fe668b43439525f70fe860f89882f0be312504',
11
+ marketAddress: '0x38e1f07b954cfab7239d7acab49997fbaad96476',
12
12
  protocolName: 'liquity-v2',
13
13
  });
14
14
  export const LIQUITY_V2_WSTETH_MARKET = (networkId = NetworkNumber.Eth) => ({
@@ -19,7 +19,7 @@ export const LIQUITY_V2_WSTETH_MARKET = (networkId = NetworkNumber.Eth) => ({
19
19
  url: 'wsteth',
20
20
  debtToken: 'BOLD',
21
21
  collateralToken: 'wstETH',
22
- marketAddress: '0x9b27787ff66aa3cea8dbc47772328459a1fa05ac',
22
+ marketAddress: '0x2d4ef56cb626e9a4c90c156018ba9ce269573c61',
23
23
  protocolName: 'liquity-v2',
24
24
  });
25
25
  export const LIQUITY_V2_RETH_MARKET = (networkId = NetworkNumber.Eth) => ({
@@ -30,7 +30,7 @@ export const LIQUITY_V2_RETH_MARKET = (networkId = NetworkNumber.Eth) => ({
30
30
  url: 'reth',
31
31
  debtToken: 'BOLD',
32
32
  collateralToken: 'rETH',
33
- marketAddress: '0xde524be191de806011e98c8d36d50d7a88391a3e',
33
+ marketAddress: '0x3b48169809dd827f22c9e0f2d71ff12ea7a94a2f',
34
34
  protocolName: 'liquity-v2',
35
35
  });
36
36
  export const LiquityV2Markets = (networkId) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.199-dev-2",
3
+ "version": "0.0.200",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -13,7 +13,7 @@
13
13
  "lint": "eslint src/ --fix",
14
14
  "lint-check": "eslint src/",
15
15
  "generate-contracts": "node scripts/generateContracts.js",
16
- "test": "mocha tests/liquityV2.ts",
16
+ "test": "mocha tests/*",
17
17
  "test-single": "mocha ./tests/$npm_config_name.ts",
18
18
  "test:debugger": "mocha --inspect-brk tests/*",
19
19
  "build-test": "npm run build && npm run test",
@@ -23,7 +23,7 @@
23
23
  "author": "",
24
24
  "license": "ISC",
25
25
  "dependencies": {
26
- "@defisaver/tokens": "^1.5.53-dev-1",
26
+ "@defisaver/tokens": "^1.5.54",
27
27
  "@ethersproject/bignumber": "^5.7.0",
28
28
  "@morpho-org/morpho-aave-v3-sdk": "^1.5.3",
29
29
  "decimal.js": "^10.4.3"
@@ -1089,7 +1089,7 @@ module.exports = {
1089
1089
  "LiquityV2View":{
1090
1090
  "abi": [{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_interestRate","type":"uint256"},{"internalType":"uint256","name":"_prevId","type":"uint256"},{"internalType":"uint256","name":"_nextId","type":"uint256"}],"name":"findInsertPosition","outputs":[{"internalType":"uint256","name":"prevId","type":"uint256"},{"internalType":"uint256","name":"nextId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_collIndex","type":"uint256"},{"internalType":"uint256","name":"_interestRate","type":"uint256"},{"internalType":"uint256","name":"_numTrials","type":"uint256"},{"internalType":"uint256","name":"_inputRandomSeed","type":"uint256"}],"name":"getApproxHint","outputs":[{"internalType":"uint256","name":"hintId","type":"uint256"},{"internalType":"uint256","name":"diff","type":"uint256"},{"internalType":"uint256","name":"latestRandomSeed","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_acc","type":"uint256"},{"internalType":"uint256","name":"_iterations","type":"uint256"}],"name":"getDebtInFront","outputs":[{"internalType":"uint256","name":"next","type":"uint256"},{"internalType":"uint256","name":"debt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_acc","type":"uint256"},{"internalType":"uint256","name":"_iterations","type":"uint256"},{"internalType":"uint256","name":"_targetIR","type":"uint256"}],"name":"getDebtInFrontByInterestRate","outputs":[{"internalType":"uint256","name":"next","type":"uint256"},{"internalType":"uint256","name":"debt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_numTroves","type":"uint256"}],"name":"getDebtInFrontByTroveNum","outputs":[{"internalType":"uint256","name":"debt","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"address","name":"_depositor","type":"address"}],"name":"getDepositorInfo","outputs":[{"internalType":"uint256","name":"compoundedBOLD","type":"uint256"},{"internalType":"uint256","name":"collGain","type":"uint256"},{"internalType":"uint256","name":"boldGain","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_collIndex","type":"uint256"},{"internalType":"uint256","name":"_interestRate","type":"uint256"},{"internalType":"uint256","name":"_numTrials","type":"uint256"},{"internalType":"uint256","name":"_inputRandomSeed","type":"uint256"}],"name":"getInsertPosition","outputs":[{"internalType":"uint256","name":"prevId","type":"uint256"},{"internalType":"uint256","name":"nextId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"}],"name":"getMarketData","outputs":[{"components":[{"internalType":"address","name":"market","type":"address"},{"internalType":"uint256","name":"CCR","type":"uint256"},{"internalType":"uint256","name":"MCR","type":"uint256"},{"internalType":"uint256","name":"SCR","type":"uint256"},{"internalType":"uint256","name":"LIQUIDATION_PENALTY_SP","type":"uint256"},{"internalType":"uint256","name":"LIQUIDATION_PENALTY_REDISTRIBUTION","type":"uint256"},{"internalType":"uint256","name":"entireSystemColl","type":"uint256"},{"internalType":"uint256","name":"entireSystemDebt","type":"uint256"},{"internalType":"address","name":"collToken","type":"address"},{"internalType":"address","name":"troveNFT","type":"address"},{"internalType":"address","name":"borrowerOperations","type":"address"},{"internalType":"address","name":"troveManager","type":"address"},{"internalType":"address","name":"stabilityPool","type":"address"},{"internalType":"address","name":"sortedTroves","type":"address"},{"internalType":"address","name":"collSurplusPool","type":"address"},{"internalType":"address","name":"activePool","type":"address"},{"internalType":"address","name":"hintHelpers","type":"address"},{"internalType":"address","name":"priceFeed","type":"address"},{"internalType":"uint256","name":"collPrice","type":"uint256"},{"internalType":"bool","name":"isShutDown","type":"bool"}],"internalType":"struct LiquityV2View.MarketData","name":"data","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_iterations","type":"uint256"}],"name":"getNumOfTrovesInFrontOfTrove","outputs":[{"internalType":"uint256","name":"next","type":"uint256"},{"internalType":"uint256","name":"numTroves","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_troveId","type":"uint256"}],"name":"getTroveInfo","outputs":[{"components":[{"internalType":"uint256","name":"troveId","type":"uint256"},{"internalType":"address","name":"owner","type":"address"},{"internalType":"address","name":"collToken","type":"address"},{"internalType":"enum ITroveManager.Status","name":"status","type":"uint8"},{"internalType":"uint256","name":"collAmount","type":"uint256"},{"internalType":"uint256","name":"debtAmount","type":"uint256"},{"internalType":"uint256","name":"collPrice","type":"uint256"},{"internalType":"uint256","name":"TCRatio","type":"uint256"},{"internalType":"uint256","name":"annualInterestRate","type":"uint256"},{"internalType":"address","name":"interestBatchManager","type":"address"},{"internalType":"uint256","name":"batchDebtShares","type":"uint256"}],"internalType":"struct LiquityV2View.TroveData","name":"trove","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_collIndex","type":"uint256"},{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_numTrials","type":"uint256"},{"internalType":"uint256","name":"_inputRandomSeed","type":"uint256"}],"name":"getTrovePosition","outputs":[{"internalType":"uint256","name":"prevId","type":"uint256"},{"internalType":"uint256","name":"nextId","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_user","type":"address"},{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_startIndex","type":"uint256"},{"internalType":"uint256","name":"_endIndex","type":"uint256"}],"name":"getUserTroves","outputs":[{"components":[{"internalType":"uint256","name":"troveId","type":"uint256"},{"internalType":"bool","name":"ownedByUser","type":"bool"}],"internalType":"struct LiquityV2View.ExistingTrove[]","name":"troves","type":"tuple[]"},{"internalType":"int256","name":"nextFreeTroveIndex","type":"int256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"}],"name":"isShutDown","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_market","type":"address"},{"internalType":"uint256","name":"_collIndex","type":"uint256"},{"internalType":"uint256","name":"_troveId","type":"uint256"},{"internalType":"uint256","name":"_debtIncrease","type":"uint256"}],"name":"predictAdjustTroveUpfrontFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
1091
1091
  "networks": {
1092
- "1": { "address": "0x10B748Dc504C2515Bb6A9e23CB2F686090b6c584" },
1092
+ "1": { "address": "0x9C43F5ED37042Fd4bA7f98aa734026c6C7Fb1Db0" },
1093
1093
  },
1094
1094
  },
1095
1095
  "LiquityV2CollSurplusPool": {
@@ -99,14 +99,22 @@ 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, limitBlocksForEventFetching: boolean, account: EthAddress): Promise<{ troveId: string }[]> => {
102
+ const nftContractCreationBlockMapping = {
103
+ ETH: 21686215,
104
+ wstETH: 21686238,
105
+ rETH: 21686257,
106
+ };
107
+
108
+ const getTransferredTroves = async (web3: Web3, network: NetworkNumber, troveNFTAddress: EthAddress, limitBlocksForEventFetching: boolean, collAsset: string, account: EthAddress): Promise<{ troveId: string }[]> => {
103
109
  const nftContract = createContractWrapper(web3, network, 'LiquityV2TroveNFT', troveNFTAddress);
110
+ // @ts-ignore
111
+ const nftContractCreationBlock = nftContractCreationBlockMapping[collAsset];
104
112
  const currentBlock = await web3.eth.getBlockNumber();
105
113
  const events = await nftContract.getPastEvents(
106
114
  TransferEventSig,
107
115
  {
108
116
  filter: { to: account },
109
- ...addToObjectIf(limitBlocksForEventFetching, { fromBlock: currentBlock - 1000 }),
117
+ fromBlock: limitBlocksForEventFetching ? (currentBlock - 1000) : nftContractCreationBlock,
110
118
  },
111
119
  );
112
120
  const userTransferredTroves = events.filter((event) => !compareAddresses(event.returnValues.from, ZERO_ADDRESS) && compareAddresses(event.returnValues.to, account));
@@ -125,7 +133,7 @@ export const getLiquityV2UserTroveIds = async (web3: Web3, network: NetworkNumbe
125
133
  const viewContract = LiquityV2ViewContract(web3, network);
126
134
  const [{ troves: userTroves, nextFreeTroveIndex }, userTransferredTroves] = await Promise.all([
127
135
  getUserTroves(viewContract, account, selectedMarket.marketAddress),
128
- getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, account),
136
+ getTransferredTroves(web3, network, troveNFTAddress, limitBlocksForEventFetching, selectedMarket.collateralToken, account),
129
137
  ]);
130
138
  const troves = [...userTroves.map(({ troveId }) => ({ troveId })), ...userTransferredTroves];
131
139
  const filteredTroves = troves.filter((value, index, self) => index === self.findIndex((t) => (
@@ -9,7 +9,7 @@ export const LIQUITY_V2_ETH_MARKET = (networkId: NetworkNumber = NetworkNumber.E
9
9
  url: 'eth',
10
10
  debtToken: 'BOLD',
11
11
  collateralToken: 'ETH',
12
- marketAddress: '0xc3fe668b43439525f70fe860f89882f0be312504',
12
+ marketAddress: '0x38e1f07b954cfab7239d7acab49997fbaad96476',
13
13
  protocolName: 'liquity-v2',
14
14
  });
15
15
 
@@ -21,7 +21,7 @@ export const LIQUITY_V2_WSTETH_MARKET = (networkId: NetworkNumber = NetworkNumbe
21
21
  url: 'wsteth',
22
22
  debtToken: 'BOLD',
23
23
  collateralToken: 'wstETH',
24
- marketAddress: '0x9b27787ff66aa3cea8dbc47772328459a1fa05ac',
24
+ marketAddress: '0x2d4ef56cb626e9a4c90c156018ba9ce269573c61',
25
25
  protocolName: 'liquity-v2',
26
26
  });
27
27
 
@@ -33,7 +33,7 @@ export const LIQUITY_V2_RETH_MARKET = (networkId: NetworkNumber = NetworkNumber.
33
33
  url: 'reth',
34
34
  debtToken: 'BOLD',
35
35
  collateralToken: 'rETH',
36
- marketAddress: '0xde524be191de806011e98c8d36d50d7a88391a3e',
36
+ marketAddress: '0x3b48169809dd827f22c9e0f2d71ff12ea7a94a2f',
37
37
  protocolName: 'liquity-v2',
38
38
  });
39
39