@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
@@ -6696,3 +6696,75 @@ export namespace LlamaLendControllerAbi {
6696
6696
  let networks_76: {};
6697
6697
  export { networks_76 as networks };
6698
6698
  }
6699
+ export namespace EulerV2View {
6700
+ let abi_77: ({
6701
+ inputs: {
6702
+ internalType: string;
6703
+ name: string;
6704
+ type: string;
6705
+ }[];
6706
+ name: string;
6707
+ outputs: {
6708
+ internalType: string;
6709
+ name: string;
6710
+ type: string;
6711
+ }[];
6712
+ stateMutability: string;
6713
+ type: string;
6714
+ } | {
6715
+ inputs: {
6716
+ components: {
6717
+ internalType: string;
6718
+ name: string;
6719
+ type: string;
6720
+ }[];
6721
+ internalType: string;
6722
+ name: string;
6723
+ type: string;
6724
+ }[];
6725
+ name: string;
6726
+ outputs: {
6727
+ internalType: string;
6728
+ name: string;
6729
+ type: string;
6730
+ }[];
6731
+ stateMutability: string;
6732
+ type: string;
6733
+ } | {
6734
+ inputs: {
6735
+ internalType: string;
6736
+ name: string;
6737
+ type: string;
6738
+ }[];
6739
+ name: string;
6740
+ outputs: {
6741
+ components: ({
6742
+ internalType: string;
6743
+ name: string;
6744
+ type: string;
6745
+ components?: undefined;
6746
+ } | {
6747
+ components: {
6748
+ internalType: string;
6749
+ name: string;
6750
+ type: string;
6751
+ }[];
6752
+ internalType: string;
6753
+ name: string;
6754
+ type: string;
6755
+ })[];
6756
+ internalType: string;
6757
+ name: string;
6758
+ type: string;
6759
+ }[];
6760
+ stateMutability: string;
6761
+ type: string;
6762
+ })[];
6763
+ export { abi_77 as abi };
6764
+ let networks_77: {
6765
+ "1": {
6766
+ address: string;
6767
+ };
6768
+ };
6769
+ export { networks_77 as networks };
6770
+ }
@@ -1031,4 +1031,10 @@ module.exports = {
1031
1031
  "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" }] }],
1032
1032
  "networks": {}
1033
1033
  },
1034
+ "EulerV2View": {
1035
+ "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" }],
1036
+ "networks": {
1037
+ "1": { "address": "0x25eCA04532C085F77Ea6CE92C94E9e69896686E6" }
1038
+ }
1039
+ }
1034
1040
  };
