Source Code
Overview
CELO Balance
CELO Value
$0.00Multichain Info
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
MiniVM
Compiler Version
v0.8.26+commit.8a97fa7a
Optimization Enabled:
Yes with 1000 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import '@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol';
import {Commands} from './libs/Commands.sol';
import {BytesLib} from './libs/BytesLib.sol';
import {IWETH9} from './interfaces/IWETH9.sol';
contract MiniVM is Initializable, AccessControlUpgradeable, UUPSUpgradeable {
using SafeERC20 for IERC20;
using BytesLib for bytes;
event ExecutionComplete(uint256 indexed commandIndex, bool indexed success);
error ExecutionFailed(uint256 commandIndex, bytes message);
error LengthMismatch();
error InvalidCommandType(uint256 commandType);
error BalanceTooLow();
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
IWETH9 public WETH9;
ISwapRouter public UniswapRouter;
uint256 private CachedValue;
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(
address defaultAdmin,
IWETH9 _wnative,
ISwapRouter _uniswapRouter
)
initializer public
{
__AccessControl_init();
__UUPSUpgradeable_init();
_grantRole(DEFAULT_ADMIN_ROLE, defaultAdmin);
WETH9 = _wnative;
UniswapRouter = _uniswapRouter;
}
function setWETH(address _WETH9) public onlyRole(DEFAULT_ADMIN_ROLE) {
WETH9 = IWETH9(_WETH9);
}
function setUniswapRouter(address _uniswapRouter) public onlyRole(DEFAULT_ADMIN_ROLE) {
UniswapRouter = ISwapRouter(_uniswapRouter);
}
function _authorizeUpgrade(address newImplementation)
internal
onlyRole(DEFAULT_ADMIN_ROLE)
override
{}
function execute(bytes calldata commands, bytes[] calldata inputs) public onlyRole(OPERATOR_ROLE) {
bool success;
bytes memory output;
uint256 numCommands = commands.length;
if (inputs.length != numCommands) revert LengthMismatch();
CachedValue = 0;
// loop through all given commands, execute them and pass along outputs as defined
for (uint256 commandIndex = 0; commandIndex < numCommands;) {
bytes1 command = commands[commandIndex];
bytes calldata input = inputs[commandIndex];
(success, output) = dispatch(command, input);
if (!success && successRequired(command)) {
revert ExecutionFailed({commandIndex: commandIndex, message: output});
}
emit ExecutionComplete(commandIndex, success);
unchecked {
commandIndex++;
}
}
}
function successRequired(bytes1 command) internal pure returns (bool) {
return command & Commands.FLAG_ALLOW_REVERT == 0;
}
function dispatch(bytes1 commandType, bytes calldata inputs) internal returns (bool success, bytes memory output) {
uint256 command = uint8(commandType & Commands.COMMAND_TYPE_MASK);
success = true;
if (command == Commands.MINT) {
address tokenAddress;
address receiverWallet;
uint256 amount;
assembly {
tokenAddress := calldataload(inputs.offset)
receiverWallet := calldataload(add(inputs.offset, 0x20))
amount := calldataload(add(inputs.offset, 0x40))
}
if (amount == type(uint256).max-1) {
amount = CachedValue;
}
(success, output) = tokenAddress.call(abi.encodeWithSignature("mint(address,uint256)", receiverWallet, amount));
if (success == true) {
CachedValue = amount;
}
} else if (command == Commands.BURN) {
address tokenAddress;
address wallet;
uint256 amount;
assembly {
tokenAddress := calldataload(inputs.offset)
wallet := calldataload(add(inputs.offset, 0x20))
amount := calldataload(add(inputs.offset, 0x40))
}
// If amount is uint256 max, use whole wallet balance
if (amount == type(uint256).max) {
amount = IERC20(tokenAddress).balanceOf(wallet);
} else if (amount == type(uint256).max-1) {
amount = CachedValue;
}
if (wallet == address(this)) {
(success, output) = tokenAddress.call(abi.encodeWithSignature("burn(uint256)", amount));
} else {
(success, output) = tokenAddress.call(abi.encodeWithSignature("burnFrom(address,uint256)", wallet, amount));
}
if (success == true) {
CachedValue = amount;
}
} else if (command == Commands.BURN_BPS) {
address tokenAddress;
address wallet;
uint256 amount;
uint256 bps;
assembly {
tokenAddress := calldataload(inputs.offset)
wallet := calldataload(add(inputs.offset, 0x20))
amount := calldataload(add(inputs.offset, 0x40))
bps := calldataload(add(inputs.offset, 0x60))
}
// If amount is uint256 max, use whole wallet balance
if (amount == type(uint256).max) {
amount = IERC20(tokenAddress).balanceOf(wallet);
} else if (amount == type(uint256).max-1) {
amount = CachedValue;
}
amount = (amount * bps) / 10_000;
if (wallet == address(this)) {
(success, output) = tokenAddress.call(abi.encodeWithSignature("burn(uint256)", amount));
} else {
(success, output) = tokenAddress.call(abi.encodeWithSignature("burnFrom(address,uint256)", wallet, amount));
}
if (success == true) {
CachedValue = amount;
}
} else if (command == Commands.TRANSFER) {
address tokenAddress;
address fromWallet;
address toWallet;
uint256 amount;
assembly {
tokenAddress := calldataload(inputs.offset)
fromWallet := calldataload(add(inputs.offset, 0x20))
toWallet := calldataload(add(inputs.offset, 0x40))
amount := calldataload(add(inputs.offset, 0x60))
}
// If amount is uint256 max, use whole wallet balance
if (amount == type(uint256).max) {
amount = IERC20(tokenAddress).balanceOf(fromWallet);
} else if (amount == type(uint256).max-1) {
amount = CachedValue;
}
if (fromWallet == address(this)) {
(success, output) = tokenAddress.call(abi.encodeWithSignature("transfer(address,uint256)", toWallet, amount));
} else {
(success, output) = tokenAddress.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", fromWallet, toWallet, amount));
}
if (success == true) {
CachedValue = amount;
}
} else if (command == Commands.TRANSFER_BPS) {
address tokenAddress;
address fromWallet;
address toWallet;
uint256 amount;
uint256 bps;
assembly {
tokenAddress := calldataload(inputs.offset)
fromWallet := calldataload(add(inputs.offset, 0x20))
toWallet := calldataload(add(inputs.offset, 0x40))
amount := calldataload(add(inputs.offset, 0x60))
bps := calldataload(add(inputs.offset, 0x80))
}
// If amount is uint256 max, use whole wallet balance
if (amount == type(uint256).max) {
amount = IERC20(tokenAddress).balanceOf(fromWallet);
} else if (amount == type(uint256).max-1) {
amount = CachedValue;
}
amount = (amount * bps) / 10_000;
if (fromWallet == address(this)) {
(success, output) = tokenAddress.call(abi.encodeWithSignature("transfer(address,uint256)", toWallet, amount));
} else {
(success, output) = tokenAddress.call(abi.encodeWithSignature("transferFrom(address,address,uint256)", fromWallet, toWallet, amount));
}
if (success == true) {
CachedValue = amount;
}
} else if (command == Commands.APPROVE) {
address tokenAddress;
address contractToApprove;
uint256 amount;
assembly {
tokenAddress := calldataload(inputs.offset)
contractToApprove := calldataload(add(inputs.offset, 0x20))
amount := calldataload(add(inputs.offset, 0x40))
}
(success, output) = tokenAddress.call(abi.encodeWithSignature("approve(address,uint256)", contractToApprove, amount));
} else if (command == Commands.PERMIT) {
address tokenAddress;
address owner;
address spender;
uint256 value;
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
assembly {
tokenAddress := calldataload(inputs.offset)
owner := calldataload(add(inputs.offset, 0x20))
spender := calldataload(add(inputs.offset, 0x40))
value := calldataload(add(inputs.offset, 0x60))
deadline := calldataload(add(inputs.offset, 0x80))
v := byte(31, calldataload(add(inputs.offset, 0xA0)))
r := calldataload(add(inputs.offset, 0xC0))
s := calldataload(add(inputs.offset, 0xE0))
}
(success, output) = tokenAddress.call(
abi.encodeWithSignature("permit(address,address,uint256,uint256,uint8,bytes32,bytes32)",
owner, spender, value, deadline, v, r, s));
} else if (command == Commands.EXECUTE_META_TRANSACTION) {
address tokenAddress;
address userAddress;
bytes32 sigR;
bytes32 sigS;
uint8 sigV;
assembly {
tokenAddress := calldataload(inputs.offset)
userAddress := calldataload(add(inputs.offset, 0x20))
// 0x40 offset is the functionSignature, decoded below
sigR := calldataload(add(inputs.offset, 0x60))
sigS := calldataload(add(inputs.offset, 0x80))
sigV := byte(31, calldataload(add(inputs.offset, 0xA0)))
}
bytes calldata functionSignature = inputs.toBytes(2);
(success, output) = tokenAddress.call(
abi.encodeWithSignature("executeMetaTransaction(address,bytes,bytes32,bytes32,uint8)",
userAddress, functionSignature, sigR, sigS, sigV));
} else if (command == Commands.WRAP_NATIVE) {
uint256 amount;
assembly {
amount := calldataload(inputs.offset)
}
// If amount is uint256 max, use whole wallet balance
if (amount == type(uint256).max) {
amount = address(this).balance;
} else if (amount == type(uint256).max-1) {
amount = CachedValue;
}
WETH9.deposit{value: amount}();
if (success == true) {
CachedValue = amount;
}
} else if (command == Commands.UNWRAP_WNATIVE) {
uint256 amount;
assembly {
amount := calldataload(inputs.offset)
}
// If amount is uint256 max, use whole wallet balance
if (amount == type(uint256).max) {
amount = WETH9.balanceOf(address(this));
} else if (amount == type(uint256).max-1) {
amount = CachedValue;
}
WETH9.withdraw(amount);
if (success == true) {
CachedValue = amount;
}
} else if (command == Commands.V3_SWAP_EXACT_IN) {
uint256 amountIn;
uint256 amountOutMinimum;
assembly {
amountIn := calldataload(inputs.offset)
amountOutMinimum := calldataload(add(inputs.offset, 0x20))
}
bytes calldata path = inputs.toBytes(2);
address tokenAddress;
assembly {
tokenAddress := shr(96, calldataload(add(path.offset, 0)))
}
if (amountIn == type(uint256).max) {
amountIn = IERC20(tokenAddress).balanceOf(address(this));
} else if (amountIn == type(uint256).max-1) {
amountIn = CachedValue;
}
ISwapRouter.ExactInputParams memory params =
ISwapRouter.ExactInputParams({
path: path,
recipient: address(this),
deadline: block.timestamp,
amountIn: amountIn,
amountOutMinimum: amountOutMinimum
});
// The call to `exactInputSingle` executes the swap.
uint256 amountOut = UniswapRouter.exactInput(params);
if (success == true) {
CachedValue = amountOut;
}
} else if (command == Commands.V3_SWAP_EXACT_OUT) {
uint256 amountInMaximum;
uint256 amountOut;
address excessAddress;
assembly {
amountInMaximum := calldataload(inputs.offset)
amountOut := calldataload(add(inputs.offset, 0x20))
excessAddress := calldataload(add(inputs.offset, 0x40))
}
bytes calldata path = inputs.toBytes(3);
address tokenAddress;
uint256 offset = path.length - 20;
assembly {
tokenAddress := shr(96, calldataload(add(path.offset, offset)))
}
ISwapRouter.ExactOutputParams memory params =
ISwapRouter.ExactOutputParams({
path: path,
recipient: address(this),
deadline: block.timestamp,
amountOut: amountOut,
amountInMaximum: amountInMaximum
});
// Executes the swap, returning the amountIn actually spent.
uint256 amountIn = UniswapRouter.exactOutput(params);
if (amountIn < amountInMaximum && excessAddress != address(this)) {
IERC20(tokenAddress).safeTransfer(excessAddress, amountInMaximum - amountIn);
}
} else {
revert InvalidCommandType(command);
}
}
receive() external payable {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/AccessControl.sol)
pragma solidity ^0.8.20;
import {IAccessControl} from "@openzeppelin/contracts/access/IAccessControl.sol";
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {ERC165Upgradeable} from "../utils/introspection/ERC165Upgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.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 AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControl, ERC165Upgradeable {
struct RoleData {
mapping(address account => bool) hasRole;
bytes32 adminRole;
}
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/// @custom:storage-location erc7201:openzeppelin.storage.AccessControl
struct AccessControlStorage {
mapping(bytes32 role => RoleData) _roles;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.AccessControl")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant AccessControlStorageLocation = 0x02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b626800;
function _getAccessControlStorage() private pure returns (AccessControlStorage storage $) {
assembly {
$.slot := AccessControlStorageLocation
}
}
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with an {AccessControlUnauthorizedAccount} error including the required role.
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function __AccessControl_init() internal onlyInitializing {
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
/**
* @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 returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
return $._roles[role].hasRole[account];
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `_msgSender()`
* is missing `role`. Overriding this function changes the behavior of the {onlyRole} modifier.
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Reverts with an {AccessControlUnauthorizedAccount} error if `account`
* is missing `role`.
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert AccessControlUnauthorizedAccount(account, role);
}
}
/**
* @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 returns (bytes32) {
AccessControlStorage storage $ = _getAccessControlStorage();
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 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 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 `callerConfirmation`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address callerConfirmation) public virtual {
if (callerConfirmation != _msgSender()) {
revert AccessControlBadConfirmation();
}
_revokeRole(role, callerConfirmation);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
AccessControlStorage storage $ = _getAccessControlStorage();
bytes32 previousAdminRole = getRoleAdmin(role);
$._roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Attempts to grant `role` to `account` and returns a boolean indicating if `role` was granted.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
if (!hasRole(role, account)) {
$._roles[role].hasRole[account] = true;
emit RoleGranted(role, account, _msgSender());
return true;
} else {
return false;
}
}
/**
* @dev Attempts to revoke `role` to `account` and returns a boolean indicating if `role` was revoked.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual returns (bool) {
AccessControlStorage storage $ = _getAccessControlStorage();
if (hasRole(role, account)) {
$._roles[role].hasRole[account] = false;
emit RoleRevoked(role, account, _msgSender());
return true;
} else {
return false;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reininitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
assembly {
$.slot := INITIALIZABLE_STORAGE
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (proxy/utils/UUPSUpgradeable.sol)
pragma solidity ^0.8.20;
import {IERC1822Proxiable} from "@openzeppelin/contracts/interfaces/draft-IERC1822.sol";
import {ERC1967Utils} from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Utils.sol";
import {Initializable} from "./Initializable.sol";
/**
* @dev An upgradeability mechanism designed for UUPS proxies. The functions included here can perform an upgrade of an
* {ERC1967Proxy}, when this contract is set as the implementation behind such a proxy.
*
* A security mechanism ensures that an upgrade does not turn off upgradeability accidentally, although this risk is
* reinstated if the upgrade retains upgradeability but removes the security mechanism, e.g. by replacing
* `UUPSUpgradeable` with a custom implementation of upgrades.
*
* The {_authorizeUpgrade} function must be overridden to include access restriction to the upgrade mechanism.
*/
abstract contract UUPSUpgradeable is Initializable, IERC1822Proxiable {
/// @custom:oz-upgrades-unsafe-allow state-variable-immutable
address private immutable __self = address(this);
/**
* @dev The version of the upgrade interface of the contract. If this getter is missing, both `upgradeTo(address)`
* and `upgradeToAndCall(address,bytes)` are present, and `upgradeTo` must be used if no function should be called,
* while `upgradeToAndCall` will invoke the `receive` function if the second argument is the empty byte string.
* If the getter returns `"5.0.0"`, only `upgradeToAndCall(address,bytes)` is present, and the second argument must
* be the empty byte string if no function should be called, making it impossible to invoke the `receive` function
* during an upgrade.
*/
string public constant UPGRADE_INTERFACE_VERSION = "5.0.0";
/**
* @dev The call is from an unauthorized context.
*/
error UUPSUnauthorizedCallContext();
/**
* @dev The storage `slot` is unsupported as a UUID.
*/
error UUPSUnsupportedProxiableUUID(bytes32 slot);
/**
* @dev Check that the execution is being performed through a delegatecall call and that the execution context is
* a proxy contract with an implementation (as defined in ERC-1967) pointing to self. This should only be the case
* for UUPS and transparent proxies that are using the current contract as their implementation. Execution of a
* function through ERC-1167 minimal proxies (clones) would not normally pass this test, but is not guaranteed to
* fail.
*/
modifier onlyProxy() {
_checkProxy();
_;
}
/**
* @dev Check that the execution is not being performed through a delegate call. This allows a function to be
* callable on the implementing contract but not through proxies.
*/
modifier notDelegated() {
_checkNotDelegated();
_;
}
function __UUPSUpgradeable_init() internal onlyInitializing {
}
function __UUPSUpgradeable_init_unchained() internal onlyInitializing {
}
/**
* @dev Implementation of the ERC-1822 {proxiableUUID} function. This returns the storage slot used by the
* implementation. It is used to validate the implementation's compatibility when performing an upgrade.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy. This is guaranteed by the `notDelegated` modifier.
*/
function proxiableUUID() external view virtual notDelegated returns (bytes32) {
return ERC1967Utils.IMPLEMENTATION_SLOT;
}
/**
* @dev Upgrade the implementation of the proxy to `newImplementation`, and subsequently execute the function call
* encoded in `data`.
*
* Calls {_authorizeUpgrade}.
*
* Emits an {Upgraded} event.
*
* @custom:oz-upgrades-unsafe-allow-reachable delegatecall
*/
function upgradeToAndCall(address newImplementation, bytes memory data) public payable virtual onlyProxy {
_authorizeUpgrade(newImplementation);
_upgradeToAndCallUUPS(newImplementation, data);
}
/**
* @dev Reverts if the execution is not performed via delegatecall or the execution
* context is not of a proxy with an ERC-1967 compliant implementation pointing to self.
* See {_onlyProxy}.
*/
function _checkProxy() internal view virtual {
if (
address(this) == __self || // Must be called through delegatecall
ERC1967Utils.getImplementation() != __self // Must be called through an active proxy
) {
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Reverts if the execution is performed via delegatecall.
* See {notDelegated}.
*/
function _checkNotDelegated() internal view virtual {
if (address(this) != __self) {
// Must not be called through delegatecall
revert UUPSUnauthorizedCallContext();
}
}
/**
* @dev Function that should revert when `msg.sender` is not authorized to upgrade the contract. Called by
* {upgradeToAndCall}.
*
* Normally, this function will use an xref:access.adoc[access control] modifier such as {Ownable-onlyOwner}.
*
* ```solidity
* function _authorizeUpgrade(address) internal onlyOwner {}
* ```
*/
function _authorizeUpgrade(address newImplementation) internal virtual;
/**
* @dev Performs an implementation upgrade with a security check for UUPS proxies, and additional setup call.
*
* As a security check, {proxiableUUID} is invoked in the new implementation, and the return value
* is expected to be the implementation slot in ERC-1967.
*
* Emits an {IERC1967-Upgraded} event.
*/
function _upgradeToAndCallUUPS(address newImplementation, bytes memory data) private {
try IERC1822Proxiable(newImplementation).proxiableUUID() returns (bytes32 slot) {
if (slot != ERC1967Utils.IMPLEMENTATION_SLOT) {
revert UUPSUnsupportedProxiableUUID(slot);
}
ERC1967Utils.upgradeToAndCall(newImplementation, data);
} catch {
// The implementation is not UUPS
revert ERC1967Utils.ERC1967InvalidImplementation(newImplementation);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/ERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import {Initializable} from "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC-165 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);
* }
* ```
*/
abstract contract ERC165Upgradeable is Initializable, IERC165 {
function __ERC165_init() internal onlyInitializing {
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (access/IAccessControl.sol)
pragma solidity ^0.8.20;
/**
* @dev External interface of AccessControl declared to support ERC-165 detection.
*/
interface IAccessControl {
/**
* @dev The `account` is missing a role.
*/
error AccessControlUnauthorizedAccount(address account, bytes32 neededRole);
/**
* @dev The caller of a function is not the expected one.
*
* NOTE: Don't confuse with {AccessControlUnauthorizedAccount}.
*/
error AccessControlBadConfirmation();
/**
* @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.
*/
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. This account bears the admin role (for the granted role).
* Expected in cases where the role was granted using the internal {AccessControl-_grantRole}.
*/
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 `callerConfirmation`.
*/
function renounceRole(bytes32 role, address callerConfirmation) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/draft-IERC1822.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1822: Universal Upgradeable Proxy Standard (UUPS) documents a method for upgradeability through a simplified
* proxy whose upgrades are fully controlled by the current implementation.
*/
interface IERC1822Proxiable {
/**
* @dev Returns the storage slot that the proxiable contract assumes is being used to store the implementation
* address.
*
* IMPORTANT: A proxy pointing at a proxiable contract should not be considered proxiable itself, because this risks
* bricking a proxy that upgrades to it, by delegating to itself until out of gas. Thus it is critical that this
* function revert if invoked through a proxy.
*/
function proxiableUUID() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC1967.sol)
pragma solidity ^0.8.20;
/**
* @dev ERC-1967: Proxy Storage Slots. This interface contains the events defined in the ERC.
*/
interface IERC1967 {
/**
* @dev Emitted when the implementation is upgraded.
*/
event Upgraded(address indexed implementation);
/**
* @dev Emitted when the admin account has changed.
*/
event AdminChanged(address previousAdmin, address newAdmin);
/**
* @dev Emitted when the beacon is changed.
*/
event BeaconUpgraded(address indexed beacon);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (proxy/beacon/IBeacon.sol)
pragma solidity ^0.8.20;
/**
* @dev This is the interface that {BeaconProxy} expects of its beacon.
*/
interface IBeacon {
/**
* @dev Must return an address that can be used as a delegate call target.
*
* {UpgradeableBeacon} will check that this address is a contract.
*/
function implementation() external view returns (address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (proxy/ERC1967/ERC1967Utils.sol)
pragma solidity ^0.8.21;
import {IBeacon} from "../beacon/IBeacon.sol";
import {IERC1967} from "../../interfaces/IERC1967.sol";
import {Address} from "../../utils/Address.sol";
import {StorageSlot} from "../../utils/StorageSlot.sol";
/**
* @dev This library provides getters and event emitting update functions for
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] slots.
*/
library ERC1967Utils {
/**
* @dev Storage slot with the address of the current implementation.
* This is the keccak-256 hash of "eip1967.proxy.implementation" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
/**
* @dev The `implementation` of the proxy is invalid.
*/
error ERC1967InvalidImplementation(address implementation);
/**
* @dev The `admin` of the proxy is invalid.
*/
error ERC1967InvalidAdmin(address admin);
/**
* @dev The `beacon` of the proxy is invalid.
*/
error ERC1967InvalidBeacon(address beacon);
/**
* @dev An upgrade function sees `msg.value > 0` that may be lost.
*/
error ERC1967NonPayable();
/**
* @dev Returns the current implementation address.
*/
function getImplementation() internal view returns (address) {
return StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 implementation slot.
*/
function _setImplementation(address newImplementation) private {
if (newImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(newImplementation);
}
StorageSlot.getAddressSlot(IMPLEMENTATION_SLOT).value = newImplementation;
}
/**
* @dev Performs implementation upgrade with additional setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-Upgraded} event.
*/
function upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit IERC1967.Upgraded(newImplementation);
if (data.length > 0) {
Address.functionDelegateCall(newImplementation, data);
} else {
_checkNonPayable();
}
}
/**
* @dev Storage slot with the admin of the contract.
* This is the keccak-256 hash of "eip1967.proxy.admin" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant ADMIN_SLOT = 0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
/**
* @dev Returns the current admin.
*
* TIP: To get this value clients can read directly from the storage slot shown below (specified by ERC-1967) using
* the https://eth.wiki/json-rpc/API#eth_getstorageat[`eth_getStorageAt`] RPC call.
* `0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103`
*/
function getAdmin() internal view returns (address) {
return StorageSlot.getAddressSlot(ADMIN_SLOT).value;
}
/**
* @dev Stores a new address in the ERC-1967 admin slot.
*/
function _setAdmin(address newAdmin) private {
if (newAdmin == address(0)) {
revert ERC1967InvalidAdmin(address(0));
}
StorageSlot.getAddressSlot(ADMIN_SLOT).value = newAdmin;
}
/**
* @dev Changes the admin of the proxy.
*
* Emits an {IERC1967-AdminChanged} event.
*/
function changeAdmin(address newAdmin) internal {
emit IERC1967.AdminChanged(getAdmin(), newAdmin);
_setAdmin(newAdmin);
}
/**
* @dev The storage slot of the UpgradeableBeacon contract which defines the implementation for this proxy.
* This is the keccak-256 hash of "eip1967.proxy.beacon" subtracted by 1.
*/
// solhint-disable-next-line private-vars-leading-underscore
bytes32 internal constant BEACON_SLOT = 0xa3f0ad74e5423aebfd80d3ef4346578335a9a72aeaee59ff6cb3582b35133d50;
/**
* @dev Returns the current beacon.
*/
function getBeacon() internal view returns (address) {
return StorageSlot.getAddressSlot(BEACON_SLOT).value;
}
/**
* @dev Stores a new beacon in the ERC-1967 beacon slot.
*/
function _setBeacon(address newBeacon) private {
if (newBeacon.code.length == 0) {
revert ERC1967InvalidBeacon(newBeacon);
}
StorageSlot.getAddressSlot(BEACON_SLOT).value = newBeacon;
address beaconImplementation = IBeacon(newBeacon).implementation();
if (beaconImplementation.code.length == 0) {
revert ERC1967InvalidImplementation(beaconImplementation);
}
}
/**
* @dev Change the beacon and trigger a setup call if data is nonempty.
* This function is payable only if the setup call is performed, otherwise `msg.value` is rejected
* to avoid stuck value in the contract.
*
* Emits an {IERC1967-BeaconUpgraded} event.
*
* CAUTION: Invoking this function has no effect on an instance of {BeaconProxy} since v5, since
* it uses an immutable beacon without looking at the value of the ERC-1967 beacon slot for
* efficiency.
*/
function upgradeBeaconToAndCall(address newBeacon, bytes memory data) internal {
_setBeacon(newBeacon);
emit IERC1967.BeaconUpgraded(newBeacon);
if (data.length > 0) {
Address.functionDelegateCall(IBeacon(newBeacon).implementation(), data);
} else {
_checkNonPayable();
}
}
/**
* @dev Reverts if `msg.value` is not zero. It can be used to avoid `msg.value` stuck in the contract
* if an upgrade doesn't perform an initialization call.
*/
function _checkNonPayable() private {
if (msg.value > 0) {
revert ERC1967NonPayable();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
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 value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of 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 value) 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 a `value` amount of tokens 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 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` 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 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 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 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @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.encodeCall(token.transfer, (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.encodeCall(token.transferFrom, (from, to, 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.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @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.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @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 silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @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.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert Errors.FailedCall();
}
}
/**
* @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 or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* 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.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @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`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) 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
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* 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[ERC 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.20;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC-1967 implementation slot:
* ```solidity
* contract ERC1967 {
* // Define the slot. Alternatively, use the SlotDerivation library to derive the slot.
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(newImplementation.code.length > 0);
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* TIP: Consider using this library along with {SlotDerivation}.
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct Int256Slot {
int256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `Int256Slot` with member `value` located at `slot`.
*/
function getInt256Slot(bytes32 slot) internal pure returns (Int256Slot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns a `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
/**
* @dev Returns a `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
assembly ("memory-safe") {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';
/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another token
/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
/// @return amountOut The amount of the received token
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
/// @return amountOut The amount of the received token
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another token
/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
/// @return amountIn The amount of the input token
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
/// @return amountIn The amount of the input token
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity ^0.8.4;
import {IERC20} from '@openzeppelin/contracts/token/ERC20/IERC20.sol';
/// @title Interface for WETH9
interface IWETH9 is IERC20 {
/// @notice Deposit ether to get wrapped ether
function deposit() external payable;
/// @notice Withdraw wrapped ether to get ether
function withdraw(uint256) external;
}// SPDX-License-Identifier: GPL-3.0-or-later
/// @title Library for Bytes Manipulation
pragma solidity ^0.8.0;
library BytesLib {
error SliceOutOfBounds();
/// @notice Decode the `_arg`-th element in `_bytes` as a dynamic array
/// @dev The decoding of `length` and `offset` is universal,
/// whereas the type declaration of `res` instructs the compiler how to read it.
/// @param _bytes The input bytes string to slice
/// @param _arg The index of the argument to extract
/// @return length Length of the array
/// @return offset Pointer to the data part of the array
function toLengthOffset(bytes calldata _bytes, uint256 _arg)
internal
pure
returns (uint256 length, uint256 offset)
{
uint256 relativeOffset;
assembly {
// The offset of the `_arg`-th element is `32 * arg`, which stores the offset of the length pointer.
// shl(5, x) is equivalent to mul(32, x)
let lengthPtr := add(_bytes.offset, calldataload(add(_bytes.offset, shl(5, _arg))))
length := calldataload(lengthPtr)
offset := add(lengthPtr, 0x20)
relativeOffset := sub(offset, _bytes.offset)
}
if (_bytes.length < length + relativeOffset) revert SliceOutOfBounds();
}
/// @notice Decode the `_arg`-th element in `_bytes` as `bytes`
/// @param _bytes The input bytes string to extract a bytes string from
/// @param _arg The index of the argument to extract
function toBytes(bytes calldata _bytes, uint256 _arg) internal pure returns (bytes calldata res) {
(uint256 length, uint256 offset) = toLengthOffset(_bytes, _arg);
assembly {
res.length := length
res.offset := offset
}
}
}// SPDX-License-Identifier: MIT
// Compatible with OpenZeppelin Contracts ^5.0.0
pragma solidity ^0.8.20;
/// @title Commands
/// @notice Command Flags used to decode commands
library Commands {
// Masks to extract certain bits of commands
bytes1 internal constant FLAG_ALLOW_REVERT = 0x80;
bytes1 internal constant COMMAND_TYPE_MASK = 0x3f;
uint256 constant MINT = 0x00;
uint256 constant BURN = 0x01; // Includes burnFrom
uint256 constant BURN_BPS = 0x02; // Includes burnFrom
uint256 constant TRANSFER = 0x03; // Includes transferFrom
uint256 constant TRANSFER_BPS = 0x04; // Includes transferFrom
uint256 constant APPROVE = 0x05; // So some other contract can use this contract's tokens (e.g. uniswap)
uint256 constant PERMIT = 0x06;
uint256 constant EXECUTE_META_TRANSACTION = 0x07;
uint256 constant WRAP_NATIVE = 0x08;
uint256 constant UNWRAP_WNATIVE = 0x09;
uint256 constant V3_SWAP_EXACT_IN = 0x0A;
uint256 constant V3_SWAP_EXACT_OUT = 0x0B;
// uint256 constant EXECUTE_SUB_PLAN = 0x0A; // Maybe for the future
}{
"optimizer": {
"enabled": true,
"runs": 1000
},
"viaIR": true,
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AccessControlBadConfirmation","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bytes32","name":"neededRole","type":"bytes32"}],"name":"AccessControlUnauthorizedAccount","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[],"name":"BalanceTooLow","type":"error"},{"inputs":[{"internalType":"address","name":"implementation","type":"address"}],"name":"ERC1967InvalidImplementation","type":"error"},{"inputs":[],"name":"ERC1967NonPayable","type":"error"},{"inputs":[{"internalType":"uint256","name":"commandIndex","type":"uint256"},{"internalType":"bytes","name":"message","type":"bytes"}],"name":"ExecutionFailed","type":"error"},{"inputs":[],"name":"FailedCall","type":"error"},{"inputs":[{"internalType":"uint256","name":"commandType","type":"uint256"}],"name":"InvalidCommandType","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"LengthMismatch","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"SliceOutOfBounds","type":"error"},{"inputs":[],"name":"UUPSUnauthorizedCallContext","type":"error"},{"inputs":[{"internalType":"bytes32","name":"slot","type":"bytes32"}],"name":"UUPSUnsupportedProxiableUUID","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"commandIndex","type":"uint256"},{"indexed":true,"internalType":"bool","name":"success","type":"bool"}],"name":"ExecutionComplete","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UPGRADE_INTERFACE_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UniswapRouter","outputs":[{"internalType":"contract ISwapRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"WETH9","outputs":[{"internalType":"contract IWETH9","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"commands","type":"bytes"},{"internalType":"bytes[]","name":"inputs","type":"bytes[]"}],"name":"execute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"defaultAdmin","type":"address"},{"internalType":"contract IWETH9","name":"_wnative","type":"address"},{"internalType":"contract ISwapRouter","name":"_uniswapRouter","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"proxiableUUID","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"callerConfirmation","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_uniswapRouter","type":"address"}],"name":"setUniswapRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_WETH9","type":"address"}],"name":"setWETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"upgradeToAndCall","outputs":[],"stateMutability":"payable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
60a080604052346100ea57306080527ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c166100d9576002600160401b03196001600160401b03821601610073575b60405161208790816100f0823960805181818161054a01526106130152f35b6001600160401b0319166001600160401b039081177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005581527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d290602090a13880610054565b63f92ee8a960e01b60005260046000fd5b600080fdfe608080604052600436101561001d575b50361561001b57600080fd5b005b60003560e01c90816301ffc9a714611a065750806324856bc314610989578063248a9ca3146109355780632f2ff15d146108d657806336568abe146108775780634aa4a4fc146108505780634f1ef286146105c457806352d1902d1461052f5780635b769f3c146104ef57806391d1485414610482578063a217fddf14610466578063ad3cb1cc14610403578063bea9849e146103c3578063c0c53b8b146101b0578063c7639d8014610189578063d547741f146101255763f5b541a6146100e5573861000f565b346101205760003660031901126101205760206040517f97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b9298152f35b600080fd5b346101205760403660031901126101205761001b600435610144611aa4565b9061018461017f826000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260016040600020015490565b611c0b565b611e9b565b346101205760003660031901126101205760206001600160a01b0360015416604051908152f35b34610120576060366003190112610120576101c9611aba565b6024356001600160a01b03811680910361012057604435906001600160a01b038216809203610120577ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c16159367ffffffffffffffff8216801590816103bb575b60011490816103b1575b1590816103a8575b5061037e5767ffffffffffffffff1982166001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0055610299918561033f575b5061028c611f68565b610294611f68565b611d11565b506001600160a01b031960005416176000556001600160a01b031960015416176001556102c257005b68ff0000000000000000197ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054167ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a1005b68ffffffffffffffffff191668010000000000000001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005585610283565b7ff92ee8a90000000000000000000000000000000000000000000000000000000060005260046000fd5b90501586610243565b303b15915061023b565b869150610231565b34610120576020366003190112610120576001600160a01b036103e4611aba565b6103ec611bb8565b166001600160a01b03196001541617600155600080f35b346101205760003660031901126101205761046260408051906104268183611b02565b600582527f352e302e30000000000000000000000000000000000000000000000000000000602083015251918291602083526020830190611b77565b0390f35b3461012057600036600319011261012057602060405160008152f35b346101205760403660031901126101205761049b611aa4565b6004356000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b6268006020526001600160a01b0360406000209116600052602052602060ff604060002054166040519015158152f35b34610120576020366003190112610120576001600160a01b03610510611aba565b610518611bb8565b166001600160a01b03196000541617600055600080f35b34610120576000366003190112610120576001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016300361059a5760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b7fe07c8dba0000000000000000000000000000000000000000000000000000000060005260046000fd5b6040366003190112610120576105d8611aba565b60243567ffffffffffffffff8111610120573660238201121561012057610609903690602481600401359101611b40565b6001600160a01b037f00000000000000000000000000000000000000000000000000000000000000001680301490811561081b575b5061059a5761064b611bb8565b6001600160a01b038216916040517f52d1902d000000000000000000000000000000000000000000000000000000008152602081600481875afa600091816107e7575b506106a85783634c9c8ce360e01b60005260045260246000fd5b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8592036107ba5750813b156107a657806001600160a01b03197f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416177f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28151156107735760008083602061001b95519101845af461076d611cb8565b91611fc1565b50503461077c57005b7fb398979f0000000000000000000000000000000000000000000000000000000060005260046000fd5b634c9c8ce360e01b60005260045260246000fd5b7faa1d49a40000000000000000000000000000000000000000000000000000000060005260045260246000fd5b9091506020813d602011610813575b8161080360209383611b02565b810103126101205751908561068e565b3d91506107f6565b90506001600160a01b037f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc541614158361063e565b346101205760003660031901126101205760206001600160a01b0360005416604051908152f35b3461012057604036600319011261012057610890611aa4565b336001600160a01b038216036108ac5761001b90600435611e9b565b7f6697b2320000000000000000000000000000000000000000000000000000000060005260046000fd5b346101205760403660031901126101205761001b6004356108f5611aa4565b9061093061017f826000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260016040600020015490565b611dc3565b346101205760203660031901126101205760206109816004356000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260016040600020015490565b604051908152f35b346101205760403660031901126101205760043567ffffffffffffffff811161012057366023820112156101205780600401359067ffffffffffffffff8211610120573660248383010111610120576024359067ffffffffffffffff821161012057366023830112156101205781600401359267ffffffffffffffff8411610120573660248560051b85010111610120573360009081527f448256db8f8fb95ee3eaaf89c1051414494e85cebb6057fcf996cc3d0ccfb456602052604090205460ff16156119cd578084036119a35791600060025560009060421981360301915b8481101561001b576000602482860101358783101561198f5760248360051b850101358581121561198b578401602481013567ffffffffffffffff81116119875760448201908036038213610d8b578491906060600160f887901c603f1680610c2d57505050506084830135915084906001198314610c23575b81929382604051610b4c81610b3e89606460208401977f40c10f19000000000000000000000000000000000000000000000000000000008952013560248401602090939291936001600160a01b0360408201951681520152565b03601f198101835282611b02565b5192355af1610b59611cb8565b91600182151514610c1a575b505b1580928193610bef575b50610ba8575090827f18643e9c376d4717d245cfdb57ec1bfe08520d98fa387b945b540fcb68c2dfaa60019493159280a301610a6a565b83610beb6040519283927f2c4029e90000000000000000000000000000000000000000000000000000000084526004840152604060248401526044830190611b77565b0390fd5b7f8000000000000000000000000000000000000000000000000000000000000000915016158a610b71565b6002558a610b65565b6002549250610ae4565b808203610dc057505050506064830135929035915060840135846000198203610da25750506040516370a0823160e01b81526001600160a01b03831660048201526020816024816001600160a01b0386165afa908115610d97579085918291610d5f575b50918192935b6001600160a01b0381163003610cfa5750604051826020820191630852cd8d60e31b835286602482015260248152610cd0604482611b02565b51925af190610cdd611cb8565b91905b600182151514610cf1575b50610b67565b6002558a610ceb565b6040517f79cc679000000000000000000000000000000000000000000000000000000000602082019081526001600160a01b039092166024820152604481018690528390610d4b8160648101610b3e565b51925af190610d58611cb8565b9190610ce0565b9150506020813d8211610d8f575b81610d7a60209383611b02565b81010312610d8b5751849081610c91565b8480fd5b3d9150610d6d565b6040513d87823e3d90fd5b90916001198314610db6575b819293610c97565b6002549250610dae565b60028103610ee75750505050606483013592903591508460848201356000198103610ec05750506040516370a0823160e01b81526001600160a01b03841660048201526020816024816001600160a01b0387165afa908115610eb557908692918391610e79575b50610e3e83949260a461271093915b013590611ce8565b04936001600160a01b0381163003610cfa5750604051826020820191630852cd8d60e31b835286602482015260248152610cd0604482611b02565b919250506020813d8211610ead575b81610e9560209383611b02565b81010312610ea95751859190610e3e610e27565b8580fd5b3d9150610e88565b6040513d88823e3d90fd5b610e3e61271091839593946001198214610edd575b60a490610e36565b6002549150610ed5565b6003810361105157505050506064830135926084810135925090359060a401358560018201611032575050604051916370a0823160e01b83526001600160a01b03841660048401526020836024816001600160a01b0386165afa8015610eb557908692918390610ffa575b839450945b83866001600160a01b0383163003610fa3575060405163a9059cbb60e01b602082019081526001600160a01b03909416602482015260448101889052909150610cd08160648101610b3e565b6040517f23b872dd00000000000000000000000000000000000000000000000000000000602082019081526001600160a01b039485166024830152949093166044840152606483015290610d4b8160848101610b3e565b509150916020813d821161102a575b8161101660209383611b02565b81010312610ea95791859291839251610f52565b3d9150611009565b9190926001198414611047575b829394610f57565b600254935061103f565b6004810361119157505050506064830135929035608482013560a48301356001810161116c575090919250604051926370a0823160e01b84526001600160a01b03851660048501526020846024816001600160a01b0387165afa9384156111615790879392918495611121575b506110d36127109160c4869791013590611ce8565b049483866001600160a01b0383163003610fa3575060405163a9059cbb60e01b602082019081526001600160a01b03909416602482015260448101889052909150610cd08160648101610b3e565b9193509193506020813d8211611159575b8161113f60209383611b02565b81010312611155575192869290916110d36110be565b8680fd5b3d9150611132565b6040513d89823e3d90fd5b6110d36127109186956001198214611187575b60c490610e36565b600254915061117f565b939593600581036112125750505050918192826040516111ff81610b3e60208201957f095ea7b30000000000000000000000000000000000000000000000000000000087526064608482013591013560248401602090939291936001600160a01b0360408201951681520152565b5192355af161120c611cb8565b90610b67565b600681036112b957505050509181928260405161012460208201937fd505accf0000000000000000000000000000000000000000000000000000000085526001600160a01b0360648201351660248401526001600160a01b03608482013516604484015260a4810135606484015260c4810135608484015260ff60e48201351660a484015261010481013560c4840152013560e482015260e481526111ff61010482611b02565b9294509091600781036113b35750505060848101358101602481019260448201359183900382016020019081831161139f571061139057918560e46111ff81839795849760ff604051958693836040602087019b7f0c53c51c000000000000000000000000000000000000000000000000000000008d526001600160a01b03606485013516602489015260a060448901528260c489015201838701378882858701015260a4810135606486015260c4810135608486015201351660a4830152601f801991011681010301601f198101835282611b02565b600486633b99b53d60e01b8152fd5b602488634e487b7160e01b81526011600452fd5b60088196949295939614600014611452575050503560001981146000146114415750475b6001600160a01b03855416803b15610ea9578582916004604051809481937fd0e30db00000000000000000000000000000000000000000000000000000000083525af18015610eb5578690611431575b5050600255610b67565b61143a91611b02565b8b85611427565b600281016113d757506002546113d7565b60098103611544575050503560001981146000146115335750602460206001600160a01b03865416604051928380926370a0823160e01b82523060048301525afa908115610d97578591611502575b505b6001600160a01b03855416803b15610ea9578580916024604051809481937f2e1a7d4d0000000000000000000000000000000000000000000000000000000083528760048401525af18015610eb5578690611431575050600255610b67565b90506020813d821161152b575b8161151c60209383611b02565b81010312610d8b57518b6114a1565b3d915061150f565b600281016114a357506002546114a3565b91929091600a81036117245750604460848301358301908101359360648201923591849003850160200190818611611710571061170157879060001981036116d75750506040516370a0823160e01b815230600482015260208160248185358a1c5afa9081156116cc57908894939291859161168c575b5061164092602094926115e0606493915b604051956115d987611ad0565b3691611b40565b8452308685015242604085015288840152013560808201526001600160a01b03855416906040519485809481937fc04b8d590000000000000000000000000000000000000000000000000000000083528760048401526024830190611c71565b03925af1908115610d9757859161165b575b50600255610b67565b90506020813d8211611684575b8161167560209383611b02565b81010312610d8b57518b611652565b3d9150611668565b9192939450506020813d82116116c4575b816116aa60209383611b02565b810103126116c0575187939291906116406115bb565b8780fd5b3d915061169d565b6040513d8a823e3d90fd5b6020936064916116409460019794971982146116f7575b6115e0906115cc565b60025491506116ee565b600488633b99b53d60e01b8152fd5b60248a634e487b7160e01b81526011600452fd5b919291600b810361195c575060a48301358301602481019360848101359392359260448301359282900383016020019081841161194857106119395781601319810111611925576117fc82606460209361179b600c868f988c010101358c1c996040519461179186611ad0565b6040369201611b40565b835230858401524260408401520135898201528460808201526001600160a01b03885416906040519485809481937ff28c04980000000000000000000000000000000000000000000000000000000083528760048401526024830190611c71565b03925af19081156116cc5788916118f4575b50818110806118e1575b611826575b50505050610b67565b81039081116118cd5760405163a9059cbb60e01b60208281019182526001600160a01b039094166024830152604482019290925287919061186a8160648101610b3e565b519082855af1156118c257845182903d6118bb575050803b155b6118905780808061181d565b7f5274afe7000000000000000000000000000000000000000000000000000000008552600452602484fd5b1415611884565b6040513d86823e3d90fd5b602487634e487b7160e01b81526011600452fd5b50306001600160a01b0384161415611818565b90506020813d821161191d575b8161190e60209383611b02565b810103126116c057518e61180e565b3d9150611901565b602489634e487b7160e01b81526011600452fd5b600489633b99b53d60e01b8152fd5b60248b634e487b7160e01b81526011600452fd5b7fd76a1e9e000000000000000000000000000000000000000000000000000000008852600452602487fd5b8380fd5b8280fd5b602482634e487b7160e01b81526032600452fd5b7fff633a380000000000000000000000000000000000000000000000000000000060005260046000fd5b63e2517d3f60e01b600052336004527f97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b92960245260446000fd5b3461012057602036600319011261012057600435907fffffffff00000000000000000000000000000000000000000000000000000000821680920361012057817f7965db0b0000000000000000000000000000000000000000000000000000000060209314908115611a7a575b5015158152f35b7f01ffc9a70000000000000000000000000000000000000000000000000000000091501483611a73565b602435906001600160a01b038216820361012057565b600435906001600160a01b038216820361012057565b60a0810190811067ffffffffffffffff821117611aec57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117611aec57604052565b67ffffffffffffffff8111611aec57601f01601f191660200190565b929192611b4c82611b24565b91611b5a6040519384611b02565b829481845281830111610120578281602093846000960137010152565b919082519283825260005b848110611ba3575050826000602080949584010152601f8019910116010190565b80602080928401015182828601015201611b82565b3360009081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff1615611bf157565b63e2517d3f60e01b60005233600452600060245260446000fd5b806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b03331660005260205260ff6040600020541615611c595750565b63e2517d3f60e01b6000523360045260245260446000fd5b90608080611c88845160a0855260a0850190611b77565b936001600160a01b0360208201511660208501526040810151604085015260608101516060850152015191015290565b3d15611ce3573d90611cc982611b24565b91611cd76040519384611b02565b82523d6000602084013e565b606090565b81810292918115918404141715611cfb57565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811660009081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff16611dbd576001600160a01b031660008181527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d60205260408120805460ff191660011790553391907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8180a4600190565b50600090565b806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b03831660005260205260ff6040600020541615600014611e9457806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b0383166000526020526040600020600160ff198254161790556001600160a01b03339216907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d600080a4600190565b5050600090565b806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b03831660005260205260ff60406000205416600014611e9457806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b038316600052602052604060002060ff1981541690556001600160a01b03339216907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b600080a4600190565b60ff7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460401c1615611f9757565b7fd7e6bcf80000000000000000000000000000000000000000000000000000000060005260046000fd5b906120005750805115611fd657805190602001fd5b7fd6bda2750000000000000000000000000000000000000000000000000000000060005260046000fd5b81511580612048575b612011575090565b6001600160a01b03907f9996b315000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b50803b1561200956fea264697066735822122075e681c399221f5dfd7a110e84017b4ac21ab7ef3e7a62cac5702a0ad1dbacdd64736f6c634300081a0033
Deployed Bytecode
0x608080604052600436101561001d575b50361561001b57600080fd5b005b60003560e01c90816301ffc9a714611a065750806324856bc314610989578063248a9ca3146109355780632f2ff15d146108d657806336568abe146108775780634aa4a4fc146108505780634f1ef286146105c457806352d1902d1461052f5780635b769f3c146104ef57806391d1485414610482578063a217fddf14610466578063ad3cb1cc14610403578063bea9849e146103c3578063c0c53b8b146101b0578063c7639d8014610189578063d547741f146101255763f5b541a6146100e5573861000f565b346101205760003660031901126101205760206040517f97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b9298152f35b600080fd5b346101205760403660031901126101205761001b600435610144611aa4565b9061018461017f826000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260016040600020015490565b611c0b565b611e9b565b346101205760003660031901126101205760206001600160a01b0360015416604051908152f35b34610120576060366003190112610120576101c9611aba565b6024356001600160a01b03811680910361012057604435906001600160a01b038216809203610120577ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460ff8160401c16159367ffffffffffffffff8216801590816103bb575b60011490816103b1575b1590816103a8575b5061037e5767ffffffffffffffff1982166001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0055610299918561033f575b5061028c611f68565b610294611f68565b611d11565b506001600160a01b031960005416176000556001600160a01b031960015416176001556102c257005b68ff0000000000000000197ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a0054167ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00557fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d2602060405160018152a1005b68ffffffffffffffffff191668010000000000000001177ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005585610283565b7ff92ee8a90000000000000000000000000000000000000000000000000000000060005260046000fd5b90501586610243565b303b15915061023b565b869150610231565b34610120576020366003190112610120576001600160a01b036103e4611aba565b6103ec611bb8565b166001600160a01b03196001541617600155600080f35b346101205760003660031901126101205761046260408051906104268183611b02565b600582527f352e302e30000000000000000000000000000000000000000000000000000000602083015251918291602083526020830190611b77565b0390f35b3461012057600036600319011261012057602060405160008152f35b346101205760403660031901126101205761049b611aa4565b6004356000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b6268006020526001600160a01b0360406000209116600052602052602060ff604060002054166040519015158152f35b34610120576020366003190112610120576001600160a01b03610510611aba565b610518611bb8565b166001600160a01b03196000541617600055600080f35b34610120576000366003190112610120576001600160a01b037f00000000000000000000000037f794f3f586a76a643be0be0d107d6b671afa7816300361059a5760206040517f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8152f35b7fe07c8dba0000000000000000000000000000000000000000000000000000000060005260046000fd5b6040366003190112610120576105d8611aba565b60243567ffffffffffffffff8111610120573660238201121561012057610609903690602481600401359101611b40565b6001600160a01b037f00000000000000000000000037f794f3f586a76a643be0be0d107d6b671afa781680301490811561081b575b5061059a5761064b611bb8565b6001600160a01b038216916040517f52d1902d000000000000000000000000000000000000000000000000000000008152602081600481875afa600091816107e7575b506106a85783634c9c8ce360e01b60005260045260246000fd5b807f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc8592036107ba5750813b156107a657806001600160a01b03197f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5416177f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc557fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b600080a28151156107735760008083602061001b95519101845af461076d611cb8565b91611fc1565b50503461077c57005b7fb398979f0000000000000000000000000000000000000000000000000000000060005260046000fd5b634c9c8ce360e01b60005260045260246000fd5b7faa1d49a40000000000000000000000000000000000000000000000000000000060005260045260246000fd5b9091506020813d602011610813575b8161080360209383611b02565b810103126101205751908561068e565b3d91506107f6565b90506001600160a01b037f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc541614158361063e565b346101205760003660031901126101205760206001600160a01b0360005416604051908152f35b3461012057604036600319011261012057610890611aa4565b336001600160a01b038216036108ac5761001b90600435611e9b565b7f6697b2320000000000000000000000000000000000000000000000000000000060005260046000fd5b346101205760403660031901126101205761001b6004356108f5611aa4565b9061093061017f826000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260016040600020015490565b611dc3565b346101205760203660031901126101205760206109816004356000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260016040600020015490565b604051908152f35b346101205760403660031901126101205760043567ffffffffffffffff811161012057366023820112156101205780600401359067ffffffffffffffff8211610120573660248383010111610120576024359067ffffffffffffffff821161012057366023830112156101205781600401359267ffffffffffffffff8411610120573660248560051b85010111610120573360009081527f448256db8f8fb95ee3eaaf89c1051414494e85cebb6057fcf996cc3d0ccfb456602052604090205460ff16156119cd578084036119a35791600060025560009060421981360301915b8481101561001b576000602482860101358783101561198f5760248360051b850101358581121561198b578401602481013567ffffffffffffffff81116119875760448201908036038213610d8b578491906060600160f887901c603f1680610c2d57505050506084830135915084906001198314610c23575b81929382604051610b4c81610b3e89606460208401977f40c10f19000000000000000000000000000000000000000000000000000000008952013560248401602090939291936001600160a01b0360408201951681520152565b03601f198101835282611b02565b5192355af1610b59611cb8565b91600182151514610c1a575b505b1580928193610bef575b50610ba8575090827f18643e9c376d4717d245cfdb57ec1bfe08520d98fa387b945b540fcb68c2dfaa60019493159280a301610a6a565b83610beb6040519283927f2c4029e90000000000000000000000000000000000000000000000000000000084526004840152604060248401526044830190611b77565b0390fd5b7f8000000000000000000000000000000000000000000000000000000000000000915016158a610b71565b6002558a610b65565b6002549250610ae4565b808203610dc057505050506064830135929035915060840135846000198203610da25750506040516370a0823160e01b81526001600160a01b03831660048201526020816024816001600160a01b0386165afa908115610d97579085918291610d5f575b50918192935b6001600160a01b0381163003610cfa5750604051826020820191630852cd8d60e31b835286602482015260248152610cd0604482611b02565b51925af190610cdd611cb8565b91905b600182151514610cf1575b50610b67565b6002558a610ceb565b6040517f79cc679000000000000000000000000000000000000000000000000000000000602082019081526001600160a01b039092166024820152604481018690528390610d4b8160648101610b3e565b51925af190610d58611cb8565b9190610ce0565b9150506020813d8211610d8f575b81610d7a60209383611b02565b81010312610d8b5751849081610c91565b8480fd5b3d9150610d6d565b6040513d87823e3d90fd5b90916001198314610db6575b819293610c97565b6002549250610dae565b60028103610ee75750505050606483013592903591508460848201356000198103610ec05750506040516370a0823160e01b81526001600160a01b03841660048201526020816024816001600160a01b0387165afa908115610eb557908692918391610e79575b50610e3e83949260a461271093915b013590611ce8565b04936001600160a01b0381163003610cfa5750604051826020820191630852cd8d60e31b835286602482015260248152610cd0604482611b02565b919250506020813d8211610ead575b81610e9560209383611b02565b81010312610ea95751859190610e3e610e27565b8580fd5b3d9150610e88565b6040513d88823e3d90fd5b610e3e61271091839593946001198214610edd575b60a490610e36565b6002549150610ed5565b6003810361105157505050506064830135926084810135925090359060a401358560018201611032575050604051916370a0823160e01b83526001600160a01b03841660048401526020836024816001600160a01b0386165afa8015610eb557908692918390610ffa575b839450945b83866001600160a01b0383163003610fa3575060405163a9059cbb60e01b602082019081526001600160a01b03909416602482015260448101889052909150610cd08160648101610b3e565b6040517f23b872dd00000000000000000000000000000000000000000000000000000000602082019081526001600160a01b039485166024830152949093166044840152606483015290610d4b8160848101610b3e565b509150916020813d821161102a575b8161101660209383611b02565b81010312610ea95791859291839251610f52565b3d9150611009565b9190926001198414611047575b829394610f57565b600254935061103f565b6004810361119157505050506064830135929035608482013560a48301356001810161116c575090919250604051926370a0823160e01b84526001600160a01b03851660048501526020846024816001600160a01b0387165afa9384156111615790879392918495611121575b506110d36127109160c4869791013590611ce8565b049483866001600160a01b0383163003610fa3575060405163a9059cbb60e01b602082019081526001600160a01b03909416602482015260448101889052909150610cd08160648101610b3e565b9193509193506020813d8211611159575b8161113f60209383611b02565b81010312611155575192869290916110d36110be565b8680fd5b3d9150611132565b6040513d89823e3d90fd5b6110d36127109186956001198214611187575b60c490610e36565b600254915061117f565b939593600581036112125750505050918192826040516111ff81610b3e60208201957f095ea7b30000000000000000000000000000000000000000000000000000000087526064608482013591013560248401602090939291936001600160a01b0360408201951681520152565b5192355af161120c611cb8565b90610b67565b600681036112b957505050509181928260405161012460208201937fd505accf0000000000000000000000000000000000000000000000000000000085526001600160a01b0360648201351660248401526001600160a01b03608482013516604484015260a4810135606484015260c4810135608484015260ff60e48201351660a484015261010481013560c4840152013560e482015260e481526111ff61010482611b02565b9294509091600781036113b35750505060848101358101602481019260448201359183900382016020019081831161139f571061139057918560e46111ff81839795849760ff604051958693836040602087019b7f0c53c51c000000000000000000000000000000000000000000000000000000008d526001600160a01b03606485013516602489015260a060448901528260c489015201838701378882858701015260a4810135606486015260c4810135608486015201351660a4830152601f801991011681010301601f198101835282611b02565b600486633b99b53d60e01b8152fd5b602488634e487b7160e01b81526011600452fd5b60088196949295939614600014611452575050503560001981146000146114415750475b6001600160a01b03855416803b15610ea9578582916004604051809481937fd0e30db00000000000000000000000000000000000000000000000000000000083525af18015610eb5578690611431575b5050600255610b67565b61143a91611b02565b8b85611427565b600281016113d757506002546113d7565b60098103611544575050503560001981146000146115335750602460206001600160a01b03865416604051928380926370a0823160e01b82523060048301525afa908115610d97578591611502575b505b6001600160a01b03855416803b15610ea9578580916024604051809481937f2e1a7d4d0000000000000000000000000000000000000000000000000000000083528760048401525af18015610eb5578690611431575050600255610b67565b90506020813d821161152b575b8161151c60209383611b02565b81010312610d8b57518b6114a1565b3d915061150f565b600281016114a357506002546114a3565b91929091600a81036117245750604460848301358301908101359360648201923591849003850160200190818611611710571061170157879060001981036116d75750506040516370a0823160e01b815230600482015260208160248185358a1c5afa9081156116cc57908894939291859161168c575b5061164092602094926115e0606493915b604051956115d987611ad0565b3691611b40565b8452308685015242604085015288840152013560808201526001600160a01b03855416906040519485809481937fc04b8d590000000000000000000000000000000000000000000000000000000083528760048401526024830190611c71565b03925af1908115610d9757859161165b575b50600255610b67565b90506020813d8211611684575b8161167560209383611b02565b81010312610d8b57518b611652565b3d9150611668565b9192939450506020813d82116116c4575b816116aa60209383611b02565b810103126116c0575187939291906116406115bb565b8780fd5b3d915061169d565b6040513d8a823e3d90fd5b6020936064916116409460019794971982146116f7575b6115e0906115cc565b60025491506116ee565b600488633b99b53d60e01b8152fd5b60248a634e487b7160e01b81526011600452fd5b919291600b810361195c575060a48301358301602481019360848101359392359260448301359282900383016020019081841161194857106119395781601319810111611925576117fc82606460209361179b600c868f988c010101358c1c996040519461179186611ad0565b6040369201611b40565b835230858401524260408401520135898201528460808201526001600160a01b03885416906040519485809481937ff28c04980000000000000000000000000000000000000000000000000000000083528760048401526024830190611c71565b03925af19081156116cc5788916118f4575b50818110806118e1575b611826575b50505050610b67565b81039081116118cd5760405163a9059cbb60e01b60208281019182526001600160a01b039094166024830152604482019290925287919061186a8160648101610b3e565b519082855af1156118c257845182903d6118bb575050803b155b6118905780808061181d565b7f5274afe7000000000000000000000000000000000000000000000000000000008552600452602484fd5b1415611884565b6040513d86823e3d90fd5b602487634e487b7160e01b81526011600452fd5b50306001600160a01b0384161415611818565b90506020813d821161191d575b8161190e60209383611b02565b810103126116c057518e61180e565b3d9150611901565b602489634e487b7160e01b81526011600452fd5b600489633b99b53d60e01b8152fd5b60248b634e487b7160e01b81526011600452fd5b7fd76a1e9e000000000000000000000000000000000000000000000000000000008852600452602487fd5b8380fd5b8280fd5b602482634e487b7160e01b81526032600452fd5b7fff633a380000000000000000000000000000000000000000000000000000000060005260046000fd5b63e2517d3f60e01b600052336004527f97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b92960245260446000fd5b3461012057602036600319011261012057600435907fffffffff00000000000000000000000000000000000000000000000000000000821680920361012057817f7965db0b0000000000000000000000000000000000000000000000000000000060209314908115611a7a575b5015158152f35b7f01ffc9a70000000000000000000000000000000000000000000000000000000091501483611a73565b602435906001600160a01b038216820361012057565b600435906001600160a01b038216820361012057565b60a0810190811067ffffffffffffffff821117611aec57604052565b634e487b7160e01b600052604160045260246000fd5b90601f8019910116810190811067ffffffffffffffff821117611aec57604052565b67ffffffffffffffff8111611aec57601f01601f191660200190565b929192611b4c82611b24565b91611b5a6040519384611b02565b829481845281830111610120578281602093846000960137010152565b919082519283825260005b848110611ba3575050826000602080949584010152601f8019910116010190565b80602080928401015182828601015201611b82565b3360009081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff1615611bf157565b63e2517d3f60e01b60005233600452600060245260446000fd5b806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b03331660005260205260ff6040600020541615611c595750565b63e2517d3f60e01b6000523360045260245260446000fd5b90608080611c88845160a0855260a0850190611b77565b936001600160a01b0360208201511660208501526040810151604085015260608101516060850152015191015290565b3d15611ce3573d90611cc982611b24565b91611cd76040519384611b02565b82523d6000602084013e565b606090565b81810292918115918404141715611cfb57565b634e487b7160e01b600052601160045260246000fd5b6001600160a01b03811660009081527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d602052604090205460ff16611dbd576001600160a01b031660008181527fb7db2dd08fcb62d0c9e08c51941cae53c267786a0b75803fb7960902fc8ef97d60205260408120805460ff191660011790553391907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8180a4600190565b50600090565b806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b03831660005260205260ff6040600020541615600014611e9457806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b0383166000526020526040600020600160ff198254161790556001600160a01b03339216907f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d600080a4600190565b5050600090565b806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b03831660005260205260ff60406000205416600014611e9457806000527f02dd7bc7dec4dceedda775e58dd541e08a116c6c53815c0bd028192f7b62680060205260406000206001600160a01b038316600052602052604060002060ff1981541690556001600160a01b03339216907ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b600080a4600190565b60ff7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a005460401c1615611f9757565b7fd7e6bcf80000000000000000000000000000000000000000000000000000000060005260046000fd5b906120005750805115611fd657805190602001fd5b7fd6bda2750000000000000000000000000000000000000000000000000000000060005260046000fd5b81511580612048575b612011575090565b6001600160a01b03907f9996b315000000000000000000000000000000000000000000000000000000006000521660045260246000fd5b50803b1561200956fea264697066735822122075e681c399221f5dfd7a110e84017b4ac21ab7ef3e7a62cac5702a0ad1dbacdd64736f6c634300081a0033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.