Warning! Contract bytecode has been changed and doesn't match the verified one. Therefore, interaction with this smart contract may be risky.
- Contract name:
- Flasher_Taiko
- Optimization enabled
- true
- Compiler version
- v0.8.17+commit.8df45f5f
- Optimization runs
- 200
- EVM Version
- default
- Verified at
- 2024-06-02T12:06:20.743575Z
Constructor Arguments
0x00000000000000000000000066f850099e6d5dbd712d15244b65bd822f36be7e0000000000000000000000000820c2782474288bb39ba3a6e4918283d158c1a50000000000000000000000007b9de408f232ea1909cbe1abf97c92ad244fc870000000000000000000000000a7927a4c99fa7b3edd5b27b1ac498a2c177ba0e00000000000000000000000000820c2782474288bb39ba3a6e4918283d158c1a5
Arg [0] (address) : 0x66f850099e6d5dbd712d15244b65bd822f36be7e
Arg [1] (address) : 0x0820c2782474288bb39ba3a6e4918283d158c1a5
Arg [2] (address) : 0x7b9de408f232ea1909cbe1abf97c92ad244fc870
Arg [3] (address) : 0xa7927a4c99fa7b3edd5b27b1ac498a2c177ba0e0
Arg [4] (address) : 0x0820c2782474288bb39ba3a6e4918283d158c1a5
contracts/multichain/taiko/Flasher_Taiko.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "./interfaces/IFlasherTaiko.sol";
import "../../interfaces/ILiquidationCallback.sol";
import "../../libraries/ErrorCodes.sol";
import "../../FlasherBasic.sol";
contract Flasher_Taiko is IFlasherTaiko, FlasherBasic {
using SafeERC20 for IERC20;
// Address of OpenOceanExchangeProxy contract
address public opOnExchangeProxy;
constructor(
address _admin,
address _opOnExchangeProxy,
address _liquidation,
address _oracle,
address _treasuryAddress
) FlasherBasic(_admin, _liquidation, _oracle, _treasuryAddress) {
validateZeroAddress(_opOnExchangeProxy);
opOnExchangeProxy = _opOnExchangeProxy;
}
/************************************************************************/
/* GATEKEEPER FUNCTIONS */
/************************************************************************/
/// @inheritdoc IFlasherTaiko
function flashLiquidation(
IMToken seizeMarket,
IMToken repayMarket,
address borrower,
uint256 repayAmount,
bytes calldata mainSwapData
) external onlyRole(GATEKEEPER) {
bytes memory callbackData = abi.encode(
FlashLiquidationCallbackData({
seizeMarket: seizeMarket,
repayMarket: repayMarket,
mainSwapData: mainSwapData
})
);
ILiquidationTaiko(address(liquidation)).liquidateUnsafeLoanFlash(
seizeMarket,
repayMarket,
borrower,
repayAmount,
callbackData
);
}
/// @inheritdoc ILiquidationCallback
function onLiquidation(
uint256 seizeAmount,
uint256 repayAmount,
bytes calldata callbackParams
) external returns (bool) {
require(msg.sender == address(liquidation), ErrorCodes.FL_UNAUTHORIZED_CALLBACK);
FlashLiquidationCallbackData memory flashCallbackData = abi.decode(
callbackParams,
(FlashLiquidationCallbackData)
);
IERC20 seizeAsset = flashCallbackData.seizeMarket.underlying();
IERC20 repayAsset = flashCallbackData.repayMarket.underlying();
uint256 remainingRepayToken = 0;
// Check if we need to swap seized asset to repay loan
if (seizeAsset != repayAsset) {
(bytes memory multicallData, uint256 minAmountOut) = abi.decode(
flashCallbackData.mainSwapData,
(bytes, uint256)
);
(, uint256 repayTokenReceived) = multicallSwap(
seizeAsset,
repayAsset,
seizeAmount,
minAmountOut,
true,
multicallData,
address(opOnExchangeProxy)
);
// After ExactIn swap we update remaining seize amount
remainingRepayToken = repayTokenReceived - repayAmount;
} else {
// In case seizeAsset == repayAsset, we don't need to swap seizeAsset to repayAsset,
// we already can repay loan.
// Substitute `repayAmount` from initial seize amount to manage further surplus transfer.
remainingRepayToken = seizeAmount - repayAmount;
}
// Transfer surplus to the treasury
transferSurplus(repayAsset, remainingRepayToken);
// Repay flash borrow amount plus fee
IERC20(repayAsset).approve(address(flashCallbackData.repayMarket), repayAmount);
return true;
}
/************************************************************************/
/* ADMIN FUNCTIONS */
/************************************************************************/
/// @inheritdoc IFlasherTaiko
function setOpOnExchangeProxy(address newOpOnExchangeProxy) external onlyRole(DEFAULT_ADMIN_ROLE) {
validateZeroAddress(newOpOnExchangeProxy);
// slither-disable-next-line missing-zero-check
opOnExchangeProxy = newOpOnExchangeProxy;
emit NewOpOnExchangeProxy(newOpOnExchangeProxy);
}
/************************************************************************/
/* INTERNAL FUNCTIONS */
/************************************************************************/
/**
* @notice Verifies if amounts are correct after swap based on trade type and expected values.
Nullify allowance for tokenIn if required.
* @param isSwapTypeExactIn Marker of trade type
* @param amountInDelta The actual value of spent In tokens
* @param amountOutDelta The actual value of received Out tokens
* @param tokenIn Input token
* @param tokenInAmount TokenIn swap amount in case of ExactIn trade type or `TokenInMaximum`
in case of ExactOut trade type
* @param tokenOutAmount TokenOut swap amount in case of ExactOut trade type or `TokenOutMinimum`
in case of ExactIn trade type
* @param tokensSpender The address of tokens spender during swap
*/
function validateAmountsAndNullifyAllowance(
bool isSwapTypeExactIn,
uint256 amountInDelta,
uint256 amountOutDelta,
IERC20 tokenIn,
uint256 tokenInAmount,
uint256 tokenOutAmount,
address tokensSpender
) internal virtual override {
if (isSwapTypeExactIn) {
require(amountInDelta <= tokenInAmount, ErrorCodes.FL_INVALID_AMOUNT_TOKEN_IN_SPENT);
require(amountOutDelta >= tokenOutAmount, ErrorCodes.FL_INVALID_AMOUNT_TOKEN_OUT_RECEIVED);
// In case `amountInDelta < tokenInAmount` we have remaining allowance that must be nullified
if (tokenIn.allowance(address(this), tokensSpender) > 0) {
tokenIn.safeApprove(tokensSpender, 0);
}
} else {
require(amountInDelta <= tokenInAmount, ErrorCodes.FL_INVALID_AMOUNT_TOKEN_IN_SPENT);
require(
amountOutDelta >= (tokenOutAmount * tokenOutDeviation) / EXP_SCALE,
ErrorCodes.FL_INVALID_AMOUNT_TOKEN_OUT_RECEIVED
);
tokenIn.safeApprove(tokensSpender, 0);
}
}
}
@openzeppelin/contracts/access/AccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
@openzeppelin/contracts/access/IAccessControl.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}
@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC3156FlashBorrower.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC3156 FlashBorrower, as defined in
* https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
*
* _Available since v4.1._
*/
interface IERC3156FlashBorrower {
/**
* @dev Receive a flash loan.
* @param initiator The initiator of the loan.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @param fee The additional amount of tokens to repay.
* @param data Arbitrary data structure, intended to contain user-defined parameters.
* @return The keccak256 hash of "ERC3156FlashBorrower.onFlashLoan"
*/
function onFlashLoan(
address initiator,
address token,
uint256 amount,
uint256 fee,
bytes calldata data
) external returns (bytes32);
}
@openzeppelin/contracts/interfaces/IERC3156FlashLender.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (interfaces/IERC3156FlashLender.sol)
pragma solidity ^0.8.0;
import "./IERC3156FlashBorrower.sol";
/**
* @dev Interface of the ERC3156 FlashLender, as defined in
* https://eips.ethereum.org/EIPS/eip-3156[ERC-3156].
*
* _Available since v4.1._
*/
interface IERC3156FlashLender {
/**
* @dev The amount of currency available to be lended.
* @param token The loan currency.
* @return The amount of `token` that can be borrowed.
*/
function maxFlashLoan(address token) external view returns (uint256);
/**
* @dev The fee to be charged for a given loan.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @return The amount of `token` to be charged for the loan, on top of the returned principal.
*/
function flashFee(address token, uint256 amount) external view returns (uint256);
/**
* @dev Initiate a flash loan.
* @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @param data Arbitrary data structure, intended to contain user-defined parameters.
*/
function flashLoan(
IERC3156FlashBorrower receiver,
address token,
uint256 amount,
bytes calldata data
) external returns (bool);
}
@openzeppelin/contracts/token/ERC20/IERC20.sol
// 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);
}
@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol
// 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);
}
@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (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. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
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));
}
}
@openzeppelin/contracts/utils/Address.sol
// 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);
}
}
}
@openzeppelin/contracts/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @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 Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}
@openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
@openzeppelin/contracts/utils/introspection/ERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
@openzeppelin/contracts/utils/introspection/IERC165.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
@openzeppelin/contracts/utils/math/Math.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}
@openzeppelin/contracts/utils/math/SignedMath.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}
contracts/FlasherBasic.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;
import "./interfaces/IFlasherBasic.sol";
import "./libraries/ErrorCodes.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
abstract contract FlasherBasic is IFlasherBasic, AccessControl {
using SafeERC20 for IERC20;
/// @dev Value is the Keccak-256 hash of "GATEKEEPER"
bytes32 public constant GATEKEEPER = bytes32(0x20162831d2f54c3e11eebafebfeda495d4c52c67b1708251179ec91fb76dd3b2);
ILiquidation public liquidation;
IPriceOracle public oracle;
address public treasuryAddress;
/// @notice Whitelist for users who can be a withdrawal recipients
mapping(address => bool) public allowedWithdrawReceivers;
/// @dev The maximum deviation from the expected amountOut for a swap.
uint256 public tokenOutDeviation = 99e16;
uint256 internal constant EXP_SCALE = 1e18;
constructor(
address _admin,
address _liquidation,
address _oracle,
address _treasuryAddress
) {
validateZeroAddress(_admin);
validateZeroAddress(_liquidation);
validateZeroAddress(_oracle);
validateZeroAddress(_treasuryAddress);
liquidation = ILiquidation(_liquidation);
oracle = IPriceOracle(_oracle);
treasuryAddress = _treasuryAddress;
_grantRole(DEFAULT_ADMIN_ROLE, _admin);
_grantRole(GATEKEEPER, _admin);
}
/* --- LOGIC --- */
/// @inheritdoc IFlasherBasic
function withdraw(
uint256 amount,
IERC20 underlying,
address to
) external virtual onlyRole(DEFAULT_ADMIN_ROLE) allowedReceiversOnly(to) {
require(underlying.balanceOf(address(this)) >= amount, ErrorCodes.INSUFFICIENT_LIQUIDITY);
emit Withdraw(address(underlying), to, amount);
underlying.safeTransfer(to, amount);
}
/* --- SETTERS --- */
/// @inheritdoc IFlasherBasic
function setTokenOutDeviation(uint256 newValue_) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
require(newValue_ > 0, ErrorCodes.FL_INCORRECT_TOKEN_OUT_DEVIATION);
uint256 oldValue = tokenOutDeviation;
tokenOutDeviation = newValue_;
emit TokenOutDeviationChanged(oldValue, newValue_);
}
/// @inheritdoc IFlasherBasic
function setLiquidationAddress(ILiquidation newLiquidationContract) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
validateZeroAddress(address(newLiquidationContract));
liquidation = newLiquidationContract;
emit NewLiquidation(newLiquidationContract);
}
/// @inheritdoc IFlasherBasic
function setOracleAddress(IPriceOracle newOracleContract) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
validateZeroAddress(address(newOracleContract));
oracle = newOracleContract;
emit NewOracle(newOracleContract);
}
/// @inheritdoc IFlasherBasic
function setTreasuryAddress(address newTreasuryAddress) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
validateZeroAddress(newTreasuryAddress);
// slither-disable-next-line missing-zero-check
treasuryAddress = newTreasuryAddress;
emit NewTreasury(newTreasuryAddress);
}
/// @inheritdoc IFlasherBasic
function addAllowedReceiver(address receiver) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
validateZeroAddress(receiver);
allowedWithdrawReceivers[receiver] = true;
emit NewAllowedWithdrawReceiver(receiver);
}
/// @inheritdoc IFlasherBasic
function addAllowedGatekeeper(address newGatekeeper) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
validateZeroAddress(newGatekeeper);
_grantRole(GATEKEEPER, newGatekeeper);
emit NewAllowedGatekeeper(newGatekeeper);
}
/// @inheritdoc IFlasherBasic
function removeAllowedReceiver(address receiver)
external
virtual
onlyRole(DEFAULT_ADMIN_ROLE)
allowedReceiversOnly(receiver)
{
delete allowedWithdrawReceivers[receiver];
emit AllowedWithdrawReceiverRemoved(receiver);
}
/// @inheritdoc IFlasherBasic
function removeAllowedGatekeeper(address gatekeeper) external virtual onlyRole(DEFAULT_ADMIN_ROLE) {
_revokeRole(GATEKEEPER, gatekeeper);
emit AllowedGatekeeperRemoved(gatekeeper);
}
/************************************************************************/
/* INTERNAL FUNCTIONS */
/************************************************************************/
/**
* @notice Transfers surplus to the treasury
* @param surplusAsset Token that was used as surplus during liquidation process
* @param transferAmount Amount of surplus token to transfer
*/
function transferSurplus(IERC20 surplusAsset, uint256 transferAmount) internal virtual {
address treasuryAddress_ = treasuryAddress;
emit SurplusTransfer(surplusAsset, treasuryAddress_, transferAmount);
surplusAsset.safeTransfer(treasuryAddress_, transferAmount);
}
/**
* @notice Verifies if amounts are correct after swap based on trade type and expected values.
Nullify allowance for tokenIn in case of ExactOut trade type.
* @param isSwapTypeExactIn Marker of trade type
* @param amountInDelta The actual value of spent In tokens
* @param amountOutDelta The actual value of received Out tokens
* @param tokenIn Input token
* @param tokenInAmount TokenIn swap amount in case of ExactIn trade type or `TokenInMaximum`
in case of ExactOut trade type
* @param tokenOutAmount TokenOut swap amount in case of ExactOut trade type or `TokenOutMinimum`
in case of ExactIn trade type
* @param tokensSpender The address of tokens spender during swap
*/
function validateAmountsAndNullifyAllowance(
bool isSwapTypeExactIn,
uint256 amountInDelta,
uint256 amountOutDelta,
IERC20 tokenIn,
uint256 tokenInAmount,
uint256 tokenOutAmount,
address tokensSpender
) internal virtual {
if (isSwapTypeExactIn) {
require(amountInDelta == tokenInAmount, ErrorCodes.FL_INVALID_AMOUNT_TOKEN_IN_SPENT);
require(amountOutDelta >= tokenOutAmount, ErrorCodes.FL_INVALID_AMOUNT_TOKEN_OUT_RECEIVED);
require(
tokenIn.allowance(address(this), tokensSpender) == 0,
ErrorCodes.FL_EXACT_IN_INCORRECT_ALLOWANCE_AFTER
);
} else {
require(amountInDelta <= tokenInAmount, ErrorCodes.FL_INVALID_AMOUNT_TOKEN_IN_SPENT);
require(
amountOutDelta >= (tokenOutAmount * tokenOutDeviation) / EXP_SCALE,
ErrorCodes.FL_INVALID_AMOUNT_TOKEN_OUT_RECEIVED
);
tokenIn.safeApprove(tokensSpender, 0);
}
}
/**
* @notice Verifies if the provided address is not a zero address, throw otherwise
* @param addressToValidate Address to validate
*/
function validateZeroAddress(address addressToValidate) internal pure virtual {
require(addressToValidate != address(0), ErrorCodes.ZERO_ADDRESS);
}
/**
* @notice Performs multicall swap on Uniswap V3 router and validates result
* @param tokenIn Input token
* @param tokenOut Output token
* @param tokenInAmount Amount of input token
* @param tokenOutAmount Amount of output token
* @param isSwapTypeExactIn Marker of trade type
* @param swapRouterAddress The address of the contract where the exchange is made
* @return amountInDelta TokenIn delta after swap
* @return amountOutDelta TokenOut delta after swap
*/
function multicallSwap(
IERC20 tokenIn,
IERC20 tokenOut,
uint256 tokenInAmount,
uint256 tokenOutAmount,
bool isSwapTypeExactIn,
bytes memory swapData,
address swapRouterAddress
) internal virtual returns (uint256 amountInDelta, uint256 amountOutDelta) {
uint256 amountInBefore = tokenIn.balanceOf(address(this));
uint256 amountOutBefore = tokenOut.balanceOf(address(this));
tokenIn.safeApprove(swapRouterAddress, tokenInAmount);
Address.functionCall(swapRouterAddress, swapData, ErrorCodes.FL_SWAP_CALL_FAILS);
amountInDelta = amountInBefore - tokenIn.balanceOf(address(this));
amountOutDelta = tokenOut.balanceOf(address(this)) - amountOutBefore;
validateAmountsAndNullifyAllowance(
isSwapTypeExactIn,
amountInDelta,
amountOutDelta,
tokenIn,
tokenInAmount,
tokenOutAmount,
swapRouterAddress
);
emit MulticallSwap(tokenIn, tokenOut, amountInDelta, amountOutDelta);
}
/**
* @notice Verifies if the provided address is in allowedWithdrawReceivers list, throw otherwise
* @param receiver Address to validate
*/
modifier allowedReceiversOnly(address receiver) {
require(allowedWithdrawReceivers[receiver], ErrorCodes.FL_RECEIVER_NOT_FOUND);
_;
}
}
contracts/interfaces/IFlasherBasic.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "./ILiquidation.sol";
import "@openzeppelin/contracts/access/IAccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IFlasherBasic is IAccessControl {
event Withdraw(address token, address to, uint256 amount);
event NewLiquidation(ILiquidation liquidation);
event NewOracle(IPriceOracle oracle);
event NewTreasury(address newTreasuryAddress);
event NewAllowedWithdrawReceiver(address receiver);
event NewAllowedGatekeeper(address bot);
event AllowedWithdrawReceiverRemoved(address receiver);
event AllowedGatekeeperRemoved(address bot);
event MulticallSwap(IERC20 tokenIn, IERC20 tokenOut, uint256 spentAmount, uint256 receivedAmount);
event SurplusTransfer(IERC20 surplusAsset, address treasuryAddress, uint256 transferAmount);
event TokenOutDeviationChanged(uint256 oldValue, uint256 newValue);
/**
* @notice get liquidation contract
*/
function liquidation() external view returns (ILiquidation);
/**
* @notice get Price oracle contract
*/
function oracle() external view returns (IPriceOracle);
/**
* @notice get treasury address
*/
function treasuryAddress() external view returns (address);
/**
* @notice get whitelist for users who can be a withdrawal recipients
*/
function allowedWithdrawReceivers(address) external view returns (bool);
/**
* @notice get keccak-256 hash of gatekeeper role
*/
function GATEKEEPER() external view returns (bytes32);
/**
* @notice Withdraw tokens to the wallet
* @param amount Amount to withdraw
* @param underlying Token to withdraw
* @param to Recipient address (RESTRICTION: allowed receivers only)
* @dev RESTRICTION: Admin only
*/
function withdraw(
uint256 amount,
IERC20 underlying,
address to
) external;
/**
* @notice Set new tokenOutDeviation
* @dev RESTRICTION: Admin only
*/
function setTokenOutDeviation(uint256 newValue_) external;
/**
* @notice Set new ILiquidation contract
* @dev RESTRICTION: Admin only
*/
function setLiquidationAddress(ILiquidation liquidationContract) external;
/**
* @notice Set new Price oracle contract
* @dev RESTRICTION: Admin only
*/
function setOracleAddress(IPriceOracle newOracleContract) external;
/**
* @notice Set new treasury address
* @dev RESTRICTION: Admin only
*/
function setTreasuryAddress(address newTreasuryAddress) external;
/**
* @notice Add new withdraw receiver address to the whitelist
* @dev RESTRICTION: Admin only
*/
function addAllowedReceiver(address receiver) external;
/**
* @notice Grant GATEKEEPER role to the new address
* @dev RESTRICTION: Admin only
*/
function addAllowedGatekeeper(address newGatekeeper) external;
/**
* @notice Remove withdraw receiver address from the whitelist
* @dev RESTRICTION: Admin only
*/
function removeAllowedReceiver(address receiver) external;
/**
* @notice Revoke GATEKEEPER role from the address
* @dev RESTRICTION: Admin only
*/
function removeAllowedGatekeeper(address gatekeeper) external;
}
contracts/interfaces/IInterestRateModel.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
/**
* @title Minterest InterestRateModel Interface
* @author Minterest
*/
interface IInterestRateModel {
/**
* @notice Calculates the current borrow interest rate per block
* @param cash The total amount of cash the market has
* @param borrows The total amount of borrows the market has outstanding
* @param protocolInterest The total amount of protocol interest the market has
* @return The borrow rate per block (as a percentage, and scaled by 1e18)
*/
function getBorrowRate(
uint256 cash,
uint256 borrows,
uint256 protocolInterest
) external view returns (uint256);
/**
* @notice Calculates the current supply interest rate per block
* @param cash The total amount of cash the market has
* @param borrows The total amount of borrows the market has outstanding
* @param protocolInterest The total amount of protocol interest the market has
* @param protocolInterestFactorMantissa The current protocol interest factor the market has
* @return The supply rate per block (as a percentage, and scaled by 1e18)
*/
function getSupplyRate(
uint256 cash,
uint256 borrows,
uint256 protocolInterest,
uint256 protocolInterestFactorMantissa
) external view returns (uint256);
}
contracts/interfaces/ILinkageLeaf.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "./ILinkageRoot.sol";
interface ILinkageLeaf {
/**
* @notice Emitted when root contract address is changed
*/
event LinkageRootSwitched(ILinkageRoot newRoot, ILinkageRoot oldRoot);
/**
* @notice Connects new root contract address
* @param newRoot New root contract address
*/
function switchLinkageRoot(ILinkageRoot newRoot) external;
}
contracts/interfaces/ILinkageRoot.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
interface ILinkageRoot {
/**
* @notice Emitted when new root contract connected to all leafs
*/
event LinkageRootSwitch(ILinkageRoot newRoot);
/**
* @notice Emitted when root interconnects its contracts
*/
event LinkageRootInterconnected();
/**
* @notice Connects new root to all leafs contracts
* @param newRoot New root contract address
*/
function switchLinkageRoot(ILinkageRoot newRoot) external;
/**
* @notice Update root for all leaf contracts
* @dev Should include only leaf contracts
*/
function interconnect() external;
}
contracts/interfaces/ILiquidation.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "@openzeppelin/contracts/access/IAccessControl.sol";
import "./IMToken.sol";
import "./ILinkageLeaf.sol";
import "./IPriceOracle.sol";
/**
* This contract provides the liquidation functionality.
*/
interface ILiquidation is IAccessControl, ILinkageLeaf {
event HealthyFactorLimitChanged(uint256 oldValue, uint256 newValue);
event ReliableLiquidation(
bool isDebtHealthy,
address liquidator,
address borrower,
IMToken seizeMarket,
IMToken repayMarket,
uint256 seizeAmountUnderlying,
uint256 repayAmountUnderlying
);
/**
* @dev Local accountState for avoiding stack-depth limits in calculating liquidation amounts.
*/
struct AccountLiquidationAmounts {
uint256 accountTotalSupplyUsd;
uint256 accountTotalCollateralUsd;
uint256 accountPresumedTotalRepayUsd;
uint256 accountTotalBorrowUsd;
uint256 accountTotalCollateralUsdAfter;
uint256 accountTotalBorrowUsdAfter;
uint256 seizeAmount;
}
/**
* @notice GET The maximum allowable value of a healthy factor after liquidation, scaled by 1e18
*/
function healthyFactorLimit() external view returns (uint256);
/**
* @notice get keccak-256 hash of TRUSTED_LIQUIDATOR role
*/
function TRUSTED_LIQUIDATOR() external view returns (bytes32);
/**
* @notice get keccak-256 hash of TIMELOCK role
*/
function TIMELOCK() external view returns (bytes32);
/**
* @notice Liquidate insolvent debt position
* @param seizeMarket Market from which the account's collateral will be seized
* @param repayMarket Market from which the account's debt will be repaid
* @param borrower Account which is being liquidated
* @param repayAmount Amount of debt to be repaid
* @return (seizeAmount, repayAmount)
* @dev RESTRICTION: Trusted liquidator only
*/
function liquidateUnsafeLoan(
IMToken seizeMarket,
IMToken repayMarket,
address borrower,
uint256 repayAmount
) external returns (uint256, uint256);
/**
* @notice Accrues interest for repay and seize markets
* @param seizeMarket Market from which the account's collateral will be seized
* @param repayMarket Market from which the account's debt will be repaid
*/
function accrue(IMToken seizeMarket, IMToken repayMarket) external;
/**
* @notice Calculates account states: total balances, seize amount, new collateral and borrow state
* @param account_ The address of the borrower
* @param marketAddresses An array with addresses of markets where the debtor is in
* @param seizeMarket Market from which the account's collateral will be seized
* @param repayMarket Market from which the account's debt will be repaid
* @param repayAmount Amount of debt to be repaid
* @return accountState Struct that contains all balance parameters
*/
function calculateLiquidationAmounts(
address account_,
IMToken[] memory marketAddresses,
IMToken seizeMarket,
IMToken repayMarket,
uint256 repayAmount
) external view returns (AccountLiquidationAmounts memory);
/**
* @notice Sets a new value for healthyFactorLimit
* @dev RESTRICTION: Timelock only
*/
function setHealthyFactorLimit(uint256 newValue_) external;
}
contracts/interfaces/ILiquidationCallback.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
interface ILiquidationCallback {
/**
* @notice Executes an operation after receiving seized funds
* @dev RESTRICTION: Liquidation contract only
*/
function onLiquidation(
uint256 seizeAmount,
uint256 repayAmount,
bytes calldata params
) external returns (bool);
}
contracts/interfaces/IMToken.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "@openzeppelin/contracts/interfaces/IERC3156FlashLender.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import "@openzeppelin/contracts/access/IAccessControl.sol";
import "./IInterestRateModel.sol";
interface IMToken is IAccessControl, IERC20, IERC3156FlashLender, IERC165 {
/**
* @notice Event emitted when interest is accrued
*/
event AccrueInterest(
uint256 cashPrior,
uint256 interestAccumulated,
uint256 borrowIndex,
uint256 totalBorrows,
uint256 totalProtocolInterest
);
/**
* @notice Event emitted when tokens are lended
*/
event Lend(address lender, uint256 lendAmount, uint256 lendTokens, uint256 newTotalTokenSupply);
/**
* @notice Event emitted when tokens are redeemed
*/
event Redeem(address redeemer, uint256 redeemAmount, uint256 redeemTokens, uint256 newTotalTokenSupply);
/**
* @notice Event emitted when underlying is borrowed
*/
event Borrow(address borrower, uint256 borrowAmount, uint256 accountBorrows, uint256 totalBorrows);
/**
* @notice Event emitted when tokens are seized
*/
event Seize(
address borrower,
address receiver,
uint256 seizeTokens,
uint256 accountsTokens,
uint256 totalSupply,
uint256 seizeUnderlyingAmount
);
/**
* @notice Event emitted when a borrow is repaid
*/
event RepayBorrow(
address payer,
address borrower,
uint256 repayAmount,
uint256 accountBorrows,
uint256 totalBorrows
);
/**
* @notice Event emitted when a borrow is repaid during autoliquidation
*/
event AutoLiquidationRepayBorrow(
address borrower,
uint256 repayAmount,
uint256 accountBorrowsNew,
uint256 totalBorrowsNew,
uint256 TotalProtocolInterestNew
);
/**
* @notice Event emitted when flash loan is executed
*/
event FlashLoanExecuted(address receiver, uint256 amount, uint256 fee);
/**
* @notice Event emitted when interestRateModel is changed
*/
event NewMarketInterestRateModel(IInterestRateModel oldInterestRateModel, IInterestRateModel newInterestRateModel);
/**
* @notice Event emitted when the protocol interest factor is changed
*/
event NewProtocolInterestFactor(
uint256 oldProtocolInterestFactorMantissa,
uint256 newProtocolInterestFactorMantissa
);
/**
* @notice Event emitted when the flash loan max share is changed
*/
event NewFlashLoanMaxShare(uint256 oldMaxShare, uint256 newMaxShare);
/**
* @notice Event emitted when the flash loan fee is changed
*/
event NewFlashLoanFee(uint256 oldFee, uint256 newFee);
/**
* @notice Event emitted when the protocol interest are added
*/
event ProtocolInterestAdded(address benefactor, uint256 addAmount, uint256 newTotalProtocolInterest);
/**
* @notice Event emitted when the protocol interest reduced
*/
event ProtocolInterestReduced(address admin, uint256 reduceAmount, uint256 newTotalProtocolInterest);
/**
* @notice Value is the Keccak-256 hash of "TIMELOCK"
*/
function TIMELOCK() external view returns (bytes32);
/**
* @notice Underlying asset for this MToken
*/
function underlying() external view returns (IERC20);
/**
* @notice EIP-20 token name for this token
*/
function name() external view returns (string memory);
/**
* @notice EIP-20 token symbol for this token
*/
function symbol() external view returns (string memory);
/**
* @notice EIP-20 token decimals for this token
*/
function decimals() external view returns (uint8);
/**
* @notice Model which tells what the current interest rate should be
*/
function interestRateModel() external view returns (IInterestRateModel);
/**
* @notice Initial exchange rate used when lending the first MTokens (used when totalTokenSupply = 0)
*/
function initialExchangeRateMantissa() external view returns (uint256);
/**
* @notice Fraction of interest currently set aside for protocol interest
*/
function protocolInterestFactorMantissa() external view returns (uint256);
/**
* @notice Block number that interest was last accrued at
*/
function accrualBlockNumber() external view returns (uint256);
/**
* @notice Accumulator of the total earned interest rate since the opening of the market
*/
function borrowIndex() external view returns (uint256);
/**
* @notice Total amount of outstanding borrows of the underlying in this market
*/
function totalBorrows() external view returns (uint256);
/**
* @notice Total amount of protocol interest of the underlying held in this market
*/
function totalProtocolInterest() external view returns (uint256);
/**
* @notice Share of market's current underlying token balance that can be used as flash loan (scaled by 1e18).
*/
function maxFlashLoanShare() external view returns (uint256);
/**
* @notice Share of flash loan amount that would be taken as fee (scaled by 1e18).
*/
function flashLoanFeeShare() external view returns (uint256);
/**
* @notice Returns total token supply
*/
function totalSupply() external view returns (uint256);
/**
* @notice Transfer `amount` tokens from `msg.sender` to `dst`
* @param dst The address of the destination account
* @param amount The number of tokens to transfer
* @return Whether or not the transfer succeeded
*/
function transfer(address dst, uint256 amount) external returns (bool);
/**
* @notice Transfer `amount` tokens from `src` to `dst`
* @param src The address of the source account
* @param dst The address of the destination account
* @param amount The number of tokens to transfer
* @return Whether or not the transfer succeeded
*/
function transferFrom(
address src,
address dst,
uint256 amount
) external returns (bool);
/**
* @notice Approve `spender` to transfer up to `amount` from `src`
* @dev This will overwrite the approval amount for `spender`
* and is subject to issues noted [here](https://eips.ethereum.org/EIPS/eip-20#approve)
* @param spender The address of the account which may transfer tokens
* @param amount The number of tokens that are approved (-1 means infinite)
* @return Whether or not the approval succeeded
*/
function approve(address spender, uint256 amount) external returns (bool);
/**
* @notice Get the current allowance from `owner` for `spender`
* @param owner The address of the account which owns the tokens to be spent
* @param spender The address of the account which may transfer tokens
* @return The number of tokens allowed to be spent (-1 means infinite)
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @notice Get the token balance of the `owner`
* @param owner The address of the account to query
* @return The number of tokens owned by `owner`
*/
function balanceOf(address owner) external view returns (uint256);
/**
* @notice Get the underlying balance of the `owner`
* @dev This also accrues interest in a transaction
* @param owner The address of the account to query
* @return The amount of underlying owned by `owner`
*/
function balanceOfUnderlying(address owner) external returns (uint256);
/**
* @notice Get a snapshot of the account's balances, and the cached exchange rate
* @dev This is used by supervisor to more efficiently perform liquidity checks.
* @param account Address of the account to snapshot
* @return (token balance, borrow balance, exchange rate mantissa)
*/
function getAccountSnapshot(address account)
external
view
returns (
uint256,
uint256,
uint256
);
/**
* @notice Returns the current per-block borrow interest rate for this mToken
* @return The borrow interest rate per block, scaled by 1e18
*/
function borrowRatePerBlock() external view returns (uint256);
/**
* @notice Returns the current per-block supply interest rate for this mToken
* @return The supply interest rate per block, scaled by 1e18
*/
function supplyRatePerBlock() external view returns (uint256);
/**
* @notice Returns the current total borrows plus accrued interest
* @return The total borrows with interest
*/
function totalBorrowsCurrent() external returns (uint256);
/**
* @notice Accrue interest to updated borrowIndex and then calculate account's
* borrow balance using the updated borrowIndex
* @param account The address whose balance should be calculated after updating borrowIndex
* @return The calculated balance
*/
function borrowBalanceCurrent(address account) external returns (uint256);
/**
* @notice Return the borrow balance of account based on stored data
* @param account The address whose balance should be calculated
* @return The calculated balance
*/
function borrowBalanceStored(address account) external view returns (uint256);
/**
* @notice Accrue interest then return the up-to-date exchange rate
* @return Calculated exchange rate scaled by 1e18
*/
function exchangeRateCurrent() external returns (uint256);
/**
* @notice Calculates the exchange rate from the underlying to the MToken
* @dev This function does not accrue interest before calculating the exchange rate
* @return Calculated exchange rate scaled by 1e18
*/
function exchangeRateStored() external view returns (uint256);
/**
* @notice Get cash balance of this mToken in the underlying asset
* @return The quantity of underlying asset owned by this contract
*/
function getCash() external view returns (uint256);
/**
* @notice Applies accrued interest to total borrows and protocol interest
* @dev This calculates interest accrued from the last checkpointed block
* up to the current block and writes new checkpoint to storage.
*/
function accrueInterest() external;
/**
* @notice Sender supplies assets into the market and receives mTokens in exchange
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param lendAmount The amount of the underlying asset to supply
*/
function lend(uint256 lendAmount) external;
/**
* @notice Sender redeems mTokens in exchange for the underlying asset
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param redeemTokens The number of mTokens to redeem into underlying
*/
function redeem(uint256 redeemTokens) external;
/**
* @notice Redeems all mTokens for account in exchange for the underlying asset.
* Can only be called within the AML system!
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param account An account that is potentially sanctioned by the AML system
*/
function redeemByAmlDecision(address account) external;
/**
* @notice Sender redeems mTokens in exchange for a specified amount of underlying asset
* @dev Accrues interest whether or not the operation succeeds, unless reverted
* @param redeemAmount The amount of underlying to receive from redeeming mTokens
*/
function redeemUnderlying(uint256 redeemAmount) external;
/**
* @notice Sender borrows assets from the protocol to their own address
* @param borrowAmount The amount of the underlying asset to borrow
*/
function borrow(uint256 borrowAmount) external;
/**
* @notice Sender repays their own borrow
* @param repayAmount The amount to repay
*/
function repayBorrow(uint256 repayAmount) external;
/**
* @notice Sender repays a borrow belonging to borrower
* @param borrower the account with the debt being payed off
* @param repayAmount The amount to repay
*/
function repayBorrowBehalf(address borrower, uint256 repayAmount) external;
/**
* @notice Liquidator repays a borrow belonging to borrower
* @param borrower_ the account with the debt being payed off
* @param repayAmount_ the amount of underlying tokens being returned
*/
function autoLiquidationRepayBorrow(address borrower_, uint256 repayAmount_) external;
/**
* @notice A public function to sweep accidental ERC-20 transfers to this contract.
* Tokens are sent to admin (timelock)
* @param token The address of the ERC-20 token to sweep
* @dev RESTRICTION: Admin only.
*/
function sweepToken(IERC20 token, address admin_) external;
/**
* @notice Burns collateral tokens at the borrower's address, transfer underlying assets
to the Liquidator address.
* @dev Called only during an auto liquidation process, msg.sender must be the Liquidation contract.
* @param borrower_ The account having collateral seized
* @param seizeUnderlyingAmount_ The number of underlying assets to seize. The caller must ensure
that the parameter is greater than zero.
* @param isLoanInsignificant_ Marker for insignificant loan whose collateral must be credited to the
protocolInterest
* @param receiver_ Address that receives accounts collateral
*/
function autoLiquidationSeize(
address borrower_,
uint256 seizeUnderlyingAmount_,
bool isLoanInsignificant_,
address receiver_
) external;
/**
* @notice The amount of currency available to be lent.
* @param token The loan currency.
* @return The amount of `token` that can be borrowed.
*/
function maxFlashLoan(address token) external view returns (uint256);
/**
* @notice The fee to be charged for a given loan.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @return The amount of `token` to be charged for the loan, on top of the returned principal.
*/
function flashFee(address token, uint256 amount) external view returns (uint256);
/**
* @notice Initiate a flash loan.
* @param receiver The receiver of the tokens in the loan, and the receiver of the callback.
* @param token The loan currency.
* @param amount The amount of tokens lent.
* @param data Arbitrary data structure, intended to contain user-defined parameters.
*/
function flashLoan(
IERC3156FlashBorrower receiver,
address token,
uint256 amount,
bytes calldata data
) external returns (bool);
/**
* @notice accrues interest and sets a new protocol interest factor for the protocol
* @dev Admin function to accrue interest and set a new protocol interest factor
* @dev RESTRICTION: Timelock only.
*/
function setProtocolInterestFactor(uint256 newProtocolInterestFactorMantissa) external;
/**
* @notice Accrues interest and increase protocol interest by transferring from msg.sender
* @param addAmount_ Amount of addition to protocol interest
*/
function addProtocolInterest(uint256 addAmount_) external;
/**
* @notice Can only be called by liquidation contract. Increase protocol interest by transferring from payer.
* @dev Calling code should make sure that accrueInterest() was called before.
* @param payer_ The address from which the protocol interest will be transferred
* @param addAmount_ Amount of addition to protocol interest
*/
function addProtocolInterestBehalf(address payer_, uint256 addAmount_) external;
/**
* @notice Accrues interest and reduces protocol interest by transferring to admin
* @param reduceAmount Amount of reduction to protocol interest
* @dev RESTRICTION: Admin only.
*/
function reduceProtocolInterest(uint256 reduceAmount, address admin_) external;
/**
* @notice accrues interest and updates the interest rate model using setInterestRateModelFresh
* @dev Admin function to accrue interest and update the interest rate model
* @param newInterestRateModel the new interest rate model to use
* @dev RESTRICTION: Timelock only.
*/
function setInterestRateModel(IInterestRateModel newInterestRateModel) external;
/**
* @notice Updates share of markets cash that can be used as maximum amount of flash loan.
* @param newMax New max amount share
* @dev RESTRICTION: Timelock only.
*/
function setFlashLoanMaxShare(uint256 newMax) external;
/**
* @notice Updates fee of flash loan.
* @param newFee New fee share of flash loan
* @dev RESTRICTION: Timelock only.
*/
function setFlashLoanFeeShare(uint256 newFee) external;
}
contracts/interfaces/IPriceOracle.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "./IMToken.sol";
interface IPriceOracle {
/**
* @notice Get the underlying price of a mToken asset
* @param mToken The mToken to get the underlying price of
* @return The underlying asset price mantissa (scaled by 1e18).
* Zero means the price is unavailable.
*
* @dev Price should be scaled to 1e18 for tokens with tokenDecimals = 1e18
* and for 1e30 for tokens with tokenDecimals = 1e6.
*/
function getUnderlyingPrice(IMToken mToken) external view returns (uint256);
/**
* @notice Return price for an asset
* @param asset address of token
* @return The underlying asset price mantissa (scaled by 1e18).
* Zero means the price is unavailable.
* @dev Price should be scaled to 1e18 for tokens with tokenDecimals = 1e18
* and for 1e30 for tokens with tokenDecimals = 1e6.
*/
function getAssetPrice(address asset) external view returns (uint256);
}
contracts/libraries/ErrorCodes.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
library ErrorCodes {
// Common
string internal constant ADMIN_ONLY = "E101";
string internal constant UNAUTHORIZED = "E102";
string internal constant OPERATION_PAUSED = "E103";
string internal constant WHITELISTED_ONLY = "E104";
string internal constant ADDRESS_IS_NOT_IN_AML_SYSTEM = "E105";
string internal constant ADDRESS_IS_BLACKLISTED = "E106";
// Invalid input
string internal constant ADMIN_ADDRESS_CANNOT_BE_ZERO = "E201";
string internal constant INVALID_REDEEM = "E202";
string internal constant REDEEM_TOO_MUCH = "E203";
string internal constant MARKET_NOT_LISTED = "E204";
string internal constant INSUFFICIENT_LIQUIDITY = "E205";
string internal constant INVALID_SENDER = "E206";
string internal constant BORROW_CAP_REACHED = "E207";
string internal constant BALANCE_OWED = "E208";
string internal constant UNRELIABLE_LIQUIDATOR = "E209";
string internal constant INVALID_DESTINATION = "E210";
string internal constant INSUFFICIENT_STAKE = "E211";
string internal constant INVALID_DURATION = "E212";
string internal constant INVALID_PERIOD_RATE = "E213";
string internal constant EB_TIER_LIMIT_REACHED = "E214";
string internal constant LQ_INCORRECT_REPAY_AMOUNT = "E215";
string internal constant LQ_INSUFFICIENT_SEIZE_AMOUNT = "E216";
string internal constant EB_TIER_DOES_NOT_EXIST = "E217";
string internal constant EB_ZERO_TIER_CANNOT_BE_ENABLED = "E218";
string internal constant EB_ALREADY_ACTIVATED_TIER = "E219";
string internal constant EB_END_BLOCK_MUST_BE_LARGER_THAN_CURRENT = "E220";
string internal constant EB_CANNOT_MINT_TOKEN_FOR_ACTIVATED_TIER = "E221";
string internal constant EB_EMISSION_BOOST_IS_NOT_IN_RANGE = "E222";
string internal constant TARGET_ADDRESS_CANNOT_BE_ZERO = "E223";
string internal constant INSUFFICIENT_TOKEN_IN_VESTING_CONTRACT = "E224";
string internal constant VESTING_SCHEDULE_ALREADY_EXISTS = "E225";
string internal constant INSUFFICIENT_TOKENS_TO_CREATE_SCHEDULE = "E226";
string internal constant NO_VESTING_SCHEDULE = "E227";
string internal constant MNT_AMOUNT_IS_ZERO = "E230";
string internal constant INCORRECT_AMOUNT = "E231";
string internal constant MEMBERSHIP_LIMIT = "E232";
string internal constant MEMBER_NOT_EXIST = "E233";
string internal constant MEMBER_ALREADY_ADDED = "E234";
string internal constant MEMBERSHIP_LIMIT_REACHED = "E235";
string internal constant REPORTED_PRICE_SHOULD_BE_GREATER_THAN_ZERO = "E236";
string internal constant MTOKEN_ADDRESS_CANNOT_BE_ZERO = "E237";
string internal constant TOKEN_ADDRESS_CANNOT_BE_ZERO = "E238";
string internal constant REDEEM_TOKENS_OR_REDEEM_AMOUNT_MUST_BE_ZERO = "E239";
string internal constant FL_TOKEN_IS_NOT_UNDERLYING = "E240";
string internal constant FL_AMOUNT_IS_TOO_LARGE = "E241";
string internal constant FL_CALLBACK_FAILED = "E242";
string internal constant EB_MARKET_INDEX_IS_LESS_THAN_USER_INDEX = "E254";
string internal constant LQ_UNSUPPORTED_FULL_REPAY = "E255";
string internal constant LQ_UNSUPPORTED_FULL_SEIZE = "E256";
string internal constant LQ_UNSUPPORTED_MARKET_RECEIVED = "E257";
string internal constant LQ_UNSUCCESSFUL_CALLBACK = "E258";
string internal constant FL_UNAUTHORIZED_CALLBACK = "E270";
string internal constant FL_INCORRECT_TOKEN_OUT_DEVIATION = "E271";
string internal constant FL_SWAP_CALL_FAILS = "E272";
string internal constant FL_INVALID_AMOUNT_TOKEN_IN_SPENT = "E273";
string internal constant FL_INVALID_AMOUNT_TOKEN_OUT_RECEIVED = "E274";
string internal constant FL_EXACT_IN_INCORRECT_ALLOWANCE_AFTER = "E275";
string internal constant FL_RECEIVER_NOT_FOUND = "E276";
// Protocol errors
string internal constant INVALID_PRICE = "E301";
string internal constant MARKET_NOT_FRESH = "E302";
string internal constant BORROW_RATE_TOO_HIGH = "E303";
string internal constant INSUFFICIENT_TOKEN_CASH = "E304";
string internal constant INSUFFICIENT_TOKENS_FOR_RELEASE = "E305";
string internal constant INSUFFICIENT_MNT_FOR_GRANT = "E306";
string internal constant TOKEN_TRANSFER_IN_UNDERFLOW = "E307";
string internal constant NOT_PARTICIPATING_IN_BUYBACK = "E308";
string internal constant NOT_ENOUGH_PARTICIPATING_ACCOUNTS = "E309";
string internal constant NOTHING_TO_DISTRIBUTE = "E310";
string internal constant ALREADY_PARTICIPATING_IN_BUYBACK = "E311";
string internal constant MNT_APPROVE_FAILS = "E312";
string internal constant TOO_EARLY_TO_DRIP = "E313";
string internal constant BB_UNSTAKE_TOO_EARLY = "E314";
string internal constant INSUFFICIENT_SHORTFALL = "E315";
string internal constant HEALTHY_FACTOR_NOT_IN_RANGE = "E316";
string internal constant BUYBACK_DRIPS_ALREADY_HAPPENED = "E317";
string internal constant EB_INDEX_SHOULD_BE_GREATER_THAN_INITIAL = "E318";
string internal constant NO_VESTING_SCHEDULES = "E319";
string internal constant INSUFFICIENT_UNRELEASED_TOKENS = "E320";
string internal constant ORACLE_PRICE_EXPIRED = "E321";
string internal constant TOKEN_NOT_FOUND = "E322";
string internal constant RECEIVED_PRICE_HAS_INVALID_ROUND = "E323";
string internal constant FL_PULL_AMOUNT_IS_TOO_LOW = "E324";
string internal constant INSUFFICIENT_TOTAL_PROTOCOL_INTEREST = "E325";
string internal constant BB_ACCOUNT_RECENTLY_VOTED = "E326";
string internal constant PRICE_FEED_ID_NOT_FOUND = "E327";
string internal constant INCORRECT_PRICE_MULTIPLIER = "E328";
string internal constant LL_NEW_ROOT_CANNOT_BE_ZERO = "E329";
string internal constant RH_PAYOUT_FROM_FUTURE = "E330";
string internal constant RH_ACCRUE_WITHOUT_UNLOCK = "E331";
string internal constant RH_LERP_DELTA_IS_GREATER_THAN_PERIOD = "E332";
string internal constant PRICE_FEED_ADDRESS_NOT_FOUND = "E333";
// Invalid input - Admin functions
string internal constant ZERO_EXCHANGE_RATE = "E401";
string internal constant SECOND_INITIALIZATION = "E402";
string internal constant MARKET_ALREADY_LISTED = "E403";
string internal constant IDENTICAL_VALUE = "E404";
string internal constant ZERO_ADDRESS = "E405";
string internal constant EC_INVALID_PROVIDER_REPRESENTATIVE = "E406";
string internal constant EC_PROVIDER_CANT_BE_REPRESENTATIVE = "E407";
string internal constant OR_ORACLE_ADDRESS_CANNOT_BE_ZERO = "E408";
string internal constant OR_UNDERLYING_TOKENS_DECIMALS_SHOULD_BE_GREATER_THAN_ZERO = "E409";
string internal constant OR_REPORTER_MULTIPLIER_SHOULD_BE_GREATER_THAN_ZERO = "E410";
string internal constant INVALID_TOKEN = "E411";
string internal constant INVALID_PROTOCOL_INTEREST_FACTOR_MANTISSA = "E412";
string internal constant INVALID_REDUCE_AMOUNT = "E413";
string internal constant LIQUIDATION_FEE_MANTISSA_SHOULD_BE_GREATER_THAN_ZERO = "E414";
string internal constant INVALID_UTILISATION_FACTOR_MANTISSA = "E415";
string internal constant INVALID_MTOKENS_OR_BORROW_CAPS = "E416";
string internal constant FL_PARAM_IS_TOO_LARGE = "E417";
string internal constant MNT_INVALID_NONVOTING_PERIOD = "E418";
string internal constant INPUT_ARRAY_LENGTHS_ARE_NOT_EQUAL = "E419";
string internal constant EC_INVALID_BOOSTS = "E420";
string internal constant EC_ACCOUNT_IS_ALREADY_LIQUIDITY_PROVIDER = "E421";
string internal constant EC_ACCOUNT_HAS_NO_AGREEMENT = "E422";
string internal constant OR_TIMESTAMP_THRESHOLD_SHOULD_BE_GREATER_THAN_ZERO = "E423";
string internal constant OR_UNDERLYING_TOKENS_DECIMALS_TOO_BIG = "E424";
string internal constant OR_REPORTER_MULTIPLIER_TOO_BIG = "E425";
string internal constant SHOULD_HAVE_REVOCABLE_SCHEDULE = "E426";
string internal constant MEMBER_NOT_IN_DELAY_LIST = "E427";
string internal constant DELAY_LIST_LIMIT = "E428";
string internal constant NUMBER_IS_NOT_IN_SCALE = "E429";
string internal constant BB_STRATUM_OF_FIRST_LOYALTY_GROUP_IS_NOT_ZERO = "E430";
string internal constant INPUT_ARRAY_IS_EMPTY = "E431";
string internal constant OR_INCORRECT_PRICE_FEED_ID = "E432";
string internal constant OR_PRICE_AGE_CAN_NOT_BE_ZERO = "E433";
string internal constant OR_INCORRECT_PRICE_FEED_ADDRESS = "E434";
string internal constant OR_INCORRECT_SECONDARY_PRICE_FEED_ADDRESS = "E435";
string internal constant RH_COOLDOWN_START_ALREADY_SET = "E436";
string internal constant RH_INCORRECT_COOLDOWN_START = "E437";
string internal constant RH_COOLDOWN_IS_FINISHED = "E438";
string internal constant RH_INCORRECT_NUMBER_OF_CHARGES = "E439";
string internal constant RH_INCORRECT_CHARGE_SHARE = "E440";
string internal constant RH_COOLDOWN_START_NOT_SET = "E441";
}
contracts/multichain/taiko/interfaces/IFlasherTaiko.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "../../../interfaces/IMToken.sol";
import "../../../interfaces/IFlasherBasic.sol";
import "../../../interfaces/ILiquidationCallback.sol";
import "./ILiquidationTaiko.sol";
interface IFlasherTaiko is IFlasherBasic, ILiquidationCallback {
event NewOpOnExchangeProxy(address newOpOnExchangeProxy);
struct FlashLiquidationCallbackData {
IMToken seizeMarket;
IMToken repayMarket;
bytes mainSwapData;
}
/**
* @notice get address of OpenOceanExchangeProxy contract
*/
function opOnExchangeProxy() external view returns (address);
/**
@notice Trigger liquidation of unsafe loan
and handles additional swap operations based on `mainSwapData`.
Transfers surplus asset to the treasury
@param seizeMarket Market from which the account's collateral will be seized
@param repayMarket Market from which the account's debt will be repaid
@param borrower The address of the borrower with the unsafe loan.
@param repayAmount Amount of debt to be repaid
@param mainSwapData The encoded data for executing the swap of seized assets to repaid assets after liquidation.
Required if (seizeAsset != repayAsset)
@dev RESTRICTION: GATEKEEPER only
*/
function flashLiquidation(
IMToken repayMarket,
IMToken seizeMarket,
address borrower,
uint256 repayAmount,
bytes calldata mainSwapData
) external;
/**
* @notice Set new Open Ocean exchange proxy contract address
* @dev RESTRICTION: Admin only
*/
function setOpOnExchangeProxy(address newOpOnExchangeProxy) external;
}
contracts/multichain/taiko/interfaces/ILiquidationTaiko.sol
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.17;
import "../../../interfaces/ILiquidation.sol";
interface ILiquidationTaiko is ILiquidation {
/**
* @notice Liquidate insolvent debt position.
* The similar to `liquidateUnsafeLoan`, but additional swap call-data can be provided.
* When call-data provided - executes callback function `onLiquidation` on msg.sender address.
* I.e caller must be a contract that implements `ILiquidationCallback` interface
* @param seizeMarket Market from which the account's collateral will be seized
* @param repayMarket Market from which the account's debt will be repaid
* @param borrower Account which is being liquidated
* @param repayAmount Amount of debt to be repaid
* @return (seizeAmount, repayAmount)
* @dev RESTRICTION: Trusted liquidator only
*/
function liquidateUnsafeLoanFlash(
IMToken seizeMarket,
IMToken repayMarket,
address borrower,
uint256 repayAmount,
bytes calldata data
) external returns (uint256, uint256);
/**
* @notice util function that returns seize amount based on seize && repay markets and repayAmount
*/
function getSeizeAmount(
IMToken seizeMarket_,
IMToken repayMarket_,
uint256 repayAmount_
) external view returns (uint256);
}
Compiler Settings
{"outputSelection":{"*":{"*":["*"],"":["*"]}},"optimizer":{"runs":200,"enabled":true},"metadata":{"useLiteralContent":true},"libraries":{}}
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_admin","internalType":"address"},{"type":"address","name":"_opOnExchangeProxy","internalType":"address"},{"type":"address","name":"_liquidation","internalType":"address"},{"type":"address","name":"_oracle","internalType":"address"},{"type":"address","name":"_treasuryAddress","internalType":"address"}]},{"type":"event","name":"AllowedGatekeeperRemoved","inputs":[{"type":"address","name":"bot","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"AllowedWithdrawReceiverRemoved","inputs":[{"type":"address","name":"receiver","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"MulticallSwap","inputs":[{"type":"address","name":"tokenIn","internalType":"contract IERC20","indexed":false},{"type":"address","name":"tokenOut","internalType":"contract IERC20","indexed":false},{"type":"uint256","name":"spentAmount","internalType":"uint256","indexed":false},{"type":"uint256","name":"receivedAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"NewAllowedGatekeeper","inputs":[{"type":"address","name":"bot","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"NewAllowedWithdrawReceiver","inputs":[{"type":"address","name":"receiver","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"NewLiquidation","inputs":[{"type":"address","name":"liquidation","internalType":"contract ILiquidation","indexed":false}],"anonymous":false},{"type":"event","name":"NewOpOnExchangeProxy","inputs":[{"type":"address","name":"newOpOnExchangeProxy","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"NewOracle","inputs":[{"type":"address","name":"oracle","internalType":"contract IPriceOracle","indexed":false}],"anonymous":false},{"type":"event","name":"NewTreasury","inputs":[{"type":"address","name":"newTreasuryAddress","internalType":"address","indexed":false}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"SurplusTransfer","inputs":[{"type":"address","name":"surplusAsset","internalType":"contract IERC20","indexed":false},{"type":"address","name":"treasuryAddress","internalType":"address","indexed":false},{"type":"uint256","name":"transferAmount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"TokenOutDeviationChanged","inputs":[{"type":"uint256","name":"oldValue","internalType":"uint256","indexed":false},{"type":"uint256","name":"newValue","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"event","name":"Withdraw","inputs":[{"type":"address","name":"token","internalType":"address","indexed":false},{"type":"address","name":"to","internalType":"address","indexed":false},{"type":"uint256","name":"amount","internalType":"uint256","indexed":false}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"GATEKEEPER","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addAllowedGatekeeper","inputs":[{"type":"address","name":"newGatekeeper","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"addAllowedReceiver","inputs":[{"type":"address","name":"receiver","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"allowedWithdrawReceivers","inputs":[{"type":"address","name":"","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"flashLiquidation","inputs":[{"type":"address","name":"seizeMarket","internalType":"contract IMToken"},{"type":"address","name":"repayMarket","internalType":"contract IMToken"},{"type":"address","name":"borrower","internalType":"address"},{"type":"uint256","name":"repayAmount","internalType":"uint256"},{"type":"bytes","name":"mainSwapData","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract ILiquidation"}],"name":"liquidation","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"onLiquidation","inputs":[{"type":"uint256","name":"seizeAmount","internalType":"uint256"},{"type":"uint256","name":"repayAmount","internalType":"uint256"},{"type":"bytes","name":"callbackParams","internalType":"bytes"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"opOnExchangeProxy","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IPriceOracle"}],"name":"oracle","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeAllowedGatekeeper","inputs":[{"type":"address","name":"gatekeeper","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"removeAllowedReceiver","inputs":[{"type":"address","name":"receiver","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setLiquidationAddress","inputs":[{"type":"address","name":"newLiquidationContract","internalType":"contract ILiquidation"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setOpOnExchangeProxy","inputs":[{"type":"address","name":"newOpOnExchangeProxy","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setOracleAddress","inputs":[{"type":"address","name":"newOracleContract","internalType":"contract IPriceOracle"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTokenOutDeviation","inputs":[{"type":"uint256","name":"newValue_","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setTreasuryAddress","inputs":[{"type":"address","name":"newTreasuryAddress","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"tokenOutDeviation","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"treasuryAddress","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"},{"type":"address","name":"underlying","internalType":"contract IERC20"},{"type":"address","name":"to","internalType":"address"}]}]
Contract Creation Code
0x6080604052670dbd2fc137a300006005553480156200001d57600080fd5b506040516200237738038062002377833981016040819052620000409162000236565b848383836200004f8462000127565b6200005a8362000127565b620000658262000127565b620000708162000127565b600180546001600160a01b038086166001600160a01b031992831617909255600280548584169083161790556003805492841692909116919091179055620000ba60008562000179565b620000e67f20162831d2f54c3e11eebafebfeda495d4c52c67b1708251179ec91fb76dd3b28562000179565b50505050620000fb846200012760201b60201c565b5050600680546001600160a01b0319166001600160a01b03939093169290921790915550620002f69050565b6040805180820190915260048152634534303560e01b60208201526001600160a01b038216620001755760405162461bcd60e51b81526004016200016c9190620002a6565b60405180910390fd5b5050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000175576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620001d53390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b80516001600160a01b03811681146200023157600080fd5b919050565b600080600080600060a086880312156200024f57600080fd5b6200025a8662000219565b94506200026a6020870162000219565b93506200027a6040870162000219565b92506200028a6060870162000219565b91506200029a6080870162000219565b90509295509295909350565b600060208083528351808285015260005b81811015620002d557858101830151858201604001528201620002b7565b506000604082860101526040601f19601f8301168501019250505092915050565b61207180620003066000396000f3fe608060405234801561001057600080fd5b506004361061018e5760003560e01c806391d14854116100de578063cd646d3811610097578063f5417e4511610071578063f5417e451461037d578063f615f21b14610392578063f727b481146103a5578063f8cacfdf146103b857600080fd5b8063cd646d3814610334578063d547741f14610357578063f2dfbf661461036a57600080fd5b806391d14854146102d7578063a217fddf146102ea578063b460af94146102f2578063c18c282a14610305578063c4d788c014610318578063c5f956af1461032157600080fd5b806336568abe1161014b57806377dec0291161012557806377dec0291461028b5780637dc0d1d01461029e5780637f59a761146102b157806388e6207b146102c457600080fd5b806336568abe146102525780634c69c00f146102655780636605bfda1461027857600080fd5b806301ffc9a714610193578063201086f3146101bb578063220f56da146101e6578063248a9ca3146101f957806326d74b6a1461022a5780632f2ff15d1461023f575b600080fd5b6101a66101a1366004611999565b6103cb565b60405190151581526020015b60405180910390f35b6006546101ce906001600160a01b031681565b6040516001600160a01b0390911681526020016101b2565b6101a66101f4366004611a0c565b610402565b61021c610207366004611a5f565b60009081526020819052604090206001015490565b6040519081526020016101b2565b61023d610238366004611a8d565b610654565b005b61023d61024d366004611aaa565b6106b8565b61023d610260366004611aaa565b6106e2565b61023d610273366004611a8d565b610760565b61023d610286366004611a8d565b6107c2565b61023d610299366004611a5f565b610824565b6002546101ce906001600160a01b031681565b61023d6102bf366004611a8d565b6108b0565b61023d6102d2366004611a8d565b610912565b6101a66102e5366004611aaa565b610977565b61021c600081565b61023d610300366004611ada565b6109a0565b61023d610313366004611b1c565b610b11565b61021c60055481565b6003546101ce906001600160a01b031681565b6101a6610342366004611a8d565b60046020526000908152604090205460ff1681565b61023d610365366004611aaa565b610c31565b6001546101ce906001600160a01b031681565b61021c60008051602061201c83398151915281565b61023d6103a0366004611a8d565b610c56565b61023d6103b3366004611a8d565b610cbe565b61023d6103c6366004611a8d565b610d72565b60006001600160e01b03198216637965db0b60e01b14806103fc57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6001546040805180820190915260048152630453237360e41b60208201526000916001600160a01b031633146104545760405162461bcd60e51b815260040161044b9190611bf1565b60405180910390fd5b50600061046383850185611c9c565b9050600081600001516001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104cd9190611d75565b9050600082602001516001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610513573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105379190611d75565b90506000816001600160a01b0316836001600160a01b0316146105b257600080856040015180602001905181019061056f9190611d92565b91509150600061059a86868e85600188600660009054906101000a90046001600160a01b0316610dd4565b91506105a890508b82611e29565b93505050506105bf565b6105bc888a611e29565b90505b6105c98282611049565b602084015160405163095ea7b360e01b81526001600160a01b039182166004820152602481018a90529083169063095ea7b3906044016020604051808303816000875af115801561061e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106429190611e3c565b5060019450505050505b949350505050565b600061065f816110af565b61067760008051602061201c833981519152836110bc565b6040516001600160a01b03831681527f66f6ca668db82b452a0a563295b3cffbf8b5cf370658c38b312c566bf7dc0a68906020015b60405180910390a15050565b6000828152602081905260409020600101546106d3816110af565b6106dd8383611121565b505050565b6001600160a01b03811633146107525760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161044b565b61075c82826110bc565b5050565b600061076b816110af565b610774826111a5565b600280546001600160a01b0319166001600160a01b0384169081179091556040519081527fb3eacd0e351fafdfefdec84e1cd19679b38dbcd63ea7c2c24da17fd2bc3b3c0e906020016106ac565b60006107cd816110af565b6107d6826111a5565b600380546001600160a01b0319166001600160a01b0384169081179091556040519081527fafa147634b29e2c7bd53ce194256b9f41cfb9ba3036f2b822fdd1d965beea086906020016106ac565b600061082f816110af565b6040805180820190915260048152634532373160e01b6020820152826108685760405162461bcd60e51b815260040161044b9190611bf1565b50600580549083905560408051828152602081018590527f802ea6ad911368c78eebeb96fe725a9cc77eb58c69fbb491a0b8d4ce1209543a91015b60405180910390a1505050565b60006108bb816110af565b6108c4826111a5565b600680546001600160a01b0319166001600160a01b0384169081179091556040519081527f5741f36bc4e3ebceca2d72a11fb55d19c18dd5466d48173734077a62df4c6d2f906020016106ac565b600061091d816110af565b610926826111a5565b61093e60008051602061201c83398151915283611121565b6040516001600160a01b03831681527fa65dc8373ae49968116d1b04f921529539a545376d416078e4af791ba0d4ff0e906020016106ac565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60006109ab816110af565b6001600160a01b0382166000908152600460208181526040928390205483518085019094529183526322991b9b60e11b9083015283919060ff16610a025760405162461bcd60e51b815260040161044b9190611bf1565b506040516370a0823160e01b815230600482015285906001600160a01b038616906370a0823190602401602060405180830381865afa158015610a49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6d9190611e5e565b1015604051806040016040528060048152602001634532303560e01b81525090610aaa5760405162461bcd60e51b815260040161044b9190611bf1565b50604080516001600160a01b038087168252851660208201529081018690527f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb9060600160405180910390a1610b0a6001600160a01b03851684876111e7565b5050505050565b60008051602061201c833981519152610b29816110af565b60006040518060600160405280896001600160a01b03168152602001886001600160a01b0316815260200185858080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050915250604051610b9c9190602001611e77565b60408051601f1981840301815290829052600154632b5c54bf60e21b83529092506001600160a01b03169063ad7152fc90610be3908b908b908b908b908890600401611eb2565b60408051808303816000875af1158015610c01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c259190611eed565b50505050505050505050565b600082815260208190526040902060010154610c4c816110af565b6106dd83836110bc565b6000610c61816110af565b610c6a826111a5565b6001600160a01b038216600081815260046020908152604091829020805460ff1916600117905590519182527f75e819533d8ef979234a86a6d5ab81c293a5a30e69f167a94265284c753b1f4591016106ac565b6000610cc9816110af565b6001600160a01b0382166000908152600460208181526040928390205483518085019094529183526322991b9b60e11b9083015283919060ff16610d205760405162461bcd60e51b815260040161044b9190611bf1565b506001600160a01b038316600081815260046020908152604091829020805460ff1916905590519182527f9c83b17aa8591f34e0fecaa75fd19a4396758ad7146783f9e9d0c95f8f6ff99991016108a3565b6000610d7d816110af565b610d86826111a5565b600180546001600160a01b0319166001600160a01b0384169081179091556040519081527fc6432123028870aaa29ecf2c788a6b41a095a7bc9ba430ba6991459dc49a091d906020016106ac565b6040516370a0823160e01b8152306004820152600090819081906001600160a01b038b16906370a0823190602401602060405180830381865afa158015610e1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e439190611e5e565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038b16906370a0823190602401602060405180830381865afa158015610e8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb19190611e5e565b9050610ec76001600160a01b038c16868b61124a565b610eee85876040518060400160405280600481526020016322991b9960e11b81525061135f565b506040516370a0823160e01b81523060048201526001600160a01b038c16906370a0823190602401602060405180830381865afa158015610f33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f579190611e5e565b610f619083611e29565b6040516370a0823160e01b815230600482015290945081906001600160a01b038c16906370a0823190602401602060405180830381865afa158015610faa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fce9190611e5e565b610fd89190611e29565b9250610fe98785858e8d8d8b61136e565b604080516001600160a01b03808e1682528c166020820152908101859052606081018490527fb477440dc92f1fe902b2bab444b11ee6fd21df9d9f24ef2289102c036e8776a99060800160405180910390a1505097509795505050505050565b600354604080516001600160a01b03858116825290921660208301819052908201839052907f46dbfa196b84ffa3337d4f188c57c55407bf719e6292278850193c7eb1f7716b9060600160405180910390a16106dd6001600160a01b03841682846111e7565b6110b9813361153d565b50565b6110c68282610977565b1561075c576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b61112b8282610977565b61075c576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556111613390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6040805180820190915260048152634534303560e01b60208201526001600160a01b03821661075c5760405162461bcd60e51b815260040161044b9190611bf1565b6040516001600160a01b0383166024820152604481018290526106dd90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611596565b8015806112c45750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa15801561129e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112c29190611e5e565b155b61132f5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606482015260840161044b565b6040516001600160a01b0383166024820152604481018290526106dd90849063095ea7b360e01b90606401611213565b606061064c848460008561166b565b8615611482576040805180820190915260048152634532373360e01b6020820152838711156113b05760405162461bcd60e51b815260040161044b9190611bf1565b50604080518082019091526004815263114c8dcd60e21b6020820152828610156113ed5760405162461bcd60e51b815260040161044b9190611bf1565b50604051636eb1769f60e11b81523060048201526001600160a01b0382811660248301526000919086169063dd62ed3e90604401602060405180830381865afa15801561143e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114629190611e5e565b111561147d5761147d6001600160a01b03851682600061124a565b611534565b6040805180820190915260048152634532373360e01b6020820152838711156114be5760405162461bcd60e51b815260040161044b9190611bf1565b50670de0b6b3a7640000600554836114d69190611f11565b6114e09190611f28565b85101560405180604001604052806004815260200163114c8dcd60e21b8152509061151e5760405162461bcd60e51b815260040161044b9190611bf1565b506115346001600160a01b03851682600061124a565b50505050505050565b6115478282610977565b61075c5761155481611746565b61155f836020611758565b604051602001611570929190611f4a565b60408051601f198184030181529082905262461bcd60e51b825261044b91600401611bf1565b60006115eb826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661135f9092919063ffffffff16565b905080516000148061160c57508080602001905181019061160c9190611e3c565b6106dd5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161044b565b6060824710156116cc5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161044b565b600080866001600160a01b031685876040516116e89190611fbf565b60006040518083038185875af1925050503d8060008114611725576040519150601f19603f3d011682016040523d82523d6000602084013e61172a565b606091505b509150915061173b878383876118fb565b979650505050505050565b60606103fc6001600160a01b03831660145b60606000611767836002611f11565b611772906002611fdb565b67ffffffffffffffff81111561178a5761178a611c04565b6040519080825280601f01601f1916602001820160405280156117b4576020820181803683370190505b509050600360fc1b816000815181106117cf576117cf611fee565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106117fe576117fe611fee565b60200101906001600160f81b031916908160001a9053506000611822846002611f11565b61182d906001611fdb565b90505b60018111156118a5576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061186157611861611fee565b1a60f81b82828151811061187757611877611fee565b60200101906001600160f81b031916908160001a90535060049490941c9361189e81612004565b9050611830565b5083156118f45760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161044b565b9392505050565b6060831561196a578251600003611963576001600160a01b0385163b6119635760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161044b565b508161064c565b61064c838381511561197f5781518083602001fd5b8060405162461bcd60e51b815260040161044b9190611bf1565b6000602082840312156119ab57600080fd5b81356001600160e01b0319811681146118f457600080fd5b60008083601f8401126119d557600080fd5b50813567ffffffffffffffff8111156119ed57600080fd5b602083019150836020828501011115611a0557600080fd5b9250929050565b60008060008060608587031215611a2257600080fd5b8435935060208501359250604085013567ffffffffffffffff811115611a4757600080fd5b611a53878288016119c3565b95989497509550505050565b600060208284031215611a7157600080fd5b5035919050565b6001600160a01b03811681146110b957600080fd5b600060208284031215611a9f57600080fd5b81356118f481611a78565b60008060408385031215611abd57600080fd5b823591506020830135611acf81611a78565b809150509250929050565b600080600060608486031215611aef57600080fd5b833592506020840135611b0181611a78565b91506040840135611b1181611a78565b809150509250925092565b60008060008060008060a08789031215611b3557600080fd5b8635611b4081611a78565b95506020870135611b5081611a78565b94506040870135611b6081611a78565b935060608701359250608087013567ffffffffffffffff811115611b8357600080fd5b611b8f89828a016119c3565b979a9699509497509295939492505050565b60005b83811015611bbc578181015183820152602001611ba4565b50506000910152565b60008151808452611bdd816020860160208601611ba1565b601f01601f19169290920160200192915050565b6020815260006118f46020830184611bc5565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff81118282101715611c3d57611c3d611c04565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715611c6c57611c6c611c04565b604052919050565b600067ffffffffffffffff821115611c8e57611c8e611c04565b50601f01601f191660200190565b60006020808385031215611caf57600080fd5b823567ffffffffffffffff80821115611cc757600080fd5b9084019060608287031215611cdb57600080fd5b611ce3611c1a565b8235611cee81611a78565b815282840135611cfd81611a78565b81850152604083013582811115611d1357600080fd5b80840193505086601f840112611d2857600080fd5b82359150611d3d611d3883611c74565b611c43565b8281528785848601011115611d5157600080fd5b82858501868301376000858483010152806040830152508094505050505092915050565b600060208284031215611d8757600080fd5b81516118f481611a78565b60008060408385031215611da557600080fd5b825167ffffffffffffffff811115611dbc57600080fd5b8301601f81018513611dcd57600080fd5b8051611ddb611d3882611c74565b818152866020838501011115611df057600080fd5b611e01826020830160208601611ba1565b60209590950151949694955050505050565b634e487b7160e01b600052601160045260246000fd5b818103818111156103fc576103fc611e13565b600060208284031215611e4e57600080fd5b815180151581146118f457600080fd5b600060208284031215611e7057600080fd5b5051919050565b60208152600060018060a01b0380845116602084015280602085015116604084015250604083015160608084015261064c6080840182611bc5565b6001600160a01b0386811682528581166020830152841660408201526060810183905260a06080820181905260009061173b90830184611bc5565b60008060408385031215611f0057600080fd5b505080516020909101519092909150565b80820281158282048414176103fc576103fc611e13565b600082611f4557634e487b7160e01b600052601260045260246000fd5b500490565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351611f82816017850160208801611ba1565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351611fb3816028840160208801611ba1565b01602801949350505050565b60008251611fd1818460208701611ba1565b9190910192915050565b808201808211156103fc576103fc611e13565b634e487b7160e01b600052603260045260246000fd5b60008161201357612013611e13565b50600019019056fe20162831d2f54c3e11eebafebfeda495d4c52c67b1708251179ec91fb76dd3b2a264697066735822122006486999338bd2f9b2ed8f523568a42b7b44b32aa33f87db30c202edcdde1d9c64736f6c6343000811003300000000000000000000000066f850099e6d5dbd712d15244b65bd822f36be7e0000000000000000000000000820c2782474288bb39ba3a6e4918283d158c1a50000000000000000000000007b9de408f232ea1909cbe1abf97c92ad244fc870000000000000000000000000a7927a4c99fa7b3edd5b27b1ac498a2c177ba0e00000000000000000000000000820c2782474288bb39ba3a6e4918283d158c1a5
Deployed ByteCode
0x608060405234801561001057600080fd5b506004361061018e5760003560e01c806391d14854116100de578063cd646d3811610097578063f5417e4511610071578063f5417e451461037d578063f615f21b14610392578063f727b481146103a5578063f8cacfdf146103b857600080fd5b8063cd646d3814610334578063d547741f14610357578063f2dfbf661461036a57600080fd5b806391d14854146102d7578063a217fddf146102ea578063b460af94146102f2578063c18c282a14610305578063c4d788c014610318578063c5f956af1461032157600080fd5b806336568abe1161014b57806377dec0291161012557806377dec0291461028b5780637dc0d1d01461029e5780637f59a761146102b157806388e6207b146102c457600080fd5b806336568abe146102525780634c69c00f146102655780636605bfda1461027857600080fd5b806301ffc9a714610193578063201086f3146101bb578063220f56da146101e6578063248a9ca3146101f957806326d74b6a1461022a5780632f2ff15d1461023f575b600080fd5b6101a66101a1366004611999565b6103cb565b60405190151581526020015b60405180910390f35b6006546101ce906001600160a01b031681565b6040516001600160a01b0390911681526020016101b2565b6101a66101f4366004611a0c565b610402565b61021c610207366004611a5f565b60009081526020819052604090206001015490565b6040519081526020016101b2565b61023d610238366004611a8d565b610654565b005b61023d61024d366004611aaa565b6106b8565b61023d610260366004611aaa565b6106e2565b61023d610273366004611a8d565b610760565b61023d610286366004611a8d565b6107c2565b61023d610299366004611a5f565b610824565b6002546101ce906001600160a01b031681565b61023d6102bf366004611a8d565b6108b0565b61023d6102d2366004611a8d565b610912565b6101a66102e5366004611aaa565b610977565b61021c600081565b61023d610300366004611ada565b6109a0565b61023d610313366004611b1c565b610b11565b61021c60055481565b6003546101ce906001600160a01b031681565b6101a6610342366004611a8d565b60046020526000908152604090205460ff1681565b61023d610365366004611aaa565b610c31565b6001546101ce906001600160a01b031681565b61021c60008051602061201c83398151915281565b61023d6103a0366004611a8d565b610c56565b61023d6103b3366004611a8d565b610cbe565b61023d6103c6366004611a8d565b610d72565b60006001600160e01b03198216637965db0b60e01b14806103fc57506301ffc9a760e01b6001600160e01b03198316145b92915050565b6001546040805180820190915260048152630453237360e41b60208201526000916001600160a01b031633146104545760405162461bcd60e51b815260040161044b9190611bf1565b60405180910390fd5b50600061046383850185611c9c565b9050600081600001516001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa1580156104a9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906104cd9190611d75565b9050600082602001516001600160a01b0316636f307dc36040518163ffffffff1660e01b8152600401602060405180830381865afa158015610513573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105379190611d75565b90506000816001600160a01b0316836001600160a01b0316146105b257600080856040015180602001905181019061056f9190611d92565b91509150600061059a86868e85600188600660009054906101000a90046001600160a01b0316610dd4565b91506105a890508b82611e29565b93505050506105bf565b6105bc888a611e29565b90505b6105c98282611049565b602084015160405163095ea7b360e01b81526001600160a01b039182166004820152602481018a90529083169063095ea7b3906044016020604051808303816000875af115801561061e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906106429190611e3c565b5060019450505050505b949350505050565b600061065f816110af565b61067760008051602061201c833981519152836110bc565b6040516001600160a01b03831681527f66f6ca668db82b452a0a563295b3cffbf8b5cf370658c38b312c566bf7dc0a68906020015b60405180910390a15050565b6000828152602081905260409020600101546106d3816110af565b6106dd8383611121565b505050565b6001600160a01b03811633146107525760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b606482015260840161044b565b61075c82826110bc565b5050565b600061076b816110af565b610774826111a5565b600280546001600160a01b0319166001600160a01b0384169081179091556040519081527fb3eacd0e351fafdfefdec84e1cd19679b38dbcd63ea7c2c24da17fd2bc3b3c0e906020016106ac565b60006107cd816110af565b6107d6826111a5565b600380546001600160a01b0319166001600160a01b0384169081179091556040519081527fafa147634b29e2c7bd53ce194256b9f41cfb9ba3036f2b822fdd1d965beea086906020016106ac565b600061082f816110af565b6040805180820190915260048152634532373160e01b6020820152826108685760405162461bcd60e51b815260040161044b9190611bf1565b50600580549083905560408051828152602081018590527f802ea6ad911368c78eebeb96fe725a9cc77eb58c69fbb491a0b8d4ce1209543a91015b60405180910390a1505050565b60006108bb816110af565b6108c4826111a5565b600680546001600160a01b0319166001600160a01b0384169081179091556040519081527f5741f36bc4e3ebceca2d72a11fb55d19c18dd5466d48173734077a62df4c6d2f906020016106ac565b600061091d816110af565b610926826111a5565b61093e60008051602061201c83398151915283611121565b6040516001600160a01b03831681527fa65dc8373ae49968116d1b04f921529539a545376d416078e4af791ba0d4ff0e906020016106ac565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60006109ab816110af565b6001600160a01b0382166000908152600460208181526040928390205483518085019094529183526322991b9b60e11b9083015283919060ff16610a025760405162461bcd60e51b815260040161044b9190611bf1565b506040516370a0823160e01b815230600482015285906001600160a01b038616906370a0823190602401602060405180830381865afa158015610a49573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a6d9190611e5e565b1015604051806040016040528060048152602001634532303560e01b81525090610aaa5760405162461bcd60e51b815260040161044b9190611bf1565b50604080516001600160a01b038087168252851660208201529081018690527f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb9060600160405180910390a1610b0a6001600160a01b03851684876111e7565b5050505050565b60008051602061201c833981519152610b29816110af565b60006040518060600160405280896001600160a01b03168152602001886001600160a01b0316815260200185858080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152505050915250604051610b9c9190602001611e77565b60408051601f1981840301815290829052600154632b5c54bf60e21b83529092506001600160a01b03169063ad7152fc90610be3908b908b908b908b908890600401611eb2565b60408051808303816000875af1158015610c01573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c259190611eed565b50505050505050505050565b600082815260208190526040902060010154610c4c816110af565b6106dd83836110bc565b6000610c61816110af565b610c6a826111a5565b6001600160a01b038216600081815260046020908152604091829020805460ff1916600117905590519182527f75e819533d8ef979234a86a6d5ab81c293a5a30e69f167a94265284c753b1f4591016106ac565b6000610cc9816110af565b6001600160a01b0382166000908152600460208181526040928390205483518085019094529183526322991b9b60e11b9083015283919060ff16610d205760405162461bcd60e51b815260040161044b9190611bf1565b506001600160a01b038316600081815260046020908152604091829020805460ff1916905590519182527f9c83b17aa8591f34e0fecaa75fd19a4396758ad7146783f9e9d0c95f8f6ff99991016108a3565b6000610d7d816110af565b610d86826111a5565b600180546001600160a01b0319166001600160a01b0384169081179091556040519081527fc6432123028870aaa29ecf2c788a6b41a095a7bc9ba430ba6991459dc49a091d906020016106ac565b6040516370a0823160e01b8152306004820152600090819081906001600160a01b038b16906370a0823190602401602060405180830381865afa158015610e1f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e439190611e5e565b6040516370a0823160e01b81523060048201529091506000906001600160a01b038b16906370a0823190602401602060405180830381865afa158015610e8d573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610eb19190611e5e565b9050610ec76001600160a01b038c16868b61124a565b610eee85876040518060400160405280600481526020016322991b9960e11b81525061135f565b506040516370a0823160e01b81523060048201526001600160a01b038c16906370a0823190602401602060405180830381865afa158015610f33573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610f579190611e5e565b610f619083611e29565b6040516370a0823160e01b815230600482015290945081906001600160a01b038c16906370a0823190602401602060405180830381865afa158015610faa573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610fce9190611e5e565b610fd89190611e29565b9250610fe98785858e8d8d8b61136e565b604080516001600160a01b03808e1682528c166020820152908101859052606081018490527fb477440dc92f1fe902b2bab444b11ee6fd21df9d9f24ef2289102c036e8776a99060800160405180910390a1505097509795505050505050565b600354604080516001600160a01b03858116825290921660208301819052908201839052907f46dbfa196b84ffa3337d4f188c57c55407bf719e6292278850193c7eb1f7716b9060600160405180910390a16106dd6001600160a01b03841682846111e7565b6110b9813361153d565b50565b6110c68282610977565b1561075c576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b61112b8282610977565b61075c576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556111613390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6040805180820190915260048152634534303560e01b60208201526001600160a01b03821661075c5760405162461bcd60e51b815260040161044b9190611bf1565b6040516001600160a01b0383166024820152604481018290526106dd90849063a9059cbb60e01b906064015b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152611596565b8015806112c45750604051636eb1769f60e11b81523060048201526001600160a01b03838116602483015284169063dd62ed3e90604401602060405180830381865afa15801561129e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112c29190611e5e565b155b61132f5760405162461bcd60e51b815260206004820152603660248201527f5361666545524332303a20617070726f76652066726f6d206e6f6e2d7a65726f60448201527520746f206e6f6e2d7a65726f20616c6c6f77616e636560501b606482015260840161044b565b6040516001600160a01b0383166024820152604481018290526106dd90849063095ea7b360e01b90606401611213565b606061064c848460008561166b565b8615611482576040805180820190915260048152634532373360e01b6020820152838711156113b05760405162461bcd60e51b815260040161044b9190611bf1565b50604080518082019091526004815263114c8dcd60e21b6020820152828610156113ed5760405162461bcd60e51b815260040161044b9190611bf1565b50604051636eb1769f60e11b81523060048201526001600160a01b0382811660248301526000919086169063dd62ed3e90604401602060405180830381865afa15801561143e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906114629190611e5e565b111561147d5761147d6001600160a01b03851682600061124a565b611534565b6040805180820190915260048152634532373360e01b6020820152838711156114be5760405162461bcd60e51b815260040161044b9190611bf1565b50670de0b6b3a7640000600554836114d69190611f11565b6114e09190611f28565b85101560405180604001604052806004815260200163114c8dcd60e21b8152509061151e5760405162461bcd60e51b815260040161044b9190611bf1565b506115346001600160a01b03851682600061124a565b50505050505050565b6115478282610977565b61075c5761155481611746565b61155f836020611758565b604051602001611570929190611f4a565b60408051601f198184030181529082905262461bcd60e51b825261044b91600401611bf1565b60006115eb826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b031661135f9092919063ffffffff16565b905080516000148061160c57508080602001905181019061160c9190611e3c565b6106dd5760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b606482015260840161044b565b6060824710156116cc5760405162461bcd60e51b815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f6044820152651c8818d85b1b60d21b606482015260840161044b565b600080866001600160a01b031685876040516116e89190611fbf565b60006040518083038185875af1925050503d8060008114611725576040519150601f19603f3d011682016040523d82523d6000602084013e61172a565b606091505b509150915061173b878383876118fb565b979650505050505050565b60606103fc6001600160a01b03831660145b60606000611767836002611f11565b611772906002611fdb565b67ffffffffffffffff81111561178a5761178a611c04565b6040519080825280601f01601f1916602001820160405280156117b4576020820181803683370190505b509050600360fc1b816000815181106117cf576117cf611fee565b60200101906001600160f81b031916908160001a905350600f60fb1b816001815181106117fe576117fe611fee565b60200101906001600160f81b031916908160001a9053506000611822846002611f11565b61182d906001611fdb565b90505b60018111156118a5576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061186157611861611fee565b1a60f81b82828151811061187757611877611fee565b60200101906001600160f81b031916908160001a90535060049490941c9361189e81612004565b9050611830565b5083156118f45760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e74604482015260640161044b565b9392505050565b6060831561196a578251600003611963576001600160a01b0385163b6119635760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e7472616374000000604482015260640161044b565b508161064c565b61064c838381511561197f5781518083602001fd5b8060405162461bcd60e51b815260040161044b9190611bf1565b6000602082840312156119ab57600080fd5b81356001600160e01b0319811681146118f457600080fd5b60008083601f8401126119d557600080fd5b50813567ffffffffffffffff8111156119ed57600080fd5b602083019150836020828501011115611a0557600080fd5b9250929050565b60008060008060608587031215611a2257600080fd5b8435935060208501359250604085013567ffffffffffffffff811115611a4757600080fd5b611a53878288016119c3565b95989497509550505050565b600060208284031215611a7157600080fd5b5035919050565b6001600160a01b03811681146110b957600080fd5b600060208284031215611a9f57600080fd5b81356118f481611a78565b60008060408385031215611abd57600080fd5b823591506020830135611acf81611a78565b809150509250929050565b600080600060608486031215611aef57600080fd5b833592506020840135611b0181611a78565b91506040840135611b1181611a78565b809150509250925092565b60008060008060008060a08789031215611b3557600080fd5b8635611b4081611a78565b95506020870135611b5081611a78565b94506040870135611b6081611a78565b935060608701359250608087013567ffffffffffffffff811115611b8357600080fd5b611b8f89828a016119c3565b979a9699509497509295939492505050565b60005b83811015611bbc578181015183820152602001611ba4565b50506000910152565b60008151808452611bdd816020860160208601611ba1565b601f01601f19169290920160200192915050565b6020815260006118f46020830184611bc5565b634e487b7160e01b600052604160045260246000fd5b6040516060810167ffffffffffffffff81118282101715611c3d57611c3d611c04565b60405290565b604051601f8201601f1916810167ffffffffffffffff81118282101715611c6c57611c6c611c04565b604052919050565b600067ffffffffffffffff821115611c8e57611c8e611c04565b50601f01601f191660200190565b60006020808385031215611caf57600080fd5b823567ffffffffffffffff80821115611cc757600080fd5b9084019060608287031215611cdb57600080fd5b611ce3611c1a565b8235611cee81611a78565b815282840135611cfd81611a78565b81850152604083013582811115611d1357600080fd5b80840193505086601f840112611d2857600080fd5b82359150611d3d611d3883611c74565b611c43565b8281528785848601011115611d5157600080fd5b82858501868301376000858483010152806040830152508094505050505092915050565b600060208284031215611d8757600080fd5b81516118f481611a78565b60008060408385031215611da557600080fd5b825167ffffffffffffffff811115611dbc57600080fd5b8301601f81018513611dcd57600080fd5b8051611ddb611d3882611c74565b818152866020838501011115611df057600080fd5b611e01826020830160208601611ba1565b60209590950151949694955050505050565b634e487b7160e01b600052601160045260246000fd5b818103818111156103fc576103fc611e13565b600060208284031215611e4e57600080fd5b815180151581146118f457600080fd5b600060208284031215611e7057600080fd5b5051919050565b60208152600060018060a01b0380845116602084015280602085015116604084015250604083015160608084015261064c6080840182611bc5565b6001600160a01b0386811682528581166020830152841660408201526060810183905260a06080820181905260009061173b90830184611bc5565b60008060408385031215611f0057600080fd5b505080516020909101519092909150565b80820281158282048414176103fc576103fc611e13565b600082611f4557634e487b7160e01b600052601260045260246000fd5b500490565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351611f82816017850160208801611ba1565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351611fb3816028840160208801611ba1565b01602801949350505050565b60008251611fd1818460208701611ba1565b9190910192915050565b808201808211156103fc576103fc611e13565b634e487b7160e01b600052603260045260246000fd5b60008161201357612013611e13565b50600019019056fe20162831d2f54c3e11eebafebfeda495d4c52c67b1708251179ec91fb76dd3b2a264697066735822122006486999338bd2f9b2ed8f523568a42b7b44b32aa33f87db30c202edcdde1d9c64736f6c63430008110033