Verified contractExact
AaveMonitorV2
Address0xcfd05bebb84787ee2efb2ea633981e44d754485d
- Balance
0 ETH
- Transactions
2,101
- Compiler
solc 0.6.12
- Same code
Only this contract
Details
- Compiler
- solc 0.6.12+commit.27d51765
- Language
- solidity
- Optimization
- Yes, 200 runs
- EVM version
- istanbul
- License
- Not stated
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 12,093,089
- Creation transaction
- 0x42a82fa5ff…edef603c7a
192 files
The source code is large: one file is shown at a time. Choose a file in the list.
- contracts/aaveV2/automatic/AaveMonitorV2.solmain8.98 KB
- contracts/DS/DSAuth.sol1.11 KB
- contracts/DS/DSAuthority.sol155 B
- contracts/DS/DSGuard.sol560 B
- contracts/DS/DSMath.sol2.36 KB
- contracts/DS/DSNote.sol493 B
- contracts/DS/DSProxy.sol1.48 KB
- contracts/DS/DSProxyFactoryInterface.sol170 B
- contracts/aave/AaveBasicProxy.sol7.38 KB
- contracts/aave/AaveHelper.sol10.55 KB
- contracts/aave/AaveLoanInfo.sol9.55 KB
- contracts/aave/AaveSafetyRatio.sol556 B
- contracts/aave/automatic/AaveMonitor.sol8.33 KB
- contracts/aave/automatic/AaveMonitorProxy.sol4.83 KB
- contracts/aave/automatic/AaveSubscriptions.sol6.13 KB
- contracts/aave/automatic/AaveSubscriptionsProxy.sol2.36 KB
- contracts/aave/import/AaveImport.sol4.26 KB
- contracts/aave/import/AaveImportTaker.sol2.68 KB
- contracts/aave/saver/AaveSaverProxy.sol4.56 KB
- contracts/aave/saver/AaveSaverReceiver.sol3.4 KB
- contracts/aave/saver/AaveSaverTaker.sol2.81 KB
- contracts/aaveV2/AaveBasicProxyV2.sol7.98 KB
- contracts/aaveV2/AaveHelperV2.sol4.59 KB
- contracts/aaveV2/AaveLoanInfoV2.sol11.27 KB
- contracts/aaveV2/AaveSafetyRatioV2.sol594 B
- contracts/aaveV2/automatic/AaveMonitorProxyV2.sol3.56 KB
- contracts/aaveV2/automatic/AaveSubscriptionsProxyV2.sol2.43 KB
- contracts/aaveV2/automatic/AaveSubscriptionsV2.sol6.19 KB
- contracts/aaveV2/import/AaveImportTakerV2.sol2.77 KB
- contracts/aaveV2/import/AaveImportV2.sol4.63 KB
- contracts/aaveV2/saver/AaveSaverProxyV2.sol4.31 KB
- contracts/aaveV2/saver/AaveSaverReceiverV2.sol3.27 KB
- contracts/aaveV2/saver/AaveSaverTakerV2.sol3.01 KB
- contracts/aaveV2/saver/optimized/AaveSaverReceiverOV2.sol6.58 KB
- contracts/aaveV2/saver/optimized/AaveSaverTakerOV2.sol3.16 KB
- contracts/auth/AdminAuth.sol1.69 KB
- contracts/auth/Auth.sol544 B
- contracts/auth/ProxyPermission.sol1.55 KB
- contracts/compound/CompoundBasicProxy.sol5.81 KB
- contracts/compound/CompoundLoanInfo.sol8.42 KB
- contracts/compound/CompoundSafetyRatio.sol2.24 KB
- contracts/compound/automatic/CompoundMonitor.sol9.3 KB
- contracts/compound/automatic/CompoundMonitorProxy.sol4.86 KB
- contracts/compound/automatic/CompoundSubscriptions.sol6.2 KB
- contracts/compound/automatic/CompoundSubscriptionsProxy.sol2.41 KB
- contracts/compound/comp/CompBalance.sol4 KB
- contracts/compound/comp/CompLeverage.sol4.18 KB
- contracts/compound/create/CompoundCreateReceiver.sol4.53 KB
- contracts/compound/create/CompoundCreateTaker.sol2.61 KB
- contracts/compound/helpers/CarefulMath.sol1.98 KB
- contracts/compound/helpers/CompoundSaverHelper.sol9.66 KB
- contracts/compound/helpers/Exponential.sol11.58 KB
- contracts/compound/import/CompoundBorrowProxy.sol1.09 KB
- contracts/compound/import/CompoundImportFlashLoan.sol3.67 KB
- contracts/compound/import/CompoundImportTaker.sol1.82 KB
- contracts/compound/saver/CompoundFlashLoanTaker.sol4.04 KB
- contracts/compound/saver/CompoundSaverFlashLoan.sol3.84 KB
- contracts/compound/saver/CompoundSaverFlashProxy.sol5.83 KB
- contracts/compound/saver/CompoundSaverProxy.sol4.24 KB
- contracts/cream/CreamBasicProxy.sol5.79 KB
- contracts/cream/CreamLoanInfo.sol8.31 KB
- contracts/cream/CreamSafetyRatio.sol2.25 KB
- contracts/cream/helpers/CreamSaverHelper.sol9.17 KB
- contracts/cream/import/CreamBorrowProxy.sol1.05 KB
- contracts/cream/import/CreamImportFlashLoan.sol3.26 KB
- contracts/cream/import/CreamImportTaker.sol2.25 KB
- contracts/cream/saver/CreamFlashLoanTaker.sol3.86 KB
- contracts/cream/saver/CreamSaverFlashLoan.sol3.85 KB
- contracts/cream/saver/CreamSaverFlashProxy.sol5.58 KB
- contracts/cream/saver/CreamSaverProxy.sol3.93 KB
- contracts/exchange/AllowanceProxy.sol1.36 KB
- contracts/exchange/Prices.sol3.58 KB
- contracts/exchange/SaverExchange.sol3.95 KB
- contracts/exchange/SaverExchangeCore.sol9.83 KB
- contracts/exchange/SaverExchangeHelper.sol2.15 KB
- contracts/exchange/SaverExchangeRegistry.sol653 B
- contracts/exchange/wrappers/KyberWrapper.sol5.13 KB
- contracts/exchange/wrappers/OasisTradeWrapper.sol4.3 KB
- contracts/exchange/wrappers/UniswapV2Wrapper.sol4.98 KB
- contracts/exchange/wrappers/UniswapWrapper.sol6.83 KB
- contracts/exchangeV3/AllowanceProxyV3.sol1.3 KB
- contracts/exchangeV3/DFSExchange.sol2.77 KB
- contracts/exchangeV3/DFSExchangeCore.sol6.35 KB
- contracts/exchangeV3/DFSExchangeData.sol1.09 KB
- contracts/exchangeV3/DFSExchangeHelper.sol3.9 KB
- contracts/exchangeV3/DFSPricesV3.sol3.79 KB
- contracts/exchangeV3/offchainWrappersV3/ScpWrapper.sol2.66 KB
- contracts/exchangeV3/offchainWrappersV3/ZeroxWrapper.sol2.73 KB
- contracts/exchangeV3/wrappersV3/KyberWrapperV3.sol5.28 KB
- contracts/exchangeV3/wrappersV3/OasisTradeWrapperV3.sol4.42 KB
- contracts/exchangeV3/wrappersV3/UniswapWrapperV3.sol4.97 KB
- contracts/flashloan/DydxFlashLoanTaker.sol2.11 KB
- contracts/interfaces/CEtherInterface.sol162 B
- contracts/interfaces/CTokenInterface.sol2.06 KB
- contracts/interfaces/CompoundOracleInterface.sol157 B
- contracts/interfaces/ComptrollerInterface.sol1.46 KB
- contracts/interfaces/DSProxyInterface.sol506 B
- contracts/interfaces/DaiJoin.sol300 B
- contracts/interfaces/ERC20.sol740 B
- contracts/interfaces/ExchangeInterface.sol755 B
- contracts/interfaces/ExchangeInterfaceV2.sol488 B
- contracts/interfaces/ExchangeInterfaceV3.sol608 B
- contracts/interfaces/Flipper.sol356 B
- contracts/interfaces/GasTokenInterface.sol434 B
- contracts/interfaces/Gem.sol621 B
- contracts/interfaces/IAToken.sol198 B
- contracts/interfaces/IAaveProtocolDataProviderV2.sol1.82 KB
- contracts/interfaces/IAaveSubscription.sol251 B
- contracts/interfaces/ICompoundSubscription.sol255 B
- contracts/interfaces/ICompoundSubscriptions.sol116 B
- contracts/interfaces/IFeeRecipient.sol225 B
- contracts/interfaces/ILendingPool.sol6.6 KB
- contracts/interfaces/ILendingPoolAddressesProvider.sol1.05 KB
- contracts/interfaces/ILendingPoolV2.sol20.58 KB
- contracts/interfaces/ILoanShifter.sol219 B
- contracts/interfaces/IMCDSubscriptions.sol211 B
- contracts/interfaces/IPriceOracleGetterAave.sol519 B
- contracts/interfaces/ITokenInterface.sol465 B
- contracts/interfaces/Join.sol313 B
- contracts/interfaces/Jug.sol220 B
- contracts/interfaces/KyberNetworkProxyInterface.sol1.64 KB
- contracts/interfaces/Manager.sol1.04 KB
- contracts/interfaces/OasisInterface.sol722 B
- contracts/interfaces/OffchainWrapperInterface.sol318 B
- contracts/interfaces/Osm.sol164 B
- contracts/interfaces/OsmMom.sol101 B
- contracts/interfaces/PipInterface.sol115 B
- contracts/interfaces/ProxyRegistryInterface.sol242 B
- contracts/interfaces/Spotter.sol224 B
- contracts/interfaces/TokenInterface.sol602 B
- contracts/interfaces/UniswapExchangeInterface.sol1.92 KB
- contracts/interfaces/UniswapFactoryInterface.sol161 B
- contracts/interfaces/UniswapRouterInterface.sol1.07 KB
- contracts/interfaces/Vat.sol1.08 KB
- contracts/interfaces/reflexer/IBasicTokenAdapters.sol334 B
- contracts/interfaces/reflexer/ICoinJoin.sol221 B
- contracts/interfaces/reflexer/IGetSafes.sol387 B
- contracts/interfaces/reflexer/IMedianOracle.sol122 B
- contracts/interfaces/reflexer/IOracleRelayer.sol314 B
- contracts/interfaces/reflexer/ISAFEEngine.sol1.56 KB
- contracts/interfaces/reflexer/ISAFEManager.sol1.11 KB
- contracts/interfaces/reflexer/ITaxCollector.sol282 B
- contracts/loggers/DefisaverLogger.sol443 B
- contracts/mcd/MCDLoanInfo.sol2.48 KB
- contracts/mcd/automaticV2/ISubscriptionsV2.sol462 B
- contracts/mcd/automaticV2/MCDMonitorProxyV2.sol3.52 KB
- contracts/mcd/automaticV2/MCDMonitorV2.sol9.39 KB
- contracts/mcd/automaticV2/MCDPriceVerifier.sol1.26 KB
- contracts/mcd/automaticV2/StaticV2.sol455 B
- contracts/mcd/automaticV2/SubscriptionsProxyV2.sol2.52 KB
- contracts/mcd/automaticV2/SubscriptionsV2.sol8.49 KB
- contracts/mcd/bids/BidProxy.sol2.75 KB
- contracts/mcd/close/MCDCloseFlashLoan.sol5.56 KB
- contracts/mcd/close/MCDCloseTaker.sol4.4 KB
- contracts/mcd/create/MCDCreateFlashLoan.sol4.02 KB
- contracts/mcd/create/MCDCreateProxyActions.sol14.66 KB
- contracts/mcd/create/MCDCreateTaker.sol2.95 KB
- contracts/mcd/saver/MCDSaverFlashLoan.sol5.92 KB
- contracts/mcd/saver/MCDSaverProxy.sol10.64 KB
- contracts/mcd/saver/MCDSaverProxyHelper.sol5 KB
- contracts/mcd/saver/MCDSaverTaker.sol4.52 KB
- contracts/reflexer/RaiLoanInfo.sol5.71 KB
- contracts/reflexer/saver/RAISaverFlashLoan.sol4.91 KB
- contracts/reflexer/saver/RAISaverProxy.sol11.97 KB
- contracts/reflexer/saver/RAISaverProxyHelper.sol7.59 KB
- contracts/reflexer/saver/RAISaverTaker.sol5.45 KB
- contracts/savings/ProtocolInterface.sol205 B
- contracts/savings/SavingsLogger.sol777 B
- contracts/savings/SavingsProxy.sol5.86 KB
- contracts/savings/aave/AaveSavingsProtocol.sol1.47 KB
- contracts/savings/compound/CompoundSavingsProtocol.sol1.65 KB
- contracts/savings/dsr/DSRSavingsProtocol.sol3.22 KB
- contracts/savings/dydx/DydxSavingsProtocol.sol3.28 KB
- contracts/savings/dydx/ISoloMargin.sol12.23 KB
- contracts/savings/fulcrum/FulcrumSavingsProtocol.sol1.82 KB
- contracts/shifter/LoanShifterReceiver.sol7.42 KB
- contracts/shifter/LoanShifterTaker.sol7.16 KB
- contracts/shifter/ShifterRegistry.sol687 B
- contracts/shifter/protocols/CompShifter.sol3.94 KB
- contracts/shifter/protocols/McdShifter.sol3.72 KB
- contracts/utils/Address.sol2.95 KB
- contracts/utils/BotRegistry.sol632 B
- contracts/utils/DFSProxy.sol2.49 KB
- contracts/utils/Discount.sol1.02 KB
- contracts/utils/DydxFlashLoanBase.sol3.06 KB
- contracts/utils/ExchangeDataParser.sol1.13 KB
- contracts/utils/FlashLoanReceiverBase.sol3.29 KB
- contracts/utils/GasBurner.sol423 B
- contracts/utils/PullTokensProxy.sol728 B
- contracts/utils/SafeERC20.sol2.05 KB
- contracts/utils/SafeMath.sol1.74 KB
- contracts/utils/ZrxAllowlist.sol1.2 KB
contracts/aaveV2/automatic/AaveMonitorV2.sol
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import "../../utils/GasBurner.sol";
import "../../DS/DSMath.sol";
import "../../auth/AdminAuth.sol";
import "../../loggers/DefisaverLogger.sol";
import "../../exchangeV3/DFSExchangeData.sol";
import "./AaveMonitorProxyV2.sol";
import "./AaveSubscriptionsV2.sol";
import "../AaveSafetyRatioV2.sol";
/// @title Contract implements logic of calling boost/repay in the automatic system
contract AaveMonitorV2 is AdminAuth, DSMath, AaveSafetyRatioV2, GasBurner {
using SafeERC20 for ERC20;
string public constant NAME = "AaveMonitorV2";
enum Method { Boost, Repay }
uint public REPAY_GAS_TOKEN = 20;
uint public BOOST_GAS_TOKEN = 20;
uint public MAX_GAS_PRICE = 400000000000; // 400 gwei
uint public REPAY_GAS_COST = 2000000;
uint public BOOST_GAS_COST = 2000000;
address public constant DEFISAVER_LOGGER = 0x5c55B921f590a89C1Ebe84dF170E655a82b62126;
address public constant AAVE_MARKET_ADDRESS = 0xB53C1a33016B2DC2fF3653530bfF1848a515c8c5;
AaveMonitorProxyV2 public aaveMonitorProxy;
AaveSubscriptionsV2 public subscriptionsContract;
address public aaveSaverProxy;
DefisaverLogger public logger = DefisaverLogger(DEFISAVER_LOGGER);
modifier onlyApproved() {
require(BotRegistry(BOT_REGISTRY_ADDRESS).botList(msg.sender), "Not auth bot");
_;
}
/// @param _aaveMonitorProxy Proxy contracts that actually is authorized to call DSProxy
/// @param _subscriptions Subscriptions contract for Aave positions
/// @param _aaveSaverProxy Contract that actually performs Repay/Boost
constructor(address _aaveMonitorProxy, address _subscriptions, address _aaveSaverProxy) public {
aaveMonitorProxy = AaveMonitorProxyV2(_aaveMonitorProxy);
subscriptionsContract = AaveSubscriptionsV2(_subscriptions);
aaveSaverProxy = _aaveSaverProxy;
}
/// @notice Bots call this method to repay for user when conditions are met
/// @dev If the contract ownes gas token it will try and use it for gas price reduction
/// @param _exData Exchange data
/// @param _user The actual address that owns the Aave position
function repayFor(
DFSExchangeData.ExchangeData memory _exData,
address _user,
uint256 _rateMode,
uint256 _flAmount
) public payable onlyApproved burnGas(REPAY_GAS_TOKEN) {
(bool isAllowed, uint ratioBefore) = canCall(Method.Repay, _user);
require(isAllowed); // check if conditions are met
uint256 gasCost = calcGasCost(REPAY_GAS_COST);
aaveMonitorProxy.callExecute{value: msg.value}(
_user,
aaveSaverProxy,
abi.encodeWithSignature(
"repay(address,(address,address,uint256,uint256,uint256,uint256,address,address,bytes,(address,address,address,uint256,uint256,bytes)),uint256,uint256,uint256)",
AAVE_MARKET_ADDRESS,
_exData,
_rateMode,
gasCost,
_flAmount
)
);
(bool isGoodRatio, uint ratioAfter) = ratioGoodAfter(Method.Repay, _user);
require(isGoodRatio); // check if the after result of the actions is good
returnEth();
logger.Log(address(this), _user, "AutomaticAaveRepayV2", abi.encode(ratioBefore, ratioAfter));
}
/// @notice Bots call this method to boost for user when conditions are met
/// @dev If the contract ownes gas token it will try and use it for gas price reduction
/// @param _exData Exchange data
/// @param _user The actual address that owns the Aave position
function boostFor(
DFSExchangeData.ExchangeData memory _exData,
address _user,
uint256 _rateMode,
uint256 _flAmount
) public payable onlyApproved burnGas(BOOST_GAS_TOKEN) {
(bool isAllowed, uint ratioBefore) = canCall(Method.Boost, _user);
require(isAllowed); // check if conditions are met
uint256 gasCost = calcGasCost(BOOST_GAS_COST);
aaveMonitorProxy.callExecute{value: msg.value}(
_user,
aaveSaverProxy,
abi.encodeWithSignature(
"boost(address,(address,address,uint256,uint256,uint256,uint256,address,address,bytes,(address,address,address,uint256,uint256,bytes)),uint256,uint256,uint256)",
AAVE_MARKET_ADDRESS,
_exData,
_rateMode,
gasCost,
_flAmount
)
);
(bool isGoodRatio, uint ratioAfter) = ratioGoodAfter(Method.Boost, _user);
require(isGoodRatio); // check if the after result of the actions is good
returnEth();
logger.Log(address(this), _user, "AutomaticAaveBoostV2", abi.encode(ratioBefore, ratioAfter));
}
/******************* INTERNAL METHODS ********************************/
function returnEth() internal {
// return if some eth left
if (address(this).balance > 0) {
msg.sender.transfer(address(this).balance);
}
}
/******************* STATIC METHODS ********************************/
/// @notice Checks if Boost/Repay could be triggered for the CDP
/// @dev Called by AaveMonitor to enforce the min/max check
/// @param _method Type of action to be called
/// @param _user The actual address that owns the Aave position
/// @return Boolean if it can be called and the ratio
function canCall(Method _method, address _user) public view returns(bool, uint) {
bool subscribed = subscriptionsContract.isSubscribed(_user);
AaveSubscriptionsV2.AaveHolder memory holder = subscriptionsContract.getHolder(_user);
// check if cdp is subscribed
if (!subscribed) return (false, 0);
// check if boost and boost allowed
if (_method == Method.Boost && !holder.boostEnabled) return (false, 0);
uint currRatio = getSafetyRatio(AAVE_MARKET_ADDRESS, _user);
if (_method == Method.Repay) {
return (currRatio < holder.minRatio, currRatio);
} else if (_method == Method.Boost) {
return (currRatio > holder.maxRatio, currRatio);
}
}
/// @dev After the Boost/Repay check if the ratio doesn't trigger another call
/// @param _method Type of action to be called
/// @param _user The actual address that owns the Aave position
/// @return Boolean if the recent action preformed correctly and the ratio
function ratioGoodAfter(Method _method, address _user) public view returns(bool, uint) {
AaveSubscriptionsV2.AaveHolder memory holder;
holder = subscriptionsContract.getHolder(_user);
uint currRatio = getSafetyRatio(AAVE_MARKET_ADDRESS, _user);
if (_method == Method.Repay) {
return (currRatio < holder.maxRatio, currRatio);
} else if (_method == Method.Boost) {
return (currRatio > holder.minRatio, currRatio);
}
}
/// @notice Calculates gas cost (in Eth) of tx
/// @dev Gas price is limited to MAX_GAS_PRICE to prevent attack of draining user CDP
/// @param _gasAmount Amount of gas used for the tx
function calcGasCost(uint _gasAmount) public view returns (uint) {
uint gasPrice = tx.gasprice <= MAX_GAS_PRICE ? tx.gasprice : MAX_GAS_PRICE;
return mul(gasPrice, _gasAmount);
}
/******************* OWNER ONLY OPERATIONS ********************************/
/// @notice As the code is new, have a emergancy admin saver proxy change
function changeAaveSaverProxy(address _newAaveSaverProxy) public onlyAdmin {
aaveSaverProxy = _newAaveSaverProxy;
}
/// @notice Allows owner to change gas cost for boost operation, but only up to 3 millions
/// @param _gasCost New gas cost for boost method
function changeBoostGasCost(uint _gasCost) public onlyOwner {
require(_gasCost < 3000000);
BOOST_GAS_COST = _gasCost;
}
/// @notice Allows owner to change gas cost for repay operation, but only up to 3 millions
/// @param _gasCost New gas cost for repay method
function changeRepayGasCost(uint _gasCost) public onlyOwner {
require(_gasCost < 3000000);
REPAY_GAS_COST = _gasCost;
}
/// @notice Allows owner to change max gas price
/// @param _maxGasPrice New max gas price
function changeMaxGasPrice(uint _maxGasPrice) public onlyOwner {
require(_maxGasPrice < 500000000000);
MAX_GAS_PRICE = _maxGasPrice;
}
/// @notice Allows owner to change gas token amount
/// @param _gasTokenAmount New gas token amount
/// @param _repay true if repay gas token, false if boost gas token
function changeGasTokenAmount(uint _gasTokenAmount, bool _repay) public onlyOwner {
if (_repay) {
REPAY_GAS_TOKEN = _gasTokenAmount;
} else {
BOOST_GAS_TOKEN = _gasTokenAmount;
}
}
}
Compiler settingsShow
{
"metadata": {
"bytecodeHash": "ipfs"
},
"libraries": {},
"optimizer": {
"runs": 200,
"enabled": true
},
"evmVersion": "istanbul",
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.