Feature Tip: Add private address tag to any address under My Name Tag !
Source Code
Overview
ETH Balance
0 ETH
Eth Value
$0.00View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Loading...
Loading
Loading...
Loading
Cross-Chain Transactions
Loading...
Loading
Contract Name:
Fiat24CryptoDeposit2
Compiler Version
v0.8.20+commit.a1b79de6
Optimization Enabled:
Yes with 1 runs
Other Settings:
paris EvmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/IERC20Upgradeable.sol";
import "@openzeppelin/contracts-upgradeable/token/ERC20/extensions/draft-IERC20PermitUpgradeable.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol";
import "@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
import "@uniswap/v3-periphery/contracts/interfaces/IPeripheryPaymentsWithFee.sol";
import "@uniswap/v3-periphery/contracts/interfaces/IQuoter.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
import {ICrossChainMessenger} from "./interfaces/ICrossChainMessenger.sol";
import "./interfaces/IFiat24CryptoDeposit.sol";
import "./libraries/DigitsOfUint.sol";
import "./Fiat24CryptoRelay.sol";
import { OApp } from "@layerzerolabs/oapp-evm/contracts/oapp/OApp.sol";
import { MessagingFee } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import "@layerzerolabs/oapp-evm-upgradeable/contracts/oapp/OAppUpgradeable.sol";
import "@layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol";
import { Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppOptionsType3Upgradeable } from "@layerzerolabs/oapp-evm-upgradeable/contracts/oapp/libs/OAppOptionsType3Upgradeable.sol";
contract Fiat24CryptoDeposit2 is OAppUpgradeable,OAppOptionsType3Upgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable,IFiat24CryptoDeposit {
using SafeMath for uint256;
using DigitsOfUint for uint256;
using OptionsBuilder for bytes;
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
bytes32 public constant CASH_OPERATOR_ROLE = keccak256("CASH_OPERATOR_ROLE");
bytes32 public constant OPERATOR_ADMIN_ROLE = keccak256("OPERATOR_ADMIN_ROLE");
bytes32 public constant PAUSE_ROLE = keccak256("PAUSE_ROLE");
bytes32 public constant UNPAUSE_ROLE = keccak256("UNPAUSE_ROLE");
//UNISWAP ADDRESSES ARBITRUM MAINNET
address public constant UNISWAP_FACTORY = 0x1F98431c8aD98523631AE4a59f267346ea31F984;
address public constant UNISWAP_ROUTER = 0xE592427A0AEce92De3Edee1F18E0157C05861564;
address public constant UNISWAP_PERIPHERY_PAYMENTS = 0xE592427A0AEce92De3Edee1F18E0157C05861564;
address public constant UNISWAP_QUOTER = 0xb27308f9F90D607463bb33eA1BeBb41C27CE5AB6;
uint256 public constant MAX_DIGITS = 5;
uint256 public constant MAX_FEE_AMOUNT_USDC = 5_000_000;
uint256 public constant MAX_RETRY_COUNT = 3;
address public usdc;
address public weth;
uint256 public slippage;
uint128 private lzNativeFee = 198009600000000;
//Max and min USDC top-up amount
uint256 public maxUsdcDepositAmount;
uint256 public minUsdcDepositAmount;
mapping(address => bool) public validXXX24Tokens;
address public usdcDepositAddress;
address public feeReceiver;
//F24 airdrop
uint256 public f24AirdropStart;
uint256 public f24PerUSDC;
bool public f24AirdropPaused;
address public cnh24;
uint32 public dstId;
uint128 public relay_gas_limit;
mapping(bytes32 => FailedRefund) public failedMessages;
// Aggregator whitelist for secure swap execution
mapping(address => bool) public whitelistedAggregators;
// Whitelisted function selectors for each aggregator (aggregator => selector => allowed)
mapping(address => mapping(bytes4 => bool)) public whitelistedSelectors;
event FeeReceiverChanged(address indexed oldFeeReceiver, address indexed newFeeReceiver);
event AggregatorWhitelistUpdated(address indexed aggregator, bool isWhitelisted);
event FunctionSelectorWhitelisted(address indexed aggregator, bytes4 indexed selector, bool isWhitelisted);
event SentDepositedTokenViaAggregator(address indexed sender, address indexed inputToken, address indexed outputToken, uint256 inputAmount, uint256 usdcAmount, address aggregator);
constructor(address _endpoint) OAppUpgradeable(_endpoint) {}
// function initialize(
// address admin,
// address _delegate,
// address _usd24,
// address _eur24,
// address _chf24,
// address _gbp24,
// address _cnh24,
// address _usdc,
// address _weth,
// address _usdcDepositAddress,
// address _feeReceiver,
// uint32 _dstId
// ) public initializer {
// require(admin != address(0), "admin is zero");
// require(_delegate != address(0), "delegate is zero");
// require(_usd24 != address(0), "usd24 is zero");
// require(_eur24 != address(0), "eur24 is zero");
// require(_chf24 != address(0), "chf24 is zero");
// require(_gbp24 != address(0), "gbp24 is zero");
// require(_cnh24 != address(0), "cnh24 is zero");
// require(_usdc != address(0), "usdc is zero");
// require(_weth != address(0), "weth is zero");
// require(_usdcDepositAddress != address(0), "usdcDepositAddress is zero");
// require(_feeReceiver != address(0), "_feeReceiver is zero");
// __AccessControl_init_unchained();
// __Pausable_init_unchained();
// __ReentrancyGuard_init();
// _setupRole(DEFAULT_ADMIN_ROLE, admin);
// _setupRole(OPERATOR_ADMIN_ROLE, admin);
// _setupRole(OPERATOR_ROLE, admin);
// __OApp_init(_delegate);
// __Ownable_init();
// _transferOwnership(admin);
// usdc = _usdc;
// weth = _weth;
// usdcDepositAddress = _usdcDepositAddress;
// feeReceiver = _feeReceiver;
// maxUsdcDepositAmount = 50000000000;
// minUsdcDepositAmount = 3000000;
// relay_gas_limit = 500000;
// dstId = _dstId;
// validXXX24Tokens[_cnh24] = true;
// validXXX24Tokens[_usd24] = true;
// validXXX24Tokens[_eur24] = true;
// validXXX24Tokens[_chf24] = true;
// validXXX24Tokens[_gbp24] = true;
// }
// Deposit ETH, convert to USDC, send cross-chain message using LayerZero OApp
function depositETH(address _outputToken, uint256 nativeFee, uint256 _amountOutMinimum) nonReentrant external payable returns (uint256) {
if (paused()) revert Fiat24CryptoDeposit__Paused();
if (msg.value == 0) revert Fiat24CryptoDeposit__ValueZero();
if (!validXXX24Tokens[_outputToken]) revert Fiat24CryptoDeposit__NotValidOutputToken(_outputToken);
uint256 amountIn = msg.value - nativeFee;
uint256 usdcAmount = _swapToUsdc(weth, amountIn, _amountOutMinimum, true);
if (usdcAmount > maxUsdcDepositAmount) revert Fiat24CryptoDeposit__UsdcAmountHigherMaxDepositAmount(usdcAmount, maxUsdcDepositAmount);
if (usdcAmount < minUsdcDepositAmount) revert Fiat24CryptoDeposit__UsdcAmountLowerMinDepositAmount(usdcAmount, minUsdcDepositAmount);
TransferHelper.safeTransfer(usdc, usdcDepositAddress, usdcAmount);
_sendLayerZeroMessage(_msgSender(), address(0), amountIn, usdcAmount, _outputToken, nativeFee, payable(msg.sender));
emit SentDepositedEth(_msgSender(), weth, _outputToken, amountIn, usdcAmount);
return usdcAmount;
}
// Deposit token via USDC, swap to target token and send cross-chain message
function depositTokenViaUsdc(address _inputToken, address _outputToken, uint256 _amount, uint256 _amountOutMinimum) nonReentrant payable external returns (uint256) {
if (paused()) revert Fiat24CryptoDeposit__Paused();
if (_amount == 0) revert Fiat24CryptoDeposit__ValueZero();
if (!validXXX24Tokens[_outputToken]) revert Fiat24CryptoDeposit__NotValidOutputToken(_outputToken);
TransferHelper.safeTransferFrom(_inputToken, _msgSender(), address(this), _amount);
uint256 usdcAmount = _swapToUsdc(_inputToken, _amount, _amountOutMinimum, false);
if (usdcAmount > maxUsdcDepositAmount) revert Fiat24CryptoDeposit__UsdcAmountHigherMaxDepositAmount(usdcAmount, maxUsdcDepositAmount);
if (usdcAmount < minUsdcDepositAmount) revert Fiat24CryptoDeposit__UsdcAmountLowerMinDepositAmount(usdcAmount, minUsdcDepositAmount);
TransferHelper.safeTransfer(usdc, usdcDepositAddress, usdcAmount);
_sendLayerZeroMessage(_msgSender(), _inputToken, _amount, usdcAmount, _outputToken, msg.value, payable(feeReceiver));
emit SentDepositedTokenViaUsd(_msgSender(), _inputToken, _outputToken, _amount, usdcAmount);
return usdcAmount;
}
/// @notice Deposit token via aggregator (1inch, odos, etc.), swap to USDC and send cross-chain message
/// @param _inputToken The token to deposit (address(0) for ETH)
/// @param _outputToken The target fiat24 token (EUR24, USD24, etc.)
/// @param _amount The amount of input token to deposit (for ETH, this is the ETH amount to swap, msg.value = _amount + lzFee)
/// @param _aggregator The whitelisted aggregator contract address
/// @param _swapCalldata The calldata for the aggregator swap
/// @param _minUsdcAmount The minimum acceptable USDC amount after swap
/// @param _feeAmountViaUsdc The fee amount in USDC to charge
function depositTokenViaAggregator(
address _inputToken,
address _outputToken,
uint256 _amount,
address _aggregator,
bytes calldata _swapCalldata,
uint256 _minUsdcAmount,
uint256 _feeAmountViaUsdc
) nonReentrant payable external returns (uint256) {
if (paused()) revert Fiat24CryptoDeposit__Paused();
if (_amount == 0) revert Fiat24CryptoDeposit__ValueZero();
if (!validXXX24Tokens[_outputToken]) revert Fiat24CryptoDeposit__NotValidOutputToken(_outputToken);
address sender = _msgSender();
uint256 lzFee;
// Handle ETH deposit
if (_inputToken == address(0) || _inputToken == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
if (msg.value <= _amount) revert Fiat24CryptoDeposit__ValueZero();
lzFee = msg.value - _amount;
// ETH is already in msg.value, will be used in swap
} else {
if (msg.value == 0) revert Fiat24CryptoDeposit__ValueZero(); // Validate LayerZero fee
lzFee = msg.value;
TransferHelper.safeTransferFrom(_inputToken, sender, address(this), _amount);
}
uint256 usdcFactAmount;
{
uint256 usdcAmount = _swapViaAggregator(_inputToken, _amount, _aggregator, _swapCalldata, _minUsdcAmount);
usdcFactAmount = _processFeeAndValidation(usdcAmount, _feeAmountViaUsdc);
TransferHelper.safeTransfer(usdc, usdcDepositAddress, usdcFactAmount);
}
_sendLayerZeroMessage(sender, _inputToken, _amount, usdcFactAmount, _outputToken, lzFee, payable(feeReceiver));
emit SentDepositedTokenViaAggregator(sender, _inputToken, _outputToken, _amount, usdcFactAmount, _aggregator);
return usdcFactAmount;
}
/// @notice Deposit token via aggregator to another account owned by the sender
/// @param _targetAccount The target Fiat24 account address to deposit to
/// @param _inputToken The token to deposit (address(0) for ETH)
/// @param _outputToken The target fiat24 token (EUR24, USD24, etc.)
/// @param _amount The amount of input token to deposit (for ETH, msg.value = _amount + lzFee)
/// @param _aggregator The whitelisted aggregator contract address
/// @param _swapCalldata The calldata for the aggregator swap
/// @param _minUsdcAmount The minimum acceptable USDC amount after swap
function depositTokenViaAggregatorToAccount(
address _targetAccount,
address _inputToken,
address _outputToken,
uint256 _amount,
address _aggregator,
bytes calldata _swapCalldata,
uint256 _minUsdcAmount
) nonReentrant payable external returns (uint256) {
if (_amount == 0 || msg.value == 0) revert Fiat24CryptoDeposit__ValueZero();
_validateDepositToAccountParams(_targetAccount, _outputToken);
address sender = _msgSender();
uint256 lzFee;
// Handle ETH deposit
if (_inputToken == address(0) || _inputToken == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
if (msg.value <= _amount) revert Fiat24CryptoDeposit__ValueZero();
lzFee = msg.value - _amount;
// ETH is already in msg.value, will be used in swap
} else {
lzFee = msg.value;
TransferHelper.safeTransferFrom(_inputToken, sender, address(this), _amount);
}
uint256 usdcAmount = _swapViaAggregator(_inputToken, _amount, _aggregator, _swapCalldata, _minUsdcAmount);
if (usdcAmount == 0) revert Fiat24CryptoDeposit__SwapOutputAmountZero();
// Process deposit to account via LayerZero
_processDepositToAccountLayerZero(_targetAccount, _inputToken, _amount, usdcAmount, _outputToken, lzFee);
emit SentDepositedTokenViaUsd(_targetAccount, _inputToken, _outputToken, _amount, usdcAmount);
emit DepositToAccount(sender, _targetAccount, _inputToken, _amount);
return usdcAmount;
}
// Deposit ETH to another account owned by the sender
function depositETHToAccount(address _targetAccount, address _outputToken, uint256 nativeFee, uint256 _amountOutMinimum) nonReentrant external payable returns (uint256) {
if (msg.value == 0) revert Fiat24CryptoDeposit__ValueZero();
_validateDepositToAccountParams(_targetAccount, _outputToken);
uint256 amountIn = msg.value - nativeFee;
uint256 usdcAmount = _swapToUsdc(weth, amountIn, _amountOutMinimum, true);
_processDepositToAccountLayerZero(_targetAccount, address(0), amountIn, usdcAmount, _outputToken, nativeFee);
emit SentDepositedEth(_targetAccount, weth, _outputToken, amountIn, usdcAmount);
emit DepositToAccount(_msgSender(),_targetAccount, weth, amountIn);
return usdcAmount;
}
// Deposit token to another account owned by the sender
function depositTokenViaUsdcToAccount(address _targetAccount, address _inputToken, address _outputToken, uint256 _amount, uint256 _amountOutMinimum) nonReentrant payable external returns (uint256) {
if (_amount == 0 || msg.value == 0) revert Fiat24CryptoDeposit__ValueZero();
_validateDepositToAccountParams(_targetAccount, _outputToken);
TransferHelper.safeTransferFrom(_inputToken, _msgSender(), address(this), _amount);
uint256 usdcAmount = _swapToUsdc(_inputToken, _amount, _amountOutMinimum, false);
_processDepositToAccountLayerZero(_targetAccount, _inputToken, _amount, usdcAmount, _outputToken, msg.value);
emit SentDepositedTokenViaUsd(_targetAccount, _inputToken, _outputToken, _amount, usdcAmount);
emit DepositToAccount(_msgSender(),_targetAccount, _inputToken, _amount);
return usdcAmount;
}
function permitAndDepositTokenViaUsdc(
address userAddress,
address _inputToken,
address _outputToken,
uint256 _amount,
uint256 _amountOutMinimum,
uint256 _feeAmountViaUsdc,
uint256 _deadline,
uint8 _v,
bytes32 _r,
bytes32 _s
) external nonReentrant payable returns (uint256) {
if (paused()) revert Fiat24CryptoDeposit__Paused();
if (!hasRole(CASH_OPERATOR_ROLE, _msgSender())) revert Fiat24Token__NotCashOperator(_msgSender());
if (_amount == 0) revert Fiat24CryptoDeposit__ValueZero();
if (!validXXX24Tokens[_outputToken]) revert Fiat24CryptoDeposit__NotValidOutputToken(_outputToken);
try IERC20PermitUpgradeable(_inputToken).permit(
userAddress,
address(this),
_amount,
_deadline,
_v, _r, _s
) {
} catch {
emit PermitFailed(userAddress, _inputToken, _amount);
}
TransferHelper.safeTransferFrom(_inputToken, userAddress, address(this), _amount);
uint256 usdcAmount = _swapToUsdc(_inputToken, _amount, _amountOutMinimum, false);
uint256 usdcFactAmount = _processFeeAndValidation(usdcAmount, _feeAmountViaUsdc);
TransferHelper.safeTransfer(usdc, usdcDepositAddress, usdcFactAmount);
_sendLayerZeroMessage(userAddress, _inputToken, _amount, usdcFactAmount, _outputToken, msg.value, payable(msg.sender));
emit SentDepositedTokenViaUsd(userAddress, _inputToken, _outputToken, _amount, usdcFactAmount);
return usdcFactAmount;
}
/**
* @notice Quotes the gas needed to pay for the full omnichain transaction in native gas.
*/
function quoteLayerzeroFee(
uint32 _dstEid,
address _userAddress,
address _inputToken,
uint256 _inputAmount,
uint256 _usdcAmount,
address _outputToken
) public view returns (MessagingFee memory fee) {
bytes memory payload = abi.encode(
_userAddress,
_inputToken,
_inputAmount,
_usdcAmount,
_outputToken
);
bytes memory defaultWorkerOptions = OptionsBuilder
.newOptions()
.addExecutorLzReceiveOption(relay_gas_limit, 0);
fee = _quote(_dstEid, payload, defaultWorkerOptions, false);
}
function getQuote(address _inputToken, address _outputToken, uint24 _fee, uint256 _amount) public returns (uint256) {
return IQuoter(UNISWAP_QUOTER).quoteExactInputSingle(_inputToken, _outputToken, _fee, _amount, 0);
}
function getPoolFeeOfMostLiquidPool(address _inputToken, address _outputToken) public view returns (uint24) {
uint24 feeOfMostLiquidPool = 0;
uint128 highestLiquidity = 0;
uint128 liquidity;
IUniswapV3Pool pool;
address poolAddress = IUniswapV3Factory(UNISWAP_FACTORY).getPool(_inputToken, _outputToken, 100);
if (poolAddress != address(0)) {
pool = IUniswapV3Pool(poolAddress);
liquidity = pool.liquidity();
if (liquidity > highestLiquidity) {
highestLiquidity = liquidity;
feeOfMostLiquidPool = 100;
}
}
poolAddress = IUniswapV3Factory(UNISWAP_FACTORY).getPool(_inputToken, _outputToken, 500);
if (poolAddress != address(0)) {
pool = IUniswapV3Pool(poolAddress);
liquidity = pool.liquidity();
if (liquidity > highestLiquidity) {
highestLiquidity = liquidity;
feeOfMostLiquidPool = 500;
}
}
poolAddress = IUniswapV3Factory(UNISWAP_FACTORY).getPool(_inputToken, _outputToken, 3000);
if (poolAddress != address(0)) {
pool = IUniswapV3Pool(poolAddress);
liquidity = pool.liquidity();
if (liquidity > highestLiquidity) {
highestLiquidity = liquidity;
feeOfMostLiquidPool = 3000;
}
}
poolAddress = IUniswapV3Factory(UNISWAP_FACTORY).getPool(_inputToken, _outputToken, 10000);
if (poolAddress != address(0)) {
pool = IUniswapV3Pool(poolAddress);
liquidity = pool.liquidity();
if (liquidity > highestLiquidity) {
highestLiquidity = liquidity;
feeOfMostLiquidPool = 10000;
}
}
return feeOfMostLiquidPool;
}
function withdrawETH(address payable to, uint256 amount) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(to != address(0), "Invalid recipient");
require(address(this).balance >= amount, "Insufficient ETH balance");
(bool success, ) = to.call{value: amount}("");
require(success, "ETH withdrawal failed");
}
function changeMaxUsdcDepositAmount(uint256 _maxUsdcDepositAmount) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
maxUsdcDepositAmount = _maxUsdcDepositAmount;
}
function changeMinUsdcDepositAmount(uint256 _minUsdcDepositAmount) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
minUsdcDepositAmount = _minUsdcDepositAmount;
}
function changeUsdcAddress(address _usdcAddress) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_usdcAddress != address(0), "Invalid usdc address");
usdc = _usdcAddress;
}
function changeUsdcDepositAddress(address _usdcDepositAddress) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
address oldUsdcDepositAddress = usdcDepositAddress;
usdcDepositAddress = _usdcDepositAddress;
emit UsdcDepositAddressChanged(oldUsdcDepositAddress, usdcDepositAddress);
}
function setFeeReceiver(address _feeReceiver) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_feeReceiver != address(0), "Invalid fee receiver address");
address oldFeeReceiver = feeReceiver;
feeReceiver = _feeReceiver;
emit FeeReceiverChanged(oldFeeReceiver, feeReceiver);
}
function setRelayGasLimit(uint128 _newLimit) external {
require(_newLimit > 0, "Gas limit must be positive");
if (!hasRole(OPERATOR_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperator(_msgSender());
relay_gas_limit = _newLimit;
}
/// @notice Add or remove aggregator from whitelist
/// @param _aggregator The aggregator contract address
/// @param _isWhitelisted True to whitelist, false to remove
/// @dev Only OPERATOR_ADMIN_ROLE can manage aggregator whitelist
function setAggregatorWhitelist(address _aggregator, bool _isWhitelisted) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_aggregator != address(0), "Invalid aggregator address");
whitelistedAggregators[_aggregator] = _isWhitelisted;
emit AggregatorWhitelistUpdated(_aggregator, _isWhitelisted);
}
/// @notice Add or remove function selector for a specific aggregator
/// @param _aggregator The aggregator contract address
/// @param _selector The function selector (first 4 bytes of function signature)
/// @param _isWhitelisted True to whitelist, false to remove
function setFunctionSelector(address _aggregator, bytes4 _selector, bool _isWhitelisted) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_aggregator != address(0), "Invalid aggregator address");
require(_selector != bytes4(0), "Invalid selector");
whitelistedSelectors[_aggregator][_selector] = _isWhitelisted;
emit FunctionSelectorWhitelisted(_aggregator, _selector, _isWhitelisted);
}
function _lzReceive(
Origin calldata /*_origin*/,
bytes32 /*_guid*/,
bytes calldata /*payload*/,
address /*_executor*/,
bytes calldata /*_extraData*/
) internal override {
}
function pause() external {
if (!(hasRole(PAUSE_ROLE, _msgSender()))) revert Fiat24CryptoDeposit__NotPauser(_msgSender());
_pause();
}
function unpause() external {
if (!(hasRole(UNPAUSE_ROLE, _msgSender()))) revert Fiat24CryptoDeposit__NotUnpauser(_msgSender());
_unpause();
}
function _payNative(uint256 _nativeFee) internal virtual override returns (uint256 nativeFee) {
return _nativeFee;
}
/// @notice Internal function to swap tokens to USDC via Uniswap
/// @param _inputToken The input token address (WETH for ETH swaps, ERC20 address for token swaps)
/// @param _amount The input token amount
/// @param _amountOutMinimum The minimum USDC amount expected
/// @param _isETH True if swapping ETH, false for ERC20 tokens
/// @return usdcAmount The actual USDC amount received
function _swapToUsdc(
address _inputToken,
uint256 _amount,
uint256 _amountOutMinimum,
bool _isETH
) internal returns (uint256 usdcAmount) {
// If input is USDC, return as is
if (_inputToken == usdc) {
return _amount;
}
uint24 poolFee = getPoolFeeOfMostLiquidPool(_inputToken, usdc);
if (poolFee == 0) revert Fiat24CryptoDeposit__NoPoolAvailable(_inputToken, usdc);
if (!_isETH) {
TransferHelper.safeApprove(_inputToken, UNISWAP_ROUTER, _amount);
}
// Setup swap parameters
ISwapRouter.ExactInputSingleParams memory params = ISwapRouter.ExactInputSingleParams({
tokenIn: _inputToken,
tokenOut: usdc,
fee: poolFee,
recipient: address(this),
deadline: block.timestamp + 15,
amountIn: _amount,
amountOutMinimum: _amountOutMinimum,
sqrtPriceLimitX96: 0
});
// Execute swap
if (_isETH) {
usdcAmount = ISwapRouter(UNISWAP_ROUTER).exactInputSingle{value: _amount}(params);
if (usdcAmount == 0) revert Fiat24CryptoDeposit__SwapOutputAmountZero();
// Refund excess ETH
uint256 beforeBalance = address(this).balance;
IPeripheryPaymentsWithFee(UNISWAP_PERIPHERY_PAYMENTS).refundETH();
uint256 refundAmount = address(this).balance - beforeBalance;
if (refundAmount > 0) {
(bool success, ) = msg.sender.call{value: refundAmount}("");
if (!success) revert Fiat24CryptoDeposit__EthRefundFailed();
}
} else {
usdcAmount = ISwapRouter(UNISWAP_ROUTER).exactInputSingle(params);
if (usdcAmount == 0) revert Fiat24CryptoDeposit__SwapOutputAmountZero();
}
return usdcAmount;
}
/// @notice Internal function to send LayerZero message
/// @param _recipient The recipient address (user or target account)
/// @param _inputToken The input token address
/// @param _inputAmount The input token amount
/// @param _usdcAmount The USDC amount
/// @param _outputToken The output token address
/// @param _nativeFee The native fee for LayerZero
/// @param _refundAddress The address to refund excess fees
function _sendLayerZeroMessage(
address _recipient,
address _inputToken,
uint256 _inputAmount,
uint256 _usdcAmount,
address _outputToken,
uint256 _nativeFee,
address payable _refundAddress
) internal {
bytes memory payload = abi.encode(
_recipient,
_inputToken,
_inputAmount,
_usdcAmount,
_outputToken
);
bytes memory options = OptionsBuilder
.newOptions()
.addExecutorLzReceiveOption(relay_gas_limit, 0);
MessagingFee memory fee = MessagingFee({
nativeFee: _nativeFee,
lzTokenFee: 0
});
_lzSend(dstId, payload, options, fee, _refundAddress);
}
/// @notice Internal function to swap tokens via aggregator
/// @param _inputToken The input token address (address(0) for ETH)
/// @param _amount The input token amount
/// @param _aggregator The aggregator contract address
/// @param _swapCalldata The swap calldata
/// @param _minUsdcAmount The minimum USDC amount expected
/// @return usdcAmount The actual USDC amount received
function _swapViaAggregator(
address _inputToken,
uint256 _amount,
address _aggregator,
bytes calldata _swapCalldata,
uint256 _minUsdcAmount
) internal returns (uint256 usdcAmount) {
if (_inputToken == usdc) {
return _amount;
}
// Validate aggregator and function selector
if (!whitelistedAggregators[_aggregator]) revert Fiat24CryptoDeposit__NotWhitelistedAggregator(_aggregator);
if (_swapCalldata.length < 4) revert Fiat24CryptoDeposit__InvalidCalldata();
bytes4 selector = bytes4(_swapCalldata[0:4]);
if (!whitelistedSelectors[_aggregator][selector]) revert Fiat24CryptoDeposit__FunctionNotWhitelisted(selector);
uint256 usdcBalanceBefore = IERC20Upgradeable(usdc).balanceOf(address(this));
if (_inputToken == address(0) || _inputToken == 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) {
(bool success, ) = _aggregator.call{value: _amount}(_swapCalldata);
if (!success) revert Fiat24CryptoDeposit__AggregatorSwapFailed();
} else {
// For ERC20 tokens, approve and call
TransferHelper.safeApprove(_inputToken, _aggregator, _amount);
(bool success, ) = _aggregator.call(_swapCalldata);
if (!success) revert Fiat24CryptoDeposit__AggregatorSwapFailed();
TransferHelper.safeApprove(_inputToken, _aggregator, 0);
}
uint256 usdcBalanceAfter = IERC20Upgradeable(usdc).balanceOf(address(this));
usdcAmount = usdcBalanceAfter - usdcBalanceBefore;
// Validate user-specified minimum amount
if (usdcAmount < _minUsdcAmount) revert Fiat24CryptoDeposit__SlippageExceeded(usdcAmount, _minUsdcAmount);
return usdcAmount;
}
/// @notice Internal function to process fee and validate deposit amounts
/// @param _usdcAmount The total USDC amount before fee
/// @param _feeAmountViaUsdc The fee amount to charge
/// @return usdcFactAmount The final USDC amount after fee deduction
function _processFeeAndValidation(
uint256 _usdcAmount,
uint256 _feeAmountViaUsdc
) internal returns (uint256 usdcFactAmount) {
if (_feeAmountViaUsdc >= MAX_FEE_AMOUNT_USDC) {
_feeAmountViaUsdc = MAX_FEE_AMOUNT_USDC;
}
if (_feeAmountViaUsdc >= _usdcAmount) {
revert Fiat24CryptoDeposit__FeeAmountExceedsOutput(_feeAmountViaUsdc, _usdcAmount);
}
usdcFactAmount = _usdcAmount - _feeAmountViaUsdc;
if (usdcFactAmount > maxUsdcDepositAmount) {
revert Fiat24CryptoDeposit__UsdcAmountHigherMaxDepositAmount(usdcFactAmount, maxUsdcDepositAmount);
}
if (usdcFactAmount < minUsdcDepositAmount) {
revert Fiat24CryptoDeposit__UsdcAmountLowerMinDepositAmount(usdcFactAmount, minUsdcDepositAmount);
}
// Transfer fee to feeReceiver if > 0
if (_feeAmountViaUsdc > 0) {
TransferHelper.safeTransfer(usdc, feeReceiver, _feeAmountViaUsdc);
}
return usdcFactAmount;
}
// Internal function to validate common parameters for deposit to account
function _validateDepositToAccountParams(address _targetAccount, address _outputToken) internal view {
if (paused()) revert Fiat24CryptoDeposit__Paused();
if (_targetAccount == address(0)) revert Fiat24CryptoDeposit__ValueZero();
if (!validXXX24Tokens[_outputToken]) revert Fiat24CryptoDeposit__NotValidOutputToken(_outputToken);
}
// Internal function to process LayerZero sending for deposit to account
function _processDepositToAccountLayerZero(
address _targetAccount,
address _inputToken,
uint256 _inputAmount,
uint256 _usdcAmount,
address _outputToken,
uint256 _nativeFee
) internal {
if (_usdcAmount > maxUsdcDepositAmount) revert Fiat24CryptoDeposit__UsdcAmountHigherMaxDepositAmount(_usdcAmount, maxUsdcDepositAmount);
if (_usdcAmount < minUsdcDepositAmount) revert Fiat24CryptoDeposit__UsdcAmountLowerMinDepositAmount(_usdcAmount, minUsdcDepositAmount);
// Transfer USDC to the designated deposit address
TransferHelper.safeTransfer(usdc, usdcDepositAddress, _usdcAmount);
_sendLayerZeroMessage(_targetAccount, _inputToken, _inputAmount, _usdcAmount, _outputToken, _nativeFee, payable(msg.sender));
}
/// @notice Add a token in validXXX24Tokens
/// @param _fiatToken The address of the Token to be added.
function addFiatToken(address _fiatToken) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_fiatToken != address(0), "Zero address");
require(!validXXX24Tokens[_fiatToken], "Already exists token");
validXXX24Tokens[_fiatToken] = true;
emit FiatTokenAdded(_fiatToken);
}
receive() external payable {}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (proxy/utils/Initializable.sol)
pragma solidity ^0.8.0;
import "../../utils/AddressUpgradeable.sol";
/**
* @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 a proxied contract can't have 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.
*
* 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 initialize the implementation contract, you can either invoke the
* initializer manually, or you can include a constructor to automatically mark it as initialized when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() initializer {}
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
*/
bool private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Modifier to protect an initializer function from being invoked twice.
*/
modifier initializer() {
// If the contract is initializing we ignore whether _initialized is set in order to support multiple
// inheritance patterns, but we only do this in the context of a constructor, because in other contexts the
// contract may have been reentered.
require(_initializing ? _isConstructor() : !_initialized, "Initializable: contract is already initialized");
bool isTopLevelCall = !_initializing;
if (isTopLevelCall) {
_initializing = true;
_initialized = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
}
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} modifier, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
function _isConstructor() private view returns (bool) {
return !AddressUpgradeable.isContract(address(this));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControlUpgradeable.sol";
import "../utils/ContextUpgradeable.sol";
import "../utils/StringsUpgradeable.sol";
import "../utils/introspection/ERC165Upgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it.
*/
abstract contract AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable {
function __AccessControl_init() internal onlyInitializing {
__Context_init_unchained();
__ERC165_init_unchained();
__AccessControl_init_unchained();
}
function __AccessControl_init_unchained() internal onlyInitializing {
}
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role, _msgSender());
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControlUpgradeable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
StringsUpgradeable.toHexString(uint160(account), 20),
" is missing role ",
StringsUpgradeable.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract PausableUpgradeable is Initializable, ContextUpgradeable {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
function __Pausable_init() internal onlyInitializing {
__Context_init_unchained();
__Pausable_init_unchained();
}
function __Pausable_init_unchained() internal onlyInitializing {
_paused = false;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
require(!paused(), "Pausable: paused");
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
require(paused(), "Pausable: not paused");
_;
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuardUpgradeable is Initializable {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
function __ReentrancyGuard_init() internal onlyInitializing {
__ReentrancyGuard_init_unchained();
}
function __ReentrancyGuard_init_unchained() internal onlyInitializing {
_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() {
// On the first call to nonReentrant, _notEntered will be true
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
_;
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20Upgradeable {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) 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 `amount` 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 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20PermitUpgradeable {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol)
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title The interface for the Uniswap V3 Factory
/// @notice The Uniswap V3 Factory facilitates creation of Uniswap V3 pools and control over the protocol fees
interface IUniswapV3Factory {
/// @notice Emitted when the owner of the factory is changed
/// @param oldOwner The owner before the owner was changed
/// @param newOwner The owner after the owner was changed
event OwnerChanged(address indexed oldOwner, address indexed newOwner);
/// @notice Emitted when a pool is created
/// @param token0 The first token of the pool by address sort order
/// @param token1 The second token of the pool by address sort order
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks
/// @param pool The address of the created pool
event PoolCreated(
address indexed token0,
address indexed token1,
uint24 indexed fee,
int24 tickSpacing,
address pool
);
/// @notice Emitted when a new fee amount is enabled for pool creation via the factory
/// @param fee The enabled fee, denominated in hundredths of a bip
/// @param tickSpacing The minimum number of ticks between initialized ticks for pools created with the given fee
event FeeAmountEnabled(uint24 indexed fee, int24 indexed tickSpacing);
/// @notice Returns the current owner of the factory
/// @dev Can be changed by the current owner via setOwner
/// @return The address of the factory owner
function owner() external view returns (address);
/// @notice Returns the tick spacing for a given fee amount, if enabled, or 0 if not enabled
/// @dev A fee amount can never be removed, so this value should be hard coded or cached in the calling context
/// @param fee The enabled fee, denominated in hundredths of a bip. Returns 0 in case of unenabled fee
/// @return The tick spacing
function feeAmountTickSpacing(uint24 fee) external view returns (int24);
/// @notice Returns the pool address for a given pair of tokens and a fee, or address 0 if it does not exist
/// @dev tokenA and tokenB may be passed in either token0/token1 or token1/token0 order
/// @param tokenA The contract address of either token0 or token1
/// @param tokenB The contract address of the other token
/// @param fee The fee collected upon every swap in the pool, denominated in hundredths of a bip
/// @return pool The pool address
function getPool(
address tokenA,
address tokenB,
uint24 fee
) external view returns (address pool);
/// @notice Creates a pool for the given two tokens and fee
/// @param tokenA One of the two tokens in the desired pool
/// @param tokenB The other of the two tokens in the desired pool
/// @param fee The desired fee for the pool
/// @dev tokenA and tokenB may be passed in either order: token0/token1 or token1/token0. tickSpacing is retrieved
/// from the fee. The call will revert if the pool already exists, the fee is invalid, or the token arguments
/// are invalid.
/// @return pool The address of the newly created pool
function createPool(
address tokenA,
address tokenB,
uint24 fee
) external returns (address pool);
/// @notice Updates the owner of the factory
/// @dev Must be called by the current owner
/// @param _owner The new owner of the factory
function setOwner(address _owner) external;
/// @notice Enables a fee amount with the given tickSpacing
/// @dev Fee amounts may never be removed once enabled
/// @param fee The fee amount to enable, denominated in hundredths of a bip (i.e. 1e-6)
/// @param tickSpacing The spacing between ticks to be enforced for all pools created with the given fee amount
function enableFeeAmount(uint24 fee, int24 tickSpacing) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
import './pool/IUniswapV3PoolImmutables.sol';
import './pool/IUniswapV3PoolState.sol';
import './pool/IUniswapV3PoolDerivedState.sol';
import './pool/IUniswapV3PoolActions.sol';
import './pool/IUniswapV3PoolOwnerActions.sol';
import './pool/IUniswapV3PoolEvents.sol';
/// @title The interface for a Uniswap V3 Pool
/// @notice A Uniswap pool facilitates swapping and automated market making between any two assets that strictly conform
/// to the ERC20 specification
/// @dev The pool interface is broken up into many smaller pieces
interface IUniswapV3Pool is
IUniswapV3PoolImmutables,
IUniswapV3PoolState,
IUniswapV3PoolDerivedState,
IUniswapV3PoolActions,
IUniswapV3PoolOwnerActions,
IUniswapV3PoolEvents
{
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
import '@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol';
/// @title Router token swapping functionality
/// @notice Functions for swapping tokens via Uniswap V3
interface ISwapRouter is IUniswapV3SwapCallback {
struct ExactInputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another token
/// @param params The parameters necessary for the swap, encoded as `ExactInputSingleParams` in calldata
/// @return amountOut The amount of the received token
function exactInputSingle(ExactInputSingleParams calldata params) external payable returns (uint256 amountOut);
struct ExactInputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountIn;
uint256 amountOutMinimum;
}
/// @notice Swaps `amountIn` of one token for as much as possible of another along the specified path
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactInputParams` in calldata
/// @return amountOut The amount of the received token
function exactInput(ExactInputParams calldata params) external payable returns (uint256 amountOut);
struct ExactOutputSingleParams {
address tokenIn;
address tokenOut;
uint24 fee;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
uint160 sqrtPriceLimitX96;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another token
/// @param params The parameters necessary for the swap, encoded as `ExactOutputSingleParams` in calldata
/// @return amountIn The amount of the input token
function exactOutputSingle(ExactOutputSingleParams calldata params) external payable returns (uint256 amountIn);
struct ExactOutputParams {
bytes path;
address recipient;
uint256 deadline;
uint256 amountOut;
uint256 amountInMaximum;
}
/// @notice Swaps as little as possible of one token for `amountOut` of another along the specified path (reversed)
/// @param params The parameters necessary for the multi-hop swap, encoded as `ExactOutputParams` in calldata
/// @return amountIn The amount of the input token
function exactOutput(ExactOutputParams calldata params) external payable returns (uint256 amountIn);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
import './IPeripheryPayments.sol';
/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPaymentsWithFee is IPeripheryPayments {
/// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH, with a percentage between
/// 0 (exclusive), and 1 (inclusive) going to feeRecipient
/// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
function unwrapWETH9WithFee(
uint256 amountMinimum,
address recipient,
uint256 feeBips,
address feeRecipient
) external payable;
/// @notice Transfers the full amount of a token held by this contract to recipient, with a percentage between
/// 0 (exclusive) and 1 (inclusive) going to feeRecipient
/// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
function sweepTokenWithFee(
address token,
uint256 amountMinimum,
address recipient,
uint256 feeBips,
address feeRecipient
) external payable;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
pragma abicoder v2;
/// @title Quoter Interface
/// @notice Supports quoting the calculated amounts from exact input or exact output swaps
/// @dev These functions are not marked view because they rely on calling non-view functions and reverting
/// to compute the result. They are also not gas efficient and should not be called on-chain.
interface IQuoter {
/// @notice Returns the amount out received for a given exact input swap without executing the swap
/// @param path The path of the swap, i.e. each token pair and the pool fee
/// @param amountIn The amount of the first token to swap
/// @return amountOut The amount of the last token that would be received
function quoteExactInput(bytes memory path, uint256 amountIn) external returns (uint256 amountOut);
/// @notice Returns the amount out received for a given exact input but for a swap of a single pool
/// @param tokenIn The token being swapped in
/// @param tokenOut The token being swapped out
/// @param fee The fee of the token pool to consider for the pair
/// @param amountIn The desired input amount
/// @param sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
/// @return amountOut The amount of `tokenOut` that would be received
function quoteExactInputSingle(
address tokenIn,
address tokenOut,
uint24 fee,
uint256 amountIn,
uint160 sqrtPriceLimitX96
) external returns (uint256 amountOut);
/// @notice Returns the amount in required for a given exact output swap without executing the swap
/// @param path The path of the swap, i.e. each token pair and the pool fee. Path must be provided in reverse order
/// @param amountOut The amount of the last token to receive
/// @return amountIn The amount of first token required to be paid
function quoteExactOutput(bytes memory path, uint256 amountOut) external returns (uint256 amountIn);
/// @notice Returns the amount in required to receive the given exact output amount but for a swap of a single pool
/// @param tokenIn The token being swapped in
/// @param tokenOut The token being swapped out
/// @param fee The fee of the token pool to consider for the pair
/// @param amountOut The desired output amount
/// @param sqrtPriceLimitX96 The price limit of the pool that cannot be exceeded by the swap
/// @return amountIn The amount required as the input for the swap in order to receive `amountOut`
function quoteExactOutputSingle(
address tokenIn,
address tokenOut,
uint24 fee,
uint256 amountOut,
uint160 sqrtPriceLimitX96
) external returns (uint256 amountIn);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.6.0;
import '@openzeppelin/contracts/token/ERC20/IERC20.sol';
library TransferHelper {
/// @notice Transfers tokens from the targeted address to the given destination
/// @notice Errors with 'STF' if transfer fails
/// @param token The contract address of the token to be transferred
/// @param from The originating address from which the tokens will be transferred
/// @param to The destination address of the transfer
/// @param value The amount to be transferred
function safeTransferFrom(
address token,
address from,
address to,
uint256 value
) internal {
(bool success, bytes memory data) =
token.call(abi.encodeWithSelector(IERC20.transferFrom.selector, from, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'STF');
}
/// @notice Transfers tokens from msg.sender to a recipient
/// @dev Errors with ST if transfer fails
/// @param token The contract address of the token which will be transferred
/// @param to The recipient of the transfer
/// @param value The value of the transfer
function safeTransfer(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.transfer.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'ST');
}
/// @notice Approves the stipulated contract to spend the given allowance in the given token
/// @dev Errors with 'SA' if transfer fails
/// @param token The contract address of the token to be approved
/// @param to The target of the approval
/// @param value The amount of the given token the target will be allowed to spend
function safeApprove(
address token,
address to,
uint256 value
) internal {
(bool success, bytes memory data) = token.call(abi.encodeWithSelector(IERC20.approve.selector, to, value));
require(success && (data.length == 0 || abi.decode(data, (bool))), 'SA');
}
/// @notice Transfers ETH to the recipient address
/// @dev Fails with `STE`
/// @param to The destination of the transfer
/// @param value The value to be transferred
function safeTransferETH(address to, uint256 value) internal {
(bool success, ) = to.call{value: value}(new bytes(0));
require(success, 'STE');
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface ICrossChainMessenger {
function sendMessage(address target, bytes memory message) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
interface IFiat24CryptoDeposit {
error Fiat24CryptoDeposit__NotOperator(address sender);
error Fiat24CryptoDeposit__NotOperatorAdmin(address sender);
error Fiat24CryptoDeposit__NotDefaultAdmin(address sender);
error Fiat24CryptoDeposit__NotRateUpdater(address sender);
error Fiat24CryptoDeposit__Paused();
error Fiat24CryptoDeposit__NotValidOutputToken(address token);
error Fiat24CryptoDeposit__AmountLessThanMinimum(uint256 outputAmount);
error Fiat24CryptoDeposit__AmountGreaterThanMaximum(uint256 inputAmount);
error Fiat24CryptoDeposit__NotValidInputToken(address token);
error Fiat24CryptoDeposit__InputTokenOutputTokenSame(address inputToken, address outputToken);
error Fiat24CryptoDeposit__AddressHasNoToken(address sender);
error Fiat24CryptoDeposit__ValueZero();
error Fiat24CryptoDeposit__EthRefundFailed();
error Fiat24CryptoDeposit__MNTRefundFailed();
error Fiat24CryptoDeposit__SwapOutputAmountZero();
error Fiat24CryptoDeposit__UsdcAmountHigherMaxDepositAmount(uint256 usdcAmount, uint256 maxAmount);
error Fiat24CryptoDeposit__UsdcAmountLowerMinDepositAmount(uint256 usdcAmount, uint256 minAmount);
error Fiat24CryptoDeposit__NoPoolAvailable(address tokenA, address tokenB);
error Fiat24CryptoDeposit__ExchangeRateNotAvailable(address inputToken, address outputToken);
error Fiat24CryptoDeposit__NotTokensWalletProvider(address sender, uint256 tokenId);
error Fiat24CryptoDeposit__NotPauser(address sender);
error Fiat24CryptoDeposit__NotUnpauser(address sender);
error Fiat24CryptoExchange__UsdAmountLowerMinAmount(uint256 usdAmount);
error Fiat24Token__NotCashOperator(address caller);
error Fiat24CryptoDeposit__FeeAmountExceedsOutput(uint256 _feeAmountViaUsdc, uint256 usdcAmount);
error Fiat24CryptoDeposit__NotWhitelistedAggregator(address aggregator);
error Fiat24CryptoDeposit__AggregatorSwapFailed();
error Fiat24CryptoDeposit__SlippageExceeded(uint256 actualAmount, uint256 minAcceptableAmount);
error Fiat24CryptoDeposit__InvalidCalldata();
error Fiat24CryptoDeposit__FunctionNotWhitelisted(bytes4 selector);
event ExchangeRatesUpdatedByOperator(address indexed sender, uint256 usdeur, uint256 usdchf, uint256 usdgbp, uint256 usdcnh, bool marketClosed);
event ExchangeRatesUpdatedByRobot(address indexed sender, uint256 usdeur, uint256 usdchf, uint256 usdgbp, uint256 usdcnh, bool marketClosed);
event SentDepositedEth(address indexed sender, address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount);
event DepositedFiat24Token(address indexed sender, address inputToken, uint256 inputAmount, address outputToken, uint256 outputAmount);
event DepositToAccount(address indexed sender, address indexed targetAddress, address inputToken, uint256 inputAmount);
event MessageProcessed(uint32 indexed srcEid, bytes32 indexed messageId);
event FailedMessageProcessed(bytes32 indexed messageId);
event SentDepositedTokenViaUsd(address indexed sender, address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount);
event DepositedTokenViaUsd(address indexed sender, address inputToken, address outputToken, uint256 inputAmount, uint256 factAmount, uint256 outputAmount);
event SentDepositedTokenViaEth(address indexed sender, address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount);
event DepositedByWallet(
uint256 indexed tokenId, address indexed clientAddress, uint256 indexed walletId, address walletAddress, address outputToken, uint256 usdcAmount
);
event MoneyExchangedExactIn(address indexed sender, address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount);
event MoneyExchangedExactOut(address indexed sender, address inputToken, address outputToken, uint256 inputAmount, uint256 outputAmount);
event UsdcDepositAddressChanged(address oldAddress, address newAddress);
event FixedNativeFeeUpdated(uint256 oldFee, uint256 newFee);
event RefundSent(uint32 indexed srcEid, bytes32 indexed srcOApp, string reason);
event RefundRetried(bytes32 indexed messageId);
event RefundProcessed(address indexed user, uint256 indexed usdcAmount);
event RefundProcessFailed(bytes32 indexed messageId, address user, uint256 usdcAmount);
event PermitFailed(address indexed owner, address indexed spender, uint256 value);
event ExchangeRateUpdatedByOperator(address indexed fiatToken, uint256 oldRate, uint256 newRate, bool _isMarketClosed);
event ExchangeRateUpdatedByRobot(address indexed fiatToken, uint256 oldRate, uint256 newRate, bool _isMarketClosed);
event FiatTokenAndRateAdded(address indexed fiatToken, uint256 indexed rateUsdcToFiat);
event FiatTokenAdded(address indexed fiatToken);
event MessageFailed(bytes32 indexed messageId, string reason);
event MessageRetried(bytes32 indexed messageId, bool success, string reason);
event CrossChainMessage(address user, address inputToken, uint256 inputAmount, uint256 usdcAmount, address outputToken);
event SwapExecuted(address indexed user, address indexed tokenIn, address indexed tokenOut, uint256 amountIn, uint256 amountOut);
struct FailedRefund {
address user;
uint256 usdcAmount;
address outputToken;
uint256 retryCount;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/utils/math/SafeMathUpgradeable.sol";
library DigitsOfUint {
using SafeMathUpgradeable for uint256;
function numDigits(uint256 _number) internal pure returns (uint256) {
uint256 number = _number;
uint256 digits = 0;
while (number != 0) {
number = number.div(10);
digits = digits.add(1);
}
return digits;
}
function hasFirstDigit(uint256 _accountId, uint256 _firstDigit) internal pure returns (bool) {
uint256 number = _accountId;
while (number >= 10) {
number = number.div(10);
}
return number == _firstDigit;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@uniswap/v3-periphery/contracts/libraries/TransferHelper.sol";
import "./interfaces/IFiat24CryptoDeposit.sol";
import "./interfaces/IFiat24Account.sol";
import "./libraries/DigitsOfUint.sol";
import "@layerzerolabs/oapp-evm-upgradeable/contracts/oapp/OAppUpgradeable.sol";
import "@layerzerolabs/oapp-evm/contracts/oapp/libs/OptionsBuilder.sol";
import { Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppOptionsType3Upgradeable } from "@layerzerolabs/oapp-evm-upgradeable/contracts/oapp/libs/OAppOptionsType3Upgradeable.sol";
contract Fiat24CryptoRelay is OAppUpgradeable,OAppOptionsType3Upgradeable, AccessControlUpgradeable, ReentrancyGuardUpgradeable, PausableUpgradeable, IFiat24CryptoDeposit {
using SafeMath for uint256;
using DigitsOfUint for uint256;
using OptionsBuilder for bytes;
bytes32 public constant OPERATOR_ROLE = keccak256("OPERATOR_ROLE");
bytes32 public constant OPERATOR_ADMIN_ROLE = keccak256("OPERATOR_ADMIN_ROLE");
bytes32 public constant CASH_OPERATOR_ROLE = keccak256("CASH_OPERATOR_ROLE");
bytes32 public constant AUTHORIZED_SENDER_ROLE = keccak256("AUTHORIZED_SENDER_ROLE");
bytes32 public constant RATES_UPDATER_OPERATOR_ROLE = keccak256("RATES_UPDATER_OPERATOR_ROLE");
bytes32 public constant RATES_UPDATER_ROBOT_ROLE = keccak256("RATES_UPDATER_ROBOT_ROLE");
bytes32 public constant PAUSE_ROLE = keccak256("PAUSE_ROLE");
bytes32 public constant UNPAUSE_ROLE = keccak256("UNPAUSE_ROLE");
uint256 public constant USDC_DIVISOR = 10000;
uint256 public constant XXX24_DIVISOR = 10000;
uint256 public constant CRYPTO_DESK = 9105; // topup subsidiary account
uint256 public constant TREASURY_DESK = 9100;
uint256 public constant FEE_DESK = 9203;
mapping(address => bool) public validXXX24Tokens;
mapping(address => mapping(address => uint256)) public exchangeRates;
mapping(uint256 => uint256) public fees;
uint256 public constant MAX_DIGITS = 5;
uint256 public fixedNativeFee;
bool public marketClosed;
uint256 public exchangeSpread;
uint256 public marketClosedSpread;
uint128 public RELAY_GAS_LIMIT;
uint256 public standardFee;
address public fiat24account;
address public usd24;
address public eur24;
address public chf24;
address public gbp24;
address public usdc;
address public cnh24;
uint256 public minUsdExchangeAmount;
mapping(bytes32 => bytes) private _failedPayloads;
bytes32[] public failedKeys;
address[] public fiatTokens;
// The mapping value should be written as idx+1
mapping(bytes32 => uint256) private _failedKeyIndex;
constructor(address _endpoint) OAppUpgradeable(_endpoint) {}
function initialize(
address admin,
address _delegate,
address _fiat24account,
address _usd24,
address _eur24,
address _chf24,
address _gbp24,
address _cnh24,
address _usdc
) public initializer {
require(admin != address(0), "admin is zero");
require(_delegate != address(0), "delegate is zero");
require(_fiat24account != address(0), "fiat24account is zero");
require(_usd24 != address(0), "usd24 is zero");
require(_eur24 != address(0), "eur24 is zero");
require(_chf24 != address(0), "chf24 is zero");
require(_gbp24 != address(0), "gbp24 is zero");
require(_cnh24 != address(0), "cnh24 is zero");
require(_usdc != address(0), "usdc is zero");
__AccessControl_init_unchained();
__ReentrancyGuard_init();
__Pausable_init_unchained();
__OApp_init(_delegate);
__Ownable_init();
_setupRole(DEFAULT_ADMIN_ROLE, admin);
_setupRole(OPERATOR_ADMIN_ROLE, admin);
_setupRole(OPERATOR_ROLE, admin);
_transferOwnership(admin);
fiat24account = _fiat24account;
usd24 = _usd24;
eur24 = _eur24;
chf24 = _chf24;
gbp24 = _gbp24;
cnh24 = _cnh24;
usdc = _usdc;
standardFee = 50;
validXXX24Tokens[_usd24] = true;
validXXX24Tokens[_eur24] = true;
validXXX24Tokens[_chf24] = true;
validXXX24Tokens[_gbp24] = true;
validXXX24Tokens[_cnh24] = true;
exchangeRates[usdc][usd24] = 10000;
exchangeRates[usd24][usd24] = 10000;
exchangeRates[usd24][eur24] = 8800;
exchangeRates[usd24][chf24] = 8300;
exchangeRates[usd24][gbp24] = 7500;
exchangeRates[usd24][_cnh24] = 72420;
marketClosed = false;
exchangeSpread = 9900;
marketClosedSpread = 9995;
fixedNativeFee = 1 ether;
minUsdExchangeAmount = 5000000;
RELAY_GAS_LIMIT = 500000;
}
// @dev Internal function override to handle incoming messages from another chain.
// @param payload The encoded message payload being received.
function _lzReceive(
Origin calldata _origin,
bytes32 _guid,
bytes calldata payload,
address /* _executor */,
bytes calldata /* _extraData */
) internal override {
try this.processMessage(payload) {
emit MessageProcessed(_origin.srcEid, _guid);
} catch Error(string memory reason) {
_storeFailedMessage(_guid, payload, reason);
} catch {
_storeFailedMessage(_guid, payload, "Unknown failure");
}
}
function processMessage(bytes calldata payload) nonReentrant external {
if (paused()) revert Fiat24CryptoDeposit__Paused();
require(msg.sender == address(this), "Only internal calls");
(address user, address inputToken, uint256 inputAmount, uint256 usdcAmount, address outputToken) =
abi.decode(payload, (address, address, uint256, uint256, address));
require(user != address(0), "Invalid user");
require(usdcAmount > 0, "Invalid amount");
require(validXXX24Tokens[outputToken], "Invalid token");
uint256 tokenId = IFiat24Account(fiat24account).historicOwnership(user);
if (tokenId == 0) revert Fiat24CryptoDeposit__AddressHasNoToken(user);
uint256 walletId = IFiat24Account(fiat24account).walletProvider(tokenId);
bool walletIdExists = IFiat24Account(fiat24account).exists(walletId);
uint256 feeInUSDC = getFee(tokenId, usdcAmount);
if (walletId == 0 || !walletIdExists) {
TransferHelper.safeTransferFrom(
usd24,
IFiat24Account(fiat24account).ownerOf(CRYPTO_DESK),
IFiat24Account(fiat24account).ownerOf(FEE_DESK),
feeInUSDC / USDC_DIVISOR
);
} else {
TransferHelper.safeTransferFrom(
usd24,
IFiat24Account(fiat24account).ownerOf(CRYPTO_DESK),
IFiat24Account(fiat24account).ownerOf(walletId),
feeInUSDC / USDC_DIVISOR
);
}
uint256 outputAmount = (usdcAmount - feeInUSDC)
.div(USDC_DIVISOR)
.mul(exchangeRates[usdc][usd24])
.div(XXX24_DIVISOR);
outputAmount = outputAmount
.mul(getExchangeRate(usd24, outputToken))
.div(XXX24_DIVISOR)
.mul(getSpread(usd24, outputToken, false))
.div(XXX24_DIVISOR);
TransferHelper.safeTransferFrom(
outputToken,
IFiat24Account(fiat24account).ownerOf(CRYPTO_DESK),
user,
outputAmount
);
emit CrossChainMessage(user, inputToken, inputAmount, usdcAmount, outputToken);
emit DepositedFiat24Token(user, inputToken, inputAmount, outputToken, outputAmount);
}
function _storeFailedMessage(bytes32 messageId, bytes calldata payload, string memory reason) internal {
if (_failedPayloads[messageId].length == 0) {
if (payload.length == 0) {
emit MessageFailed(messageId, "payload length == 0");
} else {
_failedPayloads[messageId] = payload;
failedKeys.push(messageId);
_failedKeyIndex[messageId] = failedKeys.length;
emit MessageFailed(messageId, reason);
}
} else {
emit MessageFailed(messageId, "Repeated insertion of data");
}
}
/// @notice Retry a previously failed cross-chain message
/// @param messageId The unique identifier 'guid' of the failed message to retry
function retryFailedMessage(bytes32 messageId) external {
if (!hasRole(OPERATOR_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperator(_msgSender());
bytes memory payload = _failedPayloads[messageId];
require(payload.length > 0, "No failed message to retry");
delete _failedPayloads[messageId];
this.processMessage(payload);
_removeFailedKey(messageId);
emit MessageRetried(messageId, true, "");
}
/// @notice Returns a list of messageIds for all failed messages
function getFailedKeys() external view returns (bytes32[] memory) {
return failedKeys;
}
/// @notice Manually clear a failed message without retrying its processing
/// @param messageId The unique identifier 'guid' of the failed message to retry
function adminProcessFailedMessage(bytes32 messageId) external {
if (!hasRole(OPERATOR_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperator(_msgSender());
bytes memory payload = _failedPayloads[messageId];
require(payload.length > 0, "No failed message to retry");
delete _failedPayloads[messageId];
_removeFailedKey(messageId);
emit FailedMessageProcessed(messageId);
}
function moneyExchangeExactIn(address _inputToken, address _outputToken, uint256 _inputAmount, uint256 _amountOutMinimum) nonReentrant external returns (uint256) {
if (paused()) revert Fiat24CryptoDeposit__Paused();
if (!validXXX24Tokens[_inputToken]) revert Fiat24CryptoDeposit__NotValidInputToken(_inputToken);
if (!validXXX24Tokens[_outputToken]) revert Fiat24CryptoDeposit__NotValidOutputToken(_outputToken);
if (_inputToken == _outputToken) revert Fiat24CryptoDeposit__InputTokenOutputTokenSame(_inputToken, _outputToken);
uint256 usdAmount = _inputAmount * getExchangeRate(_inputToken, usd24) / XXX24_DIVISOR;
if (usdAmount < minUsdExchangeAmount) revert Fiat24CryptoExchange__UsdAmountLowerMinAmount(usdAmount);
TransferHelper.safeTransferFrom(_inputToken, _msgSender(), IFiat24Account(fiat24account).ownerOf(TREASURY_DESK), _inputAmount);
uint256 outputAmount =
_inputAmount * getExchangeRate(_inputToken, _outputToken) / XXX24_DIVISOR * getSpread(_inputToken, _outputToken, false) / XXX24_DIVISOR;
if(outputAmount < _amountOutMinimum) revert Fiat24CryptoDeposit__AmountLessThanMinimum(outputAmount);
TransferHelper.safeTransferFrom(_outputToken, IFiat24Account(fiat24account).ownerOf(CRYPTO_DESK), _msgSender(), outputAmount);
emit MoneyExchangedExactIn(_msgSender(), _inputToken, _outputToken, _inputAmount, outputAmount);
return outputAmount;
}
function permitAndMoneyExchangeExactIn(
address userAddress,
address _inputToken,
address _outputToken,
uint256 _inputAmount,
uint256 _amountOutMinimum,
uint256 _deadline,
uint8 _v,
bytes32 _r,
bytes32 _s
) external returns (uint256) {
if (paused()) revert Fiat24CryptoDeposit__Paused();
require(hasRole(CASH_OPERATOR_ROLE, _msgSender()), "Fiat24Token: Not a Cash Operator");
if (!validXXX24Tokens[_inputToken]) revert Fiat24CryptoDeposit__NotValidInputToken(_inputToken);
if (!validXXX24Tokens[_outputToken]) revert Fiat24CryptoDeposit__NotValidOutputToken(_outputToken);
if (_inputToken == _outputToken) revert Fiat24CryptoDeposit__InputTokenOutputTokenSame(_inputToken, _outputToken);
uint256 usdAmount = _inputAmount * getExchangeRate(_inputToken, usd24) / XXX24_DIVISOR;
if (usdAmount < minUsdExchangeAmount) revert Fiat24CryptoExchange__UsdAmountLowerMinAmount(usdAmount);
// 1) Permit
try IERC20Permit(_inputToken).permit(
userAddress,
address(this),
_inputAmount,
_deadline,
_v, _r, _s
) {} catch {
emit PermitFailed(userAddress, address(this), _inputAmount);
}
TransferHelper.safeTransferFrom(_inputToken, userAddress, IFiat24Account(fiat24account).ownerOf(TREASURY_DESK), _inputAmount);
uint256 outputAmount = _inputAmount * getExchangeRate(_inputToken, _outputToken) / XXX24_DIVISOR * getSpread(_inputToken, _outputToken, false) / XXX24_DIVISOR;
if(outputAmount < _amountOutMinimum) revert Fiat24CryptoDeposit__AmountLessThanMinimum(outputAmount);
TransferHelper.safeTransferFrom(_outputToken, IFiat24Account(fiat24account).ownerOf(CRYPTO_DESK), userAddress, outputAmount);
emit MoneyExchangedExactIn(userAddress, _inputToken, _outputToken, _inputAmount, outputAmount);
return outputAmount;
}
function updateExchangeRates(uint256 _usd_eur, uint256 _usd_chf, uint256 _usd_gbp, uint256 _usd_cnh, bool _isMarketClosed) external {
if (hasRole(RATES_UPDATER_OPERATOR_ROLE, _msgSender())) {
exchangeRates[usd24][eur24] = _usd_eur;
exchangeRates[usd24][chf24] = _usd_chf;
exchangeRates[usd24][gbp24] = _usd_gbp;
exchangeRates[usd24][cnh24] = _usd_cnh;
marketClosed = _isMarketClosed;
emit ExchangeRatesUpdatedByOperator(
_msgSender(), exchangeRates[usd24][eur24], exchangeRates[usd24][chf24], exchangeRates[usd24][gbp24], exchangeRates[usd24][cnh24], marketClosed
);
} else if ((hasRole(RATES_UPDATER_ROBOT_ROLE, _msgSender()))) {
uint256 rateDiff_usd_eur =
(exchangeRates[usd24][eur24] > _usd_eur) ? (exchangeRates[usd24][eur24] - _usd_eur) : (_usd_eur - exchangeRates[usd24][eur24]);
rateDiff_usd_eur = (rateDiff_usd_eur * XXX24_DIVISOR) / exchangeRates[usd24][eur24];
uint256 rateDiff_usd_chf =
(exchangeRates[usd24][chf24] > _usd_chf) ? (exchangeRates[usd24][chf24] - _usd_chf) : (_usd_chf - exchangeRates[usd24][chf24]);
rateDiff_usd_chf = (rateDiff_usd_chf * XXX24_DIVISOR) / exchangeRates[usd24][chf24];
uint256 rateDiff_usd_gbp =
(exchangeRates[usd24][gbp24] > _usd_gbp) ? (exchangeRates[usd24][gbp24] - _usd_gbp) : (_usd_gbp - exchangeRates[usd24][gbp24]);
rateDiff_usd_gbp = (rateDiff_usd_gbp * XXX24_DIVISOR) / exchangeRates[usd24][gbp24];
uint256 rateDiff_usd_cnh =
(exchangeRates[usd24][cnh24] > _usd_cnh) ? (exchangeRates[usd24][cnh24] - _usd_cnh) : (_usd_cnh - exchangeRates[usd24][cnh24]);
rateDiff_usd_cnh = (rateDiff_usd_cnh * XXX24_DIVISOR) / exchangeRates[usd24][cnh24];
if (rateDiff_usd_eur < 300) exchangeRates[usd24][eur24] = _usd_eur;
if (rateDiff_usd_chf < 300) exchangeRates[usd24][chf24] = _usd_chf;
if (rateDiff_usd_gbp < 300) exchangeRates[usd24][gbp24] = _usd_gbp;
if (rateDiff_usd_cnh < 300) exchangeRates[usd24][cnh24] = _usd_cnh;
marketClosed = _isMarketClosed;
emit ExchangeRatesUpdatedByRobot(
_msgSender(), exchangeRates[usd24][eur24], exchangeRates[usd24][chf24], exchangeRates[usd24][gbp24], exchangeRates[usd24][cnh24], marketClosed
);
} else {
revert Fiat24CryptoDeposit__NotRateUpdater((_msgSender()));
}
}
function updateExchangeRates(
address[] calldata fiatTokenAddresses,
uint256[] calldata rates,
bool isMarketClosed
) external {
require(
hasRole(RATES_UPDATER_OPERATOR_ROLE, _msgSender()) ||
hasRole(RATES_UPDATER_ROBOT_ROLE, _msgSender()),
"Not authorized to update rates"
);
require(fiatTokenAddresses.length == rates.length, "Arrays length mismatch");
marketClosed = isMarketClosed;
for (uint256 i = 0; i < fiatTokenAddresses.length; i++) {
address token = fiatTokenAddresses[i];
uint256 rate = rates[i];
require(validXXX24Tokens[token], "Invalid token");
require(rate > 0, "Rate must be >0");
_updateExchangeRate(token, rate, isMarketClosed);
}
}
/// @notice Updating the exchange rate between USD and individual fiat currencies
function _updateExchangeRate(address _fiatToken, uint256 _rateUsdcToFiat, bool _isMarketClosed) internal {
uint256 oldRate = exchangeRates[usd24][_fiatToken];
if (hasRole(RATES_UPDATER_OPERATOR_ROLE, _msgSender())) {
exchangeRates[usd24][_fiatToken] = _rateUsdcToFiat;
emit ExchangeRateUpdatedByOperator(_fiatToken, oldRate, _rateUsdcToFiat, _isMarketClosed);
} else if (hasRole(RATES_UPDATER_ROBOT_ROLE, _msgSender())) {
uint256 delta = oldRate > _rateUsdcToFiat ? (oldRate - _rateUsdcToFiat) : (_rateUsdcToFiat - oldRate);
uint256 rateDiff = delta * XXX24_DIVISOR / oldRate;
require(rateDiff < 300, "Rate Update Robot: change too large");
exchangeRates[usd24][_fiatToken] = _rateUsdcToFiat;
emit ExchangeRateUpdatedByRobot(_fiatToken, oldRate, _rateUsdcToFiat, _isMarketClosed);
} else {
revert Fiat24CryptoDeposit__NotRateUpdater((_msgSender()));
}
}
function getExchangeRate(address _inputToken, address _outputToken) public view returns (uint256) {
uint256 exchangeRate;
if (_inputToken == usd24 || _outputToken == usd24) {
exchangeRate =
exchangeRates[_inputToken][_outputToken] == 0 ? 10000 ** 2 / exchangeRates[_outputToken][_inputToken] : exchangeRates[_inputToken][_outputToken];
} else {
exchangeRate = (10000 ** 2 / exchangeRates[usd24][_inputToken]) * exchangeRates[usd24][_outputToken] / XXX24_DIVISOR;
}
return exchangeRate;
}
function getSpread(address _inputToken, address _outputToken, bool exactOut) public view returns (uint256) {
uint256 totalSpread = 10000;
if (!(_inputToken == usd24 && _outputToken == usd24)) {
totalSpread = marketClosed ? exchangeSpread * marketClosedSpread / 10000 : exchangeSpread;
if (exactOut) {
totalSpread = 10000 * XXX24_DIVISOR / totalSpread;
}
}
return totalSpread;
}
function getFee(uint256 _tokenId, uint256 _usdcAmount) public view returns (uint256 feeInUSDC) {
// updating
uint256 _fee = standardFee;
feeInUSDC = _usdcAmount * _fee / 10000;
}
function updateUsdcUsd24ExchangeRate(uint256 _usdc_usd24) external {
if (!hasRole(RATES_UPDATER_OPERATOR_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotRateUpdater((_msgSender()));
exchangeRates[usdc][usd24] = _usdc_usd24;
}
function changeStandardFee(uint256 _standardFee) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_standardFee >= 0 && _standardFee <= 1000, "Fee must be between 0 and 1000");
standardFee = _standardFee;
}
function changeMarketClosedSpread(uint256 _marketClosedSpread) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_marketClosedSpread >= 9000 && _marketClosedSpread <= 11000, "Spread must be between 9000 and 11000");
marketClosedSpread = _marketClosedSpread;
}
function changeExchangeSpread(uint256 _exchangeSpread) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_exchangeSpread >= 9000 && _exchangeSpread <= 11000, "Spread must be between 9000 and 11000");
exchangeSpread = _exchangeSpread;
}
function changeMinUsdExchangeAmount(uint256 _minUsdExchangeAmount) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperatorAdmin(_msgSender());
require(_minUsdExchangeAmount > 0, "Min USD exchange amount must be greater than 0");
minUsdExchangeAmount = _minUsdExchangeAmount;
}
function withdrawMNT(address payable to, uint256 amount) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperator(_msgSender());
require(to != address(0), "Invalid recipient");
require(address(this).balance >= amount, "Insufficient MNT balance");
(bool success, ) = to.call{value: amount}("");
require(success, "MNT withdrawal failed");
}
/// @notice Add a token and set the USD→fiat exchange rate.
/// @param _fiatToken The address of the Token to be added.
/// @param _rateUsdToFiat Initial exchange rate
function addFiatToken(address _fiatToken, uint256 _rateUsdToFiat) external {
if (!hasRole(OPERATOR_ADMIN_ROLE, _msgSender())) revert Fiat24CryptoDeposit__NotOperator(_msgSender());
require(_fiatToken != address(0), "Zero address");
require(!validXXX24Tokens[_fiatToken], "Already exists token");
require(_rateUsdToFiat > 0, "Rate must be >0");
validXXX24Tokens[_fiatToken] = true;
fiatTokens.push(_fiatToken);
exchangeRates[usd24][_fiatToken] = _rateUsdToFiat;
emit FiatTokenAndRateAdded(_fiatToken, _rateUsdToFiat);
}
function getFiatTokens() external view returns (address[] memory) {
return fiatTokens;
}
function _removeFailedKey(bytes32 messageId) internal {
uint256 idxPlusOne = _failedKeyIndex[messageId];
require(idxPlusOne != 0, "Error message");
// If the element to be deleted is not the last element
if (idxPlusOne!= failedKeys.length) {
bytes32 lastId = failedKeys[failedKeys.length - 1];
failedKeys[idxPlusOne - 1] = lastId;
_failedKeyIndex[lastId] = idxPlusOne;
}
failedKeys.pop();
delete _failedKeyIndex[messageId];
}
function pause() external {
if (!(hasRole(PAUSE_ROLE, _msgSender()))) revert Fiat24CryptoDeposit__NotPauser(_msgSender());
_pause();
}
function unpause() external {
if (!(hasRole(UNPAUSE_ROLE, _msgSender()))) revert Fiat24CryptoDeposit__NotUnpauser(_msgSender());
_unpause();
}
receive() external payable {}
}// 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.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.20;
// @dev Import the 'MessagingFee' and 'MessagingReceipt' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppSenderUpgradeable, MessagingFee, MessagingReceipt } from "./OAppSenderUpgradeable.sol";
// @dev Import the 'Origin' so it's exposed to OApp implementers
// solhint-disable-next-line no-unused-import
import { OAppReceiverUpgradeable, Origin } from "./OAppReceiverUpgradeable.sol";
import { OAppCoreUpgradeable } from "./OAppCoreUpgradeable.sol";
/**
* @title OApp
* @dev Abstract contract serving as the base for OApp implementation, combining OAppSender and OAppReceiver functionality.
*/
abstract contract OAppUpgradeable is OAppSenderUpgradeable, OAppReceiverUpgradeable {
/**
* @dev Constructor to initialize the OApp with the provided endpoint and owner.
* @param _endpoint The address of the LOCAL LayerZero endpoint.
*/
constructor(address _endpoint) OAppCoreUpgradeable(_endpoint) {}
/**
* @dev Initializes the OApp with the provided delegate.
* @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.
* @dev Ownable is not initialized here on purpose. It should be initialized in the child contract to
* accommodate the different version of Ownable.
*/
function __OApp_init(address _delegate) internal onlyInitializing {
__OAppCore_init(_delegate);
__OAppReceiver_init_unchained();
__OAppSender_init_unchained();
}
function __OApp_init_unchained() internal onlyInitializing {}
/**
* @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(OAppSenderUpgradeable, OAppReceiverUpgradeable)
returns (uint64 senderVersion, uint64 receiverVersion)
{
return (SENDER_VERSION, RECEIVER_VERSION);
}
}// 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
pragma solidity ^0.8.20;
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { IOAppOptionsType3, EnforcedOptionParam } from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppOptionsType3.sol";
/**
* @title OAppOptionsType3
* @dev Abstract contract implementing the IOAppOptionsType3 interface with type 3 options.
*/
abstract contract OAppOptionsType3Upgradeable is IOAppOptionsType3, OwnableUpgradeable {
struct OAppOptionsType3Storage {
// @dev The "msgType" should be defined in the child contract.
mapping(uint32 => mapping(uint16 => bytes)) enforcedOptions;
}
// keccak256(abi.encode(uint256(keccak256("layerzerov2.storage.oappoptionstype3")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OAPP_OPTIONS_TYPE_3_STORAGE_LOCATION =
0x8d2bda5d9f6ffb5796910376005392955773acee5548d0fcdb10e7c264ea0000;
uint16 internal constant OPTION_TYPE_3 = 3;
function _getOAppOptionsType3Storage() internal pure returns (OAppOptionsType3Storage storage $) {
assembly {
$.slot := OAPP_OPTIONS_TYPE_3_STORAGE_LOCATION
}
}
/**
* @dev Ownable is not initialized here on purpose. It should be initialized in the child contract to
* accommodate the different version of Ownable.
*/
function __OAppOptionsType3_init() internal onlyInitializing {}
function __OAppOptionsType3_init_unchained() internal onlyInitializing {}
function enforcedOptions(uint32 _eid, uint16 _msgType) public view returns (bytes memory) {
OAppOptionsType3Storage storage $ = _getOAppOptionsType3Storage();
return $.enforcedOptions[_eid][_msgType];
}
/**
* @dev Sets the enforced options for specific endpoint and message type combinations.
* @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options.
*
* @dev Only the owner/admin of the OApp can call this function.
* @dev Provides a way for the OApp to enforce things like paying for PreCrime, AND/OR minimum dst lzReceive gas amounts etc.
* @dev These enforced options can vary as the potential options/execution on the remote may differ as per the msgType.
* eg. Amount of lzReceive() gas necessary to deliver a lzCompose() message adds overhead you dont want to pay
* if you are only making a standard LayerZero message ie. lzReceive() WITHOUT sendCompose().
*/
function setEnforcedOptions(EnforcedOptionParam[] calldata _enforcedOptions) public virtual onlyOwner {
OAppOptionsType3Storage storage $ = _getOAppOptionsType3Storage();
for (uint256 i = 0; i < _enforcedOptions.length; i++) {
// @dev Enforced options are only available for optionType 3, as type 1 and 2 dont support combining.
_assertOptionsType3(_enforcedOptions[i].options);
$.enforcedOptions[_enforcedOptions[i].eid][_enforcedOptions[i].msgType] = _enforcedOptions[i].options;
}
emit EnforcedOptionSet(_enforcedOptions);
}
/**
* @notice Combines options for a given endpoint and message type.
* @param _eid The endpoint ID.
* @param _msgType The OAPP message type.
* @param _extraOptions Additional options passed by the caller.
* @return options The combination of caller specified options AND enforced options.
*
* @dev If there is an enforced lzReceive option:
* - {gasLimit: 200k, msg.value: 1 ether} AND a caller supplies a lzReceive option: {gasLimit: 100k, msg.value: 0.5 ether}
* - The resulting options will be {gasLimit: 300k, msg.value: 1.5 ether} when the message is executed on the remote lzReceive() function.
* @dev This presence of duplicated options is handled off-chain in the verifier/executor.
*/
function combineOptions(
uint32 _eid,
uint16 _msgType,
bytes calldata _extraOptions
) public view virtual returns (bytes memory) {
OAppOptionsType3Storage storage $ = _getOAppOptionsType3Storage();
bytes memory enforced = $.enforcedOptions[_eid][_msgType];
// No enforced options, pass whatever the caller supplied, even if it's empty or legacy type 1/2 options.
if (enforced.length == 0) return _extraOptions;
// No caller options, return enforced
if (_extraOptions.length == 0) return enforced;
// @dev If caller provided _extraOptions, must be type 3 as its the ONLY type that can be combined.
if (_extraOptions.length >= 2) {
_assertOptionsType3(_extraOptions);
// @dev Remove the first 2 bytes containing the type from the _extraOptions and combine with enforced.
return bytes.concat(enforced, _extraOptions[2:]);
}
// No valid set of options was found.
revert InvalidOptions(_extraOptions);
}
/**
* @dev Internal function to assert that options are of type 3.
* @param _options The options to be checked.
*/
function _assertOptionsType3(bytes calldata _options) internal pure virtual {
uint16 optionsType = uint16(bytes2(_options[0:2]));
if (optionsType != OPTION_TYPE_3) revert InvalidOptions(_options);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library AddressUpgradeable {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @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, it is bubbled up by this
* function (like regular Solidity function calls).
*
* 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.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @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`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// 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 {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControlUpgradeable {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
import "../proxy/utils/Initializable.sol";
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract ContextUpgradeable is Initializable {
function __Context_init() internal onlyInitializing {
__Context_init_unchained();
}
function __Context_init_unchained() internal onlyInitializing {
}
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Strings.sol)
pragma solidity ^0.8.0;
/**
* @dev String operations.
*/
library StringsUpgradeable {
bytes16 private constant _HEX_SYMBOLS = "0123456789abcdef";
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
// Inspired by OraclizeAPI's implementation - MIT licence
// https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol
if (value == 0) {
return "0";
}
uint256 temp = value;
uint256 digits;
while (temp != 0) {
digits++;
temp /= 10;
}
bytes memory buffer = new bytes(digits);
while (value != 0) {
digits -= 1;
buffer[digits] = bytes1(uint8(48 + uint256(value % 10)));
value /= 10;
}
return string(buffer);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
if (value == 0) {
return "0x00";
}
uint256 temp = value;
uint256 length = 0;
while (temp != 0) {
length++;
temp >>= 8;
}
return toHexString(value, length);
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _HEX_SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165Upgradeable.sol";
import "../../proxy/utils/Initializable.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165Upgradeable is Initializable, IERC165Upgradeable {
function __ERC165_init() internal onlyInitializing {
__ERC165_init_unchained();
}
function __ERC165_init_unchained() internal onlyInitializing {
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165Upgradeable).interfaceId;
}
uint256[50] private __gap;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that never changes
/// @notice These parameters are fixed for a pool forever, i.e., the methods will always return the same values
interface IUniswapV3PoolImmutables {
/// @notice The contract that deployed the pool, which must adhere to the IUniswapV3Factory interface
/// @return The contract address
function factory() external view returns (address);
/// @notice The first of the two tokens of the pool, sorted by address
/// @return The token contract address
function token0() external view returns (address);
/// @notice The second of the two tokens of the pool, sorted by address
/// @return The token contract address
function token1() external view returns (address);
/// @notice The pool's fee in hundredths of a bip, i.e. 1e-6
/// @return The fee
function fee() external view returns (uint24);
/// @notice The pool tick spacing
/// @dev Ticks can only be used at multiples of this value, minimum of 1 and always positive
/// e.g.: a tickSpacing of 3 means ticks can be initialized every 3rd tick, i.e., ..., -6, -3, 0, 3, 6, ...
/// This value is an int24 to avoid casting even though it is always positive.
/// @return The tick spacing
function tickSpacing() external view returns (int24);
/// @notice The maximum amount of position liquidity that can use any tick in the range
/// @dev This parameter is enforced per tick to prevent liquidity from overflowing a uint128 at any point, and
/// also prevents out-of-range liquidity from being used to prevent adding in-range liquidity to a pool
/// @return The max amount of liquidity per tick
function maxLiquidityPerTick() external view returns (uint128);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that can change
/// @notice These methods compose the pool's state, and can change with any frequency including multiple times
/// per transaction
interface IUniswapV3PoolState {
/// @notice The 0th storage slot in the pool stores many values, and is exposed as a single method to save gas
/// when accessed externally.
/// @return sqrtPriceX96 The current price of the pool as a sqrt(token1/token0) Q64.96 value
/// tick The current tick of the pool, i.e. according to the last tick transition that was run.
/// This value may not always be equal to SqrtTickMath.getTickAtSqrtRatio(sqrtPriceX96) if the price is on a tick
/// boundary.
/// observationIndex The index of the last oracle observation that was written,
/// observationCardinality The current maximum number of observations stored in the pool,
/// observationCardinalityNext The next maximum number of observations, to be updated when the observation.
/// feeProtocol The protocol fee for both tokens of the pool.
/// Encoded as two 4 bit values, where the protocol fee of token1 is shifted 4 bits and the protocol fee of token0
/// is the lower 4 bits. Used as the denominator of a fraction of the swap fee, e.g. 4 means 1/4th of the swap fee.
/// unlocked Whether the pool is currently locked to reentrancy
function slot0()
external
view
returns (
uint160 sqrtPriceX96,
int24 tick,
uint16 observationIndex,
uint16 observationCardinality,
uint16 observationCardinalityNext,
uint8 feeProtocol,
bool unlocked
);
/// @notice The fee growth as a Q128.128 fees of token0 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal0X128() external view returns (uint256);
/// @notice The fee growth as a Q128.128 fees of token1 collected per unit of liquidity for the entire life of the pool
/// @dev This value can overflow the uint256
function feeGrowthGlobal1X128() external view returns (uint256);
/// @notice The amounts of token0 and token1 that are owed to the protocol
/// @dev Protocol fees will never exceed uint128 max in either token
function protocolFees() external view returns (uint128 token0, uint128 token1);
/// @notice The currently in range liquidity available to the pool
/// @dev This value has no relationship to the total liquidity across all ticks
function liquidity() external view returns (uint128);
/// @notice Look up information about a specific tick in the pool
/// @param tick The tick to look up
/// @return liquidityGross the total amount of position liquidity that uses the pool either as tick lower or
/// tick upper,
/// liquidityNet how much liquidity changes when the pool price crosses the tick,
/// feeGrowthOutside0X128 the fee growth on the other side of the tick from the current tick in token0,
/// feeGrowthOutside1X128 the fee growth on the other side of the tick from the current tick in token1,
/// tickCumulativeOutside the cumulative tick value on the other side of the tick from the current tick
/// secondsPerLiquidityOutsideX128 the seconds spent per liquidity on the other side of the tick from the current tick,
/// secondsOutside the seconds spent on the other side of the tick from the current tick,
/// initialized Set to true if the tick is initialized, i.e. liquidityGross is greater than 0, otherwise equal to false.
/// Outside values can only be used if the tick is initialized, i.e. if liquidityGross is greater than 0.
/// In addition, these values are only relative and must be used only in comparison to previous snapshots for
/// a specific position.
function ticks(int24 tick)
external
view
returns (
uint128 liquidityGross,
int128 liquidityNet,
uint256 feeGrowthOutside0X128,
uint256 feeGrowthOutside1X128,
int56 tickCumulativeOutside,
uint160 secondsPerLiquidityOutsideX128,
uint32 secondsOutside,
bool initialized
);
/// @notice Returns 256 packed tick initialized boolean values. See TickBitmap for more information
function tickBitmap(int16 wordPosition) external view returns (uint256);
/// @notice Returns the information about a position by the position's key
/// @param key The position's key is a hash of a preimage composed by the owner, tickLower and tickUpper
/// @return _liquidity The amount of liquidity in the position,
/// Returns feeGrowthInside0LastX128 fee growth of token0 inside the tick range as of the last mint/burn/poke,
/// Returns feeGrowthInside1LastX128 fee growth of token1 inside the tick range as of the last mint/burn/poke,
/// Returns tokensOwed0 the computed amount of token0 owed to the position as of the last mint/burn/poke,
/// Returns tokensOwed1 the computed amount of token1 owed to the position as of the last mint/burn/poke
function positions(bytes32 key)
external
view
returns (
uint128 _liquidity,
uint256 feeGrowthInside0LastX128,
uint256 feeGrowthInside1LastX128,
uint128 tokensOwed0,
uint128 tokensOwed1
);
/// @notice Returns data about a specific observation index
/// @param index The element of the observations array to fetch
/// @dev You most likely want to use #observe() instead of this method to get an observation as of some amount of time
/// ago, rather than at a specific index in the array.
/// @return blockTimestamp The timestamp of the observation,
/// Returns tickCumulative the tick multiplied by seconds elapsed for the life of the pool as of the observation timestamp,
/// Returns secondsPerLiquidityCumulativeX128 the seconds per in range liquidity for the life of the pool as of the observation timestamp,
/// Returns initialized whether the observation has been initialized and the values are safe to use
function observations(uint256 index)
external
view
returns (
uint32 blockTimestamp,
int56 tickCumulative,
uint160 secondsPerLiquidityCumulativeX128,
bool initialized
);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Pool state that is not stored
/// @notice Contains view functions to provide information about the pool that is computed rather than stored on the
/// blockchain. The functions here may have variable gas costs.
interface IUniswapV3PoolDerivedState {
/// @notice Returns the cumulative tick and liquidity as of each timestamp `secondsAgo` from the current block timestamp
/// @dev To get a time weighted average tick or liquidity-in-range, you must call this with two values, one representing
/// the beginning of the period and another for the end of the period. E.g., to get the last hour time-weighted average tick,
/// you must call it with secondsAgos = [3600, 0].
/// @dev The time weighted average tick represents the geometric time weighted average price of the pool, in
/// log base sqrt(1.0001) of token1 / token0. The TickMath library can be used to go from a tick value to a ratio.
/// @param secondsAgos From how long ago each cumulative tick and liquidity value should be returned
/// @return tickCumulatives Cumulative tick values as of each `secondsAgos` from the current block timestamp
/// @return secondsPerLiquidityCumulativeX128s Cumulative seconds per liquidity-in-range value as of each `secondsAgos` from the current block
/// timestamp
function observe(uint32[] calldata secondsAgos)
external
view
returns (int56[] memory tickCumulatives, uint160[] memory secondsPerLiquidityCumulativeX128s);
/// @notice Returns a snapshot of the tick cumulative, seconds per liquidity and seconds inside a tick range
/// @dev Snapshots must only be compared to other snapshots, taken over a period for which a position existed.
/// I.e., snapshots cannot be compared if a position is not held for the entire period between when the first
/// snapshot is taken and the second snapshot is taken.
/// @param tickLower The lower tick of the range
/// @param tickUpper The upper tick of the range
/// @return tickCumulativeInside The snapshot of the tick accumulator for the range
/// @return secondsPerLiquidityInsideX128 The snapshot of seconds per liquidity for the range
/// @return secondsInside The snapshot of seconds per liquidity for the range
function snapshotCumulativesInside(int24 tickLower, int24 tickUpper)
external
view
returns (
int56 tickCumulativeInside,
uint160 secondsPerLiquidityInsideX128,
uint32 secondsInside
);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissionless pool actions
/// @notice Contains pool methods that can be called by anyone
interface IUniswapV3PoolActions {
/// @notice Sets the initial price for the pool
/// @dev Price is represented as a sqrt(amountToken1/amountToken0) Q64.96 value
/// @param sqrtPriceX96 the initial sqrt price of the pool as a Q64.96
function initialize(uint160 sqrtPriceX96) external;
/// @notice Adds liquidity for the given recipient/tickLower/tickUpper position
/// @dev The caller of this method receives a callback in the form of IUniswapV3MintCallback#uniswapV3MintCallback
/// in which they must pay any token0 or token1 owed for the liquidity. The amount of token0/token1 due depends
/// on tickLower, tickUpper, the amount of liquidity, and the current price.
/// @param recipient The address for which the liquidity will be created
/// @param tickLower The lower tick of the position in which to add liquidity
/// @param tickUpper The upper tick of the position in which to add liquidity
/// @param amount The amount of liquidity to mint
/// @param data Any data that should be passed through to the callback
/// @return amount0 The amount of token0 that was paid to mint the given amount of liquidity. Matches the value in the callback
/// @return amount1 The amount of token1 that was paid to mint the given amount of liquidity. Matches the value in the callback
function mint(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount,
bytes calldata data
) external returns (uint256 amount0, uint256 amount1);
/// @notice Collects tokens owed to a position
/// @dev Does not recompute fees earned, which must be done either via mint or burn of any amount of liquidity.
/// Collect must be called by the position owner. To withdraw only token0 or only token1, amount0Requested or
/// amount1Requested may be set to zero. To withdraw all tokens owed, caller may pass any value greater than the
/// actual tokens owed, e.g. type(uint128).max. Tokens owed may be from accumulated swap fees or burned liquidity.
/// @param recipient The address which should receive the fees collected
/// @param tickLower The lower tick of the position for which to collect fees
/// @param tickUpper The upper tick of the position for which to collect fees
/// @param amount0Requested How much token0 should be withdrawn from the fees owed
/// @param amount1Requested How much token1 should be withdrawn from the fees owed
/// @return amount0 The amount of fees collected in token0
/// @return amount1 The amount of fees collected in token1
function collect(
address recipient,
int24 tickLower,
int24 tickUpper,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
/// @notice Burn liquidity from the sender and account tokens owed for the liquidity to the position
/// @dev Can be used to trigger a recalculation of fees owed to a position by calling with an amount of 0
/// @dev Fees must be collected separately via a call to #collect
/// @param tickLower The lower tick of the position for which to burn liquidity
/// @param tickUpper The upper tick of the position for which to burn liquidity
/// @param amount How much liquidity to burn
/// @return amount0 The amount of token0 sent to the recipient
/// @return amount1 The amount of token1 sent to the recipient
function burn(
int24 tickLower,
int24 tickUpper,
uint128 amount
) external returns (uint256 amount0, uint256 amount1);
/// @notice Swap token0 for token1, or token1 for token0
/// @dev The caller of this method receives a callback in the form of IUniswapV3SwapCallback#uniswapV3SwapCallback
/// @param recipient The address to receive the output of the swap
/// @param zeroForOne The direction of the swap, true for token0 to token1, false for token1 to token0
/// @param amountSpecified The amount of the swap, which implicitly configures the swap as exact input (positive), or exact output (negative)
/// @param sqrtPriceLimitX96 The Q64.96 sqrt price limit. If zero for one, the price cannot be less than this
/// value after the swap. If one for zero, the price cannot be greater than this value after the swap
/// @param data Any data to be passed through to the callback
/// @return amount0 The delta of the balance of token0 of the pool, exact when negative, minimum when positive
/// @return amount1 The delta of the balance of token1 of the pool, exact when negative, minimum when positive
function swap(
address recipient,
bool zeroForOne,
int256 amountSpecified,
uint160 sqrtPriceLimitX96,
bytes calldata data
) external returns (int256 amount0, int256 amount1);
/// @notice Receive token0 and/or token1 and pay it back, plus a fee, in the callback
/// @dev The caller of this method receives a callback in the form of IUniswapV3FlashCallback#uniswapV3FlashCallback
/// @dev Can be used to donate underlying tokens pro-rata to currently in-range liquidity providers by calling
/// with 0 amount{0,1} and sending the donation amount(s) from the callback
/// @param recipient The address which will receive the token0 and token1 amounts
/// @param amount0 The amount of token0 to send
/// @param amount1 The amount of token1 to send
/// @param data Any data to be passed through to the callback
function flash(
address recipient,
uint256 amount0,
uint256 amount1,
bytes calldata data
) external;
/// @notice Increase the maximum number of price and liquidity observations that this pool will store
/// @dev This method is no-op if the pool already has an observationCardinalityNext greater than or equal to
/// the input observationCardinalityNext.
/// @param observationCardinalityNext The desired minimum number of observations for the pool to store
function increaseObservationCardinalityNext(uint16 observationCardinalityNext) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Permissioned pool actions
/// @notice Contains pool methods that may only be called by the factory owner
interface IUniswapV3PoolOwnerActions {
/// @notice Set the denominator of the protocol's % share of the fees
/// @param feeProtocol0 new protocol fee for token0 of the pool
/// @param feeProtocol1 new protocol fee for token1 of the pool
function setFeeProtocol(uint8 feeProtocol0, uint8 feeProtocol1) external;
/// @notice Collect the protocol fee accrued to the pool
/// @param recipient The address to which collected protocol fees should be sent
/// @param amount0Requested The maximum amount of token0 to send, can be 0 to collect fees in only token1
/// @param amount1Requested The maximum amount of token1 to send, can be 0 to collect fees in only token0
/// @return amount0 The protocol fee collected in token0
/// @return amount1 The protocol fee collected in token1
function collectProtocol(
address recipient,
uint128 amount0Requested,
uint128 amount1Requested
) external returns (uint128 amount0, uint128 amount1);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Events emitted by a pool
/// @notice Contains all events emitted by the pool
interface IUniswapV3PoolEvents {
/// @notice Emitted exactly once by a pool when #initialize is first called on the pool
/// @dev Mint/Burn/Swap cannot be emitted by the pool before Initialize
/// @param sqrtPriceX96 The initial sqrt price of the pool, as a Q64.96
/// @param tick The initial tick of the pool, i.e. log base 1.0001 of the starting price of the pool
event Initialize(uint160 sqrtPriceX96, int24 tick);
/// @notice Emitted when liquidity is minted for a given position
/// @param sender The address that minted the liquidity
/// @param owner The owner of the position and recipient of any minted liquidity
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity minted to the position range
/// @param amount0 How much token0 was required for the minted liquidity
/// @param amount1 How much token1 was required for the minted liquidity
event Mint(
address sender,
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted when fees are collected by the owner of a position
/// @dev Collect events may be emitted with zero amount0 and amount1 when the caller chooses not to collect fees
/// @param owner The owner of the position for which fees are collected
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount0 The amount of token0 fees collected
/// @param amount1 The amount of token1 fees collected
event Collect(
address indexed owner,
address recipient,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount0,
uint128 amount1
);
/// @notice Emitted when a position's liquidity is removed
/// @dev Does not withdraw any fees earned by the liquidity position, which must be withdrawn via #collect
/// @param owner The owner of the position for which liquidity is removed
/// @param tickLower The lower tick of the position
/// @param tickUpper The upper tick of the position
/// @param amount The amount of liquidity to remove
/// @param amount0 The amount of token0 withdrawn
/// @param amount1 The amount of token1 withdrawn
event Burn(
address indexed owner,
int24 indexed tickLower,
int24 indexed tickUpper,
uint128 amount,
uint256 amount0,
uint256 amount1
);
/// @notice Emitted by the pool for any swaps between token0 and token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the output of the swap
/// @param amount0 The delta of the token0 balance of the pool
/// @param amount1 The delta of the token1 balance of the pool
/// @param sqrtPriceX96 The sqrt(price) of the pool after the swap, as a Q64.96
/// @param liquidity The liquidity of the pool after the swap
/// @param tick The log base 1.0001 of price of the pool after the swap
event Swap(
address indexed sender,
address indexed recipient,
int256 amount0,
int256 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick
);
/// @notice Emitted by the pool for any flashes of token0/token1
/// @param sender The address that initiated the swap call, and that received the callback
/// @param recipient The address that received the tokens from flash
/// @param amount0 The amount of token0 that was flashed
/// @param amount1 The amount of token1 that was flashed
/// @param paid0 The amount of token0 paid for the flash, which can exceed the amount0 plus the fee
/// @param paid1 The amount of token1 paid for the flash, which can exceed the amount1 plus the fee
event Flash(
address indexed sender,
address indexed recipient,
uint256 amount0,
uint256 amount1,
uint256 paid0,
uint256 paid1
);
/// @notice Emitted by the pool for increases to the number of observations that can be stored
/// @dev observationCardinalityNext is not the observation cardinality until an observation is written at the index
/// just before a mint/swap/burn.
/// @param observationCardinalityNextOld The previous value of the next observation cardinality
/// @param observationCardinalityNextNew The updated value of the next observation cardinality
event IncreaseObservationCardinalityNext(
uint16 observationCardinalityNextOld,
uint16 observationCardinalityNextNew
);
/// @notice Emitted when the protocol fee is changed by the pool
/// @param feeProtocol0Old The previous value of the token0 protocol fee
/// @param feeProtocol1Old The previous value of the token1 protocol fee
/// @param feeProtocol0New The updated value of the token0 protocol fee
/// @param feeProtocol1New The updated value of the token1 protocol fee
event SetFeeProtocol(uint8 feeProtocol0Old, uint8 feeProtocol1Old, uint8 feeProtocol0New, uint8 feeProtocol1New);
/// @notice Emitted when the collected protocol fees are withdrawn by the factory owner
/// @param sender The address that collects the protocol fees
/// @param recipient The address that receives the collected protocol fees
/// @param amount0 The amount of token0 protocol fees that is withdrawn
/// @param amount0 The amount of token1 protocol fees that is withdrawn
event CollectProtocol(address indexed sender, address indexed recipient, uint128 amount0, uint128 amount1);
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.5.0;
/// @title Callback for IUniswapV3PoolActions#swap
/// @notice Any contract that calls IUniswapV3PoolActions#swap must implement this interface
interface IUniswapV3SwapCallback {
/// @notice Called to `msg.sender` after executing a swap via IUniswapV3Pool#swap.
/// @dev In the implementation you must pay the pool tokens owed for the swap.
/// The caller of this method must be checked to be a UniswapV3Pool deployed by the canonical UniswapV3Factory.
/// amount0Delta and amount1Delta can both be 0 if no tokens were swapped.
/// @param amount0Delta The amount of token0 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token0 to the pool.
/// @param amount1Delta The amount of token1 that was sent (negative) or must be received (positive) by the pool by
/// the end of the swap. If positive, the callback must send that amount of token1 to the pool.
/// @param data Any data passed through by the caller via the IUniswapV3PoolActions#swap call
function uniswapV3SwapCallback(
int256 amount0Delta,
int256 amount1Delta,
bytes calldata data
) external;
}// SPDX-License-Identifier: GPL-2.0-or-later
pragma solidity >=0.7.5;
/// @title Periphery Payments
/// @notice Functions to ease deposits and withdrawals of ETH
interface IPeripheryPayments {
/// @notice Unwraps the contract's WETH9 balance and sends it to recipient as ETH.
/// @dev The amountMinimum parameter prevents malicious contracts from stealing WETH9 from users.
/// @param amountMinimum The minimum amount of WETH9 to unwrap
/// @param recipient The address receiving ETH
function unwrapWETH9(uint256 amountMinimum, address recipient) external payable;
/// @notice Refunds any ETH balance held by this contract to the `msg.sender`
/// @dev Useful for bundling with mint or increase liquidity that uses ether, or exact output swaps
/// that use ether for the input amount
function refundETH() external payable;
/// @notice Transfers the full amount of a token held by this contract to recipient
/// @dev The amountMinimum parameter prevents malicious contracts from stealing the token from users
/// @param token The contract address of the token which will be transferred to `recipient`
/// @param amountMinimum The minimum amount of token required for a transfer
/// @param recipient The destination address of the token
function sweepToken(
address token,
uint256 amountMinimum,
address recipient
) external payable;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address recipient, uint256 amount) 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 `amount` 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 amount) external returns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address sender,
address recipient,
uint256 amount
) external returns (bool);
/**
* @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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeMath.sol)
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMathUpgradeable {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the substraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(
uint256 a,
uint256 b,
string memory errorMessage
) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/draft-IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol";
interface IFiat24Account is IERC721Enumerable {
enum Status {
Na,
SoftBlocked,
Tourist,
Blocked,
Closed,
Live
}
function historicOwnership(address) external view returns (uint256);
function exists(uint256 tokenId) external view returns (bool);
function nickNames(uint256) external view returns (string memory);
function isMerchant(uint256) external view returns (bool);
function merchantRate(uint256) external view returns (uint256);
function status(uint256) external view returns (uint256);
function checkLimit(uint256, uint256) external view returns (bool);
function updateLimit(uint256 tokenId, uint256 amount) external;
function walletProvider(uint256) external view returns (uint256);
}// 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 "@layerzerolabs/lz-evm-protocol-v2/contracts/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: 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 { 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 immutable 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.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 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 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 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 { SafeERC20, IERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { MessagingParams, MessagingFee, MessagingReceipt } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { OAppCoreUpgradeable } from "./OAppCoreUpgradeable.sol";
/**
* @title OAppSender
* @dev Abstract contract implementing the OAppSender functionality for sending messages to a LayerZero endpoint.
*/
abstract contract OAppSenderUpgradeable is OAppCoreUpgradeable {
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;
/**
* @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
* @dev Ownable is not initialized here on purpose. It should be initialized in the child contract to
* accommodate the different version of Ownable.
*/
function __OAppSender_init(address _delegate) internal onlyInitializing {
__OAppCore_init(_delegate);
}
function __OAppSender_init_unchained() internal onlyInitializing {}
/**
* @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: MIT
pragma solidity ^0.8.20;
import { IOAppReceiver, Origin } from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppReceiver.sol";
import { OAppCoreUpgradeable } from "./OAppCoreUpgradeable.sol";
/**
* @title OAppReceiver
* @dev Abstract contract implementing the ILayerZeroReceiver interface and extending OAppCore for OApp receivers.
*/
abstract contract OAppReceiverUpgradeable is IOAppReceiver, OAppCoreUpgradeable {
// 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;
/**
* @param _delegate The delegate capable of making OApp configurations inside of the endpoint.
* @dev Ownable is not initialized here on purpose. It should be initialized in the child contract to
* accommodate the different version of Ownable.
*/
function __OAppReceiver_init(address _delegate) internal onlyInitializing {
__OAppCore_init(_delegate);
}
function __OAppReceiver_init_unchained() internal onlyInitializing {}
/**
* @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 { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { IOAppCore, ILayerZeroEndpointV2 } from "@layerzerolabs/oapp-evm/contracts/oapp/interfaces/IOAppCore.sol";
/**
* @title OAppCore
* @dev Abstract contract implementing the IOAppCore interface with basic OApp configurations.
*/
abstract contract OAppCoreUpgradeable is IOAppCore, OwnableUpgradeable {
struct OAppCoreStorage {
mapping(uint32 => bytes32) peers;
}
// keccak256(abi.encode(uint256(keccak256("layerzerov2.storage.oappcore")) - 1)) & ~bytes32(uint256(0xff))
bytes32 private constant OAPP_CORE_STORAGE_LOCATION =
0x72ab1bc1039b79dc4724ffca13de82c96834302d3c7e0d4252232d4b2dd8f900;
function _getOAppCoreStorage() internal pure returns (OAppCoreStorage storage $) {
assembly {
$.slot := OAPP_CORE_STORAGE_LOCATION
}
}
// The LayerZero endpoint associated with the given OApp
ILayerZeroEndpointV2 public immutable endpoint;
/**
* @dev Constructor to initialize the OAppCore with the provided endpoint and delegate.
* @param _endpoint The address of the LOCAL Layer Zero endpoint.
*/
constructor(address _endpoint) {
endpoint = ILayerZeroEndpointV2(_endpoint);
}
/**
* @dev Initializes the OAppCore with the provided delegate.
* @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.
* @dev Ownable is not initialized here on purpose. It should be initialized in the child contract to
* accommodate the different version of Ownable.
*/
function __OAppCore_init(address _delegate) internal onlyInitializing {
__OAppCore_init_unchained(_delegate);
}
function __OAppCore_init_unchained(address _delegate) internal onlyInitializing {
if (_delegate == address(0)) revert InvalidDelegate();
endpoint.setDelegate(_delegate);
}
/**
* @notice Returns the peer address (OApp instance) associated with a specific endpoint.
* @param _eid The endpoint ID.
* @return peer The address of the peer associated with the specified endpoint.
*/
function peers(uint32 _eid) public view override returns (bytes32) {
OAppCoreStorage storage $ = _getOAppCoreStorage();
return $.peers[_eid];
}
/**
* @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 {
OAppCoreStorage storage $ = _getOAppCoreStorage();
$.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) {
OAppCoreStorage storage $ = _getOAppCoreStorage();
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: Unlicense
/*
* @title Solidity Bytes Arrays Utils
* @author Gonçalo Sá <goncalo.sa@consensys.net>
*
* @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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/math/SafeCast.sol)
pragma solidity ^0.8.0;
/**
* @dev Wrappers over Solidity's uintXX/intXX 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.
*
* Can be combined with {SafeMath} and {SignedSafeMath} to extend it to smaller types, by performing
* all math on `uint256` and `int256` and then downcasting.
*/
library SafeCast {
/**
* @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) {
require(value <= type(uint224).max, "SafeCast: value doesn't fit in 224 bits");
return uint224(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) {
require(value <= type(uint128).max, "SafeCast: value doesn't fit in 128 bits");
return uint128(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) {
require(value <= type(uint96).max, "SafeCast: value doesn't fit in 96 bits");
return uint96(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) {
require(value <= type(uint64).max, "SafeCast: value doesn't fit in 64 bits");
return uint64(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) {
require(value <= type(uint32).max, "SafeCast: value doesn't fit in 32 bits");
return uint32(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) {
require(value <= type(uint16).max, "SafeCast: value doesn't fit in 16 bits");
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) {
require(value <= type(uint8).max, "SafeCast: value doesn't fit in 8 bits");
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) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(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
*
* _Available since v3.1._
*/
function toInt128(int256 value) internal pure returns (int128) {
require(value >= type(int128).min && value <= type(int128).max, "SafeCast: value doesn't fit in 128 bits");
return int128(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
*
* _Available since v3.1._
*/
function toInt64(int256 value) internal pure returns (int64) {
require(value >= type(int64).min && value <= type(int64).max, "SafeCast: value doesn't fit in 64 bits");
return int64(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
*
* _Available since v3.1._
*/
function toInt32(int256 value) internal pure returns (int32) {
require(value >= type(int32).min && value <= type(int32).max, "SafeCast: value doesn't fit in 32 bits");
return int32(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
*
* _Available since v3.1._
*/
function toInt16(int256 value) internal pure returns (int16) {
require(value >= type(int16).min && value <= type(int16).max, "SafeCast: value doesn't fit in 16 bits");
return int16(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.
*
* _Available since v3.1._
*/
function toInt8(int256 value) internal pure returns (int8) {
require(value >= type(int8).min && value <= type(int8).max, "SafeCast: value doesn't fit in 8 bits");
return int8(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
require(value <= uint256(type(int256).max), "SafeCast: value doesn't fit in an int256");
return int256(value);
}
}// 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: MIT
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import "../proxy/utils/Initializable.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract OwnableUpgradeable is Initializable, ContextUpgradeable {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
function __Ownable_init() internal onlyInitializing {
__Context_init_unchained();
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing 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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_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);
}
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
/**
* @dev Struct representing enforced option parameters.
*/
struct EnforcedOptionParam {
uint32 eid; // Endpoint ID
uint16 msgType; // Message Type
bytes options; // Additional options
}
/**
* @title IOAppOptionsType3
* @dev Interface for the OApp with Type 3 Options, allowing the setting and combining of enforced options.
*/
interface IOAppOptionsType3 {
// Custom error message for invalid options
error InvalidOptions(bytes options);
// Event emitted when enforced options are set
event EnforcedOptionSet(EnforcedOptionParam[] _enforcedOptions);
/**
* @notice Sets enforced options for specific endpoint and message type combinations.
* @param _enforcedOptions An array of EnforcedOptionParam structures specifying enforced options.
*/
function setEnforcedOptions(EnforcedOptionParam[] calldata _enforcedOptions) external;
/**
* @notice Combines options for a given endpoint and message type.
* @param _eid The endpoint ID.
* @param _msgType The OApp message type.
* @param _extraOptions Additional options passed by the caller.
* @return options The combination of caller specified options AND enforced options.
*/
function combineOptions(
uint32 _eid,
uint16 _msgType,
bytes calldata _extraOptions
) external view returns (bytes memory options);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165Upgradeable {
/**
* @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[EIP 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 v4.4.1 (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256 tokenId);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
function safeTransfer(
IERC20 token,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(
IERC20 token,
address from,
address to,
uint256 value
) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(
IERC20 token,
address spender,
uint256 value
) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
uint256 newAllowance = token.allowance(address(this), spender) + value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
function safeDecreaseAllowance(
IERC20 token,
address spender,
uint256 value
) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
uint256 newAllowance = oldAllowance - value;
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, newAllowance));
}
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address.functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
if (returndata.length > 0) {
// Return data is optional
require(abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { ILayerZeroReceiver, Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/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
// OpenZeppelin Contracts v4.4.1 (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../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.
*
* By default, the owner account will be the one that deploys the contract. 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;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing 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 {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { ILayerZeroEndpointV2 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/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: 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
// OpenZeppelin Contracts v4.4.1 (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Usage of this method is discouraged, use {safeTransferFrom} whenever possible.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(
address from,
address to,
uint256 tokenId
) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool _approved) external;
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(
address from,
address to,
uint256 tokenId,
bytes calldata data
) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Address.sol)
pragma solidity ^0.8.0;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize, which returns 0 for contracts in
// construction, since the code is only stored at the end of the
// constructor execution.
uint256 size;
assembly {
size := extcodesize(account)
}
return size > 0;
}
/**
* @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://diligence.consensys.net/posts/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.5.11/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @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, it is bubbled up by this
* function (like regular Solidity function calls).
*
* 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.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCall(target, data, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @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`.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value
) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
require(isContract(target), "Address: call to non-contract");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
require(isContract(target), "Address: static call to non-contract");
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
require(isContract(target), "Address: delegate call to non-contract");
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResult(success, returndata, errorMessage);
}
/**
* @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
// 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 {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
}// 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
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @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;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* 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[EIP 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);
}{
"remappings": [
"@uniswap/v3-core/=lib/v3-core/",
"@uniswap/v3-periphery/=lib/v3-periphery/",
"@uniswap/swap-router-contracts/=lib/swap-router-contracts/",
"@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/",
"openzeppelin/contracts/=node_modules/@openzeppelin/contracts/",
"openzeppelin/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable/",
"openzeppelin-4.7.3/contracts-upgradeable/=node_modules/@openzeppelin/contracts-upgradeable-4.7.3/",
"@safe-contracts/contracts/=lib/mantle-cdk/lib/safe-contracts/contracts/",
"forge-std/=lib/forge-std/src/",
"mantle-cdk/=lib/mantle-cdk/",
"solidity-bytes-utils/=node_modules/solidity-bytes-utils/",
"@layerzerolabs/=node_modules/@layerzerolabs/",
"@createx-forge/=lib/mantle-cdk/lib/createx-forge/",
"@solady/=lib/mantle-cdk/lib/solady/src/",
"createx-forge/=lib/mantle-cdk/lib/createx-forge/",
"ds-test/=lib/mantle-cdk/lib/surl/lib/forge-std/lib/ds-test/src/",
"erc4626-tests/=lib/mantle-cdk/lib/openzeppelin-contracts-upgradeable/lib/erc4626-tests/",
"halmos-cheatcodes/=lib/mantle-cdk/lib/openzeppelin-contracts-upgradeable/lib/halmos-cheatcodes/src/",
"openzeppelin-contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/",
"openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
"openzeppelin-foundry-upgrades/=lib/mantle-cdk/lib/openzeppelin-foundry-upgrades/src/",
"safe-contracts/=lib/mantle-cdk/lib/safe-contracts/",
"solady/=lib/mantle-cdk/lib/solady/src/",
"solidity-stringutils/=lib/mantle-cdk/lib/openzeppelin-foundry-upgrades/lib/solidity-stringutils/",
"surl/=lib/mantle-cdk/lib/surl/",
"swap-router-contracts/=lib/swap-router-contracts/contracts/",
"v3-core/=lib/v3-core/",
"v3-periphery/=lib/v3-periphery/contracts/"
],
"optimizer": {
"enabled": true,
"runs": 1
},
"metadata": {
"useLiteralContent": false,
"bytecodeHash": "ipfs",
"appendCBOR": true
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"evmVersion": "paris",
"viaIR": false
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"_endpoint","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"Fiat24CryptoDeposit__AddressHasNoToken","type":"error"},{"inputs":[],"name":"Fiat24CryptoDeposit__AggregatorSwapFailed","type":"error"},{"inputs":[{"internalType":"uint256","name":"inputAmount","type":"uint256"}],"name":"Fiat24CryptoDeposit__AmountGreaterThanMaximum","type":"error"},{"inputs":[{"internalType":"uint256","name":"outputAmount","type":"uint256"}],"name":"Fiat24CryptoDeposit__AmountLessThanMinimum","type":"error"},{"inputs":[],"name":"Fiat24CryptoDeposit__EthRefundFailed","type":"error"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"address","name":"outputToken","type":"address"}],"name":"Fiat24CryptoDeposit__ExchangeRateNotAvailable","type":"error"},{"inputs":[{"internalType":"uint256","name":"_feeAmountViaUsdc","type":"uint256"},{"internalType":"uint256","name":"usdcAmount","type":"uint256"}],"name":"Fiat24CryptoDeposit__FeeAmountExceedsOutput","type":"error"},{"inputs":[{"internalType":"bytes4","name":"selector","type":"bytes4"}],"name":"Fiat24CryptoDeposit__FunctionNotWhitelisted","type":"error"},{"inputs":[{"internalType":"address","name":"inputToken","type":"address"},{"internalType":"address","name":"outputToken","type":"address"}],"name":"Fiat24CryptoDeposit__InputTokenOutputTokenSame","type":"error"},{"inputs":[],"name":"Fiat24CryptoDeposit__InvalidCalldata","type":"error"},{"inputs":[],"name":"Fiat24CryptoDeposit__MNTRefundFailed","type":"error"},{"inputs":[{"internalType":"address","name":"tokenA","type":"address"},{"internalType":"address","name":"tokenB","type":"address"}],"name":"Fiat24CryptoDeposit__NoPoolAvailable","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"Fiat24CryptoDeposit__NotDefaultAdmin","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"Fiat24CryptoDeposit__NotOperator","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"Fiat24CryptoDeposit__NotOperatorAdmin","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"Fiat24CryptoDeposit__NotPauser","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"Fiat24CryptoDeposit__NotRateUpdater","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"Fiat24CryptoDeposit__NotTokensWalletProvider","type":"error"},{"inputs":[{"internalType":"address","name":"sender","type":"address"}],"name":"Fiat24CryptoDeposit__NotUnpauser","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"Fiat24CryptoDeposit__NotValidInputToken","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"Fiat24CryptoDeposit__NotValidOutputToken","type":"error"},{"inputs":[{"internalType":"address","name":"aggregator","type":"address"}],"name":"Fiat24CryptoDeposit__NotWhitelistedAggregator","type":"error"},{"inputs":[],"name":"Fiat24CryptoDeposit__Paused","type":"error"},{"inputs":[{"internalType":"uint256","name":"actualAmount","type":"uint256"},{"internalType":"uint256","name":"minAcceptableAmount","type":"uint256"}],"name":"Fiat24CryptoDeposit__SlippageExceeded","type":"error"},{"inputs":[],"name":"Fiat24CryptoDeposit__SwapOutputAmountZero","type":"error"},{"inputs":[{"internalType":"uint256","name":"usdcAmount","type":"uint256"},{"internalType":"uint256","name":"maxAmount","type":"uint256"}],"name":"Fiat24CryptoDeposit__UsdcAmountHigherMaxDepositAmount","type":"error"},{"inputs":[{"internalType":"uint256","name":"usdcAmount","type":"uint256"},{"internalType":"uint256","name":"minAmount","type":"uint256"}],"name":"Fiat24CryptoDeposit__UsdcAmountLowerMinDepositAmount","type":"error"},{"inputs":[],"name":"Fiat24CryptoDeposit__ValueZero","type":"error"},{"inputs":[{"internalType":"uint256","name":"usdAmount","type":"uint256"}],"name":"Fiat24CryptoExchange__UsdAmountLowerMinAmount","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"Fiat24Token__NotCashOperator","type":"error"},{"inputs":[],"name":"InvalidDelegate","type":"error"},{"inputs":[],"name":"InvalidEndpointCall","type":"error"},{"inputs":[{"internalType":"uint16","name":"optionType","type":"uint16"}],"name":"InvalidOptionType","type":"error"},{"inputs":[{"internalType":"bytes","name":"options","type":"bytes"}],"name":"InvalidOptions","type":"error"},{"inputs":[],"name":"LzTokenUnavailable","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"}],"name":"NoPeer","type":"error"},{"inputs":[{"internalType":"uint256","name":"msgValue","type":"uint256"}],"name":"NotEnoughNative","type":"error"},{"inputs":[{"internalType":"address","name":"addr","type":"address"}],"name":"OnlyEndpoint","type":"error"},{"inputs":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"bytes32","name":"sender","type":"bytes32"}],"name":"OnlyPeer","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"aggregator","type":"address"},{"indexed":false,"internalType":"bool","name":"isWhitelisted","type":"bool"}],"name":"AggregatorWhitelistUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdcAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"}],"name":"CrossChainMessage","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"targetAddress","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"}],"name":"DepositToAccount","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":true,"internalType":"address","name":"clientAddress","type":"address"},{"indexed":true,"internalType":"uint256","name":"walletId","type":"uint256"},{"indexed":false,"internalType":"address","name":"walletAddress","type":"address"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"usdcAmount","type":"uint256"}],"name":"DepositedByWallet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"}],"name":"DepositedFiat24Token","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"factAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"}],"name":"DepositedTokenViaUsd","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"uint16","name":"msgType","type":"uint16"},{"internalType":"bytes","name":"options","type":"bytes"}],"indexed":false,"internalType":"struct EnforcedOptionParam[]","name":"_enforcedOptions","type":"tuple[]"}],"name":"EnforcedOptionSet","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"fiatToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newRate","type":"uint256"},{"indexed":false,"internalType":"bool","name":"_isMarketClosed","type":"bool"}],"name":"ExchangeRateUpdatedByOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"fiatToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"oldRate","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newRate","type":"uint256"},{"indexed":false,"internalType":"bool","name":"_isMarketClosed","type":"bool"}],"name":"ExchangeRateUpdatedByRobot","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"usdeur","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdchf","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdgbp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdcnh","type":"uint256"},{"indexed":false,"internalType":"bool","name":"marketClosed","type":"bool"}],"name":"ExchangeRatesUpdatedByOperator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"uint256","name":"usdeur","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdchf","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdgbp","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdcnh","type":"uint256"},{"indexed":false,"internalType":"bool","name":"marketClosed","type":"bool"}],"name":"ExchangeRatesUpdatedByRobot","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"messageId","type":"bytes32"}],"name":"FailedMessageProcessed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"oldFeeReceiver","type":"address"},{"indexed":true,"internalType":"address","name":"newFeeReceiver","type":"address"}],"name":"FeeReceiverChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"fiatToken","type":"address"}],"name":"FiatTokenAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"fiatToken","type":"address"},{"indexed":true,"internalType":"uint256","name":"rateUsdcToFiat","type":"uint256"}],"name":"FiatTokenAndRateAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"oldFee","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"newFee","type":"uint256"}],"name":"FixedNativeFeeUpdated","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"aggregator","type":"address"},{"indexed":true,"internalType":"bytes4","name":"selector","type":"bytes4"},{"indexed":false,"internalType":"bool","name":"isWhitelisted","type":"bool"}],"name":"FunctionSelectorWhitelisted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"messageId","type":"bytes32"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"MessageFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"srcEid","type":"uint32"},{"indexed":true,"internalType":"bytes32","name":"messageId","type":"bytes32"}],"name":"MessageProcessed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"messageId","type":"bytes32"},{"indexed":false,"internalType":"bool","name":"success","type":"bool"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"MessageRetried","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"}],"name":"MoneyExchangedExactIn","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"}],"name":"MoneyExchangedExactOut","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":"address","name":"account","type":"address"}],"name":"Paused","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":"address","name":"owner","type":"address"},{"indexed":true,"internalType":"address","name":"spender","type":"address"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"PermitFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"messageId","type":"bytes32"},{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"usdcAmount","type":"uint256"}],"name":"RefundProcessFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"uint256","name":"usdcAmount","type":"uint256"}],"name":"RefundProcessed","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"messageId","type":"bytes32"}],"name":"RefundRetried","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint32","name":"srcEid","type":"uint32"},{"indexed":true,"internalType":"bytes32","name":"srcOApp","type":"bytes32"},{"indexed":false,"internalType":"string","name":"reason","type":"string"}],"name":"RefundSent","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"}],"name":"SentDepositedEth","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":true,"internalType":"address","name":"inputToken","type":"address"},{"indexed":true,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"usdcAmount","type":"uint256"},{"indexed":false,"internalType":"address","name":"aggregator","type":"address"}],"name":"SentDepositedTokenViaAggregator","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"}],"name":"SentDepositedTokenViaEth","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"sender","type":"address"},{"indexed":false,"internalType":"address","name":"inputToken","type":"address"},{"indexed":false,"internalType":"address","name":"outputToken","type":"address"},{"indexed":false,"internalType":"uint256","name":"inputAmount","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"outputAmount","type":"uint256"}],"name":"SentDepositedTokenViaUsd","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"user","type":"address"},{"indexed":true,"internalType":"address","name":"tokenIn","type":"address"},{"indexed":true,"internalType":"address","name":"tokenOut","type":"address"},{"indexed":false,"internalType":"uint256","name":"amountIn","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"amountOut","type":"uint256"}],"name":"SwapExecuted","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"oldAddress","type":"address"},{"indexed":false,"internalType":"address","name":"newAddress","type":"address"}],"name":"UsdcDepositAddressChanged","type":"event"},{"inputs":[],"name":"CASH_OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_DIGITS","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_FEE_AMOUNT_USDC","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"MAX_RETRY_COUNT","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"OPERATOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSE_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_FACTORY","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_PERIPHERY_PAYMENTS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_QUOTER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNISWAP_ROUTER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"UNPAUSE_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_fiatToken","type":"address"}],"name":"addFiatToken","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":"origin","type":"tuple"}],"name":"allowInitializePath","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_maxUsdcDepositAmount","type":"uint256"}],"name":"changeMaxUsdcDepositAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_minUsdcDepositAmount","type":"uint256"}],"name":"changeMinUsdcDepositAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_usdcAddress","type":"address"}],"name":"changeUsdcAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_usdcDepositAddress","type":"address"}],"name":"changeUsdcDepositAddress","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cnh24","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"uint16","name":"_msgType","type":"uint16"},{"internalType":"bytes","name":"_extraOptions","type":"bytes"}],"name":"combineOptions","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"nativeFee","type":"uint256"},{"internalType":"uint256","name":"_amountOutMinimum","type":"uint256"}],"name":"depositETH","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_targetAccount","type":"address"},{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"nativeFee","type":"uint256"},{"internalType":"uint256","name":"_amountOutMinimum","type":"uint256"}],"name":"depositETHToAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_aggregator","type":"address"},{"internalType":"bytes","name":"_swapCalldata","type":"bytes"},{"internalType":"uint256","name":"_minUsdcAmount","type":"uint256"},{"internalType":"uint256","name":"_feeAmountViaUsdc","type":"uint256"}],"name":"depositTokenViaAggregator","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_targetAccount","type":"address"},{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"address","name":"_aggregator","type":"address"},{"internalType":"bytes","name":"_swapCalldata","type":"bytes"},{"internalType":"uint256","name":"_minUsdcAmount","type":"uint256"}],"name":"depositTokenViaAggregatorToAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_amountOutMinimum","type":"uint256"}],"name":"depositTokenViaUsdc","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"_targetAccount","type":"address"},{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_amountOutMinimum","type":"uint256"}],"name":"depositTokenViaUsdcToAccount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"dstId","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"endpoint","outputs":[{"internalType":"contract ILayerZeroEndpointV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"uint16","name":"_msgType","type":"uint16"}],"name":"enforcedOptions","outputs":[{"internalType":"bytes","name":"","type":"bytes"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"f24AirdropPaused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"f24AirdropStart","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"f24PerUSDC","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"failedMessages","outputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"uint256","name":"usdcAmount","type":"uint256"},{"internalType":"address","name":"outputToken","type":"address"},{"internalType":"uint256","name":"retryCount","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"feeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"address","name":"_outputToken","type":"address"}],"name":"getPoolFeeOfMostLiquidPool","outputs":[{"internalType":"uint24","name":"","type":"uint24"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint24","name":"_fee","type":"uint24"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"getQuote","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","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":"","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":[{"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":[],"name":"maxUsdcDepositAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"minUsdcDepositAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","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":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"}],"name":"peers","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"userAddress","type":"address"},{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"address","name":"_outputToken","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"},{"internalType":"uint256","name":"_amountOutMinimum","type":"uint256"},{"internalType":"uint256","name":"_feeAmountViaUsdc","type":"uint256"},{"internalType":"uint256","name":"_deadline","type":"uint256"},{"internalType":"uint8","name":"_v","type":"uint8"},{"internalType":"bytes32","name":"_r","type":"bytes32"},{"internalType":"bytes32","name":"_s","type":"bytes32"}],"name":"permitAndDepositTokenViaUsdc","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_dstEid","type":"uint32"},{"internalType":"address","name":"_userAddress","type":"address"},{"internalType":"address","name":"_inputToken","type":"address"},{"internalType":"uint256","name":"_inputAmount","type":"uint256"},{"internalType":"uint256","name":"_usdcAmount","type":"uint256"},{"internalType":"address","name":"_outputToken","type":"address"}],"name":"quoteLayerzeroFee","outputs":[{"components":[{"internalType":"uint256","name":"nativeFee","type":"uint256"},{"internalType":"uint256","name":"lzTokenFee","type":"uint256"}],"internalType":"struct MessagingFee","name":"fee","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"relay_gas_limit","outputs":[{"internalType":"uint128","name":"","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_aggregator","type":"address"},{"internalType":"bool","name":"_isWhitelisted","type":"bool"}],"name":"setAggregatorWhitelist","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_delegate","type":"address"}],"name":"setDelegate","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"eid","type":"uint32"},{"internalType":"uint16","name":"msgType","type":"uint16"},{"internalType":"bytes","name":"options","type":"bytes"}],"internalType":"struct EnforcedOptionParam[]","name":"_enforcedOptions","type":"tuple[]"}],"name":"setEnforcedOptions","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_feeReceiver","type":"address"}],"name":"setFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_aggregator","type":"address"},{"internalType":"bytes4","name":"_selector","type":"bytes4"},{"internalType":"bool","name":"_isWhitelisted","type":"bool"}],"name":"setFunctionSelector","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":"uint128","name":"_newLimit","type":"uint128"}],"name":"setRelayGasLimit","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"slippage","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"usdc","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"usdcDepositAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"validXXX24Tokens","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"weth","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"whitelistedAggregators","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"},{"internalType":"bytes4","name":"","type":"bytes4"}],"name":"whitelistedSelectors","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"to","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawETH","outputs":[],"stateMutability":"nonpayable","type":"function"},{"stateMutability":"payable","type":"receive"}]Contract Creation Code
60a060405261013080546001600160801b03191665b416b3dec0001790553480156200002a57600080fd5b5060405162005a2238038062005a228339810160408190526200004d916200005f565b6001600160a01b031660805262000091565b6000602082840312156200007257600080fd5b81516001600160a01b03811681146200008a57600080fd5b9392505050565b60805161594b620000d76000396000818161075201528181611239015281816126d401528181613cf101528181613ed9015281816142900152614349015261594b6000f3fe6080604052600436106103455760003560e01c8063011f78c01461035157806301ffc9a71461037957806304f26978146103a9578063063286cc146103c057806306ff4eca146103f55780630caa0540146104175780630e4975dc1461042e578063100332da1461044e57806311aa773f1461046e57806313137d651461048157806317442b70146104945780631b723877146104b6578063248a9ca3146104e757806324fb9edf1461050757806326dad53c1461051c5780632c7692bd1461053c5780632f2ff15d146105705780632f5008f914610590578063309756fb146105b05780633400288b146105d257806336568abe146105f2578063389ed267146106125780633e032a3b146106345780633e413bee1461064b5780633f4ba83a1461066c5780633fc8cef314610681578063435f5bf9146106a25780634782f779146106b957806353012e5c146106d95780635535d461146106fb5780635c975abb146107285780635e280f111461074057806364fa5208146107745780636b77e75a146107875780636f34924d146107a7578063715018a6146107ba5780637d25a05e146107cf57806382413eac1461080a5780638456cb59146108395780638da5cb5b1461084e5780638f6ac9941461086357806391d148541461087a578063972d0bba1461089a578063983318d9146108b1578063a217fddf146108d2578063a4e7f8bd146108e7578063ae5e966a1461096d578063b24c7d2f14610980578063b268630b146109b1578063b3f00674146109d9578063b98bd070146109fa578063bb0b6a5314610a1a578063bc70b35414610a3a578063c0154ccb14610a5a578063c74c0fac14610a80578063c8a44efa14610aa8578063ca5eb5e114610ae4578063ce0b63ce14610b04578063d547741f14610b17578063d5da74cb14610b37578063d8264920146103c0578063dac500e314610b70578063e2e4859b14610b92578063e9b39e2a14610ba5578063ea63ac8814610bc5578063eeaa315e14610bff578063efdcd97414610c1f578063f0b41a1714610c3f578063f2fde38b14610c7a578063f5b541a614610c9a578063f7f1544514610cbc578063f80b0de914610cd7578063fbc2915f14610cf7578063ff7bd03d14610d0a57600080fd5b3661034c57005b600080fd5b34801561035d57600080fd5b50610366600381565b6040519081526020015b60405180910390f35b34801561038557600080fd5b5061039961039436600461465b565b610d2a565b6040519015158152602001610370565b3480156103b557600080fd5b506103666101375481565b3480156103cc57600080fd5b506103e873e592427a0aece92de3edee1f18e0157c0586156481565b6040516103709190614676565b34801561040157600080fd5b506104156104103660046146ad565b610d61565b005b34801561042357600080fd5b506103666101325481565b34801561043a57600080fd5b5061041561044936600461470b565b610e8a565b34801561045a57600080fd5b50610415610469366004614728565b610f3a565b61036661047c366004614761565b610fe2565b61041561048f366004614861565b611237565b3480156104a057600080fd5b5060408051600181526002602082015201610370565b3480156104c257600080fd5b506103996104d1366004614900565b6101336020526000908152604090205460ff1681565b3480156104f357600080fd5b5061036661050236600461491d565b6112d7565b34801561051357600080fd5b50610366600581565b34801561052857600080fd5b50610415610537366004614900565b6112ec565b34801561054857600080fd5b5061055c610557366004614936565b611401565b60405162ffffff9091168152602001610370565b34801561057c57600080fd5b5061041561058b366004614964565b61187c565b34801561059c57600080fd5b506104156105ab366004614900565b61189e565b3480156105bc57600080fd5b506103666000805160206158b683398151915281565b3480156105de57600080fd5b506104156105ed36600461499d565b61191f565b3480156105fe57600080fd5b5061041561060d366004614964565b6119b2565b34801561061e57600080fd5b506103666000805160206158f683398151915281565b34801561064057600080fd5b5061036661012f5481565b34801561065757600080fd5b5061012d546103e8906001600160a01b031681565b34801561067857600080fd5b50610415611a30565b34801561068d57600080fd5b5061012e546103e8906001600160a01b031681565b3480156106ae57600080fd5b50610366624c4b4081565b3480156106c557600080fd5b506104156106d43660046149c7565b611a71565b3480156106e557600080fd5b506103666000805160206158d683398151915281565b34801561070757600080fd5b5061071b6107163660046149f7565b611bc3565b6040516103709190614a7a565b34801561073457600080fd5b5060fb5460ff16610399565b34801561074c57600080fd5b506103e87f000000000000000000000000000000000000000000000000000000000000000081565b610366610782366004614a8d565b611c87565b34801561079357600080fd5b506103666107a2366004614b20565b611eb4565b6103666107b5366004614b79565b611f61565b3480156107c657600080fd5b506104156120f9565b3480156107db57600080fd5b506107f26107ea36600461499d565b600092915050565b6040516001600160401b039091168152602001610370565b34801561081657600080fd5b50610399610825366004614c17565b6001600160a01b0381163014949350505050565b34801561084557600080fd5b50610415612132565b34801561085a57600080fd5b506103e8612171565b34801561086f57600080fd5b506103666101365481565b34801561088657600080fd5b50610399610895366004614964565b612180565b3480156108a657600080fd5b506103666101315481565b3480156108bd57600080fd5b50610134546103e8906001600160a01b031681565b3480156108de57600080fd5b50610366600081565b3480156108f357600080fd5b5061093861090236600461491d565b61013a6020526000908152604090208054600182015460028301546003909301546001600160a01b039283169391929091169084565b60405161037094939291906001600160a01b039485168152602081019390935292166040820152606081019190915260800190565b61036661097b366004614c7d565b6121ab565b34801561098c57600080fd5b5061039961099b366004614900565b61013b6020526000908152604090205460ff1681565b3480156109bd57600080fd5b506103e873b27308f9f90d607463bb33ea1bebb41c27ce5ab681565b3480156109e557600080fd5b50610135546103e8906001600160a01b031681565b348015610a0657600080fd5b50610415610a15366004614cc3565b612348565b348015610a2657600080fd5b50610366610a35366004614d37565b6124e5565b348015610a4657600080fd5b5061071b610a55366004614d52565b61250d565b348015610a6657600080fd5b50610138546103e89061010090046001600160a01b031681565b348015610a8c57600080fd5b506103e8731f98431c8ad98523631ae4a59f267346ea31f98481565b348015610ab457600080fd5b50610399610ac3366004614db2565b61013c60209081526000928352604080842090915290825290205460ff1681565b348015610af057600080fd5b50610415610aff366004614900565b61268e565b610366610b12366004614dde565b61273e565b348015610b2357600080fd5b50610415610b32366004614964565b6128ca565b348015610b4357600080fd5b5061013954610b58906001600160801b031681565b6040516001600160801b039091168152602001610370565b348015610b7c57600080fd5b5061036660008051602061589683398151915281565b610366610ba0366004614e13565b6128e7565b348015610bb157600080fd5b50610415610bc0366004614900565b6129ea565b348015610bd157600080fd5b5061013854610bea90600160a81b900463ffffffff1681565b60405163ffffffff9091168152602001610370565b348015610c0b57600080fd5b50610415610c1a36600461491d565b612a7c565b348015610c2b57600080fd5b50610415610c3a366004614900565b612aa4565b348015610c4b57600080fd5b50610c5f610c5a366004614e6e565b612b6e565b60408051825181526020928301519281019290925201610370565b348015610c8657600080fd5b50610415610c95366004614900565b612be4565b348015610ca657600080fd5b5061036660008051602061585683398151915281565b348015610cc857600080fd5b50610138546103999060ff1681565b348015610ce357600080fd5b50610415610cf236600461491d565b612c84565b610366610d05366004614c7d565b612cac565b348015610d1657600080fd5b50610399610d25366004614edc565b612dac565b60006001600160e01b03198216637965db0b60e01b1480610d5b57506301ffc9a760e01b6001600160e01b03198316145b92915050565b610d7960008051602061589683398151915233612180565b610da257335b60405163c8c6739160e01b8152600401610d999190614676565b60405180910390fd5b6001600160a01b038316610dc85760405162461bcd60e51b8152600401610d9990614ef8565b6001600160e01b03198216610e125760405162461bcd60e51b815260206004820152601060248201526f24b73b30b634b21039b2b632b1ba37b960811b6044820152606401610d99565b6001600160a01b038316600081815261013c602090815260408083206001600160e01b0319871680855290835292819020805460ff191686151590811790915590519081529192917f9e96687030e30f2321bf19249e72129712de9ddb069afef9073a1c041ddd1b34910160405180910390a3505050565b6000816001600160801b031611610ee05760405162461bcd60e51b815260206004820152601a602482015279476173206c696d6974206d75737420626520706f73697469766560301b6044820152606401610d99565b610ef860008051602061585683398151915233612180565b610f175733604051630d86bd6960e31b8152600401610d999190614676565b61013980546001600160801b0319166001600160801b0392909216919091179055565b610f5260008051602061589683398151915233612180565b610f5c5733610d7f565b6001600160a01b038216610f825760405162461bcd60e51b8152600401610d9990614ef8565b6001600160a01b038216600081815261013b6020908152604091829020805460ff191685151590811790915591519182527f51372928fc73bc5fef2c5bc8324eef22ddcbc66388d34c91e02f1e67b97159bb910160405180910390a25050565b6000600260c954036110065760405162461bcd60e51b8152600401610d9990614f2c565b600260c95560fb5460ff161561102f5760405163694974fb60e11b815260040160405180910390fd5b6110476000805160206158d683398151915233612180565b6110665733604051635f9a666760e01b8152600401610d999190614676565b8760000361108657604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0389166000908152610133602052604090205460ff166110c2578860405163f5f4c28560e01b8152600401610d999190614676565b60405163d505accf60e01b81526001600160a01b038c81166004830152306024830152604482018a90526064820187905260ff8616608483015260a4820185905260c482018490528b169063d505accf9060e401600060405180830381600087803b15801561113057600080fd5b505af1925050508015611141575060015b61119357896001600160a01b03168b6001600160a01b03167f41f0da1ed8de0c51316538bf937ef0b5c7a06c31314a48e6fb2cf6dcea63ff468a60405161118a91815260200190565b60405180910390a35b61119f8a8c308b612dca565b60006111ae8b8a8a6000612ed8565b905060006111bc828961321a565b61012d54610134549192506111de916001600160a01b039182169116836132d2565b6111ed8d8d8c848f34336133d5565b8c6001600160a01b03166000805160206158368339815191528d8d8d8560405161121a9493929190614f63565b60405180910390a2600160c9559c9b505050505050505050505050565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316331461128257336040516391ac5e4f60e01b8152600401610d999190614676565b6020870180359061129c90611297908a614d37565b613463565b146112ce576112ae6020880188614d37565b876020013560405163309afaf360e21b8152600401610d99929190614f8c565b50505050505050565b60009081526097602052604090206001015490565b61130460008051602061589683398151915233612180565b61130e5733610d7f565b6001600160a01b0381166113535760405162461bcd60e51b815260206004820152600c60248201526b5a65726f206164647265737360a01b6044820152606401610d99565b6001600160a01b0381166000908152610133602052604090205460ff16156113b45760405162461bcd60e51b815260206004820152601460248201527320b63932b0b23c9032bc34b9ba39903a37b5b2b760611b6044820152606401610d99565b6001600160a01b03811660008181526101336020526040808220805460ff19166001179055517fce808c9c7545c7368fc6718785202de20d7d581f6e9d1009d9c0282e781a8fe79190a250565b604051630b4c774160e11b815260009081908190819081908190731f98431c8ad98523631ae4a59f267346ea31f98490631698ee829061144a908b908b90606490600401614fa2565b602060405180830381865afa158015611467573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148b9190614fca565b90506001600160a01b0381161561152557809150816001600160a01b0316631a6865026040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114dd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115019190614fe7565b9250836001600160801b0316836001600160801b0316111561152557829350606494505b604051630b4c774160e11b8152731f98431c8ad98523631ae4a59f267346ea31f98490631698ee8290611562908b908b906101f490600401614fa2565b602060405180830381865afa15801561157f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115a39190614fca565b90506001600160a01b0381161561163e57809150816001600160a01b0316631a6865026040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116199190614fe7565b9250836001600160801b0316836001600160801b0316111561163e578293506101f494505b604051630b4c774160e11b8152731f98431c8ad98523631ae4a59f267346ea31f98490631698ee829061167b908b908b90610bb890600401614fa2565b602060405180830381865afa158015611698573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116bc9190614fca565b90506001600160a01b0381161561175757809150816001600160a01b0316631a6865026040518163ffffffff1660e01b8152600401602060405180830381865afa15801561170e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117329190614fe7565b9250836001600160801b0316836001600160801b0316111561175757829350610bb894505b604051630b4c774160e11b8152731f98431c8ad98523631ae4a59f267346ea31f98490631698ee8290611794908b908b9061271090600401614fa2565b602060405180830381865afa1580156117b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117d59190614fca565b90506001600160a01b0381161561187057809150816001600160a01b0316631a6865026040518163ffffffff1660e01b8152600401602060405180830381865afa158015611827573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184b9190614fe7565b9250836001600160801b0316836001600160801b031611156118705782935061271094505b50929695505050505050565b611885826112d7565b61188f81336134b4565b6118998383613518565b505050565b6118b660008051602061589683398151915233612180565b6118c05733610d7f565b61013480546001600160a01b038381166001600160a01b0319831681179093556040519116917f333d753eb88dfde031e8da4385e0440b26920614852643bc6c80e79718dac36d91611913918491615004565b60405180910390a15050565b33611928612171565b6001600160a01b03161461194e5760405162461bcd60e51b8152600401610d999061501e565b600061195861359e565b63ffffffff841660009081526020829052604090819020849055519091507f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b906119a59085908590614f8c565b60405180910390a1505050565b6001600160a01b0381163314611a225760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610d99565b611a2c82826135c2565b5050565b611a486000805160206158b683398151915233612180565b611a67573360405163a8688f7360e01b8152600401610d999190614676565b611a6f613629565b565b611a8960008051602061589683398151915233612180565b611a935733610d7f565b6001600160a01b038216611add5760405162461bcd60e51b8152602060048201526011602482015270125b9d985b1a59081c9958da5c1a595b9d607a1b6044820152606401610d99565b80471015611b285760405162461bcd60e51b8152602060048201526018602482015277496e73756666696369656e74204554482062616c616e636560401b6044820152606401610d99565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611b75576040519150601f19603f3d011682016040523d82523d6000602084013e611b7a565b606091505b50509050806118995760405162461bcd60e51b8152602060048201526015602482015274115512081dda5d1a191c985dd85b0819985a5b1959605a1b6044820152606401610d99565b60606000611bcf6136b6565b63ffffffff851660009081526020828152604080832061ffff881684529091529020805491925090611c0090615053565b80601f0160208091040260200160405190810160405280929190818152602001828054611c2c90615053565b8015611c795780601f10611c4e57610100808354040283529160200191611c79565b820191906000526020600020905b815481529060010190602001808311611c5c57829003601f168201915b505050505091505092915050565b6000600260c95403611cab5760405162461bcd60e51b8152600401610d9990614f2c565b600260c95560fb5460ff1615611cd45760405163694974fb60e11b815260040160405180910390fd5b86600003611cf457604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0388166000908152610133602052604090205460ff16611d30578760405163f5f4c28560e01b8152600401610d999190614676565b3360006001600160a01b038b161580611d65575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038c16145b15611d9a57883411611d8957604051620abbb960e61b815260040160405180910390fd5b611d93893461509d565b9050611dc8565b34600003611dba57604051620abbb960e61b815260040160405180910390fd5b5034611dc88b83308c612dca565b600080611dd98d8c8c8c8c8c6136da565b9050611de5818761321a565b61012d5461013454919350611e07916001600160a01b039182169116846132d2565b50611e2d838d8c848f8761013560009054906101000a90046001600160a01b03166133d5565b8a6001600160a01b03168c6001600160a01b0316846001600160a01b03167f6bf40e12ef47210fe525b39720a1b2d058c7015139c26c39860951e220cdf1838d858e604051611e989392919092835260208301919091526001600160a01b0316604082015260600190565b60405180910390a4600160c9559b9a5050505050505050505050565b60405163f7729d4360e01b81526001600160a01b0380861660048301528416602482015262ffffff83166044820152606481018290526000608482018190529073b27308f9f90d607463bb33ea1bebb41c27ce5ab69063f7729d439060a4016020604051808303816000875af1158015611f32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f5691906150b0565b90505b949350505050565b6000600260c95403611f855760405162461bcd60e51b8152600401610d9990614f2c565b600260c955851580611f95575034155b15611fb257604051620abbb960e61b815260040160405180910390fd5b611fbc8988613a4f565b3360006001600160a01b038a161580611ff1575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b16145b156120265787341161201557604051620abbb960e61b815260040160405180910390fd5b61201f883461509d565b9050612034565b50346120348a83308b612dca565b60006120448b8a8a8a8a8a6136da565b90508060000361206757604051639b29a93160e01b815260040160405180910390fd5b6120758c8c8b848e87613ad5565b8b6001600160a01b03166000805160206158368339815191528c8c8c856040516120a29493929190614f63565b60405180910390a28b6001600160a01b0316836001600160a01b03166000805160206158168339815191528d8c6040516120dd9291906150c9565b60405180910390a3600160c9559b9a5050505050505050505050565b33612102612171565b6001600160a01b0316146121285760405162461bcd60e51b8152600401610d999061501e565b611a6f6000613b57565b61214a6000805160206158f683398151915233612180565b612169573360405163af41226f60e01b8152600401610d999190614676565b611a6f613ba9565b6033546001600160a01b031690565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000600260c954036121cf5760405162461bcd60e51b8152600401610d9990614f2c565b600260c95560fb5460ff16156121f85760405163694974fb60e11b815260040160405180910390fd5b8260000361221857604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0384166000908152610133602052604090205460ff16612254578360405163f5f4c28560e01b8152600401610d999190614676565b61226185335b3086612dca565b60006122708685856000612ed8565b90506101315481111561229c57610131546040516375889fd760e11b8152610d999183916004016150e2565b610132548110156122c6576101325460405163444ed8a560e11b8152610d999183916004016150e2565b61012d54610134546122e5916001600160a01b039081169116836132d2565b61230533610135548890879085908a9034906001600160a01b03166133d5565b336001600160a01b0316600080516020615836833981519152878787856040516123329493929190614f63565b60405180910390a2600160c95595945050505050565b33612351612171565b6001600160a01b0316146123775760405162461bcd60e51b8152600401610d999061501e565b60006123816136b6565b905060005b828110156124b3576123c88484838181106123a3576123a36150f0565b90506020028101906123b59190615106565b6123c3906040810190615126565b613c24565b8383828181106123da576123da6150f0565b90506020028101906123ec9190615106565b6123fa906040810190615126565b83600087878681811061240f5761240f6150f0565b90506020028101906124219190615106565b61242f906020810190614d37565b63ffffffff1663ffffffff168152602001908152602001600020600087878681811061245d5761245d6150f0565b905060200281019061246f9190615106565b61248090604081019060200161516c565b61ffff1681526020810191909152604001600020916124a09190836151e3565b50806124ab816152a2565b915050612386565b507fbe4864a8e820971c0247f5992e2da559595f7bf076a21cb5928d443d2a13b67483836040516119a59291906152e4565b6000806124f061359e565b63ffffffff90931660009081526020939093525050604090205490565b606060006125196136b6565b63ffffffff871660009081526020828152604080832061ffff8a16845290915281208054929350909161254b90615053565b80601f016020809104026020016040519081016040528092919081815260200182805461257790615053565b80156125c45780601f10612599576101008083540402835291602001916125c4565b820191906000526020600020905b8154815290600101906020018083116125a757829003601f168201915b5050505050905080516000036126155784848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550611f59945050505050565b6000849003612627579150611f599050565b60028410612671576126398585613c24565b8061264785600281896153c8565b604051602001612659939291906153f2565b60405160208183030381529060405292505050611f59565b8484604051639a6d49cd60e01b8152600401610d9992919061541a565b33612697612171565b6001600160a01b0316146126bd5760405162461bcd60e51b8152600401610d999061501e565b60405163ca5eb5e160e01b81526001600160a01b037f0000000000000000000000000000000000000000000000000000000000000000169063ca5eb5e190612709908490600401614676565b600060405180830381600087803b15801561272357600080fd5b505af1158015612737573d6000803e3d6000fd5b5050505050565b6000600260c954036127625760405162461bcd60e51b8152600401610d9990614f2c565b600260c95560fb5460ff161561278b5760405163694974fb60e11b815260040160405180910390fd5b346000036127ab57604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0384166000908152610133602052604090205460ff166127e7578360405163f5f4c28560e01b8152600401610d999190614676565b60006127f3843461509d565b61012e54909150600090612813906001600160a01b031683866001612ed8565b90506101315481111561283f57610131546040516375889fd760e11b8152610d999183916004016150e2565b61013254811015612869576101325460405163444ed8a560e11b8152610d999183916004016150e2565b61012d5461013454612888916001600160a01b039081169116836132d2565b61289833600084848a8a336133d5565b61012e54604051339160008051602061587683398151915291612332916001600160a01b0316908a9087908790614f63565b6128d3826112d7565b6128dd81336134b4565b61189983836135c2565b6000600260c9540361290b5760405162461bcd60e51b8152600401610d9990614f2c565b600260c95582158061291b575034155b1561293857604051620abbb960e61b815260040160405180910390fd5b6129428685613a4f565b61294c853361225a565b600061295b8685856000612ed8565b905061296b878786848934613ad5565b866001600160a01b0316600080516020615836833981519152878787856040516129989493929190614f63565b60405180910390a26001600160a01b038716336001600160a01b031660008051602061581683398151915288876040516129d39291906150c9565b60405180910390a3600160c9559695505050505050565b612a0260008051602061589683398151915233612180565b612a0c5733610d7f565b6001600160a01b038116612a595760405162461bcd60e51b8152602060048201526014602482015273496e76616c69642075736463206164647265737360601b6044820152606401610d99565b61012d80546001600160a01b0319166001600160a01b0392909216919091179055565b612a9460008051602061589683398151915233612180565b612a9e5733610d7f565b61013255565b612abc60008051602061589683398151915233612180565b612ac65733610d7f565b6001600160a01b038116612b1b5760405162461bcd60e51b815260206004820152601c60248201527b496e76616c696420666565207265636569766572206164647265737360201b6044820152606401610d99565b61013580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907fa4b009cc442411b602eaf94bc0579b6abdb8fd90b4ef5b9426e270038906bd0390600090a35050565b612b76614600565b60008686868686604051602001612b9195949392919061542e565b60408051601f1981840301815291905261013954909150600090612bc8906001600160801b031682612bc1613c66565b9190613c89565b9050612bd78983836000613ce7565b9998505050505050505050565b33612bed612171565b6001600160a01b031614612c135760405162461bcd60e51b8152600401610d999061501e565b6001600160a01b038116612c785760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610d99565b612c8181613b57565b50565b612c9c60008051602061589683398151915233612180565b612ca65733610d7f565b61013155565b6000600260c95403612cd05760405162461bcd60e51b8152600401610d9990614f2c565b600260c95534600003612cf557604051620abbb960e61b815260040160405180910390fd5b612cff8585613a4f565b6000612d0b843461509d565b61012e54909150600090612d2b906001600160a01b031683866001612ed8565b9050612d3c87600084848a8a613ad5565b61012e546040516001600160a01b038981169260008051602061587683398151915292612d7292909116908a9087908790614f63565b60405180910390a261012e546040516001600160a01b03898116923392600080516020615816833981519152926129d392169087906150c9565b600060208201803590612dc390610a359085614d37565b1492915050565b600080856001600160a01b03166323b872dd60e01b868686604051602401612df49392919061545e565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051612e329190615482565b6000604051808303816000865af19150503d8060008114612e6f576040519150601f19603f3d011682016040523d82523d6000602084013e612e74565b606091505b5091509150818015612e9e575080511580612e9e575080806020019051810190612e9e9190615494565b612ed05760405162461bcd60e51b815260206004820152600360248201526229aa2360e91b6044820152606401610d99565b505050505050565b61012d546000906001600160a01b0390811690861603612ef9575082611f59565b61012d54600090612f149087906001600160a01b0316611401565b90508062ffffff16600003612f4e5761012d5460405163a4ea635160e01b8152610d999188916001600160a01b0390911690600401615004565b82612f7257612f728673e592427a0aece92de3edee1f18e0157c0586156487613db3565b60408051610100810182526001600160a01b03808916825261012d5416602082015262ffffff83169181019190915230606082015260009060808101612fb942600f6154b1565b815260200187815260200186815260200160006001600160a01b0316815250905083156131735760405163414bf38960e01b815273e592427a0aece92de3edee1f18e0157c058615649063414bf3899088906130199085906004016154c4565b60206040518083038185885af1158015613037573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061305c91906150b0565b92508260000361307f57604051639b29a93160e01b815260040160405180910390fd5b600047905073e592427a0aece92de3edee1f18e0157c058615646001600160a01b03166312210e8a6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156130d357600080fd5b505af11580156130e7573d6000803e3d6000fd5b50505050600081476130f9919061509d565b9050801561316c57604051600090339083908381818185875af1925050503d8060008114613143576040519150601f19603f3d011682016040523d82523d6000602084013e613148565b606091505b505090508061316a57604051631390f2fb60e21b815260040160405180910390fd5b505b5050613210565b60405163414bf38960e01b815273e592427a0aece92de3edee1f18e0157c058615649063414bf389906131aa9084906004016154c4565b6020604051808303816000875af11580156131c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131ed91906150b0565b92508260000361321057604051639b29a93160e01b815260040160405180910390fd5b5050949350505050565b6000624c4b40821061322d57624c4b4091505b8282106132515781836040516306dcf1e160e51b8152600401610d999291906150e2565b61325b828461509d565b90506101315481111561328757610131546040516375889fd760e11b8152610d999183916004016150e2565b610132548110156132b1576101325460405163444ed8a560e11b8152610d999183916004016150e2565b8115610d5b5761012d5461013554610d5b916001600160a01b039081169116845b600080846001600160a01b031663a9059cbb60e01b85856040516024016132fa9291906150c9565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516133389190615482565b6000604051808303816000865af19150503d8060008114613375576040519150601f19603f3d011682016040523d82523d6000602084013e61337a565b606091505b50915091508180156133a45750805115806133a45750808060200190518101906133a49190615494565b6127375760405162461bcd60e51b815260206004820152600260248201526114d560f21b6044820152606401610d99565b600087878787876040516020016133f095949392919061542e565b60408051601f1981840301815291905261013954909150600090613420906001600160801b031682612bc1613c66565b6040805180820190915285815260006020820152610138549192509061345690600160a81b900463ffffffff1684848488613eb6565b5050505050505050505050565b60008061346e61359e565b63ffffffff8416600090815260208290526040902054909150806134ad5760405163f6ff4fb760e01b815263ffffffff85166004820152602401610d99565b9392505050565b6134be8282612180565b611a2c576134d6816001600160a01b03166014613fb1565b6134e1836020613fb1565b6040516020016134f292919061552d565b60408051601f198184030181529082905262461bcd60e51b8252610d9991600401614a7a565b6135228282612180565b611a2c5760008281526097602090815260408083206001600160a01b03851684529091529020805460ff1916600117905561355a3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b7f72ab1bc1039b79dc4724ffca13de82c96834302d3c7e0d4252232d4b2dd8f90090565b6135cc8282612180565b15611a2c5760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60fb5460ff166136725760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610d99565b60fb805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516136ac9190614676565b60405180910390a1565b7f8d2bda5d9f6ffb5796910376005392955773acee5548d0fcdb10e7c264ea000090565b61012d546000906001600160a01b03908116908816036136fb575084613a45565b6001600160a01b038516600090815261013b602052604090205460ff1661373757846040516334562a4560e01b8152600401610d999190614676565b60048310156137595760405163021e529960e61b815260040160405180910390fd5b600061376860048286886153c8565b6137719161559c565b6001600160a01b038716600090815261013c602090815260408083206001600160e01b03198516845290915290205490915060ff166137cf57604051630d84d4df60e21b81526001600160e01b031982166004820152602401610d99565b61012d546040516370a0823160e01b81526000916001600160a01b0316906370a0823190613801903090600401614676565b602060405180830381865afa15801561381e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061384291906150b0565b90506001600160a01b0389161580613876575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a16145b15613902576000876001600160a01b03168988886040516138989291906155cc565b60006040518083038185875af1925050503d80600081146138d5576040519150601f19603f3d011682016040523d82523d6000602084013e6138da565b606091505b50509050806138fc57604051635c827c7f60e11b815260040160405180910390fd5b5061399b565b61390d89888a613db3565b6000876001600160a01b031687876040516139299291906155cc565b6000604051808303816000865af19150503d8060008114613966576040519150601f19603f3d011682016040523d82523d6000602084013e61396b565b606091505b505090508061398d57604051635c827c7f60e11b815260040160405180910390fd5b6139998a896000613db3565b505b61012d546040516370a0823160e01b81526000916001600160a01b0316906370a08231906139cd903090600401614676565b602060405180830381865afa1580156139ea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a0e91906150b0565b9050613a1a828261509d565b935084841015613a41578385604051635099d57f60e01b8152600401610d999291906150e2565b5050505b9695505050505050565b60fb5460ff1615613a735760405163694974fb60e11b815260040160405180910390fd5b6001600160a01b038216613a9957604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0381166000908152610133602052604090205460ff16611a2c578060405163f5f4c28560e01b8152600401610d999190614676565b61013154831115613aff57610131546040516375889fd760e11b8152610d999185916004016150e2565b61013254831015613b29576101325460405163444ed8a560e11b8152610d999185916004016150e2565b61012d5461013454613b48916001600160a01b039081169116856132d2565b612ed0868686868686336133d5565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60fb5460ff1615613bef5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610d99565b60fb805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861369f3390565b6000613c3360028284866153c8565b613c3c916155dc565b60f01c905060038114611899578282604051639a6d49cd60e01b8152600401610d9992919061541a565b60408051600360f01b602082015281516002818303018152602290910190915290565b6060836003613c9982600061414c565b61ffff1614613ccd57613cad81600061414c565b604051633a51740d60e01b815261ffff9091166004820152602401610d99565b6000613cd985856141a9565b9050613a4586600183614221565b613cef614600565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663ddc28c586040518060a001604052808863ffffffff168152602001613d3e89613463565b8152602001878152602001868152602001851515815250306040518363ffffffff1660e01b8152600401613d7392919061560a565b6040805180830381865afa158015613d8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f5691906156d1565b600080846001600160a01b031663095ea7b360e01b8585604051602401613ddb9291906150c9565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613e199190615482565b6000604051808303816000865af19150503d8060008114613e56576040519150601f19603f3d011682016040523d82523d6000602084013e613e5b565b606091505b5091509150818015613e85575080511580613e85575080806020019051810190613e859190615494565b6127375760405162461bcd60e51b8152602060048201526002602482015261534160f01b6044820152606401610d99565b613ebe61461a565b8251602084015115613ed757613ed7846020015161428c565b7f00000000000000000000000000000000000000000000000000000000000000006001600160a01b0316632637a450826040518060a001604052808b63ffffffff168152602001613f278c613463565b81526020018a815260200189815260200160008960200151111515815250866040518463ffffffff1660e01b8152600401613f6392919061560a565b60806040518083038185885af1158015613f81573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190613fa691906156ed565b979650505050505050565b60606000613fc083600261575e565b613fcb9060026154b1565b6001600160401b03811115613fe257613fe2615187565b6040519080825280601f01601f19166020018201604052801561400c576020820181803683370190505b509050600360fc1b81600081518110614027576140276150f0565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110614056576140566150f0565b60200101906001600160f81b031916908160001a905350600061407a84600261575e565b6140859060016154b1565b90505b60018111156140fd576f181899199a1a9b1b9c1cb0b131b232b360811b85600f16601081106140b9576140b96150f0565b1a60f81b8282815181106140cf576140cf6150f0565b60200101906001600160f81b031916908160001a90535060049490941c936140f681615775565b9050614088565b5083156134ad5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610d99565b60006141598260026154b1565b835110156141a05760405162461bcd60e51b8152602060048201526014602482015273746f55696e7431365f6f75744f66426f756e647360601b6044820152606401610d99565b50016002015190565b60606001600160801b038216156141f157604080516001600160801b0319608086811b8216602084015285901b166030820152016040516020818303038152906040526134ad565b6040516001600160801b0319608085901b1660208201526030016040516020818303038152906040529392505050565b606083600361423182600061414c565b61ffff161461424557613cad81600061414c565b846001614252855161436e565b61425d90600161578c565b86866040516020016142739594939291906157ae565b6040516020818303038152906040529150509392505050565b60007f00000000000000000000000000000000000000000000000000000000000000006001600160a01b031663e4fe1d946040518163ffffffff1660e01b8152600401602060405180830381865afa1580156142ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143109190614fca565b90506001600160a01b038116614339576040516329b99a9560e11b815260040160405180910390fd5b611a2c6001600160a01b038216337f0000000000000000000000000000000000000000000000000000000000000000856143d5565b600061ffff8211156143d15760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b6064820152608401610d99565b5090565b61442d846323b872dd60e01b8585856040516024016143f69392919061545e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614433565b50505050565b6000614488826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166145059092919063ffffffff16565b80519091501561189957808060200190518101906144a69190615494565b6118995760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610d99565b6060611f59848460008585843b61455e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610d99565b600080866001600160a01b0316858760405161457a9190615482565b60006040518083038185875af1925050503d80600081146145b7576040519150601f19603f3d011682016040523d82523d6000602084013e6145bc565b606091505b5091509150613fa6828286606083156145d65750816134ad565b8251156145e65782518084602001fd5b8160405162461bcd60e51b8152600401610d999190614a7a565b604051806040016040528060008152602001600081525090565b6040805160608101825260008082526020820152908101614639614600565b905290565b80356001600160e01b03198116811461465657600080fd5b919050565b60006020828403121561466d57600080fd5b6134ad8261463e565b6001600160a01b0391909116815260200190565b6001600160a01b0381168114612c8157600080fd5b8015158114612c8157600080fd5b6000806000606084860312156146c257600080fd5b83356146cd8161468a565b92506146db6020850161463e565b915060408401356146eb8161469f565b809150509250925092565b6001600160801b0381168114612c8157600080fd5b60006020828403121561471d57600080fd5b81356134ad816146f6565b6000806040838503121561473b57600080fd5b82356147468161468a565b915060208301356147568161469f565b809150509250929050565b6000806000806000806000806000806101408b8d03121561478157600080fd5b8a3561478c8161468a565b995060208b013561479c8161468a565b985060408b01356147ac8161468a565b975060608b0135965060808b0135955060a08b0135945060c08b0135935060e08b013560ff811681146147de57600080fd5b809350506101008b013591506101208b013590509295989b9194979a5092959850565b60006060828403121561481357600080fd5b50919050565b60008083601f84011261482b57600080fd5b5081356001600160401b0381111561484257600080fd5b60208301915083602082850101111561485a57600080fd5b9250929050565b600080600080600080600060e0888a03121561487c57600080fd5b6148868989614801565b96506060880135955060808801356001600160401b03808211156148a957600080fd5b6148b58b838c01614819565b909750955060a08a013591506148ca8261468a565b90935060c089013590808211156148e057600080fd5b506148ed8a828b01614819565b989b979a50959850939692959293505050565b60006020828403121561491257600080fd5b81356134ad8161468a565b60006020828403121561492f57600080fd5b5035919050565b6000806040838503121561494957600080fd5b82356149548161468a565b915060208301356147568161468a565b6000806040838503121561497757600080fd5b8235915060208301356147568161468a565b803563ffffffff8116811461465657600080fd5b600080604083850312156149b057600080fd5b6149b983614989565b946020939093013593505050565b600080604083850312156149da57600080fd5b82356149b98161468a565b803561ffff8116811461465657600080fd5b60008060408385031215614a0a57600080fd5b614a1383614989565b9150614a21602084016149e5565b90509250929050565b60005b83811015614a45578181015183820152602001614a2d565b50506000910152565b60008151808452614a66816020860160208601614a2a565b601f01601f19169290920160200192915050565b6020815260006134ad6020830184614a4e565b60008060008060008060008060e0898b031215614aa957600080fd5b8835614ab48161468a565b97506020890135614ac48161468a565b9650604089013595506060890135614adb8161468a565b945060808901356001600160401b03811115614af657600080fd5b614b028b828c01614819565b999c989b5096999598969760a08701359660c0013595509350505050565b60008060008060808587031215614b3657600080fd5b8435614b418161468a565b93506020850135614b518161468a565b9250604085013562ffffff81168114614b6957600080fd5b9396929550929360600135925050565b60008060008060008060008060e0898b031215614b9557600080fd5b8835614ba08161468a565b97506020890135614bb08161468a565b96506040890135614bc08161468a565b9550606089013594506080890135614bd78161468a565b935060a08901356001600160401b03811115614bf257600080fd5b614bfe8b828c01614819565b999c989b50969995989497949560c00135949350505050565b60008060008060a08587031215614c2d57600080fd5b614c378686614801565b935060608501356001600160401b03811115614c5257600080fd5b614c5e87828801614819565b9094509250506080850135614c728161468a565b939692955090935050565b60008060008060808587031215614c9357600080fd5b8435614c9e8161468a565b93506020850135614cae8161468a565b93969395505050506040820135916060013590565b60008060208385031215614cd657600080fd5b82356001600160401b0380821115614ced57600080fd5b818501915085601f830112614d0157600080fd5b813581811115614d1057600080fd5b8660208260051b8501011115614d2557600080fd5b60209290920196919550909350505050565b600060208284031215614d4957600080fd5b6134ad82614989565b60008060008060608587031215614d6857600080fd5b614d7185614989565b9350614d7f602086016149e5565b925060408501356001600160401b03811115614d9a57600080fd5b614da687828801614819565b95989497509550505050565b60008060408385031215614dc557600080fd5b8235614dd08161468a565b9150614a216020840161463e565b600080600060608486031215614df357600080fd5b8335614dfe8161468a565b95602085013595506040909401359392505050565b600080600080600060a08688031215614e2b57600080fd5b8535614e368161468a565b94506020860135614e468161468a565b93506040860135614e568161468a565b94979396509394606081013594506080013592915050565b60008060008060008060c08789031215614e8757600080fd5b614e9087614989565b95506020870135614ea08161468a565b94506040870135614eb08161468a565b9350606087013592506080870135915060a0870135614ece8161468a565b809150509295509295509295565b600060608284031215614eee57600080fd5b6134ad8383614801565b6020808252601a9082015279496e76616c69642061676772656761746f72206164647265737360301b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b0394851681529290931660208301526040820152606081019190915260800190565b63ffffffff929092168252602082015260400190565b6001600160a01b03938416815291909216602082015262ffffff909116604082015260600190565b600060208284031215614fdc57600080fd5b81516134ad8161468a565b600060208284031215614ff957600080fd5b81516134ad816146f6565b6001600160a01b0392831681529116602082015260400190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c9082168061506757607f821691505b60208210810361481357634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b81810381811115610d5b57610d5b615087565b6000602082840312156150c257600080fd5b5051919050565b6001600160a01b03929092168252602082015260400190565b918252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b60008235605e1983360301811261511c57600080fd5b9190910192915050565b6000808335601e1984360301811261513d57600080fd5b8301803591506001600160401b0382111561515757600080fd5b60200191503681900382131561485a57600080fd5b60006020828403121561517e57600080fd5b6134ad826149e5565b634e487b7160e01b600052604160045260246000fd5b601f82111561189957600081815260208120601f850160051c810160208610156151c45750805b601f850160051c820191505b81811015612ed0578281556001016151d0565b6001600160401b038311156151fa576151fa615187565b61520e836152088354615053565b8361519d565b6000601f841160018114615242576000851561522a5750838201355b600019600387901b1c1916600186901b178355612737565b600083815260209020601f19861690835b828110156152735786850135825560209485019460019092019101615253565b50868210156152905760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b6000600182016152b4576152b4615087565b5060010190565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60208082528181018390526000906040808401600586901b8501820187855b888110156153ba57878303603f190184528135368b9003605e1901811261532957600080fd5b8a01606063ffffffff61533b83614989565b16855261ffff61534c8984016149e5565b168886015286820135601e1983360301811261536757600080fd5b9091018781019190356001600160401b0381111561538457600080fd5b80360383131561539357600080fd5b81888701526153a582870182856152bb565b96890196955050509186019150600101615303565b509098975050505050505050565b600080858511156153d857600080fd5b838611156153e557600080fd5b5050820193919092039150565b60008451615404818460208901614a2a565b8201838582376000930192835250909392505050565b602081526000611f596020830184866152bb565b6001600160a01b039586168152938516602085015260408401929092526060830152909116608082015260a00190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6000825161511c818460208701614a2a565b6000602082840312156154a657600080fd5b81516134ad8161469f565b80820180821115610d5b57610d5b615087565b81516001600160a01b03908116825260208084015182169083015260408084015162ffffff16908301526060808401518216908301526080808401519083015260a0838101519083015260c0808401519083015260e09283015116918101919091526101000190565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b81526000835161555f816017850160208801614a2a565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615590816028840160208801614a2a565b01602801949350505050565b6001600160e01b031981358181169160048510156155c45780818660040360031b1b83161692505b505092915050565b8183823760009101908152919050565b6001600160f01b031981358181169160028510156155c45760029490940360031b84901b1690921692915050565b6040815263ffffffff8351166040820152602083015160608201526000604084015160a0608084015261564060e0840182614a4e565b90506060850151603f198483030160a085015261565d8282614a4e565b60809690960151151560c08501525050506001600160a01b039190911660209091015290565b60006040828403121561569557600080fd5b604080519081016001600160401b03811182821017156156b7576156b7615187565b604052825181526020928301519281019290925250919050565b6000604082840312156156e357600080fd5b6134ad8383615683565b6000608082840312156156ff57600080fd5b604051606081016001600160401b03808211838310171561572257615722615187565b816040528451835260208501519150808216821461573f57600080fd5b5060208201526157528460408501615683565b60408201529392505050565b8082028115828204841417610d5b57610d5b615087565b60008161578457615784615087565b506000190190565b61ffff8181168382160190808211156157a7576157a7615087565b5092915050565b600086516157c0818460208b01614a2a565b6001600160f81b031960f888811b82169285019283526001600160f01b031960f089901b16600184015286901b1660038201528351615806816004840160208801614a2a565b0160040197965050505050505056feed5b6614ab4e245babbfe0af6033afad98c2d980a846b5852f117ec7c042e7b917d6f001db9e761de031511ef5b86376885cecce455165f34fc369223f10576a97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b929f908e8c9a42505e10f0a045312bdcf25a60d4f1a74ef534d1b6fc95e610e92e8a76ae24524824acbc21b351dd3e380dcc53874f0487c5ec4424767562c1192ee265b220c5a8891efdd9e1b1b7fa72f257bd5169f8d87e319cf3dad6ff52b94ae4fde3dfe3090fae85f62f8d63bf4c5b6a33f0bc579a46c4e5af6407837a11171139c2898040ef16910dc9f44dc697df79363da767d8bc92f2e310312b816e46da26469706673582212209765cc384933ef99cb7a19024a7b80c893c23a95ab89f2bd31bb080feb24dc0264736f6c634300081400330000000000000000000000001a44076050125825900e736c501f859c50fe728c
Deployed Bytecode
0x6080604052600436106103455760003560e01c8063011f78c01461035157806301ffc9a71461037957806304f26978146103a9578063063286cc146103c057806306ff4eca146103f55780630caa0540146104175780630e4975dc1461042e578063100332da1461044e57806311aa773f1461046e57806313137d651461048157806317442b70146104945780631b723877146104b6578063248a9ca3146104e757806324fb9edf1461050757806326dad53c1461051c5780632c7692bd1461053c5780632f2ff15d146105705780632f5008f914610590578063309756fb146105b05780633400288b146105d257806336568abe146105f2578063389ed267146106125780633e032a3b146106345780633e413bee1461064b5780633f4ba83a1461066c5780633fc8cef314610681578063435f5bf9146106a25780634782f779146106b957806353012e5c146106d95780635535d461146106fb5780635c975abb146107285780635e280f111461074057806364fa5208146107745780636b77e75a146107875780636f34924d146107a7578063715018a6146107ba5780637d25a05e146107cf57806382413eac1461080a5780638456cb59146108395780638da5cb5b1461084e5780638f6ac9941461086357806391d148541461087a578063972d0bba1461089a578063983318d9146108b1578063a217fddf146108d2578063a4e7f8bd146108e7578063ae5e966a1461096d578063b24c7d2f14610980578063b268630b146109b1578063b3f00674146109d9578063b98bd070146109fa578063bb0b6a5314610a1a578063bc70b35414610a3a578063c0154ccb14610a5a578063c74c0fac14610a80578063c8a44efa14610aa8578063ca5eb5e114610ae4578063ce0b63ce14610b04578063d547741f14610b17578063d5da74cb14610b37578063d8264920146103c0578063dac500e314610b70578063e2e4859b14610b92578063e9b39e2a14610ba5578063ea63ac8814610bc5578063eeaa315e14610bff578063efdcd97414610c1f578063f0b41a1714610c3f578063f2fde38b14610c7a578063f5b541a614610c9a578063f7f1544514610cbc578063f80b0de914610cd7578063fbc2915f14610cf7578063ff7bd03d14610d0a57600080fd5b3661034c57005b600080fd5b34801561035d57600080fd5b50610366600381565b6040519081526020015b60405180910390f35b34801561038557600080fd5b5061039961039436600461465b565b610d2a565b6040519015158152602001610370565b3480156103b557600080fd5b506103666101375481565b3480156103cc57600080fd5b506103e873e592427a0aece92de3edee1f18e0157c0586156481565b6040516103709190614676565b34801561040157600080fd5b506104156104103660046146ad565b610d61565b005b34801561042357600080fd5b506103666101325481565b34801561043a57600080fd5b5061041561044936600461470b565b610e8a565b34801561045a57600080fd5b50610415610469366004614728565b610f3a565b61036661047c366004614761565b610fe2565b61041561048f366004614861565b611237565b3480156104a057600080fd5b5060408051600181526002602082015201610370565b3480156104c257600080fd5b506103996104d1366004614900565b6101336020526000908152604090205460ff1681565b3480156104f357600080fd5b5061036661050236600461491d565b6112d7565b34801561051357600080fd5b50610366600581565b34801561052857600080fd5b50610415610537366004614900565b6112ec565b34801561054857600080fd5b5061055c610557366004614936565b611401565b60405162ffffff9091168152602001610370565b34801561057c57600080fd5b5061041561058b366004614964565b61187c565b34801561059c57600080fd5b506104156105ab366004614900565b61189e565b3480156105bc57600080fd5b506103666000805160206158b683398151915281565b3480156105de57600080fd5b506104156105ed36600461499d565b61191f565b3480156105fe57600080fd5b5061041561060d366004614964565b6119b2565b34801561061e57600080fd5b506103666000805160206158f683398151915281565b34801561064057600080fd5b5061036661012f5481565b34801561065757600080fd5b5061012d546103e8906001600160a01b031681565b34801561067857600080fd5b50610415611a30565b34801561068d57600080fd5b5061012e546103e8906001600160a01b031681565b3480156106ae57600080fd5b50610366624c4b4081565b3480156106c557600080fd5b506104156106d43660046149c7565b611a71565b3480156106e557600080fd5b506103666000805160206158d683398151915281565b34801561070757600080fd5b5061071b6107163660046149f7565b611bc3565b6040516103709190614a7a565b34801561073457600080fd5b5060fb5460ff16610399565b34801561074c57600080fd5b506103e87f0000000000000000000000001a44076050125825900e736c501f859c50fe728c81565b610366610782366004614a8d565b611c87565b34801561079357600080fd5b506103666107a2366004614b20565b611eb4565b6103666107b5366004614b79565b611f61565b3480156107c657600080fd5b506104156120f9565b3480156107db57600080fd5b506107f26107ea36600461499d565b600092915050565b6040516001600160401b039091168152602001610370565b34801561081657600080fd5b50610399610825366004614c17565b6001600160a01b0381163014949350505050565b34801561084557600080fd5b50610415612132565b34801561085a57600080fd5b506103e8612171565b34801561086f57600080fd5b506103666101365481565b34801561088657600080fd5b50610399610895366004614964565b612180565b3480156108a657600080fd5b506103666101315481565b3480156108bd57600080fd5b50610134546103e8906001600160a01b031681565b3480156108de57600080fd5b50610366600081565b3480156108f357600080fd5b5061093861090236600461491d565b61013a6020526000908152604090208054600182015460028301546003909301546001600160a01b039283169391929091169084565b60405161037094939291906001600160a01b039485168152602081019390935292166040820152606081019190915260800190565b61036661097b366004614c7d565b6121ab565b34801561098c57600080fd5b5061039961099b366004614900565b61013b6020526000908152604090205460ff1681565b3480156109bd57600080fd5b506103e873b27308f9f90d607463bb33ea1bebb41c27ce5ab681565b3480156109e557600080fd5b50610135546103e8906001600160a01b031681565b348015610a0657600080fd5b50610415610a15366004614cc3565b612348565b348015610a2657600080fd5b50610366610a35366004614d37565b6124e5565b348015610a4657600080fd5b5061071b610a55366004614d52565b61250d565b348015610a6657600080fd5b50610138546103e89061010090046001600160a01b031681565b348015610a8c57600080fd5b506103e8731f98431c8ad98523631ae4a59f267346ea31f98481565b348015610ab457600080fd5b50610399610ac3366004614db2565b61013c60209081526000928352604080842090915290825290205460ff1681565b348015610af057600080fd5b50610415610aff366004614900565b61268e565b610366610b12366004614dde565b61273e565b348015610b2357600080fd5b50610415610b32366004614964565b6128ca565b348015610b4357600080fd5b5061013954610b58906001600160801b031681565b6040516001600160801b039091168152602001610370565b348015610b7c57600080fd5b5061036660008051602061589683398151915281565b610366610ba0366004614e13565b6128e7565b348015610bb157600080fd5b50610415610bc0366004614900565b6129ea565b348015610bd157600080fd5b5061013854610bea90600160a81b900463ffffffff1681565b60405163ffffffff9091168152602001610370565b348015610c0b57600080fd5b50610415610c1a36600461491d565b612a7c565b348015610c2b57600080fd5b50610415610c3a366004614900565b612aa4565b348015610c4b57600080fd5b50610c5f610c5a366004614e6e565b612b6e565b60408051825181526020928301519281019290925201610370565b348015610c8657600080fd5b50610415610c95366004614900565b612be4565b348015610ca657600080fd5b5061036660008051602061585683398151915281565b348015610cc857600080fd5b50610138546103999060ff1681565b348015610ce357600080fd5b50610415610cf236600461491d565b612c84565b610366610d05366004614c7d565b612cac565b348015610d1657600080fd5b50610399610d25366004614edc565b612dac565b60006001600160e01b03198216637965db0b60e01b1480610d5b57506301ffc9a760e01b6001600160e01b03198316145b92915050565b610d7960008051602061589683398151915233612180565b610da257335b60405163c8c6739160e01b8152600401610d999190614676565b60405180910390fd5b6001600160a01b038316610dc85760405162461bcd60e51b8152600401610d9990614ef8565b6001600160e01b03198216610e125760405162461bcd60e51b815260206004820152601060248201526f24b73b30b634b21039b2b632b1ba37b960811b6044820152606401610d99565b6001600160a01b038316600081815261013c602090815260408083206001600160e01b0319871680855290835292819020805460ff191686151590811790915590519081529192917f9e96687030e30f2321bf19249e72129712de9ddb069afef9073a1c041ddd1b34910160405180910390a3505050565b6000816001600160801b031611610ee05760405162461bcd60e51b815260206004820152601a602482015279476173206c696d6974206d75737420626520706f73697469766560301b6044820152606401610d99565b610ef860008051602061585683398151915233612180565b610f175733604051630d86bd6960e31b8152600401610d999190614676565b61013980546001600160801b0319166001600160801b0392909216919091179055565b610f5260008051602061589683398151915233612180565b610f5c5733610d7f565b6001600160a01b038216610f825760405162461bcd60e51b8152600401610d9990614ef8565b6001600160a01b038216600081815261013b6020908152604091829020805460ff191685151590811790915591519182527f51372928fc73bc5fef2c5bc8324eef22ddcbc66388d34c91e02f1e67b97159bb910160405180910390a25050565b6000600260c954036110065760405162461bcd60e51b8152600401610d9990614f2c565b600260c95560fb5460ff161561102f5760405163694974fb60e11b815260040160405180910390fd5b6110476000805160206158d683398151915233612180565b6110665733604051635f9a666760e01b8152600401610d999190614676565b8760000361108657604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0389166000908152610133602052604090205460ff166110c2578860405163f5f4c28560e01b8152600401610d999190614676565b60405163d505accf60e01b81526001600160a01b038c81166004830152306024830152604482018a90526064820187905260ff8616608483015260a4820185905260c482018490528b169063d505accf9060e401600060405180830381600087803b15801561113057600080fd5b505af1925050508015611141575060015b61119357896001600160a01b03168b6001600160a01b03167f41f0da1ed8de0c51316538bf937ef0b5c7a06c31314a48e6fb2cf6dcea63ff468a60405161118a91815260200190565b60405180910390a35b61119f8a8c308b612dca565b60006111ae8b8a8a6000612ed8565b905060006111bc828961321a565b61012d54610134549192506111de916001600160a01b039182169116836132d2565b6111ed8d8d8c848f34336133d5565b8c6001600160a01b03166000805160206158368339815191528d8d8d8560405161121a9493929190614f63565b60405180910390a2600160c9559c9b505050505050505050505050565b7f0000000000000000000000001a44076050125825900e736c501f859c50fe728c6001600160a01b0316331461128257336040516391ac5e4f60e01b8152600401610d999190614676565b6020870180359061129c90611297908a614d37565b613463565b146112ce576112ae6020880188614d37565b876020013560405163309afaf360e21b8152600401610d99929190614f8c565b50505050505050565b60009081526097602052604090206001015490565b61130460008051602061589683398151915233612180565b61130e5733610d7f565b6001600160a01b0381166113535760405162461bcd60e51b815260206004820152600c60248201526b5a65726f206164647265737360a01b6044820152606401610d99565b6001600160a01b0381166000908152610133602052604090205460ff16156113b45760405162461bcd60e51b815260206004820152601460248201527320b63932b0b23c9032bc34b9ba39903a37b5b2b760611b6044820152606401610d99565b6001600160a01b03811660008181526101336020526040808220805460ff19166001179055517fce808c9c7545c7368fc6718785202de20d7d581f6e9d1009d9c0282e781a8fe79190a250565b604051630b4c774160e11b815260009081908190819081908190731f98431c8ad98523631ae4a59f267346ea31f98490631698ee829061144a908b908b90606490600401614fa2565b602060405180830381865afa158015611467573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148b9190614fca565b90506001600160a01b0381161561152557809150816001600160a01b0316631a6865026040518163ffffffff1660e01b8152600401602060405180830381865afa1580156114dd573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115019190614fe7565b9250836001600160801b0316836001600160801b0316111561152557829350606494505b604051630b4c774160e11b8152731f98431c8ad98523631ae4a59f267346ea31f98490631698ee8290611562908b908b906101f490600401614fa2565b602060405180830381865afa15801561157f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906115a39190614fca565b90506001600160a01b0381161561163e57809150816001600160a01b0316631a6865026040518163ffffffff1660e01b8152600401602060405180830381865afa1580156115f5573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116199190614fe7565b9250836001600160801b0316836001600160801b0316111561163e578293506101f494505b604051630b4c774160e11b8152731f98431c8ad98523631ae4a59f267346ea31f98490631698ee829061167b908b908b90610bb890600401614fa2565b602060405180830381865afa158015611698573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906116bc9190614fca565b90506001600160a01b0381161561175757809150816001600160a01b0316631a6865026040518163ffffffff1660e01b8152600401602060405180830381865afa15801561170e573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117329190614fe7565b9250836001600160801b0316836001600160801b0316111561175757829350610bb894505b604051630b4c774160e11b8152731f98431c8ad98523631ae4a59f267346ea31f98490631698ee8290611794908b908b9061271090600401614fa2565b602060405180830381865afa1580156117b1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906117d59190614fca565b90506001600160a01b0381161561187057809150816001600160a01b0316631a6865026040518163ffffffff1660e01b8152600401602060405180830381865afa158015611827573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061184b9190614fe7565b9250836001600160801b0316836001600160801b031611156118705782935061271094505b50929695505050505050565b611885826112d7565b61188f81336134b4565b6118998383613518565b505050565b6118b660008051602061589683398151915233612180565b6118c05733610d7f565b61013480546001600160a01b038381166001600160a01b0319831681179093556040519116917f333d753eb88dfde031e8da4385e0440b26920614852643bc6c80e79718dac36d91611913918491615004565b60405180910390a15050565b33611928612171565b6001600160a01b03161461194e5760405162461bcd60e51b8152600401610d999061501e565b600061195861359e565b63ffffffff841660009081526020829052604090819020849055519091507f238399d427b947898edb290f5ff0f9109849b1c3ba196a42e35f00c50a54b98b906119a59085908590614f8c565b60405180910390a1505050565b6001600160a01b0381163314611a225760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b6064820152608401610d99565b611a2c82826135c2565b5050565b611a486000805160206158b683398151915233612180565b611a67573360405163a8688f7360e01b8152600401610d999190614676565b611a6f613629565b565b611a8960008051602061589683398151915233612180565b611a935733610d7f565b6001600160a01b038216611add5760405162461bcd60e51b8152602060048201526011602482015270125b9d985b1a59081c9958da5c1a595b9d607a1b6044820152606401610d99565b80471015611b285760405162461bcd60e51b8152602060048201526018602482015277496e73756666696369656e74204554482062616c616e636560401b6044820152606401610d99565b6000826001600160a01b03168260405160006040518083038185875af1925050503d8060008114611b75576040519150601f19603f3d011682016040523d82523d6000602084013e611b7a565b606091505b50509050806118995760405162461bcd60e51b8152602060048201526015602482015274115512081dda5d1a191c985dd85b0819985a5b1959605a1b6044820152606401610d99565b60606000611bcf6136b6565b63ffffffff851660009081526020828152604080832061ffff881684529091529020805491925090611c0090615053565b80601f0160208091040260200160405190810160405280929190818152602001828054611c2c90615053565b8015611c795780601f10611c4e57610100808354040283529160200191611c79565b820191906000526020600020905b815481529060010190602001808311611c5c57829003601f168201915b505050505091505092915050565b6000600260c95403611cab5760405162461bcd60e51b8152600401610d9990614f2c565b600260c95560fb5460ff1615611cd45760405163694974fb60e11b815260040160405180910390fd5b86600003611cf457604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0388166000908152610133602052604090205460ff16611d30578760405163f5f4c28560e01b8152600401610d999190614676565b3360006001600160a01b038b161580611d65575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038c16145b15611d9a57883411611d8957604051620abbb960e61b815260040160405180910390fd5b611d93893461509d565b9050611dc8565b34600003611dba57604051620abbb960e61b815260040160405180910390fd5b5034611dc88b83308c612dca565b600080611dd98d8c8c8c8c8c6136da565b9050611de5818761321a565b61012d5461013454919350611e07916001600160a01b039182169116846132d2565b50611e2d838d8c848f8761013560009054906101000a90046001600160a01b03166133d5565b8a6001600160a01b03168c6001600160a01b0316846001600160a01b03167f6bf40e12ef47210fe525b39720a1b2d058c7015139c26c39860951e220cdf1838d858e604051611e989392919092835260208301919091526001600160a01b0316604082015260600190565b60405180910390a4600160c9559b9a5050505050505050505050565b60405163f7729d4360e01b81526001600160a01b0380861660048301528416602482015262ffffff83166044820152606481018290526000608482018190529073b27308f9f90d607463bb33ea1bebb41c27ce5ab69063f7729d439060a4016020604051808303816000875af1158015611f32573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f5691906150b0565b90505b949350505050565b6000600260c95403611f855760405162461bcd60e51b8152600401610d9990614f2c565b600260c955851580611f95575034155b15611fb257604051620abbb960e61b815260040160405180910390fd5b611fbc8988613a4f565b3360006001600160a01b038a161580611ff1575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038b16145b156120265787341161201557604051620abbb960e61b815260040160405180910390fd5b61201f883461509d565b9050612034565b50346120348a83308b612dca565b60006120448b8a8a8a8a8a6136da565b90508060000361206757604051639b29a93160e01b815260040160405180910390fd5b6120758c8c8b848e87613ad5565b8b6001600160a01b03166000805160206158368339815191528c8c8c856040516120a29493929190614f63565b60405180910390a28b6001600160a01b0316836001600160a01b03166000805160206158168339815191528d8c6040516120dd9291906150c9565b60405180910390a3600160c9559b9a5050505050505050505050565b33612102612171565b6001600160a01b0316146121285760405162461bcd60e51b8152600401610d999061501e565b611a6f6000613b57565b61214a6000805160206158f683398151915233612180565b612169573360405163af41226f60e01b8152600401610d999190614676565b611a6f613ba9565b6033546001600160a01b031690565b60009182526097602090815260408084206001600160a01b0393909316845291905290205460ff1690565b6000600260c954036121cf5760405162461bcd60e51b8152600401610d9990614f2c565b600260c95560fb5460ff16156121f85760405163694974fb60e11b815260040160405180910390fd5b8260000361221857604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0384166000908152610133602052604090205460ff16612254578360405163f5f4c28560e01b8152600401610d999190614676565b61226185335b3086612dca565b60006122708685856000612ed8565b90506101315481111561229c57610131546040516375889fd760e11b8152610d999183916004016150e2565b610132548110156122c6576101325460405163444ed8a560e11b8152610d999183916004016150e2565b61012d54610134546122e5916001600160a01b039081169116836132d2565b61230533610135548890879085908a9034906001600160a01b03166133d5565b336001600160a01b0316600080516020615836833981519152878787856040516123329493929190614f63565b60405180910390a2600160c95595945050505050565b33612351612171565b6001600160a01b0316146123775760405162461bcd60e51b8152600401610d999061501e565b60006123816136b6565b905060005b828110156124b3576123c88484838181106123a3576123a36150f0565b90506020028101906123b59190615106565b6123c3906040810190615126565b613c24565b8383828181106123da576123da6150f0565b90506020028101906123ec9190615106565b6123fa906040810190615126565b83600087878681811061240f5761240f6150f0565b90506020028101906124219190615106565b61242f906020810190614d37565b63ffffffff1663ffffffff168152602001908152602001600020600087878681811061245d5761245d6150f0565b905060200281019061246f9190615106565b61248090604081019060200161516c565b61ffff1681526020810191909152604001600020916124a09190836151e3565b50806124ab816152a2565b915050612386565b507fbe4864a8e820971c0247f5992e2da559595f7bf076a21cb5928d443d2a13b67483836040516119a59291906152e4565b6000806124f061359e565b63ffffffff90931660009081526020939093525050604090205490565b606060006125196136b6565b63ffffffff871660009081526020828152604080832061ffff8a16845290915281208054929350909161254b90615053565b80601f016020809104026020016040519081016040528092919081815260200182805461257790615053565b80156125c45780601f10612599576101008083540402835291602001916125c4565b820191906000526020600020905b8154815290600101906020018083116125a757829003601f168201915b5050505050905080516000036126155784848080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250929550611f59945050505050565b6000849003612627579150611f599050565b60028410612671576126398585613c24565b8061264785600281896153c8565b604051602001612659939291906153f2565b60405160208183030381529060405292505050611f59565b8484604051639a6d49cd60e01b8152600401610d9992919061541a565b33612697612171565b6001600160a01b0316146126bd5760405162461bcd60e51b8152600401610d999061501e565b60405163ca5eb5e160e01b81526001600160a01b037f0000000000000000000000001a44076050125825900e736c501f859c50fe728c169063ca5eb5e190612709908490600401614676565b600060405180830381600087803b15801561272357600080fd5b505af1158015612737573d6000803e3d6000fd5b5050505050565b6000600260c954036127625760405162461bcd60e51b8152600401610d9990614f2c565b600260c95560fb5460ff161561278b5760405163694974fb60e11b815260040160405180910390fd5b346000036127ab57604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0384166000908152610133602052604090205460ff166127e7578360405163f5f4c28560e01b8152600401610d999190614676565b60006127f3843461509d565b61012e54909150600090612813906001600160a01b031683866001612ed8565b90506101315481111561283f57610131546040516375889fd760e11b8152610d999183916004016150e2565b61013254811015612869576101325460405163444ed8a560e11b8152610d999183916004016150e2565b61012d5461013454612888916001600160a01b039081169116836132d2565b61289833600084848a8a336133d5565b61012e54604051339160008051602061587683398151915291612332916001600160a01b0316908a9087908790614f63565b6128d3826112d7565b6128dd81336134b4565b61189983836135c2565b6000600260c9540361290b5760405162461bcd60e51b8152600401610d9990614f2c565b600260c95582158061291b575034155b1561293857604051620abbb960e61b815260040160405180910390fd5b6129428685613a4f565b61294c853361225a565b600061295b8685856000612ed8565b905061296b878786848934613ad5565b866001600160a01b0316600080516020615836833981519152878787856040516129989493929190614f63565b60405180910390a26001600160a01b038716336001600160a01b031660008051602061581683398151915288876040516129d39291906150c9565b60405180910390a3600160c9559695505050505050565b612a0260008051602061589683398151915233612180565b612a0c5733610d7f565b6001600160a01b038116612a595760405162461bcd60e51b8152602060048201526014602482015273496e76616c69642075736463206164647265737360601b6044820152606401610d99565b61012d80546001600160a01b0319166001600160a01b0392909216919091179055565b612a9460008051602061589683398151915233612180565b612a9e5733610d7f565b61013255565b612abc60008051602061589683398151915233612180565b612ac65733610d7f565b6001600160a01b038116612b1b5760405162461bcd60e51b815260206004820152601c60248201527b496e76616c696420666565207265636569766572206164647265737360201b6044820152606401610d99565b61013580546001600160a01b038381166001600160a01b0319831681179093556040519116919082907fa4b009cc442411b602eaf94bc0579b6abdb8fd90b4ef5b9426e270038906bd0390600090a35050565b612b76614600565b60008686868686604051602001612b9195949392919061542e565b60408051601f1981840301815291905261013954909150600090612bc8906001600160801b031682612bc1613c66565b9190613c89565b9050612bd78983836000613ce7565b9998505050505050505050565b33612bed612171565b6001600160a01b031614612c135760405162461bcd60e51b8152600401610d999061501e565b6001600160a01b038116612c785760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b6064820152608401610d99565b612c8181613b57565b50565b612c9c60008051602061589683398151915233612180565b612ca65733610d7f565b61013155565b6000600260c95403612cd05760405162461bcd60e51b8152600401610d9990614f2c565b600260c95534600003612cf557604051620abbb960e61b815260040160405180910390fd5b612cff8585613a4f565b6000612d0b843461509d565b61012e54909150600090612d2b906001600160a01b031683866001612ed8565b9050612d3c87600084848a8a613ad5565b61012e546040516001600160a01b038981169260008051602061587683398151915292612d7292909116908a9087908790614f63565b60405180910390a261012e546040516001600160a01b03898116923392600080516020615816833981519152926129d392169087906150c9565b600060208201803590612dc390610a359085614d37565b1492915050565b600080856001600160a01b03166323b872dd60e01b868686604051602401612df49392919061545e565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051612e329190615482565b6000604051808303816000865af19150503d8060008114612e6f576040519150601f19603f3d011682016040523d82523d6000602084013e612e74565b606091505b5091509150818015612e9e575080511580612e9e575080806020019051810190612e9e9190615494565b612ed05760405162461bcd60e51b815260206004820152600360248201526229aa2360e91b6044820152606401610d99565b505050505050565b61012d546000906001600160a01b0390811690861603612ef9575082611f59565b61012d54600090612f149087906001600160a01b0316611401565b90508062ffffff16600003612f4e5761012d5460405163a4ea635160e01b8152610d999188916001600160a01b0390911690600401615004565b82612f7257612f728673e592427a0aece92de3edee1f18e0157c0586156487613db3565b60408051610100810182526001600160a01b03808916825261012d5416602082015262ffffff83169181019190915230606082015260009060808101612fb942600f6154b1565b815260200187815260200186815260200160006001600160a01b0316815250905083156131735760405163414bf38960e01b815273e592427a0aece92de3edee1f18e0157c058615649063414bf3899088906130199085906004016154c4565b60206040518083038185885af1158015613037573d6000803e3d6000fd5b50505050506040513d601f19601f8201168201806040525081019061305c91906150b0565b92508260000361307f57604051639b29a93160e01b815260040160405180910390fd5b600047905073e592427a0aece92de3edee1f18e0157c058615646001600160a01b03166312210e8a6040518163ffffffff1660e01b8152600401600060405180830381600087803b1580156130d357600080fd5b505af11580156130e7573d6000803e3d6000fd5b50505050600081476130f9919061509d565b9050801561316c57604051600090339083908381818185875af1925050503d8060008114613143576040519150601f19603f3d011682016040523d82523d6000602084013e613148565b606091505b505090508061316a57604051631390f2fb60e21b815260040160405180910390fd5b505b5050613210565b60405163414bf38960e01b815273e592427a0aece92de3edee1f18e0157c058615649063414bf389906131aa9084906004016154c4565b6020604051808303816000875af11580156131c9573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906131ed91906150b0565b92508260000361321057604051639b29a93160e01b815260040160405180910390fd5b5050949350505050565b6000624c4b40821061322d57624c4b4091505b8282106132515781836040516306dcf1e160e51b8152600401610d999291906150e2565b61325b828461509d565b90506101315481111561328757610131546040516375889fd760e11b8152610d999183916004016150e2565b610132548110156132b1576101325460405163444ed8a560e11b8152610d999183916004016150e2565b8115610d5b5761012d5461013554610d5b916001600160a01b039081169116845b600080846001600160a01b031663a9059cbb60e01b85856040516024016132fa9291906150c9565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b03199094169390931790925290516133389190615482565b6000604051808303816000865af19150503d8060008114613375576040519150601f19603f3d011682016040523d82523d6000602084013e61337a565b606091505b50915091508180156133a45750805115806133a45750808060200190518101906133a49190615494565b6127375760405162461bcd60e51b815260206004820152600260248201526114d560f21b6044820152606401610d99565b600087878787876040516020016133f095949392919061542e565b60408051601f1981840301815291905261013954909150600090613420906001600160801b031682612bc1613c66565b6040805180820190915285815260006020820152610138549192509061345690600160a81b900463ffffffff1684848488613eb6565b5050505050505050505050565b60008061346e61359e565b63ffffffff8416600090815260208290526040902054909150806134ad5760405163f6ff4fb760e01b815263ffffffff85166004820152602401610d99565b9392505050565b6134be8282612180565b611a2c576134d6816001600160a01b03166014613fb1565b6134e1836020613fb1565b6040516020016134f292919061552d565b60408051601f198184030181529082905262461bcd60e51b8252610d9991600401614a7a565b6135228282612180565b611a2c5760008281526097602090815260408083206001600160a01b03851684529091529020805460ff1916600117905561355a3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b7f72ab1bc1039b79dc4724ffca13de82c96834302d3c7e0d4252232d4b2dd8f90090565b6135cc8282612180565b15611a2c5760008281526097602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60fb5460ff166136725760405162461bcd60e51b815260206004820152601460248201527314185d5cd8589b194e881b9bdd081c185d5cd95960621b6044820152606401610d99565b60fb805460ff191690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa335b6040516136ac9190614676565b60405180910390a1565b7f8d2bda5d9f6ffb5796910376005392955773acee5548d0fcdb10e7c264ea000090565b61012d546000906001600160a01b03908116908816036136fb575084613a45565b6001600160a01b038516600090815261013b602052604090205460ff1661373757846040516334562a4560e01b8152600401610d999190614676565b60048310156137595760405163021e529960e61b815260040160405180910390fd5b600061376860048286886153c8565b6137719161559c565b6001600160a01b038716600090815261013c602090815260408083206001600160e01b03198516845290915290205490915060ff166137cf57604051630d84d4df60e21b81526001600160e01b031982166004820152602401610d99565b61012d546040516370a0823160e01b81526000916001600160a01b0316906370a0823190613801903090600401614676565b602060405180830381865afa15801561381e573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061384291906150b0565b90506001600160a01b0389161580613876575073eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee6001600160a01b038a16145b15613902576000876001600160a01b03168988886040516138989291906155cc565b60006040518083038185875af1925050503d80600081146138d5576040519150601f19603f3d011682016040523d82523d6000602084013e6138da565b606091505b50509050806138fc57604051635c827c7f60e11b815260040160405180910390fd5b5061399b565b61390d89888a613db3565b6000876001600160a01b031687876040516139299291906155cc565b6000604051808303816000865af19150503d8060008114613966576040519150601f19603f3d011682016040523d82523d6000602084013e61396b565b606091505b505090508061398d57604051635c827c7f60e11b815260040160405180910390fd5b6139998a896000613db3565b505b61012d546040516370a0823160e01b81526000916001600160a01b0316906370a08231906139cd903090600401614676565b602060405180830381865afa1580156139ea573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190613a0e91906150b0565b9050613a1a828261509d565b935084841015613a41578385604051635099d57f60e01b8152600401610d999291906150e2565b5050505b9695505050505050565b60fb5460ff1615613a735760405163694974fb60e11b815260040160405180910390fd5b6001600160a01b038216613a9957604051620abbb960e61b815260040160405180910390fd5b6001600160a01b0381166000908152610133602052604090205460ff16611a2c578060405163f5f4c28560e01b8152600401610d999190614676565b61013154831115613aff57610131546040516375889fd760e11b8152610d999185916004016150e2565b61013254831015613b29576101325460405163444ed8a560e11b8152610d999185916004016150e2565b61012d5461013454613b48916001600160a01b039081169116856132d2565b612ed0868686868686336133d5565b603380546001600160a01b038381166001600160a01b0319831681179093556040519116919082907f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e090600090a35050565b60fb5460ff1615613bef5760405162461bcd60e51b815260206004820152601060248201526f14185d5cd8589b194e881c185d5cd95960821b6044820152606401610d99565b60fb805460ff191660011790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a25861369f3390565b6000613c3360028284866153c8565b613c3c916155dc565b60f01c905060038114611899578282604051639a6d49cd60e01b8152600401610d9992919061541a565b60408051600360f01b602082015281516002818303018152602290910190915290565b6060836003613c9982600061414c565b61ffff1614613ccd57613cad81600061414c565b604051633a51740d60e01b815261ffff9091166004820152602401610d99565b6000613cd985856141a9565b9050613a4586600183614221565b613cef614600565b7f0000000000000000000000001a44076050125825900e736c501f859c50fe728c6001600160a01b031663ddc28c586040518060a001604052808863ffffffff168152602001613d3e89613463565b8152602001878152602001868152602001851515815250306040518363ffffffff1660e01b8152600401613d7392919061560a565b6040805180830381865afa158015613d8f573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611f5691906156d1565b600080846001600160a01b031663095ea7b360e01b8585604051602401613ddb9291906150c9565b60408051601f198184030181529181526020820180516001600160e01b03166001600160e01b0319909416939093179092529051613e199190615482565b6000604051808303816000865af19150503d8060008114613e56576040519150601f19603f3d011682016040523d82523d6000602084013e613e5b565b606091505b5091509150818015613e85575080511580613e85575080806020019051810190613e859190615494565b6127375760405162461bcd60e51b8152602060048201526002602482015261534160f01b6044820152606401610d99565b613ebe61461a565b8251602084015115613ed757613ed7846020015161428c565b7f0000000000000000000000001a44076050125825900e736c501f859c50fe728c6001600160a01b0316632637a450826040518060a001604052808b63ffffffff168152602001613f278c613463565b81526020018a815260200189815260200160008960200151111515815250866040518463ffffffff1660e01b8152600401613f6392919061560a565b60806040518083038185885af1158015613f81573d6000803e3d6000fd5b50505050506040513d601f19601f82011682018060405250810190613fa691906156ed565b979650505050505050565b60606000613fc083600261575e565b613fcb9060026154b1565b6001600160401b03811115613fe257613fe2615187565b6040519080825280601f01601f19166020018201604052801561400c576020820181803683370190505b509050600360fc1b81600081518110614027576140276150f0565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110614056576140566150f0565b60200101906001600160f81b031916908160001a905350600061407a84600261575e565b6140859060016154b1565b90505b60018111156140fd576f181899199a1a9b1b9c1cb0b131b232b360811b85600f16601081106140b9576140b96150f0565b1a60f81b8282815181106140cf576140cf6150f0565b60200101906001600160f81b031916908160001a90535060049490941c936140f681615775565b9050614088565b5083156134ad5760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610d99565b60006141598260026154b1565b835110156141a05760405162461bcd60e51b8152602060048201526014602482015273746f55696e7431365f6f75744f66426f756e647360601b6044820152606401610d99565b50016002015190565b60606001600160801b038216156141f157604080516001600160801b0319608086811b8216602084015285901b166030820152016040516020818303038152906040526134ad565b6040516001600160801b0319608085901b1660208201526030016040516020818303038152906040529392505050565b606083600361423182600061414c565b61ffff161461424557613cad81600061414c565b846001614252855161436e565b61425d90600161578c565b86866040516020016142739594939291906157ae565b6040516020818303038152906040529150509392505050565b60007f0000000000000000000000001a44076050125825900e736c501f859c50fe728c6001600160a01b031663e4fe1d946040518163ffffffff1660e01b8152600401602060405180830381865afa1580156142ec573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906143109190614fca565b90506001600160a01b038116614339576040516329b99a9560e11b815260040160405180910390fd5b611a2c6001600160a01b038216337f0000000000000000000000001a44076050125825900e736c501f859c50fe728c856143d5565b600061ffff8211156143d15760405162461bcd60e51b815260206004820152602660248201527f53616665436173743a2076616c756520646f65736e27742066697420696e203160448201526536206269747360d01b6064820152608401610d99565b5090565b61442d846323b872dd60e01b8585856040516024016143f69392919061545e565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b031990931692909217909152614433565b50505050565b6000614488826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166145059092919063ffffffff16565b80519091501561189957808060200190518101906144a69190615494565b6118995760405162461bcd60e51b815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e6044820152691bdd081cdd58d8d9595960b21b6064820152608401610d99565b6060611f59848460008585843b61455e5760405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610d99565b600080866001600160a01b0316858760405161457a9190615482565b60006040518083038185875af1925050503d80600081146145b7576040519150601f19603f3d011682016040523d82523d6000602084013e6145bc565b606091505b5091509150613fa6828286606083156145d65750816134ad565b8251156145e65782518084602001fd5b8160405162461bcd60e51b8152600401610d999190614a7a565b604051806040016040528060008152602001600081525090565b6040805160608101825260008082526020820152908101614639614600565b905290565b80356001600160e01b03198116811461465657600080fd5b919050565b60006020828403121561466d57600080fd5b6134ad8261463e565b6001600160a01b0391909116815260200190565b6001600160a01b0381168114612c8157600080fd5b8015158114612c8157600080fd5b6000806000606084860312156146c257600080fd5b83356146cd8161468a565b92506146db6020850161463e565b915060408401356146eb8161469f565b809150509250925092565b6001600160801b0381168114612c8157600080fd5b60006020828403121561471d57600080fd5b81356134ad816146f6565b6000806040838503121561473b57600080fd5b82356147468161468a565b915060208301356147568161469f565b809150509250929050565b6000806000806000806000806000806101408b8d03121561478157600080fd5b8a3561478c8161468a565b995060208b013561479c8161468a565b985060408b01356147ac8161468a565b975060608b0135965060808b0135955060a08b0135945060c08b0135935060e08b013560ff811681146147de57600080fd5b809350506101008b013591506101208b013590509295989b9194979a5092959850565b60006060828403121561481357600080fd5b50919050565b60008083601f84011261482b57600080fd5b5081356001600160401b0381111561484257600080fd5b60208301915083602082850101111561485a57600080fd5b9250929050565b600080600080600080600060e0888a03121561487c57600080fd5b6148868989614801565b96506060880135955060808801356001600160401b03808211156148a957600080fd5b6148b58b838c01614819565b909750955060a08a013591506148ca8261468a565b90935060c089013590808211156148e057600080fd5b506148ed8a828b01614819565b989b979a50959850939692959293505050565b60006020828403121561491257600080fd5b81356134ad8161468a565b60006020828403121561492f57600080fd5b5035919050565b6000806040838503121561494957600080fd5b82356149548161468a565b915060208301356147568161468a565b6000806040838503121561497757600080fd5b8235915060208301356147568161468a565b803563ffffffff8116811461465657600080fd5b600080604083850312156149b057600080fd5b6149b983614989565b946020939093013593505050565b600080604083850312156149da57600080fd5b82356149b98161468a565b803561ffff8116811461465657600080fd5b60008060408385031215614a0a57600080fd5b614a1383614989565b9150614a21602084016149e5565b90509250929050565b60005b83811015614a45578181015183820152602001614a2d565b50506000910152565b60008151808452614a66816020860160208601614a2a565b601f01601f19169290920160200192915050565b6020815260006134ad6020830184614a4e565b60008060008060008060008060e0898b031215614aa957600080fd5b8835614ab48161468a565b97506020890135614ac48161468a565b9650604089013595506060890135614adb8161468a565b945060808901356001600160401b03811115614af657600080fd5b614b028b828c01614819565b999c989b5096999598969760a08701359660c0013595509350505050565b60008060008060808587031215614b3657600080fd5b8435614b418161468a565b93506020850135614b518161468a565b9250604085013562ffffff81168114614b6957600080fd5b9396929550929360600135925050565b60008060008060008060008060e0898b031215614b9557600080fd5b8835614ba08161468a565b97506020890135614bb08161468a565b96506040890135614bc08161468a565b9550606089013594506080890135614bd78161468a565b935060a08901356001600160401b03811115614bf257600080fd5b614bfe8b828c01614819565b999c989b50969995989497949560c00135949350505050565b60008060008060a08587031215614c2d57600080fd5b614c378686614801565b935060608501356001600160401b03811115614c5257600080fd5b614c5e87828801614819565b9094509250506080850135614c728161468a565b939692955090935050565b60008060008060808587031215614c9357600080fd5b8435614c9e8161468a565b93506020850135614cae8161468a565b93969395505050506040820135916060013590565b60008060208385031215614cd657600080fd5b82356001600160401b0380821115614ced57600080fd5b818501915085601f830112614d0157600080fd5b813581811115614d1057600080fd5b8660208260051b8501011115614d2557600080fd5b60209290920196919550909350505050565b600060208284031215614d4957600080fd5b6134ad82614989565b60008060008060608587031215614d6857600080fd5b614d7185614989565b9350614d7f602086016149e5565b925060408501356001600160401b03811115614d9a57600080fd5b614da687828801614819565b95989497509550505050565b60008060408385031215614dc557600080fd5b8235614dd08161468a565b9150614a216020840161463e565b600080600060608486031215614df357600080fd5b8335614dfe8161468a565b95602085013595506040909401359392505050565b600080600080600060a08688031215614e2b57600080fd5b8535614e368161468a565b94506020860135614e468161468a565b93506040860135614e568161468a565b94979396509394606081013594506080013592915050565b60008060008060008060c08789031215614e8757600080fd5b614e9087614989565b95506020870135614ea08161468a565b94506040870135614eb08161468a565b9350606087013592506080870135915060a0870135614ece8161468a565b809150509295509295509295565b600060608284031215614eee57600080fd5b6134ad8383614801565b6020808252601a9082015279496e76616c69642061676772656761746f72206164647265737360301b604082015260600190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b6001600160a01b0394851681529290931660208301526040820152606081019190915260800190565b63ffffffff929092168252602082015260400190565b6001600160a01b03938416815291909216602082015262ffffff909116604082015260600190565b600060208284031215614fdc57600080fd5b81516134ad8161468a565b600060208284031215614ff957600080fd5b81516134ad816146f6565b6001600160a01b0392831681529116602082015260400190565b6020808252818101527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e6572604082015260600190565b600181811c9082168061506757607f821691505b60208210810361481357634e487b7160e01b600052602260045260246000fd5b634e487b7160e01b600052601160045260246000fd5b81810381811115610d5b57610d5b615087565b6000602082840312156150c257600080fd5b5051919050565b6001600160a01b03929092168252602082015260400190565b918252602082015260400190565b634e487b7160e01b600052603260045260246000fd5b60008235605e1983360301811261511c57600080fd5b9190910192915050565b6000808335601e1984360301811261513d57600080fd5b8301803591506001600160401b0382111561515757600080fd5b60200191503681900382131561485a57600080fd5b60006020828403121561517e57600080fd5b6134ad826149e5565b634e487b7160e01b600052604160045260246000fd5b601f82111561189957600081815260208120601f850160051c810160208610156151c45750805b601f850160051c820191505b81811015612ed0578281556001016151d0565b6001600160401b038311156151fa576151fa615187565b61520e836152088354615053565b8361519d565b6000601f841160018114615242576000851561522a5750838201355b600019600387901b1c1916600186901b178355612737565b600083815260209020601f19861690835b828110156152735786850135825560209485019460019092019101615253565b50868210156152905760001960f88860031b161c19848701351681555b505060018560011b0183555050505050565b6000600182016152b4576152b4615087565b5060010190565b81835281816020850137506000828201602090810191909152601f909101601f19169091010190565b60208082528181018390526000906040808401600586901b8501820187855b888110156153ba57878303603f190184528135368b9003605e1901811261532957600080fd5b8a01606063ffffffff61533b83614989565b16855261ffff61534c8984016149e5565b168886015286820135601e1983360301811261536757600080fd5b9091018781019190356001600160401b0381111561538457600080fd5b80360383131561539357600080fd5b81888701526153a582870182856152bb565b96890196955050509186019150600101615303565b509098975050505050505050565b600080858511156153d857600080fd5b838611156153e557600080fd5b5050820193919092039150565b60008451615404818460208901614a2a565b8201838582376000930192835250909392505050565b602081526000611f596020830184866152bb565b6001600160a01b039586168152938516602085015260408401929092526060830152909116608082015260a00190565b6001600160a01b039384168152919092166020820152604081019190915260600190565b6000825161511c818460208701614a2a565b6000602082840312156154a657600080fd5b81516134ad8161469f565b80820180821115610d5b57610d5b615087565b81516001600160a01b03908116825260208084015182169083015260408084015162ffffff16908301526060808401518216908301526080808401519083015260a0838101519083015260c0808401519083015260e09283015116918101919091526101000190565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b81526000835161555f816017850160208801614a2a565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351615590816028840160208801614a2a565b01602801949350505050565b6001600160e01b031981358181169160048510156155c45780818660040360031b1b83161692505b505092915050565b8183823760009101908152919050565b6001600160f01b031981358181169160028510156155c45760029490940360031b84901b1690921692915050565b6040815263ffffffff8351166040820152602083015160608201526000604084015160a0608084015261564060e0840182614a4e565b90506060850151603f198483030160a085015261565d8282614a4e565b60809690960151151560c08501525050506001600160a01b039190911660209091015290565b60006040828403121561569557600080fd5b604080519081016001600160401b03811182821017156156b7576156b7615187565b604052825181526020928301519281019290925250919050565b6000604082840312156156e357600080fd5b6134ad8383615683565b6000608082840312156156ff57600080fd5b604051606081016001600160401b03808211838310171561572257615722615187565b816040528451835260208501519150808216821461573f57600080fd5b5060208201526157528460408501615683565b60408201529392505050565b8082028115828204841417610d5b57610d5b615087565b60008161578457615784615087565b506000190190565b61ffff8181168382160190808211156157a7576157a7615087565b5092915050565b600086516157c0818460208b01614a2a565b6001600160f81b031960f888811b82169285019283526001600160f01b031960f089901b16600184015286901b1660038201528351615806816004840160208801614a2a565b0160040197965050505050505056feed5b6614ab4e245babbfe0af6033afad98c2d980a846b5852f117ec7c042e7b917d6f001db9e761de031511ef5b86376885cecce455165f34fc369223f10576a97667070c54ef182b0f5858b034beac1b6f3089aa2d3188bb1e8929f4fa9b929f908e8c9a42505e10f0a045312bdcf25a60d4f1a74ef534d1b6fc95e610e92e8a76ae24524824acbc21b351dd3e380dcc53874f0487c5ec4424767562c1192ee265b220c5a8891efdd9e1b1b7fa72f257bd5169f8d87e319cf3dad6ff52b94ae4fde3dfe3090fae85f62f8d63bf4c5b6a33f0bc579a46c4e5af6407837a11171139c2898040ef16910dc9f44dc697df79363da767d8bc92f2e310312b816e46da26469706673582212209765cc384933ef99cb7a19024a7b80c893c23a95ab89f2bd31bb080feb24dc0264736f6c63430008140033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
0000000000000000000000001a44076050125825900e736c501f859c50fe728c
-----Decoded View---------------
Arg [0] : _endpoint (address): 0x1a44076050125825900e736c501f859c50fE728c
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 0000000000000000000000001a44076050125825900e736c501f859c50fe728c
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 34 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
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.