@defisaver/positions-sdk 0.0.185-dev-1 → 0.0.185-dev-4

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.
@@ -188,14 +188,9 @@ const getCompoundV3AccountData = (web3, network, address, proxyAddress, extracte
188
188
  if (loanData.borrowAmount.toString() !== '0') {
189
189
  usedAssets[baseAssetSymbol].isBorrowed = true;
190
190
  usedAssets[baseAssetSymbol].borrowed = (0, tokens_1.assetAmountInEth)(loanData.borrowAmount, baseAssetInfo.symbol);
191
- if (selectedMarket.value === (0, compound_1.COMPOUND_V3_ETH)(network).value) {
192
- usedAssets[baseAssetSymbol].borrowedUsd = new decimal_js_1.default((0, tokens_1.assetAmountInEth)(loanData.borrowValue, baseAssetInfo.symbol))
193
- .mul(assetsData[baseAssetSymbol].price)
194
- .toString();
195
- }
196
- else {
197
- usedAssets[baseAssetSymbol].borrowedUsd = (0, tokens_1.assetAmountInEth)(loanData.borrowValue, baseAssetInfo.symbol);
198
- }
191
+ usedAssets[baseAssetSymbol].borrowedUsd = new decimal_js_1.default((0, tokens_1.assetAmountInEth)(loanData.borrowValue, baseAssetInfo.symbol))
192
+ .mul(assetsData[baseAssetSymbol].price)
193
+ .toString();
199
194
  }
200
195
  const supportedAssetsAddresses = getSupportedAssetsAddressesForMarket(selectedMarket, network);
201
196
  loanData.collAddr.forEach((coll, i) => {
@@ -6810,13 +6810,43 @@ export namespace FeedRegistry {
6810
6810
  };
6811
6811
  export { networks_77 as networks };
6812
6812
  }
6813
- export namespace LlamaLendView {
6813
+ export namespace DFSFeedRegistry {
6814
6814
  let abi_78: ({
6815
6815
  inputs: never[];
6816
6816
  name: string;
6817
6817
  type: string;
6818
6818
  outputs?: undefined;
6819
6819
  stateMutability?: undefined;
6820
+ } | {
6821
+ inputs: {
6822
+ internalType: string;
6823
+ name: string;
6824
+ type: string;
6825
+ }[];
6826
+ name: string;
6827
+ outputs: {
6828
+ internalType: string;
6829
+ name: string;
6830
+ type: string;
6831
+ }[];
6832
+ stateMutability: string;
6833
+ type: string;
6834
+ })[];
6835
+ export { abi_78 as abi };
6836
+ let networks_78: {
6837
+ "8453": {
6838
+ address: string;
6839
+ };
6840
+ };
6841
+ export { networks_78 as networks };
6842
+ }
6843
+ export namespace LlamaLendView {
6844
+ let abi_79: ({
6845
+ inputs: never[];
6846
+ name: string;
6847
+ type: string;
6848
+ outputs?: undefined;
6849
+ stateMutability?: undefined;
6820
6850
  } | {
6821
6851
  inputs: {
6822
6852
  internalType: string;
@@ -6861,8 +6891,8 @@ export namespace LlamaLendView {
6861
6891
  stateMutability: string;
6862
6892
  type: string;
6863
6893
  })[];
6864
- export { abi_78 as abi };
6865
- let networks_78: {
6894
+ export { abi_79 as abi };
6895
+ let networks_79: {
6866
6896
  "1": {
6867
6897
  address: string;
6868
6898
  };
@@ -6870,10 +6900,10 @@ export namespace LlamaLendView {
6870
6900
  address: string;
6871
6901
  };
6872
6902
  };
6873
- export { networks_78 as networks };
6903
+ export { networks_79 as networks };
6874
6904
  }
6875
6905
  export namespace LlamaLendControllerAbi {
6876
- let abi_79: ({
6906
+ let abi_80: ({
6877
6907
  name: string;
6878
6908
  inputs: {
6879
6909
  name: string;
@@ -6925,12 +6955,12 @@ export namespace LlamaLendControllerAbi {
6925
6955
  }[];
6926
6956
  anonymous?: undefined;
6927
6957
  })[];
6928
- export { abi_79 as abi };
6929
- let networks_79: {};
6930
- export { networks_79 as networks };
6958
+ export { abi_80 as abi };
6959
+ let networks_80: {};
6960
+ export { networks_80 as networks };
6931
6961
  }
6932
6962
  export namespace EulerV2View {
6933
- let abi_80: ({
6963
+ let abi_81: ({
6934
6964
  inputs: {
6935
6965
  internalType: string;
6936
6966
  name: string;
@@ -6993,11 +7023,11 @@ export namespace EulerV2View {
6993
7023
  stateMutability: string;
6994
7024
  type: string;
6995
7025
  })[];
6996
- export { abi_80 as abi };
6997
- let networks_80: {
7026
+ export { abi_81 as abi };
7027
+ let networks_81: {
6998
7028
  "1": {
6999
7029
  address: string;
7000
7030
  };
7001
7031
  };
7002
- export { networks_80 as networks };
7032
+ export { networks_81 as networks };
7003
7033
  }
@@ -1045,6 +1045,12 @@ module.exports = {
1045
1045
  "1": { "address": "0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf" },
1046
1046
  }
1047
1047
  },
1048
+ "DFSFeedRegistry": {
1049
+ "abi": [{ "inputs": [], "name": "NonContractCall", "type": "error" }, { "inputs": [], "name": "SenderNotAdmin", "type": "error" }, { "inputs": [], "name": "SenderNotOwner", "type": "error" }, { "inputs": [], "name": "adminVault", "outputs": [{ "internalType": "contract AdminVault", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "", "type": "address" }, { "internalType": "address", "name": "", "type": "address" }], "name": "aggregators", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "base", "type": "address" }, { "internalType": "address", "name": "quote", "type": "address" }], "name": "getFeed", "outputs": [{ "internalType": "address", "name": "aggregator", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "kill", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "base", "type": "address" }, { "internalType": "address", "name": "quote", "type": "address" }], "name": "latestRoundData", "outputs": [{ "internalType": "uint80", "name": "roundId", "type": "uint80" }, { "internalType": "int256", "name": "answer", "type": "int256" }, { "internalType": "uint256", "name": "startedAt", "type": "uint256" }, { "internalType": "uint256", "name": "updatedAt", "type": "uint256" }, { "internalType": "uint80", "name": "answeredInRound", "type": "uint80" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "base", "type": "address" }, { "internalType": "address", "name": "quote", "type": "address" }, { "internalType": "address", "name": "aggregator", "type": "address" }], "name": "setFeed", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address[]", "name": "bases", "type": "address[]" }, { "internalType": "address[]", "name": "quotes", "type": "address[]" }, { "internalType": "address[]", "name": "aggregator", "type": "address[]" }], "name": "setFeeds", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_token", "type": "address" }, { "internalType": "address", "name": "_receiver", "type": "address" }, { "internalType": "uint256", "name": "_amount", "type": "uint256" }], "name": "withdrawStuckFunds", "outputs": [], "stateMutability": "nonpayable", "type": "function" }],
1050
+ "networks": {
1051
+ "8453": { "address": "0x7dFF34190d0307fC234fc7E8C152C9715083eB02" },
1052
+ }
1053
+ },
1048
1054
  "LlamaLendView": {
1049
1055
  "abi": [{ "inputs": [], "name": "InvalidLlamaLendController", "type": "error" }, { "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 LlamaLendView.Band[]", "name": "bands", "type": "tuple[]" }], "internalType": "struct LlamaLendView.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 LlamaLendView.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 LlamaLendView.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 LlamaLendView.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": "debtAssetCollAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collAssetCollAmount", "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": "collateralToken", "type": "address" }, { "internalType": "address", "name": "debtToken", "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": "uint256", "name": "borrowApr", "type": "uint256" }, { "internalType": "uint256", "name": "lendApr", "type": "uint256" }, { "internalType": "uint256", "name": "debtTokenTotalSupply", "type": "uint256" }, { "internalType": "uint256", "name": "debtTokenLeftToBorrow", "type": "uint256" }, { "internalType": "uint256", "name": "loanDiscount", "type": "uint256" }], "internalType": "struct LlamaLendView.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" }, { "internalType": "uint256", "name": "_controllerId", "type": "uint256" }], "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": "debtTokenCollateralAmount", "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": "uint256", "name": "debtTokenSuppliedShares", "type": "uint256" }, { "internalType": "uint256", "name": "debtTokenSuppliedAssets", "type": "uint256" }], "internalType": "struct LlamaLendView.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" }],
1050
1056
  "networks": {
@@ -44,6 +44,7 @@ export declare const COMPPriceFeedContract: (web3: Web3, network: NetworkNumber,
44
44
  export declare const USDCPriceFeedContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.USDCPriceFeed;
45
45
  export declare const WstETHPriceFeedContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.WstETHPriceFeed;
46
46
  export declare const FeedRegistryContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.FeedRegistry;
47
+ export declare const DFSFeedRegistryContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.DFSFeedRegistry;
47
48
  export declare const MorphoBlueViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.MorphoBlueView;
48
49
  export declare const LlamaLendViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.LlamaLendView;
49
50
  export declare const EulerV2ViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.EulerV2View;
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.EulerV2ViewContract = exports.LlamaLendViewContract = exports.MorphoBlueViewContract = exports.FeedRegistryContract = exports.WstETHPriceFeedContract = 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.EulerV2ViewContract = exports.LlamaLendViewContract = exports.MorphoBlueViewContract = exports.DFSFeedRegistryContract = exports.FeedRegistryContract = exports.WstETHPriceFeedContract = 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) => {
@@ -86,6 +86,7 @@ exports.COMPPriceFeedContract = createContractFromConfigFunc('COMPPriceFeed');
86
86
  exports.USDCPriceFeedContract = createContractFromConfigFunc('USDCPriceFeed');
87
87
  exports.WstETHPriceFeedContract = createContractFromConfigFunc('WstETHPriceFeed');
88
88
  exports.FeedRegistryContract = createContractFromConfigFunc('FeedRegistry');
89
+ exports.DFSFeedRegistryContract = createContractFromConfigFunc('DFSFeedRegistry');
89
90
  exports.MorphoBlueViewContract = createContractFromConfigFunc('MorphoBlueView');
90
91
  exports.LlamaLendViewContract = createContractFromConfigFunc('LlamaLendView');
91
92
  exports.EulerV2ViewContract = createContractFromConfigFunc('EulerV2View');
@@ -766,7 +766,7 @@ exports.MORPHO_BLUE_CBBTC_USDC_860_BASE = MORPHO_BLUE_CBBTC_USDC_860_BASE;
766
766
  const MORPHO_BLUE_WSUPEROETHB_WETH_915_BASE = (networkId = common_1.NetworkNumber.Eth) => ({
767
767
  chainIds: [common_1.NetworkNumber.Base],
768
768
  label: 'Morpho',
769
- shortLabel: 'wsuperOETHb/WETH',
769
+ shortLabel: 'wsuperOETHb/ETH',
770
770
  value: types_1.MorphoBlueVersions.MorphoBlueWsuperOETHbWETH_915_Base,
771
771
  url: 'wsuperoethbweth-144bf18d',
772
772
  loanToken: '0x4200000000000000000000000000000000000006',
@@ -21,23 +21,40 @@ const constants_1 = require("../constants");
21
21
  const staking_1 = require("../staking");
22
22
  const utils_1 = require("../services/utils");
23
23
  const morphoBlueHelpers_1 = require("../helpers/morphoBlueHelpers");
24
+ const priceService_1 = require("../services/priceService");
25
+ const isMainnetNetwork = (network) => network === common_1.NetworkNumber.Eth;
24
26
  function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
25
27
  return __awaiter(this, void 0, void 0, function* () {
26
28
  const { loanToken, collateralToken, oracle, irm, lltv, oracleType, } = selectedMarket;
27
29
  const lltvInWei = new decimal_js_1.default(lltv).mul(constants_1.WAD).toString();
28
30
  const loanTokenInfo = (0, tokens_1.getAssetInfoByAddress)(loanToken, network);
29
31
  const collateralTokenInfo = (0, tokens_1.getAssetInfoByAddress)(collateralToken, network);
30
- let loanTokenFeedAddress = loanTokenInfo.addresses[common_1.NetworkNumber.Eth];
31
- if (loanTokenInfo.symbol === 'WETH') {
32
- const ethAddress = (0, tokens_1.getAssetInfo)('ETH').address;
33
- loanTokenFeedAddress = ethAddress;
34
- }
35
- const feedRegistryContract = (0, contracts_1.FeedRegistryContract)(mainnetWeb3, common_1.NetworkNumber.Eth);
32
+ const loanTokenFeedAddress = (0, priceService_1.getChainlinkAssetAddress)(loanTokenInfo.symbol, network);
36
33
  const morphoBlueViewContract = (0, contracts_1.MorphoBlueViewContract)(web3, network);
37
- const [loanTokenPrice, marketInfo] = yield Promise.all([
38
- loanTokenInfo.symbol === 'USDA' ? '100000000' : feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, constants_1.USD_QUOTE).call(),
39
- morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
40
- ]);
34
+ let marketInfo;
35
+ let loanTokenPrice;
36
+ const isTokenUSDA = loanTokenInfo.symbol === 'USDA';
37
+ const isMainnet = isMainnetNetwork(network);
38
+ if (isMainnet) {
39
+ const feedRegistryContract = (0, contracts_1.FeedRegistryContract)(mainnetWeb3, common_1.NetworkNumber.Eth);
40
+ const [_loanTokenPrice, _marketInfo] = yield Promise.all([
41
+ isTokenUSDA ? Promise.resolve('100000000') : feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, constants_1.USD_QUOTE).call(),
42
+ morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
43
+ ]);
44
+ marketInfo = _marketInfo;
45
+ loanTokenPrice = _loanTokenPrice;
46
+ }
47
+ else {
48
+ // Currently only base network is supported
49
+ const feedRegistryContract = (0, contracts_1.DFSFeedRegistryContract)(web3, network);
50
+ const [loanTokenPriceRound, _marketInfo] = yield Promise.all([
51
+ isTokenUSDA ? Promise.resolve({ answer: '100000000' }) // Normalize to match the expected object structure
52
+ : feedRegistryContract.methods.latestRoundData(loanTokenFeedAddress, constants_1.USD_QUOTE).call(),
53
+ morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
54
+ ]);
55
+ marketInfo = _marketInfo;
56
+ loanTokenPrice = loanTokenPriceRound.answer;
57
+ }
41
58
  const supplyRate = (0, morphoBlueHelpers_1.getSupplyRate)(marketInfo.totalSupplyAssets, marketInfo.totalBorrowAssets, marketInfo.borrowRate, marketInfo.fee);
42
59
  const compoundedBorrowRate = (0, morphoBlueHelpers_1.getBorrowRate)(marketInfo.borrowRate, marketInfo.totalBorrowShares);
43
60
  const utillization = new decimal_js_1.default(marketInfo.totalBorrowAssets).div(marketInfo.totalSupplyAssets).mul(100).toString();
@@ -1,5 +1,7 @@
1
1
  import Web3 from 'web3';
2
+ import { NetworkNumber } from '../types/common';
2
3
  export declare const getEthPrice: (web3: Web3) => Promise<string>;
3
4
  export declare const getUSDCPrice: (web3: Web3) => Promise<string>;
4
5
  export declare const getCompPrice: (web3: Web3) => Promise<string>;
5
6
  export declare const getWstETHPrice: (web3: Web3) => Promise<string>;
7
+ export declare const getChainlinkAssetAddress: (symbol: string, network: NetworkNumber) => string;
@@ -12,8 +12,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getWstETHPrice = exports.getCompPrice = exports.getUSDCPrice = exports.getEthPrice = void 0;
15
+ exports.getChainlinkAssetAddress = exports.getWstETHPrice = exports.getCompPrice = exports.getUSDCPrice = exports.getEthPrice = void 0;
16
16
  const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const tokens_1 = require("@defisaver/tokens");
17
18
  const contracts_1 = require("../contracts");
18
19
  const common_1 = require("../types/common");
19
20
  const multicall_1 = require("../multicall");
@@ -56,3 +57,12 @@ const getWstETHPrice = (web3) => __awaiter(void 0, void 0, void 0, function* ()
56
57
  return new decimal_js_1.default(ethPrice).mul(wstETHRate).toString();
57
58
  });
58
59
  exports.getWstETHPrice = getWstETHPrice;
60
+ // chainlink price feed available only on mainnet
61
+ const getChainlinkAssetAddress = (symbol, network) => {
62
+ if (['WBTC', 'RENBTC'].includes(symbol === null || symbol === void 0 ? void 0 : symbol.toUpperCase()))
63
+ return '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB';
64
+ if ((symbol === null || symbol === void 0 ? void 0 : symbol.toUpperCase()) === 'WETH')
65
+ return (0, tokens_1.getAssetInfo)('ETH').addresses[network];
66
+ return (0, tokens_1.getAssetInfo)(symbol).addresses[network];
67
+ };
68
+ exports.getChainlinkAssetAddress = getChainlinkAssetAddress;
@@ -0,0 +1,40 @@
1
+ /// <reference types="node" />
2
+ import type BN from "bn.js";
3
+ import type { ContractOptions } from "web3-eth-contract";
4
+ import type { EventLog } from "web3-core";
5
+ import type { EventEmitter } from "events";
6
+ import type { Callback, NonPayableTransactionObject, BlockType, BaseContract } from "./types";
7
+ export interface EventOptions {
8
+ filter?: object;
9
+ fromBlock?: BlockType;
10
+ topics?: string[];
11
+ }
12
+ export interface DFSFeedRegistry extends BaseContract {
13
+ constructor(jsonInterface: any[], address?: string, options?: ContractOptions): DFSFeedRegistry;
14
+ clone(): DFSFeedRegistry;
15
+ methods: {
16
+ adminVault(): NonPayableTransactionObject<string>;
17
+ aggregators(arg0: string, arg1: string): NonPayableTransactionObject<string>;
18
+ getFeed(base: string, quote: string): NonPayableTransactionObject<string>;
19
+ kill(): NonPayableTransactionObject<void>;
20
+ latestRoundData(base: string, quote: string): NonPayableTransactionObject<[
21
+ string,
22
+ string,
23
+ string,
24
+ string,
25
+ string
26
+ ] & {
27
+ roundId: string;
28
+ answer: string;
29
+ startedAt: string;
30
+ updatedAt: string;
31
+ answeredInRound: string;
32
+ }>;
33
+ setFeed(base: string, quote: string, aggregator: string): NonPayableTransactionObject<void>;
34
+ setFeeds(bases: string[], quotes: string[], aggregator: string[]): NonPayableTransactionObject<void>;
35
+ withdrawStuckFunds(_token: string, _receiver: string, _amount: number | string | BN): NonPayableTransactionObject<void>;
36
+ };
37
+ events: {
38
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
39
+ };
40
+ }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ /* Autogenerated file. Do not edit manually. */
3
+ /* tslint:disable */
4
+ /* eslint-disable */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -24,6 +24,7 @@ export type { CompV3BulkerMainnetUSDC } from "./CompV3BulkerMainnetUSDC";
24
24
  export type { CompV3View } from "./CompV3View";
25
25
  export type { CompoundLoanInfo } from "./CompoundLoanInfo";
26
26
  export type { Comptroller } from "./Comptroller";
27
+ export type { DFSFeedRegistry } from "./DFSFeedRegistry";
27
28
  export type { ETHPriceFeed } from "./ETHPriceFeed";
28
29
  export type { Erc20 } from "./Erc20";
29
30
  export type { EulerV2View } from "./EulerV2View";
@@ -180,14 +180,9 @@ export const getCompoundV3AccountData = (web3, network, address, proxyAddress, e
180
180
  if (loanData.borrowAmount.toString() !== '0') {
181
181
  usedAssets[baseAssetSymbol].isBorrowed = true;
182
182
  usedAssets[baseAssetSymbol].borrowed = assetAmountInEth(loanData.borrowAmount, baseAssetInfo.symbol);
183
- if (selectedMarket.value === COMPOUND_V3_ETH(network).value) {
184
- usedAssets[baseAssetSymbol].borrowedUsd = new Dec(assetAmountInEth(loanData.borrowValue, baseAssetInfo.symbol))
185
- .mul(assetsData[baseAssetSymbol].price)
186
- .toString();
187
- }
188
- else {
189
- usedAssets[baseAssetSymbol].borrowedUsd = assetAmountInEth(loanData.borrowValue, baseAssetInfo.symbol);
190
- }
183
+ usedAssets[baseAssetSymbol].borrowedUsd = new Dec(assetAmountInEth(loanData.borrowValue, baseAssetInfo.symbol))
184
+ .mul(assetsData[baseAssetSymbol].price)
185
+ .toString();
191
186
  }
192
187
  const supportedAssetsAddresses = getSupportedAssetsAddressesForMarket(selectedMarket, network);
193
188
  loanData.collAddr.forEach((coll, i) => {
@@ -6810,13 +6810,43 @@ export namespace FeedRegistry {
6810
6810
  };
6811
6811
  export { networks_77 as networks };
6812
6812
  }
6813
- export namespace LlamaLendView {
6813
+ export namespace DFSFeedRegistry {
6814
6814
  let abi_78: ({
6815
6815
  inputs: never[];
6816
6816
  name: string;
6817
6817
  type: string;
6818
6818
  outputs?: undefined;
6819
6819
  stateMutability?: undefined;
6820
+ } | {
6821
+ inputs: {
6822
+ internalType: string;
6823
+ name: string;
6824
+ type: string;
6825
+ }[];
6826
+ name: string;
6827
+ outputs: {
6828
+ internalType: string;
6829
+ name: string;
6830
+ type: string;
6831
+ }[];
6832
+ stateMutability: string;
6833
+ type: string;
6834
+ })[];
6835
+ export { abi_78 as abi };
6836
+ let networks_78: {
6837
+ "8453": {
6838
+ address: string;
6839
+ };
6840
+ };
6841
+ export { networks_78 as networks };
6842
+ }
6843
+ export namespace LlamaLendView {
6844
+ let abi_79: ({
6845
+ inputs: never[];
6846
+ name: string;
6847
+ type: string;
6848
+ outputs?: undefined;
6849
+ stateMutability?: undefined;
6820
6850
  } | {
6821
6851
  inputs: {
6822
6852
  internalType: string;
@@ -6861,8 +6891,8 @@ export namespace LlamaLendView {
6861
6891
  stateMutability: string;
6862
6892
  type: string;
6863
6893
  })[];
6864
- export { abi_78 as abi };
6865
- let networks_78: {
6894
+ export { abi_79 as abi };
6895
+ let networks_79: {
6866
6896
  "1": {
6867
6897
  address: string;
6868
6898
  };
@@ -6870,10 +6900,10 @@ export namespace LlamaLendView {
6870
6900
  address: string;
6871
6901
  };
6872
6902
  };
6873
- export { networks_78 as networks };
6903
+ export { networks_79 as networks };
6874
6904
  }
6875
6905
  export namespace LlamaLendControllerAbi {
6876
- let abi_79: ({
6906
+ let abi_80: ({
6877
6907
  name: string;
6878
6908
  inputs: {
6879
6909
  name: string;
@@ -6925,12 +6955,12 @@ export namespace LlamaLendControllerAbi {
6925
6955
  }[];
6926
6956
  anonymous?: undefined;
6927
6957
  })[];
6928
- export { abi_79 as abi };
6929
- let networks_79: {};
6930
- export { networks_79 as networks };
6958
+ export { abi_80 as abi };
6959
+ let networks_80: {};
6960
+ export { networks_80 as networks };
6931
6961
  }
6932
6962
  export namespace EulerV2View {
6933
- let abi_80: ({
6963
+ let abi_81: ({
6934
6964
  inputs: {
6935
6965
  internalType: string;
6936
6966
  name: string;
@@ -6993,11 +7023,11 @@ export namespace EulerV2View {
6993
7023
  stateMutability: string;
6994
7024
  type: string;
6995
7025
  })[];
6996
- export { abi_80 as abi };
6997
- let networks_80: {
7026
+ export { abi_81 as abi };
7027
+ let networks_81: {
6998
7028
  "1": {
6999
7029
  address: string;
7000
7030
  };
7001
7031
  };
7002
- export { networks_80 as networks };
7032
+ export { networks_81 as networks };
7003
7033
  }
@@ -1044,6 +1044,12 @@ module.exports = {
1044
1044
  "1": { "address": "0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf" },
1045
1045
  }
1046
1046
  },
1047
+ "DFSFeedRegistry": {
1048
+ "abi": [{ "inputs": [], "name": "NonContractCall", "type": "error" }, { "inputs": [], "name": "SenderNotAdmin", "type": "error" }, { "inputs": [], "name": "SenderNotOwner", "type": "error" }, { "inputs": [], "name": "adminVault", "outputs": [{ "internalType": "contract AdminVault", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "", "type": "address" }, { "internalType": "address", "name": "", "type": "address" }], "name": "aggregators", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "base", "type": "address" }, { "internalType": "address", "name": "quote", "type": "address" }], "name": "getFeed", "outputs": [{ "internalType": "address", "name": "aggregator", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "kill", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "base", "type": "address" }, { "internalType": "address", "name": "quote", "type": "address" }], "name": "latestRoundData", "outputs": [{ "internalType": "uint80", "name": "roundId", "type": "uint80" }, { "internalType": "int256", "name": "answer", "type": "int256" }, { "internalType": "uint256", "name": "startedAt", "type": "uint256" }, { "internalType": "uint256", "name": "updatedAt", "type": "uint256" }, { "internalType": "uint80", "name": "answeredInRound", "type": "uint80" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "base", "type": "address" }, { "internalType": "address", "name": "quote", "type": "address" }, { "internalType": "address", "name": "aggregator", "type": "address" }], "name": "setFeed", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address[]", "name": "bases", "type": "address[]" }, { "internalType": "address[]", "name": "quotes", "type": "address[]" }, { "internalType": "address[]", "name": "aggregator", "type": "address[]" }], "name": "setFeeds", "outputs": [], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_token", "type": "address" }, { "internalType": "address", "name": "_receiver", "type": "address" }, { "internalType": "uint256", "name": "_amount", "type": "uint256" }], "name": "withdrawStuckFunds", "outputs": [], "stateMutability": "nonpayable", "type": "function" }],
1049
+ "networks": {
1050
+ "8453": { "address": "0x7dFF34190d0307fC234fc7E8C152C9715083eB02" },
1051
+ }
1052
+ },
1047
1053
  "LlamaLendView": {
1048
1054
  "abi": [{ "inputs": [], "name": "InvalidLlamaLendController", "type": "error" }, { "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 LlamaLendView.Band[]", "name": "bands", "type": "tuple[]" }], "internalType": "struct LlamaLendView.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 LlamaLendView.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 LlamaLendView.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 LlamaLendView.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": "debtAssetCollAmount", "type": "uint256" }, { "internalType": "uint256", "name": "collAssetCollAmount", "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": "collateralToken", "type": "address" }, { "internalType": "address", "name": "debtToken", "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": "uint256", "name": "borrowApr", "type": "uint256" }, { "internalType": "uint256", "name": "lendApr", "type": "uint256" }, { "internalType": "uint256", "name": "debtTokenTotalSupply", "type": "uint256" }, { "internalType": "uint256", "name": "debtTokenLeftToBorrow", "type": "uint256" }, { "internalType": "uint256", "name": "loanDiscount", "type": "uint256" }], "internalType": "struct LlamaLendView.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" }, { "internalType": "uint256", "name": "_controllerId", "type": "uint256" }], "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": "debtTokenCollateralAmount", "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": "uint256", "name": "debtTokenSuppliedShares", "type": "uint256" }, { "internalType": "uint256", "name": "debtTokenSuppliedAssets", "type": "uint256" }], "internalType": "struct LlamaLendView.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" }],
1049
1055
  "networks": {
@@ -44,6 +44,7 @@ export declare const COMPPriceFeedContract: (web3: Web3, network: NetworkNumber,
44
44
  export declare const USDCPriceFeedContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.USDCPriceFeed;
45
45
  export declare const WstETHPriceFeedContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.WstETHPriceFeed;
46
46
  export declare const FeedRegistryContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.FeedRegistry;
47
+ export declare const DFSFeedRegistryContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.DFSFeedRegistry;
47
48
  export declare const MorphoBlueViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.MorphoBlueView;
48
49
  export declare const LlamaLendViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.LlamaLendView;
49
50
  export declare const EulerV2ViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.EulerV2View;
package/esm/contracts.js CHANGED
@@ -76,6 +76,7 @@ export const COMPPriceFeedContract = createContractFromConfigFunc('COMPPriceFeed
76
76
  export const USDCPriceFeedContract = createContractFromConfigFunc('USDCPriceFeed');
77
77
  export const WstETHPriceFeedContract = createContractFromConfigFunc('WstETHPriceFeed');
78
78
  export const FeedRegistryContract = createContractFromConfigFunc('FeedRegistry');
79
+ export const DFSFeedRegistryContract = createContractFromConfigFunc('DFSFeedRegistry');
79
80
  export const MorphoBlueViewContract = createContractFromConfigFunc('MorphoBlueView');
80
81
  export const LlamaLendViewContract = createContractFromConfigFunc('LlamaLendView');
81
82
  export const EulerV2ViewContract = createContractFromConfigFunc('EulerV2View');
@@ -715,7 +715,7 @@ export const MORPHO_BLUE_CBBTC_USDC_860_BASE = (networkId = NetworkNumber.Eth) =
715
715
  export const MORPHO_BLUE_WSUPEROETHB_WETH_915_BASE = (networkId = NetworkNumber.Eth) => ({
716
716
  chainIds: [NetworkNumber.Base],
717
717
  label: 'Morpho',
718
- shortLabel: 'wsuperOETHb/WETH',
718
+ shortLabel: 'wsuperOETHb/ETH',
719
719
  value: MorphoBlueVersions.MorphoBlueWsuperOETHbWETH_915_Base,
720
720
  url: 'wsuperoethbweth-144bf18d',
721
721
  loanToken: '0x4200000000000000000000000000000000000006',
@@ -8,30 +8,47 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
- import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
11
+ import { assetAmountInEth, getAssetInfoByAddress, } from '@defisaver/tokens';
12
12
  import { NetworkNumber, } from '../types/common';
13
- import { FeedRegistryContract, MorphoBlueViewContract, } from '../contracts';
14
- import { WAD, USD_QUOTE } from '../constants';
13
+ import { DFSFeedRegistryContract, FeedRegistryContract, MorphoBlueViewContract } from '../contracts';
14
+ import { USD_QUOTE, WAD } from '../constants';
15
15
  import { getStakingApy, STAKING_ASSETS } from '../staking';
16
16
  import { wethToEth } from '../services/utils';
17
17
  import { getBorrowRate, getMorphoBlueAggregatedPositionData, getSupplyRate } from '../helpers/morphoBlueHelpers';
18
+ import { getChainlinkAssetAddress } from '../services/priceService';
19
+ const isMainnetNetwork = (network) => network === NetworkNumber.Eth;
18
20
  export function getMorphoBlueMarketData(web3, network, selectedMarket, mainnetWeb3) {
19
21
  return __awaiter(this, void 0, void 0, function* () {
20
22
  const { loanToken, collateralToken, oracle, irm, lltv, oracleType, } = selectedMarket;
21
23
  const lltvInWei = new Dec(lltv).mul(WAD).toString();
22
24
  const loanTokenInfo = getAssetInfoByAddress(loanToken, network);
23
25
  const collateralTokenInfo = getAssetInfoByAddress(collateralToken, network);
24
- let loanTokenFeedAddress = loanTokenInfo.addresses[NetworkNumber.Eth];
25
- if (loanTokenInfo.symbol === 'WETH') {
26
- const ethAddress = getAssetInfo('ETH').address;
27
- loanTokenFeedAddress = ethAddress;
28
- }
29
- const feedRegistryContract = FeedRegistryContract(mainnetWeb3, NetworkNumber.Eth);
26
+ const loanTokenFeedAddress = getChainlinkAssetAddress(loanTokenInfo.symbol, network);
30
27
  const morphoBlueViewContract = MorphoBlueViewContract(web3, network);
31
- const [loanTokenPrice, marketInfo] = yield Promise.all([
32
- loanTokenInfo.symbol === 'USDA' ? '100000000' : feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, USD_QUOTE).call(),
33
- morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
34
- ]);
28
+ let marketInfo;
29
+ let loanTokenPrice;
30
+ const isTokenUSDA = loanTokenInfo.symbol === 'USDA';
31
+ const isMainnet = isMainnetNetwork(network);
32
+ if (isMainnet) {
33
+ const feedRegistryContract = FeedRegistryContract(mainnetWeb3, NetworkNumber.Eth);
34
+ const [_loanTokenPrice, _marketInfo] = yield Promise.all([
35
+ isTokenUSDA ? Promise.resolve('100000000') : feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, USD_QUOTE).call(),
36
+ morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
37
+ ]);
38
+ marketInfo = _marketInfo;
39
+ loanTokenPrice = _loanTokenPrice;
40
+ }
41
+ else {
42
+ // Currently only base network is supported
43
+ const feedRegistryContract = DFSFeedRegistryContract(web3, network);
44
+ const [loanTokenPriceRound, _marketInfo] = yield Promise.all([
45
+ isTokenUSDA ? Promise.resolve({ answer: '100000000' }) // Normalize to match the expected object structure
46
+ : feedRegistryContract.methods.latestRoundData(loanTokenFeedAddress, USD_QUOTE).call(),
47
+ morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
48
+ ]);
49
+ marketInfo = _marketInfo;
50
+ loanTokenPrice = loanTokenPriceRound.answer;
51
+ }
35
52
  const supplyRate = getSupplyRate(marketInfo.totalSupplyAssets, marketInfo.totalBorrowAssets, marketInfo.borrowRate, marketInfo.fee);
36
53
  const compoundedBorrowRate = getBorrowRate(marketInfo.borrowRate, marketInfo.totalBorrowShares);
37
54
  const utillization = new Dec(marketInfo.totalBorrowAssets).div(marketInfo.totalSupplyAssets).mul(100).toString();
@@ -1,5 +1,7 @@
1
1
  import Web3 from 'web3';
2
+ import { NetworkNumber } from '../types/common';
2
3
  export declare const getEthPrice: (web3: Web3) => Promise<string>;
3
4
  export declare const getUSDCPrice: (web3: Web3) => Promise<string>;
4
5
  export declare const getCompPrice: (web3: Web3) => Promise<string>;
5
6
  export declare const getWstETHPrice: (web3: Web3) => Promise<string>;
7
+ export declare const getChainlinkAssetAddress: (symbol: string, network: NetworkNumber) => string;
@@ -8,6 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import Dec from 'decimal.js';
11
+ import { getAssetInfo } from '@defisaver/tokens';
11
12
  import { COMPPriceFeedContract, ETHPriceFeedContract, USDCPriceFeedContract, WstETHPriceFeedContract, } from '../contracts';
12
13
  import { NetworkNumber } from '../types/common';
13
14
  import { multicall } from '../multicall';
@@ -46,3 +47,11 @@ export const getWstETHPrice = (web3) => __awaiter(void 0, void 0, void 0, functi
46
47
  const wstETHRate = new Dec(multicallRes[1].answer).div(1e8);
47
48
  return new Dec(ethPrice).mul(wstETHRate).toString();
48
49
  });
50
+ // chainlink price feed available only on mainnet
51
+ export const getChainlinkAssetAddress = (symbol, network) => {
52
+ if (['WBTC', 'RENBTC'].includes(symbol === null || symbol === void 0 ? void 0 : symbol.toUpperCase()))
53
+ return '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB';
54
+ if ((symbol === null || symbol === void 0 ? void 0 : symbol.toUpperCase()) === 'WETH')
55
+ return getAssetInfo('ETH').addresses[network];
56
+ return getAssetInfo(symbol).addresses[network];
57
+ };
@@ -0,0 +1,40 @@
1
+ /// <reference types="node" />
2
+ import type BN from "bn.js";
3
+ import type { ContractOptions } from "web3-eth-contract";
4
+ import type { EventLog } from "web3-core";
5
+ import type { EventEmitter } from "events";
6
+ import type { Callback, NonPayableTransactionObject, BlockType, BaseContract } from "./types";
7
+ export interface EventOptions {
8
+ filter?: object;
9
+ fromBlock?: BlockType;
10
+ topics?: string[];
11
+ }
12
+ export interface DFSFeedRegistry extends BaseContract {
13
+ constructor(jsonInterface: any[], address?: string, options?: ContractOptions): DFSFeedRegistry;
14
+ clone(): DFSFeedRegistry;
15
+ methods: {
16
+ adminVault(): NonPayableTransactionObject<string>;
17
+ aggregators(arg0: string, arg1: string): NonPayableTransactionObject<string>;
18
+ getFeed(base: string, quote: string): NonPayableTransactionObject<string>;
19
+ kill(): NonPayableTransactionObject<void>;
20
+ latestRoundData(base: string, quote: string): NonPayableTransactionObject<[
21
+ string,
22
+ string,
23
+ string,
24
+ string,
25
+ string
26
+ ] & {
27
+ roundId: string;
28
+ answer: string;
29
+ startedAt: string;
30
+ updatedAt: string;
31
+ answeredInRound: string;
32
+ }>;
33
+ setFeed(base: string, quote: string, aggregator: string): NonPayableTransactionObject<void>;
34
+ setFeeds(bases: string[], quotes: string[], aggregator: string[]): NonPayableTransactionObject<void>;
35
+ withdrawStuckFunds(_token: string, _receiver: string, _amount: number | string | BN): NonPayableTransactionObject<void>;
36
+ };
37
+ events: {
38
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
39
+ };
40
+ }
@@ -0,0 +1,4 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+ export {};
@@ -24,6 +24,7 @@ export type { CompV3BulkerMainnetUSDC } from "./CompV3BulkerMainnetUSDC";
24
24
  export type { CompV3View } from "./CompV3View";
25
25
  export type { CompoundLoanInfo } from "./CompoundLoanInfo";
26
26
  export type { Comptroller } from "./Comptroller";
27
+ export type { DFSFeedRegistry } from "./DFSFeedRegistry";
27
28
  export type { ETHPriceFeed } from "./ETHPriceFeed";
28
29
  export type { Erc20 } from "./Erc20";
29
30
  export type { EulerV2View } from "./EulerV2View";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defisaver/positions-sdk",
3
- "version": "0.0.185-dev-1",
3
+ "version": "0.0.185-dev-4",
4
4
  "description": "",
5
5
  "main": "./cjs/index.js",
6
6
  "module": "./esm/index.js",
@@ -234,15 +234,11 @@ export const getCompoundV3AccountData = async (
234
234
  if (loanData.borrowAmount.toString() !== '0') {
235
235
  usedAssets[baseAssetSymbol].isBorrowed = true;
236
236
  usedAssets[baseAssetSymbol].borrowed = assetAmountInEth(loanData.borrowAmount, baseAssetInfo.symbol);
237
- if (selectedMarket.value === COMPOUND_V3_ETH(network).value) {
238
- usedAssets[baseAssetSymbol].borrowedUsd = new Dec(
239
- assetAmountInEth(loanData.borrowValue, baseAssetInfo.symbol),
240
- )
241
- .mul(assetsData[baseAssetSymbol].price)
242
- .toString();
243
- } else {
244
- usedAssets[baseAssetSymbol].borrowedUsd = assetAmountInEth(loanData.borrowValue, baseAssetInfo.symbol);
245
- }
237
+ usedAssets[baseAssetSymbol].borrowedUsd = new Dec(
238
+ assetAmountInEth(loanData.borrowValue, baseAssetInfo.symbol),
239
+ )
240
+ .mul(assetsData[baseAssetSymbol].price)
241
+ .toString();
246
242
  }
247
243
  const supportedAssetsAddresses = getSupportedAssetsAddressesForMarket(selectedMarket, network);
248
244
 
@@ -1045,6 +1045,12 @@ module.exports = {
1045
1045
  "1": { "address": "0x47Fb2585D2C56Fe188D0E6ec628a38b74fCeeeDf" },
1046
1046
  }
1047
1047
  },
1048
+ "DFSFeedRegistry": {
1049
+ "abi": [{"inputs":[],"name":"NonContractCall","type":"error"},{"inputs":[],"name":"SenderNotAdmin","type":"error"},{"inputs":[],"name":"SenderNotOwner","type":"error"},{"inputs":[],"name":"adminVault","outputs":[{"internalType":"contract AdminVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"}],"name":"aggregators","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"base","type":"address"},{"internalType":"address","name":"quote","type":"address"}],"name":"getFeed","outputs":[{"internalType":"address","name":"aggregator","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"kill","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"base","type":"address"},{"internalType":"address","name":"quote","type":"address"}],"name":"latestRoundData","outputs":[{"internalType":"uint80","name":"roundId","type":"uint80"},{"internalType":"int256","name":"answer","type":"int256"},{"internalType":"uint256","name":"startedAt","type":"uint256"},{"internalType":"uint256","name":"updatedAt","type":"uint256"},{"internalType":"uint80","name":"answeredInRound","type":"uint80"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"base","type":"address"},{"internalType":"address","name":"quote","type":"address"},{"internalType":"address","name":"aggregator","type":"address"}],"name":"setFeed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"bases","type":"address[]"},{"internalType":"address[]","name":"quotes","type":"address[]"},{"internalType":"address[]","name":"aggregator","type":"address[]"}],"name":"setFeeds","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_receiver","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawStuckFunds","outputs":[],"stateMutability":"nonpayable","type":"function"}],
1050
+ "networks": {
1051
+ "8453": { "address": "0x7dFF34190d0307fC234fc7E8C152C9715083eB02" },
1052
+ }
1053
+ },
1048
1054
  "LlamaLendView": {
1049
1055
  "abi": [{"inputs":[],"name":"InvalidLlamaLendController","type":"error"},{"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 LlamaLendView.Band[]","name":"bands","type":"tuple[]"}],"internalType":"struct LlamaLendView.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 LlamaLendView.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 LlamaLendView.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 LlamaLendView.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":"debtAssetCollAmount","type":"uint256"},{"internalType":"uint256","name":"collAssetCollAmount","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":"collateralToken","type":"address"},{"internalType":"address","name":"debtToken","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":"uint256","name":"borrowApr","type":"uint256"},{"internalType":"uint256","name":"lendApr","type":"uint256"},{"internalType":"uint256","name":"debtTokenTotalSupply","type":"uint256"},{"internalType":"uint256","name":"debtTokenLeftToBorrow","type":"uint256"},{"internalType":"uint256","name":"loanDiscount","type":"uint256"}],"internalType":"struct LlamaLendView.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"},{"internalType":"uint256","name":"_controllerId","type":"uint256"}],"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":"debtTokenCollateralAmount","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":"uint256","name":"debtTokenSuppliedShares","type":"uint256"},{"internalType":"uint256","name":"debtTokenSuppliedAssets","type":"uint256"}],"internalType":"struct LlamaLendView.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"}],
1050
1056
  "networks": {
package/src/contracts.ts CHANGED
@@ -123,6 +123,7 @@ export const USDCPriceFeedContract = createContractFromConfigFunc<ContractTypes.
123
123
  export const WstETHPriceFeedContract = createContractFromConfigFunc<ContractTypes.WstETHPriceFeed>('WstETHPriceFeed');
124
124
 
125
125
  export const FeedRegistryContract = createContractFromConfigFunc<ContractTypes.FeedRegistry>('FeedRegistry');
126
+ export const DFSFeedRegistryContract = createContractFromConfigFunc<ContractTypes.DFSFeedRegistry>('DFSFeedRegistry');
126
127
 
127
128
  export const MorphoBlueViewContract = createContractFromConfigFunc<ContractTypes.MorphoBlueView>('MorphoBlueView');
128
129
 
@@ -723,7 +723,7 @@ export const MORPHO_BLUE_CBBTC_USDC_860_BASE = (networkId: NetworkNumber = Netwo
723
723
  export const MORPHO_BLUE_WSUPEROETHB_WETH_915_BASE = (networkId: NetworkNumber = NetworkNumber.Eth): MorphoBlueMarketData => ({
724
724
  chainIds: [NetworkNumber.Base],
725
725
  label: 'Morpho',
726
- shortLabel: 'wsuperOETHb/WETH',
726
+ shortLabel: 'wsuperOETHb/ETH',
727
727
  value: MorphoBlueVersions.MorphoBlueWsuperOETHbWETH_915_Base,
728
728
  url: 'wsuperoethbweth-144bf18d',
729
729
  loanToken: '0x4200000000000000000000000000000000000006',
@@ -1,41 +1,60 @@
1
1
  import Web3 from 'web3';
2
2
  import Dec from 'decimal.js';
3
- import { assetAmountInEth, getAssetInfo, getAssetInfoByAddress } from '@defisaver/tokens';
3
+ import {
4
+ assetAmountInEth, AssetData, getAssetInfo, getAssetInfoByAddress,
5
+ } from '@defisaver/tokens';
4
6
  import {
5
7
  Blockish, EthAddress, MMUsedAssets, NetworkNumber, PositionBalances,
6
8
  } from '../types/common';
7
- import {
8
- FeedRegistryContract,
9
- MorphoBlueViewContract,
10
- } from '../contracts';
9
+ import { DFSFeedRegistryContract, FeedRegistryContract, MorphoBlueViewContract } from '../contracts';
11
10
  import {
12
11
  MorphoBlueAssetsData, MorphoBlueMarketData, MorphoBlueMarketInfo, MorphoBluePositionData,
13
12
  } from '../types';
14
- import { WAD, USD_QUOTE } from '../constants';
13
+ import { USD_QUOTE, WAD } from '../constants';
15
14
  import { getStakingApy, STAKING_ASSETS } from '../staking';
16
15
  import { wethToEth } from '../services/utils';
17
16
  import { getBorrowRate, getMorphoBlueAggregatedPositionData, getSupplyRate } from '../helpers/morphoBlueHelpers';
17
+ import { getChainlinkAssetAddress } from '../services/priceService';
18
+
19
+ const isMainnetNetwork = (network: NetworkNumber) => network === NetworkNumber.Eth;
18
20
 
19
21
  export async function getMorphoBlueMarketData(web3: Web3, network: NetworkNumber, selectedMarket: MorphoBlueMarketData, mainnetWeb3: Web3): Promise<MorphoBlueMarketInfo> {
20
22
  const {
21
23
  loanToken, collateralToken, oracle, irm, lltv, oracleType,
22
24
  } = selectedMarket;
25
+
23
26
  const lltvInWei = new Dec(lltv).mul(WAD).toString();
24
27
  const loanTokenInfo = getAssetInfoByAddress(loanToken, network);
25
28
  const collateralTokenInfo = getAssetInfoByAddress(collateralToken, network);
26
- let loanTokenFeedAddress = loanTokenInfo.addresses[NetworkNumber.Eth];
27
- if (loanTokenInfo.symbol === 'WETH') {
28
- const ethAddress = getAssetInfo('ETH').address;
29
- loanTokenFeedAddress = ethAddress;
30
- }
31
29
 
32
- const feedRegistryContract = FeedRegistryContract(mainnetWeb3, NetworkNumber.Eth);
30
+ const loanTokenFeedAddress = getChainlinkAssetAddress(loanTokenInfo.symbol, network);
31
+
33
32
  const morphoBlueViewContract = MorphoBlueViewContract(web3, network);
34
33
 
35
- const [loanTokenPrice, marketInfo] = await Promise.all([
36
- loanTokenInfo.symbol === 'USDA' ? '100000000' : feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, USD_QUOTE).call(),
37
- morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
38
- ]);
34
+ let marketInfo;
35
+ let loanTokenPrice;
36
+ const isTokenUSDA = loanTokenInfo.symbol === 'USDA';
37
+ const isMainnet = isMainnetNetwork(network);
38
+ if (isMainnet) {
39
+ const feedRegistryContract = FeedRegistryContract(mainnetWeb3, NetworkNumber.Eth);
40
+ const [_loanTokenPrice, _marketInfo] = await Promise.all([
41
+ isTokenUSDA ? Promise.resolve('100000000') : feedRegistryContract.methods.latestAnswer(loanTokenFeedAddress, USD_QUOTE).call(),
42
+ morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
43
+ ]);
44
+ marketInfo = _marketInfo;
45
+ loanTokenPrice = _loanTokenPrice;
46
+ } else {
47
+ // Currently only base network is supported
48
+ const feedRegistryContract = DFSFeedRegistryContract(web3, network);
49
+
50
+ const [loanTokenPriceRound, _marketInfo] = await Promise.all([
51
+ isTokenUSDA ? Promise.resolve({ answer: '100000000' }) // Normalize to match the expected object structure
52
+ : feedRegistryContract.methods.latestRoundData(loanTokenFeedAddress, USD_QUOTE).call(),
53
+ morphoBlueViewContract.methods.getMarketInfoNotTuple(loanToken, collateralToken, oracle, irm, lltvInWei).call(),
54
+ ]);
55
+ marketInfo = _marketInfo;
56
+ loanTokenPrice = loanTokenPriceRound.answer;
57
+ }
39
58
 
40
59
  const supplyRate = getSupplyRate(marketInfo.totalSupplyAssets, marketInfo.totalBorrowAssets, marketInfo.borrowRate, marketInfo.fee);
41
60
  const compoundedBorrowRate = getBorrowRate(marketInfo.borrowRate, marketInfo.totalBorrowShares);
@@ -1,5 +1,6 @@
1
1
  import Web3 from 'web3';
2
2
  import Dec from 'decimal.js';
3
+ import { getAssetInfo } from '@defisaver/tokens';
3
4
  import {
4
5
  COMPPriceFeedContract,
5
6
  ETHPriceFeedContract,
@@ -50,4 +51,11 @@ export const getWstETHPrice = async (web3: Web3) => {
50
51
  const wstETHRate = new Dec(multicallRes[1].answer).div(1e8);
51
52
 
52
53
  return new Dec(ethPrice).mul(wstETHRate).toString();
53
- };
54
+ };
55
+
56
+ // chainlink price feed available only on mainnet
57
+ export const getChainlinkAssetAddress = (symbol: string, network: NetworkNumber) => {
58
+ if (['WBTC', 'RENBTC'].includes(symbol?.toUpperCase())) return '0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB';
59
+ if (symbol?.toUpperCase() === 'WETH') return getAssetInfo('ETH').addresses[network];
60
+ return getAssetInfo(symbol).addresses[network];
61
+ };
@@ -0,0 +1,77 @@
1
+ /* Autogenerated file. Do not edit manually. */
2
+ /* tslint:disable */
3
+ /* eslint-disable */
4
+
5
+ import type BN from "bn.js";
6
+ import type { ContractOptions } from "web3-eth-contract";
7
+ import type { EventLog } from "web3-core";
8
+ import type { EventEmitter } from "events";
9
+ import type {
10
+ Callback,
11
+ PayableTransactionObject,
12
+ NonPayableTransactionObject,
13
+ BlockType,
14
+ ContractEventLog,
15
+ BaseContract,
16
+ } from "./types";
17
+
18
+ export interface EventOptions {
19
+ filter?: object;
20
+ fromBlock?: BlockType;
21
+ topics?: string[];
22
+ }
23
+
24
+ export interface DFSFeedRegistry extends BaseContract {
25
+ constructor(
26
+ jsonInterface: any[],
27
+ address?: string,
28
+ options?: ContractOptions
29
+ ): DFSFeedRegistry;
30
+ clone(): DFSFeedRegistry;
31
+ methods: {
32
+ adminVault(): NonPayableTransactionObject<string>;
33
+
34
+ aggregators(
35
+ arg0: string,
36
+ arg1: string
37
+ ): NonPayableTransactionObject<string>;
38
+
39
+ getFeed(base: string, quote: string): NonPayableTransactionObject<string>;
40
+
41
+ kill(): NonPayableTransactionObject<void>;
42
+
43
+ latestRoundData(
44
+ base: string,
45
+ quote: string
46
+ ): NonPayableTransactionObject<
47
+ [string, string, string, string, string] & {
48
+ roundId: string;
49
+ answer: string;
50
+ startedAt: string;
51
+ updatedAt: string;
52
+ answeredInRound: string;
53
+ }
54
+ >;
55
+
56
+ setFeed(
57
+ base: string,
58
+ quote: string,
59
+ aggregator: string
60
+ ): NonPayableTransactionObject<void>;
61
+
62
+ setFeeds(
63
+ bases: string[],
64
+ quotes: string[],
65
+ aggregator: string[]
66
+ ): NonPayableTransactionObject<void>;
67
+
68
+ withdrawStuckFunds(
69
+ _token: string,
70
+ _receiver: string,
71
+ _amount: number | string | BN
72
+ ): NonPayableTransactionObject<void>;
73
+ };
74
+ events: {
75
+ allEvents(options?: EventOptions, cb?: Callback<EventLog>): EventEmitter;
76
+ };
77
+ }
@@ -27,6 +27,7 @@ export type { CompV3BulkerMainnetUSDC } from "./CompV3BulkerMainnetUSDC";
27
27
  export type { CompV3View } from "./CompV3View";
28
28
  export type { CompoundLoanInfo } from "./CompoundLoanInfo";
29
29
  export type { Comptroller } from "./Comptroller";
30
+ export type { DFSFeedRegistry } from "./DFSFeedRegistry";
30
31
  export type { ETHPriceFeed } from "./ETHPriceFeed";
31
32
  export type { Erc20 } from "./Erc20";
32
33
  export type { EulerV2View } from "./EulerV2View";