@defisaver/positions-sdk 0.0.165 → 0.0.166-dev2

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 (69) hide show
  1. package/cjs/config/contracts.d.ts +72 -0
  2. package/cjs/config/contracts.js +6 -0
  3. package/cjs/contracts.d.ts +1 -0
  4. package/cjs/contracts.js +2 -1
  5. package/cjs/eulerV2/index.d.ts +40 -0
  6. package/cjs/eulerV2/index.js +207 -0
  7. package/cjs/helpers/eulerHelpers/index.d.ts +27 -0
  8. package/cjs/helpers/eulerHelpers/index.js +232 -0
  9. package/cjs/helpers/index.d.ts +1 -0
  10. package/cjs/helpers/index.js +2 -1
  11. package/cjs/index.d.ts +2 -1
  12. package/cjs/index.js +3 -1
  13. package/cjs/markets/euler/index.d.ts +10 -0
  14. package/cjs/markets/euler/index.js +41 -0
  15. package/cjs/markets/index.d.ts +1 -0
  16. package/cjs/markets/index.js +3 -1
  17. package/cjs/services/utils.d.ts +2 -0
  18. package/cjs/services/utils.js +4 -1
  19. package/cjs/staking/staking.d.ts +1 -0
  20. package/cjs/staking/staking.js +10 -2
  21. package/cjs/types/contracts/generated/EulerV2View.d.ts +333 -0
  22. package/cjs/types/contracts/generated/EulerV2View.js +5 -0
  23. package/cjs/types/contracts/generated/index.d.ts +1 -0
  24. package/cjs/types/euler.d.ts +148 -0
  25. package/cjs/types/euler.js +15 -0
  26. package/cjs/types/index.d.ts +1 -0
  27. package/cjs/types/index.js +1 -0
  28. package/esm/config/contracts.d.ts +72 -0
  29. package/esm/config/contracts.js +6 -0
  30. package/esm/contracts.d.ts +1 -0
  31. package/esm/contracts.js +1 -0
  32. package/esm/eulerV2/index.d.ts +40 -0
  33. package/esm/eulerV2/index.js +199 -0
  34. package/esm/helpers/eulerHelpers/index.d.ts +27 -0
  35. package/esm/helpers/eulerHelpers/index.js +219 -0
  36. package/esm/helpers/index.d.ts +1 -0
  37. package/esm/helpers/index.js +1 -0
  38. package/esm/index.d.ts +2 -1
  39. package/esm/index.js +2 -1
  40. package/esm/markets/euler/index.d.ts +10 -0
  41. package/esm/markets/euler/index.js +34 -0
  42. package/esm/markets/index.d.ts +1 -0
  43. package/esm/markets/index.js +1 -0
  44. package/esm/services/utils.d.ts +2 -0
  45. package/esm/services/utils.js +2 -0
  46. package/esm/staking/staking.d.ts +1 -0
  47. package/esm/staking/staking.js +8 -1
  48. package/esm/types/contracts/generated/EulerV2View.d.ts +333 -0
  49. package/esm/types/contracts/generated/EulerV2View.js +4 -0
  50. package/esm/types/contracts/generated/index.d.ts +1 -0
  51. package/esm/types/euler.d.ts +148 -0
  52. package/esm/types/euler.js +12 -0
  53. package/esm/types/index.d.ts +1 -0
  54. package/esm/types/index.js +1 -0
  55. package/package.json +2 -1
  56. package/src/config/contracts.js +6 -0
  57. package/src/contracts.ts +2 -0
  58. package/src/eulerV2/index.ts +286 -0
  59. package/src/helpers/eulerHelpers/index.ts +231 -0
  60. package/src/helpers/index.ts +2 -1
  61. package/src/index.ts +2 -0
  62. package/src/markets/euler/index.ts +38 -0
  63. package/src/markets/index.ts +3 -1
  64. package/src/services/utils.ts +3 -0
  65. package/src/staking/staking.ts +8 -1
  66. package/src/types/contracts/generated/EulerV2View.ts +434 -0
  67. package/src/types/contracts/generated/index.ts +1 -0
  68. package/src/types/euler.ts +171 -0
  69. package/src/types/index.ts +2 -1
