Latest 9 from a total of 9 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Update Trusted R... | 37296288 | 68 days ago | IN | 0 MON | 0.01476021 | ||||
| Update Trusted R... | 37296201 | 68 days ago | IN | 0 MON | 0.01708962 | ||||
| Update Trusted R... | 37295704 | 68 days ago | IN | 0 MON | 0.00988838 | ||||
| Update Trusted R... | 37295664 | 68 days ago | IN | 0 MON | 0.01105404 | ||||
| Update Trusted R... | 37295664 | 68 days ago | IN | 0 MON | 0.00639601 | ||||
| Update Trusted R... | 37273899 | 68 days ago | IN | 0 MON | 0.01175275 | ||||
| Update Trusted R... | 37273899 | 68 days ago | IN | 0 MON | 0.01176351 | ||||
| Update Trusted R... | 37273899 | 68 days ago | IN | 0 MON | 0.01353092 | ||||
| Set Protocol Fee... | 36862347 | 70 days ago | IN | 0 MON | 0.0074105 |
Advanced mode: Intended for advanced users or developers and will display all Internal Transactions including zero value transfers.
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | ||||
|---|---|---|---|---|---|---|---|
| 52035965 | 1 hr ago | 0 MON | |||||
| 52035965 | 1 hr ago | 0 MON | |||||
| 52035965 | 1 hr ago | 0 MON | |||||
| 52035965 | 1 hr ago | 0 MON | |||||
| 52035965 | 1 hr ago | 0 MON | |||||
| 52035965 | 1 hr ago | 0 MON | |||||
| 52035965 | 1 hr ago | 0 MON | |||||
| 52027468 | 2 hrs ago | 0 MON | |||||
| 52027468 | 2 hrs ago | 0 MON | |||||
| 52027468 | 2 hrs ago | 0 MON | |||||
| 52027468 | 2 hrs ago | 0 MON | |||||
| 52027468 | 2 hrs ago | 0 MON | |||||
| 52027468 | 2 hrs ago | 0 MON | |||||
| 52027468 | 2 hrs ago | 0 MON | |||||
| 52026574 | 2 hrs ago | 0 MON | |||||
| 52026574 | 2 hrs ago | 0 MON | |||||
| 52026574 | 2 hrs ago | 0 MON | |||||
| 52026574 | 2 hrs ago | 0 MON | |||||
| 52026574 | 2 hrs ago | 0 MON | |||||
| 52026574 | 2 hrs ago | 0 MON | |||||
| 52026574 | 2 hrs ago | 0 MON | |||||
| 52022763 | 2 hrs ago | 0 MON | |||||
| 52022763 | 2 hrs ago | 0 MON | |||||
| 52022763 | 2 hrs ago | 0 MON | |||||
| 52022763 | 2 hrs ago | 0 MON |
Loading...
Loading
Contract Name:
ForwarderLogic
Compiler Version
v0.8.26+commit.8a97fa7a
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {IERC20, SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {FeeAdapter} from "./FeeAdapter.sol";
import {IForwarderLogic} from "./interfaces/IForwarderLogic.sol";
import {RouterLib} from "./libraries/RouterLib.sol";
import {TokenLib} from "./libraries/TokenLib.sol";
/**
* @title ForwarderLogic
* @notice Forwarder logic contract to call another router.
* Note: this contract will not work with transfer tax tokens.
*/
contract ForwarderLogic is FeeAdapter, IForwarderLogic {
using EnumerableSet for EnumerableSet.AddressSet;
using SafeERC20 for IERC20;
address private immutable ROUTER;
EnumerableSet.AddressSet private _trustedRouter;
mapping(address => bool) private _blacklist;
constructor(address router, address protocolFeeReceiver, uint96 protocolFeeShare)
FeeAdapter(protocolFeeReceiver, protocolFeeShare)
{
if (router == address(0)) revert ForwarderLogic__InvalidRouter();
ROUTER = router;
}
/**
* @dev Returns the length of the trusted routers.
*/
function getTrustedRouterLength() external view override returns (uint256) {
return _trustedRouter.length();
}
/**
* @dev Returns the trusted router at the specified index.
*/
function getTrustedRouterAt(uint256 index) external view override returns (address) {
return _trustedRouter.at(index);
}
/**
* @dev Returns the blacklist status of the account.
*/
function isBlacklisted(address account) external view override returns (bool) {
return _blacklist[account];
}
/**
* @dev Swaps an exact amount of tokenIn for as much tokenOut as possible using an external router.
* The function will simply forward the call to the router and return the amount of tokenIn and tokenOut swapped.
*
* Requirements:
* - The caller must be the router.
* - The third party router must be trusted.
* - The data must be formatted using:
* - if 0 fee, `abi.encodePacked(approval, router, uint16(0), routerData)`
* - else, `abi.encodePacked(approval, router, uint16(feePercent), bool(isFeeTokenIn), allocatee, routerData)`
* - The fee amount must be less than or equal to the amountIn.
* - The router data must use at most `amountIn - feeAmount` of tokenIn.
*/
function swapExactIn(
address tokenIn,
address tokenOut,
uint256 amountIn,
uint256,
address from,
address to,
bytes calldata data
) external override returns (uint256, uint256) {
if (msg.sender != ROUTER) revert ForwarderLogic__OnlyRouter();
if (_blacklist[from] || (from != to && _blacklist[to])) revert ForwarderLogic__Blacklisted();
RouterLib.transfer(ROUTER, tokenIn, from, address(this), amountIn);
uint256 feePercent = uint256(uint16(bytes2(data[40:42])));
(uint256 isFeeTokenIn, address allocatee, bytes memory routerData) = feePercent == 0
? (0, address(0), data[42:])
: ((bytes1(data[42:43]) != 0 ? 1 : 2), address(uint160(bytes20(data[43:63]))), data[63:]);
address tokenIn_ = tokenIn;
address tokenOut_ = tokenOut;
uint256 amountInWithoutFee = amountIn;
if (isFeeTokenIn == 1) {
uint256 feeAmount = (amountInWithoutFee * feePercent) / BPS;
amountInWithoutFee -= feeAmount;
_sendFee(tokenIn_, address(this), allocatee, feeAmount);
}
{
address approval = address(uint160(bytes20(data[0:20])));
address router = address(uint160(bytes20(data[20:40])));
SafeERC20.forceApprove(IERC20(tokenIn_), approval, amountInWithoutFee);
_call(router, routerData);
// Will always revert if amountIn is type(uint256).max, but it will never happen in practice.
uint256 allowance = IERC20(tokenIn_).allowance(address(this), approval);
if (allowance != 0) revert ForwarderLogic__UnspentAmountIn();
}
uint256 amountOut = TokenLib.balanceOf(tokenOut_, address(this));
if (isFeeTokenIn == 2) {
uint256 feeAmount = (amountOut * feePercent) / BPS;
amountOut -= feeAmount;
_sendFee(tokenOut_, address(this), allocatee, feeAmount);
}
TokenLib.transfer(tokenOut_, to, amountOut);
return (amountIn, amountOut);
}
/**
* @dev Reverts as there is no real way to only take the required amount of token in.
*/
function swapExactOut(address, address, uint256, uint256, address, address, bytes calldata)
external
pure
returns (uint256, uint256)
{
revert ForwarderLogic__NotImplemented();
}
/**
* @dev Sweeps tokens from the contract to the recipient.
*
* Requirements:
* - The caller must be the router owner.
*/
function sweep(address token, address to, uint256 amount) external override {
_checkSender();
token == address(0) ? TokenLib.transferNative(to, amount) : TokenLib.transfer(token, to, amount);
}
/**
* @dev Updates the trusted routers.
*
* Requirements:
* - The caller must be the router owner.
*/
function updateTrustedRouter(address router, bool add) external override {
_checkSender();
if (!(add ? _trustedRouter.add(router) : _trustedRouter.remove(router))) {
revert ForwarderLogic__RouterUpdateFailed();
}
emit TrustedRouterUpdated(router, add);
}
/**
* @dev Updates the blacklist.
*
* Requirements:
* - The caller must be the router owner.
*/
function updateBlacklist(address account, bool blacklisted) external override {
_checkSender();
_blacklist[account] = blacklisted;
emit BlacklistUpdated(account, blacklisted);
}
/**
* @dev Checks if the sender is the router's owner.
*
* Requirements:
* - The sender must be the router's owner.
*/
function _checkSender() internal view override {
if (msg.sender != Ownable(ROUTER).owner()) revert ForwarderLogic__OnlyRouterOwner();
}
/**
* @dev Calls the target contract with the provided data.
*
* Requirements:
* - The call must be successful.
* - The target contract must have code.
*/
function _call(address router, bytes memory data) private {
if (!_trustedRouter.contains(router)) revert ForwarderLogic__UntrustedRouter();
uint256 successState;
assembly ("memory-safe") {
successState := call(gas(), router, 0, add(data, 32), mload(data), 0, 0)
if iszero(successState) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
if iszero(returndatasize()) {
if iszero(extcodesize(router)) {
mstore(0, 0x595e4957) // ForwarderLogic__NoCode()
revert(0x1c, 4)
}
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev An operation with an ERC20 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.
*/
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.
*/
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.
*/
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 Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
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 silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && address(token).code.length > 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.20;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position is the index of the value in the `values` array plus 1.
// Position 0 is used to mean a value is not in the set.
mapping(bytes32 value => uint256) _positions;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._positions[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We cache the value's position to prevent multiple reads from the same storage slot
uint256 position = set._positions[value];
if (position != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 valueIndex = position - 1;
uint256 lastIndex = set._values.length - 1;
if (valueIndex != lastIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the lastValue to the index where the value to delete is
set._values[valueIndex] = lastValue;
// Update the tracked position of the lastValue (that was just moved)
set._positions[lastValue] = position;
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the tracked position for the deleted slot
delete set._positions[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._positions[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @title TokenLib
* @dev Helper library for token operations, such as balanceOf, transfer, transferFrom, wrap, and unwrap.
*/
library TokenLib {
error TokenLib__BalanceOfFailed();
error TokenLib__WrapFailed();
error TokenLib__UnwrapFailed();
error TokenLib__NativeTransferFailed();
error TokenLib__TransferFromFailed();
error TokenLib__TransferFailed();
error TokenLib__ApproveFailed();
/**
* @dev Returns the balance of a token for an account.
*
* Requirements:
* - The call must succeed.
* - The target contract must return at least 32 bytes.
*/
function balanceOf(address token, address account) internal view returns (uint256 amount) {
uint256 success;
uint256 returnDataSize;
assembly ("memory-safe") {
mstore(0, 0x70a08231) // balanceOf(address)
mstore(32, account)
success := staticcall(gas(), token, 28, 36, 0, 32)
returnDataSize := returndatasize()
amount := mload(0)
}
if (success == 0) _tryRevertWithReason();
// If call failed, and it didn't already bubble up the revert reason, then the return data size must be 0,
// which will revert here with a generic error message
if (returnDataSize < 32) revert TokenLib__BalanceOfFailed();
}
/**
* @dev Returns the balance of a token for an account, or the native balance of the account if the token is the
* native token.
*
* Requirements:
* - The call must succeed (if the token is not the native token).
* - The target contract must return at least 32 bytes (if the token is not the native token).
*/
function universalBalanceOf(address token, address account) internal view returns (uint256 amount) {
return token == address(0) ? account.balance : balanceOf(token, account);
}
/**
* @dev Transfers native tokens to an account.
*
* Requirements:
* - The call must succeed.
*/
function transferNative(address to, uint256 amount) internal {
uint256 success;
assembly ("memory-safe") {
success := call(gas(), to, amount, 0, 0, 0, 0)
}
if (success == 0) {
_tryRevertWithReason();
revert TokenLib__NativeTransferFailed();
}
}
/**
* @dev Transfers tokens from an account to another account.
* This function does not check if the target contract has code, this should be done before calling this function
*
* Requirements:
* - The call must succeed.
*/
function wrap(address wnative, uint256 amount) internal {
uint256 success;
assembly ("memory-safe") {
mstore(0, 0xd0e30db0) // deposit()
success := call(gas(), wnative, amount, 28, 4, 0, 0)
}
if (success == 0) {
_tryRevertWithReason();
revert TokenLib__WrapFailed();
}
}
/**
* @dev Transfers tokens from an account to another account.
* This function does not check if the target contract has code, this should be done before calling this function
*
* Requirements:
* - The call must succeed.
*/
function unwrap(address wnative, uint256 amount) internal {
uint256 success;
assembly ("memory-safe") {
mstore(0, 0x2e1a7d4d) // withdraw(uint256)
mstore(32, amount)
success := call(gas(), wnative, 0, 28, 36, 0, 0)
}
if (success == 0) {
_tryRevertWithReason();
revert TokenLib__UnwrapFailed();
}
}
/**
* @dev Transfers tokens from an account to another account.
*
* Requirements:
* - The call must succeed
* - The target contract must either return true or no value.
* - The target contract must have code.
*/
function transfer(address token, address to, uint256 amount) internal {
uint256 success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let m0x40 := mload(0x40)
mstore(0, 0xa9059cbb) // transfer(address,uint256)
mstore(32, to)
mstore(64, amount)
success := call(gas(), token, 0, 28, 68, 0, 32)
returnSize := returndatasize()
returnValue := mload(0)
mstore(0x40, m0x40)
}
if (success == 0) {
_tryRevertWithReason();
revert TokenLib__TransferFailed();
}
if (returnSize == 0 ? token.code.length == 0 : returnValue != 1) revert TokenLib__TransferFailed();
}
/**
* @dev Transfers tokens from an account to another account.
*
* Requirements:
* - The call must succeed.
* - The target contract must either return true or no value.
* - The target contract must have code.
*/
function transferFrom(address token, address from, address to, uint256 amount) internal {
uint256 success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let m0x40 := mload(0x40)
let m0x60 := mload(0x60)
mstore(0, 0x23b872dd) // transferFrom(address,address,uint256)
mstore(32, from)
mstore(64, to)
mstore(96, amount)
success := call(gas(), token, 0, 28, 100, 0, 32)
returnSize := returndatasize()
returnValue := mload(0)
mstore(0x40, m0x40)
mstore(0x60, m0x60)
}
if (success == 0) {
_tryRevertWithReason();
revert TokenLib__TransferFromFailed();
}
if (returnSize == 0 ? token.code.length == 0 : returnValue != 1) revert TokenLib__TransferFromFailed();
}
/**
* @dev Approves an account to spend tokens on behalf of the caller.
*
* Requirements:
* - The call must succeed.
* - The target contract must either return true or no value.
* - The target contract must have code.
*/
function forceApprove(address token, address spender, uint256 amount) internal {
uint256 success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
function approve(token_, amount_) -> success_ {
mstore(64, amount_)
success_ := call(gas(), token_, 0, 28, 68, 64, 32)
}
let m0x40 := mload(0x40)
mstore(0, 0x095ea7b3) // approve(address,uint256)
mstore(32, spender)
success := approve(token, amount)
if iszero(and(eq(mload(64), 1), success)) {
if iszero(lt(or(iszero(extcodesize(token)), returndatasize()), success)) {
pop(approve(token, 0))
success := approve(token, amount)
}
}
returnSize := returndatasize()
returnValue := mload(64)
mstore(0x40, m0x40)
}
if (success == 0) {
_tryRevertWithReason();
revert TokenLib__ApproveFailed();
}
if (returnSize == 0 ? token.code.length == 0 : returnValue != 1) revert TokenLib__ApproveFailed();
}
/**
* @dev Tries to bubble up the revert reason.
* This function needs to be called only if the call has failed, and will revert if there is a revert reason.
* This function might no revert if there is no revert reason, always use it in conjunction with a revert.
*/
function _tryRevertWithReason() private pure {
assembly ("memory-safe") {
if returndatasize() {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the 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.0.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*
* ==== 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.0.0) (utils/Address.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error AddressInsufficientBalance(address account);
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedInnerCall();
/**
* @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 AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
/**
* @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
* {FailedInnerCall} 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 AddressInsufficientBalance(address(this));
}
(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 {FailedInnerCall}) 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 {FailedInnerCall} 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 {FailedInnerCall}.
*/
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
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IFeeAdapter {
error FeeAdapter__InvalidProtocolFeeReceiver();
error FeeAdapter__InvalidProtocolFeeShare();
error FeeAdapter__InvalidFeeReceiver();
error FeeAdapter__InvalidFrom();
event ProtocolFeeParametersSet(
address indexed sender, address indexed protocolFeeReceiver, uint96 protocolFeeShare
);
event FeeSent(address indexed token, address indexed allocatee, uint256 feeAmount, uint256 protocolFeeAmount);
function getProtocolFeeRecipient() external view returns (address);
function getProtocolFeeShare() external view returns (uint256);
function setProtocolFeeParameters(address feeReceiver, uint96 feeShare) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.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 Ownable is Context {
address private _owner;
/**
* @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.
*/
constructor(address initialOwner) {
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) {
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 {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IFeeAdapter} from "./interfaces/IFeeAdapter.sol";
import {TokenLib} from "./libraries/TokenLib.sol";
/**
* @title FeeAdapter
* @notice This contract handles the fee sharing logic for the router.
* It allows setting the protocol fee parameters and sending fees to the protocol fee recipient.
* When sending fees, it splits the fee between the protocol fee recipient and the fee recipient
* based on the protocol fee share. E.g. if the protocol fee share is 10% and the fee amount is 100,
* then 10 will be sent to the protocol fee recipient and 90 will be sent to the fee recipient.
*/
abstract contract FeeAdapter is IFeeAdapter {
uint256 internal constant BPS = 10_000;
address private _protocolFeeRecipient;
uint96 private _protocolFeeShare;
constructor(address feeReceiver, uint96 feeShare) {
_setProtocolFeeParameters(feeReceiver, feeShare);
}
/**
* @dev Returns the protocol fee recipient address.
*/
function getProtocolFeeRecipient() external view override returns (address) {
return _protocolFeeRecipient;
}
/**
* @dev Returns the protocol fee share.
*/
function getProtocolFeeShare() external view override returns (uint256) {
return _protocolFeeShare;
}
/**
* @dev Sets the protocol fee parameters.
*
* Requirements:
* - The caller must be authorized.
* - The fee receiver address must not be zero.
* - The fee share must be less than or equal to 10_000 (100%).
*/
function setProtocolFeeParameters(address feeReceiver, uint96 feeShare) external override {
_checkSender();
_setProtocolFeeParameters(feeReceiver, feeShare);
}
/**
* @dev Internal function to set the protocol fee parameters.
*
* Requirements:
* - The fee receiver address must not be zero.
* - The fee share must be less than or equal to 10_000 (100%).
*/
function _setProtocolFeeParameters(address protocolFeeReceiver, uint96 protocolFeeShare) internal {
if (protocolFeeReceiver == address(0)) revert FeeAdapter__InvalidProtocolFeeReceiver();
if (protocolFeeShare > BPS) revert FeeAdapter__InvalidProtocolFeeShare();
_protocolFeeRecipient = protocolFeeReceiver;
_protocolFeeShare = protocolFeeShare;
emit ProtocolFeeParametersSet(msg.sender, protocolFeeReceiver, protocolFeeShare);
}
/**
* @dev Internal function to send the fee to the fee recipient.
* The user parameter is only used for event logging.
*
* Requirements:
* - The fee recipient address must not be zero.
* - The fee amount must be greater than zero.
*/
function _sendFee(address token, address payer, address allocatee, uint256 feeAmount) internal {
if (feeAmount > 0) {
if (allocatee == address(0)) revert FeeAdapter__InvalidFeeReceiver();
uint256 protocolFeeAmount = (feeAmount * _protocolFeeShare) / BPS;
uint256 remainingFeeAmount = feeAmount - protocolFeeAmount;
if (remainingFeeAmount > 0) _transferFee(token, payer, allocatee, remainingFeeAmount);
if (protocolFeeAmount > 0) _transferFee(token, payer, _protocolFeeRecipient, protocolFeeAmount);
emit FeeSent(token, allocatee, feeAmount, protocolFeeAmount);
}
}
/**
* @dev Internal function to transfer tokens from the contract to the recipient.
*
* Requirements:
* - The sender must be the contract itself.
*/
function _transferFee(address token, address from, address to, uint256 amount) internal virtual {
if (from != address(this)) revert FeeAdapter__InvalidFrom();
TokenLib.transfer(token, to, amount);
}
/**
* @dev Internal function to check if the sender is authorized.
* Must be implemented in the derived contract.
*/
function _checkSender() internal view virtual;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IFeeAdapter} from "./IFeeAdapter.sol";
interface IForwarderLogic is IFeeAdapter {
error ForwarderLogic__InvalidRouter();
error ForwarderLogic__NotImplemented();
error ForwarderLogic__OnlyRouterOwner();
error ForwarderLogic__NoCode();
error ForwarderLogic__OnlyRouter();
error ForwarderLogic__RouterUpdateFailed();
error ForwarderLogic__UntrustedRouter();
error ForwarderLogic__Blacklisted();
error ForwarderLogic__UnspentAmountIn();
event TrustedRouterUpdated(address indexed router, bool trusted);
event BlacklistUpdated(address indexed account, bool blacklisted);
function getTrustedRouterLength() external view returns (uint256);
function getTrustedRouterAt(uint256 index) external view returns (address);
function isBlacklisted(address account) external view returns (bool);
function swapExactIn(
address tokenIn,
address tokenOut,
uint256 amountIn,
uint256 amountOutMin,
address from,
address to,
bytes calldata route
) external returns (uint256 totalIn, uint256 totalOut);
function sweep(address token, address to, uint256 amount) external;
function updateTrustedRouter(address router, bool add) external;
function updateBlacklist(address account, bool blacklisted) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {TokenLib} from "./TokenLib.sol";
/**
* @title RouterLib
* @dev Helper library for router operations, such as validateAndTransfer, transfer, and swap.
* The router must implement a fallback function that uses `validateAndTransfer` to validate the allowance
* and transfer the tokens and functions that uses `swap` to call the router logic to swap tokens.
* The router logic must implement the `swapExactIn` and `swapExactOut` functions to swap tokens and
* use the `transfer` function to transfer tokens from the router according to the route selected.
*/
library RouterLib {
error RouterLib__ZeroAmount();
error RouterLib__InsufficientAllowance(uint256 allowance, uint256 amount);
/**
* @dev Returns the slot for the allowance of a token for a sender from an address.
*/
function getAllowanceSlot(
mapping(bytes32 key => uint256) storage allowances,
address token,
address sender,
address from
) internal pure returns (bytes32 s) {
assembly ("memory-safe") {
mstore(0, shl(96, token))
mstore(20, shl(96, sender))
// Overwrite the last 8 bytes of the free memory pointer with zero,
//which should always be zeros
mstore(40, shl(96, from))
let key := keccak256(0, 60)
mstore(0, key)
mstore(32, allowances.slot)
s := keccak256(0, 64)
}
}
/**
* @dev Validates the allowance of a token for a sender from an address, and transfers the token.
*
* Requirements:
* - The allowance must be greater than or equal to the amount.
* - The amount must be greater than zero.
* - If from is not the router, the token must have been approved for the router.
*/
function validateAndTransfer(mapping(bytes32 key => uint256) storage allowances) internal {
address token;
address from;
address to;
uint256 amount;
uint256 allowance;
uint256 success;
assembly ("memory-safe") {
token := shr(96, calldataload(4))
from := shr(96, calldataload(24))
to := shr(96, calldataload(44))
amount := calldataload(64)
}
bytes32 allowanceSlot = getAllowanceSlot(allowances, token, msg.sender, from);
assembly ("memory-safe") {
allowance := sload(allowanceSlot)
if iszero(lt(allowance, amount)) {
success := 1
sstore(allowanceSlot, sub(allowance, amount))
}
}
if (amount == 0) revert RouterLib__ZeroAmount(); // Also prevent calldata <= 64
if (success == 0) revert RouterLib__InsufficientAllowance(allowance, amount);
from == address(this) ? TokenLib.transfer(token, to, amount) : TokenLib.transferFrom(token, from, to, amount);
}
/**
* @dev Calls the router to transfer tokens from an account to another account.
*
* Requirements:
* - The call must succeed.
* - The target contract must use `validateAndTransfer` inside its fallback function to validate the allowance
* and transfer the tokens accordingly.
*/
function transfer(address router, address token, address from, address to, uint256 amount) internal {
assembly ("memory-safe") {
let m0x40 := mload(0x40)
mstore(0, shr(32, shl(96, token)))
mstore(24, shl(96, from))
mstore(44, shl(96, to))
mstore(64, amount)
if iszero(call(gas(), router, 0, 0, 96, 0, 0)) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
mstore(0x40, m0x40)
}
}
/**
* @dev Swaps tokens using the router logic.
* It will also set the allowance for the logic contract to spend the token from the sender and reset it
* after the swap is done.
*
* Requirements:
* - The logic contract must not be the zero address.
* - The call must succeed.
* - The logic contract must call this contract's fallback function to validate the allowance and transfer the
* tokens.
*/
function swap(
mapping(bytes32 key => uint256) storage allowances,
address tokenIn,
address tokenOut,
uint256 amountIn,
uint256 amountOut,
address from,
address to,
bytes calldata route,
bool exactIn,
address logic
) internal returns (uint256 totalIn, uint256 totalOut) {
bytes32 allowanceSlot = getAllowanceSlot(allowances, tokenIn, logic, from);
uint256 length = 256 + route.length; // 32 * 6 + 32 + 32 + route.length
bytes memory data = new bytes(length);
assembly ("memory-safe") {
sstore(allowanceSlot, amountIn)
switch exactIn
// swapExactIn(tokenIn, tokenOut, amountIn, amountOut, from, to, route)
// swapExactOut(tokenIn, tokenOut, amountOut, amountIn, from, to, route)
case 1 { mstore(data, 0xbd084435) }
default { mstore(data, 0xcb7e0007) }
mstore(add(data, 32), tokenIn)
mstore(add(data, 64), tokenOut)
mstore(add(data, 96), amountIn)
mstore(add(data, 128), amountOut)
mstore(add(data, 160), from)
mstore(add(data, 192), to)
mstore(add(data, 224), 224) // 32 * 6 + 32
mstore(add(data, 256), route.length)
calldatacopy(add(data, 288), route.offset, route.length)
if iszero(call(gas(), logic, 0, add(data, 28), add(length, 4), 0, 64)) {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
totalIn := mload(0)
totalOut := mload(32)
sstore(allowanceSlot, 0)
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}{
"optimizer": {
"enabled": true,
"runs": 1000000
},
"evmVersion": "paris",
"remappings": [
"@forge-std/contracts/=lib/forge-std/src/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"ds-test/=lib/openzeppelin-contracts-upgradeable/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"forge-std/=lib/forge-std/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/"
],
"metadata": {
"bytecodeHash": "ipfs"
},
"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":"router","type":"address"},{"internalType":"address","name":"protocolFeeReceiver","type":"address"},{"internalType":"uint96","name":"protocolFeeShare","type":"uint96"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[],"name":"FeeAdapter__InvalidFeeReceiver","type":"error"},{"inputs":[],"name":"FeeAdapter__InvalidFrom","type":"error"},{"inputs":[],"name":"FeeAdapter__InvalidProtocolFeeReceiver","type":"error"},{"inputs":[],"name":"FeeAdapter__InvalidProtocolFeeShare","type":"error"},{"inputs":[],"name":"ForwarderLogic__Blacklisted","type":"error"},{"inputs":[],"name":"ForwarderLogic__InvalidRouter","type":"error"},{"inputs":[],"name":"ForwarderLogic__NoCode","type":"error"},{"inputs":[],"name":"ForwarderLogic__NotImplemented","type":"error"},{"inputs":[],"name":"ForwarderLogic__OnlyRouter","type":"error"},{"inputs":[],"name":"ForwarderLogic__OnlyRouterOwner","type":"error"},{"inputs":[],"name":"ForwarderLogic__RouterUpdateFailed","type":"error"},{"inputs":[],"name":"ForwarderLogic__UnspentAmountIn","type":"error"},{"inputs":[],"name":"ForwarderLogic__UntrustedRouter","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"TokenLib__BalanceOfFailed","type":"error"},{"inputs":[],"name":"TokenLib__NativeTransferFailed","type":"error"},{"inputs":[],"name":"TokenLib__TransferFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":false,"internalType":"bool","name":"blacklisted","type":"bool"}],"name":"BlacklistUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"address","name":"allocatee","type":"address"},{"indexed":false,"internalType":"uint256","name":"feeAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"protocolFeeAmount","type":"uint256"}],"name":"FeeSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"protocolFeeReceiver","type":"address"},{"indexed":false,"internalType":"uint96","name":"protocolFeeShare","type":"uint96"}],"name":"ProtocolFeeParametersSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"router","type":"address"},{"indexed":false,"internalType":"bool","name":"trusted","type":"bool"}],"name":"TrustedRouterUpdated","type":"event"},{"inputs":[],"name":"getProtocolFeeRecipient","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getProtocolFeeShare","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getTrustedRouterAt","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTrustedRouterLength","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"isBlacklisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"feeReceiver","type":"address"},{"internalType":"uint96","name":"feeShare","type":"uint96"}],"name":"setProtocolFeeParameters","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tokenIn","type":"address"},{"internalType":"address","name":"tokenOut","type":"address"},{"internalType":"uint256","name":"amountIn","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"swapExactIn","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"},{"internalType":"address","name":"","type":"address"},{"internalType":"bytes","name":"","type":"bytes"}],"name":"swapExactOut","outputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"sweep","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"bool","name":"blacklisted","type":"bool"}],"name":"updateBlacklist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"router","type":"address"},{"internalType":"bool","name":"add","type":"bool"}],"name":"updateTrustedRouter","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
60a060405234801561001057600080fd5b50604051611b27380380611b2783398101604081905261002f91610140565b818161003b8282610077565b50506001600160a01b03831661006457604051632cac7a4560e21b815260040160405180910390fd5b50506001600160a01b0316608052610194565b6001600160a01b03821661009e5760405163ec049e3760e01b815260040160405180910390fd5b612710816001600160601b031611156100ca576040516318fd95d160e11b815260040160405180910390fd5b6001600160a01b038216600160a01b6001600160601b038316908102821760005560405190815233907f6d94271a74c346e0cb5cd2db3fde24fe596fe70043c7b0b32ee206a3d01378a49060200160405180910390a35050565b80516001600160a01b038116811461013b57600080fd5b919050565b60008060006060848603121561015557600080fd5b61015e84610124565b925061016c60208501610124565b60408501519092506001600160601b038116811461018957600080fd5b809150509250925092565b60805161196a6101bd600039600081816103f70152818161051a015261086f015261196a6000f3fe608060405234801561001057600080fd5b50600436106100c95760003560e01c80639155e08311610081578063c60bc2031161005b578063c60bc203146101cc578063cb7e0007146101df578063fe575a87146101f257600080fd5b80639155e08314610189578063ad8c08d51461019c578063bd084435146101a457600080fd5b806362c06767116100b257806362c067671461014357806372c8fc0e146101585780637df5106d1461017657600080fd5b80630dd4a028146100ce578063192bcad31461010b575b600080fd5b6100e16100dc366004611477565b61023b565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6000547401000000000000000000000000000000000000000090046bffffffffffffffffffffffff165b604051908152602001610102565b6101566101513660046114b2565b61024e565b005b60005473ffffffffffffffffffffffffffffffffffffffff166100e1565b610156610184366004611501565b61028c565b610156610197366004611501565b610340565b6101356103cb565b6101b76101b236600461153a565b6103dc565b60408051928352602083019190915201610102565b6101566101da36600461160b565b61080f565b6101b76101ed36600461153a565b610825565b61022b61020036600461164a565b73ffffffffffffffffffffffffffffffffffffffff1660009081526003602052604090205460ff1690565b6040519015158152602001610102565b600061024860018361085a565b92915050565b61025661086d565b73ffffffffffffffffffffffffffffffffffffffff8316156102825761027d838383610962565b505050565b61027d8282610a41565b61029461086d565b806102a9576102a4600183610a91565b6102b4565b6102b4600183610ab3565b6102ea576040517f7f93202200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff167f518f7fba6d5b3181292713ad7427d0c185379072861df7f23a29357ebb037b5482604051610334911515815260200190565b60405180910390a25050565b61034861086d565b73ffffffffffffffffffffffffffffffffffffffff821660008181526003602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001685151590811790915591519182527f6a12b3df6cba4203bd7fd06b816789f87de8c594299aed5717ae070fac781bac9101610334565b60006103d76001610ad5565b905090565b6000803373ffffffffffffffffffffffffffffffffffffffff7f0000000000000000000000000000000000000000000000000000000000000000161461044e576040517f4e8cf44d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff861660009081526003602052604090205460ff16806104de57508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141580156104de575073ffffffffffffffffffffffffffffffffffffffff851660009081526003602052604090205460ff165b15610515576040517f3cd5212100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6105427f00000000000000000000000000000000000000000000000000000000000000008b88308c610adf565b6000610552602a60288688611667565b61055b91611691565b60f01c90506000808083156105e057610578602b602a898b611667565b610581916116f6565b7fff00000000000000000000000000000000000000000000000000000000000000166000036105b15760026105b4565b60015b6105c2603f602b8a8c611667565b6105cb9161175b565b60601c6105db89603f818d611667565b6105f0565b6000806105f089602a818d611667565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505060ff93909316955090935091508e90508d8d600186900361067357600061271061064d89846117ef565b6106579190611806565b90506106638183611841565b915061067184308884610b21565b505b60006106826014828d8f611667565b61068b9161175b565b60601c905060008c8c6014906028926106a693929190611667565b6106af9161175b565b60601c90506106bf858385610c7e565b6106c98187610da8565b6040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff83811660248301526000919087169063dd62ed3e90604401602060405180830381865afa15801561073f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107639190611854565b9050801561079d576040517f209815a300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060006107ac8330610e4d565b9050866002036107eb5760006127106107c58a846117ef565b6107cf9190611806565b90506107db8183611841565b91506107e984308984610b21565b505b6107f6838e83610962565b8f99509750505050505050509850989650505050505050565b61081761086d565b6108218282610ec6565b5050565b6000806040517f9bc1923300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006108668383610fda565b9392505050565b7f000000000000000000000000000000000000000000000000000000000000000073ffffffffffffffffffffffffffffffffffffffff16638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108fc919061186d565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610960576040517fc676b64f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b600080600060405163a9059cbb6000528560205284604052602060006044601c60008b5af193503d925060005191508060405250826000036109d8576109a6611004565b6040517f87c6ec7c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81156109e8578060011415610a02565b73ffffffffffffffffffffffffffffffffffffffff86163b155b15610a39576040517f87c6ec7c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050565b600080600080600085875af190508060000361027d57610a5f611004565b6040517fa01b460600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006108668373ffffffffffffffffffffffffffffffffffffffff8416611014565b60006108668373ffffffffffffffffffffffffffffffffffffffff841661110e565b6000610248825490565b6040518460601b60201c6000528360601b6018528260601b602c528160405260008060606000808a5af1610b17573d6000803e3d6000fd5b6040525050505050565b8015610c785773ffffffffffffffffffffffffffffffffffffffff8216610b74576040517fae0edfe900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000805461271090610bac907401000000000000000000000000000000000000000090046bffffffffffffffffffffffff16846117ef565b610bb69190611806565b90506000610bc48284611841565b90508015610bd857610bd88686868461115d565b8115610c0557600054610c05908790879073ffffffffffffffffffffffffffffffffffffffff168561115d565b8373ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167f77c197a1ae17318af19ae49d654709f9fe13e90a7fb70e1bdd5f665f6b9bce828585604051610c6d929190918252602082015260400190565b60405180910390a350505b50505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b300000000000000000000000000000000000000000000000000000000179052610d0a84826111b7565b610c78576040805173ffffffffffffffffffffffffffffffffffffffff8516602482015260006044808301919091528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b300000000000000000000000000000000000000000000000000000000179052610d9e908590611279565b610c788482611279565b610ddd60018373ffffffffffffffffffffffffffffffffffffffff811660009081526001830160205260408120541515610866565b610e13576040517f3e66676500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008060008351602085016000875af1905080610e34573d6000803e3d6000fd5b3d61027d57823b61027d5763595e49576000526004601cfd5b60008060006370a0823160005283602052602060006024601c885afa91503d9050600051925081600003610e8357610e83611004565b6020811015610ebe576040517f07e05a0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505092915050565b73ffffffffffffffffffffffffffffffffffffffff8216610f13576040517fec049e3700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612710816bffffffffffffffffffffffff161115610f5d576040517f31fb2ba200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216740100000000000000000000000000000000000000006bffffffffffffffffffffffff8316908102821760005560405190815233907f6d94271a74c346e0cb5cd2db3fde24fe596fe70043c7b0b32ee206a3d01378a49060200160405180910390a35050565b6000826000018281548110610ff157610ff161188a565b9060005260206000200154905092915050565b3d15610960573d6000803e3d6000fd5b600081815260018301602052604081205480156110fd576000611038600183611841565b855490915060009061104c90600190611841565b90508082146110b157600086600001828154811061106c5761106c61188a565b906000526020600020015490508087600001848154811061108f5761108f61188a565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806110c2576110c26118b9565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610248565b6000915050610248565b5092915050565b600081815260018301602052604081205461115557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610248565b506000610248565b73ffffffffffffffffffffffffffffffffffffffff831630146111ac576040517fd32708a200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c78848383610962565b60008060008473ffffffffffffffffffffffffffffffffffffffff16846040516111e191906118e8565b6000604051808303816000865af19150503d806000811461121e576040519150601f19603f3d011682016040523d82523d6000602084013e611223565b606091505b509150915081801561124d57508051158061124d57508080602001905181019061124d9190611917565b8015611270575060008573ffffffffffffffffffffffffffffffffffffffff163b115b95945050505050565b600061129b73ffffffffffffffffffffffffffffffffffffffff841683611314565b905080516000141580156112c05750808060200190518101906112be9190611917565b155b1561027d576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff841660048201526024015b60405180910390fd5b606061086683836000846000808573ffffffffffffffffffffffffffffffffffffffff16848660405161134791906118e8565b60006040518083038185875af1925050503d8060008114611384576040519150601f19603f3d011682016040523d82523d6000602084013e611389565b606091505b50915091506113998683836113a3565b9695505050505050565b6060826113b8576113b382611432565b610866565b81511580156113dc575073ffffffffffffffffffffffffffffffffffffffff84163b155b1561142b576040517f9996b31500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8516600482015260240161130b565b5080610866565b8051156114425780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b60006020828403121561148957600080fd5b5035919050565b73ffffffffffffffffffffffffffffffffffffffff8116811461147457600080fd5b6000806000606084860312156114c757600080fd5b83356114d281611490565b925060208401356114e281611490565b929592945050506040919091013590565b801515811461147457600080fd5b6000806040838503121561151457600080fd5b823561151f81611490565b9150602083013561152f816114f3565b809150509250929050565b60008060008060008060008060e0898b03121561155657600080fd5b883561156181611490565b9750602089013561157181611490565b96506040890135955060608901359450608089013561158f81611490565b935060a089013561159f81611490565b925060c089013567ffffffffffffffff8111156115bb57600080fd5b8901601f81018b136115cc57600080fd5b803567ffffffffffffffff8111156115e357600080fd5b8b60208284010111156115f557600080fd5b989b979a50959850939692959194602001935050565b6000806040838503121561161e57600080fd5b823561162981611490565b915060208301356bffffffffffffffffffffffff8116811461152f57600080fd5b60006020828403121561165c57600080fd5b813561086681611490565b6000808585111561167757600080fd5b8386111561168457600080fd5b5050820193919092039150565b80357fffff0000000000000000000000000000000000000000000000000000000000008116906002841015611107577fffff000000000000000000000000000000000000000000000000000000000000808560020360031b1b82161691505092915050565b80357fff000000000000000000000000000000000000000000000000000000000000008116906001841015611107577fff00000000000000000000000000000000000000000000000000000000000000808560010360031b1b82161691505092915050565b80357fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008116906014841015611107577fffffffffffffffffffffffffffffffffffffffff000000000000000000000000808560140360031b1b82161691505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8082028115828204841417610248576102486117c0565b60008261183c577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b81810381811115610248576102486117c0565b60006020828403121561186657600080fd5b5051919050565b60006020828403121561187f57600080fd5b815161086681611490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6000825160005b8181101561190957602081860181015185830152016118ef565b506000920191825250919050565b60006020828403121561192957600080fd5b8151610866816114f356fea2646970667358221220c3b9a316a479febdb63acd667115ac5eacbd06a1f339548ea236c79533a8742d64736f6c634300081a003300000000000000000000000045a62b090df48243f12a21897e7ed91863e2c86b0000000000000000000000003333d2af1f8959f6572d45adc3dcd99cf77ea41a00000000000000000000000000000000000000000000000000000000000005dc
Deployed Bytecode
0x608060405234801561001057600080fd5b50600436106100c95760003560e01c80639155e08311610081578063c60bc2031161005b578063c60bc203146101cc578063cb7e0007146101df578063fe575a87146101f257600080fd5b80639155e08314610189578063ad8c08d51461019c578063bd084435146101a457600080fd5b806362c06767116100b257806362c067671461014357806372c8fc0e146101585780637df5106d1461017657600080fd5b80630dd4a028146100ce578063192bcad31461010b575b600080fd5b6100e16100dc366004611477565b61023b565b60405173ffffffffffffffffffffffffffffffffffffffff90911681526020015b60405180910390f35b6000547401000000000000000000000000000000000000000090046bffffffffffffffffffffffff165b604051908152602001610102565b6101566101513660046114b2565b61024e565b005b60005473ffffffffffffffffffffffffffffffffffffffff166100e1565b610156610184366004611501565b61028c565b610156610197366004611501565b610340565b6101356103cb565b6101b76101b236600461153a565b6103dc565b60408051928352602083019190915201610102565b6101566101da36600461160b565b61080f565b6101b76101ed36600461153a565b610825565b61022b61020036600461164a565b73ffffffffffffffffffffffffffffffffffffffff1660009081526003602052604090205460ff1690565b6040519015158152602001610102565b600061024860018361085a565b92915050565b61025661086d565b73ffffffffffffffffffffffffffffffffffffffff8316156102825761027d838383610962565b505050565b61027d8282610a41565b61029461086d565b806102a9576102a4600183610a91565b6102b4565b6102b4600183610ab3565b6102ea576040517f7f93202200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b8173ffffffffffffffffffffffffffffffffffffffff167f518f7fba6d5b3181292713ad7427d0c185379072861df7f23a29357ebb037b5482604051610334911515815260200190565b60405180910390a25050565b61034861086d565b73ffffffffffffffffffffffffffffffffffffffff821660008181526003602090815260409182902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001685151590811790915591519182527f6a12b3df6cba4203bd7fd06b816789f87de8c594299aed5717ae070fac781bac9101610334565b60006103d76001610ad5565b905090565b6000803373ffffffffffffffffffffffffffffffffffffffff7f00000000000000000000000045a62b090df48243f12a21897e7ed91863e2c86b161461044e576040517f4e8cf44d00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff861660009081526003602052604090205460ff16806104de57508473ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff16141580156104de575073ffffffffffffffffffffffffffffffffffffffff851660009081526003602052604090205460ff165b15610515576040517f3cd5212100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6105427f00000000000000000000000045a62b090df48243f12a21897e7ed91863e2c86b8b88308c610adf565b6000610552602a60288688611667565b61055b91611691565b60f01c90506000808083156105e057610578602b602a898b611667565b610581916116f6565b7fff00000000000000000000000000000000000000000000000000000000000000166000036105b15760026105b4565b60015b6105c2603f602b8a8c611667565b6105cb9161175b565b60601c6105db89603f818d611667565b6105f0565b6000806105f089602a818d611667565b8080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250505060ff93909316955090935091508e90508d8d600186900361067357600061271061064d89846117ef565b6106579190611806565b90506106638183611841565b915061067184308884610b21565b505b60006106826014828d8f611667565b61068b9161175b565b60601c905060008c8c6014906028926106a693929190611667565b6106af9161175b565b60601c90506106bf858385610c7e565b6106c98187610da8565b6040517fdd62ed3e00000000000000000000000000000000000000000000000000000000815230600482015273ffffffffffffffffffffffffffffffffffffffff83811660248301526000919087169063dd62ed3e90604401602060405180830381865afa15801561073f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107639190611854565b9050801561079d576040517f209815a300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50505060006107ac8330610e4d565b9050866002036107eb5760006127106107c58a846117ef565b6107cf9190611806565b90506107db8183611841565b91506107e984308984610b21565b505b6107f6838e83610962565b8f99509750505050505050509850989650505050505050565b61081761086d565b6108218282610ec6565b5050565b6000806040517f9bc1923300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006108668383610fda565b9392505050565b7f00000000000000000000000045a62b090df48243f12a21897e7ed91863e2c86b73ffffffffffffffffffffffffffffffffffffffff16638da5cb5b6040518163ffffffff1660e01b8152600401602060405180830381865afa1580156108d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906108fc919061186d565b73ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610960576040517fc676b64f00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b565b600080600060405163a9059cbb6000528560205284604052602060006044601c60008b5af193503d925060005191508060405250826000036109d8576109a6611004565b6040517f87c6ec7c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b81156109e8578060011415610a02565b73ffffffffffffffffffffffffffffffffffffffff86163b155b15610a39576040517f87c6ec7c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505050505050565b600080600080600085875af190508060000361027d57610a5f611004565b6040517fa01b460600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60006108668373ffffffffffffffffffffffffffffffffffffffff8416611014565b60006108668373ffffffffffffffffffffffffffffffffffffffff841661110e565b6000610248825490565b6040518460601b60201c6000528360601b6018528260601b602c528160405260008060606000808a5af1610b17573d6000803e3d6000fd5b6040525050505050565b8015610c785773ffffffffffffffffffffffffffffffffffffffff8216610b74576040517fae0edfe900000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000805461271090610bac907401000000000000000000000000000000000000000090046bffffffffffffffffffffffff16846117ef565b610bb69190611806565b90506000610bc48284611841565b90508015610bd857610bd88686868461115d565b8115610c0557600054610c05908790879073ffffffffffffffffffffffffffffffffffffffff168561115d565b8373ffffffffffffffffffffffffffffffffffffffff168673ffffffffffffffffffffffffffffffffffffffff167f77c197a1ae17318af19ae49d654709f9fe13e90a7fb70e1bdd5f665f6b9bce828585604051610c6d929190918252602082015260400190565b60405180910390a350505b50505050565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b300000000000000000000000000000000000000000000000000000000179052610d0a84826111b7565b610c78576040805173ffffffffffffffffffffffffffffffffffffffff8516602482015260006044808301919091528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167f095ea7b300000000000000000000000000000000000000000000000000000000179052610d9e908590611279565b610c788482611279565b610ddd60018373ffffffffffffffffffffffffffffffffffffffff811660009081526001830160205260408120541515610866565b610e13576040517f3e66676500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008060008351602085016000875af1905080610e34573d6000803e3d6000fd5b3d61027d57823b61027d5763595e49576000526004601cfd5b60008060006370a0823160005283602052602060006024601c885afa91503d9050600051925081600003610e8357610e83611004565b6020811015610ebe576040517f07e05a0c00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b505092915050565b73ffffffffffffffffffffffffffffffffffffffff8216610f13576040517fec049e3700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612710816bffffffffffffffffffffffff161115610f5d576040517f31fb2ba200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b73ffffffffffffffffffffffffffffffffffffffff8216740100000000000000000000000000000000000000006bffffffffffffffffffffffff8316908102821760005560405190815233907f6d94271a74c346e0cb5cd2db3fde24fe596fe70043c7b0b32ee206a3d01378a49060200160405180910390a35050565b6000826000018281548110610ff157610ff161188a565b9060005260206000200154905092915050565b3d15610960573d6000803e3d6000fd5b600081815260018301602052604081205480156110fd576000611038600183611841565b855490915060009061104c90600190611841565b90508082146110b157600086600001828154811061106c5761106c61188a565b906000526020600020015490508087600001848154811061108f5761108f61188a565b6000918252602080832090910192909255918252600188019052604090208390555b85548690806110c2576110c26118b9565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610248565b6000915050610248565b5092915050565b600081815260018301602052604081205461115557508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610248565b506000610248565b73ffffffffffffffffffffffffffffffffffffffff831630146111ac576040517fd32708a200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610c78848383610962565b60008060008473ffffffffffffffffffffffffffffffffffffffff16846040516111e191906118e8565b6000604051808303816000865af19150503d806000811461121e576040519150601f19603f3d011682016040523d82523d6000602084013e611223565b606091505b509150915081801561124d57508051158061124d57508080602001905181019061124d9190611917565b8015611270575060008573ffffffffffffffffffffffffffffffffffffffff163b115b95945050505050565b600061129b73ffffffffffffffffffffffffffffffffffffffff841683611314565b905080516000141580156112c05750808060200190518101906112be9190611917565b155b1561027d576040517f5274afe700000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff841660048201526024015b60405180910390fd5b606061086683836000846000808573ffffffffffffffffffffffffffffffffffffffff16848660405161134791906118e8565b60006040518083038185875af1925050503d8060008114611384576040519150601f19603f3d011682016040523d82523d6000602084013e611389565b606091505b50915091506113998683836113a3565b9695505050505050565b6060826113b8576113b382611432565b610866565b81511580156113dc575073ffffffffffffffffffffffffffffffffffffffff84163b155b1561142b576040517f9996b31500000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8516600482015260240161130b565b5080610866565b8051156114425780518082602001fd5b6040517f1425ea4200000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b50565b60006020828403121561148957600080fd5b5035919050565b73ffffffffffffffffffffffffffffffffffffffff8116811461147457600080fd5b6000806000606084860312156114c757600080fd5b83356114d281611490565b925060208401356114e281611490565b929592945050506040919091013590565b801515811461147457600080fd5b6000806040838503121561151457600080fd5b823561151f81611490565b9150602083013561152f816114f3565b809150509250929050565b60008060008060008060008060e0898b03121561155657600080fd5b883561156181611490565b9750602089013561157181611490565b96506040890135955060608901359450608089013561158f81611490565b935060a089013561159f81611490565b925060c089013567ffffffffffffffff8111156115bb57600080fd5b8901601f81018b136115cc57600080fd5b803567ffffffffffffffff8111156115e357600080fd5b8b60208284010111156115f557600080fd5b989b979a50959850939692959194602001935050565b6000806040838503121561161e57600080fd5b823561162981611490565b915060208301356bffffffffffffffffffffffff8116811461152f57600080fd5b60006020828403121561165c57600080fd5b813561086681611490565b6000808585111561167757600080fd5b8386111561168457600080fd5b5050820193919092039150565b80357fffff0000000000000000000000000000000000000000000000000000000000008116906002841015611107577fffff000000000000000000000000000000000000000000000000000000000000808560020360031b1b82161691505092915050565b80357fff000000000000000000000000000000000000000000000000000000000000008116906001841015611107577fff00000000000000000000000000000000000000000000000000000000000000808560010360031b1b82161691505092915050565b80357fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008116906014841015611107577fffffffffffffffffffffffffffffffffffffffff000000000000000000000000808560140360031b1b82161691505092915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8082028115828204841417610248576102486117c0565b60008261183c577f4e487b7100000000000000000000000000000000000000000000000000000000600052601260045260246000fd5b500490565b81810381811115610248576102486117c0565b60006020828403121561186657600080fd5b5051919050565b60006020828403121561187f57600080fd5b815161086681611490565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b6000825160005b8181101561190957602081860181015185830152016118ef565b506000920191825250919050565b60006020828403121561192957600080fd5b8151610866816114f356fea2646970667358221220c3b9a316a479febdb63acd667115ac5eacbd06a1f339548ea236c79533a8742d64736f6c634300081a0033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000045a62b090df48243f12a21897e7ed91863e2c86b0000000000000000000000003333d2af1f8959f6572d45adc3dcd99cf77ea41a00000000000000000000000000000000000000000000000000000000000005dc
-----Decoded View---------------
Arg [0] : router (address): 0x45A62B090DF48243F12A21897e7ed91863E2c86b
Arg [1] : protocolFeeReceiver (address): 0x3333d2AF1f8959F6572d45adC3dCd99cF77Ea41A
Arg [2] : protocolFeeShare (uint96): 1500
-----Encoded View---------------
3 Constructor Arguments found :
Arg [0] : 00000000000000000000000045a62b090df48243f12a21897e7ed91863e2c86b
Arg [1] : 0000000000000000000000003333d2af1f8959f6572d45adc3dcd99cf77ea41a
Arg [2] : 00000000000000000000000000000000000000000000000000000000000005dc
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in MON
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
[ 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.