@defisaver/positions-sdk 0.0.23 → 0.0.25
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/README.md +63 -63
- package/cjs/helpers/curveUsdHelpers/index.js +0 -1
- package/cjs/markets/curveUsd/index.js +15 -15
- package/cjs/spark/index.js +1 -0
- package/cjs/types/curveUsd.d.ts +5 -6
- package/cjs/types/curveUsd.js +5 -5
- package/esm/helpers/curveUsdHelpers/index.js +0 -1
- package/esm/markets/curveUsd/index.js +15 -15
- package/esm/spark/index.js +1 -0
- package/esm/types/curveUsd.d.ts +5 -6
- package/esm/types/curveUsd.js +5 -5
- package/package.json +40 -40
- package/src/aaveV2/index.ts +226 -226
- package/src/aaveV3/index.ts +561 -561
- package/src/assets/index.ts +60 -60
- package/src/chickenBonds/index.ts +123 -123
- package/src/compoundV2/index.ts +219 -219
- package/src/compoundV3/index.ts +275 -275
- package/src/config/contracts.js +673 -673
- package/src/constants/index.ts +3 -3
- package/src/contracts.ts +100 -100
- package/src/curveUsd/index.ts +228 -228
- package/src/exchange/index.ts +17 -17
- package/src/helpers/aaveHelpers/index.ts +134 -134
- package/src/helpers/chickenBondsHelpers/index.ts +23 -23
- package/src/helpers/compoundHelpers/index.ts +181 -181
- package/src/helpers/curveUsdHelpers/index.ts +32 -33
- package/src/helpers/index.ts +5 -5
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/sparkHelpers/index.ts +106 -106
- package/src/index.ts +40 -40
- package/src/liquity/index.ts +116 -116
- package/src/maker/index.ts +101 -101
- package/src/markets/aave/index.ts +80 -80
- package/src/markets/aave/marketAssets.ts +32 -32
- package/src/markets/compound/index.ts +141 -141
- package/src/markets/compound/marketsAssets.ts +46 -46
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/index.ts +3 -3
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +9 -9
- package/src/moneymarket/moneymarketCommonService.ts +75 -75
- package/src/morpho/markets.ts +39 -39
- package/src/morphoAaveV2/index.ts +255 -255
- package/src/morphoAaveV3/index.ts +619 -619
- package/src/multicall/index.ts +22 -22
- package/src/services/dsrService.ts +15 -15
- package/src/services/priceService.ts +21 -21
- package/src/services/utils.ts +34 -34
- package/src/spark/index.ts +422 -421
- package/src/staking/staking.ts +167 -167
- package/src/types/aave.ts +256 -256
- package/src/types/chickenBonds.ts +45 -45
- package/src/types/common.ts +83 -83
- package/src/types/compound.ts +128 -128
- package/src/types/curveUsd.ts +112 -113
- package/src/types/index.ts +6 -6
- package/src/types/liquity.ts +30 -30
- package/src/types/maker.ts +50 -50
- package/src/types/spark.ts +106 -106
- package/yarn-error.log +0 -64
|
@@ -1,182 +1,182 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
|
-
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
|
-
import {
|
|
4
|
-
BaseAdditionalAssetData, CompoundAggregatedPositionData, CompoundMarketData, CompoundV2AssetsData, CompoundV2UsedAssets, CompoundV3AssetData, CompoundV3AssetsData, CompoundV3UsedAssets, CompoundVersions,
|
|
5
|
-
} from '../../types';
|
|
6
|
-
import { getEthAmountForDecimals, handleWbtcLegacy, wethToEth } from '../../services/utils';
|
|
7
|
-
import { SECONDS_PER_YEAR } from '../../constants';
|
|
8
|
-
import {
|
|
9
|
-
aprToApy, calcLeverageLiqPrice, calculateBorrowingAssetLimit, getAssetsTotal, isLeveragedPos,
|
|
10
|
-
} from '../../moneymarket';
|
|
11
|
-
import { calculateNetApy } from '../../staking';
|
|
12
|
-
import { NetworkNumber } from '../../types/common';
|
|
13
|
-
|
|
14
|
-
export const formatMarketData = (data: any, network: NetworkNumber, baseAssetPrice: string): CompoundV3AssetData => {
|
|
15
|
-
const assetInfo = getAssetInfoByAddress(data.tokenAddr, network);
|
|
16
|
-
const isWETH = assetInfo.symbol === 'WETH';
|
|
17
|
-
const price = getEthAmountForDecimals(data.price, 8);
|
|
18
|
-
return ({
|
|
19
|
-
...data,
|
|
20
|
-
priceInBaseAsset: getEthAmountForDecimals(data.price, 8),
|
|
21
|
-
price: new Dec(price).mul(baseAssetPrice).toString(),
|
|
22
|
-
collateralFactor: getEthAmountForDecimals(data.borrowCollateralFactor, 18),
|
|
23
|
-
liquidationRatio: getEthAmountForDecimals(data.liquidateCollateralFactor, 18),
|
|
24
|
-
supplyCap: getEthAmountForDecimals(data.supplyCap, assetInfo.decimals),
|
|
25
|
-
totalSupply: getEthAmountForDecimals(data.totalSupply, assetInfo.decimals),
|
|
26
|
-
symbol: isWETH ? 'ETH' : assetInfo.symbol,
|
|
27
|
-
supplyRate: '0',
|
|
28
|
-
borrowRate: '0',
|
|
29
|
-
canBeBorrowed: false,
|
|
30
|
-
canBeSupplied: true,
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// TODO: maybe not hardcode decimals
|
|
35
|
-
export const formatBaseData = (data: any, network: NetworkNumber, baseAssetPrice: string): CompoundV3AssetData & BaseAdditionalAssetData => {
|
|
36
|
-
const assetInfo = getAssetInfoByAddress(data.tokenAddr, network);
|
|
37
|
-
const totalSupply = getEthAmountForDecimals(new Dec(data.totalSupply).mul(data.supplyIndex).toString(), 15 + assetInfo.decimals);
|
|
38
|
-
const totalBorrow = getEthAmountForDecimals(new Dec(data.totalBorrow).mul(data.borrowIndex).toString(), 15 + assetInfo.decimals);
|
|
39
|
-
return ({
|
|
40
|
-
...data,
|
|
41
|
-
supplyRate: aprToApy(new Dec(data.supplyRate).div(1e18).mul(SECONDS_PER_YEAR).mul(100)
|
|
42
|
-
.toString()),
|
|
43
|
-
borrowRate: aprToApy(new Dec(data.borrowRate).div(1e18).mul(SECONDS_PER_YEAR).mul(100)
|
|
44
|
-
.toString()),
|
|
45
|
-
utilization: getEthAmountForDecimals(data.utilization, 16), // utilization is totalSupply/totalBorrow in 1e18, but we need % so when we mul with 100 it's 16 decimals
|
|
46
|
-
totalSupply,
|
|
47
|
-
totalBorrow,
|
|
48
|
-
marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(),
|
|
49
|
-
symbol: wethToEth(assetInfo.symbol),
|
|
50
|
-
priceInBaseAsset: getEthAmountForDecimals(data.price, 8),
|
|
51
|
-
price: baseAssetPrice,
|
|
52
|
-
collateralFactor: '0',
|
|
53
|
-
liquidationRatio: '0',
|
|
54
|
-
canBeBorrowed: true,
|
|
55
|
-
canBeSupplied: true,
|
|
56
|
-
supplyCap: '0',
|
|
57
|
-
rewardSupplySpeed: getEthAmountForDecimals(data.baseTrackingSupplyRewardsSpeed, 15),
|
|
58
|
-
rewardBorrowSpeed: getEthAmountForDecimals(data.baseTrackingBorrowRewardsSpeed, 15),
|
|
59
|
-
minDebt: getEthAmountForDecimals(data.baseBorrowMin, assetInfo.decimals),
|
|
60
|
-
isBase: true,
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
export const getIncentiveApys = (
|
|
65
|
-
baseData: CompoundV3AssetData & BaseAdditionalAssetData,
|
|
66
|
-
compPrice: string,
|
|
67
|
-
): {
|
|
68
|
-
incentiveSupplyApy: string,
|
|
69
|
-
incentiveBorrowApy: string,
|
|
70
|
-
incentiveSupplyToken: string,
|
|
71
|
-
incentiveBorrowToken: string,
|
|
72
|
-
} => {
|
|
73
|
-
const incentiveSupplyApy = aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString();
|
|
74
|
-
const incentiveBorrowApy = aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardBorrowSpeed * +compPrice) / +baseData.price / +baseData.totalBorrow).toString();
|
|
75
|
-
return {
|
|
76
|
-
incentiveSupplyApy,
|
|
77
|
-
incentiveBorrowApy,
|
|
78
|
-
incentiveSupplyToken: 'COMP',
|
|
79
|
-
incentiveBorrowToken: 'COMP',
|
|
80
|
-
};
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const getCompoundV2AggregatedData = ({
|
|
84
|
-
usedAssets, assetsData, ...rest
|
|
85
|
-
}: { usedAssets: CompoundV2UsedAssets, assetsData: CompoundV2AssetsData }) => {
|
|
86
|
-
const payload = {} as CompoundAggregatedPositionData;
|
|
87
|
-
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
88
|
-
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
89
|
-
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
90
|
-
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => new Dec(suppliedUsd).mul(assetsData[symbol].collateralFactor));
|
|
91
|
-
|
|
92
|
-
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd).toString();
|
|
93
|
-
|
|
94
|
-
payload.leftToBorrowUsd = leftToBorrowUsd;
|
|
95
|
-
payload.borrowLimitUsd = new Dec(leftToBorrowUsd).add(payload.borrowedUsd).toString();
|
|
96
|
-
|
|
97
|
-
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
98
|
-
payload.ratio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
99
|
-
? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
100
|
-
: '0';
|
|
101
|
-
payload.minRatio = '100';
|
|
102
|
-
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
103
|
-
? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
104
|
-
: '0';
|
|
105
|
-
|
|
106
|
-
// Calculate borrow limits per asset
|
|
107
|
-
Object.values(usedAssets).forEach((item) => {
|
|
108
|
-
if (item.isBorrowed) {
|
|
109
|
-
// eslint-disable-next-line no-param-reassign
|
|
110
|
-
item.limit = calculateBorrowingAssetLimit(item.borrowedUsd, payload.borrowLimitUsd);
|
|
111
|
-
}
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy(usedAssets, assetsData);
|
|
115
|
-
payload.netApy = netApy;
|
|
116
|
-
payload.incentiveUsd = incentiveUsd;
|
|
117
|
-
payload.totalInterestUsd = totalInterestUsd;
|
|
118
|
-
|
|
119
|
-
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
120
|
-
payload.leveragedType = leveragedType;
|
|
121
|
-
if (leveragedType !== '') {
|
|
122
|
-
payload.leveragedAsset = leveragedAsset;
|
|
123
|
-
const assetPrice = assetsData[handleWbtcLegacy(leveragedAsset)].price;
|
|
124
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
return payload;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export const getCompoundV3AggregatedData = ({
|
|
131
|
-
usedAssets, assetsData, network, selectedMarket, ...rest
|
|
132
|
-
}: { usedAssets: CompoundV3UsedAssets, assetsData: CompoundV3AssetsData, network: NetworkNumber, selectedMarket: CompoundMarketData }) => {
|
|
133
|
-
const payload = {} as CompoundAggregatedPositionData;
|
|
134
|
-
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
135
|
-
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
136
|
-
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
137
|
-
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => new Dec(suppliedUsd).mul(assetsData[symbol].collateralFactor));
|
|
138
|
-
payload.liquidationLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => new Dec(suppliedUsd).mul(assetsData[symbol].liquidationRatio));
|
|
139
|
-
payload.debtTooLow = new Dec(usedAssets[selectedMarket.baseAsset]?.borrowed || 0).gt(0) && new Dec(usedAssets[selectedMarket.baseAsset].borrowed).lt(assetsData[selectedMarket.baseAsset].minDebt);
|
|
140
|
-
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
141
|
-
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
142
|
-
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
143
|
-
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
144
|
-
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy(usedAssets, assetsData);
|
|
145
|
-
payload.netApy = netApy;
|
|
146
|
-
payload.incentiveUsd = incentiveUsd;
|
|
147
|
-
payload.totalInterestUsd = totalInterestUsd;
|
|
148
|
-
payload.minRatio = '100';
|
|
149
|
-
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
150
|
-
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
151
|
-
payload.minDebt = assetsData[selectedMarket.baseAsset].minDebt;
|
|
152
|
-
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets, selectedMarket.value === CompoundVersions.CompoundV3ETH ? 0.001 : 5);
|
|
153
|
-
payload.leveragedType = leveragedType;
|
|
154
|
-
if (leveragedType !== '') {
|
|
155
|
-
payload.leveragedAsset = leveragedAsset;
|
|
156
|
-
let assetPrice = assetsData[leveragedAsset].price;
|
|
157
|
-
if (leveragedType === 'lsd-leverage') {
|
|
158
|
-
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toString();
|
|
159
|
-
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
160
|
-
}
|
|
161
|
-
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// TO DO: handle strategies
|
|
165
|
-
/* const subscribedStrategies = rest.compoundStrategies
|
|
166
|
-
? compoundV3GetSubscribedStrategies({ selectedMarket, compoundStrategies: rest.compoundStrategies })
|
|
167
|
-
: []; */
|
|
168
|
-
|
|
169
|
-
// TODO possibly move to global helper, since every protocol has the same graphData?
|
|
170
|
-
// payload.ratioTooLow = false;
|
|
171
|
-
// payload.ratioTooHigh = false;
|
|
172
|
-
|
|
173
|
-
// TO DO: handle strategies
|
|
174
|
-
/* if (subscribedStrategies.length) {
|
|
175
|
-
subscribedStrategies.forEach(({ graphData }) => {
|
|
176
|
-
payload.ratioTooLow = parseFloat(payload.ratio) < parseFloat(graphData.minRatio);
|
|
177
|
-
payload.ratioTooHigh = graphData.boostEnabled && parseFloat(payload.ratio) > parseFloat(graphData.maxRatio);
|
|
178
|
-
});
|
|
179
|
-
} */
|
|
180
|
-
|
|
181
|
-
return payload;
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { getAssetInfoByAddress } from '@defisaver/tokens';
|
|
3
|
+
import {
|
|
4
|
+
BaseAdditionalAssetData, CompoundAggregatedPositionData, CompoundMarketData, CompoundV2AssetsData, CompoundV2UsedAssets, CompoundV3AssetData, CompoundV3AssetsData, CompoundV3UsedAssets, CompoundVersions,
|
|
5
|
+
} from '../../types';
|
|
6
|
+
import { getEthAmountForDecimals, handleWbtcLegacy, wethToEth } from '../../services/utils';
|
|
7
|
+
import { SECONDS_PER_YEAR } from '../../constants';
|
|
8
|
+
import {
|
|
9
|
+
aprToApy, calcLeverageLiqPrice, calculateBorrowingAssetLimit, getAssetsTotal, isLeveragedPos,
|
|
10
|
+
} from '../../moneymarket';
|
|
11
|
+
import { calculateNetApy } from '../../staking';
|
|
12
|
+
import { NetworkNumber } from '../../types/common';
|
|
13
|
+
|
|
14
|
+
export const formatMarketData = (data: any, network: NetworkNumber, baseAssetPrice: string): CompoundV3AssetData => {
|
|
15
|
+
const assetInfo = getAssetInfoByAddress(data.tokenAddr, network);
|
|
16
|
+
const isWETH = assetInfo.symbol === 'WETH';
|
|
17
|
+
const price = getEthAmountForDecimals(data.price, 8);
|
|
18
|
+
return ({
|
|
19
|
+
...data,
|
|
20
|
+
priceInBaseAsset: getEthAmountForDecimals(data.price, 8),
|
|
21
|
+
price: new Dec(price).mul(baseAssetPrice).toString(),
|
|
22
|
+
collateralFactor: getEthAmountForDecimals(data.borrowCollateralFactor, 18),
|
|
23
|
+
liquidationRatio: getEthAmountForDecimals(data.liquidateCollateralFactor, 18),
|
|
24
|
+
supplyCap: getEthAmountForDecimals(data.supplyCap, assetInfo.decimals),
|
|
25
|
+
totalSupply: getEthAmountForDecimals(data.totalSupply, assetInfo.decimals),
|
|
26
|
+
symbol: isWETH ? 'ETH' : assetInfo.symbol,
|
|
27
|
+
supplyRate: '0',
|
|
28
|
+
borrowRate: '0',
|
|
29
|
+
canBeBorrowed: false,
|
|
30
|
+
canBeSupplied: true,
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// TODO: maybe not hardcode decimals
|
|
35
|
+
export const formatBaseData = (data: any, network: NetworkNumber, baseAssetPrice: string): CompoundV3AssetData & BaseAdditionalAssetData => {
|
|
36
|
+
const assetInfo = getAssetInfoByAddress(data.tokenAddr, network);
|
|
37
|
+
const totalSupply = getEthAmountForDecimals(new Dec(data.totalSupply).mul(data.supplyIndex).toString(), 15 + assetInfo.decimals);
|
|
38
|
+
const totalBorrow = getEthAmountForDecimals(new Dec(data.totalBorrow).mul(data.borrowIndex).toString(), 15 + assetInfo.decimals);
|
|
39
|
+
return ({
|
|
40
|
+
...data,
|
|
41
|
+
supplyRate: aprToApy(new Dec(data.supplyRate).div(1e18).mul(SECONDS_PER_YEAR).mul(100)
|
|
42
|
+
.toString()),
|
|
43
|
+
borrowRate: aprToApy(new Dec(data.borrowRate).div(1e18).mul(SECONDS_PER_YEAR).mul(100)
|
|
44
|
+
.toString()),
|
|
45
|
+
utilization: getEthAmountForDecimals(data.utilization, 16), // utilization is totalSupply/totalBorrow in 1e18, but we need % so when we mul with 100 it's 16 decimals
|
|
46
|
+
totalSupply,
|
|
47
|
+
totalBorrow,
|
|
48
|
+
marketLiquidity: new Dec(totalSupply).minus(totalBorrow).toString(),
|
|
49
|
+
symbol: wethToEth(assetInfo.symbol),
|
|
50
|
+
priceInBaseAsset: getEthAmountForDecimals(data.price, 8),
|
|
51
|
+
price: baseAssetPrice,
|
|
52
|
+
collateralFactor: '0',
|
|
53
|
+
liquidationRatio: '0',
|
|
54
|
+
canBeBorrowed: true,
|
|
55
|
+
canBeSupplied: true,
|
|
56
|
+
supplyCap: '0',
|
|
57
|
+
rewardSupplySpeed: getEthAmountForDecimals(data.baseTrackingSupplyRewardsSpeed, 15),
|
|
58
|
+
rewardBorrowSpeed: getEthAmountForDecimals(data.baseTrackingBorrowRewardsSpeed, 15),
|
|
59
|
+
minDebt: getEthAmountForDecimals(data.baseBorrowMin, assetInfo.decimals),
|
|
60
|
+
isBase: true,
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
export const getIncentiveApys = (
|
|
65
|
+
baseData: CompoundV3AssetData & BaseAdditionalAssetData,
|
|
66
|
+
compPrice: string,
|
|
67
|
+
): {
|
|
68
|
+
incentiveSupplyApy: string,
|
|
69
|
+
incentiveBorrowApy: string,
|
|
70
|
+
incentiveSupplyToken: string,
|
|
71
|
+
incentiveBorrowToken: string,
|
|
72
|
+
} => {
|
|
73
|
+
const incentiveSupplyApy = aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardSupplySpeed * +compPrice) / +baseData.price / +baseData.totalSupply).toString();
|
|
74
|
+
const incentiveBorrowApy = aprToApy((100 * SECONDS_PER_YEAR * +baseData.rewardBorrowSpeed * +compPrice) / +baseData.price / +baseData.totalBorrow).toString();
|
|
75
|
+
return {
|
|
76
|
+
incentiveSupplyApy,
|
|
77
|
+
incentiveBorrowApy,
|
|
78
|
+
incentiveSupplyToken: 'COMP',
|
|
79
|
+
incentiveBorrowToken: 'COMP',
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const getCompoundV2AggregatedData = ({
|
|
84
|
+
usedAssets, assetsData, ...rest
|
|
85
|
+
}: { usedAssets: CompoundV2UsedAssets, assetsData: CompoundV2AssetsData }) => {
|
|
86
|
+
const payload = {} as CompoundAggregatedPositionData;
|
|
87
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
88
|
+
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
89
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
90
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => new Dec(suppliedUsd).mul(assetsData[symbol].collateralFactor));
|
|
91
|
+
|
|
92
|
+
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd).toString();
|
|
93
|
+
|
|
94
|
+
payload.leftToBorrowUsd = leftToBorrowUsd;
|
|
95
|
+
payload.borrowLimitUsd = new Dec(leftToBorrowUsd).add(payload.borrowedUsd).toString();
|
|
96
|
+
|
|
97
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
98
|
+
payload.ratio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
99
|
+
? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
100
|
+
: '0';
|
|
101
|
+
payload.minRatio = '100';
|
|
102
|
+
payload.collRatio = payload.borrowedUsd && payload.borrowedUsd !== '0'
|
|
103
|
+
? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString()
|
|
104
|
+
: '0';
|
|
105
|
+
|
|
106
|
+
// Calculate borrow limits per asset
|
|
107
|
+
Object.values(usedAssets).forEach((item) => {
|
|
108
|
+
if (item.isBorrowed) {
|
|
109
|
+
// eslint-disable-next-line no-param-reassign
|
|
110
|
+
item.limit = calculateBorrowingAssetLimit(item.borrowedUsd, payload.borrowLimitUsd);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy(usedAssets, assetsData);
|
|
115
|
+
payload.netApy = netApy;
|
|
116
|
+
payload.incentiveUsd = incentiveUsd;
|
|
117
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
118
|
+
|
|
119
|
+
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
120
|
+
payload.leveragedType = leveragedType;
|
|
121
|
+
if (leveragedType !== '') {
|
|
122
|
+
payload.leveragedAsset = leveragedAsset;
|
|
123
|
+
const assetPrice = assetsData[handleWbtcLegacy(leveragedAsset)].price;
|
|
124
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return payload;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
export const getCompoundV3AggregatedData = ({
|
|
131
|
+
usedAssets, assetsData, network, selectedMarket, ...rest
|
|
132
|
+
}: { usedAssets: CompoundV3UsedAssets, assetsData: CompoundV3AssetsData, network: NetworkNumber, selectedMarket: CompoundMarketData }) => {
|
|
133
|
+
const payload = {} as CompoundAggregatedPositionData;
|
|
134
|
+
payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
135
|
+
payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
136
|
+
payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
137
|
+
payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => new Dec(suppliedUsd).mul(assetsData[symbol].collateralFactor));
|
|
138
|
+
payload.liquidationLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }: { isSupplied: boolean, collateral: boolean }) => isSupplied && collateral, ({ symbol, suppliedUsd }: { symbol: string, suppliedUsd: string }) => new Dec(suppliedUsd).mul(assetsData[symbol].liquidationRatio));
|
|
139
|
+
payload.debtTooLow = new Dec(usedAssets[selectedMarket.baseAsset]?.borrowed || 0).gt(0) && new Dec(usedAssets[selectedMarket.baseAsset].borrowed).lt(assetsData[selectedMarket.baseAsset].minDebt);
|
|
140
|
+
const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
141
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
142
|
+
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
143
|
+
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
144
|
+
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy(usedAssets, assetsData);
|
|
145
|
+
payload.netApy = netApy;
|
|
146
|
+
payload.incentiveUsd = incentiveUsd;
|
|
147
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
148
|
+
payload.minRatio = '100';
|
|
149
|
+
payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
|
|
150
|
+
payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
|
|
151
|
+
payload.minDebt = assetsData[selectedMarket.baseAsset].minDebt;
|
|
152
|
+
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets, selectedMarket.value === CompoundVersions.CompoundV3ETH ? 0.001 : 5);
|
|
153
|
+
payload.leveragedType = leveragedType;
|
|
154
|
+
if (leveragedType !== '') {
|
|
155
|
+
payload.leveragedAsset = leveragedAsset;
|
|
156
|
+
let assetPrice = assetsData[leveragedAsset].price;
|
|
157
|
+
if (leveragedType === 'lsd-leverage') {
|
|
158
|
+
payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toString();
|
|
159
|
+
assetPrice = new Dec(assetPrice).div(assetsData.ETH.price).toString();
|
|
160
|
+
}
|
|
161
|
+
payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
// TO DO: handle strategies
|
|
165
|
+
/* const subscribedStrategies = rest.compoundStrategies
|
|
166
|
+
? compoundV3GetSubscribedStrategies({ selectedMarket, compoundStrategies: rest.compoundStrategies })
|
|
167
|
+
: []; */
|
|
168
|
+
|
|
169
|
+
// TODO possibly move to global helper, since every protocol has the same graphData?
|
|
170
|
+
// payload.ratioTooLow = false;
|
|
171
|
+
// payload.ratioTooHigh = false;
|
|
172
|
+
|
|
173
|
+
// TO DO: handle strategies
|
|
174
|
+
/* if (subscribedStrategies.length) {
|
|
175
|
+
subscribedStrategies.forEach(({ graphData }) => {
|
|
176
|
+
payload.ratioTooLow = parseFloat(payload.ratio) < parseFloat(graphData.minRatio);
|
|
177
|
+
payload.ratioTooHigh = graphData.boostEnabled && parseFloat(payload.ratio) > parseFloat(graphData.maxRatio);
|
|
178
|
+
});
|
|
179
|
+
} */
|
|
180
|
+
|
|
181
|
+
return payload;
|
|
182
182
|
};
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import Dec from 'decimal.js';
|
|
2
|
-
import { CrvUSDAggregatedPositionData, CrvUSDMarketData, CrvUSDUsedAssets } from '../../types';
|
|
3
|
-
import { NetworkNumber } from '../../types/common';
|
|
4
|
-
import { getAssetsTotal } from '../../moneymarket';
|
|
5
|
-
|
|
6
|
-
export const getCrvUsdAggregatedData = ({
|
|
7
|
-
loanExists, usedAssets, network, selectedMarket, ...rest
|
|
8
|
-
}:{
|
|
9
|
-
loanExists: boolean, usedAssets: CrvUSDUsedAssets, network: NetworkNumber, selectedMarket: CrvUSDMarketData,
|
|
10
|
-
}): CrvUSDAggregatedPositionData => {
|
|
11
|
-
const _supplied = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ supplied }: { supplied: string }) => supplied); // this is wrong if we are in soft-liquidations
|
|
12
|
-
const _borrowed = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowed }: { borrowed: string }) => borrowed);
|
|
13
|
-
const _suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
14
|
-
const _borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
15
|
-
|
|
16
|
-
const ratio = loanExists
|
|
17
|
-
? new Dec(_suppliedUsd)
|
|
18
|
-
.dividedBy(_borrowedUsd)
|
|
19
|
-
.times(100)
|
|
20
|
-
.toString()
|
|
21
|
-
: '0';
|
|
22
|
-
|
|
23
|
-
// we don't have borrowLimitUsd here
|
|
24
|
-
|
|
25
|
-
return {
|
|
26
|
-
ratio,
|
|
27
|
-
supplied: _supplied,
|
|
28
|
-
suppliedUsd: _suppliedUsd,
|
|
29
|
-
borrowedUsd: _borrowedUsd,
|
|
30
|
-
borrowed: _borrowed,
|
|
31
|
-
safetyRatio: ratio,
|
|
32
|
-
|
|
33
|
-
};
|
|
1
|
+
import Dec from 'decimal.js';
|
|
2
|
+
import { CrvUSDAggregatedPositionData, CrvUSDMarketData, CrvUSDUsedAssets } from '../../types';
|
|
3
|
+
import { NetworkNumber } from '../../types/common';
|
|
4
|
+
import { getAssetsTotal } from '../../moneymarket';
|
|
5
|
+
|
|
6
|
+
export const getCrvUsdAggregatedData = ({
|
|
7
|
+
loanExists, usedAssets, network, selectedMarket, ...rest
|
|
8
|
+
}:{
|
|
9
|
+
loanExists: boolean, usedAssets: CrvUSDUsedAssets, network: NetworkNumber, selectedMarket: CrvUSDMarketData,
|
|
10
|
+
}): CrvUSDAggregatedPositionData => {
|
|
11
|
+
const _supplied = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ supplied }: { supplied: string }) => supplied); // this is wrong if we are in soft-liquidations
|
|
12
|
+
const _borrowed = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowed }: { borrowed: string }) => borrowed);
|
|
13
|
+
const _suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }: { isSupplied: boolean }) => isSupplied, ({ suppliedUsd }: { suppliedUsd: string }) => suppliedUsd);
|
|
14
|
+
const _borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }: { isBorrowed: boolean }) => isBorrowed, ({ borrowedUsd }: { borrowedUsd: string }) => borrowedUsd);
|
|
15
|
+
|
|
16
|
+
const ratio = loanExists
|
|
17
|
+
? new Dec(_suppliedUsd)
|
|
18
|
+
.dividedBy(_borrowedUsd)
|
|
19
|
+
.times(100)
|
|
20
|
+
.toString()
|
|
21
|
+
: '0';
|
|
22
|
+
|
|
23
|
+
// we don't have borrowLimitUsd here
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
ratio,
|
|
27
|
+
supplied: _supplied,
|
|
28
|
+
suppliedUsd: _suppliedUsd,
|
|
29
|
+
borrowedUsd: _borrowedUsd,
|
|
30
|
+
borrowed: _borrowed,
|
|
31
|
+
safetyRatio: ratio,
|
|
32
|
+
};
|
|
34
33
|
};
|
package/src/helpers/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * as aaveHelpers from './aaveHelpers';
|
|
2
|
-
export * as compoundHelpers from './compoundHelpers';
|
|
3
|
-
export * as sparkHelpers from './sparkHelpers';
|
|
4
|
-
export * as curveUsdHelpers from './curveUsdHelpers';
|
|
5
|
-
export * as makerHelpers from './makerHelpers';
|
|
1
|
+
export * as aaveHelpers from './aaveHelpers';
|
|
2
|
+
export * as compoundHelpers from './compoundHelpers';
|
|
3
|
+
export * as sparkHelpers from './sparkHelpers';
|
|
4
|
+
export * as curveUsdHelpers from './curveUsdHelpers';
|
|
5
|
+
export * as makerHelpers from './makerHelpers';
|
|
6
6
|
export * as chickenBondsHelpers from './chickenBondsHelpers';
|
|
@@ -1,95 +1,95 @@
|
|
|
1
|
-
import Web3 from 'web3';
|
|
2
|
-
import Dec from 'decimal.js';
|
|
3
|
-
import { Blockish, NetworkNumber } from '../../types/common';
|
|
4
|
-
import {
|
|
5
|
-
McdDogContract, McdJugContract, McdSpotterContract, McdVatContract,
|
|
6
|
-
} from '../../contracts';
|
|
7
|
-
import { multicall } from '../../multicall';
|
|
8
|
-
import { SECONDS_PER_YEAR } from '../../constants';
|
|
9
|
-
import { bytesToString } from '../../services/utils';
|
|
10
|
-
import { IlkInfo } from '../../types';
|
|
11
|
-
|
|
12
|
-
export const getUnclaimedCollateral = async (web3: Web3, network: NetworkNumber, urn: string, ilk: string) => {
|
|
13
|
-
const vatContract = McdVatContract(web3, network);
|
|
14
|
-
const coll = await vatContract.methods.gem(ilk, urn).call();
|
|
15
|
-
return coll;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const getCollateralInfo = async (ilk: string, web3: Web3, network: NetworkNumber, block: Blockish = 'latest'): Promise<IlkInfo> => {
|
|
19
|
-
const spotterContract = McdSpotterContract(web3, network);
|
|
20
|
-
const vatContract = McdVatContract(web3, network);
|
|
21
|
-
const dogContract = McdDogContract(web3, network);
|
|
22
|
-
const jugContract = McdJugContract(web3, network);
|
|
23
|
-
|
|
24
|
-
const multicallData = [
|
|
25
|
-
{
|
|
26
|
-
target: spotterContract.options.address,
|
|
27
|
-
abiItem: spotterContract.options.jsonInterface.find(({ name }) => name === 'par'),
|
|
28
|
-
params: [],
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
target: spotterContract.options.address,
|
|
32
|
-
abiItem: spotterContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
|
|
33
|
-
params: [ilk],
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
target: vatContract.options.address,
|
|
37
|
-
abiItem: vatContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
|
|
38
|
-
params: [ilk],
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
target: jugContract.options.address,
|
|
42
|
-
abiItem: jugContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
|
|
43
|
-
params: [ilk],
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
target: jugContract.options.address,
|
|
47
|
-
abiItem: jugContract.options.jsonInterface.find(({ name }) => name === 'drip'),
|
|
48
|
-
params: [ilk],
|
|
49
|
-
},
|
|
50
|
-
{
|
|
51
|
-
target: dogContract.options.address,
|
|
52
|
-
abiItem: dogContract.options.jsonInterface.find(({ name }) => name === 'chop'),
|
|
53
|
-
params: [ilk],
|
|
54
|
-
},
|
|
55
|
-
];
|
|
56
|
-
|
|
57
|
-
const multiRes = await multicall(multicallData, web3, network, block);
|
|
58
|
-
|
|
59
|
-
const par = new Dec(multiRes[0][0].toString()).div(1e27).toString();
|
|
60
|
-
const mat = new Dec(multiRes[1][1].toString()).div(1e27).toString();
|
|
61
|
-
const art = new Dec(multiRes[2][0].toString()).toString();
|
|
62
|
-
const rate = new Dec(multiRes[2][1].toString()).toString();
|
|
63
|
-
const spot = new Dec(multiRes[2][2].toString()).div(1e27).toString();
|
|
64
|
-
const line = new Dec(multiRes[2][3].toString()).div(1e45).toString();
|
|
65
|
-
const dust = new Dec(multiRes[2][1].toString()).div(1e45).toString();
|
|
66
|
-
const duty = new Dec(multiRes[3][0].toString()).toString();
|
|
67
|
-
const futureRate = new Dec(multiRes[4][0].toString()).toString();
|
|
68
|
-
const chop = new Dec(multiRes[5][0].toString()).div(1e18).toString();
|
|
69
|
-
|
|
70
|
-
const stabilityFee = new Dec(duty.toString())
|
|
71
|
-
.div(1e27)
|
|
72
|
-
.pow(SECONDS_PER_YEAR)
|
|
73
|
-
.minus(1)
|
|
74
|
-
.mul(100)
|
|
75
|
-
.toNumber();
|
|
76
|
-
const liquidationFee = new Dec(chop).mul(100).sub(100).toString();
|
|
77
|
-
const globalDebtCurrent = new Dec(art).div(1e18).mul(new Dec(futureRate).div(1e27)).toString();
|
|
78
|
-
const globalDebtCeiling = line;
|
|
79
|
-
const creatableDebt = new Dec(globalDebtCeiling).sub(globalDebtCurrent).toString();
|
|
80
|
-
|
|
81
|
-
return {
|
|
82
|
-
ilkLabel: bytesToString(ilk),
|
|
83
|
-
currentRate: rate,
|
|
84
|
-
futureRate,
|
|
85
|
-
minDebt: dust,
|
|
86
|
-
globalDebtCurrent,
|
|
87
|
-
globalDebtCeiling,
|
|
88
|
-
assetPrice: new Dec(spot).times(par).times(mat).toString(),
|
|
89
|
-
liqRatio: mat,
|
|
90
|
-
liqPercent: +mat * 100,
|
|
91
|
-
stabilityFee,
|
|
92
|
-
liquidationFee: new Dec(liquidationFee).lt(0) ? '0' : liquidationFee,
|
|
93
|
-
creatableDebt,
|
|
94
|
-
};
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import Dec from 'decimal.js';
|
|
3
|
+
import { Blockish, NetworkNumber } from '../../types/common';
|
|
4
|
+
import {
|
|
5
|
+
McdDogContract, McdJugContract, McdSpotterContract, McdVatContract,
|
|
6
|
+
} from '../../contracts';
|
|
7
|
+
import { multicall } from '../../multicall';
|
|
8
|
+
import { SECONDS_PER_YEAR } from '../../constants';
|
|
9
|
+
import { bytesToString } from '../../services/utils';
|
|
10
|
+
import { IlkInfo } from '../../types';
|
|
11
|
+
|
|
12
|
+
export const getUnclaimedCollateral = async (web3: Web3, network: NetworkNumber, urn: string, ilk: string) => {
|
|
13
|
+
const vatContract = McdVatContract(web3, network);
|
|
14
|
+
const coll = await vatContract.methods.gem(ilk, urn).call();
|
|
15
|
+
return coll;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const getCollateralInfo = async (ilk: string, web3: Web3, network: NetworkNumber, block: Blockish = 'latest'): Promise<IlkInfo> => {
|
|
19
|
+
const spotterContract = McdSpotterContract(web3, network);
|
|
20
|
+
const vatContract = McdVatContract(web3, network);
|
|
21
|
+
const dogContract = McdDogContract(web3, network);
|
|
22
|
+
const jugContract = McdJugContract(web3, network);
|
|
23
|
+
|
|
24
|
+
const multicallData = [
|
|
25
|
+
{
|
|
26
|
+
target: spotterContract.options.address,
|
|
27
|
+
abiItem: spotterContract.options.jsonInterface.find(({ name }) => name === 'par'),
|
|
28
|
+
params: [],
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
target: spotterContract.options.address,
|
|
32
|
+
abiItem: spotterContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
|
|
33
|
+
params: [ilk],
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
target: vatContract.options.address,
|
|
37
|
+
abiItem: vatContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
|
|
38
|
+
params: [ilk],
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
target: jugContract.options.address,
|
|
42
|
+
abiItem: jugContract.options.jsonInterface.find(({ name }) => name === 'ilks'),
|
|
43
|
+
params: [ilk],
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
target: jugContract.options.address,
|
|
47
|
+
abiItem: jugContract.options.jsonInterface.find(({ name }) => name === 'drip'),
|
|
48
|
+
params: [ilk],
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
target: dogContract.options.address,
|
|
52
|
+
abiItem: dogContract.options.jsonInterface.find(({ name }) => name === 'chop'),
|
|
53
|
+
params: [ilk],
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
const multiRes = await multicall(multicallData, web3, network, block);
|
|
58
|
+
|
|
59
|
+
const par = new Dec(multiRes[0][0].toString()).div(1e27).toString();
|
|
60
|
+
const mat = new Dec(multiRes[1][1].toString()).div(1e27).toString();
|
|
61
|
+
const art = new Dec(multiRes[2][0].toString()).toString();
|
|
62
|
+
const rate = new Dec(multiRes[2][1].toString()).toString();
|
|
63
|
+
const spot = new Dec(multiRes[2][2].toString()).div(1e27).toString();
|
|
64
|
+
const line = new Dec(multiRes[2][3].toString()).div(1e45).toString();
|
|
65
|
+
const dust = new Dec(multiRes[2][1].toString()).div(1e45).toString();
|
|
66
|
+
const duty = new Dec(multiRes[3][0].toString()).toString();
|
|
67
|
+
const futureRate = new Dec(multiRes[4][0].toString()).toString();
|
|
68
|
+
const chop = new Dec(multiRes[5][0].toString()).div(1e18).toString();
|
|
69
|
+
|
|
70
|
+
const stabilityFee = new Dec(duty.toString())
|
|
71
|
+
.div(1e27)
|
|
72
|
+
.pow(SECONDS_PER_YEAR)
|
|
73
|
+
.minus(1)
|
|
74
|
+
.mul(100)
|
|
75
|
+
.toNumber();
|
|
76
|
+
const liquidationFee = new Dec(chop).mul(100).sub(100).toString();
|
|
77
|
+
const globalDebtCurrent = new Dec(art).div(1e18).mul(new Dec(futureRate).div(1e27)).toString();
|
|
78
|
+
const globalDebtCeiling = line;
|
|
79
|
+
const creatableDebt = new Dec(globalDebtCeiling).sub(globalDebtCurrent).toString();
|
|
80
|
+
|
|
81
|
+
return {
|
|
82
|
+
ilkLabel: bytesToString(ilk),
|
|
83
|
+
currentRate: rate,
|
|
84
|
+
futureRate,
|
|
85
|
+
minDebt: dust,
|
|
86
|
+
globalDebtCurrent,
|
|
87
|
+
globalDebtCeiling,
|
|
88
|
+
assetPrice: new Dec(spot).times(par).times(mat).toString(),
|
|
89
|
+
liqRatio: mat,
|
|
90
|
+
liqPercent: +mat * 100,
|
|
91
|
+
stabilityFee,
|
|
92
|
+
liquidationFee: new Dec(liquidationFee).lt(0) ? '0' : liquidationFee,
|
|
93
|
+
creatableDebt,
|
|
94
|
+
};
|
|
95
95
|
};
|