@@ -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/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.LlamaLendViewContract = exports.MorphoBlueViewContract = exports.FeedRegistryContract = exports.USDCPriceFeedContract = exports.COMPPriceFeedContract = exports.ETHPriceFeedContract = exports.ChickenBondsManagerContract = exports.ChickenBondsViewContract = exports.McdVatContract = exports.McdJugContract = exports.McdDogContract = exports.McdSpotterContract = exports.McdViewContract = exports.LiquityActivePoolContract = exports.LiquityPriceFeedContract = exports.LiquityTroveManagerContract = exports.LiquityCollSurplusPoolContract = exports.LiquityViewContract = exports.CrvUSDFactoryContract = exports.CrvUSDViewContract = exports.SparkViewContract = exports.SparkIncentiveDataProviderContract = exports.MorphoAaveV2ViewContract = exports.PotContract = exports.ComptrollerContract = exports.CompoundLoanInfoContract = exports.AaveLoanInfoV2Contract = exports.wstETHContract = exports.CompV3ViewContract = exports.BalanceScannerContract = exports.REthContract = exports.CbEthContract = exports.LidoContract = exports.GhoTokenContract = exports.AaveIncentiveDataProviderV3Contract = exports.AaveV3ViewContract = exports.UniMulticallContract = exports.createContractWrapper = exports.getErc20Contract = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
6
+ exports.EulerV2ViewContract = exports.LlamaLendViewContract = exports.MorphoBlueViewContract = exports.FeedRegistryContract = exports.USDCPriceFeedContract = exports.COMPPriceFeedContract = exports.ETHPriceFeedContract = exports.ChickenBondsManagerContract = exports.ChickenBondsViewContract = exports.McdVatContract = exports.McdJugContract = exports.McdDogContract = exports.McdSpotterContract = exports.McdViewContract = exports.LiquityActivePoolContract = exports.LiquityPriceFeedContract = exports.LiquityTroveManagerContract = exports.LiquityCollSurplusPoolContract = exports.LiquityViewContract = exports.CrvUSDFactoryContract = exports.CrvUSDViewContract = exports.SparkViewContract = exports.SparkIncentiveDataProviderContract = exports.MorphoAaveV2ViewContract = exports.PotContract = exports.ComptrollerContract = exports.CompoundLoanInfoContract = exports.AaveLoanInfoV2Contract = exports.wstETHContract = exports.CompV3ViewContract = exports.BalanceScannerContract = exports.REthContract = exports.CbEthContract = exports.LidoContract = exports.GhoTokenContract = exports.AaveIncentiveDataProviderV3Contract = exports.AaveV3ViewContract = exports.UniMulticallContract = exports.createContractWrapper = exports.getErc20Contract = exports.getConfigContractAbi = exports.getConfigContractAddress = void 0;
7
7
  const contracts_1 = __importDefault(require("./config/contracts"));
8
8
  const contractConfig = contracts_1.default;
