Verified contractPartialMIT
ArbitrumBridgeAdapter
Address0x166fcdb88b4be6eccba5a3e11eec02dd93d0edeb
- Balance
0 ETH
- Transactions
0
- Compiler
solc 0.8.30
- Same code
Only this contract
Details
- Compiler
- solc 0.8.30+commit.73712a01
- Language
- solidity
- Optimization
- Yes, 44,444,444 runs
- EVM version
- osaka
- Via IR
- yes
- License
- MIT
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,326,050
- Creation transaction
- 0xc0d406cade…4bc49d2594
12 files
- src/adapters/arbitrum/ArbitrumBridgeAdapter.solmain3.32 KB
- lib/ks-common-sc/lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol182 B
- lib/ks-common-sc/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol2.78 KB
- lib/ks-common-sc/src/libraries/CustomRevert.sol4.75 KB
- lib/ks-common-sc/src/libraries/token/TokenHelper.sol8.42 KB
- src/adapters/BaseBridgeAdapter.sol792 B
- src/interfaces/adapters/IBridgeAdapter.sol910 B
- src/interfaces/adapters/arbitrum/IArbitrumBridgeAdapter.sol1.85 KB
- src/libraries/BitMask.sol388 B
- src/types/BoolAddress.sol1.28 KB
- src/vendors/arbitrum/IInbox.sol3.02 KB
- src/vendors/arbitrum/IL1GatewayRouter.sol1.89 KB
src/adapters/arbitrum/ArbitrumBridgeAdapter.sol
// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;
import {IBridgeAdapter} from '../../interfaces/adapters/IBridgeAdapter.sol';
import {
IArbitrumBridgeAdapter
} from '../../interfaces/adapters/arbitrum/IArbitrumBridgeAdapter.sol';
import {BaseBridgeAdapter} from '../BaseBridgeAdapter.sol';
import {IInbox} from '../../vendors/arbitrum/IInbox.sol';
import {IL1GatewayRouter} from '../../vendors/arbitrum/IL1GatewayRouter.sol';
import {TokenHelper} from 'ks-common-sc/src/libraries/token/TokenHelper.sol';
/// @title ArbitrumBridgeAdapter
/// @notice Deposits into an Arbitrum chain through its native bridge: native through the inbox,
/// tokens through the gateway router.
contract ArbitrumBridgeAdapter is BaseBridgeAdapter, IArbitrumBridgeAdapter {
using TokenHelper for address;
/**
* @inheritdoc IBridgeAdapter
* @dev `result` is the encoded inbox message number of the retryable ticket.
*/
function bridge(
address inputToken,
uint256 inputAmount,
bytes32, // destinationChainId
bytes32, // bridgeOutputToken
bytes calldata bridgeData
) external payable onlyDelegateCall returns (bytes memory result) {
/// @dev The params are fully static, so they are encoded without a leading offset word.
BridgeAdapterParams calldata params;
assembly ('memory-safe') {
params := bridgeData.offset
}
uint256 maxSubmissionCost =
quoteSubmissionCost(params.inbox, params.gatewayRouter, inputToken, block.basefee);
uint256 fee = maxSubmissionCost + params.gasLimit * params.maxFeePerGas;
if (inputToken.isNative()) {
/// @dev The router's whole native balance is deposited, less the L2 fee.
inputAmount = address(this).balance - fee;
/// @dev `depositEth` credits the caller's L2 alias, so the deposit is a retryable ticket to
/// `to`. The unsafe variant keeps the refund addresses unaliased when `to` has code on L1.
return abi.encode(
IInbox(params.inbox).unsafeCreateRetryableTicket{value: inputAmount + fee}(
params.to,
inputAmount,
maxSubmissionCost,
params.to,
params.to,
params.gasLimit,
params.maxFeePerGas,
''
)
);
}
(bool shouldApprove, address gateway) = params.gateway.unpack();
if (shouldApprove) {
inputToken.forceApprove(gateway, type(uint256).max);
}
/// @dev The gateway returns the encoded inbox message number.
return IL1GatewayRouter(params.gatewayRouter).outboundTransfer{value: fee}(
inputToken,
params.to,
inputAmount,
params.gasLimit,
params.maxFeePerGas,
abi.encode(maxSubmissionCost, '')
);
}
/**
* @inheritdoc IArbitrumBridgeAdapter
* @dev A token deposit's ticket carries the gateway's calldata, whose length does not depend on
* the sender, recipient or amount.
*/
function quoteSubmissionCost(address inbox, address gatewayRouter, address token, uint256 baseFee)
public
view
returns (uint256 maxSubmissionCost)
{
uint256 dataLength = token.isNative()
? 0
: IL1GatewayRouter(gatewayRouter)
.getOutboundCalldata(token, address(0), address(0), 0, '')
.length;
return IInbox(inbox).calculateRetryableSubmissionFee(dataLength, baseFee);
}
}
lib/ks-common-sc/lib/openzeppelin-contracts/contracts/interfaces/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (interfaces/IERC20.sol)
pragma solidity >=0.4.16;
import {IERC20} from "../token/ERC20/IERC20.sol";
lib/ks-common-sc/lib/openzeppelin-contracts/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.4.0) (token/ERC20/IERC20.sol)
pragma solidity >=0.4.16;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
lib/ks-common-sc/src/libraries/CustomRevert.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/// @title Library for reverting with custom errors efficiently
/// @notice Contains functions for reverting with custom errors with different argument types efficiently
/// @dev To use this library, declare `using CustomRevert for bytes4;` and replace `revert CustomError()` with
/// `CustomError.selector.revertWith()`
/// @dev The functions may tamper with the free memory pointer but it is fine since the call context is exited immediately
library CustomRevert {
/// @dev ERC-7751 error for wrapping bubbled up reverts
error WrappedError(address target, bytes4 selector, bytes reason, bytes details);
/// @dev Reverts with the selector of a custom error in the scratch space
function revertWith(bytes4 selector) internal pure {
assembly ('memory-safe') {
mstore(0, selector)
revert(0, 0x04)
}
}
/// @dev Reverts with a custom error with an address argument in the scratch space
function revertWith(bytes4 selector, address addr) internal pure {
assembly ('memory-safe') {
mstore(0, selector)
mstore(0x04, and(addr, 0xffffffffffffffffffffffffffffffffffffffff))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with an int24 argument in the scratch space
function revertWith(bytes4 selector, int24 value) internal pure {
assembly ('memory-safe') {
mstore(0, selector)
mstore(0x04, signextend(2, value))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with a uint160 argument in the scratch space
function revertWith(bytes4 selector, uint160 value) internal pure {
assembly ('memory-safe') {
mstore(0, selector)
mstore(0x04, and(value, 0xffffffffffffffffffffffffffffffffffffffff))
revert(0, 0x24)
}
}
/// @dev Reverts with a custom error with two int24 arguments
function revertWith(bytes4 selector, int24 value1, int24 value2) internal pure {
assembly ('memory-safe') {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), signextend(2, value1))
mstore(add(fmp, 0x24), signextend(2, value2))
revert(fmp, 0x44)
}
}
/// @dev Reverts with a custom error with two uint160 arguments
function revertWith(bytes4 selector, uint160 value1, uint160 value2) internal pure {
assembly ('memory-safe') {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
revert(fmp, 0x44)
}
}
/// @dev Reverts with a custom error with two address arguments
function revertWith(bytes4 selector, address value1, address value2) internal pure {
assembly ('memory-safe') {
let fmp := mload(0x40)
mstore(fmp, selector)
mstore(add(fmp, 0x04), and(value1, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(add(fmp, 0x24), and(value2, 0xffffffffffffffffffffffffffffffffffffffff))
revert(fmp, 0x44)
}
}
/// @notice bubble up the revert message returned by a call and revert with a wrapped ERC-7751 error
/// @dev this method can be vulnerable to revert data bombs
function bubbleUpAndRevertWith(
address revertingContract,
bytes4 revertingFunctionSelector,
bytes4 additionalContext
) internal pure {
bytes4 wrappedErrorSelector = WrappedError.selector;
assembly ('memory-safe') {
// Ensure the size of the revert data is a multiple of 32 bytes
let encodedDataSize := mul(div(add(returndatasize(), 31), 32), 32)
let fmp := mload(0x40)
// Encode wrapped error selector, address, function selector, offset, additional context, size, revert reason
mstore(fmp, wrappedErrorSelector)
mstore(add(fmp, 0x04), and(revertingContract, 0xffffffffffffffffffffffffffffffffffffffff))
mstore(
add(fmp, 0x24),
and(
revertingFunctionSelector,
0xffffffff00000000000000000000000000000000000000000000000000000000
)
)
// offset revert reason
mstore(add(fmp, 0x44), 0x80)
// offset additional context
mstore(add(fmp, 0x64), add(0xa0, encodedDataSize))
// size revert reason
mstore(add(fmp, 0x84), returndatasize())
// revert reason
returndatacopy(add(fmp, 0xa4), 0, returndatasize())
// size additional context
mstore(add(fmp, add(0xa4, encodedDataSize)), 0x04)
// additional context
mstore(
add(fmp, add(0xc4, encodedDataSize)),
and(additionalContext, 0xffffffff00000000000000000000000000000000000000000000000000000000)
)
revert(fmp, add(0xe4, encodedDataSize))
}
}
}
lib/ks-common-sc/src/libraries/token/TokenHelper.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {CustomRevert} from '../CustomRevert.sol';
import {IERC20} from 'openzeppelin-contracts/contracts/interfaces/IERC20.sol';
/// @title Library for transferring, approving and holding native tokens and ERC20 tokens
/// @dev This library is based on CurrencyLibrary.sol from Uniswap/v4-core and SafeTransferLib.sol from transmissions11/solmate
library TokenHelper {
/// @notice Additional context for ERC-7751 wrapped error when a native transfer fails
error NativeTransferFailed();
/// @notice Additional context for ERC-7751 wrapped error when an ERC20 transfer fails
error ERC20TransferFailed();
/// @notice Additional context for ERC-7751 wrapped error when an ERC20 approve fails
error ERC20ApproveFailed();
address internal constant NATIVE_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
function isNative(address token) internal pure returns (bool) {
return token == NATIVE_ADDRESS || token == address(0);
}
function safeTransferNative(address to, uint256 amount) internal {
if (amount == 0) return;
bool success;
assembly ('memory-safe') {
// Transfer the ETH and revert if it fails.
success := call(gas(), to, amount, 0, 0, 0, 0)
}
// revert with NativeTransferFailed, containing the bubbled up error as an argument
if (!success) {
CustomRevert.bubbleUpAndRevertWith(to, bytes4(0), NativeTransferFailed.selector);
}
}
function safeTransferERC20(address token, address to, uint256 amount) internal {
if (amount == 0) return;
bool success;
assembly ('memory-safe') {
// Get a pointer to some free memory.
let fmp := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(fmp, 0xa9059cbb00000000000000000000000000000000000000000000000000000000)
mstore(add(fmp, 4), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(fmp, 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, fmp, 68, 0, 32)
)
// Now clean the memory we used
mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here
mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here
}
// revert with ERC20TransferFailed, containing the bubbled up error as an argument
if (!success) {
CustomRevert.bubbleUpAndRevertWith(
token, IERC20.transfer.selector, ERC20TransferFailed.selector
);
}
}
function safeTransfer(address token, address to, uint256 amount) internal {
if (isNative(token)) {
safeTransferNative(to, amount);
} else {
safeTransferERC20(token, to, amount);
}
}
function safeTransferFrom(address token, address from, address to, uint256 amount) internal {
if (amount == 0) return;
bool success;
assembly ('memory-safe') {
// Get a pointer to some free memory.
let fmp := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(fmp, 0x23b872dd00000000000000000000000000000000000000000000000000000000)
mstore(add(fmp, 4), and(from, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "from" argument.
mstore(add(fmp, 36), and(to, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "to" argument.
mstore(add(fmp, 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, fmp, 100, 0, 32)
)
// Now clean the memory we used
mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `from` were stored here
mstore(add(fmp, 0x20), 0) // 4 bytes of `from` and 28 bytes of `to` were stored here
mstore(add(fmp, 0x40), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
mstore(add(fmp, 0x60), 0) // 4 bytes of `amount` were stored here
}
// revert with ERC20TransferFailed, containing the bubbled up error as an argument
if (!success) {
CustomRevert.bubbleUpAndRevertWith(
token, IERC20.transferFrom.selector, ERC20TransferFailed.selector
);
}
}
function trySafeApprove(address token, address spender, uint256 amount)
internal
returns (bool success)
{
assembly ('memory-safe') {
// Get a pointer to some free memory.
let fmp := mload(0x40)
// Write the abi-encoded calldata into memory, beginning with the function selector.
mstore(fmp, 0x095ea7b300000000000000000000000000000000000000000000000000000000)
mstore(add(fmp, 4), and(spender, 0xffffffffffffffffffffffffffffffffffffffff)) // Append and mask the "spender" argument.
mstore(add(fmp, 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, fmp, 68, 0, 32)
)
// Now clean the memory we used
mstore(fmp, 0) // 4 byte `selector` and 28 bytes of `to` were stored here
mstore(add(fmp, 0x20), 0) // 4 bytes of `to` and 28 bytes of `amount` were stored here
mstore(add(fmp, 0x40), 0) // 4 bytes of `amount` were stored here
}
}
function safeApprove(address token, address spender, uint256 amount) internal {
// revert with ERC20ApproveFailed, containing the bubbled up error as an argument
if (!trySafeApprove(token, spender, amount)) {
CustomRevert.bubbleUpAndRevertWith(
token, IERC20.approve.selector, ERC20ApproveFailed.selector
);
}
}
function forceApprove(address token, address spender, uint256 amount) internal {
// meant to be used with tokens that require the approval to be set to zero before setting it to a non-zero value, such as USDT
if (!trySafeApprove(token, spender, amount)) {
safeApprove(token, spender, 0);
safeApprove(token, spender, amount);
}
}
function balanceOf(address token, address account) internal view returns (uint256) {
if (isNative(token)) {
return account.balance;
} else {
return IERC20(token).balanceOf(account);
}
}
function selfBalance(address token) internal view returns (uint256) {
if (isNative(token)) {
return address(this).balance;
} else {
return IERC20(token).balanceOf(address(this));
}
}
}
src/adapters/BaseBridgeAdapter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IBridgeAdapter} from '../interfaces/adapters/IBridgeAdapter.sol';
/**
* @title BaseBridgeAdapter
* @notice Base for adapters that run inside a router's context.
* @dev Records its own deployment address at construction so `onlyDelegateCall` can tell the two
* apart: reached by `delegatecall`, `address(this)` is the router's, not this one's. An adapter
* that must keep storage or an identity of its own cannot use this — see `BridgeForwarder`.
*/
abstract contract BaseBridgeAdapter is IBridgeAdapter {
address internal immutable original;
constructor() {
original = address(this);
}
modifier onlyDelegateCall() {
if (original == address(this)) {
revert NotDelegateCall();
}
_;
}
}
src/interfaces/adapters/IBridgeAdapter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title IBridgeAdapter
* @notice Common entry point every bridge adapter exposes to the routers.
*/
interface IBridgeAdapter {
/// @notice Thrown when the function is not called via delegate call.
error NotDelegateCall();
/**
* @notice Bridges the tokens.
* @param inputToken The address of the input token.
* @param inputAmount The amount of the input token.
* @param destinationChainId The ID of the destination chain.
* @param bridgeOutputToken The address of the bridge output token.
* @param bridgeData The data for the bridge operation.
* @return result The result of the bridge operation.
*/
function bridge(
address inputToken,
uint256 inputAmount,
bytes32 destinationChainId,
bytes32 bridgeOutputToken,
bytes calldata bridgeData
) external payable returns (bytes memory result);
}
src/interfaces/adapters/arbitrum/IArbitrumBridgeAdapter.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {BoolAddress} from '../../../types/BoolAddress.sol';
/// @title IArbitrumBridgeAdapter
/// @notice Interface of {ArbitrumBridgeAdapter}
interface IArbitrumBridgeAdapter {
/**
* @notice Parameters for depositing into an Arbitrum chain through its native bridge.
* @param gateway The L1 gateway of the input token, as `L1GatewayRouter.getGateway` returns it,
* and whether to approve it for spending the input token. Unused for native.
* @param gatewayRouter The L1 gateway router of the destination chain. Unused for native.
* @param inbox The inbox of the destination chain.
* @param to The recipient on the destination chain. It also receives the unspent L2 fee, except
* from gateways that refund the sender. For native it can also cancel the retryable ticket and
* receives the deposit if the ticket is cancelled or expires.
* @param gasLimit The L2 gas limit of the retryable ticket.
* @param maxFeePerGas The L2 gas price bid of the retryable ticket.
*/
struct BridgeAdapterParams {
BoolAddress gateway;
address gatewayRouter;
address inbox;
address to;
uint256 gasLimit;
uint256 maxFeePerGas;
}
/**
* @notice Returns the submission cost of the retryable ticket that deposits `token`.
* @param inbox The inbox of the destination chain.
* @param gatewayRouter The L1 gateway router of the destination chain. Unused for native.
* @param token The L1 token, or the native address.
* @param baseFee The L1 base fee to price the submission at.
* @return maxSubmissionCost The submission cost the inbox charges at `baseFee`.
*/
function quoteSubmissionCost(address inbox, address gatewayRouter, address token, uint256 baseFee)
external
view
returns (uint256 maxSubmissionCost);
}
src/libraries/BitMask.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
uint256 constant MASK_1_BIT = 0x1;
uint256 constant MASK_8_BITS = 0xff;
uint256 constant MASK_24_BITS = 0xffffff;
uint256 constant MASK_127_BITS = 0x7fffffffffffffffffffffffffffffff;
uint256 constant MASK_128_BITS = 0xffffffffffffffffffffffffffffffff;
uint160 constant MASK_160_BITS = 0x00ffffffffffffffffffffffffffffffffffffffff;
src/types/BoolAddress.sol
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {MASK_160_BITS} from '../libraries/BitMask.sol';
/**
* @notice BoolAddress is packed version of solidity structure.
*
* Layout: 1 bit boolean value | 160 bits address value
*/
type BoolAddress is uint256;
using BoolAddressLibrary for BoolAddress global;
function toBoolAddress(bool boolValue, address addressValue) pure returns (BoolAddress result) {
assembly ('memory-safe') {
result := or(shl(160, boolValue), addressValue)
}
}
/**
* @title BoolAddressLibrary
* @notice Accessors for the packed {BoolAddress} type.
*/
library BoolAddressLibrary {
uint256 internal constant BOOL_VALUE_OFFSET = 160;
function boolValue(BoolAddress self) internal pure returns (bool _boolValue) {
assembly ('memory-safe') {
_boolValue := shr(BOOL_VALUE_OFFSET, self)
}
}
function addressValue(BoolAddress self) internal pure returns (address _addressValue) {
assembly ('memory-safe') {
_addressValue := and(self, MASK_160_BITS)
}
}
function unpack(BoolAddress self) internal pure returns (bool _boolValue, address _addressValue) {
assembly ('memory-safe') {
_boolValue := shr(BOOL_VALUE_OFFSET, self)
_addressValue := and(self, MASK_160_BITS)
}
}
}
src/vendors/arbitrum/IInbox.sol
// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1
// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
/// @dev The declarations of nitro-contracts v3.2.0 `src/bridge/IInbox.sol`, `IInboxBase.sol` and
/// `IDelayedMessageProvider.sol` that the adapter and its tests use, as upstream declares them.
interface IInbox {
/// @dev event emitted when a inbox message is added to the Bridge's delayed accumulator
event InboxMessageDelivered(uint256 indexed messageNum, bytes data);
/**
* @notice Put a message in the L2 inbox that can be reexecuted for some fixed amount of time if it reverts
* @dev Same as createRetryableTicket, but does not guarantee that submission will succeed by requiring the needed funds
* come from the deposit alone, rather than falling back on the user's L2 balance
* @dev Advanced usage only (does not rewrite aliases for excessFeeRefundAddress and callValueRefundAddress).
* createRetryableTicket method is the recommended standard.
* @dev Gas limit and maxFeePerGas should not be set to 1 as that is used to trigger the RetryableData error
* @param to destination L2 contract address
* @param l2CallValue call value for retryable L2 message
* @param maxSubmissionCost Max gas deducted from user's L2 balance to cover base submission fee
* @param excessFeeRefundAddress the address which receives the difference between execution fee paid and the actual execution cost
* @param callValueRefundAddress l2Callvalue gets credited here on L2 if retryable txn times out or gets cancelled
* @param gasLimit Max gas deducted from user's L2 balance to cover L2 execution. Should not be set to 1 (magic value used to trigger the RetryableData error)
* @param maxFeePerGas price bid for L2 execution. Should not be set to 1 (magic value used to trigger the RetryableData error)
* @param data ABI encoded data of L2 message
* @return unique message number of the retryable transaction
*/
function unsafeCreateRetryableTicket(
address to,
uint256 l2CallValue,
uint256 maxSubmissionCost,
address excessFeeRefundAddress,
address callValueRefundAddress,
uint256 gasLimit,
uint256 maxFeePerGas,
bytes calldata data
) external payable returns (uint256);
/**
* @notice Get the L1 fee for submitting a retryable
* @dev This fee can be paid by funds already in the L2 aliased address or by the current message value
* @dev This formula may change in the future, to future proof your code query this method instead of inlining!!
* @param dataLength The length of the retryable's calldata, in bytes
* @param baseFee The block basefee when the retryable is included in the chain, if 0 current block.basefee will be used
*/
function calculateRetryableSubmissionFee(uint256 dataLength, uint256 baseFee)
external
view
returns (uint256);
}
src/vendors/arbitrum/IL1GatewayRouter.sol
// SPDX-License-Identifier: Apache-2.0
/*
* Copyright 2020, Offchain Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
/// @dev The declarations of token-bridge-contracts v1.2.5 `IL1GatewayRouter.sol`,
/// `ITokenGateway.sol` and `IGatewayRouter.sol` that the adapter and its tests use, as upstream
/// declares them.
interface IL1GatewayRouter {
function outboundTransfer(
address _token,
address _to,
uint256 _amount,
uint256 _maxGas,
uint256 _gasPriceBid,
bytes calldata _data
) external payable returns (bytes memory);
function getOutboundCalldata(
address _token,
address _from,
address _to,
uint256 _amount,
bytes memory _data
) external view returns (bytes memory);
/**
* @notice Calculate the address used when bridging an ERC20 token
* @dev the L1 and L2 address oracles may not always be in sync.
* For example, a custom token may have been registered but not deploy or the contract self destructed.
* @param l1ERC20 address of L1 token
* @return L2 address of a bridged ERC20 token
*/
function calculateL2TokenAddress(address l1ERC20) external view returns (address);
function getGateway(address _token) external view returns (address gateway);
function inbox() external view returns (address);
}
Compiler settingsShow
{
"viaIR": true,
"metadata": {
"appendCBOR": true,
"bytecodeHash": "ipfs",
"useLiteralContent": false
},
"libraries": {},
"optimizer": {
"runs": 44444444,
"enabled": true
},
"evmVersion": "osaka",
"remappings": [
"forge-std/=lib/ks-common-sc/lib/forge-std/src/",
"hardhat/=node_modules/hardhat/",
"ks-common-sc/=lib/ks-common-sc/",
"ks-allowance-hub/=lib/ks-allowance-hub/",
"openzeppelin-contracts/=lib/ks-common-sc/lib/openzeppelin-contracts/",
"lib/ks-allowance-hub/lib/ks-common-sc/lib/openzeppelin-contracts/:erc4626-tests/=lib/ks-allowance-hub/lib/ks-common-sc/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/ks-allowance-hub/lib/ks-common-sc/lib/openzeppelin-contracts/:erc4626-tests/=lib/ks-allowance-hub/lib/ks-common-sc/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/ks-allowance-hub/lib/ks-common-sc/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/ks-allowance-hub/lib/ks-common-sc/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/ks-allowance-hub/lib/ks-common-sc/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/ks-allowance-hub/lib/ks-common-sc/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/ks-common-sc/lib/openzeppelin-contracts/:erc4626-tests/=lib/ks-common-sc/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/ks-common-sc/lib/openzeppelin-contracts/:erc4626-tests/=lib/ks-common-sc/lib/openzeppelin-contracts/lib/erc4626-tests/",
"lib/ks-common-sc/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/ks-common-sc/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"lib/ks-common-sc/lib/openzeppelin-contracts/:halmos-cheatcodes/=lib/ks-common-sc/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/",
"@openzeppelin/contracts/=lib/ks-common-sc/lib/openzeppelin-contracts/contracts/",
"erc4626-tests/=lib/ks-common-sc/lib/openzeppelin-contracts/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/ks-common-sc/lib/openzeppelin-contracts/lib/halmos-cheatcodes/src/"
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.