@defisaver/positions-sdk 0.0.171 → 0.0.172

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 (53) 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 +41 -0
  6. package/cjs/eulerV2/index.js +218 -0
  7. package/cjs/helpers/eulerHelpers/index.d.ts +27 -0
  8. package/cjs/helpers/eulerHelpers/index.js +234 -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 +8 -0
  14. package/cjs/markets/euler/index.js +30 -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/types/contracts/generated/EulerV2View.d.ts +345 -0
  20. package/cjs/types/contracts/generated/EulerV2View.js +5 -0
  21. package/cjs/types/contracts/generated/index.d.ts +1 -0
  22. package/cjs/types/euler.d.ts +149 -0
  23. package/cjs/types/euler.js +14 -0
  24. package/cjs/types/index.d.ts +1 -0
  25. package/cjs/types/index.js +1 -0
  26. package/esm/config/contracts.d.ts +72 -0
  27. package/esm/config/contracts.js +6 -0
  28. package/esm/contracts.d.ts +1 -0
  29. package/esm/contracts.js +1 -0
  30. package/esm/eulerV2/index.d.ts +41 -0
  31. package/esm/eulerV2/index.js +210 -0
  32. package/esm/helpers/eulerHelpers/index.d.ts +27 -0
  33. package/esm/helpers/eulerHelpers/index.js +221 -0
  34. package/esm/helpers/index.d.ts +1 -0
  35. package/esm/helpers/index.js +1 -0
  36. package/esm/index.d.ts +2 -1
  37. package/esm/index.js +2 -1
  38. package/esm/markets/euler/index.d.ts +8 -0
  39. package/esm/markets/euler/index.js +24 -0
  40. package/esm/markets/index.d.ts +1 -0
  41. package/esm/markets/index.js +1 -0
  42. package/esm/services/utils.d.ts +2 -0
  43. package/esm/services/utils.js +2 -0
  44. package/esm/types/contracts/generated/EulerV2View.d.ts +345 -0
  45. package/esm/types/contracts/generated/EulerV2View.js +4 -0
  46. package/esm/types/contracts/generated/index.d.ts +1 -0
  47. package/esm/types/euler.d.ts +149 -0
  48. package/esm/types/euler.js +11 -0
  49. package/esm/types/index.d.ts +1 -0
  50. package/esm/types/index.js +1 -0
  51. package/package.json +1 -1
  52. package/src/types/contracts/generated/EulerV2View.ts +446 -0
  53. package/src/types/contracts/generated/index.ts +1 -0
