@defisaver/positions-sdk 0.0.6 → 0.0.8
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 +1 -3
- package/cjs/chickenBonds/index.js +2 -1
- package/cjs/helpers/aaveHelpers/index.js +14 -2
- package/cjs/helpers/chickenBondsHelpers/index.d.ts +1 -0
- package/cjs/helpers/chickenBondsHelpers/index.js +14 -1
- package/cjs/helpers/compoundHelpers/index.js +2 -2
- package/cjs/types/chickenBonds.d.ts +1 -0
- package/esm/aaveV3/index.js +3 -5
- package/esm/chickenBonds/index.js +3 -2
- package/esm/helpers/aaveHelpers/index.js +14 -2
- package/esm/helpers/chickenBondsHelpers/index.d.ts +1 -0
- package/esm/helpers/chickenBondsHelpers/index.js +12 -0
- package/esm/helpers/compoundHelpers/index.js +2 -2
- package/esm/types/chickenBonds.d.ts +1 -0
- package/package.json +1 -1
- package/src/aaveV3/index.ts +16 -4
- package/src/chickenBonds/index.ts +3 -2
- package/src/helpers/aaveHelpers/index.ts +16 -2
- package/src/helpers/chickenBondsHelpers/index.ts +11 -0
- package/src/helpers/compoundHelpers/index.ts +4 -4
- package/src/types/chickenBonds.ts +1 -0
package/cjs/aaveV3/index.js
CHANGED
|
@@ -163,14 +163,12 @@ function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
163
163
|
liquidationRatio: new decimal_js_1.default(tokenMarket.liquidationThreshold).div(10000).toString(),
|
|
164
164
|
collateralFactor: new decimal_js_1.default(tokenMarket.ltv).div(10000).toString(),
|
|
165
165
|
priceSource: tokenMarket.priceSource,
|
|
166
|
-
} }));
|
|
166
|
+
}, aTokenAddress: tokenMarket.aTokenAddress }));
|
|
167
167
|
})));
|
|
168
168
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
169
169
|
/* eslint-disable no-param-reassign */
|
|
170
170
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
171
171
|
if (['wstETH', 'cbETH', 'rETH', 'sDAI'].includes(_market.symbol)) {
|
|
172
|
-
if (!(0, utils_1.isLayer2Network)(network) && _market.symbol === 'cbETH')
|
|
173
|
-
return;
|
|
174
172
|
_market.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(_market.symbol, defaultWeb3);
|
|
175
173
|
_market.incentiveSupplyToken = _market.symbol;
|
|
176
174
|
}
|
|
@@ -90,7 +90,7 @@ const fetchCBondsForUser = (web3, network, address) => __awaiter(void 0, void 0,
|
|
|
90
90
|
return bonds.map(({ bondID, accruedBLUSD, claimedBLUSD, endTime, lusdAmount, maxAmountBLUSD, startTime, status, tokenURI, }) => ({
|
|
91
91
|
bondId: bondID,
|
|
92
92
|
status,
|
|
93
|
-
|
|
93
|
+
tokenURI: (0, chickenBondsHelpers_1.decodeTokenURIToSvg)(tokenURI),
|
|
94
94
|
startTime: new Date(+startTime * 1000),
|
|
95
95
|
endTime: new Date(+endTime * 1000),
|
|
96
96
|
accruedBLUSD: (0, tokens_1.assetAmountInEth)(accruedBLUSD, 'bLUSD'),
|
|
@@ -112,6 +112,7 @@ const fetchCBondForId = (web3, network, bondId) => __awaiter(void 0, void 0, voi
|
|
|
112
112
|
claimedBLUSD: (0, tokens_1.assetAmountInEth)(bond.claimedBLUSD, 'bLUSD'),
|
|
113
113
|
lusdAmount: (0, tokens_1.assetAmountInEth)(bond.lusdAmount, 'LUSD'),
|
|
114
114
|
maxAmountBLUSD: (0, tokens_1.assetAmountInEth)(bond.maxAmountBLUSD, 'bLUSD'),
|
|
115
|
+
tokenURI: (0, chickenBondsHelpers_1.decodeTokenURIToSvg)(bond.tokenURI),
|
|
115
116
|
};
|
|
116
117
|
});
|
|
117
118
|
exports.fetchCBondForId = fetchCBondForId;
|
|
@@ -77,8 +77,20 @@ const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
77
77
|
const payload = {};
|
|
78
78
|
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
79
79
|
payload.suppliedCollateralUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
80
|
-
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) =>
|
|
81
|
-
|
|
80
|
+
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
81
|
+
const suppliedUsdAmount = (0, exports.isMorphoAaveV3)(data)
|
|
82
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
83
|
+
? new decimal_js_1.default(suppliedUsd).minus(new decimal_js_1.default(suppliedUsd).div(100).times(0.1)).toString()
|
|
84
|
+
: suppliedUsd;
|
|
85
|
+
return new decimal_js_1.default(suppliedUsdAmount).mul((0, exports.aaveAnyGetEmodeMutableProps)(data, symbol).collateralFactor);
|
|
86
|
+
});
|
|
87
|
+
payload.liquidationLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
88
|
+
const suppliedUsdAmount = (0, exports.isMorphoAaveV3)(data)
|
|
89
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
90
|
+
? new decimal_js_1.default(suppliedUsd).minus(new decimal_js_1.default(suppliedUsd).div(100).times(0.1)).toString()
|
|
91
|
+
: suppliedUsd;
|
|
92
|
+
return new decimal_js_1.default(suppliedUsdAmount).mul((0, exports.aaveAnyGetEmodeMutableProps)(data, symbol).liquidationRatio);
|
|
93
|
+
});
|
|
82
94
|
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
83
95
|
const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
84
96
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const calcCBondsBLUSDFloorPrice: (bLUSDSupply: string, totalReserveLUSD: string) => string;
|
|
2
2
|
export declare const calcAverageBondAgeMs: (totalWeightedStartTimes: string, totalPendingLusd: string) => number;
|
|
3
|
+
export declare const decodeTokenURIToSvg: (tokenURI: string) => string;
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.calcAverageBondAgeMs = exports.calcCBondsBLUSDFloorPrice = void 0;
|
|
6
|
+
exports.decodeTokenURIToSvg = exports.calcAverageBondAgeMs = exports.calcCBondsBLUSDFloorPrice = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const calcCBondsBLUSDFloorPrice = (bLUSDSupply, totalReserveLUSD) => {
|
|
9
9
|
if (new decimal_js_1.default(bLUSDSupply).eq(0))
|
|
@@ -17,3 +17,16 @@ const calcAverageBondAgeMs = (totalWeightedStartTimes, totalPendingLusd) => {
|
|
|
17
17
|
return Date.now() - averageStartTimeMs;
|
|
18
18
|
};
|
|
19
19
|
exports.calcAverageBondAgeMs = calcAverageBondAgeMs;
|
|
20
|
+
const decodeTokenURIToSvg = (tokenURI) => {
|
|
21
|
+
var _a;
|
|
22
|
+
try {
|
|
23
|
+
const dataStartIndex = tokenURI.indexOf('base64,') + 'base64,'.length;
|
|
24
|
+
const json = atob(tokenURI.slice(dataStartIndex));
|
|
25
|
+
return (_a = JSON.parse(json)) === null || _a === void 0 ? void 0 : _a.image;
|
|
26
|
+
}
|
|
27
|
+
catch (e) {
|
|
28
|
+
console.error(e);
|
|
29
|
+
return 'Error parsing NFT image';
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
exports.decodeTokenURIToSvg = decodeTokenURIToSvg;
|
|
@@ -26,7 +26,7 @@ const formatMarketData = (data, network, baseAssetPrice) => {
|
|
|
26
26
|
const assetInfo = (0, tokens_1.getAssetInfoByAddress)(data.tokenAddr, network);
|
|
27
27
|
const isWETH = assetInfo.symbol === 'WETH';
|
|
28
28
|
const price = (0, utils_1.getEthAmountForDecimals)(data.price, 8);
|
|
29
|
-
return (Object.assign(Object.assign({}, data), {
|
|
29
|
+
return (Object.assign(Object.assign({}, data), { priceInBaseAsset: (0, utils_1.getEthAmountForDecimals)(data.price, 8), price: new decimal_js_1.default(price).mul(baseAssetPrice).toString(), collateralFactor: (0, utils_1.getEthAmountForDecimals)(data.borrowCollateralFactor, 18), liquidationRatio: (0, utils_1.getEthAmountForDecimals)(data.liquidateCollateralFactor, 18), supplyCap: (0, utils_1.getEthAmountForDecimals)(data.supplyCap, assetInfo.decimals), totalSupply: (0, utils_1.getEthAmountForDecimals)(data.totalSupply, assetInfo.decimals), symbol: isWETH ? 'ETH' : assetInfo.symbol, supplyRate: '0', borrowRate: '0', canBeBorrowed: false, canBeSupplied: true }));
|
|
30
30
|
};
|
|
31
31
|
exports.formatMarketData = formatMarketData;
|
|
32
32
|
// TODO: maybe not hardcode decimals
|
|
@@ -38,7 +38,7 @@ const formatBaseData = (data, network, baseAssetPrice) => {
|
|
|
38
38
|
.toString()), borrowRate: (0, moneymarket_1.aprToApy)(new decimal_js_1.default(data.borrowRate).div(1e18).mul(constants_1.SECONDS_PER_YEAR).mul(100)
|
|
39
39
|
.toString()), utilization: (0, utils_1.getEthAmountForDecimals)(data.utilization, 16), // utilization is totalSupply/totalBorrow in 1e18, but we need % so when we mul with 100 it's 16 decimals
|
|
40
40
|
totalSupply,
|
|
41
|
-
totalBorrow, marketLiquidity: new decimal_js_1.default(totalSupply).minus(totalBorrow).toString(), symbol: (0, utils_1.wethToEth)(assetInfo.symbol),
|
|
41
|
+
totalBorrow, marketLiquidity: new decimal_js_1.default(totalSupply).minus(totalBorrow).toString(), symbol: (0, utils_1.wethToEth)(assetInfo.symbol), priceInBaseAsset: (0, utils_1.getEthAmountForDecimals)(data.price, 8), price: baseAssetPrice, collateralFactor: '0', liquidationRatio: '0', canBeBorrowed: true, canBeSupplied: true, supplyCap: '0', rewardSupplySpeed: (0, utils_1.getEthAmountForDecimals)(data.baseTrackingSupplyRewardsSpeed, 15), rewardBorrowSpeed: (0, utils_1.getEthAmountForDecimals)(data.baseTrackingBorrowRewardsSpeed, 15), minDebt: (0, utils_1.getEthAmountForDecimals)(data.baseBorrowMin, assetInfo.decimals), isBase: true }));
|
|
42
42
|
};
|
|
43
43
|
exports.formatBaseData = formatBaseData;
|
|
44
44
|
const getIncentiveApys = (baseData, compPrice) => {
|
package/esm/aaveV3/index.js
CHANGED
|
@@ -9,14 +9,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
11
|
import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tokens';
|
|
12
|
-
import { AaveIncentiveDataProviderV3Contract, AaveV3ViewContract,
|
|
12
|
+
import { AaveIncentiveDataProviderV3Contract, AaveV3ViewContract, getConfigContractAbi, getConfigContractAddress, GhoTokenContract, } from '../contracts';
|
|
13
13
|
import { addToObjectIf, ethToWeth, getAbiItem, isLayer2Network, wethToEth, } from '../services/utils';
|
|
14
14
|
import { NetworkNumber, } from '../types/common';
|
|
15
15
|
import { calculateNetApy, getStakingApy } from '../staking';
|
|
16
16
|
import { multicall } from '../multicall';
|
|
17
17
|
import { getAssetsBalances } from '../assets';
|
|
18
18
|
import { calculateBorrowingAssetLimit } from '../moneymarket';
|
|
19
|
-
import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode } from '../helpers/aaveHelpers';
|
|
19
|
+
import { aaveAnyGetAggregatedPositionData, aaveV3IsInIsolationMode, aaveV3IsInSiloedMode, } from '../helpers/aaveHelpers';
|
|
20
20
|
import { AAVE_V3 } from '../markets/aave';
|
|
21
21
|
export const test = (web3, network) => {
|
|
22
22
|
const contract = AaveV3ViewContract(web3, 1);
|
|
@@ -154,14 +154,12 @@ export function getAaveV3MarketData(web3, network, market, defaultWeb3) {
|
|
|
154
154
|
liquidationRatio: new Dec(tokenMarket.liquidationThreshold).div(10000).toString(),
|
|
155
155
|
collateralFactor: new Dec(tokenMarket.ltv).div(10000).toString(),
|
|
156
156
|
priceSource: tokenMarket.priceSource,
|
|
157
|
-
} }));
|
|
157
|
+
}, aTokenAddress: tokenMarket.aTokenAddress }));
|
|
158
158
|
})));
|
|
159
159
|
yield Promise.all(assetsData.map((_market) => __awaiter(this, void 0, void 0, function* () {
|
|
160
160
|
/* eslint-disable no-param-reassign */
|
|
161
161
|
const rewardForMarket = rewardInfo === null || rewardInfo === void 0 ? void 0 : rewardInfo[_market.underlyingTokenAddress];
|
|
162
162
|
if (['wstETH', 'cbETH', 'rETH', 'sDAI'].includes(_market.symbol)) {
|
|
163
|
-
if (!isLayer2Network(network) && _market.symbol === 'cbETH')
|
|
164
|
-
return;
|
|
165
163
|
_market.incentiveSupplyApy = yield getStakingApy(_market.symbol, defaultWeb3);
|
|
166
164
|
_market.incentiveSupplyToken = _market.symbol;
|
|
167
165
|
}
|
|
@@ -11,7 +11,7 @@ import Dec from 'decimal.js';
|
|
|
11
11
|
import { assetAmountInEth, getAssetInfo } from '@defisaver/tokens';
|
|
12
12
|
import { ChickenBondsManagerContract, ChickenBondsViewContract } from '../contracts';
|
|
13
13
|
import { multicall } from '../multicall';
|
|
14
|
-
import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice } from '../helpers/chickenBondsHelpers';
|
|
14
|
+
import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice, decodeTokenURIToSvg } from '../helpers/chickenBondsHelpers';
|
|
15
15
|
export const getChickenBondsAccountBalances = (web3, network, block, addressMapping, bondId) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
16
|
const viewContract = ChickenBondsViewContract(web3, network, block);
|
|
17
17
|
const fullBondInfo = yield viewContract.methods.getBondFullInfo(bondId).call({}, block);
|
|
@@ -82,7 +82,7 @@ export const fetchCBondsForUser = (web3, network, address) => __awaiter(void 0,
|
|
|
82
82
|
return bonds.map(({ bondID, accruedBLUSD, claimedBLUSD, endTime, lusdAmount, maxAmountBLUSD, startTime, status, tokenURI, }) => ({
|
|
83
83
|
bondId: bondID,
|
|
84
84
|
status,
|
|
85
|
-
|
|
85
|
+
tokenURI: decodeTokenURIToSvg(tokenURI),
|
|
86
86
|
startTime: new Date(+startTime * 1000),
|
|
87
87
|
endTime: new Date(+endTime * 1000),
|
|
88
88
|
accruedBLUSD: assetAmountInEth(accruedBLUSD, 'bLUSD'),
|
|
@@ -103,5 +103,6 @@ export const fetchCBondForId = (web3, network, bondId) => __awaiter(void 0, void
|
|
|
103
103
|
claimedBLUSD: assetAmountInEth(bond.claimedBLUSD, 'bLUSD'),
|
|
104
104
|
lusdAmount: assetAmountInEth(bond.lusdAmount, 'LUSD'),
|
|
105
105
|
maxAmountBLUSD: assetAmountInEth(bond.maxAmountBLUSD, 'bLUSD'),
|
|
106
|
+
tokenURI: decodeTokenURIToSvg(bond.tokenURI),
|
|
106
107
|
};
|
|
107
108
|
});
|
|
@@ -61,8 +61,20 @@ export const aaveAnyGetAggregatedPositionData = (_a) => {
|
|
|
61
61
|
const payload = {};
|
|
62
62
|
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
63
63
|
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
64
|
-
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) =>
|
|
65
|
-
|
|
64
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
65
|
+
const suppliedUsdAmount = isMorphoAaveV3(data)
|
|
66
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
67
|
+
? new Dec(suppliedUsd).minus(new Dec(suppliedUsd).div(100).times(0.1)).toString()
|
|
68
|
+
: suppliedUsd;
|
|
69
|
+
return new Dec(suppliedUsdAmount).mul(aaveAnyGetEmodeMutableProps(data, symbol).collateralFactor);
|
|
70
|
+
});
|
|
71
|
+
payload.liquidationLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
72
|
+
const suppliedUsdAmount = isMorphoAaveV3(data)
|
|
73
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
74
|
+
? new Dec(suppliedUsd).minus(new Dec(suppliedUsd).div(100).times(0.1)).toString()
|
|
75
|
+
: suppliedUsd;
|
|
76
|
+
return new Dec(suppliedUsdAmount).mul(aaveAnyGetEmodeMutableProps(data, symbol).liquidationRatio);
|
|
77
|
+
});
|
|
66
78
|
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
67
79
|
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
68
80
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
export declare const calcCBondsBLUSDFloorPrice: (bLUSDSupply: string, totalReserveLUSD: string) => string;
|
|
2
2
|
export declare const calcAverageBondAgeMs: (totalWeightedStartTimes: string, totalPendingLusd: string) => number;
|
|
3
|
+
export declare const decodeTokenURIToSvg: (tokenURI: string) => string;
|
|
@@ -9,3 +9,15 @@ export const calcAverageBondAgeMs = (totalWeightedStartTimes, totalPendingLusd)
|
|
|
9
9
|
.toNumber();
|
|
10
10
|
return Date.now() - averageStartTimeMs;
|
|
11
11
|
};
|
|
12
|
+
export const decodeTokenURIToSvg = (tokenURI) => {
|
|
13
|
+
var _a;
|
|
14
|
+
try {
|
|
15
|
+
const dataStartIndex = tokenURI.indexOf('base64,') + 'base64,'.length;
|
|
16
|
+
const json = atob(tokenURI.slice(dataStartIndex));
|
|
17
|
+
return (_a = JSON.parse(json)) === null || _a === void 0 ? void 0 : _a.image;
|
|
18
|
+
}
|
|
19
|
+
catch (e) {
|
|
20
|
+
console.error(e);
|
|
21
|
+
return 'Error parsing NFT image';
|
|
22
|
+
}
|
|
23
|
+
};
|
|
@@ -20,7 +20,7 @@ export const formatMarketData = (data, network, baseAssetPrice) => {
|
|
|
20
20
|
const assetInfo = getAssetInfoByAddress(data.tokenAddr, network);
|
|
21
21
|
const isWETH = assetInfo.symbol === 'WETH';
|
|
22
22
|
const price = getEthAmountForDecimals(data.price, 8);
|
|
23
|
-
return (Object.assign(Object.assign({}, data), {
|
|
23
|
+
return (Object.assign(Object.assign({}, data), { priceInBaseAsset: getEthAmountForDecimals(data.price, 8), price: new Dec(price).mul(baseAssetPrice).toString(), collateralFactor: getEthAmountForDecimals(data.borrowCollateralFactor, 18), liquidationRatio: getEthAmountForDecimals(data.liquidateCollateralFactor, 18), supplyCap: getEthAmountForDecimals(data.supplyCap, assetInfo.decimals), totalSupply: getEthAmountForDecimals(data.totalSupply, assetInfo.decimals), symbol: isWETH ? 'ETH' : assetInfo.symbol, supplyRate: '0', borrowRate: '0', canBeBorrowed: false, canBeSupplied: true }));
|
|
24
24
|
};
|
|
25
25
|
// TODO: maybe not hardcode decimals
|
|
26
26
|
export const formatBaseData = (data, network, baseAssetPrice) => {
|
|
@@ -31,7 +31,7 @@ export const formatBaseData = (data, network, baseAssetPrice) => {
|
|
|
31
31
|
.toString()), borrowRate: aprToApy(new Dec(data.borrowRate).div(1e18).mul(SECONDS_PER_YEAR).mul(100)
|
|
32
32
|
.toString()), utilization: getEthAmountForDecimals(data.utilization, 16), // utilization is totalSupply/totalBorrow in 1e18, but we need % so when we mul with 100 it's 16 decimals
|
|
33
33
|
totalSupply,
|
|
34
|
-
totalBorrow, marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(), symbol: wethToEth(assetInfo.symbol),
|
|
34
|
+
totalBorrow, marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(), symbol: wethToEth(assetInfo.symbol), priceInBaseAsset: getEthAmountForDecimals(data.price, 8), price: baseAssetPrice, collateralFactor: '0', liquidationRatio: '0', canBeBorrowed: true, canBeSupplied: true, supplyCap: '0', rewardSupplySpeed: getEthAmountForDecimals(data.baseTrackingSupplyRewardsSpeed, 15), rewardBorrowSpeed: getEthAmountForDecimals(data.baseTrackingBorrowRewardsSpeed, 15), minDebt: getEthAmountForDecimals(data.baseBorrowMin, assetInfo.decimals), isBase: true }));
|
|
35
35
|
};
|
|
36
36
|
export const getIncentiveApys = (baseData, compPrice) => {
|
|
37
37
|
const incentiveSupplyApy = aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString();
|
package/package.json
CHANGED
package/src/aaveV3/index.ts
CHANGED
|
@@ -4,15 +4,23 @@ import { assetAmountInEth, assetAmountInWei, getAssetInfo } from '@defisaver/tok
|
|
|
4
4
|
import {
|
|
5
5
|
AaveIncentiveDataProviderV3Contract,
|
|
6
6
|
AaveV3ViewContract,
|
|
7
|
-
GhoTokenContract,
|
|
8
7
|
getConfigContractAbi,
|
|
9
8
|
getConfigContractAddress,
|
|
9
|
+
GhoTokenContract,
|
|
10
10
|
} from '../contracts';
|
|
11
11
|
import {
|
|
12
12
|
addToObjectIf, ethToWeth, getAbiItem, isLayer2Network, wethToEth,
|
|
13
13
|
} from '../services/utils';
|
|
14
14
|
import {
|
|
15
|
-
AaveMarketInfo,
|
|
15
|
+
AaveMarketInfo,
|
|
16
|
+
AaveV3AssetData,
|
|
17
|
+
AaveV3AssetsData,
|
|
18
|
+
AaveV3IncentiveData,
|
|
19
|
+
AaveV3MarketData,
|
|
20
|
+
AaveV3PositionData,
|
|
21
|
+
AaveV3UsedAsset,
|
|
22
|
+
AaveV3UsedAssets,
|
|
23
|
+
EModeCategoryDataMapping,
|
|
16
24
|
} from '../types/aave';
|
|
17
25
|
import {
|
|
18
26
|
Blockish, EthAddress, NetworkNumber, PositionBalances,
|
|
@@ -22,7 +30,11 @@ import { multicall } from '../multicall';
|
|
|
22
30
|
import { IUiIncentiveDataProviderV3 } from '../types/contracts/generated/AaveUiIncentiveDataProviderV3';
|
|
23
31
|
import { getAssetsBalances } from '../assets';
|
|
24
32
|
import { calculateBorrowingAssetLimit } from '../moneymarket';
|
|
25
|
-
import {
|
|
33
|
+
import {
|
|
34
|
+
aaveAnyGetAggregatedPositionData,
|
|
35
|
+
aaveV3IsInIsolationMode,
|
|
36
|
+
aaveV3IsInSiloedMode,
|
|
37
|
+
} from '../helpers/aaveHelpers';
|
|
26
38
|
import { AAVE_V3 } from '../markets/aave';
|
|
27
39
|
|
|
28
40
|
export const test = (web3: Web3, network: NetworkNumber) => {
|
|
@@ -237,6 +249,7 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
237
249
|
collateralFactor: new Dec(tokenMarket.ltv).div(10000).toString(),
|
|
238
250
|
priceSource: tokenMarket.priceSource,
|
|
239
251
|
},
|
|
252
|
+
aTokenAddress: tokenMarket.aTokenAddress,
|
|
240
253
|
});
|
|
241
254
|
}));
|
|
242
255
|
|
|
@@ -245,7 +258,6 @@ export async function getAaveV3MarketData(web3: Web3, network: NetworkNumber, ma
|
|
|
245
258
|
/* eslint-disable no-param-reassign */
|
|
246
259
|
const rewardForMarket: IUiIncentiveDataProviderV3.AggregatedReserveIncentiveDataStructOutput | undefined = rewardInfo?.[_market.underlyingTokenAddress as any];
|
|
247
260
|
if (['wstETH', 'cbETH', 'rETH', 'sDAI'].includes(_market.symbol)) {
|
|
248
|
-
if (!isLayer2Network(network) && _market.symbol === 'cbETH') return;
|
|
249
261
|
_market.incentiveSupplyApy = await getStakingApy(_market.symbol, defaultWeb3);
|
|
250
262
|
_market.incentiveSupplyToken = _market.symbol;
|
|
251
263
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { ChickenBondsManagerContract, ChickenBondsViewContract } from '../contracts';
|
|
10
10
|
import { BondInfoBasic, ChickenBondsSystemInfoBasic } from '../types';
|
|
11
11
|
import { multicall } from '../multicall';
|
|
12
|
-
import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice } from '../helpers/chickenBondsHelpers';
|
|
12
|
+
import { calcAverageBondAgeMs, calcCBondsBLUSDFloorPrice, decodeTokenURIToSvg } from '../helpers/chickenBondsHelpers';
|
|
13
13
|
|
|
14
14
|
export const getChickenBondsAccountBalances = async (web3: Web3, network: NetworkNumber, block: Blockish, addressMapping: boolean, bondId: string): Promise<PositionBalances> => {
|
|
15
15
|
const viewContract = ChickenBondsViewContract(web3, network, block);
|
|
@@ -94,7 +94,7 @@ export const fetchCBondsForUser = async (web3: Web3, network: NetworkNumber, add
|
|
|
94
94
|
}) => ({
|
|
95
95
|
bondId: bondID,
|
|
96
96
|
status,
|
|
97
|
-
|
|
97
|
+
tokenURI: decodeTokenURIToSvg(tokenURI),
|
|
98
98
|
startTime: new Date(+startTime * 1000),
|
|
99
99
|
endTime: new Date(+endTime * 1000),
|
|
100
100
|
accruedBLUSD: assetAmountInEth(accruedBLUSD, 'bLUSD'),
|
|
@@ -118,5 +118,6 @@ export const fetchCBondForId = async (web3: Web3, network: NetworkNumber, bondId
|
|
|
118
118
|
claimedBLUSD: assetAmountInEth(bond.claimedBLUSD, 'bLUSD'),
|
|
119
119
|
lusdAmount: assetAmountInEth(bond.lusdAmount, 'LUSD'),
|
|
120
120
|
maxAmountBLUSD: assetAmountInEth(bond.maxAmountBLUSD, 'bLUSD'),
|
|
121
|
+
tokenURI: decodeTokenURIToSvg(bond.tokenURI),
|
|
121
122
|
};
|
|
122
123
|
};
|
|
@@ -87,12 +87,26 @@ export const aaveAnyGetAggregatedPositionData = ({
|
|
|
87
87
|
payload.borrowLimitUsd = getAssetsTotal(
|
|
88
88
|
usedAssets,
|
|
89
89
|
({ isSupplied, collateral }: { isSupplied: boolean, collateral: string }) => isSupplied && collateral,
|
|
90
|
-
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) =>
|
|
90
|
+
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => {
|
|
91
|
+
const suppliedUsdAmount = isMorphoAaveV3(data)
|
|
92
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
93
|
+
? new Dec(suppliedUsd).minus(new Dec(suppliedUsd).div(100).times(0.1)).toString()
|
|
94
|
+
: suppliedUsd;
|
|
95
|
+
|
|
96
|
+
return new Dec(suppliedUsdAmount).mul(aaveAnyGetEmodeMutableProps(data, symbol).collateralFactor);
|
|
97
|
+
},
|
|
91
98
|
);
|
|
92
99
|
payload.liquidationLimitUsd = getAssetsTotal(
|
|
93
100
|
usedAssets,
|
|
94
101
|
({ isSupplied, collateral }: { isSupplied: boolean, collateral: string }) => isSupplied && collateral,
|
|
95
|
-
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) =>
|
|
102
|
+
({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => {
|
|
103
|
+
const suppliedUsdAmount = isMorphoAaveV3(data)
|
|
104
|
+
// Morpho has a slightly different method for calculating health ratio than underlying pool (To account for potential errors in rounding)
|
|
105
|
+
? new Dec(suppliedUsd).minus(new Dec(suppliedUsd).div(100).times(0.1)).toString()
|
|
106
|
+
: suppliedUsd;
|
|
107
|
+
|
|
108
|
+
return new Dec(suppliedUsdAmount).mul(aaveAnyGetEmodeMutableProps(data, symbol).liquidationRatio);
|
|
109
|
+
},
|
|
96
110
|
);
|
|
97
111
|
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
98
112
|
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
@@ -10,4 +10,15 @@ export const calcAverageBondAgeMs = (totalWeightedStartTimes: string, totalPendi
|
|
|
10
10
|
.toNumber();
|
|
11
11
|
|
|
12
12
|
return Date.now() - averageStartTimeMs;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const decodeTokenURIToSvg = (tokenURI: string): string => {
|
|
16
|
+
try {
|
|
17
|
+
const dataStartIndex = tokenURI.indexOf('base64,') + 'base64,'.length;
|
|
18
|
+
const json = atob(tokenURI.slice(dataStartIndex));
|
|
19
|
+
return JSON.parse(json)?.image;
|
|
20
|
+
} catch (e) {
|
|
21
|
+
console.error(e);
|
|
22
|
+
return 'Error parsing NFT image';
|
|
23
|
+
}
|
|
13
24
|
};
|
|
@@ -17,8 +17,8 @@ export const formatMarketData = (data: any, network: NetworkNumber, baseAssetPri
|
|
|
17
17
|
const price = getEthAmountForDecimals(data.price, 8);
|
|
18
18
|
return ({
|
|
19
19
|
...data,
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
priceInBaseAsset: getEthAmountForDecimals(data.price, 8),
|
|
21
|
+
price: new Dec(price).mul(baseAssetPrice).toString(),
|
|
22
22
|
collateralFactor: getEthAmountForDecimals(data.borrowCollateralFactor, 18),
|
|
23
23
|
liquidationRatio: getEthAmountForDecimals(data.liquidateCollateralFactor, 18),
|
|
24
24
|
supplyCap: getEthAmountForDecimals(data.supplyCap, assetInfo.decimals),
|
|
@@ -47,8 +47,8 @@ export const formatBaseData = (data: any, network: NetworkNumber, baseAssetPrice
|
|
|
47
47
|
totalBorrow,
|
|
48
48
|
marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(),
|
|
49
49
|
symbol: wethToEth(assetInfo.symbol),
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
priceInBaseAsset: getEthAmountForDecimals(data.price, 8),
|
|
51
|
+
price: baseAssetPrice,
|
|
52
52
|
collateralFactor: '0',
|
|
53
53
|
liquidationRatio: '0',
|
|
54
54
|
canBeBorrowed: true,
|