Source Code
Overview
S Balance
S Value
$0.00Latest 9 from a total of 9 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Execute SOR | 10736681 | 330 days ago | IN | 0 S | 0.00733705 | ||||
| Execute SOR | 7843585 | 344 days ago | IN | 0 S | 0.00733705 | ||||
| Execute SOR | 1442838 | 396 days ago | IN | 0 S | 0.00037816 | ||||
| Claim Owner | 1355720 | 397 days ago | IN | 0 S | 0.00003274 | ||||
| Nominate Owner | 1337346 | 397 days ago | IN | 0 S | 0.00005504 | ||||
| Register Whiteli... | 1334363 | 397 days ago | IN | 0 S | 0.00007569 | ||||
| Register Whiteli... | 1334360 | 397 days ago | IN | 0 S | 0.00007569 | ||||
| Register Whiteli... | 1334358 | 397 days ago | IN | 0 S | 0.00007569 | ||||
| Set Fee Collecto... | 1334318 | 397 days ago | IN | 0 S | 0.00005079 |
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 13298612 | 318 days ago | 0.03918102 S | ||||
| 13298612 | 318 days ago | 0.03918102 S | ||||
| 13256432 | 318 days ago | 0.01468208 S | ||||
| 13256432 | 318 days ago | 0.01468208 S | ||||
| 13256358 | 318 days ago | 0.04155847 S | ||||
| 13256358 | 318 days ago | 0.04155847 S | ||||
| 13255985 | 318 days ago | 128.52057457 S | ||||
| 13255985 | 318 days ago | 128.52057457 S | ||||
| 13250186 | 318 days ago | 0.01468208 S | ||||
| 13250186 | 318 days ago | 0.01468208 S | ||||
| 13243481 | 318 days ago | 0.00847913 S | ||||
| 13243481 | 318 days ago | 0.00847913 S | ||||
| 13238929 | 318 days ago | 333.22913588 S | ||||
| 13238929 | 318 days ago | 333.22913588 S | ||||
| 13237723 | 318 days ago | 0.01852605 S | ||||
| 13237723 | 318 days ago | 0.01852605 S | ||||
| 13232455 | 318 days ago | 0.04985556 S | ||||
| 13232455 | 318 days ago | 0.04985556 S | ||||
| 13232445 | 318 days ago | 0.03234639 S | ||||
| 13232445 | 318 days ago | 0.03234639 S | ||||
| 13232443 | 318 days ago | 0.01180423 S | ||||
| 13232443 | 318 days ago | 0.01180423 S | ||||
| 13228219 | 318 days ago | 1.2315911 S | ||||
| 13228219 | 318 days ago | 1.2315911 S | ||||
| 13227250 | 318 days ago | 0.03171017 S |
Cross-Chain Transactions
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Contract Name:
BungeeGateway
Compiler Version
v0.8.19+commit.7dd6d404
Optimization Enabled:
Yes with 200 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {ISwapExecutor} from "../interfaces/ISwapExecutor.sol";
import {ICalldataExecutor} from "../interfaces/ICalldataExecutor.sol";
import {ISwitchboardRouter} from "../interfaces/ISwitchboardRouter.sol";
import {SingleOutputRequestImpl} from "./SingleOutputRequestImpl.sol";
import {SwapRequestImpl} from "./SwapRequestImpl.sol";
import {BungeeGatewayBase} from "./BungeeGatewayBase.sol";
import {BungeeGatewayStorage} from "./BungeeGatewayStorage.sol";
import {InvalidMsg} from "../common/BungeeErrors.sol";
contract BungeeGateway is BungeeGatewayStorage, BungeeGatewayBase {
SingleOutputRequestImpl public immutable SINGLE_OUTPUT_REQUEST_IMPL;
SwapRequestImpl public immutable SWAP_REQUEST_IMPL;
bytes4 immutable RECEIVE_MSG_FUNCTION_SIG = bytes4(keccak256("receiveMsg(bytes)"));
/**
* @notice Constructor.
* @param _owner owner of the contract.
* @param _mofaSigner address of the mofa signer.
* @param _switchboardRouter address of the switchboard router.
Switchboard router is responsible for sending and delivering messages between chains.
* @param _calldataRouter address of the calldata executor contract.
* @param _permit2 address of the permit 2 contract.
* @param _expiryBuffer expiry buffer for the request fulfilment deadline.
*/
constructor(
address _owner,
address _mofaSigner,
address _switchboardRouter,
address _swapExecutor,
address _calldataRouter,
address _permit2,
uint256 _expiryBuffer,
address _singleOutputRequestImpl,
address _swapOutputRequestImpl
) BungeeGatewayStorage(_owner, _permit2) {
MOFA_SIGNER = _mofaSigner;
SWITCHBOARD_ROUTER = ISwitchboardRouter(_switchboardRouter);
SWAP_EXECUTOR = ISwapExecutor(_swapExecutor);
CALLDATA_EXECUTOR = ICalldataExecutor(_calldataRouter);
EXPIRY_BUFFER = _expiryBuffer;
SINGLE_OUTPUT_REQUEST_IMPL = SingleOutputRequestImpl(_singleOutputRequestImpl);
SWAP_REQUEST_IMPL = SwapRequestImpl(_swapOutputRequestImpl);
}
function executeSOR(bytes calldata data) external payable returns (bytes memory) {
(bool success, bytes memory result) = address(SINGLE_OUTPUT_REQUEST_IMPL).delegatecall(data);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
return result;
}
function executeSR(bytes calldata data) external payable returns (bytes memory) {
(bool success, bytes memory result) = address(SWAP_REQUEST_IMPL).delegatecall(data);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
return result;
}
function inboundMsgFromSwitchboard(uint8 implId, uint32, bytes calldata payload) external payable {
address impl;
if (implId == SINGLE_OUTPUT_IMPL_ID) impl = address(SINGLE_OUTPUT_REQUEST_IMPL);
// there will be no inbound msg for swap request
if (impl == address(0)) revert InvalidMsg();
(bool success, bytes memory result) = impl.delegatecall(
abi.encodeWithSelector(RECEIVE_MSG_FUNCTION_SIG, payload)
);
if (!success) {
assembly {
revert(add(result, 32), mload(result))
}
}
}
/// @dev fallback function to receive native tokens
/// @dev especially useful for receiving native token swap output in SwapRequest
/// @dev this will be applied to BungeeGateway as a whole
receive() external payable {}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
interface IEIP712 {
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import {IEIP712} from "./IEIP712.sol";
/// @title SignatureTransfer
/// @notice Handles ERC20 token transfers through signature based actions
/// @dev Requires user's token approval on the Permit2 contract
interface ISignatureTransfer is IEIP712 {
/// @notice Thrown when the requested amount for a transfer is larger than the permissioned amount
/// @param maxAmount The maximum amount a spender can request to transfer
error InvalidAmount(uint256 maxAmount);
/// @notice Thrown when the number of tokens permissioned to a spender does not match the number of tokens being transferred
/// @dev If the spender does not need to transfer the number of tokens permitted, the spender can request amount 0 to be transferred
error LengthMismatch();
/// @notice Emits an event when the owner successfully invalidates an unordered nonce.
event UnorderedNonceInvalidation(
address indexed owner,
uint256 word,
uint256 mask
);
/// @notice The token and amount details for a transfer signed in the permit transfer signature
struct TokenPermissions {
// ERC20 token address
address token;
// the maximum amount that can be spent
uint256 amount;
}
/// @notice The signed permit message for a single token transfer
struct PermitTransferFrom {
TokenPermissions permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice Specifies the recipient address and amount for batched transfers.
/// @dev Recipients and amounts correspond to the index of the signed token permissions array.
/// @dev Reverts if the requested amount is greater than the permitted signed amount.
struct SignatureTransferDetails {
// recipient address
address to;
// spender requested amount
uint256 requestedAmount;
}
/// @notice Used to reconstruct the signed permit message for multiple token transfers
/// @dev Do not need to pass in spender address as it is required that it is msg.sender
/// @dev Note that a user still signs over a spender address
struct PermitBatchTransferFrom {
// the tokens and corresponding amounts permitted for a transfer
TokenPermissions[] permitted;
// a unique value for every token owner's signature to prevent signature replays
uint256 nonce;
// deadline on the permit signature
uint256 deadline;
}
/// @notice A map from token owner address and a caller specified word index to a bitmap. Used to set bits in the bitmap to prevent against signature replay protection
/// @dev Uses unordered nonces so that permit messages do not need to be spent in a certain order
/// @dev The mapping is indexed first by the token owner, then by an index specified in the nonce
/// @dev It returns a uint256 bitmap
/// @dev The index, or wordPosition is capped at type(uint248).max
function nonceBitmap(address, uint256) external view returns (uint256);
/// @notice Transfers a token using a signed permit message
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param signature The signature to verify
function permitTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfers a token using a signed permit message
/// @notice Includes extra data provided by the caller to verify signature over
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @dev Reverts if the requested amount is greater than the permitted signed amount
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails The spender's requested transfer details for the permitted token
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitTransferFrom memory permit,
SignatureTransferDetails calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Transfers multiple tokens using a signed permit message
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param signature The signature to verify
function permitTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes calldata signature
) external;
/// @notice Transfers multiple tokens using a signed permit message
/// @dev The witness type string must follow EIP712 ordering of nested structs and must include the TokenPermissions type definition
/// @notice Includes extra data provided by the caller to verify signature over
/// @param permit The permit data signed over by the owner
/// @param owner The owner of the tokens to transfer
/// @param transferDetails Specifies the recipient and requested amount for the token transfer
/// @param witness Extra data to include when checking the user signature
/// @param witnessTypeString The EIP-712 type definition for remaining string stub of the typehash
/// @param signature The signature to verify
function permitWitnessTransferFrom(
PermitBatchTransferFrom memory permit,
SignatureTransferDetails[] calldata transferDetails,
address owner,
bytes32 witness,
string calldata witnessTypeString,
bytes calldata signature
) external;
/// @notice Invalidates the bits specified in mask for the bitmap at the word position
/// @dev The wordPos is maxed at type(uint248).max
/// @param wordPos A number to index the nonceBitmap at
/// @param mask A bitmap masked against msg.sender's current bitmap at the word position
function invalidateUnorderedNonces(uint256 wordPos, uint256 mask) external;
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
/// @notice Modern and gas efficient ERC20 + EIP-2612 implementation.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/tokens/ERC20.sol)
/// @author Modified from Uniswap (https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2ERC20.sol)
/// @dev Do not manually set balances without updating totalSupply, as the sum of all user balances must not exceed it.
abstract contract ERC20 {
/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/
event Transfer(address indexed from, address indexed to, uint256 amount);
event Approval(address indexed owner, address indexed spender, uint256 amount);
/*//////////////////////////////////////////////////////////////
METADATA STORAGE
//////////////////////////////////////////////////////////////*/
string public name;
string public symbol;
uint8 public immutable decimals;
/*//////////////////////////////////////////////////////////////
ERC20 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 public totalSupply;
mapping(address => uint256) public balanceOf;
mapping(address => mapping(address => uint256)) public allowance;
/*//////////////////////////////////////////////////////////////
EIP-2612 STORAGE
//////////////////////////////////////////////////////////////*/
uint256 internal immutable INITIAL_CHAIN_ID;
bytes32 internal immutable INITIAL_DOMAIN_SEPARATOR;
mapping(address => uint256) public nonces;
/*//////////////////////////////////////////////////////////////
CONSTRUCTOR
//////////////////////////////////////////////////////////////*/
constructor(string memory _name, string memory _symbol, uint8 _decimals) {
name = _name;
symbol = _symbol;
decimals = _decimals;
INITIAL_CHAIN_ID = block.chainid;
INITIAL_DOMAIN_SEPARATOR = computeDomainSeparator();
}
/*//////////////////////////////////////////////////////////////
ERC20 LOGIC
//////////////////////////////////////////////////////////////*/
function approve(address spender, uint256 amount) public virtual returns (bool) {
allowance[msg.sender][spender] = amount;
emit Approval(msg.sender, spender, amount);
return true;
}
function transfer(address to, uint256 amount) public virtual returns (bool) {
balanceOf[msg.sender] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(msg.sender, to, amount);
return true;
}
function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {
uint256 allowed = allowance[from][msg.sender]; // Saves gas for limited approvals.
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
balanceOf[from] -= amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(from, to, amount);
return true;
}
/*//////////////////////////////////////////////////////////////
EIP-2612 LOGIC
//////////////////////////////////////////////////////////////*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) public virtual {
require(deadline >= block.timestamp, "PERMIT_DEADLINE_EXPIRED");
// Unchecked because the only math done is incrementing
// the owner's nonce which cannot realistically overflow.
unchecked {
address recoveredAddress = ecrecover(
keccak256(
abi.encodePacked(
"\x19\x01",
DOMAIN_SEPARATOR(),
keccak256(
abi.encode(
keccak256(
"Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"
),
owner,
spender,
value,
nonces[owner]++,
deadline
)
)
)
),
v,
r,
s
);
require(recoveredAddress != address(0) && recoveredAddress == owner, "INVALID_SIGNER");
allowance[recoveredAddress][spender] = value;
}
emit Approval(owner, spender, value);
}
function DOMAIN_SEPARATOR() public view virtual returns (bytes32) {
return block.chainid == INITIAL_CHAIN_ID ? INITIAL_DOMAIN_SEPARATOR : computeDomainSeparator();
}
function computeDomainSeparator() internal view virtual returns (bytes32) {
return
keccak256(
abi.encode(
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
keccak256(bytes(name)),
keccak256("1"),
block.chainid,
address(this)
)
);
}
/*//////////////////////////////////////////////////////////////
INTERNAL MINT/BURN LOGIC
//////////////////////////////////////////////////////////////*/
function _mint(address to, uint256 amount) internal virtual {
totalSupply += amount;
// Cannot overflow because the sum of all user
// balances can't exceed the max uint256 value.
unchecked {
balanceOf[to] += amount;
}
emit Transfer(address(0), to, amount);
}
function _burn(address from, uint256 amount) internal virtual {
balanceOf[from] -= amount;
// Cannot underflow because a user's balance
// will never be larger than the total supply.
unchecked {
totalSupply -= amount;
}
emit Transfer(from, address(0), amount);
}
}// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity >=0.8.0;
import {ERC20} from "../tokens/ERC20.sol";
/// @notice Safe ETH and ERC20 transfer library that gracefully handles missing return values.
/// @author Solmate (https://github.com/transmissions11/solmate/blob/main/src/utils/SafeTransferLib.sol)
/// @dev Use with caution! Some functions in this library knowingly create dirty bits at the destination of the free memory pointer.
/// @dev Note that none of the functions in this library check that a token has code at all! That responsibility is delegated to the caller.
library SafeTransferLib {
/*//////////////////////////////////////////////////////////////
ETH OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferETH(address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Transfer the ETH and store if it succeeded or not.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
require(success, "ETH_TRANSFER_FAILED");
}
/*//////////////////////////////////////////////////////////////
ERC20 OPERATIONS
//////////////////////////////////////////////////////////////*/
function safeTransferFrom(ERC20 token, address from, address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
mstore(add(freeMemoryPointer, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 68), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 100 because the length of our calldata totals up like so: 4 + 32 * 3.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 100, 0, 32)
)
}
require(success, "TRANSFER_FROM_FAILED");
}
function safeTransfer(ERC20 token, address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "TRANSFER_FAILED");
}
function safeApprove(ERC20 token, address to, uint256 amount) internal {
bool success;
/// @solidity memory-safe-assembly
assembly {
// Get a pointer to some free memory.
let freeMemoryPointer := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(freeMemoryPointer, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(freeMemoryPointer, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(freeMemoryPointer, 36), amount) // Append the "amount" argument. Masking not required as it's a full 32 byte type.
success := and(
// Set success to whether the call reverted, if not we check it either
// returned exactly 1 (can't just be non-zero data), or had no return data.
or(and(eq(mload(0), 1), gt(returndatasize(), 31)), iszero(returndatasize())),
// We use 68 because the length of our calldata totals up like so: 4 + 32 * 2.
// We use 0 and 32 to copy up to 32 bytes of return data into the scratch space.
// Counterintuitively, this call must be positioned second to the or() call in the
// surrounding and() call or else returndatasize() will be zero during the computation.
call(gas(), token, 0, freeMemoryPointer, 68, 0, 32)
)
}
require(success, "APPROVE_FAILED");
}
}// SPDX-License-Identifier: MIT pragma solidity ^0.8.17; // error MofaSignatureInvalid(); error InsufficientNativeAmount(); error InvalidMultipleNativeTokens(); error FulfilmentChainInvalid(); error RequestAlreadyFulfilled(); error RouterNotRegistered(); error TransferFailed(); error CallerNotBungeeGateway(); error NoExecutionCacheFound(); error ExecutionCacheFailed(); error SwapOutputInsufficient(); error UnsupportedDestinationChainId(); error MinOutputNotMet(); error OnlyOwner(); error OnlyNominee(); error InvalidRequest(); error FulfilmentDeadlineNotMet(); error CallerNotDelegate(); error BungeeSiblingDoesNotExist(); error InvalidMsg(); error NotDelegate(); error RequestProcessed(); error RequestNotProcessed(); error InvalidSwitchboard(); error PromisedAmountNotMet(); error MsgReceiveFailed(); error RouterAlreadyWhitelisted(); error InvalidStake(); error RouterAlreadyRegistered(); error InvalidFulfil(); error InsufficientCapacity(); error ReleaseFundsNotImplemented();
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract BungeeEvents {
/// @notice Emitted when a request is extracted
/// @param requestHash hash of the request
/// @param transmitter address of the transmitter
/// @param execution encoded execution data
event RequestExtracted(bytes32 indexed requestHash, uint8 implId, address transmitter, bytes execution);
/// @notice Emitted when a request is fulfilled
/// @param requestHash hash of the request
/// @param fulfiller address of the fulfiller
/// @param execution encoded execution data
event RequestFulfilled(bytes32 indexed requestHash, uint8 implId, address fulfiller, bytes execution);
// emitted on the source once settlement completes
/// @param requestHash hash of the request
event RequestSettled(bytes32 indexed requestHash);
// emitted on the destination once settlement completes
event RequestsSettledOnDestination(
bytes32[] requestHashes,
uint8 implId,
address transmitter,
uint256 outboundFees
);
/// @notice Emitted on the originChain when a request is withdrawn beyond fulfilment deadline
/// @param requestHash hash of the request
/// @param token token being withdrawn
/// @param amount amount being withdrawn
/// @param to address of the recipient
event WithdrawOnOrigin(bytes32 indexed requestHash, address token, uint256 amount, address to);
/// @notice Emitted on the destinationChain when a request is withdrawn if transmitter fails to fulfil
/// @param requestHash hash of the request
/// @param token token being withdrawn
/// @param amount amount being withdrawn
/// @param to address of the recipient
event WithdrawOnDestination(bytes32 indexed requestHash, address token, uint256 amount, address to);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
// Basic details in the request
struct BasicRequest {
// src chain id
uint256 originChainId;
// dest chain id
uint256 destinationChainId;
// deadline of the request
uint256 deadline;
// nonce used for uniqueness in signature
uint256 nonce;
// address of the user placing the request.
address sender;
// address of the receiver on destination chain
address receiver;
// delegate address that has some rights over the request signed
address delegate;
// address of bungee gateway, this address will have access to pull funds from the sender.
address bungeeGateway;
// id of the switchboard
uint32 switchboardId;
// address of the input token
address inputToken;
// amount of the input tokens
uint256 inputAmount;
// output token to be received on the destination.
address outputToken;
// minimum amount to be receive on the destination for the output token.
uint256 minOutputAmount;
// native token refuel amount on the destination chain
uint256 refuelAmount;
}
// The Request which user signs
struct Request {
// basic details in the request.
BasicRequest basicReq;
// swap output token that the user is okay with swapping input token to.
address swapOutputToken;
// minimum swap output the user is okay with swapping the input token to.
// Transmitter can choose or not choose to swap tokens.
uint256 minSwapOutput;
// any sort of metadata to be passed with the request
bytes32 metadata;
// fees of the affiliate if any
bytes affiliateFees;
}
// Transmitter's origin chain execution details for a request with promisedAmounts.
struct ExtractExec {
// User signed Request
Request request;
// address of the router being used for the request.
address router;
// promised amount for output token on the destination
uint256 promisedAmount;
// promised amount for native token refuel on the destination
uint256 promisedRefuelAmount;
// RouterPayload (router specific data) + RouterValue (value required by the router) etc etc
bytes routerData;
// swapPayload 0x00 if no swap is involved.
bytes swapPayload;
// swapRouterAddress
address swapRouter;
// user signature against the request
bytes userSignature;
// address of the beneficiary submitted by the transmitter.
// the beneficiary will be the one receiving locked tokens when a request is settled.
address beneficiary;
}
// Transmitter's destination chain execution details with fulfil amounts.
struct FulfilExec {
// User Signed Request
Request request;
// address of the router
address fulfilRouter;
// amount to be sent to the receiver for output token.
uint256 fulfilAmount;
// amount to be sent to the receiver for native token refuel.
uint256 refuelFulfilAmount;
// extraPayload for router.
bytes routerData;
// total msg.value to be sent to fulfil native token output token
uint256 msgValue;
}
struct ExtractedRequest {
uint256 expiry;
address router;
address sender;
address delegate;
uint32 switchboardId;
address token;
address transmitter; // For stake capacity
address beneficiary; // For Transmitter
uint256 amount;
uint256 promisedAmount; // For Transmitter
uint256 promisedRefuelAmount;
bytes affiliateFees; // For integrator
}
struct FulfilledRequest {
uint256 fulfilledAmount;
uint256 fulfilledRefuelAmount;
bool processed;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
// Basic details in the request
struct BasicRequest {
// chain id
uint256 chainId;
// deadline of the request
uint256 deadline;
// nonce used for uniqueness in signature
uint256 nonce;
// address of the user placing the request.
address sender;
// address of the receiver on destination chain
address receiver;
// address of bungee gateway, this address will have access to pull funds from the sender.
address bungeeGateway;
// address of the input token
address inputToken;
// amount of the input tokens
uint256 inputAmount;
// array of output tokens to be received on the destination.
address[] outputTokens;
// array of minimum amounts to be receive on the destination for the output tokens array.
uint256[] minOutputAmounts;
}
// The Request which user signs
struct Request {
// basic details in the request.
BasicRequest basicReq;
// array of addresses to check if request whitelists only certain transmitters
address[] exclusiveTransmitters;
// any sort of metadata to be passed with the request
bytes32 metadata;
// fees of the affiliate if any
bytes affiliateFees;
// calldata execution parameter. Only to be used when execution is required on destination.
// minimum dest gas limit to execute calldata on destination
uint256 minDestGas;
// calldata to be executed on the destination
// calldata can only be executed on the receiver in the request.
bytes destinationPayload;
}
// Transmitter's origin chain execution details for a request with fulfilAmounts.
struct SwapExec {
// User signed Request
Request request;
// array of fulfil amounts for the corresponding output tokens on the destination
uint256[] fulfilAmounts;
// swapPayload 0x00 if no swap is involved.
bytes swapPayload;
// swapRouterAddress
address swapRouter;
// user signature against the request
bytes userSignature;
// address of the beneficiary submitted by the transmitter.
// the beneficiary will be the one receiving locked tokens when a request is settled.
address beneficiary;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {ERC20, SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {IBaseRouter} from "../interfaces/IBaseRouter.sol";
import {ISwapExecutor} from "../interfaces/ISwapExecutor.sol";
import {ICalldataExecutor} from "../interfaces/ICalldataExecutor.sol";
import {ISwitchboardRouter} from "../interfaces/ISwitchboardRouter.sol";
import {IStakeVault} from "../interfaces/IStakeVault.sol";
import {IFeeCollector} from "../interfaces/IFeeCollector.sol";
import {
RouterAlreadyWhitelisted,
RouterAlreadyRegistered,
TransferFailed,
InvalidStake,
InsufficientCapacity,
InvalidMsg
} from "../common/BungeeErrors.sol";
import {BungeeGatewayStorage} from "./BungeeGatewayStorage.sol";
// @todo should this be renamed to ImplBase. These are implemented by all Impls, not BungeeGateway, but actually acts on BungeeGatewayStorage
abstract contract BungeeGatewayBase is BungeeGatewayStorage {
using SafeTransferLib for ERC20;
/*//////////////////////////////////////////////////////////////////////////
ADMIN FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/**
* @notice send funds to the provided address if stuck, can be called only by owner.
* @param token address of the token
* @param amount hash of the command.
* @param to address, funds will be transferred to this address.
*/
function rescue(address token, address to, uint256 amount) external onlyOwner {
_sendFundsFromContract(token, amount, to);
}
/**
* @notice sets the new mofa signer address.
Can only be called by the owner.
* @param _mofaSigner address of the new mofa signer.
*/
function setMofaSigner(address _mofaSigner) external onlyOwner {
MOFA_SIGNER = _mofaSigner;
}
/**
* @notice sets the new switchboard router.
Can only be called by the owner.
* @param _switchboardRouter address of the new switchboard router.
*/
function setSwitchboardRouter(address _switchboardRouter) external onlyOwner {
SWITCHBOARD_ROUTER = ISwitchboardRouter(_switchboardRouter);
}
/**
* @notice sets the new fee collector.
Can only be called by the owner.
* @param _feeCollector address of the new switchboard router.
*/
function setFeeCollector(address _feeCollector) external onlyOwner {
FEE_COLLECTOR = IFeeCollector(_feeCollector);
}
/**
* @notice sets the new expiry buffer.
Can only be called by the owner.
* @param _expiryBuffer expiry buffer for the request fulfilment deadline.
*/
function setExpiryBuffer(uint256 _expiryBuffer) external onlyOwner {
EXPIRY_BUFFER = _expiryBuffer;
}
/**
* @notice sets the new swap executor contract.
Can only be called by the owner.
* @param _swapExecutor address of the new swap executor.
*/
function setSwapExecutor(address _swapExecutor) external onlyOwner {
SWAP_EXECUTOR = ISwapExecutor(_swapExecutor);
}
/**
* @notice sets the new calldata executor contract.
Can only be called by the owner.
* @param _calldataExecutor address of the new calldata executor.
*/
function setCalldataExecutor(address _calldataExecutor) external onlyOwner {
CALLDATA_EXECUTOR = ICalldataExecutor(_calldataExecutor);
}
/**
* @notice sets the new StakeVault contract.
Can only be called by the owner.
* @param _stakeVault address of the new calldata executor.
*/
function setStakeVault(address _stakeVault) external onlyOwner {
STAKE_VAULT = IStakeVault(_stakeVault);
}
/// @notice register a whitelisted router
function registerWhitelistedRouter(address whitelistedRouter) external onlyOwner {
if (isWhitelisted[whitelistedRouter]) revert RouterAlreadyWhitelisted();
if (bungeeRouters[whitelistedRouter]) revert RouterAlreadyRegistered();
isWhitelisted[whitelistedRouter] = true;
_addBungeeRouter(whitelistedRouter);
}
/// @notice register a staked router
function registerStakedRouter(address stakedRouter) external onlyOwner {
if (bungeeRouters[stakedRouter]) revert RouterAlreadyRegistered();
_addBungeeRouter(stakedRouter);
}
/// @notice Adds a new router to the protocol
function _addBungeeRouter(address _bungeeRouter) internal {
bungeeRouters[_bungeeRouter] = true;
}
function isBungeeRouter(address router) public view returns (bool) {
return bungeeRouters[router];
}
/**
* @notice adds the new whitelisted receiver address against a router.
Can only be called by the owner.
* @param receiver address of the new whitelisted receiver contract.
* @param destinationChainId destination chain id where the receiver will exist.
* @param router router address from which the funs will be routed from.
*/
function setWhitelistedReceiver(address receiver, uint256 destinationChainId, address router) external onlyOwner {
whitelistedReceivers[router][destinationChainId] = receiver;
}
/**
* @notice gets the receiver address set for the router on the destination chain.
* @param destinationChainId destination chain id where the receiver will exist.
* @param router router address from which the funds will be routed from.
*/
function getWhitelistedReceiver(address router, uint256 destinationChainId) external view returns (address) {
return whitelistedReceivers[router][destinationChainId];
}
/**
* @notice Transmitter can register and increment their stake against a token
* @dev Transmitter would transfer their tokens for the stake
*/
function registerTransmitterStake(address token, uint256 capacity) external payable {
transmitterCapacity[msg.sender][token] = transmitterCapacity[msg.sender][token] + capacity;
if (token == NATIVE_TOKEN_ADDRESS) {
if (msg.value != capacity) revert InvalidStake();
(bool success, ) = address(STAKE_VAULT).call{value: capacity, gas: 5000}("");
if (!success) revert TransferFailed();
} else {
ERC20(token).safeTransferFrom(msg.sender, address(STAKE_VAULT), capacity);
}
}
/**
* @notice Transmitter can withdraw their stake against a token
* @dev Transmitter would receive their tokens back
* @dev Transmitter's capacity would be reduced
*/
function withdrawTransmitterStake(address token, uint256 capacity) external {
transmitterCapacity[msg.sender][token] = transmitterCapacity[msg.sender][token] - capacity;
STAKE_VAULT.withdrawStake(token, capacity, msg.sender);
}
function withdrawBeneficiarySettlement(address beneficiary, address router, address token) external {
uint256 amount = beneficiarySettlements[beneficiary][router][token];
if (amount > 0) {
beneficiarySettlements[beneficiary][router][token] = 0;
// Transfer the tokens to the beneficiary
IBaseRouter(router).releaseFunds(token, amount, beneficiary);
}
}
/**
* @notice extract the user requests and routes it via the respetive routers.
* @notice the user requests can only be extracted if the mofa signature is valid.
* @notice each request can be routed via a different router.
* @dev if the switchboard id is not same as the user request, it will revert.
* @dev if the fulfilled amounts is not equal to or greater than the promised amount, revert.
* @dev mark the extracted hash deleted.
* @param payload msg payload sent.
*/
function receiveMsg(bytes calldata payload) external payable {
// If the msg sender is not switchboard router, revert.
if (msg.sender != address(SWITCHBOARD_ROUTER)) revert InvalidMsg();
_receiveMsg(payload);
}
function _receiveMsg(bytes calldata payload) internal virtual {}
/// @notice check capacity for a whitelisted router or staked transmitter
/// @dev if the router is whitelisted, it has a max capacity
/// @dev if the router is not whitelisted, return registered transmitter capacity
function checkCapacity(address transmitter, address token) public view returns (uint256) {
return transmitterCapacity[transmitter][token];
}
function _increaseCapacity(address transmitter, address token, uint256 increaseBy) internal {
transmitterCapacity[transmitter][token] = transmitterCapacity[transmitter][token] + increaseBy;
}
function _reduceCapacity(address transmitter, address token, uint256 reduceBy) internal {
transmitterCapacity[transmitter][token] = transmitterCapacity[transmitter][token] - reduceBy;
}
function _validateAndReduceStake(uint256 inputAmount, address inputToken) internal {
// check capacity before extraction
if (checkCapacity(msg.sender, inputToken) < inputAmount) revert InsufficientCapacity();
_reduceCapacity(msg.sender, inputToken, inputAmount);
}
/**
* @dev send funds to the provided address.
* @param token address of the token
* @param amount hash of the command.
* @param to address, funds will be transferred to this address.
*/
function _sendFundsFromContract(address token, uint256 amount, address to) internal {
/// native token case
if (token == NATIVE_TOKEN_ADDRESS) {
(bool success, ) = to.call{value: amount, gas: 5000}("");
if (!success) revert TransferFailed();
return;
}
/// ERC20 case
ERC20(token).safeTransfer(to, amount);
}
/**
* @dev send funds from an address to the provided address.
* @param token address of the token
* @param from atomic execution.
* @param amount hash of the command.
* @param to address, funds will be transferred to this address.
*/
function _sendFundsToReceiver(address token, address from, uint256 amount, address to) internal {
/// native token case
if (token == NATIVE_TOKEN_ADDRESS) {
(bool success, ) = to.call{value: amount, gas: 5000}("");
if (!success) revert TransferFailed();
return;
}
/// ERC20 case
ERC20(token).safeTransferFrom(from, to, amount);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
import {Ownable} from "../utils/Ownable.sol";
import {ISwapExecutor} from "../interfaces/ISwapExecutor.sol";
import {ICalldataExecutor} from "../interfaces/ICalldataExecutor.sol";
import {ISwitchboardRouter} from "../interfaces/ISwitchboardRouter.sol";
import {IStakeVault} from "../interfaces/IStakeVault.sol";
import {IFeeCollector} from "../interfaces/IFeeCollector.sol";
// SingleOutputRequest
import {
Request as SingleOutputRequest,
ExtractExec as SingleOutputExtractExec,
ExtractedRequest as SingleOutputExtractedRequest,
FulfilledRequest as SingleOutputFulfilledRequest
} from "../common/SingleOutputStructs.sol";
import {RequestLib as SingleOutputRequestLib} from "../lib/SingleOutputRequestLib.sol";
abstract contract BungeeGatewayStorage is Ownable {
using SingleOutputRequestLib for SingleOutputRequest;
using SingleOutputRequestLib for SingleOutputExtractExec;
/// @dev the maximum capacity for whitelisted routers
uint256 internal constant WHITELISTED_MAX_CAPACITY = type(uint256).max;
/// @dev address used to identify native token
address public constant NATIVE_TOKEN_ADDRESS = address(0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE);
/// @dev id used to identify single output implementation
uint8 public constant SINGLE_OUTPUT_IMPL_ID = 1;
/// @dev id used to identify swap request implementation
uint8 public constant SWAP_REQUEST_IMPL_ID = 2;
/// @notice address of the permit 2 contract
ISignatureTransfer public immutable PERMIT2;
/// @notice address of the protocol signer
/// @dev this address signs on the request batch that transmitter submits to the protocol.
address public MOFA_SIGNER;
/// @notice address of the SwitchboardRouter
/// @dev BungeeGateway uses this contract to handle cross-chain messages via Socket
ISwitchboardRouter public SWITCHBOARD_ROUTER;
/// @notice address of the SwapExecutor
/// @dev BungeeGateway delegates swap executions to this contract.
ISwapExecutor public SWAP_EXECUTOR;
/// @notice address of the CalldataExecutor
/// @dev BungeeGateway delegates calldata execution at destination chain to this contract.
ICalldataExecutor public CALLDATA_EXECUTOR;
/// @notice address of the FeeCollector
/// @dev BungeeGateway collects fees from the users and transfers them to this contract.
IFeeCollector public FEE_COLLECTOR;
/// @notice address of the StakeVault
/// @dev BungeeGateway transfers all stake to StakeVault
/// @dev BungeeGateway triggers StakeVault to release stake funds
IStakeVault public STAKE_VAULT;
/// @notice this is the buffer time for expiry of any new request
uint256 public EXPIRY_BUFFER;
/// @notice this holds all the requests that have been fulfilled.
mapping(bytes32 requestHash => SingleOutputFulfilledRequest request) internal singleOutputFulfilledRequests;
/// @notice this holds all the requests that have been extracted.
mapping(bytes32 requestHash => SingleOutputExtractedRequest request) internal singleOutputExtractedRequests;
/// @notice this mapping holds all the receiver contracts, these contracts will receive funds.
/// @dev bridged funds would reach receiver contracts first and then transmitter uses these funds to fulfil order.
mapping(address router => mapping(uint256 toChainId => address whitelistedReceiver)) internal whitelistedReceivers;
/// @notice this mapping holds all the addresses that are routers.
/// @dev bungee sends funds from the users to these routers on the origin chain.
/// @dev bungee calls these when fulfilment happens on the destination.
mapping(address routers => bool supported) internal bungeeRouters;
/// @dev this holds all the routers that are whitelisted.
mapping(address router => bool whitelisted) public isWhitelisted;
/// @notice this mapping holds capacity for a transmitter
/// @dev token is checked against the inputToken or swapOutputToken of the request
mapping(address transmitter => mapping(address token => uint256 capacity)) public transmitterCapacity;
/// @notice this mapping stores orders that have been withdrawn on the originChain after Request expiry
/// @dev Requests are deleted from the extractedRequests mapping when withdrawn on the origin chain
/// @dev This mapping stores the withdrawn requests for external contracts to track
mapping(bytes32 requestHash => bool withdrawn) public withdrawnRequests;
/// @notice this mapping stores the settlement amounts for the beneficiaries
/// @dev not all routers would have settlement, so these amounts may not be cleared for some routers
mapping(address beneficiary => mapping(address router => mapping(address token => uint256 amount)))
public beneficiarySettlements;
/**
* @notice Constructor.
* @dev Defines all immutable variables & owner
* @param _owner owner of the contract.
* @param _permit2 address of the permit 2 contract.
*/
constructor(address _owner, address _permit2) Ownable(_owner) {
PERMIT2 = ISignatureTransfer(_permit2);
}
/*//////////////////////////////////////////////////////////////////////////
GETTERS
//////////////////////////////////////////////////////////////////////////*/
function getSingleOutputExtractedRequest(
bytes32 requestHash
) external view returns (SingleOutputExtractedRequest memory) {
return singleOutputExtractedRequests[requestHash];
}
function getSingleOutputFulfilledRequest(
bytes32 requestHash
) external view returns (SingleOutputFulfilledRequest memory) {
return singleOutputFulfilledRequests[requestHash];
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {IBaseRouterSingleOutput as IBaseRouter} from "../interfaces/IBaseRouterSingleOutput.sol";
import {AuthenticationLib} from "../lib/AuthenticationLib.sol";
import {AffiliateFeesLib} from "../lib/AffiliateFeesLib.sol";
import {
InsufficientNativeAmount,
MofaSignatureInvalid,
RouterNotRegistered,
MinOutputNotMet,
InvalidRequest,
InvalidMsg,
FulfilmentDeadlineNotMet,
SwapOutputInsufficient,
NotDelegate,
RequestProcessed,
InvalidSwitchboard,
InvalidRequest,
PromisedAmountNotMet,
RequestNotProcessed
} from "../common/BungeeErrors.sol";
import {Permit2Lib} from "../lib/Permit2Lib.sol";
import {BungeeEvents} from "../common/BungeeEvents.sol";
import {ERC20, SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {RequestLib} from "../lib/SingleOutputRequestLib.sol";
import {Request, FulfilExec, ExtractExec, ExtractedRequest, FulfilledRequest} from "../common/SingleOutputStructs.sol";
import {BungeeGatewayBase} from "./BungeeGatewayBase.sol";
import {BungeeGatewayStorage} from "./BungeeGatewayStorage.sol";
contract SingleOutputRequestImpl is BungeeGatewayStorage, BungeeGatewayBase, BungeeEvents {
using RequestLib for Request;
using RequestLib for ExtractExec[];
using SafeTransferLib for ERC20;
constructor(address _owner, address _permit2) BungeeGatewayStorage(_owner, _permit2) {}
/*//////////////////////////////////////////////////////////////////////////
SOURCE FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/**
* @notice extract the user requests and routes it via the respetive routers.
* @notice the user requests can only be extracted if the mofa signature is valid.
* @notice each request can be routed via a different router.
* @notice it would be assumed as a successful execution if the router call does not revert.
* @dev state of the request would be saved against the requesthash created.
* @dev funds from the user wallet will be pulled and sent to the router.
* @dev if there is a swap involved then swapped funds would reach the router.
* @param extractExecs batch of extractions submitted by the transmitter.
* @param mofaSignature signature of mofa on the batch.
*/
function extractRequests(ExtractExec[] calldata extractExecs, bytes calldata mofaSignature) external {
// Checks if batch has been authorised by MOFA
_checkMofaSig(extractExecs, mofaSignature);
// Iterate through extractExec
unchecked {
for (uint256 i = 0; i < extractExecs.length; i++) {
// Check if the promised amount is more than the minOutputAmount
if (
// check output amount
(extractExecs[i].promisedAmount < extractExecs[i].request.basicReq.minOutputAmount) ||
// check refuel amount
(extractExecs[i].promisedRefuelAmount < extractExecs[i].request.basicReq.refuelAmount)
) revert MinOutputNotMet();
// If a swap is involved the router would receive the swap output tokens specified in request.
// If no swap is involved the router would receive the input tokens specified in request.
if (extractExecs[i].swapPayload.length > 0) {
_swapAndCallRouter(extractExecs[i]);
} else {
_callRouter(extractExecs[i]);
}
}
}
}
/**
* @notice extract the user requests and routes it via the respetive routers.
* @notice the user requests can only be extracted if the mofa signature is valid.
* @notice each request can be routed via a different router.
* @dev if the switchboard id is not same as the user request, it will revert.
* @dev if the fulfilled amounts is not equal to or greater than the promised amount, revert.
* @dev mark the extracted hash deleted.
* @param payload msg payload sent.
*/
function _receiveMsg(bytes calldata payload) internal override {
uint32 switchboardId = uint32(bytes4(payload));
/// @dev fulfilledAmounts would be output token fulfilled for each request in the batch. hence a 1d array
(
bytes32[] memory requestHashes,
uint256[] memory fulfilledAmounts,
uint256[] memory fulfilledRefuelAmounts
) = abi.decode(payload[4:], (bytes32[], uint256[], uint256[]));
unchecked {
for (uint256 i = 0; i < requestHashes.length; i++) {
_validateAndReleaseSettleRequests(
switchboardId,
requestHashes[i],
fulfilledAmounts[i],
fulfilledRefuelAmounts[i]
);
}
}
}
/*//////////////////////////////////////////////////////////////////////////
INTERNAL SOURCE FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/**
* @notice checks if the mofa signature is valid on the batch submitted by the transmitter.
* @param extractExecs batch of extractions submitted by the transmitter.
* @param mofaSignature signature of mofa on the batch.
*/
function _checkMofaSig(ExtractExec[] calldata extractExecs, bytes memory mofaSignature) internal view {
// Create the hash of BatchHash
bytes32 batchHash = extractExecs.hashOriginBatch();
// Get the signer
address signer = AuthenticationLib.authenticate(batchHash, mofaSignature);
// Check if addresses match
if (signer != MOFA_SIGNER) revert MofaSignatureInvalid();
}
/**
* @notice this function is used when the transmitter submits a swap for a user request.
* @notice assumption is that the receiver of the swap will be the router mentioned in the exec.
* @dev Funds would be transferred to the swap executor first.
* @dev Swap executor will be called with the swap payload.
* @dev Funds after the swap should reach the router.
* @dev If the swap does not give back enough, revert.
* @dev If all is good, the router will be called with relevant details.
* @dev Saves the extraction details against the requestHash.
* @param extractExec execution submitted by the transmitter for the request.
When a request is settled beneficiary will receive funds.
*/
function _swapAndCallRouter(ExtractExec memory extractExec) internal {
// Create the request hash for the submitted request.
bytes32 requestHash = extractExec.request.hashOriginRequest();
bool isNativeToken = extractExec.request.swapOutputToken == NATIVE_TOKEN_ADDRESS;
// Get the initial balance of the router for the swap output token
uint256 initialBalance = isNativeToken
? extractExec.router.balance
: ERC20(extractExec.request.swapOutputToken).balanceOf(extractExec.router);
// Calls Permit2 to transfer funds from user to swap executor.
PERMIT2.permitWitnessTransferFrom(
Permit2Lib.toPermit(
extractExec.request.basicReq.inputToken,
extractExec.request.basicReq.inputAmount,
extractExec.request.basicReq.nonce,
extractExec.request.basicReq.deadline
),
/// @dev transfer tokens to SwapExecutor
Permit2Lib.transferDetails(extractExec.request.basicReq.inputAmount, address(SWAP_EXECUTOR)),
extractExec.request.basicReq.sender,
requestHash,
RequestLib.PERMIT2_ORDER_TYPE,
extractExec.userSignature
);
// Call the swap executor to execute the swap.
/// @dev swap output tokens are expected to be sent to the router
SWAP_EXECUTOR.executeSwap(
extractExec.request.basicReq.inputToken,
extractExec.request.basicReq.inputAmount,
extractExec.swapRouter,
extractExec.swapPayload
);
// Get the final balance of the swap output token on the router
uint256 swappedAmount = isNativeToken
? extractExec.router.balance - initialBalance
: ERC20(extractExec.request.swapOutputToken).balanceOf(extractExec.router) - initialBalance;
// Check if the minimum swap output is sufficed after the swap. If not revert.
if (swappedAmount < extractExec.request.minSwapOutput) revert SwapOutputInsufficient();
if (!isWhitelisted[extractExec.router]) {
_validateAndReduceStake(swappedAmount, extractExec.request.swapOutputToken);
}
uint256 expiry = block.timestamp + EXPIRY_BUFFER;
// Call the router with relevant details
IBaseRouter(extractExec.router).execute(
swappedAmount,
extractExec.request.swapOutputToken,
requestHash,
expiry,
whitelistedReceivers[extractExec.router][extractExec.request.basicReq.destinationChainId],
address(FEE_COLLECTOR),
extractExec
);
// Save the extraction details
singleOutputExtractedRequests[requestHash] = ExtractedRequest({
expiry: expiry,
router: extractExec.router,
sender: extractExec.request.basicReq.sender,
delegate: extractExec.request.basicReq.delegate,
switchboardId: extractExec.request.basicReq.switchboardId,
token: extractExec.request.swapOutputToken,
amount: swappedAmount,
affiliateFees: extractExec.request.affiliateFees,
transmitter: msg.sender,
beneficiary: extractExec.beneficiary,
promisedAmount: extractExec.promisedAmount,
promisedRefuelAmount: extractExec.promisedRefuelAmount
});
// Emits Extraction Event
emit RequestExtracted(requestHash, SINGLE_OUTPUT_IMPL_ID, msg.sender, abi.encode(extractExec));
}
/**
* @notice this function is used when the transmitter submits a request that does not involve a swap.
* @dev funds would be transferred to the router directly from the user.
* @dev Saves the extraction details against the requestHash.
* @param extractExec execution submitted by the transmitter for the request.
When a request is settled beneficiary will receive funds.
*/
function _callRouter(ExtractExec memory extractExec) internal {
// If not whitelisted, valiate if the router is part of the protocol and reduce transmitter stake
if (!isWhitelisted[extractExec.router]) {
_validateAndReduceStake(extractExec.request.basicReq.inputAmount, extractExec.request.basicReq.inputToken);
}
// Create the request hash for the submitted request.
bytes32 requestHash = extractExec.request.hashOriginRequest();
// Calls Permit2 to transfer funds from user to the router.
PERMIT2.permitWitnessTransferFrom(
Permit2Lib.toPermit(
extractExec.request.basicReq.inputToken,
extractExec.request.basicReq.inputAmount,
extractExec.request.basicReq.nonce,
extractExec.request.basicReq.deadline
),
Permit2Lib.transferDetails(extractExec.request.basicReq.inputAmount, extractExec.router),
extractExec.request.basicReq.sender,
requestHash,
RequestLib.PERMIT2_ORDER_TYPE,
extractExec.userSignature
);
uint256 expiry = block.timestamp + EXPIRY_BUFFER;
// Call the router with relevant details
IBaseRouter(extractExec.router).execute(
extractExec.request.basicReq.inputAmount,
extractExec.request.basicReq.inputToken,
requestHash,
expiry,
whitelistedReceivers[extractExec.router][extractExec.request.basicReq.destinationChainId],
address(FEE_COLLECTOR),
extractExec
);
// Save the extraction details
singleOutputExtractedRequests[requestHash] = ExtractedRequest({
expiry: expiry,
router: extractExec.router,
sender: extractExec.request.basicReq.sender,
delegate: extractExec.request.basicReq.delegate,
switchboardId: extractExec.request.basicReq.switchboardId,
token: extractExec.request.basicReq.inputToken,
amount: extractExec.request.basicReq.inputAmount,
affiliateFees: extractExec.request.affiliateFees,
transmitter: msg.sender,
beneficiary: extractExec.beneficiary,
promisedAmount: extractExec.promisedAmount,
promisedRefuelAmount: extractExec.promisedRefuelAmount
});
// Emits Extraction Event
emit RequestExtracted(requestHash, SINGLE_OUTPUT_IMPL_ID, msg.sender, abi.encode(extractExec));
}
/**
* @notice validates the settlement details against the request.
* @param switchboardId id of the switchboard that received the msg.
* @param requestHash hash of the request that needs to be settled.
* @param fulfilledAmount amount sent to the receiver on the destination.
*/
function _validateAndReleaseSettleRequests(
uint32 switchboardId,
bytes32 requestHash,
uint256 fulfilledAmount,
uint256 fulfilledRefuelAmount
) internal {
// Check if the extraction exists and the switchboard id is correct.
ExtractedRequest memory eReq = singleOutputExtractedRequests[requestHash];
// Check if the request is valid.
// Check if request has already been settled.
if (eReq.sender == address(0)) revert InvalidRequest();
if (eReq.switchboardId != switchboardId) revert InvalidSwitchboard();
// Check if the fulfilment was done correctly.
// Check if the request was fulfilled: output token & refuel amount
if ((eReq.promisedAmount > fulfilledAmount) || (eReq.promisedRefuelAmount > fulfilledRefuelAmount))
revert PromisedAmountNotMet();
// Get the beneficiary amount to settle the request.
// Checks if there was affiliate fees involved.
uint256 beneficiaryAmount = AffiliateFeesLib.getAmountAfterFee(eReq.amount, eReq.affiliateFees);
if (isWhitelisted[eReq.router]) {
// Settle Fee.
if (eReq.amount > beneficiaryAmount) {
FEE_COLLECTOR.settleFee(requestHash);
}
// track the amount to be settled
beneficiarySettlements[eReq.beneficiary][eReq.router][eReq.token] += beneficiaryAmount;
} else {
// replenish transmitter stake by input amount
_increaseCapacity(eReq.transmitter, eReq.token, eReq.amount);
}
// Delete the origin execution.
delete singleOutputExtractedRequests[requestHash];
// Emits Settlement event
emit RequestSettled(requestHash);
}
/**
* @notice this function can be called by user on source chain to revoke order after fulfil deadline has passed
* @dev Asks router to send back escrowed funds to commander in case of RFQ.
* @dev Slash the stake from the transmitter to pay back to the user.
* @dev Funds routed via whitelisted routers cannot be withdrawn on source. Withdraw on destination can be done for whitelisted routes.
* @param requestHash hash of the request
*/
function withdrawRequestOnOrigin(bytes32 requestHash) external {
ExtractedRequest memory eReq = singleOutputExtractedRequests[requestHash];
// Check if the request is valid.
if (eReq.sender == address(0)) revert InvalidRequest();
// Checks deadline of request fulfilment and if its exceeded,
if (block.timestamp < eReq.expiry) revert FulfilmentDeadlineNotMet();
if (isWhitelisted[eReq.router]) {
// Checks if there was affiliate fees involved.
uint256 routerAmount = AffiliateFeesLib.getAmountAfterFee(eReq.amount, eReq.affiliateFees);
FEE_COLLECTOR.refundFee(requestHash, eReq.sender);
// Ask router to transfer funds back to the user
IBaseRouter(eReq.router).releaseFunds(eReq.token, routerAmount, eReq.sender);
} else {
// Withdraw transmitter stake and give back to the user.
/// @dev transmitter capacity would already be reduced when the request was extracted
/// no need to change the capacity any way then
STAKE_VAULT.withdrawStake(eReq.token, eReq.amount, eReq.sender);
}
// Emits Withdraw event
emit WithdrawOnOrigin(requestHash, eReq.token, eReq.amount, eReq.sender);
// Stores WithdrawnRequest
withdrawnRequests[requestHash] = true;
// Delete the origin execution
delete singleOutputExtractedRequests[requestHash];
}
/*//////////////////////////////////////////////////////////////////////////
DESTINATION FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/**
* @notice Performs fulfilment of a batch of requests
* @dev Called by transmitter to fulfil a request
* @dev Calculates and tracks destination hash of fulfilled requests
* @dev Can fulfil a batch of requests
* @dev Checks if provided router contract is registered with Bungee protocol
* @param fulfilExecs Array of FulfilExec
*/
function fulfilRequests(FulfilExec[] calldata fulfilExecs) external payable {
// Will be used to check if the msg value was sufficient at the end.
uint256 nativeAmount = 0;
// Iterate through the array of fulfil execs.
for (uint256 i = 0; i < fulfilExecs.length; i++) {
FulfilExec memory fulfilExec = fulfilExecs[i];
// Calculate the request hash. Being tracked on singleOutputFulfilledRequests
bytes32 requestHash = fulfilExec.request.hashDestinationRequest();
// 1.a Check if the command is already fulfilled / cancelled
if (singleOutputFulfilledRequests[requestHash].processed) revert RequestProcessed();
// 1.c Check if the provided router address is part of the Bungee protocol
if (!isBungeeRouter(fulfilExec.fulfilRouter)) revert RouterNotRegistered();
// 1.d Check if promisedOutput amounts are more than minOutput amounts
if (
// check output amount
(fulfilExec.fulfilAmount < fulfilExec.request.basicReq.minOutputAmount) ||
// check refuel amount
(fulfilExec.refuelFulfilAmount < fulfilExec.request.basicReq.refuelAmount)
) revert MinOutputNotMet();
// 2. Call the fulfil function on the router
IBaseRouter(fulfilExec.fulfilRouter).fulfil{value: fulfilExec.msgValue}(
requestHash,
fulfilExec,
msg.sender
);
nativeAmount += fulfilExec.msgValue;
// 4. BungeeGateway stores order hash and its outputToken, promisedOutput
singleOutputFulfilledRequests[requestHash] = FulfilledRequest({
fulfilledAmount: fulfilExec.fulfilAmount,
fulfilledRefuelAmount: fulfilExec.refuelFulfilAmount,
processed: true
});
// Emits Fulfilment Event
emit RequestFulfilled(requestHash, SINGLE_OUTPUT_IMPL_ID, msg.sender, abi.encode(fulfilExec));
}
if (msg.value < nativeAmount) revert InsufficientNativeAmount();
}
/**
* @notice Sends a settlement message back towards source to settle the requests.
* @param requestHashes Array of request hashes to be settled.
* @param gasLimit Gas limit to be used on the message receiving chain.
* @param chainSlug Chain slug used in Socket to send the message towards i.e, source chain id
* @param switchboardId id of the switchboard to use. switchboardIds of all requests in the batch must match
*/
function settleRequests(
bytes32[] calldata requestHashes,
uint256 gasLimit,
uint32 chainSlug,
uint32 switchboardId
) external payable {
// Create an empty array of fulfilled amounts.
/// @dev fulfilledAmounts would be output token fulfilled for each request in the batch. hence a 1d array
uint256[] memory fulfilledAmounts = new uint256[](requestHashes.length);
uint256[] memory fulfilledRefuelAmounts = new uint256[](requestHashes.length);
// Loop through the requestHashes and set fulfilled amounts
unchecked {
for (uint256 i = 0; i < requestHashes.length; i++) {
FulfilledRequest memory fReq = singleOutputFulfilledRequests[requestHashes[i]];
// check if request already processed
if (!fReq.processed) revert RequestNotProcessed();
// Get the amount send to he receiver of the command and push into array
fulfilledAmounts[i] = fReq.fulfilledAmount;
fulfilledRefuelAmounts[i] = fReq.fulfilledRefuelAmount;
}
}
// Call the switchboard router to send the message.
SWITCHBOARD_ROUTER.sendOutboundMsg{value: msg.value}(
chainSlug,
switchboardId,
SINGLE_OUTPUT_IMPL_ID,
gasLimit,
abi.encode(requestHashes, fulfilledAmounts, fulfilledRefuelAmounts)
);
emit RequestsSettledOnDestination(requestHashes, SINGLE_OUTPUT_IMPL_ID, msg.sender, msg.value);
}
function withdrawRequestOnDestination(
address router,
Request calldata request,
bytes calldata withdrawRequestData
) external payable {
// generate the requestHash
bytes32 requestHash = request.hashDestinationRequest();
// checks if the caller is the delegate
if (msg.sender != request.basicReq.delegate) revert NotDelegate();
// Check if the command is already fulfilled / cancelled
if (singleOutputFulfilledRequests[requestHash].processed) revert RequestProcessed();
// mark request as cancelled
singleOutputFulfilledRequests[requestHash] = FulfilledRequest({
fulfilledAmount: 0,
fulfilledRefuelAmount: 0,
processed: true
});
// check router is in system
if (!isBungeeRouter(router)) revert RouterNotRegistered();
/// @dev router should know if the request hash is not supposed to be handled by it
IBaseRouter(router).withdrawRequestOnDestination(request, withdrawRequestData);
// TODO : need to add an event here
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {IBungeeExecutor} from "../interfaces/IBungeeExecutor.sol";
import {Request, SwapExec} from "../common/SwapRequestStructs.sol";
import {AuthenticationLib} from "../lib/AuthenticationLib.sol";
import {AffiliateFeesLib} from "../lib/AffiliateFeesLib.sol";
import {RequestLib} from "../lib/SwapRequestLib.sol";
import {MofaSignatureInvalid, MinOutputNotMet, InvalidMultipleNativeTokens} from "../common/BungeeErrors.sol";
import {Permit2Lib} from "../lib/Permit2Lib.sol";
import {ERC20} from "solmate/src/tokens/ERC20.sol";
import {BungeeEvents} from "../common/BungeeEvents.sol";
import {SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {IFeeCollector} from "../interfaces/IFeeCollector.sol";
import {BungeeGatewayBase} from "./BungeeGatewayBase.sol";
import {BungeeGatewayStorage} from "./BungeeGatewayStorage.sol";
contract SwapRequestImpl is BungeeGatewayStorage, BungeeGatewayBase, BungeeEvents {
using RequestLib for Request;
using RequestLib for SwapExec[];
using SafeTransferLib for ERC20;
constructor(address _owner, address _permit2) BungeeGatewayStorage(_owner, _permit2) {}
/*//////////////////////////////////////////////////////////////////////////
SOURCE FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/**
* @notice extract the user requests and routes it via the respetive routers.
* @notice the user requests can only be extracted if the mofa signature is valid.
* @notice each request can be routed via a different router.
* @notice it would be assumed as a successful execution if the router call does not revert.
* @dev state of the request would be saved against the requesthash created.
* @dev funds from the user wallet will be pulled and sent to the router.
* @dev if there is a swap involved then swapped funds would reach the router.
* @param swapExecs batch of extractions submitted by the transmitter.
* @param mofaSignature signature of mofa on the batch.
*/
function extractAndSwap(SwapExec[] calldata swapExecs, bytes calldata mofaSignature) external payable {
// Checks if batch has been authorised by MOFA
_checkMofaSig(swapExecs, mofaSignature);
// Iterate through swapExec
unchecked {
for (uint256 i = 0; i < swapExecs.length; i++) {
SwapExec memory exec = swapExecs[i];
// Preventing multiple native tokens
bool isNativeTokenUsed = false;
// Check if the promised amount is more than the minOutputAmount
for (uint256 j = 0; j < exec.request.basicReq.outputTokens.length; j++) {
if (exec.fulfilAmounts[j] < exec.request.basicReq.minOutputAmounts[j]) revert MinOutputNotMet();
// Check if native token has already been used as an output token
if (exec.request.basicReq.outputTokens[j] == NATIVE_TOKEN_ADDRESS) {
if (isNativeTokenUsed) revert InvalidMultipleNativeTokens();
isNativeTokenUsed = true;
}
}
// Create the request hash for the submitted request.
bytes32 requestHash = exec.request.hashRequest();
// If swap payload is present solver wants to use user funds to perform swap
// If swap payload is not present then output tokens are directly transferred from solver
if (exec.swapPayload.length > 0) {
_swapRequestExternal(requestHash, exec);
} else {
_fulfilRequest(requestHash, exec);
}
// calldata execution via Calldata Executor using Request.destinationPayload, Request.minDestGas
_executeCalldata(
exec.request.basicReq.receiver,
exec.request.minDestGas,
exec.fulfilAmounts,
exec.request.basicReq.outputTokens,
requestHash,
exec.request.destinationPayload
);
}
}
}
/*//////////////////////////////////////////////////////////////////////////
INTERNAL SOURCE FUNCTIONS
//////////////////////////////////////////////////////////////////////////*/
/**
* @notice checks if the mofa signature is valid on the batch submitted by the transmitter.
* @param swapExecs batch of extractions submitted by the transmitter.
* @param mofaSignature signature of mofa on the batch.
*/
function _checkMofaSig(SwapExec[] calldata swapExecs, bytes memory mofaSignature) internal view {
// Create the hash of BatchHash
bytes32 batchHash = swapExecs.hashBatch();
// Get the signer
address signer = AuthenticationLib.authenticate(batchHash, mofaSignature);
// Check if addresses match
if (signer != MOFA_SIGNER) revert MofaSignatureInvalid();
}
/**
* @dev collects unlocked fee in input token and registers it with the FeeCollector
*/
function _collectFee(address token, uint256 amount, address feeTaker) internal {
_sendFundsFromContract(token, amount, address(FEE_COLLECTOR));
IFeeCollector(FEE_COLLECTOR).registerFee(feeTaker, amount, token);
}
/**
* @notice this function is used when the transmitter submits a swap for a user request.
* @notice assumption is that the receiver of the swap will be the router mentioned in the exec.
* @dev Funds would be transferred to the swap executor first.
* @dev Swap executor will be called with the swap payload.
* @dev Funds after the swap should reach directly to the user
* @dev If the fulfilAmounts are not met, the transaction will revert.
* @param swapExec execution submitted by the transmitter for the request.
*/
function _swapRequestExternal(bytes32 requestHash, SwapExec memory swapExec) internal {
// Calls Permit2 to transfer funds from user to swap executor.
PERMIT2.permitWitnessTransferFrom(
Permit2Lib.toPermit(
swapExec.request.basicReq.inputToken,
swapExec.request.basicReq.inputAmount,
swapExec.request.basicReq.nonce,
swapExec.request.basicReq.deadline
),
/// @dev transfer tokens to SwapExecutor
Permit2Lib.transferDetails(swapExec.request.basicReq.inputAmount, address(SWAP_EXECUTOR)),
swapExec.request.basicReq.sender,
requestHash,
RequestLib.PERMIT2_ORDER_TYPE,
swapExec.userSignature
);
// Check output token balances of receiver before swap
uint256[] memory initialBalances = new uint256[](swapExec.request.basicReq.outputTokens.length);
for (uint256 i = 0; i < swapExec.request.basicReq.outputTokens.length; i++) {
if (swapExec.request.basicReq.outputTokens[i] == NATIVE_TOKEN_ADDRESS) {
initialBalances[i] = swapExec.request.basicReq.receiver.balance;
} else {
initialBalances[i] = ERC20(swapExec.request.basicReq.outputTokens[i]).balanceOf(
swapExec.request.basicReq.receiver
);
}
}
// Check if fee is supposed to be deducted
/// @dev fee has to be deducted from input token since swap may be for multiple output tokens
(, uint256 feeAmount, address feeTaker) = AffiliateFeesLib.getAffiliateFees(
swapExec.request.basicReq.inputAmount,
swapExec.request.affiliateFees
);
// Call the swap executor to execute the swap.
/// @dev swap output tokens are expected to be sent directly to the user
/// @dev expects swapPayload to perform a single, but multi output swap
if (feeAmount > 0) {
// Collect fee and execute swap
SWAP_EXECUTOR.collectFeeAndExecuteSwap(
swapExec.request.basicReq.inputToken,
swapExec.request.basicReq.inputAmount,
swapExec.swapRouter,
swapExec.swapPayload,
FEE_COLLECTOR,
feeTaker,
feeAmount
);
} else {
SWAP_EXECUTOR.executeSwap(
swapExec.request.basicReq.inputToken,
swapExec.request.basicReq.inputAmount,
swapExec.swapRouter,
swapExec.swapPayload
);
}
/// @dev fulfilAmounts are expected to be sent directly to user by the swap router
// Get the final balances of receiver and check if the fulfilAmounts were met
for (uint256 i = 0; i < swapExec.request.basicReq.outputTokens.length; i++) {
uint256 finalBalance;
if (swapExec.request.basicReq.outputTokens[i] == NATIVE_TOKEN_ADDRESS) {
finalBalance = swapExec.request.basicReq.receiver.balance;
} else {
finalBalance = ERC20(swapExec.request.basicReq.outputTokens[i]).balanceOf(
swapExec.request.basicReq.receiver
);
}
// Check if the fulfilAmounts were met
if (finalBalance - initialBalances[i] < swapExec.fulfilAmounts[i]) revert MinOutputNotMet();
}
emit RequestFulfilled(requestHash, SWAP_REQUEST_IMPL_ID, msg.sender, abi.encode(swapExec));
}
/**
* @notice this function is used when the transmitter submits a request that does not involve a swap.
* @dev funds would be transferred to the router directly from the user.
* @dev Saves the extraction details against the requestHash.
* @param swapExec execution submitted by the transmitter for the request.
When a request is settled beneficiary will receive funds.
*/
function _fulfilRequest(bytes32 requestHash, SwapExec memory swapExec) internal {
// Calls Permit2 to transfer funds from user to BungeeGateway
PERMIT2.permitWitnessTransferFrom(
Permit2Lib.toPermit(
swapExec.request.basicReq.inputToken,
swapExec.request.basicReq.inputAmount,
swapExec.request.basicReq.nonce,
swapExec.request.basicReq.deadline
),
Permit2Lib.transferDetails(swapExec.request.basicReq.inputAmount, address(this)),
swapExec.request.basicReq.sender,
requestHash,
RequestLib.PERMIT2_ORDER_TYPE,
swapExec.userSignature
);
// Check if fee is supposed to be deducted
(uint256 netInputAmount, uint256 feeAmount, address feeTaker) = AffiliateFeesLib.getAffiliateFees(
swapExec.request.basicReq.inputAmount,
swapExec.request.affiliateFees
);
if (feeAmount > 0) {
// @todo how to register BungeeGateway and SwapExecutor as router
_collectFee(swapExec.request.basicReq.inputToken, feeAmount, feeTaker);
}
// Transfer fulfilAmounts from transmitter to user
unchecked {
for (uint256 i = 0; i < swapExec.fulfilAmounts.length; i++) {
// Send the tokens in the exec to the receiver.
_sendFundsToReceiver({
token: swapExec.request.basicReq.outputTokens[i],
from: msg.sender,
amount: swapExec.fulfilAmounts[i],
to: swapExec.request.basicReq.receiver
});
}
}
// Transfer input amount to beneficiary
_sendFundsFromContract(address(swapExec.request.basicReq.inputToken), netInputAmount, swapExec.beneficiary);
emit RequestFulfilled(requestHash, SWAP_REQUEST_IMPL_ID, msg.sender, abi.encode(swapExec));
}
/// @dev delegates calldata execution to the CalldataExecutor contract
/// @param to destination address
/// @param minDestGasLimit minimum gas limit that should be used for the destination execution
/// @param fulfilledAmounts array of amounts fulfilled on the destination in the request
/// @param outputTokens array of output tokens in the request
/// @param requestHash hash of the request
/// @param executionData calldata to be executed on the destination
function _executeCalldata(
address to,
uint256 minDestGasLimit,
uint256[] memory fulfilledAmounts,
address[] memory outputTokens,
bytes32 requestHash,
bytes memory executionData
) internal {
// @review these checks & encoding must be here or in the CalldataExecutor contract?
// Check and return with no action if the data is empty
// Check and return with no action if the destination is invalid
if (executionData.length == 0 || to == address(0) || to == address(this)) return;
// Encodes request data in the payload
bytes memory encodedData = abi.encodeCall(
// @todo too many hops for destination calldata? BungeeGateway → CalldataExecutor → IBungeeExecutor → Aave deposit
IBungeeExecutor.executeData,
(fulfilledAmounts, requestHash, outputTokens, executionData)
);
// Execute calldata
CALLDATA_EXECUTOR.executeCalldata(to, encodedData, minDestGasLimit);
}
function _receiveMsg(bytes calldata payload) internal override {
// Do nothing, not needed.
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface IBaseRouter {
function releaseFunds(address token, uint256 amount, address recipient) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {IBaseRouter} from "./IBaseRouter.sol";
import {FulfilExec, ExtractExec, Request} from "../common/SingleOutputStructs.sol";
interface IBaseRouterSingleOutput is IBaseRouter {
function execute(
uint256 amount,
address inputToken,
bytes32 requestHash,
uint256 expiry,
address receiverContract,
address feeCollector,
ExtractExec memory exec
) external;
function fulfil(bytes32 requestHash, FulfilExec calldata fulfilExec, address transmitter) external payable;
function withdrawRequestOnDestination(Request calldata request, bytes calldata withdrawRequestData) external;
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.17;
interface IBungeeExecutor {
function executeData(
uint256[] calldata amounts,
bytes32 commandHash,
address[] calldata tokens,
bytes memory callData
) external payable;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface ICalldataExecutor {
function executeCalldata(address to, bytes memory encodedData, uint256 msgGasLimit) external returns (bool);
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface IFeeCollector {
function registerFee(address feeTaker, uint256 feeAmount, address feeToken) external;
function registerFee(address feeTaker, uint256 feeAmount, address feeToken, bytes32 requestHash) external;
function settleFee(bytes32 requestHash) external;
function refundFee(bytes32 requestHash, address to) external;
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.17;
interface IStakeVault {
function withdrawStake(address token, uint256 capacity, address transmitter) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {IFeeCollector} from "./IFeeCollector.sol";
interface ISwapExecutor {
function executeSwap(address token, uint256 amount, address swapRouter, bytes memory swapPayload) external;
function executeSwapWithValue(address swapRouter, bytes memory swapPayload, uint256 msgValue) external;
function collectFeeAndExecuteSwap(
address token,
uint256 amount,
address swapRouter,
bytes memory swapPayload,
IFeeCollector feeCollector,
address feeTaker,
uint256 feeAmount
) external;
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
interface ISwitchboardRouter {
function sendOutboundMsg(
uint32 originChainId,
uint32 switchboardId,
uint8 msgId,
uint256 destGasLimit,
bytes calldata payload
) external payable;
function receiveAndDeliverMsg(uint32 switchboardId, uint32 siblingChainId, bytes calldata payload) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity ^0.8.17;
import {ERC20, SafeTransferLib} from "solmate/src/utils/SafeTransferLib.sol";
import {BytesLib} from "./BytesLib.sol";
/// @notice helpers for AffiliateFees struct
library AffiliateFeesLib {
/// @notice SafeTransferLib - library for safe and optimized operations on ERC20 tokens
using SafeTransferLib for ERC20;
/// @notice error when affiliate fee length is wrong
error WrongAffiliateFeeLength();
/// @notice event emitted when affiliate fee is deducted
event AffiliateFeeDeducted(address feeToken, address feeTakerAddress, uint256 feeAmount);
// Precision used for affiliate fee calculation
uint256 internal constant PRECISION = 10000000000000000;
/**
* @dev calculates & transfers fee to feeTakerAddress
* @param bridgingAmount amount to be bridged
* @param affiliateFees packed bytes containing feeTakerAddress and feeInBps
* ensure the affiliateFees is packed as follows:
* address feeTakerAddress (20 bytes) + uint48 feeInBps (6 bytes) = 26 bytes
* @return bridgingAmount after deducting affiliate fees
*/
function getAffiliateFees(
uint256 bridgingAmount,
bytes memory affiliateFees
) internal pure returns (uint256, uint256, address) {
address feeTakerAddress;
uint256 feeAmount = 0;
if (affiliateFees.length > 0) {
uint48 feeInBps;
if (affiliateFees.length != 26) revert WrongAffiliateFeeLength();
feeInBps = BytesLib.toUint48(affiliateFees, 20);
feeTakerAddress = BytesLib.toAddress(affiliateFees, 0);
if (feeInBps > 0) {
// calculate fee
feeAmount = ((bridgingAmount * feeInBps) / PRECISION);
bridgingAmount -= feeAmount;
}
}
return (bridgingAmount, feeAmount, feeTakerAddress);
}
function getAmountAfterFee(uint256 bridgingAmount, bytes memory affiliateFees) internal pure returns (uint256) {
address feeTakerAddress;
uint256 feeAmount = 0;
if (affiliateFees.length > 0) {
uint48 feeInBps;
if (affiliateFees.length != 26) revert WrongAffiliateFeeLength();
feeInBps = BytesLib.toUint48(affiliateFees, 20);
feeTakerAddress = BytesLib.toAddress(affiliateFees, 0);
if (feeInBps > 0) {
// calculate fee
feeAmount = ((bridgingAmount * feeInBps) / PRECISION);
bridgingAmount -= feeAmount;
}
}
return (bridgingAmount);
}
}// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
// Library to authenticate the signer address.
library AuthenticationLib {
/// @notice authenticate a message hash signed by Bungee Protocol
/// @param messageHash hash of the message
/// @param signature signature of the message
/// @return true if signature is valid
function authenticate(bytes32 messageHash, bytes memory signature) internal pure returns (address) {
bytes32 ethSignedMessageHash = getEthSignedMessageHash(messageHash);
return recoverSigner(ethSignedMessageHash, signature);
}
function getEthSignedMessageHash(bytes32 _messageHash) public pure returns (bytes32) {
/*
Signature is produced by signing a keccak256 hash with the following format:
"\x19Ethereum Signed Message\n" + len(msg) + msg
*/
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash));
}
function recoverSigner(bytes32 _ethSignedMessageHash, bytes memory _signature) public pure returns (address) {
(bytes32 r, bytes32 s, uint8 v) = splitSignature(_signature);
return ecrecover(_ethSignedMessageHash, v, r, s);
}
function splitSignature(bytes memory sig) public pure returns (bytes32 r, bytes32 s, uint8 v) {
require(sig.length == 65, "invalid signature length");
assembly {
/*
First 32 bytes stores the length of the signature
add(sig, 32) = pointer of sig + 32
effectively, skips first 32 bytes of signature
mload(p) loads next 32 bytes starting at the memory address p into memory
*/
// first 32 bytes, after the length prefix
r := mload(add(sig, 32))
// second 32 bytes
s := mload(add(sig, 64))
// final byte (first byte of the next 32 bytes)
v := byte(0, mload(add(sig, 96)))
}
// implicitly return (r, s, v)
}
}// SPDX-License-Identifier: Unlicense /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <[email protected]> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity >=0.8.4 <0.9.0; library BytesLib { function concat(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bytes memory) { bytes memory tempBytes; assembly { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // Store the length of the first bytes array at the beginning of // the memory for tempBytes. let length := mload(_preBytes) mstore(tempBytes, length) // Maintain a memory counter for the current write location in the // temp bytes array by adding the 32 bytes for the array length to // the starting location. let mc := add(tempBytes, 0x20) // Stop copying when the memory counter reaches the length of the // first bytes array. let end := add(mc, length) for { // Initialize a copy counter to the start of the _preBytes data, // 32 bytes into its memory. let cc := add(_preBytes, 0x20) } lt(mc, end) { // Increase both counters by 32 bytes each iteration. mc := add(mc, 0x20) cc := add(cc, 0x20) } { // Write the _preBytes data into the tempBytes memory 32 bytes // at a time. mstore(mc, mload(cc)) } // Add the length of _postBytes to the current length of tempBytes // and store it as the new length in the first 32 bytes of the // tempBytes memory. length := mload(_postBytes) mstore(tempBytes, add(length, mload(tempBytes))) // Move the memory counter back from a multiple of 0x20 to the // actual end of the _preBytes data. mc := end // Stop copying when the memory counter reaches the new combined // length of the arrays. end := add(mc, length) for { let cc := add(_postBytes, 0x20) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } // Update the free-memory pointer by padding our last write location // to 32 bytes: add 31 bytes to the end of tempBytes to move to the // next 32 byte block, then round down to the nearest multiple of // 32. If the sum of the length of the two arrays is zero then add // one before rounding down to leave a blank 32 bytes (the length block with 0). mstore( 0x40, and( add(add(end, iszero(add(length, mload(_preBytes)))), 31), not(31) // Round down to the nearest 32 bytes. ) ) } return tempBytes; } function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal { assembly { // Read the first 32 bytes of _preBytes storage, which is the length // of the array. (We don't need to use the offset into the slot // because arrays use the entire slot.) let fslot := sload(_preBytes.slot) // Arrays of 31 bytes or less have an even value in their slot, // while longer arrays have an odd value. The actual length is // the slot divided by two for odd values, and the lowest order // byte divided by two for even values. // If the slot is even, bitwise and the slot with 255 and divide by // two to get the length. If the slot is odd, bitwise and the slot // with -1 and divide by two. let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) let newlength := add(slength, mlength) // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage switch add(lt(slength, 32), lt(newlength, 32)) case 2 { // Since the new array still fits in the slot, we just need to // update the contents of the slot. // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length sstore( _preBytes.slot, // all the modifications to the slot are inside this // next block add( // we can just add to the slot contents because the // bytes we want to change are the LSBs fslot, add( mul( div( // load the bytes from memory mload(add(_postBytes, 0x20)), // zero all bytes to the right exp(0x100, sub(32, mlength)) ), // and now shift left the number of bytes to // leave space for the length in the slot exp(0x100, sub(32, newlength)) ), // increase length by the double of the memory // bytes length mul(mlength, 2) ) ) ) } case 1 { // The stored value fits in the slot, but the combined value // will exceed it. // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes.slot, add(mul(newlength, 2), 1)) // The contents of the _postBytes array start 32 bytes into // the structure. Our first read should obtain the `submod` // bytes that can fit into the unused space in the last word // of the stored array. To get this, we read 32 bytes starting // from `submod`, so the data we read overlaps with the array // contents by `submod` bytes. Masking the lowest-order // `submod` bytes allows us to add that value directly to the // stored value. let submod := sub(32, slength) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore( sc, add( and(fslot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00), and(mload(mc), mask) ) ) for { mc := add(mc, 0x20) sc := add(sc, 1) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } default { // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) // Start copying to the last used word of the stored array. let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes.slot, add(mul(newlength, 2), 1)) // Copy over the first `submod` bytes of the new data as in // case 1 above. let slengthmod := mod(slength, 32) let mlengthmod := mod(mlength, 32) let submod := sub(32, slengthmod) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore(sc, add(sload(sc), and(mload(mc), mask))) for { sc := add(sc, 1) mc := add(mc, 0x20) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } } } function slice(bytes memory _bytes, uint256 _start, uint256 _length) internal pure returns (bytes memory) { require(_length + 31 >= _length, "slice_overflow"); require(_bytes.length >= _start + _length, "slice_outOfBounds"); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_bytes.length >= _start + 20, "toAddress_outOfBounds"); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) { require(_bytes.length >= _start + 1, "toUint8_outOfBounds"); uint8 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x1), _start)) } return tempUint; } function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) { require(_bytes.length >= _start + 2, "toUint16_outOfBounds"); uint16 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x2), _start)) } return tempUint; } function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) { require(_bytes.length >= _start + 4, "toUint32_outOfBounds"); uint32 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x4), _start)) } return tempUint; } function toUint48(bytes memory _bytes, uint256 _start) internal pure returns (uint48) { require(_bytes.length >= _start + 6, "toUint48_outOfBounds"); uint48 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x6), _start)) } return tempUint; } function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) { require(_bytes.length >= _start + 8, "toUint64_outOfBounds"); uint64 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x8), _start)) } return tempUint; } function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) { require(_bytes.length >= _start + 12, "toUint96_outOfBounds"); uint96 tempUint; assembly { tempUint := mload(add(add(_bytes, 0xc), _start)) } return tempUint; } function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) { require(_bytes.length >= _start + 16, "toUint128_outOfBounds"); uint128 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x10), _start)) } return tempUint; } function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) { require(_bytes.length >= _start + 32, "toUint256_outOfBounds"); uint256 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x20), _start)) } return tempUint; } function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) { require(_bytes.length >= _start + 32, "toBytes32_outOfBounds"); bytes32 tempBytes32; assembly { tempBytes32 := mload(add(add(_bytes, 0x20), _start)) } return tempBytes32; } function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) { bool success = true; assembly { let length := mload(_preBytes) // if lengths don't match the arrays are not equal switch eq(length, mload(_postBytes)) case 1 { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 let mc := add(_preBytes, 0x20) let end := add(mc, length) for { let cc := add(_postBytes, 0x20) // the next line is the loop condition: // while(uint256(mc < end) + cb == 2) } eq(add(lt(mc, end), cb), 2) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { // if any of these checks fails then arrays are not equal if iszero(eq(mload(mc), mload(cc))) { // unsuccess: success := 0 cb := 0 } } } default { // unsuccess: success := 0 } } return success; } function equal_nonAligned(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) { bool success = true; assembly { let length := mload(_preBytes) // if lengths don't match the arrays are not equal switch eq(length, mload(_postBytes)) case 1 { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 let endMinusWord := add(_preBytes, length) let mc := add(_preBytes, 0x20) let cc := add(_postBytes, 0x20) for { // the next line is the loop condition: // while(uint256(mc < endWord) + cb == 2) } eq(add(lt(mc, endMinusWord), cb), 2) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { // if any of these checks fails then arrays are not equal if iszero(eq(mload(mc), mload(cc))) { // unsuccess: success := 0 cb := 0 } } // Only if still successful // For <1 word tail bytes if gt(success, 0) { // Get the remainder of length/32 // length % 32 = AND(length, 32 - 1) let numTailBytes := and(length, 0x1f) let mcRem := mload(mc) let ccRem := mload(cc) for { let i := 0 // the next line is the loop condition: // while(uint256(i < numTailBytes) + cb == 2) } eq(add(lt(i, numTailBytes), cb), 2) { i := add(i, 1) } { if iszero(eq(byte(i, mcRem), byte(i, ccRem))) { // unsuccess: success := 0 cb := 0 } } } } default { // unsuccess: success := 0 } } return success; } function equalStorage(bytes storage _preBytes, bytes memory _postBytes) internal view returns (bool) { bool success = true; assembly { // we know _preBytes_offset is 0 let fslot := sload(_preBytes.slot) // Decode the length of the stored array like in concatStorage(). let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) // if lengths don't match the arrays are not equal switch eq(slength, mlength) case 1 { // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage if iszero(iszero(slength)) { switch lt(slength, 32) case 1 { // blank the last byte which is the length fslot := mul(div(fslot, 0x100), 0x100) if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) { // unsuccess: success := 0 } } default { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) let sc := keccak256(0x0, 0x20) let mc := add(_postBytes, 0x20) let end := add(mc, mlength) // the next line is the loop condition: // while(uint256(mc < end) + cb == 2) for { } eq(add(lt(mc, end), cb), 2) { sc := add(sc, 1) mc := add(mc, 0x20) } { if iszero(eq(sload(sc), mload(mc))) { // unsuccess: success := 0 cb := 0 } } } } } default { // unsuccess: success := 0 } } return success; } }
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import {ISignatureTransfer} from "permit2/src/interfaces/ISignatureTransfer.sol";
// Library to get Permit 2 related data.
library Permit2Lib {
string public constant TOKEN_PERMISSIONS_TYPE = "TokenPermissions(address token,uint256 amount)";
function toPermit(
address inputToken,
uint256 inputAmount,
uint256 nonce,
uint256 deadline
) internal pure returns (ISignatureTransfer.PermitTransferFrom memory) {
return
ISignatureTransfer.PermitTransferFrom({
permitted: ISignatureTransfer.TokenPermissions({token: inputToken, amount: inputAmount}),
nonce: nonce,
deadline: deadline
});
}
function transferDetails(
uint256 amount,
address spender
) internal pure returns (ISignatureTransfer.SignatureTransferDetails memory) {
return ISignatureTransfer.SignatureTransferDetails({to: spender, requestedAmount: amount});
}
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.17;
import {BasicRequest, Request, ExtractExec} from "../common/SingleOutputStructs.sol";
import {Permit2Lib} from "./Permit2Lib.sol";
/// @notice helpers for handling BasicRequest
library BasicRequestLib {
bytes internal constant BASIC_REQUEST_TYPE =
abi.encodePacked(
"BasicRequest(",
"uint256 originChainId,",
"uint256 destinationChainId,",
"uint256 deadline,",
"uint256 nonce,",
"address sender,",
"address receiver,",
"address delegate,",
"address bungeeGateway,",
"uint32 switchboardId,",
"address inputToken,",
"uint256 inputAmount,",
"address outputToken,",
"uint256 minOutputAmount,"
"uint256 refuelAmount)"
);
bytes32 internal constant BASIC_REQUEST_TYPE_HASH = keccak256(BASIC_REQUEST_TYPE);
/// @notice Hash of BasicRequest struct on the origin chain
/// @dev enforces originChainId to be the current chainId. Resulting hash would be the same on all chains.
/// @dev helps avoid extra checking of chainId in the contract
/// @param basicReq BasicRequest object to be hashed
function originHash(BasicRequest memory basicReq) internal view returns (bytes32) {
return
keccak256(
abi.encodePacked(
BASIC_REQUEST_TYPE_HASH,
abi.encode(
block.chainid,
basicReq.destinationChainId,
basicReq.deadline,
basicReq.nonce,
basicReq.sender,
basicReq.receiver,
basicReq.delegate,
basicReq.bungeeGateway,
basicReq.switchboardId,
basicReq.inputToken,
basicReq.inputAmount,
basicReq.outputToken,
basicReq.minOutputAmount,
basicReq.refuelAmount
)
)
);
}
/// @notice Hash of BasicRequest struct on the destination chain
/// @dev enforces destinationChain to be the current chainId. Resulting hash would be the same on all chains.
/// @dev helps avoid extra checking of chainId in the contract
/// @param basicReq BasicRequest object to be hashed
function destinationHash(BasicRequest memory basicReq) internal view returns (bytes32) {
return
keccak256(
abi.encodePacked(
BASIC_REQUEST_TYPE_HASH,
abi.encode(
basicReq.originChainId,
block.chainid,
basicReq.deadline,
basicReq.nonce,
basicReq.sender,
basicReq.receiver,
basicReq.delegate,
basicReq.bungeeGateway,
basicReq.switchboardId,
basicReq.inputToken,
basicReq.inputAmount,
basicReq.outputToken,
basicReq.minOutputAmount,
basicReq.refuelAmount
)
)
);
}
}
/// @title Bungee Request Library.
/// @author bungee protocol
/// @notice This library is responsible for all the hashing related to Request object.
library RequestLib {
using BasicRequestLib for BasicRequest;
// Permit 2 Witness Order Type.
string internal constant PERMIT2_ORDER_TYPE =
string(
abi.encodePacked(
"Request witness)",
abi.encodePacked(BasicRequestLib.BASIC_REQUEST_TYPE, REQUEST_TYPE),
Permit2Lib.TOKEN_PERMISSIONS_TYPE
)
);
// REQUEST TYPE encode packed
bytes internal constant REQUEST_TYPE =
abi.encodePacked(
"Request(",
"BasicRequest basicReq,",
"address swapOutputToken,",
"uint256 minSwapOutput,",
"bytes32 metadata,",
"bytes affiliateFees)"
);
// EXTRACT EXEC TYPE.
bytes internal constant EXTRACT_EXEC_TYPE =
abi.encodePacked(
"ExtractExec(",
"Request request,",
"address router,",
"uint256 promisedAmount,",
"uint256 promisedRefuelAmount,",
"bytes routerData,",
"bytes swapPayload,",
"address swapRouter,",
"bytes userSignature,",
"address beneficiary)"
);
// BUNGEE_REQUEST_TYPE
bytes internal constant BUNGEE_REQUEST_TYPE = abi.encodePacked(REQUEST_TYPE, BasicRequestLib.BASIC_REQUEST_TYPE);
// Keccak Hash of BUNGEE_REQUEST_TYPE
bytes32 internal constant BUNGEE_REQUEST_TYPE_HASH = keccak256(BUNGEE_REQUEST_TYPE);
// Exec Type.
bytes internal constant EXEC_TYPE = abi.encodePacked(EXTRACT_EXEC_TYPE, REQUEST_TYPE);
// Keccak Hash of Exec Type.
bytes32 internal constant EXTRACT_EXEC_TYPE_HASH = keccak256(EXEC_TYPE);
/// @notice Hash of request on the origin chain
/// @param request request that is signe by the user
function hashOriginRequest(Request memory request) internal view returns (bytes32) {
return
keccak256(
abi.encode(
BUNGEE_REQUEST_TYPE_HASH,
request.basicReq.originHash(),
request.swapOutputToken,
request.minSwapOutput,
request.metadata,
keccak256(request.affiliateFees)
)
);
}
/// @notice Hash of request on the destination chain
/// @param request request signed by the user
function hashDestinationRequest(Request memory request) internal view returns (bytes32) {
return
keccak256(
abi.encode(
BUNGEE_REQUEST_TYPE_HASH,
request.basicReq.destinationHash(),
request.swapOutputToken,
request.minSwapOutput,
request.metadata,
keccak256(request.affiliateFees)
)
);
}
/// @notice Hash of Extract Exec on the origin chain
/// @param execution Transmitter submitted extract exec object
function hashOriginExtractExec(ExtractExec memory execution) internal view returns (bytes32) {
return
keccak256(
abi.encode(
EXTRACT_EXEC_TYPE_HASH,
hashOriginRequest(execution.request),
execution.router,
execution.promisedAmount,
execution.promisedRefuelAmount,
keccak256(execution.routerData),
keccak256(execution.swapPayload),
execution.swapRouter,
keccak256(execution.userSignature),
execution.beneficiary
)
);
}
/// @notice hash a batch of extract execs
/// @param extractExecs batch of extract execs to be hashed
function hashOriginBatch(ExtractExec[] memory extractExecs) internal view returns (bytes32) {
unchecked {
bytes32 outputHash = keccak256("BUNGEE_EXTRACT_EXEC");
// Hash all of the extract execs present in the batch.
for (uint256 i = 0; i < extractExecs.length; i++) {
outputHash = keccak256(abi.encode(outputHash, hashOriginExtractExec(extractExecs[i])));
}
return outputHash;
}
}
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.17;
import {BasicRequest, Request, SwapExec} from "../common/SwapRequestStructs.sol";
import {Permit2Lib} from "./Permit2Lib.sol";
/// @notice helpers for handling CommandInfo objects
library BasicRequestLib {
bytes internal constant BASIC_REQUEST_TYPE =
abi.encodePacked(
"BasicRequest(",
"uint256 chainId,",
"uint256 deadline,",
"uint256 nonce,",
"address sender,",
"address receiver,",
"address bungeeGateway,",
"address inputToken,",
"uint256 inputAmount,",
"address[] outputTokens,",
"uint256[] minOutputAmounts)"
);
bytes32 internal constant BASIC_REQUEST_TYPE_HASH = keccak256(BASIC_REQUEST_TYPE);
/// @notice Hash of BasicRequest struct on the swap chain
/// @dev enforces chainId to be the current chainId
/// @dev helps avoid extra checking of chainId in the contract
/// @param basicReq BasicRequest object to be hashed
function hash(BasicRequest memory basicReq) internal view returns (bytes32) {
return
keccak256(
abi.encode(
BASIC_REQUEST_TYPE_HASH,
block.chainid,
basicReq.deadline,
basicReq.nonce,
basicReq.sender,
basicReq.receiver,
basicReq.bungeeGateway,
basicReq.inputToken,
basicReq.inputAmount,
keccak256(abi.encodePacked(basicReq.outputTokens)),
keccak256(abi.encodePacked(basicReq.minOutputAmounts))
)
);
}
}
/// @title Bungee Request Library.
/// @author bungee protocol
/// @notice This library is responsible for all the hashing related to Request object.
library RequestLib {
using BasicRequestLib for BasicRequest;
// Permit 2 Witness Order Type.
string internal constant PERMIT2_ORDER_TYPE =
string(
abi.encodePacked(
"Request witness)",
abi.encodePacked(BasicRequestLib.BASIC_REQUEST_TYPE, REQUEST_TYPE),
Permit2Lib.TOKEN_PERMISSIONS_TYPE
)
);
// REQUEST TYPE encode packed
bytes internal constant REQUEST_TYPE =
abi.encodePacked(
"Request(",
"BasicRequest basicReq,",
"address[] exclusiveTransmitters,",
"bytes32 metadata,",
"bytes affiliateFees,",
"uint256 minDestGas,",
"bytes destinationPayload)"
);
// SWAP EXEC TYPE.
// @review this lib again, make sure things are solid
bytes internal constant SWAP_EXEC_TYPE =
abi.encodePacked(
"SwapExec(",
"Request request,",
"uint256[] fulfilAmounts,",
"bytes swapPayload,",
"address swapRouter,",
"bytes userSignature,",
"address beneficiary)"
);
// BUNGEE_REQUEST_TYPE
bytes internal constant BUNGEE_REQUEST_TYPE = abi.encodePacked(REQUEST_TYPE, BasicRequestLib.BASIC_REQUEST_TYPE);
// Keccak Hash of BUNGEE_REQUEST_TYPE
bytes32 internal constant BUNGEE_REQUEST_TYPE_HASH = keccak256(BUNGEE_REQUEST_TYPE);
// Exec Type.
bytes internal constant EXEC_TYPE = abi.encodePacked(SWAP_EXEC_TYPE, REQUEST_TYPE);
// Keccak Hash of Exec Type.
bytes32 internal constant SWAP_EXEC_TYPE_HASH = keccak256(EXEC_TYPE);
/// @notice Hash of request on the swap chain
/// @param request request that is signe by the user
function hashRequest(Request memory request) internal view returns (bytes32) {
return
keccak256(
abi.encode(
BUNGEE_REQUEST_TYPE_HASH,
request.basicReq.hash(),
keccak256(abi.encodePacked(request.exclusiveTransmitters)),
request.metadata,
keccak256(request.affiliateFees),
request.minDestGas,
keccak256(request.destinationPayload)
)
);
}
/// @notice Hash of Swap Exec on the swap chain
/// @param execution Transmitter submitted swap exec object
function hashSwapExec(SwapExec memory execution) internal view returns (bytes32) {
return
keccak256(
abi.encode(
SWAP_EXEC_TYPE_HASH,
hashRequest(execution.request),
keccak256(abi.encodePacked(execution.fulfilAmounts)),
keccak256(execution.swapPayload),
execution.swapRouter,
keccak256(execution.userSignature),
execution.beneficiary
)
);
}
/// @notice hash a batch of swap execs
/// @param swapExecs batch of swap execs to be hashed
function hashBatch(SwapExec[] memory swapExecs) internal view returns (bytes32) {
unchecked {
bytes32 outputHash = keccak256("BUNGEE_SWAP_EXEC");
// Hash all of the swap execs present in the batch.
for (uint256 i = 0; i < swapExecs.length; i++) {
outputHash = keccak256(abi.encode(outputHash, hashSwapExec(swapExecs[i])));
}
return outputHash;
}
}
}// SPDX-License-Identifier: GPL-3.0-only
pragma solidity ^0.8.17;
import {OnlyOwner, OnlyNominee} from "../common/BungeeErrors.sol";
abstract contract Ownable {
address private _owner;
address private _nominee;
event OwnerNominated(address indexed nominee);
event OwnerClaimed(address indexed claimer);
constructor(address owner_) {
_claimOwner(owner_);
}
modifier onlyOwner() {
if (msg.sender != _owner) {
revert OnlyOwner();
}
_;
}
function owner() public view returns (address) {
return _owner;
}
function nominee() public view returns (address) {
return _nominee;
}
function nominateOwner(address nominee_) external {
if (msg.sender != _owner) {
revert OnlyOwner();
}
_nominee = nominee_;
emit OwnerNominated(_nominee);
}
function claimOwner() external {
if (msg.sender != _nominee) {
revert OnlyNominee();
}
_claimOwner(msg.sender);
}
function _claimOwner(address claimer_) internal {
_owner = claimer_;
_nominee = address(0);
emit OwnerClaimed(claimer_);
}
}{
"optimizer": {
"enabled": true,
"runs": 200
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_mofaSigner","type":"address"},{"internalType":"address","name":"_switchboardRouter","type":"address"},{"internalType":"address","name":"_swapExecutor","type":"address"},{"internalType":"address","name":"_calldataRouter","type":"address"},{"internalType":"address","name":"_permit2","type":"address"},{"internalType":"uint256","name":"_expiryBuffer","type":"uint256"},{"internalType":"address","name":"_singleOutputRequestImpl","type":"address"},{"internalType":"address","name":"_swapOutputRequestImpl","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"InvalidMsg","type":"error"},{"inputs":[],"name":"InvalidStake","type":"error"},{"inputs":[],"name":"OnlyNominee","type":"error"},{"inputs":[],"name":"OnlyOwner","type":"error"},{"inputs":[],"name":"RouterAlreadyRegistered","type":"error"},{"inputs":[],"name":"RouterAlreadyWhitelisted","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"claimer","type":"address"}],"name":"OwnerClaimed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"nominee","type":"address"}],"name":"OwnerNominated","type":"event"},{"inputs":[],"name":"CALLDATA_EXECUTOR","outputs":[{"internalType":"contract ICalldataExecutor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"EXPIRY_BUFFER","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"FEE_COLLECTOR","outputs":[{"internalType":"contract IFeeCollector","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MOFA_SIGNER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"NATIVE_TOKEN_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PERMIT2","outputs":[{"internalType":"contract ISignatureTransfer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SINGLE_OUTPUT_IMPL_ID","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SINGLE_OUTPUT_REQUEST_IMPL","outputs":[{"internalType":"contract SingleOutputRequestImpl","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"STAKE_VAULT","outputs":[{"internalType":"contract IStakeVault","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SWAP_EXECUTOR","outputs":[{"internalType":"contract ISwapExecutor","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SWAP_REQUEST_IMPL","outputs":[{"internalType":"contract SwapRequestImpl","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SWAP_REQUEST_IMPL_ID","outputs":[{"internalType":"uint8","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"SWITCHBOARD_ROUTER","outputs":[{"internalType":"contract ISwitchboardRouter","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"address","name":"router","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"beneficiarySettlements","outputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"transmitter","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"checkCapacity","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"claimOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"executeSOR","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"executeSR","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestHash","type":"bytes32"}],"name":"getSingleOutputExtractedRequest","outputs":[{"components":[{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"address","name":"router","type":"address"},{"internalType":"address","name":"sender","type":"address"},{"internalType":"address","name":"delegate","type":"address"},{"internalType":"uint32","name":"switchboardId","type":"uint32"},{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"transmitter","type":"address"},{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint256","name":"promisedAmount","type":"uint256"},{"internalType":"uint256","name":"promisedRefuelAmount","type":"uint256"},{"internalType":"bytes","name":"affiliateFees","type":"bytes"}],"internalType":"struct ExtractedRequest","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestHash","type":"bytes32"}],"name":"getSingleOutputFulfilledRequest","outputs":[{"components":[{"internalType":"uint256","name":"fulfilledAmount","type":"uint256"},{"internalType":"uint256","name":"fulfilledRefuelAmount","type":"uint256"},{"internalType":"bool","name":"processed","type":"bool"}],"internalType":"struct FulfilledRequest","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"router","type":"address"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"}],"name":"getWhitelistedReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint8","name":"implId","type":"uint8"},{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"inboundMsgFromSwitchboard","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"router","type":"address"}],"name":"isBungeeRouter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"router","type":"address"}],"name":"isWhitelisted","outputs":[{"internalType":"bool","name":"whitelisted","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"nominee_","type":"address"}],"name":"nominateOwner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"nominee","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"receiveMsg","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"stakedRouter","type":"address"}],"name":"registerStakedRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"capacity","type":"uint256"}],"name":"registerTransmitterStake","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"whitelistedRouter","type":"address"}],"name":"registerWhitelistedRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"rescue","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_calldataExecutor","type":"address"}],"name":"setCalldataExecutor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_expiryBuffer","type":"uint256"}],"name":"setExpiryBuffer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeCollector","type":"address"}],"name":"setFeeCollector","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_mofaSigner","type":"address"}],"name":"setMofaSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_stakeVault","type":"address"}],"name":"setStakeVault","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_swapExecutor","type":"address"}],"name":"setSwapExecutor","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_switchboardRouter","type":"address"}],"name":"setSwitchboardRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"receiver","type":"address"},{"internalType":"uint256","name":"destinationChainId","type":"uint256"},{"internalType":"address","name":"router","type":"address"}],"name":"setWhitelistedReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"transmitter","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"transmitterCapacity","outputs":[{"internalType":"uint256","name":"capacity","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"beneficiary","type":"address"},{"internalType":"address","name":"router","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"withdrawBeneficiarySettlement","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"capacity","type":"uint256"}],"name":"withdrawTransmitterStake","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"requestHash","type":"bytes32"}],"name":"withdrawnRequests","outputs":[{"internalType":"bool","name":"withdrawn","type":"bool"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
610100604052635ba303c560e11b60e0523480156200001d57600080fd5b5060405162001ddb38038062001ddb833981016040819052620000409162000130565b8884816200004e81620000c0565b506001600160a01b03908116608052600280549a82166001600160a01b03199b8c1617905560038054998216998b16999099179098555060048054968816968916969096179095556005805494871694909716939093179095555060089390935591811660a0521660c05250620001e2565b600080546001600160a01b0383166001600160a01b0319918216811783556001805490921690915560405190917ffbe19c9b601f5ee90b44c7390f3fa2319eba01762d34ee372aeafd59b25c7f8791a250565b80516001600160a01b03811681146200012b57600080fd5b919050565b60008060008060008060008060006101208a8c0312156200015057600080fd5b6200015b8a62000113565b98506200016b60208b0162000113565b97506200017b60408b0162000113565b96506200018b60608b0162000113565b95506200019b60808b0162000113565b9450620001ab60a08b0162000113565b935060c08a01519250620001c260e08b0162000113565b9150620001d36101008b0162000113565b90509295985092959850929598565b60805160a05160c05160e051611baa62000231600039600061125001526000818161076f015261146d01526000818161089501528181610a8401526111fa015260006105770152611baa6000f3fe60806040526004361061026b5760003560e01c806374f8d3fd11610144578063b3b4b6bc116100b6578063e1282c5c1161007a578063e1282c5c146107ff578063e9899ed214610843578063f36ba4d814610863578063f5b841e214610883578063f8281486146108b7578063fe9e60d3146108d757600080fd5b8063b3b4b6bc1461075d578063b746078a14610791578063c66eaeb6146107a4578063cc6dc63a146107b7578063df2ebdbb146107d757600080fd5b8063823d008811610108578063823d0088146106b45780638da5cb5b146106c9578063967aef08146106e75780639ed0cb1314610707578063a42dce8014610727578063ae3100c01461074757600080fd5b806374f8d3fd146105d957806376479d1b1461061c578063795d86b81461063c5780637f660b011461065c57806380f7013e1461067c57600080fd5b80633af32abf116101dd5780635b94db27116101a15780635b94db27146104f55780636a0706db146105155780636a7372da146105355780636afdd85014610565578063733957f8146105995780637373161f146105b957600080fd5b80633af32abf1461041e5780633bd1adec1461044e5780633cbc7eaa146104635780633de408a11461048a5780634c7a7732146104c857600080fd5b80631e789c361161022f5780631e789c361461034257806320798eb71461038b57806320f99c0a146103a057806320ff430b146103be5780632a022241146103de57806331feeadd146103fe57600080fd5b80630b345879146102775780630c0a0ccb146102b45780630cb352e0146102e25780630e4bfd6e1461030257806312f07c251461032257600080fd5b3661027257005b600080fd5b34801561028357600080fd5b50600454610297906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156102c057600080fd5b506102d46102cf36600461170c565b6108ea565b6040519081526020016102ab565b3480156102ee57600080fd5b50600554610297906001600160a01b031681565b34801561030e57600080fd5b50600354610297906001600160a01b031681565b34801561032e57600080fd5b50600254610297906001600160a01b031681565b34801561034e57600080fd5b5061037b61035d36600461173f565b6001600160a01b03166000908152600c602052604090205460ff1690565b60405190151581526020016102ab565b61039e610399366004611761565b610917565b005b3480156103ac57600080fd5b506001546001600160a01b0316610297565b3480156103ca57600080fd5b5061039e6103d936600461178b565b610a47565b6103f16103ec366004611810565b610a7d565b6040516102ab91906118a2565b34801561040a57600080fd5b5061039e6104193660046118b5565b610b16565b34801561042a57600080fd5b5061037b61043936600461173f565b600d6020526000908152604090205460ff1681565b34801561045a57600080fd5b5061039e610beb565b34801561046f57600080fd5b50610478600181565b60405160ff90911681526020016102ab565b34801561049657600080fd5b506102d46104a53660046118b5565b601060209081526000938452604080852082529284528284209052825290205481565b3480156104d457600080fd5b506104e86104e33660046118f8565b610c21565b6040516102ab9190611911565b34801561050157600080fd5b5061039e61051036600461173f565b610dcb565b34801561052157600080fd5b5061039e61053036600461173f565b610e40565b34801561054157600080fd5b5061037b6105503660046118f8565b600f6020526000908152604090205460ff1681565b34801561057157600080fd5b506102977f000000000000000000000000000000000000000000000000000000000000000081565b3480156105a557600080fd5b5061039e6105b436600461173f565b610e8d565b3480156105c557600080fd5b5061039e6105d43660046118f8565b610eda565b3480156105e557600080fd5b506102976105f4366004611761565b6001600160a01b039182166000908152600b6020908152604080832093835292905220541690565b34801561062857600080fd5b5061039e61063736600461173f565b610f0a565b34801561064857600080fd5b5061039e61065736600461173f565b610fd8565b34801561066857600080fd5b50600654610297906001600160a01b031681565b34801561068857600080fd5b506102d461069736600461170c565b600e60209081526000928352604080842090915290825290205481565b3480156106c057600080fd5b50610478600281565b3480156106d557600080fd5b506000546001600160a01b0316610297565b3480156106f357600080fd5b5061039e610702366004611761565b611046565b34801561071357600080fd5b5061039e6107223660046119fc565b611109565b34801561073357600080fd5b5061039e61074236600461173f565b611171565b34801561075357600080fd5b506102d460085481565b34801561076957600080fd5b506102977f000000000000000000000000000000000000000000000000000000000000000081565b61039e61079f366004611810565b6111be565b61039e6107b2366004611a2f565b6111e9565b3480156107c357600080fd5b5061039e6107d236600461173f565b61131b565b3480156107e357600080fd5b5061029773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b34801561080b57600080fd5b5061081f61081a3660046118f8565b611368565b604080518251815260208084015190820152918101511515908201526060016102ab565b34801561084f57600080fd5b5061039e61085e36600461173f565b6113cc565b34801561086f57600080fd5b5061039e61087e36600461173f565b611419565b34801561088f57600080fd5b506102977f000000000000000000000000000000000000000000000000000000000000000081565b3480156108c357600080fd5b50600754610297906001600160a01b031681565b6103f16108e5366004611810565b611466565b6001600160a01b038083166000908152600e60209081526040808320938516835292905220545b92915050565b336000908152600e602090815260408083206001600160a01b0386168452909152902054610946908290611ab9565b336000908152600e602090815260408083206001600160a01b03871680855292529091209190915573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed1901610a27578034146109a957604051634eba4d4960e11b815260040160405180910390fd5b6007546040516000916001600160a01b03169061138890849084818181858888f193505050503d80600081146109fb576040519150601f19603f3d011682016040523d82523d6000602084013e610a00565b606091505b5050905080610a22576040516312171d8360e31b815260040160405180910390fd5b505050565b600754610a43906001600160a01b0384811691339116846114a5565b5050565b6000546001600160a01b03163314610a7257604051635fc483c560e01b815260040160405180910390fd5b610a22838284611546565b60606000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168585604051610abc929190611acc565b600060405180830381855af49150503d8060008114610af7576040519150601f19603f3d011682016040523d82523d6000602084013e610afc565b606091505b509150915081610b0e57805160208201fd5b949350505050565b6001600160a01b03808416600090815260106020908152604080832086851684528252808320938516835292905220548015610be5576001600160a01b038481166000818152601060209081526040808320888616808552908352818420958816808552959092528083209290925590516362524dd760e01b81526004810193909352602483018490526044830191909152906362524dd790606401600060405180830381600087803b158015610bcc57600080fd5b505af1158015610be0573d6000803e3d6000fd5b505050505b50505050565b6001546001600160a01b03163314610c1657604051637c91ccdd60e01b815260040160405180910390fd5b610c1f336115f8565b565b604080516101808101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e08201839052610100820183905261012082018390526101408201929092526101608101919091526000828152600a60208181526040928390208351610180810185528154815260018201546001600160a01b0390811693820193909352600282015483169481019490945260038101548083166060860152600160a01b900463ffffffff1660808501526004810154821660a08501526005810154821660c0850152600681015490911660e0840152600781015461010084015260088101546101208401526009810154610140840152908101805461016084019190610d4290611adc565b80601f0160208091040260200160405190810160405280929190818152602001828054610d6e90611adc565b8015610dbb5780601f10610d9057610100808354040283529160200191610dbb565b820191906000526020600020905b815481529060010190602001808311610d9e57829003601f168201915b5050505050815250509050919050565b6000546001600160a01b03163314610df657604051635fc483c560e01b815260040160405180910390fd5b600180546001600160a01b0319166001600160a01b0383169081179091556040517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290600090a250565b6000546001600160a01b03163314610e6b57604051635fc483c560e01b815260040160405180910390fd5b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610eb857604051635fc483c560e01b815260040160405180910390fd5b600580546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610f0557604051635fc483c560e01b815260040160405180910390fd5b600855565b6000546001600160a01b03163314610f3557604051635fc483c560e01b815260040160405180910390fd5b6001600160a01b0381166000908152600d602052604090205460ff1615610f6f5760405163406c5bd360e01b815260040160405180910390fd5b6001600160a01b0381166000908152600c602052604090205460ff1615610fa957604051633ba24ff960e11b815260040160405180910390fd5b6001600160a01b0381166000908152600d60205260409020805460ff19166001179055610fd58161164b565b50565b6000546001600160a01b0316331461100357604051635fc483c560e01b815260040160405180910390fd5b6001600160a01b0381166000908152600c602052604090205460ff161561103d57604051633ba24ff960e11b815260040160405180910390fd5b610fd58161164b565b336000908152600e602090815260408083206001600160a01b0386168452909152902054611075908290611b16565b336000818152600e602090815260408083206001600160a01b038881168086529190935292819020949094556007549351632385922d60e01b81526004810192909252602482018590526044820192909252911690632385922d90606401600060405180830381600087803b1580156110ed57600080fd5b505af1158015611101573d6000803e3d6000fd5b505050505050565b6000546001600160a01b0316331461113457604051635fc483c560e01b815260040160405180910390fd5b6001600160a01b039081166000908152600b60209081526040808320948352939052919091208054919092166001600160a01b0319909116179055565b6000546001600160a01b0316331461119c57604051635fc483c560e01b815260040160405180910390fd5b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6003546001600160a01b03163314610a4357604051631bd147a760e01b815260040160405180910390fd5b600060001960ff86160161121a57507f00000000000000000000000000000000000000000000000000000000000000005b6001600160a01b03811661124157604051631bd147a760e01b815260040160405180910390fd5b600080826001600160a01b03167f00000000000000000000000000000000000000000000000000000000000000008686604051602401611282929190611b29565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516112c09190611b58565b600060405180830381855af49150503d80600081146112fb576040519150601f19603f3d011682016040523d82523d6000602084013e611300565b606091505b50915091508161131257805160208201fd5b50505050505050565b6000546001600160a01b0316331461134657604051635fc483c560e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b61138e604051806060016040528060008152602001600081526020016000151581525090565b506000908152600960209081526040918290208251606081018452815481526001820154928101929092526002015460ff1615159181019190915290565b6000546001600160a01b031633146113f757604051635fc483c560e01b815260040160405180910390fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b0316331461144457604051635fc483c560e01b815260040160405180910390fd5b600780546001600160a01b0319166001600160a01b0392909216919091179055565b60606000807f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168585604051610abc929190611acc565b60006040516323b872dd60e01b81526001600160a01b03851660048201526001600160a01b03841660248201528260448201526020600060648360008a5af13d15601f3d116001600051141617169150508061153f5760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b60448201526064015b60405180910390fd5b5050505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b038416016115e4576000816001600160a01b03168361138890604051600060405180830381858888f193505050503d80600081146115bd576040519150601f19603f3d011682016040523d82523d6000602084013e6115c2565b606091505b5050905080610be5576040516312171d8360e31b815260040160405180910390fd5b610a226001600160a01b038416828461166f565b600080546001600160a01b0383166001600160a01b0319918216811783556001805490921690915560405190917ffbe19c9b601f5ee90b44c7390f3fa2319eba01762d34ee372aeafd59b25c7f8791a250565b6001600160a01b03166000908152600c60205260409020805460ff19166001179055565b600060405163a9059cbb60e01b81526001600160a01b0384166004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080610be55760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606401611536565b80356001600160a01b038116811461170757600080fd5b919050565b6000806040838503121561171f57600080fd5b611728836116f0565b9150611736602084016116f0565b90509250929050565b60006020828403121561175157600080fd5b61175a826116f0565b9392505050565b6000806040838503121561177457600080fd5b61177d836116f0565b946020939093013593505050565b6000806000606084860312156117a057600080fd5b6117a9846116f0565b92506117b7602085016116f0565b9150604084013590509250925092565b60008083601f8401126117d957600080fd5b50813567ffffffffffffffff8111156117f157600080fd5b60208301915083602082850101111561180957600080fd5b9250929050565b6000806020838503121561182357600080fd5b823567ffffffffffffffff81111561183a57600080fd5b611846858286016117c7565b90969095509350505050565b60005b8381101561186d578181015183820152602001611855565b50506000910152565b6000815180845261188e816020860160208601611852565b601f01601f19169290920160200192915050565b60208152600061175a6020830184611876565b6000806000606084860312156118ca57600080fd5b6118d3846116f0565b92506118e1602085016116f0565b91506118ef604085016116f0565b90509250925092565b60006020828403121561190a57600080fd5b5035919050565b60208152815160208201526000602083015161193860408401826001600160a01b03169052565b5060408301516001600160a01b03811660608401525060608301516001600160a01b038116608084015250608083015163ffffffff811660a08401525060a08301516001600160a01b03811660c08401525060c08301516001600160a01b03811660e08401525060e08301516101006119bb818501836001600160a01b03169052565b840151610120848101919091528401516101408085019190915284015161016080850191909152840151610180808501529050610b0e6101a0840182611876565b600080600060608486031215611a1157600080fd5b611a1a846116f0565b9250602084013591506118ef604085016116f0565b60008060008060608587031215611a4557600080fd5b843560ff81168114611a5657600080fd5b9350602085013563ffffffff81168114611a6f57600080fd5b9250604085013567ffffffffffffffff811115611a8b57600080fd5b611a97878288016117c7565b95989497509550505050565b634e487b7160e01b600052601160045260246000fd5b8082018082111561091157610911611aa3565b8183823760009101908152919050565b600181811c90821680611af057607f821691505b602082108103611b1057634e487b7160e01b600052602260045260246000fd5b50919050565b8181038181111561091157610911611aa3565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b60008251611b6a818460208701611852565b919091019291505056fea2646970667358221220cd96527e70faa197907f020270d6f14fa9f311e4fcdd8e75b324bd0863a011d464736f6c63430008130033000000000000000000000000a5acba07788f16b4790fcbb09ca3b7fc8dd053a20000000000000000000000009033472ec5dcf3e2905ed93108de5f8961005f40000000000000000000000000fd6b5c873faf51a9a9968eeaf31ec2c9c93dc2a600000000000000000000000056acf08c6c6d64f2cdb01b9ab7d35fa9a023662a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000000000000000000000000000000000000000002a30000000000000000000000000d6bdbd7238281667bb658bcdd1d662ccc2ef5b2e000000000000000000000000a5a197e5668524b2681d1bcf4109522cf7818f95
Deployed Bytecode
0x60806040526004361061026b5760003560e01c806374f8d3fd11610144578063b3b4b6bc116100b6578063e1282c5c1161007a578063e1282c5c146107ff578063e9899ed214610843578063f36ba4d814610863578063f5b841e214610883578063f8281486146108b7578063fe9e60d3146108d757600080fd5b8063b3b4b6bc1461075d578063b746078a14610791578063c66eaeb6146107a4578063cc6dc63a146107b7578063df2ebdbb146107d757600080fd5b8063823d008811610108578063823d0088146106b45780638da5cb5b146106c9578063967aef08146106e75780639ed0cb1314610707578063a42dce8014610727578063ae3100c01461074757600080fd5b806374f8d3fd146105d957806376479d1b1461061c578063795d86b81461063c5780637f660b011461065c57806380f7013e1461067c57600080fd5b80633af32abf116101dd5780635b94db27116101a15780635b94db27146104f55780636a0706db146105155780636a7372da146105355780636afdd85014610565578063733957f8146105995780637373161f146105b957600080fd5b80633af32abf1461041e5780633bd1adec1461044e5780633cbc7eaa146104635780633de408a11461048a5780634c7a7732146104c857600080fd5b80631e789c361161022f5780631e789c361461034257806320798eb71461038b57806320f99c0a146103a057806320ff430b146103be5780632a022241146103de57806331feeadd146103fe57600080fd5b80630b345879146102775780630c0a0ccb146102b45780630cb352e0146102e25780630e4bfd6e1461030257806312f07c251461032257600080fd5b3661027257005b600080fd5b34801561028357600080fd5b50600454610297906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b3480156102c057600080fd5b506102d46102cf36600461170c565b6108ea565b6040519081526020016102ab565b3480156102ee57600080fd5b50600554610297906001600160a01b031681565b34801561030e57600080fd5b50600354610297906001600160a01b031681565b34801561032e57600080fd5b50600254610297906001600160a01b031681565b34801561034e57600080fd5b5061037b61035d36600461173f565b6001600160a01b03166000908152600c602052604090205460ff1690565b60405190151581526020016102ab565b61039e610399366004611761565b610917565b005b3480156103ac57600080fd5b506001546001600160a01b0316610297565b3480156103ca57600080fd5b5061039e6103d936600461178b565b610a47565b6103f16103ec366004611810565b610a7d565b6040516102ab91906118a2565b34801561040a57600080fd5b5061039e6104193660046118b5565b610b16565b34801561042a57600080fd5b5061037b61043936600461173f565b600d6020526000908152604090205460ff1681565b34801561045a57600080fd5b5061039e610beb565b34801561046f57600080fd5b50610478600181565b60405160ff90911681526020016102ab565b34801561049657600080fd5b506102d46104a53660046118b5565b601060209081526000938452604080852082529284528284209052825290205481565b3480156104d457600080fd5b506104e86104e33660046118f8565b610c21565b6040516102ab9190611911565b34801561050157600080fd5b5061039e61051036600461173f565b610dcb565b34801561052157600080fd5b5061039e61053036600461173f565b610e40565b34801561054157600080fd5b5061037b6105503660046118f8565b600f6020526000908152604090205460ff1681565b34801561057157600080fd5b506102977f000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba381565b3480156105a557600080fd5b5061039e6105b436600461173f565b610e8d565b3480156105c557600080fd5b5061039e6105d43660046118f8565b610eda565b3480156105e557600080fd5b506102976105f4366004611761565b6001600160a01b039182166000908152600b6020908152604080832093835292905220541690565b34801561062857600080fd5b5061039e61063736600461173f565b610f0a565b34801561064857600080fd5b5061039e61065736600461173f565b610fd8565b34801561066857600080fd5b50600654610297906001600160a01b031681565b34801561068857600080fd5b506102d461069736600461170c565b600e60209081526000928352604080842090915290825290205481565b3480156106c057600080fd5b50610478600281565b3480156106d557600080fd5b506000546001600160a01b0316610297565b3480156106f357600080fd5b5061039e610702366004611761565b611046565b34801561071357600080fd5b5061039e6107223660046119fc565b611109565b34801561073357600080fd5b5061039e61074236600461173f565b611171565b34801561075357600080fd5b506102d460085481565b34801561076957600080fd5b506102977f000000000000000000000000a5a197e5668524b2681d1bcf4109522cf7818f9581565b61039e61079f366004611810565b6111be565b61039e6107b2366004611a2f565b6111e9565b3480156107c357600080fd5b5061039e6107d236600461173f565b61131b565b3480156107e357600080fd5b5061029773eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81565b34801561080b57600080fd5b5061081f61081a3660046118f8565b611368565b604080518251815260208084015190820152918101511515908201526060016102ab565b34801561084f57600080fd5b5061039e61085e36600461173f565b6113cc565b34801561086f57600080fd5b5061039e61087e36600461173f565b611419565b34801561088f57600080fd5b506102977f000000000000000000000000d6bdbd7238281667bb658bcdd1d662ccc2ef5b2e81565b3480156108c357600080fd5b50600754610297906001600160a01b031681565b6103f16108e5366004611810565b611466565b6001600160a01b038083166000908152600e60209081526040808320938516835292905220545b92915050565b336000908152600e602090815260408083206001600160a01b0386168452909152902054610946908290611ab9565b336000908152600e602090815260408083206001600160a01b03871680855292529091209190915573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed1901610a27578034146109a957604051634eba4d4960e11b815260040160405180910390fd5b6007546040516000916001600160a01b03169061138890849084818181858888f193505050503d80600081146109fb576040519150601f19603f3d011682016040523d82523d6000602084013e610a00565b606091505b5050905080610a22576040516312171d8360e31b815260040160405180910390fd5b505050565b600754610a43906001600160a01b0384811691339116846114a5565b5050565b6000546001600160a01b03163314610a7257604051635fc483c560e01b815260040160405180910390fd5b610a22838284611546565b60606000807f000000000000000000000000d6bdbd7238281667bb658bcdd1d662ccc2ef5b2e6001600160a01b03168585604051610abc929190611acc565b600060405180830381855af49150503d8060008114610af7576040519150601f19603f3d011682016040523d82523d6000602084013e610afc565b606091505b509150915081610b0e57805160208201fd5b949350505050565b6001600160a01b03808416600090815260106020908152604080832086851684528252808320938516835292905220548015610be5576001600160a01b038481166000818152601060209081526040808320888616808552908352818420958816808552959092528083209290925590516362524dd760e01b81526004810193909352602483018490526044830191909152906362524dd790606401600060405180830381600087803b158015610bcc57600080fd5b505af1158015610be0573d6000803e3d6000fd5b505050505b50505050565b6001546001600160a01b03163314610c1657604051637c91ccdd60e01b815260040160405180910390fd5b610c1f336115f8565b565b604080516101808101825260008082526020820181905291810182905260608082018390526080820183905260a0820183905260c0820183905260e08201839052610100820183905261012082018390526101408201929092526101608101919091526000828152600a60208181526040928390208351610180810185528154815260018201546001600160a01b0390811693820193909352600282015483169481019490945260038101548083166060860152600160a01b900463ffffffff1660808501526004810154821660a08501526005810154821660c0850152600681015490911660e0840152600781015461010084015260088101546101208401526009810154610140840152908101805461016084019190610d4290611adc565b80601f0160208091040260200160405190810160405280929190818152602001828054610d6e90611adc565b8015610dbb5780601f10610d9057610100808354040283529160200191610dbb565b820191906000526020600020905b815481529060010190602001808311610d9e57829003601f168201915b5050505050815250509050919050565b6000546001600160a01b03163314610df657604051635fc483c560e01b815260040160405180910390fd5b600180546001600160a01b0319166001600160a01b0383169081179091556040517f906a1c6bd7e3091ea86693dd029a831c19049ce77f1dce2ce0bab1cacbabce2290600090a250565b6000546001600160a01b03163314610e6b57604051635fc483c560e01b815260040160405180910390fd5b600480546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610eb857604051635fc483c560e01b815260040160405180910390fd5b600580546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b03163314610f0557604051635fc483c560e01b815260040160405180910390fd5b600855565b6000546001600160a01b03163314610f3557604051635fc483c560e01b815260040160405180910390fd5b6001600160a01b0381166000908152600d602052604090205460ff1615610f6f5760405163406c5bd360e01b815260040160405180910390fd5b6001600160a01b0381166000908152600c602052604090205460ff1615610fa957604051633ba24ff960e11b815260040160405180910390fd5b6001600160a01b0381166000908152600d60205260409020805460ff19166001179055610fd58161164b565b50565b6000546001600160a01b0316331461100357604051635fc483c560e01b815260040160405180910390fd5b6001600160a01b0381166000908152600c602052604090205460ff161561103d57604051633ba24ff960e11b815260040160405180910390fd5b610fd58161164b565b336000908152600e602090815260408083206001600160a01b0386168452909152902054611075908290611b16565b336000818152600e602090815260408083206001600160a01b038881168086529190935292819020949094556007549351632385922d60e01b81526004810192909252602482018590526044820192909252911690632385922d90606401600060405180830381600087803b1580156110ed57600080fd5b505af1158015611101573d6000803e3d6000fd5b505050505050565b6000546001600160a01b0316331461113457604051635fc483c560e01b815260040160405180910390fd5b6001600160a01b039081166000908152600b60209081526040808320948352939052919091208054919092166001600160a01b0319909116179055565b6000546001600160a01b0316331461119c57604051635fc483c560e01b815260040160405180910390fd5b600680546001600160a01b0319166001600160a01b0392909216919091179055565b6003546001600160a01b03163314610a4357604051631bd147a760e01b815260040160405180910390fd5b600060001960ff86160161121a57507f000000000000000000000000d6bdbd7238281667bb658bcdd1d662ccc2ef5b2e5b6001600160a01b03811661124157604051631bd147a760e01b815260040160405180910390fd5b600080826001600160a01b03167fb746078a000000000000000000000000000000000000000000000000000000008686604051602401611282929190611b29565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516112c09190611b58565b600060405180830381855af49150503d80600081146112fb576040519150601f19603f3d011682016040523d82523d6000602084013e611300565b606091505b50915091508161131257805160208201fd5b50505050505050565b6000546001600160a01b0316331461134657604051635fc483c560e01b815260040160405180910390fd5b600280546001600160a01b0319166001600160a01b0392909216919091179055565b61138e604051806060016040528060008152602001600081526020016000151581525090565b506000908152600960209081526040918290208251606081018452815481526001820154928101929092526002015460ff1615159181019190915290565b6000546001600160a01b031633146113f757604051635fc483c560e01b815260040160405180910390fd5b600380546001600160a01b0319166001600160a01b0392909216919091179055565b6000546001600160a01b0316331461144457604051635fc483c560e01b815260040160405180910390fd5b600780546001600160a01b0319166001600160a01b0392909216919091179055565b60606000807f000000000000000000000000a5a197e5668524b2681d1bcf4109522cf7818f956001600160a01b03168585604051610abc929190611acc565b60006040516323b872dd60e01b81526001600160a01b03851660048201526001600160a01b03841660248201528260448201526020600060648360008a5af13d15601f3d116001600051141617169150508061153f5760405162461bcd60e51b81526020600482015260146024820152731514905394d1915497d19493d357d1905253115160621b60448201526064015b60405180910390fd5b5050505050565b73eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed196001600160a01b038416016115e4576000816001600160a01b03168361138890604051600060405180830381858888f193505050503d80600081146115bd576040519150601f19603f3d011682016040523d82523d6000602084013e6115c2565b606091505b5050905080610be5576040516312171d8360e31b815260040160405180910390fd5b610a226001600160a01b038416828461166f565b600080546001600160a01b0383166001600160a01b0319918216811783556001805490921690915560405190917ffbe19c9b601f5ee90b44c7390f3fa2319eba01762d34ee372aeafd59b25c7f8791a250565b6001600160a01b03166000908152600c60205260409020805460ff19166001179055565b600060405163a9059cbb60e01b81526001600160a01b0384166004820152826024820152602060006044836000895af13d15601f3d1160016000511416171691505080610be55760405162461bcd60e51b815260206004820152600f60248201526e1514905394d1915497d19052531151608a1b6044820152606401611536565b80356001600160a01b038116811461170757600080fd5b919050565b6000806040838503121561171f57600080fd5b611728836116f0565b9150611736602084016116f0565b90509250929050565b60006020828403121561175157600080fd5b61175a826116f0565b9392505050565b6000806040838503121561177457600080fd5b61177d836116f0565b946020939093013593505050565b6000806000606084860312156117a057600080fd5b6117a9846116f0565b92506117b7602085016116f0565b9150604084013590509250925092565b60008083601f8401126117d957600080fd5b50813567ffffffffffffffff8111156117f157600080fd5b60208301915083602082850101111561180957600080fd5b9250929050565b6000806020838503121561182357600080fd5b823567ffffffffffffffff81111561183a57600080fd5b611846858286016117c7565b90969095509350505050565b60005b8381101561186d578181015183820152602001611855565b50506000910152565b6000815180845261188e816020860160208601611852565b601f01601f19169290920160200192915050565b60208152600061175a6020830184611876565b6000806000606084860312156118ca57600080fd5b6118d3846116f0565b92506118e1602085016116f0565b91506118ef604085016116f0565b90509250925092565b60006020828403121561190a57600080fd5b5035919050565b60208152815160208201526000602083015161193860408401826001600160a01b03169052565b5060408301516001600160a01b03811660608401525060608301516001600160a01b038116608084015250608083015163ffffffff811660a08401525060a08301516001600160a01b03811660c08401525060c08301516001600160a01b03811660e08401525060e08301516101006119bb818501836001600160a01b03169052565b840151610120848101919091528401516101408085019190915284015161016080850191909152840151610180808501529050610b0e6101a0840182611876565b600080600060608486031215611a1157600080fd5b611a1a846116f0565b9250602084013591506118ef604085016116f0565b60008060008060608587031215611a4557600080fd5b843560ff81168114611a5657600080fd5b9350602085013563ffffffff81168114611a6f57600080fd5b9250604085013567ffffffffffffffff811115611a8b57600080fd5b611a97878288016117c7565b95989497509550505050565b634e487b7160e01b600052601160045260246000fd5b8082018082111561091157610911611aa3565b8183823760009101908152919050565b600181811c90821680611af057607f821691505b602082108103611b1057634e487b7160e01b600052602260045260246000fd5b50919050565b8181038181111561091157610911611aa3565b60208152816020820152818360408301376000818301604090810191909152601f909201601f19160101919050565b60008251611b6a818460208701611852565b919091019291505056fea2646970667358221220cd96527e70faa197907f020270d6f14fa9f311e4fcdd8e75b324bd0863a011d464736f6c63430008130033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000a5acba07788f16b4790fcbb09ca3b7fc8dd053a20000000000000000000000009033472ec5dcf3e2905ed93108de5f8961005f40000000000000000000000000fd6b5c873faf51a9a9968eeaf31ec2c9c93dc2a600000000000000000000000056acf08c6c6d64f2cdb01b9ab7d35fa9a023662a0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba30000000000000000000000000000000000000000000000000000000000002a30000000000000000000000000d6bdbd7238281667bb658bcdd1d662ccc2ef5b2e000000000000000000000000a5a197e5668524b2681d1bcf4109522cf7818f95
-----Decoded View---------------
Arg [0] : _owner (address): 0xa5acBA07788f16B4790FCBb09cA3b7Fc8dd053A2
Arg [1] : _mofaSigner (address): 0x9033472EC5dCf3e2905ED93108dE5f8961005F40
Arg [2] : _switchboardRouter (address): 0xFD6b5c873fAf51a9a9968eeaF31EC2C9C93DC2A6
Arg [3] : _swapExecutor (address): 0x56AcF08C6C6d64f2CDB01b9Ab7D35FA9a023662A
Arg [4] : _calldataRouter (address): 0x0000000000000000000000000000000000000000
Arg [5] : _permit2 (address): 0x000000000022D473030F116dDEE9F6B43aC78BA3
Arg [6] : _expiryBuffer (uint256): 10800
Arg [7] : _singleOutputRequestImpl (address): 0xd6bdbd7238281667bb658BCDD1d662Ccc2EF5b2E
Arg [8] : _swapOutputRequestImpl (address): 0xa5a197e5668524b2681d1BCf4109522Cf7818F95
-----Encoded View---------------
9 Constructor Arguments found :
Arg [0] : 000000000000000000000000a5acba07788f16b4790fcbb09ca3b7fc8dd053a2
Arg [1] : 0000000000000000000000009033472ec5dcf3e2905ed93108de5f8961005f40
Arg [2] : 000000000000000000000000fd6b5c873faf51a9a9968eeaf31ec2c9c93dc2a6
Arg [3] : 00000000000000000000000056acf08c6c6d64f2cdb01b9ab7d35fa9a023662a
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [5] : 000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3
Arg [6] : 0000000000000000000000000000000000000000000000000000000000002a30
Arg [7] : 000000000000000000000000d6bdbd7238281667bb658bcdd1d662ccc2ef5b2e
Arg [8] : 000000000000000000000000a5a197e5668524b2681d1bcf4109522cf7818f95
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in S
Multichain Portfolio | 35 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.