@defisaver/positions-sdk 2.1.161 → 2.1.163
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/aaveV2/index.js +2 -0
- package/cjs/aaveV3/index.js +7 -1
- package/cjs/curveUsd/index.d.ts +5 -2
- package/cjs/curveUsd/index.js +30 -15
- package/cjs/fluid/index.d.ts +5 -0
- package/cjs/fluid/index.js +36 -1
- package/cjs/helpers/aaveHelpers/index.d.ts +9 -1
- package/cjs/helpers/aaveHelpers/index.js +26 -6
- package/cjs/helpers/aaveV4Helpers/index.js +1 -0
- package/cjs/helpers/compoundHelpers/index.js +2 -0
- package/cjs/helpers/curveUsdHelpers/index.d.ts +3 -1
- package/cjs/helpers/curveUsdHelpers/index.js +15 -2
- package/cjs/helpers/fluidHelpers/index.js +1 -0
- package/cjs/helpers/liquityV2Helpers/index.js +1 -0
- package/cjs/helpers/llamaLendHelpers/index.js +1 -0
- package/cjs/helpers/makerHelpers/index.d.ts +1 -1
- package/cjs/helpers/makerHelpers/index.js +2 -2
- package/cjs/helpers/morphoBlueHelpers/index.js +2 -0
- package/cjs/helpers/morphoMidnightHelpers/index.js +2 -0
- package/cjs/helpers/sparkHelpers/index.js +1 -0
- package/cjs/liquity/index.js +15 -2
- package/cjs/maker/index.d.ts +7 -2
- package/cjs/maker/index.js +44 -12
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/maker/index.d.ts +1 -0
- package/cjs/markets/maker/index.js +13 -0
- package/cjs/moneymarket/moneymarketCommonService.d.ts +9 -0
- package/cjs/moneymarket/moneymarketCommonService.js +13 -1
- package/cjs/portfolio/index.d.ts +5 -1
- package/cjs/portfolio/index.js +282 -16
- package/cjs/spark/index.js +1 -0
- package/cjs/staking/staking.d.ts +20 -0
- package/cjs/staking/staking.js +19 -1
- package/cjs/types/aave.d.ts +3 -0
- package/cjs/types/aaveV4.d.ts +1 -0
- package/cjs/types/compound.d.ts +2 -0
- package/cjs/types/curveUsd.d.ts +6 -0
- package/cjs/types/fluid.d.ts +1 -0
- package/cjs/types/liquity.d.ts +4 -0
- package/cjs/types/liquityV2.d.ts +2 -0
- package/cjs/types/maker.d.ts +4 -0
- package/cjs/types/morphoBlue.d.ts +2 -0
- package/cjs/types/morphoMidnight.d.ts +1 -0
- package/cjs/types/portfolio.d.ts +26 -10
- package/cjs/types/spark.d.ts +2 -0
- package/esm/aaveV2/index.js +2 -0
- package/esm/aaveV3/index.js +7 -1
- package/esm/curveUsd/index.d.ts +5 -2
- package/esm/curveUsd/index.js +30 -15
- package/esm/fluid/index.d.ts +5 -0
- package/esm/fluid/index.js +33 -0
- package/esm/helpers/aaveHelpers/index.d.ts +9 -1
- package/esm/helpers/aaveHelpers/index.js +23 -5
- package/esm/helpers/aaveV4Helpers/index.js +1 -0
- package/esm/helpers/compoundHelpers/index.js +2 -0
- package/esm/helpers/curveUsdHelpers/index.d.ts +3 -1
- package/esm/helpers/curveUsdHelpers/index.js +16 -3
- package/esm/helpers/fluidHelpers/index.js +1 -0
- package/esm/helpers/liquityV2Helpers/index.js +1 -0
- package/esm/helpers/llamaLendHelpers/index.js +2 -1
- package/esm/helpers/makerHelpers/index.d.ts +1 -1
- package/esm/helpers/makerHelpers/index.js +2 -2
- package/esm/helpers/morphoBlueHelpers/index.js +2 -0
- package/esm/helpers/morphoMidnightHelpers/index.js +2 -0
- package/esm/helpers/sparkHelpers/index.js +1 -0
- package/esm/liquity/index.js +16 -3
- package/esm/maker/index.d.ts +7 -2
- package/esm/maker/index.js +44 -14
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/maker/index.d.ts +1 -0
- package/esm/markets/maker/index.js +10 -0
- package/esm/moneymarket/moneymarketCommonService.d.ts +9 -0
- package/esm/moneymarket/moneymarketCommonService.js +11 -0
- package/esm/portfolio/index.d.ts +5 -1
- package/esm/portfolio/index.js +284 -19
- package/esm/spark/index.js +1 -0
- package/esm/staking/staking.d.ts +20 -0
- package/esm/staking/staking.js +17 -0
- package/esm/types/aave.d.ts +3 -0
- package/esm/types/aaveV4.d.ts +1 -0
- package/esm/types/compound.d.ts +2 -0
- package/esm/types/curveUsd.d.ts +6 -0
- package/esm/types/fluid.d.ts +1 -0
- package/esm/types/liquity.d.ts +4 -0
- package/esm/types/liquityV2.d.ts +2 -0
- package/esm/types/maker.d.ts +4 -0
- package/esm/types/morphoBlue.d.ts +2 -0
- package/esm/types/morphoMidnight.d.ts +1 -0
- package/esm/types/portfolio.d.ts +26 -10
- package/esm/types/spark.d.ts +2 -0
- package/package.json +1 -1
- package/src/aaveV2/index.ts +2 -0
- package/src/aaveV3/index.ts +6 -1
- package/src/curveUsd/index.ts +33 -16
- package/src/fluid/index.ts +40 -0
- package/src/helpers/aaveHelpers/index.ts +27 -7
- package/src/helpers/aaveV4Helpers/index.ts +1 -0
- package/src/helpers/compoundHelpers/index.ts +2 -0
- package/src/helpers/curveUsdHelpers/index.ts +23 -3
- package/src/helpers/fluidHelpers/index.ts +1 -0
- package/src/helpers/liquityV2Helpers/index.ts +1 -0
- package/src/helpers/llamaLendHelpers/index.ts +2 -1
- package/src/helpers/makerHelpers/index.ts +2 -1
- package/src/helpers/morphoBlueHelpers/index.ts +2 -0
- package/src/helpers/morphoMidnightHelpers/index.ts +2 -0
- package/src/helpers/sparkHelpers/index.ts +1 -0
- package/src/liquity/index.ts +17 -3
- package/src/maker/index.ts +77 -30
- package/src/markets/index.ts +2 -1
- package/src/markets/maker/index.ts +10 -0
- package/src/moneymarket/moneymarketCommonService.ts +15 -0
- package/src/portfolio/index.ts +260 -5
- package/src/spark/index.ts +1 -0
- package/src/staking/staking.ts +28 -0
- package/src/types/aave.ts +4 -0
- package/src/types/aaveV4.ts +1 -0
- package/src/types/compound.ts +2 -0
- package/src/types/curveUsd.ts +7 -0
- package/src/types/fluid.ts +1 -0
- package/src/types/liquity.ts +6 -0
- package/src/types/liquityV2.ts +2 -0
- package/src/types/maker.ts +6 -0
- package/src/types/morphoBlue.ts +2 -0
- package/src/types/morphoMidnight.ts +1 -0
- package/src/types/portfolio.ts +31 -12
- package/src/types/spark.ts +2 -0
|
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
12
|
import Dec from 'decimal.js';
|
|
13
|
-
import { calcLeverageLiqPrice, getAssetsTotal, getExposure, isLeveragedPos, } from '../../moneymarket';
|
|
13
|
+
import { calcLeverageLiqPrice, getAssetsTotal, getExposure, getSafetyRatioFromCollateralRatio, isLeveragedPos, } from '../../moneymarket';
|
|
14
14
|
import { mapRange } from '../../services/utils';
|
|
15
15
|
import { calculateNetApy } from '../../staking';
|
|
16
16
|
export const getLlamaLendAggregatedData = (_a) => {
|
|
@@ -36,6 +36,7 @@ export const getLlamaLendAggregatedData = (_a) => {
|
|
|
36
36
|
: '0';
|
|
37
37
|
// this is all approximation
|
|
38
38
|
payload.minAllowedRatio = mapRange(numOfBands, 4, 50, 115, 140); // collateral ratio
|
|
39
|
+
payload.safetyRatio = loanExists ? getSafetyRatioFromCollateralRatio(payload.ratio, payload.minAllowedRatio) : '0';
|
|
39
40
|
payload.collFactor = new Dec(1).div(payload.minAllowedRatio).mul(100).toString(); // collateral factor = 1 / collateral ratio
|
|
40
41
|
// only take in consideration collAsset
|
|
41
42
|
payload.borrowLimitUsd = ((_b = usedAssets === null || usedAssets === void 0 ? void 0 : usedAssets[collAsset]) === null || _b === void 0 ? void 0 : _b.isSupplied)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const parseCollateralInfo: (ilk: string, _par: string, _mat: string, _art: string, _rate: string, _spot: string, _line: string, _duty: string, _futureRate: string, _chop: string) => {
|
|
1
|
+
export declare const parseCollateralInfo: (ilk: string, _par: string, _mat: string, _art: string, _rate: string, _spot: string, _line: string, _dust: string, _duty: string, _futureRate: string, _chop: string) => {
|
|
2
2
|
ilkLabel: string;
|
|
3
3
|
currentRate: string;
|
|
4
4
|
futureRate: string;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import Dec from 'decimal.js';
|
|
2
2
|
import { SECONDS_PER_YEAR } from '../../constants';
|
|
3
3
|
import { bytesToString } from '../../services/utils';
|
|
4
|
-
export const parseCollateralInfo = (ilk, _par, _mat, _art, _rate, _spot, _line, _duty, _futureRate, _chop) => {
|
|
4
|
+
export const parseCollateralInfo = (ilk, _par, _mat, _art, _rate, _spot, _line, _dust, _duty, _futureRate, _chop) => {
|
|
5
5
|
const par = new Dec(_par).div(1e27).toString();
|
|
6
6
|
const mat = new Dec(_mat).div(1e27).toString();
|
|
7
7
|
const art = new Dec(_art).toString();
|
|
8
8
|
const rate = new Dec(_rate).toString();
|
|
9
9
|
const spot = new Dec(_spot).div(1e27).toString();
|
|
10
10
|
const line = new Dec(_line).div(1e45).toString();
|
|
11
|
-
const dust = new Dec(
|
|
11
|
+
const dust = new Dec(_dust).div(1e45).toString(); // Vat.ilks.dust, rad (1e45) -> DAI
|
|
12
12
|
const duty = new Dec(_duty).toString();
|
|
13
13
|
const futureRate = new Dec(_futureRate).toString();
|
|
14
14
|
const chop = new Dec(_chop).div(1e18).toString();
|
|
@@ -40,6 +40,8 @@ export const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, ma
|
|
|
40
40
|
payload.ltv = new Dec(((_c = usedAssets[loanToken]) === null || _c === void 0 ? void 0 : _c.borrowed) || 0).div(oracle).div(((_d = usedAssets[collateralToken]) === null || _d === void 0 ? void 0 : _d.supplied) || 1).toString(); // default to 1 because can't div 0
|
|
41
41
|
payload.ratio = new Dec(((_e = usedAssets[collateralToken]) === null || _e === void 0 ? void 0 : _e.supplied) || 0).mul(oracle).div(((_f = usedAssets[loanToken]) === null || _f === void 0 ? void 0 : _f.borrowed) || 1).mul(100)
|
|
42
42
|
.toString();
|
|
43
|
+
// Borrow limit over debt, so 100 sits on the market's LLTV however low it is (`ratio` is the raw collateral ratio).
|
|
44
|
+
payload.safetyRatio = +payload.borrowedUsd > 0 ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
43
45
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
44
46
|
payload.leveragedType = leveragedType;
|
|
45
47
|
payload.liquidationPrice = '';
|
|
@@ -58,6 +58,8 @@ export const getMorphoMidnightAggregatedPositionData = ({ usedAssets, assetsData
|
|
|
58
58
|
payload.ltv = new Dec(payload.suppliedCollateralUsd).eq(0) ? '0' : new Dec(payload.borrowedUsd).div(payload.suppliedCollateralUsd).toString();
|
|
59
59
|
payload.ratio = new Dec(payload.borrowedUsd).eq(0) ? '0' : new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString();
|
|
60
60
|
payload.healthRatio = new Dec(payload.borrowedUsd).eq(0) ? 'Infinity' : new Dec(payload.liquidationLimitUsd).div(payload.borrowedUsd).toDP(4).toString();
|
|
61
|
+
// Borrow limit over debt, so 100 sits on the market's LLTV however low it is (`ratio` is the raw collateral ratio).
|
|
62
|
+
payload.safetyRatio = +payload.borrowedUsd > 0 ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
61
63
|
const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
|
|
62
64
|
payload.leveragedType = leveragedType;
|
|
63
65
|
payload.liquidationPrice = '';
|
|
@@ -70,6 +70,7 @@ export const sparkGetAggregatedPositionData = (_a) => {
|
|
|
70
70
|
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
71
71
|
payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
72
72
|
payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
|
|
73
|
+
payload.safetyRatio = payload.ratio;
|
|
73
74
|
const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy({ usedAssets, assetsData });
|
|
74
75
|
payload.netApy = netApy;
|
|
75
76
|
payload.incentiveUsd = incentiveUsd;
|
package/esm/liquity/index.js
CHANGED
|
@@ -15,7 +15,8 @@ import { LIQUITY_TROVE_STATUS_ENUM } from '../types';
|
|
|
15
15
|
import { ZERO_ADDRESS } from '../constants';
|
|
16
16
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
17
17
|
import { getEthAmountForDecimals } from '../services/utils';
|
|
18
|
-
import { getExposure } from '../moneymarket';
|
|
18
|
+
import { getExposure, getSafetyRatioFromCollateralRatio } from '../moneymarket';
|
|
19
|
+
import { calculateNetApyFromRates } from '../staking';
|
|
19
20
|
export const LIQUITY_NORMAL_MODE_RATIO = 110; // MCR
|
|
20
21
|
export const LIQUITY_RECOVERY_MODE_RATIO = 150; // CCR
|
|
21
22
|
export const _getLiquityAccountBalances = (provider, network, block, addressMapping, address) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -68,6 +69,14 @@ export const _getLiquityTroveInfo = (provider, network, address) => __awaiter(vo
|
|
|
68
69
|
_getDebtInFront(viewContract, address),
|
|
69
70
|
]);
|
|
70
71
|
const recoveryMode = troveInfo[6];
|
|
72
|
+
const minCollateralRatio = recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO;
|
|
73
|
+
const collateral = assetAmountInEth(troveInfo[1].toString());
|
|
74
|
+
const debtInAsset = assetAmountInEth(troveInfo[2].toString());
|
|
75
|
+
const collateralUsd = new Dec(collateral).mul(assetAmountInEth(assetPrice.toString())).toString();
|
|
76
|
+
const collRatio = +debtInAsset ? new Dec(collateralUsd).div(debtInAsset).mul(100).toString() : '0';
|
|
77
|
+
// LUSD debt is interest free (only a one-off borrowing fee on issuance) and ETH collateral earns no yield,
|
|
78
|
+
// so a trove's net APY is always 0. It is exposed for parity with the other protocols.
|
|
79
|
+
const { netApy, totalInterestUsd, incentiveUsd } = calculateNetApyFromRates({ suppliedUsd: collateralUsd, borrowedUsd: debtInAsset });
|
|
71
80
|
const payload = {
|
|
72
81
|
troveStatus: LIQUITY_TROVE_STATUS_ENUM[+(troveInfo[0].toString())],
|
|
73
82
|
collateral: assetAmountInEth(troveInfo[1].toString()),
|
|
@@ -80,10 +89,14 @@ export const _getLiquityTroveInfo = (provider, network, address) => __awaiter(vo
|
|
|
80
89
|
totalETH: totalETH.toString(),
|
|
81
90
|
totalLUSD: totalLUSD.toString(),
|
|
82
91
|
debtInFront: debtInFront.toString(),
|
|
83
|
-
minCollateralRatio
|
|
92
|
+
minCollateralRatio,
|
|
93
|
+
safetyRatio: getSafetyRatioFromCollateralRatio(collRatio, minCollateralRatio),
|
|
84
94
|
priceForRecovery: new Dec(recoveryMode ? LIQUITY_RECOVERY_MODE_RATIO : LIQUITY_NORMAL_MODE_RATIO).mul(totalLUSD).div(totalETH).div(100)
|
|
85
95
|
.toString(),
|
|
86
|
-
exposure: getExposure(
|
|
96
|
+
exposure: getExposure(debtInAsset, collateralUsd),
|
|
97
|
+
netApy,
|
|
98
|
+
totalInterestUsd,
|
|
99
|
+
incentiveUsd,
|
|
87
100
|
};
|
|
88
101
|
return payload;
|
|
89
102
|
});
|
package/esm/maker/index.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { Client, PublicClient } from 'viem';
|
|
2
2
|
import { Blockish, EthAddress, EthereumProvider, NetworkNumber, PositionBalances } from '../types/common';
|
|
3
|
-
import { CdpData, CdpInfo } from '../types';
|
|
3
|
+
import { CdpData, CdpInfo, IlkInfo } from '../types';
|
|
4
4
|
export declare const _getMakerAccountBalances: (provider: PublicClient, network: NetworkNumber, block: Blockish, addressMapping: boolean, cdpId: string, _managerAddress?: EthAddress) => Promise<PositionBalances>;
|
|
5
5
|
export declare const getMakerAccountBalances: (provider: EthereumProvider, network: NetworkNumber, block: Blockish, addressMapping: boolean, cdpId: string, _managerAddress?: EthAddress) => Promise<PositionBalances>;
|
|
6
6
|
export declare const _getUserCdps: (provider: Client, network: NetworkNumber, userAddress: EthAddress) => Promise<CdpInfo[]>;
|
|
7
7
|
export declare const getUserCdps: (provider: EthereumProvider, network: NetworkNumber, userAddress: EthAddress) => Promise<CdpInfo[]>;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const _getMakerIlksData: (provider: Client, network: NetworkNumber, ilkLabels: string[]) => Promise<Record<string, IlkInfo>>;
|
|
9
|
+
export declare const getMakerIlksData: (provider: EthereumProvider, network: NetworkNumber, ilkLabels: string[]) => Promise<Record<string, IlkInfo>>;
|
|
10
|
+
/**
|
|
11
|
+
* @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
|
|
12
|
+
*/
|
|
13
|
+
export declare const _getMakerCdpData: (provider: Client, network: NetworkNumber, cdp: CdpInfo, ilkInfo?: IlkInfo) => Promise<CdpData>;
|
|
9
14
|
export declare const getMakerCdpData: (provider: EthereumProvider, network: NetworkNumber, cdp: CdpInfo) => Promise<CdpData>;
|
package/esm/maker/index.js
CHANGED
|
@@ -8,13 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import Dec from 'decimal.js';
|
|
11
|
-
import { assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset, } from '@defisaver/tokens';
|
|
11
|
+
import { assetAmountInEth, bytesToString, getAssetInfo, ilkToAsset, stringToBytes, } from '@defisaver/tokens';
|
|
12
12
|
import { getConfigContractAddress, McdDogContractViem, McdGetCdpsContractViem, McdJugContractViem, McdSpotterContractViem, McdVatContractViem, McdViewContractViem, } from '../contracts';
|
|
13
|
-
import { CdpType } from '../types';
|
|
13
|
+
import { CdpType, } from '../types';
|
|
14
14
|
import { wethToEth } from '../services/utils';
|
|
15
15
|
import { parseCollateralInfo } from '../helpers/makerHelpers';
|
|
16
16
|
import { getViemProvider, setViemBlockNumber } from '../services/viem';
|
|
17
|
-
import { getExposure } from '../moneymarket';
|
|
17
|
+
import { getExposure, getSafetyRatioFromCollateralRatio } from '../moneymarket';
|
|
18
|
+
import { calculateNetApyFromRates, getStakingApy, STAKING_ASSETS } from '../staking';
|
|
18
19
|
export const _getMakerAccountBalances = (provider, network, block, addressMapping, cdpId, _managerAddress) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
20
|
let balances = {
|
|
20
21
|
collateral: {},
|
|
@@ -38,7 +39,7 @@ export const _getMakerAccountBalances = (provider, network, block, addressMappin
|
|
|
38
39
|
// [urn, owner, userAddr, ilk, collateral, debt]
|
|
39
40
|
const cdpInfo = yield viewContract.read.getCdpInfo((needsIlk ? [managerAddress, cdpId, ilk] : [cdpId]), setViemBlockNumber(block));
|
|
40
41
|
cdpInfo.ilk = cdpInfo[3];
|
|
41
|
-
const [par, [_, mat], [artGlobal, rate, spot, line], [duty], futureRate, chop,] = yield Promise.all([
|
|
42
|
+
const [par, [_, mat], [artGlobal, rate, spot, line, dust], [duty], futureRate, chop,] = yield Promise.all([
|
|
42
43
|
spotterContract.read.par(setViemBlockNumber(block)),
|
|
43
44
|
spotterContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
|
|
44
45
|
vatContract.read.ilks(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
|
|
@@ -46,7 +47,7 @@ export const _getMakerAccountBalances = (provider, network, block, addressMappin
|
|
|
46
47
|
jugContract.read.drip(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
|
|
47
48
|
dogContract.read.chop(needsIlk ? [ilk] : [cdpInfo.ilk], setViemBlockNumber(block)),
|
|
48
49
|
]);
|
|
49
|
-
const ilkInfo = parseCollateralInfo(needsIlk ? ilk : cdpInfo.ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), duty.toString(), futureRate.toString(), chop.toString());
|
|
50
|
+
const ilkInfo = parseCollateralInfo(needsIlk ? ilk : cdpInfo.ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), dust.toString(), duty.toString(), futureRate.toString(), chop.toString());
|
|
50
51
|
const collateral = cdpInfo[4];
|
|
51
52
|
const debt = cdpInfo[5];
|
|
52
53
|
const asset = wethToEth(ilkToAsset(needsIlk ? ilk : cdpInfo.ilk));
|
|
@@ -80,22 +81,38 @@ export const _getUserCdps = (provider, network, userAddress) => __awaiter(void 0
|
|
|
80
81
|
return parsedStandardCdps;
|
|
81
82
|
});
|
|
82
83
|
export const getUserCdps = (provider, network, userAddress) => __awaiter(void 0, void 0, void 0, function* () { return _getUserCdps(getViemProvider(provider, network), network, userAddress); });
|
|
83
|
-
export const
|
|
84
|
+
export const _getMakerIlksData = (provider, network, ilkLabels) => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
85
|
const vatContract = McdVatContractViem(provider, network);
|
|
85
86
|
const spotterContract = McdSpotterContractViem(provider, network);
|
|
86
87
|
const dogContract = McdDogContractViem(provider, network);
|
|
87
88
|
const jugContract = McdJugContractViem(provider, network);
|
|
88
|
-
const
|
|
89
|
+
const par = yield spotterContract.read.par();
|
|
90
|
+
const ilksInfo = yield Promise.all(ilkLabels.map((ilkLabel) => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
const ilk = stringToBytes(ilkLabel);
|
|
92
|
+
const [[_, mat], [artGlobal, rate, spot, line, dust], [duty], futureRate, chop,] = yield Promise.all([
|
|
93
|
+
spotterContract.read.ilks([ilk]),
|
|
94
|
+
vatContract.read.ilks([ilk]),
|
|
95
|
+
jugContract.read.ilks([ilk]),
|
|
96
|
+
jugContract.read.drip([ilk]),
|
|
97
|
+
dogContract.read.chop([ilk]),
|
|
98
|
+
]);
|
|
99
|
+
return parseCollateralInfo(ilk, par.toString(), mat.toString(), artGlobal.toString(), rate.toString(), spot.toString(), line.toString(), dust.toString(), duty.toString(), futureRate.toString(), chop.toString());
|
|
100
|
+
})));
|
|
101
|
+
return Object.fromEntries(ilksInfo.map((ilkInfo) => [ilkInfo.ilkLabel, ilkInfo]));
|
|
102
|
+
});
|
|
103
|
+
export const getMakerIlksData = (provider, network, ilkLabels) => __awaiter(void 0, void 0, void 0, function* () { return _getMakerIlksData(getViemProvider(provider, network, { batch: { multicall: true } }), network, ilkLabels); });
|
|
104
|
+
/**
|
|
105
|
+
* @param ilkInfo optional precomputed ilk data (from `_getMakerIlksData`); when provided the per-ilk reads are skipped
|
|
106
|
+
*/
|
|
107
|
+
export const _getMakerCdpData = (provider, network, cdp, ilkInfo) => __awaiter(void 0, void 0, void 0, function* () {
|
|
108
|
+
const vatContract = McdVatContractViem(provider, network);
|
|
109
|
+
const [[ink, art], coll, fetchedIlkInfo, collStakingApy,] = yield Promise.all([
|
|
89
110
|
vatContract.read.urns([cdp.ilk, cdp.urn]),
|
|
90
111
|
vatContract.read.gem([cdp.ilk, cdp.urn]),
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
vatContract.read.ilks([cdp.ilk]),
|
|
94
|
-
jugContract.read.ilks([cdp.ilk]),
|
|
95
|
-
jugContract.read.drip([cdp.ilk]),
|
|
96
|
-
dogContract.read.chop([cdp.ilk]),
|
|
112
|
+
ilkInfo || _getMakerIlksData(provider, network, [cdp.ilkLabel]).then((ilks) => ilks[cdp.ilkLabel]),
|
|
113
|
+
STAKING_ASSETS.includes(cdp.asset) ? getStakingApy(cdp.asset) : Promise.resolve('0'),
|
|
97
114
|
]);
|
|
98
|
-
const collInfo =
|
|
115
|
+
const collInfo = fetchedIlkInfo;
|
|
99
116
|
const collateral = assetAmountInEth(ink.toString(), `MCD-${cdp.asset}`);
|
|
100
117
|
const collateralUsd = new Dec(collateral).mul(collInfo.assetPrice).toString();
|
|
101
118
|
const debt = new Dec(art).times(collInfo.currentRate).div(1e27).floor()
|
|
@@ -107,7 +124,16 @@ export const _getMakerCdpData = (provider, network, cdp) => __awaiter(void 0, vo
|
|
|
107
124
|
.toString();
|
|
108
125
|
if (new Dec(debt).eq(0))
|
|
109
126
|
ratio = '0';
|
|
127
|
+
const safetyRatio = getSafetyRatioFromCollateralRatio(ratio, collInfo.liqPercent);
|
|
110
128
|
const debtTooLow = new Dec(debt).gt(0) && new Dec(assetAmountInEth(debt, 'DAI')).lt(collInfo.minDebt);
|
|
129
|
+
// DAI debt accrues the ilk's stability fee. Collateral earns nothing inside the vault, except for the
|
|
130
|
+
// native yield of staked collateral (e.g. wstETH), which is tracked as an incentive.
|
|
131
|
+
const { netApy, totalInterestUsd, incentiveUsd } = calculateNetApyFromRates({
|
|
132
|
+
suppliedUsd: collateralUsd,
|
|
133
|
+
borrowedUsd: assetAmountInEth(debt, 'DAI'),
|
|
134
|
+
borrowRate: collInfo.stabilityFee.toString(),
|
|
135
|
+
incentives: [{ apy: collStakingApy, amountUsd: collateralUsd }],
|
|
136
|
+
});
|
|
111
137
|
return {
|
|
112
138
|
owner: cdp.owner,
|
|
113
139
|
id: cdp.id.toString(),
|
|
@@ -126,6 +152,7 @@ export const _getMakerCdpData = (provider, network, cdp) => __awaiter(void 0, vo
|
|
|
126
152
|
debtAssetMarketPrice: '1',
|
|
127
153
|
liquidationPrice,
|
|
128
154
|
ratio,
|
|
155
|
+
safetyRatio,
|
|
129
156
|
liqRatio: collInfo.liqRatio.toString(),
|
|
130
157
|
liqPercent: parseFloat(collInfo.liqPercent.toString()),
|
|
131
158
|
assetPrice: collInfo.assetPrice,
|
|
@@ -141,6 +168,9 @@ export const _getMakerCdpData = (provider, network, cdp) => __awaiter(void 0, vo
|
|
|
141
168
|
liquidationFee: collInfo.liquidationFee,
|
|
142
169
|
lastUpdated: Date.now(),
|
|
143
170
|
exposure: getExposure(assetAmountInEth(debt, 'DAI'), collateralUsd),
|
|
171
|
+
netApy,
|
|
172
|
+
totalInterestUsd,
|
|
173
|
+
incentiveUsd,
|
|
144
174
|
};
|
|
145
175
|
});
|
|
146
176
|
export const getMakerCdpData = (provider, network, cdp) => __awaiter(void 0, void 0, void 0, function* () { return _getMakerCdpData(getViemProvider(provider, network), network, cdp); });
|
package/esm/markets/index.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export { LlamaLendMarkets } from './llamaLend';
|
|
|
8
8
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
9
9
|
export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
|
|
10
10
|
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|
|
11
|
+
export { MakerActiveIlks } from './maker';
|
package/esm/markets/index.js
CHANGED
|
@@ -8,3 +8,4 @@ export { LlamaLendMarkets } from './llamaLend';
|
|
|
8
8
|
export { LiquityV2Markets, findLiquityV2MarketByAddress } from './liquityV2';
|
|
9
9
|
export { FluidMarkets, getFluidVersionsDataForNetwork, getFluidMarketInfoById, getFTokenAddress, getFluidMarketInfoByAddress, } from './fluid';
|
|
10
10
|
export { AaveV4Spokes, findAaveV4SpokeByAddress } from './aaveV4';
|
|
11
|
+
export { MakerActiveIlks } from './maker';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const MakerActiveIlks: string[];
|
|
@@ -11,3 +11,12 @@ export declare const isLeveragedPos: (usedAssets: MMUsedAssets, dustLimit?: numb
|
|
|
11
11
|
};
|
|
12
12
|
export declare const aprToApy: (interest: string | number, frequency?: number) => string;
|
|
13
13
|
export declare const getExposure: (borrowedUsd: string, suppliedUsd: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* A collateral ratio rebased so that 100 means "sitting exactly on the liquidation ratio": the scale the
|
|
16
|
+
* shared `safetyRatio` field assumes. Protocols that liquidate on a raw collateral ratio (Maker at the ilk's
|
|
17
|
+
* liquidation ratio, Liquity at 110%, crvUSD/LlamaLend at the band-derived minimum) pass through here.
|
|
18
|
+
*
|
|
19
|
+
* Yields '0' when the liquidation ratio isn't available (or is 0), the "no signal" value consumers already recognise.
|
|
20
|
+
* Mirrors `getSafetyRatioFromCollateralRatio` on the client.
|
|
21
|
+
*/
|
|
22
|
+
export declare const getSafetyRatioFromCollateralRatio: (collateralRatio: string | number | undefined, liquidationRatio: string | number | undefined) => string;
|
|
@@ -88,3 +88,14 @@ export const getExposure = (borrowedUsd, suppliedUsd) => {
|
|
|
88
88
|
const balanceUsd = new Dec(suppliedUsd).sub(borrowedUsd).toString();
|
|
89
89
|
return new Dec(suppliedUsd).div(balanceUsd).toDecimalPlaces(2).toString();
|
|
90
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* A collateral ratio rebased so that 100 means "sitting exactly on the liquidation ratio": the scale the
|
|
93
|
+
* shared `safetyRatio` field assumes. Protocols that liquidate on a raw collateral ratio (Maker at the ilk's
|
|
94
|
+
* liquidation ratio, Liquity at 110%, crvUSD/LlamaLend at the band-derived minimum) pass through here.
|
|
95
|
+
*
|
|
96
|
+
* Yields '0' when the liquidation ratio isn't available (or is 0), the "no signal" value consumers already recognise.
|
|
97
|
+
* Mirrors `getSafetyRatioFromCollateralRatio` on the client.
|
|
98
|
+
*/
|
|
99
|
+
export const getSafetyRatioFromCollateralRatio = (collateralRatio, liquidationRatio) => (+(liquidationRatio !== null && liquidationRatio !== void 0 ? liquidationRatio : 0) > 0
|
|
100
|
+
? new Dec(collateralRatio || 0).div(liquidationRatio).mul(100).toString()
|
|
101
|
+
: '0');
|
package/esm/portfolio/index.d.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { EthAddress, EthereumProvider, NetworkNumber } from '../types/common';
|
|
2
|
-
import { PortfolioPositionsData } from '../types';
|
|
2
|
+
import { PortfolioMarketsData, PortfolioPositionsData } from '../types';
|
|
3
3
|
export declare function getPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean): Promise<{
|
|
4
4
|
positions: PortfolioPositionsData;
|
|
5
5
|
stakingPositions: any;
|
|
6
6
|
rewardsData: any;
|
|
7
7
|
markets: any;
|
|
8
8
|
}>;
|
|
9
|
+
export declare function getShifterPortfolioData(provider: EthereumProvider, network: NetworkNumber, defaultProvider: EthereumProvider, addresses: EthAddress[], isSim?: boolean): Promise<{
|
|
10
|
+
positions: PortfolioPositionsData;
|
|
11
|
+
markets: PortfolioMarketsData;
|
|
12
|
+
}>;
|
|
9
13
|
export * from './discovery';
|