@defisaver/positions-sdk 0.0.144 → 0.0.145

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.
@@ -17,14 +17,13 @@ const decimal_js_1 = __importDefault(require("decimal.js"));
17
17
  const tokens_1 = require("@defisaver/tokens");
18
18
  const contracts_1 = require("../contracts");
19
19
  const utils_1 = require("../services/utils");
20
- const aave_1 = require("../types/aave");
21
20
  const common_1 = require("../types/common");
22
21
  const staking_1 = require("../staking");
23
22
  const multicall_1 = require("../multicall");
24
23
  const assets_1 = require("../assets");
25
24
  const moneymarket_1 = require("../moneymarket");
26
25
  const aaveHelpers_1 = require("../helpers/aaveHelpers");
27
- const aave_2 = require("../markets/aave");
26
+ const aave_1 = require("../markets/aave");
28
27
  const test = (web3, network) => {
29
28
  const contract = (0, contracts_1.AaveV3ViewContract)(web3, 1);
30
29
  return contract.methods.AAVE_REFERRAL_CODE().call();
@@ -74,94 +73,7 @@ const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
74
73
  };
75
74
  exports.aaveV3EmodeCategoriesMapping = aaveV3EmodeCategoriesMapping;
76
75
  // eslint-disable-next-line no-bitwise
