Latest 25 from a total of 1,831 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Execute | 143145435 | 8 days ago | IN | 0 ETH | 0.000000024706 | ||||
| Forward Settleme... | 143143384 | 8 days ago | IN | 0.0001 ETH | 0.000000009142 | ||||
| Create Order | 143142098 | 8 days ago | IN | 0 ETH | 0.000000002212 | ||||
| Create Order | 143140284 | 8 days ago | IN | 0 ETH | 0.000000076755 | ||||
| Create Order | 143139902 | 8 days ago | IN | 0.00037 ETH | 0.000000004723 | ||||
| Fill Order | 143138976 | 8 days ago | IN | 0.129983803586552 ETH | 0.000000008146 | ||||
| Forward Settleme... | 143137863 | 8 days ago | IN | 0.00001324 ETH | 0.000228234406 | ||||
| Fill Order | 143137711 | 8 days ago | IN | 0 ETH | 0.000000013141 | ||||
| Create Order | 143137349 | 8 days ago | IN | 0.0427 ETH | 0.000000008996 | ||||
| Fill Order | 143137335 | 8 days ago | IN | 0.040994408233834 ETH | 0.000000010229 | ||||
| Create Order | 143135437 | 8 days ago | IN | 0 ETH | 0.000000001907 | ||||
| Create Order | 143135058 | 8 days ago | IN | 0 ETH | 0.000000002176 | ||||
| Fill Order | 143135037 | 8 days ago | IN | 0 ETH | 0.00000001271 | ||||
| Create Order | 143133853 | 8 days ago | IN | 0 ETH | 0.000000003937 | ||||
| Create Order | 143132699 | 8 days ago | IN | 0 ETH | 0.000000012197 | ||||
| Fill Order | 143132112 | 8 days ago | IN | 0 ETH | 0.000000028747 | ||||
| Execute | 143132087 | 8 days ago | IN | 0 ETH | 0.000000028449 | ||||
| Fill Order | 143131221 | 8 days ago | IN | 0.002099093713576 ETH | 0.000000010635 | ||||
| Fill Order | 143130756 | 8 days ago | IN | 0 ETH | 0.000000031038 | ||||
| Execute | 143129232 | 8 days ago | IN | 0 ETH | 0.000000037853 | ||||
| Create Order | 143127675 | 8 days ago | IN | 0 ETH | 0.000000021223 | ||||
| Create Order | 143125375 | 9 days ago | IN | 0 ETH | 0.000000032311 | ||||
| Create Order | 143125323 | 9 days ago | IN | 0 ETH | 0.000000021643 | ||||
| Create Order | 143125293 | 9 days ago | IN | 0 ETH | 0.000000021057 | ||||
| Create Order | 143125251 | 9 days ago | IN | 0 ETH | 0.000000021307 |
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | |||
|---|---|---|---|---|---|---|
| 143145435 | 8 days ago | 0.0430697387 ETH | ||||
| 143143384 | 8 days ago | 0.0001 ETH | ||||
| 143138976 | 8 days ago | 0.129983803586552 ETH | ||||
| 143137863 | 8 days ago | 0.00001324 ETH | ||||
| 143137335 | 8 days ago | 0.040994408233834 ETH | ||||
| 143132087 | 8 days ago | 0.117999646 ETH | ||||
| 143131221 | 8 days ago | 0.002099093713576 ETH | ||||
| 143129232 | 8 days ago | 0.06921963238 ETH | ||||
| 143121544 | 9 days ago | 0.022997004541774 ETH | ||||
| 143121513 | 9 days ago | 0.00001309 ETH | ||||
| 143121248 | 9 days ago | 0.013998090096604 ETH | ||||
| 143117529 | 9 days ago | 0.22082867768 ETH | ||||
| 143113064 | 9 days ago | 0.036452677194027 ETH | ||||
| 143111683 | 9 days ago | 0.020137355117805 ETH | ||||
| 143110881 | 9 days ago | 0.028996270487196 ETH | ||||
| 143110614 | 9 days ago | 0.022097129198195 ETH | ||||
| 143110066 | 9 days ago | 0.02236704987986 ETH | ||||
| 143105282 | 9 days ago | 0.019997369897347 ETH | ||||
| 143104112 | 9 days ago | 0.00001374 ETH | ||||
| 143102379 | 9 days ago | 0.024996668366028 ETH | ||||
| 143102199 | 9 days ago | 0.019997263211814 ETH | ||||
| 143097625 | 9 days ago | 0.0172993067 ETH | ||||
| 143092722 | 9 days ago | 0.702865418951625 ETH | ||||
| 143092407 | 9 days ago | 0.127983862677762 ETH | ||||
| 143091995 | 9 days ago | 0.0001 ETH |
Cross-Chain Transactions
Loading...
Loading
Contract Source Code Verified (Exact Match)
Contract Name:
Spoke
Compiler Version
v0.8.23+commit.f704f362
Optimization Enabled:
Yes with 9999 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {AxelarExecutable} from "./axelar/AxelarExecutable.sol";
import {IAxelarGateway} from "./interfaces/IAxelarGateway.sol";
import {IAxelarGasService} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol";
import {InterchainAddressTracker} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/utils/InterchainAddressTracker.sol";
import {OApp, Origin, MessagingFee} from "./oapp/OApp.sol";
import {ILayerZeroEndpointV2} from "./oapp/interfaces/ILayerZeroEndpointV2.sol";
import {OptionsBuilder} from "@layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import {Initializable} from "@openzeppelin/contracts/proxy/utils/Initializable.sol";
import {ReentrancyGuard} from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {ISquidMulticall} from "./interfaces/ISquidMulticall.sol";
import {ISpoke} from "./interfaces/ISpoke.sol";
import {Utils} from "./libraries/Utils.sol";
contract Spoke is ISpoke, OApp, AxelarExecutable, Initializable, InterchainAddressTracker, ReentrancyGuard {
using Address for address payable;
using SafeERC20 for IERC20;
using OptionsBuilder for bytes;
/// @dev token address => fee amount collected in this token
mapping(address => uint256) public tokenToCollectedFees;
mapping(bytes32 => OrderStatus) public orderHashToStatus;
mapping(bytes32 => SettlementStatus) public settlementToStatus;
IAxelarGasService public gasService;
ISquidMulticall public squidMulticall;
address public feeCollector;
/// @dev Chain name must follow Axelar format
/// https://docs.axelar.dev/dev/reference/mainnet-contract-addresses
string public hubChainName;
string public hubAddress;
/// @dev Endpoint must follow LayerZero format
/// https://docs.layerzero.network/v2/developers/evm/technical-reference/deployed-contracts
uint32 public hubEndpoint;
bytes32 public hubAddressBytes32;
modifier onlyFeeCollector() {
if (msg.sender != feeCollector) revert OnlyFeeCollector();
_;
}
modifier onlyTrustedAddress(string calldata fromChainName, string calldata fromContractAddress) {
if (!isTrustedAddress(fromChainName, fromContractAddress)) revert OnlyTrustedAddress();
_;
}
constructor()
AxelarExecutable(0xC012A11111111111111111111111111111111111)
OApp(0xC012A11111111111111111111111111111111111, msg.sender)
Ownable(msg.sender)
{}
//////////////////////////////////////////////////////////////
// //
// Initializer //
// //
//////////////////////////////////////////////////////////////
/// @notice One-time use initialize function for the protocol. This function is required to be called
/// within the deploying transaction to set the initial state of the Spoke.sol contract. These parameters
/// cannot be updated after initialization.
/// @notice The _hubChainName and _hubAddress will be set as the trusted chain and address for Axelar
/// general message passing. Only the trusted Hub.sol contract can execute interchain transactions
/// in the Spoke.sol contract.
/// @param _axelarGateway Address of the relevant Axelar's AxelarGateway.sol contract deployment.
/// @param _axelarGasService Address of the relevant Axelar's AxelarGasService.sol contract deployment.
/// @param _squidMulticall Address of the relevant Squid's SquidMulticall.sol contract deployment.
/// @param _feeCollector Address of the EOA that would collect fees from the protocol. Recommended to use
/// a multisig wallet.
/// @param _hubChainName Chain name of the chain the Hub.sol contract will be deployed to, must follow
/// Axelar's chain name format. This chain name will be passed to the Axelar Gateway to determine the
/// target chain for general message passing from the Spoke.
/// @param _hubAddress String for the address of the relevant Hub.sol contract, this should be computed
/// deterministically using the CREATE2 opcode to remain permissionless.
/// @param _endpoint Address of the LayerZero EndpointV2 contract, responsible for managing cross-chain
/// communications.
/// @param _owner Address set as the owner of the Spoke.sol contract upon deployment.
/// @param _hub Address of the relevant Hub.sol contract, this should be computed deterministically
/// using the CREATE2 opcode to remain permissionless.
/// @param _hubEndpoint Endpoint ID as specified by LayerZero:
/// https://docs.layerzero.network/v2/developers/evm/technical-reference/deployed-contracts
function initialize(
IAxelarGateway _axelarGateway,
IAxelarGasService _axelarGasService,
ISquidMulticall _squidMulticall,
address _feeCollector,
string memory _hubChainName,
string memory _hubAddress,
ILayerZeroEndpointV2 _endpoint,
address _owner,
address _hub,
uint32 _hubEndpoint
) external initializer {
transferOwnership(_owner);
gateway = _axelarGateway;
gasService = _axelarGasService;
squidMulticall = _squidMulticall;
feeCollector = _feeCollector;
hubChainName = _hubChainName;
hubAddress = _hubAddress;
_setTrustedAddress(_hubChainName, _hubAddress);
if (address(_endpoint) != 0x1111111111111111111111111111111111111111) {
endpoint = _endpoint;
_endpoint.setDelegate(_owner);
hubEndpoint = _hubEndpoint;
_setPeer(_hubEndpoint, addressToBytes32(_hub));
hubAddressBytes32 = addressToBytes32(_hub);
}
emit SpokeInitialized(
gateway,
gasService,
squidMulticall,
feeCollector,
hubChainName,
hubAddress
);
}
//////////////////////////////////////////////////////////////
// //
// Source endpoints //
// //
//////////////////////////////////////////////////////////////
/// @inheritdoc ISpoke
function createOrder(Order calldata order) external payable {
_createOrder(order, msg.sender);
}
/// @notice Executes the intent on the source chain, locking the ERC20 or native tokens in the
/// Spoke.sol contract, setting the OrderStatus to CREATED, and making the order eligible
/// to be filled on the destination chain.
/// @dev Orders are tied to the keccak256 hash of the Order therefore each Order is unique
/// according to the parameters in the Order and can only be executed a single time.
/// @param order Order to be executed by the Spoke.sol contract in the format of the Order struct.
/// @param fromAddress Address of the holder of funds for a particular order.
function _createOrder(Order calldata order, address fromAddress) private nonReentrant {
bytes32 orderHash = keccak256(abi.encode(order));
if (orderHashToStatus[orderHash] != OrderStatus.EMPTY) revert OrderAlreadyExists();
if (block.timestamp >= order.expiry) revert OrderExpired();
if (order.fromChain != _getChainId()) revert InvalidSourceChain();
if (order.fromToken != Utils.NATIVE_TOKEN && msg.value != 0) revert UnexpectedNativeToken();
orderHashToStatus[orderHash] = OrderStatus.CREATED;
if (order.fromToken == Utils.NATIVE_TOKEN) {
if (msg.value != order.fromAmount) revert InvalidNativeAmount();
} else {
IERC20(order.fromToken).safeTransferFrom(fromAddress, address(this), order.fromAmount);
}
emit OrderCreated(orderHash, order);
}
/// @inheritdoc ISpoke
function refundOrder(Order calldata order) external nonReentrant {
bytes32 orderHash = keccak256(abi.encode(order));
if (orderHashToStatus[orderHash] != OrderStatus.CREATED) revert OrderStateNotCreated();
if (msg.sender != order.filler) {
if (!(block.timestamp > (order.expiry + 4 days))) revert OrderNotExpired();
}
if (order.fromChain != _getChainId()) revert InvalidSourceChain();
orderHashToStatus[orderHash] = OrderStatus.REFUNDED;
if (order.fromToken == Utils.NATIVE_TOKEN) {
payable(order.fromAddress).sendValue(order.fromAmount);
} else {
IERC20(order.fromToken).safeTransfer(order.fromAddress, order.fromAmount);
}
emit OrderRefunded(orderHash);
}
/// @inheritdoc ISpoke
function collectFees(address[] calldata tokens) external onlyFeeCollector {
if (tokens.length == 0) revert InvalidArrayLength();
for (uint256 i = 0; i < tokens.length; i++) {
uint256 feeAmount = tokenToCollectedFees[tokens[i]];
if (feeAmount > 0) {
tokenToCollectedFees[tokens[i]] = 0;
if (tokens[i] == Utils.NATIVE_TOKEN) {
payable(feeCollector).sendValue(feeAmount);
} else {
IERC20(tokens[i]).safeTransfer(feeCollector, feeAmount);
}
}
emit FeesCollected(feeCollector, tokens[i], feeAmount);
}
}
//////////////////////////////////////////////////////////////
// //
// Destination endpoints //
// //
//////////////////////////////////////////////////////////////
/// @inheritdoc ISpoke
function fillOrder(Order calldata order, ISquidMulticall.Call[] calldata calls) public payable {
if (order.toToken == Utils.NATIVE_TOKEN && msg.value != order.fillAmount) {
revert InvalidNativeAmount();
}
_fillOrder(order, calls);
}
/// @notice Fills an order on the destination chain, transferring the order.fillAmount of
/// order.toToken from the order.filler to the order.toAddress, setting the SettlementStatus to
/// FILLED, and making the order eligible to be forwarded to the Hub for processing.
/// @dev Orders that contain post hooks (postHookHash != bytes32(0)) require SquidMulticall calls
/// to be provided during fill. These extra calls will be ran by SquidMulticall after filling the
/// order during the same transaction.
/// @dev Only the order.filler can fill any particular order.
/// @param order Order to be filled by the Spoke.sol contract in the format of the Order struct.
/// @param calls Calls to be ran by the multicall after fill, formatted to the SquidMulticall Call struct.
function _fillOrder(Order memory order, ISquidMulticall.Call[] calldata calls) internal nonReentrant {
bytes32 orderHash = keccak256(abi.encode(order));
if (settlementToStatus[orderHash] != SettlementStatus.EMPTY) revert OrderAlreadySettled();
if (msg.sender != order.filler) revert OnlyFillerCanSettle();
if (order.toChain != _getChainId()) revert InvalidDestinationChain();
settlementToStatus[orderHash] = SettlementStatus.FILLED;
if (order.toToken == Utils.NATIVE_TOKEN) {
if (order.postHookHash != bytes32(0)) {
bytes memory callsData = abi.encode(calls);
if (keccak256(callsData) != order.postHookHash) revert InvalidPostHookProvided();
ISquidMulticall(squidMulticall).run{value: order.fillAmount}(calls);
} else {
payable(order.toAddress).sendValue(order.fillAmount);
}
} else {
if (order.postHookHash != bytes32(0)) {
bytes memory callsData = abi.encode(calls);
if (keccak256(callsData) != order.postHookHash) revert InvalidPostHookProvided();
IERC20(order.toToken).safeTransferFrom(
order.filler,
address(squidMulticall),
order.fillAmount
);
ISquidMulticall(squidMulticall).run(calls);
} else {
IERC20(order.toToken).safeTransferFrom(
order.filler,
order.toAddress,
order.fillAmount
);
}
}
emit OrderFilled(orderHash, order);
}
/// @inheritdoc ISpoke
function forwardSettlements(
bytes32[] calldata orderHashes,
uint256 lzFee,
uint128 gasLimit,
Provider provider
) external payable nonReentrant {
if (msg.value == 0) revert GasRequired();
if (orderHashes.length == 0) revert InvalidArrayLength();
for (uint256 i = 0; i < orderHashes.length; i++) {
if (
settlementToStatus[orderHashes[i]] == SettlementStatus.EMPTY
) revert OrderNotSettled();
settlementToStatus[orderHashes[i]] = SettlementStatus.FORWARDED;
emit SettlementForwarded(orderHashes[i]);
}
bytes memory payload = abi.encode(orderHashes);
if (provider == Provider.AXELAR) {
gasService.payNativeGasForContractCall{value: msg.value}(
address(this),
hubChainName,
hubAddress,
payload,
msg.sender
);
gateway.callContract(hubChainName, hubAddress, payload);
} else if (provider == Provider.LAYERZERO) {
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(gasLimit, 0);
_lzSend(
hubEndpoint,
payload,
options,
MessagingFee(msg.value, lzFee),
payable(msg.sender)
);
} else {
revert InvalidProvider();
}
}
//////////////////////////////////////////////////////////////
// //
// Message passing endpoints //
// //
//////////////////////////////////////////////////////////////
/// @notice Called by Axelar protocol when receiving a GMP on the destination chain from the Hub.
/// Contains logic that will parse the payload and release tokens for eligible orders to the order.filler.
/// @dev This method will only accept GMP's from the hubChain and hubAddress set within the Spoke.sol
/// initializer at the time of contract deployment.
/// @dev There are two options for FillType: SINGLE and MULTI
/// SINGLE is used when a batch of orders only contains a single unique order.fromToken, and only requires
/// a single transfer to release the tokens for the batch of orders to the order.filler.
/// MULTI is used when a batch of orders contains multiple unique order.fromToken, and will use as many
/// transfers as there are unique tokens in the batch.
/// @param fromChain Chain name of the chain that sent the GMP according to Axelar's chain name format:
/// https://docs.axelar.dev/dev/reference/mainnet-contract-addresses
/// @param fromContractAddress Address that sent the GMP.
/// @param payload Value provided by the Hub containing the aggregated data for the orders being processed.
/// Expected format is: abi.encode(ICoral.FillType fillType, bytes32[] orderHashes, address filler,
/// uint256[] fromAmounts, uint256[] fees, address[] fromTokens)
function _execute(
string calldata fromChain,
string calldata fromContractAddress,
bytes calldata payload
) internal virtual override onlyTrustedAddress(fromChain, fromContractAddress) {
(
FillType fillType,
bytes32[] memory orderHashes,
address filler,
uint256[] memory fromAmounts,
uint256[] memory processedFees,
address[] memory fromTokens
) = abi.decode(
payload,
(FillType, bytes32[], address, uint256[], uint256[], address[])
);
if (fillType == FillType.SINGLE) {
if (
fromTokens.length != 1 ||
fromAmounts.length != 1 ||
processedFees.length != 1
) revert InvalidArrayLength();
_releaseBatched(orderHashes, filler, fromAmounts[0], processedFees[0], fromTokens[0]);
} else if (fillType == FillType.MULTI) {
_releaseMultiTokenBatched(orderHashes, filler, fromAmounts, processedFees, fromTokens);
} else {
revert InvalidFillType();
}
}
/// @notice Receives and processes a LayerZero message on the destination chain from the Hub.
/// This function decodes the message payload and releases tokens for eligible orders to the order.filler.
/// @dev This function will only accept messages originating from the hubEndpoint and hubAddressBytes32
/// that are configured during initialization.
/// @dev Utilizes LayerZero's OApp standard for cross-chain messaging.
/// @param _origin Struct containing the message's origin information, including the source chain's
/// Endpoint ID, the sender's address, and a message nonce.
/// @param _guid A globally unique identifier for tracking the LayerZero message packet.
/// @param payload The encoded message payload containing order details, formatted as:
/// abi.encode(ICoral.FillType fillType, bytes32[] orderHashes, address filler,
/// uint256[] fromAmounts, uint256[] fees, address[] fromTokens).
/// @param _executor The address of the Executor contract that called EndpointV2's lzReceive function.
/// This is primarily for auditing purposes and not utilized in logic.
/// @param _extraData Additional arbitrary data appended by the Executor to accompany the message payload.
/// It is not modified by the OApp and can include metadata or instructions for execution.
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata payload,
address _executor,
bytes calldata _extraData
) internal override {
if (_origin.sender != hubAddressBytes32) revert UnauthorizedOriginAddress();
if (_origin.srcEid != hubEndpoint) revert UnauthorizedOriginEndpoint();
(
FillType fillType,
bytes32[] memory orderHashes,
address filler,
uint256[] memory fromAmounts,
uint256[] memory processedFees,
address[] memory fromTokens
) = abi.decode(
payload,
(FillType, bytes32[], address, uint256[], uint256[], address[])
);
if (fillType == FillType.SINGLE) {
if (
fromTokens.length != 1 ||
fromAmounts.length != 1 ||
processedFees.length != 1
) revert InvalidArrayLength();
_releaseBatched(orderHashes, filler, fromAmounts[0], processedFees[0], fromTokens[0]);
} else if (fillType == FillType.MULTI) {
_releaseMultiTokenBatched(orderHashes, filler, fromAmounts, processedFees, fromTokens);
} else {
revert InvalidFillType();
}
}
/// @notice Checks the OrderStatus of each order hash provided to ensure all orders are set to CREATED,
/// set the OrderStatus of all order hashes to SETTLED, increments the fees for the provided token and
/// processedFees, and transfers the fromAmount of ERC20 or native token from the Spoke.sol contract
/// to the filler in a single transfer for all orders in the batch.
/// @dev The provided order hashes are computed on the Hub based on orders that were processed and had
/// a matching order hash that was processed on the order.toChain of the particular orders. Orders are
/// eligible on the Hub to be forwarded to the order.fromChain once they've been filled on the
/// order.toChain. Cross chain messages secured by Axelar protocol allow this function to receive
/// confirmation that derived from the order.toChain Spoke.sol contract.
/// @dev This method is called by the SINGLE FillType, therefore this will process orders for a single
/// unique filler and token.
/// @param orderHashes Array of keccak256 hashes of Orders being finalized.
/// @param filler Address of the order.filler for all orders in the particular batch.
/// @param fromAmount Amount of order.fromToken to be released to the filler.
/// @param processedFees Amount of order.fromToken to be reserved as protocol fees.
/// @param fromToken Address of the order.fromToken for all orders in the particular batch.
function _releaseBatched(
bytes32[] memory orderHashes,
address filler,
uint256 fromAmount,
uint256 processedFees,
address fromToken
) internal nonReentrant {
if (orderHashes.length == 0) revert InvalidArrayLength();
for (uint256 i = 0; i < orderHashes.length; i++) {
bytes32 orderHash = orderHashes[i];
if (orderHashToStatus[orderHash] != OrderStatus.CREATED) revert OrderStateNotCreated();
orderHashToStatus[orderHash] = OrderStatus.SETTLED;
emit TokensReleased(orderHash);
}
tokenToCollectedFees[fromToken] += processedFees;
if (fromToken == Utils.NATIVE_TOKEN) {
payable(filler).sendValue(fromAmount);
} else {
IERC20(fromToken).safeTransfer(filler, fromAmount);
}
}
/// @notice Checks the OrderStatus of each order hash provided to ensure all orders are set to CREATED,
/// set the OrderStatus of all order hashes to SETTLED, increments the fees for each unique token provided
/// and the related processedFees according to the array position, and transfers the fromAmounts of native
/// token or each unique ERC20 token from the Spoke.sol contract to the filler with a transfer for each
/// unique token in the particular batch.
/// @dev The provided order hashes are computed on the Hub based on orders that were processed and had
/// a matching order hash that was processed on the order.toChain of the particular orders. Orders are
/// eligible on the Hub to be forwarded to the order.fromChain once they've been filled on the
/// order.toChain. Cross chain messages secured by Axelar protocol allow this function to receive
/// confirmation that derived from the order.toChain Spoke.sol contract.
/// @dev This method is called by the MULTI FillType, therefore this will process orders for all unique
/// tokens in the particular batch and a single filler.
/// @param orderHashes Array of keccak256 hashes of Orders being finalized.
/// @param filler Address of the order.filler for all orders in the particular batch.
/// @param fromAmounts Array of amounts of order.fromToken to be released to the filler.
/// @param processedFees Array of amounts of order.fromToken to be reserved as protocol fees.
/// @param fromTokens Array of addresses for all unique order.fromToken in a particular batch.
function _releaseMultiTokenBatched(
bytes32[] memory orderHashes,
address filler,
uint256[] memory fromAmounts,
uint256[] memory processedFees,
address[] memory fromTokens
) internal nonReentrant {
if (
orderHashes.length == 0 ||
fromAmounts.length != fromTokens.length ||
processedFees.length != fromTokens.length ||
fromTokens.length < 2
) revert InvalidArrayLength();
for (uint256 i = 0; i < orderHashes.length; i++) {
bytes32 orderHash = orderHashes[i];
if (orderHashToStatus[orderHash] != OrderStatus.CREATED) revert OrderStateNotCreated();
orderHashToStatus[orderHash] = OrderStatus.SETTLED;
emit TokensReleased(orderHash);
}
for (uint256 i = 0; i < fromTokens.length; i++) {
tokenToCollectedFees[fromTokens[i]] += processedFees[i];
if (fromTokens[i] == Utils.NATIVE_TOKEN) {
payable(filler).sendValue(fromAmounts[i]);
} else {
IERC20(fromTokens[i]).safeTransfer(filler, fromAmounts[i]);
}
}
}
//////////////////////////////////////////////////////////////
// //
// Utilities //
// //
//////////////////////////////////////////////////////////////
/// @notice Finds the index of a given token in an array of tokens.
/// @param token Address of the token to find in the array.
/// @param fromTokens Array of token addresses to search for the given token.
/// @return uint256 Index of the token in the array, or the maximum value of uint256 if the token
/// is not found.
function _findTokenIndex(
address token,
address[] calldata fromTokens
) private pure returns (uint256) {
for (uint256 i = 0; i < fromTokens.length; i++) {
if (fromTokens[i] == token) {
return i;
}
}
return type(uint256).max;
}
/// @notice Retrieves the current chain ID.
/// @return uint256 The current chain ID.
function _getChainId() private view returns (uint256) {
uint256 chainId;
assembly {
chainId := chainid()
}
return chainId;
}
function addressToBytes32(address _addr) public pure returns (bytes32) {
return bytes32(uint256(uint160(_addr)));
}
/// @notice Provides a gas fee estimate for sending a message to a specified destination chain
/// through LayerZero.
/// Computes fees required for executing a LayerZero cross-chain message considering the native and
/// optional ZRO token fees.
/// @param _dstEid Destination chain's Endpoint ID as specified by LayerZero documentation.
/// @param orderHashes An array of order hashes to be encapsulated in the message payload for
/// processing at the destination.
/// @param gasLimit The gas limit to be used for executing the lzReceive function on the destination
/// chain, affecting the fee.
/// @param _payInLzToken A boolean indicating if part of the fee will be paid in LayerZero's ZRO
/// token, impacting the fee structure.
/// @return nativeFee The estimated fee in native tokens required for processing the message on
/// the destination chain.
/// @return lzTokenFee The estimated fee in ZRO tokens, if opted for payment through LayerZero's
/// token mechanism.
function quote(
uint32 _dstEid,
bytes32[] calldata orderHashes,
uint128 gasLimit,
bool _payInLzToken
) public view returns (uint256 nativeFee, uint256 lzTokenFee) {
bytes memory payload = abi.encode(orderHashes);
bytes memory options = OptionsBuilder.newOptions().addExecutorLzReceiveOption(gasLimit, 0);
MessagingFee memory fee = _quote(_dstEid, payload, options, _payInLzToken);
return (fee.nativeFee, fee.lzTokenFee);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { GasInfo } from '../types/GasEstimationTypes.sol';
import { IInterchainGasEstimation } from './IInterchainGasEstimation.sol';
import { IUpgradable } from './IUpgradable.sol';
/**
* @title IAxelarGasService Interface
* @notice This is an interface for the AxelarGasService contract which manages gas payments
* and refunds for cross-chain communication on the Axelar network.
* @dev This interface inherits IUpgradable
*/
interface IAxelarGasService is IInterchainGasEstimation, IUpgradable {
error InvalidAddress();
error NotCollector();
error InvalidAmounts();
error InvalidGasUpdates();
error InvalidParams();
error InsufficientGasPayment(uint256 required, uint256 provided);
event GasPaidForContractCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event GasPaidForContractCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForContractCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForContractCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
uint256 gasFeeAmount,
address refundAddress
);
event GasPaidForExpressCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event GasPaidForExpressCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForExpressCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForExpressCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
uint256 gasFeeAmount,
address refundAddress
);
event GasAdded(
bytes32 indexed txHash,
uint256 indexed logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasAdded(bytes32 indexed txHash, uint256 indexed logIndex, uint256 gasFeeAmount, address refundAddress);
event ExpressGasAdded(
bytes32 indexed txHash,
uint256 indexed logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeExpressGasAdded(
bytes32 indexed txHash,
uint256 indexed logIndex,
uint256 gasFeeAmount,
address refundAddress
);
event Refunded(
bytes32 indexed txHash,
uint256 indexed logIndex,
address payable receiver,
address token,
uint256 amount
);
/**
* @notice Pay for gas for any type of contract execution on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @dev If estimateOnChain is true, the function will estimate the gas cost and revert if the payment is insufficient.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param executionGasLimit The gas limit for the contract call
* @param estimateOnChain Flag to enable on-chain gas estimation
* @param refundAddress The address where refunds, if any, should be sent
* @param params Additional parameters for gas payment. This can be left empty for normal contract call payments.
*/
function payGas(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
uint256 executionGasLimit,
bool estimateOnChain,
address refundAddress,
bytes calldata params
) external payable;
/**
* @notice Pay for gas using ERC20 tokens for a contract call on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param gasToken The address of the ERC20 token used to pay for gas
* @param gasFeeAmount The amount of tokens to pay for gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function payGasForContractCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Pay for gas using ERC20 tokens for a contract call with tokens on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call with tokens will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call with tokens
* @param symbol The symbol of the token to be sent with the call
* @param amount The amount of tokens to be sent with the call
* @param gasToken The address of the ERC20 token used to pay for gas
* @param gasFeeAmount The amount of tokens to pay for gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function payGasForContractCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Pay for gas using native currency for a contract call on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param refundAddress The address where refunds, if any, should be sent
*/
function payNativeGasForContractCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address refundAddress
) external payable;
/**
* @notice Pay for gas using native currency for a contract call with tokens on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call with tokens will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call with tokens
* @param symbol The symbol of the token to be sent with the call
* @param amount The amount of tokens to be sent with the call
* @param refundAddress The address where refunds, if any, should be sent
*/
function payNativeGasForContractCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address refundAddress
) external payable;
/**
* @notice Pay for gas using ERC20 tokens for an express contract call on a destination chain.
* @dev This function is called on the source chain before calling the gateway to express execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param gasToken The address of the ERC20 token used to pay for gas
* @param gasFeeAmount The amount of tokens to pay for gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function payGasForExpressCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Pay for gas using ERC20 tokens for an express contract call with tokens on a destination chain.
* @dev This function is called on the source chain before calling the gateway to express execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call with tokens will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call with tokens
* @param symbol The symbol of the token to be sent with the call
* @param amount The amount of tokens to be sent with the call
* @param gasToken The address of the ERC20 token used to pay for gas
* @param gasFeeAmount The amount of tokens to pay for gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function payGasForExpressCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Pay for gas using native currency for an express contract call on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param refundAddress The address where refunds, if any, should be sent
*/
function payNativeGasForExpressCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address refundAddress
) external payable;
/**
* @notice Pay for gas using native currency for an express contract call with tokens on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call with tokens will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call with tokens
* @param symbol The symbol of the token to be sent with the call
* @param amount The amount of tokens to be sent with the call
* @param refundAddress The address where refunds, if any, should be sent
*/
function payNativeGasForExpressCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address refundAddress
) external payable;
/**
* @notice Add additional gas payment using ERC20 tokens after initiating a cross-chain call.
* @dev This function can be called on the source chain after calling the gateway to execute a remote contract.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param gasToken The ERC20 token address used to add gas
* @param gasFeeAmount The amount of tokens to add as gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function addGas(
bytes32 txHash,
uint256 logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Add additional gas payment using native currency after initiating a cross-chain call.
* @dev This function can be called on the source chain after calling the gateway to execute a remote contract.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param refundAddress The address where refunds, if any, should be sent
*/
function addNativeGas(
bytes32 txHash,
uint256 logIndex,
address refundAddress
) external payable;
/**
* @notice Add additional gas payment using ERC20 tokens after initiating an express cross-chain call.
* @dev This function can be called on the source chain after calling the gateway to express execute a remote contract.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param gasToken The ERC20 token address used to add gas
* @param gasFeeAmount The amount of tokens to add as gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function addExpressGas(
bytes32 txHash,
uint256 logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Add additional gas payment using native currency after initiating an express cross-chain call.
* @dev This function can be called on the source chain after calling the gateway to express execute a remote contract.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param refundAddress The address where refunds, if any, should be sent
*/
function addNativeExpressGas(
bytes32 txHash,
uint256 logIndex,
address refundAddress
) external payable;
/**
* @notice Updates the gas price for a specific chain.
* @dev This function is called by the gas oracle to update the gas prices for a specific chains.
* @param chains Array of chain names
* @param gasUpdates Array of gas updates
*/
function updateGasInfo(string[] calldata chains, GasInfo[] calldata gasUpdates) external;
/**
* @notice Allows the gasCollector to collect accumulated fees from the contract.
* @dev Use address(0) as the token address for native currency.
* @param receiver The address to receive the collected fees
* @param tokens Array of token addresses to be collected
* @param amounts Array of amounts to be collected for each respective token address
*/
function collectFees(
address payable receiver,
address[] calldata tokens,
uint256[] calldata amounts
) external;
/**
* @notice Refunds gas payment to the receiver in relation to a specific cross-chain transaction.
* @dev Only callable by the gasCollector.
* @dev Use address(0) as the token address to refund native currency.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param receiver The address to receive the refund
* @param token The token address to be refunded
* @param amount The amount to refund
*/
function refund(
bytes32 txHash,
uint256 logIndex,
address payable receiver,
address token,
uint256 amount
) external;
/**
* @notice Returns the address of the designated gas collector.
* @return address of the gas collector
*/
function gasCollector() external returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// General interface for upgradable contracts
interface IContractIdentifier {
/**
* @notice Returns the contract ID. It can be used as a check during upgrades.
* @dev Meant to be overridden in derived contracts.
* @return bytes32 The contract ID
*/
function contractId() external pure returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IContractIdentifier } from './IContractIdentifier.sol';
interface IImplementation is IContractIdentifier {
error NotProxy();
function setup(bytes calldata data) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title IInterchainAddressTracker
* @dev Manages trusted addresses by chain, keeps track of addresses supported by the Axelar gateway contract
*/
interface IInterchainAddressTracker {
error ZeroAddress();
error LengthMismatch();
error ZeroStringLength();
error UntrustedChain();
event TrustedAddressSet(string chain, string address_);
event TrustedAddressRemoved(string chain);
/**
* @dev Gets the name of the chain this is deployed at
*/
function chainName() external view returns (string memory);
/**
* @dev Gets the trusted address at a remote chain
* @param chain Chain name of the remote chain
* @return trustedAddress_ The trusted address for the chain. Returns '' if the chain is untrusted
*/
function trustedAddress(string memory chain) external view returns (string memory trustedAddress_);
/**
* @dev Gets the trusted address hash for a chain
* @param chain Chain name
* @return trustedAddressHash_ the hash of the trusted address for that chain
*/
function trustedAddressHash(string memory chain) external view returns (bytes32 trustedAddressHash_);
/**
* @dev Checks whether the interchain sender is a trusted address
* @param chain Chain name of the sender
* @param address_ Address of the sender
* @return bool true if the sender chain/address are trusted, false otherwise
*/
function isTrustedAddress(string calldata chain, string calldata address_) external view returns (bool);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { GasEstimationType, GasInfo } from '../types/GasEstimationTypes.sol';
/**
* @title IInterchainGasEstimation Interface
* @notice This is an interface for the InterchainGasEstimation contract
* which allows for estimating gas fees for cross-chain communication on the Axelar network.
*/
interface IInterchainGasEstimation {
error UnsupportedEstimationType(GasEstimationType gasEstimationType);
/**
* @notice Event emitted when the gas price for a specific chain is updated.
* @param chain The name of the chain
* @param info The gas info for the chain
*/
event GasInfoUpdated(string chain, GasInfo info);
/**
* @notice Returns the gas price for a specific chain.
* @param chain The name of the chain
* @return gasInfo The gas info for the chain
*/
function getGasInfo(string calldata chain) external view returns (GasInfo memory);
/**
* @notice Estimates the gas fee for a cross-chain contract call.
* @param destinationChain Axelar registered name of the destination chain
* @param destinationAddress Destination contract address being called
* @param executionGasLimit The gas limit to be used for the destination contract execution,
* e.g. pass in 200k if your app consumes needs upto 200k for this contract call
* @param params Additional parameters for the gas estimation
* @return gasEstimate The cross-chain gas estimate, in terms of source chain's native gas token that should be forwarded to the gas service.
*/
function estimateGasFee(
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
uint256 executionGasLimit,
bytes calldata params
) external view returns (uint256 gasEstimate);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title IOwnable Interface
* @notice IOwnable is an interface that abstracts the implementation of a
* contract with ownership control features. It's commonly used in upgradable
* contracts and includes the functionality to get current owner, transfer
* ownership, and propose and accept ownership.
*/
interface IOwnable {
error NotOwner();
error InvalidOwner();
error InvalidOwnerAddress();
event OwnershipTransferStarted(address indexed newOwner);
event OwnershipTransferred(address indexed newOwner);
/**
* @notice Returns the current owner of the contract.
* @return address The address of the current owner
*/
function owner() external view returns (address);
/**
* @notice Returns the address of the pending owner of the contract.
* @return address The address of the pending owner
*/
function pendingOwner() external view returns (address);
/**
* @notice Transfers ownership of the contract to a new address
* @param newOwner The address to transfer ownership to
*/
function transferOwnership(address newOwner) external;
/**
* @notice Proposes to transfer the contract's ownership to a new address.
* The new owner needs to accept the ownership explicitly.
* @param newOwner The address to transfer ownership to
*/
function proposeOwnership(address newOwner) external;
/**
* @notice Transfers ownership to the pending owner.
* @dev Can only be called by the pending owner
*/
function acceptOwnership() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IOwnable } from './IOwnable.sol';
import { IImplementation } from './IImplementation.sol';
// General interface for upgradable contracts
interface IUpgradable is IOwnable, IImplementation {
error InvalidCodeHash();
error InvalidImplementation();
error SetupFailed();
event Upgraded(address indexed newImplementation);
function implementation() external view returns (address);
function upgrade(
address newImplementation,
bytes32 newImplementationCodeHash,
bytes calldata params
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library StringStorage {
struct Wrapper {
string value;
}
function set(bytes32 slot, string memory value) internal {
_getStorageStruct(slot).value = value;
}
function get(bytes32 slot) internal view returns (string memory value) {
value = _getStorageStruct(slot).value;
}
function clear(bytes32 slot) internal {
delete _getStorageStruct(slot).value;
}
function _getStorageStruct(bytes32 slot) internal pure returns (Wrapper storage wrapper) {
assembly {
wrapper.slot := slot
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title GasEstimationType
* @notice This enum represents the gas estimation types for different chains.
*/
enum GasEstimationType {
Default,
OptimismEcotone,
OptimismBedrock,
Arbitrum,
Scroll
}
/**
* @title GasInfo
* @notice This struct represents the gas pricing information for a specific chain.
* @dev Smaller uint types are used for efficient struct packing to save storage costs.
*/
struct GasInfo {
/// @dev Custom gas pricing rule, such as L1 data fee on L2s
uint64 gasEstimationType;
/// @dev Scalar value needed for specific gas estimation types, expected to be less than 1e10
uint64 l1FeeScalar;
/// @dev Axelar base fee for cross-chain message approval on destination, in terms of source native gas token
uint128 axelarBaseFee;
/// @dev Gas price of destination chain, in terms of the source chain token, i.e dest_gas_price * dest_token_market_price / src_token_market_price
uint128 relativeGasPrice;
/// @dev Needed for specific gas estimation types. Blob base fee of destination chain, in terms of the source chain token, i.e dest_blob_base_fee * dest_token_market_price / src_token_market_price
uint128 relativeBlobBaseFee;
/// @dev Axelar express fee for express execution, in terms of source chain token
uint128 expressFee;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IInterchainAddressTracker } from '../interfaces/IInterchainAddressTracker.sol';
import { StringStorage } from '../libs/StringStorage.sol';
/**
* @title InterchainAddressTracker
* @dev Manages and validates trusted interchain addresses of an application.
*/
contract InterchainAddressTracker is IInterchainAddressTracker {
bytes32 internal constant PREFIX_ADDRESS_MAPPING = keccak256('interchain-address-tracker-address-mapping');
bytes32 internal constant PREFIX_ADDRESS_HASH_MAPPING =
keccak256('interchain-address-tracker-address-hash-mapping');
// bytes32(uint256(keccak256('interchain-address-tracker-chain-name')) - 1)
bytes32 internal constant _CHAIN_NAME_SLOT = 0x0e2c162a1f4b5cff9fdbd6b34678a9bcb9898a0b9fbca695b112d61688d8b2ac;
function _setChainName(string memory chainName_) internal {
StringStorage.set(_CHAIN_NAME_SLOT, chainName_);
}
/**
* @dev Gets the name of the chain this is deployed at
*/
function chainName() external view returns (string memory chainName_) {
chainName_ = StringStorage.get(_CHAIN_NAME_SLOT);
}
/**
* @dev Gets the trusted address at a remote chain
* @param chain Chain name of the remote chain
* @return trustedAddress_ The trusted address for the chain. Returns '' if the chain is untrusted
*/
function trustedAddress(string memory chain) public view returns (string memory trustedAddress_) {
trustedAddress_ = StringStorage.get(_getTrustedAddressSlot(chain));
}
/**
* @dev Gets the trusted address hash for a chain
* @param chain Chain name
* @return trustedAddressHash_ the hash of the trusted address for that chain
*/
function trustedAddressHash(string memory chain) public view returns (bytes32 trustedAddressHash_) {
bytes32 slot = _getTrustedAddressHashSlot(chain);
assembly {
trustedAddressHash_ := sload(slot)
}
}
/**
* @dev Checks whether the interchain sender is a trusted address
* @param chain Chain name of the sender
* @param address_ Address of the sender
* @return bool true if the sender chain/address are trusted, false otherwise
*/
function isTrustedAddress(string calldata chain, string calldata address_) public view returns (bool) {
bytes32 addressHash = keccak256(bytes(address_));
return addressHash == trustedAddressHash(chain);
}
/**
* @dev Gets the key for the trusted address at a remote chain
* @param chain Chain name of the remote chain
* @return slot the slot to store the trusted address in
*/
function _getTrustedAddressSlot(string memory chain) internal pure returns (bytes32 slot) {
slot = keccak256(abi.encode(PREFIX_ADDRESS_MAPPING, chain));
}
/**
* @dev Gets the key for the trusted address at a remote chain
* @param chain Chain name of the remote chain
* @return slot the slot to store the trusted address hash in
*/
function _getTrustedAddressHashSlot(string memory chain) internal pure returns (bytes32 slot) {
slot = keccak256(abi.encode(PREFIX_ADDRESS_HASH_MAPPING, chain));
}
/**
* @dev Sets the trusted address and its hash for a remote chain
* @param chain Chain name of the remote chain
* @param address_ the string representation of the trusted address
*/
function _setTrustedAddress(string memory chain, string memory address_) internal {
if (bytes(chain).length == 0) revert ZeroStringLength();
if (bytes(address_).length == 0) revert ZeroStringLength();
StringStorage.set(_getTrustedAddressSlot(chain), address_);
bytes32 slot = _getTrustedAddressHashSlot(chain);
bytes32 addressHash = keccak256(bytes(address_));
assembly {
sstore(slot, addressHash)
}
emit TrustedAddressSet(chain, address_);
}
/**
* @dev Remove the trusted address of the chain.
* @param chain Chain name that should be made untrusted
*/
function _removeTrustedAddress(string memory chain) internal {
if (bytes(chain).length == 0) revert ZeroStringLength();
StringStorage.clear(_getTrustedAddressSlot(chain));
bytes32 slot = _getTrustedAddressHashSlot(chain);
assembly {
sstore(slot, 0)
}
emit TrustedAddressRemoved(chain);
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/CalldataBytesLib.sol";
library ExecutorOptions {
using CalldataBytesLib for bytes;
uint8 internal constant WORKER_ID = 1;
uint8 internal constant OPTION_TYPE_LZRECEIVE = 1;
uint8 internal constant OPTION_TYPE_NATIVE_DROP = 2;
uint8 internal constant OPTION_TYPE_LZCOMPOSE = 3;
uint8 internal constant OPTION_TYPE_ORDERED_EXECUTION = 4;
uint8 internal constant OPTION_TYPE_LZREAD = 5;
error Executor_InvalidLzReceiveOption();
error Executor_InvalidNativeDropOption();
error Executor_InvalidLzComposeOption();
error Executor_InvalidLzReadOption();
/// @dev decode the next executor option from the options starting from the specified cursor
/// @param _options [executor_id][executor_option][executor_id][executor_option]...
/// executor_option = [option_size][option_type][option]
/// option_size = len(option_type) + len(option)
/// executor_id: uint8, option_size: uint16, option_type: uint8, option: bytes
/// @param _cursor the cursor to start decoding from
/// @return optionType the type of the option
/// @return option the option of the executor
/// @return cursor the cursor to start decoding the next executor option
function nextExecutorOption(
bytes calldata _options,
uint256 _cursor
) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
unchecked {
// skip worker id
cursor = _cursor + 1;
// read option size
uint16 size = _options.toU16(cursor);
cursor += 2;
// read option type
optionType = _options.toU8(cursor);
// startCursor and endCursor are used to slice the option from _options
uint256 startCursor = cursor + 1; // skip option type
uint256 endCursor = cursor + size;
option = _options[startCursor:endCursor];
cursor += size;
}
}
function decodeLzReceiveOption(bytes calldata _option) internal pure returns (uint128 gas, uint128 value) {
if (_option.length != 16 && _option.length != 32) revert Executor_InvalidLzReceiveOption();
gas = _option.toU128(0);
value = _option.length == 32 ? _option.toU128(16) : 0;
}
function decodeNativeDropOption(bytes calldata _option) internal pure returns (uint128 amount, bytes32 receiver) {
if (_option.length != 48) revert Executor_InvalidNativeDropOption();
amount = _option.toU128(0);
receiver = _option.toB32(16);
}
function decodeLzComposeOption(
bytes calldata _option
) internal pure returns (uint16 index, uint128 gas, uint128 value) {
if (_option.length != 18 && _option.length != 34) revert Executor_InvalidLzComposeOption();
index = _option.toU16(0);
gas = _option.toU128(2);
value = _option.length == 34 ? _option.toU128(18) : 0;
}
function decodeLzReadOption(
bytes calldata _option
) internal pure returns (uint128 gas, uint32 calldataSize, uint128 value) {
if (_option.length != 20 && _option.length != 36) revert Executor_InvalidLzReadOption();
gas = _option.toU128(0);
calldataSize = _option.toU32(16);
value = _option.length == 36 ? _option.toU128(20) : 0;
}
function encodeLzReceiveOption(uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
return _value == 0 ? abi.encodePacked(_gas) : abi.encodePacked(_gas, _value);
}
function encodeNativeDropOption(uint128 _amount, bytes32 _receiver) internal pure returns (bytes memory) {
return abi.encodePacked(_amount, _receiver);
}
function encodeLzComposeOption(uint16 _index, uint128 _gas, uint128 _value) internal pure returns (bytes memory) {
return _value == 0 ? abi.encodePacked(_index, _gas) : abi.encodePacked(_index, _gas, _value);
}
function encodeLzReadOption(
uint128 _gas,
uint32 _calldataSize,
uint128 _value
) internal pure returns (bytes memory) {
return _value == 0 ? abi.encodePacked(_gas, _calldataSize) : abi.encodePacked(_gas, _calldataSize, _value);
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
import { BitMap256 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/BitMaps.sol";
import { CalldataBytesLib } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/CalldataBytesLib.sol";
library DVNOptions {
using CalldataBytesLib for bytes;
using BytesLib for bytes;
uint8 internal constant WORKER_ID = 2;
uint8 internal constant OPTION_TYPE_PRECRIME = 1;
error DVN_InvalidDVNIdx();
error DVN_InvalidDVNOptions(uint256 cursor);
/// @dev group dvn options by its idx
/// @param _options [dvn_id][dvn_option][dvn_id][dvn_option]...
/// dvn_option = [option_size][dvn_idx][option_type][option]
/// option_size = len(dvn_idx) + len(option_type) + len(option)
/// dvn_id: uint8, dvn_idx: uint8, option_size: uint16, option_type: uint8, option: bytes
/// @return dvnOptions the grouped options, still share the same format of _options
/// @return dvnIndices the dvn indices
function groupDVNOptionsByIdx(
bytes memory _options
) internal pure returns (bytes[] memory dvnOptions, uint8[] memory dvnIndices) {
if (_options.length == 0) return (dvnOptions, dvnIndices);
uint8 numDVNs = getNumDVNs(_options);
// if there is only 1 dvn, we can just return the whole options
if (numDVNs == 1) {
dvnOptions = new bytes[](1);
dvnOptions[0] = _options;
dvnIndices = new uint8[](1);
dvnIndices[0] = _options.toUint8(3); // dvn idx
return (dvnOptions, dvnIndices);
}
// otherwise, we need to group the options by dvn_idx
dvnIndices = new uint8[](numDVNs);
dvnOptions = new bytes[](numDVNs);
unchecked {
uint256 cursor = 0;
uint256 start = 0;
uint8 lastDVNIdx = 255; // 255 is an invalid dvn_idx
while (cursor < _options.length) {
++cursor; // skip worker_id
// optionLength asserted in getNumDVNs (skip check)
uint16 optionLength = _options.toUint16(cursor);
cursor += 2;
// dvnIdx asserted in getNumDVNs (skip check)
uint8 dvnIdx = _options.toUint8(cursor);
// dvnIdx must equal to the lastDVNIdx for the first option
// so it is always skipped in the first option
// this operation slices out options whenever the scan finds a different lastDVNIdx
if (lastDVNIdx == 255) {
lastDVNIdx = dvnIdx;
} else if (dvnIdx != lastDVNIdx) {
uint256 len = cursor - start - 3; // 3 is for worker_id and option_length
bytes memory opt = _options.slice(start, len);
_insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, opt);
// reset the start and lastDVNIdx
start += len;
lastDVNIdx = dvnIdx;
}
cursor += optionLength;
}
// skip check the cursor here because the cursor is asserted in getNumDVNs
// if we have reached the end of the options, we need to process the last dvn
uint256 size = cursor - start;
bytes memory op = _options.slice(start, size);
_insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, op);
// revert dvnIndices to start from 0
for (uint8 i = 0; i < numDVNs; ++i) {
--dvnIndices[i];
}
}
}
function _insertDVNOptions(
bytes[] memory _dvnOptions,
uint8[] memory _dvnIndices,
uint8 _dvnIdx,
bytes memory _newOptions
) internal pure {
// dvnIdx starts from 0 but default value of dvnIndices is 0,
// so we tell if the slot is empty by adding 1 to dvnIdx
if (_dvnIdx == 255) revert DVN_InvalidDVNIdx();
uint8 dvnIdxAdj = _dvnIdx + 1;
for (uint256 j = 0; j < _dvnIndices.length; ++j) {
uint8 index = _dvnIndices[j];
if (dvnIdxAdj == index) {
_dvnOptions[j] = abi.encodePacked(_dvnOptions[j], _newOptions);
break;
} else if (index == 0) {
// empty slot, that means it is the first time we see this dvn
_dvnIndices[j] = dvnIdxAdj;
_dvnOptions[j] = _newOptions;
break;
}
}
}
/// @dev get the number of unique dvns
/// @param _options the format is the same as groupDVNOptionsByIdx
function getNumDVNs(bytes memory _options) internal pure returns (uint8 numDVNs) {
uint256 cursor = 0;
BitMap256 bitmap;
// find number of unique dvn_idx
unchecked {
while (cursor < _options.length) {
++cursor; // skip worker_id
uint16 optionLength = _options.toUint16(cursor);
cursor += 2;
if (optionLength < 2) revert DVN_InvalidDVNOptions(cursor); // at least 1 byte for dvn_idx and 1 byte for option_type
uint8 dvnIdx = _options.toUint8(cursor);
// if dvnIdx is not set, increment numDVNs
// max num of dvns is 255, 255 is an invalid dvn_idx
// The order of the dvnIdx is not required to be sequential, as enforcing the order may weaken
// the composability of the options. e.g. if we refrain from enforcing the order, an OApp that has
// already enforced certain options can append additional options to the end of the enforced
// ones without restrictions.
if (dvnIdx == 255) revert DVN_InvalidDVNIdx();
if (!bitmap.get(dvnIdx)) {
++numDVNs;
bitmap = bitmap.set(dvnIdx);
}
cursor += optionLength;
}
}
if (cursor != _options.length) revert DVN_InvalidDVNOptions(cursor);
}
/// @dev decode the next dvn option from _options starting from the specified cursor
/// @param _options the format is the same as groupDVNOptionsByIdx
/// @param _cursor the cursor to start decoding
/// @return optionType the type of the option
/// @return option the option
/// @return cursor the cursor to start decoding the next option
function nextDVNOption(
bytes calldata _options,
uint256 _cursor
) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
unchecked {
// skip worker id
cursor = _cursor + 1;
// read option size
uint16 size = _options.toU16(cursor);
cursor += 2;
// read option type
optionType = _options.toU8(cursor + 1); // skip dvn_idx
// startCursor and endCursor are used to slice the option from _options
uint256 startCursor = cursor + 2; // skip option type and dvn_idx
uint256 endCursor = cursor + size;
option = _options[startCursor:endCursor];
cursor += size;
}
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
library CalldataBytesLib {
function toU8(bytes calldata _bytes, uint256 _start) internal pure returns (uint8) {
return uint8(_bytes[_start]);
}
function toU16(bytes calldata _bytes, uint256 _start) internal pure returns (uint16) {
unchecked {
uint256 end = _start + 2;
return uint16(bytes2(_bytes[_start:end]));
}
}
function toU32(bytes calldata _bytes, uint256 _start) internal pure returns (uint32) {
unchecked {
uint256 end = _start + 4;
return uint32(bytes4(_bytes[_start:end]));
}
}
function toU64(bytes calldata _bytes, uint256 _start) internal pure returns (uint64) {
unchecked {
uint256 end = _start + 8;
return uint64(bytes8(_bytes[_start:end]));
}
}
function toU128(bytes calldata _bytes, uint256 _start) internal pure returns (uint128) {
unchecked {
uint256 end = _start + 16;
return uint128(bytes16(_bytes[_start:end]));
}
}
function toU256(bytes calldata _bytes, uint256 _start) internal pure returns (uint256) {
unchecked {
uint256 end = _start + 32;
return uint256(bytes32(_bytes[_start:end]));
}
}
function toAddr(bytes calldata _bytes, uint256 _start) internal pure returns (address) {
unchecked {
uint256 end = _start + 20;
return address(bytes20(_bytes[_start:end]));
}
}
function toB32(bytes calldata _bytes, uint256 _start) internal pure returns (bytes32) {
unchecked {
uint256 end = _start + 32;
return bytes32(_bytes[_start:end]);
}
}
}// SPDX-License-Identifier: MIT
// modified from https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/structs/BitMaps.sol
pragma solidity ^0.8.20;
type BitMap256 is uint256;
using BitMaps for BitMap256 global;
library BitMaps {
/**
* @dev Returns whether the bit at `index` is set.
*/
function get(BitMap256 bitmap, uint8 index) internal pure returns (bool) {
uint256 mask = 1 << index;
return BitMap256.unwrap(bitmap) & mask != 0;
}
/**
* @dev Sets the bit at `index`.
*/
function set(BitMap256 bitmap, uint8 index) internal pure returns (BitMap256) {
uint256 mask = 1 << index;
return BitMap256.wrap(BitMap256.unwrap(bitmap) | mask);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { ExecutorOptions } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/libs/ExecutorOptions.sol";
import { DVNOptions } from "@layerzerolabs/lz-evm-messagelib-v2/contracts/uln/libs/DVNOptions.sol";
/**
* @title OptionsBuilder
* @dev Library for building and encoding various message options.
*/
library OptionsBuilder {
using SafeCast for uint256;
using BytesLib for bytes;
// Constants for options types
uint16 internal constant TYPE_1 = 1; // legacy options type 1
uint16 internal constant TYPE_2 = 2; // legacy options type 2
uint16 internal constant TYPE_3 = 3;
// Custom error message
error InvalidSize(uint256 max, uint256 actual);
error InvalidOptionType(uint16 optionType);
// Modifier to ensure only options of type 3 are used
modifier onlyType3(bytes memory _options) {
if (_options.toUint16(0) != TYPE_3) revert InvalidOptionType(_options.toUint16(0));
_;
}
/**
* @dev Creates a new options container with type 3.
* @return options The newly created options container.
*/
function newOptions() internal pure returns (bytes memory) {
return abi.encodePacked(TYPE_3);
}
/**
* @dev Adds an executor LZ receive option to the existing options.
* @param _options The existing options container.
* @param _gas The gasLimit used on the lzReceive() function in the OApp.
* @param _value The msg.value passed to the lzReceive() function in the OApp.
* @return options The updated options container.
*
* @dev When multiples of this option are added, they are summed by the executor
* eg. if (_gas: 200k, and _value: 1 ether) AND (_gas: 100k, _value: 0.5 ether) are sent in an option to the LayerZeroEndpoint,
* that becomes (300k, 1.5 ether) when the message is executed on the remote lzReceive() function.
*/
function addExecutorLzReceiveOption(
bytes memory _options,
uint128 _gas,
uint128 _value
) internal pure onlyType3(_options) returns (bytes memory) {
bytes memory option = ExecutorOptions.encodeLzReceiveOption(_gas, _value);
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZRECEIVE, option);
}
/**
* @dev Adds an executor native drop option to the existing options.
* @param _options The existing options container.
* @param _amount The amount for the native value that is airdropped to the 'receiver'.
* @param _receiver The receiver address for the native drop option.
* @return options The updated options container.
*
* @dev When multiples of this option are added, they are summed by the executor on the remote chain.
*/
function addExecutorNativeDropOption(
bytes memory _options,
uint128 _amount,
bytes32 _receiver
) internal pure onlyType3(_options) returns (bytes memory) {
bytes memory option = ExecutorOptions.encodeNativeDropOption(_amount, _receiver);
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_NATIVE_DROP, option);
}
// /**
// * @dev Adds an executor native drop option to the existing options.
// * @param _options The existing options container.
// * @param _amount The amount for the native value that is airdropped to the 'receiver'.
// * @param _receiver The receiver address for the native drop option.
// * @return options The updated options container.
// *
// * @dev When multiples of this option are added, they are summed by the executor on the remote chain.
// */
function addExecutorLzReadOption(
bytes memory _options,
uint128 _gas,
uint32 _size,
uint128 _value
) internal pure onlyType3(_options) returns (bytes memory) {
bytes memory option = ExecutorOptions.encodeLzReadOption(_gas, _size, _value);
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZREAD, option);
}
/**
* @dev Adds an executor LZ compose option to the existing options.
* @param _options The existing options container.
* @param _index The index for the lzCompose() function call.
* @param _gas The gasLimit for the lzCompose() function call.
* @param _value The msg.value for the lzCompose() function call.
* @return options The updated options container.
*
* @dev When multiples of this option are added, they are summed PER index by the executor on the remote chain.
* @dev If the OApp sends N lzCompose calls on the remote, you must provide N incremented indexes starting with 0.
* ie. When your remote OApp composes (N = 3) messages, you must set this option for index 0,1,2
*/
function addExecutorLzComposeOption(
bytes memory _options,
uint16 _index,
uint128 _gas,
uint128 _value
) internal pure onlyType3(_options) returns (bytes memory) {
bytes memory option = ExecutorOptions.encodeLzComposeOption(_index, _gas, _value);
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_LZCOMPOSE, option);
}
/**
* @dev Adds an executor ordered execution option to the existing options.
* @param _options The existing options container.
* @return options The updated options container.
*/
function addExecutorOrderedExecutionOption(
bytes memory _options
) internal pure onlyType3(_options) returns (bytes memory) {
return addExecutorOption(_options, ExecutorOptions.OPTION_TYPE_ORDERED_EXECUTION, bytes(""));
}
/**
* @dev Adds a DVN pre-crime option to the existing options.
* @param _options The existing options container.
* @param _dvnIdx The DVN index for the pre-crime option.
* @return options The updated options container.
*/
function addDVNPreCrimeOption(
bytes memory _options,
uint8 _dvnIdx
) internal pure onlyType3(_options) returns (bytes memory) {
return addDVNOption(_options, _dvnIdx, DVNOptions.OPTION_TYPE_PRECRIME, bytes(""));
}
/**
* @dev Adds an executor option to the existing options.
* @param _options The existing options container.
* @param _optionType The type of the executor option.
* @param _option The encoded data for the executor option.
* @return options The updated options container.
*/
function addExecutorOption(
bytes memory _options,
uint8 _optionType,
bytes memory _option
) internal pure onlyType3(_options) returns (bytes memory) {
return
abi.encodePacked(
_options,
ExecutorOptions.WORKER_ID,
_option.length.toUint16() + 1, // +1 for optionType
_optionType,
_option
);
}
/**
* @dev Adds a DVN option to the existing options.
* @param _options The existing options container.
* @param _dvnIdx The DVN index for the DVN option.
* @param _optionType The type of the DVN option.
* @param _option The encoded data for the DVN option.
* @return options The updated options container.
*/
function addDVNOption(
bytes memory _options,
uint8 _dvnIdx,
uint8 _optionType,
bytes memory _option
) internal pure onlyType3(_options) returns (bytes memory) {
return
abi.encodePacked(
_options,
DVNOptions.WORKER_ID,
_option.length.toUint16() + 2, // +2 for optionType and dvnIdx
_dvnIdx,
_optionType,
_option
);
}
/**
* @dev Encodes legacy options of type 1.
* @param _executionGas The gasLimit value passed to lzReceive().
* @return legacyOptions The encoded legacy options.
*/
function encodeLegacyOptionsType1(uint256 _executionGas) internal pure returns (bytes memory) {
if (_executionGas > type(uint128).max) revert InvalidSize(type(uint128).max, _executionGas);
return abi.encodePacked(TYPE_1, _executionGas);
}
/**
* @dev Encodes legacy options of type 2.
* @param _executionGas The gasLimit value passed to lzReceive().
* @param _nativeForDst The amount of native air dropped to the receiver.
* @param _receiver The _nativeForDst receiver address.
* @return legacyOptions The encoded legacy options of type 2.
*/
function encodeLegacyOptionsType2(
uint256 _executionGas,
uint256 _nativeForDst,
bytes memory _receiver // @dev Use bytes instead of bytes32 in legacy type 2 for _receiver.
) internal pure returns (bytes memory) {
if (_executionGas > type(uint128).max) revert InvalidSize(type(uint128).max, _executionGas);
if (_nativeForDst > type(uint128).max) revert InvalidSize(type(uint128).max, _nativeForDst);
if (_receiver.length > 32) revert InvalidSize(32, _receiver.length);
return abi.encodePacked(TYPE_2, _executionGas, _nativeForDst, _receiver);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (access/Ownable.sol)
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* The initial owner is set to the address provided by the deployer. This can
* later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
/**
* @dev The caller account is not authorized to perform an operation.
*/
error OwnableUnauthorizedAccount(address account);
/**
* @dev The owner is not a valid owner account. (eg. `address(0)`)
*/
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the address provided by the deployer as the initial owner.
*/
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (interfaces/IERC1363.sol)
pragma solidity ^0.8.20;
import {IERC20} from "./IERC20.sol";
import {IERC165} from "./IERC165.sol";
/**
* @title IERC1363
* @dev Interface of the ERC-1363 standard as defined in the https://eips.ethereum.org/EIPS/eip-1363[ERC-1363].
*
* Defines an extension interface for ERC-20 tokens that supports executing code on a recipient contract
* after `transfer` or `transferFrom`, or code on a spender contract after `approve`, in a single transaction.
*/
interface IERC1363 is IERC20, IERC165 {
/*
* Note: the ERC-165 identifier for this interface is 0xb0202a11.
* 0xb0202a11 ===
* bytes4(keccak256('transferAndCall(address,uint256)')) ^
* bytes4(keccak256('transferAndCall(address,uint256,bytes)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256)')) ^
* bytes4(keccak256('transferFromAndCall(address,address,uint256,bytes)')) ^
* bytes4(keccak256('approveAndCall(address,uint256)')) ^
* bytes4(keccak256('approveAndCall(address,uint256,bytes)'))
*/
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferAndCall(address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the allowance mechanism
* and then calls {IERC1363Receiver-onTransferReceived} on `to`.
* @param from The address which you want to send tokens from.
* @param to The address which you want to transfer to.
* @param value The amount of tokens to be transferred.
* @param data Additional data with no specified format, sent in call to `to`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function transferFromAndCall(address from, address to, uint256 value, bytes calldata data) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value) external returns (bool);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens and then calls {IERC1363Spender-onApprovalReceived} on `spender`.
* @param spender The address which will spend the funds.
* @param value The amount of tokens to be spent.
* @param data Additional data with no specified format, sent in call to `spender`.
* @return A boolean value indicating whether the operation succeeded unless throwing.
*/
function approveAndCall(address spender, uint256 value, bytes calldata data) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC165.sol)
pragma solidity ^0.8.20;
import {IERC165} from "../utils/introspection/IERC165.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.0) (interfaces/IERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../token/ERC20/IERC20.sol";// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.20;
/**
* @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed
* behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Storage of the initializable contract.
*
* It's implemented on a custom ERC-7201 namespace to reduce the risk of storage collisions
* when using with upgradeable contracts.
*
* @custom:storage-location erc7201:openzeppelin.storage.Initializable
*/
struct InitializableStorage {
/**
* @dev Indicates that the contract has been initialized.
*/
uint64 _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool _initializing;
}
// keccak256(abi.encode(uint256(keccak256("openzeppelin.storage.Initializable")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant INITIALIZABLE_STORAGE = 0xf0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00;
/**
* @dev The contract is already initialized.
*/
error InvalidInitialization();
/**
* @dev The contract is not initializing.
*/
error NotInitializing();
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint64 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that in the context of a constructor an `initializer` may be invoked any
* number of times. This behavior in the constructor can be useful during testing and is not expected to be used in
* production.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
// Cache values to avoid duplicated sloads
bool isTopLevelCall = !$._initializing;
uint64 initialized = $._initialized;
// Allowed calls:
// - initialSetup: the contract is not in the initializing state and no previous version was
// initialized
// - construction: the contract is initialized at version 1 (no reinitialization) and the
// current contract is just being deployed
bool initialSetup = initialized == 0 && isTopLevelCall;
bool construction = initialized == 1 && address(this).code.length == 0;
if (!initialSetup && !construction) {
revert InvalidInitialization();
}
$._initialized = 1;
if (isTopLevelCall) {
$._initializing = true;
}
_;
if (isTopLevelCall) {
$._initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: Setting the version to 2**64 - 1 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint64 version) {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing || $._initialized >= version) {
revert InvalidInitialization();
}
$._initialized = version;
$._initializing = true;
_;
$._initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
_checkInitializing();
_;
}
/**
* @dev Reverts if the contract is not in an initializing state. See {onlyInitializing}.
*/
function _checkInitializing() internal view virtual {
if (!_isInitializing()) {
revert NotInitializing();
}
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
// solhint-disable-next-line var-name-mixedcase
InitializableStorage storage $ = _getInitializableStorage();
if ($._initializing) {
revert InvalidInitialization();
}
if ($._initialized != type(uint64).max) {
$._initialized = type(uint64).max;
emit Initialized(type(uint64).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint64) {
return _getInitializableStorage()._initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _getInitializableStorage()._initializing;
}
/**
* @dev Pointer to storage slot. Allows integrators to override it with a custom storage location.
*
* NOTE: Consider following the ERC-7201 formula to derive storage locations.
*/
function _initializableStorageSlot() internal pure virtual returns (bytes32) {
return INITIALIZABLE_STORAGE;
}
/**
* @dev Returns a pointer to the storage namespace.
*/
// solhint-disable-next-line var-name-mixedcase
function _getInitializableStorage() private pure returns (InitializableStorage storage $) {
bytes32 slot = _initializableStorageSlot();
assembly {
$.slot := slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-20 standard as defined in the ERC.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the value of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the value of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves a `value` amount of tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, uint256 value) external returns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/
function allowance(address owner, address spender) external view returns (uint256);
/**
* @dev Sets a `value` amount of tokens as the allowance of `spender` over the
* caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/
function approve(address spender, uint256 value) external returns (bool);
/**
* @dev Moves a `value` amount of tokens from `from` to `to` using the
* allowance mechanism. `value` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 value) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.3.0) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC1363} from "../../../interfaces/IERC1363.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC-20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
/**
* @dev An operation with an ERC-20 token failed.
*/
error SafeERC20FailedOperation(address token);
/**
* @dev Indicates a failed `decreaseAllowance` request.
*/
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}
/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `requestedDecrease`. If `token` returns no
* value, non-reverting calls are assumed to be successful.
*
* IMPORTANT: If the token implements ERC-7674 (ERC-20 with temporary allowance), and if the "client"
* smart contract uses ERC-7674 to set temporary allowances, then the "client" smart contract should avoid using
* this function. Performing a {safeIncreaseAllowance} or {safeDecreaseAllowance} operation on a token contract
* that has a non-zero temporary allowance (for that particular owner-spender) will result in unexpected behavior.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*
* NOTE: If the token implements ERC-7674, this function will not modify any temporary allowance. This function
* only sets the "standard" allowance. Any temporary allowance will remain active, in addition to the value being
* set here.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Performs an {ERC1363} transferAndCall, with a fallback to the simple {ERC20} transfer if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
safeTransfer(token, to, value);
} else if (!token.transferAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} transferFromAndCall, with a fallback to the simple {ERC20} transferFrom if the target
* has no code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* Reverts if the returned value is other than `true`.
*/
function transferFromAndCallRelaxed(
IERC1363 token,
address from,
address to,
uint256 value,
bytes memory data
) internal {
if (to.code.length == 0) {
safeTransferFrom(token, from, to, value);
} else if (!token.transferFromAndCall(from, to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Performs an {ERC1363} approveAndCall, with a fallback to the simple {ERC20} approve if the target has no
* code. This can be used to implement an {ERC721}-like safe transfer that rely on {ERC1363} checks when
* targeting contracts.
*
* NOTE: When the recipient address (`to`) has no code (i.e. is an EOA), this function behaves as {forceApprove}.
* Opposedly, when the recipient address (`to`) has code, this function only attempts to call {ERC1363-approveAndCall}
* once without retrying, and relies on the returned value to be true.
*
* Reverts if the returned value is other than `true`.
*/
function approveAndCallRelaxed(IERC1363 token, address to, uint256 value, bytes memory data) internal {
if (to.code.length == 0) {
forceApprove(token, to, value);
} else if (!token.approveAndCall(to, value, data)) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturnBool} that reverts if call fails to meet the requirements.
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
let success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
// bubble errors
if iszero(success) {
let ptr := mload(0x40)
returndatacopy(ptr, 0, returndatasize())
revert(ptr, returndatasize())
}
returnSize := returndatasize()
returnValue := mload(0)
}
if (returnSize == 0 ? address(token).code.length == 0 : returnValue != 1) {
revert SafeERC20FailedOperation(address(token));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silently catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
bool success;
uint256 returnSize;
uint256 returnValue;
assembly ("memory-safe") {
success := call(gas(), token, 0, add(data, 0x20), mload(data), 0, 0x20)
returnSize := returndatasize()
returnValue := mload(0)
}
return success && (returnSize == 0 ? address(token).code.length > 0 : returnValue == 1);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (utils/Address.sol)
pragma solidity ^0.8.20;
import {Errors} from "./Errors.sol";
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev There's no code at `target` (it is not a contract).
*/
error AddressEmptyCode(address target);
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.20/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert Errors.InsufficientBalance(address(this).balance, amount);
}
(bool success, bytes memory returndata) = recipient.call{value: amount}("");
if (!success) {
_revert(returndata);
}
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason or custom error, it is bubbled
* up by this function (like regular Solidity function calls). However, if
* the call reverted with no returned reason, this function reverts with a
* {Errors.FailedCall} error.
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert Errors.InsufficientBalance(address(this).balance, value);
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and reverts if the target
* was not a contract or bubbling up the revert reason (falling back to {Errors.FailedCall}) in case
* of an unsuccessful call.
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
// only check if target is a contract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
/**
* @dev Tool to verify that a low level call was successful, and reverts if it wasn't, either by bubbling the
* revert reason or with a default {Errors.FailedCall} error.
*/
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
/**
* @dev Reverts with returndata if present. Otherwise reverts with {Errors.FailedCall}.
*/
function _revert(bytes memory returndata) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
assembly ("memory-safe") {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert Errors.FailedCall();
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.0.1) (utils/Context.sol)
pragma solidity ^0.8.20;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/Errors.sol)
pragma solidity ^0.8.20;
/**
* @dev Collection of common custom errors used in multiple contracts
*
* IMPORTANT: Backwards compatibility is not guaranteed in future versions of the library.
* It is recommended to avoid relying on the error API for critical functionality.
*
* _Available since v5.1._
*/
library Errors {
/**
* @dev The ETH balance of the account is not enough to perform the operation.
*/
error InsufficientBalance(uint256 balance, uint256 needed);
/**
* @dev A call to an address target failed. The target may have reverted.
*/
error FailedCall();
/**
* @dev The deployment failed.
*/
error FailedDeployment();
/**
* @dev A necessary precompile is missing.
*/
error MissingPrecompile(address);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/introspection/IERC165.sol)
pragma solidity ^0.8.20;
/**
* @dev Interface of the ERC-165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[ERC].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[ERC section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
pragma solidity ^0.8.20;
/**
* @dev Wrappers over Solidity's uintXX/intXX/bool casting operators with added overflow
* checks.
*
* Downcasting from uint256/int256 in Solidity does not revert on overflow. This can
* easily result in undesired exploitation or bugs, since developers usually
* assume that overflows raise errors. `SafeCast` restores this intuition by
* reverting the transaction when such an operation overflows.
*
* Using this library instead of the unchecked operations eliminates an entire
* class of bugs, so it's recommended to use it always.
*/
library SafeCast {
/**
* @dev Value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedUintDowncast(uint8 bits, uint256 value);
/**
* @dev An int value doesn't fit in an uint of `bits` size.
*/
error SafeCastOverflowedIntToUint(int256 value);
/**
* @dev Value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedIntDowncast(uint8 bits, int256 value);
/**
* @dev An uint value doesn't fit in an int of `bits` size.
*/
error SafeCastOverflowedUintToInt(uint256 value);
/**
* @dev Returns the downcasted uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toUint248(uint256 value) internal pure returns (uint248) {
if (value > type(uint248).max) {
revert SafeCastOverflowedUintDowncast(248, value);
}
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toUint240(uint256 value) internal pure returns (uint240) {
if (value > type(uint240).max) {
revert SafeCastOverflowedUintDowncast(240, value);
}
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toUint232(uint256 value) internal pure returns (uint232) {
if (value > type(uint232).max) {
revert SafeCastOverflowedUintDowncast(232, value);
}
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toUint224(uint256 value) internal pure returns (uint224) {
if (value > type(uint224).max) {
revert SafeCastOverflowedUintDowncast(224, value);
}
return uint224(value);
}
/**
* @dev Returns the downcasted uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toUint216(uint256 value) internal pure returns (uint216) {
if (value > type(uint216).max) {
revert SafeCastOverflowedUintDowncast(216, value);
}
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toUint208(uint256 value) internal pure returns (uint208) {
if (value > type(uint208).max) {
revert SafeCastOverflowedUintDowncast(208, value);
}
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toUint200(uint256 value) internal pure returns (uint200) {
if (value > type(uint200).max) {
revert SafeCastOverflowedUintDowncast(200, value);
}
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toUint192(uint256 value) internal pure returns (uint192) {
if (value > type(uint192).max) {
revert SafeCastOverflowedUintDowncast(192, value);
}
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toUint184(uint256 value) internal pure returns (uint184) {
if (value > type(uint184).max) {
revert SafeCastOverflowedUintDowncast(184, value);
}
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toUint176(uint256 value) internal pure returns (uint176) {
if (value > type(uint176).max) {
revert SafeCastOverflowedUintDowncast(176, value);
}
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toUint168(uint256 value) internal pure returns (uint168) {
if (value > type(uint168).max) {
revert SafeCastOverflowedUintDowncast(168, value);
}
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toUint160(uint256 value) internal pure returns (uint160) {
if (value > type(uint160).max) {
revert SafeCastOverflowedUintDowncast(160, value);
}
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toUint152(uint256 value) internal pure returns (uint152) {
if (value > type(uint152).max) {
revert SafeCastOverflowedUintDowncast(152, value);
}
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toUint144(uint256 value) internal pure returns (uint144) {
if (value > type(uint144).max) {
revert SafeCastOverflowedUintDowncast(144, value);
}
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toUint136(uint256 value) internal pure returns (uint136) {
if (value > type(uint136).max) {
revert SafeCastOverflowedUintDowncast(136, value);
}
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toUint128(uint256 value) internal pure returns (uint128) {
if (value > type(uint128).max) {
revert SafeCastOverflowedUintDowncast(128, value);
}
return uint128(value);
}
/**
* @dev Returns the downcasted uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toUint120(uint256 value) internal pure returns (uint120) {
if (value > type(uint120).max) {
revert SafeCastOverflowedUintDowncast(120, value);
}
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toUint112(uint256 value) internal pure returns (uint112) {
if (value > type(uint112).max) {
revert SafeCastOverflowedUintDowncast(112, value);
}
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toUint104(uint256 value) internal pure returns (uint104) {
if (value > type(uint104).max) {
revert SafeCastOverflowedUintDowncast(104, value);
}
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toUint96(uint256 value) internal pure returns (uint96) {
if (value > type(uint96).max) {
revert SafeCastOverflowedUintDowncast(96, value);
}
return uint96(value);
}
/**
* @dev Returns the downcasted uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toUint88(uint256 value) internal pure returns (uint88) {
if (value > type(uint88).max) {
revert SafeCastOverflowedUintDowncast(88, value);
}
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toUint80(uint256 value) internal pure returns (uint80) {
if (value > type(uint80).max) {
revert SafeCastOverflowedUintDowncast(80, value);
}
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toUint72(uint256 value) internal pure returns (uint72) {
if (value > type(uint72).max) {
revert SafeCastOverflowedUintDowncast(72, value);
}
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toUint64(uint256 value) internal pure returns (uint64) {
if (value > type(uint64).max) {
revert SafeCastOverflowedUintDowncast(64, value);
}
return uint64(value);
}
/**
* @dev Returns the downcasted uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toUint56(uint256 value) internal pure returns (uint56) {
if (value > type(uint56).max) {
revert SafeCastOverflowedUintDowncast(56, value);
}
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toUint48(uint256 value) internal pure returns (uint48) {
if (value > type(uint48).max) {
revert SafeCastOverflowedUintDowncast(48, value);
}
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toUint40(uint256 value) internal pure returns (uint40) {
if (value > type(uint40).max) {
revert SafeCastOverflowedUintDowncast(40, value);
}
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toUint32(uint256 value) internal pure returns (uint32) {
if (value > type(uint32).max) {
revert SafeCastOverflowedUintDowncast(32, value);
}
return uint32(value);
}
/**
* @dev Returns the downcasted uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toUint24(uint256 value) internal pure returns (uint24) {
if (value > type(uint24).max) {
revert SafeCastOverflowedUintDowncast(24, value);
}
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toUint16(uint256 value) internal pure returns (uint16) {
if (value > type(uint16).max) {
revert SafeCastOverflowedUintDowncast(16, value);
}
return uint16(value);
}
/**
* @dev Returns the downcasted uint8 from uint256, reverting on
* overflow (when the input is greater than largest uint8).
*
* Counterpart to Solidity's `uint8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toUint8(uint256 value) internal pure returns (uint8) {
if (value > type(uint8).max) {
revert SafeCastOverflowedUintDowncast(8, value);
}
return uint8(value);
}
/**
* @dev Converts a signed int256 into an unsigned uint256.
*
* Requirements:
*
* - input must be greater than or equal to 0.
*/
function toUint256(int256 value) internal pure returns (uint256) {
if (value < 0) {
revert SafeCastOverflowedIntToUint(value);
}
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(248, value);
}
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(240, value);
}
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(232, value);
}
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(224, value);
}
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(216, value);
}
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(208, value);
}
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(200, value);
}
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(192, value);
}
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(184, value);
}
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(176, value);
}
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(168, value);
}
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(160, value);
}
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(152, value);
}
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(144, value);
}
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(136, value);
}
}
/**
* @dev Returns the downcasted int128 from int256, reverting on
* overflow (when the input is less than smallest int128 or
* greater than largest int128).
*
* Counterpart to Solidity's `int128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*/
function toInt128(int256 value) internal pure returns (int128 downcasted) {
downcasted = int128(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(128, value);
}
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(120, value);
}
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(112, value);
}
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(104, value);
}
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(96, value);
}
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(88, value);
}
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(80, value);
}
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(72, value);
}
}
/**
* @dev Returns the downcasted int64 from int256, reverting on
* overflow (when the input is less than smallest int64 or
* greater than largest int64).
*
* Counterpart to Solidity's `int64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*/
function toInt64(int256 value) internal pure returns (int64 downcasted) {
downcasted = int64(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(64, value);
}
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(56, value);
}
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(48, value);
}
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(40, value);
}
}
/**
* @dev Returns the downcasted int32 from int256, reverting on
* overflow (when the input is less than smallest int32 or
* greater than largest int32).
*
* Counterpart to Solidity's `int32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*/
function toInt32(int256 value) internal pure returns (int32 downcasted) {
downcasted = int32(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(32, value);
}
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(24, value);
}
}
/**
* @dev Returns the downcasted int16 from int256, reverting on
* overflow (when the input is less than smallest int16 or
* greater than largest int16).
*
* Counterpart to Solidity's `int16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*/
function toInt16(int256 value) internal pure returns (int16 downcasted) {
downcasted = int16(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(16, value);
}
}
/**
* @dev Returns the downcasted int8 from int256, reverting on
* overflow (when the input is less than smallest int8 or
* greater than largest int8).
*
* Counterpart to Solidity's `int8` operator.
*
* Requirements:
*
* - input must fit into 8 bits
*/
function toInt8(int256 value) internal pure returns (int8 downcasted) {
downcasted = int8(value);
if (downcasted != value) {
revert SafeCastOverflowedIntDowncast(8, value);
}
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*/
function toInt256(uint256 value) internal pure returns (int256) {
// Note: Unsafe cast below is okay because `type(int256).max` is guaranteed to be positive
if (value > uint256(type(int256).max)) {
revert SafeCastOverflowedUintToInt(value);
}
return int256(value);
}
/**
* @dev Cast a boolean (false or true) to a uint256 (0 or 1) with no jump.
*/
function toUint(bool b) internal pure returns (uint256 u) {
assembly ("memory-safe") {
u := iszero(iszero(b))
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.1.0) (utils/ReentrancyGuard.sol)
pragma solidity ^0.8.20;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If EIP-1153 (transient storage) is available on the chain you're deploying at,
* consider using {ReentrancyGuardTransient} instead.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
/**
* @dev Unauthorized reentrant call.
*/
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be NOT_ENTERED
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
// Any calls to nonReentrant after this point will fail
_status = ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IAxelarGateway } from '../interfaces/IAxelarGateway.sol';
import { IAxelarExecutable } from '../interfaces/IAxelarExecutable.sol';
contract AxelarExecutable is IAxelarExecutable {
IAxelarGateway public gateway;
constructor(address gateway_) {
if (gateway_ == address(0)) revert InvalidAddress();
gateway = IAxelarGateway(gateway_);
}
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) external {
bytes32 payloadHash = keccak256(payload);
if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, payloadHash))
revert NotApprovedByGateway();
_execute(sourceChain, sourceAddress, payload);
}
function executeWithToken(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) external {
bytes32 payloadHash = keccak256(payload);
if (
!gateway.validateContractCallAndMint(
commandId,
sourceChain,
sourceAddress,
payloadHash,
tokenSymbol,
amount
)
) revert NotApprovedByGateway();
_executeWithToken(sourceChain, sourceAddress, payload, tokenSymbol, amount);
}
function _execute(
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) internal virtual {}
function _executeWithToken(
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) internal virtual {}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IAxelarGateway } from './IAxelarGateway.sol';
interface IAxelarExecutable {
error InvalidAddress();
error NotApprovedByGateway();
function gateway() external view returns (IAxelarGateway);
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) external;
function executeWithToken(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IGovernable } from './IGovernable.sol';
import { IImplementation } from './IImplementation.sol';
interface IAxelarGateway is IImplementation, IGovernable {
/**********\
|* Errors *|
\**********/
error NotSelf();
error InvalidCodeHash();
error SetupFailed();
error InvalidAuthModule();
error InvalidTokenDeployer();
error InvalidAmount();
error InvalidChainId();
error InvalidCommands();
error TokenDoesNotExist(string symbol);
error TokenAlreadyExists(string symbol);
error TokenDeployFailed(string symbol);
error TokenContractDoesNotExist(address token);
error BurnFailed(string symbol);
error MintFailed(string symbol);
error InvalidSetMintLimitsParams();
error ExceedMintLimit(string symbol);
/**********\
|* Events *|
\**********/
event TokenSent(
address indexed sender,
string destinationChain,
string destinationAddress,
string symbol,
uint256 amount
);
event ContractCall(
address indexed sender,
string destinationChain,
string destinationContractAddress,
bytes32 indexed payloadHash,
bytes payload
);
event ContractCallWithToken(
address indexed sender,
string destinationChain,
string destinationContractAddress,
bytes32 indexed payloadHash,
bytes payload,
string symbol,
uint256 amount
);
event Executed(bytes32 indexed commandId);
event TokenDeployed(string symbol, address tokenAddresses);
event ContractCallApproved(
bytes32 indexed commandId,
string sourceChain,
string sourceAddress,
address indexed contractAddress,
bytes32 indexed payloadHash,
bytes32 sourceTxHash,
uint256 sourceEventIndex
);
event ContractCallApprovedWithMint(
bytes32 indexed commandId,
string sourceChain,
string sourceAddress,
address indexed contractAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
bytes32 sourceTxHash,
uint256 sourceEventIndex
);
event ContractCallExecuted(bytes32 indexed commandId);
event TokenMintLimitUpdated(string symbol, uint256 limit);
event OperatorshipTransferred(bytes newOperatorsData);
event Upgraded(address indexed implementation);
/********************\
|* Public Functions *|
\********************/
function sendToken(
string calldata destinationChain,
string calldata destinationAddress,
string calldata symbol,
uint256 amount
) external;
function callContract(
string calldata destinationChain,
string calldata contractAddress,
bytes calldata payload
) external;
function callContractWithToken(
string calldata destinationChain,
string calldata contractAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount
) external;
function isContractCallApproved(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
address contractAddress,
bytes32 payloadHash
) external view returns (bool);
function isContractCallAndMintApproved(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
address contractAddress,
bytes32 payloadHash,
string calldata symbol,
uint256 amount
) external view returns (bool);
function validateContractCall(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes32 payloadHash
) external returns (bool);
function validateContractCallAndMint(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes32 payloadHash,
string calldata symbol,
uint256 amount
) external returns (bool);
/***********\
|* Getters *|
\***********/
function authModule() external view returns (address);
function tokenDeployer() external view returns (address);
function tokenMintLimit(string memory symbol) external view returns (uint256);
function tokenMintAmount(string memory symbol) external view returns (uint256);
function allTokensFrozen() external view returns (bool);
function implementation() external view returns (address);
function tokenAddresses(string memory symbol) external view returns (address);
function tokenFrozen(string memory symbol) external view returns (bool);
function isCommandExecuted(bytes32 commandId) external view returns (bool);
/************************\
|* Governance Functions *|
\************************/
function setTokenMintLimits(string[] calldata symbols, uint256[] calldata limits) external;
function upgrade(
address newImplementation,
bytes32 newImplementationCodeHash,
bytes calldata setupParams
) external;
/**********************\
|* External Functions *|
\**********************/
function execute(bytes calldata input) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// General interface for upgradable contracts
interface IContractIdentifier {
/**
* @notice Returns the contract ID. It can be used as a check during upgrades.
* @dev Meant to be overridden in derived contracts.
* @return bytes32 The contract ID
*/
function contractId() external pure returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ICoral {
/// @notice Fill type that designates what method to be used on the Spoke on the source chain
/// upon releasing tokens to the filler.
/// SINGLE is used when a batch of orders only contains a single unique order.fromToken, and only requires
/// a single transfer to release the tokens for the batch of orders to the order.filler.
/// MULTI is used when a batch of orders contains multiple unique order.fromToken, and will use as many
/// transfers as there are unique tokens in the batch.
enum FillType {
// Single token release.
SINGLE,
// Multi token release.
MULTI
}
/// @notice Defines the cross-chain messaging provider options available for executing interchain transactions.
/// Each provider represents a specific protocol for sending and receiving messages across blockchains.
enum Provider {
AXELAR,
LAYERZERO
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title IGovernable Interface
* @notice This is an interface used by the AxelarGateway contract to manage governance and mint limiter roles.
*/
interface IGovernable {
error NotGovernance();
error NotMintLimiter();
error InvalidGovernance();
error InvalidMintLimiter();
event GovernanceTransferred(address indexed previousGovernance, address indexed newGovernance);
event MintLimiterTransferred(address indexed previousGovernance, address indexed newGovernance);
/**
* @notice Returns the governance address.
* @return address of the governance
*/
function governance() external view returns (address);
/**
* @notice Returns the mint limiter address.
* @return address of the mint limiter
*/
function mintLimiter() external view returns (address);
/**
* @notice Transfer the governance role to another address.
* @param newGovernance The new governance address
*/
function transferGovernance(address newGovernance) external;
/**
* @notice Transfer the mint limiter role to another address.
* @param newGovernance The new mint limiter address
*/
function transferMintLimiter(address newGovernance) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IContractIdentifier } from './IContractIdentifier.sol';
interface IImplementation is IContractIdentifier {
error NotProxy();
function setup(bytes calldata data) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {IAxelarGateway} from "./IAxelarGateway.sol";
import {IAxelarGasService} from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol";
import {ICoral} from "./ICoral.sol";
import {ISquidMulticall} from "./ISquidMulticall.sol";
/// @title Spoke
/// @notice Entry point of the protocol. The Spoke.sol contract manages the state of orders, token transfers,
/// and settlement.
interface ISpoke is ICoral {
/// @notice Order status type that tracks the state of an Order throughout its lifecycle on the Spoke.
enum OrderStatus {
// Order does not exist.
EMPTY,
// Order has been created, pending settlement.
CREATED,
// Order has been settled.
SETTLED,
// Order has been refunded.
REFUNDED
}
/// @notice Settlement status type that tracks the settlement state of an Order throughout its lifecycle on the Spoke.
enum SettlementStatus {
// Order settlement does not exist.
EMPTY,
// Order has been filled.
FILLED,
// Order has been forwarded to the Hub pending source token release.
FORWARDED
}
/// @notice Calldata format expected by the Spoke.sol contract.
struct Order {
// Address that will supply the fromAmount of fromToken on the fromChain.
address fromAddress;
// Address to receive the fillAmount of toToken on the toChain.
address toAddress;
// Address that will fill the Order on the toChain.
address filler;
// Address of the ERC20 token being supplied on the fromChain.
// 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE in case of native token.
address fromToken;
// Address of the ERC20 token being supplied on the toChain.
// 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE in case of native token.
address toToken;
// Expiration in UNIX for the Order to be created on the fromChain.
uint256 expiry;
// Amount of fromToken to be provided by the fromAddress.
uint256 fromAmount;
// Amount of toToken to be provided by the filler.
uint256 fillAmount;
// Protocol fees are taken out of the fromAmount and are calculated within the Spoke.sol
// contract for single chain orders or on the Hub for cross chain orders.
// The following formula determines the amount of fromToken reserved as fees:
// fee = (fromAmount * feeRate) / 1000000
uint256 feeRate;
// Chain ID of the chain the Order will be created on.
uint256 fromChain;
// Chain ID of the chain the Order will be filled on.
uint256 toChain;
// Keccak256 hash of the abi.encoded ISquidMulticall.Call[] calldata calls that should be provided
// at the time of filling the order.
bytes32 postHookHash;
}
/// @notice Emitted when the Spoke.sol contract is successfully initialized after contract deployment.
/// @param gateway Address set as the relevant Axelar's AxelarGateway.sol contract deployment.
/// @param gasService Address set as the relevant Axelar's AxelarGasService.sol contract deployment.
/// @param squidMulticall Address set as the relevant Squid's SquidMulticall.sol contract deployment.
/// @param feeCollector Address set as the EOA that can collect fees from the protocol.
/// @param hubChainName Chain name of the chain the Hub.sol contract is deployed to.
/// @param hubAddress Address set as the relevant Hub.sol contract.
event SpokeInitialized(
IAxelarGateway indexed gateway,
IAxelarGasService indexed gasService,
ISquidMulticall squidMulticall,
address feeCollector,
string hubChainName,
string hubAddress
);
/// @dev Source events
/// @notice Emitted when fees are collected from the Spoke.sol contract.
/// @param feeCollector Address of the EOA that collected fees.
/// @param token Token for which fees were collected.
/// @param amount Amount of token for which fees were collected.
event FeesCollected(
address indexed feeCollector,
address indexed token,
uint256 indexed amount
);
/// @notice Emitted when an Order is created on the source chain.
/// @param orderHash Keccak256 hash of the Order that was created.
/// @param order Raw Order struct of the Order that was created.
event OrderCreated(bytes32 indexed orderHash, Order order);
/// @notice Emitted when an Order is refunded on the source chain.
/// @param orderHash Keccak256 hash of the Order that was refunded.
event OrderRefunded(bytes32 indexed orderHash);
/// @notice Emitted when an Order has been settled and tokens released to the filler, completing
/// its lifecycle.
/// @param orderHash Keccak256 hash of the Order that was settled.
event TokensReleased(bytes32 indexed orderHash);
/// @dev Destination events
/// @notice Emitted when an Order is filled on the source chain.
/// @param orderHash Keccak256 hash of the Order that was filled.
/// @param order Raw Order struct of the Order that was filled.
event OrderFilled(bytes32 indexed orderHash, Order order);
/// @notice Emitted when an Order settlement has been forwarded to the Hub for processing.
/// @param orderHash Keccak256 hash of the Order that was forwarded.
event SettlementForwarded(bytes32 indexed orderHash);
/// @notice Thrown when zero msg.value is provided to a function that requires extra native tokens to be
/// supplied to pay for gas needs.
error GasRequired();
/// @notice Thrown when an array has an incorrect length.
error InvalidArrayLength();
/// @notice Thrown when the targeted chain is not equal to the order.toChain of the provided Order.
error InvalidDestinationChain();
/// @notice Thrown when an invalid FillType is provided to the Axelar GMP targeting the Spoke.sol contract.
error InvalidFillType();
/// @notice Thrown when the provided msg.value does not match the order.fromAmount or order.fillAmount of
/// the provided Order that deals with native tokens.
error InvalidNativeAmount();
/// @notice Thrown when the order.postHookHash of the provided Order does not match the keccak256 hash of
/// the abi.encoded ISquidMulticall.Call[] calldata calls provided while filling an Order.
error InvalidPostHookProvided();
/// @notice Thrown when an invalid cross-chain messaging provider is provided to the forwarding function.
error InvalidProvider();
/// @notice Thrown when the targeted chain is not equal to the order.fromChain of the provided Order.
error InvalidSourceChain();
/// @notice Thrown when the caller address is not equal to the feeCollecter address set within the initializer.
error OnlyFeeCollector();
/// @notice Thrown when the caller msg.sender is not equal to the order.filler of the provided Order.
error OnlyFillerCanSettle();
/// @notice Thrown when an Axelar GMP is executed from an address or chain that does not match the
/// hubChainName and hubAddress set within the initializer.
error OnlyTrustedAddress();
/// @notice Thrown when the orderHashToStatus of the orderHash of the provided Order is not in the
// required OrderStatus.EMPTY state.
error OrderAlreadyExists();
/// @notice Thrown when the settlementToStatus of the orderHash of the provided Order is not in the
// required SettlementStatus.EMPTY state.
error OrderAlreadySettled();
/// @notice Thrown when the current block.timestamp is greater than the order.expiry of the provided Order.
error OrderExpired();
/// @notice Thrown when the current block.timestamp is not greater than the order.expiry + buffer
/// when attempting to refund an order.
error OrderNotExpired();
/// @notice Thrown when the settlementToStatus of the orderHash of the provided Order is not in the
// required SettlementStatus.FILLED state.
error OrderNotSettled();
/// @notice Thrown when the orderHashToStatus of the orderHash of the provided Order is not in the
// required OrderStatus.CREATED state.
error OrderStateNotCreated();
/// @notice Thrown when the order.fromToken of a provided Order is not a native token and a non-zero
/// msg.value is provided.
error UnexpectedNativeToken();
/// @notice Thrown when a LayerZero GMP is executed from an address that does not match the hubAddressBytes32
/// set within the initializer.
error UnauthorizedOriginAddress();
/// @notice Thrown when a LayerZero GMP is executed from an inactive or unapproved chain endpoint.
error UnauthorizedOriginEndpoint();
/// @notice Executes the intent on the source chain, locking the ERC20 or native tokens in the
/// Spoke.sol contract, setting the OrderStatus to CREATED, and making the order eligible
/// to be filled on the destination chain.
/// @dev Orders are tied to the keccak256 hash of the Order therefore each Order is unique
/// according to the parameters in the Order and can only be executed a single time. Using this
/// method tokens will transfer from the msg.sender, but the order will belong to the
/// order.fromAddress.
/// @param order Order to be executed by the Spoke.sol contract in the format of the Order struct.
function createOrder(Order calldata order) external payable;
/// @notice Refunds an eligible Order, transferring the order.fromAmount of order.fromToken from
/// the Spoke.sol contract to the order.fromAddress.
/// @dev Orders can be instantly refunded by the order.filler if the filler decides they don't wish
/// to fill the order.
/// @dev Orders can be refunded by anyone as long is the block.timestamp of the target chain is
/// greater than the order.expiry + 96 hours.
/// @param order Order to be refunded by the Spoke.sol contract in the format of the Order struct.
function refundOrder(Order calldata order) external;
/// @notice Transfers collected protocol fees from the Spoke.sol contract to the feeCollector and
/// sets the fee balance for the provided tokens to zero.
/// @dev Fees can be collected for all ERC20 and native tokens, this method will transfer the full
/// balance of the currently collected fees per token provided.
/// @param tokens Array of ERC20 tokens to collect fees for.
function collectFees(address[] calldata tokens) external;
/// @notice Fills an order on the destination chain, transferring the order.fillAmount of
/// order.toToken from the order.filler to the order.toAddress, setting the SettlementStatus to
/// FILLED, and making the order eligible to be forwarded to the Hub for processing.
/// @dev Orders that contain post hooks (postHookHash != bytes32(0)) require SquidMulticall calls
/// to be provided during fill. These extra calls will be ran by SquidMulticall after filling the
/// order during the same transaction.
/// @dev Only the order.filler can fill any particular order.
/// @param order Order to be filled by the Spoke.sol contract in the format of the Order struct.
/// @param calls Calls to be ran by the multicall after fill, formatted to the SquidMulticall Call struct.
function fillOrder(Order calldata order, ISquidMulticall.Call[] calldata calls) external payable;
/// @notice Sets the SettlementStatus of orders to FORWARDED and executes an Axelar GMP containing
/// an array of eligible order hashes to be sent cross chain to the Hub for processing.
/// @dev Provided orders must have the settlementToStatus set FILLED to be eligible to be forwarded.
/// @dev Gas is required in the form of native tokens, therefore the msg.value must contain enough
/// native token to pay for the Axelar GMP and execution costs of the calldata on the Hub.
/// @dev It is recommended to forward settlements in batches, the number of orders that can be forwarded
/// in a batch is dependent on the block gas limit of the particular chain.
/// @param orderHashes Array of order hashes to be forwarded by the Spoke.sol contract.
/// @param lzFee LayerZero-specific additional fee required to forward the settlement via LayerZero.
/// @param gasLimit Execution gas limit for the Message Passing to enforce execution constraints.
/// @param provider Enum indicating whether the forwarding is done through AXELAR or LAYERZERO provider.
function forwardSettlements(
bytes32[] calldata orderHashes,
uint256 lzFee,
uint128 gasLimit,
Provider provider
) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
/// @title SquidMulticall
/// @notice Multicall logic specific to Squid calls format. The contract specificity is mainly
/// to enable ERC20 and native token amounts in calldata between two calls.
/// @dev Support receiption of NFTs.
interface ISquidMulticall {
/// @notice Call type that enables to specific behaviours of the multicall.
enum CallType {
// Will simply run calldata
Default,
// Will update amount field in calldata with ERC20 token balance of the multicall contract.
FullTokenBalance,
// Will update amount field in calldata with native token balance of the multicall contract.
FullNativeBalance,
// Will run a safeTransferFrom to get full ERC20 token balance of the caller.
CollectTokenBalance
}
/// @notice Calldata format expected by multicall.
struct Call {
// Call type, see CallType struct description.
CallType callType;
// Address that will be called.
address target;
// Native token amount that will be sent in call.
uint256 value;
// Calldata that will be send in call.
bytes callData;
// Extra data used by multicall depending on call type.
// Default: unused (provide 0x)
// FullTokenBalance: address of the ERC20 token to get balance of and zero indexed position
// of the amount parameter to update in function call contained by calldata.
// Expect format is: abi.encode(address token, uint256 amountParameterPosition)
// Eg: for function swap(address tokenIn, uint amountIn, address tokenOut, uint amountOutMin,)
// amountParameterPosition would be 1.
// FullNativeBalance: unused (provide 0x)
// CollectTokenBalance: address of the ERC20 token to collect.
// Expect format is: abi.encode(address token)
bytes payload;
}
/// Thrown when one of the calls fails.
/// @param callPosition Zero indexed position of the call in the call set provided to the
/// multicall.
/// @param reason Revert data returned by contract called in failing call.
error CallFailed(uint256 callPosition, bytes reason);
/// @notice Main function of the multicall that runs the call set.
/// @param calls Call set to be ran by multicall.
function run(Call[] calldata calls) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity 0.8.23;
import {Address} from "@openzeppelin/contracts/utils/Address.sol";
/// @title Utils
/// @notice Library for general purpose functions and values.
library Utils {
using Address for address payable;
/// @notice Arbitrary address chosen to represent native token of current network.
address internal constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE;
bytes32 internal constant ORDER_TYPEHASH = keccak256("Order(address fromAddress,address toAddress,address filler,address fromToken,address toToken,uint256 expiry,uint256 fromAmount,uint256 fillAmount,uint256 feeRate,uint256 fromChain,uint256 toChain,bytes32 postHookHash)");
string internal constant ORDER_WITNESS_TYPE_STRING =
"Order witness)Order(address fromAddress,address toAddress,address filler,address fromToken,address toToken,uint256 expiry,uint256 fromAmount,uint256 fillAmount,uint256 feeRate,uint256 fromChain,uint256 toChain,bytes32 postHookHash)TokenPermissions(address token,uint256 amount)";
uint256 internal constant FEE_DIVISOR = 1000000;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IMessageLibManager } from "./IMessageLibManager.sol";
import { IMessagingComposer } from "./IMessagingComposer.sol";
import { IMessagingChannel } from "./IMessagingChannel.sol";
import { IMessagingContext } from "./IMessagingContext.sol";
struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
bool payInLzToken;
}
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}
struct Origin {
uint32 srcEid;
bytes32 sender;
uint64 nonce;
}
interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);
event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);
event PacketDelivered(Origin origin, address receiver);
event LzReceiveAlert(
address indexed receiver,
address indexed executor,
Origin origin,
bytes32 guid,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);
event LzTokenSet(address token);
event DelegateSet(address sender, address delegate);
function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);
function send(
MessagingParams calldata _params,
address _refundAddress
) external payable returns (MessagingReceipt memory);
function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;
function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);
function initializable(Origin calldata _origin, address _receiver) external view returns (bool);
function lzReceive(
Origin calldata _origin,
address _receiver,
bytes32 _guid,
bytes calldata _message,
bytes calldata _extraData
) external payable;
// oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;
function setLzToken(address _lzToken) external;
function lzToken() external view returns (address);
function nativeToken() external view returns (address);
function setDelegate(address _delegate) external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { Origin } from "./ILayerZeroEndpointV2.sol";
interface ILayerZeroReceiver {
function allowInitializePath(Origin calldata _origin) external view returns (bool);
function nextNonce(uint32 _eid, bytes32 _sender) external view returns (uint64);
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
struct SetConfigParam {
uint32 eid;
uint32 configType;
bytes config;
}
interface IMessageLibManager {
struct Timeout {
address lib;
uint256 expiry;
}
event LibraryRegistered(address newLib);
event DefaultSendLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
event SendLibrarySet(address sender, uint32 eid, address newLib);
event ReceiveLibrarySet(address receiver, uint32 eid, address newLib);
event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);
function registerLibrary(address _lib) external;
function isRegisteredLibrary(address _lib) external view returns (bool);
function getRegisteredLibraries() external view returns (address[] memory);
function setDefaultSendLibrary(uint32 _eid, address _newLib) external;
function defaultSendLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _gracePeriod) external;
function defaultReceiveLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;
function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);
function isSupportedEid(uint32 _eid) external view returns (bool);
function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);
/// ------------------- OApp interfaces -------------------
function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;
function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);
function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);
function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;
function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);
function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _expiry) external;
function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);
function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;
function getConfig(
address _oapp,
address _lib,
uint32 _eid,
uint32 _configType
) external view returns (bytes memory config);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingChannel {
event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
function eid() external view returns (uint32);
// this is an emergency function if a message cannot be verified for some reasons
// required to provide _nextNonce to avoid race condition
function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;
function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);
function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);
function inboundPayloadHash(
address _receiver,
uint32 _srcEid,
bytes32 _sender,
uint64 _nonce
) external view returns (bytes32);
function lazyInboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingComposer {
event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
event LzComposeAlert(
address indexed from,
address indexed to,
address indexed executor,
bytes32 guid,
uint16 index,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);
function composeQueue(
address _from,
address _to,
bytes32 _guid,
uint16 _index
) external view returns (bytes32 messageHash);
function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;
function lzCompose(
address _from,
address _to,
bytes32 _guid,
uint16 _index,
bytes calldata _message,
bytes calldata _extraData
) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingContext {
function isSendingMessage() external view returns (bool);
function getSendContext() external view returns (uint32 dstEid, address sender);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { ILayerZeroEndpointV2 } from "./ILayerZeroEndpointV2.sol";
/**
* @title IOAppCore
*/
interface IOAppCore {
// Custom error messages
error OnlyPeer(uint32 eid, bytes32 sender);
error NoPeer(uint32 eid);
error InvalidEndpointCall();
error InvalidDelegate();
// Event emitted when a peer (OApp) is set for a corresponding endpoint
event PeerSet(uint32 eid, bytes32 peer);
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol contract.
* @return receiverVersion The version of the OAppReceiver.sol contract.
*/
function oAppVersion() external view returns (uint64 senderVersion, uint64 receiverVersion);
/**
* @notice Retrieves the LayerZero endpoint associated with the OApp.
* @return iEndpoint The LayerZero endpoint as an interface.
*/
function endpoint() external view returns (ILayerZeroEndpointV2 iEndpoint);
/**
* @notice Retrieves the peer (OApp) associated with a corresponding endpoint.
* @param _eid The endpoint ID.
* @return peer The peer address (OApp instance) associated with the corresponding endpoint.
*/
function peers(uint32 _eid) external view returns (bytes32 peer);
/**
* @notice Sets the peer address (OApp instance) for a corresponding endpoint.
* @param _eid The endpoint ID.
* @param _peer The address of the peer to be associated with the corresponding endpoint.
*/
function setPeer(uint32 _eid, bytes32 _peer) external;
/**
* @notice Sets the delegate address for the OApp Core.
* @param _delegate The address of the delegate to be set.
*/
function setDelegate(address _delegate) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { ILayerZeroReceiver, Origin } from "./ILayerZeroReceiver.sol";
interface IOAppReceiver is ILayerZeroReceiver {
/**
* @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
* @param _origin The origin information containing the source endpoint and sender address.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address on the src chain.
* - nonce: The nonce of the message.
* @param _message The lzReceive payload.
* @param _sender The sender address.
* @return isSender Is a valid sender.
*
* @dev Applications can optionally choose to implement a separate composeMsg sender that is NOT the bridging layer.
* @dev The default sender IS the OAppReceiver implementer.
*/
function isComposeMsgSender(
Origin calldata _origin,
bytes calldata _message,
address _sender
) external view returns (bool isSender);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
// @dev Import the 'MessagingFee' and 'MessagingReceipt' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppSender, MessagingFee, MessagingReceipt } from "./OAppSender.sol";
// @dev Import the 'Origin' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppReceiver, Origin } from "./OAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";
/**
* @title OApp
* @dev Abstract contract serving as the base for OApp implementation, combining OAppSender and OAppReceiver functionality.
*/
abstract contract OApp is OAppSender, OAppReceiver {
/**
* @dev Constructor to initialize the OApp with the provided endpoint and owner.
* @param _endpoint The address of the LOCAL LayerZero endpoint.
* @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
*/
constructor(address _endpoint, address _delegate) OAppCore(_endpoint, _delegate) {}
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol implementation.
* @return receiverVersion The version of the OAppReceiver.sol implementation.
*/
function oAppVersion()
public
pure
virtual
override(OAppSender, OAppReceiver)
returns (uint64 senderVersion, uint64 receiverVersion)
{
return (SENDER_VERSION, RECEIVER_VERSION);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { IOAppCore, ILayerZeroEndpointV2 } from "./interfaces/IOAppCore.sol";
/**
* @title OAppCore
* @dev Abstract contract implementing the IOAppCore interface with basic OApp configurations.
*/
abstract contract OAppCore is IOAppCore, Ownable {
// The LayerZero endpoint associated with the given OApp
ILayerZeroEndpointV2 public endpoint;
// Mapping to store peers associated with corresponding endpoints
mapping(uint32 eid => bytes32 peer) public peers;
/**
* @dev Constructor to initialize the OAppCore with the provided endpoint and delegate.
* @param _endpoint The address of the LOCAL Layer Zero endpoint.
* @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
*
* @dev The delegate typically should be set as the owner of the contract.
*/
constructor(address _endpoint, address _delegate) {
endpoint = ILayerZeroEndpointV2(_endpoint);
if (_delegate == address(0)) revert InvalidDelegate();
// endpoint.setDelegate(_delegate);
}
/**
* @notice Sets the peer address (OApp instance) for a corresponding endpoint.
* @param _eid The endpoint ID.
* @param _peer The address of the peer to be associated with the corresponding endpoint.
*
* @dev Only the owner/admin of the OApp can call this function.
* @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
* @dev Set this to bytes32(0) to remove the peer address.
* @dev Peer is a bytes32 to accommodate non-evm chains.
*/
function setPeer(uint32 _eid, bytes32 _peer) public virtual onlyOwner {
_setPeer(_eid, _peer);
}
/**
* @notice Sets the peer address (OApp instance) for a corresponding endpoint.
* @param _eid The endpoint ID.
* @param _peer The address of the peer to be associated with the corresponding endpoint.
*
* @dev Indicates that the peer is trusted to send LayerZero messages to this OApp.
* @dev Set this to bytes32(0) to remove the peer address.
* @dev Peer is a bytes32 to accommodate non-evm chains.
*/
function _setPeer(uint32 _eid, bytes32 _peer) internal virtual {
peers[_eid] = _peer;
emit PeerSet(_eid, _peer);
}
/**
* @notice Internal function to get the peer address associated with a specific endpoint; reverts if NOT set.
* ie. the peer is set to bytes32(0).
* @param _eid The endpoint ID.
* @return peer The address of the peer associated with the specified endpoint.
*/
function _getPeerOrRevert(uint32 _eid) internal view virtual returns (bytes32) {
bytes32 peer = peers[_eid];
if (peer == bytes32(0)) revert NoPeer(_eid);
return peer;
}
/**
* @notice Sets the delegate address for the OApp.
* @param _delegate The address of the delegate to be set.
*
* @dev Only the owner/admin of the OApp can call this function.
* @dev Provides the ability for a delegate to set configs, on behalf of the OApp, directly on the Endpoint contract.
*/
function setDelegate(address _delegate) public onlyOwner {
endpoint.setDelegate(_delegate);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { IOAppReceiver, Origin } from "./interfaces/IOAppReceiver.sol";
import { OAppCore } from "./OAppCore.sol";
/**
* @title OAppReceiver
* @dev Abstract contract implementing the ILayerZeroReceiver interface and extending OAppCore for OApp receivers.
*/
abstract contract OAppReceiver is IOAppReceiver, OAppCore {
// Custom error message for when the caller is not the registered endpoint/
error OnlyEndpoint(address addr);
// @dev The version of the OAppReceiver implementation.
// @dev Version is bumped when changes are made to this contract.
uint64 internal constant RECEIVER_VERSION = 2;
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol contract.
* @return receiverVersion The version of the OAppReceiver.sol contract.
*
* @dev Providing 0 as the default for OAppSender version. Indicates that the OAppSender is not implemented.
* ie. this is a RECEIVE only OApp.
* @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions.
*/
function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
return (0, RECEIVER_VERSION);
}
/**
* @notice Indicates whether an address is an approved composeMsg sender to the Endpoint.
* @dev _origin The origin information containing the source endpoint and sender address.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address on the src chain.
* - nonce: The nonce of the message.
* @dev _message The lzReceive payload.
* @param _sender The sender address.
* @return isSender Is a valid sender.
*
* @dev Applications can optionally choose to implement separate composeMsg senders that are NOT the bridging layer.
* @dev The default sender IS the OAppReceiver implementer.
*/
function isComposeMsgSender(
Origin calldata /*_origin*/,
bytes calldata /*_message*/,
address _sender
) public view virtual returns (bool) {
return _sender == address(this);
}
/**
* @notice Checks if the path initialization is allowed based on the provided origin.
* @param origin The origin information containing the source endpoint and sender address.
* @return Whether the path has been initialized.
*
* @dev This indicates to the endpoint that the OApp has enabled msgs for this particular path to be received.
* @dev This defaults to assuming if a peer has been set, its initialized.
* Can be overridden by the OApp if there is other logic to determine this.
*/
function allowInitializePath(Origin calldata origin) public view virtual returns (bool) {
return peers[origin.srcEid] == origin.sender;
}
/**
* @notice Retrieves the next nonce for a given source endpoint and sender address.
* @dev _srcEid The source endpoint ID.
* @dev _sender The sender address.
* @return nonce The next nonce.
*
* @dev The path nonce starts from 1. If 0 is returned it means that there is NO nonce ordered enforcement.
* @dev Is required by the off-chain executor to determine the OApp expects msg execution is ordered.
* @dev This is also enforced by the OApp.
* @dev By default this is NOT enabled. ie. nextNonce is hardcoded to return 0.
*/
function nextNonce(uint32 /*_srcEid*/, bytes32 /*_sender*/) public view virtual returns (uint64 nonce) {
return 0;
}
/**
* @dev Entry point for receiving messages or packets from the endpoint.
* @param _origin The origin information containing the source endpoint and sender address.
* - srcEid: The source chain endpoint ID.
* - sender: The sender address on the src chain.
* - nonce: The nonce of the message.
* @param _guid The unique identifier for the received LayerZero message.
* @param _message The payload of the received message.
* @param _executor The address of the executor for the received message.
* @param _extraData Additional arbitrary data provided by the corresponding executor.
*
* @dev Entry point for receiving msg/packet from the LayerZero endpoint.
*/
function lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) public payable virtual {
// Ensures that only the endpoint can attempt to lzReceive() messages to this OApp.
if (address(endpoint) != msg.sender) revert OnlyEndpoint(msg.sender);
// Ensure that the sender matches the expected peer for the source endpoint.
if (_getPeerOrRevert(_origin.srcEid) != _origin.sender) revert OnlyPeer(_origin.srcEid, _origin.sender);
// Call the internal OApp implementation of lzReceive.
_lzReceive(_origin, _guid, _message, _executor, _extraData);
}
/**
* @dev Internal function to implement lzReceive logic without needing to copy the basic parameter validation.
*/
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata _message,
address _executor,
bytes calldata _extraData
) internal virtual;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { MessagingParams, MessagingFee, MessagingReceipt } from "./interfaces/ILayerZeroEndpointV2.sol";
import { OAppCore } from "./OAppCore.sol";
/**
* @title OAppSender
* @dev Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.
*/
abstract contract OAppSender is OAppCore {
using SafeERC20 for IERC20;
// Custom error messages
error NotEnoughNative(uint256 msgValue);
error LzTokenUnavailable();
// @dev The version of the OAppSender implementation.
// @dev Version is bumped when changes are made to this contract.
uint64 internal constant SENDER_VERSION = 1;
/**
* @notice Retrieves the OApp version information.
* @return senderVersion The version of the OAppSender.sol contract.
* @return receiverVersion The version of the OAppReceiver.sol contract.
*
* @dev Providing 0 as the default for OAppReceiver version. Indicates that the OAppReceiver is not implemented.
* ie. this is a SEND only OApp.
* @dev If the OApp uses both OAppSender and OAppReceiver, then this needs to be override returning the correct versions
*/
function oAppVersion() public view virtual returns (uint64 senderVersion, uint64 receiverVersion) {
return (SENDER_VERSION, 0);
}
/**
* @dev Internal function to interact with the LayerZero EndpointV2.quote() for fee calculation.
* @param _dstEid The destination endpoint ID.
* @param _message The message payload.
* @param _options Additional options for the message.
* @param _payInLzToken Flag indicating whether to pay the fee in LZ tokens.
* @return fee The calculated MessagingFee for the message.
* - nativeFee: The native fee for the message.
* - lzTokenFee: The LZ token fee for the message.
*/
function _quote(
uint32 _dstEid,
bytes memory _message,
bytes memory _options,
bool _payInLzToken
) internal view virtual returns (MessagingFee memory fee) {
return
endpoint.quote(
MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _payInLzToken),
address(this)
);
}
/**
* @dev Internal function to interact with the LayerZero EndpointV2.send() for sending a message.
* @param _dstEid The destination endpoint ID.
* @param _message The message payload.
* @param _options Additional options for the message.
* @param _fee The calculated LayerZero fee for the message.
* - nativeFee: The native fee.
* - lzTokenFee: The lzToken fee.
* @param _refundAddress The address to receive any excess fee values sent to the endpoint.
* @return receipt The receipt for the sent message.
* - guid: The unique identifier for the sent message.
* - nonce: The nonce of the sent message.
* - fee: The LayerZero fee incurred for the message.
*/
function _lzSend(
uint32 _dstEid,
bytes memory _message,
bytes memory _options,
MessagingFee memory _fee,
address _refundAddress
) internal virtual returns (MessagingReceipt memory receipt) {
// @dev Push corresponding fees to the endpoint, any excess is sent back to the _refundAddress from the endpoint.
uint256 messageValue = _payNative(_fee.nativeFee);
if (_fee.lzTokenFee > 0) _payLzToken(_fee.lzTokenFee);
return
// solhint-disable-next-line check-send-result
endpoint.send{ value: messageValue }(
MessagingParams(_dstEid, _getPeerOrRevert(_dstEid), _message, _options, _fee.lzTokenFee > 0),
_refundAddress
);
}
/**
* @dev Internal function to pay the native fee associated with the message.
* @param _nativeFee The native fee to be paid.
* @return nativeFee The amount of native currency paid.
*
* @dev If the OApp needs to initiate MULTIPLE LayerZero messages in a single transaction,
* this will need to be overridden because msg.value would contain multiple lzFees.
* @dev Should be overridden in the event the LayerZero endpoint requires a different native currency.
* @dev Some EVMs use an ERC20 as a method for paying transactions/gasFees.
* @dev The endpoint is EITHER/OR, ie. it will NOT support both types of native payment at a time.
*/
function _payNative(uint256 _nativeFee) internal virtual returns (uint256 nativeFee) {
if (msg.value != _nativeFee) revert NotEnoughNative(msg.value);
return _nativeFee;
}
/**
* @dev Internal function to pay the LZ token fee associated with the message.
* @param _lzTokenFee The LZ token fee to be paid.
*
* @dev If the caller is trying to pay in the specified lzToken, then the lzTokenFee is passed to the endpoint.
* @dev Any excess sent, is passed back to the specified _refundAddress in the _lzSend().
*/
function _payLzToken(uint256 _lzTokenFee) internal virtual {
// @dev Cannot cache the token because it is not immutable in the endpoint.
address lzToken = endpoint.lzToken();
if (lzToken == address(0)) revert LzTokenUnavailable();
// Pay LZ token fee by sending tokens to the endpoint.
IERC20(lzToken).safeTransferFrom(msg.sender, address(endpoint), _lzTokenFee);
}
}// 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.0 <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) { // We're using the unchecked block below because otherwise execution ends // with the native overflow error code. unchecked { 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 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 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; } }
{
"optimizer": {
"enabled": true,
"runs": 9999
},
"viaIR": true,
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"FailedCall","type":"error"},{"inputs":[],"name":"GasRequired","type":"error"},{"inputs":[{"internalType":"uint256","name":"balance","type":"uint256"},{"internalType":"uint256","name":"needed","type":"uint256"}],"name":"InsufficientBalance","type":"error"},{"inputs":[],"name":"InvalidAddress","type":"error"},{"inputs":[],"name":"InvalidArrayLength","type":"error"},{"inputs":[],"name":"InvalidDelegate","type":"error"},{"inputs":[],"name":"InvalidDestinationChain","type":"error"},{"inputs":[],"name":"InvalidEndpointCall","type":"error"},{"inputs":[],"name":"InvalidFillType","type":"error"},{"inputs":[],"name":"InvalidInitialization","type":"error"},{"inputs":[],"name":"InvalidNativeAmount","type":"error"},{"inputs":[{"internalType":"uint16","name":"optionType","type":"uint16"}],"name":"InvalidOptionType","type":"error"},{"inputs":[],"name":"InvalidPostHookProvided","type":"error"},{"inputs":[],"name":"InvalidProvider","type":"error"},{"inputs":[],"name":"InvalidSourceChain","type":"error"},{"inputs":[],"name":"LengthMismatch","type":"error"},{"inputs":[],"name":"LzTokenUnavailable","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"NoPeer","type":"error"},{"inputs":[],"name":"NotApprovedByGateway","type":"error"},{"inputs":[{"internalType":"uint256","name":"msgValue","type":"uint256"}],"name":"NotEnoughNative","type":"error"},{"inputs":[],"name":"NotInitializing","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"OnlyEndpoint","type":"error"},{"inputs":[],"name":"OnlyFeeCollector","type":"error"},{"inputs":[],"name":"OnlyFillerCanSettle","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"}],"name":"OnlyPeer","type":"error"},{"inputs":[],"name":"OnlyTrustedAddress","type":"error"},{"inputs":[],"name":"OrderAlreadyExists","type":"error"},{"inputs":[],"name":"OrderAlreadySettled","type":"error"},{"inputs":[],"name":"OrderExpired","type":"error"},{"inputs":[],"name":"OrderNotExpired","type":"error"},{"inputs":[],"name":"OrderNotSettled","type":"error"},{"inputs":[],"name":"OrderStateNotCreated","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"uint8","name":"bits","type":"uint8"},{"internalType":"uint256","name":"value","type":"uint256"}],"name":"SafeCastOverflowedUintDowncast","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"UnauthorizedOriginAddress","type":"error"},{"inputs":[],"name":"UnauthorizedOriginEndpoint","type":"error"},{"inputs":[],"name":"UnexpectedNativeToken","type":"error"},{"inputs":[],"name":"UntrustedChain","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"inputs":[],"name":"ZeroStringLength","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"feeCollector","type":"address"},{"indexed":true,"internalType":"address","name":"token","type":"address"},{"indexed":true,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"FeesCollected","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"version","type":"uint64"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"components":[{"internalType":"address","name":"fromAddress","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"address","name":"filler","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"fromAmount","type":"uint256"},{"internalType":"uint256","name":"fillAmount","type":"uint256"},{"internalType":"uint256","name":"feeRate","type":"uint256"},{"internalType":"uint256","name":"fromChain","type":"uint256"},{"internalType":"uint256","name":"toChain","type":"uint256"},{"internalType":"bytes32","name":"postHookHash","type":"bytes32"}],"indexed":false,"internalType":"struct ISpoke.Order","name":"order","type":"tuple"}],"name":"OrderCreated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"},{"components":[{"internalType":"address","name":"fromAddress","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"address","name":"filler","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"fromAmount","type":"uint256"},{"internalType":"uint256","name":"fillAmount","type":"uint256"},{"internalType":"uint256","name":"feeRate","type":"uint256"},{"internalType":"uint256","name":"fromChain","type":"uint256"},{"internalType":"uint256","name":"toChain","type":"uint256"},{"internalType":"bytes32","name":"postHookHash","type":"bytes32"}],"indexed":false,"internalType":"struct ISpoke.Order","name":"order","type":"tuple"}],"name":"OrderFilled","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"OrderRefunded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"eid","type":"uint32"},{"indexed":false,"internalType":"bytes32","name":"peer","type":"bytes32"}],"name":"PeerSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"SettlementForwarded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"contract IAxelarGateway","name":"gateway","type":"address"},{"indexed":true,"internalType":"contract IAxelarGasService","name":"gasService","type":"address"},{"indexed":false,"internalType":"contract ISquidMulticall","name":"squidMulticall","type":"address"},{"indexed":false,"internalType":"address","name":"feeCollector","type":"address"},{"indexed":false,"internalType":"string","name":"hubChainName","type":"string"},{"indexed":false,"internalType":"string","name":"hubAddress","type":"string"}],"name":"SpokeInitialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"orderHash","type":"bytes32"}],"name":"TokensReleased","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"chain","type":"string"}],"name":"TrustedAddressRemoved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"chain","type":"string"},{"indexed":false,"internalType":"string","name":"address_","type":"string"}],"name":"TrustedAddressSet","type":"event"},{"inputs":[{"internalType":"address","name":"_addr","type":"address"}],"name":"addressToBytes32","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"origin","type":"tuple"}],"name":"allowInitializePath","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"chainName","outputs":[{"internalType":"string","name":"chainName_","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"tokens","type":"address[]"}],"name":"collectFees","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromAddress","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"address","name":"filler","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"fromAmount","type":"uint256"},{"internalType":"uint256","name":"fillAmount","type":"uint256"},{"internalType":"uint256","name":"feeRate","type":"uint256"},{"internalType":"uint256","name":"fromChain","type":"uint256"},{"internalType":"uint256","name":"toChain","type":"uint256"},{"internalType":"bytes32","name":"postHookHash","type":"bytes32"}],"internalType":"struct ISpoke.Order","name":"order","type":"tuple"}],"name":"createOrder","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"endpoint","outputs":[{"internalType":"contract ILayerZeroEndpointV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"commandId","type":"bytes32"},{"internalType":"string","name":"sourceChain","type":"string"},{"internalType":"string","name":"sourceAddress","type":"string"},{"internalType":"bytes","name":"payload","type":"bytes"}],"name":"execute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"commandId","type":"bytes32"},{"internalType":"string","name":"sourceChain","type":"string"},{"internalType":"string","name":"sourceAddress","type":"string"},{"internalType":"bytes","name":"payload","type":"bytes"},{"internalType":"string","name":"tokenSymbol","type":"string"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"executeWithToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"feeCollector","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromAddress","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"address","name":"filler","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"fromAmount","type":"uint256"},{"internalType":"uint256","name":"fillAmount","type":"uint256"},{"internalType":"uint256","name":"feeRate","type":"uint256"},{"internalType":"uint256","name":"fromChain","type":"uint256"},{"internalType":"uint256","name":"toChain","type":"uint256"},{"internalType":"bytes32","name":"postHookHash","type":"bytes32"}],"internalType":"struct ISpoke.Order","name":"order","type":"tuple"},{"components":[{"internalType":"enum ISquidMulticall.CallType","name":"callType","type":"uint8"},{"internalType":"address","name":"target","type":"address"},{"internalType":"uint256","name":"value","type":"uint256"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"bytes","name":"payload","type":"bytes"}],"internalType":"struct ISquidMulticall.Call[]","name":"calls","type":"tuple[]"}],"name":"fillOrder","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes32[]","name":"orderHashes","type":"bytes32[]"},{"internalType":"uint256","name":"lzFee","type":"uint256"},{"internalType":"uint128","name":"gasLimit","type":"uint128"},{"internalType":"enum ICoral.Provider","name":"provider","type":"uint8"}],"name":"forwardSettlements","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"gasService","outputs":[{"internalType":"contract IAxelarGasService","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gateway","outputs":[{"internalType":"contract IAxelarGateway","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hubAddress","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hubAddressBytes32","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hubChainName","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"hubEndpoint","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IAxelarGateway","name":"_axelarGateway","type":"address"},{"internalType":"contract IAxelarGasService","name":"_axelarGasService","type":"address"},{"internalType":"contract ISquidMulticall","name":"_squidMulticall","type":"address"},{"internalType":"address","name":"_feeCollector","type":"address"},{"internalType":"string","name":"_hubChainName","type":"string"},{"internalType":"string","name":"_hubAddress","type":"string"},{"internalType":"contract ILayerZeroEndpointV2","name":"_endpoint","type":"address"},{"internalType":"address","name":"_owner","type":"address"},{"internalType":"address","name":"_hub","type":"address"},{"internalType":"uint32","name":"_hubEndpoint","type":"uint32"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"","type":"tuple"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"address","name":"_sender","type":"address"}],"name":"isComposeMsgSender","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"chain","type":"string"},{"internalType":"string","name":"address_","type":"string"}],"name":"isTrustedAddress","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"srcEid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"},{"internalType":"uint64","name":"nonce","type":"uint64"}],"internalType":"struct Origin","name":"_origin","type":"tuple"},{"internalType":"bytes32","name":"_guid","type":"bytes32"},{"internalType":"bytes","name":"_message","type":"bytes"},{"internalType":"address","name":"_executor","type":"address"},{"internalType":"bytes","name":"_extraData","type":"bytes"}],"name":"lzReceive","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint32","name":"","type":"uint32"},{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"nextNonce","outputs":[{"internalType":"uint64","name":"nonce","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"oAppVersion","outputs":[{"internalType":"uint64","name":"senderVersion","type":"uint64"},{"internalType":"uint64","name":"receiverVersion","type":"uint64"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"orderHashToStatus","outputs":[{"internalType":"enum ISpoke.OrderStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"peers","outputs":[{"internalType":"bytes32","name":"peer","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_dstEid","type":"uint32"},{"internalType":"bytes32[]","name":"orderHashes","type":"bytes32[]"},{"internalType":"uint128","name":"gasLimit","type":"uint128"},{"internalType":"bool","name":"_payInLzToken","type":"bool"}],"name":"quote","outputs":[{"internalType":"uint256","name":"nativeFee","type":"uint256"},{"internalType":"uint256","name":"lzTokenFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"fromAddress","type":"address"},{"internalType":"address","name":"toAddress","type":"address"},{"internalType":"address","name":"filler","type":"address"},{"internalType":"address","name":"fromToken","type":"address"},{"internalType":"address","name":"toToken","type":"address"},{"internalType":"uint256","name":"expiry","type":"uint256"},{"internalType":"uint256","name":"fromAmount","type":"uint256"},{"internalType":"uint256","name":"fillAmount","type":"uint256"},{"internalType":"uint256","name":"feeRate","type":"uint256"},{"internalType":"uint256","name":"fromChain","type":"uint256"},{"internalType":"uint256","name":"toChain","type":"uint256"},{"internalType":"bytes32","name":"postHookHash","type":"bytes32"}],"internalType":"struct ISpoke.Order","name":"order","type":"tuple"}],"name":"refundOrder","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegate","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"bytes32","name":"_peer","type":"bytes32"}],"name":"setPeer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"settlementToStatus","outputs":[{"internalType":"enum ISpoke.SettlementStatus","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"squidMulticall","outputs":[{"internalType":"contract ISquidMulticall","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"tokenToCollectedFees","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"string","name":"chain","type":"string"}],"name":"trustedAddress","outputs":[{"internalType":"string","name":"trustedAddress_","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"chain","type":"string"}],"name":"trustedAddressHash","outputs":[{"internalType":"bytes32","name":"trustedAddressHash_","type":"bytes32"}],"stateMutability":"view","type":"function"}]Contract Creation Code
608080604052346100a95733156100935760008054336001600160a01b0319808316821784559290916001600160a01b0316907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09080a373c012a1111111111111111111111111111111111190818160015416176001556003541617600355600160045560405161434d9081620000af8239f35b631e4fbdf760e01b815260006004820152602490fd5b600080fdfe6080604052600436101561001257600080fd5b60003560e01c80630630dea414610267578063076e9f6c146102625780630af7b75b1461025d5780630d77797c14610258578063116191b61461025357806313137d651461024e57806317442b70146102495780631a98b2e0146102445780631c93b03a1461023f5780631e44fb971461023a57806321b4ae78146102355780632b8cb1f6146102305780633400288b1461022b578063477aedc714610226578063491606581461022157806358c0f7291461021c57806359ce62e9146102175780635e280f11146102125780636a22d8cc1461020d578063715018a6146102085780637d25a05e1461020357806382413eac146101fe57806382c947b7146101f957806382e5f9e4146101f45780638da5cb5b146101ef578063951f4016146101ea578063a32b52a7146101e5578063aab59a09146101e0578063bb0b6a53146101db578063c415b95c146101d6578063c506bff4146101d1578063ca5eb5e1146101cc578063db715f7b146101c7578063f2fde38b146101c2578063f69b1b29146101bd578063ff7bd03d146101b85763ffd5982a146101b357600080fd5b611e75565b611e2f565b611e0b565b611d9d565b611d5f565b611ccd565b611c68565b611c41565b611c06565b611aac565b611a74565b611a4c565b611a25565b6119e6565b611820565b6117c1565b61179a565b611728565b611701565b6116da565b6116b3565b6114fc565b6113ba565b6112eb565b61128f565b61126b565b6110f8565b610f06565b610dfc565b610d13565b610cf1565b610bdf565b610b79565b610914565b610856565b610653565b6102d8565b9181601f8401121561029d5782359167ffffffffffffffff831161029d576020808501948460051b01011161029d57565b600080fd5b604435906fffffffffffffffffffffffffffffffff8216820361029d57565b6002111561029d57565b35906102d6826102c1565b565b608060031936011261029d576004803567ffffffffffffffff811161029d57610304903690830161026c565b909161030e6102a2565b926064359061031c826102c1565b610324612a7a565b34156105ec5783156105c35760005b84811061050b575061035f9061035160405195869260208401611eda565b03601f19810185528461075e565b61036881611f1c565b8061048b57509091506103926103866008546001600160a01b031690565b6001600160a01b031690565b803b1561029d57600060405180927f0c93e3bb00000000000000000000000000000000000000000000000000000000825281806103d33389308a8501611f26565b039134905af1801561047357610478575b506103fa6103866003546001600160a01b031690565b91823b1561029d5761043d92600092836040518096819582947f1c92115f0000000000000000000000000000000000000000000000000000000084528301611f82565b03925af180156104735761045a575b505b6104586001600455565b005b8061046761046d926106f1565b80610b6e565b3861044c565b611f76565b80610467610485926106f1565b386103e4565b80610497600192611f1c565b036104e357506104b16104dd926104ac612ab5565b612aea565b906104c1600d5463ffffffff1690565b916104ca610781565b9134835260243560208401523393612d2a565b5061044e565b6040517f7626db82000000000000000000000000000000000000000000000000000000008152fd5b61053461052d61051c838886611ec5565b356000526007602052604060002090565b5460ff1690565b61053d81611a6a565b1561059a578061056361055661051c6001948987611ec5565b600260ff19825416179055565b61056e818785611ec5565b357f69f975bd70ea51b973eb6aff3812f49adf595bd59d6f3d29840d5695cc19ba30600080a201610333565b836040517f4811daf5000000000000000000000000000000000000000000000000000000008152fd5b826040517f9d89020a000000000000000000000000000000000000000000000000000000008152fd5b826040517f03aeed96000000000000000000000000000000000000000000000000000000008152fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6004111561064e57565b610615565b3461029d57602060031936011261029d576004356000526006602052602060ff604060002054166040519061068781610644565b8152f35b6001600160a01b0381160361029d57565b60e435906102d68261068b565b61010435906102d68261068b565b35906102d68261068b565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b67ffffffffffffffff811161070557604052565b6106c2565b6040810190811067ffffffffffffffff82111761070557604052565b6060810190811067ffffffffffffffff82111761070557604052565b60a0810190811067ffffffffffffffff82111761070557604052565b90601f601f19910116810190811067ffffffffffffffff82111761070557604052565b604051906102d68261070a565b604051906102d682610742565b60405190610180820182811067ffffffffffffffff82111761070557604052565b67ffffffffffffffff811161070557601f01601f191660200190565b9291926107e4826107bc565b916107f2604051938461075e565b82948184528183011161029d578281602093846000960137010152565b9080601f8301121561029d5781602061082a933591016107d8565b90565b60c435906102d68261068b565b63ffffffff81160361029d57565b61012435906102d68261083a565b3461029d5761014060031936011261029d576004356108748161068b565b602435906108818261068b565b6044359161088e8361068b565b6064359261089b8461068b565b67ffffffffffffffff9360843585811161029d576108bd90369060040161080f565b60a43595861161029d576108d861045896369060040161080f565b906108e161082d565b926108ea61069c565b946108f36106a9565b966108fc610848565b98611fb4565b60031961018091011261029d57600490565b61018060031936011261029d5761092a36610902565b610932612a7a565b604090815160208101906109588161094a85856128ba565b03601f19810183528261075e565b5190209161097361052d846000526006602052604060002090565b61097c81610644565b610b455760a0820135421015610b1c574661012083013503610af3576060820173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee806001600160a01b036109c3846129a2565b16141580610aea575b610ac1576109f46109e7866000526006602052604060002090565b600160ff19825416179055565b610a00610386836129a2565b03610a78575060c08201353403610a4f577f181de28643611afcf1cb4c095a1ef99c157e78437294f478c978e4a56e1ca77e91610a42915b51918291826128ba565b0390a26104586001600455565b600490517f44e8bd2c000000000000000000000000000000000000000000000000000000008152fd5b91610a4291610abc610aad6103867f181de28643611afcf1cb4c095a1ef99c157e78437294f478c978e4a56e1ca77e966129a2565b60c08401359030903390613fa5565b610a38565b600483517fd453e7b5000000000000000000000000000000000000000000000000000000008152fd5b503415156109cc565b600490517f9284b197000000000000000000000000000000000000000000000000000000008152fd5b600490517fc56873ba000000000000000000000000000000000000000000000000000000008152fd5b600490517f966753c5000000000000000000000000000000000000000000000000000000008152fd5b600091031261029d57565b3461029d57600060031936011261029d5760206001600160a01b0360035416604051908152f35b600319606091011261029d57600490565b9181601f8401121561029d5782359167ffffffffffffffff831161029d576020838186019501011161029d57565b60e060031936011261029d57610bf436610ba0565b67ffffffffffffffff60843581811161029d57610c15903690600401610bb1565b91610c2160a43561068b565b60c43590811161029d57610c39903690600401610bb1565b50506001600160a01b03600154163303610cc057610c5e610c5984612771565b61300f565b926020810135809403610c75576104589350613251565b610c7f8491612771565b6040517fc26bebcc00000000000000000000000000000000000000000000000000000000815263ffffffff9190911660048201526024810191909152604490fd5b6040517f91ac5e4f000000000000000000000000000000000000000000000000000000008152336004820152602490fd5b3461029d57600060031936011261029d57604080516001815260026020820152f35b3461029d5760c060031936011261029d5767ffffffffffffffff60243581811161029d57610d45903690600401610bb1565b60443583811161029d57610d5d903690600401610bb1565b60649291923585811161029d57610d78903690600401610bb1565b9160843596871161029d57610d94610458973690600401610bb1565b95909460a435976004356127b1565b60005b838110610db65750506000910152565b8181015183820152602001610da6565b90601f19601f602093610de481518092818752878088019101610da3565b0116010190565b90602061082a928181520190610dc6565b3461029d57600080600319360112610f035760405190807f0e2c162a1f4b5cff9fdbd6b34678a9bcb9898a0b9fbca695b112d61688d8b2ac8054610e3f81611850565b80865292602092600192808416908115610ed35750600114610e7c575b610e7887610e6c8189038261075e565b60405191829182610deb565b0390f35b815293507f6703f9a97b5b44375099a890a40c8c70a9efc4d97fa39f72811f72b1a93211625b838510610ec057505050508101602001610e6c82610e783880610e5c565b8054868601840152938201938101610ea2565b9050879650610e7897945060209350610e6c95925060ff1991501682840152151560051b82010192933880610e5c565b80fd5b3461029d5761018060031936011261029d57610f2136610902565b610f29612a7a565b6040516020810190610f3f8161094a85856128ba565b519020906001610f5c61052d846000526006602052604060002090565b610f6581610644565b036110c457610f79610386604083016129a2565b330361107f575b466101208201350361105557610fb0610fa3836000526006602052604060002090565b600360ff19825416179055565b606081019073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03610fdb846129a2565b160361102c57610ffd915060c0610ff4610386836129a2565b9101359061341f565b7fa60671d8537ed193e567f86ddf28cf35dc67073b5ad80a2d41359cfa78db0a1e600080a26104586001600455565b61103b610386611050936129a2565b9060c0611047826129a2565b910135916133b9565b610ffd565b60046040517f9284b197000000000000000000000000000000000000000000000000000000008152fd5b61109561108f60a08301356129db565b42111590565b15610f805760046040517f796c85f3000000000000000000000000000000000000000000000000000000008152fd5b60046040517fab81a57d000000000000000000000000000000000000000000000000000000008152fd5b8015150361029d57565b3461029d57608060031936011261029d576004356111158161083a565b60243567ffffffffffffffff811161029d5761117e9161113c61121192369060040161026c565b6111dc61114a9392936102a2565b6111866064359161115a836110ee565b6040988997611170895197889260208401611eda565b03601f19810187528661075e565b6104ac612ab5565b61118e612bec565b506111a46103866001546001600160a01b031690565b936111ae8661300f565b6111c56111b961078e565b63ffffffff9098168852565b602087015286860152606085015215156080840152565b825180809581947fddc28c58000000000000000000000000000000000000000000000000000000008352309060048401612c9f565b03915afa9081156104735760009161123e575b508051602091820151925190815290810191909152604090f35b61125e9150823d8411611264575b611256818361075e565b8101906134e8565b38611224565b503d61124c565b3461029d57600060031936011261029d57602063ffffffff600d5416604051908152f35b3461029d57604060031936011261029d576104586004356112af8161083a565b6112b76134fc565b60243590612fbe565b602060031982011261029d576004359067ffffffffffffffff821161029d5761082a9160040161080f565b3461029d576113016112fc366112c0565b613540565b6040519060008282549161131483611850565b9283835260209460019186600182169182600014611397575050600114611358575b50506113449250038361075e565b610e78604051928284938452830190610dc6565b85925060005281600020906000915b85831061137f57505061134493508201013880611336565b80548389018501528794508693909201918101611367565b9150935061134495925060ff1991501682840152151560051b8201013880611336565b3461029d57608060031936011261029d57600467ffffffffffffffff60243581811161029d576113ed9036908401610bb1565b9160443581811161029d576114059036908601610bb1565b9160643590811161029d5761141d9036908701610bb1565b9490938260208361142f368a8a6107d8565b8281519101208460008c6114816001600160a01b0360035416948c604051998a98899788967f5f6970c300000000000000000000000000000000000000000000000000000000885280359088016129fd565b03925af1908115610473576000916114cd575b50156114a4576104589650613588565b866040517f500c44b4000000000000000000000000000000000000000000000000000000008152fd5b6114ef915060203d6020116114f5575b6114e7818361075e565b81019061277b565b38611494565b503d6114dd565b3461029d57602060031936011261029d5760043567ffffffffffffffff811161029d5761152d90369060040161026c565b906001600160a01b0390600a9082600a5416330361168957831561165f5760005b84811061155757005b8061158961157061156b6001948987611ec5565b6129a2565b6001600160a01b03166000526005602052604060002090565b54806115d9575b84546001600160a01b031686806115ab61156b868c8a611ec5565b1691167f9bcb6d1f38f6800906185471a11ede9a8e16200853225aa62558db6076490f2d600080a40161154e565b60006115ec61157061156b858b89611ec5565b5573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee8661161161156b858b89611ec5565b1603611639576116348161162f61038688546001600160a01b031690565b61341f565b611590565b6116348161164e61038661156b868c8a611ec5565b87546001600160a01b0316906133b9565b60046040517f9d89020a000000000000000000000000000000000000000000000000000000008152fd5b60046040517f91034599000000000000000000000000000000000000000000000000000000008152fd5b3461029d57600060031936011261029d5760206001600160a01b0360095416604051908152f35b3461029d57600060031936011261029d5760206001600160a01b0360015416604051908152f35b3461029d57600060031936011261029d5760206001600160a01b0360085416604051908152f35b3461029d57600080600319360112610f03576117426134fc565b806001600160a01b0381547fffffffffffffffffffffffff000000000000000000000000000000000000000081168355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b3461029d57604060031936011261029d576117b660043561083a565b602060405160008152f35b3461029d5760a060031936011261029d576117db36610ba0565b5060643567ffffffffffffffff811161029d576117fc903690600401610bb1565b5050602060843561180c8161068b565b604051906001600160a01b03309116148152f35b3461029d57602060031936011261029d57602060043561183f8161068b565b6001600160a01b0360405191168152f35b90600182811c92168015611899575b602083101461186a57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b91607f169161185f565b600b54600092916118b382611850565b8082529160209060019081811690811561193257506001146118d6575b50505050565b92939450600b6000527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9926000935b85851061191f5750505060209250010190388080806118d0565b8054858501840152938201938101611905565b915050602094955060ff1991509291921683830152151560051b010190388080806118d0565b600c546000929161196882611850565b80825291602090600190818116908115611932575060011461198a5750505050565b92939450600c6000527fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7926000935b8585106119d35750505060209250010190388080806118d0565b80548585018401529382019381016119b9565b3461029d57600060031936011261029d57610e78604051611a1181611a0a816118a3565b038261075e565b604051918291602083526020830190610dc6565b3461029d57600060031936011261029d5760206001600160a01b0360005416604051908152f35b3461029d57600060031936011261029d576020600e54604051908152f35b6003111561064e57565b3461029d57602060031936011261029d57600435600052600760205260ff60406000205416604051600382101561064e576020918152f35b6101a060031936011261029d57611ac236610902565b6101843567ffffffffffffffff811161029d57611ae390369060040161026c565b906080830173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038235611b108161068b565b161480611bf8575b611bce576101808436031261029d5761045893611b7a611b3661079b565b92611b40836106b7565b8452611b4e602084016106b7565b6020850152611b5f604084016106b7565b6040850152611b70606084016106b7565b60608501526106b7565b608083015260a081013560a083015260c081013560c083015260e081013560e0830152610100808201359083015261012080820135908301526101408082013590830152610160809101359082015261363b565b60046040517f44e8bd2c000000000000000000000000000000000000000000000000000000008152fd5b5060e0840135341415611b18565b3461029d57602060031936011261029d5763ffffffff600435611c288161083a565b1660005260026020526020604060002054604051908152f35b3461029d57600060031936011261029d5760206001600160a01b03600a5416604051908152f35b3461029d57604060031936011261029d5767ffffffffffffffff60043581811161029d57611c9a903690600401610bb1565b60249291923591821161029d57602092611cbb611cc3933690600401610bb1565b929091612a33565b6040519015158152f35b3461029d5760006020600319360112610f0357600435611cec8161068b565b611cf46134fc565b816001600160a01b03806001541692833b15611d5b576024908360405195869485937fca5eb5e10000000000000000000000000000000000000000000000000000000085521660048401525af1801561047357611d4f575080f35b611d58906106f1565b80f35b8280fd5b3461029d57602060031936011261029d576001600160a01b03600435611d848161068b565b1660005260056020526020604060002054604051908152f35b3461029d57602060031936011261029d57600435611dba8161068b565b611dc26134fc565b6001600160a01b03811615611dda57610458906135db565b60246040517f1e4fbdf700000000000000000000000000000000000000000000000000000000815260006004820152fd5b3461029d57600060031936011261029d57610e78604051611a1181611a0a81611958565b3461029d57606060031936011261029d576020611e4b36610ba0565b63ffffffff8135611e5b8161083a565b166000526002825260406000205482604051920135148152f35b3461029d576020611e8d611e88366112c0565b613d70565b54604051908152f35b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9190811015611ed55760051b0190565b611e96565b602081528260208201527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831161029d5760409260051b809284830137010190565b6002111561064e57565b9190611f6f6080929594956001600160a01b03809316855260a06020860152611f61611f5460a087016118a3565b8681036040880152611958565b908582036060870152610dc6565b9416910152565b6040513d6000823e3d90fd5b61082a9160608252611fa6611f99606084016118a3565b8381036020850152611958565b916040818403910152610dc6565b9896949290979593917ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a009889549a60ff8c60401c16159b8c67ffffffffffffffff82168015918261216d575b506001149081612163575b15908161215a575b506121305761204e9b60017fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000008f93161790556120d4576124bc565b61205457565b6120a07ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a007fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff8154169055565b604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29080602081015b0390a1565b61212b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00680100000000000000007fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff825416179055565b6124bc565b60046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b90501538612013565b303b15915061200b565b91508e612000565b601f8111612181575050565b600090600b6000527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9906020601f850160051c830194106121dd575b601f0160051c01915b8281106121d257505050565b8181556001016121c6565b90925082906121bd565b601f81116121f3575050565b600090600c6000527fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7906020601f850160051c8301941061224f575b601f0160051c01915b82811061224457505050565b818155600101612238565b909250829061222f565b90601f811161226757505050565b6000916000526020600020906020601f850160051c830194106122a5575b601f0160051c01915b82811061229a57505050565b81815560010161228e565b9092508290612285565b90815167ffffffffffffffff8111610705576122d5816122d0600b54611850565b612175565b602080601f831160011461231757508190612307939460009261230c575b50506000198260011b9260031b1c19161790565b600b55565b0151905038806122f3565b90601f1983169461234a600b6000527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db990565b926000905b87821061238757505083600195961061236e575b505050811b01600b55565b015160001960f88460031b161c19169055388080612363565b8060018596829496860151815501950193019061234f565b90815167ffffffffffffffff8111610705576123c5816123c0600c54611850565b6121e7565b602080601f83116001146123fb575081906123f6939460009261230c5750506000198260011b9260031b1c19161790565b600c55565b90601f1983169461242e600c6000527fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c790565b926000905b87821061246b575050836001959610612452575b505050811b01600c55565b015160001960f88460031b161c19169055388080612447565b80600185968294968601518155019501930190612433565b9061082a926001600160a01b038092168352166020820152608060408201526124ae608082016118a3565b906060818303910152611958565b6125ae926125466125c59796959361251261257a949d9b9a9d6124de8c612a5a565b6001600160a01b03167fffffffffffffffffffffffff00000000000000000000000000000000000000006003541617600355565b6001600160a01b03167fffffffffffffffffffffffff00000000000000000000000000000000000000006008541617600855565b6001600160a01b03167fffffffffffffffffffffffff00000000000000000000000000000000000000006009541617600955565b6001600160a01b03167fffffffffffffffffffffffff0000000000000000000000000000000000000000600a541617600a55565b6125b7816122af565b6125c08261239f565b612e44565b6001600160a01b0393848116907311111111111111111111111111111111111111118203612678575b50505050506126056003546001600160a01b031690565b907ff25a5e989fb7e02dc64e8a2c85e4fbaae049d3ce88c8cbb840860122201da24b6126396008546001600160a01b031690565b9161264c6009546001600160a01b031690565b92612673612662600a546001600160a01b031690565b836040519485941697169583612483565b0390a3565b6126b0906001600160a01b03167fffffffffffffffffffffffff00000000000000000000000000000000000000006001541617600155565b803b1561029d576040517fca5eb5e10000000000000000000000000000000000000000000000000000000081526001600160a01b039290921660048301526000908290602490829084905af18015610473576127549361274f92869261275e575b506127478463ffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000600d541617600d55565b168092612fbe565b600e55565b38808080806125ee565b8061046761276b926106f1565b38612711565b3561082a8161083a565b9081602091031261029d575161082a816110ee565b601f8260209493601f19938186528686013760008582860101520116010190565b9260209861285092986127ce6128289c95986000989a36916107d8565b8b81519101209261283c6001600160a01b03600354169a6040519e8f9d8e9c8d9b7f1876eed9000000000000000000000000000000000000000000000000000000008d5260048d015260c060248d015260c48c0191612790565b9060031993848b84030160448c0152612790565b936064880152868403016084870152612790565b9060a483015203925af19081156104735760009161289b575b501561287157565b60046040517f500c44b4000000000000000000000000000000000000000000000000000000008152fd5b6128b4915060203d6020116114f5576114e7818361075e565b38612869565b610180810192916128db826128ce836106b7565b6001600160a01b03169052565b6128fa6128ea602083016106b7565b6001600160a01b03166020840152565b612919612909604083016106b7565b6001600160a01b03166040840152565b612938612928606083016106b7565b6001600160a01b03166060840152565b612957612947608083016106b7565b6001600160a01b03166080840152565b60a081013560a083015260c081013560c083015260e081013560e083015261010080820135908301526101208082013590830152610140808201359083015261016080910135910152565b3561082a8161068b565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b906205460082018092116129eb57565b6129ac565b919082018092116129eb57565b9695949060609492612a2e94612a20928a52608060208b015260808a0191612790565b918783036040890152612790565b930152565b612a46612a5593611e88939536916107d8565b602081519101209336916107d8565b541490565b612a626134fc565b6001600160a01b03811615611dda576102d6906135db565b600260045414612a8b576002600455565b60046040517f3ee5aeb5000000000000000000000000000000000000000000000000000000008152fd5b6040517e0300000000000000000000000000000000000000000000000000000000000060208201526002815261082a8161070a565b9061ffff91600383612afb83613db2565b1603612bb1577fffffffffffffffffffffffffffffffff000000000000000000000000000000006040519260801b16602083015260108252612b3c8261070a565b600383612b4883613db2565b1603612bb1578151838111612b795783166001019283116129eb5761094a61082a9260405194859360208501613e20565b604490604051907f6dfcc650000000000000000000000000000000000000000000000000000000008252601060048301526024820152fd5b82612bbd602492613db2565b6040517f3a51740d00000000000000000000000000000000000000000000000000000000815291166004820152fd5b60405190612bf98261070a565b60006020838281520152565b60405190612c1282610726565b8160008152600060208201526040612c28612bec565b910152565b919082604091031261029d57604051612c458161070a565b6020808294805184520151910152565b60808183031261029d5760405191612c6c83610726565b81518352602082015167ffffffffffffffff8116810361029d576020840152612c9791604001612c2d565b604082015290565b906001600160a01b036020919493946040845263ffffffff81511660408501528281015160608501526080612d19612ce5604084015160a08489015260e0880190610dc6565b60608401517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08883030160a0890152610dc6565b910151151560c08501529416910152565b608093612d9c612dd19694612d3d612c05565b506020612d4a8451613ea5565b930190815180612e10575b50612d6b6103866001546001600160a01b031690565b95612d758661300f565b9251151592612d856111b961078e565b602087015260408601526060850152151586840152565b6040518096819582947f2637a45000000000000000000000000000000000000000000000000000000000845260048401612c9f565b03925af190811561047357600091612de7575090565b61082a915060803d608011612e09575b612e01818361075e565b810190612c55565b503d612df7565b612e1990613edf565b38612d55565b9091612e3661082a93604084526040840190610dc6565b916020818403910152610dc6565b9190825115612f9457805115612f9457612e5d83613540565b9281519367ffffffffffffffff851161070557612e8485612e7e8354611850565b83612259565b602080601f8711600114612f055750857fdb6b260ea45f7fe513e1d3b8c21017a29e3a41610e95aefb8862b81c69aec61c9596612ed692600091612efa575b506000198260011b9260031b1c19161790565b90555b612ee281613d70565b8251602084012090556120cf60405192839283612e1f565b905085015138612ec3565b90601f198716612f1a84600052602060002090565b926000905b828210612f7c5750509187917fdb6b260ea45f7fe513e1d3b8c21017a29e3a41610e95aefb8862b81c69aec61c979860019410612f63575b5050811b019055612ed9565b86015160001960f88460031b161c191690553880612f57565b80600185968294968b01518155019501930190612f1f565b60046040517fdeba1689000000000000000000000000000000000000000000000000000000008152fd5b63ffffffff1660008181526002602090815260409182902084905581519283528201929092527f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b91819081016120cf565b63ffffffff1680600052600260205260406000205490811561302f575090565b602490604051907ff6ff4fb70000000000000000000000000000000000000000000000000000000082526004820152fd5b67ffffffffffffffff81116107055760051b60200190565b9080601f8301121561029d57602090823561309281613060565b936130a0604051958661075e565b81855260208086019260051b82010192831161029d57602001905b8282106130c9575050505090565b813581529083019083016130bb565b9080601f8301121561029d5760209082356130f281613060565b93613100604051958661075e565b81855260208086019260051b82010192831161029d57602001905b828210613129575050505090565b8135815290830190830161311b565b9080601f8301121561029d57602090823561315281613060565b93613160604051958661075e565b81855260208086019260051b82010192831161029d57602001905b828210613189575050505090565b83809183356131978161068b565b81520191019061317b565b91909160c08184031261029d576131b8816102cb565b9267ffffffffffffffff602083013581811161029d57826131da918501613078565b936131e7604085016106b7565b93606081013583811161029d57846132009183016130d8565b93608082013584811161029d57816132199184016130d8565b9360a083013590811161029d5761082a9201613138565b805115611ed55760200190565b8051821015611ed55760209160051b010190565b919091600e5460208201350361338f5761326a90612771565b63ffffffff61328a613281600d5463ffffffff1690565b63ffffffff1690565b91160361336557816132a6916001600160a01b039301906131a2565b93949195909216906132b781611f1c565b8061331c57506001835114801590613310575b8015613304575b61165f576132fe6132f16132ea6132ea6102d698613230565b5194613230565b516001600160a01b031690565b93614196565b506001825114156132d1565b506001855114156132ca565b8061332d6001929794959697611f1c565b0361333b576102d694614002565b60046040517f43013282000000000000000000000000000000000000000000000000000000008152fd5b60046040517fc6705675000000000000000000000000000000000000000000000000000000008152fd5b60046040517f5c49dc24000000000000000000000000000000000000000000000000000000008152fd5b916001600160a01b03604051927fa9059cbb000000000000000000000000000000000000000000000000000000006020850152166024830152604482015260448152608081019181831067ffffffffffffffff841117610705576102d6926040526142a3565b8147106134ae576001600160a01b0390600080809481948294165af13d156134a5573d61344b816107bc565b90613459604051928361075e565b8152809260203d92013e5b1561346c5750565b80511561347b57805190602001fd5b60046040517fd6bda275000000000000000000000000000000000000000000000000000000008152fd5b60609150613464565b506040517fcf4791810000000000000000000000000000000000000000000000000000000081524760048201526024810191909152604490fd5b9060408282031261029d5761082a91612c2d565b6001600160a01b0360005416330361351057565b60246040517f118cdaa7000000000000000000000000000000000000000000000000000000008152336004820152fd5b6040516135828161094a60208201947fa5b4aa1bcb538076d57d083e3004c6907e2eba42d84c21922d441967a02b472f86526040808401526060830190610dc6565b51902090565b90613597939291959495612a33565b156135b157816132a6916001600160a01b039301906131a2565b60046040517fca37de93000000000000000000000000000000000000000000000000000000008152fd5b600054906001600160a01b0380911691827fffffffffffffffffffffffff0000000000000000000000000000000000000000821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b613643612a7a565b60409081519360208501856136fe848381516001600160a01b03168152610180810192916020818101516001600160a01b0316908301526040818101516001600160a01b0316908301526060818101516001600160a01b0316908301526080818101516001600160a01b03169083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151908301526101208082015190830152610140808201519083015261016080910151910152565b0395613712601f199788810183528261075e565b5190209461372d61052d876000526007602052604060002090565b61373681611a6a565b613bcd5783830161375161038682516001600160a01b031690565b3303613ba4576101408401514603613b7b5761377a6109e7886000526007602052604060002090565b608084016001600160a01b0361379782516001600160a01b031690565b1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81036139d45750505061016083018051909190156139805784516137e76020820192826137db878b87613c46565b0390810183528261075e565b519020905103613957576138066103866009546001600160a01b031690565b9060e083015191803b1561029d5761384f9560009386518098819582947ff87ef80000000000000000000000000000000000000000000000000000000000845260048401613c46565b03925af1918215610473577f6955fd9b2a7639a9baac024897cad7007b45ffa74cbfe9582d58401ff6b977b79361393793613944575b505b519182918281516001600160a01b03168152610180810192916020818101516001600160a01b0316908301526040818101516001600160a01b0316908301526060818101516001600160a01b0316908301526080818101516001600160a01b03169083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151908301526101208082015190830152610140808201519083015261016080910151910152565b0390a26102d66001600455565b80610467613951926106f1565b38613885565b600483517f332c0963000000000000000000000000000000000000000000000000000000008152fd5b5050507f6955fd9b2a7639a9baac024897cad7007b45ffa74cbfe9582d58401ff6b977b79250613937916139cf6139c461038660208501516001600160a01b031690565b60e08401519061341f565b613887565b90919261016086989598019182511515600014613b2757508651613a026020820192826137db8c8a87613c46565b519020905103613afe5790613a35613a27610386613a5694516001600160a01b031690565b91516001600160a01b031690565b613a4a6103866009546001600160a01b031690565b9060e086015192613fa5565b613a6b6103866009546001600160a01b031690565b93843b1561029d57613aaf946000928386518098819582947ff87ef80000000000000000000000000000000000000000000000000000000000845260048401613c46565b03925af1918215610473577f6955fd9b2a7639a9baac024897cad7007b45ffa74cbfe9582d58401ff6b977b79361393793613aeb575b50613887565b80610467613af8926106f1565b38613ae5565b600485517f332c0963000000000000000000000000000000000000000000000000000000008152fd5b925050507f6955fd9b2a7639a9baac024897cad7007b45ffa74cbfe9582d58401ff6b977b79550613937949250613b686139cf92516001600160a01b031690565b60208501516001600160a01b0316613a4a565b600485517fb86ac1ef000000000000000000000000000000000000000000000000000000008152fd5b600485517fa4e189a6000000000000000000000000000000000000000000000000000000008152fd5b600484517f4747436c000000000000000000000000000000000000000000000000000000008152fd5b90357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18236030181121561029d57016020813591019167ffffffffffffffff821161029d57813603831361029d57565b9160208181850182865252604093604081019460408460051b83010195856000935b868510613c7a57505050505050505090565b90919293949596977fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc082820301845288357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff618436030181121561029d57830190813560a0600482101561029d576001938a93613d40613d5e9385613cfe8897610644565b83526001600160a01b0386850135613d158161068b565b16868401528b8401358c84015260609080613d3283870187613bf6565b929093860152840191612790565b91613d5060809182810190613bf6565b929091818503910152612790565b9a019401950193929695949190613c68565b6040516135828161094a60208201947f5f58fea7d48d37d5d1cc2546dfcc3d3cbfe8d758d5ca19c44087f52e15a1050586526040808401526060830190610dc6565b6002815110613dc2576002015190565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f746f55696e7431365f6f75744f66426f756e64730000000000000000000000006044820152fd5b602090613e37600495949382815194859201610da3565b01907fffff0000000000000000000000000000000000000000000000000000000000007f01000000000000000000000000000000000000000000000000000000000000009182845260f01b1660018301526003820152613ea08251809360208685019101610da3565b010190565b803403613eaf5790565b60246040517f9f704120000000000000000000000000000000000000000000000000000000008152346004820152fd5b6001600160a01b03908160015416916040517fe4fe1d94000000000000000000000000000000000000000000000000000000008152602081600481875afa90811561047357600091613f6a575b5016918215613f40576102d6923390613fa5565b60046040517f5373352a000000000000000000000000000000000000000000000000000000008152fd5b90506020813d602011613f9d575b81613f856020938361075e565b8101031261029d5751613f978161068b565b38613f2c565b3d9150613f78565b90926102d693604051937f23b872dd0000000000000000000000000000000000000000000000000000000060208601526001600160a01b038092166024860152166044840152606483015260648252613ffd82610742565b6142a3565b939294919061400f612a7a565b845115801561418a575b801561417e575b8015614173575b61165f5760005b85518110156140af57614041818761323d565b5190600161405c61052d846000526006602052604060002090565b61406581610644565b036110c457816140846105566001946000526006602052604060002090565b7fd48052bf92f3eec93ecdeeec72ea80e1071c926cb4d6e5a37ee71be8a0ce9a10600080a20161402e565b50919350919360005b855181101561416357806140ce6001928461323d565b516140ea6140e26115706132f1858c61323d565b9182546129f0565b905573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6141116103866132f1848b61323d565b0361413957614133614123828761323d565b516001600160a01b03861661341f565b016140b8565b61415e61414c6103866132f1848b61323d565b85614157848961323d565b51916133b9565b614133565b5050505090506102d66001600455565b506002845110614027565b50855184511415614020565b50815184511415614019565b92939094916141a3612a7a565b83511561165f5760009560005b8551811015614230576141c3818761323d565b519060016141de61052d846000526006602052604060002090565b6141e781610644565b036110c457816142066105566001946000526006602052604060002090565b7fd48052bf92f3eec93ecdeeec72ea80e1071c926cb4d6e5a37ee71be8a0ce9a108a80a2016141b0565b509295509250926142576140e2856001600160a01b03166000526005602052604060002090565b90556001600160a01b0392831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee8103614294575061428a921661341f565b6102d66001600455565b61429e93506133b9565b61428a565b906000602091828151910182855af115611f76576000513d61430e57506001600160a01b0381163b155b6142d45750565b6024906001600160a01b03604051917f5274afe7000000000000000000000000000000000000000000000000000000008352166004820152fd5b600114156142cd56fea2646970667358221220fbf9204717bf5fcea958a0a7a3caa8db19197ae7b8acdf8fc53baf44aaf8353b64736f6c63430008170033
Deployed Bytecode
0x6080604052600436101561001257600080fd5b60003560e01c80630630dea414610267578063076e9f6c146102625780630af7b75b1461025d5780630d77797c14610258578063116191b61461025357806313137d651461024e57806317442b70146102495780631a98b2e0146102445780631c93b03a1461023f5780631e44fb971461023a57806321b4ae78146102355780632b8cb1f6146102305780633400288b1461022b578063477aedc714610226578063491606581461022157806358c0f7291461021c57806359ce62e9146102175780635e280f11146102125780636a22d8cc1461020d578063715018a6146102085780637d25a05e1461020357806382413eac146101fe57806382c947b7146101f957806382e5f9e4146101f45780638da5cb5b146101ef578063951f4016146101ea578063a32b52a7146101e5578063aab59a09146101e0578063bb0b6a53146101db578063c415b95c146101d6578063c506bff4146101d1578063ca5eb5e1146101cc578063db715f7b146101c7578063f2fde38b146101c2578063f69b1b29146101bd578063ff7bd03d146101b85763ffd5982a146101b357600080fd5b611e75565b611e2f565b611e0b565b611d9d565b611d5f565b611ccd565b611c68565b611c41565b611c06565b611aac565b611a74565b611a4c565b611a25565b6119e6565b611820565b6117c1565b61179a565b611728565b611701565b6116da565b6116b3565b6114fc565b6113ba565b6112eb565b61128f565b61126b565b6110f8565b610f06565b610dfc565b610d13565b610cf1565b610bdf565b610b79565b610914565b610856565b610653565b6102d8565b9181601f8401121561029d5782359167ffffffffffffffff831161029d576020808501948460051b01011161029d57565b600080fd5b604435906fffffffffffffffffffffffffffffffff8216820361029d57565b6002111561029d57565b35906102d6826102c1565b565b608060031936011261029d576004803567ffffffffffffffff811161029d57610304903690830161026c565b909161030e6102a2565b926064359061031c826102c1565b610324612a7a565b34156105ec5783156105c35760005b84811061050b575061035f9061035160405195869260208401611eda565b03601f19810185528461075e565b61036881611f1c565b8061048b57509091506103926103866008546001600160a01b031690565b6001600160a01b031690565b803b1561029d57600060405180927f0c93e3bb00000000000000000000000000000000000000000000000000000000825281806103d33389308a8501611f26565b039134905af1801561047357610478575b506103fa6103866003546001600160a01b031690565b91823b1561029d5761043d92600092836040518096819582947f1c92115f0000000000000000000000000000000000000000000000000000000084528301611f82565b03925af180156104735761045a575b505b6104586001600455565b005b8061046761046d926106f1565b80610b6e565b3861044c565b611f76565b80610467610485926106f1565b386103e4565b80610497600192611f1c565b036104e357506104b16104dd926104ac612ab5565b612aea565b906104c1600d5463ffffffff1690565b916104ca610781565b9134835260243560208401523393612d2a565b5061044e565b6040517f7626db82000000000000000000000000000000000000000000000000000000008152fd5b61053461052d61051c838886611ec5565b356000526007602052604060002090565b5460ff1690565b61053d81611a6a565b1561059a578061056361055661051c6001948987611ec5565b600260ff19825416179055565b61056e818785611ec5565b357f69f975bd70ea51b973eb6aff3812f49adf595bd59d6f3d29840d5695cc19ba30600080a201610333565b836040517f4811daf5000000000000000000000000000000000000000000000000000000008152fd5b826040517f9d89020a000000000000000000000000000000000000000000000000000000008152fd5b826040517f03aeed96000000000000000000000000000000000000000000000000000000008152fd5b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b6004111561064e57565b610615565b3461029d57602060031936011261029d576004356000526006602052602060ff604060002054166040519061068781610644565b8152f35b6001600160a01b0381160361029d57565b60e435906102d68261068b565b61010435906102d68261068b565b35906102d68261068b565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b67ffffffffffffffff811161070557604052565b6106c2565b6040810190811067ffffffffffffffff82111761070557604052565b6060810190811067ffffffffffffffff82111761070557604052565b60a0810190811067ffffffffffffffff82111761070557604052565b90601f601f19910116810190811067ffffffffffffffff82111761070557604052565b604051906102d68261070a565b604051906102d682610742565b60405190610180820182811067ffffffffffffffff82111761070557604052565b67ffffffffffffffff811161070557601f01601f191660200190565b9291926107e4826107bc565b916107f2604051938461075e565b82948184528183011161029d578281602093846000960137010152565b9080601f8301121561029d5781602061082a933591016107d8565b90565b60c435906102d68261068b565b63ffffffff81160361029d57565b61012435906102d68261083a565b3461029d5761014060031936011261029d576004356108748161068b565b602435906108818261068b565b6044359161088e8361068b565b6064359261089b8461068b565b67ffffffffffffffff9360843585811161029d576108bd90369060040161080f565b60a43595861161029d576108d861045896369060040161080f565b906108e161082d565b926108ea61069c565b946108f36106a9565b966108fc610848565b98611fb4565b60031961018091011261029d57600490565b61018060031936011261029d5761092a36610902565b610932612a7a565b604090815160208101906109588161094a85856128ba565b03601f19810183528261075e565b5190209161097361052d846000526006602052604060002090565b61097c81610644565b610b455760a0820135421015610b1c574661012083013503610af3576060820173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee806001600160a01b036109c3846129a2565b16141580610aea575b610ac1576109f46109e7866000526006602052604060002090565b600160ff19825416179055565b610a00610386836129a2565b03610a78575060c08201353403610a4f577f181de28643611afcf1cb4c095a1ef99c157e78437294f478c978e4a56e1ca77e91610a42915b51918291826128ba565b0390a26104586001600455565b600490517f44e8bd2c000000000000000000000000000000000000000000000000000000008152fd5b91610a4291610abc610aad6103867f181de28643611afcf1cb4c095a1ef99c157e78437294f478c978e4a56e1ca77e966129a2565b60c08401359030903390613fa5565b610a38565b600483517fd453e7b5000000000000000000000000000000000000000000000000000000008152fd5b503415156109cc565b600490517f9284b197000000000000000000000000000000000000000000000000000000008152fd5b600490517fc56873ba000000000000000000000000000000000000000000000000000000008152fd5b600490517f966753c5000000000000000000000000000000000000000000000000000000008152fd5b600091031261029d57565b3461029d57600060031936011261029d5760206001600160a01b0360035416604051908152f35b600319606091011261029d57600490565b9181601f8401121561029d5782359167ffffffffffffffff831161029d576020838186019501011161029d57565b60e060031936011261029d57610bf436610ba0565b67ffffffffffffffff60843581811161029d57610c15903690600401610bb1565b91610c2160a43561068b565b60c43590811161029d57610c39903690600401610bb1565b50506001600160a01b03600154163303610cc057610c5e610c5984612771565b61300f565b926020810135809403610c75576104589350613251565b610c7f8491612771565b6040517fc26bebcc00000000000000000000000000000000000000000000000000000000815263ffffffff9190911660048201526024810191909152604490fd5b6040517f91ac5e4f000000000000000000000000000000000000000000000000000000008152336004820152602490fd5b3461029d57600060031936011261029d57604080516001815260026020820152f35b3461029d5760c060031936011261029d5767ffffffffffffffff60243581811161029d57610d45903690600401610bb1565b60443583811161029d57610d5d903690600401610bb1565b60649291923585811161029d57610d78903690600401610bb1565b9160843596871161029d57610d94610458973690600401610bb1565b95909460a435976004356127b1565b60005b838110610db65750506000910152565b8181015183820152602001610da6565b90601f19601f602093610de481518092818752878088019101610da3565b0116010190565b90602061082a928181520190610dc6565b3461029d57600080600319360112610f035760405190807f0e2c162a1f4b5cff9fdbd6b34678a9bcb9898a0b9fbca695b112d61688d8b2ac8054610e3f81611850565b80865292602092600192808416908115610ed35750600114610e7c575b610e7887610e6c8189038261075e565b60405191829182610deb565b0390f35b815293507f6703f9a97b5b44375099a890a40c8c70a9efc4d97fa39f72811f72b1a93211625b838510610ec057505050508101602001610e6c82610e783880610e5c565b8054868601840152938201938101610ea2565b9050879650610e7897945060209350610e6c95925060ff1991501682840152151560051b82010192933880610e5c565b80fd5b3461029d5761018060031936011261029d57610f2136610902565b610f29612a7a565b6040516020810190610f3f8161094a85856128ba565b519020906001610f5c61052d846000526006602052604060002090565b610f6581610644565b036110c457610f79610386604083016129a2565b330361107f575b466101208201350361105557610fb0610fa3836000526006602052604060002090565b600360ff19825416179055565b606081019073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b03610fdb846129a2565b160361102c57610ffd915060c0610ff4610386836129a2565b9101359061341f565b7fa60671d8537ed193e567f86ddf28cf35dc67073b5ad80a2d41359cfa78db0a1e600080a26104586001600455565b61103b610386611050936129a2565b9060c0611047826129a2565b910135916133b9565b610ffd565b60046040517f9284b197000000000000000000000000000000000000000000000000000000008152fd5b61109561108f60a08301356129db565b42111590565b15610f805760046040517f796c85f3000000000000000000000000000000000000000000000000000000008152fd5b60046040517fab81a57d000000000000000000000000000000000000000000000000000000008152fd5b8015150361029d57565b3461029d57608060031936011261029d576004356111158161083a565b60243567ffffffffffffffff811161029d5761117e9161113c61121192369060040161026c565b6111dc61114a9392936102a2565b6111866064359161115a836110ee565b6040988997611170895197889260208401611eda565b03601f19810187528661075e565b6104ac612ab5565b61118e612bec565b506111a46103866001546001600160a01b031690565b936111ae8661300f565b6111c56111b961078e565b63ffffffff9098168852565b602087015286860152606085015215156080840152565b825180809581947fddc28c58000000000000000000000000000000000000000000000000000000008352309060048401612c9f565b03915afa9081156104735760009161123e575b508051602091820151925190815290810191909152604090f35b61125e9150823d8411611264575b611256818361075e565b8101906134e8565b38611224565b503d61124c565b3461029d57600060031936011261029d57602063ffffffff600d5416604051908152f35b3461029d57604060031936011261029d576104586004356112af8161083a565b6112b76134fc565b60243590612fbe565b602060031982011261029d576004359067ffffffffffffffff821161029d5761082a9160040161080f565b3461029d576113016112fc366112c0565b613540565b6040519060008282549161131483611850565b9283835260209460019186600182169182600014611397575050600114611358575b50506113449250038361075e565b610e78604051928284938452830190610dc6565b85925060005281600020906000915b85831061137f57505061134493508201013880611336565b80548389018501528794508693909201918101611367565b9150935061134495925060ff1991501682840152151560051b8201013880611336565b3461029d57608060031936011261029d57600467ffffffffffffffff60243581811161029d576113ed9036908401610bb1565b9160443581811161029d576114059036908601610bb1565b9160643590811161029d5761141d9036908701610bb1565b9490938260208361142f368a8a6107d8565b8281519101208460008c6114816001600160a01b0360035416948c604051998a98899788967f5f6970c300000000000000000000000000000000000000000000000000000000885280359088016129fd565b03925af1908115610473576000916114cd575b50156114a4576104589650613588565b866040517f500c44b4000000000000000000000000000000000000000000000000000000008152fd5b6114ef915060203d6020116114f5575b6114e7818361075e565b81019061277b565b38611494565b503d6114dd565b3461029d57602060031936011261029d5760043567ffffffffffffffff811161029d5761152d90369060040161026c565b906001600160a01b0390600a9082600a5416330361168957831561165f5760005b84811061155757005b8061158961157061156b6001948987611ec5565b6129a2565b6001600160a01b03166000526005602052604060002090565b54806115d9575b84546001600160a01b031686806115ab61156b868c8a611ec5565b1691167f9bcb6d1f38f6800906185471a11ede9a8e16200853225aa62558db6076490f2d600080a40161154e565b60006115ec61157061156b858b89611ec5565b5573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee8661161161156b858b89611ec5565b1603611639576116348161162f61038688546001600160a01b031690565b61341f565b611590565b6116348161164e61038661156b868c8a611ec5565b87546001600160a01b0316906133b9565b60046040517f9d89020a000000000000000000000000000000000000000000000000000000008152fd5b60046040517f91034599000000000000000000000000000000000000000000000000000000008152fd5b3461029d57600060031936011261029d5760206001600160a01b0360095416604051908152f35b3461029d57600060031936011261029d5760206001600160a01b0360015416604051908152f35b3461029d57600060031936011261029d5760206001600160a01b0360085416604051908152f35b3461029d57600080600319360112610f03576117426134fc565b806001600160a01b0381547fffffffffffffffffffffffff000000000000000000000000000000000000000081168355167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e08280a380f35b3461029d57604060031936011261029d576117b660043561083a565b602060405160008152f35b3461029d5760a060031936011261029d576117db36610ba0565b5060643567ffffffffffffffff811161029d576117fc903690600401610bb1565b5050602060843561180c8161068b565b604051906001600160a01b03309116148152f35b3461029d57602060031936011261029d57602060043561183f8161068b565b6001600160a01b0360405191168152f35b90600182811c92168015611899575b602083101461186a57565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602260045260246000fd5b91607f169161185f565b600b54600092916118b382611850565b8082529160209060019081811690811561193257506001146118d6575b50505050565b92939450600b6000527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9926000935b85851061191f5750505060209250010190388080806118d0565b8054858501840152938201938101611905565b915050602094955060ff1991509291921683830152151560051b010190388080806118d0565b600c546000929161196882611850565b80825291602090600190818116908115611932575060011461198a5750505050565b92939450600c6000527fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7926000935b8585106119d35750505060209250010190388080806118d0565b80548585018401529382019381016119b9565b3461029d57600060031936011261029d57610e78604051611a1181611a0a816118a3565b038261075e565b604051918291602083526020830190610dc6565b3461029d57600060031936011261029d5760206001600160a01b0360005416604051908152f35b3461029d57600060031936011261029d576020600e54604051908152f35b6003111561064e57565b3461029d57602060031936011261029d57600435600052600760205260ff60406000205416604051600382101561064e576020918152f35b6101a060031936011261029d57611ac236610902565b6101843567ffffffffffffffff811161029d57611ae390369060040161026c565b906080830173eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038235611b108161068b565b161480611bf8575b611bce576101808436031261029d5761045893611b7a611b3661079b565b92611b40836106b7565b8452611b4e602084016106b7565b6020850152611b5f604084016106b7565b6040850152611b70606084016106b7565b60608501526106b7565b608083015260a081013560a083015260c081013560c083015260e081013560e0830152610100808201359083015261012080820135908301526101408082013590830152610160809101359082015261363b565b60046040517f44e8bd2c000000000000000000000000000000000000000000000000000000008152fd5b5060e0840135341415611b18565b3461029d57602060031936011261029d5763ffffffff600435611c288161083a565b1660005260026020526020604060002054604051908152f35b3461029d57600060031936011261029d5760206001600160a01b03600a5416604051908152f35b3461029d57604060031936011261029d5767ffffffffffffffff60043581811161029d57611c9a903690600401610bb1565b60249291923591821161029d57602092611cbb611cc3933690600401610bb1565b929091612a33565b6040519015158152f35b3461029d5760006020600319360112610f0357600435611cec8161068b565b611cf46134fc565b816001600160a01b03806001541692833b15611d5b576024908360405195869485937fca5eb5e10000000000000000000000000000000000000000000000000000000085521660048401525af1801561047357611d4f575080f35b611d58906106f1565b80f35b8280fd5b3461029d57602060031936011261029d576001600160a01b03600435611d848161068b565b1660005260056020526020604060002054604051908152f35b3461029d57602060031936011261029d57600435611dba8161068b565b611dc26134fc565b6001600160a01b03811615611dda57610458906135db565b60246040517f1e4fbdf700000000000000000000000000000000000000000000000000000000815260006004820152fd5b3461029d57600060031936011261029d57610e78604051611a1181611a0a81611958565b3461029d57606060031936011261029d576020611e4b36610ba0565b63ffffffff8135611e5b8161083a565b166000526002825260406000205482604051920135148152f35b3461029d576020611e8d611e88366112c0565b613d70565b54604051908152f35b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9190811015611ed55760051b0190565b611e96565b602081528260208201527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff831161029d5760409260051b809284830137010190565b6002111561064e57565b9190611f6f6080929594956001600160a01b03809316855260a06020860152611f61611f5460a087016118a3565b8681036040880152611958565b908582036060870152610dc6565b9416910152565b6040513d6000823e3d90fd5b61082a9160608252611fa6611f99606084016118a3565b8381036020850152611958565b916040818403910152610dc6565b9896949290979593917ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a009889549a60ff8c60401c16159b8c67ffffffffffffffff82168015918261216d575b506001149081612163575b15908161215a575b506121305761204e9b60017fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000008f93161790556120d4576124bc565b61205457565b6120a07ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a007fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff8154169055565b604051600181527fc7f505b2f371ae2175ee4913f4499e1f2633a7b5936321eed1cdaeb6115181d29080602081015b0390a1565b61212b7ff0c57e16840df040f15088dc2f81fe391c3923bec73e23a9662efc9c229c6a00680100000000000000007fffffffffffffffffffffffffffffffffffffffffffffff00ffffffffffffffff825416179055565b6124bc565b60046040517ff92ee8a9000000000000000000000000000000000000000000000000000000008152fd5b90501538612013565b303b15915061200b565b91508e612000565b601f8111612181575050565b600090600b6000527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db9906020601f850160051c830194106121dd575b601f0160051c01915b8281106121d257505050565b8181556001016121c6565b90925082906121bd565b601f81116121f3575050565b600090600c6000527fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c7906020601f850160051c8301941061224f575b601f0160051c01915b82811061224457505050565b818155600101612238565b909250829061222f565b90601f811161226757505050565b6000916000526020600020906020601f850160051c830194106122a5575b601f0160051c01915b82811061229a57505050565b81815560010161228e565b9092508290612285565b90815167ffffffffffffffff8111610705576122d5816122d0600b54611850565b612175565b602080601f831160011461231757508190612307939460009261230c575b50506000198260011b9260031b1c19161790565b600b55565b0151905038806122f3565b90601f1983169461234a600b6000527f0175b7a638427703f0dbe7bb9bbf987a2551717b34e79f33b5b1008d1fa01db990565b926000905b87821061238757505083600195961061236e575b505050811b01600b55565b015160001960f88460031b161c19169055388080612363565b8060018596829496860151815501950193019061234f565b90815167ffffffffffffffff8111610705576123c5816123c0600c54611850565b6121e7565b602080601f83116001146123fb575081906123f6939460009261230c5750506000198260011b9260031b1c19161790565b600c55565b90601f1983169461242e600c6000527fdf6966c971051c3d54ec59162606531493a51404a002842f56009d7e5cf4a8c790565b926000905b87821061246b575050836001959610612452575b505050811b01600c55565b015160001960f88460031b161c19169055388080612447565b80600185968294968601518155019501930190612433565b9061082a926001600160a01b038092168352166020820152608060408201526124ae608082016118a3565b906060818303910152611958565b6125ae926125466125c59796959361251261257a949d9b9a9d6124de8c612a5a565b6001600160a01b03167fffffffffffffffffffffffff00000000000000000000000000000000000000006003541617600355565b6001600160a01b03167fffffffffffffffffffffffff00000000000000000000000000000000000000006008541617600855565b6001600160a01b03167fffffffffffffffffffffffff00000000000000000000000000000000000000006009541617600955565b6001600160a01b03167fffffffffffffffffffffffff0000000000000000000000000000000000000000600a541617600a55565b6125b7816122af565b6125c08261239f565b612e44565b6001600160a01b0393848116907311111111111111111111111111111111111111118203612678575b50505050506126056003546001600160a01b031690565b907ff25a5e989fb7e02dc64e8a2c85e4fbaae049d3ce88c8cbb840860122201da24b6126396008546001600160a01b031690565b9161264c6009546001600160a01b031690565b92612673612662600a546001600160a01b031690565b836040519485941697169583612483565b0390a3565b6126b0906001600160a01b03167fffffffffffffffffffffffff00000000000000000000000000000000000000006001541617600155565b803b1561029d576040517fca5eb5e10000000000000000000000000000000000000000000000000000000081526001600160a01b039290921660048301526000908290602490829084905af18015610473576127549361274f92869261275e575b506127478463ffffffff167fffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000600d541617600d55565b168092612fbe565b600e55565b38808080806125ee565b8061046761276b926106f1565b38612711565b3561082a8161083a565b9081602091031261029d575161082a816110ee565b601f8260209493601f19938186528686013760008582860101520116010190565b9260209861285092986127ce6128289c95986000989a36916107d8565b8b81519101209261283c6001600160a01b03600354169a6040519e8f9d8e9c8d9b7f1876eed9000000000000000000000000000000000000000000000000000000008d5260048d015260c060248d015260c48c0191612790565b9060031993848b84030160448c0152612790565b936064880152868403016084870152612790565b9060a483015203925af19081156104735760009161289b575b501561287157565b60046040517f500c44b4000000000000000000000000000000000000000000000000000000008152fd5b6128b4915060203d6020116114f5576114e7818361075e565b38612869565b610180810192916128db826128ce836106b7565b6001600160a01b03169052565b6128fa6128ea602083016106b7565b6001600160a01b03166020840152565b612919612909604083016106b7565b6001600160a01b03166040840152565b612938612928606083016106b7565b6001600160a01b03166060840152565b612957612947608083016106b7565b6001600160a01b03166080840152565b60a081013560a083015260c081013560c083015260e081013560e083015261010080820135908301526101208082013590830152610140808201359083015261016080910135910152565b3561082a8161068b565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b906205460082018092116129eb57565b6129ac565b919082018092116129eb57565b9695949060609492612a2e94612a20928a52608060208b015260808a0191612790565b918783036040890152612790565b930152565b612a46612a5593611e88939536916107d8565b602081519101209336916107d8565b541490565b612a626134fc565b6001600160a01b03811615611dda576102d6906135db565b600260045414612a8b576002600455565b60046040517f3ee5aeb5000000000000000000000000000000000000000000000000000000008152fd5b6040517e0300000000000000000000000000000000000000000000000000000000000060208201526002815261082a8161070a565b9061ffff91600383612afb83613db2565b1603612bb1577fffffffffffffffffffffffffffffffff000000000000000000000000000000006040519260801b16602083015260108252612b3c8261070a565b600383612b4883613db2565b1603612bb1578151838111612b795783166001019283116129eb5761094a61082a9260405194859360208501613e20565b604490604051907f6dfcc650000000000000000000000000000000000000000000000000000000008252601060048301526024820152fd5b82612bbd602492613db2565b6040517f3a51740d00000000000000000000000000000000000000000000000000000000815291166004820152fd5b60405190612bf98261070a565b60006020838281520152565b60405190612c1282610726565b8160008152600060208201526040612c28612bec565b910152565b919082604091031261029d57604051612c458161070a565b6020808294805184520151910152565b60808183031261029d5760405191612c6c83610726565b81518352602082015167ffffffffffffffff8116810361029d576020840152612c9791604001612c2d565b604082015290565b906001600160a01b036020919493946040845263ffffffff81511660408501528281015160608501526080612d19612ce5604084015160a08489015260e0880190610dc6565b60608401517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08883030160a0890152610dc6565b910151151560c08501529416910152565b608093612d9c612dd19694612d3d612c05565b506020612d4a8451613ea5565b930190815180612e10575b50612d6b6103866001546001600160a01b031690565b95612d758661300f565b9251151592612d856111b961078e565b602087015260408601526060850152151586840152565b6040518096819582947f2637a45000000000000000000000000000000000000000000000000000000000845260048401612c9f565b03925af190811561047357600091612de7575090565b61082a915060803d608011612e09575b612e01818361075e565b810190612c55565b503d612df7565b612e1990613edf565b38612d55565b9091612e3661082a93604084526040840190610dc6565b916020818403910152610dc6565b9190825115612f9457805115612f9457612e5d83613540565b9281519367ffffffffffffffff851161070557612e8485612e7e8354611850565b83612259565b602080601f8711600114612f055750857fdb6b260ea45f7fe513e1d3b8c21017a29e3a41610e95aefb8862b81c69aec61c9596612ed692600091612efa575b506000198260011b9260031b1c19161790565b90555b612ee281613d70565b8251602084012090556120cf60405192839283612e1f565b905085015138612ec3565b90601f198716612f1a84600052602060002090565b926000905b828210612f7c5750509187917fdb6b260ea45f7fe513e1d3b8c21017a29e3a41610e95aefb8862b81c69aec61c979860019410612f63575b5050811b019055612ed9565b86015160001960f88460031b161c191690553880612f57565b80600185968294968b01518155019501930190612f1f565b60046040517fdeba1689000000000000000000000000000000000000000000000000000000008152fd5b63ffffffff1660008181526002602090815260409182902084905581519283528201929092527f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b91819081016120cf565b63ffffffff1680600052600260205260406000205490811561302f575090565b602490604051907ff6ff4fb70000000000000000000000000000000000000000000000000000000082526004820152fd5b67ffffffffffffffff81116107055760051b60200190565b9080601f8301121561029d57602090823561309281613060565b936130a0604051958661075e565b81855260208086019260051b82010192831161029d57602001905b8282106130c9575050505090565b813581529083019083016130bb565b9080601f8301121561029d5760209082356130f281613060565b93613100604051958661075e565b81855260208086019260051b82010192831161029d57602001905b828210613129575050505090565b8135815290830190830161311b565b9080601f8301121561029d57602090823561315281613060565b93613160604051958661075e565b81855260208086019260051b82010192831161029d57602001905b828210613189575050505090565b83809183356131978161068b565b81520191019061317b565b91909160c08184031261029d576131b8816102cb565b9267ffffffffffffffff602083013581811161029d57826131da918501613078565b936131e7604085016106b7565b93606081013583811161029d57846132009183016130d8565b93608082013584811161029d57816132199184016130d8565b9360a083013590811161029d5761082a9201613138565b805115611ed55760200190565b8051821015611ed55760209160051b010190565b919091600e5460208201350361338f5761326a90612771565b63ffffffff61328a613281600d5463ffffffff1690565b63ffffffff1690565b91160361336557816132a6916001600160a01b039301906131a2565b93949195909216906132b781611f1c565b8061331c57506001835114801590613310575b8015613304575b61165f576132fe6132f16132ea6132ea6102d698613230565b5194613230565b516001600160a01b031690565b93614196565b506001825114156132d1565b506001855114156132ca565b8061332d6001929794959697611f1c565b0361333b576102d694614002565b60046040517f43013282000000000000000000000000000000000000000000000000000000008152fd5b60046040517fc6705675000000000000000000000000000000000000000000000000000000008152fd5b60046040517f5c49dc24000000000000000000000000000000000000000000000000000000008152fd5b916001600160a01b03604051927fa9059cbb000000000000000000000000000000000000000000000000000000006020850152166024830152604482015260448152608081019181831067ffffffffffffffff841117610705576102d6926040526142a3565b8147106134ae576001600160a01b0390600080809481948294165af13d156134a5573d61344b816107bc565b90613459604051928361075e565b8152809260203d92013e5b1561346c5750565b80511561347b57805190602001fd5b60046040517fd6bda275000000000000000000000000000000000000000000000000000000008152fd5b60609150613464565b506040517fcf4791810000000000000000000000000000000000000000000000000000000081524760048201526024810191909152604490fd5b9060408282031261029d5761082a91612c2d565b6001600160a01b0360005416330361351057565b60246040517f118cdaa7000000000000000000000000000000000000000000000000000000008152336004820152fd5b6040516135828161094a60208201947fa5b4aa1bcb538076d57d083e3004c6907e2eba42d84c21922d441967a02b472f86526040808401526060830190610dc6565b51902090565b90613597939291959495612a33565b156135b157816132a6916001600160a01b039301906131a2565b60046040517fca37de93000000000000000000000000000000000000000000000000000000008152fd5b600054906001600160a01b0380911691827fffffffffffffffffffffffff0000000000000000000000000000000000000000821617600055167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e0600080a3565b613643612a7a565b60409081519360208501856136fe848381516001600160a01b03168152610180810192916020818101516001600160a01b0316908301526040818101516001600160a01b0316908301526060818101516001600160a01b0316908301526080818101516001600160a01b03169083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151908301526101208082015190830152610140808201519083015261016080910151910152565b0395613712601f199788810183528261075e565b5190209461372d61052d876000526007602052604060002090565b61373681611a6a565b613bcd5783830161375161038682516001600160a01b031690565b3303613ba4576101408401514603613b7b5761377a6109e7886000526007602052604060002090565b608084016001600160a01b0361379782516001600160a01b031690565b1673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee81036139d45750505061016083018051909190156139805784516137e76020820192826137db878b87613c46565b0390810183528261075e565b519020905103613957576138066103866009546001600160a01b031690565b9060e083015191803b1561029d5761384f9560009386518098819582947ff87ef80000000000000000000000000000000000000000000000000000000000845260048401613c46565b03925af1918215610473577f6955fd9b2a7639a9baac024897cad7007b45ffa74cbfe9582d58401ff6b977b79361393793613944575b505b519182918281516001600160a01b03168152610180810192916020818101516001600160a01b0316908301526040818101516001600160a01b0316908301526060818101516001600160a01b0316908301526080818101516001600160a01b03169083015260a081015160a083015260c081015160c083015260e081015160e083015261010080820151908301526101208082015190830152610140808201519083015261016080910151910152565b0390a26102d66001600455565b80610467613951926106f1565b38613885565b600483517f332c0963000000000000000000000000000000000000000000000000000000008152fd5b5050507f6955fd9b2a7639a9baac024897cad7007b45ffa74cbfe9582d58401ff6b977b79250613937916139cf6139c461038660208501516001600160a01b031690565b60e08401519061341f565b613887565b90919261016086989598019182511515600014613b2757508651613a026020820192826137db8c8a87613c46565b519020905103613afe5790613a35613a27610386613a5694516001600160a01b031690565b91516001600160a01b031690565b613a4a6103866009546001600160a01b031690565b9060e086015192613fa5565b613a6b6103866009546001600160a01b031690565b93843b1561029d57613aaf946000928386518098819582947ff87ef80000000000000000000000000000000000000000000000000000000000845260048401613c46565b03925af1918215610473577f6955fd9b2a7639a9baac024897cad7007b45ffa74cbfe9582d58401ff6b977b79361393793613aeb575b50613887565b80610467613af8926106f1565b38613ae5565b600485517f332c0963000000000000000000000000000000000000000000000000000000008152fd5b925050507f6955fd9b2a7639a9baac024897cad7007b45ffa74cbfe9582d58401ff6b977b79550613937949250613b686139cf92516001600160a01b031690565b60208501516001600160a01b0316613a4a565b600485517fb86ac1ef000000000000000000000000000000000000000000000000000000008152fd5b600485517fa4e189a6000000000000000000000000000000000000000000000000000000008152fd5b600484517f4747436c000000000000000000000000000000000000000000000000000000008152fd5b90357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe18236030181121561029d57016020813591019167ffffffffffffffff821161029d57813603831361029d57565b9160208181850182865252604093604081019460408460051b83010195856000935b868510613c7a57505050505050505090565b90919293949596977fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc082820301845288357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff618436030181121561029d57830190813560a0600482101561029d576001938a93613d40613d5e9385613cfe8897610644565b83526001600160a01b0386850135613d158161068b565b16868401528b8401358c84015260609080613d3283870187613bf6565b929093860152840191612790565b91613d5060809182810190613bf6565b929091818503910152612790565b9a019401950193929695949190613c68565b6040516135828161094a60208201947f5f58fea7d48d37d5d1cc2546dfcc3d3cbfe8d758d5ca19c44087f52e15a1050586526040808401526060830190610dc6565b6002815110613dc2576002015190565b60646040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f746f55696e7431365f6f75744f66426f756e64730000000000000000000000006044820152fd5b602090613e37600495949382815194859201610da3565b01907fffff0000000000000000000000000000000000000000000000000000000000007f01000000000000000000000000000000000000000000000000000000000000009182845260f01b1660018301526003820152613ea08251809360208685019101610da3565b010190565b803403613eaf5790565b60246040517f9f704120000000000000000000000000000000000000000000000000000000008152346004820152fd5b6001600160a01b03908160015416916040517fe4fe1d94000000000000000000000000000000000000000000000000000000008152602081600481875afa90811561047357600091613f6a575b5016918215613f40576102d6923390613fa5565b60046040517f5373352a000000000000000000000000000000000000000000000000000000008152fd5b90506020813d602011613f9d575b81613f856020938361075e565b8101031261029d5751613f978161068b565b38613f2c565b3d9150613f78565b90926102d693604051937f23b872dd0000000000000000000000000000000000000000000000000000000060208601526001600160a01b038092166024860152166044840152606483015260648252613ffd82610742565b6142a3565b939294919061400f612a7a565b845115801561418a575b801561417e575b8015614173575b61165f5760005b85518110156140af57614041818761323d565b5190600161405c61052d846000526006602052604060002090565b61406581610644565b036110c457816140846105566001946000526006602052604060002090565b7fd48052bf92f3eec93ecdeeec72ea80e1071c926cb4d6e5a37ee71be8a0ce9a10600080a20161402e565b50919350919360005b855181101561416357806140ce6001928461323d565b516140ea6140e26115706132f1858c61323d565b9182546129f0565b905573eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6141116103866132f1848b61323d565b0361413957614133614123828761323d565b516001600160a01b03861661341f565b016140b8565b61415e61414c6103866132f1848b61323d565b85614157848961323d565b51916133b9565b614133565b5050505090506102d66001600455565b506002845110614027565b50855184511415614020565b50815184511415614019565b92939094916141a3612a7a565b83511561165f5760009560005b8551811015614230576141c3818761323d565b519060016141de61052d846000526006602052604060002090565b6141e781610644565b036110c457816142066105566001946000526006602052604060002090565b7fd48052bf92f3eec93ecdeeec72ea80e1071c926cb4d6e5a37ee71be8a0ce9a108a80a2016141b0565b509295509250926142576140e2856001600160a01b03166000526005602052604060002090565b90556001600160a01b0392831673eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee8103614294575061428a921661341f565b6102d66001600455565b61429e93506133b9565b61428a565b906000602091828151910182855af115611f76576000513d61430e57506001600160a01b0381163b155b6142d45750565b6024906001600160a01b03604051917f5274afe7000000000000000000000000000000000000000000000000000000008352166004820152fd5b600114156142cd56fea2646970667358221220fbf9204717bf5fcea958a0a7a3caa8db19197ae7b8acdf8fc53baf44aaf8353b64736f6c63430008170033
Loading...
Loading
Loading...
Loading
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|---|---|---|---|---|
| ETH | 58.56% | $3,405.93 | 0.0112 | $38.25 | |
| ETH | 9.78% | $0.999802 | 6.3864 | $6.39 | |
| ETH | 6.91% | $0.99978 | 4.514 | $4.51 | |
| ETH | 1.11% | $3,405.93 | 0.00021211 | $0.7224 | |
| BSC | 2.53% | $0.999771 | 1.6539 | $1.65 | |
| BSC | 2.36% | $0.999828 | 1.5409 | $1.54 | |
| BSC | 1.39% | $3,396.08 | 0.00026733 | $0.9078 | |
| BASE | 2.91% | $0.999802 | 1.8981 | $1.9 | |
| BASE | 2.60% | $3,401.74 | 0.0004986 | $1.7 | |
| BASE | 0.49% | $3,395.84 | 0.00009406 | $0.3194 | |
| ARB | 1.80% | $0.999754 | 1.1743 | $1.17 | |
| ARB | 1.64% | $3,406 | 0.00031463 | $1.07 | |
| ARB | 0.83% | $0.999642 | 0.5448 | $0.5446 | |
| ARB | 0.27% | $3,401.61 | 0.00005171 | $0.1759 | |
| LINEA | 1.19% | $3,405.93 | 0.00022765 | $0.77537 | |
| LINEA | 0.83% | $3,390.05 | 0.00016064 | $0.5445 | |
| LINEA | 0.82% | $0.99978 | 0.533 | $0.5328 | |
| POL | 0.74% | $0.999802 | 0.4849 | $0.4848 | |
| POL | 0.62% | $0.99958 | 0.4019 | $0.4017 | |
| AVAX | 0.67% | $0.999828 | 0.4376 | $0.4374 | |
| AVAX | 0.51% | $0.999698 | 0.3303 | $0.3302 | |
| AVAX | 0.06% | $17.34 | 0.00232845 | $0.040366 | |
| OP | 0.33% | $3,405.4 | 0.00006283 | $0.213964 | |
| OP | 0.31% | $0.999802 | 0.2007 | $0.2006 | |
| CELO | 0.28% | $0.99978 | 0.1824 | $0.1823 | |
| CELO | 0.23% | $1 | 0.1518 | $0.1518 | |
| HYPEREVM | 0.18% | $0.99958 | 0.1163 | $0.1162 | |
| HYPEREVM | <0.01% | $40.73 | 0.00015359 | $0.006255 | |
| SONIC | 0.06% | $0.167555 | 0.2431 | $0.040739 | |
| BLAST | <0.01% | $3,405.48 | 0.0000015 | $0.005106 |
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.