@@ -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": "string", "name": "name", "type": "string" }, { "internalType": "address", "name": "governorAdmin", "type": "address" }, { "internalType": "bool", "name": "isEscrowed", "type": "bool" }, { "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": "string", "name": "name", "type": "string" }, { "internalType": "address", "name": "governorAdmin", "type": "address" }, { "internalType": "bool", "name": "isEscrowed", "type": "bool" }, { "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": "string", "name": "name", "type": "string" }, { "internalType": "address", "name": "governorAdmin", "type": "address" }, { "internalType": "bool", "name": "isEscrowed", "type": "bool" }, { "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": "0x8932E46Ecf96b5Fe033F5e27Ab6dC755Cb668967" }
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,41 @@
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
+ addressSpaceTakenByAnotherAccount: boolean;
36
+ };
37
+ export declare const getEulerV2AccountData: (web3: Web3, network: NetworkNumber, addressForPosition: string, ownerAddress: string, extractedState: ({
38
+ selectedMarket: EulerV2Market;
39
+ assetsData: EulerV2AssetsData;
40
+ marketData: EulerV2MarketInfoData;
41
+ })) => Promise<EulerV2PositionData>;
@@ -0,0 +1,218 @@
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
+ const isEscrow = collateral.isEscrowed;
50
+ const isGoverned = !(0, utils_1.compareAddresses)(collateral.governorAdmin, constants_1.ZERO_ADDRESS);
51
+ const vaultType = isEscrow
52
+ ? types_1.EulerV2VaultType.Escrow
53
+ : (isGoverned ? types_1.EulerV2VaultType.Governed : types_1.EulerV2VaultType.Ungoverned);
54
+ return ({
55
+ vaultAddress: collateral.vaultAddr,
56
+ assetAddress: (0, utils_1.wethToEthByAddress)(collateral.assetAddr),
57
+ symbol: (0, utils_1.wethToEth)(assetInfo.symbol),
58
+ vaultSymbol: collateral.vaultSymbol,
59
+ name: collateral.name,
60
+ vaultType,
61
+ decimals,
62
+ liquidationRatio: new decimal_js_1.default(collateral.liquidationLTV).div(10000).toString(),
63
+ collateralFactor: new decimal_js_1.default(collateral.borrowLTV).div(10000).toString(),
64
+ totalBorrow: (0, utils_1.getEthAmountForDecimals)(collateral.totalBorrows, decimals),
65
+ cash: (0, utils_1.getEthAmountForDecimals)(collateral.cash, decimals),
66
+ supplyCap: (0, utils_1.isMaxuint)(collateral.supplyCap) ? collateral.supplyCap : (0, utils_1.getEthAmountForDecimals)(collateral.supplyCap, decimals),
67
+ borrowCap: '0',
68
+ price: isInUSD ? (0, tokens_1.assetAmountInEth)(collateral.assetPriceInUnit) : new decimal_js_1.default((0, tokens_1.assetAmountInEth)(collateral.assetPriceInUnit)).mul(usdPrice).toString(),
69
+ canBeBorrowed: false,
70
+ canBeSupplied: true,
71
+ borrowRate,
72
+ supplyRate,
73
+ utilization: new decimal_js_1.default(utilizationRate).mul(100).toString(),
74
+ governorAdmin: collateral.governorAdmin,
75
+ });
76
+ });
77
+ for (const coll of colls) {
78
+ if (staking_1.STAKING_ASSETS.includes(coll.symbol)) {
79
+ coll.incentiveSupplyApy = yield (0, staking_1.getStakingApy)(coll.symbol, defaultWeb3);
80
+ coll.incentiveSupplyToken = coll.symbol;
81
+ }
82
+ }
83
+ const isEscrow = data.collaterals.length === 0;
84
+ const isGoverned = !(0, utils_1.compareAddresses)(data.governorAdmin, constants_1.ZERO_ADDRESS);
85
+ const vaultType = isEscrow ? types_1.EulerV2VaultType.Escrow : (isGoverned ? types_1.EulerV2VaultType.Governed : types_1.EulerV2VaultType.Ungoverned);
86
+ const decimals = data.decimals;
87
+ // (1 + SPY/10**27) ** secondsPerYear - 1
88
+ const interestRate = data.interestRate;
89
+ const borrowRate = (0, eulerHelpers_1.getEulerV2BorrowRate)(interestRate);
90
+ const utilizationRate = (0, eulerHelpers_1.getUtilizationRate)(data.totalBorrows, data.totalAssets);
91
+ const supplyRate = (0, eulerHelpers_1.getEulerV2SupplyRate)(borrowRate, utilizationRate, data.interestFee);
92
+ const marketAsset = {
93
+ assetAddress: data.assetAddr,
94
+ vaultAddress: data.vaultAddr,
95
+ symbol: selectedMarket.asset,
96
+ vaultSymbol: selectedMarket.shortLabel,
97
+ decimals,
98
+ totalBorrow: (0, utils_1.getEthAmountForDecimals)(data.totalBorrows, decimals),
99
+ cash: (0, utils_1.getEthAmountForDecimals)(data.cash, decimals),
100
+ supplyCap: (0, utils_1.isMaxuint)(data.supplyCap) ? data.supplyCap : (0, utils_1.getEthAmountForDecimals)(data.supplyCap, decimals),
101
+ borrowCap: (0, utils_1.isMaxuint)(data.supplyCap) ? data.borrowCap : (0, utils_1.getEthAmountForDecimals)(data.borrowCap, decimals),
102
+ price: isInUSD ? (0, tokens_1.assetAmountInEth)(data.assetPriceInUnit) : new decimal_js_1.default((0, tokens_1.assetAmountInEth)(data.assetPriceInUnit)).mul(usdPrice).toString(),
103
+ sortIndex: 0,
104
+ canBeBorrowed: true,
105
+ canBeSupplied: false,
106
+ borrowRate,
107
+ supplyRate,
108
+ collateralFactor: '0',
109
+ liquidationRatio: '0',
110
+ utilization: new decimal_js_1.default(utilizationRate).mul(100).toString(),
111
+ governorAdmin: data.governorAdmin,
112
+ vaultType,
113
+ name: data.name,
114
+ };
115
+ const assetsData = {
116
+ [data.vaultAddr.toLowerCase()]: marketAsset,
117
+ };
118
+ colls
119
+ .sort((coll1, coll2) => {
120
+ const aMarket = new decimal_js_1.default(coll1.price).times(coll1.totalBorrow).toString();
121
+ const bMarket = new decimal_js_1.default(coll2.price).times(coll2.totalBorrow).toString();
122
+ return new decimal_js_1.default(bMarket).minus(aMarket).toNumber();
123
+ })
124
+ .forEach((market, i) => {
125
+ assetsData[market.vaultAddress.toLowerCase()] = Object.assign(Object.assign({}, market), { sortIndex: i + 1 });
126
+ });
127
+ const marketData = {
128
+ name: data.name,
129
+ symbol: data.symbol,
130
+ decimals: data.decimals,
131
+ irm: data.irm,
132
+ creator: data.creator,
133
+ governorAdmin: data.governorAdmin,
134
+ unitOfAccount: data.unitOfAccount,
135
+ unitOfAccountUsdPrice: usdPrice,
136
+ isInUSD,
137
+ oracle: data.oracle,
138
+ collaterals: data.collaterals.map((collateral) => collateral.vaultAddr),
139
+ isEscrow,
140
+ isGoverned,
141
+ vaultType,
142
+ vaultAddress: data.vaultAddr,
143
+ };
144
+ return {
145
+ marketData,
146
+ assetsData,
147
+ };
148
+ });
149
+ exports.getEulerV2MarketsData = getEulerV2MarketsData;
150
+ // export const getEulerV2AccountBalances = async (
151
+ // web3: Web3,
152
+ // network: NetworkNumber,
153
+ // selectedMarket: EulerV2MarketData
154
+ // ): Promise<> => {
155
+ //
156
+ // }
157
+ exports.EMPTY_EULER_V2_DATA = {
158
+ usedAssets: {},
159
+ suppliedUsd: '0',
160
+ borrowedUsd: '0',
161
+ borrowLimitUsd: '0',
162
+ leftToBorrowUsd: '0',
163
+ ratio: '0',
164
+ minRatio: '0',
165
+ netApy: '0',
166
+ incentiveUsd: '0',
167
+ totalInterestUsd: '0',
168
+ isSubscribedToAutomation: false,
169
+ automationResubscribeRequired: false,
170
+ borrowVault: '',
171
+ borrowAmountInUnit: '0',
172
+ inLockDownMode: false,
173
+ inPermitDisabledMode: false,
174
+ lastUpdated: Date.now(),
175
+ hasBorrowInDifferentVault: false,
176
+ addressSpaceTakenByAnotherAccount: false,
177
+ };
178
+ const getEulerV2AccountData = (web3, network, addressForPosition, ownerAddress, extractedState) => __awaiter(void 0, void 0, void 0, function* () {
179
+ if (!addressForPosition)
180
+ throw new Error('No address provided');
181
+ const { selectedMarket, assetsData, marketData, } = extractedState;
182
+ let payload = Object.assign(Object.assign({}, exports.EMPTY_EULER_V2_DATA), { lastUpdated: Date.now() });
183
+ const isInUSD = marketData.isInUSD;
184
+ const parsingDecimals = isInUSD ? 18 : (0, tokens_1.getAssetInfoByAddress)(marketData.unitOfAccount).decimals;
185
+ const contract = (0, contracts_1.EulerV2ViewContract)(web3, network);
186
+ const loanData = yield contract.methods.getUserData(addressForPosition).call();
187
+ const usedAssets = {};
188
+ // there is no user position check for a specific market, only global check
189
+ // but we need to make sure it works for the UI and show position only for the selected market
190
+ if (!(0, utils_1.compareAddresses)(loanData.borrowVault, selectedMarket.marketAddress)) {
191
+ 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), addressSpaceTakenByAnotherAccount: !(0, utils_1.compareAddresses)(loanData.owner, ownerAddress) && !(0, utils_1.compareAddresses)(loanData.owner, constants_1.ZERO_ADDRESS) });
192
+ }
193
+ else {
194
+ payload = Object.assign(Object.assign({}, payload), { borrowVault: loanData.borrowVault, borrowAmountInUnit: loanData.borrowAmountInUnit, inLockDownMode: loanData.inLockDownMode, inPermitDisabledMode: loanData.inPermitDisabledMode, addressSpaceTakenByAnotherAccount: !(0, utils_1.compareAddresses)(loanData.owner, ownerAddress) && !(0, utils_1.compareAddresses)(loanData.owner, constants_1.ZERO_ADDRESS) });
195
+ const borrowedInUnit = (0, utils_1.getEthAmountForDecimals)(loanData.borrowAmountInUnit, parsingDecimals);
196
+ const borrowedInAsset = (0, utils_1.getEthAmountForDecimals)(loanData.borrowAmountInAsset, marketData.decimals);
197
+ const borrowVault = loanData.borrowVault;
198
+ if (borrowVault && !(0, utils_1.compareAddresses)(constants_1.ZERO_ADDRESS, borrowVault) && borrowedInUnit) {
199
+ const borrowInfo = assetsData[borrowVault.toLowerCase()];
200
+ 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 });
201
+ }
202
+ }
203
+ loanData.collaterals.forEach((collateral, i) => {
204
+ const key = collateral.collateralVault.toLowerCase();
205
+ const collInfo = assetsData[key];
206
+ if (!collInfo || !marketData.collaterals.map(a => a.toLowerCase()).includes(key))
207
+ return; // this is a token supplied but not being used as a collateral for the market
208
+ const suppliedInUnit = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInUnit, parsingDecimals);
209
+ const suppliedInAsset = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInAsset, collInfo.decimals);
210
+ const collateralAmountInUSD = (0, utils_1.getEthAmountForDecimals)(collateral.collateralAmountInUSD, 18);
211
+ usedAssets[key] = Object.assign(Object.assign({}, exports.EMPTY_USED_ASSET), { collateral: true, isSupplied: !new decimal_js_1.default(suppliedInAsset).eq(0), supplied: suppliedInAsset, suppliedUsd: collateralAmountInUSD, vaultAddress: collateral.collateralVault, symbol: collInfo.symbol });
212
+ });
213
+ payload = Object.assign(Object.assign(Object.assign({}, payload), { usedAssets }), (0, eulerHelpers_1.getEulerV2AggregatedData)({
214
+ usedAssets, assetsData, network,
215
+ }));
216
+ return payload;
217
+ });
218
+ 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>;