@@ -1030,4 +1030,10 @@ module.exports = {
1030
1030
  "abi": [{ "name": "UserState", "inputs": [{ "name": "user", "type": "address", "indexed": true }, { "name": "collateral", "type": "uint256", "indexed": false }, { "name": "debt", "type": "uint256", "indexed": false }, { "name": "n1", "type": "int256", "indexed": false }, { "name": "n2", "type": "int256", "indexed": false }, { "name": "liquidation_discount", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "Borrow", "inputs": [{ "name": "user", "type": "address", "indexed": true }, { "name": "collateral_increase", "type": "uint256", "indexed": false }, { "name": "loan_increase", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "Repay", "inputs": [{ "name": "user", "type": "address", "indexed": true }, { "name": "collateral_decrease", "type": "uint256", "indexed": false }, { "name": "loan_decrease", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "RemoveCollateral", "inputs": [{ "name": "user", "type": "address", "indexed": true }, { "name": "collateral_decrease", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "Liquidate", "inputs": [{ "name": "liquidator", "type": "address", "indexed": true }, { "name": "user", "type": "address", "indexed": true }, { "name": "collateral_received", "type": "uint256", "indexed": false }, { "name": "stablecoin_received", "type": "uint256", "indexed": false }, { "name": "debt", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "SetMonetaryPolicy", "inputs": [{ "name": "monetary_policy", "type": "address", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "SetBorrowingDiscounts", "inputs": [{ "name": "loan_discount", "type": "uint256", "indexed": false }, { "name": "liquidation_discount", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "name": "CollectFees", "inputs": [{ "name": "amount", "type": "uint256", "indexed": false }, { "name": "new_supply", "type": "uint256", "indexed": false }], "anonymous": false, "type": "event" }, { "stateMutability": "nonpayable", "type": "constructor", "inputs": [{ "name": "collateral_token", "type": "address" }, { "name": "monetary_policy", "type": "address" }, { "name": "loan_discount", "type": "uint256" }, { "name": "liquidation_discount", "type": "uint256" }, { "name": "amm", "type": "address" }], "outputs": [] }, { "stateMutability": "pure", "type": "function", "name": "factory", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "pure", "type": "function", "name": "amm", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "pure", "type": "function", "name": "collateral_token", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "pure", "type": "function", "name": "borrowed_token", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "save_rate", "inputs": [], "outputs": [] }, { "stateMutability": "view", "type": "function", "name": "debt", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "loan_exists", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "bool" }] }, { "stateMutability": "view", "type": "function", "name": "total_debt", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "max_borrowable", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "N", "type": "uint256" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "max_borrowable", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "N", "type": "uint256" }, { "name": "current_debt", "type": "uint256" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "min_collateral", "inputs": [{ "name": "debt", "type": "uint256" }, { "name": "N", "type": "uint256" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "calculate_debt_n1", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "N", "type": "uint256" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "create_loan", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "N", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "create_loan_extended", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "N", "type": "uint256" }, { "name": "callbacker", "type": "address" }, { "name": "callback_args", "type": "uint256[]" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "add_collateral", "inputs": [{ "name": "collateral", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "add_collateral", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "_for", "type": "address" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "remove_collateral", "inputs": [{ "name": "collateral", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "remove_collateral", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "use_eth", "type": "bool" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "borrow_more", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "borrow_more_extended", "inputs": [{ "name": "collateral", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "callbacker", "type": "address" }, { "name": "callback_args", "type": "uint256[]" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay", "inputs": [{ "name": "_d_debt", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay", "inputs": [{ "name": "_d_debt", "type": "uint256" }, { "name": "_for", "type": "address" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay", "inputs": [{ "name": "_d_debt", "type": "uint256" }, { "name": "_for", "type": "address" }, { "name": "max_active_band", "type": "int256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay", "inputs": [{ "name": "_d_debt", "type": "uint256" }, { "name": "_for", "type": "address" }, { "name": "max_active_band", "type": "int256" }, { "name": "use_eth", "type": "bool" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "repay_extended", "inputs": [{ "name": "callbacker", "type": "address" }, { "name": "callback_args", "type": "uint256[]" }], "outputs": [] }, { "stateMutability": "view", "type": "function", "name": "health_calculator", "inputs": [{ "name": "user", "type": "address" }, { "name": "d_collateral", "type": "int256" }, { "name": "d_debt", "type": "int256" }, { "name": "full", "type": "bool" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "view", "type": "function", "name": "health_calculator", "inputs": [{ "name": "user", "type": "address" }, { "name": "d_collateral", "type": "int256" }, { "name": "d_debt", "type": "int256" }, { "name": "full", "type": "bool" }, { "name": "N", "type": "uint256" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "liquidate", "inputs": [{ "name": "user", "type": "address" }, { "name": "min_x", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "liquidate", "inputs": [{ "name": "user", "type": "address" }, { "name": "min_x", "type": "uint256" }, { "name": "use_eth", "type": "bool" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "liquidate_extended", "inputs": [{ "name": "user", "type": "address" }, { "name": "min_x", "type": "uint256" }, { "name": "frac", "type": "uint256" }, { "name": "use_eth", "type": "bool" }, { "name": "callbacker", "type": "address" }, { "name": "callback_args", "type": "uint256[]" }], "outputs": [] }, { "stateMutability": "view", "type": "function", "name": "tokens_to_liquidate", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "tokens_to_liquidate", "inputs": [{ "name": "user", "type": "address" }, { "name": "frac", "type": "uint256" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "health", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "view", "type": "function", "name": "health", "inputs": [{ "name": "user", "type": "address" }, { "name": "full", "type": "bool" }], "outputs": [{ "name": "", "type": "int256" }] }, { "stateMutability": "view", "type": "function", "name": "users_to_liquidate", "inputs": [], "outputs": [{ "name": "", "type": "tuple[]", "components": [{ "name": "user", "type": "address" }, { "name": "x", "type": "uint256" }, { "name": "y", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "health", "type": "int256" }] }] }, { "stateMutability": "view", "type": "function", "name": "users_to_liquidate", "inputs": [{ "name": "_from", "type": "uint256" }], "outputs": [{ "name": "", "type": "tuple[]", "components": [{ "name": "user", "type": "address" }, { "name": "x", "type": "uint256" }, { "name": "y", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "health", "type": "int256" }] }] }, { "stateMutability": "view", "type": "function", "name": "users_to_liquidate", "inputs": [{ "name": "_from", "type": "uint256" }, { "name": "_limit", "type": "uint256" }], "outputs": [{ "name": "", "type": "tuple[]", "components": [{ "name": "user", "type": "address" }, { "name": "x", "type": "uint256" }, { "name": "y", "type": "uint256" }, { "name": "debt", "type": "uint256" }, { "name": "health", "type": "int256" }] }] }, { "stateMutability": "view", "type": "function", "name": "amm_price", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "user_prices", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "uint256[2]" }] }, { "stateMutability": "view", "type": "function", "name": "user_state", "inputs": [{ "name": "user", "type": "address" }], "outputs": [{ "name": "", "type": "uint256[4]" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_amm_fee", "inputs": [{ "name": "fee", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_amm_admin_fee", "inputs": [{ "name": "fee", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_monetary_policy", "inputs": [{ "name": "monetary_policy", "type": "address" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_borrowing_discounts", "inputs": [{ "name": "loan_discount", "type": "uint256" }, { "name": "liquidation_discount", "type": "uint256" }], "outputs": [] }, { "stateMutability": "nonpayable", "type": "function", "name": "set_callback", "inputs": [{ "name": "cb", "type": "address" }], "outputs": [] }, { "stateMutability": "view", "type": "function", "name": "admin_fees", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "nonpayable", "type": "function", "name": "collect_fees", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "check_lock", "inputs": [], "outputs": [{ "name": "", "type": "bool" }] }, { "stateMutability": "view", "type": "function", "name": "liquidation_discounts", "inputs": [{ "name": "arg0", "type": "address" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "loans", "inputs": [{ "name": "arg0", "type": "uint256" }], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "view", "type": "function", "name": "loan_ix", "inputs": [{ "name": "arg0", "type": "address" }], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "n_loans", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "minted", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "redeemed", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "monetary_policy", "inputs": [], "outputs": [{ "name": "", "type": "address" }] }, { "stateMutability": "view", "type": "function", "name": "liquidation_discount", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }, { "stateMutability": "view", "type": "function", "name": "loan_discount", "inputs": [], "outputs": [{ "name": "", "type": "uint256" }] }],
1031
1031
  "networks": {}
1032
1032
  },
1033
+ "EulerV2View": {
1034
+ "abi": [{ "inputs": [], "name": "USD", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [], "name": "feedRegistry", "outputs": [{ "internalType": "contract IFeedRegistry", "name": "", "type": "address" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_account", "type": "address" }, { "internalType": "uint256", "name": "_page", "type": "uint256" }, { "internalType": "uint256", "name": "_perPage", "type": "uint256" }], "name": "fetchUsedAccounts", "outputs": [{ "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "address[]", "name": "accounts", "type": "address[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getAaveTokenPriceInETH", "outputs": [{ "internalType": "uint256", "name": "price", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getAaveTokenPriceInUSD", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getAaveV3TokenPriceInETH", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getAaveV3TokenPriceInUSD", "outputs": [{ "internalType": "uint256", "name": "price", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }], "name": "getAddrForChainlinkOracle", "outputs": [{ "internalType": "address", "name": "tokenAddrForChainlinkUsage", "type": "address" }], "stateMutability": "pure", "type": "function" }, { "inputs": [{ "components": [{ "internalType": "address", "name": "vault", "type": "address" }, { "internalType": "bool", "name": "isBorrowOperation", "type": "bool" }, { "internalType": "uint256", "name": "liquidityAdded", "type": "uint256" }, { "internalType": "uint256", "name": "liquidityRemoved", "type": "uint256" }], "internalType": "struct EulerV2View.LiquidityChangeParams[]", "name": "params", "type": "tuple[]" }], "name": "getApyAfterValuesEstimation", "outputs": [{ "internalType": "uint256[]", "name": "estimatedBorrowRates", "type": "uint256[]" }], "stateMutability": "nonpayable", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }], "name": "getChainlinkPriceInETH", "outputs": [{ "internalType": "int256", "name": "chainlinkPriceInETH", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }, { "internalType": "bool", "name": "_useFallback", "type": "bool" }], "name": "getChainlinkPriceInUSD", "outputs": [{ "internalType": "int256", "name": "chainlinkPriceInUSD", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }], "name": "getPriceInETH", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }], "name": "getPriceInUSD", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }, { "internalType": "uint80", "name": "_roundId", "type": "uint80" }, { "internalType": "contract IAggregatorV3", "name": "aggregator", "type": "address" }], "name": "getRoundInfo", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "uint256", "name": "updateTimestamp", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_inputTokenAddr", "type": "address" }, { "internalType": "uint80", "name": "_roundId", "type": "uint80" }], "name": "getRoundInfo", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }, { "internalType": "uint256", "name": "updateTimestamp", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getSparkTokenPriceInETH", "outputs": [{ "internalType": "uint256", "name": "", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_tokenAddr", "type": "address" }], "name": "getSparkTokenPriceInUSD", "outputs": [{ "internalType": "uint256", "name": "price", "type": "uint256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_user", "type": "address" }], "name": "getUserData", "outputs": [{ "components": [{ "internalType": "address", "name": "user", "type": "address" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "bool", "name": "inLockDownMode", "type": "bool" }, { "internalType": "bool", "name": "inPermitDisabledMode", "type": "bool" }, { "internalType": "address", "name": "borrowVault", "type": "address" }, { "internalType": "uint256", "name": "borrowAmountInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowAmountInAsset", "type": "uint256" }, { "components": [{ "internalType": "address", "name": "collateralVault", "type": "address" }, { "internalType": "bool", "name": "usedInBorrow", "type": "bool" }, { "internalType": "uint256", "name": "collateralAmountInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "collateralAmountInAsset", "type": "uint256" }, { "internalType": "uint256", "name": "collateralAmountInUSD", "type": "uint256" }], "internalType": "struct EulerV2View.UserCollateralInfo[]", "name": "collaterals", "type": "tuple[]" }], "internalType": "struct EulerV2View.UserData", "name": "data", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address[]", "name": "_users", "type": "address[]" }], "name": "getUsersData", "outputs": [{ "components": [{ "internalType": "address", "name": "user", "type": "address" }, { "internalType": "address", "name": "owner", "type": "address" }, { "internalType": "bool", "name": "inLockDownMode", "type": "bool" }, { "internalType": "bool", "name": "inPermitDisabledMode", "type": "bool" }, { "internalType": "address", "name": "borrowVault", "type": "address" }, { "internalType": "uint256", "name": "borrowAmountInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "borrowAmountInAsset", "type": "uint256" }, { "components": [{ "internalType": "address", "name": "collateralVault", "type": "address" }, { "internalType": "bool", "name": "usedInBorrow", "type": "bool" }, { "internalType": "uint256", "name": "collateralAmountInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "collateralAmountInAsset", "type": "uint256" }, { "internalType": "uint256", "name": "collateralAmountInUSD", "type": "uint256" }], "internalType": "struct EulerV2View.UserCollateralInfo[]", "name": "collaterals", "type": "tuple[]" }], "internalType": "struct EulerV2View.UserData[]", "name": "data", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_vault", "type": "address" }], "name": "getVaultCollaterals", "outputs": [{ "components": [{ "internalType": "address", "name": "vaultAddr", "type": "address" }, { "internalType": "address", "name": "assetAddr", "type": "address" }, { "internalType": "string", "name": "vaultSymbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "uint256", "name": "sharePriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "assetPriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "cash", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrows", "type": "uint256" }, { "internalType": "uint256", "name": "supplyCap", "type": "uint256" }, { "internalType": "uint16", "name": "borrowLTV", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationLTV", "type": "uint16" }, { "internalType": "uint16", "name": "initialLiquidationLTV", "type": "uint16" }, { "internalType": "uint48", "name": "targetTimestamp", "type": "uint48" }, { "internalType": "uint32", "name": "rampDuration", "type": "uint32" }, { "internalType": "uint256", "name": "interestFee", "type": "uint256" }, { "internalType": "uint256", "name": "interestRate", "type": "uint256" }], "internalType": "struct EulerV2View.CollateralInfo[]", "name": "collateralsInfo", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address", "name": "_vault", "type": "address" }], "name": "getVaultInfoFull", "outputs": [{ "components": [{ "internalType": "address", "name": "vaultAddr", "type": "address" }, { "internalType": "address", "name": "assetAddr", "type": "address" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "symbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "cash", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrows", "type": "uint256" }, { "internalType": "uint256", "name": "totalAssets", "type": "uint256" }, { "internalType": "uint256", "name": "supplyCap", "type": "uint256" }, { "internalType": "uint256", "name": "borrowCap", "type": "uint256" }, { "components": [{ "internalType": "address", "name": "vaultAddr", "type": "address" }, { "internalType": "address", "name": "assetAddr", "type": "address" }, { "internalType": "string", "name": "vaultSymbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "uint256", "name": "sharePriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "assetPriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "cash", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrows", "type": "uint256" }, { "internalType": "uint256", "name": "supplyCap", "type": "uint256" }, { "internalType": "uint16", "name": "borrowLTV", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationLTV", "type": "uint16" }, { "internalType": "uint16", "name": "initialLiquidationLTV", "type": "uint16" }, { "internalType": "uint48", "name": "targetTimestamp", "type": "uint48" }, { "internalType": "uint32", "name": "rampDuration", "type": "uint32" }, { "internalType": "uint256", "name": "interestFee", "type": "uint256" }, { "internalType": "uint256", "name": "interestRate", "type": "uint256" }], "internalType": "struct EulerV2View.CollateralInfo[]", "name": "collaterals", "type": "tuple[]" }, { "internalType": "uint16", "name": "maxLiquidationDiscount", "type": "uint16" }, { "internalType": "uint256", "name": "liquidationCoolOffTime", "type": "uint256" }, { "internalType": "bool", "name": "badDebtSocializationEnabled", "type": "bool" }, { "internalType": "address", "name": "unitOfAccount", "type": "address" }, { "internalType": "uint256", "name": "unitOfAccountInUsd", "type": "uint256" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "uint256", "name": "assetPriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "sharePriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "interestRate", "type": "uint256" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "address", "name": "balanceTrackerAddress", "type": "address" }, { "internalType": "address", "name": "creator", "type": "address" }, { "internalType": "address", "name": "governorAdmin", "type": "address" }, { "internalType": "uint256", "name": "interestFee", "type": "uint256" }], "internalType": "struct EulerV2View.VaultInfoFull", "name": "data", "type": "tuple" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "address[]", "name": "_vaults", "type": "address[]" }], "name": "getVaultsInfosFull", "outputs": [{ "components": [{ "internalType": "address", "name": "vaultAddr", "type": "address" }, { "internalType": "address", "name": "assetAddr", "type": "address" }, { "internalType": "string", "name": "name", "type": "string" }, { "internalType": "string", "name": "symbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "uint256", "name": "totalSupplyShares", "type": "uint256" }, { "internalType": "uint256", "name": "cash", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrows", "type": "uint256" }, { "internalType": "uint256", "name": "totalAssets", "type": "uint256" }, { "internalType": "uint256", "name": "supplyCap", "type": "uint256" }, { "internalType": "uint256", "name": "borrowCap", "type": "uint256" }, { "components": [{ "internalType": "address", "name": "vaultAddr", "type": "address" }, { "internalType": "address", "name": "assetAddr", "type": "address" }, { "internalType": "string", "name": "vaultSymbol", "type": "string" }, { "internalType": "uint256", "name": "decimals", "type": "uint256" }, { "internalType": "uint256", "name": "sharePriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "assetPriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "cash", "type": "uint256" }, { "internalType": "uint256", "name": "totalBorrows", "type": "uint256" }, { "internalType": "uint256", "name": "supplyCap", "type": "uint256" }, { "internalType": "uint16", "name": "borrowLTV", "type": "uint16" }, { "internalType": "uint16", "name": "liquidationLTV", "type": "uint16" }, { "internalType": "uint16", "name": "initialLiquidationLTV", "type": "uint16" }, { "internalType": "uint48", "name": "targetTimestamp", "type": "uint48" }, { "internalType": "uint32", "name": "rampDuration", "type": "uint32" }, { "internalType": "uint256", "name": "interestFee", "type": "uint256" }, { "internalType": "uint256", "name": "interestRate", "type": "uint256" }], "internalType": "struct EulerV2View.CollateralInfo[]", "name": "collaterals", "type": "tuple[]" }, { "internalType": "uint16", "name": "maxLiquidationDiscount", "type": "uint16" }, { "internalType": "uint256", "name": "liquidationCoolOffTime", "type": "uint256" }, { "internalType": "bool", "name": "badDebtSocializationEnabled", "type": "bool" }, { "internalType": "address", "name": "unitOfAccount", "type": "address" }, { "internalType": "uint256", "name": "unitOfAccountInUsd", "type": "uint256" }, { "internalType": "address", "name": "oracle", "type": "address" }, { "internalType": "uint256", "name": "assetPriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "sharePriceInUnit", "type": "uint256" }, { "internalType": "uint256", "name": "interestRate", "type": "uint256" }, { "internalType": "address", "name": "irm", "type": "address" }, { "internalType": "address", "name": "balanceTrackerAddress", "type": "address" }, { "internalType": "address", "name": "creator", "type": "address" }, { "internalType": "address", "name": "governorAdmin", "type": "address" }, { "internalType": "uint256", "name": "interestFee", "type": "uint256" }], "internalType": "struct EulerV2View.VaultInfoFull[]", "name": "data", "type": "tuple[]" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "int256", "name": "_btcPrice", "type": "int256" }], "name": "getWBtcPrice", "outputs": [{ "internalType": "int256", "name": "wBtcPrice", "type": "int256" }], "stateMutability": "view", "type": "function" }, { "inputs": [{ "internalType": "int256", "name": "_stEthPrice", "type": "int256" }], "name": "getWStEthPrice", "outputs": [{ "internalType": "int256", "name": "wStEthPrice", "type": "int256" }], "stateMutability": "view", "type": "function" }],
1035
+ "networks": {
1036
+ "1": { "address": "0x25eCA04532C085F77Ea6CE92C94E9e69896686E6" }
1037
+ }
1038
+ }
1033
1039
  };
@@ -45,3 +45,4 @@ export declare const USDCPriceFeedContract: (web3: Web3, network: NetworkNumber,
45
45
  export declare const FeedRegistryContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.FeedRegistry;
46
46
  export declare const MorphoBlueViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.MorphoBlueView;
47
47
  export declare const LlamaLendViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.LlamaLendView;
48
+ export declare const EulerV2ViewContract: (web3: Web3, network: NetworkNumber, block?: Blockish) => ContractTypes.EulerV2View;
package/esm/contracts.js CHANGED
@@ -77,3 +77,4 @@ export const USDCPriceFeedContract = createContractFromConfigFunc('USDCPriceFeed
77
77
  export const FeedRegistryContract = createContractFromConfigFunc('FeedRegistry');
78
78
  export const MorphoBlueViewContract = createContractFromConfigFunc('MorphoBlueView');
79
79
  export const LlamaLendViewContract = createContractFromConfigFunc('LlamaLendView');
80
+ export const EulerV2ViewContract = createContractFromConfigFunc('EulerV2View');
@@ -0,0 +1,40 @@
1
+ import Web3 from 'web3';
2
+ import { NetworkNumber } from '../types/common';
3
+ import { EulerV2AssetsData, EulerV2FullMarketData, EulerV2Market, EulerV2MarketInfoData, EulerV2PositionData } from '../types';
4
+ export declare const EMPTY_USED_ASSET: {
5
+ isSupplied: boolean;
6
+ isBorrowed: boolean;
7
+ supplied: string;
8
+ suppliedUsd: string;
9
+ borrowed: string;
10
+ borrowedUsd: string;
11
+ symbol: string;
12
+ collateral: boolean;
13
+ vaultAddress: string;
14
+ };
15
+ export declare const getEulerV2MarketsData: (web3: Web3, network: NetworkNumber, selectedMarket: EulerV2Market, defaultWeb3: Web3) => Promise<EulerV2FullMarketData>;
16
+ export declare const EMPTY_EULER_V2_DATA: {
17
+ usedAssets: {};
18
+ suppliedUsd: string;
19
+ borrowedUsd: string;
20
+ borrowLimitUsd: string;
21
+ leftToBorrowUsd: string;
22
+ ratio: string;
23
+ minRatio: string;
24
+ netApy: string;
25
+ incentiveUsd: string;
26
+ totalInterestUsd: string;
27
+ isSubscribedToAutomation: boolean;
28
+ automationResubscribeRequired: boolean;
29
+ borrowVault: string;
30
+ borrowAmountInUnit: string;
31
+ inLockDownMode: boolean;
32
+ inPermitDisabledMode: boolean;
33
+ lastUpdated: number;
34
+ hasBorrowInDifferentVault: boolean;
35
+ };
36
+ export declare const getEulerV2AccountData: (web3: Web3, network: NetworkNumber, address: string, extractedState: ({
37
+ selectedMarket: EulerV2Market;
38
+ assetsData: EulerV2AssetsData;
39
+ marketData: EulerV2MarketInfoData;
40
+ })) => Promise<EulerV2PositionData>;
@@ -0,0 +1,199 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Dec from 'decimal.js';
11
+ import { assetAmountInEth, getAssetInfoByAddress } from '@defisaver/tokens';
12
+ import { getStakingApy, STAKING_ASSETS } from '../staking';
13
+ import { compareAddresses, getEthAmountForDecimals, isMaxuint } from '../services/utils';
14
+ import { EulerV2VaultType, } from '../types';
15
+ import { getEulerV2AggregatedData, getEulerV2BorrowRate, getEulerV2SupplyRate, getUtilizationRate, } from '../helpers/eulerHelpers';
16
+ import { ZERO_ADDRESS } from '../constants';
17
+ import { EulerV2ViewContract } from '../contracts';
18
+ export const EMPTY_USED_ASSET = {
19
+ isSupplied: false,
20
+ isBorrowed: false,
21
+ supplied: '0',
22
+ suppliedUsd: '0',
23
+ borrowed: '0',
24
+ borrowedUsd: '0',
25
+ symbol: '',
26
+ collateral: false,
27
+ vaultAddress: '',
28
+ };
29
+ const UnitOfAccountUSD = '0x0000000000000000000000000000000000000348';
30
+ export const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3) => __awaiter(void 0, void 0, void 0, function* () {
31
+ const contract = EulerV2ViewContract(web3, network);
32
+ const data = yield contract.methods.getVaultInfoFull(selectedMarket.marketAddress).call();
33
+ const isInUSD = compareAddresses(UnitOfAccountUSD, data.unitOfAccount);
34
+ const usdPrice = getEthAmountForDecimals(data.unitOfAccountInUsd, 8);
35
+ // parse collateral tokens
36
+ // imma use address as key for assetsData because there can be more collateral vaults with the same name
37
+ const colls = data.collaterals.map((collateral) => {
38
+ const decimals = collateral.decimals;
39
+ const assetInfo = getAssetInfoByAddress(collateral.assetAddr);
40
+ const borrowRate = getEulerV2BorrowRate(collateral.interestRate);
41
+ const utilizationRate = getUtilizationRate(collateral.totalBorrows, new Dec(collateral.totalBorrows).plus(collateral.cash).toString());
42
+ const supplyRate = getEulerV2SupplyRate(borrowRate, utilizationRate, collateral.interestFee);
43
+ return ({
44
+ vaultAddress: collateral.vaultAddr,
45
+ assetAddress: collateral.assetAddr,
46
+ symbol: assetInfo.symbol,
47
+ vaultSymbol: collateral.vaultSymbol,
48
+ decimals,
49
+ liquidationRatio: new Dec(collateral.liquidationLTV).div(10000).toString(),
50
+ collateralFactor: new Dec(collateral.borrowLTV).div(10000).toString(),
51
+ totalBorrow: getEthAmountForDecimals(collateral.totalBorrows, decimals),
52
+ cash: getEthAmountForDecimals(collateral.cash, decimals),
53
+ supplyCap: isMaxuint(collateral.supplyCap) ? collateral.supplyCap : getEthAmountForDecimals(collateral.supplyCap, decimals),
54
+ borrowCap: '0',
55
+ price: isInUSD ? assetAmountInEth(collateral.assetPriceInUnit) : new Dec(assetAmountInEth(collateral.assetPriceInUnit)).mul(usdPrice).toString(),
56
+ canBeBorrowed: false,
57
+ canBeSupplied: true,
58
+ borrowRate,
59
+ supplyRate,
60
+ utilization: new Dec(utilizationRate).mul(100).toString(),
61
+ });
62
+ });
63
+ for (const coll of colls) {
64
+ if (STAKING_ASSETS.includes(coll.symbol)) {
65
+ coll.incentiveSupplyApy = yield getStakingApy(coll.symbol, defaultWeb3);
66
+ coll.incentiveSupplyToken = coll.symbol;
67
+ }
68
+ }
69
+ const isEscrow = data.collaterals.length === 0;
70
+ const isGoverned = !compareAddresses(data.governorAdmin, ZERO_ADDRESS);
71
+ const vaultType = isEscrow ? EulerV2VaultType.Escrow : (isGoverned ? EulerV2VaultType.Governed : EulerV2VaultType.Ungoverned);
72
+ const decimals = data.decimals;
73
+ // (1 + SPY/10**27) ** secondsPerYear - 1
74
+ const interestRate = data.interestRate;
75
+ const borrowRate = getEulerV2BorrowRate(interestRate);
76
+ const utilizationRate = getUtilizationRate(data.totalBorrows, data.totalAssets);
77
+ const supplyRate = getEulerV2SupplyRate(borrowRate, utilizationRate, data.interestFee);
78
+ const marketAsset = {
79
+ assetAddress: data.assetAddr,
80
+ vaultAddress: data.vaultAddr,
81
+ symbol: selectedMarket.asset,
82
+ vaultSymbol: selectedMarket.shortLabel,
83
+ decimals,
84
+ totalBorrow: getEthAmountForDecimals(data.totalBorrows, decimals),
85
+ cash: getEthAmountForDecimals(data.cash, decimals),
86
+ supplyCap: isMaxuint(data.supplyCap) ? data.supplyCap : getEthAmountForDecimals(data.supplyCap, decimals),
87
+ borrowCap: isMaxuint(data.supplyCap) ? data.borrowCap : getEthAmountForDecimals(data.borrowCap, decimals),
88
+ price: isInUSD ? assetAmountInEth(data.assetPriceInUnit) : new Dec(assetAmountInEth(data.assetPriceInUnit)).mul(usdPrice).toString(),
89
+ sortIndex: 0,
90
+ canBeBorrowed: true,
91
+ canBeSupplied: false,
92
+ borrowRate,
93
+ supplyRate,
94
+ collateralFactor: '0',
95
+ liquidationRatio: '0',
96
+ utilization: new Dec(utilizationRate).mul(100).toString(),
97
+ };
98
+ const assetsData = {
99
+ [data.vaultAddr.toLowerCase()]: marketAsset,
100
+ };
101
+ colls
102
+ .sort((coll1, coll2) => {
103
+ const aMarket = new Dec(coll1.price).times(coll1.totalBorrow).toString();
104
+ const bMarket = new Dec(coll2.price).times(coll2.totalBorrow).toString();
105
+ return new Dec(bMarket).minus(aMarket).toNumber();
106
+ })
107
+ .forEach((market, i) => {
108
+ assetsData[market.vaultAddress.toLowerCase()] = Object.assign(Object.assign({}, market), { sortIndex: i + 1 });
109
+ });
110
+ const marketData = {
111
+ name: data.name,
112
+ symbol: data.symbol,
113
+ decimals: data.decimals,
114
+ irm: data.irm,
115
+ creator: data.creator,
116
+ governorAdmin: data.governorAdmin,
117
+ unitOfAccount: data.unitOfAccount,
118
+ unitOfAccountUsdPrice: usdPrice,
119
+ isInUSD,
120
+ oracle: data.oracle,
121
+ collaterals: data.collaterals.map((collateral) => collateral.vaultAddr),
122
+ isEscrow,
123
+ isGoverned,
124
+ vaultType,
125
+ vaultAddress: data.vaultAddr,
126
+ };
127
+ return {
128
+ marketData,
129
+ assetsData,
130
+ };
131
+ });
132
+ // export const getEulerV2AccountBalances = async (
133
+ // web3: Web3,
134
+ // network: NetworkNumber,
135
+ // selectedMarket: EulerV2MarketData
136
+ // ): Promise<> => {
137
+ //
138
+ // }
139
+ export const EMPTY_EULER_V2_DATA = {
140
+ usedAssets: {},
141
+ suppliedUsd: '0',
142
+ borrowedUsd: '0',
143
+ borrowLimitUsd: '0',
144
+ leftToBorrowUsd: '0',
145
+ ratio: '0',
146
+ minRatio: '0',
147
+ netApy: '0',
148
+ incentiveUsd: '0',
149
+ totalInterestUsd: '0',
150
+ isSubscribedToAutomation: false,
151
+ automationResubscribeRequired: false,
152
+ borrowVault: '',
153
+ borrowAmountInUnit: '0',
154
+ inLockDownMode: false,
155
+ inPermitDisabledMode: false,
156
+ lastUpdated: Date.now(),
157
+ hasBorrowInDifferentVault: false,
158
+ };
159
+ export const getEulerV2AccountData = (web3, network, address, extractedState) => __awaiter(void 0, void 0, void 0, function* () {
160
+ if (!address)
161
+ throw new Error('No address provided');
162
+ const { selectedMarket, assetsData, marketData, } = extractedState;
163
+ let payload = Object.assign(Object.assign({}, EMPTY_EULER_V2_DATA), { lastUpdated: Date.now() });
164
+ const isInUSD = marketData.isInUSD;
165
+ // TODO: maybe not the best practice to get decimals from tokens package
166
+ const parsingDecimals = isInUSD ? 18 : getAssetInfoByAddress(marketData.unitOfAccount).decimals;
167
+ const contract = EulerV2ViewContract(web3, network);
168
+ const loanData = yield contract.methods.getUserData(address).call();
169
+ const usedAssets = {};
170
+ // there is no user position check for a specific market, only global check
171
+ // but we need to make sure it works for the UI and show position only for the selected market
172
+ if (!compareAddresses(loanData.borrowVault, selectedMarket.marketAddress)) {
173
+ payload = Object.assign(Object.assign({}, payload), { borrowVault: ZERO_ADDRESS, borrowAmountInUnit: '0', inLockDownMode: false, inPermitDisabledMode: false, hasBorrowInDifferentVault: !compareAddresses(loanData.borrowVault, ZERO_ADDRESS) });
174
+ }
175
+ else {
176
+ payload = Object.assign(Object.assign({}, payload), { borrowVault: loanData.borrowVault, borrowAmountInUnit: loanData.borrowAmountInUnit, inLockDownMode: loanData.inLockDownMode, inPermitDisabledMode: loanData.inPermitDisabledMode, hasBorrowInDifferentVault: false });
177
+ const borrowedInUnit = getEthAmountForDecimals(loanData.borrowAmountInUnit, parsingDecimals);
178
+ const borrowedInAsset = getEthAmountForDecimals(loanData.borrowAmountInAsset, marketData.decimals);
179
+ const borrowVault = loanData.borrowVault;
180
+ if (borrowVault && !compareAddresses(ZERO_ADDRESS, borrowVault) && borrowedInUnit) {
181
+ const borrowInfo = assetsData[borrowVault.toLowerCase()];
182
+ usedAssets[borrowVault.toLowerCase()] = Object.assign(Object.assign({}, EMPTY_USED_ASSET), { isBorrowed: true, borrowed: borrowedInAsset, borrowedUsd: isInUSD ? borrowedInUnit : new Dec(borrowedInUnit).mul(marketData.unitOfAccountUsdPrice).toString(), vaultAddress: loanData.borrowVault, symbol: borrowInfo.symbol });
183
+ }
184
+ }
185
+ loanData.collaterals.forEach((collateral, i) => {
186
+ const key = collateral.collateralVault.toLowerCase();
187
+ const collInfo = assetsData[key];
188
+ if (!collInfo || !marketData.collaterals.map(a => a.toLowerCase()).includes(key))
189
+ return; // this is a token supplied but not being used as a collateral for the market
190
+ const suppliedInUnit = getEthAmountForDecimals(collateral.collateralAmountInUnit, parsingDecimals);
191
+ const suppliedInAsset = getEthAmountForDecimals(collateral.collateralAmountInAsset, collInfo.decimals);
192
+ const collateralAmountInUSD = getEthAmountForDecimals(collateral.collateralAmountInUSD, 18);
193
+ usedAssets[key] = Object.assign(Object.assign({}, EMPTY_USED_ASSET), { collateral: true, isSupplied: true, supplied: suppliedInAsset, suppliedUsd: collateralAmountInUSD, vaultAddress: collateral.collateralVault, symbol: collInfo.symbol });
194
+ });
195
+ payload = Object.assign(Object.assign(Object.assign({}, payload), { usedAssets }), getEulerV2AggregatedData({
196
+ usedAssets, assetsData, network,
197
+ }));
198
+ return payload;
199
+ });
@@ -0,0 +1,27 @@
1
+ import Web3 from 'web3';
2
+ import { EthAddress, NetworkNumber } from '../../types/common';
3
+ import { EulerV2AggregatedPositionData, EulerV2AssetsData, EulerV2UsedAssets } from '../../types';
4
+ export declare const isLeveragedPos: (usedAssets: EulerV2UsedAssets, dustLimit?: number) => {
5
+ leveragedType: string;
6
+ leveragedAsset: string;
7
+ leveragedVault: string;
8
+ };
9
+ export declare const calculateNetApy: (usedAssets: EulerV2UsedAssets, assetsData: EulerV2AssetsData) => {
10
+ netApy: string;
11
+ totalInterestUsd: string;
12
+ incentiveUsd: string;
13
+ };
14
+ export declare const getEulerV2AggregatedData: ({ usedAssets, assetsData, network, ...rest }: {
15
+ usedAssets: EulerV2UsedAssets;
16
+ assetsData: EulerV2AssetsData;
17
+ network: NetworkNumber;
18
+ }) => EulerV2AggregatedPositionData;
19
+ export declare const getEulerV2BorrowRate: (interestRate: string) => string;
20
+ export declare const getUtilizationRate: (totalBorrows: string, totalAssets: string) => string;
21
+ export declare const getEulerV2SupplyRate: (borrowRate: string, utilizationRate: string, _interestFee: string) => string;
22
+ export declare const getApyAfterValuesEstimationEulerV2: (actions: {
23
+ action: string;
24
+ amount: string;
25
+ asset: string;
26
+ vaultAddress: EthAddress;
27
+ }[], web3: Web3, network: NetworkNumber) => Promise<any>;
@@ -0,0 +1,219 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import Dec from 'decimal.js';
22
+ import { assetAmountInWei } from '@defisaver/tokens';
23
+ import { calcLeverageLiqPrice, getAssetsTotal, STABLE_ASSETS, } from '../../moneymarket';
24
+ import { calculateInterestEarned } from '../../staking';
25
+ import { EulerV2ViewContract } from '../../contracts';
26
+ import { borrowOperations } from '../../constants';
27
+ import { multicall } from '../../multicall';
28
+ export const isLeveragedPos = (usedAssets, dustLimit = 5) => {
29
+ let borrowUnstable = 0;
30
+ let supplyStable = 0;
31
+ let borrowStable = 0;
32
+ let supplyUnstable = 0;
33
+ let longAsset = '';
34
+ let shortAsset = '';
35
+ let leverageAssetVault = '';
36
+ Object.values(usedAssets).forEach(({ symbol, suppliedUsd, borrowedUsd, collateral, vaultAddress, }) => {
37
+ const isSupplied = (+suppliedUsd) > dustLimit; // ignore dust like <limit leftover supply
38
+ const isBorrowed = (+borrowedUsd) > dustLimit; // ignore dust like <limit leftover supply
39
+ if (isSupplied && STABLE_ASSETS.includes(symbol) && collateral)
40
+ supplyStable += 1;
41
+ if (isBorrowed && STABLE_ASSETS.includes(symbol))
42
+ borrowStable += 1;
43
+ if (isBorrowed && !STABLE_ASSETS.includes(symbol)) {
44
+ borrowUnstable += 1;
45
+ shortAsset = symbol;
46
+ leverageAssetVault = vaultAddress;
47
+ }
48
+ if (isSupplied && !STABLE_ASSETS.includes(symbol) && collateral) {
49
+ supplyUnstable += 1;
50
+ longAsset = symbol;
51
+ leverageAssetVault = vaultAddress;
52
+ }
53
+ });
54
+ const isLong = borrowStable > 0 && borrowUnstable === 0 && supplyUnstable === 1 && supplyStable === 0;
55
+ const isShort = supplyStable > 0 && supplyUnstable === 0 && borrowUnstable === 1 && borrowStable === 0;
56
+ // lsd -> liquid staking derivative
57
+ const isLsdLeveraged = supplyUnstable === 1 && borrowUnstable === 1 && shortAsset === 'ETH' && ['stETH', 'wstETH', 'cbETH', 'rETH'].includes(longAsset);
58
+ if (isLong) {
59
+ return {
60
+ leveragedType: 'long',
61
+ leveragedAsset: longAsset,
62
+ leveragedVault: leverageAssetVault,
63
+ };
64
+ }
65
+ if (isShort) {
66
+ return {
67
+ leveragedType: 'short',
68
+ leveragedAsset: shortAsset,
69
+ leveragedVault: leverageAssetVault,
70
+ };
71
+ }
72
+ if (isLsdLeveraged) {
73
+ return {
74
+ leveragedType: 'lsd-leverage',
75
+ leveragedAsset: longAsset,
76
+ leveragedVault: leverageAssetVault,
77
+ };
78
+ }
79
+ return {
80
+ leveragedType: '',
81
+ leveragedAsset: '',
82
+ leveragedVault: '',
83
+ };
84
+ };
85
+ export const calculateNetApy = (usedAssets, assetsData) => {
86
+ const sumValues = Object.values(usedAssets).reduce((_acc, usedAsset) => {
87
+ const acc = Object.assign({}, _acc);
88
+ const assetData = assetsData[usedAsset.vaultAddress.toLowerCase()];
89
+ if (usedAsset.isSupplied) {
90
+ const amount = usedAsset.suppliedUsd;
91
+ acc.suppliedUsd = new Dec(acc.suppliedUsd).add(amount).toString();
92
+ const rate = assetData.supplyRate;
93
+ const supplyInterest = calculateInterestEarned(amount, rate, 'year', true);
94
+ acc.supplyInterest = new Dec(acc.supplyInterest).add(supplyInterest.toString()).toString();
95
+ }
96
+ if (usedAsset.isBorrowed) {
97
+ const amount = usedAsset.borrowedUsd;
98
+ acc.borrowedUsd = new Dec(acc.borrowedUsd).add(amount).toString();
99
+ const rate = assetData.borrowRate;
100
+ const borrowInterest = calculateInterestEarned(amount, rate, 'year', true);
101
+ acc.borrowInterest = new Dec(acc.borrowInterest).sub(borrowInterest.toString()).toString();
102
+ }
103
+ return acc;
104
+ }, {
105
+ borrowInterest: '0', supplyInterest: '0', incentiveUsd: '0', borrowedUsd: '0', suppliedUsd: '0',
106
+ });
107
+ const { borrowedUsd, suppliedUsd, borrowInterest, supplyInterest, incentiveUsd, } = sumValues;
108
+ const totalInterestUsd = new Dec(borrowInterest).add(supplyInterest).add(incentiveUsd).toString();
109
+ const balance = new Dec(suppliedUsd).sub(borrowedUsd);
110
+ const netApy = new Dec(totalInterestUsd).div(balance).times(100).toString();
111
+ return { netApy, totalInterestUsd, incentiveUsd };
112
+ };
113
+ export const getEulerV2AggregatedData = (_a) => {
114
+ var { usedAssets, assetsData, network } = _a, rest = __rest(_a, ["usedAssets", "assetsData", "network"]);
115
+ const payload = {};
116
+ payload.suppliedUsd = getAssetsTotal(usedAssets, ({ isSupplied }) => isSupplied, ({ suppliedUsd }) => suppliedUsd);
117
+ payload.suppliedCollateralUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ suppliedUsd }) => suppliedUsd);
118
+ payload.borrowedUsd = getAssetsTotal(usedAssets, ({ isBorrowed }) => isBorrowed, ({ borrowedUsd }) => borrowedUsd);
119
+ payload.borrowLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ vaultAddress, suppliedUsd }) => new Dec(suppliedUsd).mul(assetsData[vaultAddress.toLowerCase()].collateralFactor));
120
+ payload.liquidationLimitUsd = getAssetsTotal(usedAssets, ({ isSupplied, collateral }) => isSupplied && collateral, ({ vaultAddress, suppliedUsd }) => new Dec(suppliedUsd).mul(assetsData[vaultAddress.toLowerCase()].liquidationRatio));
121
+ const leftToBorrowUsd = new Dec(payload.borrowLimitUsd).sub(payload.borrowedUsd);
122
+ payload.leftToBorrowUsd = leftToBorrowUsd.lte('0') ? '0' : leftToBorrowUsd.toString();
123
+ payload.ratio = +payload.suppliedUsd ? new Dec(payload.borrowLimitUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
124
+ payload.collRatio = +payload.suppliedUsd ? new Dec(payload.suppliedCollateralUsd).div(payload.borrowedUsd).mul(100).toString() : '0';
125
+ const { netApy, incentiveUsd, totalInterestUsd } = calculateNetApy(usedAssets, assetsData);
126
+ payload.netApy = netApy;
127
+ payload.incentiveUsd = incentiveUsd;
128
+ payload.totalInterestUsd = totalInterestUsd;
129
+ payload.minRatio = '100';
130
+ payload.liqRatio = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).toString();
131
+ payload.liqPercent = new Dec(payload.borrowLimitUsd).div(payload.liquidationLimitUsd).mul(100).toString();
132
+ const { leveragedType, leveragedAsset, leveragedVault } = isLeveragedPos(usedAssets);
133
+ payload.leveragedType = leveragedType;
134
+ if (leveragedType !== '') {
135
+ payload.leveragedAsset = leveragedAsset;
136
+ let assetPrice = assetsData[leveragedVault.toLowerCase()].price;
137
+ if (leveragedType === 'lsd-leverage') {
138
+ const ethAsset = Object.values(assetsData).find((asset) => ['WETH', 'ETH'].includes(asset.symbol));
139
+ if (ethAsset) {
140
+ payload.leveragedLsdAssetRatio = new Dec(assetsData[leveragedVault.toLowerCase()].price).div(ethAsset.price).toString();
141
+ assetPrice = new Dec(assetPrice).div(ethAsset.price).toString();
142
+ }
143
+ }
144
+ payload.liquidationPrice = calcLeverageLiqPrice(leveragedType, assetPrice, payload.borrowedUsd, payload.liquidationLimitUsd);
145
+ }
146
+ return payload;
147
+ };
148
+ export const getEulerV2BorrowRate = (interestRate) => {
149
+ const _interestRate = new Dec(interestRate).div(1e27).toString();
150
+ const secondsPerYear = 31556953;
151
+ const a = new Dec(1).plus(_interestRate).pow(secondsPerYear - 1).toString();
152
+ return new Dec(new Dec(a).minus(1)).mul(100).toString();
153
+ };
154
+ export const getUtilizationRate = (totalBorrows, totalAssets) => new Dec(totalBorrows).div(totalAssets).toString();
155
+ export const getEulerV2SupplyRate = (borrowRate, utilizationRate, _interestFee) => {
156
+ const interestFee = new Dec(_interestFee).div(10000);
157
+ const fee = new Dec(1).minus(interestFee);
158
+ return new Dec(borrowRate).mul(utilizationRate).mul(fee).toString();
159
+ };
160
+ const getLiquidityChanges = (action, amount, isBorrowOperation) => {
161
+ let liquidityAdded;
162
+ let liquidityRemoved;
163
+ if (isBorrowOperation) {
164
+ liquidityAdded = action === 'payback' ? amount : '0';
165
+ liquidityRemoved = action === 'borrow' ? amount : '0';
166
+ }
167
+ else {
168
+ liquidityAdded = action === 'collateral' ? amount : '0';
169
+ liquidityRemoved = action === 'withdraw' ? amount : '0';
170
+ }
171
+ return { liquidityAdded, liquidityRemoved };
172
+ };
173
+ export const getApyAfterValuesEstimationEulerV2 = (actions, web3, network) => __awaiter(void 0, void 0, void 0, function* () {
174
+ const eulerV2ViewContract = EulerV2ViewContract(web3, network);
175
+ const multicallData = [];
176
+ const apyAfterValuesEstimationParams = [];
177
+ actions.forEach(({ action, amount, asset, vaultAddress, }) => {
178
+ const amountInWei = assetAmountInWei(amount, asset);
179
+ const isBorrowOperation = borrowOperations.includes(action);
180
+ const { liquidityAdded, liquidityRemoved } = getLiquidityChanges(action, amountInWei, isBorrowOperation);
181
+ apyAfterValuesEstimationParams.push([
182
+ vaultAddress,
183
+ borrowOperations.includes(action),
184
+ liquidityAdded,
185
+ liquidityRemoved,
186
+ ]);
187
+ multicallData.push({
188
+ target: eulerV2ViewContract.options.address,
189
+ abiItem: eulerV2ViewContract.options.jsonInterface.find(({ name }) => name === 'getVaultInfoFull'),
190
+ params: [vaultAddress],
191
+ });
192
+ });
193
+ multicallData.push({
194
+ target: eulerV2ViewContract.options.address,
195
+ abiItem: eulerV2ViewContract.options.jsonInterface.find(({ name }) => name === 'getApyAfterValuesEstimation'),
196
+ params: [apyAfterValuesEstimationParams],
197
+ });
198
+ const multicallRes = yield multicall(multicallData, web3, network);
199
+ const numOfActions = actions.length;
200
+ const data = {};
201
+ for (let i = 0; i < numOfActions; i += 1) {
202
+ const _interestRate = multicallRes[numOfActions].estimatedBorrowRates[i];
203
+ const vaultInfo = multicallRes[i][0];
204
+ const decimals = vaultInfo.decimals;
205
+ const borrowRate = getEulerV2BorrowRate(_interestRate);
206
+ const amount = new Dec(actions[i].amount).mul(Math.pow(10, decimals)).toString();
207
+ const action = actions[i].action;
208
+ const isBorrowOperation = borrowOperations.includes(action);
209
+ const { liquidityAdded, liquidityRemoved } = getLiquidityChanges(action, amount, isBorrowOperation);
210
+ const totalBorrows = new Dec(vaultInfo.totalBorrows).add(isBorrowOperation ? liquidityRemoved : '0').sub(isBorrowOperation ? liquidityAdded : '0').toString();
211
+ const totalAssets = new Dec(vaultInfo.totalAssets).add(isBorrowOperation ? '0' : liquidityAdded).sub(isBorrowOperation ? '0' : liquidityRemoved).toString();
212
+ const utilizationRate = getUtilizationRate(totalBorrows, totalAssets);
213
+ data[vaultInfo.vaultAddr.toLowerCase()] = {
214
+ borrowRate,
215
+ supplyRate: getEulerV2SupplyRate(borrowRate, utilizationRate, vaultInfo.interestFee),
216
+ };
217
+ }
218
+ return data;
219
+ });
@@ -6,3 +6,4 @@ export * as makerHelpers from './makerHelpers';
6
6
  export * as chickenBondsHelpers from './chickenBondsHelpers';
7
7
  export * as morphoBlueHelpers from './morphoBlueHelpers';
8
8
  export * as llamaLendHelpers from './llamaLendHelpers';
9
+ export * as eulerV2Helpers from './eulerHelpers';
@@ -6,3 +6,4 @@ export * as makerHelpers from './makerHelpers';
6
6
  export * as chickenBondsHelpers from './chickenBondsHelpers';
7
7
  export * as morphoBlueHelpers from './morphoBlueHelpers';
8
8
  export * as llamaLendHelpers from './llamaLendHelpers';
9
+ export * as eulerV2Helpers from './eulerHelpers';