@defisaver/positions-sdk 0.0.24 → 0.0.26

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.
Files changed (36) hide show
  1. package/cjs/config/contracts.d.ts +8 -0
  2. package/cjs/config/contracts.js +6 -4
  3. package/cjs/curveUsd/index.js +1 -1
  4. package/cjs/helpers/curveUsdHelpers/index.d.ts +2 -1
  5. package/cjs/helpers/curveUsdHelpers/index.js +24 -17
  6. package/cjs/moneymarket/moneymarketCommonService.js +1 -1
  7. package/cjs/services/utils.d.ts +4 -0
  8. package/cjs/services/utils.js +13 -1
  9. package/cjs/spark/index.js +1 -0
  10. package/cjs/types/contracts/generated/CrvUSDView.d.ts +30 -4
  11. package/cjs/types/curveUsd.d.ts +6 -0
  12. package/esm/config/contracts.d.ts +8 -0
  13. package/esm/config/contracts.js +6 -4
  14. package/esm/curveUsd/index.js +1 -1
  15. package/esm/helpers/curveUsdHelpers/index.d.ts +2 -1
  16. package/esm/helpers/curveUsdHelpers/index.js +25 -18
  17. package/esm/moneymarket/moneymarketCommonService.js +1 -1
  18. package/esm/services/utils.d.ts +4 -0
  19. package/esm/services/utils.js +11 -0
  20. package/esm/spark/index.js +1 -0
  21. package/esm/types/contracts/generated/CrvUSDView.d.ts +30 -4
  22. package/esm/types/curveUsd.d.ts +6 -0
  23. package/package.json +1 -1
  24. package/src/config/contracts.js +6 -4
  25. package/src/curveUsd/index.ts +1 -1
  26. package/src/helpers/curveUsdHelpers/index.ts +28 -20
  27. package/src/moneymarket/moneymarketCommonService.ts +1 -1
  28. package/src/services/utils.ts +14 -1
  29. package/src/spark/index.ts +1 -0
  30. package/src/types/contracts/generated/CrvUSDView.ts +43 -8
  31. package/src/types/curveUsd.ts +6 -0
  32. package/yarn-error.log +64 -0
  33. package/.yarn/releases/yarn-1.22.1.cjs +0 -147386
  34. package/.yarn/releases/yarn-1.22.1.js +0 -147386
  35. package/.yarnrc.yml +0 -1
  36. package/package-lock.json +0 -12896
@@ -2913,6 +2913,12 @@ export namespace crvUSDsfrxETHAmm {
2913
2913
  }
