zellic-audit
Initial commit
f998fcd
raw
history blame
No virus
47.7 kB
{
"language": "Solidity",
"sources": {
"contracts/actions/aave/Deposit.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later\npragma solidity ^0.8.15;\n\nimport { Executable } from \"../common/Executable.sol\";\nimport { UseStore, Write, Read } from \"../common/UseStore.sol\";\nimport { OperationStorage } from \"../../core/OperationStorage.sol\";\nimport { ILendingPool } from \"../../interfaces/aave/ILendingPool.sol\";\nimport { DepositData } from \"../../core/types/Aave.sol\";\nimport { SafeMath } from \"../../libs/SafeMath.sol\";\nimport { SafeERC20, IERC20 } from \"../../libs/SafeERC20.sol\";\nimport { AAVE_LENDING_POOL, DEPOSIT_ACTION } from \"../../core/constants/Aave.sol\";\n\n/**\n * @title Deposit | AAVE Action contract\n * @notice Deposits the specified asset as collateral on AAVE's lending pool\n */\ncontract AaveDeposit is Executable, UseStore {\n using Write for OperationStorage;\n using Read for OperationStorage;\n using SafeMath for uint256;\n\n constructor(address _registry) UseStore(_registry) {}\n\n /**\n * @dev Look at UseStore.sol to get additional info on paramsMapping\n * @param data Encoded calldata that conforms to the DepositData struct\n * @param paramsMap Maps operation storage values by index (index offset by +1) to execute calldata params\n */\n function execute(bytes calldata data, uint8[] memory paramsMap) external payable override {\n DepositData memory deposit = parseInputs(data);\n\n uint256 mappedDepositAmount = store().readUint(\n bytes32(deposit.amount),\n paramsMap[1],\n address(this)\n );\n\n uint256 actualDepositAmount = deposit.sumAmounts\n ? mappedDepositAmount.add(deposit.amount)\n : mappedDepositAmount;\n\n ILendingPool(registry.getRegisteredService(AAVE_LENDING_POOL)).deposit(\n deposit.asset,\n actualDepositAmount,\n address(this),\n 0\n );\n\n if (deposit.setAsCollateral) {\n ILendingPool(registry.getRegisteredService(AAVE_LENDING_POOL)).setUserUseReserveAsCollateral(\n deposit.asset,\n true\n );\n }\n\n store().write(bytes32(actualDepositAmount));\n emit Action(DEPOSIT_ACTION, bytes(abi.encode(actualDepositAmount)));\n }\n\n function parseInputs(bytes memory _callData) public pure returns (DepositData memory params) {\n return abi.decode(_callData, (DepositData));\n }\n}\n"
},
"contracts/actions/common/Executable.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later\npragma solidity ^0.8.15;\n\n/**\n * @title Shared Action Executable interface\n * @notice Provides a common interface for an execute method to all Action\n */\ninterface Executable {\n function execute(bytes calldata data, uint8[] memory paramsMap) external payable;\n\n /**\n * @dev Emitted once an Action has completed execution\n * @param name The Action name\n * @param returned The bytes value returned by the Action\n **/\n event Action(string indexed name, bytes returned);\n}\n"
},
"contracts/actions/common/UseStore.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later\npragma solidity ^0.8.15;\n\nimport { OperationStorage } from \"../../core/OperationStorage.sol\";\nimport { ServiceRegistry } from \"../../core/ServiceRegistry.sol\";\nimport { OPERATION_STORAGE } from \"../../core/constants/Common.sol\";\n\n/**\n * @title UseStore contract\n * @notice Provides access to the OperationStorage contract\n * @dev Is used by Action contracts to store and retrieve values from Operation Storage.\n * @dev Previously stored values are used to override values passed to Actions during Operation execution\n */\nabstract contract UseStore {\n ServiceRegistry internal immutable registry;\n\n constructor(address _registry) {\n registry = ServiceRegistry(_registry);\n }\n\n function store() internal view returns (OperationStorage) {\n return OperationStorage(registry.getRegisteredService(OPERATION_STORAGE));\n }\n}\n\nlibrary Read {\n function read(\n OperationStorage _storage,\n bytes32 param,\n uint256 paramMapping,\n address who\n ) internal view returns (bytes32) {\n if (paramMapping > 0) {\n return _storage.at(paramMapping - 1, who);\n }\n\n return param;\n }\n\n function readUint(\n OperationStorage _storage,\n bytes32 param,\n uint256 paramMapping,\n address who\n ) internal view returns (uint256) {\n return uint256(read(_storage, param, paramMapping, who));\n }\n}\n\nlibrary Write {\n function write(OperationStorage _storage, bytes32 value) internal {\n _storage.push(value);\n }\n}\n"
},
"contracts/core/OperationStorage.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later\npragma solidity ^0.8.15;\n\nimport { ServiceRegistry } from \"./ServiceRegistry.sol\";\n\n/**\n * @title Operation Storage\n * @notice Stores the return values from Actions during an Operation's execution\n * @dev valuesHolders is an array of t/x initiators (msg.sender) who have pushed values to Operation Storage\n * returnValues is a mapping between a msg.sender and an array of Action return values generated by that senders transaction\n */\ncontract OperationStorage {\n uint8 internal action = 0;\n bytes32[] public actions;\n bool[] public optionals;\n mapping(address => bytes32[]) public returnValues;\n address[] public valuesHolders;\n bool private locked;\n address private whoLocked;\n address public initiator;\n address immutable operationExecutorAddress;\n\n ServiceRegistry internal immutable registry;\n\n constructor(ServiceRegistry _registry, address _operationExecutorAddress) {\n registry = _registry;\n operationExecutorAddress = _operationExecutorAddress;\n }\n\n /**\n * @dev Locks storage to protect against re-entrancy attacks.@author\n */\n function lock() external {\n locked = true;\n whoLocked = msg.sender;\n }\n\n /**\n * @dev Only the original locker can unlock the contract at the end of the transaction\n */\n function unlock() external {\n require(whoLocked == msg.sender, \"Only the locker can unlock\");\n require(locked, \"Not locked\");\n locked = false;\n whoLocked = address(0);\n }\n\n /**\n * @dev Sets the initiator of the original call\n * Is used by Automation Bot branch in the onFlashloan callback in Operation Executor\n * Ensures that third party calls to Operation Storage do not maliciously override values in Operation Storage\n * @param _initiator Sets the initiator to Operation Executor contract when storing return values from flashloan nested Action\n */\n function setInitiator(address _initiator) external {\n require(msg.sender == operationExecutorAddress);\n initiator = _initiator;\n }\n\n /**\n * @param _actions Stores the Actions currently being executed for a given Operation and their optionality\n */\n function setOperationActions(bytes32[] memory _actions, bool[] memory _optionals) external {\n actions = _actions;\n optionals = _optionals;\n }\n\n /**\n * @param actionHash Checks the current action has against the expected action hash\n */\n function verifyAction(bytes32 actionHash, bool skipped) external {\n if(skipped) {\n require(optionals[action], \"Action cannot be skipped\");\n }\n require(actions[action] == actionHash, \"incorrect-action\");\n registry.getServiceAddress(actionHash);\n action++;\n }\n\n /**\n * @dev Custom operations have no Actions stored in Operation Registry\n * @return Returns true / false depending on whether the Operation has any actions to verify the Operation against\n */\n function hasActionsToVerify() external view returns (bool) {\n return actions.length > 0;\n }\n\n /**\n * @param value Pushes a bytes32 to end of the returnValues array\n */\n function push(bytes32 value) external {\n address who = msg.sender;\n if (who == operationExecutorAddress) {\n who = initiator;\n }\n\n if (returnValues[who].length == 0) {\n valuesHolders.push(who);\n }\n returnValues[who].push(value);\n }\n\n /**\n * @dev Values are stored against an address (who)\n * This ensures that malicious actors looking to push values to Operation Storage mid transaction cannot overwrite values\n * @param index The index of the desired value\n * @param who The msg.sender address responsible for storing values\n */\n function at(uint256 index, address who) external view returns (bytes32) {\n if (who == operationExecutorAddress) {\n who = initiator;\n }\n return returnValues[who][index];\n }\n\n /**\n * @param who The msg.sender address responsible for storing values\n * @return The length of return values stored against a given msg.sender address\n */\n function len(address who) external view returns (uint256) {\n if (who == operationExecutorAddress) {\n who = initiator;\n }\n return returnValues[who].length;\n }\n\n /**\n * @dev Clears storage in preparation for the next Operation\n */\n function clearStorage() external {\n delete action;\n delete actions;\n for (uint256 i = 0; i < valuesHolders.length; i++) {\n delete returnValues[valuesHolders[i]];\n }\n delete valuesHolders;\n }\n}\n"
},
"contracts/interfaces/aave/ILendingPool.sol": {
"content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity ^0.8.15;\n\npragma experimental ABIEncoderV2;\n\nimport { ILendingPoolAddressesProvider } from \"./ILendingPoolAddressesProvider.sol\";\nimport { DataTypes } from \"./DataTypes.sol\";\n\ninterface ILendingPool {\n /**\n * @dev Emitted on deposit()\n * @param reserve The address of the underlying asset of the reserve\n * @param user The address initiating the deposit\n * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens\n * @param amount The amount deposited\n * @param referral The referral code used\n **/\n event Deposit(\n address indexed reserve,\n address user,\n address indexed onBehalfOf,\n uint256 amount,\n uint16 indexed referral\n );\n\n /**\n * @dev Emitted on withdraw()\n * @param reserve The address of the underlyng asset being withdrawn\n * @param user The address initiating the withdrawal, owner of aTokens\n * @param to Address that will receive the underlying\n * @param amount The amount to be withdrawn\n **/\n event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);\n\n /**\n * @dev Emitted on borrow() and flashLoan() when debt needs to be opened\n * @param reserve The address of the underlying asset being borrowed\n * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just\n * initiator of the transaction on flashLoan()\n * @param onBehalfOf The address that will be getting the debt\n * @param amount The amount borrowed out\n * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable\n * @param borrowRate The numeric rate at which the user has borrowed\n * @param referral The referral code used\n **/\n event Borrow(\n address indexed reserve,\n address user,\n address indexed onBehalfOf,\n uint256 amount,\n uint256 borrowRateMode,\n uint256 borrowRate,\n uint16 indexed referral\n );\n\n /**\n * @dev Emitted on repay()\n * @param reserve The address of the underlying asset of the reserve\n * @param user The beneficiary of the repayment, getting his debt reduced\n * @param repayer The address of the user initiating the repay(), providing the funds\n * @param amount The amount repaid\n **/\n event Repay(\n address indexed reserve,\n address indexed user,\n address indexed repayer,\n uint256 amount\n );\n\n /**\n * @dev Emitted on swapBorrowRateMode()\n * @param reserve The address of the underlying asset of the reserve\n * @param user The address of the user swapping his rate mode\n * @param rateMode The rate mode that the user wants to swap to\n **/\n event Swap(address indexed reserve, address indexed user, uint256 rateMode);\n\n /**\n * @dev Emitted on setUserUseReserveAsCollateral()\n * @param reserve The address of the underlying asset of the reserve\n * @param user The address of the user enabling the usage as collateral\n **/\n event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);\n\n /**\n * @dev Emitted on setUserUseReserveAsCollateral()\n * @param reserve The address of the underlying asset of the reserve\n * @param user The address of the user enabling the usage as collateral\n **/\n event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);\n\n /**\n * @dev Emitted on rebalanceStableBorrowRate()\n * @param reserve The address of the underlying asset of the reserve\n * @param user The address of the user for which the rebalance has been executed\n **/\n event RebalanceStableBorrowRate(address indexed reserve, address indexed user);\n\n /**\n * @dev Emitted on flashLoan()\n * @param target The address of the flash loan receiver contract\n * @param initiator The address initiating the flash loan\n * @param asset The address of the asset being flash borrowed\n * @param amount The amount flash borrowed\n * @param premium The fee flash borrowed\n * @param referralCode The referral code used\n **/\n event FlashLoan(\n address indexed target,\n address indexed initiator,\n address indexed asset,\n uint256 amount,\n uint256 premium,\n uint16 referralCode\n );\n\n /**\n * @dev Emitted when the pause is triggered.\n */\n event Paused();\n\n /**\n * @dev Emitted when the pause is lifted.\n */\n event Unpaused();\n\n /**\n * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via\n * LendingPoolCollateral manager using a DELEGATECALL\n * This allows to have the events in the generated ABI for LendingPool.\n * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation\n * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation\n * @param user The address of the borrower getting liquidated\n * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover\n * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator\n * @param liquidator The address of the liquidator\n * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants\n * to receive the underlying collateral asset directly\n **/\n event LiquidationCall(\n address indexed collateralAsset,\n address indexed debtAsset,\n address indexed user,\n uint256 debtToCover,\n uint256 liquidatedCollateralAmount,\n address liquidator,\n bool receiveAToken\n );\n\n /**\n * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared\n * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal,\n * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it\n * gets added to the LendingPool ABI\n * @param reserve The address of the underlying asset of the reserve\n * @param liquidityRate The new liquidity rate\n * @param stableBorrowRate The new stable borrow rate\n * @param variableBorrowRate The new variable borrow rate\n * @param liquidityIndex The new liquidity index\n * @param variableBorrowIndex The new variable borrow index\n **/\n event ReserveDataUpdated(\n address indexed reserve,\n uint256 liquidityRate,\n uint256 stableBorrowRate,\n uint256 variableBorrowRate,\n uint256 liquidityIndex,\n uint256 variableBorrowIndex\n );\n\n /**\n * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.\n * - E.g. User deposits 100 USDC and gets in return 100 aUSDC\n * @param asset The address of the underlying asset to deposit\n * @param amount The amount to be deposited\n * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user\n * wants to receive them on his own wallet, or a different address if the beneficiary of aTokens\n * is a different wallet\n * @param referralCode Code used to register the integrator originating the operation, for potential rewards.\n * 0 if the action is executed directly by the user, without any middle-man\n **/\n function deposit(\n address asset,\n uint256 amount,\n address onBehalfOf,\n uint16 referralCode\n ) external;\n\n /**\n * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned\n * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC\n * @param asset The address of the underlying asset to withdraw\n * @param amount The underlying amount to be withdrawn\n * - Send the value type(uint256).max in order to withdraw the whole aToken balance\n * @param to Address that will receive the underlying, same as msg.sender if the user\n * wants to receive it on his own wallet, or a different address if the beneficiary is a\n * different wallet\n * @return The final amount withdrawn\n **/\n function withdraw(\n address asset,\n uint256 amount,\n address to\n ) external returns (uint256);\n\n /**\n * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower\n * already deposited enough collateral, or he was given enough allowance by a credit delegator on the\n * corresponding debt token (StableDebtToken or VariableDebtToken)\n * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet\n * and 100 stable/variable debt tokens, depending on the `interestRateMode`\n * @param asset The address of the underlying asset to borrow\n * @param amount The amount to be borrowed\n * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable\n * @param referralCode Code used to register the integrator originating the operation, for potential rewards.\n * 0 if the action is executed directly by the user, without any middle-man\n * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself\n * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator\n * if he has been given credit delegation allowance\n **/\n function borrow(\n address asset,\n uint256 amount,\n uint256 interestRateMode,\n uint16 referralCode,\n address onBehalfOf\n ) external;\n\n /**\n * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned\n * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address\n * @param asset The address of the borrowed underlying asset previously borrowed\n * @param amount The amount to repay\n * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`\n * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable\n * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the\n * user calling the function if he wants to reduce/remove his own debt, or the address of any other\n * other borrower whose debt should be removed\n * @return The final amount repaid\n **/\n function repay(\n address asset,\n uint256 amount,\n uint256 rateMode,\n address onBehalfOf\n ) external returns (uint256);\n\n /**\n * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa\n * @param asset The address of the underlying asset borrowed\n * @param rateMode The rate mode that the user wants to swap to\n **/\n function swapBorrowRateMode(address asset, uint256 rateMode) external;\n\n /**\n * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve.\n * - Users can be rebalanced if the following conditions are satisfied:\n * 1. Usage ratio is above 95%\n * 2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been\n * borrowed at a stable rate and depositors are not earning enough\n * @param asset The address of the underlying asset borrowed\n * @param user The address of the user to be rebalanced\n **/\n function rebalanceStableBorrowRate(address asset, address user) external;\n\n /**\n * @dev Allows depositors to enable/disable a specific deposited asset as collateral\n * @param asset The address of the underlying asset deposited\n * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise\n **/\n function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external;\n\n /**\n * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1\n * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives\n * a proportionally amount of the `collateralAsset` plus a bonus to cover market risk\n * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation\n * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation\n * @param user The address of the borrower getting liquidated\n * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover\n * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants\n * to receive the underlying collateral asset directly\n **/\n function liquidationCall(\n address collateralAsset,\n address debtAsset,\n address user,\n uint256 debtToCover,\n bool receiveAToken\n ) external;\n\n /**\n * @dev Allows smartcontracts to access the liquidity of the pool within one transaction,\n * as long as the amount taken plus a fee is returned.\n * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration.\n * For further details please visit https://developers.aave.com\n * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface\n * @param assets The addresses of the assets being flash-borrowed\n * @param amounts The amounts amounts being flash-borrowed\n * @param modes Types of the debt to open if the flash loan is not returned:\n * 0 -> Don't open any debt, just revert if funds can't be transferred from the receiver\n * 1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address\n * 2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address\n * @param onBehalfOf The address that will receive the debt in the case of using on `modes` 1 or 2\n * @param params Variadic packed params to pass to the receiver as extra information\n * @param referralCode Code used to register the integrator originating the operation, for potential rewards.\n * 0 if the action is executed directly by the user, without any middle-man\n **/\n function flashLoan(\n address receiverAddress,\n address[] calldata assets,\n uint256[] calldata amounts,\n uint256[] calldata modes,\n address onBehalfOf,\n bytes calldata params,\n uint16 referralCode\n ) external;\n\n /**\n * @dev Returns the user account data across all the reserves\n * @param user The address of the user\n * @return totalCollateralETH the total collateral in ETH of the user\n * @return totalDebtETH the total debt in ETH of the user\n * @return availableBorrowsETH the borrowing power left of the user\n * @return currentLiquidationThreshold the liquidation threshold of the user\n * @return ltv the loan to value of the user\n * @return healthFactor the current health factor of the user\n **/\n function getUserAccountData(address user)\n external\n view\n returns (\n uint256 totalCollateralETH,\n uint256 totalDebtETH,\n uint256 availableBorrowsETH,\n uint256 currentLiquidationThreshold,\n uint256 ltv,\n uint256 healthFactor\n );\n\n function initReserve(\n address reserve,\n address aTokenAddress,\n address stableDebtAddress,\n address variableDebtAddress,\n address interestRateStrategyAddress\n ) external;\n\n function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress)\n external;\n\n function setConfiguration(address reserve, uint256 configuration) external;\n\n /**\n * @dev Returns the configuration of the reserve\n * @param asset The address of the underlying asset of the reserve\n * @return The configuration of the reserve\n **/\n function getConfiguration(address asset)\n external\n view\n returns (DataTypes.ReserveConfigurationMap memory);\n\n /**\n * @dev Returns the configuration of the user across all the reserves\n * @param user The user address\n * @return The configuration of the user\n **/\n function getUserConfiguration(address user)\n external\n view\n returns (DataTypes.UserConfigurationMap memory);\n\n /**\n * @dev Returns the normalized income normalized income of the reserve\n * @param asset The address of the underlying asset of the reserve\n * @return The reserve's normalized income\n */\n function getReserveNormalizedIncome(address asset) external view returns (uint256);\n\n /**\n * @dev Returns the normalized variable debt per unit of asset\n * @param asset The address of the underlying asset of the reserve\n * @return The reserve normalized variable debt\n */\n function getReserveNormalizedVariableDebt(address asset) external view returns (uint256);\n\n /**\n * @dev Returns the state and configuration of the reserve\n * @param asset The address of the underlying asset of the reserve\n * @return The state of the reserve\n **/\n function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);\n\n function finalizeTransfer(\n address asset,\n address from,\n address to,\n uint256 amount,\n uint256 balanceFromAfter,\n uint256 balanceToBefore\n ) external;\n\n function getReservesList() external view returns (address[] memory);\n\n function getAddressesProvider() external view returns (ILendingPoolAddressesProvider);\n\n function setPause(bool val) external;\n\n function paused() external view returns (bool);\n}\n"
},
"contracts/core/types/Aave.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later\npragma solidity ^0.8.15;\n\nstruct DepositData {\n address asset;\n uint256 amount;\n bool sumAmounts;\n bool setAsCollateral;\n}\n\nstruct BorrowData {\n address asset;\n uint256 amount;\n address to;\n}\n\nstruct WithdrawData {\n address asset;\n uint256 amount;\n address to;\n}\n\nstruct PaybackData {\n address asset;\n uint256 amount;\n bool paybackAll;\n}\n"
},
"contracts/libs/SafeMath.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.15;\n\nlibrary SafeMath {\n function add(uint256 a, uint256 b) internal pure returns (uint256) {\n uint256 c = a + b;\n require(c >= a, \"SafeMath: addition overflow\");\n\n return c;\n }\n\n function sub(uint256 a, uint256 b) internal pure returns (uint256) {\n return sub(a, b, \"SafeMath: subtraction overflow\");\n }\n\n function sub(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n require(b <= a, errorMessage);\n uint256 c = a - b;\n\n return c;\n }\n\n function mul(uint256 a, uint256 b) internal pure returns (uint256) {\n // Gas optimization: this is cheaper than requiring 'a' not being zero, but the\n // benefit is lost if 'b' is also tested.\n // See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522\n if (a == 0) {\n return 0;\n }\n\n uint256 c = a * b;\n require(c / a == b, \"SafeMath: multiplication overflow\");\n\n return c;\n }\n\n function div(uint256 a, uint256 b) internal pure returns (uint256) {\n return div(a, b, \"SafeMath: division by zero\");\n }\n\n function div(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n require(b > 0, errorMessage);\n uint256 c = a / b;\n // assert(a == b * c + a % b); // There is no case in which this doesn't hold\n\n return c;\n }\n\n function mod(uint256 a, uint256 b) internal pure returns (uint256) {\n return mod(a, b, \"SafeMath: modulo by zero\");\n }\n\n function mod(\n uint256 a,\n uint256 b,\n string memory errorMessage\n ) internal pure returns (uint256) {\n require(b != 0, errorMessage);\n return a % b;\n }\n}\n"
},
"contracts/libs/SafeERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.8.1;\n\nimport { IERC20 } from \"../interfaces/tokens/IERC20.sol\";\nimport { Address } from \"./Address.sol\";\nimport { SafeMath } from \"./SafeMath.sol\";\n\nlibrary SafeERC20 {\n using SafeMath for uint256;\n using Address for address;\n\n function safeTransfer(\n IERC20 token,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));\n }\n\n function safeTransferFrom(\n IERC20 token,\n address from,\n address to,\n uint256 value\n ) internal {\n _callOptionalReturn(\n token,\n abi.encodeWithSelector(token.transferFrom.selector, from, to, value)\n );\n }\n\n /**\n * @dev Deprecated. This function has issues similar to the ones found in\n * {ERC20-approve}, and its usage is discouraged.\n */\n function safeApprove(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));\n _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));\n }\n\n function safeIncreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender).add(value);\n _callOptionalReturn(\n token,\n abi.encodeWithSelector(token.approve.selector, spender, newAllowance)\n );\n }\n\n function safeDecreaseAllowance(\n IERC20 token,\n address spender,\n uint256 value\n ) internal {\n uint256 newAllowance = token.allowance(address(this), spender).sub(\n value,\n \"SafeERC20: decreased allowance below zero\"\n );\n _callOptionalReturn(\n token,\n abi.encodeWithSelector(token.approve.selector, spender, newAllowance)\n );\n }\n\n function _callOptionalReturn(IERC20 token, bytes memory data) private {\n bytes memory returndata = address(token).functionCall(data, \"SafeERC20: low-level call failed\");\n if (returndata.length > 0) {\n // Return data is optional\n // solhint-disable-next-line max-line-length\n require(abi.decode(returndata, (bool)), \"SafeERC20: ERC20 operation did not succeed\");\n }\n }\n}\n"
},
"contracts/core/constants/Aave.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later\npragma solidity ^0.8.15;\n\nstring constant AAVE_LENDING_POOL = \"AaveLendingPool\";\nstring constant AAVE_WETH_GATEWAY = \"AaveWethGateway\";\n\n/**\n * @dev We do not include patch versions in contract names to allow\n * for hotfixes of Action contracts\n * and to limit updates to TheGraph\n * if the types encoded in emitted events change then use a minor version and\n * update the ServiceRegistry with a new entry\n * and update TheGraph decoding accordingly\n */\nstring constant BORROW_ACTION = \"AaveBorrow_2\";\nstring constant DEPOSIT_ACTION = \"AaveDeposit_2\";\nstring constant WITHDRAW_ACTION = \"AaveWithdraw_2\";\nstring constant PAYBACK_ACTION = \"AavePayback_2\";\n"
},
"contracts/core/ServiceRegistry.sol": {
"content": "//SPDX-License-Identifier: Unlicense\npragma solidity >=0.8.1;\n\n/**\n * @title Service Registry\n * @notice Stores addresses of deployed contracts\n */\ncontract ServiceRegistry {\n uint256 public constant MAX_DELAY = 30 days;\n\n mapping(bytes32 => uint256) public lastExecuted;\n mapping(bytes32 => address) private namedService;\n address public owner;\n uint256 public requiredDelay;\n\n modifier validateInput(uint256 len) {\n require(msg.data.length == len, \"registry/illegal-padding\");\n _;\n }\n\n modifier delayedExecution() {\n bytes32 operationHash = keccak256(msg.data);\n uint256 reqDelay = requiredDelay;\n\n /* solhint-disable not-rely-on-time */\n if (lastExecuted[operationHash] == 0 && reqDelay > 0) {\n // not called before, scheduled for execution\n lastExecuted[operationHash] = block.timestamp;\n emit ChangeScheduled(operationHash, block.timestamp + reqDelay, msg.data);\n } else {\n require(block.timestamp - reqDelay > lastExecuted[operationHash], \"registry/delay-too-small\");\n emit ChangeApplied(operationHash, block.timestamp, msg.data);\n _;\n lastExecuted[operationHash] = 0;\n }\n /* solhint-enable not-rely-on-time */\n }\n\n modifier onlyOwner() {\n require(msg.sender == owner, \"registry/only-owner\");\n _;\n }\n\n constructor(uint256 initialDelay) {\n require(initialDelay <= MAX_DELAY, \"registry/invalid-delay\");\n requiredDelay = initialDelay;\n owner = msg.sender;\n }\n\n /**\n * @param newOwner Transfers ownership of the registry to a new address\n */\n function transferOwnership(address newOwner)\n external\n onlyOwner\n validateInput(36)\n delayedExecution\n {\n owner = newOwner;\n }\n\n /**\n * @param newDelay Updates the required delay before an change can be confirmed with a follow up t/x\n */\n function changeRequiredDelay(uint256 newDelay)\n external\n onlyOwner\n validateInput(36)\n delayedExecution\n {\n require(newDelay <= MAX_DELAY, \"registry/invalid-delay\");\n requiredDelay = newDelay;\n }\n\n /**\n * @param name Hashes the supplied name\n * @return Returns the hash of the name\n */\n function getServiceNameHash(string memory name) external pure returns (bytes32) {\n return keccak256(abi.encodePacked(name));\n }\n\n /**\n * @param serviceNameHash The hashed name\n * @param serviceAddress The address stored for a given name\n */\n function addNamedService(bytes32 serviceNameHash, address serviceAddress)\n external\n onlyOwner\n validateInput(68)\n delayedExecution\n {\n require(namedService[serviceNameHash] == address(0), \"registry/service-override\");\n namedService[serviceNameHash] = serviceAddress;\n }\n\n /**\n * @param serviceNameHash The hashed name\n * @param serviceAddress The address to update for a given name\n */\n function updateNamedService(bytes32 serviceNameHash, address serviceAddress)\n external\n onlyOwner\n validateInput(68)\n delayedExecution\n {\n require(namedService[serviceNameHash] != address(0), \"registry/service-does-not-exist\");\n namedService[serviceNameHash] = serviceAddress;\n }\n\n /**\n * @param serviceNameHash The hashed service name to remove\n */\n function removeNamedService(bytes32 serviceNameHash) external onlyOwner validateInput(36) {\n require(namedService[serviceNameHash] != address(0), \"registry/service-does-not-exist\");\n namedService[serviceNameHash] = address(0);\n emit NamedServiceRemoved(serviceNameHash);\n }\n\n /**\n * @param serviceName Get a service address by its name\n */\n function getRegisteredService(string memory serviceName) external view returns (address) {\n return namedService[keccak256(abi.encodePacked(serviceName))];\n }\n\n /**\n * @param serviceNameHash Get a service address by the hash of its name\n */\n function getServiceAddress(bytes32 serviceNameHash) external view returns (address) {\n return namedService[serviceNameHash];\n }\n\n /**\n * @dev Voids any submitted changes that are yet to be confirmed by a follow-up transaction\n * @param scheduledExecution Clear any scheduled changes\n */\n function clearScheduledExecution(bytes32 scheduledExecution)\n external\n onlyOwner\n validateInput(36)\n {\n require(lastExecuted[scheduledExecution] > 0, \"registry/execution-not-scheduled\");\n lastExecuted[scheduledExecution] = 0;\n emit ChangeCancelled(scheduledExecution);\n }\n\n event ChangeScheduled(bytes32 dataHash, uint256 scheduledFor, bytes data);\n event ChangeApplied(bytes32 dataHash, uint256 appliedAt, bytes data);\n event ChangeCancelled(bytes32 dataHash);\n event NamedServiceRemoved(bytes32 nameHash);\n}\n"
},
"contracts/core/constants/Common.sol": {
"content": "// SPDX-License-Identifier: AGPL-3.0-or-later\npragma solidity ^0.8.15;\n\nstring constant OPERATION_STORAGE = \"OperationStorage_2\";\nstring constant OPERATION_EXECUTOR = \"OperationExecutor_2\";\nstring constant OPERATIONS_REGISTRY = \"OperationsRegistry_2\";\nstring constant ONE_INCH_AGGREGATOR = \"OneInchAggregator\";\nstring constant WETH = \"WETH\";\nstring constant DAI = \"DAI\";\nuint256 constant RAY = 10**27;\nbytes32 constant NULL = \"\";\n\n/**\n * @dev We do not include patch versions in contract names to allow\n * for hotfixes of Action contracts\n * and to limit updates to TheGraph\n * if the types encoded in emitted events change then use a minor version and\n * update the ServiceRegistry with a new entry\n * and update TheGraph decoding accordingly\n */\nstring constant PULL_TOKEN_ACTION = \"PullToken_2\";\nstring constant SEND_TOKEN_ACTION = \"SendToken_2\";\nstring constant SET_APPROVAL_ACTION = \"SetApproval_2\";\nstring constant TAKE_FLASH_LOAN_ACTION = \"TakeFlashloan_2\";\nstring constant WRAP_ETH = \"WrapEth_2\";\nstring constant UNWRAP_ETH = \"UnwrapEth_2\";\nstring constant RETURN_FUNDS_ACTION = \"ReturnFunds_2\";\n\nstring constant UNISWAP_ROUTER = \"UniswapRouter\";\nstring constant SWAP = \"Swap\";\n\naddress constant ETH = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;\n"
},
"contracts/interfaces/aave/ILendingPoolAddressesProvider.sol": {
"content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity ^0.8.15;\n\n/**\n * @title LendingPoolAddressesProvider contract\n * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles\n * - Acting also as factory of proxies and admin of those, so with right to change its implementations\n * - Owned by the Aave Governance\n * @author Aave\n **/\ninterface ILendingPoolAddressesProvider {\n event MarketIdSet(string newMarketId);\n event LendingPoolUpdated(address indexed newAddress);\n event ConfigurationAdminUpdated(address indexed newAddress);\n event EmergencyAdminUpdated(address indexed newAddress);\n event LendingPoolConfiguratorUpdated(address indexed newAddress);\n event LendingPoolCollateralManagerUpdated(address indexed newAddress);\n event PriceOracleUpdated(address indexed newAddress);\n event LendingRateOracleUpdated(address indexed newAddress);\n event ProxyCreated(bytes32 id, address indexed newAddress);\n event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy);\n\n function getMarketId() external view returns (string memory);\n\n function setMarketId(string calldata marketId) external;\n\n function setAddress(bytes32 id, address newAddress) external;\n\n function setAddressAsProxy(bytes32 id, address impl) external;\n\n function getAddress(bytes32 id) external view returns (address);\n\n function getLendingPool() external view returns (address);\n\n function setLendingPoolImpl(address pool) external;\n\n function getLendingPoolConfigurator() external view returns (address);\n\n function setLendingPoolConfiguratorImpl(address configurator) external;\n\n function getLendingPoolCollateralManager() external view returns (address);\n\n function setLendingPoolCollateralManager(address manager) external;\n\n function getPoolAdmin() external view returns (address);\n\n function setPoolAdmin(address admin) external;\n\n function getEmergencyAdmin() external view returns (address);\n\n function setEmergencyAdmin(address admin) external;\n\n function getPriceOracle() external view returns (address);\n\n function setPriceOracle(address priceOracle) external;\n\n function getLendingRateOracle() external view returns (address);\n\n function setLendingRateOracle(address lendingRateOracle) external;\n}\n"
},
"contracts/interfaces/aave/DataTypes.sol": {
"content": "// SPDX-License-Identifier: agpl-3.0\npragma solidity ^0.8.15;\n\nlibrary DataTypes {\n // refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties.\n struct ReserveData {\n //stores the reserve configuration\n ReserveConfigurationMap configuration;\n //the liquidity index. Expressed in ray\n uint128 liquidityIndex;\n //variable borrow index. Expressed in ray\n uint128 variableBorrowIndex;\n //the current supply rate. Expressed in ray\n uint128 currentLiquidityRate;\n //the current variable borrow rate. Expressed in ray\n uint128 currentVariableBorrowRate;\n //the current stable borrow rate. Expressed in ray\n uint128 currentStableBorrowRate;\n uint40 lastUpdateTimestamp;\n //tokens addresses\n address aTokenAddress;\n address stableDebtTokenAddress;\n address variableDebtTokenAddress;\n //address of the interest rate strategy\n address interestRateStrategyAddress;\n //the id of the reserve. Represents the position in the list of the active reserves\n uint8 id;\n }\n\n struct ReserveConfigurationMap {\n //bit 0-15: LTV\n //bit 16-31: Liq. threshold\n //bit 32-47: Liq. bonus\n //bit 48-55: Decimals\n //bit 56: Reserve is active\n //bit 57: reserve is frozen\n //bit 58: borrowing is enabled\n //bit 59: stable rate borrowing enabled\n //bit 60-63: reserved\n //bit 64-79: reserve factor\n uint256 data;\n }\n\n struct UserConfigurationMap {\n uint256 data;\n }\n\n enum InterestRateMode {\n NONE,\n STABLE,\n VARIABLE\n }\n}\n"
},
"contracts/interfaces/tokens/IERC20.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity ^0.8.15;\n\ninterface IERC20 {\n function totalSupply() external view returns (uint256 supply);\n\n function balanceOf(address _owner) external view returns (uint256 balance);\n\n function transfer(address _to, uint256 _value) external returns (bool success);\n\n function transferFrom(\n address _from,\n address _to,\n uint256 _value\n ) external returns (bool success);\n\n function approve(address _spender, uint256 _value) external returns (bool success);\n\n function allowance(address _owner, address _spender) external view returns (uint256 remaining);\n\n function decimals() external view returns (uint256 digits);\n}\n"
},
"contracts/libs/Address.sol": {
"content": "// SPDX-License-Identifier: MIT\n\npragma solidity >=0.8.1;\n\nlibrary Address {\n function isContract(address account) internal view returns (bool) {\n // According to EIP-1052, 0x0 is the value returned for not-yet created accounts\n // and 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470 is returned\n // for accounts without code, i.e. `keccak256('')`\n bytes32 codehash;\n bytes32 accountHash = 0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470;\n // solhint-disable-next-line no-inline-assembly\n assembly {\n codehash := extcodehash(account)\n }\n return (codehash != accountHash && codehash != 0x0);\n }\n\n function sendValue(address payable recipient, uint256 amount) internal {\n require(address(this).balance >= amount, \"Address: insufficient balance\");\n\n // solhint-disable-next-line avoid-low-level-calls, avoid-call-value\n (bool success, ) = recipient.call{ value: amount }(\"\");\n require(success, \"Address: unable to send value, recipient may have reverted\");\n }\n\n function functionCall(address target, bytes memory data) internal returns (bytes memory) {\n return functionCall(target, data, \"Address: low-level call failed\");\n }\n\n function functionCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n return _functionCallWithValue(target, data, 0, errorMessage);\n }\n\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value\n ) internal returns (bytes memory) {\n return functionCallWithValue(target, data, value, \"Address: low-level call with value failed\");\n }\n\n function functionCallWithValue(\n address target,\n bytes memory data,\n uint256 value,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(address(this).balance >= value, \"Address: insufficient balance for call\");\n return _functionCallWithValue(target, data, value, errorMessage);\n }\n\n function _functionCallWithValue(\n address target,\n bytes memory data,\n uint256 weiValue,\n string memory errorMessage\n ) private returns (bytes memory) {\n require(isContract(target), \"Address: call to non-contract\");\n\n (bool success, bytes memory returndata) = target.call{ value: weiValue }(data);\n if (success) {\n return returndata;\n } else {\n // Look for revert reason and bubble it up if present\n if (returndata.length > 0) {\n // The easiest way to bubble the revert reason is using memory via assembly\n\n // solhint-disable-next-line no-inline-assembly\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n } else {\n revert(errorMessage);\n }\n }\n }\n\n function functionDelegateCall(\n address target,\n bytes memory data,\n string memory errorMessage\n ) internal returns (bytes memory) {\n require(isContract(target), \"Address: delegate call to non-contract\");\n\n (bool success, bytes memory returndata) = target.delegatecall(data);\n if (success) {\n return returndata;\n }\n\n if (returndata.length > 0) {\n assembly {\n let returndata_size := mload(returndata)\n revert(add(32, returndata), returndata_size)\n }\n }\n\n revert(errorMessage);\n }\n}\n"
}
},
"settings": {
"optimizer": {
"enabled": false,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}
}