77
- const isEnabledOnBitmap = (bitmap, assetId) => (((bitmap >> assetId) & 1) !== 0);
78
- // @DEV: hardcode emodes till they add new emodes structs to all chains
79
- const getAllEmodesHardcoded = (network, selectedMarket) => {
80
- switch (network) {
81
- case common_1.NetworkNumber.Eth:
82
- {
83
- switch (selectedMarket) {
84
- case aave_1.AaveVersions.AaveV3:
85
- return [
86
- {
87
- ltv: 9300,
88
- liquidationThreshold: 9500,
89
- liquidationBonus: 10100,
90
- collateralBitmap: '2952790659',
91
- label: 'ETH correlated',
92
- borrowableBitmap: '2952790659',
93
- },
94
- ];
95
- case aave_1.AaveVersions.AaveV3Lido:
96
- return [
97
- {
98
- ltv: 9350,
99
- liquidationThreshold: 9550,
100
- liquidationBonus: 10100,
101
- collateralBitmap: '3',
102
- label: 'ETH correlated',
103
- borrowableBitmap: '3',
104
- },
105
- ];
106
- case aave_1.AaveVersions.AaveV3Etherfi:
107
- return [];
108
- default:
109
- throw new Error('Emode not implemented for this market');
110
- }
111
- }
112
- case common_1.NetworkNumber.Arb:
113
- return [
114
- {
115
- ltv: 9300,
116
- liquidationThreshold: 9500,
117
- liquidationBonus: 10100,
118
- collateralBitmap: '4261',
119
- label: 'Stablecoins',
120
- borrowableBitmap: '4261',
121
- },
122
- {
123
- ltv: 9300,
124
- liquidationThreshold: 9500,
125
- liquidationBonus: 10100,
126
- collateralBitmap: '33040',
127
- label: 'ETH correlated',
128
- borrowableBitmap: '33040',
129
- },
130
- ];
131
- case common_1.NetworkNumber.Opt:
132
- return [
133
- {
134
- ltv: 9000,
135
- liquidationThreshold: 9300,
136
- liquidationBonus: 10100,
137
- collateralBitmap: '8357',
138
- label: 'Stablecoins',
139
- borrowableBitmap: '8357',
140
- },
141
- {
142
- ltv: 9300,
143
- liquidationThreshold: 9500,
144
- liquidationBonus: 10100,
145
- collateralBitmap: '4624',
146
- label: 'ETH correlated',
147
- borrowableBitmap: '4624',
148
- },
149
- ];
150
- case common_1.NetworkNumber.Base:
151
- return [
152
- {
153
- ltv: 9000,
154
- liquidationThreshold: 9300,
155
- liquidationBonus: 10200,
156
- collateralBitmap: '43',
157
- label: 'ETH correlated',
158
- borrowableBitmap: '43',
159
- },
160
- ];
161
- default:
162
- throw new Error('Emode not implemented for this network');
163
- }
164
- };
76
+ const isEnabledOnBitmap = (bitmap, assetId) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
165
77
  function getAaveV3MarketData(web3, network, market, defaultWeb3) {
166
78
  return __awaiter(this, void 0, void 0, function* () {
167
79
  const _addresses = market.assets.map(a => (0, tokens_1.getAssetInfo)((0, utils_1.ethToWeth)(a), network).address);
@@ -203,8 +115,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
203
115
  // eslint-disable-next-line prefer-const
204
116
  let [loanInfo, eModesInfo, isBorrowAllowed, multiRes] = yield Promise.all([
205
117
  loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call(),
206
- // loanInfoContract.methods.getAllEmodes(marketAddress).call(),
207
- getAllEmodesHardcoded(network, market.value),
118
+ loanInfoContract.methods.getAllEmodes(marketAddress).call(),
208
119
  loanInfoContract.methods.isBorrowAllowed(marketAddress).call(),
209
120
  isL2 ? [{ 0: null }, { 0: null }, { 0: null }, { 0: null }, { 0: null }] : (0, multicall_1.multicall)(multicallCallsObject, web3, network),
210
121
  ]);
@@ -227,9 +138,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
227
138
  }
228
139
  const [{ 0: ghoDiscountedPerDiscountToken }, { 0: discountRate }, { 0: minDiscountTokenBalance }, { 0: minGhoBalanceForDiscount }, { 0: facilitatorsList },] = multiRes;
229
140
  let rewardInfo = null;
230
- // @DEV: Temporarily disable incentives for Arbitrum and Optimism
231
- // const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
232
- const networksWithIncentives = [];
141
+ const networksWithIncentives = [common_1.NetworkNumber.Arb, common_1.NetworkNumber.Opt];
233
142
  if (networksWithIncentives.includes(network)) {
234
143
  rewardInfo = yield aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
235
144
  rewardInfo = rewardInfo.reduce((all, _market) => {
@@ -374,7 +283,7 @@ const getAaveV3AccountBalances = (web3, network, block, addressMapping, address)
374
283
  return balances;
375
284
  }
376
285
  const loanInfoContract = (0, contracts_1.AaveV3ViewContract)(web3, network, block);
377
- const market = (0, aave_2.AAVE_V3)(network);
286
+ const market = (0, aave_1.AAVE_V3)(network);
378
287
  const marketAddress = market.providerAddress;
379
288
  // @ts-ignore
380
289
  const protocolDataProviderContract = (0, contracts_1.createContractWrapper)(web3, network, market.protocolData, market.protocolDataAddress);
@@ -510,7 +419,7 @@ const getAaveV3AccountData = (web3, network, address, extractedState) => __await
510
419
  exports.getAaveV3AccountData = getAaveV3AccountData;
511
420
  const getAaveV3FullPositionData = (web3, network, address, market, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
512
421
  const marketData = yield getAaveV3MarketData(web3, network, market, mainnetWeb3);
513
- const positionData = yield (0, exports.getAaveV3AccountData)(web3, network, address, { assetsData: marketData.assetsData, selectedMarket: market });
422
+ const positionData = yield (0, exports.getAaveV3AccountData)(web3, network, address, { assetsData: marketData.assetsData, selectedMarket: market, eModeCategoriesData: marketData.eModeCategoriesData });
514
423
  return positionData;
515
424
  });
516
425
  exports.getAaveV3FullPositionData = getAaveV3FullPositionData;
@@ -266,16 +266,16 @@ module.exports = {
266
266
  "abi": [{ "inputs": [{ "internalType": "contract IPoolAddressesProvider", "name": "provider", "type": "address" }], "name": "getReservesIncentivesData", "outputs": [{ "components": [{ "internalType": "address", "name": "underlyingAsset", "type": "address" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "uint256", "name": "emissionPerSecond", "type": "uint256" }, { "internalType": "uint256", "name": "incentivesLastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesIndex", "type": "uint256" }, { "internalType": "uint256", "name": "emissionEndTimestamp", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "precision", "type": "uint8" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.RewardInfo[]", "name": "rewardsTokenInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.IncentiveData", "name": "aIncentiveData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "uint256", "name": "emissionPerSecond", "type": "uint256" }, { "internalType": "uint256", "name": "incentivesLastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesIndex", "type": "uint256" }, { "internalType": "uint256", "name": "emissionEndTimestamp", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "precision", "type": "uint8" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.RewardInfo[]", "name": "rewardsTokenInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.IncentiveData", "name": "vIncentiveData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "uint256", "name": "emissionPerSecond", "type": "uint256" }, { "internalType": "uint256", "name": "incentivesLastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesIndex", "type": "uint256" }, { "internalType": "uint256", "name": "emissionEndTimestamp", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "precision", "type": "uint8" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.RewardInfo[]", "name": "rewardsTokenInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.IncentiveData", "name": "sIncentiveData", "type": "tuple" }], "internalType": "struct IUiIncentiveDataProviderV3.AggregatedReserveIncentiveData[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "contract IPoolAddressesProvider", "name": "provider", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "getUserReservesIncentivesData", "outputs": [{ "components": [{ "internalType": "address", "name": "underlyingAsset", "type": "address" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "uint256", "name": "userUnclaimedRewards", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesUserIndex", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.UserRewardInfo[]", "name": "userRewardsInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.UserIncentiveData", "name": "aTokenIncentivesUserData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "uint256", "name": "userUnclaimedRewards", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesUserIndex", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.UserRewardInfo[]", "name": "userRewardsInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.UserIncentiveData", "name": "vTokenIncentivesUserData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "uint256", "name": "userUnclaimedRewards", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesUserIndex", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.UserRewardInfo[]", "name": "userRewardsInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.UserIncentiveData", "name": "sTokenIncentivesUserData", "type": "tuple" }], "internalType": "struct IUiIncentiveDataProviderV3.UserReserveIncentiveData[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }],
267
267
  "networks": {
268
268
  "1": {
269
- "address": "0x162A7AC02f547ad796CA549f757e2b8d1D9b10a6"
269
+ "address": "0x5a40cDe2b76Da2beD545efB3ae15708eE56aAF9c"
270
270
  },
271
271
  "10": {
272
- "address": "0x6F143FE2F7B02424ad3CaD1593D6f36c0Aab69d7"
272
+ "address": "0xc0179321f0825c3e0F59Fe7Ca4E40557b97797a3"
273
273
  },
274
274
  "8453": {
275
- "address": "0xEdD3b4737C1a0011626631a977b91Cf3E944982d"
275
+ "address": "0x5c5228aC8BC1528482514aF3e27E692495148717"
276
276
  },
277
277
  "42161": {
278
- "address": "0xDA67AF3403555Ce0AE3ffC22fDb7354458277358"
278
+ "address": "0xE92cd6164CE7DC68e740765BC1f2a091B6CBc3e4"
279
279
  }
280
280
  }
281
281
  },
@@ -11,7 +11,6 @@ import Dec from 'decimal.js';
11
11
  import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
12
12
  import { AaveIncentiveDataProviderV3Contract, AaveV3ViewContract, createContractWrapper, getConfigContractAbi, getConfigContractAddress, GhoTokenContract, } from '../contracts';
13
13
  import { addToObjectIf, ethToWeth, getAbiItem, isLayer2Network, wethToEth, wethToEthByAddress, } from '../services/utils';
14
- import { AaveVersions, } from '../types/aave';
15
14
  import { NetworkNumber, } from '../types/common';
16
15
  import { getStakingApy, STAKING_ASSETS } from '../staking';
17
16
  import { multicall } from '../multicall';
@@ -65,94 +64,7 @@ export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
65
64
  return categoriesMapping;
66
65
  };
67
66
  // eslint-disable-next-line no-bitwise
68
- const isEnabledOnBitmap = (bitmap, assetId) => (((bitmap >> assetId) & 1) !== 0);
69
- // @DEV: hardcode emodes till they add new emodes structs to all chains
70
- const getAllEmodesHardcoded = (network, selectedMarket) => {
71
- switch (network) {
72
- case NetworkNumber.Eth:
73
- {
74
- switch (selectedMarket) {
75
- case AaveVersions.AaveV3:
76
- return [
77
- {
78
- ltv: 9300,
79
- liquidationThreshold: 9500,
80
- liquidationBonus: 10100,
81
- collateralBitmap: '2952790659',
82
- label: 'ETH correlated',
83
- borrowableBitmap: '2952790659',
84
- },
85
- ];
86
- case AaveVersions.AaveV3Lido:
87
- return [
88
- {
89
- ltv: 9350,
90
- liquidationThreshold: 9550,
91
- liquidationBonus: 10100,
92
- collateralBitmap: '3',
93
- label: 'ETH correlated',
94
- borrowableBitmap: '3',
95
- },
96
- ];
97
- case AaveVersions.AaveV3Etherfi:
98
- return [];
99
- default:
100
- throw new Error('Emode not implemented for this market');
101
- }
102
- }
103
- case NetworkNumber.Arb:
104
- return [
105
- {
106
- ltv: 9300,
107
- liquidationThreshold: 9500,
108
- liquidationBonus: 10100,
109
- collateralBitmap: '4261',
110
- label: 'Stablecoins',
111
- borrowableBitmap: '4261',
112
- },
113
- {
114
- ltv: 9300,
115
- liquidationThreshold: 9500,
116
- liquidationBonus: 10100,
117
- collateralBitmap: '33040',
118
- label: 'ETH correlated',
119
- borrowableBitmap: '33040',
120
- },
121
- ];
122
- case NetworkNumber.Opt:
123
- return [
124
- {
125
- ltv: 9000,
126
- liquidationThreshold: 9300,
127
- liquidationBonus: 10100,
128
- collateralBitmap: '8357',
129
- label: 'Stablecoins',
130
- borrowableBitmap: '8357',
131
- },
132
- {
133
- ltv: 9300,
134
- liquidationThreshold: 9500,
135
- liquidationBonus: 10100,
136
- collateralBitmap: '4624',
137
- label: 'ETH correlated',
138
- borrowableBitmap: '4624',
139
- },
140
- ];
141
- case NetworkNumber.Base:
142
- return [
143
- {
144
- ltv: 9000,
145
- liquidationThreshold: 9300,
146
- liquidationBonus: 10200,
147
- collateralBitmap: '43',
148
- label: 'ETH correlated',
149
- borrowableBitmap: '43',
150
- },
151
- ];
152
- default:
153
- throw new Error('Emode not implemented for this network');
154
- }
155
- };
67
+ const isEnabledOnBitmap = (bitmap, assetId) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
156
68
  export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
157
69
  return __awaiter(this, void 0, void 0, function* () {
158
70
  const _addresses = market.assets.map(a => getAssetInfo(ethToWeth(a), network).address);
@@ -194,8 +106,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
194
106
  // eslint-disable-next-line prefer-const
195
107
  let [loanInfo, eModesInfo, isBorrowAllowed, multiRes] = yield Promise.all([
196
108
  loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call(),
197
- // loanInfoContract.methods.getAllEmodes(marketAddress).call(),
198
- getAllEmodesHardcoded(network, market.value),
109
+ loanInfoContract.methods.getAllEmodes(marketAddress).call(),
199
110
  loanInfoContract.methods.isBorrowAllowed(marketAddress).call(),
200
111
  isL2 ? [{ 0: null }, { 0: null }, { 0: null }, { 0: null }, { 0: null }] : multicall(multicallCallsObject, web3, network),
201
112
  ]);
@@ -218,9 +129,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
218
129
  }
219
130
  const [{ 0: ghoDiscountedPerDiscountToken }, { 0: discountRate }, { 0: minDiscountTokenBalance }, { 0: minGhoBalanceForDiscount }, { 0: facilitatorsList },] = multiRes;
220
131
  let rewardInfo = null;
221
- // @DEV: Temporarily disable incentives for Arbitrum and Optimism
222
- // const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
223
- const networksWithIncentives = [];
132
+ const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
224
133
  if (networksWithIncentives.includes(network)) {
225
134
  rewardInfo = yield aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
226
135
  rewardInfo = rewardInfo.reduce((all, _market) => {
@@ -498,6 +407,6 @@ export const getAaveV3AccountData = (web3, network, address, extractedState) =>
498
407
  });
499
408
  export const getAaveV3FullPositionData = (web3, network, address, market, mainnetWeb3) => __awaiter(void 0, void 0, void 0, function* () {
500
409
  const marketData = yield getAaveV3MarketData(web3, network, market, mainnetWeb3);
501
- const positionData = yield getAaveV3AccountData(web3, network, address, { assetsData: marketData.assetsData, selectedMarket: market });
410
+ const positionData = yield getAaveV3AccountData(web3, network, address, { assetsData: marketData.assetsData, selectedMarket: market, eModeCategoriesData: marketData.eModeCategoriesData });
502
411
  return positionData;
503
412
  });
@@ -265,16 +265,16 @@ module.exports = {
265
265
  "abi": [{ "inputs": [{ "internalType": "contract IPoolAddressesProvider", "name": "provider", "type": "address" }], "name": "getReservesIncentivesData", "outputs": [{ "components": [{ "internalType": "address", "name": "underlyingAsset", "type": "address" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "uint256", "name": "emissionPerSecond", "type": "uint256" }, { "internalType": "uint256", "name": "incentivesLastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesIndex", "type": "uint256" }, { "internalType": "uint256", "name": "emissionEndTimestamp", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "precision", "type": "uint8" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.RewardInfo[]", "name": "rewardsTokenInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.IncentiveData", "name": "aIncentiveData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "uint256", "name": "emissionPerSecond", "type": "uint256" }, { "internalType": "uint256", "name": "incentivesLastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesIndex", "type": "uint256" }, { "internalType": "uint256", "name": "emissionEndTimestamp", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "precision", "type": "uint8" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.RewardInfo[]", "name": "rewardsTokenInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.IncentiveData", "name": "vIncentiveData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "uint256", "name": "emissionPerSecond", "type": "uint256" }, { "internalType": "uint256", "name": "incentivesLastUpdateTimestamp", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesIndex", "type": "uint256" }, { "internalType": "uint256", "name": "emissionEndTimestamp", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "precision", "type": "uint8" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.RewardInfo[]", "name": "rewardsTokenInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.IncentiveData", "name": "sIncentiveData", "type": "tuple" }], "internalType": "struct IUiIncentiveDataProviderV3.AggregatedReserveIncentiveData[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "contract IPoolAddressesProvider", "name": "provider", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "getUserReservesIncentivesData", "outputs": [{ "components": [{ "internalType": "address", "name": "underlyingAsset", "type": "address" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "uint256", "name": "userUnclaimedRewards", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesUserIndex", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.UserRewardInfo[]", "name": "userRewardsInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.UserIncentiveData", "name": "aTokenIncentivesUserData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "uint256", "name": "userUnclaimedRewards", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesUserIndex", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.UserRewardInfo[]", "name": "userRewardsInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.UserIncentiveData", "name": "vTokenIncentivesUserData", "type": "tuple" }, { "components": [{ "internalType": "address", "name": "tokenAddress", "type": "address" }, { "internalType": "address", "name": "incentiveControllerAddress", "type": "address" }, { "components": [{ "internalType": "string", "name": "rewardTokenSymbol", "type": "string" }, { "internalType": "address", "name": "rewardOracleAddress", "type": "address" }, { "internalType": "address", "name": "rewardTokenAddress", "type": "address" }, { "internalType": "uint256", "name": "userUnclaimedRewards", "type": "uint256" }, { "internalType": "uint256", "name": "tokenIncentivesUserIndex", "type": "uint256" }, { "internalType": "int256", "name": "rewardPriceFeed", "type": "int256" }, { "internalType": "uint8", "name": "priceFeedDecimals", "type": "uint8" }, { "internalType": "uint8", "name": "rewardTokenDecimals", "type": "uint8" }], "internalType": "struct IUiIncentiveDataProviderV3.UserRewardInfo[]", "name": "userRewardsInformation", "type": "tuple[]" }], "internalType": "struct IUiIncentiveDataProviderV3.UserIncentiveData", "name": "sTokenIncentivesUserData", "type": "tuple" }], "internalType": "struct IUiIncentiveDataProviderV3.UserReserveIncentiveData[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }],
266
266
  "networks": {
267
267
  "1": {
268
- "address": "0x162A7AC02f547ad796CA549f757e2b8d1D9b10a6"
268
+ "address": "0x5a40cDe2b76Da2beD545efB3ae15708eE56aAF9c"
269
269
  },
270
270
  "10": {
271
- "address": "0x6F143FE2F7B02424ad3CaD1593D6f36c0Aab69d7"
271
+ "address": "0xc0179321f0825c3e0F59Fe7Ca4E40557b97797a3"
272
272
  },
273
273
  "8453": {
274
- "address": "0xEdD3b4737C1a0011626631a977b91Cf3E944982d"
274
+ "address": "0x5c5228aC8BC1528482514aF3e27E692495148717"
275
275
  },
276
276
  "42161": {
277
- "address": "0xDA67AF3403555Ce0AE3ffC22fDb7354458277358"
277
+ "address": "0xE92cd6164CE7DC68e740765BC1f2a091B6CBc3e4"
278
278
  }
279
279
  }
280
280
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.144",
3
+ "version": "0.0.145",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -12,7 +12,7 @@
12
12
  "dev": "npm run generate-contracts && tsc -p tsconfig.cjs.json --watch",
13
13
  "lint": "eslint src/ --fix",
14
14
  "generate-contracts": "node scripts/generateContracts.js",
15
- "test": "mocha tests/*",
15
+ "test": "mocha tests/aaveV3.js",
16
16
  "test:debugger": "mocha --inspect-brk tests/*",
17
17
  "build-test": "npm run build && mocha tests/*"
18
18
  },
@@ -103,96 +103,7 @@ export const aaveV3EmodeCategoriesMapping = (extractedState: any, usedAssets: Aa
103
103
  };
104
104
 
105
105
  // eslint-disable-next-line no-bitwise
106
- const isEnabledOnBitmap = (bitmap: number, assetId: number) => (((bitmap >> assetId) & 1) !== 0);
107
-
108
- // @DEV: hardcode emodes till they add new emodes structs to all chains
109
- const getAllEmodesHardcoded = (network: NetworkNumber, selectedMarket: AaveVersions) => {
110
- switch (network) {
111
- case NetworkNumber.Eth:
112
- {
113
- switch (selectedMarket) {
114
- case AaveVersions.AaveV3:
115
- return [
116
- {
117
- ltv: 9300,
118
- liquidationThreshold: 9500,
119
- liquidationBonus: 10100,
120
- collateralBitmap: '2952790659',
121
- label: 'ETH correlated',
122
- borrowableBitmap: '2952790659',
123
- },
124
- ];
125
- case AaveVersions.AaveV3Lido:
126
- return [
127
- {
128
- ltv: 9350,
129
- liquidationThreshold: 9550,
130
- liquidationBonus: 10100,
131
- collateralBitmap: '3',
132
- label: 'ETH correlated',
133
- borrowableBitmap: '3',
134
- },
135
- ];
136
- case AaveVersions.AaveV3Etherfi:
137
- return [];
138
- default:
139
- throw new Error('Emode not implemented for this market');
140
- }
141
- }
142
- case NetworkNumber.Arb:
143
- return [
144
- {
145
- ltv: 9300,
146
- liquidationThreshold: 9500,
147
- liquidationBonus: 10100,
148
- collateralBitmap: '4261',
149
- label: 'Stablecoins',
150
- borrowableBitmap: '4261',
151
- },
152
- {
153
- ltv: 9300,
154
- liquidationThreshold: 9500,
155
- liquidationBonus: 10100,
156
- collateralBitmap: '33040',
157
- label: 'ETH correlated',
158
- borrowableBitmap: '33040',
159
- },
160
- ];
161
- case NetworkNumber.Opt:
162
- return [
163
- {
164
- ltv: 9000,
165
- liquidationThreshold: 9300,
166
- liquidationBonus: 10100,
167
- collateralBitmap: '8357',
168
- label: 'Stablecoins',
169
- borrowableBitmap: '8357',
170
- },
171
- {
172
- ltv: 9300,
173
- liquidationThreshold: 9500,
174
- liquidationBonus: 10100,
175
- collateralBitmap: '4624',
176
- label: 'ETH correlated',
177
- borrowableBitmap: '4624',
178
- },
179
- ];
180
- case NetworkNumber.Base:
181
- return [
182
- {
183
- ltv: 9000,
184
- liquidationThreshold: 9300,
185
- liquidationBonus: 10200,
186
- collateralBitmap: '43',
187
- label: 'ETH correlated',
188
- borrowableBitmap: '43',
189
- },
190
- ];
191
- default:
192
- throw new Error('Emode not implemented for this network');
193
- }
194
- };
195
-
106
+ const isEnabledOnBitmap = (bitmap: number, assetId: number) => (BigInt(bitmap) >> BigInt(assetId)) & BigInt(1);
196
107
  export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, market: AaveMarketInfo, defaultWeb3: Web3): Promise<AaveV3MarketData> {
197
108
  const _addresses = market.assets.map(a => getAssetInfo(ethToWeth(a), network).address);
198
109
 
@@ -239,8 +150,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
239
150
  // eslint-disable-next-line prefer-const
240
151
  let [loanInfo, eModesInfo, isBorrowAllowed, multiRes] = await Promise.all([
241
152
  loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call(),
242
- // loanInfoContract.methods.getAllEmodes(marketAddress).call(),
243
- getAllEmodesHardcoded(network, market.value),
153
+ loanInfoContract.methods.getAllEmodes(marketAddress).call(),
244
154
  loanInfoContract.methods.isBorrowAllowed(marketAddress).call(), // Used on L2s check for PriceOracleSentinel (mainnet will always return true)
245
155
  isL2 ? [{ 0: null }, { 0: null }, { 0: null }, { 0: null }, { 0: null }] : multicall(multicallCallsObject, web3, network),
246
156
  ]);
@@ -270,9 +180,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
270
180
  ] = multiRes;
271
181
 
272
182
  let rewardInfo: IUiIncentiveDataProviderV3.AggregatedReserveIncentiveDataStructOutput[] | null = null;
273
- // @DEV: Temporarily disable incentives for Arbitrum and Optimism
274
- // const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
275
- const networksWithIncentives: NetworkNumber[] = [];
183
+ const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
276
184
  if (networksWithIncentives.includes(network)) {
277
185
  rewardInfo = await aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
278
186
  rewardInfo = rewardInfo.reduce((all: any, _market: AaveV3IncentiveData) => {
@@ -671,6 +579,6 @@ export const getAaveV3AccountData = async (web3: Web3, network: NetworkNumber, a
671
579
 
672
580
  export const getAaveV3FullPositionData = async (web3: Web3, network: NetworkNumber, address: string, market: AaveMarketInfo, mainnetWeb3: Web3): Promise<AaveV3PositionData> => {
673
581
  const marketData = await getAaveV3MarketData(web3, network, market, mainnetWeb3);
674
- const positionData = await getAaveV3AccountData(web3, network, address, { assetsData: marketData.assetsData, selectedMarket: market });
582
+ const positionData = await getAaveV3AccountData(web3, network, address, { assetsData: marketData.assetsData, selectedMarket: market, eModeCategoriesData: marketData.eModeCategoriesData });
675
583
  return positionData;
676
584
  };
@@ -266,16 +266,16 @@ module.exports = {
266
266
  "abi": [{"inputs":[{"internalType":"contract IPoolAddressesProvider","name":"provider","type":"address"}],"name":"getReservesIncentivesData","outputs":[{"components":[{"internalType":"address","name":"underlyingAsset","type":"address"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"incentiveControllerAddress","type":"address"},{"components":[{"internalType":"string","name":"rewardTokenSymbol","type":"string"},{"internalType":"address","name":"rewardTokenAddress","type":"address"},{"internalType":"address","name":"rewardOracleAddress","type":"address"},{"internalType":"uint256","name":"emissionPerSecond","type":"uint256"},{"internalType":"uint256","name":"incentivesLastUpdateTimestamp","type":"uint256"},{"internalType":"uint256","name":"tokenIncentivesIndex","type":"uint256"},{"internalType":"uint256","name":"emissionEndTimestamp","type":"uint256"},{"internalType":"int256","name":"rewardPriceFeed","type":"int256"},{"internalType":"uint8","name":"rewardTokenDecimals","type":"uint8"},{"internalType":"uint8","name":"precision","type":"uint8"},{"internalType":"uint8","name":"priceFeedDecimals","type":"uint8"}],"internalType":"struct IUiIncentiveDataProviderV3.RewardInfo[]","name":"rewardsTokenInformation","type":"tuple[]"}],"internalType":"struct IUiIncentiveDataProviderV3.IncentiveData","name":"aIncentiveData","type":"tuple"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"incentiveControllerAddress","type":"address"},{"components":[{"internalType":"string","name":"rewardTokenSymbol","type":"string"},{"internalType":"address","name":"rewardTokenAddress","type":"address"},{"internalType":"address","name":"rewardOracleAddress","type":"address"},{"internalType":"uint256","name":"emissionPerSecond","type":"uint256"},{"internalType":"uint256","name":"incentivesLastUpdateTimestamp","type":"uint256"},{"internalType":"uint256","name":"tokenIncentivesIndex","type":"uint256"},{"internalType":"uint256","name":"emissionEndTimestamp","type":"uint256"},{"internalType":"int256","name":"rewardPriceFeed","type":"int256"},{"internalType":"uint8","name":"rewardTokenDecimals","type":"uint8"},{"internalType":"uint8","name":"precision","type":"uint8"},{"internalType":"uint8","name":"priceFeedDecimals","type":"uint8"}],"internalType":"struct IUiIncentiveDataProviderV3.RewardInfo[]","name":"rewardsTokenInformation","type":"tuple[]"}],"internalType":"struct IUiIncentiveDataProviderV3.IncentiveData","name":"vIncentiveData","type":"tuple"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"incentiveControllerAddress","type":"address"},{"components":[{"internalType":"string","name":"rewardTokenSymbol","type":"string"},{"internalType":"address","name":"rewardTokenAddress","type":"address"},{"internalType":"address","name":"rewardOracleAddress","type":"address"},{"internalType":"uint256","name":"emissionPerSecond","type":"uint256"},{"internalType":"uint256","name":"incentivesLastUpdateTimestamp","type":"uint256"},{"internalType":"uint256","name":"tokenIncentivesIndex","type":"uint256"},{"internalType":"uint256","name":"emissionEndTimestamp","type":"uint256"},{"internalType":"int256","name":"rewardPriceFeed","type":"int256"},{"internalType":"uint8","name":"rewardTokenDecimals","type":"uint8"},{"internalType":"uint8","name":"precision","type":"uint8"},{"internalType":"uint8","name":"priceFeedDecimals","type":"uint8"}],"internalType":"struct IUiIncentiveDataProviderV3.RewardInfo[]","name":"rewardsTokenInformation","type":"tuple[]"}],"internalType":"struct IUiIncentiveDataProviderV3.IncentiveData","name":"sIncentiveData","type":"tuple"}],"internalType":"struct IUiIncentiveDataProviderV3.AggregatedReserveIncentiveData[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IPoolAddressesProvider","name":"provider","type":"address"},{"internalType":"address","name":"user","type":"address"}],"name":"getUserReservesIncentivesData","outputs":[{"components":[{"internalType":"address","name":"underlyingAsset","type":"address"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"incentiveControllerAddress","type":"address"},{"components":[{"internalType":"string","name":"rewardTokenSymbol","type":"string"},{"internalType":"address","name":"rewardOracleAddress","type":"address"},{"internalType":"address","name":"rewardTokenAddress","type":"address"},{"internalType":"uint256","name":"userUnclaimedRewards","type":"uint256"},{"internalType":"uint256","name":"tokenIncentivesUserIndex","type":"uint256"},{"internalType":"int256","name":"rewardPriceFeed","type":"int256"},{"internalType":"uint8","name":"priceFeedDecimals","type":"uint8"},{"internalType":"uint8","name":"rewardTokenDecimals","type":"uint8"}],"internalType":"struct IUiIncentiveDataProviderV3.UserRewardInfo[]","name":"userRewardsInformation","type":"tuple[]"}],"internalType":"struct IUiIncentiveDataProviderV3.UserIncentiveData","name":"aTokenIncentivesUserData","type":"tuple"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"incentiveControllerAddress","type":"address"},{"components":[{"internalType":"string","name":"rewardTokenSymbol","type":"string"},{"internalType":"address","name":"rewardOracleAddress","type":"address"},{"internalType":"address","name":"rewardTokenAddress","type":"address"},{"internalType":"uint256","name":"userUnclaimedRewards","type":"uint256"},{"internalType":"uint256","name":"tokenIncentivesUserIndex","type":"uint256"},{"internalType":"int256","name":"rewardPriceFeed","type":"int256"},{"internalType":"uint8","name":"priceFeedDecimals","type":"uint8"},{"internalType":"uint8","name":"rewardTokenDecimals","type":"uint8"}],"internalType":"struct IUiIncentiveDataProviderV3.UserRewardInfo[]","name":"userRewardsInformation","type":"tuple[]"}],"internalType":"struct IUiIncentiveDataProviderV3.UserIncentiveData","name":"vTokenIncentivesUserData","type":"tuple"},{"components":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"address","name":"incentiveControllerAddress","type":"address"},{"components":[{"internalType":"string","name":"rewardTokenSymbol","type":"string"},{"internalType":"address","name":"rewardOracleAddress","type":"address"},{"internalType":"address","name":"rewardTokenAddress","type":"address"},{"internalType":"uint256","name":"userUnclaimedRewards","type":"uint256"},{"internalType":"uint256","name":"tokenIncentivesUserIndex","type":"uint256"},{"internalType":"int256","name":"rewardPriceFeed","type":"int256"},{"internalType":"uint8","name":"priceFeedDecimals","type":"uint8"},{"internalType":"uint8","name":"rewardTokenDecimals","type":"uint8"}],"internalType":"struct IUiIncentiveDataProviderV3.UserRewardInfo[]","name":"userRewardsInformation","type":"tuple[]"}],"internalType":"struct IUiIncentiveDataProviderV3.UserIncentiveData","name":"sTokenIncentivesUserData","type":"tuple"}],"internalType":"struct IUiIncentiveDataProviderV3.UserReserveIncentiveData[]","name":"","type":"tuple[]"}],"stateMutability":"view","type":"function"}],
267
267
  "networks": {
268
268
  "1": {
269
- "address": "0x162A7AC02f547ad796CA549f757e2b8d1D9b10a6"
269
+ "address": "0x5a40cDe2b76Da2beD545efB3ae15708eE56aAF9c"
270
270
  },
271
271
  "10": {
272
- "address": "0x6F143FE2F7B02424ad3CaD1593D6f36c0Aab69d7"
272
+ "address": "0xc0179321f0825c3e0F59Fe7Ca4E40557b97797a3"
273
273
  },
274
274
  "8453": {
275
- "address": "0xEdD3b4737C1a0011626631a977b91Cf3E944982d"
275
+ "address": "0x5c5228aC8BC1528482514aF3e27E692495148717"
276
276
  },
277
277
  "42161": {
278
- "address": "0xDA67AF3403555Ce0AE3ffC22fDb7354458277358"
278
+ "address": "0xE92cd6164CE7DC68e740765BC1f2a091B6CBc3e4"
279
279
  }
280
280
  }
281
281
  },