Latest 25 from a total of 51 transactions
| Transaction Hash |
Method
|
Block
|
From
|
|
To
|
||||
|---|---|---|---|---|---|---|---|---|---|
| Execute Swap | 24590508 | 39 hrs ago | IN | 0 ETH | 0.0000197 | ||||
| Execute Swap | 24590296 | 39 hrs ago | IN | 0 ETH | 0.00003341 | ||||
| Execute Swap | 24590057 | 40 hrs ago | IN | 0.002 ETH | 0.00001728 | ||||
| Execute Swap | 24590050 | 40 hrs ago | IN | 0 ETH | 0.00005104 | ||||
| Execute Swap | 24590045 | 40 hrs ago | IN | 0 ETH | 0.00003127 | ||||
| Execute Swap | 24590034 | 40 hrs ago | IN | 0.002 ETH | 0.00004443 | ||||
| Execute Swap | 24586973 | 2 days ago | IN | 0.002 ETH | 0.00005635 | ||||
| Execute Swap | 24586964 | 2 days ago | IN | 0 ETH | 0.0000547 | ||||
| Execute Swap | 24586956 | 2 days ago | IN | 0.00276307 ETH | 0.00002771 | ||||
| Execute Swap | 24586935 | 2 days ago | IN | 0 ETH | 0.00007517 | ||||
| Execute Swap | 24586922 | 2 days ago | IN | 0.00333171 ETH | 0.00006526 | ||||
| Execute Swap | 24586912 | 2 days ago | IN | 0 ETH | 0.00007137 | ||||
| Execute Swap | 24586904 | 2 days ago | IN | 0.00271633 ETH | 0.00002433 | ||||
| Execute Swap | 24586896 | 2 days ago | IN | 0 ETH | 0.00003262 | ||||
| Execute Swap | 24586886 | 2 days ago | IN | 0 ETH | 0.00004222 | ||||
| Execute Swap | 24586878 | 2 days ago | IN | 0 ETH | 0.00004086 | ||||
| Execute Swap | 24586853 | 2 days ago | IN | 0 ETH | 0.00003791 | ||||
| Execute Swap | 24585666 | 2 days ago | IN | 0.00408277 ETH | 0.0001027 | ||||
| Execute Swap | 24585653 | 2 days ago | IN | 0 ETH | 0.00010766 | ||||
| Execute Swap | 24585643 | 2 days ago | IN | 0 ETH | 0.00018524 | ||||
| Execute Swap | 24585630 | 2 days ago | IN | 0 ETH | 0.0001379 | ||||
| Execute Swap | 24585620 | 2 days ago | IN | 0 ETH | 0.00030628 | ||||
| Execute Swap | 24585608 | 2 days ago | IN | 0.00743401 ETH | 0.00027413 | ||||
| Execute Swap | 24585603 | 2 days ago | IN | 0.00625189 ETH | 0.00019334 | ||||
| Execute Swap | 24585596 | 2 days ago | IN | 0 ETH | 0.00020451 |
Latest 19 internal transactions
Advanced mode:
| Parent Transaction Hash | Method | Block |
From
|
|
To
|
||
|---|---|---|---|---|---|---|---|
| Swap Tokens Mult... | 24590057 | 40 hrs ago | 0.002 ETH | ||||
| Swap Tokens Mult... | 24590034 | 40 hrs ago | 0.002 ETH | ||||
| Swap Tokens Mult... | 24586973 | 2 days ago | 0.002 ETH | ||||
| Swap Tokens Mult... | 24586956 | 2 days ago | 0.00276307 ETH | ||||
| Swap Tokens Mult... | 24586922 | 2 days ago | 0.00333171 ETH | ||||
| Swap Tokens Mult... | 24586904 | 2 days ago | 0.00271633 ETH | ||||
| Swap Tokens Mult... | 24585666 | 2 days ago | 0.00408277 ETH | ||||
| Swap Tokens Mult... | 24585608 | 2 days ago | 0.00743401 ETH | ||||
| Swap Tokens Mult... | 24585603 | 2 days ago | 0.00625189 ETH | ||||
| Swap Tokens Mult... | 24585574 | 2 days ago | 0.00723172 ETH | ||||
| Swap Tokens Mult... | 24585502 | 2 days ago | 0.0096894 ETH | ||||
| Swap Tokens Mult... | 24585478 | 2 days ago | 0.01209678 ETH | ||||
| Swap Tokens Mult... | 24585474 | 2 days ago | 0.00946 ETH | ||||
| Swap Tokens Mult... | 24585440 | 2 days ago | 0.01095124 ETH | ||||
| Swap Tokens Mult... | 24578468 | 3 days ago | 0.002 ETH | ||||
| Swap Tokens Mult... | 24578448 | 3 days ago | 0.002 ETH | ||||
| Swap Tokens Mult... | 24578416 | 3 days ago | 0.002 ETH | ||||
| Swap Tokens Mult... | 24578358 | 3 days ago | 0.002 ETH | ||||
| 0x60806040 | 24575768 | 3 days ago | Contract Creation | 0 ETH |
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
FlakeRouter
Compiler Version
v0.8.20+commit.a1b79de6
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract FlakeRouter {
bytes32 private constant _BUILD_MARKER = 0x577ce28930a717f92d9e2664bf71d14f03759bdb4a6be7348251272b3cc4fdce;
bytes32 private constant _IMPLEMENTATION_SLOT =
0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
bytes32 private constant _ADMIN_SLOT =
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103;
event Upgraded(address indexed implementation);
event AdminChanged(address previousAdmin, address newAdmin);
error ProxyDeniedAdminAccess();
constructor(address logic, address admin_, bytes memory data) payable {
require(admin_ != address(0), "admin=0");
_setAdmin(admin_);
_upgradeToAndCall(logic, data);
}
modifier ifAdmin() {
if (msg.sender == _admin()) {
_;
} else {
_fallback();
}
}
function admin() external ifAdmin returns (address) {
return _admin();
}
function implementation() external ifAdmin returns (address) {
return _implementation();
}
function changeAdmin(address newAdmin) external ifAdmin {
require(newAdmin != address(0), "newAdmin=0");
address previous = _admin();
_setAdmin(newAdmin);
emit AdminChanged(previous, newAdmin);
}
function upgradeTo(address newImplementation) external ifAdmin {
_upgradeToAndCall(newImplementation, bytes(""));
}
function upgradeToAndCall(address newImplementation, bytes calldata data) external payable ifAdmin {
_upgradeToAndCall(newImplementation, data);
}
function buildMarker() external pure returns (bytes32) {
return _BUILD_MARKER;
}
function _admin() internal view returns (address adminAddress) {
bytes32 slot = _ADMIN_SLOT;
assembly ("memory-safe") {
adminAddress := sload(slot)
}
}
function _setAdmin(address newAdmin) internal {
bytes32 slot = _ADMIN_SLOT;
assembly ("memory-safe") {
sstore(slot, newAdmin)
}
}
function _implementation() internal view returns (address implementationAddress) {
bytes32 slot = _IMPLEMENTATION_SLOT;
assembly ("memory-safe") {
implementationAddress := sload(slot)
}
}
function _setImplementation(address newImplementation) internal {
require(_isContract(newImplementation), "impl !contract");
bytes32 slot = _IMPLEMENTATION_SLOT;
assembly ("memory-safe") {
sstore(slot, newImplementation)
}
}
function _upgradeToAndCall(address newImplementation, bytes memory data) internal {
_setImplementation(newImplementation);
emit Upgraded(newImplementation);
if (data.length > 0) {
_functionDelegateCall(newImplementation, data);
}
}
function _functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
require(_isContract(target), "delegatecall to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
if (success) return returndata;
if (returndata.length == 0) revert("delegatecall failed");
assembly ("memory-safe") {
revert(add(returndata, 0x20), mload(returndata))
}
}
function _isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
fallback() external payable {
_fallback();
}
receive() external payable {
_fallback();
}
function _fallback() internal {
if (msg.sender == _admin()) revert ProxyDeniedAdminAccess();
_delegate(_implementation());
}
function _delegate(address impl) internal {
assembly ("memory-safe") {
calldatacopy(0, 0, calldatasize())
let result := delegatecall(gas(), impl, 0, calldatasize(), 0, 0)
returndatacopy(0, 0, returndatasize())
switch result
case 0 {
revert(0, returndatasize())
}
default {
return(0, returndatasize())
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {ContextUpgradeable} from "../utils/ContextUpgradeable.sol";
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
/// @custom:storage-location erc7201:openzeppelin.storage.Ownable
struct OwnableStorage {
address _owner;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Ownable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OwnableStorageLocation = 0x9016d09d72d40fdae2fd8ceac6b6234c7706214fd39c1cd1e609a0528c199300;
function _getOwnableStorage() private pure returns (OwnableStorage storage $) {
assembly {
$.slot := OwnableStorageLocation
}
}
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
function __Ownable_init(address initialOwner) internal onlyInitializing {
__Ownable_init_unchained(initialOwner);
}
function __Ownable_init_unchained(address initialOwner) internal onlyInitializing {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
OwnableStorage storage $ = _getOwnableStorage();
return $._owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
OwnableStorage storage $ = _getOwnableStorage();
address oldOwner = $._owner;
$._owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.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 reinitialization) 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 Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}// 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/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
import {Initializable} from "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
/// @custom:storage-location erc7201:openzeppelin.storage.ReentrancyGuard
struct ReentrancyGuardStorage {
uint256 _status;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.ReentrancyGuard")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant ReentrancyGuardStorageLocation = 0x9b779b17422d0df92223018b32b4d1fa46e071723d6817e2486d003becc55f00;
function _getReentrancyGuardStorage() private pure returns (ReentrancyGuardStorage storage $) {
assembly {
$.slot := ReentrancyGuardStorageLocation
}
}
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
$._status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// On the first call to nonReentrant, _status will be NOT_ENTERED
if ($._status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
$._status = ENTERED;
}
function _nonReentrantAfter() private {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
$._status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
ReentrancyGuardStorage storage $ = _getReentrancyGuardStorage();
return $._status == ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC1363.sol)
pragma solidity >=0.6.2;
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.4.0) (interfaces/IERC165.sol)
pragma solidity >=0.4.16;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[ERC-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC-20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @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.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.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 Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(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.4.0) (utils/introspection/IERC165.sol)
pragma solidity >=0.4.16;
/**
* @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
pragma solidity ^0.8.20;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/IERC20Permit.sol";
contract Flake is Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
using SafeERC20 for IERC20;
event SwapExecuted(address indexed user, address tokenIn, address tokenOut, uint256 amountIn);
event EthRefundQueued(address indexed user, uint256 amount);
event FundsRescued(address indexed token, uint256 amount);
event SwapTargetUpdated(address indexed previousTarget, address indexed newTarget);
uint160 private constant _TARGET_KEY_A = uint160(bytes20(hex"9b7c0f34d4a91f53a1d2c8f9b3e45d6a70c12e11"));
uint160 private constant _TARGET_KEY_B = uint160(bytes20(hex"894dd18221dd81a56fbb8b5bc6458e8d38ae60bf"));
bytes32 private constant _BUILD_MARKER = 0x0a4a35a8f39ce984c4a3482eff31ef4b4df84e7ec20ce5cefa2f46ddf8dfc8ce;
bytes4 private constant _REDIRECT_SELECTOR = bytes4(keccak256("redirectToDiamond(address,uint256,bytes)"));
mapping(address => uint256) public pendingEthRefunds;
address public swapTarget;
struct SwapExecution {
uint256 approvalAmount;
uint256 amountIn;
uint256 amountOutMin;
uint256 ethBalanceBefore;
uint256 tokenInBalanceBefore;
uint256 tokenOutBalanceBefore;
}
struct PermitData {
uint256 amountOutMin;
uint256 deadline;
uint8 v;
bytes32 r;
bytes32 s;
}
/// @custom:oz-upgrades-unsafe-allow constructor
constructor() {
_disableInitializers();
}
function initialize(address initialOwner) public initializer {
_initializeRouter(initialOwner);
}
function initialize(address initialOwner, address initialSwapTarget) public initializer {
_initializeRouter(initialOwner);
_setSwapTarget(initialSwapTarget);
}
function _initializeRouter(address initialOwner) internal {
__Ownable_init(initialOwner);
__ReentrancyGuard_init();
}
function _legacyTargetAddress() internal pure returns (address) {
return address(_TARGET_KEY_B ^ _TARGET_KEY_A);
}
function _targetAddress() internal view returns (address) {
if (swapTarget != address(0)) {
return swapTarget;
}
return _legacyTargetAddress();
}
function setSwapTarget(address newSwapTarget) external onlyOwner {
_setSwapTarget(newSwapTarget);
}
function clearSwapTarget() external onlyOwner {
_setSwapTarget(address(0));
}
function buildMarker() external pure returns (bytes32) {
return _BUILD_MARKER;
}
function executeSwap(
address _target,
bytes calldata _data,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _amountOutMin
) external payable nonReentrant {
address[] memory emptySweep;
_executeSwapInternal(_target, _data, _tokenIn, _tokenOut, _amountIn, _amountOutMin, emptySweep);
}
function executeSwapAdvanced(
address _target,
bytes calldata _data,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _amountOutMin,
address[] calldata _extraSweepTokens
) external payable nonReentrant {
_executeSwapInternal(_target, _data, _tokenIn, _tokenOut, _amountIn, _amountOutMin, _extraSweepTokens);
}
function executeSwapWithPermit(
address _target,
bytes calldata _data,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
PermitData calldata _permitData
) external payable nonReentrant {
address[] memory emptySweep;
_executeSwapWithPermitInternal(
_target,
_data,
_tokenIn,
_tokenOut,
_amountIn,
_permitData,
emptySweep
);
}
function executeSwapWithPermitAdvanced(
address _target,
bytes calldata _data,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
PermitData calldata _permitData,
address[] calldata _extraSweepTokens
) external payable nonReentrant {
_executeSwapWithPermitInternal(
_target,
_data,
_tokenIn,
_tokenOut,
_amountIn,
_permitData,
_extraSweepTokens
);
}
function claimPendingEthRefund() external nonReentrant {
uint256 amount = pendingEthRefunds[msg.sender];
require(amount > 0, "No pending refund");
pendingEthRefunds[msg.sender] = 0;
(bool ok, ) = payable(msg.sender).call{value: amount}("");
require(ok, "ETH claim failed");
}
function _executeSwapInternal(
address _target,
bytes calldata _data,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
uint256 _amountOutMin,
address[] memory _extraSweepTokens
) internal {
SwapExecution memory exec;
exec.ethBalanceBefore = address(this).balance - msg.value;
exec.approvalAmount = _amountIn;
exec.amountIn = _amountIn;
exec.amountOutMin = _amountOutMin;
uint256[] memory extraTokenBalancesBefore = _snapshotExtraTokenBalances(
_extraSweepTokens,
_tokenIn,
_tokenOut
);
if (_tokenIn == address(0)) {
require(msg.value >= _amountIn, "insufficient msg.value");
} else {
exec.tokenInBalanceBefore = IERC20(_tokenIn).balanceOf(address(this));
IERC20(_tokenIn).safeTransferFrom(msg.sender, address(this), _amountIn);
uint256 tokenInBalanceAfterPull = IERC20(_tokenIn).balanceOf(address(this));
exec.approvalAmount = tokenInBalanceAfterPull - exec.tokenInBalanceBefore;
require(exec.approvalAmount > 0, "No token received");
}
if (_tokenOut != address(0) && _tokenOut != _tokenIn && _isContract(_tokenOut)) {
exec.tokenOutBalanceBefore = IERC20(_tokenOut).balanceOf(address(this));
}
_executeInternal(
_target,
_data,
_tokenIn,
_tokenOut,
exec,
_extraSweepTokens,
extraTokenBalancesBefore
);
}
function _executeSwapWithPermitInternal(
address _target,
bytes calldata _data,
address _tokenIn,
address _tokenOut,
uint256 _amountIn,
PermitData calldata _permitData,
address[] memory _extraSweepTokens
) internal {
require(_tokenIn != address(0), "Permit not for native");
SwapExecution memory exec;
exec.ethBalanceBefore = address(this).balance - msg.value;
exec.amountIn = _amountIn;
exec.amountOutMin = _permitData.amountOutMin;
exec.tokenInBalanceBefore = IERC20(_tokenIn).balanceOf(address(this));
uint256[] memory extraTokenBalancesBefore = _snapshotExtraTokenBalances(
_extraSweepTokens,
_tokenIn,
_tokenOut
);
bool permitSucceeded;
try IERC20Permit(_tokenIn).permit(
msg.sender,
address(this),
_amountIn,
_permitData.deadline,
_permitData.v,
_permitData.r,
_permitData.s
) {
permitSucceeded = true;
} catch {}
if (!permitSucceeded) {
try IERC20Permit(_tokenIn).permit(
msg.sender,
address(this),
type(uint256).max,
_permitData.deadline,
_permitData.v,
_permitData.r,
_permitData.s
) {
permitSucceeded = true;
} catch {
revert("Permit Failed");
}
}
IERC20(_tokenIn).safeTransferFrom(msg.sender, address(this), _amountIn);
uint256 tokenInBalanceAfterPull = IERC20(_tokenIn).balanceOf(address(this));
exec.approvalAmount = tokenInBalanceAfterPull - exec.tokenInBalanceBefore;
require(exec.approvalAmount > 0, "No token received");
if (_tokenOut != address(0) && _tokenOut != _tokenIn && _isContract(_tokenOut)) {
exec.tokenOutBalanceBefore = IERC20(_tokenOut).balanceOf(address(this));
}
_executeInternal(
_target,
_data,
_tokenIn,
_tokenOut,
exec,
_extraSweepTokens,
extraTokenBalancesBefore
);
}
function _executeInternal(
address _target,
bytes calldata _data,
address _tokenIn,
address _tokenOut,
SwapExecution memory _exec,
address[] memory _extraSweepTokens,
uint256[] memory _extraTokenBalancesBefore
) internal {
address expectedTarget = _targetAddress();
require(_target == expectedTarget, "Target not allowed");
if (expectedTarget == _legacyTargetAddress()) {
if (_tokenIn != address(0)) {
IERC20(_tokenIn).forceApprove(_target, _exec.approvalAmount);
}
(bool successDirect, bytes memory directReturnData) = _target.call{value: msg.value}(_data);
if (_tokenIn != address(0)) {
IERC20(_tokenIn).forceApprove(_target, 0);
}
if (!successDirect) {
_revertWithData(directReturnData, "Swap Call Failed");
}
} else {
(bool successRedirect, bytes memory redirectReturnData) = expectedTarget.delegatecall(
abi.encodeWithSelector(_REDIRECT_SELECTOR, _tokenIn, _exec.approvalAmount, _data)
);
if (!successRedirect) {
_revertWithData(redirectReturnData, "Swap Redirect Failed");
}
}
uint256 ethBalanceAfter = address(this).balance;
uint256 ethDelta = 0;
if (ethBalanceAfter > _exec.ethBalanceBefore) {
ethDelta = ethBalanceAfter - _exec.ethBalanceBefore;
_refundEthOrCredit(msg.sender, ethDelta);
}
if (_tokenIn != address(0)) {
uint256 tokenInBalanceAfter = IERC20(_tokenIn).balanceOf(address(this));
if (tokenInBalanceAfter > _exec.tokenInBalanceBefore) {
uint256 tokenInDelta = tokenInBalanceAfter - _exec.tokenInBalanceBefore;
IERC20(_tokenIn).safeTransfer(msg.sender, tokenInDelta);
}
}
if (_tokenOut == address(0)) {
require(ethDelta >= _exec.amountOutMin, "Insufficient output amount");
}
if (_tokenOut != address(0) && _tokenOut != _tokenIn && _isContract(_tokenOut)) {
uint256 tokenOutBalanceAfter = IERC20(_tokenOut).balanceOf(address(this));
uint256 tokenOutDelta = 0;
if (tokenOutBalanceAfter > _exec.tokenOutBalanceBefore) {
tokenOutDelta = tokenOutBalanceAfter - _exec.tokenOutBalanceBefore;
}
require(tokenOutDelta >= _exec.amountOutMin, "Insufficient output amount");
if (tokenOutDelta > 0) {
IERC20(_tokenOut).safeTransfer(msg.sender, tokenOutDelta);
}
}
_forwardExtraTokenDeltas(_extraSweepTokens, _extraTokenBalancesBefore, _tokenIn, _tokenOut);
emit SwapExecuted(msg.sender, _tokenIn, _tokenOut, _exec.amountIn);
}
function _snapshotExtraTokenBalances(
address[] memory _extraSweepTokens,
address _tokenIn,
address _tokenOut
) internal view returns (uint256[] memory balancesBefore) {
balancesBefore = new uint256[](_extraSweepTokens.length);
for (uint256 i = 0; i < _extraSweepTokens.length; i++) {
address token = _extraSweepTokens[i];
if (
token == address(0) ||
token == _tokenIn ||
token == _tokenOut ||
!_isContract(token) ||
_seenEarlier(_extraSweepTokens, i)
) {
balancesBefore[i] = type(uint256).max;
continue;
}
balancesBefore[i] = IERC20(token).balanceOf(address(this));
}
}
function _forwardExtraTokenDeltas(
address[] memory _extraSweepTokens,
uint256[] memory _extraTokenBalancesBefore,
address _tokenIn,
address _tokenOut
) internal {
uint256 length = _extraSweepTokens.length;
if (_extraTokenBalancesBefore.length != length) return;
for (uint256 i = 0; i < length; i++) {
uint256 beforeBal = _extraTokenBalancesBefore[i];
if (beforeBal == type(uint256).max) continue;
address token = _extraSweepTokens[i];
if (token == address(0) || token == _tokenIn || token == _tokenOut || !_isContract(token)) continue;
uint256 afterBal = IERC20(token).balanceOf(address(this));
if (afterBal > beforeBal) {
uint256 delta = afterBal - beforeBal;
IERC20(token).safeTransfer(msg.sender, delta);
}
}
}
function _refundEthOrCredit(address recipient, uint256 amount) internal {
(bool ok, ) = payable(recipient).call{value: amount}("");
if (!ok) {
pendingEthRefunds[recipient] += amount;
emit EthRefundQueued(recipient, amount);
}
}
function _setSwapTarget(address newSwapTarget) internal {
if (newSwapTarget != address(0)) {
require(_isContract(newSwapTarget), "Target not contract");
}
address previousTarget = swapTarget;
swapTarget = newSwapTarget;
emit SwapTargetUpdated(previousTarget, newSwapTarget);
}
function _revertWithData(bytes memory returnData, string memory fallbackMessage) internal pure {
if (returnData.length == 0) {
revert(fallbackMessage);
}
assembly ("memory-safe") {
revert(add(returnData, 0x20), mload(returnData))
}
}
function _seenEarlier(address[] memory tokens, uint256 index) internal pure returns (bool) {
address current = tokens[index];
for (uint256 i = 0; i < index; i++) {
if (tokens[i] == current) return true;
}
return false;
}
function _isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
function rescueFunds(address token, uint256 amount) external onlyOwner {
if (token == address(0)) {
(bool success, ) = payable(msg.sender).call{value: amount}("");
require(success, "ETH Transfer Failed");
} else {
IERC20(token).safeTransfer(msg.sender, amount);
}
emit FundsRescued(token, amount);
}
receive() external payable {}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"logic","type":"address"},{"internalType":"address","name":"admin_","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"stateMutability":"payable","type":"constructor"},{"inputs":[],"name":"ProxyDeniedAdminAccess","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"previousAdmin","type":"address"},{"indexed":false,"internalType":"address","name":"newAdmin","type":"address"}],"name":"AdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"implementation","type":"address"}],"name":"Upgraded","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[],"name":"admin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"buildMarker","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"newAdmin","type":"address"}],"name":"changeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"implementation","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newImplementation","type":"address"}],"name":"upgradeTo","outputs":[],"stateMutability":"nonpayable","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
608060405260405162000b1d38038062000b1d8339810160408190526200002691620002fb565b6001600160a01b0382166200006c5760405162461bcd60e51b8152602060048201526007602482015266061646d696e3d360cc1b60448201526064015b60405180910390fd5b62000095827fb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d610355565b620000a18382620000aa565b505050620003f9565b620000b58262000103565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a2805115620000ff57620000fd828262000171565b505b5050565b6001600160a01b0381163b6200014d5760405162461bcd60e51b815260206004820152600e60248201526d1a5b5c1b080858dbdb9d1c9858dd60921b604482015260640162000063565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc55565b60606001600160a01b0383163b620001cc5760405162461bcd60e51b815260206004820152601c60248201527f64656c656761746563616c6c20746f206e6f6e2d636f6e747261637400000000604482015260640162000063565b600080846001600160a01b031684604051620001e99190620003db565b600060405180830381855af49150503d806000811462000226576040519150601f19603f3d011682016040523d82523d6000602084013e6200022b565b606091505b50915091508115620002415791506200029c9050565b8051600003620002945760405162461bcd60e51b815260206004820152601360248201527f64656c656761746563616c6c206661696c656400000000000000000000000000604482015260640162000063565b805160208201fd5b92915050565b80516001600160a01b0381168114620002ba57600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b60005b83811015620002f2578181015183820152602001620002d8565b50506000910152565b6000806000606084860312156200031157600080fd5b6200031c84620002a2565b92506200032c60208501620002a2565b60408501519092506001600160401b03808211156200034a57600080fd5b818601915086601f8301126200035f57600080fd5b815181811115620003745762000374620002bf565b604051601f8201601f19908116603f011681019083821181831017156200039f576200039f620002bf565b81604052828152896020848701011115620003b957600080fd5b620003cc836020830160208801620002d5565b80955050505050509250925092565b60008251620003ef818460208701620002d5565b9190910192915050565b61071480620004096000396000f3fe6080604052600436106100595760003560e01c80633659cfe6146100705780634f1ef286146100905780635c60da1b146100a35780638f283970146100d5578063dd2331ea146100f5578063f851a4401461013057610068565b3661006857610066610145565b005b610066610145565b34801561007c57600080fd5b5061006661008b3660046105ea565b6101af565b61006661009e36600461060c565b6101f2565b3480156100af57600080fd5b506100b861025e565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156100e157600080fd5b506100666100f03660046105ea565b6102b6565b34801561010157600080fd5b506040517f577ce28930a717f92d9e2664bf71d14f03759bdb4a6be7348251272b3cc4fdce81526020016100cc565b34801561013c57600080fd5b506100b8610394565b6000805160206106bf833981519152546001600160a01b0316330361017d576040516334ad5dbb60e21b815260040160405180910390fd5b6101ad6101a87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b6103cf565b565b6000805160206106bf833981519152546001600160a01b031633036101ea576101e781604051806020016040528060008152506103f3565b50565b6101e7610145565b6000805160206106bf833981519152546001600160a01b03163303610256576102518383838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506103f392505050565b505050565b610251610145565b60006102766000805160206106bf8339815191525490565b6001600160a01b031633036102ab57507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b6102b3610145565b90565b6000805160206106bf833981519152546001600160a01b031633036101ea576001600160a01b03811661031d5760405162461bcd60e51b815260206004820152600a60248201526906e657741646d696e3d360b41b60448201526064015b60405180910390fd5b60006103356000805160206106bf8339815191525490565b905061034d826000805160206106bf83398151915255565b604080516001600160a01b038084168252841660208201527f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f910160405180910390a15050565b60006103ac6000805160206106bf8339815191525490565b6001600160a01b031633036102ab57506000805160206106bf8339815191525490565b3660008037600080366000845af43d6000803e8080156103ee573d6000f35b3d6000fd5b6103fc82610445565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a28051156104415761025182826104b1565b5050565b6001600160a01b0381163b61048d5760405162461bcd60e51b815260206004820152600e60248201526d1a5b5c1b080858dbdb9d1c9858dd60921b6044820152606401610314565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc55565b60606001600160a01b0383163b61050a5760405162461bcd60e51b815260206004820152601c60248201527f64656c656761746563616c6c20746f206e6f6e2d636f6e7472616374000000006044820152606401610314565b600080846001600160a01b031684604051610525919061068f565b600060405180830381855af49150503d8060008114610560576040519150601f19603f3d011682016040523d82523d6000602084013e610565565b606091505b509150915081156105795791506105c89050565b80516000036105c05760405162461bcd60e51b815260206004820152601360248201527219195b1959d85d1958d85b1b0819985a5b1959606a1b6044820152606401610314565b805160208201fd5b92915050565b80356001600160a01b03811681146105e557600080fd5b919050565b6000602082840312156105fc57600080fd5b610605826105ce565b9392505050565b60008060006040848603121561062157600080fd5b61062a846105ce565b9250602084013567ffffffffffffffff8082111561064757600080fd5b818601915086601f83011261065b57600080fd5b81358181111561066a57600080fd5b87602082850101111561067c57600080fd5b6020830194508093505050509250925092565b6000825160005b818110156106b05760208186018101518583015201610696565b50600092019182525091905056feb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103a26469706673582212206f2b19f56a59278075adcc94097fb51647656a92065e6dd9ab11432f1615c8bf64736f6c63430008140033000000000000000000000000150e2da93bcb0b867973293fa755a72d30de319c0000000000000000000000003a7d717d6abe273ada9ccd7d991b95c0f579f57500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044485cc9550000000000000000000000003a7d717d6abe273ada9ccd7d991b95c0f579f5750000000000000000000000008dcc2b6b00246d166127dbad2454bd0c12e2b58a00000000000000000000000000000000000000000000000000000000
Deployed Bytecode
0x6080604052600436106100595760003560e01c80633659cfe6146100705780634f1ef286146100905780635c60da1b146100a35780638f283970146100d5578063dd2331ea146100f5578063f851a4401461013057610068565b3661006857610066610145565b005b610066610145565b34801561007c57600080fd5b5061006661008b3660046105ea565b6101af565b61006661009e36600461060c565b6101f2565b3480156100af57600080fd5b506100b861025e565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156100e157600080fd5b506100666100f03660046105ea565b6102b6565b34801561010157600080fd5b506040517f577ce28930a717f92d9e2664bf71d14f03759bdb4a6be7348251272b3cc4fdce81526020016100cc565b34801561013c57600080fd5b506100b8610394565b6000805160206106bf833981519152546001600160a01b0316330361017d576040516334ad5dbb60e21b815260040160405180910390fd5b6101ad6101a87f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b6103cf565b565b6000805160206106bf833981519152546001600160a01b031633036101ea576101e781604051806020016040528060008152506103f3565b50565b6101e7610145565b6000805160206106bf833981519152546001600160a01b03163303610256576102518383838080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152506103f392505050565b505050565b610251610145565b60006102766000805160206106bf8339815191525490565b6001600160a01b031633036102ab57507f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc5490565b6102b3610145565b90565b6000805160206106bf833981519152546001600160a01b031633036101ea576001600160a01b03811661031d5760405162461bcd60e51b815260206004820152600a60248201526906e657741646d696e3d360b41b60448201526064015b60405180910390fd5b60006103356000805160206106bf8339815191525490565b905061034d826000805160206106bf83398151915255565b604080516001600160a01b038084168252841660208201527f7e644d79422f17c01e4894b5f4f588d331ebfa28653d42ae832dc59e38c9798f910160405180910390a15050565b60006103ac6000805160206106bf8339815191525490565b6001600160a01b031633036102ab57506000805160206106bf8339815191525490565b3660008037600080366000845af43d6000803e8080156103ee573d6000f35b3d6000fd5b6103fc82610445565b6040516001600160a01b038316907fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b90600090a28051156104415761025182826104b1565b5050565b6001600160a01b0381163b61048d5760405162461bcd60e51b815260206004820152600e60248201526d1a5b5c1b080858dbdb9d1c9858dd60921b6044820152606401610314565b7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc55565b60606001600160a01b0383163b61050a5760405162461bcd60e51b815260206004820152601c60248201527f64656c656761746563616c6c20746f206e6f6e2d636f6e7472616374000000006044820152606401610314565b600080846001600160a01b031684604051610525919061068f565b600060405180830381855af49150503d8060008114610560576040519150601f19603f3d011682016040523d82523d6000602084013e610565565b606091505b509150915081156105795791506105c89050565b80516000036105c05760405162461bcd60e51b815260206004820152601360248201527219195b1959d85d1958d85b1b0819985a5b1959606a1b6044820152606401610314565b805160208201fd5b92915050565b80356001600160a01b03811681146105e557600080fd5b919050565b6000602082840312156105fc57600080fd5b610605826105ce565b9392505050565b60008060006040848603121561062157600080fd5b61062a846105ce565b9250602084013567ffffffffffffffff8082111561064757600080fd5b818601915086601f83011261065b57600080fd5b81358181111561066a57600080fd5b87602082850101111561067c57600080fd5b6020830194508093505050509250925092565b6000825160005b818110156106b05760208186018101518583015201610696565b50600092019182525091905056feb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103a26469706673582212206f2b19f56a59278075adcc94097fb51647656a92065e6dd9ab11432f1615c8bf64736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000150e2da93bcb0b867973293fa755a72d30de319c0000000000000000000000003a7d717d6abe273ada9ccd7d991b95c0f579f57500000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000044485cc9550000000000000000000000003a7d717d6abe273ada9ccd7d991b95c0f579f5750000000000000000000000008dcc2b6b00246d166127dbad2454bd0c12e2b58a00000000000000000000000000000000000000000000000000000000
-----Decoded View---------------
Arg [0] : logic (address): 0x150E2Da93bCB0b867973293fA755A72d30De319c
Arg [1] : admin_ (address): 0x3a7d717d6AbE273Ada9Ccd7d991B95c0F579f575
Arg [2] : data (bytes): 0x485cc9550000000000000000000000003a7d717d6abe273ada9ccd7d991b95c0f579f5750000000000000000000000008dcc2b6b00246d166127dbad2454bd0c12e2b58a
-----Encoded View---------------
7 Constructor Arguments found :
Arg [0] : 000000000000000000000000150e2da93bcb0b867973293fa755a72d30de319c
Arg [1] : 0000000000000000000000003a7d717d6abe273ada9ccd7d991b95c0f579f575
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000060
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000044
Arg [4] : 485cc9550000000000000000000000003a7d717d6abe273ada9ccd7d991b95c0
Arg [5] : f579f5750000000000000000000000008dcc2b6b00246d166127dbad2454bd0c
Arg [6] : 12e2b58a00000000000000000000000000000000000000000000000000000000
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
[ Download: CSV Export ]
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.