2914
2914
  export namespace crvUSDView {
2915
2915
  let abi_50: ({
2916
+ inputs: never[];
2917
+ name: string;
2918
+ type: string;
2919
+ outputs?: undefined;
2920
+ stateMutability?: undefined;
2921
+ } | {
2916
2922
  inputs: {
2917
2923
  internalType: string;
2918
2924
  name: string;
@@ -2963,6 +2969,8 @@ export namespace crvUSDView {
2963
2969
  createdBlock: number;
2964
2970
  oldVersions: {
2965
2971
  "17657253": string;
2972
+ "17683243": string;
2973
+ "18419795": string;
2966
2974
  };
2967
2975
  };
2968
2976
  };
@@ -528,13 +528,15 @@ module.exports = {
528
528
  }
529
529
  },
530
530
  "crvUSDView": {
531
- "abi": [{ "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "createLoanData", "outputs": [{ "components": [{ "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "uint256", "name": "minColl", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrow", "type": "uint256" }, { "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "internalType": "struct CurveUsdView.CreateLoanData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "n", "type": "int256" }], "name": "getBandData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "getBandsData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "from", "type": "int256" }, { "internalType": "int256", "name": "to", "type": "int256" }], "name": "getBandsData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }], "name": "globalData", "outputs": [{ "components": [{ "internalType": "address", "name": "collateral", "type": "address" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "int256", "name": "activeBand", "type": "int256" }, { "internalType": "uint256", "name": "A", "type": "uint256" }, { "internalType": "uint256", "name": "totalDebt", "type": "uint256" }, { "internalType": "uint256", "name": "ammPrice", "type": "uint256" }, { "internalType": "uint256", "name": "basePrice", "type": "uint256" }, { "internalType": "uint256", "name": "oraclePrice", "type": "uint256" }, { "internalType": "uint256", "name": "minted", "type": "uint256" }, { "internalType": "uint256", "name": "redeemed", "type": "uint256" }, { "internalType": "uint256", "name": "monetaryPolicyRate", "type": "uint256" }, { "internalType": "uint256", "name": "ammRate", "type": "uint256" }, { "internalType": "int256", "name": "minBand", "type": "int256" }, { "internalType": "int256", "name": "maxBand", "type": "int256" }], "internalType": "struct CurveUsdView.GlobalData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }, { "internalType": "int256", "name": "collChange", "type": "int256" }, { "internalType": "int256", "name": "debtChange", "type": "int256" }, { "internalType": "bool", "name": "isFull", "type": "bool" }, { "internalType": "uint256", "name": "numBands", "type": "uint256" }], "name": "healthCalculator", "outputs": [{ "internalType": "int256", "name": "", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "maxBorrow", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "minCollateral", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "userData", "outputs": [{ "components": [{ "internalType": "bool", "name": "loanExists", "type": "bool" }, { "internalType": "uint256", "name": "collateralPrice", "type": "uint256" }, { "internalType": "uint256", "name": "marketCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "curveUsdCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }, { "internalType": "uint256", "name": "priceLow", "type": "uint256" }, { "internalType": "uint256", "name": "priceHigh", "type": "uint256" }, { "internalType": "uint256", "name": "liquidationDiscount", "type": "uint256" }, { "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "int256[2]", "name": "bandRange", "type": "int256[2]" }, { "internalType": "uint256[][2]", "name": "usersBands", "type": "uint256[][2]" }], "internalType": "struct CurveUsdView.UserData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }],
531
+ "abi": [{ "inputs": [], "name": "CurveUsdInvalidController", "type": "error" }, { "inputs": [], "name": "WBTC_HEALTH_ZAP", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "WBTC_MARKET", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "createLoanData", "outputs": [{ "components": [{ "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "uint256", "name": "minColl", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrow", "type": "uint256" }, { "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "internalType": "struct CurveUsdView.CreateLoanData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "n", "type": "int256" }], "name": "getBandData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "from", "type": "int256" }, { "internalType": "int256", "name": "to", "type": "int256" }], "name": "getBandsData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "getBandsDataForPosition", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_controllerAddress", "type": "address" }, { "internalType": "address", "name": "_user", "type": "address" }], "name": "getCollAmountsFromAMM", "outputs": [{ "internalType": "uint256", "name": "crvUsdAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }, { "internalType": "address", "name": "_controllerAddr", "type": "address" }], "name": "getCollateralRatio", "outputs": [{ "internalType": "uint256", "name": "collRatio", "type": "uint256" }, { "internalType": "bool", "name": "isInSoftLiquidation", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }], "name": "globalData", "outputs": [{ "components": [{ "internalType": "address", "name": "collateral", "type": "address" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "int256", "name": "activeBand", "type": "int256" }, { "internalType": "uint256", "name": "A", "type": "uint256" }, { "internalType": "uint256", "name": "totalDebt", "type": "uint256" }, { "internalType": "uint256", "name": "ammPrice", "type": "uint256" }, { "internalType": "uint256", "name": "basePrice", "type": "uint256" }, { "internalType": "uint256", "name": "oraclePrice", "type": "uint256" }, { "internalType": "uint256", "name": "minted", "type": "uint256" }, { "internalType": "uint256", "name": "redeemed", "type": "uint256" }, { "internalType": "uint256", "name": "monetaryPolicyRate", "type": "uint256" }, { "internalType": "uint256", "name": "ammRate", "type": "uint256" }, { "internalType": "int256", "name": "minBand", "type": "int256" }, { "internalType": "int256", "name": "maxBand", "type": "int256" }], "internalType": "struct CurveUsdView.GlobalData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }, { "internalType": "int256", "name": "collChange", "type": "int256" }, { "internalType": "int256", "name": "debtChange", "type": "int256" }, { "internalType": "bool", "name": "isFull", "type": "bool" }, { "internalType": "uint256", "name": "numBands", "type": "uint256" }], "name": "healthCalculator", "outputs": [{ "internalType": "int256", "name": "health", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_controllerAddr", "type": "address" }], "name": "isControllerValid", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "maxBorrow", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "minCollateral", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "userData", "outputs": [{ "components": [{ "internalType": "bool", "name": "loanExists", "type": "bool" }, { "internalType": "uint256", "name": "collateralPrice", "type": "uint256" }, { "internalType": "uint256", "name": "marketCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "curveUsdCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }, { "internalType": "uint256", "name": "priceLow", "type": "uint256" }, { "internalType": "uint256", "name": "priceHigh", "type": "uint256" }, { "internalType": "uint256", "name": "liquidationDiscount", "type": "uint256" }, { "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "int256[2]", "name": "bandRange", "type": "int256[2]" }, { "internalType": "uint256[][2]", "name": "usersBands", "type": "uint256[][2]" }, { "internalType": "uint256", "name": "collRatio", "type": "uint256" }, { "internalType": "bool", "name": "isInSoftLiquidation", "type": "bool" }], "internalType": "struct CurveUsdView.UserData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_controllerAddress", "type": "address" }, { "internalType": "address", "name": "_user", "type": "address" }], "name": "userMaxWithdraw", "outputs": [{ "internalType": "uint256", "name": "maxWithdraw", "type": "uint256" }], "stateMutability": "view", "type": "function" }],
532
532
  "networks": {
533
533
  "1": {
534
- "address": "0x512460CF2Bb80823C135F5DC04D2a1fF258FAA1e",
535
- "createdBlock": 17683243,
534
+ "address": "0x4BbCf0e587853aAEdFC3E60f74C10E07D8deA701",
535
+ "createdBlock": 18823384,
536
536
  "oldVersions": {
537
- "17657253": "0xa81430a4eC71466264b9ee50403F8d63E8c72B95"
537
+ "17657253": "0xa81430a4eC71466264b9ee50403F8d63E8c72B95",
538
+ "17683243": "0x512460CF2Bb80823C135F5DC04D2a1fF258FAA1e",
539
+ "18419795": "0x4df1281f9d2303be453e0085881702a4b1358692",
538
540
  }
539
541
  }
540
542
  }
@@ -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,33 @@ 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 { loanExists, usedAssets, network, selectedMarket } = _a, rest = __rest(_a, ["loanExists", "usedAssets", "network", "selectedMarket"]);
22
- const _supplied = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ supplied }) => supplied); // this is wrong if we are in soft-liquidations
23
- const _borrowed = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowed }) => borrowed);
24
- const _suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
25
- const _borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
26
- const ratio = loanExists
27
- ? new decimal_js_1.default(_suppliedUsd)
28
- .dividedBy(_borrowedUsd)
22
+ var { loanExists, usedAssets, network, selectedMarket, numOfBands } = _a, rest = __rest(_a, ["loanExists", "usedAssets", "network", "selectedMarket", "numOfBands"]);
23
+ const payload = {};
24
+ payload.supplied = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ supplied }) => supplied); // this is wrong if we are in soft-liquidations
25
+ payload.borrowed = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowed }) => borrowed);
26
+ payload.suppliedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
27
+ payload.borrowedUsd = (0, moneymarket_1.getAssetsTotal)(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
28
+ payload.ratio = loanExists
29
+ ? new decimal_js_1.default(payload.suppliedUsd)
30
+ .dividedBy(payload.borrowedUsd)
29
31
  .times(100)
30
32
  .toString()
31
33
  : '0';
32
- // we don't have borrowLimitUsd here
33
- return {
34
- ratio,
35
- supplied: _supplied,
36
- suppliedUsd: _suppliedUsd,
37
- borrowedUsd: _borrowedUsd,
38
- borrowed: _borrowed,
39
- safetyRatio: ratio,
40
- };
34
+ // this is all approximation
35
+ payload.minAllowedRatio = (0, utils_1.mapRange)(numOfBands, 4, 50, 115, 140); // collateral ratio
36
+ payload.collFactor = new decimal_js_1.default(1).div(payload.minAllowedRatio).mul(100).toString(); // collateral factor = 1 / collateral ratio
37
+ // only take in consideration collAsset
38
+ payload.borrowLimitUsd = usedAssets[selectedMarket.collAsset].isSupplied
39
+ ? new decimal_js_1.default(usedAssets[selectedMarket.collAsset].suppliedUsd).mul(payload.collFactor).toString()
40
+ : '0';
41
+ const { leveragedType, leveragedAsset } = (0, moneymarket_1.isLeveragedPos)(usedAssets);
42
+ payload.leveragedType = leveragedType;
43
+ if (leveragedType !== '') {
44
+ payload.leveragedAsset = leveragedAsset;
45
+ payload.liquidationPrice = (0, moneymarket_1.calcLeverageLiqPrice)(leveragedType, usedAssets[selectedMarket.collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
46
+ }
47
+ return payload;
41
48
  };
42
49
  exports.getCrvUsdAggregatedData = getCrvUsdAggregatedData;
@@ -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;
@@ -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;
@@ -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;
@@ -105,6 +105,7 @@ const getSparkMarketsData = (web3, network, selectedMarket, mainnetWeb3) => __aw
105
105
  price: new decimal_js_1.default(market.price.toString()).div(1e8).toString(),
106
106
  isolationModeBorrowingEnabled: market.isolationModeBorrowingEnabled,
107
107
  isFlashLoanEnabled: market.isFlashLoanEnabled,
108
+ aTokenAddress: market.aTokenAddress,
108
109
  eModeCategoryData: {
109
110
  label: market.label,
110
111
  liquidationBonus: new decimal_js_1.default(market.liquidationBonus).div(10000).toString(),
@@ -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
- "getBandsData(address,uint256,uint256,uint256)"(market: string, collateral: number | string | BN, debt: number | string | BN, N: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
199
- "getBandsData(address,int256,int256)"(market: string, from: number | string | BN, to: number | string | BN): NonPayableTransactionObject<CurveUsdView.BandStructOutput[]>;
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;
@@ -67,6 +67,12 @@ export interface CrvUSDAggregatedPositionData {
67
67
  borrowedUsd: string;
68
68
  borrowed: string;
69
69
  safetyRatio: string;
70
+ borrowLimitUsd: string;
71
+ minAllowedRatio: number;
72
+ collFactor: string;
73
+ leveragedType: string;
74
+ leveragedAsset?: string;
75
+ liquidationPrice?: string;
70
76
  }
71
77
  export interface CrvUSDUsedAsset {
72
78
  isSupplied: boolean;
@@ -2913,6 +2913,12 @@ export namespace crvUSDsfrxETHAmm {
2913
2913
  }
2914
2914
  export namespace crvUSDView {
2915
2915
  let abi_50: ({
2916
+ inputs: never[];
2917
+ name: string;
2918
+ type: string;
2919
+ outputs?: undefined;
2920
+ stateMutability?: undefined;
2921
+ } | {
2916
2922
  inputs: {
2917
2923
  internalType: string;
2918
2924
  name: string;
@@ -2963,6 +2969,8 @@ export namespace crvUSDView {
2963
2969
  createdBlock: number;
2964
2970
  oldVersions: {
2965
2971
  "17657253": string;
2972
+ "17683243": string;
2973
+ "18419795": string;
2966
2974
  };
2967
2975
  };
2968
2976
  };
@@ -527,13 +527,15 @@ module.exports = {
527
527
  }
528
528
  },
529
529
  "crvUSDView": {
530
- "abi": [{ "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "createLoanData", "outputs": [{ "components": [{ "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "uint256", "name": "minColl", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrow", "type": "uint256" }, { "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "internalType": "struct CurveUsdView.CreateLoanData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "n", "type": "int256" }], "name": "getBandData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "getBandsData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "from", "type": "int256" }, { "internalType": "int256", "name": "to", "type": "int256" }], "name": "getBandsData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }], "name": "globalData", "outputs": [{ "components": [{ "internalType": "address", "name": "collateral", "type": "address" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "int256", "name": "activeBand", "type": "int256" }, { "internalType": "uint256", "name": "A", "type": "uint256" }, { "internalType": "uint256", "name": "totalDebt", "type": "uint256" }, { "internalType": "uint256", "name": "ammPrice", "type": "uint256" }, { "internalType": "uint256", "name": "basePrice", "type": "uint256" }, { "internalType": "uint256", "name": "oraclePrice", "type": "uint256" }, { "internalType": "uint256", "name": "minted", "type": "uint256" }, { "internalType": "uint256", "name": "redeemed", "type": "uint256" }, { "internalType": "uint256", "name": "monetaryPolicyRate", "type": "uint256" }, { "internalType": "uint256", "name": "ammRate", "type": "uint256" }, { "internalType": "int256", "name": "minBand", "type": "int256" }, { "internalType": "int256", "name": "maxBand", "type": "int256" }], "internalType": "struct CurveUsdView.GlobalData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }, { "internalType": "int256", "name": "collChange", "type": "int256" }, { "internalType": "int256", "name": "debtChange", "type": "int256" }, { "internalType": "bool", "name": "isFull", "type": "bool" }, { "internalType": "uint256", "name": "numBands", "type": "uint256" }], "name": "healthCalculator", "outputs": [{ "internalType": "int256", "name": "", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "maxBorrow", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "minCollateral", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "userData", "outputs": [{ "components": [{ "internalType": "bool", "name": "loanExists", "type": "bool" }, { "internalType": "uint256", "name": "collateralPrice", "type": "uint256" }, { "internalType": "uint256", "name": "marketCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "curveUsdCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }, { "internalType": "uint256", "name": "priceLow", "type": "uint256" }, { "internalType": "uint256", "name": "priceHigh", "type": "uint256" }, { "internalType": "uint256", "name": "liquidationDiscount", "type": "uint256" }, { "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "int256[2]", "name": "bandRange", "type": "int256[2]" }, { "internalType": "uint256[][2]", "name": "usersBands", "type": "uint256[][2]" }], "internalType": "struct CurveUsdView.UserData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }],
530
+ "abi": [{ "inputs": [], "name": "CurveUsdInvalidController", "type": "error" }, { "inputs": [], "name": "WBTC_HEALTH_ZAP", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "WBTC_MARKET", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "createLoanData", "outputs": [{ "components": [{ "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "uint256", "name": "minColl", "type": "uint256" }, { "internalType": "uint256", "name": "maxBorrow", "type": "uint256" }, { "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "internalType": "struct CurveUsdView.CreateLoanData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "n", "type": "int256" }], "name": "getBandData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "int256", "name": "from", "type": "int256" }, { "internalType": "int256", "name": "to", "type": "int256" }], "name": "getBandsData", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "getBandsDataForPosition", "outputs": [{ "components": [{ "internalType": "int256", "name": "id", "type": "int256" }, { "internalType": "uint256", "name": "lowPrice", "type": "uint256" }, { "internalType": "uint256", "name": "highPrice", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }], "internalType": "struct CurveUsdView.Band[]", "name": "bands", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_controllerAddress", "type": "address" }, { "internalType": "address", "name": "_user", "type": "address" }], "name": "getCollAmountsFromAMM", "outputs": [{ "internalType": "uint256", "name": "crvUsdAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collAmount", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }, { "internalType": "address", "name": "_controllerAddr", "type": "address" }], "name": "getCollateralRatio", "outputs": [{ "internalType": "uint256", "name": "collRatio", "type": "uint256" }, { "internalType": "bool", "name": "isInSoftLiquidation", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }], "name": "globalData", "outputs": [{ "components": [{ "internalType": "address", "name": "collateral", "type": "address" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "int256", "name": "activeBand", "type": "int256" }, { "internalType": "uint256", "name": "A", "type": "uint256" }, { "internalType": "uint256", "name": "totalDebt", "type": "uint256" }, { "internalType": "uint256", "name": "ammPrice", "type": "uint256" }, { "internalType": "uint256", "name": "basePrice", "type": "uint256" }, { "internalType": "uint256", "name": "oraclePrice", "type": "uint256" }, { "internalType": "uint256", "name": "minted", "type": "uint256" }, { "internalType": "uint256", "name": "redeemed", "type": "uint256" }, { "internalType": "uint256", "name": "monetaryPolicyRate", "type": "uint256" }, { "internalType": "uint256", "name": "ammRate", "type": "uint256" }, { "internalType": "int256", "name": "minBand", "type": "int256" }, { "internalType": "int256", "name": "maxBand", "type": "int256" }], "internalType": "struct CurveUsdView.GlobalData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }, { "internalType": "int256", "name": "collChange", "type": "int256" }, { "internalType": "int256", "name": "debtChange", "type": "int256" }, { "internalType": "bool", "name": "isFull", "type": "bool" }, { "internalType": "uint256", "name": "numBands", "type": "uint256" }], "name": "healthCalculator", "outputs": [{ "internalType": "int256", "name": "health", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_controllerAddr", "type": "address" }], "name": "isControllerValid", "outputs": [{ "internalType": "bool", "name": "", "type": "bool" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "collateral", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "maxBorrow", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "uint256", "name": "debt", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }], "name": "minCollateral", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "market", "type": "address" }, { "internalType": "address", "name": "user", "type": "address" }], "name": "userData", "outputs": [{ "components": [{ "internalType": "bool", "name": "loanExists", "type": "bool" }, { "internalType": "uint256", "name": "collateralPrice", "type": "uint256" }, { "internalType": "uint256", "name": "marketCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "curveUsdCollateralAmount", "type": "uint256" }, { "internalType": "uint256", "name": "debtAmount", "type": "uint256" }, { "internalType": "uint256", "name": "N", "type": "uint256" }, { "internalType": "uint256", "name": "priceLow", "type": "uint256" }, { "internalType": "uint256", "name": "priceHigh", "type": "uint256" }, { "internalType": "uint256", "name": "liquidationDiscount", "type": "uint256" }, { "internalType": "int256", "name": "health", "type": "int256" }, { "internalType": "int256[2]", "name": "bandRange", "type": "int256[2]" }, { "internalType": "uint256[][2]", "name": "usersBands", "type": "uint256[][2]" }, { "internalType": "uint256", "name": "collRatio", "type": "uint256" }, { "internalType": "bool", "name": "isInSoftLiquidation", "type": "bool" }], "internalType": "struct CurveUsdView.UserData", "name": "", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_controllerAddress", "type": "address" }, { "internalType": "address", "name": "_user", "type": "address" }], "name": "userMaxWithdraw", "outputs": [{ "internalType": "uint256", "name": "maxWithdraw", "type": "uint256" }], "stateMutability": "view", "type": "function" }],
531
531
  "networks": {
532
532
  "1": {
533
- "address": "0x512460CF2Bb80823C135F5DC04D2a1fF258FAA1e",
534
- "createdBlock": 17683243,
533
+ "address": "0x4BbCf0e587853aAEdFC3E60f74C10E07D8deA701",
534
+ "createdBlock": 18823384,
535
535
  "oldVersions": {
536
- "17657253": "0xa81430a4eC71466264b9ee50403F8d63E8c72B95"
536
+ "17657253": "0xa81430a4eC71466264b9ee50403F8d63E8c72B95",
537
+ "17683243": "0x512460CF2Bb80823C135F5DC04D2a1fF258FAA1e",
538
+ "18419795": "0x4df1281f9d2303be453e0085881702a4b1358692",
537
539
  }
538
540
  }
539
541
  }
@@ -179,7 +179,7 @@ export const getCurveUsdUserData = (web3, network, address, selectedMarket, acti
179
179
  priceHigh,
180
180
  priceLow, liquidationDiscount: assetAmountInEth(data.liquidationDiscount), numOfBands: data.N, usedAssets,
181
181
  status }), getCrvUsdAggregatedData({
182
- loanExists: data.loanExists, usedAssets, network: NetworkNumber.Eth, selectedMarket,
182
+ loanExists: data.loanExists, usedAssets, network: NetworkNumber.Eth, selectedMarket, numOfBands: data.N,
183
183
  })), { userBands });
184
184
  });
185
185
  export const getCurveUsdFullPositionData = (web3, network, address, selectedMarket) => __awaiter(void 0, void 0, void 0, function* () {
@@ -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;
@@ -10,26 +10,33 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import Dec from 'decimal.js';
13
- import { getAssetsTotal } from '../../moneymarket';
13
+ import { calcLeverageLiqPrice, getAssetsTotal, isLeveragedPos } from '../../moneymarket';
14
+ import { mapRange } from '../../services/utils';
14
15
  export const getCrvUsdAggregatedData = (_a) => {
15
- var { loanExists, usedAssets, network, selectedMarket } = _a, rest = __rest(_a, ["loanExists", "usedAssets", "network", "selectedMarket"]);
16
- const _supplied = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ supplied }) => supplied); // this is wrong if we are in soft-liquidations
17
- const _borrowed = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowed }) => borrowed);
18
- const _suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
19
- const _borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
20
- const ratio = loanExists
21
- ? new Dec(_suppliedUsd)
22
- .dividedBy(_borrowedUsd)
16
+ var { loanExists, usedAssets, network, selectedMarket, numOfBands } = _a, rest = __rest(_a, ["loanExists", "usedAssets", "network", "selectedMarket", "numOfBands"]);
17
+ const payload = {};
18
+ payload.supplied = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ supplied }) => supplied); // this is wrong if we are in soft-liquidations
19
+ payload.borrowed = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowed }) => borrowed);
20
+ payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
21
+ payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
22
+ payload.ratio = loanExists
23
+ ? new Dec(payload.suppliedUsd)
24
+ .dividedBy(payload.borrowedUsd)
23
25
  .times(100)
