ETH Price: $2,926.98 (-0.88%)

Contract

0x73d883b30461201E982bfe0d8E9948a004537767

Overview

ETH Balance

0 ETH

ETH Value

$0.00

More Info

Private Name Tags

Multichain Info

No addresses found
Transaction Hash
Block
From
To

There are no matching entries

Please try again later

Parent Transaction Hash Block From To
View All Internal Transactions

Cross-Chain Transactions
Loading...
Loading

Similar Match Source Code
This contract matches the deployed Bytecode of the Source Code for Contract 0xCE4058b0...346dD1787
The constructor portion of the code might be different and could alter the actual behaviour of the contract

Contract Name:
RevenueManagement

Compiler Version
v0.8.12+commit.f00d7308

Optimization Enabled:
Yes with 1000 runs

Other Settings:
london EvmVersion

Contract Source Code (Solidity Standard Json-Input format)

// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.12;

import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { PausableUpgradeable } from "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import { ReentrancyGuardUpgradeable } from "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import { IERC20Metadata, IERC20 } from "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { RecoverERC20 } from "@radiant-v2-core/radiant/libraries/RecoverERC20.sol";
import { WadRayMath } from "@radiant-v2-core/lending/libraries/math/WadRayMath.sol";
import { PercentageMath } from "@radiant-v2-core/lending/libraries/math/PercentageMath.sol";
import { IOracleRouter } from "./interfaces/IOracleRouter.sol";
import { ILendingPoolAddressesProvider } from "@radiant-v2-core/interfaces/ILendingPoolAddressesProvider.sol";
import { DexSwapStrategy } from "./libraries/swap-strategies/DexSwapStrategy.sol";
import { ILendingPool } from "@radiant-v2-core/interfaces/ILendingPool.sol";
import { IAToken } from "@radiant-v2-core/interfaces/IAToken.sol";
import { Errors } from "./libraries/Errors.sol";

