@defisaver/positions-sdk 0.0.142 → 0.0.144
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/aaveV3/index.js +38 -15
- package/esm/aaveV3/index.js +36 -13
- package/package.json +1 -1
- package/src/aaveV3/index.ts +36 -13
package/cjs/aaveV3/index.js
CHANGED
|
@@ -17,13 +17,14 @@ 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");
|
|
20
21
|
const common_1 = require("../types/common");
|
|
21
22
|
const staking_1 = require("../staking");
|
|
22
23
|
const multicall_1 = require("../multicall");
|
|
23
24
|
const assets_1 = require("../assets");
|
|
24
25
|
const moneymarket_1 = require("../moneymarket");
|
|
25
26
|
const aaveHelpers_1 = require("../helpers/aaveHelpers");
|
|
26
|
-
const
|
|
27
|
+
const aave_2 = require("../markets/aave");
|
|
27
28
|
const test = (web3, network) => {
|
|
28
29
|
const contract = (0, contracts_1.AaveV3ViewContract)(web3, 1);
|
|
29
30
|
return contract.methods.AAVE_REFERRAL_CODE().call();
|
|
@@ -75,19 +76,39 @@ exports.aaveV3EmodeCategoriesMapping = aaveV3EmodeCategoriesMapping;
|
|
|
75
76
|
// eslint-disable-next-line no-bitwise
|
|
76
77
|
const isEnabledOnBitmap = (bitmap, assetId) => (((bitmap >> assetId) & 1) !== 0);
|
|
77
78
|
// @DEV: hardcode emodes till they add new emodes structs to all chains
|
|
78
|
-
const getAllEmodesHardcoded = (network) => {
|
|
79
|
+
const getAllEmodesHardcoded = (network, selectedMarket) => {
|
|
79
80
|
switch (network) {
|
|
80
81
|
case common_1.NetworkNumber.Eth:
|
|
81
|
-
|
|
82
|
-
{
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
+
}
|
|
91
112
|
case common_1.NetworkNumber.Arb:
|
|
92
113
|
return [
|
|
93
114
|
{
|
|
@@ -183,7 +204,7 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
183
204
|
let [loanInfo, eModesInfo, isBorrowAllowed, multiRes] = yield Promise.all([
|
|
184
205
|
loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call(),
|
|
185
206
|
// loanInfoContract.methods.getAllEmodes(marketAddress).call(),
|
|
186
|
-
getAllEmodesHardcoded(network),
|
|
207
|
+
getAllEmodesHardcoded(network, market.value),
|
|
187
208
|
loanInfoContract.methods.isBorrowAllowed(marketAddress).call(),
|
|
188
209
|
isL2 ? [{ 0: null }, { 0: null }, { 0: null }, { 0: null }, { 0: null }] : (0, multicall_1.multicall)(multicallCallsObject, web3, network),
|
|
189
210
|
]);
|
|
@@ -206,7 +227,9 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
206
227
|
}
|
|
207
228
|
const [{ 0: ghoDiscountedPerDiscountToken }, { 0: discountRate }, { 0: minDiscountTokenBalance }, { 0: minGhoBalanceForDiscount }, { 0: facilitatorsList },] = multiRes;
|
|
208
229
|
let rewardInfo = null;
|
|
209
|
-
|
|
230
|
+
// @DEV: Temporarily disable incentives for Arbitrum and Optimism
|
|
231
|
+
// const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
|
|
232
|
+
const networksWithIncentives = [];
|
|
210
233
|
if (networksWithIncentives.includes(network)) {
|
|
211
234
|
rewardInfo = yield aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
|
|
212
235
|
rewardInfo = rewardInfo.reduce((all, _market) => {
|
|
@@ -351,7 +374,7 @@ const getAaveV3AccountBalances = (web3, network, block, addressMapping, address)
|
|
|
351
374
|
return balances;
|
|
352
375
|
}
|
|
353
376
|
const loanInfoContract = (0, contracts_1.AaveV3ViewContract)(web3, network, block);
|
|
354
|
-
const market = (0,
|
|
377
|
+
const market = (0, aave_2.AAVE_V3)(network);
|
|
355
378
|
const marketAddress = market.providerAddress;
|
|
356
379
|
// @ts-ignore
|
|
357
380
|
const protocolDataProviderContract = (0, contracts_1.createContractWrapper)(web3, network, market.protocolData, market.protocolDataAddress);
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -11,6 +11,7 @@ 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';
|
|
14
15
|
import { NetworkNumber, } from '../types/common';
|
|
15
16
|
import { getStakingApy, STAKING_ASSETS } from '../staking';
|
|
16
17
|
import { multicall } from '../multicall';
|
|
@@ -66,19 +67,39 @@ export const aaveV3EmodeCategoriesMapping = (extractedState, usedAssets) => {
|
|
|
66
67
|
// eslint-disable-next-line no-bitwise
|
|
67
68
|
const isEnabledOnBitmap = (bitmap, assetId) => (((bitmap >> assetId) & 1) !== 0);
|
|
68
69
|
// @DEV: hardcode emodes till they add new emodes structs to all chains
|
|
69
|
-
const getAllEmodesHardcoded = (network) => {
|
|
70
|
+
const getAllEmodesHardcoded = (network, selectedMarket) => {
|
|
70
71
|
switch (network) {
|
|
71
72
|
case NetworkNumber.Eth:
|
|
72
|
-
|
|
73
|
-
{
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
+
}
|
|
82
103
|
case NetworkNumber.Arb:
|
|
83
104
|
return [
|
|
84
105
|
{
|
|
@@ -174,7 +195,7 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
174
195
|
let [loanInfo, eModesInfo, isBorrowAllowed, multiRes] = yield Promise.all([
|
|
175
196
|
loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call(),
|
|
176
197
|
// loanInfoContract.methods.getAllEmodes(marketAddress).call(),
|
|
177
|
-
getAllEmodesHardcoded(network),
|
|
198
|
+
getAllEmodesHardcoded(network, market.value),
|
|
178
199
|
loanInfoContract.methods.isBorrowAllowed(marketAddress).call(),
|
|
179
200
|
isL2 ? [{ 0: null }, { 0: null }, { 0: null }, { 0: null }, { 0: null }] : multicall(multicallCallsObject, web3, network),
|
|
180
201
|
]);
|
|
@@ -197,7 +218,9 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
197
218
|
}
|
|
198
219
|
const [{ 0: ghoDiscountedPerDiscountToken }, { 0: discountRate }, { 0: minDiscountTokenBalance }, { 0: minGhoBalanceForDiscount }, { 0: facilitatorsList },] = multiRes;
|
|
199
220
|
let rewardInfo = null;
|
|
200
|
-
|
|
221
|
+
// @DEV: Temporarily disable incentives for Arbitrum and Optimism
|
|
222
|
+
// const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
|
|
223
|
+
const networksWithIncentives = [];
|
|
201
224
|
if (networksWithIncentives.includes(network)) {
|
|
202
225
|
rewardInfo = yield aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
|
|
203
226
|
rewardInfo = rewardInfo.reduce((all, _market) => {
|
package/package.json
CHANGED
package/src/aaveV3/index.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
AaveV3PositionData,
|
|
22
22
|
AaveV3UsedAsset,
|
|
23
23
|
AaveV3UsedAssets,
|
|
24
|
+
AaveVersions,
|
|
24
25
|
EModeCategoriesData,
|
|
25
26
|
EModeCategoryData,
|
|
26
27
|
EModeCategoryDataMapping,
|
|
@@ -105,19 +106,39 @@ export const aaveV3EmodeCategoriesMapping = (extractedState: any, usedAssets: Aa
|
|
|
105
106
|
const isEnabledOnBitmap = (bitmap: number, assetId: number) => (((bitmap >> assetId) & 1) !== 0);
|
|
106
107
|
|
|
107
108
|
// @DEV: hardcode emodes till they add new emodes structs to all chains
|
|
108
|
-
const getAllEmodesHardcoded = (network: NetworkNumber) => {
|
|
109
|
+
const getAllEmodesHardcoded = (network: NetworkNumber, selectedMarket: AaveVersions) => {
|
|
109
110
|
switch (network) {
|
|
110
111
|
case NetworkNumber.Eth:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
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
|
+
}
|
|
121
142
|
case NetworkNumber.Arb:
|
|
122
143
|
return [
|
|
123
144
|
{
|
|
@@ -219,7 +240,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
219
240
|
let [loanInfo, eModesInfo, isBorrowAllowed, multiRes] = await Promise.all([
|
|
220
241
|
loanInfoContract.methods.getFullTokensInfo(marketAddress, _addresses).call(),
|
|
221
242
|
// loanInfoContract.methods.getAllEmodes(marketAddress).call(),
|
|
222
|
-
getAllEmodesHardcoded(network),
|
|
243
|
+
getAllEmodesHardcoded(network, market.value),
|
|
223
244
|
loanInfoContract.methods.isBorrowAllowed(marketAddress).call(), // Used on L2s check for PriceOracleSentinel (mainnet will always return true)
|
|
224
245
|
isL2 ? [{ 0: null }, { 0: null }, { 0: null }, { 0: null }, { 0: null }] : multicall(multicallCallsObject, web3, network),
|
|
225
246
|
]);
|
|
@@ -249,7 +270,9 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
249
270
|
] = multiRes;
|
|
250
271
|
|
|
251
272
|
let rewardInfo: IUiIncentiveDataProviderV3.AggregatedReserveIncentiveDataStructOutput[] | null = null;
|
|
252
|
-
|
|
273
|
+
// @DEV: Temporarily disable incentives for Arbitrum and Optimism
|
|
274
|
+
// const networksWithIncentives = [NetworkNumber.Arb, NetworkNumber.Opt];
|
|
275
|
+
const networksWithIncentives: NetworkNumber[] = [];
|
|
253
276
|
if (networksWithIncentives.includes(network)) {
|
|
254
277
|
rewardInfo = await aaveIncentivesContract.methods.getReservesIncentivesData(marketAddress).call();
|
|
255
278
|
rewardInfo = rewardInfo.reduce((all: any, _market: AaveV3IncentiveData) => {
|