24
26
  .toString()
25
27
  : '0';
26
- // we don't have borrowLimitUsd here
27
- return {
28
- ratio,
29
- supplied: _supplied,
30
- suppliedUsd: _suppliedUsd,
31
- borrowedUsd: _borrowedUsd,
32
- borrowed: _borrowed,
33
- safetyRatio: ratio,
34
- };
28
+ // this is all approximation
29
+ payload.minAllowedRatio = mapRange(numOfBands, 4, 50, 115, 140); // collateral ratio
30
+ payload.collFactor = new Dec(1).div(payload.minAllowedRatio).mul(100).toString(); // collateral factor = 1 / collateral ratio
31
+ // only take in consideration collAsset
32
+ payload.borrowLimitUsd = usedAssets[selectedMarket.collAsset].isSupplied
33
+ ? new Dec(usedAssets[selectedMarket.collAsset].suppliedUsd).mul(payload.collFactor).toString()
34
+ : '0';
35
+ const { leveragedType, leveragedAsset } = isLeveragedPos(usedAssets);
36
+ payload.leveragedType = leveragedType;
37
+ if (leveragedType !== '') {
38
+ payload.leveragedAsset = leveragedAsset;
39
+ payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, usedAssets[selectedMarket.collAsset].price, payload.borrowedUsd, payload.borrowLimitUsd);
40
+ }
41
+ return payload;
35
42
  };