/// @title RevenueManagement contract
/// @author Radiant
/// @custom:security-contact [email protected]
contract RevenueManagement is OwnableUpgradeable, PausableUpgradeable, ReentrancyGuardUpgradeable, RecoverERC20 {
    using SafeERC20 for IERC20;
    using WadRayMath for uint256;
    using PercentageMath for uint256;

    //////////////// <*_*> Storage <*_*> ////////////////
    /// @notice MiddleFeeDistribution address (MultiFeeDistribution on mainnet)
    address public mfd;

    /// @notice Core markets lending pool
    address public coreLendingPool;

    /// @notice List of output tokens
    address[] public outputTokens;

    mapping(address => OutputTokenConfig) public outputTokenConfigs;
    mapping(address => IOracleRouter) public inputTokenOracle;
    mapping(address => bool) public isWhitelisted;
    mapping(address => bool) public approvedLendingPools;
    mapping(address => bool) public approvedSwapAddresses;

    //////////////// =^..^= Events =^..^= ////////////////
    event SetWhitelisted(address indexed account, bool isWhitelisted);
    event SetLendingPoolWhitelist(address indexed lendingPool, bool status);
    event SetApprovedSwapAddress(address indexed account, bool approved);
    event TokensAcquired(address indexed token, uint256 amount);
    event InputTokenAdded(address indexed token, IOracleRouter oracle);
    event InputTokenRemoved(address indexed token);
    event OutputTokensConfigUpdated(uint256 outputTokensLength);
    event MFDUpdated(address newMFD);
    event CoreLendingPoolUpdated(address newCoreLendingPool);

    //////////////// *-_-* Structs *-_-* ////////////////
    struct OutputTokenConfig {
        // 10000 = 100%
        uint256 maximumSlippage;
        // 10000 = 100%
        uint256 percentage;
        address priceOracle;
        IAToken rTokenCore;
    }

    struct SwapInput {
        uint256 amountIn;
        bytes data;
        address inputToken;
        uint256 minOutput;
        address outputToken;
        SwapStrategies swapStrategy;
    }

    enum SwapStrategies {
        NONE,
        AGGREGATOR
    }

    modifier onlyWhitelisted() {
        if (!isWhitelisted[msg.sender]) revert Errors.NotAuthorized();
        _;
    }

    constructor() {
        _disableInitializers();
    }

    /**
     * @notice Initializer
     * @param _mfd MiddleFeeDistribution address
     * @param _coreLendingPool Core lending pool address
     */
    function initialize(address _mfd, address _coreLendingPool) external initializer {
        if (_mfd == address(0)) revert Errors.AddressZero();
        if (_coreLendingPool == address(0)) revert Errors.AddressZero();

        mfd = _mfd;
        coreLendingPool = _coreLendingPool;

        __Ownable_init();
        __Pausable_init();
    }

    /**
     * @notice Recover ERC20 tokens from the contract.
     * @param tokenAddress Token address to recover
     * @param tokenAmount Amount to recover
     */
    function recoverERC20(address tokenAddress, uint256 tokenAmount) external onlyOwner {
        _recoverERC20(tokenAddress, tokenAmount);
    }

    /**
     * @notice Pause the contract
     */
    function pause() external onlyOwner {
        _pause();
    }

    /**
     * @notice Unpause the contract
     */
    function unpause() external onlyOwner {
        _unpause();
    }

    /**
     * @notice External methods to deposit tokens to the core lending pool then transfer to mfd
     * @dev Only owner can call this method
     * @param _token Address of the token to deposit
     * @param _amount Amount of the token to deposit
     */
    function depositToCoreLendingPool(address _token, uint256 _amount) external onlyOwner {
        _depositToCoreLendingPool(_token, _amount);
    }

    /**
     * @notice Set a new MiddleFeeDistribution address
     * @param _newMFD New MiddleFeeDistribution address
     */
    function setMFD(address _newMFD) external onlyOwner {
        if (_newMFD == address(0)) revert Errors.AddressZero();
        mfd = _newMFD;
        emit MFDUpdated(_newMFD);
    }

    /**
     * @notice Set a new core lending pool address
     * @param _newCoreLendingPool New core lending pool address
     */
    function setCoreLendingPool(address _newCoreLendingPool) external onlyOwner {
        if (_newCoreLendingPool == address(0)) revert Errors.AddressZero();
        coreLendingPool = _newCoreLendingPool;
        emit CoreLendingPoolUpdated(_newCoreLendingPool);
    }

    /**
     * @notice Set state for an address in whitelist
     * @param _account Address
     * @param _isWhitelisted Whitelisted state
     */
    function setWhitelist(address _account, bool _isWhitelisted) external onlyOwner {
        if (_account == address(0)) revert Errors.AddressZero();
        isWhitelisted[_account] = _isWhitelisted;
        emit SetWhitelisted(_account, _isWhitelisted);
    }

    /**
     * @notice Set state for an address in lending pool whitelist
     * @param lendingPool Address of the lending pool to whitelist
     * @param status Whitelist status
     */
    function setLendingPoolWhitelist(address lendingPool, bool status) external onlyOwner {
        if (lendingPool == address(0)) revert Errors.AddressZero();
        approvedLendingPools[lendingPool] = status;
        emit SetLendingPoolWhitelist(lendingPool, status);
    }

    /**
     * @notice Set state for an address in swap whitelist
     * @param _account Address
     * @param _approved Approved state
     */
    function setApprovedSwapAddress(address _account, bool _approved) external onlyOwner {
        if (_account == address(0)) revert Errors.AddressZero();
        approvedSwapAddresses[_account] = _approved;
        emit SetApprovedSwapAddress(_account, _approved);
    }

    /**
     * @notice Adds an input token
     * @param _inputToken Input token
     * @param _inputTokenOracle Input token configuration
     */
    function addInputToken(address _inputToken, IOracleRouter _inputTokenOracle) external onlyOwner {
        if (_inputToken == address(0)) revert Errors.AddressZero();
        if (address(_inputTokenOracle) == address(0)) revert Errors.AddressZero();
        inputTokenOracle[_inputToken] = _inputTokenOracle;
        emit InputTokenAdded(_inputToken, _inputTokenOracle);
    }

    /**
     * @notice Removes an input token
     * @param _inputToken Input token
     */
    function removeInputToken(address _inputToken) external onlyOwner {
        if (address(inputTokenOracle[_inputToken]) == address(0)) revert Errors.TokenNotPresent();
        delete inputTokenOracle[_inputToken];
        emit InputTokenRemoved(_inputToken);
    }

    /**
     * @notice Unwraps rTokens to the underlying tokens
     * @param _rTokens Addresses of the rTokens to unwrap
     * @param _amounts Amounts of the rTokens to unwrap
     */
    function unwrapRToken(IAToken[] calldata _rTokens, uint256[] calldata _amounts)
        external
        onlyWhitelisted
        nonReentrant
    {
        if (_rTokens.length != _amounts.length) revert Errors.InputTokenConfigLengthMismatch();

        for (uint256 i = 0; i < _rTokens.length; ++i) {
            address underlyingToken = _rTokens[i].UNDERLYING_ASSET_ADDRESS();
            uint256 amountToWithdraw = _amounts[i];

            address lendingPoolAddress = address(_rTokens[i].POOL());
            if (!approvedLendingPools[lendingPoolAddress]) revert Errors.InvalidLendingPool();

            ILendingPool lendingPool = ILendingPool(lendingPoolAddress);
            lendingPool.withdraw(underlyingToken, amountToWithdraw, address(this));
        }
    }

    /**
     * @notice Swap tokens
     * @param swapInput Swap input
     */
    function swapTokens(SwapInput[] calldata swapInput) external whenNotPaused onlyWhitelisted nonReentrant {
        // First compute the total value of the input tokens
        uint256 totalInputValue = computeInputValue(swapInput);

        // Get the initial balance of the output tokens so we can see the actual delta later
        uint256[] memory initialOutputTokenBalances = new uint256[](outputTokens.length);
        for (uint256 i = 0; i < outputTokens.length; ++i) {
            initialOutputTokenBalances[i] = IERC20(outputTokens[i]).balanceOf(address(this));
        }

        // Perform the swaps as instructed
        for (uint256 i = 0; i < swapInput.length; ++i) {
            if (swapInput[i].swapStrategy == SwapStrategies.AGGREGATOR) {
                DexSwapStrategy.swap(
                    swapInput[i].inputToken,
                    swapInput[i].amountIn,
                    swapInput[i].minOutput,
                    swapInput[i].data,
                    isApprovedSwapAddress
                );
            } else {
                revert Errors.InvalidSwapStrategy();
            }
        }

        // Finally verify that the output tokens are within the expected range
        for (uint256 i = 0; i < outputTokens.length; ++i) {
            OutputTokenConfig memory outputTokenConfig = outputTokenConfigs[outputTokens[i]];
            uint256 price = IOracleRouter(outputTokenConfig.priceOracle).getAssetPrice(outputTokens[i]);

            uint8 targetTokenDecimals = IERC20Metadata(outputTokens[i]).decimals();

            uint256 targetValue = totalInputValue.percentMul(outputTokenConfig.percentage);

            uint256 targetTokens = (targetValue * 10 ** targetTokenDecimals) / price;

            uint256 actualTokens = IERC20(outputTokens[i]).balanceOf(address(this)) - initialOutputTokenBalances[i];

            // Skip if no tokens were acquired
            if (actualTokens == 0) {
                continue;
            }

            emit TokensAcquired(outputTokens[i], actualTokens);

            uint256 maximumSlippage = outputTokenConfig.maximumSlippage;

            if (
                !(
                    actualTokens >= targetTokens.percentMul(10_000 - maximumSlippage)
                        && actualTokens <= targetTokens.percentMul(10_000 + maximumSlippage)
                )
            ) {
                revert Errors.OutputTokenBalanceOutOfRange();
            }

            _depositToCoreLendingPool(outputTokens[i], actualTokens);
        }
    }

    /**
     * @notice Set output tokens configuration
     * @param _outputTokens Output tokens
     * @param _configs Output token configurations
     */
    function setOutputTokensConfig(address[] calldata _outputTokens, OutputTokenConfig[] calldata _configs)
        public
        onlyOwner
    {
        if (_outputTokens.length != _configs.length) {
            revert Errors.OutputTokenConfigLengthMismatch();
        }

        // Check there are no duplicates in the output tokens
        for (uint256 i = 0; i < _outputTokens.length; ++i) {
            for (uint256 j = i + 1; j < _outputTokens.length; ++j) {
                if (_outputTokens[i] == _outputTokens[j]) {
                    revert Errors.DuplicateOutputToken();
                }
            }
        }

        delete outputTokens;

        uint256 sumCheck;
        for (uint256 i = 0; i < _configs.length; ++i) {
            outputTokens.push(_outputTokens[i]);
            outputTokenConfigs[_outputTokens[i]] = _configs[i];
            sumCheck += _configs[i].percentage;
        }

        if (sumCheck != 10_000) {
            revert Errors.PercentageMismatch();
        }

        emit OutputTokensConfigUpdated(_outputTokens.length);
    }

    /**
     * @notice Check if an input token is configured
     * @param _inputToken Address of the token to check
     */
    function isInputTokenValid(address _inputToken) public view returns (bool) {
        return address(inputTokenOracle[_inputToken]) != address(0);
    }

    /**
     * @notice Check if an address is approved for swaps
     * @param _address Address to check
     */
    function isApprovedSwapAddress(address _address) public view returns (bool) {
        return approvedSwapAddresses[_address];
    }

    /**
     * @notice Computes the total value of the input tokens
     * @param swapInput Swap input
     */
    function computeInputValue(SwapInput[] calldata swapInput) public view returns (uint256) {
        uint256 totalInputValue = 0;
        for (uint256 i = 0; i < swapInput.length; ++i) {
            uint256 price = inputTokenOracle[swapInput[i].inputToken].getAssetPrice(swapInput[i].inputToken);

            uint256 tokenDecimals = IERC20Metadata(swapInput[i].inputToken).decimals();

            uint256 assetValue = (price * swapInput[i].amountIn) / (10 ** tokenDecimals);

            totalInputValue += assetValue;
        }
        return totalInputValue;
    }

    /**
     * @notice Deposit tokens to the core lending pool then transfer to mfd
     * @param _token Address of the token to deposit
     * @param _amount Amount of the token to deposit
     */
    function _depositToCoreLendingPool(address _token, uint256 _amount) internal {
        ILendingPool lendingPool = ILendingPool(coreLendingPool);
        IERC20(_token).approve(coreLendingPool, _amount);
        lendingPool.deposit(_token, _amount, address(this), 0);
        IERC20(outputTokenConfigs[_token].rTokenCore).safeTransfer(mfd, _amount);
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which provides a basic access control mechanism, where
 * there is an account (an owner) that can be granted exclusive access to
 * specific functions.
 *
 * By default, the owner account will be the one that deploys the contract. This
 * can later be changed with {transferOwnership}.
 *
 * This module is used through inheritance. It will make available the modifier
 * `onlyOwner`, which can be applied to your functions to restrict their use to
 * the owner.
 */
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
    address private _owner;

    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    /**
     * @dev Initializes the contract setting the deployer as the initial owner.
     */
    function __Ownable_init() internal onlyInitializing {
        __Ownable_init_unchained();
    }

    function __Ownable_init_unchained() internal onlyInitializing {
        _transferOwnership(_msgSender());
    }

    /**
     * @dev Throws if called by any account other than the owner.
     */
    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    /**
     * @dev Returns the address of the current owner.
     */
    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby disabling any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Can only be called by the current owner.
     */
    function transferOwnership(address newOwner) public virtual onlyOwner {
        require(newOwner != address(0), "Ownable: new owner is the zero address");
        _transferOwnership(newOwner);
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)

pragma solidity ^0.8.0;

import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module which allows children to implement an emergency stop
 * mechanism that can be triggered by an authorized account.
 *
 * This module is used through inheritance. It will make available the
 * modifiers `whenNotPaused` and `whenPaused`, which can be applied to
 * the functions of your contract. Note that they will not be pausable by
 * simply including this module, only once the modifiers are put in place.
 */
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
    /**
     * @dev Emitted when the pause is triggered by `account`.
     */
    event Paused(address account);

    /**
     * @dev Emitted when the pause is lifted by `account`.
     */
    event Unpaused(address account);

    bool private _paused;

    /**
     * @dev Initializes the contract in unpaused state.
     */
    function __Pausable_init() internal onlyInitializing {
        __Pausable_init_unchained();
    }

    function __Pausable_init_unchained() internal onlyInitializing {
        _paused = false;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is not paused.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    modifier whenNotPaused() {
        _requireNotPaused();
        _;
    }

    /**
     * @dev Modifier to make a function callable only when the contract is paused.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    modifier whenPaused() {
        _requirePaused();
        _;
    }

    /**
     * @dev Returns true if the contract is paused, and false otherwise.
     */
    function paused() public view virtual returns (bool) {
        return _paused;
    }

    /**
     * @dev Throws if the contract is paused.
     */
    function _requireNotPaused() internal view virtual {
        require(!paused(), "Pausable: paused");
    }

    /**
     * @dev Throws if the contract is not paused.
     */
    function _requirePaused() internal view virtual {
        require(paused(), "Pausable: not paused");
    }

    /**
     * @dev Triggers stopped state.
     *
     * Requirements:
     *
     * - The contract must not be paused.
     */
    function _pause() internal virtual whenNotPaused {
        _paused = true;
        emit Paused(_msgSender());
    }

    /**
     * @dev Returns to normal state.
     *
     * Requirements:
     *
     * - The contract must be paused.
     */
    function _unpause() internal virtual whenPaused {
        _paused = false;
        emit Unpaused(_msgSender());
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Contract module that helps prevent reentrant calls to a function.
 *
 * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
 * available, which can be applied to functions to make sure there are no nested
 * (reentrant) calls to them.
 *
 * Note that because there is a single `nonReentrant` guard, functions marked as
 * `nonReentrant` may not call one another. This can be worked around by making
 * those functions `private`, and then adding `external` `nonReentrant` entry
 * points to them.
 *
 * TIP: If you would like to learn more about reentrancy and alternative ways
 * to protect against it, check out our blog post
 * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
 */
abstract contract ReentrancyGuardUpgradeable is Initializable {
    // Booleans are more expensive than uint256 or any type that takes up a full
    // word because each write operation emits an extra SLOAD to first read the
    // slot's contents, replace the bits taken up by the boolean, and then write
    // back. This is the compiler's defense against contract upgrades and
    // pointer aliasing, and it cannot be disabled.

    // The values being non-zero value makes deployment a bit more expensive,
    // but in exchange the refund on every call to nonReentrant will be lower in
    // amount. Since refunds are capped to a percentage of the total
    // transaction's gas, it is best to keep them low in cases like this one, to
    // increase the likelihood of the full refund coming into effect.
    uint256 private constant _NOT_ENTERED = 1;
    uint256 private constant _ENTERED = 2;

    uint256 private _status;

    function __ReentrancyGuard_init() internal onlyInitializing {
        __ReentrancyGuard_init_unchained();
    }

    function __ReentrancyGuard_init_unchained() internal onlyInitializing {
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Prevents a contract from calling itself, directly or indirectly.
     * Calling a `nonReentrant` function from another `nonReentrant`
     * function is not supported. It is possible to prevent this from happening
     * by making the `nonReentrant` function external, and making it call a
     * `private` function that does the actual work.
     */
    modifier nonReentrant() {
        _nonReentrantBefore();
        _;
        _nonReentrantAfter();
    }

    function _nonReentrantBefore() private {
        // On the first call to nonReentrant, _status will be _NOT_ENTERED
        require(_status != _ENTERED, "ReentrancyGuard: reentrant call");

        // Any calls to nonReentrant after this point will fail
        _status = _ENTERED;
    }

    function _nonReentrantAfter() private {
        // By storing the original value once again, a refund is triggered (see
        // https://eips.ethereum.org/EIPS/eip-2200)
        _status = _NOT_ENTERED;
    }

    /**
     * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
     * `nonReentrant` function in the call stack.
     */
    function _reentrancyGuardEntered() internal view returns (bool) {
        return _status == _ENTERED;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[49] private __gap;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";

/**
 * @dev Interface for the optional metadata functions from the ERC20 standard.
 *
 * _Available since v4.1._
 */
interface IERC20Metadata is IERC20 {
    /**
     * @dev Returns the name of the token.
     */
    function name() external view returns (string memory);

    /**
     * @dev Returns the symbol of the token.
     */
    function symbol() external view returns (string memory);

    /**
     * @dev Returns the decimals places of the token.
     */
    function decimals() external view returns (uint8);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/utils/SafeERC20.sol)

pragma solidity ^0.8.0;

import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";

/**
 * @title SafeERC20
 * @dev Wrappers around ERC20 operations that throw on failure (when the token
 * contract returns false). Tokens that return no value (and instead revert or
 * throw on failure) are also supported, non-reverting calls are assumed to be
 * successful.
 * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
 * which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
 */
library SafeERC20 {
    using Address for address;

    /**
     * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeTransfer(IERC20 token, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
    }

    /**
     * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
     * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
     */
    function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
        _callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
    }

    /**
     * @dev Deprecated. This function has issues similar to the ones found in
     * {IERC20-approve}, and its usage is discouraged.
     *
     * Whenever possible, use {safeIncreaseAllowance} and
     * {safeDecreaseAllowance} instead.
     */
    function safeApprove(IERC20 token, address spender, uint256 value) internal {
        // safeApprove should only be called when setting an initial allowance,
        // or when resetting it to zero. To increase and decrease it, use
        // 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
        require(
            (value == 0) || (token.allowance(address(this), spender) == 0),
            "SafeERC20: approve from non-zero to non-zero allowance"
        );
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
    }

    /**
     * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        uint256 oldAllowance = token.allowance(address(this), spender);
        _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
    }

    /**
     * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful.
     */
    function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
        unchecked {
            uint256 oldAllowance = token.allowance(address(this), spender);
            require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
        }
    }

    /**
     * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
     * non-reverting calls are assumed to be successful. Compatible with tokens that require the approval to be set to
     * 0 before setting it to a non-zero value.
     */
    function forceApprove(IERC20 token, address spender, uint256 value) internal {
        bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);

        if (!_callOptionalReturnBool(token, approvalCall)) {
            _callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
            _callOptionalReturn(token, approvalCall);
        }
    }

    /**
     * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
     * Revert on invalid signature.
     */
    function safePermit(
        IERC20Permit token,
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) internal {
        uint256 nonceBefore = token.nonces(owner);
        token.permit(owner, spender, value, deadline, v, r, s);
        uint256 nonceAfter = token.nonces(owner);
        require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     */
    function _callOptionalReturn(IERC20 token, bytes memory data) private {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
        // the target address contains contract code and also asserts for success in the low-level call.

        bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
        require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
    }

    /**
     * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
     * on the return value: the return value is optional (but if data is returned, it must not be false).
     * @param token The token targeted by the call.
     * @param data The call data (encoded using abi.encode or one of its variants).
     *
     * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
     */
    function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
        // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
        // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
        // and not revert is the subcall reverts.

        (bool success, bytes memory returndata) = address(token).call(data);
        return
            success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
    }
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;

import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";

/// @title RecoverERC20 contract
/// @author Radiant Devs
/// @dev All function calls are currently implemented without side effects
contract RecoverERC20 {
	using SafeERC20 for IERC20;

	/// @notice Emitted when ERC20 token is recovered
	event Recovered(address indexed token, uint256 amount);

	/**
	 * @notice Added to support recovering LP Rewards from other systems such as BAL to be distributed to holders
	 */
	function _recoverERC20(address tokenAddress, uint256 tokenAmount) internal {
		IERC20(tokenAddress).safeTransfer(msg.sender, tokenAmount);
		emit Recovered(tokenAddress, tokenAmount);
	}
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.12;

import {Errors} from "../helpers/Errors.sol";

/**
 * @title WadRayMath library
 * @author Aave
 * @dev Provides mul and div function for wads (decimal numbers with 18 digits precision) and rays (decimals with 27 digits)
 **/

library WadRayMath {
	uint256 internal constant WAD = 1e18;
	uint256 internal constant halfWAD = WAD / 2;

	uint256 internal constant RAY = 1e27;
	uint256 internal constant halfRAY = RAY / 2;

	uint256 internal constant WAD_RAY_RATIO = 1e9;

	/**
	 * @return One ray, 1e27
	 **/
	function ray() internal pure returns (uint256) {
		return RAY;
	}

	/**
	 * @return One wad, 1e18
	 **/

	function wad() internal pure returns (uint256) {
		return WAD;
	}

	/**
	 * @return Half ray, 1e27/2
	 **/
	function halfRay() internal pure returns (uint256) {
		return halfRAY;
	}

	/**
	 * @return Half ray, 1e18/2
	 **/
	function halfWad() internal pure returns (uint256) {
		return halfWAD;
	}

	/**
	 * @dev Multiplies two wad, rounding half up to the nearest wad
	 * @param a Wad
	 * @param b Wad
	 * @return The result of a*b, in wad
	 **/
	function wadMul(uint256 a, uint256 b) internal pure returns (uint256) {
		if (a == 0 || b == 0) {
			return 0;
		}

		require(a <= (type(uint256).max - halfWAD) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);

		return (a * b + halfWAD) / WAD;
	}

	/**
	 * @dev Divides two wad, rounding half up to the nearest wad
	 * @param a Wad
	 * @param b Wad
	 * @return The result of a/b, in wad
	 **/
	function wadDiv(uint256 a, uint256 b) internal pure returns (uint256) {
		require(b != 0, Errors.MATH_DIVISION_BY_ZERO);
		uint256 halfB = b / 2;

		require(a <= (type(uint256).max - halfB) / WAD, Errors.MATH_MULTIPLICATION_OVERFLOW);

		return (a * WAD + halfB) / b;
	}

	/**
	 * @dev Multiplies two ray, rounding half up to the nearest ray
	 * @param a Ray
	 * @param b Ray
	 * @return The result of a*b, in ray
	 **/
	function rayMul(uint256 a, uint256 b) internal pure returns (uint256) {
		if (a == 0 || b == 0) {
			return 0;
		}

		require(a <= (type(uint256).max - halfRAY) / b, Errors.MATH_MULTIPLICATION_OVERFLOW);

		return (a * b + halfRAY) / RAY;
	}

	/**
	 * @dev Divides two ray, rounding half up to the nearest ray
	 * @param a Ray
	 * @param b Ray
	 * @return The result of a/b, in ray
	 **/
	function rayDiv(uint256 a, uint256 b) internal pure returns (uint256) {
		require(b != 0, Errors.MATH_DIVISION_BY_ZERO);
		uint256 halfB = b / 2;

		require(a <= (type(uint256).max - halfB) / RAY, Errors.MATH_MULTIPLICATION_OVERFLOW);

		return (a * RAY + halfB) / b;
	}

	/**
	 * @dev Casts ray down to wad
	 * @param a Ray
	 * @return a casted to wad, rounded half up to the nearest wad
	 **/
	function rayToWad(uint256 a) internal pure returns (uint256) {
		uint256 halfRatio = WAD_RAY_RATIO / 2;
		uint256 result = halfRatio + a;
		require(result >= halfRatio, Errors.MATH_ADDITION_OVERFLOW);

		return result / WAD_RAY_RATIO;
	}

	/**
	 * @dev Converts wad up to ray
	 * @param a Wad
	 * @return a converted in ray
	 **/
	function wadToRay(uint256 a) internal pure returns (uint256) {
		uint256 result = a * WAD_RAY_RATIO;
		require(result / WAD_RAY_RATIO == a, Errors.MATH_MULTIPLICATION_OVERFLOW);
		return result;
	}
}

// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.12;

import {Errors} from "../helpers/Errors.sol";

/**
 * @title PercentageMath library
 * @author Aave
 * @notice Provides functions to perform percentage calculations
 * @dev Percentages are defined by default with 2 decimals of precision (100.00). The precision is indicated by PERCENTAGE_FACTOR
 * @dev Operations are rounded half up
 **/

library PercentageMath {
	uint256 constant PERCENTAGE_FACTOR = 1e4; //percentage plus two decimals
	uint256 constant HALF_PERCENT = PERCENTAGE_FACTOR / 2;

	/**
	 * @dev Executes a percentage multiplication
	 * @param value The value of which the percentage needs to be calculated
	 * @param percentage The percentage of the value to be calculated
	 * @return The percentage of value
	 **/
	function percentMul(uint256 value, uint256 percentage) internal pure returns (uint256) {
		if (value == 0 || percentage == 0) {
			return 0;
		}

		require(value <= (type(uint256).max - HALF_PERCENT) / percentage, Errors.MATH_MULTIPLICATION_OVERFLOW);

		return (value * percentage + HALF_PERCENT) / PERCENTAGE_FACTOR;
	}

	/**
	 * @dev Executes a percentage division
	 * @param value The value of which the percentage needs to be calculated
	 * @param percentage The percentage of the value to be calculated
	 * @return The value divided the percentage
	 **/
	function percentDiv(uint256 value, uint256 percentage) internal pure returns (uint256) {
		require(percentage != 0, Errors.MATH_DIVISION_BY_ZERO);
		uint256 halfPercentage = percentage / 2;

		require(value <= (type(uint256).max - halfPercentage) / PERCENTAGE_FACTOR, Errors.MATH_MULTIPLICATION_OVERFLOW);

		return (value * PERCENTAGE_FACTOR + halfPercentage) / percentage;
	}
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;

import "@radiant-v2-core/interfaces/IPriceOracleGetter.sol";

interface IOracleRouter is IPriceOracleGetter {
    enum OracleProviderType {
        Chainlink,
        Pyth
    }
    /**
     * @notice Get the underlying price of a kToken asset
     * @param asset to get the underlying price of
     * @return The underlying asset price
     *  Zero means the price is unavailable.
     */

    /// @notice Gets a list of prices from a list of assets addresses
    /// @param assets The list of assets addresses
    function getAssetsPrices(address[] calldata assets) external view returns (uint256[] memory);

    /// @notice Gets the address of the source for an asset address
    /// @param asset The address of the asset
    /// @return address The address of the source, bytes32 The id of the source
    function getSourceOfAsset(address asset) external view returns (address, bytes32);

    /// @notice Set the source of an asset
    /// @param _asset The address of the asset
    /// @param _feedAddress The address of the feed
    /// @param _feedId The id of the feed
    /// @param _heartbeat The heartbeat of the feed
    /// @param _oracleType The type of the oracle
    /// @param isFallback True if the feed is a fallback
    function setAssetSource(
        address _asset,
        address _feedAddress,
        bytes32 _feedId,
        uint256 _heartbeat,
        OracleProviderType _oracleType,
        bool isFallback
    ) external;

    /**
     * @notice Updates multiple price feeds on Pyth oracle
     * @param priceUpdateData received from Pyth network and used to update the oracle
     */
    function updateUnderlyingPrices(bytes[] calldata priceUpdateData) external payable;
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.12;

/**
 * @title LendingPoolAddressesProvider contract
 * @dev Main registry of addresses part of or connected to the protocol, including permissioned roles
 * - Acting also as factory of proxies and admin of those, so with right to change its implementations
 * - Owned by the Aave Governance
 * @author Aave
 **/
interface ILendingPoolAddressesProvider {
	event MarketIdSet(string newMarketId);
	event LendingPoolUpdated(address indexed newAddress);
	event ConfigurationAdminUpdated(address indexed newAddress);
	event EmergencyAdminUpdated(address indexed newAddress);
	event LendingPoolConfiguratorUpdated(address indexed newAddress);
	event LendingPoolCollateralManagerUpdated(address indexed newAddress);
	event PriceOracleUpdated(address indexed newAddress);
	event LendingRateOracleUpdated(address indexed newAddress);
	event ProxyCreated(bytes32 id, address indexed newAddress);
	event AddressSet(bytes32 id, address indexed newAddress, bool hasProxy);

	function getMarketId() external view returns (string memory);

	function setMarketId(string calldata marketId) external;

	function setAddress(bytes32 id, address newAddress) external;

	function setAddressAsProxy(bytes32 id, address impl) external;

	function getAddress(bytes32 id) external view returns (address);

	function getLendingPool() external view returns (address);

	function setLendingPoolImpl(address pool) external;

	function getLendingPoolConfigurator() external view returns (address);

	function setLendingPoolConfiguratorImpl(address configurator) external;

	function getLendingPoolCollateralManager() external view returns (address);

	function setLendingPoolCollateralManager(address manager) external;

	function getPoolAdmin() external view returns (address);

	function setPoolAdmin(address admin) external;

	function getEmergencyAdmin() external view returns (address);

	function setEmergencyAdmin(address admin) external;

	function getPriceOracle() external view returns (address);

	function setPriceOracle(address priceOracle) external;

	function getLendingRateOracle() external view returns (address);

	function setLendingRateOracle(address lendingRateOracle) external;

	function getLiquidationFeeTo() external view returns (address);

	function setLiquidationFeeTo(address liquidationFeeTo) external;
}

// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;

import { IERC20, SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { Errors } from "../Errors.sol";

struct SwapData {
    uint256 value; // amount of gas token that will be paid
    address addressToCall; // address to call and send bytes data to perform the aggregator swap
    address addressToApprove; // address to approve tokens that will be swapped
    bytes data; // bytes that will be passed to the aggregator to perform a swap
}

/// @title DexSwapStrategy library
/// @author Radiant
/// @custom:security-contact [email protected]
library DexSwapStrategy {
    using SafeERC20 for IERC20;

    /**
     * @notice Swap function
     * @param _data Data to perform the swap
     */
    function swap(
        address inputToken,
        uint256 amountIn,
        uint256 _minOutput,
        bytes calldata _data,
        function(address) view returns (bool) isApprovedAddress
    ) internal {
        SwapData memory swapData = bytesToSwapData(_data);

        if (swapData.value != 0) {
            revert Errors.NativeAssetsNotSupported();
        }

        if (!isApprovedAddress(swapData.addressToCall)) {
            revert Errors.AddressNotApproved();
        }

        IERC20(inputToken).forceApprove(swapData.addressToApprove, amountIn);

        uint256 returnAmount;
        (bool success, bytes memory responseData) = swapData.addressToCall.call(swapData.data);
        if (success) {
            returnAmount = abi.decode(responseData, (uint256));
        } else {
            revert Errors.DexSwapFailed();
        }

        if (returnAmount < _minOutput) {
            revert Errors.ReceivedLessThanMinOutput();
        }

        IERC20(inputToken).forceApprove(swapData.addressToApprove, 0);
    }

    /**
     * @notice Convert bytes to SwapData
     * @param rawData Raw data
     * @return swapData SwapData
     */
    function bytesToSwapData(bytes memory rawData) internal pure returns (SwapData memory) {
        if (rawData.length < 160) revert Errors.InvalidInputData();

        SwapData memory swapData;
        uint256 value;
        address addressToCall;
        address addressToApprove;

        assembly {
            value := mload(add(rawData, 32))
            addressToCall := mload(add(rawData, 64))
            addressToApprove := mload(add(rawData, 96))
        }

        swapData.value = value;
        swapData.addressToCall = addressToCall;
        swapData.addressToApprove = addressToApprove;

        swapData.data = new bytes(rawData.length - 160);
        uint256 rawDataLength = rawData.length;
        for (uint256 i = 160; i < rawDataLength;) {
            swapData.data[i - 160] = rawData[i];
            unchecked {
                ++i;
            }
        }

        return swapData;
    }
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.12;
pragma experimental ABIEncoderV2;

import {ILendingPoolAddressesProvider} from "./ILendingPoolAddressesProvider.sol";
import {DataTypes} from "../lending/libraries/types/DataTypes.sol";

interface ILendingPool {
	/**
	 * @dev Emitted on deposit()
	 * @param reserve The address of the underlying asset of the reserve
	 * @param user The address initiating the deposit
	 * @param onBehalfOf The beneficiary of the deposit, receiving the aTokens
	 * @param amount The amount deposited
	 * @param referral The referral code used
	 **/
	event Deposit(
		address indexed reserve,
		address user,
		address indexed onBehalfOf,
		uint256 amount,
		uint16 indexed referral
	);

	/**
	 * @dev Emitted on withdraw()
	 * @param reserve The address of the underlyng asset being withdrawn
	 * @param user The address initiating the withdrawal, owner of aTokens
	 * @param to Address that will receive the underlying
	 * @param amount The amount to be withdrawn
	 **/
	event Withdraw(address indexed reserve, address indexed user, address indexed to, uint256 amount);

	/**
	 * @dev Emitted on borrow() and flashLoan() when debt needs to be opened
	 * @param reserve The address of the underlying asset being borrowed
	 * @param user The address of the user initiating the borrow(), receiving the funds on borrow() or just
	 * initiator of the transaction on flashLoan()
	 * @param onBehalfOf The address that will be getting the debt
	 * @param amount The amount borrowed out
	 * @param borrowRateMode The rate mode: 1 for Stable, 2 for Variable
	 * @param borrowRate The numeric rate at which the user has borrowed
	 * @param referral The referral code used
	 **/
	event Borrow(
		address indexed reserve,
		address user,
		address indexed onBehalfOf,
		uint256 amount,
		uint256 borrowRateMode,
		uint256 borrowRate,
		uint16 indexed referral
	);

	/**
	 * @dev Emitted on repay()
	 * @param reserve The address of the underlying asset of the reserve
	 * @param user The beneficiary of the repayment, getting his debt reduced
	 * @param repayer The address of the user initiating the repay(), providing the funds
	 * @param amount The amount repaid
	 **/
	event Repay(address indexed reserve, address indexed user, address indexed repayer, uint256 amount);

	/**
	 * @dev Emitted on swapBorrowRateMode()
	 * @param reserve The address of the underlying asset of the reserve
	 * @param user The address of the user swapping his rate mode
	 * @param rateMode The rate mode that the user wants to swap to
	 **/
	event Swap(address indexed reserve, address indexed user, uint256 rateMode);

	/**
	 * @dev Emitted on setUserUseReserveAsCollateral()
	 * @param reserve The address of the underlying asset of the reserve
	 * @param user The address of the user enabling the usage as collateral
	 **/
	event ReserveUsedAsCollateralEnabled(address indexed reserve, address indexed user);

	/**
	 * @dev Emitted on setUserUseReserveAsCollateral()
	 * @param reserve The address of the underlying asset of the reserve
	 * @param user The address of the user enabling the usage as collateral
	 **/
	event ReserveUsedAsCollateralDisabled(address indexed reserve, address indexed user);

	/**
	 * @dev Emitted on rebalanceStableBorrowRate()
	 * @param reserve The address of the underlying asset of the reserve
	 * @param user The address of the user for which the rebalance has been executed
	 **/
	event RebalanceStableBorrowRate(address indexed reserve, address indexed user);

	/**
	 * @dev Emitted on flashLoan()
	 * @param target The address of the flash loan receiver contract
	 * @param initiator The address initiating the flash loan
	 * @param asset The address of the asset being flash borrowed
	 * @param amount The amount flash borrowed
	 * @param premium The fee flash borrowed
	 * @param referralCode The referral code used
	 **/
	event FlashLoan(
		address indexed target,
		address indexed initiator,
		address indexed asset,
		uint256 amount,
		uint256 premium,
		uint16 referralCode
	);

	/**
	 * @dev Emitted when the pause is triggered.
	 */
	event Paused();

	/**
	 * @dev Emitted when the pause is lifted.
	 */
	event Unpaused();

	/**
	 * @dev Emitted when a borrower is liquidated. This event is emitted by the LendingPool via
	 * LendingPoolCollateral manager using a DELEGATECALL
	 * This allows to have the events in the generated ABI for LendingPool.
	 * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
	 * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation
	 * @param user The address of the borrower getting liquidated
	 * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover
	 * @param liquidatedCollateralAmount The amount of collateral received by the liiquidator
	 * @param liquidator The address of the liquidator
	 * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants
	 * to receive the underlying collateral asset directly
	 **/
	event LiquidationCall(
		address indexed collateralAsset,
		address indexed debtAsset,
		address indexed user,
		uint256 debtToCover,
		uint256 liquidatedCollateralAmount,
		address liquidator,
		bool receiveAToken
	);

	/**
	 * @dev Emitted when the state of a reserve is updated. NOTE: This event is actually declared
	 * in the ReserveLogic library and emitted in the updateInterestRates() function. Since the function is internal,
	 * the event will actually be fired by the LendingPool contract. The event is therefore replicated here so it
	 * gets added to the LendingPool ABI
	 * @param reserve The address of the underlying asset of the reserve
	 * @param liquidityRate The new liquidity rate
	 * @param stableBorrowRate The new stable borrow rate
	 * @param variableBorrowRate The new variable borrow rate
	 * @param liquidityIndex The new liquidity index
	 * @param variableBorrowIndex The new variable borrow index
	 **/
	event ReserveDataUpdated(
		address indexed reserve,
		uint256 liquidityRate,
		uint256 stableBorrowRate,
		uint256 variableBorrowRate,
		uint256 liquidityIndex,
		uint256 variableBorrowIndex
	);

	function initialize(ILendingPoolAddressesProvider provider) external;

	/**
	 * @dev Deposits an `amount` of underlying asset into the reserve, receiving in return overlying aTokens.
	 * - E.g. User deposits 100 USDC and gets in return 100 aUSDC
	 * @param asset The address of the underlying asset to deposit
	 * @param amount The amount to be deposited
	 * @param onBehalfOf The address that will receive the aTokens, same as msg.sender if the user
	 *   wants to receive them on his own wallet, or a different address if the beneficiary of aTokens
	 *   is a different wallet
	 * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
	 *   0 if the action is executed directly by the user, without any middle-man
	 **/
	function deposit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external;

	function depositWithAutoDLP(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external;

	/**
	 * @dev Withdraws an `amount` of underlying asset from the reserve, burning the equivalent aTokens owned
	 * E.g. User has 100 aUSDC, calls withdraw() and receives 100 USDC, burning the 100 aUSDC
	 * @param asset The address of the underlying asset to withdraw
	 * @param amount The underlying amount to be withdrawn
	 *   - Send the value type(uint256).max in order to withdraw the whole aToken balance
	 * @param to Address that will receive the underlying, same as msg.sender if the user
	 *   wants to receive it on his own wallet, or a different address if the beneficiary is a
	 *   different wallet
	 * @return The final amount withdrawn
	 **/
	function withdraw(address asset, uint256 amount, address to) external returns (uint256);

	/**
	 * @dev Allows users to borrow a specific `amount` of the reserve underlying asset, provided that the borrower
	 * already deposited enough collateral, or he was given enough allowance by a credit delegator on the
	 * corresponding debt token (StableDebtToken or VariableDebtToken)
	 * - E.g. User borrows 100 USDC passing as `onBehalfOf` his own address, receiving the 100 USDC in his wallet
	 *   and 100 stable/variable debt tokens, depending on the `interestRateMode`
	 * @param asset The address of the underlying asset to borrow
	 * @param amount The amount to be borrowed
	 * @param interestRateMode The interest rate mode at which the user wants to borrow: 1 for Stable, 2 for Variable
	 * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
	 *   0 if the action is executed directly by the user, without any middle-man
	 * @param onBehalfOf Address of the user who will receive the debt. Should be the address of the borrower itself
	 * calling the function if he wants to borrow against his own collateral, or the address of the credit delegator
	 * if he has been given credit delegation allowance
	 **/
	function borrow(
		address asset,
		uint256 amount,
		uint256 interestRateMode,
		uint16 referralCode,
		address onBehalfOf
	) external;

	/**
	 * @notice Repays a borrowed `amount` on a specific reserve, burning the equivalent debt tokens owned
	 * - E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the `onBehalfOf` address
	 * @param asset The address of the borrowed underlying asset previously borrowed
	 * @param amount The amount to repay
	 * - Send the value type(uint256).max in order to repay the whole debt for `asset` on the specific `debtMode`
	 * @param rateMode The interest rate mode at of the debt the user wants to repay: 1 for Stable, 2 for Variable
	 * @param onBehalfOf Address of the user who will get his debt reduced/removed. Should be the address of the
	 * user calling the function if he wants to reduce/remove his own debt, or the address of any other
	 * other borrower whose debt should be removed
	 * @return The final amount repaid
	 **/
	function repay(address asset, uint256 amount, uint256 rateMode, address onBehalfOf) external returns (uint256);

	/**
	 * @dev Allows a borrower to swap his debt between stable and variable mode, or viceversa
	 * @param asset The address of the underlying asset borrowed
	 * @param rateMode The rate mode that the user wants to swap to
	 **/
	function swapBorrowRateMode(address asset, uint256 rateMode) external;

	/**
	 * @dev Rebalances the stable interest rate of a user to the current stable rate defined on the reserve.
	 * - Users can be rebalanced if the following conditions are satisfied:
	 *     1. Usage ratio is above 95%
	 *     2. the current deposit APY is below REBALANCE_UP_THRESHOLD * maxVariableBorrowRate, which means that too much has been
	 *        borrowed at a stable rate and depositors are not earning enough
	 * @param asset The address of the underlying asset borrowed
	 * @param user The address of the user to be rebalanced
	 **/
	function rebalanceStableBorrowRate(address asset, address user) external;

	/**
	 * @dev Allows depositors to enable/disable a specific deposited asset as collateral
	 * @param asset The address of the underlying asset deposited
	 * @param useAsCollateral `true` if the user wants to use the deposit as collateral, `false` otherwise
	 **/
	function setUserUseReserveAsCollateral(address asset, bool useAsCollateral) external;

	/**
	 * @dev Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1
	 * - The caller (liquidator) covers `debtToCover` amount of debt of the user getting liquidated, and receives
	 *   a proportionally amount of the `collateralAsset` plus a bonus to cover market risk
	 * @param collateralAsset The address of the underlying asset used as collateral, to receive as result of the liquidation
	 * @param debtAsset The address of the underlying borrowed asset to be repaid with the liquidation
	 * @param user The address of the borrower getting liquidated
	 * @param debtToCover The debt amount of borrowed `asset` the liquidator wants to cover
	 * @param receiveAToken `true` if the liquidators wants to receive the collateral aTokens, `false` if he wants
	 * to receive the underlying collateral asset directly
	 **/
	function liquidationCall(
		address collateralAsset,
		address debtAsset,
		address user,
		uint256 debtToCover,
		bool receiveAToken
	) external;

	/**
	 * @dev Allows smartcontracts to access the liquidity of the pool within one transaction,
	 * as long as the amount taken plus a fee is returned.
	 * IMPORTANT There are security concerns for developers of flashloan receiver contracts that must be kept into consideration.
	 * For further details please visit https://developers.aave.com
	 * @param receiverAddress The address of the contract receiving the funds, implementing the IFlashLoanReceiver interface
	 * @param assets The addresses of the assets being flash-borrowed
	 * @param amounts The amounts amounts being flash-borrowed
	 * @param modes Types of the debt to open if the flash loan is not returned:
	 *   0 -> Don't open any debt, just revert if funds can't be transferred from the receiver
	 *   1 -> Open debt at stable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
	 *   2 -> Open debt at variable rate for the value of the amount flash-borrowed to the `onBehalfOf` address
	 * @param onBehalfOf The address  that will receive the debt in the case of using on `modes` 1 or 2
	 * @param params Variadic packed params to pass to the receiver as extra information
	 * @param referralCode Code used to register the integrator originating the operation, for potential rewards.
	 *   0 if the action is executed directly by the user, without any middle-man
	 **/
	function flashLoan(
		address receiverAddress,
		address[] calldata assets,
		uint256[] calldata amounts,
		uint256[] calldata modes,
		address onBehalfOf,
		bytes calldata params,
		uint16 referralCode
	) external;

	/**
	 * @dev Returns the user account data across all the reserves
	 * @param user The address of the user
	 * @return totalCollateral the total collateral in USD to 8 decimals of the user
	 * @return totalDebt the total debt in USD to 8 decimals of the user
	 * @return availableBorrows the borrowing power left of the user
	 * @return currentLiquidationThreshold the liquidation threshold of the user
	 * @return ltv the loan to value of the user
	 * @return healthFactor the current health factor of the user
	 **/
	function getUserAccountData(
		address user
	)
		external
		view
		returns (
			uint256 totalCollateral,
			uint256 totalDebt,
			uint256 availableBorrows,
			uint256 currentLiquidationThreshold,
			uint256 ltv,
			uint256 healthFactor
		);

	function initReserve(
		address reserve,
		address aTokenAddress,
		address stableDebtAddress,
		address variableDebtAddress,
		address interestRateStrategyAddress
	) external;

	function setReserveInterestRateStrategyAddress(address reserve, address rateStrategyAddress) external;

	function setConfiguration(address reserve, uint256 configuration) external;

	/**
	 * @dev Returns the configuration of the reserve
	 * @param asset The address of the underlying asset of the reserve
	 * @return The configuration of the reserve
	 **/
	function getConfiguration(address asset) external view returns (DataTypes.ReserveConfigurationMap memory);

	/**
	 * @dev Returns the configuration of the user across all the reserves
	 * @param user The user address
	 * @return The configuration of the user
	 **/
	function getUserConfiguration(address user) external view returns (DataTypes.UserConfigurationMap memory);

	/**
	 * @dev Returns the normalized income normalized income of the reserve
	 * @param asset The address of the underlying asset of the reserve
	 * @return The reserve's normalized income
	 */
	function getReserveNormalizedIncome(address asset) external view returns (uint256);

	/**
	 * @dev Returns the normalized variable debt per unit of asset
	 * @param asset The address of the underlying asset of the reserve
	 * @return The reserve normalized variable debt
	 */
	function getReserveNormalizedVariableDebt(address asset) external view returns (uint256);

	/**
	 * @dev Returns the state and configuration of the reserve
	 * @param asset The address of the underlying asset of the reserve
	 * @return The state of the reserve
	 **/
	function getReserveData(address asset) external view returns (DataTypes.ReserveData memory);

	function finalizeTransfer(
		address asset,
		address from,
		address to,
		uint256 amount,
		uint256 balanceFromAfter,
		uint256 balanceToBefore
	) external;

	function getReservesList() external view returns (address[] memory);

	function getAddressesProvider() external view returns (ILendingPoolAddressesProvider);

	function setPause(bool val) external;

	function paused() external view returns (bool);
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.12;

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {IScaledBalanceToken} from "./IScaledBalanceToken.sol";
import {IInitializableAToken} from "./IInitializableAToken.sol";
import {IAaveIncentivesController} from "./IAaveIncentivesController.sol";
import {ILendingPool} from "./ILendingPool.sol";

interface IAToken is IERC20, IScaledBalanceToken, IInitializableAToken {
	/**
	 * @dev Emitted after the mint action
	 * @param from The address performing the mint
	 * @param value The amount being
	 * @param index The new liquidity index of the reserve
	 **/
	event Mint(address indexed from, uint256 value, uint256 index);

	/**
	 * @dev Mints `amount` aTokens to `user`
	 * @param user The address receiving the minted tokens
	 * @param amount The amount of tokens getting minted
	 * @param index The new liquidity index of the reserve
	 * @return `true` if the the previous balance of the user was 0
	 */
	function mint(address user, uint256 amount, uint256 index) external returns (bool);

	/**
	 * @dev Emitted after aTokens are burned
	 * @param from The owner of the aTokens, getting them burned
	 * @param target The address that will receive the underlying
	 * @param value The amount being burned
	 * @param index The new liquidity index of the reserve
	 **/
	event Burn(address indexed from, address indexed target, uint256 value, uint256 index);

	/**
	 * @dev Emitted during the transfer action
	 * @param from The user whose tokens are being transferred
	 * @param to The recipient
	 * @param value The amount being transferred
	 * @param index The new liquidity index of the reserve
	 **/
	event BalanceTransfer(address indexed from, address indexed to, uint256 value, uint256 index);

	/**
	 * @dev Burns aTokens from `user` and sends the equivalent amount of underlying to `receiverOfUnderlying`
	 * @param user The owner of the aTokens, getting them burned
	 * @param receiverOfUnderlying The address that will receive the underlying
	 * @param amount The amount being burned
	 * @param index The new liquidity index of the reserve
	 **/
	function burn(address user, address receiverOfUnderlying, uint256 amount, uint256 index) external;

	/**
	 * @dev Mints aTokens to the reserve treasury
	 * @param amount The amount of tokens getting minted
	 * @param index The new liquidity index of the reserve
	 */
	function mintToTreasury(uint256 amount, uint256 index) external;

	/**
	 * @dev Transfers aTokens in the event of a borrow being liquidated, in case the liquidators reclaims the aToken
	 * @param from The address getting liquidated, current owner of the aTokens
	 * @param to The recipient
	 * @param value The amount of tokens getting transferred
	 **/
	function transferOnLiquidation(address from, address to, uint256 value) external;

	/**
	 * @dev Transfers the underlying asset to `target`. Used by the LendingPool to transfer
	 * assets in borrow(), withdraw() and flashLoan()
	 * @param user The recipient of the underlying
	 * @param amount The amount getting transferred
	 * @return The amount transferred
	 **/
	function transferUnderlyingTo(address user, uint256 amount) external returns (uint256);

	/**
	 * @dev Invoked to execute actions on the aToken side after a repayment.
	 * @param user The user executing the repayment
	 * @param amount The amount getting repaid
	 **/
	function handleRepayment(address user, uint256 amount) external;

	/**
	 * @dev Updates the treasury address
	 * @param treasury The new treasury address
	 */
	function setTreasuryAddress(address treasury) external;

	/**
	 * @dev Returns the address of the incentives controller contract
	 **/
	function getIncentivesController() external view returns (IAaveIncentivesController);

	/**
	 * @dev Returns the address of the underlying asset of this aToken (E.g. WETH for aWETH)
	 **/
	function UNDERLYING_ASSET_ADDRESS() external view returns (address);

	/**
	 * @dev Returns the address of the lending pool where this aToken is used
	 **/
	function POOL() external view returns (ILendingPool);
}

File 15 of 27 : Errors.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.12;

/**
 * @title Errors library
 * @author Aave & Radiant
 * @custom:security-contact [email protected]
 * @notice Defines the error messages emitted by the different contracts of the Aave & Radiant protocols
 * @dev Error messages prefix glossary:
 *  - VL = ValidationLogic
 *  - MATH = Math libraries
 *  - CT = Common errors between tokens (AToken, VariableDebtToken and StableDebtToken)
 *  - AT = AToken
 *  - SDT = StableDebtToken
 *  - VDT = VariableDebtToken
 *  - LP = LendingPool
 *  - LPAPR = LendingPoolAddressesProviderRegistry
 *  - LPC = LendingPoolConfiguration
 *  - RL = ReserveLogic
 *  - LPCM = LendingPoolCollateralManager
 *  - P = Pausable
 */
library Errors {
    // Common errors
    error AddressZero();
    error AmountZero();
    error NotAContract();
    error NotAuthorized();

    // Oracle specific errors
    error NoFeedSet();
    error NoFallbackFeedSet();
    error NoPriceAvailable();
    error PoolDisabled();
    error PoolNotDisabled();
    // Oracle specific errors
    error RoundNotComplete();

    // Oracles General errors
    error InvalidOracleProviderType();
    error InvalidFeed();
    error NegativePythPriceValue(int64 price);
    error NegativeChainlinkPriceValue(int256 answer);
    error ExponentOutOfRange(int32 expo);

    // Riz Registry errors
    error PoolRegisteredAlready();
    error NoAddressProvider();
    error NotLPConfigurator();

    // Riz LockZap errors
    error CannotRizZap();
    error InvalidLendingPool();
    error InvalidRatio();
    error InvalidLockLength();
    error SlippageTooHigh();
    error SpecifiedSlippageExceedLimit();
    error InvalidZapETHSource();
    error ReceivedETHOnAlternativeAssetZap();
    error InsufficientETH();
    error SwapFailed(address asset, uint256 amount);
    error WrongRoute(address fromToken, address toToken);

    // RizLendingPoolConfigurator errors
    error DecimalsOutOfRange(uint256 decimals);

    // RizLendingPoolAddressesProvider errors
    error InvalidId(bytes32 id);
    error MarketIdAlreadySet();

    // Riz Leverager errors
    error ReceiveNotAllowed();
    error FallbackNotAllowed();

    /// @notice Disallow a loop count of 0
    error InvalidLoopCount();

    /// @notice Thrown when deployer sets the margin too high
    error MarginTooHigh();

    // Revenue Management errors
    error OutputTokenConfigLengthMismatch();
    error InputTokenConfigLengthMismatch();
    error IndexOutOfBounds();
    error OutputTokenBalanceOutOfRange();
    error TokenAlreadyAdded();
    error TokenNotPresent();
    error PercentageMismatch();
    error InvalidSwapStrategy();
    error DexSwapFailed();
    error ReceivedLessThanMinOutput();
    error InvalidInputData();
    error AddressNotApproved();
    error NativeAssetsNotSupported();
    error DuplicateOutputToken();

    // Bad Debt Manager errors
    error OnlyLendingPool();
    error UserAlreadyWithdrawn();
    error BadDebtIsZero();
    error UserAllowanceZero();
    error NotEmergencyAdmin();
    error InvalidAssetsLength();

    // BaseStrategy errors
    error NotSelf();

    // TokenizedStrategy errors
    error ReentrantCall();
    error NotManagement();
    error NotKeeper();
    error NotEmergencyAuthorized();
    error AlreadyInitialized();
    error InvalidChainID();
    error CannotBeSelf();
    error ZeroShares();
    error ZeroAssets();
    error DepositMoreThanMax();
    error MintMoreThanMax();
    error WithdrawMoreThanMax();
    error RedeemMoreThanMax();
    error SelfMint();
    error ExceedsMaxBPS();
    error TooMuchLoss();
    error NotShutdown();
    error NotPending();
    error ExceedsMaxFee();
    error TooLong();
    error InvalidTransfer();
    error CannotMintToAddressZero();
    error CannotBurnToAddressZero();
    error CannotApproveAddressZero();
    error InsufficientAllowance();
    error PermitDeadlineExpired();
    error InvalidSigner();

    // Common aave errors
    string public constant CALLER_NOT_POOL_ADMIN = "33"; // 'The caller must be the pool admin'
    string public constant BORROW_ALLOWANCE_NOT_ENOUGH = "59"; // User borrows on behalf, but allowance are too small

    // Contract specific errors
    string public constant VL_INVALID_AMOUNT = "1"; // 'Amount must be greater than 0'
    string public constant VL_NO_ACTIVE_RESERVE = "2"; // 'Action requires an active reserve'
    string public constant VL_RESERVE_FROZEN = "3"; // 'Action cannot be performed because the reserve is frozen'
    string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = "4"; // 'The current liquidity is not enough'
    string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = "5"; // 'User cannot withdraw more than the available
        // balance'
    string public constant VL_TRANSFER_NOT_ALLOWED = "6"; // 'Transfer cannot be allowed.'
    string public constant VL_BORROWING_NOT_ENABLED = "7"; // 'Borrowing is not enabled'
    string public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = "8"; // 'Invalid interest rate mode selected'
    string public constant VL_COLLATERAL_BALANCE_IS_0 = "9"; // 'The collateral balance is 0'
    string public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = "10"; // 'Health factor is lesser than
        // the liquidation threshold'
    string public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = "11"; // 'There is not enough collateral to cover a
        // new borrow'
    string public constant VL_STABLE_BORROWING_NOT_ENABLED = "12"; // stable borrowing not enabled
    string public constant VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY = "13"; // collateral is (mostly) the same currency
        // that is being borrowed
    string public constant VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = "14"; // 'The requested amount is greater than
        // the max loan size in stable rate mode
    string public constant VL_NO_DEBT_OF_SELECTED_TYPE = "15"; // 'for repayment of stable debt, the user needs to have
        // stable debt, otherwise, he needs to have variable debt'
    string public constant VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = "16"; // 'To repay on behalf of an user an
        // explicit amount to repay is needed'
    string public constant VL_NO_STABLE_RATE_LOAN_IN_RESERVE = "17"; // 'User does not have a stable rate loan in
        // progress on this reserve'
    string public constant VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = "18"; // 'User does not have a variable rate loan in
        // progress on this reserve'
    string public constant VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = "19"; // 'The underlying balance needs to be
        // greater than 0'
    string public constant VL_DEPOSIT_ALREADY_IN_USE = "20"; // 'User deposit is already being used as collateral'
    string public constant LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = "21"; // 'User does not have any stable rate loan for
        // this reserve'
    string public constant LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = "22"; // 'Interest rate rebalance conditions
        // were not met'
    string public constant LP_LIQUIDATION_CALL_FAILED = "23"; // 'Liquidation call failed'
    string public constant LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = "24"; // 'There is not enough liquidity available to
        // borrow'
    string public constant LP_REQUESTED_AMOUNT_TOO_SMALL = "25"; // 'The requested amount is too small for a FlashLoan.'
    string public constant LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = "26"; // 'The actual balance of the protocol is
        // inconsistent'
    string public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = "27"; // 'The caller of the function is not the
        // lending pool configurator'
    string public constant LP_INCONSISTENT_FLASHLOAN_PARAMS = "28";
    string public constant CT_CALLER_MUST_BE_LENDING_POOL = "29"; // 'The caller of this function must be a lending
        // pool'
    string public constant CT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = "30"; // 'User cannot give allowance to himself'
    string public constant CT_TRANSFER_AMOUNT_NOT_GT_0 = "31"; // 'Transferred amount needs to be greater than zero'
    string public constant RL_RESERVE_ALREADY_INITIALIZED = "32"; // 'Reserve has already been initialized'
    string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = "34"; // 'The liquidity of the reserve needs to be 0'
    string public constant LPC_INVALID_ATOKEN_POOL_ADDRESS = "35"; // 'The liquidity of the reserve needs to be 0'
    string public constant LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = "36"; // 'The liquidity of the reserve needs to
        // be 0'
    string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = "37"; // 'The liquidity of the reserve needs
        // to be 0'
    string public constant LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = "38"; // 'The liquidity of the reserve
        // needs to be 0'
    string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = "39"; // 'The liquidity of the reserve
        // needs to be 0'
    string public constant LPC_INVALID_ADDRESSES_PROVIDER_ID = "40"; // 'The liquidity of the reserve needs to be 0'
    string public constant LPC_INVALID_CONFIGURATION = "75"; // 'Invalid risk parameters for the reserve'
    string public constant LPC_CALLER_NOT_EMERGENCY_ADMIN = "76"; // 'The caller must be the emergency admin'
    string public constant LPAPR_PROVIDER_NOT_REGISTERED = "41"; // 'Provider is not registered'
    string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = "42"; // 'Health factor is not below the threshold'
    string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = "43"; // 'The collateral chosen cannot be liquidated'
    string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = "44"; // 'User did not borrow the specified
        // currency'
    string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = "45"; // "There isn't enough liquidity available to
        // liquidate"
    string public constant LPCM_NO_ERRORS = "46"; // 'No errors'
    string public constant LP_INVALID_FLASHLOAN_MODE = "47"; //Invalid flashloan mode selected
    string public constant MATH_MULTIPLICATION_OVERFLOW = "48";
    string public constant MATH_ADDITION_OVERFLOW = "49";
    string public constant MATH_DIVISION_BY_ZERO = "50";
    string public constant RL_LIQUIDITY_INDEX_OVERFLOW = "51"; //  Liquidity index overflows uint128
    string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = "52"; //  Variable borrow index overflows uint128
    string public constant RL_LIQUIDITY_RATE_OVERFLOW = "53"; //  Liquidity rate overflows uint128
    string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = "54"; //  Variable borrow rate overflows uint128
    string public constant RL_STABLE_BORROW_RATE_OVERFLOW = "55"; //  Stable borrow rate overflows uint128
    string public constant CT_INVALID_MINT_AMOUNT = "56"; //invalid amount to mint
    string public constant LP_FAILED_REPAY_WITH_COLLATERAL = "57";
    string public constant CT_INVALID_BURN_AMOUNT = "58"; //invalid amount to burn
    string public constant LP_FAILED_COLLATERAL_SWAP = "60";
    string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = "61";
    string public constant LP_REENTRANCY_NOT_ALLOWED = "62";
    string public constant LP_CALLER_MUST_BE_AN_ATOKEN = "63";
    string public constant LP_IS_PAUSED = "64"; // 'Pool is paused'
    string public constant LP_NO_MORE_RESERVES_ALLOWED = "65";
    string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = "66";
    string public constant RC_INVALID_LTV = "67";
    string public constant RC_INVALID_LIQ_THRESHOLD = "68";
    string public constant RC_INVALID_LIQ_BONUS = "69";
    string public constant RC_INVALID_DECIMALS = "70";
    string public constant RC_INVALID_RESERVE_FACTOR = "71";
    string public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = "72";
    string public constant VL_INCONSISTENT_FLASHLOAN_PARAMS = "73";
    string public constant LP_INCONSISTENT_PARAMS_LENGTH = "74";
    string public constant UL_INVALID_INDEX = "77";
    string public constant LP_NOT_CONTRACT = "78";
    string public constant SDT_STABLE_DEBT_OVERFLOW = "79";
    string public constant SDT_BURN_EXCEEDS_BALANCE = "80";

    /**
     * @dev Custom Radiant codes added +200 to avoid conflicts with the AaveV2/V3 ones
     * @custom:borrow-and-supply-caps
     */
    string public constant INVALID_BORROW_CAP = "201"; // Invalid borrow cap value
    string public constant INVALID_SUPPLY_CAP = "202"; // Invalid supply cap value
    string public constant BORROW_CAP_EXCEEDED = "203"; // Borrow cap is exceeded
    string public constant SUPPLY_CAP_EXCEEDED = "204"; // Supply cap is exceeded

    enum CollateralManagerErrors {
        NO_ERROR,
        NO_COLLATERAL_AVAILABLE,
        COLLATERAL_CANNOT_BE_LIQUIDATED,
        CURRRENCY_NOT_BORROWED,
        HEALTH_FACTOR_ABOVE_THRESHOLD,
        NOT_ENOUGH_LIQUIDITY,
        NO_ACTIVE_RESERVE,
        HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,
        INVALID_EQUAL_ASSETS_TO_SWAP,
        FROZEN_RESERVE
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)

pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";

/**
 * @dev Provides information about the current execution context, including the
 * sender of the transaction and its data. While these are generally available
 * via msg.sender and msg.data, they should not be accessed in such a direct
 * manner, since when dealing with meta-transactions the account sending and
 * paying for execution may not be the actual sender (as far as an application
 * is concerned).
 *
 * This contract is only required for intermediate, library-like contracts.
 */
abstract contract ContextUpgradeable is Initializable {
    function __Context_init() internal onlyInitializing {
    }

    function __Context_init_unchained() internal onlyInitializing {
    }
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }

    function _msgData() internal view virtual returns (bytes calldata) {
        return msg.data;
    }

    /**
     * @dev This empty reserved space is put in place to allow future versions to add new
     * variables without shifting down storage in the inheritance chain.
     * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
     */
    uint256[50] private __gap;
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)

pragma solidity ^0.8.2;

import "../../utils/AddressUpgradeable.sol";

/**
 * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
 * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
 * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
 * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
 *
 * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
 * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
 * case an upgrade adds a module that needs to be initialized.
 *
 * For example:
 *
 * [.hljs-theme-light.nopadding]
 * ```solidity
 * contract MyToken is ERC20Upgradeable {
 *     function initialize() initializer public {
 *         __ERC20_init("MyToken", "MTK");
 *     }
 * }
 *
 * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
 *     function initializeV2() reinitializer(2) public {
 *         __ERC20Permit_init("MyToken");
 *     }
 * }
 * ```
 *
 * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
 * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
 *
 * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
 * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
 *
 * [CAUTION]
 * ====
 * Avoid leaving a contract uninitialized.
 *
 * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
 * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
 * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
 *
 * [.hljs-theme-light.nopadding]
 * ```
 * /// @custom:oz-upgrades-unsafe-allow constructor
 * constructor() {
 *     _disableInitializers();
 * }
 * ```
 * ====
 */
abstract contract Initializable {
    /**
     * @dev Indicates that the contract has been initialized.
     * @custom:oz-retyped-from bool
     */
    uint8 private _initialized;

    /**
     * @dev Indicates that the contract is in the process of being initialized.
     */
    bool private _initializing;

    /**
     * @dev Triggered when the contract has been initialized or reinitialized.
     */
    event Initialized(uint8 version);

    /**
     * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
     * `onlyInitializing` functions can be used to initialize parent contracts.
     *
     * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
     * constructor.
     *
     * Emits an {Initialized} event.
     */
    modifier initializer() {
        bool isTopLevelCall = !_initializing;
        require(
            (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
            "Initializable: contract is already initialized"
        );
        _initialized = 1;
        if (isTopLevelCall) {
            _initializing = true;
        }
        _;
        if (isTopLevelCall) {
            _initializing = false;
            emit Initialized(1);
        }
    }

    /**
     * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
     * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
     * used to initialize parent contracts.
     *
     * A reinitializer may be used after the original initialization step. This is essential to configure modules that
     * are added through upgrades and that require initialization.
     *
     * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
     * cannot be nested. If one is invoked in the context of another, execution will revert.
     *
     * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
     * a contract, executing them in the right order is up to the developer or operator.
     *
     * WARNING: setting the version to 255 will prevent any future reinitialization.
     *
     * Emits an {Initialized} event.
     */
    modifier reinitializer(uint8 version) {
        require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
        _initialized = version;
        _initializing = true;
        _;
        _initializing = false;
        emit Initialized(version);
    }

    /**
     * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
     * {initializer} and {reinitializer} modifiers, directly or indirectly.
     */
    modifier onlyInitializing() {
        require(_initializing, "Initializable: contract is not initializing");
        _;
    }

    /**
     * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
     * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
     * to any version. It is recommended to use this to lock implementation contracts that are designed to be called
     * through proxies.
     *
     * Emits an {Initialized} event the first time it is successfully executed.
     */
    function _disableInitializers() internal virtual {
        require(!_initializing, "Initializable: contract is initializing");
        if (_initialized != type(uint8).max) {
            _initialized = type(uint8).max;
            emit Initialized(type(uint8).max);
        }
    }

    /**
     * @dev Returns the highest version that has been initialized. See {reinitializer}.
     */
    function _getInitializedVersion() internal view returns (uint8) {
        return _initialized;
    }

    /**
     * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
     */
    function _isInitializing() internal view returns (bool) {
        return _initializing;
    }
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 standard as defined in the EIP.
 */
interface IERC20 {
    /**
     * @dev Emitted when `value` tokens are moved from one account (`from`) to
     * another (`to`).
     *
     * Note that `value` may be zero.
     */
    event Transfer(address indexed from, address indexed to, uint256 value);

    /**
     * @dev Emitted when the allowance of a `spender` for an `owner` is set by
     * a call to {approve}. `value` is the new allowance.
     */
    event Approval(address indexed owner, address indexed spender, uint256 value);

    /**
     * @dev Returns the amount of tokens in existence.
     */
    function totalSupply() external view returns (uint256);

    /**
     * @dev Returns the amount of tokens owned by `account`.
     */
    function balanceOf(address account) external view returns (uint256);

    /**
     * @dev Moves `amount` tokens from the caller's account to `to`.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transfer(address to, uint256 amount) external returns (bool);

    /**
     * @dev Returns the remaining number of tokens that `spender` will be
     * allowed to spend on behalf of `owner` through {transferFrom}. This is
     * zero by default.
     *
     * This value changes when {approve} or {transferFrom} are called.
     */
    function allowance(address owner, address spender) external view returns (uint256);

    /**
     * @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * IMPORTANT: Beware that changing an allowance with this method brings the risk
     * that someone may use both the old and the new allowance by unfortunate
     * transaction ordering. One possible solution to mitigate this race
     * condition is to first reduce the spender's allowance to 0 and set the
     * desired value afterwards:
     * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
     *
     * Emits an {Approval} event.
     */
    function approve(address spender, uint256 amount) external returns (bool);

    /**
     * @dev Moves `amount` tokens from `from` to `to` using the
     * allowance mechanism. `amount` is then deducted from the caller's
     * allowance.
     *
     * Returns a boolean value indicating whether the operation succeeded.
     *
     * Emits a {Transfer} event.
     */
    function transferFrom(address from, address to, uint256 amount) external returns (bool);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)

pragma solidity ^0.8.0;

/**
 * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
 * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
 *
 * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
 * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
 * need to send a transaction, and thus is not required to hold Ether at all.
 */
interface IERC20Permit {
    /**
     * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
     * given ``owner``'s signed approval.
     *
     * IMPORTANT: The same issues {IERC20-approve} has related to transaction
     * ordering also apply here.
     *
     * Emits an {Approval} event.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     * - `deadline` must be a timestamp in the future.
     * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
     * over the EIP712-formatted function arguments.
     * - the signature must use ``owner``'s current nonce (see {nonces}).
     *
     * For more information on the signature format, see the
     * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
     * section].
     */
    function permit(
        address owner,
        address spender,
        uint256 value,
        uint256 deadline,
        uint8 v,
        bytes32 r,
        bytes32 s
    ) external;

    /**
     * @dev Returns the current nonce for `owner`. This value must be
     * included whenever a signature is generated for {permit}.
     *
     * Every successful call to {permit} increases ``owner``'s nonce by one. This
     * prevents a signature from being used multiple times.
     */
    function nonces(address owner) external view returns (uint256);

    /**
     * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
     */
    // solhint-disable-next-line func-name-mixedcase
    function DOMAIN_SEPARATOR() external view returns (bytes32);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library Address {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

File 21 of 27 : Errors.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.12;

/**
 * @title Errors library
 * @author Aave
 * @notice Defines the error messages emitted by the different contracts of the Aave protocol
 * @dev Error messages prefix glossary:
 *  - VL = ValidationLogic
 *  - MATH = Math libraries
 *  - CT = Common errors between tokens (AToken, VariableDebtToken and StableDebtToken)
 *  - AT = AToken
 *  - SDT = StableDebtToken
 *  - VDT = VariableDebtToken
 *  - LP = LendingPool
 *  - LPAPR = LendingPoolAddressesProviderRegistry
 *  - LPC = LendingPoolConfiguration
 *  - RL = ReserveLogic
 *  - LPCM = LendingPoolCollateralManager
 *  - P = Pausable
 */
library Errors {
	//common errors
	string public constant CALLER_NOT_POOL_ADMIN = "33"; // 'The caller must be the pool admin'
	string public constant BORROW_ALLOWANCE_NOT_ENOUGH = "59"; // User borrows on behalf, but allowance are too small

	//contract specific errors
	string public constant VL_INVALID_AMOUNT = "1"; // 'Amount must be greater than 0'
	string public constant VL_NO_ACTIVE_RESERVE = "2"; // 'Action requires an active reserve'
	string public constant VL_RESERVE_FROZEN = "3"; // 'Action cannot be performed because the reserve is frozen'
	string public constant VL_CURRENT_AVAILABLE_LIQUIDITY_NOT_ENOUGH = "4"; // 'The current liquidity is not enough'
	string public constant VL_NOT_ENOUGH_AVAILABLE_USER_BALANCE = "5"; // 'User cannot withdraw more than the available balance'
	string public constant VL_TRANSFER_NOT_ALLOWED = "6"; // 'Transfer cannot be allowed.'
	string public constant VL_BORROWING_NOT_ENABLED = "7"; // 'Borrowing is not enabled'
	string public constant VL_INVALID_INTEREST_RATE_MODE_SELECTED = "8"; // 'Invalid interest rate mode selected'
	string public constant VL_COLLATERAL_BALANCE_IS_0 = "9"; // 'The collateral balance is 0'
	string public constant VL_HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD = "10"; // 'Health factor is lesser than the liquidation threshold'
	string public constant VL_COLLATERAL_CANNOT_COVER_NEW_BORROW = "11"; // 'There is not enough collateral to cover a new borrow'
	string public constant VL_STABLE_BORROWING_NOT_ENABLED = "12"; // stable borrowing not enabled
	string public constant VL_COLLATERAL_SAME_AS_BORROWING_CURRENCY = "13"; // collateral is (mostly) the same currency that is being borrowed
	string public constant VL_AMOUNT_BIGGER_THAN_MAX_LOAN_SIZE_STABLE = "14"; // 'The requested amount is greater than the max loan size in stable rate mode
	string public constant VL_NO_DEBT_OF_SELECTED_TYPE = "15"; // 'for repayment of stable debt, the user needs to have stable debt, otherwise, he needs to have variable debt'
	string public constant VL_NO_EXPLICIT_AMOUNT_TO_REPAY_ON_BEHALF = "16"; // 'To repay on behalf of an user an explicit amount to repay is needed'
	string public constant VL_NO_STABLE_RATE_LOAN_IN_RESERVE = "17"; // 'User does not have a stable rate loan in progress on this reserve'
	string public constant VL_NO_VARIABLE_RATE_LOAN_IN_RESERVE = "18"; // 'User does not have a variable rate loan in progress on this reserve'
	string public constant VL_UNDERLYING_BALANCE_NOT_GREATER_THAN_0 = "19"; // 'The underlying balance needs to be greater than 0'
	string public constant VL_DEPOSIT_ALREADY_IN_USE = "20"; // 'User deposit is already being used as collateral'
	string public constant LP_NOT_ENOUGH_STABLE_BORROW_BALANCE = "21"; // 'User does not have any stable rate loan for this reserve'
	string public constant LP_INTEREST_RATE_REBALANCE_CONDITIONS_NOT_MET = "22"; // 'Interest rate rebalance conditions were not met'
	string public constant LP_LIQUIDATION_CALL_FAILED = "23"; // 'Liquidation call failed'
	string public constant LP_NOT_ENOUGH_LIQUIDITY_TO_BORROW = "24"; // 'There is not enough liquidity available to borrow'
	string public constant LP_REQUESTED_AMOUNT_TOO_SMALL = "25"; // 'The requested amount is too small for a FlashLoan.'
	string public constant LP_INCONSISTENT_PROTOCOL_ACTUAL_BALANCE = "26"; // 'The actual balance of the protocol is inconsistent'
	string public constant LP_CALLER_NOT_LENDING_POOL_CONFIGURATOR = "27"; // 'The caller of the function is not the lending pool configurator'
	string public constant LP_INCONSISTENT_FLASHLOAN_PARAMS = "28";
	string public constant CT_CALLER_MUST_BE_LENDING_POOL = "29"; // 'The caller of this function must be a lending pool'
	string public constant CT_CANNOT_GIVE_ALLOWANCE_TO_HIMSELF = "30"; // 'User cannot give allowance to himself'
	string public constant CT_TRANSFER_AMOUNT_NOT_GT_0 = "31"; // 'Transferred amount needs to be greater than zero'
	string public constant RL_RESERVE_ALREADY_INITIALIZED = "32"; // 'Reserve has already been initialized'
	string public constant LPC_RESERVE_LIQUIDITY_NOT_0 = "34"; // 'The liquidity of the reserve needs to be 0'
	string public constant LPC_INVALID_ATOKEN_POOL_ADDRESS = "35"; // 'The liquidity of the reserve needs to be 0'
	string public constant LPC_INVALID_STABLE_DEBT_TOKEN_POOL_ADDRESS = "36"; // 'The liquidity of the reserve needs to be 0'
	string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_POOL_ADDRESS = "37"; // 'The liquidity of the reserve needs to be 0'
	string public constant LPC_INVALID_STABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = "38"; // 'The liquidity of the reserve needs to be 0'
	string public constant LPC_INVALID_VARIABLE_DEBT_TOKEN_UNDERLYING_ADDRESS = "39"; // 'The liquidity of the reserve needs to be 0'
	string public constant LPC_INVALID_ADDRESSES_PROVIDER_ID = "40"; // 'The liquidity of the reserve needs to be 0'
	string public constant LPC_INVALID_CONFIGURATION = "75"; // 'Invalid risk parameters for the reserve'
	string public constant LPC_CALLER_NOT_EMERGENCY_ADMIN = "76"; // 'The caller must be the emergency admin'
	string public constant LPAPR_PROVIDER_NOT_REGISTERED = "41"; // 'Provider is not registered'
	string public constant LPCM_HEALTH_FACTOR_NOT_BELOW_THRESHOLD = "42"; // 'Health factor is not below the threshold'
	string public constant LPCM_COLLATERAL_CANNOT_BE_LIQUIDATED = "43"; // 'The collateral chosen cannot be liquidated'
	string public constant LPCM_SPECIFIED_CURRENCY_NOT_BORROWED_BY_USER = "44"; // 'User did not borrow the specified currency'
	string public constant LPCM_NOT_ENOUGH_LIQUIDITY_TO_LIQUIDATE = "45"; // "There isn't enough liquidity available to liquidate"
	string public constant LPCM_NO_ERRORS = "46"; // 'No errors'
	string public constant LP_INVALID_FLASHLOAN_MODE = "47"; //Invalid flashloan mode selected
	string public constant MATH_MULTIPLICATION_OVERFLOW = "48";
	string public constant MATH_ADDITION_OVERFLOW = "49";
	string public constant MATH_DIVISION_BY_ZERO = "50";
	string public constant RL_LIQUIDITY_INDEX_OVERFLOW = "51"; //  Liquidity index overflows uint128
	string public constant RL_VARIABLE_BORROW_INDEX_OVERFLOW = "52"; //  Variable borrow index overflows uint128
	string public constant RL_LIQUIDITY_RATE_OVERFLOW = "53"; //  Liquidity rate overflows uint128
	string public constant RL_VARIABLE_BORROW_RATE_OVERFLOW = "54"; //  Variable borrow rate overflows uint128
	string public constant RL_STABLE_BORROW_RATE_OVERFLOW = "55"; //  Stable borrow rate overflows uint128
	string public constant CT_INVALID_MINT_AMOUNT = "56"; //invalid amount to mint
	string public constant LP_FAILED_REPAY_WITH_COLLATERAL = "57";
	string public constant CT_INVALID_BURN_AMOUNT = "58"; //invalid amount to burn
	string public constant LP_FAILED_COLLATERAL_SWAP = "60";
	string public constant LP_INVALID_EQUAL_ASSETS_TO_SWAP = "61";
	string public constant LP_REENTRANCY_NOT_ALLOWED = "62";
	string public constant LP_CALLER_MUST_BE_AN_ATOKEN = "63";
	string public constant LP_IS_PAUSED = "64"; // 'Pool is paused'
	string public constant LP_NO_MORE_RESERVES_ALLOWED = "65";
	string public constant LP_INVALID_FLASH_LOAN_EXECUTOR_RETURN = "66";
	string public constant RC_INVALID_LTV = "67";
	string public constant RC_INVALID_LIQ_THRESHOLD = "68";
	string public constant RC_INVALID_LIQ_BONUS = "69";
	string public constant RC_INVALID_DECIMALS = "70";
	string public constant RC_INVALID_RESERVE_FACTOR = "71";
	string public constant LPAPR_INVALID_ADDRESSES_PROVIDER_ID = "72";
	string public constant VL_INCONSISTENT_FLASHLOAN_PARAMS = "73";
	string public constant LP_INCONSISTENT_PARAMS_LENGTH = "74";
	string public constant UL_INVALID_INDEX = "77";
	string public constant LP_NOT_CONTRACT = "78";
	string public constant SDT_STABLE_DEBT_OVERFLOW = "79";
	string public constant SDT_BURN_EXCEEDS_BALANCE = "80";

	/**
	 * @dev Custom Radiant codes added +200 to avoid conflicts with the AaveV2/V3 ones
	 * @custom:borrow-and-supply-caps
	 */
	string public constant INVALID_BORROW_CAP = "201"; // Invalid borrow cap value
	string public constant INVALID_SUPPLY_CAP = "202"; // Invalid supply cap value
	string public constant BORROW_CAP_EXCEEDED = "203"; // Borrow cap is exceeded
	string public constant SUPPLY_CAP_EXCEEDED = "204"; // Supply cap is exceeded

	enum CollateralManagerErrors {
		NO_ERROR,
		NO_COLLATERAL_AVAILABLE,
		COLLATERAL_CANNOT_BE_LIQUIDATED,
		CURRRENCY_NOT_BORROWED,
		HEALTH_FACTOR_ABOVE_THRESHOLD,
		NOT_ENOUGH_LIQUIDITY,
		NO_ACTIVE_RESERVE,
		HEALTH_FACTOR_LOWER_THAN_LIQUIDATION_THRESHOLD,
		INVALID_EQUAL_ASSETS_TO_SWAP,
		FROZEN_RESERVE
	}
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.12;

/**
 * @title IPriceOracleGetter interface
 * @notice Interface for the Aave price oracle.
 **/

interface IPriceOracleGetter {
	/**
	 * @dev returns the asset price in ETH
	 * @param asset the address of the asset
	 * @return the ETH price of the asset
	 **/
	function getAssetPrice(address asset) external view returns (uint256);
}

File 23 of 27 : DataTypes.sol
// SPDX-License-Identifier: AGPL-3.0
pragma solidity 0.8.12;

library DataTypes {
	// refer to the whitepaper, section 1.1 basic concepts for a formal description of these properties.
	struct ReserveData {
		//stores the reserve configuration
		ReserveConfigurationMap configuration;
		//the liquidity index. Expressed in ray
		uint128 liquidityIndex;
		//variable borrow index. Expressed in ray
		uint128 variableBorrowIndex;
		//the current supply rate. Expressed in ray
		uint128 currentLiquidityRate;
		//the current variable borrow rate. Expressed in ray
		uint128 currentVariableBorrowRate;
		//the current stable borrow rate. Expressed in ray
		uint128 currentStableBorrowRate;
		uint40 lastUpdateTimestamp;
		//tokens addresses
		address aTokenAddress;
		address stableDebtTokenAddress;
		address variableDebtTokenAddress;
		//address of the interest rate strategy
		address interestRateStrategyAddress;
		//the id of the reserve. Represents the position in the list of the active reserves
		uint8 id;
	}

	struct ReserveConfigurationMap {
		//bit 0-15: LTV
		//bit 16-31: Liq. threshold
		//bit 32-47: Liq. bonus
		//bit 48-55: Decimals
		//bit 56: Reserve is active
		//bit 57: reserve is frozen
		//bit 58: borrowing is enabled
		//bit 59: stable rate borrowing enabled
		//bit 60-63: reserved
		//bit 64-79: reserve factor
		///@custom:borrow-and-supply-caps
		//bit 80-115 borrow cap in whole tokens, borrowCap == 0 => no cap
		//bit 116-151 supply cap in whole tokens, supplyCap == 0 => no cap
		uint256 data;
	}

	struct UserConfigurationMap {
		uint256 data;
	}

	enum InterestRateMode {
		NONE,
		STABLE,
		VARIABLE
	}
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.12;

interface IScaledBalanceToken {
	/**
	 * @dev Returns the scaled balance of the user. The scaled balance is the sum of all the
	 * updated stored balance divided by the reserve's liquidity index at the moment of the update
	 * @param user The user whose balance is calculated
	 * @return The scaled balance of the user
	 **/
	function scaledBalanceOf(address user) external view returns (uint256);

	/**
	 * @dev Returns the scaled balance of the user and the scaled total supply.
	 * @param user The address of the user
	 * @return The scaled balance of the user
	 * @return The scaled balance and the scaled total supply
	 **/
	function getScaledUserBalanceAndSupply(address user) external view returns (uint256, uint256);

	/**
	 * @dev Returns the scaled total supply of the variable debt token. Represents sum(debt/index)
	 * @return The scaled total supply
	 **/
	function scaledTotalSupply() external view returns (uint256);
}

File 25 of 27 : IInitializableAToken.sol
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.12;

import {ILendingPool} from "./ILendingPool.sol";
import {IAaveIncentivesController} from "./IAaveIncentivesController.sol";

/**
 * @title IInitializableAToken
 * @notice Interface for the initialize function on AToken
 * @author Aave
 **/
interface IInitializableAToken {
	/**
	 * @dev Emitted when an aToken is initialized
	 * @param underlyingAsset The address of the underlying asset
	 * @param pool The address of the associated lending pool
	 * @param treasury The address of the treasury
	 * @param incentivesController The address of the incentives controller for this aToken
	 * @param aTokenDecimals the decimals of the underlying
	 * @param aTokenName the name of the aToken
	 * @param aTokenSymbol the symbol of the aToken
	 * @param params A set of encoded parameters for additional initialization
	 **/
	event Initialized(
		address indexed underlyingAsset,
		address indexed pool,
		address treasury,
		address incentivesController,
		uint8 aTokenDecimals,
		string aTokenName,
		string aTokenSymbol,
		bytes params
	);

	/**
	 * @dev Initializes the aToken
	 * @param pool The address of the lending pool where this aToken will be used
	 * @param treasury The address of the Aave treasury, receiving the fees on this aToken
	 * @param underlyingAsset The address of the underlying asset of this aToken (E.g. WETH for aWETH)
	 * @param incentivesController The smart contract managing potential incentives distribution
	 * @param aTokenDecimals The decimals of the aToken, same as the underlying asset's
	 * @param aTokenName The name of the aToken
	 * @param aTokenSymbol The symbol of the aToken
	 */
	function initialize(
		ILendingPool pool,
		address treasury,
		address underlyingAsset,
		IAaveIncentivesController incentivesController,
		uint8 aTokenDecimals,
		string calldata aTokenName,
		string calldata aTokenSymbol,
		bytes calldata params
	) external;
}

// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.12;
pragma experimental ABIEncoderV2;

interface IAaveIncentivesController {
	event RewardsAccrued(address indexed user, uint256 amount);

	event RewardsClaimed(address indexed user, address indexed to, uint256 amount);

	event RewardsClaimed(address indexed user, address indexed to, address indexed claimer, uint256 amount);

	event ClaimerSet(address indexed user, address indexed claimer);

	/*
	 * @dev Returns the configuration of the distribution for a certain asset
	 * @param asset The address of the reference asset of the distribution
	 * @return The asset index, the emission per second and the last updated timestamp
	 **/
	function getAssetData(address asset) external view returns (uint256, uint256, uint256);

	/**
	 * @dev Whitelists an address to claim the rewards on behalf of another address
	 * @param user The address of the user
	 * @param claimer The address of the claimer
	 */
	function setClaimer(address user, address claimer) external;

	/**
	 * @dev Returns the whitelisted claimer for a certain address (0x0 if not set)
	 * @param user The address of the user
	 * @return The claimer address
	 */
	function getClaimer(address user) external view returns (address);

	/**
	 * @dev Configure assets for a certain rewards emission
	 * @param assets The assets to incentivize
	 * @param emissionsPerSecond The emission for each asset
	 */
	function configureAssets(address[] calldata assets, uint256[] calldata emissionsPerSecond) external;

	/**
	 * @dev Called by the corresponding asset on any update that affects the rewards distribution
	 * @param user The address of the user
	 **/
	function handleActionBefore(address user) external;

	/**
	 * @dev Called by the corresponding asset on any update that affects the rewards distribution
	 * @param user The address of the user
	 * @param userBalance The balance of the user of the asset in the lending pool
	 * @param totalSupply The total supply of the asset in the lending pool
	 **/
	function handleActionAfter(address user, uint256 userBalance, uint256 totalSupply) external;

	/**
	 * @dev Returns the total of rewards of an user, already accrued + not yet accrued
	 * @param user The address of the user
	 * @return The rewards
	 **/
	function getRewardsBalance(address[] calldata assets, address user) external view returns (uint256);

	/**
	 * @dev Claims reward for an user, on all the assets of the lending pool, accumulating the pending rewards
	 * @param amount Amount of rewards to claim
	 * @param to Address that will be receiving the rewards
	 * @return Rewards claimed
	 **/
	function claimRewards(address[] calldata assets, uint256 amount, address to) external returns (uint256);

	/**
	 * @dev Claims reward for an user on behalf, on all the assets of the lending pool, accumulating the pending rewards. The caller must
	 * be whitelisted via "allowClaimOnBehalf" function by the RewardsAdmin role manager
	 * @param amount Amount of rewards to claim
	 * @param user Address to check and claim rewards
	 * @param to Address that will be receiving the rewards
	 * @return Rewards claimed
	 **/
	function claimRewardsOnBehalf(
		address[] calldata assets,
		uint256 amount,
		address user,
		address to
	) external returns (uint256);

	/**
	 * @dev returns the unclaimed rewards of the user
	 * @param user the address of the user
	 * @return the unclaimed user rewards
	 */
	function getUserUnclaimedRewards(address user) external view returns (uint256);

	/**
	 * @dev returns the unclaimed rewards of the user
	 * @param user the address of the user
	 * @param asset The asset to incentivize
	 * @return the user index for the asset
	 */
	function getUserAssetData(address user, address asset) external view returns (uint256);

	/**
	 * @dev for backward compatibility with previous implementation of the Incentives controller
	 */
	function REWARD_TOKEN() external view returns (address);

	/**
	 * @dev for backward compatibility with previous implementation of the Incentives controller
	 */
	function PRECISION() external view returns (uint8);

	/**
	 * @dev Gets the distribution end timestamp of the emissions
	 */
	function DISTRIBUTION_END() external view returns (uint256);
}

// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)

pragma solidity ^0.8.1;

/**
 * @dev Collection of functions related to the address type
 */
library AddressUpgradeable {
    /**
     * @dev Returns true if `account` is a contract.
     *
     * [IMPORTANT]
     * ====
     * It is unsafe to assume that an address for which this function returns
     * false is an externally-owned account (EOA) and not a contract.
     *
     * Among others, `isContract` will return false for the following
     * types of addresses:
     *
     *  - an externally-owned account
     *  - a contract in construction
     *  - an address where a contract will be created
     *  - an address where a contract lived, but was destroyed
     *
     * Furthermore, `isContract` will also return true if the target contract within
     * the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
     * which only has an effect at the end of a transaction.
     * ====
     *
     * [IMPORTANT]
     * ====
     * You shouldn't rely on `isContract` to protect against flash loan attacks!
     *
     * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
     * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
     * constructor.
     * ====
     */
    function isContract(address account) internal view returns (bool) {
        // This method relies on extcodesize/address.code.length, which returns 0
        // for contracts in construction, since the code is only stored at the end
        // of the constructor execution.

        return account.code.length > 0;
    }

    /**
     * @dev Replacement for Solidity's `transfer`: sends `amount` wei to
     * `recipient`, forwarding all available gas and reverting on errors.
     *
     * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
     * of certain opcodes, possibly making contracts go over the 2300 gas limit
     * imposed by `transfer`, making them unable to receive funds via
     * `transfer`. {sendValue} removes this limitation.
     *
     * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
     *
     * IMPORTANT: because control is transferred to `recipient`, care must be
     * taken to not create reentrancy vulnerabilities. Consider using
     * {ReentrancyGuard} or the
     * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
     */
    function sendValue(address payable recipient, uint256 amount) internal {
        require(address(this).balance >= amount, "Address: insufficient balance");

        (bool success, ) = recipient.call{value: amount}("");
        require(success, "Address: unable to send value, recipient may have reverted");
    }

    /**
     * @dev Performs a Solidity function call using a low level `call`. A
     * plain `call` is an unsafe replacement for a function call: use this
     * function instead.
     *
     * If `target` reverts with a revert reason, it is bubbled up by this
     * function (like regular Solidity function calls).
     *
     * Returns the raw returned data. To convert to the expected return value,
     * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
     *
     * Requirements:
     *
     * - `target` must be a contract.
     * - calling `target` with `data` must not revert.
     *
     * _Available since v3.1._
     */
    function functionCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, "Address: low-level call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
     * `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        return functionCallWithValue(target, data, 0, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but also transferring `value` wei to `target`.
     *
     * Requirements:
     *
     * - the calling contract must have an ETH balance of at least `value`.
     * - the called Solidity function must be `payable`.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
        return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
    }

    /**
     * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
     * with `errorMessage` as a fallback revert reason when `target` reverts.
     *
     * _Available since v3.1._
     */
    function functionCallWithValue(
        address target,
        bytes memory data,
        uint256 value,
        string memory errorMessage
    ) internal returns (bytes memory) {
        require(address(this).balance >= value, "Address: insufficient balance for call");
        (bool success, bytes memory returndata) = target.call{value: value}(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
        return functionStaticCall(target, data, "Address: low-level static call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a static call.
     *
     * _Available since v3.3._
     */
    function functionStaticCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        (bool success, bytes memory returndata) = target.staticcall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
        return functionDelegateCall(target, data, "Address: low-level delegate call failed");
    }

    /**
     * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
     * but performing a delegate call.
     *
     * _Available since v3.4._
     */
    function functionDelegateCall(
        address target,
        bytes memory data,
        string memory errorMessage
    ) internal returns (bytes memory) {
        (bool success, bytes memory returndata) = target.delegatecall(data);
        return verifyCallResultFromTarget(target, success, returndata, errorMessage);
    }

    /**
     * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
     * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
     *
     * _Available since v4.8._
     */
    function verifyCallResultFromTarget(
        address target,
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal view returns (bytes memory) {
        if (success) {
            if (returndata.length == 0) {
                // only check isContract if the call was successful and the return data is empty
                // otherwise we already know that it was a contract
                require(isContract(target), "Address: call to non-contract");
            }
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    /**
     * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
     * revert reason or using the provided one.
     *
     * _Available since v4.3._
     */
    function verifyCallResult(
        bool success,
        bytes memory returndata,
        string memory errorMessage
    ) internal pure returns (bytes memory) {
        if (success) {
            return returndata;
        } else {
            _revert(returndata, errorMessage);
        }
    }

    function _revert(bytes memory returndata, string memory errorMessage) private pure {
        // Look for revert reason and bubble it up if present
        if (returndata.length > 0) {
            // The easiest way to bubble the revert reason is using memory via assembly
            /// @solidity memory-safe-assembly
            assembly {
                let returndata_size := mload(returndata)
                revert(add(32, returndata), returndata_size)
            }
        } else {
            revert(errorMessage);
        }
    }
}

Settings
{
  "remappings": [
    "@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
    "@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "@uniswap/v2-core/contracts/=lib/uniswap-v2-core/contracts/",
    "@layerzerolabs/solidity-examples/contracts/=lib/layer-zero/contracts/",
    "@radiant-v2-core/interfaces/=lib/radiant-v2-core/contracts/main/interfaces/",
    "@radiant-v2-core/lending/=lib/radiant-v2-core/contracts/main/lending/",
    "@radiant-v2-core/radiant/=lib/radiant-v2-core/contracts/main/radiant/",
    "@radiant-v2-core/mocks/=lib/radiant-v2-core/contracts/main/test/",
    "@balancer-labs/v2-interfaces/=lib/balancer-v2-monorepo/pkg/interfaces/",
    "@bgd-labs-stk-v3/contracts/=lib/bgd-labs-stk-v3/src/contracts/",
    "aave-token-v3/=lib/bgd-labs-stk-v3/lib/aave-token-v3/src/",
    "@aave/core-v3/=lib/bgd-labs-stk-v3/lib/aave-address-book/lib/aave-v3-core/",
    "@aave/periphery-v3/=lib/bgd-labs-stk-v3/lib/aave-address-book/lib/aave-v3-periphery/",
    "aave-address-book/=lib/bgd-labs-stk-v3/lib/aave-address-book/src/",
    "aave-helpers/=lib/bgd-labs-stk-v3/lib/aave-helpers/",
    "aave-token-v2/=lib/bgd-labs-stk-v3/lib/aave-token-v3/lib/aave-token-v2/contracts/",
    "aave-v3-core/=lib/bgd-labs-stk-v3/lib/aave-address-book/lib/aave-v3-core/",
    "aave-v3-periphery/=lib/bgd-labs-stk-v3/lib/aave-address-book/lib/aave-v3-periphery/",
    "balancer-v2-monorepo/=lib/balancer-v2-monorepo/",
    "bgd-labs-stk-v3/=lib/bgd-labs-stk-v3/",
    "ds-test/=lib/forge-std/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
    "forge-std/=lib/forge-std/src/",
    "governance-crosschain-bridges/=lib/bgd-labs-stk-v3/lib/aave-helpers/lib/governance-crosschain-bridges/",
    "layer-zero/=lib/layer-zero/contracts/",
    "openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/",
    "openzeppelin/=lib/openzeppelin-contracts-upgradeable/contracts/",
    "radiant-v2-core/=lib/radiant-v2-core/contracts/",
    "solidity-utils/=lib/bgd-labs-stk-v3/lib/aave-helpers/lib/solidity-utils/",
    "uniswap-v2-core/=lib/uniswap-v2-core/contracts/"
  ],
  "optimizer": {
    "enabled": true,
    "runs": 1000
  },
  "metadata": {
    "useLiteralContent": false,
    "bytecodeHash": "ipfs"
  },
  "outputSelection": {
    "*": {
      "*": [
        "evm.bytecode",
        "evm.deployedBytecode",
        "devdoc",
        "userdoc",
        "metadata",
        "abi"
      ]
    }
  },
  "evmVersion": "london",
  "viaIR": false,
  "libraries": {}
}

Contract Security Audit

Contract ABI

API
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AddressNotApproved","type":"error"},{"inputs":[],"name":"AddressZero","type":"error"},{"inputs":[],"name":"DexSwapFailed","type":"error"},{"inputs":[],"name":"DuplicateOutputToken","type":"error"},{"inputs":[],"name":"InputTokenConfigLengthMismatch","type":"error"},{"inputs":[],"name":"InvalidInputData","type":"error"},{"inputs":[],"name":"InvalidLendingPool","type":"error"},{"inputs":[],"name":"InvalidSwapStrategy","type":"error"},{"inputs":[],"name":"NativeAssetsNotSupported","type":"error"},{"inputs":[],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"OutputTokenBalanceOutOfRange","type":"error"},{"inputs":[],"name":"OutputTokenConfigLengthMismatch","type":"error"},{"inputs":[],"name":"PercentageMismatch","type":"error"},{"inputs":[],"name":"ReceivedLessThanMinOutput","type":"error"},{"inputs":[],"name":"TokenNotPresent","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newCoreLendingPool","type":"address"}],"name":"CoreLendingPoolUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"contract IOracleRouter","name":"oracle","type":"address"}],"name":"InputTokenAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"}],"name":"InputTokenRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"newMFD","type":"address"}],"name":"MFDUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"outputTokensLength","type":"uint256"}],"name":"OutputTokensConfigUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Recovered","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"SetApprovedSwapAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"lendingPool","type":"address"},{"indexed":false,"internalType":"bool","name":"status","type":"bool"}],"name":"SetLendingPoolWhitelist","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"isWhitelisted","type":"bool"}],"name":"SetWhitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"TokensAcquired","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"contract IOracleRouter","name":"_inputTokenOracle","type":"address"}],"name":"addInputToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvedLendingPools","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"approvedSwapAddresses","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"uint256","name":"minOutput","type":"uint256"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"enum RevenueManagement.SwapStrategies","name":"swapStrategy","type":"uint8"}],"internalType":"struct RevenueManagement.SwapInput[]","name":"swapInput","type":"tuple[]"}],"name":"computeInputValue","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"coreLendingPool","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"depositToCoreLendingPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_mfd","type":"address"},{"internalType":"address","name":"_coreLendingPool","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"inputTokenOracle","outputs":[{"internalType":"contract IOracleRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_address","type":"address"}],"name":"isApprovedSwapAddress","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_inputToken","type":"address"}],"name":"isInputTokenValid","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"isWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mfd","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"outputTokenConfigs","outputs":[{"internalType":"uint256","name":"maximumSlippage","type":"uint256"},{"internalType":"uint256","name":"percentage","type":"uint256"},{"internalType":"address","name":"priceOracle","type":"address"},{"internalType":"contract IAToken","name":"rTokenCore","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"outputTokens","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenAmount","type":"uint256"}],"name":"recoverERC20","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_inputToken","type":"address"}],"name":"removeInputToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"bool","name":"_approved","type":"bool"}],"name":"setApprovedSwapAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newCoreLendingPool","type":"address"}],"name":"setCoreLendingPool","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"lendingPool","type":"address"},{"internalType":"bool","name":"status","type":"bool"}],"name":"setLendingPoolWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_newMFD","type":"address"}],"name":"setMFD","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address[]","name":"_outputTokens","type":"address[]"},{"components":[{"internalType":"uint256","name":"maximumSlippage","type":"uint256"},{"internalType":"uint256","name":"percentage","type":"uint256"},{"internalType":"address","name":"priceOracle","type":"address"},{"internalType":"contract IAToken","name":"rTokenCore","type":"address"}],"internalType":"struct RevenueManagement.OutputTokenConfig[]","name":"_configs","type":"tuple[]"}],"name":"setOutputTokensConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"},{"internalType":"bool","name":"_isWhitelisted","type":"bool"}],"name":"setWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"},{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"uint256","name":"minOutput","type":"uint256"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"enum RevenueManagement.SwapStrategies","name":"swapStrategy","type":"uint8"}],"internalType":"struct RevenueManagement.SwapInput[]","name":"swapInput","type":"tuple[]"}],"name":"swapTokens","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IAToken[]","name":"_rTokens","type":"address[]"},{"internalType":"uint256[]","name":"_amounts","type":"uint256[]"}],"name":"unwrapRToken","outputs":[],"stateMutability":"nonpayable","type":"function"}]

0x60806040523480156200001157600080fd5b506200001c62000022565b620000e3565b600054610100900460ff16156200008f5760405162461bcd60e51b815260206004820152602760248201527f496e697469616c697a61626c653a20636f6e747261637420697320696e697469604482015266616c697a696e6760c81b606482015260840160405180910390fd5b60005460ff90811614620000e1576000805460ff191660ff9081179091556040519081527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b565b612f2380620000f36000396000f3fe608060405234801561001057600080fd5b50600436106101da5760003560e01c80638456cb5911610104578063b127e145116100a2578063fb02be4f11610071578063fb02be4f146104a7578063fb14cbd4146104ba578063fc4872bf146104cd578063fedf2521146104e057600080fd5b8063b127e145146103fd578063bdf81d0b14610410578063ebb2549014610423578063f2fde38b1461049457600080fd5b80638faaa288116100de5780638faaa2881461039b5780639ef6463c146103ae578063a50cb986146103d7578063b0c634ee146103ea57600080fd5b80638456cb591461036f5780638980f11f146103775780638da5cb5b1461038a57600080fd5b80634be1fe281161017c5780636c9a7d051161014b5780636c9a7d051461031e578063715018a61461033157806371d81fec14610339578063734507001461034c57600080fd5b80634be1fe28146102c157806353d6fd59146102d45780635c0e6d87146102e75780635c975abb1461031357600080fd5b80633c17b7d3116101b85780633c17b7d3146102575780633f4ba83a14610278578063485cc955146102805780634932bf491461029357600080fd5b80631a2d87c7146101df57806328c34c08146101f45780633af32abf14610224575b600080fd5b6101f26101ed3660046128c7565b610503565b005b6102076102023660046128f3565b610519565b6040516001600160a01b0390911681526020015b60405180910390f35b61024761023236600461290c565b60ce6020526000908152604090205460ff1681565b604051901515815260200161021b565b61026a610265366004612975565b610543565b60405190815260200161021b565b6101f2610773565b6101f261028e3660046129b7565b610785565b6102476102a136600461290c565b6001600160a01b03908116600090815260cd602052604090205416151590565b6101f26102cf3660046129f0565b610932565b6101f26102e2366004612a98565b610bdb565b6102476102f536600461290c565b6001600160a01b0316600090815260d0602052604090205460ff1690565b60655460ff16610247565b6101f261032c36600461290c565b610c6a565b6101f2610cee565b60ca54610207906001600160a01b031681565b61024761035a36600461290c565b60d06020526000908152604090205460ff1681565b6101f2610d00565b6101f26103853660046128c7565b610d10565b6033546001600160a01b0316610207565b6101f26103a9366004612a98565b610d22565b6102076103bc36600461290c565b60cd602052600090815260409020546001600160a01b031681565b6101f26103e53660046129b7565b610da9565b60c954610207906001600160a01b031681565b6101f261040b366004612a98565b610e5f565b6101f261041e366004612975565b610ee6565b61046561043136600461290c565b60cc602052600090815260409020805460018201546002830154600390930154919290916001600160a01b03918216911684565b6040805194855260208501939093526001600160a01b039182169284019290925216606082015260800161021b565b6101f26104a236600461290c565b61158f565b6101f26104b536600461290c565b61161f565b6101f26104c836600461290c565b6116c7565b6101f26104db366004612ac6565b611744565b6102476104ee36600461290c565b60cf6020526000908152604090205460ff1681565b61050b611a04565b6105158282611a5e565b5050565b60cb818154811061052957600080fd5b6000918252602090912001546001600160a01b0316905081565b600080805b8381101561076957600060cd600087878581811061056857610568612b32565b905060200281019061057a9190612b48565b61058b90606081019060400161290c565b6001600160a01b0390811682526020820192909252604001600020541663b3596f078787858181106105bf576105bf612b32565b90506020028101906105d19190612b48565b6105e290606081019060400161290c565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561063e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106629190612b68565b9050600086868481811061067857610678612b32565b905060200281019061068a9190612b48565b61069b90606081019060400161290c565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106fc9190612b81565b60ff169050600061070e82600a612c9e565b88888681811061072057610720612b32565b90506020028101906107329190612b48565b61073d903585612caa565b6107479190612cc9565b90506107538186612ceb565b94505050508061076290612d03565b9050610548565b5090505b92915050565b61077b611a04565b610783611b8e565b565b600054610100900460ff16158080156107a55750600054600160ff909116105b806107bf5750303b1580156107bf575060005460ff166001145b6108365760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084015b60405180910390fd5b6000805460ff191660011790558015610859576000805461ff0019166101001790555b6001600160a01b03831661088057604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b0382166108a757604051639fabe1c160e01b815260040160405180910390fd5b60c980546001600160a01b038086166001600160a01b03199283161790925560ca8054928516929091169190911790556108df611be0565b6108e7611c53565b801561092d576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050565b61093a611a04565b828114610973576040517fe7fa722b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b83811015610a4f57600061098b826001612ceb565b90505b84811015610a3e578585828181106109a8576109a8612b32565b90506020020160208101906109bd919061290c565b6001600160a01b03168686848181106109d8576109d8612b32565b90506020020160208101906109ed919061290c565b6001600160a01b03161415610a2e576040517f0d037f8d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a3781612d03565b905061098e565b50610a4881612d03565b9050610976565b50610a5c60cb6000612880565b6000805b82811015610b655760cb868683818110610a7c57610a7c612b32565b9050602002016020810190610a91919061290c565b81546001810183556000928352602090922090910180546001600160a01b0319166001600160a01b03909216919091179055838382818110610ad557610ad5612b32565b90506080020160cc6000888885818110610af157610af1612b32565b9050602002016020810190610b06919061290c565b6001600160a01b031681526020810191909152604001600020610b298282612d1e565b905050838382818110610b3e57610b3e612b32565b9050608002016020013582610b539190612ceb565b9150610b5e81612d03565b9050610a60565b508061271014610ba1576040517f0477518700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040518481527f8d376a4e1d8870f81c356be9c126b31c302f0429d5423a7a1243f646f0eba5949060200160405180910390a15050505050565b610be3611a04565b6001600160a01b038216610c0a57604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038216600081815260ce6020908152604091829020805460ff191685151590811790915591519182527f26742d25b283cf51a0e3c4183d934871ed96d1bd33cf40706f87a94f29f686ac91015b60405180910390a25050565b610c72611a04565b6001600160a01b038116610c9957604051639fabe1c160e01b815260040160405180910390fd5b60ca80546001600160a01b0319166001600160a01b0383169081179091556040519081527f6930d1412afb621c8b8d5ce398e75d8d8bd0458ca90d3424958e502dfeae7875906020015b60405180910390a150565b610cf6611a04565b6107836000611cc6565b610d08611a04565b610783611d18565b610d18611a04565b6105158282611d55565b610d2a611a04565b6001600160a01b038216610d5157604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038216600081815260cf6020908152604091829020805460ff191685151590811790915591519182527f682f9c70bad742209244948af878d200ac46ca830c40d244b76967262347b4cb9101610c5e565b610db1611a04565b6001600160a01b038216610dd857604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038116610dff57604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b03828116600081815260cd602090815260409182902080546001600160a01b0319169486169485179055905192835290917ff94898767cdccad6f60acbffed75166708ff54b47f2822abb5476352c037787a9101610c5e565b610e67611a04565b6001600160a01b038216610e8e57604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038216600081815260d06020908152604091829020805460ff191685151590811790915591519182527f4adc78dec192f73e22bd7c1330e489f5fe079836d3c097e9c2d88b862ec8b6ce9101610c5e565b610eee611da4565b33600090815260ce602052604090205460ff16610f1e5760405163ea8e4eb560e01b815260040160405180910390fd5b610f26611df7565b6000610f328383610543565b60cb5490915060009067ffffffffffffffff811115610f5357610f53612d88565b604051908082528060200260200182016040528015610f7c578160200160208202803683370190505b50905060005b60cb548110156110415760cb8181548110610f9f57610f9f612b32565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610ff0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110149190612b68565b82828151811061102657611026612b32565b602090810291909101015261103a81612d03565b9050610f82565b5060005b838110156111a157600185858381811061106157611061612b32565b90506020028101906110739190612b48565b6110849060c081019060a001612db4565b600181111561109557611095612d9e565b141561115f5761115a8585838181106110b0576110b0612b32565b90506020028101906110c29190612b48565b6110d390606081019060400161290c565b8686848181106110e5576110e5612b32565b90506020028101906110f79190612b48565b3587878581811061110a5761110a612b32565b905060200281019061111c9190612b48565b6060013588888681811061113257611132612b32565b90506020028101906111449190612b48565b611152906020810190612dd5565b6102f5611e51565b611191565b6040517f74ac268b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61119a81612d03565b9050611045565b5060005b60cb5481101561158257600060cc600060cb84815481106111c8576111c8612b32565b60009182526020808320909101546001600160a01b03908116845283820194909452604092830182208351608081018552815481526001820154928101929092526002810154851693820184905260030154909316606084015260cb8054939450909263b3596f0791908690811061124257611242612b32565b60009182526020909120015460405160e083901b7fffffffff000000000000000000000000000000000000000000000000000000001681526001600160a01b039091166004820152602401602060405180830381865afa1580156112aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ce9190612b68565b9050600060cb84815481106112e5576112e5612b32565b60009182526020918290200154604080517f313ce56700000000000000000000000000000000000000000000000000000000815290516001600160a01b039092169263313ce567926004808401938290030181865afa15801561134c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113709190612b81565b9050600061138b84602001518861204f90919063ffffffff16565b905060008361139b84600a612e1c565b6113a59084612caa565b6113af9190612cc9565b905060008787815181106113c5576113c5612b32565b602002602001015160cb88815481106113e0576113e0612b32565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015611431573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114559190612b68565b61145f9190612e2b565b90508061147157505050505050611572565b60cb878154811061148457611484612b32565b600091825260209182902001546040518381526001600160a01b03909116917f58b0b4a0cc56da318e6d4c63aebe81ac4a2e221518b74c4de26cf62e216ba3bc910160405180910390a285516114e66114df82612710612e2b565b849061204f565b821015801561150357506114ff6114df82612710612ceb565b8211155b611539576040517faf587d6000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61156a60cb898154811061154f5761154f612b32565b6000918252602090912001546001600160a01b031683611a5e565b505050505050505b61157b81612d03565b90506111a5565b5050506105156001609755565b611597611a04565b6001600160a01b0381166116135760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f6464726573730000000000000000000000000000000000000000000000000000606482015260840161082d565b61161c81611cc6565b50565b611627611a04565b6001600160a01b03818116600090815260cd602052604090205416611678576040517f41f2a4a300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038116600081815260cd602052604080822080546001600160a01b0319169055517fbbdac506546a1c601761a0bf8dc65e172d91ba9b6caec595e1251851c0a7d04d9190a250565b6116cf611a04565b6001600160a01b0381166116f657604051639fabe1c160e01b815260040160405180910390fd5b60c980546001600160a01b0319166001600160a01b0383169081179091556040519081527fda698b594605a93dd68e126773558b6a9858df49f45d3854adbb50bdb6d3379590602001610ce3565b33600090815260ce602052604090205460ff166117745760405163ea8e4eb560e01b815260040160405180910390fd5b61177c611df7565b8281146117b5576040517f27dbe09300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b838110156119f35760008585838181106117d4576117d4612b32565b90506020020160208101906117e9919061290c565b6001600160a01b031663b16a19de6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611826573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184a9190612e42565b9050600084848481811061186057611860612b32565b905060200201359050600087878581811061187d5761187d612b32565b9050602002016020810190611892919061290c565b6001600160a01b0316637535d2466040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f39190612e42565b6001600160a01b038116600090815260cf602052604090205490915060ff16611948576040517fd8cad67600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f69328dec0000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152602482018490523060448301528291908216906369328dec906064016020604051808303816000875af11580156119b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119dd9190612b68565b5050505050806119ec90612d03565b90506117b8565b506119fe6001609755565b50505050565b6033546001600160a01b031633146107835760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161082d565b60ca5460405163095ea7b360e01b81526001600160a01b0391821660048201819052602482018490529184169063095ea7b3906044016020604051808303816000875af1158015611ab3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ad79190612e5f565b506040517fe8eda9df0000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152602482018490523060448301526000606483015282169063e8eda9df90608401600060405180830381600087803b158015611b4857600080fd5b505af1158015611b5c573d6000803e3d6000fd5b505060c9546001600160a01b03868116600090815260cc602052604090206003015461092d9450811692501684612118565b611b966121c1565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600054610100900460ff16611c4b5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161082d565b610783612213565b600054610100900460ff16611cbe5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161082d565b610783612287565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b611d20611da4565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611bc33390565b611d696001600160a01b0383163383612118565b816001600160a01b03167f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa2882604051610c5e91815260200190565b60655460ff16156107835760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a2070617573656400000000000000000000000000000000604482015260640161082d565b60026097541415611e4a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161082d565b6002609755565b6000611e9284848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506122fe92505050565b805190915015611ece576040517f9513f45400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611edf81602001518363ffffffff16565b611f15576040517fcafd331600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040810151611f2f906001600160a01b03891690886124ad565b600080600083602001516001600160a01b03168460600151604051611f549190612ea8565b6000604051808303816000865af19150503d8060008114611f91576040519150601f19603f3d011682016040523d82523d6000602084013e611f96565b606091505b50915091508115611fbc5780806020019051810190611fb59190612b68565b9250611fee565b6040517fb52a547f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b87831015612028576040517f97a48cb000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040840151612043906001600160a01b038c169060006124ad565b50505050505050505050565b600082158061205c575081155b156120695750600061076d565b816120776002612710612cc9565b61208390600019612e2b565b61208d9190612cc9565b8311156040518060400160405280600281526020017f3438000000000000000000000000000000000000000000000000000000000000815250906120e45760405162461bcd60e51b815260040161082d9190612eba565b506127106120f3600282612cc9565b6120fd8486612caa565b6121079190612ceb565b6121119190612cc9565b9392505050565b6040516001600160a01b03831660248201526044810182905261092d9084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915261254d565b60655460ff166107835760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f7420706175736564000000000000000000000000604482015260640161082d565b600054610100900460ff1661227e5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161082d565b61078333611cc6565b600054610100900460ff166122f25760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161082d565b6065805460ff19169055565b604080516080810182526000808252602082018190529181019190915260608082015260a08251101561235d576040517f7016bd9b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516080810182526000808252602080830182815283850192835260608085018190529187015194870151918701518585526001600160a01b0380841690925290811690925285519293929091906123b99060a090612e2b565b67ffffffffffffffff8111156123d1576123d1612d88565b6040519080825280601f01601f1916602001820160405280156123fb576020820181803683370190505b506060850152855160a05b818110156124a15787818151811061242057612420612b32565b016020015160608701517fff000000000000000000000000000000000000000000000000000000000000009091169061245a60a084612e2b565b8151811061246a5761246a612b32565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600101612406565b50939695505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663095ea7b360e01b1790526125138482612635565b6119fe576040516001600160a01b03841660248201526000604482015261254790859063095ea7b360e01b9060640161215d565b6119fe84825b60006125a2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166126dc9092919063ffffffff16565b90508051600014806125c35750808060200190518101906125c39190612e5f565b61092d5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161082d565b6000806000846001600160a01b0316846040516126529190612ea8565b6000604051808303816000865af19150503d806000811461268f576040519150601f19603f3d011682016040523d82523d6000602084013e612694565b606091505b50915091508180156126be5750805115806126be5750808060200190518101906126be9190612e5f565b80156126d357506001600160a01b0385163b15155b95945050505050565b60606126eb84846000856126f3565b949350505050565b60608247101561276b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161082d565b600080866001600160a01b031685876040516127879190612ea8565b60006040518083038185875af1925050503d80600081146127c4576040519150601f19603f3d011682016040523d82523d6000602084013e6127c9565b606091505b50915091506127da878383876127e5565b979650505050505050565b6060831561285157825161284a576001600160a01b0385163b61284a5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161082d565b50816126eb565b6126eb83838151156128665781518083602001fd5b8060405162461bcd60e51b815260040161082d9190612eba565b508054600082559060005260206000209081019061161c91905b808211156128ae576000815560010161289a565b5090565b6001600160a01b038116811461161c57600080fd5b600080604083850312156128da57600080fd5b82356128e5816128b2565b946020939093013593505050565b60006020828403121561290557600080fd5b5035919050565b60006020828403121561291e57600080fd5b8135612111816128b2565b60008083601f84011261293b57600080fd5b50813567ffffffffffffffff81111561295357600080fd5b6020830191508360208260051b850101111561296e57600080fd5b9250929050565b6000806020838503121561298857600080fd5b823567ffffffffffffffff81111561299f57600080fd5b6129ab85828601612929565b90969095509350505050565b600080604083850312156129ca57600080fd5b82356129d5816128b2565b915060208301356129e5816128b2565b809150509250929050565b60008060008060408587031215612a0657600080fd5b843567ffffffffffffffff80821115612a1e57600080fd5b612a2a88838901612929565b90965094506020870135915080821115612a4357600080fd5b818701915087601f830112612a5757600080fd5b813581811115612a6657600080fd5b8860208260071b8501011115612a7b57600080fd5b95989497505060200194505050565b801515811461161c57600080fd5b60008060408385031215612aab57600080fd5b8235612ab6816128b2565b915060208301356129e581612a8a565b60008060008060408587031215612adc57600080fd5b843567ffffffffffffffff80821115612af457600080fd5b612b0088838901612929565b90965094506020870135915080821115612b1957600080fd5b50612b2687828801612929565b95989497509550505050565b634e487b7160e01b600052603260045260246000fd5b6000823560be19833603018112612b5e57600080fd5b9190910192915050565b600060208284031215612b7a57600080fd5b5051919050565b600060208284031215612b9357600080fd5b815160ff8116811461211157600080fd5b634e487b7160e01b600052601160045260246000fd5b600181815b80851115612bf5578160001904821115612bdb57612bdb612ba4565b80851615612be857918102915b93841c9390800290612bbf565b509250929050565b600082612c0c5750600161076d565b81612c195750600061076d565b8160018114612c2f5760028114612c3957612c55565b600191505061076d565b60ff841115612c4a57612c4a612ba4565b50506001821b61076d565b5060208310610133831016604e8410600b8410161715612c78575081810a61076d565b612c828383612bba565b8060001904821115612c9657612c96612ba4565b029392505050565b60006121118383612bfd565b6000816000190483118215151615612cc457612cc4612ba4565b500290565b600082612ce657634e487b7160e01b600052601260045260246000fd5b500490565b60008219821115612cfe57612cfe612ba4565b500190565b6000600019821415612d1757612d17612ba4565b5060010190565b81358155602082013560018201556040820135612d3a816128b2565b6002820180546001600160a01b0319166001600160a01b038316179055506060820135612d66816128b2565b6003820180546001600160a01b0319166001600160a01b038316179055505050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b600060208284031215612dc657600080fd5b81356002811061211157600080fd5b6000808335601e19843603018112612dec57600080fd5b83018035915067ffffffffffffffff821115612e0757600080fd5b60200191503681900382131561296e57600080fd5b600061211160ff841683612bfd565b600082821015612e3d57612e3d612ba4565b500390565b600060208284031215612e5457600080fd5b8151612111816128b2565b600060208284031215612e7157600080fd5b815161211181612a8a565b60005b83811015612e97578181015183820152602001612e7f565b838111156119fe5750506000910152565b60008251612b5e818460208701612e7c565b6020815260008251806020840152612ed9816040850160208701612e7c565b601f01601f1916919091016040019291505056fea264697066735822122053937e680feaffeeb2a35997324f0dc1a630e17cfdda6b62fbf3e01b5f97cd8964736f6c634300080c0033

Deployed Bytecode

0x608060405234801561001057600080fd5b50600436106101da5760003560e01c80638456cb5911610104578063b127e145116100a2578063fb02be4f11610071578063fb02be4f146104a7578063fb14cbd4146104ba578063fc4872bf146104cd578063fedf2521146104e057600080fd5b8063b127e145146103fd578063bdf81d0b14610410578063ebb2549014610423578063f2fde38b1461049457600080fd5b80638faaa288116100de5780638faaa2881461039b5780639ef6463c146103ae578063a50cb986146103d7578063b0c634ee146103ea57600080fd5b80638456cb591461036f5780638980f11f146103775780638da5cb5b1461038a57600080fd5b80634be1fe281161017c5780636c9a7d051161014b5780636c9a7d051461031e578063715018a61461033157806371d81fec14610339578063734507001461034c57600080fd5b80634be1fe28146102c157806353d6fd59146102d45780635c0e6d87146102e75780635c975abb1461031357600080fd5b80633c17b7d3116101b85780633c17b7d3146102575780633f4ba83a14610278578063485cc955146102805780634932bf491461029357600080fd5b80631a2d87c7146101df57806328c34c08146101f45780633af32abf14610224575b600080fd5b6101f26101ed3660046128c7565b610503565b005b6102076102023660046128f3565b610519565b6040516001600160a01b0390911681526020015b60405180910390f35b61024761023236600461290c565b60ce6020526000908152604090205460ff1681565b604051901515815260200161021b565b61026a610265366004612975565b610543565b60405190815260200161021b565b6101f2610773565b6101f261028e3660046129b7565b610785565b6102476102a136600461290c565b6001600160a01b03908116600090815260cd602052604090205416151590565b6101f26102cf3660046129f0565b610932565b6101f26102e2366004612a98565b610bdb565b6102476102f536600461290c565b6001600160a01b0316600090815260d0602052604090205460ff1690565b60655460ff16610247565b6101f261032c36600461290c565b610c6a565b6101f2610cee565b60ca54610207906001600160a01b031681565b61024761035a36600461290c565b60d06020526000908152604090205460ff1681565b6101f2610d00565b6101f26103853660046128c7565b610d10565b6033546001600160a01b0316610207565b6101f26103a9366004612a98565b610d22565b6102076103bc36600461290c565b60cd602052600090815260409020546001600160a01b031681565b6101f26103e53660046129b7565b610da9565b60c954610207906001600160a01b031681565b6101f261040b366004612a98565b610e5f565b6101f261041e366004612975565b610ee6565b61046561043136600461290c565b60cc602052600090815260409020805460018201546002830154600390930154919290916001600160a01b03918216911684565b6040805194855260208501939093526001600160a01b039182169284019290925216606082015260800161021b565b6101f26104a236600461290c565b61158f565b6101f26104b536600461290c565b61161f565b6101f26104c836600461290c565b6116c7565b6101f26104db366004612ac6565b611744565b6102476104ee36600461290c565b60cf6020526000908152604090205460ff1681565b61050b611a04565b6105158282611a5e565b5050565b60cb818154811061052957600080fd5b6000918252602090912001546001600160a01b0316905081565b600080805b8381101561076957600060cd600087878581811061056857610568612b32565b905060200281019061057a9190612b48565b61058b90606081019060400161290c565b6001600160a01b0390811682526020820192909252604001600020541663b3596f078787858181106105bf576105bf612b32565b90506020028101906105d19190612b48565b6105e290606081019060400161290c565b6040517fffffffff0000000000000000000000000000000000000000000000000000000060e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa15801561063e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106629190612b68565b9050600086868481811061067857610678612b32565b905060200281019061068a9190612b48565b61069b90606081019060400161290c565b6001600160a01b031663313ce5676040518163ffffffff1660e01b8152600401602060405180830381865afa1580156106d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106fc9190612b81565b60ff169050600061070e82600a612c9e565b88888681811061072057610720612b32565b90506020028101906107329190612b48565b61073d903585612caa565b6107479190612cc9565b90506107538186612ceb565b94505050508061076290612d03565b9050610548565b5090505b92915050565b61077b611a04565b610783611b8e565b565b600054610100900460ff16158080156107a55750600054600160ff909116105b806107bf5750303b1580156107bf575060005460ff166001145b6108365760405162461bcd60e51b815260206004820152602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a656400000000000000000000000000000000000060648201526084015b60405180910390fd5b6000805460ff191660011790558015610859576000805461ff0019166101001790555b6001600160a01b03831661088057604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b0382166108a757604051639fabe1c160e01b815260040160405180910390fd5b60c980546001600160a01b038086166001600160a01b03199283161790925560ca8054928516929091169190911790556108df611be0565b6108e7611c53565b801561092d576000805461ff0019169055604051600181527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb38474024989060200160405180910390a15b505050565b61093a611a04565b828114610973576040517fe7fa722b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b83811015610a4f57600061098b826001612ceb565b90505b84811015610a3e578585828181106109a8576109a8612b32565b90506020020160208101906109bd919061290c565b6001600160a01b03168686848181106109d8576109d8612b32565b90506020020160208101906109ed919061290c565b6001600160a01b03161415610a2e576040517f0d037f8d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610a3781612d03565b905061098e565b50610a4881612d03565b9050610976565b50610a5c60cb6000612880565b6000805b82811015610b655760cb868683818110610a7c57610a7c612b32565b9050602002016020810190610a91919061290c565b81546001810183556000928352602090922090910180546001600160a01b0319166001600160a01b03909216919091179055838382818110610ad557610ad5612b32565b90506080020160cc6000888885818110610af157610af1612b32565b9050602002016020810190610b06919061290c565b6001600160a01b031681526020810191909152604001600020610b298282612d1e565b905050838382818110610b3e57610b3e612b32565b9050608002016020013582610b539190612ceb565b9150610b5e81612d03565b9050610a60565b508061271014610ba1576040517f0477518700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040518481527f8d376a4e1d8870f81c356be9c126b31c302f0429d5423a7a1243f646f0eba5949060200160405180910390a15050505050565b610be3611a04565b6001600160a01b038216610c0a57604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038216600081815260ce6020908152604091829020805460ff191685151590811790915591519182527f26742d25b283cf51a0e3c4183d934871ed96d1bd33cf40706f87a94f29f686ac91015b60405180910390a25050565b610c72611a04565b6001600160a01b038116610c9957604051639fabe1c160e01b815260040160405180910390fd5b60ca80546001600160a01b0319166001600160a01b0383169081179091556040519081527f6930d1412afb621c8b8d5ce398e75d8d8bd0458ca90d3424958e502dfeae7875906020015b60405180910390a150565b610cf6611a04565b6107836000611cc6565b610d08611a04565b610783611d18565b610d18611a04565b6105158282611d55565b610d2a611a04565b6001600160a01b038216610d5157604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038216600081815260cf6020908152604091829020805460ff191685151590811790915591519182527f682f9c70bad742209244948af878d200ac46ca830c40d244b76967262347b4cb9101610c5e565b610db1611a04565b6001600160a01b038216610dd857604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038116610dff57604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b03828116600081815260cd602090815260409182902080546001600160a01b0319169486169485179055905192835290917ff94898767cdccad6f60acbffed75166708ff54b47f2822abb5476352c037787a9101610c5e565b610e67611a04565b6001600160a01b038216610e8e57604051639fabe1c160e01b815260040160405180910390fd5b6001600160a01b038216600081815260d06020908152604091829020805460ff191685151590811790915591519182527f4adc78dec192f73e22bd7c1330e489f5fe079836d3c097e9c2d88b862ec8b6ce9101610c5e565b610eee611da4565b33600090815260ce602052604090205460ff16610f1e5760405163ea8e4eb560e01b815260040160405180910390fd5b610f26611df7565b6000610f328383610543565b60cb5490915060009067ffffffffffffffff811115610f5357610f53612d88565b604051908082528060200260200182016040528015610f7c578160200160208202803683370190505b50905060005b60cb548110156110415760cb8181548110610f9f57610f9f612b32565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015610ff0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110149190612b68565b82828151811061102657611026612b32565b602090810291909101015261103a81612d03565b9050610f82565b5060005b838110156111a157600185858381811061106157611061612b32565b90506020028101906110739190612b48565b6110849060c081019060a001612db4565b600181111561109557611095612d9e565b141561115f5761115a8585838181106110b0576110b0612b32565b90506020028101906110c29190612b48565b6110d390606081019060400161290c565b8686848181106110e5576110e5612b32565b90506020028101906110f79190612b48565b3587878581811061110a5761110a612b32565b905060200281019061111c9190612b48565b6060013588888681811061113257611132612b32565b90506020028101906111449190612b48565b611152906020810190612dd5565b6102f5611e51565b611191565b6040517f74ac268b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61119a81612d03565b9050611045565b5060005b60cb5481101561158257600060cc600060cb84815481106111c8576111c8612b32565b60009182526020808320909101546001600160a01b03908116845283820194909452604092830182208351608081018552815481526001820154928101929092526002810154851693820184905260030154909316606084015260cb8054939450909263b3596f0791908690811061124257611242612b32565b60009182526020909120015460405160e083901b7fffffffff000000000000000000000000000000000000000000000000000000001681526001600160a01b039091166004820152602401602060405180830381865afa1580156112aa573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112ce9190612b68565b9050600060cb84815481106112e5576112e5612b32565b60009182526020918290200154604080517f313ce56700000000000000000000000000000000000000000000000000000000815290516001600160a01b039092169263313ce567926004808401938290030181865afa15801561134c573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906113709190612b81565b9050600061138b84602001518861204f90919063ffffffff16565b905060008361139b84600a612e1c565b6113a59084612caa565b6113af9190612cc9565b905060008787815181106113c5576113c5612b32565b602002602001015160cb88815481106113e0576113e0612b32565b6000918252602090912001546040516370a0823160e01b81523060048201526001600160a01b03909116906370a0823190602401602060405180830381865afa158015611431573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114559190612b68565b61145f9190612e2b565b90508061147157505050505050611572565b60cb878154811061148457611484612b32565b600091825260209182902001546040518381526001600160a01b03909116917f58b0b4a0cc56da318e6d4c63aebe81ac4a2e221518b74c4de26cf62e216ba3bc910160405180910390a285516114e66114df82612710612e2b565b849061204f565b821015801561150357506114ff6114df82612710612ceb565b8211155b611539576040517faf587d6000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61156a60cb898154811061154f5761154f612b32565b6000918252602090912001546001600160a01b031683611a5e565b505050505050505b61157b81612d03565b90506111a5565b5050506105156001609755565b611597611a04565b6001600160a01b0381166116135760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201527f6464726573730000000000000000000000000000000000000000000000000000606482015260840161082d565b61161c81611cc6565b50565b611627611a04565b6001600160a01b03818116600090815260cd602052604090205416611678576040517f41f2a4a300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6001600160a01b038116600081815260cd602052604080822080546001600160a01b0319169055517fbbdac506546a1c601761a0bf8dc65e172d91ba9b6caec595e1251851c0a7d04d9190a250565b6116cf611a04565b6001600160a01b0381166116f657604051639fabe1c160e01b815260040160405180910390fd5b60c980546001600160a01b0319166001600160a01b0383169081179091556040519081527fda698b594605a93dd68e126773558b6a9858df49f45d3854adbb50bdb6d3379590602001610ce3565b33600090815260ce602052604090205460ff166117745760405163ea8e4eb560e01b815260040160405180910390fd5b61177c611df7565b8281146117b5576040517f27dbe09300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60005b838110156119f35760008585838181106117d4576117d4612b32565b90506020020160208101906117e9919061290c565b6001600160a01b031663b16a19de6040518163ffffffff1660e01b8152600401602060405180830381865afa158015611826573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184a9190612e42565b9050600084848481811061186057611860612b32565b905060200201359050600087878581811061187d5761187d612b32565b9050602002016020810190611892919061290c565b6001600160a01b0316637535d2466040518163ffffffff1660e01b8152600401602060405180830381865afa1580156118cf573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906118f39190612e42565b6001600160a01b038116600090815260cf602052604090205490915060ff16611948576040517fd8cad67600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f69328dec0000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152602482018490523060448301528291908216906369328dec906064016020604051808303816000875af11580156119b9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906119dd9190612b68565b5050505050806119ec90612d03565b90506117b8565b506119fe6001609755565b50505050565b6033546001600160a01b031633146107835760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604482015260640161082d565b60ca5460405163095ea7b360e01b81526001600160a01b0391821660048201819052602482018490529184169063095ea7b3906044016020604051808303816000875af1158015611ab3573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611ad79190612e5f565b506040517fe8eda9df0000000000000000000000000000000000000000000000000000000081526001600160a01b038481166004830152602482018490523060448301526000606483015282169063e8eda9df90608401600060405180830381600087803b158015611b4857600080fd5b505af1158015611b5c573d6000803e3d6000fd5b505060c9546001600160a01b03868116600090815260cc602052604090206003015461092d9450811692501684612118565b611b966121c1565b6065805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516001600160a01b03909116815260200160405180910390a1565b600054610100900460ff16611c4b5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161082d565b610783612213565b600054610100900460ff16611cbe5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161082d565b610783612287565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b611d20611da4565b6065805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258611bc33390565b611d696001600160a01b0383163383612118565b816001600160a01b03167f8c1256b8896378cd5044f80c202f9772b9d77dc85c8a6eb51967210b09bfaa2882604051610c5e91815260200190565b60655460ff16156107835760405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a2070617573656400000000000000000000000000000000604482015260640161082d565b60026097541415611e4a5760405162461bcd60e51b815260206004820152601f60248201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604482015260640161082d565b6002609755565b6000611e9284848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506122fe92505050565b805190915015611ece576040517f9513f45400000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b611edf81602001518363ffffffff16565b611f15576040517fcafd331600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040810151611f2f906001600160a01b03891690886124ad565b600080600083602001516001600160a01b03168460600151604051611f549190612ea8565b6000604051808303816000865af19150503d8060008114611f91576040519150601f19603f3d011682016040523d82523d6000602084013e611f96565b606091505b50915091508115611fbc5780806020019051810190611fb59190612b68565b9250611fee565b6040517fb52a547f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b87831015612028576040517f97a48cb000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040840151612043906001600160a01b038c169060006124ad565b50505050505050505050565b600082158061205c575081155b156120695750600061076d565b816120776002612710612cc9565b61208390600019612e2b565b61208d9190612cc9565b8311156040518060400160405280600281526020017f3438000000000000000000000000000000000000000000000000000000000000815250906120e45760405162461bcd60e51b815260040161082d9190612eba565b506127106120f3600282612cc9565b6120fd8486612caa565b6121079190612ceb565b6121119190612cc9565b9392505050565b6040516001600160a01b03831660248201526044810182905261092d9084907fa9059cbb00000000000000000000000000000000000000000000000000000000906064015b60408051601f198184030181529190526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fffffffff000000000000000000000000000000000000000000000000000000009093169290921790915261254d565b60655460ff166107835760405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f7420706175736564000000000000000000000000604482015260640161082d565b600054610100900460ff1661227e5760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161082d565b61078333611cc6565b600054610100900460ff166122f25760405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201526a6e697469616c697a696e6760a81b606482015260840161082d565b6065805460ff19169055565b604080516080810182526000808252602082018190529181019190915260608082015260a08251101561235d576040517f7016bd9b00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b604080516080810182526000808252602080830182815283850192835260608085018190529187015194870151918701518585526001600160a01b0380841690925290811690925285519293929091906123b99060a090612e2b565b67ffffffffffffffff8111156123d1576123d1612d88565b6040519080825280601f01601f1916602001820160405280156123fb576020820181803683370190505b506060850152855160a05b818110156124a15787818151811061242057612420612b32565b016020015160608701517fff000000000000000000000000000000000000000000000000000000000000009091169061245a60a084612e2b565b8151811061246a5761246a612b32565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a905350600101612406565b50939695505050505050565b604080516001600160a01b038416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1663095ea7b360e01b1790526125138482612635565b6119fe576040516001600160a01b03841660248201526000604482015261254790859063095ea7b360e01b9060640161215d565b6119fe84825b60006125a2826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166126dc9092919063ffffffff16565b90508051600014806125c35750808060200190518101906125c39190612e5f565b61092d5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f74207375636365656400000000000000000000000000000000000000000000606482015260840161082d565b6000806000846001600160a01b0316846040516126529190612ea8565b6000604051808303816000865af19150503d806000811461268f576040519150601f19603f3d011682016040523d82523d6000602084013e612694565b606091505b50915091508180156126be5750805115806126be5750808060200190518101906126be9190612e5f565b80156126d357506001600160a01b0385163b15155b95945050505050565b60606126eb84846000856126f3565b949350505050565b60608247101561276b5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c0000000000000000000000000000000000000000000000000000606482015260840161082d565b600080866001600160a01b031685876040516127879190612ea8565b60006040518083038185875af1925050503d80600081146127c4576040519150601f19603f3d011682016040523d82523d6000602084013e6127c9565b606091505b50915091506127da878383876127e5565b979650505050505050565b6060831561285157825161284a576001600160a01b0385163b61284a5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161082d565b50816126eb565b6126eb83838151156128665781518083602001fd5b8060405162461bcd60e51b815260040161082d9190612eba565b508054600082559060005260206000209081019061161c91905b808211156128ae576000815560010161289a565b5090565b6001600160a01b038116811461161c57600080fd5b600080604083850312156128da57600080fd5b82356128e5816128b2565b946020939093013593505050565b60006020828403121561290557600080fd5b5035919050565b60006020828403121561291e57600080fd5b8135612111816128b2565b60008083601f84011261293b57600080fd5b50813567ffffffffffffffff81111561295357600080fd5b6020830191508360208260051b850101111561296e57600080fd5b9250929050565b6000806020838503121561298857600080fd5b823567ffffffffffffffff81111561299f57600080fd5b6129ab85828601612929565b90969095509350505050565b600080604083850312156129ca57600080fd5b82356129d5816128b2565b915060208301356129e5816128b2565b809150509250929050565b60008060008060408587031215612a0657600080fd5b843567ffffffffffffffff80821115612a1e57600080fd5b612a2a88838901612929565b90965094506020870135915080821115612a4357600080fd5b818701915087601f830112612a5757600080fd5b813581811115612a6657600080fd5b8860208260071b8501011115612a7b57600080fd5b95989497505060200194505050565b801515811461161c57600080fd5b60008060408385031215612aab57600080fd5b8235612ab6816128b2565b915060208301356129e581612a8a565b60008060008060408587031215612adc57600080fd5b843567ffffffffffffffff80821115612af457600080fd5b612b0088838901612929565b90965094506020870135915080821115612b1957600080fd5b50612b2687828801612929565b95989497509550505050565b634e487b7160e01b600052603260045260246000fd5b6000823560be19833603018112612b5e57600080fd5b9190910192915050565b600060208284031215612b7a57600080fd5b5051919050565b600060208284031215612b9357600080fd5b815160ff8116811461211157600080fd5b634e487b7160e01b600052601160045260246000fd5b600181815b80851115612bf5578160001904821115612bdb57612bdb612ba4565b80851615612be857918102915b93841c9390800290612bbf565b509250929050565b600082612c0c5750600161076d565b81612c195750600061076d565b8160018114612c2f5760028114612c3957612c55565b600191505061076d565b60ff841115612c4a57612c4a612ba4565b50506001821b61076d565b5060208310610133831016604e8410600b8410161715612c78575081810a61076d565b612c828383612bba565b8060001904821115612c9657612c96612ba4565b029392505050565b60006121118383612bfd565b6000816000190483118215151615612cc457612cc4612ba4565b500290565b600082612ce657634e487b7160e01b600052601260045260246000fd5b500490565b60008219821115612cfe57612cfe612ba4565b500190565b6000600019821415612d1757612d17612ba4565b5060010190565b81358155602082013560018201556040820135612d3a816128b2565b6002820180546001600160a01b0319166001600160a01b038316179055506060820135612d66816128b2565b6003820180546001600160a01b0319166001600160a01b038316179055505050565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052602160045260246000fd5b600060208284031215612dc657600080fd5b81356002811061211157600080fd5b6000808335601e19843603018112612dec57600080fd5b83018035915067ffffffffffffffff821115612e0757600080fd5b60200191503681900382131561296e57600080fd5b600061211160ff841683612bfd565b600082821015612e3d57612e3d612ba4565b500390565b600060208284031215612e5457600080fd5b8151612111816128b2565b600060208284031215612e7157600080fd5b815161211181612a8a565b60005b83811015612e97578181015183820152602001612e7f565b838111156119fe5750506000910152565b60008251612b5e818460208701612e7c565b6020815260008251806020840152612ed9816040850160208701612e7c565b601f01601f1916919091016040019291505056fea264697066735822122053937e680feaffeeb2a35997324f0dc1a630e17cfdda6b62fbf3e01b5f97cd8964736f6c634300080c0033

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
Loading...
Loading

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.