9
9
  const getConfigContractAddress = (name, network, block) => {
@@ -87,3 +87,4 @@ exports.USDCPriceFeedContract = createContractFromConfigFunc('USDCPriceFeed');
87
87
  exports.FeedRegistryContract = createContractFromConfigFunc('FeedRegistry');
88
88
  exports.MorphoBlueViewContract = createContractFromConfigFunc('MorphoBlueView');
89
89
  exports.LlamaLendViewContract = createContractFromConfigFunc('LlamaLendView');
90
+ exports.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,207 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getEulerV2AccountData = exports.EMPTY_EULER_V2_DATA = exports.getEulerV2MarketsData = exports.EMPTY_USED_ASSET = void 0;
16
+ const decimal_js_1 = __importDefault(require("decimal.js"));
17
+ const tokens_1 = require("@defisaver/tokens");
18
+ const staking_1 = require("../staking");
19
+ const utils_1 = require("../services/utils");
20
+ const types_1 = require("../types");
21
+ const eulerHelpers_1 = require("../helpers/eulerHelpers");
22
+ const constants_1 = require("../constants");
23
+ const contracts_1 = require("../contracts");
24
+ exports.EMPTY_USED_ASSET = {
25
+ isSupplied: false,
26
+ isBorrowed: false,
27
+ supplied: '0',
28
+ suppliedUsd: '0',
29
+ borrowed: '0',
30
+ borrowedUsd: '0',
31
+ symbol: '',
32
+ collateral: false,
33
+ vaultAddress: '',
34
+ };
35
+ const UnitOfAccountUSD = '0x0000000000000000000000000000000000000348';
36
+ const getEulerV2MarketsData = (web3, network, selectedMarket, defaultWeb3) => __awaiter(void 0, void 0, void 0, function* () {
37
+ const contract = (0, contracts_1.EulerV2ViewContract)(web3, network);
38
+ const data = yield contract.methods.getVaultInfoFull(selectedMarket.marketAddress).call();
39
+ const isInUSD = (0, utils_1.compareAddresses)(UnitOfAccountUSD, data.unitOfAccount);
40
+ const usdPrice = (0, utils_1.getEthAmountForDecimals)(data.unitOfAccountInUsd, 8);
41
+ // parse collateral tokens
42
+ // imma use address as key for assetsData because there can be more collateral vaults with the same name
43
+ const colls = data.collaterals.map((collateral) => {
44
+ const decimals = collateral.decimals;
45
+ const assetInfo = (0, tokens_1.getAssetInfoByAddress)(collateral.assetAddr);
46
+ const borrowRate = (0, eulerHelpers_1.getEulerV2BorrowRate)(collateral.interestRate);
47
+ const utilizationRate = (0, eulerHelpers_1.getUtilizationRate)(collateral.totalBorrows, new decimal_js_1.default(collateral.totalBorrows).plus(collateral.cash).toString());
48
+ const supplyRate = (0, eulerHelpers_1.getEulerV2SupplyRate)(borrowRate, utilizationRate, collateral.interestFee);
49
+ return ({
50
+ vaultAddress: collateral.vaultAddr,
51
+ assetAddress: collateral.assetAddr,
52
+ symbol: assetInfo.symbol,
53
+ vaultSymbol: collateral.vaultSymbol,
54
+ decimals,
55
+ liquidationRatio: new decimal_js_1.default(collateral.liquidationLTV).div(10000).toString(),
56
+ collateralFactor: new decimal_js_1.default(collateral.borrowLTV).div(10000).toString(),
57
+ totalBorrow: (0, utils_1.getEthAmountForDecimals)(collateral.totalBorrows, decimals),
58
+ cash: (0, utils_1.getEthAmountForDecimals)(collateral.cash, decimals),
59
+ supplyCap: (0, utils_1.isMaxuint)(collateral.supplyCap) ? collateral.supplyCap : (0, utils_1.getEthAmountForDecimals)(collateral.supplyCap, decimals),
60
+ borrowCap: '0',
61
+ price: isInUSD ? (0, tokens_1.assetAmountInEth)(collateral.assetPriceInUnit) : new decimal_js_1.default((0, tokens_1.assetAmountInEth)(collateral.assetPriceInUnit)).mul(usdPrice).toString(),
62
+ canBeBorrowed: false,
63
+ canBeSupplied: true,
64
+ borrowRate,
65
+ supplyRate,
66
+ utilization: new decimal_js_1.default(utilizationRate).mul(100).toString(),
67
+ });
68
+ });
69
+ for (const coll of colls) {
70
+ if (staking_1.STAKING_ASSETS.includes(coll.symbol)) {
71
+ coll.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(coll.symbol, defaultWeb3);
72
+ coll.incentiveSupplyToken = coll.symbol;
73
+ }
74
+ }
75
+ const isEscrow = data.collaterals.length === 0;
76
+ const isGoverned = !(0, utils_1.compareAddresses)(data.governorAdmin, constants_1.ZERO_ADDRESS);
77
+ const vaultType = isEscrow ? types_1.EulerV2VaultType.Escrow : (isGoverned ? types_1.EulerV2VaultType.Governed : types_1.EulerV2VaultType.Ungoverned);
78
+ const decimals = data.decimals;
79
+ // (1 + SPY/10**27) ** secondsPerYear - 1
80
+ const interestRate = data.interestRate;
81
+ const borrowRate = (0, eulerHelpers_1.getEulerV2BorrowRate)(interestRate);
82
+ const utilizationRate = (0, eulerHelpers_1.getUtilizationRate)(data.totalBorrows, data.totalAssets);
83
+ const supplyRate = (0, eulerHelpers_1.getEulerV2SupplyRate)(borrowRate, utilizationRate, data.interestFee);
84
+ const marketAsset = {
85
+ assetAddress: data.assetAddr,
86
+ vaultAddress: data.vaultAddr,
87
+ symbol: selectedMarket.asset,
88
+ vaultSymbol: selectedMarket.shortLabel,
89
+ decimals,
90
+ totalBorrow: (0, utils_1.getEthAmountForDecimals)(data.totalBorrows, decimals),
91
+ cash: (0, utils_1.getEthAmountForDecimals)(data.cash, decimals),
92
+ supplyCap: (0, utils_1.isMaxuint)(data.supplyCap) ? data.supplyCap : (0, utils_1.getEthAmountForDecimals)(data.supplyCap, decimals),
93
+ borrowCap: (0, utils_1.isMaxuint)(data.supplyCap) ? data.borrowCap : (0, utils_1.getEthAmountForDecimals)(data.borrowCap, decimals),
94
+ price: isInUSD ? (0, tokens_1.assetAmountInEth)(data.assetPriceInUnit) : new decimal_js_1.default((0, tokens_1.assetAmountInEth)(data.assetPriceInUnit)).mul(usdPrice).toString(),
95
+ sortIndex: 0,
96
+ canBeBorrowed: true,
97
+ canBeSupplied: false,
98
+ borrowRate,
99
+ supplyRate,
100
+ collateralFactor: '0',
101
+ liquidationRatio: '0',
102
+ utilization: new decimal_js_1.default(utilizationRate).mul(100).toString(),
103
+ };
104
+ const assetsData = {
105
+ [data.vaultAddr.toLowerCase()]: marketAsset,
106
+ };
107
+ colls
108
+ .sort((coll1, coll2) => {
109
+ const aMarket = new decimal_js_1.default(coll1.price).times(coll1.totalBorrow).toString();
110
+ const bMarket = new decimal_js_1.default(coll2.price).times(coll2.totalBorrow).toString();
111
+ return new decimal_js_1.default(bMarket).minus(aMarket).toNumber();
112
+ })
113
+ .forEach((market, i) => {
114
+ assetsData[market.vaultAddress.toLowerCase()] = Object.assign(Object.assign({}, market), { sortIndex: i + 1 });
115
+ });
116
+ const marketData = {
117
+ name: data.name,
118
+ symbol: data.symbol,
119
+ decimals: data.decimals,
120
+ irm: data.irm,
121
+ creator: data.creator,
122
+ governorAdmin: data.governorAdmin,
123
+ unitOfAccount: data.unitOfAccount,
124
+ unitOfAccountUsdPrice: usdPrice,
125
+ isInUSD,
126
+ oracle: data.oracle,
127
+ collaterals: data.collaterals.map((collateral) => collateral.vaultAddr),
128
+ isEscrow,
129
+ isGoverned,
130
+ vaultType,
131
+ vaultAddress: data.vaultAddr,
132
+ };
133
+ return {
134
+ marketData,
135
+ assetsData,
136
+ };
137
+ });
138
+ exports.getEulerV2MarketsData = getEulerV2MarketsData;
139
+ // export const getEulerV2AccountBalances = async (
140
+ // web3: Web3,
141
+ // network: NetworkNumber,
142
+ // selectedMarket: EulerV2MarketData
143
+ // ): Promise<> => {
144
+ //
145
+ // }
146
+ exports.EMPTY_EULER_V2_DATA = {
147
+ usedAssets: {},
148
+ suppliedUsd: '0',
149
+ borrowedUsd: '0',
150
+ borrowLimitUsd: '0',
151
+ leftToBorrowUsd: '0',
152
+ ratio: '0',
153
+ minRatio: '0',
154
+ netApy: '0',
155
+ incentiveUsd: '0',
156
+ totalInterestUsd: '0',
157
+ isSubscribedToAutomation: false,
158
+ automationResubscribeRequired: false,
159
+ borrowVault: '',
160
+ borrowAmountInUnit: '0',
161
+ inLockDownMode: false,
162
+ inPermitDisabledMode: false,
163
+ lastUpdated: Date.now(),
164
+ hasBorrowInDifferentVault: false,
165
+ };
166
+ const getEulerV2AccountData = (web3, network, address, extractedState) => __awaiter(void 0, void 0, void 0, function* () {
167
+ if (!address)
168
+ throw new Error('No address provided');
169
+ const { selectedMarket, assetsData, marketData, } = extractedState;
170
+ let payload = Object.assign(Object.assign({}, exports.EMPTY_EULER_V2_DATA), { lastUpdated: Date.now() });
171
+ const isInUSD = marketData.isInUSD;
172
+ // TODO: maybe not the best practice to get decimals from tokens package
173
+ const parsingDecimals = isInUSD ? 18 : (0, tokens_1.getAssetInfoByAddress)(marketData.unitOfAccount).decimals;
174
+ const contract = (0, contracts_1.EulerV2ViewContract)(web3, network);
175
+ const loanData = yield contract.methods.getUserData(address).call();
176
+ const usedAssets = {};
177
+ // there is no user position check for a specific market, only global check
178
+ // but we need to make sure it works for the UI and show position only for the selected market
179
+ if (!(0, utils_1.compareAddresses)(loanData.borrowVault, selectedMarket.marketAddress)) {
180
+ payload = Object.assign(Object.assign({}, payload), { borrowVault: constants_1.ZERO_ADDRESS, borrowAmountInUnit: '0', inLockDownMode: false, inPermitDisabledMode: false, hasBorrowInDifferentVault: !(0, utils_1.compareAddresses)(loanData.borrowVault, constants_1.ZERO_ADDRESS) });
181
+ }
182
+ else {
183
+ payload = Object.assign(Object.assign({}, payload), { borrowVault: loanData.borrowVault, borrowAmountInUnit: loanData.borrowAmountInUnit, inLockDownMode: loanData.inLockDownMode, inPermitDisabledMode: loanData.inPermitDisabledMode, hasBorrowInDifferentVault: false });
184
+ const borrowedInUnit = (0, utils_1.getEthAmountForDecimals)(loanData.borrowAmountInUnit, parsingDecimals);
185
+ const borrowedInAsset = (0, utils_1.getEthAmountForDecimals)(loanData.borrowAmountInAsset, marketData.decimals);
186
+ const borrowVault = loanData.borrowVault;
187
+ if (borrowVault && !(0, utils_1.compareAddresses)(constants_1.ZERO_ADDRESS, borrowVault) && borrowedInUnit) {
188
+ const borrowInfo = assetsData[borrowVault.toLowerCase()];
189
+ usedAssets[borrowVault.toLowerCase()] = Object.assign(Object.assign({}, exports.EMPTY_USED_ASSET), { isBorrowed: true, borrowed: borrowedInAsset, borrowedUsd: isInUSD ? borrowedInUnit : new decimal_js_1.default(borrowedInUnit).mul(marketData.unitOfAccountUsdPrice).toString(), vaultAddress: loanData.borrowVault, symbol: borrowInfo.symbol });
190
+ }
191
+ }
192
+ loanData.collaterals.forEach((collateral, i) => {
193
+ const key = collateral.collateralVault.toLowerCase();
194
+ const collInfo = assetsData[key];
195
+ if (!collInfo || !marketData.collaterals.map(a => a.toLowerCase()).includes(key))
196
+ return; // this is a token supplied but not being used as a collateral for the market
197
+ const suppliedInUnit = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInUnit, parsingDecimals);
198
+ const suppliedInAsset = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInAsset, collInfo.decimals);
199
+ const collateralAmountInUSD = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInUSD, 18);
200
+ usedAssets[key] = Object.assign(Object.assign({}, exports.EMPTY_USED_ASSET), { collateral: true, isSupplied: true, supplied: suppliedInAsset, suppliedUsd: collateralAmountInUSD, vaultAddress: collateral.collateralVault, symbol: collInfo.symbol });
201
+ });
202
+ payload = Object.assign(Object.assign(Object.assign({}, payload), { usedAssets }), (0, eulerHelpers_1.getEulerV2AggregatedData)({
203
+ usedAssets, assetsData, network,
204
+ }));
205
+ return payload;
206
+ });
207
+ exports.getEulerV2AccountData = getEulerV2AccountData;
@@ -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>;