@@ -16,7 +16,7 @@ export const calcLeverageLiqPrice = (leverageType, assetPrice, borrowedUsd, borr
16
16
  return '0';
17
17
  };
18
18
  export const calculateBorrowingAssetLimit = (assetBorrowedUsd, borrowLimitUsd) => new Dec(assetBorrowedUsd).div(borrowLimitUsd).times(100).toString();
19
- export const STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI'];
19
+ export const STABLE_ASSETS = ['DAI', 'USDC', 'USDT', 'TUSD', 'USDP', 'GUSD', 'BUSD', 'SUSD', 'FRAX', 'LUSD', 'USDC.e', 'GHO', 'sDAI', 'crvUSD'];
20
20
  export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
21
21
  let borrowUnstable = 0;
22
22
  let supplyStable = 0;
@@ -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;
@@ -19,3 +19,14 @@ export const bytesToString = (hex) => Buffer.from(hex.replace(/^0x/, ''), 'hex')
19
19
  .toString()
20
20
  // eslint-disable-next-line no-control-regex
21
21
  .replace(/\x00/g, '');
22
+ /**
23
+ * Map an input value from one range (minInput, maxInput) to a value in another range (minOutput, maxOutput)
24
+ */
25
+ export const mapRange = (input, minInput, maxInput, minOutput, maxOutput) => {
26
+ // slope = 1.0 * (output_end - output_start) / (input_end - input_start)
27
+ const inputDiff = new Dec(maxInput).minus(minInput);
28
+ const outputDiff = new Dec(maxOutput).minus(minOutput);
29
+ const slope = new Dec(outputDiff).div(inputDiff);
30
+ // output = output_start + slope * (input - input_start)
31
+ return new Dec(minOutput).plus(new Dec(slope).mul(new Dec(input).minus(minInput))).toDP(2).toNumber();
32
+ };
@@ -98,6 +98,7 @@ export const getSparkMarketsData = (web3, network, selectedMarket, mainnetWeb3)
98
98
  price: new Dec(market.price.toString()).div(1e8).toString(),
99
99
  isolationModeBorrowingEnabled: market.isolationModeBorrowingEnabled,
100
100
  isFlashLoanEnabled: market.isFlashLoanEnabled,
101
+ aTokenAddress: market.aTokenAddress,
101
102
  eModeCategoryData: {
102
103
  label: market.label,
103
104
  liquidationBonus: new Dec(market.liquidationBonus).div(10000).toString(),