diff --git a/src/adaptors/crvusd/abiControllers.json b/src/adaptors/crvusd/abiControllers.json new file mode 100644 index 0000000000..fef7feb3b4 --- /dev/null +++ b/src/adaptors/crvusd/abiControllers.json @@ -0,0 +1,576 @@ +[ + { + "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": "payable", "type": "fallback" }, + { + "stateMutability": "view", + "type": "function", + "name": "factory", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "amm", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "collateral_token", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "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": "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": "payable", + "type": "function", + "name": "create_loan", + "inputs": [ + { "name": "collateral", "type": "uint256" }, + { "name": "debt", "type": "uint256" }, + { "name": "N", "type": "uint256" } + ], + "outputs": [] + }, + { + "stateMutability": "payable", + "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": "payable", + "type": "function", + "name": "add_collateral", + "inputs": [{ "name": "collateral", "type": "uint256" }], + "outputs": [] + }, + { + "stateMutability": "payable", + "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": "payable", + "type": "function", + "name": "borrow_more", + "inputs": [ + { "name": "collateral", "type": "uint256" }, + { "name": "debt", "type": "uint256" } + ], + "outputs": [] + }, + { + "stateMutability": "payable", + "type": "function", + "name": "repay", + "inputs": [{ "name": "_d_debt", "type": "uint256" }], + "outputs": [] + }, + { + "stateMutability": "payable", + "type": "function", + "name": "repay", + "inputs": [ + { "name": "_d_debt", "type": "uint256" }, + { "name": "_for", "type": "address" } + ], + "outputs": [] + }, + { + "stateMutability": "payable", + "type": "function", + "name": "repay", + "inputs": [ + { "name": "_d_debt", "type": "uint256" }, + { "name": "_for", "type": "address" }, + { "name": "max_active_band", "type": "int256" } + ], + "outputs": [] + }, + { + "stateMutability": "payable", + "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": "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" }] + } +] diff --git a/src/adaptors/crvusd/abiFactory.json b/src/adaptors/crvusd/abiFactory.json new file mode 100644 index 0000000000..b571b14c53 --- /dev/null +++ b/src/adaptors/crvusd/abiFactory.json @@ -0,0 +1,273 @@ +[ + { + "name": "AddMarket", + "inputs": [ + { "name": "collateral", "type": "address", "indexed": true }, + { "name": "controller", "type": "address", "indexed": false }, + { "name": "amm", "type": "address", "indexed": false }, + { "name": "monetary_policy", "type": "address", "indexed": false }, + { "name": "ix", "type": "uint256", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "SetDebtCeiling", + "inputs": [ + { "name": "addr", "type": "address", "indexed": true }, + { "name": "debt_ceiling", "type": "uint256", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "MintForMarket", + "inputs": [ + { "name": "addr", "type": "address", "indexed": true }, + { "name": "amount", "type": "uint256", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "RemoveFromMarket", + "inputs": [ + { "name": "addr", "type": "address", "indexed": true }, + { "name": "amount", "type": "uint256", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "SetImplementations", + "inputs": [ + { "name": "amm", "type": "address", "indexed": false }, + { "name": "controller", "type": "address", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "name": "SetAdmin", + "inputs": [{ "name": "admin", "type": "address", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "SetFeeReceiver", + "inputs": [{ "name": "fee_receiver", "type": "address", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "stateMutability": "nonpayable", + "type": "constructor", + "inputs": [ + { "name": "stablecoin", "type": "address" }, + { "name": "admin", "type": "address" }, + { "name": "fee_receiver", "type": "address" }, + { "name": "weth", "type": "address" } + ], + "outputs": [] + }, + { + "stateMutability": "view", + "type": "function", + "name": "stablecoin", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "add_market", + "inputs": [ + { "name": "token", "type": "address" }, + { "name": "A", "type": "uint256" }, + { "name": "fee", "type": "uint256" }, + { "name": "admin_fee", "type": "uint256" }, + { "name": "_price_oracle_contract", "type": "address" }, + { "name": "monetary_policy", "type": "address" }, + { "name": "loan_discount", "type": "uint256" }, + { "name": "liquidation_discount", "type": "uint256" }, + { "name": "debt_ceiling", "type": "uint256" } + ], + "outputs": [{ "name": "", "type": "address[2]" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "total_debt", + "inputs": [], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_controller", + "inputs": [{ "name": "collateral", "type": "address" }], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_controller", + "inputs": [ + { "name": "collateral", "type": "address" }, + { "name": "i", "type": "uint256" } + ], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_amm", + "inputs": [{ "name": "collateral", "type": "address" }], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "get_amm", + "inputs": [ + { "name": "collateral", "type": "address" }, + { "name": "i", "type": "uint256" } + ], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_implementations", + "inputs": [ + { "name": "controller", "type": "address" }, + { "name": "amm", "type": "address" } + ], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_admin", + "inputs": [{ "name": "admin", "type": "address" }], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_fee_receiver", + "inputs": [{ "name": "fee_receiver", "type": "address" }], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_debt_ceiling", + "inputs": [ + { "name": "_to", "type": "address" }, + { "name": "debt_ceiling", "type": "uint256" } + ], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "rug_debt_ceiling", + "inputs": [{ "name": "_to", "type": "address" }], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "collect_fees_above_ceiling", + "inputs": [{ "name": "_to", "type": "address" }], + "outputs": [] + }, + { + "stateMutability": "view", + "type": "function", + "name": "controllers", + "inputs": [{ "name": "arg0", "type": "uint256" }], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "amms", + "inputs": [{ "name": "arg0", "type": "uint256" }], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "admin", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "fee_receiver", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "controller_implementation", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "amm_implementation", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "n_collaterals", + "inputs": [], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "collaterals", + "inputs": [{ "name": "arg0", "type": "uint256" }], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "collaterals_index", + "inputs": [ + { "name": "arg0", "type": "address" }, + { "name": "arg1", "type": "uint256" } + ], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "debt_ceiling", + "inputs": [{ "name": "arg0", "type": "address" }], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "debt_ceiling_residual", + "inputs": [{ "name": "arg0", "type": "address" }], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "WETH", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + } +] diff --git a/src/adaptors/crvusd/abiPolicies.json b/src/adaptors/crvusd/abiPolicies.json new file mode 100644 index 0000000000..ccc7b4790d --- /dev/null +++ b/src/adaptors/crvusd/abiPolicies.json @@ -0,0 +1,159 @@ +[ + { + "name": "SetAdmin", + "inputs": [{ "name": "admin", "type": "address", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "AddPegKeeper", + "inputs": [{ "name": "peg_keeper", "type": "address", "indexed": true }], + "anonymous": false, + "type": "event" + }, + { + "name": "RemovePegKeeper", + "inputs": [{ "name": "peg_keeper", "type": "address", "indexed": true }], + "anonymous": false, + "type": "event" + }, + { + "name": "SetRate", + "inputs": [{ "name": "rate", "type": "uint256", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "SetSigma", + "inputs": [{ "name": "sigma", "type": "uint256", "indexed": false }], + "anonymous": false, + "type": "event" + }, + { + "name": "SetTargetDebtFraction", + "inputs": [ + { "name": "target_debt_fraction", "type": "uint256", "indexed": false } + ], + "anonymous": false, + "type": "event" + }, + { + "stateMutability": "nonpayable", + "type": "constructor", + "inputs": [ + { "name": "admin", "type": "address" }, + { "name": "price_oracle", "type": "address" }, + { "name": "controller_factory", "type": "address" }, + { "name": "peg_keepers", "type": "address[5]" }, + { "name": "rate", "type": "uint256" }, + { "name": "sigma", "type": "uint256" }, + { "name": "target_debt_fraction", "type": "uint256" } + ], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_admin", + "inputs": [{ "name": "admin", "type": "address" }], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "add_peg_keeper", + "inputs": [{ "name": "pk", "type": "address" }], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "remove_peg_keeper", + "inputs": [{ "name": "pk", "type": "address" }], + "outputs": [] + }, + { + "stateMutability": "view", + "type": "function", + "name": "rate", + "inputs": [], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "rate_write", + "inputs": [], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_rate", + "inputs": [{ "name": "rate", "type": "uint256" }], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_sigma", + "inputs": [{ "name": "sigma", "type": "uint256" }], + "outputs": [] + }, + { + "stateMutability": "nonpayable", + "type": "function", + "name": "set_target_debt_fraction", + "inputs": [{ "name": "target_debt_fraction", "type": "uint256" }], + "outputs": [] + }, + { + "stateMutability": "view", + "type": "function", + "name": "admin", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "rate0", + "inputs": [], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "sigma", + "inputs": [], + "outputs": [{ "name": "", "type": "int256" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "target_debt_fraction", + "inputs": [], + "outputs": [{ "name": "", "type": "uint256" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "peg_keepers", + "inputs": [{ "name": "arg0", "type": "uint256" }], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "PRICE_ORACLE", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + }, + { + "stateMutability": "view", + "type": "function", + "name": "CONTROLLER_FACTORY", + "inputs": [], + "outputs": [{ "name": "", "type": "address" }] + } +] diff --git a/src/adaptors/crvusd/index.js b/src/adaptors/crvusd/index.js new file mode 100644 index 0000000000..e23bada86a --- /dev/null +++ b/src/adaptors/crvusd/index.js @@ -0,0 +1,140 @@ +const axios = require('axios'); +const sdk = require('@defillama/sdk4'); + +const abiFactory = require('./abiFactory.json'); +const abiControllers = require('./abiControllers.json'); +const abiPolicies = require('./abiPolicies.json'); + +const factory = '0xC9332fdCB1C491Dcc683bAe86Fe3cb70360738BC'; +const crvUsd = '0xf939E0A03FB07F59A73314E73794Be0E57ac1b4E'; + +const apy = async () => { + const nCollaterals = ( + await sdk.api.abi.call({ + target: factory, + abi: abiFactory.find((m) => m.name === 'n_collaterals'), + }) + ).output; + + const controllers = ( + await sdk.api.abi.multiCall({ + calls: [...Array.from({ length: nCollaterals }).keys()].map((i) => ({ + target: factory, + params: i, + })), + abi: abiFactory.find((m) => m.name === 'controllers'), + }) + ).output.map((o) => o.output); + + const amms = ( + await sdk.api.abi.multiCall({ + calls: [...Array.from({ length: nCollaterals }).keys()].map((i) => ({ + target: factory, + params: i, + })), + abi: abiFactory.find((m) => m.name === 'amms'), + }) + ).output.map((o) => o.output); + + const collateralTokens = ( + await sdk.api.abi.multiCall({ + calls: controllers.map((i) => ({ + target: i, + })), + abi: abiControllers.find((m) => m.name === 'collateral_token'), + }) + ).output.map((o) => o.output); + + const monetaryPolicies = ( + await sdk.api.abi.multiCall({ + calls: controllers.map((i) => ({ + target: i, + })), + abi: abiControllers.find((m) => m.name === 'monetary_policy'), + }) + ).output.map((o) => o.output); + + const rates = ( + await sdk.api.abi.multiCall({ + calls: monetaryPolicies.map((i) => ({ + target: i, + })), + abi: abiPolicies.find((m) => m.name === 'rate'), + }) + ).output.map((o) => o.output); + + const collateralBalance = ( + await sdk.api.abi.multiCall({ + calls: collateralTokens.map((t, i) => ({ + target: t, + params: amms[i], + })), + abi: 'erc20:balanceOf', + }) + ).output.map((o) => o.output); + + const totalDebt = ( + await sdk.api.abi.multiCall({ + calls: controllers.map((i) => ({ + target: i, + })), + abi: abiControllers.find((m) => m.name === 'total_debt'), + }) + ).output.map((o) => o.output); + + const debtCeiling = ( + await sdk.api.abi.multiCall({ + calls: controllers.map((t) => ({ + target: factory, + params: t, + })), + abi: abiFactory.find((m) => m.name === 'debt_ceiling'), + }) + ).output.map((o) => o.output); + + const coins = collateralTokens.map((t) => `ethereum:${t}`); + const prices = ( + await axios.get(`https://coins.llama.fi/prices/current/${coins}`) + ).data.coins; + + const pools = collateralTokens.map((t, i) => { + const token = prices[`ethereum:${t}`]; + const price = token.price; + const decimals = token.decimals; + const symbol = token.symbol; + + const totalSupplyUsd = (collateralBalance[i] * price) / 10 ** decimals; + const totalBorrowUsd = totalDebt[i] / 1e18; + // cdp + const tvlUsd = totalSupplyUsd; + const debtCeilingUsd = debtCeiling[i] / 1e18; + + // https://docs.curve.fi/crvUSD/monetarypolicy/#interest-rates + const apyBaseBorrow = + ((1 + rates[i] / 1e18) ** (365 * 24 * 60 * 60) - 1) * 100; + + return { + pool: amms[i], + symbol, + project: 'crvusd', + chain: 'ethereum', + tvlUsd, + totalSupplyUsd, + totalBorrowUsd, + debtCeilingUsd, + apyBase: 0, + apyBaseBorrow, + underlyingTokens: [collateralTokens[i]], + mintedCoin: 'crvusd', + }; + }); + + return pools.filter( + (i) => i.pool !== '0x136e783846ef68C8Bd00a3369F787dF8d683a696' + ); +}; + +module.exports = { + apy, + url: 'https://crvusd.curve.fi/#/ethereum/markets', +};