@defisaver/positions-sdk 0.0.30 → 0.0.33
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/config/contracts.d.ts +1023 -41
- package/cjs/config/contracts.js +185 -44
- package/cjs/constants/index.d.ts +2 -0
- package/cjs/constants/index.js +3 -1
- package/cjs/contracts.d.ts +2 -0
- package/cjs/contracts.js +7 -11
- package/cjs/curveUsd/index.js +1 -1
- package/cjs/helpers/curveUsdHelpers/index.d.ts +2 -1
- package/cjs/helpers/curveUsdHelpers/index.js +25 -17
- package/cjs/helpers/index.d.ts +1 -0
- package/cjs/helpers/index.js +2 -1
- package/cjs/helpers/morphoBlueHelpers/index.d.ts +7 -0
- package/cjs/helpers/morphoBlueHelpers/index.js +41 -0
- package/cjs/index.d.ts +2 -1
- package/cjs/index.js +3 -1
- package/cjs/markets/index.d.ts +1 -0
- package/cjs/markets/index.js +3 -1
- package/cjs/markets/morphoBlue/index.d.ts +6 -0
- package/cjs/markets/morphoBlue/index.js +24 -0
- package/cjs/moneymarket/moneymarketCommonService.js +1 -1
- package/cjs/morphoBlue/index.d.ts +5 -0
- package/cjs/morphoBlue/index.js +153 -0
- package/cjs/services/utils.d.ts +4 -0
- package/cjs/services/utils.js +13 -1
- package/cjs/types/common.d.ts +1 -1
- package/cjs/types/contracts/generated/CrvUSDView.d.ts +30 -4
- package/cjs/types/contracts/generated/FeedRegistry.d.ts +182 -0
- package/cjs/types/contracts/generated/FeedRegistry.js +5 -0
- package/cjs/types/contracts/generated/MorphoBlueView.d.ts +122 -0
- package/cjs/types/contracts/generated/MorphoBlueView.js +5 -0
- package/cjs/types/contracts/generated/index.d.ts +2 -0
- package/cjs/types/curveUsd.d.ts +6 -0
- package/cjs/types/index.d.ts +1 -0
- package/cjs/types/index.js +1 -0
- package/cjs/types/morphoBlue.d.ts +74 -0
- package/cjs/types/morphoBlue.js +7 -0
- package/esm/config/contracts.d.ts +1023 -41
- package/esm/config/contracts.js +185 -44
- package/esm/constants/index.d.ts +2 -0
- package/esm/constants/index.js +2 -0
- package/esm/contracts.d.ts +2 -0
- package/esm/contracts.js +6 -10
- package/esm/curveUsd/index.js +1 -1
- package/esm/helpers/curveUsdHelpers/index.d.ts +2 -1
- package/esm/helpers/curveUsdHelpers/index.js +26 -18
- package/esm/helpers/index.d.ts +1 -0
- package/esm/helpers/index.js +1 -0
- package/esm/helpers/morphoBlueHelpers/index.d.ts +7 -0
- package/esm/helpers/morphoBlueHelpers/index.js +34 -0
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/markets/index.d.ts +1 -0
- package/esm/markets/index.js +1 -0
- package/esm/markets/morphoBlue/index.d.ts +6 -0
- package/esm/markets/morphoBlue/index.js +19 -0
- package/esm/moneymarket/moneymarketCommonService.js +1 -1
- package/esm/morphoBlue/index.d.ts +5 -0
- package/esm/morphoBlue/index.js +145 -0
- package/esm/services/utils.d.ts +4 -0
- package/esm/services/utils.js +11 -0
- package/esm/types/common.d.ts +1 -1
- package/esm/types/contracts/generated/CrvUSDView.d.ts +30 -4
- package/esm/types/contracts/generated/FeedRegistry.d.ts +182 -0
- package/esm/types/contracts/generated/FeedRegistry.js +4 -0
- package/esm/types/contracts/generated/MorphoBlueView.d.ts +122 -0
- package/esm/types/contracts/generated/MorphoBlueView.js +4 -0
- package/esm/types/contracts/generated/index.d.ts +2 -0
- package/esm/types/curveUsd.d.ts +6 -0
- package/esm/types/index.d.ts +1 -0
- package/esm/types/index.js +1 -0
- package/esm/types/morphoBlue.d.ts +74 -0
- package/esm/types/morphoBlue.js +4 -0
- 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 +817 -676
- package/src/constants/index.ts +6 -4
- package/src/contracts.ts +125 -127
- 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 +40 -32
- package/src/helpers/index.ts +7 -6
- package/src/helpers/makerHelpers/index.ts +94 -94
- package/src/helpers/morphoBlueHelpers/index.ts +47 -0
- package/src/helpers/sparkHelpers/index.ts +106 -106
- package/src/index.ts +42 -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 +24 -24
- package/src/markets/compound/index.ts +141 -141
- package/src/markets/compound/marketsAssets.ts +48 -48
- package/src/markets/curveUsd/index.ts +69 -69
- package/src/markets/index.ts +5 -4
- package/src/markets/morphoBlue/index.ts +21 -0
- package/src/markets/spark/index.ts +29 -29
- package/src/markets/spark/marketAssets.ts +10 -10
- package/src/moneymarket/moneymarketCommonService.ts +75 -75
- package/src/morphoAaveV2/index.ts +255 -255
- package/src/morphoAaveV3/index.ts +619 -619
- package/src/morphoBlue/index.ts +166 -0
- 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 +48 -35
- package/src/spark/index.ts +422 -422
- 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/contracts/generated/CrvUSDView.ts +43 -8
- package/src/types/contracts/generated/FeedRegistry.ts +337 -0
- package/src/types/contracts/generated/MorphoBlueView.ts +171 -0
- package/src/types/contracts/generated/index.ts +2 -0
- package/src/types/curveUsd.ts +118 -112
- package/src/types/index.ts +8 -7
- package/src/types/liquity.ts +30 -30
- package/src/types/maker.ts +50 -50
- package/src/types/morphoBlue.ts +80 -0
- package/src/types/spark.ts +106 -106
- package/yarn-error.log +64 -0
- package/src/morpho/markets.ts +0 -39
package/cjs/contracts.js
CHANGED
|
@@ -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.USDCPriceFeedContract = exports.COMPPriceFeedContract = exports.ETHPriceFeedContract = exports.ChickenBondsManagerContract = exports.ChickenBondsViewContract = exports.McdVatContract = exports.McdJugContract = exports.McdDogContract = exports.McdSpotterContract = exports.McdViewContract = exports.LiquityActivePoolContract = exports.LiquityPriceFeedContract = exports.LiquityTroveManagerContract = exports.LiquityCollSurplusPoolContract = exports.LiquityViewContract = exports.CrvUSDFactoryContract = exports.CrvUSDViewContract = exports.SparkViewContract = exports.SparkIncentiveDataProviderContract = exports.MorphoAaveV2ViewContract = exports.PotContract = exports.ComptrollerContract = exports.CompoundLoanInfoContract = exports.AaveLoanInfoV2Contract = exports.wstETHContract = exports.CompV3ViewContract = exports.BalanceScannerContract = exports.REthContract = exports.CbEthContract = exports.LidoContract = exports.GhoTokenContract = exports.AaveIncentiveDataProviderV3Contract = exports.AaveV3ViewContract = exports.UniMulticallContract = exports.createContractWrapper = exports.getErc20Contract = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
|
|
6
|
+
exports.MorphoBlueViewContract = exports.FeedRegistryContract = exports.USDCPriceFeedContract = exports.COMPPriceFeedContract = exports.ETHPriceFeedContract = exports.ChickenBondsManagerContract = exports.ChickenBondsViewContract = exports.McdVatContract = exports.McdJugContract = exports.McdDogContract = exports.McdSpotterContract = exports.McdViewContract = exports.LiquityActivePoolContract = exports.LiquityPriceFeedContract = exports.LiquityTroveManagerContract = exports.LiquityCollSurplusPoolContract = exports.LiquityViewContract = exports.CrvUSDFactoryContract = exports.CrvUSDViewContract = exports.SparkViewContract = exports.SparkIncentiveDataProviderContract = exports.MorphoAaveV2ViewContract = exports.PotContract = exports.ComptrollerContract = exports.CompoundLoanInfoContract = exports.AaveLoanInfoV2Contract = exports.wstETHContract = exports.CompV3ViewContract = exports.BalanceScannerContract = exports.REthContract = exports.CbEthContract = exports.LidoContract = exports.GhoTokenContract = exports.AaveIncentiveDataProviderV3Contract = exports.AaveV3ViewContract = exports.UniMulticallContract = exports.createContractWrapper = exports.getErc20Contract = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
|
|
7
7
|
const contracts_1 = __importDefault(require("./config/contracts"));
|
|
8
8
|
const contractConfig = contracts_1.default;
|
|
9
9
|
const getConfigContractAddress = (name, network, block) => {
|
|
@@ -15,12 +15,9 @@ const getConfigContractAddress = (name, network, block) => {
|
|
|
15
15
|
}
|
|
16
16
|
const oldVersions = (networkData === null || networkData === void 0 ? void 0 : networkData.oldVersions) || {};
|
|
17
17
|
// Versions are ordered from oldest to the newest
|
|
18
|
-
for (const [createdBlock,
|
|
18
|
+
for (const [createdBlock, oldVersionObject] of Object.entries(oldVersions).reverse()) {
|
|
19
19
|
if (block >= Number(createdBlock)) {
|
|
20
|
-
|
|
21
|
-
return addressOrObject.address;
|
|
22
|
-
}
|
|
23
|
-
return addressOrObject;
|
|
20
|
+
return oldVersionObject.address;
|
|
24
21
|
}
|
|
25
22
|
}
|
|
26
23
|
}
|
|
@@ -36,12 +33,9 @@ const getConfigContractAbi = (name, network, block) => {
|
|
|
36
33
|
}
|
|
37
34
|
const oldVersions = (networkData === null || networkData === void 0 ? void 0 : networkData.oldVersions) || {};
|
|
38
35
|
// Versions are ordered from oldest to the newest
|
|
39
|
-
for (const [createdBlock,
|
|
36
|
+
for (const [createdBlock, oldVersionObject] of Object.entries(oldVersions).reverse()) {
|
|
40
37
|
if (block >= Number(createdBlock)) {
|
|
41
|
-
|
|
42
|
-
return addressOrObject.abi;
|
|
43
|
-
}
|
|
44
|
-
return latestAbi;
|
|
38
|
+
return oldVersionObject.abi;
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
41
|
}
|
|
@@ -90,3 +84,5 @@ exports.ChickenBondsManagerContract = createContractFromConfigFunc('ChickenBonds
|
|
|
90
84
|
exports.ETHPriceFeedContract = createContractFromConfigFunc('ETHPriceFeed');
|
|
91
85
|
exports.COMPPriceFeedContract = createContractFromConfigFunc('COMPPriceFeed');
|
|
92
86
|
exports.USDCPriceFeedContract = createContractFromConfigFunc('USDCPriceFeed');
|
|
87
|
+
exports.FeedRegistryContract = createContractFromConfigFunc('FeedRegistry');
|
|
88
|
+
exports.MorphoBlueViewContract = createContractFromConfigFunc('MorphoBlueView');
|
package/cjs/curveUsd/index.js
CHANGED
|
@@ -187,7 +187,7 @@ const getCurveUsdUserData = (web3, network, address, selectedMarket, activeBand)
|
|
|
187
187
|
priceHigh,
|
|
188
188
|
priceLow, liquidationDiscount: (0, tokens_1.assetAmountInEth)(data.liquidationDiscount), numOfBands: data.N, usedAssets,
|
|
189
189
|
status }), (0, curveUsdHelpers_1.getCrvUsdAggregatedData)({
|
|
190
|
-
loanExists: data.loanExists, usedAssets, network: common_1.NetworkNumber.Eth, selectedMarket,
|
|
190
|
+
loanExists: data.loanExists, usedAssets, network: common_1.NetworkNumber.Eth, selectedMarket, numOfBands: data.N,
|
|
191
191
|
})), { userBands });
|
|
192
192
|
});
|
|
193
193
|
exports.getCurveUsdUserData = getCurveUsdUserData;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CrvUSDAggregatedPositionData, CrvUSDMarketData, CrvUSDUsedAssets } from '../../types';
|
|
2
2
|
import { NetworkNumber } from '../../types/common';
|
|
3
|
-
export declare const getCrvUsdAggregatedData: ({ loanExists, usedAssets, network, selectedMarket, ...rest }: {
|
|
3
|
+
export declare const getCrvUsdAggregatedData: ({ loanExists, usedAssets, network, selectedMarket, numOfBands, ...rest }: {
|
|
4
4
|
loanExists: boolean;
|
|
5
5
|
usedAssets: CrvUSDUsedAssets;
|
|
6
6
|
network: NetworkNumber;
|
|
7
7
|
selectedMarket: CrvUSDMarketData;
|
|
8
|
+
numOfBands: number | string;
|
|
8
9
|
}) => CrvUSDAggregatedPositionData;
|
|
@@ -17,26 +17,34 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
17
|
exports.getCrvUsdAggregatedData = void 0;
|
|
18
18
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
19
19
|
const moneymarket_1 = require("../../moneymarket");
|
|
20
|
+
const utils_1 = require("../../services/utils");
|
|
20
21
|
const getCrvUsdAggregatedData = (_a) => {
|
|
21
|
-
var
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
var _b;
|
|
23
|
+
var { loanExists, usedAssets, network, selectedMarket, numOfBands } = _a, rest = __rest(_a, ["loanExists", "usedAssets", "network", "selectedMarket", "numOfBands"]);
|
|
24
|
+
const payload = {};
|
|
25
|
+
payload.supplied = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ supplied }) => supplied); // this is wrong if we are in soft-liquidations
|
|
26
|
+
payload.borrowed = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowed }) => borrowed);
|
|
27
|
+
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
28
|
+
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
29
|
+
payload.ratio = loanExists
|
|
30
|
+
? new decimal_js_1.default(payload.suppliedUsd)
|
|
31
|
+
.dividedBy(payload.borrowedUsd)
|
|
29
32
|
.times(100)
|
|
30
33
|
.toString()
|
|
31
34
|
: '0';
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
// this is all approximation
|
|
36
|
+
payload.minAllowedRatio = (0, utils_1.mapRange)(numOfBands, 4, 50, 115, 140); // collateral ratio
|
|
37
|
+
payload.collFactor = new decimal_js_1.default(1).div(payload.minAllowedRatio).mul(100).toString(); // collateral factor = 1 / collateral ratio
|
|
38
|
+
// only take in consideration collAsset
|
|
39
|
+
payload.borrowLimitUsd = ((_b = usedAssets === null || usedAssets === void 0 ? void 0 : usedAssets[selectedMarket.collAsset]) === null || _b === void 0 ? void 0 : _b.isSupplied)
|
|
40
|
+
? new decimal_js_1.default(usedAssets[selectedMarket.collAsset].suppliedUsd).mul(payload.collFactor).toString()
|
|
41
|
+
: '0';
|
|
42
|
+
const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
|
|
43
|
+
payload.leveragedType = leveragedType;
|
|
44
|
+
if (leveragedType !== '') {
|
|
45
|
+
payload.leveragedAsset = leveragedAsset;
|
|
46
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, usedAssets[selectedMarket.collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
|
|
47
|
+
}
|
|
48
|
+
return payload;
|
|
41
49
|
};
|
|
42
50
|
exports.getCrvUsdAggregatedData = getCrvUsdAggregatedData;
|
package/cjs/helpers/index.d.ts
CHANGED
|
@@ -4,3 +4,4 @@ export * as sparkHelpers from './sparkHelpers';
|
|
|
4
4
|
export * as curveUsdHelpers from './curveUsdHelpers';
|
|
5
5
|
export * as makerHelpers from './makerHelpers';
|
|
6
6
|
export * as chickenBondsHelpers from './chickenBondsHelpers';
|
|
7
|
+
export * as morphoBlueHelpers from './morphoBlueHelpers';
|
package/cjs/helpers/index.js
CHANGED
|
@@ -23,10 +23,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.chickenBondsHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
|
|
26
|
+
exports.morphoBlueHelpers = exports.chickenBondsHelpers = exports.makerHelpers = exports.curveUsdHelpers = exports.sparkHelpers = exports.compoundHelpers = exports.aaveHelpers = void 0;
|
|
27
27
|
exports.aaveHelpers = __importStar(require("./aaveHelpers"));
|
|
28
28
|
exports.compoundHelpers = __importStar(require("./compoundHelpers"));
|
|
29
29
|
exports.sparkHelpers = __importStar(require("./sparkHelpers"));
|
|
30
30
|
exports.curveUsdHelpers = __importStar(require("./curveUsdHelpers"));
|
|
31
31
|
exports.makerHelpers = __importStar(require("./makerHelpers"));
|
|
32
32
|
exports.chickenBondsHelpers = __importStar(require("./chickenBondsHelpers"));
|
|
33
|
+
exports.morphoBlueHelpers = __importStar(require("./morphoBlueHelpers"));
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { MMUsedAssets } from '../../types/common';
|
|
2
|
+
import { MorphoBlueAggregatedPositionData, MorphoBlueAssetsData } from '../../types';
|
|
3
|
+
export declare const getMorphoBlueAggregatedPositionData: ({ usedAssets, assetsData, lltv }: {
|
|
4
|
+
usedAssets: MMUsedAssets;
|
|
5
|
+
assetsData: MorphoBlueAssetsData;
|
|
6
|
+
lltv: string;
|
|
7
|
+
}) => MorphoBlueAggregatedPositionData;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getMorphoBlueAggregatedPositionData = void 0;
|
|
7
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
|
+
const moneymarket_1 = require("../../moneymarket");
|
|
9
|
+
const staking_1 = require("../../staking");
|
|
10
|
+
const getMorphoBlueAggregatedPositionData = ({ usedAssets, assetsData, lltv }) => {
|
|
11
|
+
const payload = {};
|
|
12
|
+
payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
|
|
13
|
+
payload.suppliedCollateralUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
|
|
14
|
+
payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
|
|
15
|
+
payload.borrowLimitUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ symbol, suppliedUsd }) => {
|
|
16
|
+
const suppliedUsdAmount = suppliedUsd;
|
|
17
|
+
return new decimal_js_1.default(suppliedUsdAmount).mul(lltv);
|
|
18
|
+
});
|
|
19
|
+
payload.liquidationLimitUsd = payload.borrowLimitUsd;
|
|
20
|
+
const leftToBorrowUsd = new decimal_js_1.default(payload.borrowLimitUsd).sub(payload.borrowedUsd);
|
|
21
|
+
payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
|
|
22
|
+
const { netApy, incentiveUsd, totalInterestUsd } = (0, staking_1.calculateNetApy)(usedAssets, assetsData);
|
|
23
|
+
payload.netApy = netApy;
|
|
24
|
+
payload.incentiveUsd = incentiveUsd;
|
|
25
|
+
payload.totalInterestUsd = totalInterestUsd;
|
|
26
|
+
payload.ltv = new decimal_js_1.default(payload.borrowedUsd).div(payload.suppliedCollateralUsd).toString();
|
|
27
|
+
const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
|
|
28
|
+
payload.leveragedType = leveragedType;
|
|
29
|
+
if (leveragedType !== '') {
|
|
30
|
+
payload.leveragedAsset = leveragedAsset;
|
|
31
|
+
let assetPrice = assetsData[leveragedAsset].price;
|
|
32
|
+
if (leveragedType === 'lsd-leverage') {
|
|
33
|
+
// Treat ETH like a stablecoin in a long stETH position
|
|
34
|
+
payload.leveragedLsdAssetRatio = new decimal_js_1.default(assetsData[leveragedAsset].price).div(assetsData.ETH.price).toDP(18).toString();
|
|
35
|
+
assetPrice = new decimal_js_1.default(assetPrice).div(assetsData.ETH.price).toString();
|
|
36
|
+
}
|
|
37
|
+
payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
|
|
38
|
+
}
|
|
39
|
+
return payload;
|
|
40
|
+
};
|
|
41
|
+
exports.getMorphoBlueAggregatedPositionData = getMorphoBlueAggregatedPositionData;
|
package/cjs/index.d.ts
CHANGED
|
@@ -15,5 +15,6 @@ import * as markets from './markets';
|
|
|
15
15
|
import * as helpers from './helpers';
|
|
16
16
|
import * as chickenBonds from './chickenBonds';
|
|
17
17
|
import * as exchange from './exchange';
|
|
18
|
+
import * as morphoBlue from './morphoBlue';
|
|
18
19
|
export * from './types';
|
|
19
|
-
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, };
|
|
20
|
+
export { aaveV2, aaveV3, morphoAaveV2, morphoAaveV3, compoundV2, compoundV3, spark, curveUsd, liquity, maker, chickenBonds, exchange, staking, multicall, moneymarket, markets, helpers, morphoBlue, };
|
package/cjs/index.js
CHANGED
|
@@ -26,7 +26,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
26
26
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.helpers = exports.markets = exports.moneymarket = exports.multicall = exports.staking = exports.exchange = exports.chickenBonds = exports.maker = exports.liquity = exports.curveUsd = exports.spark = exports.compoundV3 = exports.compoundV2 = exports.morphoAaveV3 = exports.morphoAaveV2 = exports.aaveV3 = exports.aaveV2 = void 0;
|
|
29
|
+
exports.morphoBlue = exports.helpers = exports.markets = exports.moneymarket = exports.multicall = exports.staking = exports.exchange = exports.chickenBonds = exports.maker = exports.liquity = exports.curveUsd = exports.spark = exports.compoundV3 = exports.compoundV2 = exports.morphoAaveV3 = exports.morphoAaveV2 = exports.aaveV3 = exports.aaveV2 = void 0;
|
|
30
30
|
const aaveV3 = __importStar(require("./aaveV3"));
|
|
31
31
|
exports.aaveV3 = aaveV3;
|
|
32
32
|
const morphoAaveV3 = __importStar(require("./morphoAaveV3"));
|
|
@@ -61,4 +61,6 @@ const chickenBonds = __importStar(require("./chickenBonds"));
|
|
|
61
61
|
exports.chickenBonds = chickenBonds;
|
|
62
62
|
const exchange = __importStar(require("./exchange"));
|
|
63
63
|
exports.exchange = exchange;
|
|
64
|
+
const morphoBlue = __importStar(require("./morphoBlue"));
|
|
65
|
+
exports.morphoBlue = morphoBlue;
|
|
64
66
|
__exportStar(require("./types"), exports);
|
package/cjs/markets/index.d.ts
CHANGED
package/cjs/markets/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CrvUsdMarkets = exports.SparkMarkets = exports.CompoundMarkets = exports.AaveMarkets = void 0;
|
|
3
|
+
exports.MorphoBlueMarkets = exports.CrvUsdMarkets = exports.SparkMarkets = exports.CompoundMarkets = exports.AaveMarkets = void 0;
|
|
4
4
|
var aave_1 = require("./aave");
|
|
5
5
|
Object.defineProperty(exports, "AaveMarkets", { enumerable: true, get: function () { return aave_1.AaveMarkets; } });
|
|
6
6
|
var compound_1 = require("./compound");
|
|
@@ -9,3 +9,5 @@ var spark_1 = require("./spark");
|
|
|
9
9
|
Object.defineProperty(exports, "SparkMarkets", { enumerable: true, get: function () { return spark_1.SparkMarkets; } });
|
|
10
10
|
var curveUsd_1 = require("./curveUsd");
|
|
11
11
|
Object.defineProperty(exports, "CrvUsdMarkets", { enumerable: true, get: function () { return curveUsd_1.CrvUsdMarkets; } });
|
|
12
|
+
var morphoBlue_1 = require("./morphoBlue");
|
|
13
|
+
Object.defineProperty(exports, "MorphoBlueMarkets", { enumerable: true, get: function () { return morphoBlue_1.MorphoBlueMarkets; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { MorphoBlueMarketData } from '../../types';
|
|
2
|
+
import { NetworkNumber } from '../../types/common';
|
|
3
|
+
export declare const MORPHO_BLUE_WSTETH_ETH: (networkId?: NetworkNumber) => MorphoBlueMarketData;
|
|
4
|
+
export declare const MorphoBlueMarkets: (networkId: NetworkNumber) => {
|
|
5
|
+
readonly morphobluewstetheth: MorphoBlueMarketData;
|
|
6
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MorphoBlueMarkets = exports.MORPHO_BLUE_WSTETH_ETH = void 0;
|
|
4
|
+
const types_1 = require("../../types");
|
|
5
|
+
const common_1 = require("../../types/common");
|
|
6
|
+
const MORPHO_BLUE_WSTETH_ETH = (networkId = common_1.NetworkNumber.Eth) => ({
|
|
7
|
+
chainIds: [1],
|
|
8
|
+
label: 'Morpho Blue',
|
|
9
|
+
shortLabel: 'wstETH/ETH',
|
|
10
|
+
value: types_1.MorphoBlueVersions.MorphoBlueWstEthEth,
|
|
11
|
+
url: 'default',
|
|
12
|
+
loanToken: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2',
|
|
13
|
+
collateralToken: '0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0',
|
|
14
|
+
oracle: '0x2a01eb9496094da03c4e364def50f5ad1280ad72',
|
|
15
|
+
irm: '0x870aC11D48B15DB9a138Cf899d20F13F79Ba00BC',
|
|
16
|
+
lltv: 0.945,
|
|
17
|
+
// icon: SvgAdapter(protocolIcons.spark),
|
|
18
|
+
protocolName: 'morpho-blue',
|
|
19
|
+
});
|
|
20
|
+
exports.MORPHO_BLUE_WSTETH_ETH = MORPHO_BLUE_WSTETH_ETH;
|
|
21
|
+
const MorphoBlueMarkets = (networkId) => ({
|
|
22
|
+
[types_1.MorphoBlueVersions.MorphoBlueWstEthEth]: (0, exports.MORPHO_BLUE_WSTETH_ETH)(networkId),
|
|
23
|
+
});
|
|
24
|
+
exports.MorphoBlueMarkets = MorphoBlueMarkets;
|
|
@@ -27,7 +27,7 @@ const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borrowLimit
|
|
|
27
27
|
exports.calcLeverageLiqPrice = calcLeverageLiqPrice;
|
|
28
28
|
const calculateBorrowingAssetLimit = (assetBorrowedUsd, borrowLimitUsd) => new decimal_js_1.default(assetBorrowedUsd).div(borrowLimitUsd).times(100).toString();
|
|
29
29
|
exports.calculateBorrowingAssetLimit = calculateBorrowingAssetLimit;
|
|
30
|
-
exports.STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI'];
|
|
30
|
+
exports.STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD'];
|
|
31
31
|
const isLeveragedPos = (usedAssets, dustLimit = 5) => {
|
|
32
32
|
let borrowUnstable = 0;
|
|
33
33
|
let supplyStable = 0;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Web3 from 'web3';
|
|
2
|
+
import { NetworkNumber } from '../types/common';
|
|
3
|
+
import { MorphoBlueMarketData, MorphoBlueMarketInfo, MorphoBluePositionData } from '../types';
|
|
4
|
+
export declare function getMorphoBlueMarketData(web3: Web3, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, mainnetWeb3: Web3): Promise<MorphoBlueMarketInfo>;
|
|
5
|
+
export declare function getMorphoBlueAccountData(web3: Web3, network: NetworkNumber, account: string, selectedMarket: MorphoBlueMarketData, marketInfo: MorphoBlueMarketInfo): Promise<MorphoBluePositionData>;
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.getMorphoBlueAccountData = exports.getMorphoBlueMarketData = void 0;
|
|
16
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
17
|
+
const tokens_1 = require("@defisaver/tokens");
|
|
18
|
+
const contracts_1 = require("../contracts");
|
|
19
|
+
const constants_1 = require("../constants");
|
|
20
|
+
const staking_1 = require("../staking");
|
|
21
|
+
const utils_1 = require("../services/utils");
|
|
22
|
+
const multicall_1 = require("../multicall");
|
|
23
|
+
const morphoBlueHelpers_1 = require("../helpers/morphoBlueHelpers");
|
|
24
|
+
const compound = (ratePerSeconds) => {
|
|
25
|
+
const compounding = new decimal_js_1.default(ratePerSeconds).mul(constants_1.SECONDS_PER_YEAR).toString();
|
|
26
|
+
const apyNumber = Math.expm1(new decimal_js_1.default(compounding).div(constants_1.WAD).toNumber());
|
|
27
|
+
return new decimal_js_1.default(apyNumber).mul(constants_1.WAD).floor().toString();
|
|
28
|
+
};
|
|
29
|
+
const getSupplyRate = (totalSupplyAssets, totalBorrowAssets, borrowRate, fee) => {
|
|
30
|
+
if (totalBorrowAssets === '0' || totalSupplyAssets === '0') {
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
const utillization = new decimal_js_1.default(totalBorrowAssets).mul(constants_1.WAD).div(totalSupplyAssets).ceil()
|
|
34
|
+
.toString();
|
|
35
|
+
const supplyRate = new decimal_js_1.default(utillization).mul(borrowRate).div(constants_1.WAD).ceil()
|
|
36
|
+
.toString();
|
|
37
|
+
const ratePerSecond = new decimal_js_1.default(supplyRate).mul(new decimal_js_1.default(constants_1.WAD).minus(fee)).div(constants_1.WAD).ceil()
|
|
38
|
+
.toString();
|
|
39
|
+
return compound(ratePerSecond);
|
|
40
|
+
};
|
|
41
|
+
const getBorrowRate = (borrowRate, totalBorrowShares) => {
|
|
42
|
+
if (totalBorrowShares === '0') {
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
return compound(borrowRate);
|
|
46
|
+
};
|
|
47
|
+
function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
|
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
|
|
50
|
+
const lltvInWei = new decimal_js_1.default(lltv).mul(constants_1.WAD).toString();
|
|
51
|
+
const loanTokenInfo = (0, tokens_1.getAssetInfoByAddress)(loanToken);
|
|
52
|
+
const collateralTokenInfo = (0, tokens_1.getAssetInfoByAddress)(collateralToken);
|
|
53
|
+
let loanTokenFeedAddress = loanToken;
|
|
54
|
+
if (loanTokenInfo.symbol === 'WETH') {
|
|
55
|
+
const ethAddress = (0, tokens_1.getAssetInfo)('ETH').address;
|
|
56
|
+
loanTokenFeedAddress = ethAddress;
|
|
57
|
+
}
|
|
58
|
+
const FeedRegistryAddress = (0, contracts_1.getConfigContractAddress)('FeedRegistry', network);
|
|
59
|
+
const FeedRegistryAbi = (0, contracts_1.getConfigContractAbi)('FeedRegistry');
|
|
60
|
+
const viewContractAddress = (0, contracts_1.getConfigContractAddress)('MorphoBlueView', network);
|
|
61
|
+
const viewContractAbi = (0, contracts_1.getConfigContractAbi)('MorphoBlueView');
|
|
62
|
+
const multicallCallsObject = [
|
|
63
|
+
{
|
|
64
|
+
target: FeedRegistryAddress,
|
|
65
|
+
abiItem: (0, utils_1.getAbiItem)(FeedRegistryAbi, 'latestAnswer'),
|
|
66
|
+
params: [loanTokenFeedAddress, constants_1.USD_QUOTE],
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
target: viewContractAddress,
|
|
70
|
+
abiItem: (0, utils_1.getAbiItem)(viewContractAbi, 'getMarketInfoNotTuple'),
|
|
71
|
+
params: [loanToken, collateralToken, oracle, irm, lltvInWei],
|
|
72
|
+
},
|
|
73
|
+
];
|
|
74
|
+
const multicallData = yield (0, multicall_1.multicall)(multicallCallsObject, web3, network);
|
|
75
|
+
const loanTokenPrice = multicallData[0][0];
|
|
76
|
+
const marketInfo = multicallData[1][0];
|
|
77
|
+
const supplyRate = getSupplyRate(marketInfo.totalSupplyAssets, marketInfo.totalBorrowAssets, marketInfo.borrowRate, marketInfo.fee);
|
|
78
|
+
const compoundedBorrowRate = getBorrowRate(marketInfo.borrowRate, marketInfo.totalBorrowShares);
|
|
79
|
+
const utillization = new decimal_js_1.default(marketInfo.totalBorrowAssets).div(marketInfo.totalSupplyAssets).mul(100).toString();
|
|
80
|
+
const oracleRate = new decimal_js_1.default(marketInfo.oracle).div(1e36).toString();
|
|
81
|
+
const assetsData = {};
|
|
82
|
+
assetsData[(0, utils_1.wethToEth)(loanTokenInfo.symbol)] = {
|
|
83
|
+
symbol: (0, utils_1.wethToEth)(loanTokenInfo.symbol),
|
|
84
|
+
address: loanToken,
|
|
85
|
+
price: new decimal_js_1.default(loanTokenPrice).div(1e8).toString(),
|
|
86
|
+
supplyRate: new decimal_js_1.default(supplyRate).div(constants_1.WAD).mul(100).toString(),
|
|
87
|
+
borrowRate: new decimal_js_1.default(compoundedBorrowRate).div(constants_1.WAD).mul(100).toString(),
|
|
88
|
+
totalSupply: new decimal_js_1.default(marketInfo.totalSupplyAssets).div(constants_1.WAD).toString(),
|
|
89
|
+
totalBorrow: new decimal_js_1.default(marketInfo.totalBorrowAssets).div(constants_1.WAD).toString(),
|
|
90
|
+
};
|
|
91
|
+
assetsData[(0, utils_1.wethToEth)(collateralTokenInfo.symbol)] = {
|
|
92
|
+
symbol: (0, utils_1.wethToEth)(collateralTokenInfo.symbol),
|
|
93
|
+
address: collateralToken,
|
|
94
|
+
price: new decimal_js_1.default(loanTokenPrice).div(1e8).mul(oracleRate).toString(),
|
|
95
|
+
supplyRate: '0',
|
|
96
|
+
borrowRate: '0',
|
|
97
|
+
};
|
|
98
|
+
if (['wstETH', 'cbETH', 'rETH'].includes(collateralTokenInfo.symbol)) {
|
|
99
|
+
assetsData[collateralTokenInfo.symbol].incentiveSupplyApy = yield (0, staking_1.getStakingApy)(collateralTokenInfo.symbol, mainnetWeb3);
|
|
100
|
+
assetsData[collateralTokenInfo.symbol].incentiveSupplyToken = collateralTokenInfo.symbol;
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
id: marketInfo.id,
|
|
104
|
+
fee: new decimal_js_1.default(marketInfo.fee).div(constants_1.WAD).toString(),
|
|
105
|
+
loanToken: (0, utils_1.wethToEth)(loanTokenInfo.symbol),
|
|
106
|
+
collateralToken: (0, utils_1.wethToEth)(collateralTokenInfo.symbol),
|
|
107
|
+
utillization,
|
|
108
|
+
oracle: oracleRate,
|
|
109
|
+
lltv: new decimal_js_1.default(lltv).toString(),
|
|
110
|
+
assetsData,
|
|
111
|
+
};
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
exports.getMorphoBlueMarketData = getMorphoBlueMarketData;
|
|
115
|
+
function getMorphoBlueAccountData(web3, network, account, selectedMarket, marketInfo) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const { loanToken, collateralToken, oracle, irm, lltv, } = selectedMarket;
|
|
118
|
+
const lltvInWei = new decimal_js_1.default(lltv).mul(constants_1.WAD).toString();
|
|
119
|
+
const marketObject = {
|
|
120
|
+
loanToken, collateralToken, oracle, irm, lltv: lltvInWei,
|
|
121
|
+
};
|
|
122
|
+
const viewContract = (0, contracts_1.MorphoBlueViewContract)(web3, network);
|
|
123
|
+
const loanInfo = yield viewContract.methods.getUserInfo(marketObject, account).call();
|
|
124
|
+
const usedAssets = {};
|
|
125
|
+
const loanTokenInfo = marketInfo.assetsData[marketInfo.loanToken];
|
|
126
|
+
const loanTokenSupplied = new decimal_js_1.default(loanInfo.suppliedInAssets).div(constants_1.WAD).toString();
|
|
127
|
+
const loanTokenBorrowed = new decimal_js_1.default(loanInfo.borrowedInAssets).div(constants_1.WAD).toString();
|
|
128
|
+
usedAssets[marketInfo.loanToken] = {
|
|
129
|
+
symbol: loanTokenInfo.symbol,
|
|
130
|
+
supplied: loanTokenSupplied,
|
|
131
|
+
borrowed: loanTokenBorrowed,
|
|
132
|
+
isSupplied: new decimal_js_1.default(loanInfo.suppliedInAssets).gt(0),
|
|
133
|
+
isBorrowed: new decimal_js_1.default(loanInfo.borrowedInAssets).gt(0),
|
|
134
|
+
collateral: false,
|
|
135
|
+
suppliedUsd: new decimal_js_1.default(loanTokenSupplied).mul(loanTokenInfo.price).toString(),
|
|
136
|
+
borrowedUsd: new decimal_js_1.default(loanTokenBorrowed).mul(loanTokenInfo.price).toString(),
|
|
137
|
+
};
|
|
138
|
+
const collateralTokenInfo = marketInfo.assetsData[marketInfo.collateralToken];
|
|
139
|
+
const collateralTokenSupplied = new decimal_js_1.default(loanInfo.collateral).div(constants_1.WAD).toString();
|
|
140
|
+
usedAssets[marketInfo.collateralToken] = {
|
|
141
|
+
symbol: collateralTokenInfo.symbol,
|
|
142
|
+
supplied: collateralTokenSupplied,
|
|
143
|
+
borrowed: '0',
|
|
144
|
+
isSupplied: new decimal_js_1.default(loanInfo.collateral).gt(0),
|
|
145
|
+
isBorrowed: false,
|
|
146
|
+
collateral: true,
|
|
147
|
+
suppliedUsd: new decimal_js_1.default(collateralTokenSupplied).mul(collateralTokenInfo.price).toString(),
|
|
148
|
+
borrowedUsd: '0',
|
|
149
|
+
};
|
|
150
|
+
return Object.assign({ usedAssets }, (0, morphoBlueHelpers_1.getMorphoBlueAggregatedPositionData)({ usedAssets, assetsData: marketInfo.assetsData, lltv: marketInfo.lltv }));
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.getMorphoBlueAccountData = getMorphoBlueAccountData;
|
package/cjs/services/utils.d.ts
CHANGED
|
@@ -14,3 +14,7 @@ export declare const handleWbtcLegacy: (asset: string) => string;
|
|
|
14
14
|
export declare const wethToEthByAddress: (maybeWethAddr: string, chainId?: NetworkNumber) => string;
|
|
15
15
|
export declare const ethToWethByAddress: (maybeEthAddr: string, chainId?: NetworkNumber) => string;
|
|
16
16
|
export declare const bytesToString: (hex: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
19
|
+
*/
|
|
20
|
+
export declare const mapRange: (input: number | string, minInput: number | string, maxInput: number | string, minOutput: number | string, maxOutput: number | string) => number;
|
package/cjs/services/utils.js
CHANGED
|
@@ -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.bytesToString = exports.ethToWethByAddress = exports.wethToEthByAddress = exports.handleWbtcLegacy = exports.getEthAmountForDecimals = exports.compareAddresses = exports.isAddress = exports.ADDRESS_REGEX = exports.getAbiItem = exports.wstEthToStEth = exports.stEthToWstEth = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.isLayer2Network = void 0;
|
|
6
|
+
exports.mapRange = exports.bytesToString = exports.ethToWethByAddress = exports.wethToEthByAddress = exports.handleWbtcLegacy = exports.getEthAmountForDecimals = exports.compareAddresses = exports.isAddress = exports.ADDRESS_REGEX = exports.getAbiItem = exports.wstEthToStEth = exports.stEthToWstEth = exports.wethToEth = exports.ethToWeth = exports.addToObjectIf = exports.isLayer2Network = void 0;
|
|
7
7
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
8
8
|
const tokens_1 = require("@defisaver/tokens");
|
|
9
9
|
const common_1 = require("../types/common");
|
|
@@ -39,3 +39,15 @@ const bytesToString = (hex) => Buffer.from(hex.replace(/^0x/, ''), 'hex')
|
|
|
39
39
|
// eslint-disable-next-line no-control-regex
|
|
40
40
|
.replace(/\x00/g, '');
|
|
41
41
|
exports.bytesToString = bytesToString;
|
|
42
|
+
/**
|
|
43
|
+
* Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
|
|
44
|
+
*/
|
|
45
|
+
const mapRange = (input, minInput, maxInput, minOutput, maxOutput) => {
|
|
46
|
+
// slope = 1.0 * (output_end - output_start) / (input_end - input_start)
|
|
47
|
+
const inputDiff = new decimal_js_1.default(maxInput).minus(minInput);
|
|
48
|
+
const outputDiff = new decimal_js_1.default(maxOutput).minus(minOutput);
|
|
49
|
+
const slope = new decimal_js_1.default(outputDiff).div(inputDiff);
|
|
50
|
+
// output = output_start + slope * (input - input_start)
|
|
51
|
+
return new decimal_js_1.default(minOutput).plus(new decimal_js_1.default(slope).mul(new decimal_js_1.default(input).minus(minInput))).toDP(2).toNumber();
|
|
52
|
+
};
|
|
53
|
+
exports.mapRange = mapRange;
|
package/cjs/types/common.d.ts
CHANGED
|
@@ -138,7 +138,9 @@ export declare namespace CurveUsdView {
|
|
|
138
138
|
[
|
|
139
139
|
number | string | BN[],
|
|
140
140
|
number | string | BN[]
|
|
141
|
-
]
|
|
141
|
+
],
|
|
142
|
+
number | string | BN,
|
|
143
|
+
boolean
|
|
142
144
|
] | {
|
|
143
145
|
loanExists: boolean;
|
|
144
146
|
collateralPrice: number | string | BN;
|
|
@@ -152,6 +154,8 @@ export declare namespace CurveUsdView {
|
|
|
152
154
|
health: number | string | BN;
|
|
153
155
|
bandRange: [number | string | BN, number | string | BN];
|
|
154
156
|
usersBands: [number | string | BN[], number | string | BN[]];
|
|
157
|
+
collRatio: number | string | BN;
|
|
158
|
+
isInSoftLiquidation: boolean;
|
|
155
159
|
};
|
|
156
160
|
type UserDataStructOutputArray = [
|
|
157
161
|
boolean,
|
|
@@ -171,7 +175,9 @@ export declare namespace CurveUsdView {
|
|
|
171
175
|
[
|
|
172
176
|
string[],
|
|
173
177
|
string[]
|
|
174
|
-
]
|
|
178
|
+
],
|
|
179
|
+
string,
|
|
180
|
+
boolean
|
|
175
181
|
];
|
|
176
182
|
type UserDataStructOutputStruct = {
|
|
177
183
|
loanExists: boolean;
|
|
@@ -186,6 +192,8 @@ export declare namespace CurveUsdView {
|
|
|
186
192
|
health: string;
|
|
187
193
|
bandRange: [string, string];
|
|
188
194
|
usersBands: [string[], string[]];
|
|
195
|
+
collRatio: string;
|
|
196
|
+
isInSoftLiquidation: boolean;
|
|
189
197
|
};
|
|
190
198
|
type UserDataStructOutput = UserDataStructOutputArray & UserDataStructOutputStruct;
|
|
191
199
|
}
|
|
@@ -193,15 +201,33 @@ export interface CrvUSDView extends BaseContract {
|
|
|
193
201
|
constructor(jsonInterface: any[], address?: string, options?: ContractOptions): CrvUSDView;
|
|
194
202
|
clone(): CrvUSDView;
|
|
195
203
|
methods: {
|
|
204
|
+
WBTC_HEALTH_ZAP(): NonPayableTransactionObject<string>;
|
|
205
|
+
WBTC_MARKET(): NonPayableTransactionObject<string>;
|
|
196
206
|
createLoanData(market: string, collateral: number | string | BN, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<CurveUsdView.CreateLoanDataStructOutput>;
|
|
197
207
|
getBandData(market: string, n: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput>;
|
|
198
|
-
|
|
199
|
-
|
|
208
|
+
getBandsData(market: string, from: number | string | BN, to: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
|
|
209
|
+
getBandsDataForPosition(market: string, collateral: number | string | BN, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
|
|
210
|
+
getCollAmountsFromAMM(_controllerAddress: string, _user: string): NonPayableTransactionObject<[
|
|
211
|
+
string,
|
|
212
|
+
string
|
|
213
|
+
] & {
|
|
214
|
+
crvUsdAmount: string;
|
|
215
|
+
collAmount: string;
|
|
216
|
+
}>;
|
|
217
|
+
getCollateralRatio(_user: string, _controllerAddr: string): NonPayableTransactionObject<[
|
|
218
|
+
string,
|
|
219
|
+
boolean
|
|
220
|
+
] & {
|
|
221
|
+
collRatio: string;
|
|
222
|
+
isInSoftLiquidation: boolean;
|
|
223
|
+
}>;
|
|
200
224
|
globalData(market: string): NonPayableTransactionObject<CurveUsdView.GlobalDataStructOutput>;
|
|
201
225
|
healthCalculator(market: string, user: string, collChange: number | string | BN, debtChange: number | string | BN, isFull: boolean, numBands: number | string | BN): NonPayableTransactionObject<string>;
|
|
226
|
+
isControllerValid(_controllerAddr: string): NonPayableTransactionObject<boolean>;
|
|
202
227
|
maxBorrow(market: string, collateral: number | string | BN, N: number | string | BN): NonPayableTransactionObject<string>;
|
|
203
228
|
minCollateral(market: string, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<string>;
|
|
204
229
|
userData(market: string, user: string): NonPayableTransactionObject<CurveUsdView.UserDataStructOutput>;
|
|
230
|
+
userMaxWithdraw(_controllerAddress: string, _user: string): NonPayableTransactionObject<string>;
|
|
205
231
|
};
|
|
206
232
|
events: {
|
|
207
233
|
allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
|