Source Code
Latest 25 from a total of 22,031 transactions
| Transaction Hash |
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Execute | 31256125 | 10 mins ago | IN | 0 FRAX | 0.00000893 | ||||
| Execute | 31255980 | 14 mins ago | IN | 0 FRAX | 0.00000871 | ||||
| Execute | 31254762 | 55 mins ago | IN | 0 FRAX | 0.00000897 | ||||
| Execute | 31254751 | 55 mins ago | IN | 0 FRAX | 0.00000862 | ||||
| Execute | 31254744 | 56 mins ago | IN | 0 FRAX | 0.00000916 | ||||
| Execute | 31252342 | 2 hrs ago | IN | 0 FRAX | 0.00000873 | ||||
| Execute | 31250124 | 3 hrs ago | IN | 0 FRAX | 0.00000889 | ||||
| Execute | 31249728 | 3 hrs ago | IN | 0 FRAX | 0.0000087 | ||||
| Execute | 31248689 | 4 hrs ago | IN | 0 FRAX | 0.00001117 | ||||
| Execute | 31248563 | 4 hrs ago | IN | 0 FRAX | 0.00001803 | ||||
| Execute | 31248474 | 4 hrs ago | IN | 0 FRAX | 0.00001009 | ||||
| Execute | 31248442 | 4 hrs ago | IN | 0 FRAX | 0.00000881 | ||||
| Execute | 31246673 | 5 hrs ago | IN | 0 FRAX | 0.0000097 | ||||
| Execute | 31246317 | 5 hrs ago | IN | 0 FRAX | 0.00001017 | ||||
| Execute | 31245810 | 5 hrs ago | IN | 0 FRAX | 0.00000967 | ||||
| Execute | 31245618 | 6 hrs ago | IN | 0 FRAX | 0.00000821 | ||||
| Execute | 31244171 | 6 hrs ago | IN | 0 FRAX | 0.00000849 | ||||
| Execute | 31240584 | 8 hrs ago | IN | 0 FRAX | 0.00001043 | ||||
| Execute | 31239665 | 9 hrs ago | IN | 0 FRAX | 0.00001031 | ||||
| Execute | 31239649 | 9 hrs ago | IN | 0 FRAX | 0.00001032 | ||||
| Execute | 31239610 | 9 hrs ago | IN | 0 FRAX | 0.00000996 | ||||
| Execute | 31239605 | 9 hrs ago | IN | 0 FRAX | 0.00000979 | ||||
| Execute | 31239510 | 9 hrs ago | IN | 0 FRAX | 0.00000955 | ||||
| Execute | 31239351 | 9 hrs ago | IN | 0 FRAX | 0.00000872 | ||||
| Execute | 31238952 | 9 hrs ago | IN | 0 FRAX | 0.00001089 |
Advanced mode: Intended for advanced users or developers and will display all Internal Transactions including zero value transfers.
Latest 25 internal transactions (View All)
Advanced mode:
| Parent Transaction Hash | Block | From | To | ||||
|---|---|---|---|---|---|---|---|
| 31256137 | 9 mins ago | 0 FRAX | |||||
| 31256137 | 9 mins ago | 0 FRAX | |||||
| 31256137 | 9 mins ago | 0 FRAX | |||||
| 31256137 | 9 mins ago | 0 FRAX | |||||
| 31256125 | 10 mins ago | 0 FRAX | |||||
| 31256125 | 10 mins ago | 0 FRAX | |||||
| 31256125 | 10 mins ago | 0 FRAX | |||||
| 31255980 | 14 mins ago | 0 FRAX | |||||
| 31255980 | 14 mins ago | 0 FRAX | |||||
| 31255980 | 14 mins ago | 0 FRAX | |||||
| 31255417 | 33 mins ago | 0 FRAX | |||||
| 31255417 | 33 mins ago | 0 FRAX | |||||
| 31255137 | 43 mins ago | 0 FRAX | |||||
| 31255137 | 43 mins ago | 0 FRAX | |||||
| 31255102 | 44 mins ago | 0 FRAX | |||||
| 31255102 | 44 mins ago | 0 FRAX | |||||
| 31255074 | 45 mins ago | 0 FRAX | |||||
| 31255074 | 45 mins ago | 0 FRAX | |||||
| 31255074 | 45 mins ago | 0 FRAX | |||||
| 31255074 | 45 mins ago | 0 FRAX | |||||
| 31255005 | 47 mins ago | 0 FRAX | |||||
| 31255005 | 47 mins ago | 0 FRAX | |||||
| 31254770 | 55 mins ago | 0 FRAX | |||||
| 31254770 | 55 mins ago | 0 FRAX | |||||
| 31254770 | 55 mins ago | 0 FRAX |
Cross-Chain Transactions
Loading...
Loading
Contract Name:
DVN
Compiler Version
v0.8.22+commit.4fc1097e
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { ILayerZeroUltraLightNodeV2 } from "@layerzerolabs/lz-evm-v1-0.7/contracts/interfaces/ILayerZeroUltraLightNodeV2.sol";
import { Worker } from "../../Worker.sol";
import { MultiSig } from "./MultiSig.sol";
import { ReadLib1002 } from "../readlib/ReadLib1002.sol";
import { IDVN } from "../interfaces/IDVN.sol";
import { IDVNFeeLib } from "../interfaces/IDVNFeeLib.sol";
import { IReceiveUlnE2 } from "../interfaces/IReceiveUlnE2.sol";
struct ExecuteParam {
uint32 vid;
address target;
bytes callData;
uint256 expiration;
bytes signatures;
}
contract DVN is Worker, MultiSig, IDVN {
// to uniquely identify this DVN instance
// set to endpoint v1 eid if available OR endpoint v2 eid % 30_000
uint32 public immutable vid;
uint32 public immutable localEidV2; // endpoint-v2 only, for read call
mapping(uint32 dstEid => DstConfig) public dstConfig;
mapping(bytes32 executableHash => bool used) public usedHashes;
error DVN_OnlySelf();
error DVN_InvalidRole(bytes32 role);
error DVN_InstructionExpired();
error DVN_InvalidTarget(address target);
error DVN_InvalidVid(uint32 vid);
error DVN_InvalidSignatures();
error DVN_DuplicatedHash(bytes32 executableHash);
event VerifySignaturesFailed(uint256 idx);
event ExecuteFailed(uint256 _index, bytes _data);
event HashAlreadyUsed(ExecuteParam param, bytes32 _hash);
// same as DVNFeePaid, but for ULNv2
event VerifierFeePaid(uint256 fee);
// ========================= Constructor =========================
/// @dev DVN doesn't have a roleAdmin (address(0x0))
/// @dev Supports all of ULNv2, ULN301, ULN302 and more
/// @param _localEidV2 local endpoint-v2 eid
/// @param _vid unique identifier for this DVN instance
/// @param _messageLibs array of message lib addresses that are granted the MESSAGE_LIB_ROLE
/// @param _priceFeed price feed address
/// @param _signers array of signer addresses for multisig
/// @param _quorum quorum for multisig
/// @param _admins array of admin addresses that are granted the ADMIN_ROLE
constructor(
uint32 _localEidV2,
uint32 _vid,
address[] memory _messageLibs,
address _priceFeed,
address[] memory _signers,
uint64 _quorum,
address[] memory _admins
) Worker(_messageLibs, _priceFeed, 12000, address(0x0), _admins) MultiSig(_signers, _quorum) {
vid = _vid;
localEidV2 = _localEidV2;
}
// ========================= Modifier =========================
/// @dev depending on role, restrict access to only self or admin
/// @dev ALLOWLIST, DENYLIST, MESSAGE_LIB_ROLE can only be granted/revoked by self
/// @dev ADMIN_ROLE can only be granted/revoked by admin
/// @dev reverts if not one of the above roles
/// @param _role role to check
modifier onlySelfOrAdmin(bytes32 _role) {
if (_role == ALLOWLIST || _role == DENYLIST || _role == MESSAGE_LIB_ROLE) {
// self required
if (address(this) != msg.sender) {
revert DVN_OnlySelf();
}
} else if (_role == ADMIN_ROLE) {
// admin required
_checkRole(ADMIN_ROLE);
} else {
revert DVN_InvalidRole(_role);
}
_;
}
modifier onlySelf() {
if (address(this) != msg.sender) {
revert DVN_OnlySelf();
}
_;
}
// ========================= OnlySelf =========================
/// @dev set signers for multisig
/// @dev function sig 0x31cb6105
/// @param _signer signer address
/// @param _active true to add, false to remove
function setSigner(address _signer, bool _active) external onlySelf {
_setSigner(_signer, _active);
}
/// @dev set quorum for multisig
/// @dev function sig 0x8585c945
/// @param _quorum to set
function setQuorum(uint64 _quorum) external onlySelf {
_setQuorum(_quorum);
}
// ========================= OnlySelf / OnlyAdmin =========================
/// @dev overrides AccessControl to allow self/admin to grant role'
/// @dev function sig 0x2f2ff15d
/// @param _role role to grant
/// @param _account account to grant role to
function grantRole(bytes32 _role, address _account) public override onlySelfOrAdmin(_role) {
_grantRole(_role, _account);
}
/// @dev overrides AccessControl to allow self/admin to revoke role
/// @dev function sig 0xd547741f
/// @param _role role to revoke
/// @param _account account to revoke role from
function revokeRole(bytes32 _role, address _account) public override onlySelfOrAdmin(_role) {
_revokeRole(_role, _account);
}
// ========================= OnlyQuorum =========================
/// @notice function for quorum to change admin without going through execute function
/// @dev calldata in the case is abi.encode new admin address
function quorumChangeAdmin(ExecuteParam calldata _param) external {
if (_param.expiration <= block.timestamp) {
revert DVN_InstructionExpired();
}
if (_param.target != address(this)) {
revert DVN_InvalidTarget(_param.target);
}
if (_param.vid != vid) {
revert DVN_InvalidVid(_param.vid);
}
// generate and validate hash
bytes32 hash = hashCallData(_param.vid, _param.target, _param.callData, _param.expiration);
(bool sigsValid, ) = verifySignatures(hash, _param.signatures);
if (!sigsValid) {
revert DVN_InvalidSignatures();
}
if (usedHashes[hash]) {
revert DVN_DuplicatedHash(hash);
}
usedHashes[hash] = true;
_grantRole(ADMIN_ROLE, abi.decode(_param.callData, (address)));
}
// ========================= OnlyAdmin =========================
/// @param _params array of DstConfigParam
function setDstConfig(DstConfigParam[] calldata _params) external onlyRole(ADMIN_ROLE) {
for (uint256 i = 0; i < _params.length; ++i) {
DstConfigParam calldata param = _params[i];
dstConfig[param.dstEid] = DstConfig(param.gas, param.multiplierBps, param.floorMarginUSD);
}
emit SetDstConfig(_params);
}
/// @dev takes a list of instructions and executes them in order
/// @dev if any of the instructions fail, it will emit an error event and continue to execute the rest of the instructions
/// @param _params array of ExecuteParam, includes target, callData, expiration, signatures
function execute(ExecuteParam[] calldata _params) external onlyRole(ADMIN_ROLE) {
for (uint256 i = 0; i < _params.length; ++i) {
ExecuteParam calldata param = _params[i];
// 1. skip if invalid vid
if (param.vid != vid) {
continue;
}
// 2. skip if expired
if (param.expiration <= block.timestamp) {
continue;
}
// generate and validate hash
bytes32 hash = hashCallData(param.vid, param.target, param.callData, param.expiration);
// 3. check signatures
(bool sigsValid, ) = verifySignatures(hash, param.signatures);
if (!sigsValid) {
emit VerifySignaturesFailed(i);
continue;
}
// 4. should check hash
bool shouldCheckHash = _shouldCheckHash(bytes4(param.callData));
if (shouldCheckHash) {
if (usedHashes[hash]) {
emit HashAlreadyUsed(param, hash);
continue;
} else {
usedHashes[hash] = true; // prevent reentry and replay attack
}
}
(bool success, bytes memory rtnData) = param.target.call(param.callData);
if (!success) {
if (shouldCheckHash) {
// need to unset the usedHash otherwise it cant be used
usedHashes[hash] = false;
}
// emit an event in any case
emit ExecuteFailed(i, rtnData);
}
}
}
/// @dev to support ULNv2
/// @dev the withdrawFee function for ULN30X is built in the Worker contract
/// @param _lib message lib address
/// @param _to address to withdraw to
/// @param _amount amount to withdraw
function withdrawFeeFromUlnV2(address _lib, address payable _to, uint256 _amount) external onlyRole(ADMIN_ROLE) {
if (!hasRole(MESSAGE_LIB_ROLE, _lib)) {
revert Worker_OnlyMessageLib();
}
ILayerZeroUltraLightNodeV2(_lib).withdrawNative(_to, _amount);
}
// ========================= OnlyMessageLib =========================
/// @dev for ULN301, ULN302 and more to assign job
/// @dev dvn network can reject job from _sender by adding/removing them from allowlist/denylist
/// @param _param assign job param
/// @param _options dvn options
function assignJob(
AssignJobParam calldata _param,
bytes calldata _options
) external payable onlyRole(MESSAGE_LIB_ROLE) onlyAcl(_param.sender) returns (uint256 totalFee) {
IDVNFeeLib.FeeParams memory feeParams = IDVNFeeLib.FeeParams(
priceFeed,
_param.dstEid,
_param.confirmations,
_param.sender,
quorum,
defaultMultiplierBps
);
totalFee = IDVNFeeLib(workerFeeLib).getFeeOnSend(feeParams, dstConfig[_param.dstEid], _options);
}
/// @dev to support ULNv2
/// @dev dvn network can reject job from _sender by adding/removing them from allowlist/denylist
/// @param _dstEid destination EndpointId
/// @param //_outboundProofType outbound proof type
/// @param _confirmations block confirmations
/// @param _sender message sender address
function assignJob(
uint16 _dstEid,
uint16 /*_outboundProofType*/,
uint64 _confirmations,
address _sender
) external onlyRole(MESSAGE_LIB_ROLE) onlyAcl(_sender) returns (uint256 totalFee) {
IDVNFeeLib.FeeParams memory params = IDVNFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
// ULNV2 does not have dvn options
totalFee = IDVNFeeLib(workerFeeLib).getFeeOnSend(params, dstConfig[_dstEid], bytes(""));
emit VerifierFeePaid(totalFee);
}
/// @dev to support ReadLib
// @param _packetHeader - version + nonce + path
// @param _cmd - the command to be executed to obtain the payload
// @param _options - options
function assignJob(
address _sender,
bytes calldata /*_packetHeader*/,
bytes calldata _cmd,
bytes calldata _options
) external payable onlyRole(MESSAGE_LIB_ROLE) onlyAcl(_sender) returns (uint256 fee) {
IDVNFeeLib.FeeParamsForRead memory feeParams = IDVNFeeLib.FeeParamsForRead(
priceFeed,
_sender,
quorum,
defaultMultiplierBps
);
fee = IDVNFeeLib(workerFeeLib).getFeeOnSend(feeParams, dstConfig[localEidV2], _cmd, _options);
}
// ========================= View =========================
/// @dev getFee can revert if _sender doesn't pass ACL
/// @param _dstEid destination EndpointId
/// @param _confirmations block confirmations
/// @param _sender message sender address
/// @param _options dvn options
/// @return fee fee in native amount
function getFee(
uint32 _dstEid,
uint64 _confirmations,
address _sender,
bytes calldata _options
) external view onlyAcl(_sender) returns (uint256 fee) {
IDVNFeeLib.FeeParams memory params = IDVNFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
fee = IDVNFeeLib(workerFeeLib).getFee(params, dstConfig[_dstEid], _options);
}
/// @dev to support ULNv2
/// @dev getFee can revert if _sender doesn't pass ACL
/// @param _dstEid destination EndpointId
/// @param //_outboundProofType outbound proof type
/// @param _confirmations block confirmations
/// @param _sender message sender address
function getFee(
uint16 _dstEid,
uint16 /*_outboundProofType*/,
uint64 _confirmations,
address _sender
) public view onlyAcl(_sender) returns (uint256 fee) {
IDVNFeeLib.FeeParams memory params = IDVNFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
fee = IDVNFeeLib(workerFeeLib).getFee(params, dstConfig[_dstEid], bytes(""));
}
/// @dev to support ReadLib
// @param _packetHeader - version + nonce + path
// @param _cmd - the command to be executed to obtain the payload
// @param _options - options
function getFee(
address _sender,
bytes calldata /*_packetHeader*/,
bytes calldata _cmd,
bytes calldata _options
) external view onlyAcl(_sender) returns (uint256 fee) {
IDVNFeeLib.FeeParamsForRead memory feeParams = IDVNFeeLib.FeeParamsForRead(
priceFeed,
_sender,
quorum,
defaultMultiplierBps
);
fee = IDVNFeeLib(workerFeeLib).getFee(feeParams, dstConfig[localEidV2], _cmd, _options);
}
/// @param _target target address
/// @param _callData call data
/// @param _expiration expiration timestamp
/// @return hash of above
function hashCallData(
uint32 _vid,
address _target,
bytes calldata _callData,
uint256 _expiration
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_vid, _target, _expiration, _callData));
}
// ========================= Internal =========================
/// @dev to save gas, we don't check hash for some functions (where replaying won't change the state)
/// @dev for example, some administrative functions like changing signers, the contract should check hash to double spending
/// @dev should ensure that all onlySelf functions have unique functionSig
/// @param _functionSig function signature
/// @return true if should check hash
function _shouldCheckHash(bytes4 _functionSig) internal pure returns (bool) {
// never check for these selectors to save gas
return
_functionSig != IReceiveUlnE2.verify.selector && // 0x0223536e, replaying won't change the state
_functionSig != ReadLib1002.verify.selector && // 0xab750e75, replaying won't change the state
_functionSig != ILayerZeroUltraLightNodeV2.updateHash.selector; // 0x704316e5, replaying will be revert at uln
}
}// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1
// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
import "./IOwnable.sol";
interface IBridge {
event MessageDelivered(
uint256 indexed messageIndex,
bytes32 indexed beforeInboxAcc,
address inbox,
uint8 kind,
address sender,
bytes32 messageDataHash,
uint256 baseFeeL1,
uint64 timestamp
);
event BridgeCallTriggered(
address indexed outbox,
address indexed to,
uint256 value,
bytes data
);
event InboxToggle(address indexed inbox, bool enabled);
event OutboxToggle(address indexed outbox, bool enabled);
event SequencerInboxUpdated(address newSequencerInbox);
event RollupUpdated(address rollup);
function allowedDelayedInboxList(uint256) external returns (address);
function allowedOutboxList(uint256) external returns (address);
/// @dev Accumulator for delayed inbox messages; tail represents hash of the current state; each element represents the inclusion of a new message.
function delayedInboxAccs(uint256) external view returns (bytes32);
/// @dev Accumulator for sequencer inbox messages; tail represents hash of the current state; each element represents the inclusion of a new message.
function sequencerInboxAccs(uint256) external view returns (bytes32);
function rollup() external view returns (IOwnable);
function sequencerInbox() external view returns (address);
function activeOutbox() external view returns (address);
function allowedDelayedInboxes(address inbox) external view returns (bool);
function allowedOutboxes(address outbox) external view returns (bool);
function sequencerReportedSubMessageCount() external view returns (uint256);
function executeCall(
address to,
uint256 value,
bytes calldata data
) external returns (bool success, bytes memory returnData);
function delayedMessageCount() external view returns (uint256);
function sequencerMessageCount() external view returns (uint256);
// ---------- onlySequencerInbox functions ----------
function enqueueSequencerMessage(
bytes32 dataHash,
uint256 afterDelayedMessagesRead,
uint256 prevMessageCount,
uint256 newMessageCount
)
external
returns (
uint256 seqMessageIndex,
bytes32 beforeAcc,
bytes32 delayedAcc,
bytes32 acc
);
/**
* @dev Allows the sequencer inbox to submit a delayed message of the batchPostingReport type
* This is done through a separate function entrypoint instead of allowing the sequencer inbox
* to call `enqueueDelayedMessage` to avoid the gas overhead of an extra SLOAD in either
* every delayed inbox or every sequencer inbox call.
*/
function submitBatchSpendingReport(address batchPoster, bytes32 dataHash)
external
returns (uint256 msgNum);
// ---------- onlyRollupOrOwner functions ----------
function setSequencerInbox(address _sequencerInbox) external;
function setDelayedInbox(address inbox, bool enabled) external;
function setOutbox(address inbox, bool enabled) external;
function updateRollupAddress(IOwnable _rollup) external;
}// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1
// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
interface IDelayedMessageProvider {
/// @dev event emitted when a inbox message is added to the Bridge's delayed accumulator
event InboxMessageDelivered(uint256 indexed messageNum, bytes data);
/// @dev event emitted when a inbox message is added to the Bridge's delayed accumulator
/// same as InboxMessageDelivered but the batch data is available in tx.input
event InboxMessageDeliveredFromOrigin(uint256 indexed messageNum);
}// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/nitro/blob/master/LICENSE
// SPDX-License-Identifier: BUSL-1.1
// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
import "./IBridge.sol";
import "./IInboxBase.sol";
interface IInbox is IInboxBase {
function sendL1FundedUnsignedTransaction(
uint256 gasLimit,
uint256 maxFeePerGas,
uint256 nonce,
address to,
bytes calldata data
) external payable returns (uint256);
function sendL1FundedContractTransaction(
uint256 gasLimit,
uint256 maxFeePerGas,
address to,
bytes calldata data
) external payable returns (uint256);
/**
* @dev This method can only be called upon L1 fork and will not alias the caller
* This method will revert if not called from origin
*/
function sendL1FundedUnsignedTransactionToFork(
uint256 gasLimit,
uint256 maxFeePerGas,
uint256 nonce,
address to,
bytes calldata data
) external payable returns (uint256);
/**
* @dev This method can only be called upon L1 fork and will not alias the caller
* This method will revert if not called from origin
*/
function sendUnsignedTransactionToFork(
uint256 gasLimit,
uint256 maxFeePerGas,
uint256 nonce,
address to,
uint256 value,
bytes calldata data
) external returns (uint256);
/**
* @notice Send a message to initiate L2 withdrawal
* @dev This method can only be called upon L1 fork and will not alias the caller
* This method will revert if not called from origin
*/
function sendWithdrawEthToFork(
uint256 gasLimit,
uint256 maxFeePerGas,
uint256 nonce,
uint256 value,
address withdrawTo
) external returns (uint256);
/**
* @notice Deposit eth from L1 to L2 to address of the sender if sender is an EOA, and to its aliased address if the sender is a contract
* @dev This does not trigger the fallback function when receiving in the L2 side.
* Look into retryable tickets if you are interested in this functionality.
* @dev This function should not be called inside contract constructors
*/
function depositEth() external payable returns (uint256);
/**
* @notice Put a message in the L2 inbox that can be reexecuted for some fixed amount of time if it reverts
* @dev all msg.value will deposited to callValueRefundAddress on L2
* @dev Gas limit and maxFeePerGas should not be set to 1 as that is used to trigger the RetryableData error
* @param to destination L2 contract address
* @param l2CallValue call value for retryable L2 message
* @param maxSubmissionCost Max gas deducted from user's L2 balance to cover base submission fee
* @param excessFeeRefundAddress gasLimit x maxFeePerGas - execution cost gets credited here on L2 balance
* @param callValueRefundAddress l2Callvalue gets credited here on L2 if retryable txn times out or gets cancelled
* @param gasLimit Max gas deducted from user's L2 balance to cover L2 execution. Should not be set to 1 (magic value used to trigger the RetryableData error)
* @param maxFeePerGas price bid for L2 execution. Should not be set to 1 (magic value used to trigger the RetryableData error)
* @param data ABI encoded data of L2 message
* @return unique message number of the retryable transaction
*/
function createRetryableTicket(
address to,
uint256 l2CallValue,
uint256 maxSubmissionCost,
address excessFeeRefundAddress,
address callValueRefundAddress,
uint256 gasLimit,
uint256 maxFeePerGas,
bytes calldata data
) external payable returns (uint256);
/**
* @notice Put a message in the L2 inbox that can be reexecuted for some fixed amount of time if it reverts
* @dev Same as createRetryableTicket, but does not guarantee that submission will succeed by requiring the needed funds
* come from the deposit alone, rather than falling back on the user's L2 balance
* @dev Advanced usage only (does not rewrite aliases for excessFeeRefundAddress and callValueRefundAddress).
* createRetryableTicket method is the recommended standard.
* @dev Gas limit and maxFeePerGas should not be set to 1 as that is used to trigger the RetryableData error
* @param to destination L2 contract address
* @param l2CallValue call value for retryable L2 message
* @param maxSubmissionCost Max gas deducted from user's L2 balance to cover base submission fee
* @param excessFeeRefundAddress gasLimit x maxFeePerGas - execution cost gets credited here on L2 balance
* @param callValueRefundAddress l2Callvalue gets credited here on L2 if retryable txn times out or gets cancelled
* @param gasLimit Max gas deducted from user's L2 balance to cover L2 execution. Should not be set to 1 (magic value used to trigger the RetryableData error)
* @param maxFeePerGas price bid for L2 execution. Should not be set to 1 (magic value used to trigger the RetryableData error)
* @param data ABI encoded data of L2 message
* @return unique message number of the retryable transaction
*/
function unsafeCreateRetryableTicket(
address to,
uint256 l2CallValue,
uint256 maxSubmissionCost,
address excessFeeRefundAddress,
address callValueRefundAddress,
uint256 gasLimit,
uint256 maxFeePerGas,
bytes calldata data
) external payable returns (uint256);
// ---------- initializer ----------
/**
* @dev function to be called one time during the inbox upgrade process
* this is used to fix the storage slots
*/
function postUpgradeInit(IBridge _bridge) external;
}// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1
// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
import "./IBridge.sol";
import "./IDelayedMessageProvider.sol";
import "./ISequencerInbox.sol";
interface IInboxBase is IDelayedMessageProvider {
function bridge() external view returns (IBridge);
function sequencerInbox() external view returns (ISequencerInbox);
function maxDataSize() external view returns (uint256);
/**
* @notice Send a generic L2 message to the chain
* @dev This method is an optimization to avoid having to emit the entirety of the messageData in a log. Instead validators are expected to be able to parse the data from the transaction's input
* @param messageData Data of the message being sent
*/
function sendL2MessageFromOrigin(bytes calldata messageData) external returns (uint256);
/**
* @notice Send a generic L2 message to the chain
* @dev This method can be used to send any type of message that doesn't require L1 validation
* @param messageData Data of the message being sent
*/
function sendL2Message(bytes calldata messageData) external returns (uint256);
function sendUnsignedTransaction(
uint256 gasLimit,
uint256 maxFeePerGas,
uint256 nonce,
address to,
uint256 value,
bytes calldata data
) external returns (uint256);
function sendContractTransaction(
uint256 gasLimit,
uint256 maxFeePerGas,
address to,
uint256 value,
bytes calldata data
) external returns (uint256);
/**
* @notice Get the L1 fee for submitting a retryable
* @dev This fee can be paid by funds already in the L2 aliased address or by the current message value
* @dev This formula may change in the future, to future proof your code query this method instead of inlining!!
* @param dataLength The length of the retryable's calldata, in bytes
* @param baseFee The block basefee when the retryable is included in the chain, if 0 current block.basefee will be used
*/
function calculateRetryableSubmissionFee(uint256 dataLength, uint256 baseFee)
external
view
returns (uint256);
// ---------- onlyRollupOrOwner functions ----------
/// @notice pauses all inbox functionality
function pause() external;
/// @notice unpauses all inbox functionality
function unpause() external;
/// @notice add or remove users from allowList
function setAllowList(address[] memory user, bool[] memory val) external;
/// @notice enable or disable allowList
function setAllowListEnabled(bool _allowListEnabled) external;
/// @notice check if user is in allowList
function isAllowed(address user) external view returns (bool);
/// @notice check if allowList is enabled
function allowListEnabled() external view returns (bool);
function initialize(IBridge _bridge, ISequencerInbox _sequencerInbox) external;
/// @notice returns the current admin
function getProxyAdmin() external view returns (address);
}// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1
// solhint-disable-next-line compiler-version
pragma solidity >=0.4.21 <0.9.0;
interface IOwnable {
function owner() external view returns (address);
}// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1
// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
pragma experimental ABIEncoderV2;
import "../libraries/IGasRefunder.sol";
import "./IDelayedMessageProvider.sol";
import "./IBridge.sol";
interface ISequencerInbox is IDelayedMessageProvider {
struct MaxTimeVariation {
uint256 delayBlocks;
uint256 futureBlocks;
uint256 delaySeconds;
uint256 futureSeconds;
}
struct TimeBounds {
uint64 minTimestamp;
uint64 maxTimestamp;
uint64 minBlockNumber;
uint64 maxBlockNumber;
}
enum BatchDataLocation {
TxInput,
SeparateBatchEvent,
NoData
}
event SequencerBatchDelivered(
uint256 indexed batchSequenceNumber,
bytes32 indexed beforeAcc,
bytes32 indexed afterAcc,
bytes32 delayedAcc,
uint256 afterDelayedMessagesRead,
TimeBounds timeBounds,
BatchDataLocation dataLocation
);
event OwnerFunctionCalled(uint256 indexed id);
/// @dev a separate event that emits batch data when this isn't easily accessible in the tx.input
event SequencerBatchData(uint256 indexed batchSequenceNumber, bytes data);
/// @dev a valid keyset was added
event SetValidKeyset(bytes32 indexed keysetHash, bytes keysetBytes);
/// @dev a keyset was invalidated
event InvalidateKeyset(bytes32 indexed keysetHash);
function totalDelayedMessagesRead() external view returns (uint256);
function bridge() external view returns (IBridge);
/// @dev The size of the batch header
// solhint-disable-next-line func-name-mixedcase
function HEADER_LENGTH() external view returns (uint256);
/// @dev If the first batch data byte after the header has this bit set,
/// the sequencer inbox has authenticated the data. Currently not used.
// solhint-disable-next-line func-name-mixedcase
function DATA_AUTHENTICATED_FLAG() external view returns (bytes1);
function rollup() external view returns (IOwnable);
function isBatchPoster(address) external view returns (bool);
function isSequencer(address) external view returns (bool);
function maxDataSize() external view returns (uint256);
struct DasKeySetInfo {
bool isValidKeyset;
uint64 creationBlock;
}
function maxTimeVariation()
external
view
returns (
uint256,
uint256,
uint256,
uint256
);
function dasKeySetInfo(bytes32) external view returns (bool, uint64);
/// @notice Remove force inclusion delay after a L1 chainId fork
function removeDelayAfterFork() external;
/// @notice Force messages from the delayed inbox to be included in the chain
/// Callable by any address, but message can only be force-included after maxTimeVariation.delayBlocks and
/// maxTimeVariation.delaySeconds has elapsed. As part of normal behaviour the sequencer will include these
/// messages so it's only necessary to call this if the sequencer is down, or not including any delayed messages.
/// @param _totalDelayedMessagesRead The total number of messages to read up to
/// @param kind The kind of the last message to be included
/// @param l1BlockAndTime The l1 block and the l1 timestamp of the last message to be included
/// @param baseFeeL1 The l1 gas price of the last message to be included
/// @param sender The sender of the last message to be included
/// @param messageDataHash The messageDataHash of the last message to be included
function forceInclusion(
uint256 _totalDelayedMessagesRead,
uint8 kind,
uint64[2] calldata l1BlockAndTime,
uint256 baseFeeL1,
address sender,
bytes32 messageDataHash
) external;
function inboxAccs(uint256 index) external view returns (bytes32);
function batchCount() external view returns (uint256);
function isValidKeysetHash(bytes32 ksHash) external view returns (bool);
/// @notice the creation block is intended to still be available after a keyset is deleted
function getKeysetCreationBlock(bytes32 ksHash) external view returns (uint256);
// ---------- BatchPoster functions ----------
function addSequencerL2BatchFromOrigin(
uint256 sequenceNumber,
bytes calldata data,
uint256 afterDelayedMessagesRead,
IGasRefunder gasRefunder
) external;
function addSequencerL2Batch(
uint256 sequenceNumber,
bytes calldata data,
uint256 afterDelayedMessagesRead,
IGasRefunder gasRefunder,
uint256 prevMessageCount,
uint256 newMessageCount
) external;
// ---------- onlyRollupOrOwner functions ----------
/**
* @notice Set max delay for sequencer inbox
* @param maxTimeVariation_ the maximum time variation parameters
*/
function setMaxTimeVariation(MaxTimeVariation memory maxTimeVariation_) external;
/**
* @notice Updates whether an address is authorized to be a batch poster at the sequencer inbox
* @param addr the address
* @param isBatchPoster_ if the specified address should be authorized as a batch poster
*/
function setIsBatchPoster(address addr, bool isBatchPoster_) external;
/**
* @notice Makes Data Availability Service keyset valid
* @param keysetBytes bytes of the serialized keyset
*/
function setValidKeyset(bytes calldata keysetBytes) external;
/**
* @notice Invalidates a Data Availability Service keyset
* @param ksHash hash of the keyset
*/
function invalidateKeysetHash(bytes32 ksHash) external;
/**
* @notice Updates whether an address is authorized to be a sequencer.
* @dev The IsSequencer information is used only off-chain by the nitro node to validate sequencer feed signer.
* @param addr the address
* @param isSequencer_ if the specified address should be authorized as a sequencer
*/
function setIsSequencer(address addr, bool isSequencer_) external;
// ---------- initializer ----------
function initialize(IBridge bridge_, MaxTimeVariation calldata maxTimeVariation_) external;
function updateRollupAddress() external;
}// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.0;
library AddressAliasHelper {
uint160 internal constant OFFSET = uint160(0x1111000000000000000000000000000000001111);
/// @notice Utility function that converts the address in the L1 that submitted a tx to
/// the inbox to the msg.sender viewed in the L2
/// @param l1Address the address in the L1 that triggered the tx to L2
/// @return l2Address L2 address as viewed in msg.sender
function applyL1ToL2Alias(address l1Address) internal pure returns (address l2Address) {
unchecked {
l2Address = address(uint160(l1Address) + OFFSET);
}
}
/// @notice Utility function that converts the msg.sender viewed in the L2 to the
/// address in the L1 that submitted a tx to the inbox
/// @param l2Address L2 address as viewed in msg.sender
/// @return l1Address the address in the L1 that triggered the tx to L2
function undoL1ToL2Alias(address l2Address) internal pure returns (address l1Address) {
unchecked {
l1Address = address(uint160(l2Address) - OFFSET);
}
}
}// Copyright 2021-2022, Offchain Labs, Inc.
// For license information, see https://github.com/OffchainLabs/nitro-contracts/blob/main/LICENSE
// SPDX-License-Identifier: BUSL-1.1
// solhint-disable-next-line compiler-version
pragma solidity >=0.6.9 <0.9.0;
interface IGasRefunder {
function onGasSpent(
address payable spender,
uint256 gasUsed,
uint256 calldataSize
) external returns (bool success);
}
abstract contract GasRefundEnabled {
/// @dev this refunds the sender for execution costs of the tx
/// calldata costs are only refunded if `msg.sender == tx.origin` to guarantee the value refunded relates to charging
/// for the `tx.input`. this avoids a possible attack where you generate large calldata from a contract and get over-refunded
modifier refundsGas(IGasRefunder gasRefunder) {
uint256 startGasLeft = gasleft();
_;
if (address(gasRefunder) != address(0)) {
uint256 calldataSize = msg.data.length;
uint256 calldataWords = (calldataSize + 31) / 32;
// account for the CALLDATACOPY cost of the proxy contract, including the memory expansion cost
startGasLeft += calldataWords * 6 + (calldataWords**2) / 512;
// if triggered in a contract call, the spender may be overrefunded by appending dummy data to the call
// so we check if it is a top level call, which would mean the sender paid calldata as part of tx.input
// solhint-disable-next-line avoid-tx-origin
if (msg.sender != tx.origin) {
// We can't be sure if this calldata came from the top level tx,
// so to be safe we tell the gas refunder there was no calldata.
calldataSize = 0;
}
gasRefunder.onGasSpent(payable(msg.sender), startGasLeft - gasleft(), calldataSize);
}
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IAxelarGateway } from '../interfaces/IAxelarGateway.sol';
import { IAxelarExecutable } from '../interfaces/IAxelarExecutable.sol';
contract AxelarExecutable is IAxelarExecutable {
IAxelarGateway public immutable gateway;
constructor(address gateway_) {
if (gateway_ == address(0)) revert InvalidAddress();
gateway = IAxelarGateway(gateway_);
}
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) external {
bytes32 payloadHash = keccak256(payload);
if (!gateway.validateContractCall(commandId, sourceChain, sourceAddress, payloadHash))
revert NotApprovedByGateway();
_execute(sourceChain, sourceAddress, payload);
}
function executeWithToken(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) external {
bytes32 payloadHash = keccak256(payload);
if (
!gateway.validateContractCallAndMint(
commandId,
sourceChain,
sourceAddress,
payloadHash,
tokenSymbol,
amount
)
) revert NotApprovedByGateway();
_executeWithToken(sourceChain, sourceAddress, payload, tokenSymbol, amount);
}
function _execute(
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) internal virtual {}
function _executeWithToken(
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) internal virtual {}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IAxelarGateway } from './IAxelarGateway.sol';
interface IAxelarExecutable {
error InvalidAddress();
error NotApprovedByGateway();
function gateway() external view returns (IAxelarGateway);
function execute(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload
) external;
function executeWithToken(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes calldata payload,
string calldata tokenSymbol,
uint256 amount
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IUpgradable } from '../interfaces/IUpgradable.sol';
/**
* @title IAxelarGasService Interface
* @notice This is an interface for the AxelarGasService contract which manages gas payments
* and refunds for cross-chain communication on the Axelar network.
* @dev This interface inherits IUpgradable
*/
interface IAxelarGasService is IUpgradable {
error NothingReceived();
error InvalidAddress();
error NotCollector();
error InvalidAmounts();
event GasPaidForContractCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event GasPaidForContractCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForContractCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForContractCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
uint256 gasFeeAmount,
address refundAddress
);
event GasPaidForExpressCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event GasPaidForExpressCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForExpressCall(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasPaidForExpressCallWithToken(
address indexed sourceAddress,
string destinationChain,
string destinationAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
uint256 gasFeeAmount,
address refundAddress
);
event GasAdded(
bytes32 indexed txHash,
uint256 indexed logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeGasAdded(bytes32 indexed txHash, uint256 indexed logIndex, uint256 gasFeeAmount, address refundAddress);
event ExpressGasAdded(
bytes32 indexed txHash,
uint256 indexed logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
);
event NativeExpressGasAdded(
bytes32 indexed txHash,
uint256 indexed logIndex,
uint256 gasFeeAmount,
address refundAddress
);
event Refunded(
bytes32 indexed txHash,
uint256 indexed logIndex,
address payable receiver,
address token,
uint256 amount
);
/**
* @notice Pay for gas using ERC20 tokens for a contract call on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param gasToken The address of the ERC20 token used to pay for gas
* @param gasFeeAmount The amount of tokens to pay for gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function payGasForContractCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Pay for gas using ERC20 tokens for a contract call with tokens on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call with tokens will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call with tokens
* @param symbol The symbol of the token to be sent with the call
* @param amount The amount of tokens to be sent with the call
* @param gasToken The address of the ERC20 token used to pay for gas
* @param gasFeeAmount The amount of tokens to pay for gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function payGasForContractCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Pay for gas using native currency for a contract call on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param refundAddress The address where refunds, if any, should be sent
*/
function payNativeGasForContractCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address refundAddress
) external payable;
/**
* @notice Pay for gas using native currency for a contract call with tokens on a destination chain.
* @dev This function is called on the source chain before calling the gateway to execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call with tokens will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call with tokens
* @param symbol The symbol of the token to be sent with the call
* @param amount The amount of tokens to be sent with the call
* @param refundAddress The address where refunds, if any, should be sent
*/
function payNativeGasForContractCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address refundAddress
) external payable;
/**
* @notice Pay for gas using ERC20 tokens for an express contract call on a destination chain.
* @dev This function is called on the source chain before calling the gateway to express execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param gasToken The address of the ERC20 token used to pay for gas
* @param gasFeeAmount The amount of tokens to pay for gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function payGasForExpressCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Pay for gas using ERC20 tokens for an express contract call with tokens on a destination chain.
* @dev This function is called on the source chain before calling the gateway to express execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call with tokens will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call with tokens
* @param symbol The symbol of the token to be sent with the call
* @param amount The amount of tokens to be sent with the call
* @param gasToken The address of the ERC20 token used to pay for gas
* @param gasFeeAmount The amount of tokens to pay for gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function payGasForExpressCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Pay for gas using native currency for an express contract call on a destination chain.
* @dev This function is called on the source chain before calling the gateway to express execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call
* @param refundAddress The address where refunds, if any, should be sent
*/
function payNativeGasForExpressCall(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
address refundAddress
) external payable;
/**
* @notice Pay for gas using native currency for an express contract call with tokens on a destination chain.
* @dev This function is called on the source chain before calling the gateway to express execute a remote contract.
* @param sender The address making the payment
* @param destinationChain The target chain where the contract call with tokens will be made
* @param destinationAddress The target address on the destination chain
* @param payload Data payload for the contract call with tokens
* @param symbol The symbol of the token to be sent with the call
* @param amount The amount of tokens to be sent with the call
* @param refundAddress The address where refunds, if any, should be sent
*/
function payNativeGasForExpressCallWithToken(
address sender,
string calldata destinationChain,
string calldata destinationAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount,
address refundAddress
) external payable;
/**
* @notice Add additional gas payment using ERC20 tokens after initiating a cross-chain call.
* @dev This function can be called on the source chain after calling the gateway to execute a remote contract.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param gasToken The ERC20 token address used to add gas
* @param gasFeeAmount The amount of tokens to add as gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function addGas(
bytes32 txHash,
uint256 logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Add additional gas payment using native currency after initiating a cross-chain call.
* @dev This function can be called on the source chain after calling the gateway to execute a remote contract.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param refundAddress The address where refunds, if any, should be sent
*/
function addNativeGas(
bytes32 txHash,
uint256 logIndex,
address refundAddress
) external payable;
/**
* @notice Add additional gas payment using ERC20 tokens after initiating an express cross-chain call.
* @dev This function can be called on the source chain after calling the gateway to express execute a remote contract.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param gasToken The ERC20 token address used to add gas
* @param gasFeeAmount The amount of tokens to add as gas
* @param refundAddress The address where refunds, if any, should be sent
*/
function addExpressGas(
bytes32 txHash,
uint256 logIndex,
address gasToken,
uint256 gasFeeAmount,
address refundAddress
) external;
/**
* @notice Add additional gas payment using native currency after initiating an express cross-chain call.
* @dev This function can be called on the source chain after calling the gateway to express execute a remote contract.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param refundAddress The address where refunds, if any, should be sent
*/
function addNativeExpressGas(
bytes32 txHash,
uint256 logIndex,
address refundAddress
) external payable;
/**
* @notice Allows the gasCollector to collect accumulated fees from the contract.
* @dev Use address(0) as the token address for native currency.
* @param receiver The address to receive the collected fees
* @param tokens Array of token addresses to be collected
* @param amounts Array of amounts to be collected for each respective token address
*/
function collectFees(
address payable receiver,
address[] calldata tokens,
uint256[] calldata amounts
) external;
/**
* @notice Refunds gas payment to the receiver in relation to a specific cross-chain transaction.
* @dev Only callable by the gasCollector.
* @dev Use address(0) as the token address to refund native currency.
* @param txHash The transaction hash of the cross-chain call
* @param logIndex The log index for the cross-chain call
* @param receiver The address to receive the refund
* @param token The token address to be refunded
* @param amount The amount to refund
*/
function refund(
bytes32 txHash,
uint256 logIndex,
address payable receiver,
address token,
uint256 amount
) external;
/**
* @notice Returns the address of the designated gas collector.
* @return address of the gas collector
*/
function gasCollector() external returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IGovernable } from './IGovernable.sol';
import { IImplementation } from './IImplementation.sol';
interface IAxelarGateway is IImplementation, IGovernable {
/**********\
|* Errors *|
\**********/
error NotSelf();
error InvalidCodeHash();
error SetupFailed();
error InvalidAuthModule();
error InvalidTokenDeployer();
error InvalidAmount();
error InvalidChainId();
error InvalidCommands();
error TokenDoesNotExist(string symbol);
error TokenAlreadyExists(string symbol);
error TokenDeployFailed(string symbol);
error TokenContractDoesNotExist(address token);
error BurnFailed(string symbol);
error MintFailed(string symbol);
error InvalidSetMintLimitsParams();
error ExceedMintLimit(string symbol);
/**********\
|* Events *|
\**********/
event TokenSent(
address indexed sender,
string destinationChain,
string destinationAddress,
string symbol,
uint256 amount
);
event ContractCall(
address indexed sender,
string destinationChain,
string destinationContractAddress,
bytes32 indexed payloadHash,
bytes payload
);
event ContractCallWithToken(
address indexed sender,
string destinationChain,
string destinationContractAddress,
bytes32 indexed payloadHash,
bytes payload,
string symbol,
uint256 amount
);
event Executed(bytes32 indexed commandId);
event TokenDeployed(string symbol, address tokenAddresses);
event ContractCallApproved(
bytes32 indexed commandId,
string sourceChain,
string sourceAddress,
address indexed contractAddress,
bytes32 indexed payloadHash,
bytes32 sourceTxHash,
uint256 sourceEventIndex
);
event ContractCallApprovedWithMint(
bytes32 indexed commandId,
string sourceChain,
string sourceAddress,
address indexed contractAddress,
bytes32 indexed payloadHash,
string symbol,
uint256 amount,
bytes32 sourceTxHash,
uint256 sourceEventIndex
);
event ContractCallExecuted(bytes32 indexed commandId);
event TokenMintLimitUpdated(string symbol, uint256 limit);
event OperatorshipTransferred(bytes newOperatorsData);
event Upgraded(address indexed implementation);
/********************\
|* Public Functions *|
\********************/
function sendToken(
string calldata destinationChain,
string calldata destinationAddress,
string calldata symbol,
uint256 amount
) external;
function callContract(
string calldata destinationChain,
string calldata contractAddress,
bytes calldata payload
) external;
function callContractWithToken(
string calldata destinationChain,
string calldata contractAddress,
bytes calldata payload,
string calldata symbol,
uint256 amount
) external;
function isContractCallApproved(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
address contractAddress,
bytes32 payloadHash
) external view returns (bool);
function isContractCallAndMintApproved(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
address contractAddress,
bytes32 payloadHash,
string calldata symbol,
uint256 amount
) external view returns (bool);
function validateContractCall(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes32 payloadHash
) external returns (bool);
function validateContractCallAndMint(
bytes32 commandId,
string calldata sourceChain,
string calldata sourceAddress,
bytes32 payloadHash,
string calldata symbol,
uint256 amount
) external returns (bool);
/***********\
|* Getters *|
\***********/
function authModule() external view returns (address);
function tokenDeployer() external view returns (address);
function tokenMintLimit(string memory symbol) external view returns (uint256);
function tokenMintAmount(string memory symbol) external view returns (uint256);
function allTokensFrozen() external view returns (bool);
function implementation() external view returns (address);
function tokenAddresses(string memory symbol) external view returns (address);
function tokenFrozen(string memory symbol) external view returns (bool);
function isCommandExecuted(bytes32 commandId) external view returns (bool);
/************************\
|* Governance Functions *|
\************************/
function setTokenMintLimits(string[] calldata symbols, uint256[] calldata limits) external;
function upgrade(
address newImplementation,
bytes32 newImplementationCodeHash,
bytes calldata setupParams
) external;
/**********************\
|* External Functions *|
\**********************/
function execute(bytes calldata input) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// General interface for upgradable contracts
interface IContractIdentifier {
/**
* @notice Returns the contract ID. It can be used as a check during upgrades.
* @dev Meant to be overridden in derived contracts.
* @return bytes32 The contract ID
*/
function contractId() external pure returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title IGovernable Interface
* @notice This is an interface used by the AxelarGateway contract to manage governance and mint limiter roles.
*/
interface IGovernable {
error NotGovernance();
error NotMintLimiter();
error InvalidGovernance();
error InvalidMintLimiter();
event GovernanceTransferred(address indexed previousGovernance, address indexed newGovernance);
event MintLimiterTransferred(address indexed previousGovernance, address indexed newGovernance);
/**
* @notice Returns the governance address.
* @return address of the governance
*/
function governance() external view returns (address);
/**
* @notice Returns the mint limiter address.
* @return address of the mint limiter
*/
function mintLimiter() external view returns (address);
/**
* @notice Transfer the governance role to another address.
* @param newGovernance The new governance address
*/
function transferGovernance(address newGovernance) external;
/**
* @notice Transfer the mint limiter role to another address.
* @param newGovernance The new mint limiter address
*/
function transferMintLimiter(address newGovernance) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IContractIdentifier } from './IContractIdentifier.sol';
interface IImplementation is IContractIdentifier {
error NotProxy();
function setup(bytes calldata data) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
/**
* @title IOwnable Interface
* @notice IOwnable is an interface that abstracts the implementation of a
* contract with ownership control features. It's commonly used in upgradable
* contracts and includes the functionality to get current owner, transfer
* ownership, and propose and accept ownership.
*/
interface IOwnable {
error NotOwner();
error InvalidOwner();
error InvalidOwnerAddress();
event OwnershipTransferStarted(address indexed newOwner);
event OwnershipTransferred(address indexed newOwner);
/**
* @notice Returns the current owner of the contract.
* @return address The address of the current owner
*/
function owner() external view returns (address);
/**
* @notice Returns the address of the pending owner of the contract.
* @return address The address of the pending owner
*/
function pendingOwner() external view returns (address);
/**
* @notice Transfers ownership of the contract to a new address
* @param newOwner The address to transfer ownership to
*/
function transferOwnership(address newOwner) external;
/**
* @notice Proposes to transfer the contract's ownership to a new address.
* The new owner needs to accept the ownership explicitly.
* @param newOwner The address to transfer ownership to
*/
function proposeOwnership(address newOwner) external;
/**
* @notice Transfers ownership to the pending owner.
* @dev Can only be called by the pending owner
*/
function acceptOwnership() external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import { IOwnable } from './IOwnable.sol';
import { IImplementation } from './IImplementation.sol';
// General interface for upgradable contracts
interface IUpgradable is IOwnable, IImplementation {
error InvalidCodeHash();
error InvalidImplementation();
error SetupFailed();
event Upgraded(address indexed newImplementation);
function implementation() external view returns (address);
function upgrade(
address newImplementation,
bytes32 newImplementationCodeHash,
bytes calldata params
) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Client} from "../libraries/Client.sol";
/// @notice Application contracts that intend to receive messages from
/// the router should implement this interface.
interface IAny2EVMMessageReceiver {
/// @notice Called by the Router to deliver a message.
/// If this reverts, any token transfers also revert. The message
/// will move to a FAILED state and become available for manual execution.
/// @param message CCIP Message
/// @dev Note ensure you check the msg.sender is the OffRampRouter
function ccipReceive(Client.Any2EVMMessage calldata message) external;
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Client} from "../libraries/Client.sol";
interface IRouterClient {
error UnsupportedDestinationChain(uint64 destChainSelector);
error InsufficientFeeTokenAmount();
error InvalidMsgValue();
/// @notice Checks if the given chain ID is supported for sending/receiving.
/// @param chainSelector The chain to check.
/// @return supported is true if it is supported, false if not.
function isChainSupported(uint64 chainSelector) external view returns (bool supported);
/// @notice Gets a list of all supported tokens which can be sent or received
/// to/from a given chain id.
/// @param chainSelector The chainSelector.
/// @return tokens The addresses of all tokens that are supported.
function getSupportedTokens(uint64 chainSelector) external view returns (address[] memory tokens);
/// @param destinationChainSelector The destination chainSelector
/// @param message The cross-chain CCIP message including data and/or tokens
/// @return fee returns guaranteed execution fee for the specified message
/// delivery to destination chain
/// @dev returns 0 fee on invalid message.
function getFee(
uint64 destinationChainSelector,
Client.EVM2AnyMessage memory message
) external view returns (uint256 fee);
/// @notice Request a message to be sent to the destination chain
/// @param destinationChainSelector The destination chain ID
/// @param message The cross-chain CCIP message including data and/or tokens
/// @return messageId The message ID
/// @dev Note if msg.value is larger than the required fee (from getFee) we accept
/// the overpayment with no refund.
function ccipSend(
uint64 destinationChainSelector,
Client.EVM2AnyMessage calldata message
) external payable returns (bytes32);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
// End consumer library.
library Client {
struct EVMTokenAmount {
address token; // token address on the local chain.
uint256 amount; // Amount of tokens.
}
struct Any2EVMMessage {
bytes32 messageId; // MessageId corresponding to ccipSend on source.
uint64 sourceChainSelector; // Source chain selector.
bytes sender; // abi.decode(sender) if coming from an EVM chain.
bytes data; // payload sent in original message.
EVMTokenAmount[] destTokenAmounts; // Tokens and their amounts in their destination chain representation.
}
// If extraArgs is empty bytes, the default is 200k gas limit and strict = false.
struct EVM2AnyMessage {
bytes receiver; // abi.encode(receiver address) for dest EVM chains
bytes data; // Data payload
EVMTokenAmount[] tokenAmounts; // Token transfers
address feeToken; // Address of feeToken. address(0) means you will send msg.value.
bytes extraArgs; // Populate this with _argsToBytes(EVMExtraArgsV1)
}
// extraArgs will evolve to support new features
// bytes4(keccak256("CCIP EVMExtraArgsV1"));
bytes4 public constant EVM_EXTRA_ARGS_V1_TAG = 0x97a657c9;
struct EVMExtraArgsV1 {
uint256 gasLimit; // ATTENTION!!! MAX GAS LIMIT 4M FOR BETA TESTING
bool strict; // See strict sequencing details below.
}
function _argsToBytes(EVMExtraArgsV1 memory extraArgs) internal pure returns (bytes memory bts) {
return abi.encodeWithSelector(EVM_EXTRA_ARGS_V1_TAG, extraArgs);
}
}// SPDX-License-Identifier: MIT
pragma solidity >0.5.0 <0.9.0;
/**
* @title ICrossDomainMessenger
*/
interface ICrossDomainMessenger {
/**********
* Events *
**********/
event SentMessage(
address indexed target,
address sender,
bytes message,
uint256 messageNonce,
uint256 gasLimit
);
event RelayedMessage(bytes32 indexed msgHash);
event FailedRelayedMessage(bytes32 indexed msgHash);
/*************
* Variables *
*************/
function xDomainMessageSender() external view returns (address);
/********************
* Public Functions *
********************/
/**
* Sends a cross domain message to the target messenger.
* @param _target Target contract address.
* @param _message Message to send to the target.
* @param _gasLimit Gas limit for the provided message.
*/
function sendMessage(
address _target,
bytes calldata _message,
uint32 _gasLimit
) external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IMessageLibManager } from "./IMessageLibManager.sol";
import { IMessagingComposer } from "./IMessagingComposer.sol";
import { IMessagingChannel } from "./IMessagingChannel.sol";
import { IMessagingContext } from "./IMessagingContext.sol";
struct MessagingParams {
uint32 dstEid;
bytes32 receiver;
bytes message;
bytes options;
bool payInLzToken;
}
struct MessagingReceipt {
bytes32 guid;
uint64 nonce;
MessagingFee fee;
}
struct MessagingFee {
uint256 nativeFee;
uint256 lzTokenFee;
}
struct Origin {
uint32 srcEid;
bytes32 sender;
uint64 nonce;
}
interface ILayerZeroEndpointV2 is IMessageLibManager, IMessagingComposer, IMessagingChannel, IMessagingContext {
event PacketSent(bytes encodedPayload, bytes options, address sendLibrary);
event PacketVerified(Origin origin, address receiver, bytes32 payloadHash);
event PacketDelivered(Origin origin, address receiver);
event LzReceiveAlert(
address indexed receiver,
address indexed executor,
Origin origin,
bytes32 guid,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);
event LzTokenSet(address token);
event DelegateSet(address sender, address delegate);
function quote(MessagingParams calldata _params, address _sender) external view returns (MessagingFee memory);
function send(
MessagingParams calldata _params,
address _refundAddress
) external payable returns (MessagingReceipt memory);
function verify(Origin calldata _origin, address _receiver, bytes32 _payloadHash) external;
function verifiable(Origin calldata _origin, address _receiver) external view returns (bool);
function initializable(Origin calldata _origin, address _receiver) external view returns (bool);
function lzReceive(
Origin calldata _origin,
address _receiver,
bytes32 _guid,
bytes calldata _message,
bytes calldata _extraData
) external payable;
// oapp can burn messages partially by calling this function with its own business logic if messages are verified in order
function clear(address _oapp, Origin calldata _origin, bytes32 _guid, bytes calldata _message) external;
function setLzToken(address _lzToken) external;
function lzToken() external view returns (address);
function nativeToken() external view returns (address);
function setDelegate(address _delegate) external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IERC165 } from "@openzeppelin/contracts/utils/introspection/IERC165.sol";
import { SetConfigParam } from "./IMessageLibManager.sol";
enum MessageLibType {
Send,
Receive,
SendAndReceive
}
interface IMessageLib is IERC165 {
function setConfig(address _oapp, SetConfigParam[] calldata _config) external;
function getConfig(uint32 _eid, address _oapp, uint32 _configType) external view returns (bytes memory config);
function isSupportedEid(uint32 _eid) external view returns (bool);
// message libs of same major version are compatible
function version() external view returns (uint64 major, uint8 minor, uint8 endpointVersion);
function messageLibType() external view returns (MessageLibType);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
struct SetConfigParam {
uint32 eid;
uint32 configType;
bytes config;
}
interface IMessageLibManager {
struct Timeout {
address lib;
uint256 expiry;
}
event LibraryRegistered(address newLib);
event DefaultSendLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibrarySet(uint32 eid, address newLib);
event DefaultReceiveLibraryTimeoutSet(uint32 eid, address oldLib, uint256 expiry);
event SendLibrarySet(address sender, uint32 eid, address newLib);
event ReceiveLibrarySet(address receiver, uint32 eid, address newLib);
event ReceiveLibraryTimeoutSet(address receiver, uint32 eid, address oldLib, uint256 timeout);
function registerLibrary(address _lib) external;
function isRegisteredLibrary(address _lib) external view returns (bool);
function getRegisteredLibraries() external view returns (address[] memory);
function setDefaultSendLibrary(uint32 _eid, address _newLib) external;
function defaultSendLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibrary(uint32 _eid, address _newLib, uint256 _gracePeriod) external;
function defaultReceiveLibrary(uint32 _eid) external view returns (address);
function setDefaultReceiveLibraryTimeout(uint32 _eid, address _lib, uint256 _expiry) external;
function defaultReceiveLibraryTimeout(uint32 _eid) external view returns (address lib, uint256 expiry);
function isSupportedEid(uint32 _eid) external view returns (bool);
function isValidReceiveLibrary(address _receiver, uint32 _eid, address _lib) external view returns (bool);
/// ------------------- OApp interfaces -------------------
function setSendLibrary(address _oapp, uint32 _eid, address _newLib) external;
function getSendLibrary(address _sender, uint32 _eid) external view returns (address lib);
function isDefaultSendLibrary(address _sender, uint32 _eid) external view returns (bool);
function setReceiveLibrary(address _oapp, uint32 _eid, address _newLib, uint256 _gracePeriod) external;
function getReceiveLibrary(address _receiver, uint32 _eid) external view returns (address lib, bool isDefault);
function setReceiveLibraryTimeout(address _oapp, uint32 _eid, address _lib, uint256 _expiry) external;
function receiveLibraryTimeout(address _receiver, uint32 _eid) external view returns (address lib, uint256 expiry);
function setConfig(address _oapp, address _lib, SetConfigParam[] calldata _params) external;
function getConfig(
address _oapp,
address _lib,
uint32 _eid,
uint32 _configType
) external view returns (bytes memory config);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingChannel {
event InboundNonceSkipped(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce);
event PacketNilified(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
event PacketBurnt(uint32 srcEid, bytes32 sender, address receiver, uint64 nonce, bytes32 payloadHash);
function eid() external view returns (uint32);
// this is an emergency function if a message cannot be verified for some reasons
// required to provide _nextNonce to avoid race condition
function skip(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce) external;
function nilify(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
function burn(address _oapp, uint32 _srcEid, bytes32 _sender, uint64 _nonce, bytes32 _payloadHash) external;
function nextGuid(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (bytes32);
function inboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
function outboundNonce(address _sender, uint32 _dstEid, bytes32 _receiver) external view returns (uint64);
function inboundPayloadHash(
address _receiver,
uint32 _srcEid,
bytes32 _sender,
uint64 _nonce
) external view returns (bytes32);
function lazyInboundNonce(address _receiver, uint32 _srcEid, bytes32 _sender) external view returns (uint64);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingComposer {
event ComposeSent(address from, address to, bytes32 guid, uint16 index, bytes message);
event ComposeDelivered(address from, address to, bytes32 guid, uint16 index);
event LzComposeAlert(
address indexed from,
address indexed to,
address indexed executor,
bytes32 guid,
uint16 index,
uint256 gas,
uint256 value,
bytes message,
bytes extraData,
bytes reason
);
function composeQueue(
address _from,
address _to,
bytes32 _guid,
uint16 _index
) external view returns (bytes32 messageHash);
function sendCompose(address _to, bytes32 _guid, uint16 _index, bytes calldata _message) external;
function lzCompose(
address _from,
address _to,
bytes32 _guid,
uint16 _index,
bytes calldata _message,
bytes calldata _extraData
) external payable;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IMessagingContext {
function isSendingMessage() external view returns (bool);
function getSendContext() external view returns (uint32 dstEid, address sender);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { MessagingFee } from "./ILayerZeroEndpointV2.sol";
import { IMessageLib } from "./IMessageLib.sol";
struct Packet {
uint64 nonce;
uint32 srcEid;
address sender;
uint32 dstEid;
bytes32 receiver;
bytes32 guid;
bytes message;
}
interface ISendLib is IMessageLib {
function send(
Packet calldata _packet,
bytes calldata _options,
bool _payInLzToken
) external returns (MessagingFee memory, bytes memory encodedPacket);
function quote(
Packet calldata _packet,
bytes calldata _options,
bool _payInLzToken
) external view returns (MessagingFee memory);
function setTreasury(address _treasury) external;
function withdrawFee(address _to, uint256 _amount) external;
function withdrawLzTokenFee(address _lzToken, address _to, uint256 _amount) external;
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
library AddressCast {
error AddressCast_InvalidSizeForAddress();
error AddressCast_InvalidAddress();
function toBytes32(bytes calldata _addressBytes) internal pure returns (bytes32 result) {
if (_addressBytes.length > 32) revert AddressCast_InvalidAddress();
result = bytes32(_addressBytes);
unchecked {
uint256 offset = 32 - _addressBytes.length;
result = result >> (offset * 8);
}
}
function toBytes32(address _address) internal pure returns (bytes32 result) {
result = bytes32(uint256(uint160(_address)));
}
function toBytes(bytes32 _addressBytes32, uint256 _size) internal pure returns (bytes memory result) {
if (_size == 0 || _size > 32) revert AddressCast_InvalidSizeForAddress();
result = new bytes(_size);
unchecked {
uint256 offset = 256 - _size * 8;
assembly {
mstore(add(result, 32), shl(offset, _addressBytes32))
}
}
}
function toAddress(bytes32 _addressBytes32) internal pure returns (address result) {
result = address(uint160(uint256(_addressBytes32)));
}
function toAddress(bytes calldata _addressBytes) internal pure returns (address result) {
if (_addressBytes.length != 20) revert AddressCast_InvalidAddress();
result = address(bytes20(_addressBytes));
}
}// 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: LZBL-1.2
pragma solidity ^0.8.20;
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
library Transfer {
using SafeERC20 for IERC20;
address internal constant ADDRESS_ZERO = address(0);
error Transfer_NativeFailed(address _to, uint256 _value);
error Transfer_ToAddressIsZero();
function native(address _to, uint256 _value) internal {
if (_to == ADDRESS_ZERO) revert Transfer_ToAddressIsZero();
(bool success, ) = _to.call{ value: _value }("");
if (!success) revert Transfer_NativeFailed(_to, _value);
}
function token(address _token, address _to, uint256 _value) internal {
if (_to == ADDRESS_ZERO) revert Transfer_ToAddressIsZero();
IERC20(_token).safeTransfer(_to, _value);
}
function nativeOrToken(address _token, address _to, uint256 _value) internal {
if (_token == ADDRESS_ZERO) {
native(_to, _value);
} else {
token(_token, _to, _value);
}
}
}// 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: LZBL-1.2
pragma solidity ^0.8.20;
import { CalldataBytesLib } from "../../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;
error Executor_InvalidLzReceiveOption();
error Executor_InvalidNativeDropOption();
error Executor_InvalidLzComposeOption();
/// @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 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);
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { Packet } from "../../interfaces/ISendLib.sol";
import { AddressCast } from "../../libs/AddressCast.sol";
library PacketV1Codec {
using AddressCast for address;
using AddressCast for bytes32;
uint8 internal constant PACKET_VERSION = 1;
// header (version + nonce + path)
// version
uint256 private constant PACKET_VERSION_OFFSET = 0;
// nonce
uint256 private constant NONCE_OFFSET = 1;
// path
uint256 private constant SRC_EID_OFFSET = 9;
uint256 private constant SENDER_OFFSET = 13;
uint256 private constant DST_EID_OFFSET = 45;
uint256 private constant RECEIVER_OFFSET = 49;
// payload (guid + message)
uint256 private constant GUID_OFFSET = 81; // keccak256(nonce + path)
uint256 private constant MESSAGE_OFFSET = 113;
function encode(Packet memory _packet) internal pure returns (bytes memory encodedPacket) {
encodedPacket = abi.encodePacked(
PACKET_VERSION,
_packet.nonce,
_packet.srcEid,
_packet.sender.toBytes32(),
_packet.dstEid,
_packet.receiver,
_packet.guid,
_packet.message
);
}
function encodePacketHeader(Packet memory _packet) internal pure returns (bytes memory) {
return
abi.encodePacked(
PACKET_VERSION,
_packet.nonce,
_packet.srcEid,
_packet.sender.toBytes32(),
_packet.dstEid,
_packet.receiver
);
}
function encodePayload(Packet memory _packet) internal pure returns (bytes memory) {
return abi.encodePacked(_packet.guid, _packet.message);
}
function header(bytes calldata _packet) internal pure returns (bytes calldata) {
return _packet[0:GUID_OFFSET];
}
function version(bytes calldata _packet) internal pure returns (uint8) {
return uint8(bytes1(_packet[PACKET_VERSION_OFFSET:NONCE_OFFSET]));
}
function nonce(bytes calldata _packet) internal pure returns (uint64) {
return uint64(bytes8(_packet[NONCE_OFFSET:SRC_EID_OFFSET]));
}
function srcEid(bytes calldata _packet) internal pure returns (uint32) {
return uint32(bytes4(_packet[SRC_EID_OFFSET:SENDER_OFFSET]));
}
function sender(bytes calldata _packet) internal pure returns (bytes32) {
return bytes32(_packet[SENDER_OFFSET:DST_EID_OFFSET]);
}
function senderAddressB20(bytes calldata _packet) internal pure returns (address) {
return sender(_packet).toAddress();
}
function dstEid(bytes calldata _packet) internal pure returns (uint32) {
return uint32(bytes4(_packet[DST_EID_OFFSET:RECEIVER_OFFSET]));
}
function receiver(bytes calldata _packet) internal pure returns (bytes32) {
return bytes32(_packet[RECEIVER_OFFSET:GUID_OFFSET]);
}
function receiverB20(bytes calldata _packet) internal pure returns (address) {
return receiver(_packet).toAddress();
}
function guid(bytes calldata _packet) internal pure returns (bytes32) {
return bytes32(_packet[GUID_OFFSET:MESSAGE_OFFSET]);
}
function message(bytes calldata _packet) internal pure returns (bytes calldata) {
return bytes(_packet[MESSAGE_OFFSET:]);
}
function payload(bytes calldata _packet) internal pure returns (bytes calldata) {
return bytes(_packet[GUID_OFFSET:]);
}
function payloadHash(bytes calldata _packet) internal pure returns (bytes32) {
return keccak256(payload(_packet));
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.7.0;
pragma abicoder v2;
interface ILayerZeroUltraLightNodeV2 {
// Relayer functions
function validateTransactionProof(
uint16 _srcChainId,
address _dstAddress,
uint _gasLimit,
bytes32 _lookupHash,
bytes32 _blockData,
bytes calldata _transactionProof
) external;
// an Oracle delivers the block data using updateHash()
function updateHash(uint16 _srcChainId, bytes32 _lookupHash, uint _confirmations, bytes32 _blockData) external;
// can only withdraw the receivable of the msg.sender
function withdrawNative(address payable _to, uint _amount) external;
function withdrawZRO(address _to, uint _amount) external;
// view functions
function getAppConfig(
uint16 _remoteChainId,
address _userApplicationAddress
) external view returns (ApplicationConfiguration memory);
function accruedNativeFee(address _address) external view returns (uint);
struct ApplicationConfiguration {
uint16 inboundProofLibraryVersion;
uint64 inboundBlockConfirmations;
address relayer;
uint16 outboundProofType;
uint64 outboundBlockConfirmations;
address oracle;
}
event HashReceived(
uint16 indexed srcChainId,
address indexed oracle,
bytes32 lookupHash,
bytes32 blockData,
uint confirmations
);
event RelayerParams(bytes adapterParams, uint16 outboundProofType);
event Packet(bytes payload);
event InvalidDst(
uint16 indexed srcChainId,
bytes srcAddress,
address indexed dstAddress,
uint64 nonce,
bytes32 payloadHash
);
event PacketReceived(
uint16 indexed srcChainId,
bytes srcAddress,
address indexed dstAddress,
uint64 nonce,
bytes32 payloadHash
);
event AppConfigUpdated(address indexed userApplication, uint indexed configType, bytes newConfig);
event AddInboundProofLibraryForChain(uint16 indexed chainId, address lib);
event EnableSupportedOutboundProof(uint16 indexed chainId, uint16 proofType);
event SetChainAddressSize(uint16 indexed chainId, uint size);
event SetDefaultConfigForChainId(
uint16 indexed chainId,
uint16 inboundProofLib,
uint64 inboundBlockConfirm,
address relayer,
uint16 outboundProofType,
uint64 outboundBlockConfirm,
address oracle
);
event SetDefaultAdapterParamsForChainId(uint16 indexed chainId, uint16 indexed proofType, bytes adapterParams);
event SetLayerZeroToken(address indexed tokenAddress);
event SetRemoteUln(uint16 indexed chainId, bytes32 uln);
event SetTreasury(address indexed treasuryAddress);
event WithdrawZRO(address indexed msgSender, address indexed to, uint amount);
event WithdrawNative(address indexed msgSender, address indexed to, uint amount);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/ContextUpgradeable.sol";
import {Initializable} from "../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 {
__Ownable_init_unchained();
}
function __Ownable_init_unchained() internal onlyInitializing {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
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);
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[49] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (proxy/utils/Initializable.sol)
pragma solidity ^0.8.2;
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 proxied contracts do not make use of a constructor, it's common to move constructor logic to an
* external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer
* function so it can only be called once. The {initializer} modifier provided by this contract will have this effect.
*
* The initialization functions use a version number. Once a version number is used, it is consumed and cannot be
* reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in
* case an upgrade adds a module that needs to be initialized.
*
* For example:
*
* [.hljs-theme-light.nopadding]
* ```solidity
* contract MyToken is ERC20Upgradeable {
* function initialize() initializer public {
* __ERC20_init("MyToken", "MTK");
* }
* }
*
* contract MyTokenV2 is MyToken, ERC20PermitUpgradeable {
* function initializeV2() reinitializer(2) public {
* __ERC20Permit_init("MyToken");
* }
* }
* ```
*
* TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as
* possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}.
*
* CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure
* that all initializers are idempotent. This is not verified automatically as constructors are by Solidity.
*
* [CAUTION]
* ====
* Avoid leaving a contract uninitialized.
*
* An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation
* contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke
* the {_disableInitializers} function in the constructor to automatically lock it when it is deployed:
*
* [.hljs-theme-light.nopadding]
* ```
* /// @custom:oz-upgrades-unsafe-allow constructor
* constructor() {
* _disableInitializers();
* }
* ```
* ====
*/
abstract contract Initializable {
/**
* @dev Indicates that the contract has been initialized.
* @custom:oz-retyped-from bool
*/
uint8 private _initialized;
/**
* @dev Indicates that the contract is in the process of being initialized.
*/
bool private _initializing;
/**
* @dev Triggered when the contract has been initialized or reinitialized.
*/
event Initialized(uint8 version);
/**
* @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope,
* `onlyInitializing` functions can be used to initialize parent contracts.
*
* Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a
* constructor.
*
* Emits an {Initialized} event.
*/
modifier initializer() {
bool isTopLevelCall = !_initializing;
require(
(isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1),
"Initializable: contract is already initialized"
);
_initialized = 1;
if (isTopLevelCall) {
_initializing = true;
}
_;
if (isTopLevelCall) {
_initializing = false;
emit Initialized(1);
}
}
/**
* @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the
* contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be
* used to initialize parent contracts.
*
* A reinitializer may be used after the original initialization step. This is essential to configure modules that
* are added through upgrades and that require initialization.
*
* When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer`
* cannot be nested. If one is invoked in the context of another, execution will revert.
*
* Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in
* a contract, executing them in the right order is up to the developer or operator.
*
* WARNING: setting the version to 255 will prevent any future reinitialization.
*
* Emits an {Initialized} event.
*/
modifier reinitializer(uint8 version) {
require(!_initializing && _initialized < version, "Initializable: contract is already initialized");
_initialized = version;
_initializing = true;
_;
_initializing = false;
emit Initialized(version);
}
/**
* @dev Modifier to protect an initialization function so that it can only be invoked by functions with the
* {initializer} and {reinitializer} modifiers, directly or indirectly.
*/
modifier onlyInitializing() {
require(_initializing, "Initializable: contract is not initializing");
_;
}
/**
* @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call.
* Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized
* to any version. It is recommended to use this to lock implementation contracts that are designed to be called
* through proxies.
*
* Emits an {Initialized} event the first time it is successfully executed.
*/
function _disableInitializers() internal virtual {
require(!_initializing, "Initializable: contract is initializing");
if (_initialized != type(uint8).max) {
_initialized = type(uint8).max;
emit Initialized(type(uint8).max);
}
}
/**
* @dev Returns the highest version that has been initialized. See {reinitializer}.
*/
function _getInitializedVersion() internal view returns (uint8) {
return _initialized;
}
/**
* @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}.
*/
function _isInitializing() internal view returns (bool) {
return _initializing;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @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
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/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 functionCallWithValue(target, data, 0, "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");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or 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 {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
import {Initializable} from "../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 {
}
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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
/**
* @dev This empty reserved space is put in place to allow future versions to add new
* variables without shifting down storage in the inheritance chain.
* See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps
*/
uint256[50] private __gap;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.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:
*
* ```solidity
* 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}:
*
* ```solidity
* 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. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
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);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @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 virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.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 virtual 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.
*
* May emit a {RoleGranted} event.
*/
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.
*
* May emit a {RoleRevoked} event.
*/
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`.
*
* May emit a {RoleRevoked} event.
*/
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.
*
* May emit a {RoleGranted} event.
*
* [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.
*
* May emit a {RoleGranted} event.
*/
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.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}// 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 IAccessControl {
/**
* @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 (last updated v4.9.0) (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 Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
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
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.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 Pausable is Context {
/**
* @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.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
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());
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (token/ERC20/extensions/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.
*
* ==== Security Considerations
*
* There are two important considerations concerning the use of `permit`. The first is that a valid permit signature
* expresses an allowance, and it should not be assumed to convey additional meaning. In particular, it should not be
* considered as an intention to spend the allowance in any specific way. The second is that because permits have
* built-in replay protection and can be submitted by anyone, they can be frontrun. A protocol that uses permits should
* take this into consideration and allow a `permit` call to fail. Combining these two aspects, a pattern that may be
* generally recommended is:
*
* ```solidity
* function doThingWithPermit(..., uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s) public {
* try token.permit(msg.sender, address(this), value, deadline, v, r, s) {} catch {}
* doThing(..., value);
* }
*
* function doThing(..., uint256 value) public {
* token.safeTransferFrom(msg.sender, address(this), value);
* ...
* }
* ```
*
* Observe that: 1) `msg.sender` is used as the owner, leaving no ambiguity as to the signer intent, and 2) the use of
* `try/catch` allows the permit to fail and makes the code tolerant to frontrunning. (See also
* {SafeERC20-safeTransferFrom}).
*
* Additionally, note that smart contract wallets (such as Argent or Safe) are not able to produce permit signatures, so
* contracts should have entry points that don't rely on permit.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*
* CAUTION: See Security Considerations above.
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the 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 `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/
function transfer(address to, 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 `from` to `to` 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 from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.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;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.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));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
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");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @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");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @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
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 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://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/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 functionCallWithValue(target, data, 0, "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");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, 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) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or 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 {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (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;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.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 ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// 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);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SafeCast.sol)
// This file was procedurally generated from scripts/generate/templates/SafeCast.js.
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 uint248 from uint256, reverting on
* overflow (when the input is greater than largest uint248).
*
* Counterpart to Solidity's `uint248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toUint248(uint256 value) internal pure returns (uint248) {
require(value <= type(uint248).max, "SafeCast: value doesn't fit in 248 bits");
return uint248(value);
}
/**
* @dev Returns the downcasted uint240 from uint256, reverting on
* overflow (when the input is greater than largest uint240).
*
* Counterpart to Solidity's `uint240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toUint240(uint256 value) internal pure returns (uint240) {
require(value <= type(uint240).max, "SafeCast: value doesn't fit in 240 bits");
return uint240(value);
}
/**
* @dev Returns the downcasted uint232 from uint256, reverting on
* overflow (when the input is greater than largest uint232).
*
* Counterpart to Solidity's `uint232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toUint232(uint256 value) internal pure returns (uint232) {
require(value <= type(uint232).max, "SafeCast: value doesn't fit in 232 bits");
return uint232(value);
}
/**
* @dev Returns the downcasted uint224 from uint256, reverting on
* overflow (when the input is greater than largest uint224).
*
* Counterpart to Solidity's `uint224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.2._
*/
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 uint216 from uint256, reverting on
* overflow (when the input is greater than largest uint216).
*
* Counterpart to Solidity's `uint216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toUint216(uint256 value) internal pure returns (uint216) {
require(value <= type(uint216).max, "SafeCast: value doesn't fit in 216 bits");
return uint216(value);
}
/**
* @dev Returns the downcasted uint208 from uint256, reverting on
* overflow (when the input is greater than largest uint208).
*
* Counterpart to Solidity's `uint208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toUint208(uint256 value) internal pure returns (uint208) {
require(value <= type(uint208).max, "SafeCast: value doesn't fit in 208 bits");
return uint208(value);
}
/**
* @dev Returns the downcasted uint200 from uint256, reverting on
* overflow (when the input is greater than largest uint200).
*
* Counterpart to Solidity's `uint200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toUint200(uint256 value) internal pure returns (uint200) {
require(value <= type(uint200).max, "SafeCast: value doesn't fit in 200 bits");
return uint200(value);
}
/**
* @dev Returns the downcasted uint192 from uint256, reverting on
* overflow (when the input is greater than largest uint192).
*
* Counterpart to Solidity's `uint192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toUint192(uint256 value) internal pure returns (uint192) {
require(value <= type(uint192).max, "SafeCast: value doesn't fit in 192 bits");
return uint192(value);
}
/**
* @dev Returns the downcasted uint184 from uint256, reverting on
* overflow (when the input is greater than largest uint184).
*
* Counterpart to Solidity's `uint184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toUint184(uint256 value) internal pure returns (uint184) {
require(value <= type(uint184).max, "SafeCast: value doesn't fit in 184 bits");
return uint184(value);
}
/**
* @dev Returns the downcasted uint176 from uint256, reverting on
* overflow (when the input is greater than largest uint176).
*
* Counterpart to Solidity's `uint176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toUint176(uint256 value) internal pure returns (uint176) {
require(value <= type(uint176).max, "SafeCast: value doesn't fit in 176 bits");
return uint176(value);
}
/**
* @dev Returns the downcasted uint168 from uint256, reverting on
* overflow (when the input is greater than largest uint168).
*
* Counterpart to Solidity's `uint168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toUint168(uint256 value) internal pure returns (uint168) {
require(value <= type(uint168).max, "SafeCast: value doesn't fit in 168 bits");
return uint168(value);
}
/**
* @dev Returns the downcasted uint160 from uint256, reverting on
* overflow (when the input is greater than largest uint160).
*
* Counterpart to Solidity's `uint160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toUint160(uint256 value) internal pure returns (uint160) {
require(value <= type(uint160).max, "SafeCast: value doesn't fit in 160 bits");
return uint160(value);
}
/**
* @dev Returns the downcasted uint152 from uint256, reverting on
* overflow (when the input is greater than largest uint152).
*
* Counterpart to Solidity's `uint152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toUint152(uint256 value) internal pure returns (uint152) {
require(value <= type(uint152).max, "SafeCast: value doesn't fit in 152 bits");
return uint152(value);
}
/**
* @dev Returns the downcasted uint144 from uint256, reverting on
* overflow (when the input is greater than largest uint144).
*
* Counterpart to Solidity's `uint144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toUint144(uint256 value) internal pure returns (uint144) {
require(value <= type(uint144).max, "SafeCast: value doesn't fit in 144 bits");
return uint144(value);
}
/**
* @dev Returns the downcasted uint136 from uint256, reverting on
* overflow (when the input is greater than largest uint136).
*
* Counterpart to Solidity's `uint136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toUint136(uint256 value) internal pure returns (uint136) {
require(value <= type(uint136).max, "SafeCast: value doesn't fit in 136 bits");
return uint136(value);
}
/**
* @dev Returns the downcasted uint128 from uint256, reverting on
* overflow (when the input is greater than largest uint128).
*
* Counterpart to Solidity's `uint128` operator.
*
* Requirements:
*
* - input must fit into 128 bits
*
* _Available since v2.5._
*/
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 uint120 from uint256, reverting on
* overflow (when the input is greater than largest uint120).
*
* Counterpart to Solidity's `uint120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toUint120(uint256 value) internal pure returns (uint120) {
require(value <= type(uint120).max, "SafeCast: value doesn't fit in 120 bits");
return uint120(value);
}
/**
* @dev Returns the downcasted uint112 from uint256, reverting on
* overflow (when the input is greater than largest uint112).
*
* Counterpart to Solidity's `uint112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toUint112(uint256 value) internal pure returns (uint112) {
require(value <= type(uint112).max, "SafeCast: value doesn't fit in 112 bits");
return uint112(value);
}
/**
* @dev Returns the downcasted uint104 from uint256, reverting on
* overflow (when the input is greater than largest uint104).
*
* Counterpart to Solidity's `uint104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toUint104(uint256 value) internal pure returns (uint104) {
require(value <= type(uint104).max, "SafeCast: value doesn't fit in 104 bits");
return uint104(value);
}
/**
* @dev Returns the downcasted uint96 from uint256, reverting on
* overflow (when the input is greater than largest uint96).
*
* Counterpart to Solidity's `uint96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.2._
*/
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 uint88 from uint256, reverting on
* overflow (when the input is greater than largest uint88).
*
* Counterpart to Solidity's `uint88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toUint88(uint256 value) internal pure returns (uint88) {
require(value <= type(uint88).max, "SafeCast: value doesn't fit in 88 bits");
return uint88(value);
}
/**
* @dev Returns the downcasted uint80 from uint256, reverting on
* overflow (when the input is greater than largest uint80).
*
* Counterpart to Solidity's `uint80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toUint80(uint256 value) internal pure returns (uint80) {
require(value <= type(uint80).max, "SafeCast: value doesn't fit in 80 bits");
return uint80(value);
}
/**
* @dev Returns the downcasted uint72 from uint256, reverting on
* overflow (when the input is greater than largest uint72).
*
* Counterpart to Solidity's `uint72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toUint72(uint256 value) internal pure returns (uint72) {
require(value <= type(uint72).max, "SafeCast: value doesn't fit in 72 bits");
return uint72(value);
}
/**
* @dev Returns the downcasted uint64 from uint256, reverting on
* overflow (when the input is greater than largest uint64).
*
* Counterpart to Solidity's `uint64` operator.
*
* Requirements:
*
* - input must fit into 64 bits
*
* _Available since v2.5._
*/
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 uint56 from uint256, reverting on
* overflow (when the input is greater than largest uint56).
*
* Counterpart to Solidity's `uint56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toUint56(uint256 value) internal pure returns (uint56) {
require(value <= type(uint56).max, "SafeCast: value doesn't fit in 56 bits");
return uint56(value);
}
/**
* @dev Returns the downcasted uint48 from uint256, reverting on
* overflow (when the input is greater than largest uint48).
*
* Counterpart to Solidity's `uint48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toUint48(uint256 value) internal pure returns (uint48) {
require(value <= type(uint48).max, "SafeCast: value doesn't fit in 48 bits");
return uint48(value);
}
/**
* @dev Returns the downcasted uint40 from uint256, reverting on
* overflow (when the input is greater than largest uint40).
*
* Counterpart to Solidity's `uint40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toUint40(uint256 value) internal pure returns (uint40) {
require(value <= type(uint40).max, "SafeCast: value doesn't fit in 40 bits");
return uint40(value);
}
/**
* @dev Returns the downcasted uint32 from uint256, reverting on
* overflow (when the input is greater than largest uint32).
*
* Counterpart to Solidity's `uint32` operator.
*
* Requirements:
*
* - input must fit into 32 bits
*
* _Available since v2.5._
*/
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 uint24 from uint256, reverting on
* overflow (when the input is greater than largest uint24).
*
* Counterpart to Solidity's `uint24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toUint24(uint256 value) internal pure returns (uint24) {
require(value <= type(uint24).max, "SafeCast: value doesn't fit in 24 bits");
return uint24(value);
}
/**
* @dev Returns the downcasted uint16 from uint256, reverting on
* overflow (when the input is greater than largest uint16).
*
* Counterpart to Solidity's `uint16` operator.
*
* Requirements:
*
* - input must fit into 16 bits
*
* _Available since v2.5._
*/
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
*
* _Available since v2.5._
*/
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.
*
* _Available since v3.0._
*/
function toUint256(int256 value) internal pure returns (uint256) {
require(value >= 0, "SafeCast: value must be positive");
return uint256(value);
}
/**
* @dev Returns the downcasted int248 from int256, reverting on
* overflow (when the input is less than smallest int248 or
* greater than largest int248).
*
* Counterpart to Solidity's `int248` operator.
*
* Requirements:
*
* - input must fit into 248 bits
*
* _Available since v4.7._
*/
function toInt248(int256 value) internal pure returns (int248 downcasted) {
downcasted = int248(value);
require(downcasted == value, "SafeCast: value doesn't fit in 248 bits");
}
/**
* @dev Returns the downcasted int240 from int256, reverting on
* overflow (when the input is less than smallest int240 or
* greater than largest int240).
*
* Counterpart to Solidity's `int240` operator.
*
* Requirements:
*
* - input must fit into 240 bits
*
* _Available since v4.7._
*/
function toInt240(int256 value) internal pure returns (int240 downcasted) {
downcasted = int240(value);
require(downcasted == value, "SafeCast: value doesn't fit in 240 bits");
}
/**
* @dev Returns the downcasted int232 from int256, reverting on
* overflow (when the input is less than smallest int232 or
* greater than largest int232).
*
* Counterpart to Solidity's `int232` operator.
*
* Requirements:
*
* - input must fit into 232 bits
*
* _Available since v4.7._
*/
function toInt232(int256 value) internal pure returns (int232 downcasted) {
downcasted = int232(value);
require(downcasted == value, "SafeCast: value doesn't fit in 232 bits");
}
/**
* @dev Returns the downcasted int224 from int256, reverting on
* overflow (when the input is less than smallest int224 or
* greater than largest int224).
*
* Counterpart to Solidity's `int224` operator.
*
* Requirements:
*
* - input must fit into 224 bits
*
* _Available since v4.7._
*/
function toInt224(int256 value) internal pure returns (int224 downcasted) {
downcasted = int224(value);
require(downcasted == value, "SafeCast: value doesn't fit in 224 bits");
}
/**
* @dev Returns the downcasted int216 from int256, reverting on
* overflow (when the input is less than smallest int216 or
* greater than largest int216).
*
* Counterpart to Solidity's `int216` operator.
*
* Requirements:
*
* - input must fit into 216 bits
*
* _Available since v4.7._
*/
function toInt216(int256 value) internal pure returns (int216 downcasted) {
downcasted = int216(value);
require(downcasted == value, "SafeCast: value doesn't fit in 216 bits");
}
/**
* @dev Returns the downcasted int208 from int256, reverting on
* overflow (when the input is less than smallest int208 or
* greater than largest int208).
*
* Counterpart to Solidity's `int208` operator.
*
* Requirements:
*
* - input must fit into 208 bits
*
* _Available since v4.7._
*/
function toInt208(int256 value) internal pure returns (int208 downcasted) {
downcasted = int208(value);
require(downcasted == value, "SafeCast: value doesn't fit in 208 bits");
}
/**
* @dev Returns the downcasted int200 from int256, reverting on
* overflow (when the input is less than smallest int200 or
* greater than largest int200).
*
* Counterpart to Solidity's `int200` operator.
*
* Requirements:
*
* - input must fit into 200 bits
*
* _Available since v4.7._
*/
function toInt200(int256 value) internal pure returns (int200 downcasted) {
downcasted = int200(value);
require(downcasted == value, "SafeCast: value doesn't fit in 200 bits");
}
/**
* @dev Returns the downcasted int192 from int256, reverting on
* overflow (when the input is less than smallest int192 or
* greater than largest int192).
*
* Counterpart to Solidity's `int192` operator.
*
* Requirements:
*
* - input must fit into 192 bits
*
* _Available since v4.7._
*/
function toInt192(int256 value) internal pure returns (int192 downcasted) {
downcasted = int192(value);
require(downcasted == value, "SafeCast: value doesn't fit in 192 bits");
}
/**
* @dev Returns the downcasted int184 from int256, reverting on
* overflow (when the input is less than smallest int184 or
* greater than largest int184).
*
* Counterpart to Solidity's `int184` operator.
*
* Requirements:
*
* - input must fit into 184 bits
*
* _Available since v4.7._
*/
function toInt184(int256 value) internal pure returns (int184 downcasted) {
downcasted = int184(value);
require(downcasted == value, "SafeCast: value doesn't fit in 184 bits");
}
/**
* @dev Returns the downcasted int176 from int256, reverting on
* overflow (when the input is less than smallest int176 or
* greater than largest int176).
*
* Counterpart to Solidity's `int176` operator.
*
* Requirements:
*
* - input must fit into 176 bits
*
* _Available since v4.7._
*/
function toInt176(int256 value) internal pure returns (int176 downcasted) {
downcasted = int176(value);
require(downcasted == value, "SafeCast: value doesn't fit in 176 bits");
}
/**
* @dev Returns the downcasted int168 from int256, reverting on
* overflow (when the input is less than smallest int168 or
* greater than largest int168).
*
* Counterpart to Solidity's `int168` operator.
*
* Requirements:
*
* - input must fit into 168 bits
*
* _Available since v4.7._
*/
function toInt168(int256 value) internal pure returns (int168 downcasted) {
downcasted = int168(value);
require(downcasted == value, "SafeCast: value doesn't fit in 168 bits");
}
/**
* @dev Returns the downcasted int160 from int256, reverting on
* overflow (when the input is less than smallest int160 or
* greater than largest int160).
*
* Counterpart to Solidity's `int160` operator.
*
* Requirements:
*
* - input must fit into 160 bits
*
* _Available since v4.7._
*/
function toInt160(int256 value) internal pure returns (int160 downcasted) {
downcasted = int160(value);
require(downcasted == value, "SafeCast: value doesn't fit in 160 bits");
}
/**
* @dev Returns the downcasted int152 from int256, reverting on
* overflow (when the input is less than smallest int152 or
* greater than largest int152).
*
* Counterpart to Solidity's `int152` operator.
*
* Requirements:
*
* - input must fit into 152 bits
*
* _Available since v4.7._
*/
function toInt152(int256 value) internal pure returns (int152 downcasted) {
downcasted = int152(value);
require(downcasted == value, "SafeCast: value doesn't fit in 152 bits");
}
/**
* @dev Returns the downcasted int144 from int256, reverting on
* overflow (when the input is less than smallest int144 or
* greater than largest int144).
*
* Counterpart to Solidity's `int144` operator.
*
* Requirements:
*
* - input must fit into 144 bits
*
* _Available since v4.7._
*/
function toInt144(int256 value) internal pure returns (int144 downcasted) {
downcasted = int144(value);
require(downcasted == value, "SafeCast: value doesn't fit in 144 bits");
}
/**
* @dev Returns the downcasted int136 from int256, reverting on
* overflow (when the input is less than smallest int136 or
* greater than largest int136).
*
* Counterpart to Solidity's `int136` operator.
*
* Requirements:
*
* - input must fit into 136 bits
*
* _Available since v4.7._
*/
function toInt136(int256 value) internal pure returns (int136 downcasted) {
downcasted = int136(value);
require(downcasted == value, "SafeCast: value doesn't fit in 136 bits");
}
/**
* @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 downcasted) {
downcasted = int128(value);
require(downcasted == value, "SafeCast: value doesn't fit in 128 bits");
}
/**
* @dev Returns the downcasted int120 from int256, reverting on
* overflow (when the input is less than smallest int120 or
* greater than largest int120).
*
* Counterpart to Solidity's `int120` operator.
*
* Requirements:
*
* - input must fit into 120 bits
*
* _Available since v4.7._
*/
function toInt120(int256 value) internal pure returns (int120 downcasted) {
downcasted = int120(value);
require(downcasted == value, "SafeCast: value doesn't fit in 120 bits");
}
/**
* @dev Returns the downcasted int112 from int256, reverting on
* overflow (when the input is less than smallest int112 or
* greater than largest int112).
*
* Counterpart to Solidity's `int112` operator.
*
* Requirements:
*
* - input must fit into 112 bits
*
* _Available since v4.7._
*/
function toInt112(int256 value) internal pure returns (int112 downcasted) {
downcasted = int112(value);
require(downcasted == value, "SafeCast: value doesn't fit in 112 bits");
}
/**
* @dev Returns the downcasted int104 from int256, reverting on
* overflow (when the input is less than smallest int104 or
* greater than largest int104).
*
* Counterpart to Solidity's `int104` operator.
*
* Requirements:
*
* - input must fit into 104 bits
*
* _Available since v4.7._
*/
function toInt104(int256 value) internal pure returns (int104 downcasted) {
downcasted = int104(value);
require(downcasted == value, "SafeCast: value doesn't fit in 104 bits");
}
/**
* @dev Returns the downcasted int96 from int256, reverting on
* overflow (when the input is less than smallest int96 or
* greater than largest int96).
*
* Counterpart to Solidity's `int96` operator.
*
* Requirements:
*
* - input must fit into 96 bits
*
* _Available since v4.7._
*/
function toInt96(int256 value) internal pure returns (int96 downcasted) {
downcasted = int96(value);
require(downcasted == value, "SafeCast: value doesn't fit in 96 bits");
}
/**
* @dev Returns the downcasted int88 from int256, reverting on
* overflow (when the input is less than smallest int88 or
* greater than largest int88).
*
* Counterpart to Solidity's `int88` operator.
*
* Requirements:
*
* - input must fit into 88 bits
*
* _Available since v4.7._
*/
function toInt88(int256 value) internal pure returns (int88 downcasted) {
downcasted = int88(value);
require(downcasted == value, "SafeCast: value doesn't fit in 88 bits");
}
/**
* @dev Returns the downcasted int80 from int256, reverting on
* overflow (when the input is less than smallest int80 or
* greater than largest int80).
*
* Counterpart to Solidity's `int80` operator.
*
* Requirements:
*
* - input must fit into 80 bits
*
* _Available since v4.7._
*/
function toInt80(int256 value) internal pure returns (int80 downcasted) {
downcasted = int80(value);
require(downcasted == value, "SafeCast: value doesn't fit in 80 bits");
}
/**
* @dev Returns the downcasted int72 from int256, reverting on
* overflow (when the input is less than smallest int72 or
* greater than largest int72).
*
* Counterpart to Solidity's `int72` operator.
*
* Requirements:
*
* - input must fit into 72 bits
*
* _Available since v4.7._
*/
function toInt72(int256 value) internal pure returns (int72 downcasted) {
downcasted = int72(value);
require(downcasted == value, "SafeCast: value doesn't fit in 72 bits");
}
/**
* @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 downcasted) {
downcasted = int64(value);
require(downcasted == value, "SafeCast: value doesn't fit in 64 bits");
}
/**
* @dev Returns the downcasted int56 from int256, reverting on
* overflow (when the input is less than smallest int56 or
* greater than largest int56).
*
* Counterpart to Solidity's `int56` operator.
*
* Requirements:
*
* - input must fit into 56 bits
*
* _Available since v4.7._
*/
function toInt56(int256 value) internal pure returns (int56 downcasted) {
downcasted = int56(value);
require(downcasted == value, "SafeCast: value doesn't fit in 56 bits");
}
/**
* @dev Returns the downcasted int48 from int256, reverting on
* overflow (when the input is less than smallest int48 or
* greater than largest int48).
*
* Counterpart to Solidity's `int48` operator.
*
* Requirements:
*
* - input must fit into 48 bits
*
* _Available since v4.7._
*/
function toInt48(int256 value) internal pure returns (int48 downcasted) {
downcasted = int48(value);
require(downcasted == value, "SafeCast: value doesn't fit in 48 bits");
}
/**
* @dev Returns the downcasted int40 from int256, reverting on
* overflow (when the input is less than smallest int40 or
* greater than largest int40).
*
* Counterpart to Solidity's `int40` operator.
*
* Requirements:
*
* - input must fit into 40 bits
*
* _Available since v4.7._
*/
function toInt40(int256 value) internal pure returns (int40 downcasted) {
downcasted = int40(value);
require(downcasted == value, "SafeCast: value doesn't fit in 40 bits");
}
/**
* @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 downcasted) {
downcasted = int32(value);
require(downcasted == value, "SafeCast: value doesn't fit in 32 bits");
}
/**
* @dev Returns the downcasted int24 from int256, reverting on
* overflow (when the input is less than smallest int24 or
* greater than largest int24).
*
* Counterpart to Solidity's `int24` operator.
*
* Requirements:
*
* - input must fit into 24 bits
*
* _Available since v4.7._
*/
function toInt24(int256 value) internal pure returns (int24 downcasted) {
downcasted = int24(value);
require(downcasted == value, "SafeCast: value doesn't fit in 24 bits");
}
/**
* @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 downcasted) {
downcasted = int16(value);
require(downcasted == value, "SafeCast: value doesn't fit in 16 bits");
}
/**
* @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 downcasted) {
downcasted = int8(value);
require(downcasted == value, "SafeCast: value doesn't fit in 8 bits");
}
/**
* @dev Converts an unsigned uint256 into a signed int256.
*
* Requirements:
*
* - input must be less than or equal to maxInt256.
*
* _Available since v3.0._
*/
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: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @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] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/structs/EnumerableSet.sol)
// This file was procedurally generated from scripts/generate/templates/EnumerableSet.js.
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```solidity
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure
* unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an
* array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
bytes32[] memory store = _values(set._inner);
bytes32[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface ILayerZeroPriceFeed {
/**
* @dev
* priceRatio: (USD price of 1 unit of remote native token in unit of local native token) * PRICE_RATIO_DENOMINATOR
*/
struct Price {
uint128 priceRatio; // float value * 10 ^ 20, decimal awared. for aptos to evm, the basis would be (10^18 / 10^8) * 10 ^20 = 10 ^ 30.
uint64 gasPriceInUnit; // for evm, it is in wei, for aptos, it is in octas.
uint32 gasPerByte;
}
struct UpdatePrice {
uint32 eid;
Price price;
}
/**
* @dev
* ArbGasInfo.go:GetPricesInArbGas
*
*/
struct ArbitrumPriceExt {
uint64 gasPerL2Tx; // L2 overhead
uint32 gasPerL1CallDataByte;
}
struct UpdatePriceExt {
uint32 eid;
Price price;
ArbitrumPriceExt extend;
}
error LZ_PriceFeed_OnlyPriceUpdater();
error LZ_PriceFeed_InsufficientFee(uint256 provided, uint256 required);
error LZ_PriceFeed_NotAnOPStack(uint32 l2Eid);
function nativeTokenPriceUSD() external view returns (uint128);
function getFee(uint32 _dstEid, uint256 _callDataSize, uint256 _gas) external view returns (uint256);
function getPrice(uint32 _dstEid) external view returns (Price memory);
function getPriceRatioDenominator() external view returns (uint128);
function estimateFeeByEid(
uint32 _dstEid,
uint256 _callDataSize,
uint256 _gas
) external view returns (uint256 fee, uint128 priceRatio, uint128 priceRatioDenominator, uint128 nativePriceUSD);
function estimateFeeOnSend(
uint32 _dstEid,
uint256 _callDataSize,
uint256 _gas
) external payable returns (uint256 fee, uint128 priceRatio, uint128 priceRatioDenominator, uint128 nativePriceUSD);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface ILayerZeroReadExecutor {
// @notice query price and assign jobs at the same time
// @param _sender - the source sending contract address. executors may apply price discrimination to senders
// @param _options - optional parameters for extra service plugins, e.g. sending dust tokens at the destination chain
function assignJob(address _sender, bytes calldata _options) external returns (uint256 fee);
// @notice query the executor price for executing the payload on this chain
// @param _sender - the source sending contract address. executors may apply price discrimination to senders
// @param _options - optional parameters for extra service plugins, e.g. sending dust tokens
function getFee(address _sender, bytes calldata _options) external view returns (uint256 fee);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface ILayerZeroTreasury {
function getFee(
address _sender,
uint32 _dstEid,
uint256 _totalNativeFee,
bool _payInLzToken
) external view returns (uint256 fee);
function payFee(
address _sender,
uint32 _dstEid,
uint256 _totalNativeFee,
bool _payInLzToken
) external payable returns (uint256 fee);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IWorker {
event SetWorkerLib(address workerLib);
event SetPriceFeed(address priceFeed);
event SetDefaultMultiplierBps(uint16 multiplierBps);
event SetSupportedOptionTypes(uint32 dstEid, uint8[] optionTypes);
event Withdraw(address lib, address to, uint256 amount);
error Worker_NotAllowed();
error Worker_OnlyMessageLib();
error Worker_RoleRenouncingDisabled();
function setPriceFeed(address _priceFeed) external;
function priceFeed() external view returns (address);
function setDefaultMultiplierBps(uint16 _multiplierBps) external;
function defaultMultiplierBps() external view returns (uint16);
function withdrawFee(address _lib, address _to, uint256 _amount) external;
function setSupportedOptionTypes(uint32 _eid, uint8[] calldata _optionTypes) external;
function getSupportedOptionTypes(uint32 _eid) external view returns (uint8[] memory);
}// SPDX-License-Identifier: MIT OR Apache-2.0
pragma solidity ^0.8.20;
/// @dev copied from https://github.com/nomad-xyz/ExcessivelySafeCall/blob/main/src/ExcessivelySafeCall.sol.
library SafeCall {
/// @notice calls a contract with a specified gas limit and value and captures the return data
/// @param _target The address to call
/// @param _gas The amount of gas to forward to the remote contract
/// @param _value The value in wei to send to the remote contract
/// to memory.
/// @param _maxCopy The maximum number of bytes of returndata to copy
/// to memory.
/// @param _calldata The data to send to the remote contract
/// @return success and returndata, as `.call()`. Returndata is capped to
/// `_maxCopy` bytes.
function safeCall(
address _target,
uint256 _gas,
uint256 _value,
uint16 _maxCopy,
bytes memory _calldata
) internal returns (bool, bytes memory) {
// check that target has code
uint size;
assembly {
size := extcodesize(_target)
}
if (size == 0) {
return (false, new bytes(0));
}
// set up for assembly call
uint256 _toCopy;
bool _success;
bytes memory _returnData = new bytes(_maxCopy);
// dispatch message to recipient
// by assembly calling "handle" function
// we call via assembly to avoid memcopying a very large returndata
// returned by a malicious contract
assembly {
_success := call(
_gas, // gas
_target, // recipient
_value, // ether value
add(_calldata, 0x20), // inloc
mload(_calldata), // inlen
0, // outloc
0 // outlen
)
// limit our copy to 100 bytes
_toCopy := returndatasize()
if gt(_toCopy, _maxCopy) {
_toCopy := _maxCopy
}
// Store the length of the copied bytes
mstore(_returnData, _toCopy)
// copy the bytes from returndata[0:_toCopy]
returndatacopy(add(_returnData, 0x20), 0, _toCopy)
}
return (_success, _returnData);
}
/// @notice Use when you _really_ really _really_ don't trust the called
/// contract. This prevents the called contract from causing reversion of
/// the caller in as many ways as we can.
/// @dev The main difference between this and a solidity low-level call is
/// that we limit the number of bytes that the callee can cause to be
/// copied to caller memory. This prevents stupid things like malicious
/// contracts returning 10,000,000 bytes causing a local OOG when copying
/// to memory.
/// @param _target The address to call
/// @param _gas The amount of gas to forward to the remote contract
/// @param _maxCopy The maximum number of bytes of returndata to copy
/// to memory.
/// @param _calldata The data to send to the remote contract
/// @return success and returndata, as `.call()`. Returndata is capped to
/// `_maxCopy` bytes.
function safeStaticCall(
address _target,
uint256 _gas,
uint16 _maxCopy,
bytes memory _calldata
) internal view returns (bool, bytes memory) {
// check that target has code
uint size;
assembly {
size := extcodesize(_target)
}
if (size == 0) {
return (false, new bytes(0));
}
// set up for assembly call
uint256 _toCopy;
bool _success;
bytes memory _returnData = new bytes(_maxCopy);
// dispatch message to recipient
// by assembly calling "handle" function
// we call via assembly to avoid memcopying a very large returndata
// returned by a malicious contract
assembly {
_success := staticcall(
_gas, // gas
_target, // recipient
add(_calldata, 0x20), // inloc
mload(_calldata), // inlen
0, // outloc
0 // outlen
)
// limit our copy to 256 bytes
_toCopy := returndatasize()
if gt(_toCopy, _maxCopy) {
_toCopy := _maxCopy
}
// Store the length of the copied bytes
mstore(_returnData, _toCopy)
// copy the bytes from returndata[0:_toCopy]
returndatacopy(add(_returnData, 0x20), 0, _toCopy)
}
return (_success, _returnData);
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
/// @dev simply a container of endpoint address and local eid
abstract contract MessageLibBase {
address internal immutable endpoint;
uint32 internal immutable localEid;
error LZ_MessageLib_OnlyEndpoint();
modifier onlyEndpoint() {
if (endpoint != msg.sender) revert LZ_MessageLib_OnlyEndpoint();
_;
}
constructor(address _endpoint, uint32 _localEid) {
endpoint = _endpoint;
localEid = _localEid;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;
import { IInbox } from "@arbitrum/nitro-contracts/src/bridge/IInbox.sol";
import { ArbitrumDVNAdapterL2 } from "./ArbitrumDVNAdapterL2.sol";
import { DVNAdapterBase } from "../DVNAdapterBase.sol";
import { DVNAdapterMessageCodec } from "../libs/DVNAdapterMessageCodec.sol";
contract ArbitrumDVNAdapterL1 is DVNAdapterBase {
// --- Config Struct ---
struct DstConfig {
uint16 multiplierBps;
uint256 maxSubmissionCost;
uint256 gasLimit;
uint256 maxFeePerGas;
}
// --- Events ---
event RetryableTicketCreated(uint256 indexed ticketId);
error OnlyArbitrum();
uint32 public immutable arbitrumEid; // eid % 30000 (v1 eid)
IInbox public immutable inbox;
address public peer; // L2 adapter
DstConfig public dstConfig;
constructor(
address[] memory _admins,
uint32 _arbitrumEid,
address _inbox
) DVNAdapterBase(msg.sender, _admins, 12000) {
arbitrumEid = _arbitrumEid; // eid % 30000 (v1 eid)
inbox = IInbox(_inbox);
}
// --- Admin ---
function setPeer(address _peer) external onlyRole(ADMIN_ROLE) {
peer = _peer;
}
function setDstConfig(
uint16 _multiplierBps,
uint256 _maxSubmissionCost,
uint256 _gasLimit,
uint256 _maxFeePerGas
) external onlyRole(ADMIN_ROLE) {
dstConfig = DstConfig({
multiplierBps: _multiplierBps,
maxSubmissionCost: _maxSubmissionCost,
gasLimit: _gasLimit,
maxFeePerGas: _maxFeePerGas
});
}
// --- Send ---
function assignJob(
AssignJobParam calldata _param,
bytes calldata /*_options*/
) external payable override onlyRole(MESSAGE_LIB_ROLE) onlyAcl(_param.sender) returns (uint256 fee) {
DstConfig storage config = dstConfig;
fee = _getArbitrumFee(_param.dstEid, config);
bytes memory payload = abi.encodeWithSelector(
ArbitrumDVNAdapterL2.verify.selector,
DVNAdapterMessageCodec.encode(
receiveLibs[msg.sender][_param.dstEid],
_param.packetHeader,
_param.payloadHash
)
);
// fee estimation: https://github.com/OffchainLabs/arbitrum-sdk/blob/main/src/lib/message/L1ToL2MessageCreator.ts#L52
uint256 ticketID = inbox.createRetryableTicket{ value: fee }(
peer,
0,
config.maxSubmissionCost,
peer,
peer,
config.gasLimit,
config.maxFeePerGas,
payload
);
emit RetryableTicketCreated(ticketID);
// adjust fee based on multiplier
// if (workerFeeLib != address(0)) {
// fee = IDVNAdapterFeeLib(workerFeeLib).getFee(
// _param.dstEid,
// _param.sender,
// defaultMultiplierBps,
// config.multiplierBps,
// fee
// );
// }
}
// --- View ---
function getFee(
uint32 _dstEid,
uint64 /*_confirmations*/,
address _sender,
bytes calldata /*_options*/
) public view override onlyAcl(_sender) returns (uint256 fee) {
DstConfig storage config = dstConfig;
fee = _getArbitrumFee(_dstEid, config);
// adjust fee based on multiplier
// if (workerFeeLib != address(0)) {
// fee = IDVNAdapterFeeLib(workerFeeLib).getFee(
// _dstEid,
// _sender,
// defaultMultiplierBps,
// config.multiplierBps,
// fee
// );
// }
}
function _getArbitrumFee(uint32 _dstEid, DstConfig storage _dstConfig) internal view returns (uint256 fee) {
if (_dstEid % 30000 != arbitrumEid) revert OnlyArbitrum();
fee = _dstConfig.maxSubmissionCost + _dstConfig.gasLimit * _dstConfig.maxFeePerGas;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;
import { AddressAliasHelper } from "@arbitrum/nitro-contracts/src/libraries/AddressAliasHelper.sol";
import { DVNAdapterBase } from "../DVNAdapterBase.sol";
contract ArbitrumDVNAdapterL2 is DVNAdapterBase {
// --- Errors ---
error UntrustedPeer(address peer);
// --- Events ---
event PeerSet(address peer);
// --- Variables ---
address public peer; // L1 adapter
constructor(address[] memory _admins) DVNAdapterBase(msg.sender, _admins, 12000) {}
// --- Admin ---
function setPeer(address _peer) external onlyRole(ADMIN_ROLE) {
peer = _peer;
emit PeerSet(_peer);
}
// --- Send ---
function assignJob(
AssignJobParam calldata /*_param*/,
bytes calldata /*_options*/
) external payable override returns (uint256) {
revert DVNAdapter_NotImplemented();
}
function getFee(
uint32 /*_dstEid*/,
uint64 /*_confirmations*/,
address /*_sender*/,
bytes calldata /*_options*/
) external pure override returns (uint256) {
revert DVNAdapter_NotImplemented();
}
// --- Receive ---
function verify(bytes calldata _payload) external {
// To check that message came from L1, we check that the sender is the L1 contract's L2 alias.
if (msg.sender != AddressAliasHelper.applyL1ToL2Alias(peer)) revert UntrustedPeer(msg.sender);
_decodeAndVerify(0, _payload); //todo: fix
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { AxelarExecutable } from "@axelar-network/axelar-gmp-sdk-solidity/contracts/executable/AxelarExecutable.sol";
import { ISendLib } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ISendLib.sol";
import { DVNAdapterBase } from "../DVNAdapterBase.sol";
import { IAxelarDVNAdapter } from "../../../interfaces/adapters/IAxelarDVNAdapter.sol";
import { IAxelarDVNAdapterFeeLib } from "../../../interfaces/adapters/IAxelarDVNAdapterFeeLib.sol";
interface ISendLibBase {
function fees(address _worker) external view returns (uint256);
}
/// @title AxelarDVNAdapter
/// @dev How Axelar DVN Adapter works:
/// 1. Estimate gas fee off-chain using the Axelar SDK.
/// refer to https://docs.axelar.dev/dev/axelarjs-sdk/axelar-query-api#estimategasfee
/// 2. Pay gas fee by calling `payNativeGasForContractCall` on the AxelarGasService contract.
/// refer to https://docs.axelar.dev/dev/general-message-passing/gas-services/pay-gas#paynativegasforcontractcall
/// 3. Send message by calling `callContract` on the AxelarGateway contract.
/// refer to https://docs.axelar.dev/dev/general-message-passing/gmp-messages#call-a-contract-on-chain-b-from-chain-a
/// 4. Refund surplus gas fee asynchronously.
/// refer to https://docs.axelar.dev/dev/general-message-passing/gas-services/refund
/// @dev Recovery:
/// 1. If not enough gas fee is paid, the message will be hangup on source chain and can `add gas` to retry.
/// refer to https://docs.axelar.dev/dev/general-message-passing/recovery#increase-gas-payment-to-the-gas-receiver-on-the-source-chain
/// 2. If the message is not executed on the destination chain, you can manually retry by calling `execute` on the `ReceiveAxelarDVNAdapter` contract.
/// refer to https://docs.axelar.dev/dev/general-message-passing/recovery#manually-execute-a-transfer
/// @dev As the Gas is estimated off-chain, we need to update the gas fee periodically on-chain by calling `setNativeGasFee` with the new fee.
contract AxelarDVNAdapter is DVNAdapterBase, AxelarExecutable, IAxelarDVNAdapter {
mapping(string srcChainName => SrcConfig) public srcConfig; // by chain name
mapping(uint32 dstEid => DstConfig) public dstConfig; // by dstEid
// set default multiplier to 2.5x
constructor(
address[] memory _admins,
address _gateway
) AxelarExecutable(_gateway) DVNAdapterBase(msg.sender, _admins, 10000) {}
// ========================= OnlyAdmin =========================
function setDstConfig(DstConfigParam[] calldata _params) external onlyRole(ADMIN_ROLE) {
for (uint256 i = 0; i < _params.length; i++) {
DstConfigParam calldata param = _params[i];
uint32 eid = param.eid % 30000;
// set once per chainName
// only one adapter per dvn that services both endpoint v1 and v2
// we standardize the eid stored here with mod 30000
if (bytes(dstConfig[eid].chainName).length == 0) {
dstConfig[eid].chainName = param.chainName;
dstConfig[eid].peer = param.peer;
srcConfig[param.chainName].eid = eid;
srcConfig[param.chainName].peer = param.peer;
}
dstConfig[eid].multiplierBps = param.multiplierBps;
dstConfig[eid].nativeGasFee = param.nativeGasFee;
}
emit DstConfigSet(_params);
}
/// @notice sets message fee in native gas for destination chains.
/// @dev Axelar does not support quoting fee on-chain. Instead, the fee needs to be obtained off-chain by querying through the Axelar SDK.
/// @dev The fee may change over time when token prices change, requiring admins to monitor and make necessary updates to reflect the actual fee.
/// @dev Adding a buffer to the required fee is advisable. Any surplus fee will be refunded asynchronously if it exceeds the necessary amount.
/// https://docs.axelar.dev/dev/general-message-passing/gas-services/pay-gas
/// https://github.com/axelarnetwork/axelarjs/blob/070c8fe061f1082e79772fdc5c4675c0237bbba2/packages/api/src/axelar-query/isomorphic.ts#L54
/// https://github.com/axelarnetwork/axelar-cgp-solidity/blob/d4536599321774927bf9716178a9e360f8e0efac/contracts/gas-service/AxelarGasService.sol#L403
function setNativeGasFee(NativeGasFeeParam[] calldata _params) external onlyRole(ADMIN_ROLE) {
for (uint256 i = 0; i < _params.length; i++) {
NativeGasFeeParam calldata param = _params[i];
dstConfig[param.dstEid % 30000].nativeGasFee = param.nativeGasFee;
}
emit NativeGasFeeSet(_params);
}
// ========================= OnlyWorkerFeeLib =========================
function withdrawToFeeLib(address _sendLib) external {
if (msg.sender != workerFeeLib) revert AxelarDVNAdapter_OnlyWorkerFeeLib();
_withdrawFeeFromSendLib(_sendLib, workerFeeLib);
}
// ========================= OnlyMessageLib =========================
function assignJob(
AssignJobParam calldata _param,
bytes calldata _options
) external payable override onlyAcl(_param.sender) returns (uint totalFee) {
bytes32 receiveLib = _getAndAssertReceiveLib(msg.sender, _param.dstEid);
IAxelarDVNAdapterFeeLib.Param memory feeLibParam = IAxelarDVNAdapterFeeLib.Param({
dstEid: _param.dstEid,
confirmations: _param.confirmations,
sender: _param.sender,
defaultMultiplierBps: defaultMultiplierBps
});
DstConfig memory config = dstConfig[_param.dstEid % 30000];
bytes memory payload = _encode(receiveLib, _param.packetHeader, _param.payloadHash);
totalFee = IAxelarDVNAdapterFeeLib(workerFeeLib).getFeeOnSend(
feeLibParam,
config,
payload,
_options,
msg.sender
);
gateway.callContract(config.chainName, config.peer, payload);
}
// ========================= View =========================
function getFee(
uint32 _dstEid,
uint64 _confirmations,
address _sender,
bytes calldata _options
) external view override returns (uint256 totalFee) {
IAxelarDVNAdapterFeeLib.Param memory feeLibParam = IAxelarDVNAdapterFeeLib.Param(
_dstEid,
_confirmations,
_sender,
defaultMultiplierBps
);
totalFee = IAxelarDVNAdapterFeeLib(workerFeeLib).getFee(feeLibParam, dstConfig[_dstEid % 30000], _options);
}
// ========================= Internal =========================
function _execute(
string calldata _sourceChain,
string calldata _sourceAddress,
bytes calldata _payload
) internal override {
SrcConfig memory config = srcConfig[_sourceChain];
// assert peer is the same as the source chain
_assertPeer(_sourceChain, _sourceAddress, config.peer);
_decodeAndVerify(config.eid, _payload);
}
function _assertPeer(string memory _sourceChain, string memory _sourceAddress, string memory peer) private pure {
if (keccak256(bytes(_sourceAddress)) != keccak256(bytes(peer))) {
revert AxelarDVNAdapter_UntrustedPeer(_sourceChain, _sourceAddress);
}
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { Proxied } from "hardhat-deploy/solc_0.8/proxy/Proxied.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { IAxelarGasService } from "@axelar-network/axelar-gmp-sdk-solidity/contracts/interfaces/IAxelarGasService.sol";
import { Transfer } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/Transfer.sol";
import { IAxelarDVNAdapter } from "../../../interfaces/adapters/IAxelarDVNAdapter.sol";
import { IAxelarDVNAdapterFeeLib } from "../../../interfaces/adapters/IAxelarDVNAdapterFeeLib.sol";
import { ILayerZeroPriceFeed } from "../../../../interfaces/ILayerZeroPriceFeed.sol";
contract AxelarDVNAdapterFeeLib is OwnableUpgradeable, Proxied, IAxelarDVNAdapterFeeLib {
uint16 internal constant BPS_DENOMINATOR = 10000;
/// @dev to be applied to native gas fee before sending to Axelar Gas Service
uint16 public nativeGasFeeMultiplierBps;
IAxelarDVNAdapter public dvn;
IAxelarGasService public gasService;
ILayerZeroPriceFeed public priceFeed;
mapping(uint32 dstEid => DstConfig) public dstConfig;
function initialize(
address _gasService,
address _dvn,
uint16 _nativeGasFeeMultiplierBps
) external proxied initializer {
__Ownable_init();
gasService = IAxelarGasService(_gasService);
dvn = IAxelarDVNAdapter(_dvn);
nativeGasFeeMultiplierBps = _nativeGasFeeMultiplierBps;
}
// ================================ OnlyOwner ================================
function withdrawToken(address _token, address _to, uint256 _amount) external onlyOwner {
// transfers native if _token is address(0x0)
Transfer.nativeOrToken(_token, _to, _amount);
emit TokenWithdrawn(_token, _to, _amount);
}
function setGasService(address _gasService) external onlyOwner {
gasService = IAxelarGasService(_gasService);
emit GasServiceSet(_gasService);
}
function setPriceFeed(address _priceFeed) external onlyOwner {
priceFeed = ILayerZeroPriceFeed(_priceFeed);
emit PriceFeedSet(_priceFeed);
}
function setDstConfig(DstConfigParam[] calldata _param) external onlyOwner {
for (uint256 i = 0; i < _param.length; i++) {
DstConfigParam calldata param = _param[i];
dstConfig[param.dstEid] = DstConfig({ gas: param.gas, floorMarginUSD: param.floorMarginUSD });
}
emit DstConfigSet(_param);
}
function setNativeGasFeeMultiplierBps(uint16 _multiplierBps) external onlyOwner {
nativeGasFeeMultiplierBps = _multiplierBps;
emit NativeGasFeeMultiplierBpsSet(_multiplierBps);
}
// ================================ External ================================
function getFeeOnSend(
Param calldata _param,
IAxelarDVNAdapter.DstConfig calldata _dstConfig,
bytes memory _payload,
bytes calldata _options,
address _sendLib
) external payable returns (uint256 totalFee) {
if (_dstConfig.nativeGasFee == 0) revert AxelarDVNAdapter_EidNotSupported(_param.dstEid);
if (_options.length > 0) revert AxelarDVNAdapter_OptionsUnsupported();
totalFee = _applyPremium(_dstConfig.multiplierBps, _param.defaultMultiplierBps, _dstConfig.nativeGasFee);
uint256 feeToAxelar = _getAxelarFeeWithBuffer(_dstConfig.nativeGasFee);
// withdraw from uln to fee lib if not enough balance
uint256 balance = address(this).balance;
if (balance < feeToAxelar) {
dvn.withdrawToFeeLib(_sendLib);
// revert if still not enough
balance = address(this).balance;
if (balance < feeToAxelar) revert AxelarDVNAdapter_InsufficientBalance(balance, feeToAxelar);
}
// pay axelar gas service
gasService.payNativeGasForContractCall{ value: feeToAxelar }(
msg.sender, // sender
_dstConfig.chainName, // destinationChain
_dstConfig.peer, // destinationAddress
_payload, // payload
address(this) // refundAddress
);
}
function getFee(
Param calldata _param,
IAxelarDVNAdapter.DstConfig calldata _dstConfig,
bytes calldata _options
) external pure returns (uint256 totalFee) {
if (_dstConfig.nativeGasFee == 0) revert AxelarDVNAdapter_EidNotSupported(_param.dstEid);
if (_options.length > 0) revert AxelarDVNAdapter_OptionsUnsupported();
totalFee = _applyPremium(_dstConfig.multiplierBps, _param.defaultMultiplierBps, _dstConfig.nativeGasFee);
}
// ================================ Internal ================================
function _getAxelarFeeWithBuffer(uint256 _nativeGasFee) internal view returns (uint256) {
return (_nativeGasFee * nativeGasFeeMultiplierBps) / BPS_DENOMINATOR;
}
function _applyPremium(
uint16 multiplierBps,
uint16 defaultMultiplierBps,
uint256 fee
) internal pure returns (uint256) {
uint256 multiplier = multiplierBps == 0 ? defaultMultiplierBps : multiplierBps;
return (fee * multiplier) / BPS_DENOMINATOR;
}
receive() external payable {}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { IRouterClient } from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import { IAny2EVMMessageReceiver } from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IAny2EVMMessageReceiver.sol";
import { Client } from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import { DVNAdapterBase } from "../DVNAdapterBase.sol";
import { ICCIPDVNAdapter } from "../../../interfaces/adapters/ICCIPDVNAdapter.sol";
import { ICCIPDVNAdapterFeeLib } from "../../../interfaces/adapters/ICCIPDVNAdapterFeeLib.sol";
/// @title CCIPDVNAdapter
/// @dev How CCIP DVN Adapter works:
/// 1. Estimate gas cost for the message on-chain by calling `getFee` on the Router contract.
/// refer to https://docs.chain.link/ccip/api-reference/i-router-client#getfee
/// 2. Call `ccipSend` on the Router contract to send the message.
/// refer to https://docs.chain.link/ccip/api-reference/i-router-client#ccipsend
/// @dev Recovery:
/// 1. If not enough gas paid, the message will be failed to execute on the destination chain, you can manually retry by calling `manuallyExecute` on the `OffRamp` contract.
/// refer to https://github.com/smartcontractkit/ccip/blob/ccip-develop/contracts/src/v0.8/ccip/offRamp/EVM2EVMOffRamp.sol#L222
contract CCIPDVNAdapter is DVNAdapterBase, IAny2EVMMessageReceiver, ICCIPDVNAdapter {
address private constant NATIVE_GAS_TOKEN_ADDRESS = address(0);
IRouterClient public immutable router;
mapping(uint32 dstEid => DstConfig) public dstConfig;
mapping(uint64 srcChainSelector => SrcConfig) public srcConfig;
constructor(address[] memory _admins, address _router) DVNAdapterBase(msg.sender, _admins, 12000) {
router = IRouterClient(_router);
}
// ========================= OnlyAdmin =========================
/// @notice sets configuration for destination chains
/// @param _params array of chain configurations
function setDstConfig(DstConfigParam[] calldata _params) external onlyRole(ADMIN_ROLE) {
for (uint256 i = 0; i < _params.length; i++) {
DstConfigParam calldata param = _params[i];
uint32 eid = param.eid % 30000;
// set once per chainSelector
// only one adapter per dvn that services both endpoint v1 and v2
// we standardize the eid stored here with mod 30000
if (dstConfig[eid].chainSelector == 0) {
dstConfig[eid].chainSelector = param.chainSelector;
dstConfig[eid].peer = param.peer;
srcConfig[param.chainSelector].eid = eid;
srcConfig[param.chainSelector].peer = param.peer;
}
dstConfig[eid].multiplierBps = param.multiplierBps;
dstConfig[eid].gas = param.gas;
}
emit DstConfigSet(_params);
}
// ========================= OnlyMessageLib =========================
function assignJob(
AssignJobParam calldata _param,
bytes calldata _options
) external payable override onlyAcl(_param.sender) returns (uint256 totalFee) {
bytes32 receiveLib = _getAndAssertReceiveLib(msg.sender, _param.dstEid);
ICCIPDVNAdapterFeeLib.Param memory feeLibParam = ICCIPDVNAdapterFeeLib.Param(
_param.dstEid,
_param.confirmations,
_param.sender,
defaultMultiplierBps
);
DstConfig memory config = dstConfig[_param.dstEid % 30000];
bytes memory data = _encode(receiveLib, _param.packetHeader, _param.payloadHash);
Client.EVM2AnyMessage memory message = _createCCIPMessage(data, config.peer, config.gas);
IRouterClient ccipRouter = router;
uint256 ccipFee;
(ccipFee, totalFee) = ICCIPDVNAdapterFeeLib(workerFeeLib).getFeeOnSend(
feeLibParam,
config,
message,
_options,
ccipRouter
);
_assertBalanceAndWithdrawFee(msg.sender, ccipFee);
ccipRouter.ccipSend{ value: ccipFee }(config.chainSelector, message);
}
// ========================= OnlyRouter =========================
function ccipReceive(Client.Any2EVMMessage calldata _message) external {
if (msg.sender != address(router)) revert CCIPDVNAdapter_InvalidRouter(msg.sender);
SrcConfig memory config = srcConfig[_message.sourceChainSelector];
_assertPeer(_message.sourceChainSelector, _message.sender, config.peer);
_decodeAndVerify(config.eid, _message.data);
}
// ========================= View =========================
function getFee(
uint32 _dstEid,
uint64 _confirmations,
address _sender,
bytes calldata _options
) external view override onlyAcl(_sender) returns (uint256 totalFee) {
ICCIPDVNAdapterFeeLib.Param memory feeLibParam = ICCIPDVNAdapterFeeLib.Param(
_dstEid,
_confirmations,
_sender,
defaultMultiplierBps
);
DstConfig memory config = dstConfig[_dstEid % 30000];
bytes memory data = _encodeEmpty();
Client.EVM2AnyMessage memory message = _createCCIPMessage(data, config.peer, config.gas);
totalFee = ICCIPDVNAdapterFeeLib(workerFeeLib).getFee(feeLibParam, config, message, _options, router);
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAny2EVMMessageReceiver).interfaceId || super.supportsInterface(interfaceId);
}
// ========================= Internal =========================
function _createCCIPMessage(
bytes memory _data,
bytes memory _receiver,
uint256 _gas
) private pure returns (Client.EVM2AnyMessage memory message) {
message = Client.EVM2AnyMessage({
receiver: _receiver,
data: _data,
tokenAmounts: new Client.EVMTokenAmount[](0), // Empty array indicating no tokens are being sent
extraArgs: Client._argsToBytes(Client.EVMExtraArgsV1({ gasLimit: _gas, strict: false })),
feeToken: NATIVE_GAS_TOKEN_ADDRESS
});
}
function _assertPeer(uint64 _sourceChainSelector, bytes memory _sourceAddress, bytes memory peer) private pure {
if (keccak256(_sourceAddress) != keccak256(peer)) {
revert CCIPDVNAdapter_UntrustedPeer(_sourceChainSelector, _sourceAddress);
}
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { Proxied } from "hardhat-deploy/solc_0.8/proxy/Proxied.sol";
import { OwnableUpgradeable } from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import { Client } from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import { IRouterClient } from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import { ICCIPDVNAdapter } from "../../../interfaces/adapters/ICCIPDVNAdapter.sol";
import { ICCIPDVNAdapterFeeLib } from "../../../interfaces/adapters/ICCIPDVNAdapterFeeLib.sol";
contract CCIPDVNAdapterFeeLib is OwnableUpgradeable, Proxied, ICCIPDVNAdapterFeeLib {
uint16 internal constant BPS_DENOMINATOR = 10000;
mapping(uint32 dstEid => DstConfig) public dstConfig;
function initialize() external proxied initializer {
__Ownable_init();
}
// ================================ OnlyOwner ===============================
function setDstConfig(DstConfigParam[] calldata _param) external onlyOwner {
for (uint256 i = 0; i < _param.length; i++) {
DstConfigParam calldata param = _param[i];
dstConfig[param.dstEid] = DstConfig({ floorMarginUSD: param.floorMarginUSD });
}
emit DstConfigSet(_param);
}
// ================================ External ================================
function getFeeOnSend(
Param calldata _params,
ICCIPDVNAdapter.DstConfig calldata _dstConfig,
Client.EVM2AnyMessage calldata _message,
bytes calldata _options,
IRouterClient _router
) external payable returns (uint256 ccipFee, uint256 totalFee) {
if (_dstConfig.gas == 0) revert CCIPDVNAdapter_EidNotSupported(_params.dstEid);
if (_options.length > 0) revert CCIPDVNAdapter_OptionsUnsupported();
ccipFee = _router.getFee(_dstConfig.chainSelector, _message);
totalFee = _applyPremium(_dstConfig.multiplierBps, _params.defaultMultiplierBps, ccipFee);
}
function getFee(
Param calldata _params,
ICCIPDVNAdapter.DstConfig calldata _dstConfig,
Client.EVM2AnyMessage calldata _message,
bytes calldata _options,
IRouterClient _router
) external view returns (uint256 totalFee) {
if (_dstConfig.gas == 0) revert CCIPDVNAdapter_EidNotSupported(_params.dstEid);
if (_options.length > 0) revert CCIPDVNAdapter_OptionsUnsupported();
totalFee = _router.getFee(_dstConfig.chainSelector, _message);
totalFee = _applyPremium(_dstConfig.multiplierBps, _params.defaultMultiplierBps, totalFee);
}
// ================================ Internal ================================
function _applyPremium(
uint16 _multiplierBps,
uint16 _defaultMultiplierBps,
uint256 _fee
) internal pure returns (uint256 fee) {
uint256 multiplier = _multiplierBps == 0 ? _defaultMultiplierBps : _multiplierBps;
fee = (_fee * multiplier) / BPS_DENOMINATOR;
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { Transfer } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/Transfer.sol";
import { ISendLib } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ISendLib.sol";
import { ILayerZeroDVN } from "../../interfaces/ILayerZeroDVN.sol";
import { Worker } from "../../../Worker.sol";
import { DVNAdapterMessageCodec } from "./libs/DVNAdapterMessageCodec.sol";
interface ISendLibBase {
function fees(address _worker) external view returns (uint256);
}
interface IReceiveUln {
function verify(bytes calldata _packetHeader, bytes32 _payloadHash, uint64 _confirmations) external;
}
struct ReceiveLibParam {
address sendLib;
uint32 dstEid;
bytes32 receiveLib;
}
/// @title SendDVNAdapterBase
/// @notice base contract for DVN adapters
/// @dev limitations:
/// - doesn't accept alt token
/// - doesn't respect block confirmations
abstract contract DVNAdapterBase is Worker, ILayerZeroDVN {
// --- Errors ---
error DVNAdapter_InsufficientBalance(uint256 actual, uint256 requested);
error DVNAdapter_NotImplemented();
error DVNAdapter_MissingRecieveLib(address sendLib, uint32 dstEid);
event ReceiveLibsSet(ReceiveLibParam[] params);
/// @dev on change of application config, dvn adapters will not perform any additional verification
/// @dev to avoid messages from being stuck, all verifications from adapters will be done with the maximum possible confirmations
uint64 internal constant MAX_CONFIRMATIONS = type(uint64).max;
/// @dev receive lib to call verify() on at destination
mapping(address sendLib => mapping(uint32 dstEid => bytes32 receiveLib)) public receiveLibs;
constructor(
address _roleAdmin,
address[] memory _admins,
uint16 _defaultMultiplierBps
) Worker(new address[](0), address(0x0), _defaultMultiplierBps, _roleAdmin, _admins) {}
// ========================= OnlyAdmin =========================
/// @notice sets receive lib for destination chains
/// @dev DEFAULT_ADMIN_ROLE can set MESSAGE_LIB_ROLE for sendLibs and use below function to set receiveLibs
function setReceiveLibs(ReceiveLibParam[] calldata _params) external onlyRole(DEFAULT_ADMIN_ROLE) {
for (uint256 i = 0; i < _params.length; i++) {
ReceiveLibParam calldata param = _params[i];
receiveLibs[param.sendLib][param.dstEid] = param.receiveLib;
}
emit ReceiveLibsSet(_params);
}
// ========================= Internal =========================
function _getAndAssertReceiveLib(address _sendLib, uint32 _dstEid) internal view returns (bytes32 lib) {
lib = receiveLibs[_sendLib][_dstEid];
if (lib == bytes32(0)) revert DVNAdapter_MissingRecieveLib(_sendLib, _dstEid);
}
function _encode(
bytes32 _receiveLib,
bytes memory _packetHeader,
bytes32 _payloadHash
) internal pure returns (bytes memory) {
return DVNAdapterMessageCodec.encode(_receiveLib, _packetHeader, _payloadHash);
}
function _encodeEmpty() internal pure returns (bytes memory) {
return
DVNAdapterMessageCodec.encode(bytes32(0), new bytes(DVNAdapterMessageCodec.PACKET_HEADER_SIZE), bytes32(0));
}
function _decodeAndVerify(uint32 _srcEid, bytes calldata _payload) internal {
require((DVNAdapterMessageCodec.srcEid(_payload) % 30000) == _srcEid, "DVNAdapterBase: invalid srcEid");
(address receiveLib, bytes memory packetHeader, bytes32 payloadHash) = DVNAdapterMessageCodec.decode(_payload);
IReceiveUln(receiveLib).verify(packetHeader, payloadHash, MAX_CONFIRMATIONS);
}
function _withdrawFeeFromSendLib(address _sendLib, address _to) internal {
uint256 fee = ISendLibBase(_sendLib).fees(address(this));
if (fee > 0) {
ISendLib(_sendLib).withdrawFee(_to, fee);
emit Withdraw(_sendLib, _to, fee);
}
}
function _assertBalanceAndWithdrawFee(address _sendLib, uint256 _messageFee) internal {
uint256 balance = address(this).balance;
if (balance < _messageFee) {
// withdraw all fees from the sendLib if balance is insufficient
_withdrawFeeFromSendLib(_sendLib, address(this));
// check balance again
balance = address(this).balance;
// revert if balance is still insufficient, need to transfer more funds manually to the adapter
if (balance < _messageFee) revert DVNAdapter_InsufficientBalance(balance, _messageFee);
}
}
/// @dev to receive refund
receive() external payable {}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { AddressCast } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol";
library DVNAdapterMessageCodec {
using AddressCast for bytes32;
error DVNAdapter_InvalidMessageSize();
uint256 private constant RECEIVE_LIB_OFFSET = 0;
uint256 private constant PAYLOAD_HASH_OFFSET = 32;
uint256 private constant PACKET_HEADER_OFFSET = 64;
uint256 private constant SRC_EID_OFFSET = 73; // 64 + 1 + 8
uint256 internal constant PACKET_HEADER_SIZE = 81; // version(uint8) + nonce(uint64) + path(uint32,bytes32,uint32,bytes32)
uint256 internal constant MESSAGE_SIZE = 32 + 32 + PACKET_HEADER_SIZE; // receive_lib(bytes32) + payloadHash(bytes32) + packetHeader
function encode(
bytes32 _receiveLib,
bytes memory _packetHeader,
bytes32 _payloadHash
) internal pure returns (bytes memory payload) {
return abi.encodePacked(_receiveLib, _payloadHash, _packetHeader);
}
function decode(
bytes calldata _message
) internal pure returns (address receiveLib, bytes memory packetHeader, bytes32 payloadHash) {
if (_message.length != MESSAGE_SIZE) revert DVNAdapter_InvalidMessageSize();
receiveLib = bytes32(_message[RECEIVE_LIB_OFFSET:PAYLOAD_HASH_OFFSET]).toAddress();
payloadHash = bytes32(_message[PAYLOAD_HASH_OFFSET:PACKET_HEADER_OFFSET]);
packetHeader = _message[PACKET_HEADER_OFFSET:];
}
function srcEid(bytes calldata _message) internal pure returns (uint32) {
return uint32(bytes4(_message[SRC_EID_OFFSET:SRC_EID_OFFSET + 4]));
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;
import { ICrossDomainMessenger } from "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";
import { OptimismDVNAdapterL2 } from "./OptimismDVNAdapterL2.sol";
import { DVNAdapterMessageCodec } from "../libs/DVNAdapterMessageCodec.sol";
import { DVNAdapterBase } from "../DVNAdapterBase.sol";
/// @title OptimismDVNAdapterL1
/// @dev How Optimism DVN adapter works:
/// 1. call `sendMessage` on the L1CrossDomainMessenger contract.
/// refer to https://docs.optimism.io/builders/dapp-developers/bridging/messaging#basics-of-communication-between-layers
/// @dev Recovery:
/// 1. If the message is not executed or failed to execute on the destination chain, you can manually retry by calling `relayMessage` on the `CrossDomainMessenger` contract.
/// refer to https://github.com/ethereum-optimism/optimism/blob/develop/packages/contracts-bedrock/src/universal/CrossDomainMessenger.sol#L211C14-L211C26
contract OptimismDVNAdapterL1 is DVNAdapterBase {
// --- Errors ---
error OnlyOptimism();
error NoPeer();
// --- Events ---
event PeerSet(address indexed peer);
event GasLimitSet(uint32 gasLimit);
uint32 public immutable optimismEid; // eid % 30000 (v1 eid)
address public immutable l1Messenger; // L1CrossDomainMessenger
uint32 public gasLimit;
address public peer;
constructor(
address[] memory _admins,
uint32 _optimismEid,
address _l1Messenger
) DVNAdapterBase(msg.sender, _admins, 12000) {
optimismEid = _optimismEid; // eid % 30000 (v1 eid)
l1Messenger = _l1Messenger;
}
// --- Admin ---
function setGasLimit(uint32 _gasLimit) external onlyRole(ADMIN_ROLE) {
gasLimit = _gasLimit;
emit GasLimitSet(_gasLimit);
}
function setPeer(address _peer) external onlyRole(ADMIN_ROLE) {
peer = _peer;
emit PeerSet(_peer);
}
// --- Send ---
function assignJob(
AssignJobParam calldata _param,
bytes calldata /*_options*/
) external payable override onlyAcl(_param.sender) returns (uint256) {
_getAndAssertReceiveLib(msg.sender, _param.dstEid);
if (_param.dstEid % 30000 != optimismEid) revert OnlyOptimism();
if (peer == address(0)) revert NoPeer();
bytes memory payload = abi.encodeWithSelector(
OptimismDVNAdapterL2.verify.selector,
DVNAdapterMessageCodec.encode(
receiveLibs[msg.sender][_param.dstEid],
_param.packetHeader,
_param.payloadHash
)
);
ICrossDomainMessenger(l1Messenger).sendMessage(peer, payload, gasLimit);
return 0;
}
// --- View ---
function getFee(
uint32 /*_dstEid*/,
uint64 /*_confirmations*/,
address _sender,
bytes calldata /*_options*/
) public view override onlyAcl(_sender) returns (uint256) {
// no fee, charged as gas when sending message from L1 to L2
return 0;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity ^0.8.20;
import { ICrossDomainMessenger } from "@eth-optimism/contracts/libraries/bridge/ICrossDomainMessenger.sol";
import { DVNAdapterBase } from "../DVNAdapterBase.sol";
contract OptimismDVNAdapterL2 is DVNAdapterBase {
// --- Errors ---
error UntrustedPeer(address peer);
error Unauthorized();
// --- Events ---
event PeerSet(address indexed peer);
address public immutable l2Messenger; // L2CrossDomainMessenger
address public peer;
constructor(address[] memory _admins, address _l2Messenger) DVNAdapterBase(msg.sender, _admins, 12000) {
l2Messenger = _l2Messenger;
}
// --- Admin ---
function setPeer(address _peer) external onlyRole(ADMIN_ROLE) {
peer = _peer;
emit PeerSet(_peer);
}
// --- Send ---
function assignJob(
AssignJobParam calldata /*_param*/,
bytes calldata /*_options*/
) external payable override returns (uint256) {
revert DVNAdapter_NotImplemented();
}
function getFee(
uint32 /*_dstEid*/,
uint64 /*_confirmations*/,
address /*_sender*/,
bytes calldata /*_options*/
) external pure override returns (uint256) {
revert DVNAdapter_NotImplemented();
}
// --- Receive ---
function verify(bytes calldata _payload) external {
// assert messenger
if (msg.sender != l2Messenger) revert Unauthorized();
// assert peer
address xSender = ICrossDomainMessenger(l2Messenger).xDomainMessageSender();
if (xSender != peer) revert UntrustedPeer(xSender);
_decodeAndVerify(0, _payload); //todo: fix
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { ILayerZeroDVN } from "../interfaces/ILayerZeroDVN.sol";
contract DeadDVN is ILayerZeroDVN {
string internal constant ERROR_NOT_ALLOWED = "Please set your OApp's DVNs and/or Executor";
/// @dev for ULN301, ULN302 and more to assign job
function assignJob(AssignJobParam calldata, bytes calldata) external payable returns (uint256) {
revert(ERROR_NOT_ALLOWED);
}
/// @dev to support ULNv2
function assignJob(uint16, uint16, uint64, address) external pure returns (uint256) {
revert(ERROR_NOT_ALLOWED);
}
// ========================= View =========================
function getFee(uint32, uint64, address, bytes calldata) external pure returns (uint256) {
revert(ERROR_NOT_ALLOWED);
}
/// @dev to support ULNv2
function getFee(uint16, uint16, uint64, address) public pure returns (uint256) {
revert(ERROR_NOT_ALLOWED);
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { Transfer } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/Transfer.sol";
import { ILayerZeroPriceFeed } from "../../interfaces/ILayerZeroPriceFeed.sol";
import { IDVN } from "../interfaces/IDVN.sol";
import { IDVNFeeLib } from "../interfaces/IDVNFeeLib.sol";
import { DVNOptions } from "../libs/DVNOptions.sol";
import { ReadCmdCodecV1 } from "../libs/ReadCmdCodecV1.sol";
import { SupportedCmdTypesLib, SupportedCmdTypes, BitMap256 } from "../libs/SupportedCmdTypes.sol";
contract DVNFeeLib is Ownable, IDVNFeeLib {
using DVNOptions for bytes;
struct SetSupportedCmdTypesParam {
uint32 targetEid;
BitMap256 types;
}
struct BlockTimeConfig {
uint32 avgBlockTime; // milliseconds
uint64 blockNum; // the block number of the reference timestamp
uint64 timestamp; // second, the reference timestamp of the block number
uint32 maxPastRetention; // second, the max retention time the DVN will accept read requests/compute from the past time
uint32 maxFutureRetention; // second, the max retention time the DVN will accept read requests/compute from the future time
}
uint16 internal constant BPS_BASE = 10000;
// encoded( execute(ExecuteParam[]) ): funcSigHash + params -> 4 + 32(Offset of the array) + 32(array size) + 32(first element start offset)\
// + 32(vid) + 32(target) + 32(calldata-offset) + 32(expiration) + 32(signatures-offset) = 260
uint16 internal constant EXECUTE_FIXED_BYTES = 260;
uint16 internal constant SIGNATURE_RAW_BYTES = 65; // not encoded
// verify(bytes calldata _packetHeader, bytes32 _payloadHash, uint64 _confirmations)\
// 4 + 32(header offset) + 32(payloadHash) + 32(confirmations, 8 -> 32 padded) + 32(header-size) + 96(81 -> header-padded) = 228,
// padded to multiples of 32 = 256, encoded as bytes with an 32 byte for the bytes size = 288
uint16 internal constant VERIFY_BYTES_ULN = 288;
// verify(bytes calldata _packetHeader, bytes32 _cmdHash, bytes32 _payloadHash)\
// 4 + 32(header offset) + 32(cmdHash) + 32(payloadHash) + 32(header-size) + 96(81 -> header-padded) = 228,
// padded to multiples of 32 = 256, encoded as bytes with an 32 byte for the bytes size = 288
uint16 internal constant VERIFY_BYTES_CMD_LIB = 288;
uint256 internal immutable nativeDecimalsRate;
uint32 internal immutable localEidV2; // endpoint-v2 only, for read call
SupportedCmdTypes internal supportedCmdTypes;
uint120 internal evmCallRequestV1FeeUSD;
uint120 internal evmCallComputeV1ReduceFeeUSD;
uint16 internal evmCallComputeV1MapBps;
mapping(uint32 dstEid => BlockTimeConfig) public dstBlockTimeConfigs;
constructor(uint32 _localEidV2, uint256 _nativeDecimalsRate) {
localEidV2 = _localEidV2;
nativeDecimalsRate = _nativeDecimalsRate;
}
// ================================ OnlyOwner ================================
function setSupportedCmdTypes(SetSupportedCmdTypesParam[] calldata _params) external onlyOwner {
for (uint256 i = 0; i < _params.length; i++) {
supportedCmdTypes.cmdTypes[_params[i].targetEid] = _params[i].types;
}
}
function getSupportedCmdTypes(uint32 _targetEid) external view returns (BitMap256) {
return supportedCmdTypes.cmdTypes[_targetEid];
}
function setDstBlockTimeConfigs(
uint32[] calldata dstEids,
BlockTimeConfig[] calldata _blockConfigs
) external onlyOwner {
if (dstEids.length != _blockConfigs.length) revert DVN_INVALID_INPUT_LENGTH();
for (uint256 i = 0; i < dstEids.length; i++) {
dstBlockTimeConfigs[dstEids[i]] = _blockConfigs[i];
}
}
function withdrawToken(address _token, address _to, uint256 _amount) external onlyOwner {
// transfers native if _token is address(0x0)
Transfer.nativeOrToken(_token, _to, _amount);
}
function setCmdFees(
uint120 _evmCallRequestV1FeeUSD,
uint120 _evmCallComputeV1ReduceFeeUSD,
uint16 _evmCallComputeV1MapBps
) external onlyOwner {
evmCallRequestV1FeeUSD = _evmCallRequestV1FeeUSD;
evmCallComputeV1ReduceFeeUSD = _evmCallComputeV1ReduceFeeUSD;
evmCallComputeV1MapBps = _evmCallComputeV1MapBps;
}
function getCmdFees() external view returns (uint120, uint120, uint16) {
return (evmCallRequestV1FeeUSD, evmCallComputeV1ReduceFeeUSD, evmCallComputeV1MapBps);
}
// ========================= External =========================
/// @dev get fee function that can change state. e.g. paying priceFeed
/// @param _params fee params
/// @param _dstConfig dst config
/// @param //_options options
function getFeeOnSend(
FeeParams calldata _params,
IDVN.DstConfig calldata _dstConfig,
bytes calldata _options
) external payable returns (uint256) {
return getFee(_params, _dstConfig, _options);
}
function getFeeOnSend(
FeeParamsForRead calldata _params,
IDVN.DstConfig calldata _dstConfig,
bytes calldata _cmd,
bytes calldata _options
) external payable returns (uint256 fee) {
fee = getFee(_params, _dstConfig, _cmd, _options);
}
// ========================= View =========================
/// @dev get fee view function
/// @param _params fee params
/// @param _dstConfig dst config
/// @param //_options options
function getFee(
FeeParams calldata _params,
IDVN.DstConfig calldata _dstConfig,
bytes calldata _options
) public view returns (uint256) {
if (_dstConfig.gas == 0) revert DVN_EidNotSupported(_params.dstEid);
_decodeDVNOptions(_options); // validate options
uint256 callDataSize = _getCallDataSize(_params.quorum);
(uint256 fee, , , uint128 nativePriceUSD) = ILayerZeroPriceFeed(_params.priceFeed).estimateFeeByEid(
_params.dstEid,
callDataSize,
_dstConfig.gas
);
return
_applyPremium(
fee,
_dstConfig.multiplierBps,
_params.defaultMultiplierBps,
_dstConfig.floorMarginUSD,
nativePriceUSD
);
}
function getFee(
FeeParamsForRead calldata _params,
IDVN.DstConfig calldata _dstConfig,
bytes calldata _cmd,
bytes calldata _options
) public view returns (uint256) {
if (_dstConfig.gas == 0) revert DVN_EidNotSupported(localEidV2);
_decodeDVNOptions(_options); // validate options
uint256 callDataSize = _getReadCallDataSize(_params.quorum);
(uint256 fee, , , uint128 nativePriceUSD) = ILayerZeroPriceFeed(_params.priceFeed).estimateFeeByEid(
localEidV2,
callDataSize,
_dstConfig.gas
);
// cmdFeeUSD -> cmdFee native final
uint256 cmdFeeUSD = _estimateCmdFee(_cmd);
uint256 cmdFee = (cmdFeeUSD * nativeDecimalsRate) / nativePriceUSD;
return
_applyPremium(
fee + cmdFee,
_dstConfig.multiplierBps,
_params.defaultMultiplierBps,
_dstConfig.floorMarginUSD,
nativePriceUSD
);
}
// ========================= Internal =========================
function _getCallDataSize(uint256 _quorum) internal pure returns (uint256) {
return _getCallDataSizeByQuorumAndVerifyBytes(_quorum, VERIFY_BYTES_ULN);
}
function _getReadCallDataSize(uint256 _quorum) internal pure returns (uint256) {
return _getCallDataSizeByQuorumAndVerifyBytes(_quorum, VERIFY_BYTES_CMD_LIB);
}
function _getCallDataSizeByQuorumAndVerifyBytes(
uint256 _quorum,
uint256 verifyBytes
) internal pure returns (uint256) {
uint256 totalSignatureBytes = _quorum * SIGNATURE_RAW_BYTES;
if (totalSignatureBytes % 32 != 0) {
totalSignatureBytes = totalSignatureBytes - (totalSignatureBytes % 32) + 32;
}
// getFee should charge on execute(updateHash)
// totalSignatureBytesPadded also has 32 as size of the bytes
return uint256(EXECUTE_FIXED_BYTES) + verifyBytes + totalSignatureBytes + 32;
}
function _applyPremium(
uint256 _fee,
uint16 _bps,
uint16 _defaultBps,
uint128 _marginUSD,
uint128 _nativePriceUSD
) internal view returns (uint256) {
uint16 multiplierBps = _bps == 0 ? _defaultBps : _bps;
uint256 feeWithMultiplier = (_fee * multiplierBps) / 10000;
if (_nativePriceUSD == 0 || _marginUSD == 0) {
return feeWithMultiplier;
}
uint256 feeWithFloorMargin = _fee + (_marginUSD * nativeDecimalsRate) / _nativePriceUSD;
return feeWithFloorMargin > feeWithMultiplier ? feeWithFloorMargin : feeWithMultiplier;
}
function _decodeDVNOptions(bytes calldata _options) internal pure returns (uint256) {
uint256 cursor;
while (cursor < _options.length) {
(uint8 optionType, , uint256 newCursor) = _options.nextDVNOption(cursor);
cursor = newCursor;
revert DVN_UnsupportedOptionType(optionType);
}
if (cursor != _options.length) revert DVNOptions.DVN_InvalidDVNOptions(cursor);
return 0; // todo: precrime fee model
}
function _estimateCmdFee(bytes calldata _cmd) internal view returns (uint256 fee) {
ReadCmdCodecV1.Cmd memory cmd = ReadCmdCodecV1.decode(_cmd, _assertCmdTypeSupported);
fee = cmd.numEvmCallRequestV1 * evmCallRequestV1FeeUSD;
if (cmd.evmCallComputeV1Map) {
fee += (fee * evmCallComputeV1MapBps) / BPS_BASE;
}
if (cmd.evmCallComputeV1Reduce) {
fee += evmCallComputeV1ReduceFeeUSD;
}
}
function _assertCmdTypeSupported(
uint32 _targetEid,
bool _isBlockNum,
uint64 _blockNumOrTimestamp,
uint8 _cmdType
) internal view {
supportedCmdTypes.assertSupported(_targetEid, _cmdType);
if (supportedCmdTypes.isSupported(_targetEid, SupportedCmdTypesLib.CMD_V1__TIMESTAMP_VALIDATE)) {
BlockTimeConfig memory blockCnf = dstBlockTimeConfigs[_targetEid];
uint64 timestamp = _blockNumOrTimestamp;
if (_isBlockNum) {
// convert the blockNum to the timestamp
if (_blockNumOrTimestamp > blockCnf.blockNum) {
timestamp =
blockCnf.timestamp +
((_blockNumOrTimestamp - blockCnf.blockNum) * blockCnf.avgBlockTime) /
1000;
} else {
timestamp =
blockCnf.timestamp -
((blockCnf.blockNum - _blockNumOrTimestamp) * blockCnf.avgBlockTime) /
1000;
}
}
if (
timestamp + blockCnf.maxPastRetention < block.timestamp ||
timestamp > block.timestamp + blockCnf.maxFutureRetention
) {
revert DVN_TimestampOutOfRange(_targetEid, timestamp);
}
}
}
function version() external pure returns (uint64 major, uint8 minor) {
return (1, 1);
}
// send funds here to pay for price feed directly
receive() external payable {}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
abstract contract MultiSig {
using EnumerableSet for EnumerableSet.AddressSet;
enum Errors {
NoError,
SignatureError,
DuplicatedSigner,
SignerNotInCommittee
}
EnumerableSet.AddressSet internal signerSet;
uint64 public quorum;
error MultiSig_OnlySigner();
error MultiSig_QuorumIsZero();
error MultiSig_SignersSizeIsLessThanQuorum(uint64 signersSize, uint64 quorum);
error MultiSig_UnorderedSigners();
error MultiSig_StateAlreadySet(address signer, bool active);
error MultiSig_StateNotSet(address signer, bool active);
error MultiSig_InvalidSigner();
event UpdateSigner(address _signer, bool _active);
event UpdateQuorum(uint64 _quorum);
modifier onlySigner() {
if (!isSigner(msg.sender)) {
revert MultiSig_OnlySigner();
}
_;
}
constructor(address[] memory _signers, uint64 _quorum) {
if (_quorum == 0) {
revert MultiSig_QuorumIsZero();
}
for (uint256 i = 0; i < _signers.length; i++) {
address signer = _signers[i];
if (signer == address(0)) {
revert MultiSig_InvalidSigner();
}
signerSet.add(signer);
}
uint64 _signerSize = uint64(signerSet.length());
if (_signerSize < _quorum) {
revert MultiSig_SignersSizeIsLessThanQuorum(_signerSize, _quorum);
}
quorum = _quorum;
}
function _setSigner(address _signer, bool _active) internal {
if (_active) {
if (_signer == address(0)) {
revert MultiSig_InvalidSigner();
}
if (!signerSet.add(_signer)) {
revert MultiSig_StateAlreadySet(_signer, _active);
}
} else {
if (!signerSet.remove(_signer)) {
revert MultiSig_StateNotSet(_signer, _active);
}
}
uint64 _signerSize = uint64(signerSet.length());
uint64 _quorum = quorum;
if (_signerSize < _quorum) {
revert MultiSig_SignersSizeIsLessThanQuorum(_signerSize, _quorum);
}
emit UpdateSigner(_signer, _active);
}
function _setQuorum(uint64 _quorum) internal {
if (_quorum == 0) {
revert MultiSig_QuorumIsZero();
}
uint64 _signerSize = uint64(signerSet.length());
if (_signerSize < _quorum) {
revert MultiSig_SignersSizeIsLessThanQuorum(_signerSize, _quorum);
}
quorum = _quorum;
emit UpdateQuorum(_quorum);
}
function verifySignatures(bytes32 _hash, bytes calldata _signatures) public view returns (bool, Errors) {
if (_signatures.length != uint256(quorum) * 65) {
return (false, Errors.SignatureError);
}
bytes32 messageDigest = _getEthSignedMessageHash(_hash);
address lastSigner = address(0); // There cannot be a signer with address 0.
for (uint256 i = 0; i < quorum; i++) {
// the quorum is guaranteed not to be zero in the constructor and setter
bytes calldata signature = _signatures[i * 65:(i + 1) * 65];
(address currentSigner, ECDSA.RecoverError error) = ECDSA.tryRecover(messageDigest, signature);
if (error != ECDSA.RecoverError.NoError) return (false, Errors.SignatureError);
if (currentSigner <= lastSigner) return (false, Errors.DuplicatedSigner); // prevent duplicate signatures, the signers must be ordered to sign the digest
if (!isSigner(currentSigner)) return (false, Errors.SignerNotInCommittee); // signature is not in committee
lastSigner = currentSigner;
}
return (true, Errors.NoError);
}
function _getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash));
}
// ============================================== View ==============================================
function getSigners() public view returns (address[] memory) {
return signerSet.values();
}
// compatibility with the previous version
function signers(address _signer) public view returns (bool) {
return isSigner(_signer);
}
function isSigner(address _signer) public view returns (bool) {
return signerSet.contains(_signer);
}
function signerSize() public view returns (uint256) {
return signerSet.length();
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { BitMap256 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/BitMaps.sol";
import { ILayerZeroReadDVN } from "../interfaces/ILayerZeroReadDVN.sol";
import { ReadCmdCodecV1 } from "../libs/ReadCmdCodecV1.sol";
import { ReadLib1002 } from "../readlib/ReadLib1002.sol";
import { SupportedCmdTypes } from "../libs/SupportedCmdTypes.sol";
contract SimpleReadDVN is ILayerZeroReadDVN {
struct SetSupportedCmdTypesParam {
uint32 targetEid;
BitMap256 types;
}
uint128 internal constant DENOMINATOR = 10 ** 18;
uint128 internal constant NATIVE_DECIMALS = 10 ** 18;
uint16 internal constant BPS_BASE = 10000;
address payable public immutable readLib;
// the usd fee should be usd * DENOMINATOR
uint128 internal evmCallRequestV1FeeUSD;
uint128 internal evmCallComputeV1MapFeeUSD;
uint128 internal evmCallComputeV1ReduceFeeUSD;
uint128 internal nativePriceUSD; // usd * DENOMINATOR
SupportedCmdTypes internal supportedCmdTypes;
constructor(address payable _readLib) {
readLib = _readLib;
}
function setSupportedCmdTypes(SetSupportedCmdTypesParam[] calldata _params) external {
for (uint256 i = 0; i < _params.length; i++) {
supportedCmdTypes.cmdTypes[_params[i].targetEid] = _params[i].types;
}
}
function assignJob(
address /*_sender*/,
bytes calldata /*_packetHeader*/,
bytes calldata _cmd,
bytes calldata /*_options*/
) external payable returns (uint256) {
uint256 cmdFeeUSD = _estimateCmdFee(_cmd);
uint256 cmdFee = (cmdFeeUSD * NATIVE_DECIMALS) / nativePriceUSD;
return cmdFee;
}
function verify(bytes calldata _packetHeader, bytes32 _cmdHash, bytes32 _payloadHash) external {
ReadLib1002(readLib).verify(_packetHeader, _cmdHash, _payloadHash);
}
// ========================= View =========================
function getFee(
address /*_sender*/,
bytes calldata /*_packetHeader*/,
bytes calldata _cmd,
bytes calldata /*_options*/
) external view returns (uint256) {
// cmdFeeUSD -> cmdFee native
uint256 cmdFeeUSD = _estimateCmdFee(_cmd);
uint256 cmdFee = (cmdFeeUSD * NATIVE_DECIMALS) / nativePriceUSD;
return cmdFee;
}
function setCmdFees(
uint128 _evmCallReqV1FeeUSD,
uint128 _evmCallComputeV1MapFeeUSD,
uint128 _evmCallComputeV1ReduceFeeUSD,
uint128 _nativePriceUSD
) external {
evmCallRequestV1FeeUSD = _evmCallReqV1FeeUSD;
evmCallComputeV1MapFeeUSD = _evmCallComputeV1MapFeeUSD;
evmCallComputeV1ReduceFeeUSD = _evmCallComputeV1ReduceFeeUSD;
nativePriceUSD = _nativePriceUSD;
}
function getCmdFees() external view returns (uint128, uint128, uint128, uint128) {
return (evmCallRequestV1FeeUSD, evmCallComputeV1MapFeeUSD, evmCallComputeV1ReduceFeeUSD, nativePriceUSD);
}
function _estimateCmdFee(bytes calldata _cmd) internal view returns (uint256 fee) {
ReadCmdCodecV1.Cmd memory cmd = ReadCmdCodecV1.decode(_cmd, _assertCmdTypeSupported);
fee = cmd.numEvmCallRequestV1 * evmCallRequestV1FeeUSD;
if (cmd.evmCallComputeV1Map) {
fee += evmCallComputeV1MapFeeUSD * cmd.numEvmCallRequestV1;
}
if (cmd.evmCallComputeV1Reduce) {
fee += evmCallComputeV1ReduceFeeUSD;
}
}
function _assertCmdTypeSupported(
uint32 _targetEid,
bool /*_isBlockNum*/,
uint64 /*_blockNumOrTimestamp*/,
uint8 _cmdType
) internal view {
supportedCmdTypes.assertSupported(_targetEid, _cmdType);
}
receive() external payable virtual {}
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface IAxelarDVNAdapter {
struct MultiplierParam {
uint32 dstEid;
uint16 multiplierBps;
}
struct FloorMarginUSDParam {
uint32 dstEid;
uint128 floorMarginUSD;
}
struct NativeGasFeeParam {
uint32 dstEid;
uint256 nativeGasFee;
}
struct DstConfigParam {
uint32 eid;
string chainName;
string peer;
uint16 multiplierBps;
uint256 nativeGasFee;
}
struct DstConfig {
string chainName;
string peer;
uint16 multiplierBps;
uint256 nativeGasFee;
}
struct SrcConfig {
uint32 eid;
string peer;
}
event DstConfigSet(DstConfigParam[] params);
event NativeGasFeeSet(NativeGasFeeParam[] params);
event MultiplierSet(MultiplierParam[] params);
event FloorMarginUSDSet(FloorMarginUSDParam[] params);
error AxelarDVNAdapter_UntrustedPeer(string chainName, string peer);
error AxelarDVNAdapter_OnlyWorkerFeeLib();
function withdrawToFeeLib(address _sendLib) external;
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IAxelarDVNAdapter } from "./IAxelarDVNAdapter.sol";
interface IAxelarDVNAdapterFeeLib {
struct Param {
uint32 dstEid;
uint64 confirmations;
address sender;
uint16 defaultMultiplierBps;
}
struct DstConfig {
uint64 gas;
uint128 floorMarginUSD; // uses priceFeed PRICE_RATIO_DENOMINATOR
}
struct DstConfigParam {
uint32 dstEid;
uint64 gas;
uint128 floorMarginUSD; // uses priceFeed PRICE_RATIO_DENOMINATOR
}
event DstConfigSet(DstConfigParam[] params);
event TokenWithdrawn(address token, address to, uint256 amount);
event GasServiceSet(address gasService);
event PriceFeedSet(address priceFeed);
event NativeGasFeeMultiplierBpsSet(uint16 multiplierBps);
error AxelarDVNAdapter_OptionsUnsupported();
error AxelarDVNAdapter_InsufficientBalance(uint256 actual, uint256 requested);
error AxelarDVNAdapter_EidNotSupported(uint32 eid);
function getFeeOnSend(
Param calldata _params,
IAxelarDVNAdapter.DstConfig calldata _dstConfig,
bytes memory _payload,
bytes calldata _options,
address _sendLib
) external payable returns (uint256 totalFee);
function getFee(
Param calldata _params,
IAxelarDVNAdapter.DstConfig calldata _dstConfig,
bytes calldata _options
) external view returns (uint256 totalFee);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface ICCIPDVNAdapter {
struct DstConfigParam {
uint32 eid;
uint16 multiplierBps;
uint64 chainSelector;
uint256 gas;
bytes peer;
}
struct DstConfig {
// https://docs.chain.link/ccip/supported-networks/v1_2_0/testnet#ethereum-sepolia
// https://docs.chain.link/ccip/supported-networks/v1_0_0/mainnet
uint64 chainSelector;
uint16 multiplierBps;
// https://github.com/smartcontractkit/ccip/blob/ccip-develop/contracts/src/v0.8/ccip/libraries/Client.sol#L22C51-L22C51
// for destination is evm chain, need to use `abi.encode(address)` to get the peer
bytes peer;
uint256 gas;
}
struct SrcConfig {
uint32 eid;
bytes peer;
}
event DstConfigSet(DstConfigParam[] params);
error CCIPDVNAdapter_UntrustedPeer(uint64 chainSelector, bytes peer);
error CCIPDVNAdapter_InvalidRouter(address router);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { Client } from "@chainlink/contracts-ccip/src/v0.8/ccip/libraries/Client.sol";
import { IRouterClient } from "@chainlink/contracts-ccip/src/v0.8/ccip/interfaces/IRouterClient.sol";
import { ICCIPDVNAdapter } from "./ICCIPDVNAdapter.sol";
interface ICCIPDVNAdapterFeeLib {
struct Param {
uint32 dstEid;
uint64 confirmations;
address sender;
uint16 defaultMultiplierBps;
}
struct DstConfig {
uint128 floorMarginUSD; // uses priceFeed PRICE_RATIO_DENOMINATOR
}
struct DstConfigParam {
uint32 dstEid;
uint128 floorMarginUSD; // uses priceFeed PRICE_RATIO_DENOMINATOR
}
event DstConfigSet(DstConfigParam[] params);
error CCIPDVNAdapter_OptionsUnsupported();
error CCIPDVNAdapter_EidNotSupported(uint32 eid);
function getFeeOnSend(
Param calldata _params,
ICCIPDVNAdapter.DstConfig calldata _dstConfig,
Client.EVM2AnyMessage calldata _message,
bytes calldata _options,
IRouterClient _router
) external payable returns (uint256 ccipFee, uint256 totalFee);
function getFee(
Param calldata _params,
ICCIPDVNAdapter.DstConfig calldata _dstConfig,
Client.EVM2AnyMessage calldata _message,
bytes calldata _options,
IRouterClient _router
) external view returns (uint256 totalFee);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IWorker } from "../../interfaces/IWorker.sol";
import { ILayerZeroDVN } from "./ILayerZeroDVN.sol";
import { ILayerZeroReadDVN } from "./ILayerZeroReadDVN.sol";
interface IDVN is IWorker, ILayerZeroDVN, ILayerZeroReadDVN {
struct DstConfigParam {
uint32 dstEid;
uint64 gas;
uint16 multiplierBps;
uint128 floorMarginUSD;
}
struct DstConfig {
uint64 gas;
uint16 multiplierBps;
uint128 floorMarginUSD; // uses priceFeed PRICE_RATIO_DENOMINATOR
}
event SetDstConfig(DstConfigParam[] params);
function dstConfig(uint32 _dstEid) external view returns (uint64, uint16, uint128);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
import { IDVN } from "./IDVN.sol";
interface IDVNFeeLib {
struct FeeParams {
address priceFeed;
uint32 dstEid;
uint64 confirmations;
address sender;
uint64 quorum;
uint16 defaultMultiplierBps;
}
struct FeeParamsForRead {
address priceFeed;
address sender;
uint64 quorum;
uint16 defaultMultiplierBps;
}
error DVN_UnsupportedOptionType(uint8 optionType);
error DVN_EidNotSupported(uint32 eid);
error DVN_TimestampOutOfRange(uint32 eid, uint64 timestamp);
error DVN_INVALID_INPUT_LENGTH();
function getFeeOnSend(
FeeParams calldata _params,
IDVN.DstConfig calldata _dstConfig,
bytes calldata _options
) external payable returns (uint256 fee);
function getFee(
FeeParams calldata _params,
IDVN.DstConfig calldata _dstConfig,
bytes calldata _options
) external view returns (uint256 fee);
function getFeeOnSend(
FeeParamsForRead calldata _params,
IDVN.DstConfig calldata _dstConfig,
bytes calldata _cmd,
bytes calldata _options
) external payable returns (uint256 fee);
function getFee(
FeeParamsForRead calldata _params,
IDVN.DstConfig calldata _dstConfig,
bytes calldata _cmd,
bytes calldata _options
) external view returns (uint256 fee);
function version() external view returns (uint64 major, uint8 minor);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface ILayerZeroDVN {
struct AssignJobParam {
uint32 dstEid;
bytes packetHeader;
bytes32 payloadHash;
uint64 confirmations;
address sender;
}
// @notice query price and assign jobs at the same time
// @param _dstEid - the destination endpoint identifier
// @param _packetHeader - version + nonce + path
// @param _payloadHash - hash of guid + message
// @param _confirmations - block confirmation delay before relaying blocks
// @param _sender - the source sending contract address
// @param _options - options
function assignJob(AssignJobParam calldata _param, bytes calldata _options) external payable returns (uint256 fee);
// @notice query the dvn fee for relaying block information to the destination chain
// @param _dstEid the destination endpoint identifier
// @param _confirmations - block confirmation delay before relaying blocks
// @param _sender - the source sending contract address
// @param _options - options
function getFee(
uint32 _dstEid,
uint64 _confirmations,
address _sender,
bytes calldata _options
) external view returns (uint256 fee);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
interface ILayerZeroReadDVN {
// @notice query price and assign jobs at the same time
// @param _packetHeader - version + nonce + path
// @param _cmd - the command to be executed to obtain the payload
// @param _options - options
function assignJob(
address _sender,
bytes calldata _packetHeader,
bytes calldata _cmd,
bytes calldata _options
) external payable returns (uint256 fee);
// @notice query the dvn fee for relaying block information to the destination chain
// @param _packetHeader - version + nonce + path
// @param _cmd - the command to be executed to obtain the payload
// @param _options - options
function getFee(
address _sender,
bytes calldata _packetHeader,
bytes calldata _cmd,
bytes calldata _options
) external view returns (uint256 fee);
}// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0;
/// @dev should be implemented by the ReceiveUln302 contract and future ReceiveUln contracts on EndpointV2
interface IReceiveUlnE2 {
/// @notice for each dvn to verify the payload
/// @dev this function signature 0x0223536e
function verify(bytes calldata _packetHeader, bytes32 _payloadHash, uint64 _confirmations) external;
/// @notice verify the payload at endpoint, will check if all DVNs verified
function commitVerification(bytes calldata _packetHeader, bytes32 _payloadHash) external;
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { BytesLib } from "solidity-bytes-utils/contracts/BytesLib.sol";
import { BitMap256 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/BitMaps.sol";
import { CalldataBytesLib } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/CalldataBytesLib.sol";
library DVNOptions {
using CalldataBytesLib for bytes;
using BytesLib for bytes;
uint8 internal constant WORKER_ID = 2;
uint8 internal constant OPTION_TYPE_PRECRIME = 1;
error DVN_InvalidDVNIdx();
error DVN_InvalidDVNOptions(uint256 cursor);
/// @dev group dvn options by its idx
/// @param _options [dvn_id][dvn_option][dvn_id][dvn_option]...
/// dvn_option = [option_size][dvn_idx][option_type][option]
/// option_size = len(dvn_idx) + len(option_type) + len(option)
/// dvn_id: uint8, dvn_idx: uint8, option_size: uint16, option_type: uint8, option: bytes
/// @return dvnOptions the grouped options, still share the same format of _options
/// @return dvnIndices the dvn indices
function groupDVNOptionsByIdx(
bytes memory _options
) internal pure returns (bytes[] memory dvnOptions, uint8[] memory dvnIndices) {
if (_options.length == 0) return (dvnOptions, dvnIndices);
uint8 numDVNs = getNumDVNs(_options);
// if there is only 1 dvn, we can just return the whole options
if (numDVNs == 1) {
dvnOptions = new bytes[](1);
dvnOptions[0] = _options;
dvnIndices = new uint8[](1);
dvnIndices[0] = _options.toUint8(3); // dvn idx
return (dvnOptions, dvnIndices);
}
// otherwise, we need to group the options by dvn_idx
dvnIndices = new uint8[](numDVNs);
dvnOptions = new bytes[](numDVNs);
unchecked {
uint256 cursor = 0;
uint256 start = 0;
uint8 lastDVNIdx = 255; // 255 is an invalid dvn_idx
while (cursor < _options.length) {
++cursor; // skip worker_id
// optionLength asserted in getNumDVNs (skip check)
uint16 optionLength = _options.toUint16(cursor);
cursor += 2;
// dvnIdx asserted in getNumDVNs (skip check)
uint8 dvnIdx = _options.toUint8(cursor);
// dvnIdx must equal to the lastDVNIdx for the first option
// so it is always skipped in the first option
// this operation slices out options whenever the scan finds a different lastDVNIdx
if (lastDVNIdx == 255) {
lastDVNIdx = dvnIdx;
} else if (dvnIdx != lastDVNIdx) {
uint256 len = cursor - start - 3; // 3 is for worker_id and option_length
bytes memory opt = _options.slice(start, len);
_insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, opt);
// reset the start and lastDVNIdx
start += len;
lastDVNIdx = dvnIdx;
}
cursor += optionLength;
}
// skip check the cursor here because the cursor is asserted in getNumDVNs
// if we have reached the end of the options, we need to process the last dvn
uint256 size = cursor - start;
bytes memory op = _options.slice(start, size);
_insertDVNOptions(dvnOptions, dvnIndices, lastDVNIdx, op);
// revert dvnIndices to start from 0
for (uint8 i = 0; i < numDVNs; ++i) {
--dvnIndices[i];
}
}
}
function _insertDVNOptions(
bytes[] memory _dvnOptions,
uint8[] memory _dvnIndices,
uint8 _dvnIdx,
bytes memory _newOptions
) internal pure {
// dvnIdx starts from 0 but default value of dvnIndices is 0,
// so we tell if the slot is empty by adding 1 to dvnIdx
if (_dvnIdx == 255) revert DVN_InvalidDVNIdx();
uint8 dvnIdxAdj = _dvnIdx + 1;
for (uint256 j = 0; j < _dvnIndices.length; ++j) {
uint8 index = _dvnIndices[j];
if (dvnIdxAdj == index) {
_dvnOptions[j] = abi.encodePacked(_dvnOptions[j], _newOptions);
break;
} else if (index == 0) {
// empty slot, that means it is the first time we see this dvn
_dvnIndices[j] = dvnIdxAdj;
_dvnOptions[j] = _newOptions;
break;
}
}
}
/// @dev get the number of unique dvns
/// @param _options the format is the same as groupDVNOptionsByIdx
function getNumDVNs(bytes memory _options) internal pure returns (uint8 numDVNs) {
uint256 cursor = 0;
BitMap256 bitmap;
// find number of unique dvn_idx
unchecked {
while (cursor < _options.length) {
++cursor; // skip worker_id
uint16 optionLength = _options.toUint16(cursor);
cursor += 2;
if (optionLength < 2) revert DVN_InvalidDVNOptions(cursor); // at least 1 byte for dvn_idx and 1 byte for option_type
uint8 dvnIdx = _options.toUint8(cursor);
// if dvnIdx is not set, increment numDVNs
// max num of dvns is 255, 255 is an invalid dvn_idx
// The order of the dvnIdx is not required to be sequential, as enforcing the order may weaken
// the composability of the options. e.g. if we refrain from enforcing the order, an OApp that has
// already enforced certain options can append additional options to the end of the enforced
// ones without restrictions.
if (dvnIdx == 255) revert DVN_InvalidDVNIdx();
if (!bitmap.get(dvnIdx)) {
++numDVNs;
bitmap = bitmap.set(dvnIdx);
}
cursor += optionLength;
}
}
if (cursor != _options.length) revert DVN_InvalidDVNOptions(cursor);
}
/// @dev decode the next dvn option from _options starting from the specified cursor
/// @param _options the format is the same as groupDVNOptionsByIdx
/// @param _cursor the cursor to start decoding
/// @return optionType the type of the option
/// @return option the option
/// @return cursor the cursor to start decoding the next option
function nextDVNOption(
bytes calldata _options,
uint256 _cursor
) internal pure returns (uint8 optionType, bytes calldata option, uint256 cursor) {
unchecked {
// skip worker id
cursor = _cursor + 1;
// read option size
uint16 size = _options.toU16(cursor);
cursor += 2;
// read option type
optionType = _options.toU8(cursor + 1); // skip dvn_idx
// startCursor and endCursor are used to slice the option from _options
uint256 startCursor = cursor + 2; // skip option type and dvn_idx
uint256 endCursor = cursor + size;
option = _options[startCursor:endCursor];
cursor += size;
}
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { SupportedCmdTypes, SupportedCmdTypesLib } from "./SupportedCmdTypes.sol";
library ReadCmdCodecV1 {
uint16 internal constant CMD_VERSION = 1;
uint8 internal constant REQUEST_VERSION = 1;
uint16 internal constant RESOLVER_TYPE_SINGLE_VIEW_EVM_CALL = 1;
uint8 internal constant COMPUTE_VERSION = 1;
uint16 internal constant COMPUTE_TYPE_SINGLE_VIEW_EVM_CALL = 1;
uint8 internal constant COMPUTE_SETTING_MAP_ONLY = 0;
uint8 internal constant COMPUTE_SETTING_REDUCE_ONLY = 1;
uint8 internal constant COMPUTE_SETTING_MAP_AND_REDUCE = 2;
error InvalidCmd();
error InvalidVersion();
error InvalidType();
struct Cmd {
uint16 numEvmCallRequestV1;
bool evmCallComputeV1Map;
bool evmCallComputeV1Reduce;
}
function decode(
bytes calldata _cmd,
function(uint32, bool, uint64, uint8) view _assertCmdTypeSupported
) internal view returns (Cmd memory cmd) {
uint256 cursor = 0;
// decode the header in scope, depress stack too deep
{
uint16 cmdVersion = uint16(bytes2(_cmd[cursor:cursor + 2]));
cursor += 2;
if (cmdVersion != CMD_VERSION) revert InvalidVersion();
cursor += 2; // skip appCmdLabel
uint16 requestCount = uint16(bytes2(_cmd[cursor:cursor + 2]));
cursor += 2;
// there is only one request type in this version, so total request count should be the same as numEvmCallRequestV1
if (requestCount == 0) revert InvalidCmd();
cmd.numEvmCallRequestV1 = requestCount;
}
// decode the requests
for (uint16 i = 0; i < cmd.numEvmCallRequestV1; i++) {
uint8 requestVersion = uint8(_cmd[cursor]);
cursor += 1;
if (requestVersion != REQUEST_VERSION) revert InvalidVersion();
// skip appRequestLabel
cursor += 2;
uint16 resolverType = uint16(bytes2(_cmd[cursor:cursor + 2]));
cursor += 2;
if (resolverType == RESOLVER_TYPE_SINGLE_VIEW_EVM_CALL) {
uint16 requestSize = uint16(bytes2(_cmd[cursor:cursor + 2]));
cursor += 2;
// decode the request in scope, depress stack too deep
{
uint256 requestCursor = cursor;
uint32 targetEid = uint32(bytes4(_cmd[requestCursor:requestCursor + 4]));
requestCursor += 4;
bool isBlockNum = uint8(_cmd[requestCursor]) == 1;
requestCursor += 1;
uint64 blockNumOrTimestamp = uint64(bytes8(_cmd[requestCursor:requestCursor + 8]));
_assertCmdTypeSupported(
targetEid,
isBlockNum,
blockNumOrTimestamp,
SupportedCmdTypesLib.CMD_V1__REQUEST_V1__EVM_CALL
);
}
if (cursor + requestSize > _cmd.length) revert InvalidCmd();
cursor += requestSize;
} else {
revert InvalidType();
}
}
// decode the compute if it exists
if (cursor < _cmd.length) {
uint8 computeVersion = uint8(_cmd[cursor]);
cursor += 1;
if (computeVersion != COMPUTE_VERSION) revert InvalidVersion();
uint16 computeType = uint16(bytes2(_cmd[cursor:cursor + 2]));
cursor += 2;
if (computeType != COMPUTE_TYPE_SINGLE_VIEW_EVM_CALL) revert InvalidType();
uint8 computeSetting = uint8(_cmd[cursor]);
cursor += 1;
if (computeSetting == COMPUTE_SETTING_MAP_ONLY) {
cmd.evmCallComputeV1Map = true;
} else if (computeSetting == COMPUTE_SETTING_REDUCE_ONLY) {
cmd.evmCallComputeV1Reduce = true;
} else if (computeSetting == COMPUTE_SETTING_MAP_AND_REDUCE) {
cmd.evmCallComputeV1Map = true;
cmd.evmCallComputeV1Reduce = true;
} else {
revert InvalidType();
}
uint32 targetEid = uint32(bytes4(_cmd[cursor:cursor + 4]));
cursor += 4;
bool isBlockNum = uint8(_cmd[cursor]) == 1;
cursor += 1;
uint64 blockNumOrTimestamp = uint64(bytes8(_cmd[cursor:cursor + 8]));
cursor += 8;
_assertCmdTypeSupported(
targetEid,
isBlockNum,
blockNumOrTimestamp,
SupportedCmdTypesLib.CMD_V1__COMPUTE_V1__EVM_CALL
);
// assert the remaining length: confirmations(2), to(20)
cursor += 22;
}
if (cursor != _cmd.length) revert InvalidCmd();
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import { BitMap256 } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/BitMaps.sol";
struct SupportedCmdTypes {
mapping(uint32 => BitMap256) cmdTypes; // support options
}
using SupportedCmdTypesLib for SupportedCmdTypes global;
library SupportedCmdTypesLib {
// the max number of supported command types is 256
uint8 internal constant CMD_V1__REQUEST_V1__EVM_CALL = 0;
uint8 internal constant CMD_V1__COMPUTE_V1__EVM_CALL = 1;
uint8 internal constant CMD_V1__TIMESTAMP_VALIDATE = 2; // validate timestamp, to check if the timestamp is out of range
// more types can be added here in the future
error UnsupportedTargetEid();
function assertSupported(SupportedCmdTypes storage _self, uint32 _targetEid, uint8 _type) internal view {
if (!isSupported(_self, _targetEid, _type)) revert UnsupportedTargetEid();
}
function isSupported(SupportedCmdTypes storage _self, uint32 _targetEid, uint8 _type) internal view returns (bool) {
return _self.cmdTypes[_targetEid].get(_type);
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { SafeCast } from "@openzeppelin/contracts/utils/math/SafeCast.sol";
import { ExecutorOptions } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/ExecutorOptions.sol";
import { DVNOptions } from "./DVNOptions.sol";
library UlnOptions {
using SafeCast for uint256;
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;
error LZ_ULN_InvalidWorkerOptions(uint256 cursor);
error LZ_ULN_InvalidWorkerId(uint8 workerId);
error LZ_ULN_InvalidLegacyType1Option();
error LZ_ULN_InvalidLegacyType2Option();
error LZ_ULN_UnsupportedOptionType(uint16 optionType);
/// @dev decode the options into executorOptions and dvnOptions
/// @param _options the options can be either legacy options (type 1 or 2) or type 3 options
/// @return executorOptions the executor options, share the same format of type 3 options
/// @return dvnOptions the dvn options, share the same format of type 3 options
function decode(
bytes calldata _options
) internal pure returns (bytes memory executorOptions, bytes memory dvnOptions) {
// at least 2 bytes for the option type, but can have no options
if (_options.length < 2) revert LZ_ULN_InvalidWorkerOptions(0);
uint16 optionsType = uint16(bytes2(_options[0:2]));
uint256 cursor = 2;
// type3 options: [worker_option][worker_option]...
// worker_option: [worker_id][option_size][option]
// worker_id: uint8, option_size: uint16, option: bytes
if (optionsType == TYPE_3) {
unchecked {
uint256 start = cursor;
uint8 lastWorkerId; // worker_id starts from 1, so 0 is an invalid worker_id
// heuristic: we assume that the options are mostly EXECUTOR options only
// checking the workerID can reduce gas usage for most cases
while (cursor < _options.length) {
uint8 workerId = uint8(bytes1(_options[cursor:cursor + 1]));
if (workerId == 0) revert LZ_ULN_InvalidWorkerId(0);
// workerId must equal to the lastWorkerId for the first option
// so it is always skipped in the first option
// this operation slices out options whenever the the scan finds a different workerId
if (lastWorkerId == 0) {
lastWorkerId = workerId;
} else if (workerId != lastWorkerId) {
bytes calldata op = _options[start:cursor]; // slice out the last worker's options
(executorOptions, dvnOptions) = _insertWorkerOptions(
executorOptions,
dvnOptions,
lastWorkerId,
op
);
// reset the start cursor and lastWorkerId
start = cursor;
lastWorkerId = workerId;
}
++cursor; // for workerId
uint16 size = uint16(bytes2(_options[cursor:cursor + 2]));
if (size == 0) revert LZ_ULN_InvalidWorkerOptions(cursor);
cursor += size + 2;
}
// the options length must be the same as the cursor at the end
if (cursor != _options.length) revert LZ_ULN_InvalidWorkerOptions(cursor);
// if we have reached the end of the options and the options are not empty
// we need to process the last worker's options
if (_options.length > 2) {
bytes calldata op = _options[start:cursor];
(executorOptions, dvnOptions) = _insertWorkerOptions(executorOptions, dvnOptions, lastWorkerId, op);
}
}
} else {
executorOptions = decodeLegacyOptions(optionsType, _options);
}
}
function _insertWorkerOptions(
bytes memory _executorOptions,
bytes memory _dvnOptions,
uint8 _workerId,
bytes calldata _newOptions
) private pure returns (bytes memory, bytes memory) {
if (_workerId == ExecutorOptions.WORKER_ID) {
_executorOptions = _executorOptions.length == 0
? _newOptions
: abi.encodePacked(_executorOptions, _newOptions);
} else if (_workerId == DVNOptions.WORKER_ID) {
_dvnOptions = _dvnOptions.length == 0 ? _newOptions : abi.encodePacked(_dvnOptions, _newOptions);
} else {
revert LZ_ULN_InvalidWorkerId(_workerId);
}
return (_executorOptions, _dvnOptions);
}
/// @dev decode the legacy options (type 1 or 2) into executorOptions
/// @param _optionType the legacy option type
/// @param _options the legacy options, which still has the option type in the first 2 bytes
/// @return executorOptions the executor options, share the same format of type 3 options
/// Data format:
/// legacy type 1: [extraGas]
/// legacy type 2: [extraGas][dstNativeAmt][dstNativeAddress]
/// extraGas: uint256, dstNativeAmt: uint256, dstNativeAddress: bytes
function decodeLegacyOptions(
uint16 _optionType,
bytes calldata _options
) internal pure returns (bytes memory executorOptions) {
if (_optionType == TYPE_1) {
if (_options.length != 34) revert LZ_ULN_InvalidLegacyType1Option();
// execution gas
uint128 executionGas = uint256(bytes32(_options[2:2 + 32])).toUint128();
// dont use the encode function in the ExecutorOptions lib for saving gas by calling abi.encodePacked once
// the result is a lzReceive option: [executor_id][option_size][option_type][execution_gas]
// option_type: uint8, execution_gas: uint128
// option_size = len(option_type) + len(execution_gas) = 1 + 16 = 17
executorOptions = abi.encodePacked(
ExecutorOptions.WORKER_ID,
uint16(17), // 16 + 1, 16 for option_length, + 1 for option_type
ExecutorOptions.OPTION_TYPE_LZRECEIVE,
executionGas
);
} else if (_optionType == TYPE_2) {
// receiver size <= 32
if (_options.length <= 66 || _options.length > 98) revert LZ_ULN_InvalidLegacyType2Option();
// execution gas
uint128 executionGas = uint256(bytes32(_options[2:2 + 32])).toUint128();
// nativeDrop (amount + receiver)
uint128 amount = uint256(bytes32(_options[34:34 + 32])).toUint128(); // offset 2 + 32
bytes32 receiver;
unchecked {
uint256 receiverLen = _options.length - 66; // offset 2 + 32 + 32
receiver = bytes32(_options[66:]);
receiver = receiver >> (8 * (32 - receiverLen)); // padding 0 to the left
}
// dont use the encode function in the ExecutorOptions lib for saving gas by calling abi.encodePacked once
// the result has one lzReceive option and one nativeDrop option:
// [executor_id][lzReceive_option_size][option_type][execution_gas] +
// [executor_id][nativeDrop_option_size][option_type][nativeDrop_amount][receiver]
// option_type: uint8, execution_gas: uint128, nativeDrop_amount: uint128, receiver: bytes32
// lzReceive_option_size = len(option_type) + len(execution_gas) = 1 + 16 = 17
// nativeDrop_option_size = len(option_type) + len(nativeDrop_amount) + len(receiver) = 1 + 16 + 32 = 49
executorOptions = abi.encodePacked(
ExecutorOptions.WORKER_ID,
uint16(17), // 16 + 1, 16 for option_length, + 1 for option_type
ExecutorOptions.OPTION_TYPE_LZRECEIVE,
executionGas,
ExecutorOptions.WORKER_ID,
uint16(49), // 48 + 1, 32 + 16 for option_length, + 1 for option_type
ExecutorOptions.OPTION_TYPE_NATIVE_DROP,
amount,
receiver
);
} else {
revert LZ_ULN_UnsupportedOptionType(_optionType);
}
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { ERC165, IERC165 } from "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import { ILayerZeroEndpointV2, MessagingFee, Origin } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ILayerZeroEndpointV2.sol";
import { IMessageLib, MessageLibType, SetConfigParam } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/IMessageLib.sol";
import { ISendLib, Packet } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ISendLib.sol";
import { PacketV1Codec } from "@layerzerolabs/lz-evm-protocol-v2/contracts/messagelib/libs/PacketV1Codec.sol";
import { Transfer } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/Transfer.sol";
import { AddressCast } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/AddressCast.sol";
import { ILayerZeroReadExecutor } from "../../interfaces/ILayerZeroReadExecutor.sol";
import { ILayerZeroReadDVN } from "../interfaces/ILayerZeroReadDVN.sol";
import { ILayerZeroTreasury } from "../../interfaces/ILayerZeroTreasury.sol";
import { UlnOptions } from "../libs/UlnOptions.sol";
import { DVNOptions } from "../libs/DVNOptions.sol";
import { SafeCall } from "../../libs/SafeCall.sol";
import { MessageLibBase } from "../../MessageLibBase.sol";
import { ReadLibBase, ReadLibConfig } from "./ReadLibBase.sol";
contract ReadLib1002 is ISendLib, ERC165, ReadLibBase, MessageLibBase {
using PacketV1Codec for bytes;
using SafeCall for address;
uint32 internal constant CONFIG_TYPE_READ_LID_CONFIG = 1;
uint16 internal constant TREASURY_MAX_COPY = 32;
uint256 internal immutable treasuryGasLimit;
mapping(address oapp => mapping(uint32 eid => mapping(uint64 nonce => bytes32 cmdHash))) public cmdHashLookup;
mapping(bytes32 headerHash => mapping(bytes32 cmdHash => mapping(address dvn => bytes32 payloadHash)))
public hashLookup;
// accumulated fees for workers and treasury
mapping(address worker => uint256 fee) public fees;
uint256 internal treasuryNativeFeeCap;
address internal treasury;
event PayloadVerified(address dvn, bytes header, bytes32 cmdHash, bytes32 payloadHash);
event ExecutorFeePaid(address executor, uint256 fee);
event DVNFeePaid(address[] requiredDVNs, address[] optionalDVNs, uint256[] fees);
event NativeFeeWithdrawn(address worker, address receiver, uint256 amount);
event LzTokenFeeWithdrawn(address lzToken, address receiver, uint256 amount);
event TreasurySet(address treasury);
event TreasuryNativeFeeCapSet(uint256 newTreasuryNativeFeeCap);
error LZ_RL_InvalidReceiver();
error LZ_RL_InvalidPacketHeader();
error LZ_RL_InvalidCmdHash();
error LZ_RL_InvalidPacketVersion();
error LZ_RL_InvalidEid();
error LZ_RL_Verifying();
error LZ_RL_InvalidConfigType(uint32 configType);
error LZ_RL_InvalidAmount(uint256 requested, uint256 available);
error LZ_RL_NotTreasury();
error LZ_RL_CannotWithdrawAltToken();
constructor(
address _endpoint,
uint256 _treasuryGasLimit,
uint256 _treasuryGasForFeeCap
) MessageLibBase(_endpoint, ILayerZeroEndpointV2(_endpoint).eid()) {
treasuryGasLimit = _treasuryGasLimit;
treasuryNativeFeeCap = _treasuryGasForFeeCap;
}
function supportsInterface(bytes4 _interfaceId) public view override(ERC165, IERC165) returns (bool) {
return
_interfaceId == type(IMessageLib).interfaceId ||
_interfaceId == type(ISendLib).interfaceId ||
super.supportsInterface(_interfaceId);
}
// ============================ OnlyOwner ===================================
function setTreasury(address _treasury) external onlyOwner {
treasury = _treasury;
emit TreasurySet(_treasury);
}
/// @dev the new value can not be greater than the old value, i.e. down only
function setTreasuryNativeFeeCap(uint256 _newTreasuryNativeFeeCap) external onlyOwner {
// assert the new value is no greater than the old value
if (_newTreasuryNativeFeeCap > treasuryNativeFeeCap)
revert LZ_RL_InvalidAmount(_newTreasuryNativeFeeCap, treasuryNativeFeeCap);
treasuryNativeFeeCap = _newTreasuryNativeFeeCap;
emit TreasuryNativeFeeCapSet(_newTreasuryNativeFeeCap);
}
// ============================ OnlyEndpoint ===================================
function send(
Packet calldata _packet,
bytes calldata _options,
bool _payInLzToken
) external onlyEndpoint returns (MessagingFee memory, bytes memory) {
// the receiver must be the same as the sender
if (AddressCast.toBytes32(_packet.sender) != _packet.receiver) revert LZ_RL_InvalidReceiver();
// pay worker and treasury
(bytes memory encodedPacket, uint256 totalNativeFee) = _payWorkers(_packet, _options);
(uint256 treasuryNativeFee, uint256 lzTokenFee) = _payTreasury(
_packet.sender,
_packet.dstEid,
totalNativeFee,
_payInLzToken
);
totalNativeFee += treasuryNativeFee;
// store the cmdHash for verification in order to prevent reorg attack
cmdHashLookup[_packet.sender][_packet.dstEid][_packet.nonce] = keccak256(_packet.message);
return (MessagingFee(totalNativeFee, lzTokenFee), encodedPacket);
}
function setConfig(address _oapp, SetConfigParam[] calldata _params) external onlyEndpoint {
for (uint256 i = 0; i < _params.length; i++) {
SetConfigParam calldata param = _params[i];
_assertSupportedEid(param.eid);
if (param.configType == CONFIG_TYPE_READ_LID_CONFIG) {
_setReadLibConfig(param.eid, _oapp, abi.decode(param.config, (ReadLibConfig)));
} else {
revert LZ_RL_InvalidConfigType(param.configType);
}
}
}
// ============================ External ===================================
/// @dev The verification will be done in the same chain where the packet is sent.
/// @dev dont need to check endpoint verifiable here to save gas, as it will reverts if not verifiable.
/// @param _packetHeader - the srcEid should be the localEid and the dstEid should be the channel id.
/// The original packet header in PacketSent event should be processed to flip the srcEid and dstEid.
function commitVerification(bytes calldata _packetHeader, bytes32 _cmdHash, bytes32 _payloadHash) external {
// assert packet header is of right size 81
if (_packetHeader.length != 81) revert LZ_RL_InvalidPacketHeader();
// assert packet header version is the same
if (_packetHeader.version() != PacketV1Codec.PACKET_VERSION) revert LZ_RL_InvalidPacketVersion();
// assert the packet is for this endpoint
if (_packetHeader.dstEid() != localEid) revert LZ_RL_InvalidEid();
// cache these values to save gas
address receiver = _packetHeader.receiverB20();
uint32 srcEid = _packetHeader.srcEid(); // channel id
uint64 nonce = _packetHeader.nonce();
// reorg protection. to allow reverification, the cmdHash cant be removed
if (cmdHashLookup[receiver][srcEid][nonce] != _cmdHash) revert LZ_RL_InvalidCmdHash();
ReadLibConfig memory config = getReadLibConfig(receiver, srcEid);
_verifyAndReclaimStorage(config, keccak256(_packetHeader), _cmdHash, _payloadHash);
// endpoint will revert if nonce <= lazyInboundNonce
Origin memory origin = Origin(srcEid, _packetHeader.sender(), nonce);
ILayerZeroEndpointV2(endpoint).verify(origin, receiver, _payloadHash);
}
/// @dev DVN verifies the payload with the packet header and command hash
/// @param _packetHeader - the packet header is needed for event only, which can be conveniently for off-chain to track the packet state.
function verify(bytes calldata _packetHeader, bytes32 _cmdHash, bytes32 _payloadHash) external {
hashLookup[keccak256(_packetHeader)][_cmdHash][msg.sender] = _payloadHash;
emit PayloadVerified(msg.sender, _packetHeader, _cmdHash, _payloadHash);
}
function withdrawFee(address _to, uint256 _amount) external {
uint256 fee = fees[msg.sender];
if (_amount > fee) revert LZ_RL_InvalidAmount(_amount, fee);
unchecked {
fees[msg.sender] = fee - _amount;
}
// transfers native if nativeToken == address(0x0)
address nativeToken = ILayerZeroEndpointV2(endpoint).nativeToken();
Transfer.nativeOrToken(nativeToken, _to, _amount);
emit NativeFeeWithdrawn(msg.sender, _to, _amount);
}
// ============================ Treasury ===================================
/// @dev _lzToken is a user-supplied value because lzToken might change in the endpoint before all lzToken can be taken out
function withdrawLzTokenFee(address _lzToken, address _to, uint256 _amount) external {
if (msg.sender != treasury) revert LZ_RL_NotTreasury();
// lz token cannot be the same as the native token
if (ILayerZeroEndpointV2(endpoint).nativeToken() == _lzToken) revert LZ_RL_CannotWithdrawAltToken();
Transfer.token(_lzToken, _to, _amount);
emit LzTokenFeeWithdrawn(_lzToken, _to, _amount);
}
// ============================ View ===================================
function quote(
Packet calldata _packet,
bytes calldata _options,
bool _payInLzToken
) external view returns (MessagingFee memory) {
// split workers options
(bytes memory executorOptions, bytes memory dvnOptions) = UlnOptions.decode(_options);
address sender = _packet.sender;
uint32 dstEid = _packet.dstEid;
// quote the executor and dvns
ReadLibConfig memory config = getReadLibConfig(sender, dstEid);
uint256 nativeFee = _quoteDVNs(
config,
sender,
PacketV1Codec.encodePacketHeader(_packet),
_packet.message,
dvnOptions
);
nativeFee += ILayerZeroReadExecutor(config.executor).getFee(sender, executorOptions);
// quote treasury
(uint256 treasuryNativeFee, uint256 lzTokenFee) = _quoteTreasury(sender, dstEid, nativeFee, _payInLzToken);
nativeFee += treasuryNativeFee;
return MessagingFee(nativeFee, lzTokenFee);
}
function verifiable(
ReadLibConfig calldata _config,
bytes32 _headerHash,
bytes32 _cmdHash,
bytes32 _payloadHash
) external view returns (bool) {
return _checkVerifiable(_config, _headerHash, _cmdHash, _payloadHash);
}
function getConfig(uint32 _eid, address _oapp, uint32 _configType) external view returns (bytes memory) {
if (_configType == CONFIG_TYPE_READ_LID_CONFIG) {
return abi.encode(getReadLibConfig(_oapp, _eid));
} else {
revert LZ_RL_InvalidConfigType(_configType);
}
}
function getTreasuryAndNativeFeeCap() external view returns (address, uint256) {
return (treasury, treasuryNativeFeeCap);
}
function isSupportedEid(uint32 _eid) external view returns (bool) {
return _isSupportedEid(_eid);
}
function messageLibType() external pure returns (MessageLibType) {
return MessageLibType.SendAndReceive;
}
function version() external pure returns (uint64 major, uint8 minor, uint8 endpointVersion) {
return (10, 0, 2);
}
// ============================ Internal ===================================
/// 1/ handle executor
/// 2/ handle other workers
function _payWorkers(
Packet calldata _packet,
bytes calldata _options
) internal returns (bytes memory encodedPacket, uint256 totalNativeFee) {
// split workers options
(bytes memory executorOptions, bytes memory dvnOptions) = UlnOptions.decode(_options);
// handle executor
ReadLibConfig memory config = getReadLibConfig(_packet.sender, _packet.dstEid);
totalNativeFee = _payExecutor(config.executor, _packet.sender, executorOptions);
// handle dvns
(uint256 dvnFee, bytes memory packetBytes) = _payDVNs(config, _packet, dvnOptions);
totalNativeFee += dvnFee;
encodedPacket = packetBytes;
}
function _payDVNs(
ReadLibConfig memory _config,
Packet calldata _packet,
bytes memory _options
) internal returns (uint256 totalFee, bytes memory encodedPacket) {
bytes memory packetHeader = PacketV1Codec.encodePacketHeader(_packet);
bytes memory payload = PacketV1Codec.encodePayload(_packet);
uint256[] memory dvnFees;
(totalFee, dvnFees) = _assignDVNJobs(_config, _packet.sender, packetHeader, _packet.message, _options);
encodedPacket = abi.encodePacked(packetHeader, payload);
emit DVNFeePaid(_config.requiredDVNs, _config.optionalDVNs, dvnFees);
}
function _assignDVNJobs(
ReadLibConfig memory _config,
address _sender,
bytes memory _packetHeader,
bytes calldata _cmd,
bytes memory _options
) internal returns (uint256 totalFee, uint256[] memory dvnFees) {
(bytes[] memory optionsArray, uint8[] memory dvnIds) = DVNOptions.groupDVNOptionsByIdx(_options);
uint8 dvnsLength = _config.requiredDVNCount + _config.optionalDVNCount;
dvnFees = new uint256[](dvnsLength);
for (uint8 i = 0; i < dvnsLength; ++i) {
address dvn = i < _config.requiredDVNCount
? _config.requiredDVNs[i]
: _config.optionalDVNs[i - _config.requiredDVNCount];
bytes memory options = "";
for (uint256 j = 0; j < dvnIds.length; ++j) {
if (dvnIds[j] == i) {
options = optionsArray[j];
break;
}
}
dvnFees[i] = ILayerZeroReadDVN(dvn).assignJob(_sender, _packetHeader, _cmd, options);
if (dvnFees[i] > 0) {
fees[dvn] += dvnFees[i];
totalFee += dvnFees[i];
}
}
}
function _quoteDVNs(
ReadLibConfig memory _config,
address _sender,
bytes memory _packetHeader,
bytes calldata _cmd,
bytes memory _options
) internal view returns (uint256 totalFee) {
(bytes[] memory optionsArray, uint8[] memory dvnIndices) = DVNOptions.groupDVNOptionsByIdx(_options);
// here we merge 2 list of dvns into 1 to allocate the indexed dvn options to the right dvn
uint8 dvnsLength = _config.requiredDVNCount + _config.optionalDVNCount;
for (uint8 i = 0; i < dvnsLength; ++i) {
address dvn = i < _config.requiredDVNCount
? _config.requiredDVNs[i]
: _config.optionalDVNs[i - _config.requiredDVNCount];
bytes memory options = "";
// it is a double loop here. however, if the list is short, the cost is very acceptable.
for (uint256 j = 0; j < dvnIndices.length; ++j) {
if (dvnIndices[j] == i) {
options = optionsArray[j];
break;
}
}
totalFee += ILayerZeroReadDVN(dvn).getFee(_sender, _packetHeader, _cmd, options);
}
}
function _payTreasury(
address _sender,
uint32 _dstEid,
uint256 _totalNativeFee,
bool _payInLzToken
) internal returns (uint256 treasuryNativeFee, uint256 lzTokenFee) {
if (treasury != address(0x0)) {
bytes memory callData = abi.encodeCall(
ILayerZeroTreasury.payFee,
(_sender, _dstEid, _totalNativeFee, _payInLzToken)
);
(bool success, bytes memory result) = treasury.safeCall(treasuryGasLimit, 0, TREASURY_MAX_COPY, callData);
(treasuryNativeFee, lzTokenFee) = _parseTreasuryResult(_totalNativeFee, _payInLzToken, success, result);
// fee should be in lzTokenFee if payInLzToken, otherwise in native
if (treasuryNativeFee > 0) {
fees[treasury] += treasuryNativeFee;
}
}
}
/// @dev this interface should be DoS-free if the user is paying with native. properties
/// 1/ treasury can return an overly high lzToken fee
/// 2/ if treasury returns an overly high native fee, it will be capped by maxNativeFee,
/// which can be reasoned with the configurations
/// 3/ the owner can not configure the treasury in a way that force this function to revert
function _quoteTreasury(
address _sender,
uint32 _dstEid,
uint256 _totalNativeFee,
bool _payInLzToken
) internal view returns (uint256 nativeFee, uint256 lzTokenFee) {
// treasury must be set, and it has to be a contract
if (treasury != address(0x0)) {
bytes memory callData = abi.encodeCall(
ILayerZeroTreasury.getFee,
(_sender, _dstEid, _totalNativeFee, _payInLzToken)
);
(bool success, bytes memory result) = treasury.safeStaticCall(
treasuryGasLimit,
TREASURY_MAX_COPY,
callData
);
return _parseTreasuryResult(_totalNativeFee, _payInLzToken, success, result);
}
}
function _parseTreasuryResult(
uint256 _totalNativeFee,
bool _payInLzToken,
bool _success,
bytes memory _result
) internal view returns (uint256 nativeFee, uint256 lzTokenFee) {
// failure, charges nothing
if (!_success || _result.length < TREASURY_MAX_COPY) return (0, 0);
// parse the result
uint256 treasureFeeQuote = abi.decode(_result, (uint256));
if (_payInLzToken) {
lzTokenFee = treasureFeeQuote;
} else {
// pay in native
// we must prevent high-treasuryFee Dos attack
// nativeFee = min(treasureFeeQuote, maxNativeFee)
// opportunistically raise the maxNativeFee to be the same as _totalNativeFee
// can't use the _totalNativeFee alone because the oapp can use custom workers to force the fee to 0.
// maxNativeFee = max (_totalNativeFee, treasuryNativeFeeCap)
uint256 maxNativeFee = _totalNativeFee > treasuryNativeFeeCap ? _totalNativeFee : treasuryNativeFeeCap;
// min (treasureFeeQuote, nativeFeeCap)
nativeFee = treasureFeeQuote > maxNativeFee ? maxNativeFee : treasureFeeQuote;
}
}
function _verifyAndReclaimStorage(
ReadLibConfig memory _config,
bytes32 _headerHash,
bytes32 _cmdHash,
bytes32 _payloadHash
) internal {
if (!_checkVerifiable(_config, _headerHash, _cmdHash, _payloadHash)) {
revert LZ_RL_Verifying();
}
// iterate the required DVNs
if (_config.requiredDVNCount > 0) {
for (uint8 i = 0; i < _config.requiredDVNCount; ++i) {
delete hashLookup[_headerHash][_cmdHash][_config.requiredDVNs[i]];
}
}
// iterate the optional DVNs
if (_config.optionalDVNCount > 0) {
for (uint8 i = 0; i < _config.optionalDVNCount; ++i) {
delete hashLookup[_headerHash][_cmdHash][_config.optionalDVNs[i]];
}
}
}
/// @dev for verifiable view function
/// @dev checks if this verification is ready to be committed to the endpoint
function _checkVerifiable(
ReadLibConfig memory _config,
bytes32 _headerHash,
bytes32 _cmdHash,
bytes32 _payloadHash
) internal view returns (bool) {
// iterate the required DVNs
if (_config.requiredDVNCount > 0) {
for (uint8 i = 0; i < _config.requiredDVNCount; ++i) {
if (!_verified(_config.requiredDVNs[i], _headerHash, _cmdHash, _payloadHash)) {
// return if any of the required DVNs haven't signed
return false;
}
}
if (_config.optionalDVNCount == 0) {
// returns early if all required DVNs have signed and there are no optional DVNs
return true;
}
}
// then it must require optional validations
uint8 threshold = _config.optionalDVNThreshold;
for (uint8 i = 0; i < _config.optionalDVNCount; ++i) {
if (_verified(_config.optionalDVNs[i], _headerHash, _cmdHash, _payloadHash)) {
// increment the optional count if the optional DVN has signed
threshold--;
if (threshold == 0) {
// early return if the optional threshold has hit
return true;
}
}
}
// return false as a catch-all
return false;
}
function _verified(
address _dvn,
bytes32 _headerHash,
bytes32 _cmdHash,
bytes32 _expectedPayloadHash
) internal view returns (bool verified) {
verified = hashLookup[_headerHash][_cmdHash][_dvn] == _expectedPayloadHash;
}
function _payExecutor(
address _executor,
address _sender,
bytes memory _executorOptions
) internal returns (uint256 executorFee) {
executorFee = ILayerZeroReadExecutor(_executor).assignJob(_sender, _executorOptions);
if (executorFee > 0) {
fees[_executor] += executorFee;
}
emit ExecutorFeePaid(_executor, executorFee);
}
receive() external payable {}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
struct ReadLibConfig {
address executor;
// we store the length of required DVNs and optional DVNs instead of using DVN.length directly to save gas
uint8 requiredDVNCount; // 0 indicate DEFAULT, NIL_DVN_COUNT indicate NONE (to override the value of default)
uint8 optionalDVNCount; // 0 indicate DEFAULT, NIL_DVN_COUNT indicate NONE (to override the value of default)
uint8 optionalDVNThreshold; // (0, optionalDVNCount]
address[] requiredDVNs; // no duplicates. sorted an an ascending order. allowed overlap with optionalDVNs
address[] optionalDVNs; // no duplicates. sorted an an ascending order. allowed overlap with requiredDVNs
}
struct SetDefaultReadLibConfigParam {
uint32 eid;
ReadLibConfig config;
}
/// @dev includes the utility functions for checking ReadLib states and logics
abstract contract ReadLibBase is Ownable {
address internal constant DEFAULT_CONFIG = address(0);
// reserved values for
uint8 internal constant DEFAULT = 0;
uint8 internal constant NIL_DVN_COUNT = type(uint8).max;
// 127 to prevent total number of DVNs (127 * 2) exceeding uint8.max (255)
// by limiting the total size, it would help constraint the design of DVNOptions
uint8 private constant MAX_COUNT = (type(uint8).max - 1) / 2;
mapping(address oapp => mapping(uint32 eid => ReadLibConfig config)) internal readLibConfigs;
error LZ_RL_Unsorted();
error LZ_RL_InvalidRequiredDVNCount();
error LZ_RL_InvalidOptionalDVNCount();
error LZ_RL_AtLeastOneDVN();
error LZ_RL_InvalidOptionalDVNThreshold();
error LZ_RL_UnsupportedEid(uint32 eid);
error LZ_RL_InvalidExecutor();
event DefaultReadLibConfigsSet(SetDefaultReadLibConfigParam[] params);
event ReadLibConfigSet(address oapp, uint32 eid, ReadLibConfig config);
// ============================ OnlyOwner ===================================
/// @dev about the DEFAULT ReadLib config
/// 1) its values are all LITERAL (e.g. 0 is 0). whereas in the oapp ReadLib config, 0 (default value) points to the default ReadLib config
/// this design enables the oapp to point to DEFAULT config without explicitly setting the config
/// 2) its configuration is more restrictive than the oapp ReadLib config that
/// a) it must not use NIL value, where NIL is used only by oapps to indicate the LITERAL 0
/// b) it must have at least one DVN and executor
function setDefaultReadLibConfigs(SetDefaultReadLibConfigParam[] calldata _params) external onlyOwner {
for (uint256 i = 0; i < _params.length; ++i) {
SetDefaultReadLibConfigParam calldata param = _params[i];
// 2.a must not use NIL
if (param.config.requiredDVNCount == NIL_DVN_COUNT) revert LZ_RL_InvalidRequiredDVNCount();
if (param.config.optionalDVNCount == NIL_DVN_COUNT) revert LZ_RL_InvalidOptionalDVNCount();
// 2.b must have at least one dvn and executor
_assertAtLeastOneDVN(param.config);
if (param.config.executor == address(0x0)) revert LZ_RL_InvalidExecutor();
_setConfig(DEFAULT_CONFIG, param.eid, param.config);
}
emit DefaultReadLibConfigsSet(_params);
}
// ============================ View ===================================
// @dev assuming most oapps use default, we get default as memory and custom as storage to save gas
function getReadLibConfig(address _oapp, uint32 _remoteEid) public view returns (ReadLibConfig memory rtnConfig) {
ReadLibConfig storage defaultConfig = readLibConfigs[DEFAULT_CONFIG][_remoteEid];
ReadLibConfig storage customConfig = readLibConfigs[_oapp][_remoteEid];
address executor = customConfig.executor;
rtnConfig.executor = executor != address(0x0) ? executor : defaultConfig.executor;
if (customConfig.requiredDVNCount == DEFAULT) {
if (defaultConfig.requiredDVNCount > 0) {
// copy only if count > 0. save gas
rtnConfig.requiredDVNs = defaultConfig.requiredDVNs;
rtnConfig.requiredDVNCount = defaultConfig.requiredDVNCount;
} // else, do nothing
} else {
if (customConfig.requiredDVNCount != NIL_DVN_COUNT) {
rtnConfig.requiredDVNs = customConfig.requiredDVNs;
rtnConfig.requiredDVNCount = customConfig.requiredDVNCount;
} // else, do nothing
}
if (customConfig.optionalDVNCount == DEFAULT) {
if (defaultConfig.optionalDVNCount > 0) {
// copy only if count > 0. save gas
rtnConfig.optionalDVNs = defaultConfig.optionalDVNs;
rtnConfig.optionalDVNCount = defaultConfig.optionalDVNCount;
rtnConfig.optionalDVNThreshold = defaultConfig.optionalDVNThreshold;
}
} else {
if (customConfig.optionalDVNCount != NIL_DVN_COUNT) {
rtnConfig.optionalDVNs = customConfig.optionalDVNs;
rtnConfig.optionalDVNCount = customConfig.optionalDVNCount;
rtnConfig.optionalDVNThreshold = customConfig.optionalDVNThreshold;
}
}
// the final value must have at least one dvn
// it is possible that some default config result into 0 dvns
_assertAtLeastOneDVN(rtnConfig);
}
/// @dev Get the readLib config without the default config for the given remoteEid.
function getAppReadLibConfig(address _oapp, uint32 _remoteEid) external view returns (ReadLibConfig memory) {
return readLibConfigs[_oapp][_remoteEid];
}
// ============================ Internal ===================================
function _setReadLibConfig(uint32 _remoteEid, address _oapp, ReadLibConfig memory _param) internal {
_setConfig(_oapp, _remoteEid, _param);
// get ReadLib config again as a catch all to ensure the config is valid
getReadLibConfig(_oapp, _remoteEid);
emit ReadLibConfigSet(_oapp, _remoteEid, _param);
}
/// @dev a supported Eid must have a valid default readLib config, which has at least one dvn
function _isSupportedEid(uint32 _remoteEid) internal view returns (bool) {
ReadLibConfig storage defaultConfig = readLibConfigs[DEFAULT_CONFIG][_remoteEid];
return defaultConfig.requiredDVNCount > 0 || defaultConfig.optionalDVNThreshold > 0;
}
function _assertSupportedEid(uint32 _remoteEid) internal view {
if (!_isSupportedEid(_remoteEid)) revert LZ_RL_UnsupportedEid(_remoteEid);
}
// ============================ Private ===================================
function _assertAtLeastOneDVN(ReadLibConfig memory _config) private pure {
if (_config.requiredDVNCount == 0 && _config.optionalDVNThreshold == 0) revert LZ_RL_AtLeastOneDVN();
}
/// @dev this private function is used in both setDefaultReadLibConfigs and setReadLibConfig
function _setConfig(address _oapp, uint32 _eid, ReadLibConfig memory _param) private {
// @dev required dvns
// if dvnCount == NONE, dvns list must be empty
// if dvnCount == DEFAULT, dvn list must be empty
// otherwise, dvnList.length == dvnCount and assert the list is valid
if (_param.requiredDVNCount == NIL_DVN_COUNT || _param.requiredDVNCount == DEFAULT) {
if (_param.requiredDVNs.length != 0) revert LZ_RL_InvalidRequiredDVNCount();
} else {
if (_param.requiredDVNs.length != _param.requiredDVNCount || _param.requiredDVNCount > MAX_COUNT)
revert LZ_RL_InvalidRequiredDVNCount();
_assertNoDuplicates(_param.requiredDVNs);
}
// @dev optional dvns
// if optionalDVNCount == NONE, optionalDVNs list must be empty and threshold must be 0
// if optionalDVNCount == DEFAULT, optionalDVNs list must be empty and threshold must be 0
// otherwise, optionalDVNs.length == optionalDVNCount, threshold > 0 && threshold <= optionalDVNCount and assert the list is valid
// example use case: an oapp uses the DEFAULT 'required' but
// a) use a custom 1/1 dvn (practically a required dvn), or
// b) use a custom 2/3 dvn
if (_param.optionalDVNCount == NIL_DVN_COUNT || _param.optionalDVNCount == DEFAULT) {
if (_param.optionalDVNs.length != 0) revert LZ_RL_InvalidOptionalDVNCount();
if (_param.optionalDVNThreshold != 0) revert LZ_RL_InvalidOptionalDVNThreshold();
} else {
if (_param.optionalDVNs.length != _param.optionalDVNCount || _param.optionalDVNCount > MAX_COUNT)
revert LZ_RL_InvalidOptionalDVNCount();
if (_param.optionalDVNThreshold == 0 || _param.optionalDVNThreshold > _param.optionalDVNCount)
revert LZ_RL_InvalidOptionalDVNThreshold();
_assertNoDuplicates(_param.optionalDVNs);
}
// don't assert valid count here, as it needs to be validated along side default config
readLibConfigs[_oapp][_eid] = _param;
}
function _assertNoDuplicates(address[] memory _dvns) private pure {
address lastDVN = address(0);
for (uint256 i = 0; i < _dvns.length; i++) {
address dvn = _dvns[i];
if (dvn <= lastDVN) revert LZ_RL_Unsorted(); // to ensure no duplicates
lastDVN = dvn;
}
}
}// SPDX-License-Identifier: LZBL-1.2
pragma solidity ^0.8.20;
import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol";
import { AccessControl } from "@openzeppelin/contracts/access/AccessControl.sol";
import { ISendLib } from "@layerzerolabs/lz-evm-protocol-v2/contracts/interfaces/ISendLib.sol";
import { Transfer } from "@layerzerolabs/lz-evm-protocol-v2/contracts/libs/Transfer.sol";
import { IWorker } from "./interfaces/IWorker.sol";
abstract contract Worker is AccessControl, Pausable, IWorker {
bytes32 internal constant MESSAGE_LIB_ROLE = keccak256("MESSAGE_LIB_ROLE");
bytes32 internal constant ALLOWLIST = keccak256("ALLOWLIST");
bytes32 internal constant DENYLIST = keccak256("DENYLIST");
bytes32 internal constant ADMIN_ROLE = keccak256("ADMIN_ROLE");
address public workerFeeLib;
uint64 public allowlistSize;
uint16 public defaultMultiplierBps;
address public priceFeed;
mapping(uint32 eid => uint8[] optionTypes) internal supportedOptionTypes;
// ========================= Constructor =========================
/// @param _messageLibs array of message lib addresses that are granted the MESSAGE_LIB_ROLE
/// @param _priceFeed price feed address
/// @param _defaultMultiplierBps default multiplier for worker fee
/// @param _roleAdmin address that is granted the DEFAULT_ADMIN_ROLE (can grant and revoke all roles)
/// @param _admins array of admin addresses that are granted the ADMIN_ROLE
constructor(
address[] memory _messageLibs,
address _priceFeed,
uint16 _defaultMultiplierBps,
address _roleAdmin,
address[] memory _admins
) {
defaultMultiplierBps = _defaultMultiplierBps;
priceFeed = _priceFeed;
if (_roleAdmin != address(0x0)) {
_grantRole(DEFAULT_ADMIN_ROLE, _roleAdmin); // _roleAdmin can grant and revoke all roles
}
for (uint256 i = 0; i < _messageLibs.length; ++i) {
_grantRole(MESSAGE_LIB_ROLE, _messageLibs[i]);
}
for (uint256 i = 0; i < _admins.length; ++i) {
_grantRole(ADMIN_ROLE, _admins[i]);
}
}
// ========================= Modifier =========================
modifier onlyAcl(address _sender) {
if (!hasAcl(_sender)) {
revert Worker_NotAllowed();
}
_;
}
/// @dev Access control list using allowlist and denylist
/// @dev 1) if one address is in the denylist -> deny
/// @dev 2) else if address in the allowlist OR allowlist is empty (allows everyone)-> allow
/// @dev 3) else deny
/// @param _sender address to check
function hasAcl(address _sender) public view returns (bool) {
if (hasRole(DENYLIST, _sender)) {
return false;
} else if (allowlistSize == 0 || hasRole(ALLOWLIST, _sender)) {
return true;
} else {
return false;
}
}
// ========================= OnyDefaultAdmin =========================
/// @dev flag to pause execution of workers (if used with whenNotPaused modifier)
/// @param _paused true to pause, false to unpause
function setPaused(bool _paused) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (_paused) {
_pause();
} else {
_unpause();
}
}
// ========================= OnlyAdmin =========================
/// @param _priceFeed price feed address
function setPriceFeed(address _priceFeed) external onlyRole(ADMIN_ROLE) {
priceFeed = _priceFeed;
emit SetPriceFeed(_priceFeed);
}
/// @param _workerFeeLib worker fee lib address
function setWorkerFeeLib(address _workerFeeLib) external onlyRole(ADMIN_ROLE) {
workerFeeLib = _workerFeeLib;
emit SetWorkerLib(_workerFeeLib);
}
/// @param _multiplierBps default multiplier for worker fee
function setDefaultMultiplierBps(uint16 _multiplierBps) external onlyRole(ADMIN_ROLE) {
defaultMultiplierBps = _multiplierBps;
emit SetDefaultMultiplierBps(_multiplierBps);
}
/// @dev supports withdrawing fee from ULN301, ULN302 and more
/// @param _lib message lib address
/// @param _to address to withdraw fee to
/// @param _amount amount to withdraw
function withdrawFee(address _lib, address _to, uint256 _amount) external onlyRole(ADMIN_ROLE) {
if (!hasRole(MESSAGE_LIB_ROLE, _lib)) revert Worker_OnlyMessageLib();
ISendLib(_lib).withdrawFee(_to, _amount);
emit Withdraw(_lib, _to, _amount);
}
/// @dev supports withdrawing token from the contract
/// @param _token token address
/// @param _to address to withdraw token to
/// @param _amount amount to withdraw
function withdrawToken(address _token, address _to, uint256 _amount) external onlyRole(ADMIN_ROLE) {
// transfers native if _token is address(0x0)
Transfer.nativeOrToken(_token, _to, _amount);
}
function setSupportedOptionTypes(uint32 _eid, uint8[] calldata _optionTypes) external onlyRole(ADMIN_ROLE) {
supportedOptionTypes[_eid] = _optionTypes;
}
// ========================= View Functions =========================
function getSupportedOptionTypes(uint32 _eid) external view returns (uint8[] memory) {
return supportedOptionTypes[_eid];
}
// ========================= Internal Functions =========================
/// @dev overrides AccessControl to allow for counting of allowlistSize
/// @param _role role to grant
/// @param _account address to grant role to
function _grantRole(bytes32 _role, address _account) internal override {
if (_role == ALLOWLIST && !hasRole(_role, _account)) {
++allowlistSize;
}
super._grantRole(_role, _account);
}
/// @dev overrides AccessControl to allow for counting of allowlistSize
/// @param _role role to revoke
/// @param _account address to revoke role from
function _revokeRole(bytes32 _role, address _account) internal override {
if (_role == ALLOWLIST && hasRole(_role, _account)) {
--allowlistSize;
}
super._revokeRole(_role, _account);
}
/// @dev overrides AccessControl to disable renouncing of roles
function renounceRole(bytes32 /*role*/, address /*account*/) public pure override {
revert Worker_RoleRenouncingDisabled();
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
abstract contract Proxied {
/// @notice to be used by initialisation / postUpgrade function so that only the proxy's admin can execute them
/// It also allows these functions to be called inside a contructor
/// even if the contract is meant to be used without proxy
modifier proxied() {
address proxyAdminAddress = _proxyAdmin();
// With hardhat-deploy proxies
// the proxyAdminAddress is zero only for the implementation contract
// if the implementation contract want to be used as a standalone/immutable contract
// it simply has to execute the `proxied` function
// This ensure the proxyAdminAddress is never zero post deployment
// And allow you to keep the same code for both proxied contract and immutable contract
if (proxyAdminAddress == address(0)) {
// ensure can not be called twice when used outside of proxy : no admin
// solhint-disable-next-line security/no-inline-assembly
assembly {
sstore(
0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103,
0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
)
}
} else {
require(msg.sender == proxyAdminAddress);
}
_;
}
modifier onlyProxyAdmin() {
require(msg.sender == _proxyAdmin(), "NOT_AUTHORIZED");
_;
}
function _proxyAdmin() internal view returns (address ownerAddress) {
// solhint-disable-next-line security/no-inline-assembly
assembly {
ownerAddress := sload(0xb53127684a568b3173ae13b9f8a6016e243e63b6e8ee1178d6a717850b5d6103)
}
}
}// SPDX-License-Identifier: Unlicense /* * @title Solidity Bytes Arrays Utils * @author Gonçalo Sá <[email protected]> * * @dev Bytes tightly packed arrays utility library for ethereum contracts written in Solidity. * The library lets you concatenate, slice and type cast bytes arrays both in memory and storage. */ pragma solidity >=0.8.0 <0.9.0; library BytesLib { function concat( bytes memory _preBytes, bytes memory _postBytes ) internal pure returns (bytes memory) { bytes memory tempBytes; assembly { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // Store the length of the first bytes array at the beginning of // the memory for tempBytes. let length := mload(_preBytes) mstore(tempBytes, length) // Maintain a memory counter for the current write location in the // temp bytes array by adding the 32 bytes for the array length to // the starting location. let mc := add(tempBytes, 0x20) // Stop copying when the memory counter reaches the length of the // first bytes array. let end := add(mc, length) for { // Initialize a copy counter to the start of the _preBytes data, // 32 bytes into its memory. let cc := add(_preBytes, 0x20) } lt(mc, end) { // Increase both counters by 32 bytes each iteration. mc := add(mc, 0x20) cc := add(cc, 0x20) } { // Write the _preBytes data into the tempBytes memory 32 bytes // at a time. mstore(mc, mload(cc)) } // Add the length of _postBytes to the current length of tempBytes // and store it as the new length in the first 32 bytes of the // tempBytes memory. length := mload(_postBytes) mstore(tempBytes, add(length, mload(tempBytes))) // Move the memory counter back from a multiple of 0x20 to the // actual end of the _preBytes data. mc := end // Stop copying when the memory counter reaches the new combined // length of the arrays. end := add(mc, length) for { let cc := add(_postBytes, 0x20) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } // Update the free-memory pointer by padding our last write location // to 32 bytes: add 31 bytes to the end of tempBytes to move to the // next 32 byte block, then round down to the nearest multiple of // 32. If the sum of the length of the two arrays is zero then add // one before rounding down to leave a blank 32 bytes (the length block with 0). mstore(0x40, and( add(add(end, iszero(add(length, mload(_preBytes)))), 31), not(31) // Round down to the nearest 32 bytes. )) } return tempBytes; } function concatStorage(bytes storage _preBytes, bytes memory _postBytes) internal { assembly { // Read the first 32 bytes of _preBytes storage, which is the length // of the array. (We don't need to use the offset into the slot // because arrays use the entire slot.) let fslot := sload(_preBytes.slot) // Arrays of 31 bytes or less have an even value in their slot, // while longer arrays have an odd value. The actual length is // the slot divided by two for odd values, and the lowest order // byte divided by two for even values. // If the slot is even, bitwise and the slot with 255 and divide by // two to get the length. If the slot is odd, bitwise and the slot // with -1 and divide by two. let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) let newlength := add(slength, mlength) // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage switch add(lt(slength, 32), lt(newlength, 32)) case 2 { // Since the new array still fits in the slot, we just need to // update the contents of the slot. // uint256(bytes_storage) = uint256(bytes_storage) + uint256(bytes_memory) + new_length sstore( _preBytes.slot, // all the modifications to the slot are inside this // next block add( // we can just add to the slot contents because the // bytes we want to change are the LSBs fslot, add( mul( div( // load the bytes from memory mload(add(_postBytes, 0x20)), // zero all bytes to the right exp(0x100, sub(32, mlength)) ), // and now shift left the number of bytes to // leave space for the length in the slot exp(0x100, sub(32, newlength)) ), // increase length by the double of the memory // bytes length mul(mlength, 2) ) ) ) } case 1 { // The stored value fits in the slot, but the combined value // will exceed it. // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes.slot, add(mul(newlength, 2), 1)) // The contents of the _postBytes array start 32 bytes into // the structure. Our first read should obtain the `submod` // bytes that can fit into the unused space in the last word // of the stored array. To get this, we read 32 bytes starting // from `submod`, so the data we read overlaps with the array // contents by `submod` bytes. Masking the lowest-order // `submod` bytes allows us to add that value directly to the // stored value. let submod := sub(32, slength) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore( sc, add( and( fslot, 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00 ), and(mload(mc), mask) ) ) for { mc := add(mc, 0x20) sc := add(sc, 1) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } default { // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) // Start copying to the last used word of the stored array. let sc := add(keccak256(0x0, 0x20), div(slength, 32)) // save new length sstore(_preBytes.slot, add(mul(newlength, 2), 1)) // Copy over the first `submod` bytes of the new data as in // case 1 above. let slengthmod := mod(slength, 32) let mlengthmod := mod(mlength, 32) let submod := sub(32, slengthmod) let mc := add(_postBytes, submod) let end := add(_postBytes, mlength) let mask := sub(exp(0x100, submod), 1) sstore(sc, add(sload(sc), and(mload(mc), mask))) for { sc := add(sc, 1) mc := add(mc, 0x20) } lt(mc, end) { sc := add(sc, 1) mc := add(mc, 0x20) } { sstore(sc, mload(mc)) } mask := exp(0x100, sub(mc, end)) sstore(sc, mul(div(mload(mc), mask), mask)) } } } function slice( bytes memory _bytes, uint256 _start, uint256 _length ) internal pure returns (bytes memory) { require(_length + 31 >= _length, "slice_overflow"); require(_bytes.length >= _start + _length, "slice_outOfBounds"); bytes memory tempBytes; assembly { switch iszero(_length) case 0 { // Get a location of some free memory and store it in tempBytes as // Solidity does for memory variables. tempBytes := mload(0x40) // The first word of the slice result is potentially a partial // word read from the original array. To read it, we calculate // the length of that partial word and start copying that many // bytes into the array. The first word we copy will start with // data we don't care about, but the last `lengthmod` bytes will // land at the beginning of the contents of the new array. When // we're done copying, we overwrite the full first word with // the actual length of the slice. let lengthmod := and(_length, 31) // The multiplication in the next line is necessary // because when slicing multiples of 32 bytes (lengthmod == 0) // the following copy loop was copying the origin's length // and then ending prematurely not copying everything it should. let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod))) let end := add(mc, _length) for { // The multiplication in the next line has the same exact purpose // as the one above. let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start) } lt(mc, end) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { mstore(mc, mload(cc)) } mstore(tempBytes, _length) //update free-memory pointer //allocating the array padded to 32 bytes like the compiler does now mstore(0x40, and(add(mc, 31), not(31))) } //if we want a zero-length slice let's just return a zero-length array default { tempBytes := mload(0x40) //zero out the 32 bytes slice we are about to return //we need to do it because Solidity does not garbage collect mstore(tempBytes, 0) mstore(0x40, add(tempBytes, 0x20)) } } return tempBytes; } function toAddress(bytes memory _bytes, uint256 _start) internal pure returns (address) { require(_bytes.length >= _start + 20, "toAddress_outOfBounds"); address tempAddress; assembly { tempAddress := div(mload(add(add(_bytes, 0x20), _start)), 0x1000000000000000000000000) } return tempAddress; } function toUint8(bytes memory _bytes, uint256 _start) internal pure returns (uint8) { require(_bytes.length >= _start + 1 , "toUint8_outOfBounds"); uint8 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x1), _start)) } return tempUint; } function toUint16(bytes memory _bytes, uint256 _start) internal pure returns (uint16) { require(_bytes.length >= _start + 2, "toUint16_outOfBounds"); uint16 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x2), _start)) } return tempUint; } function toUint32(bytes memory _bytes, uint256 _start) internal pure returns (uint32) { require(_bytes.length >= _start + 4, "toUint32_outOfBounds"); uint32 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x4), _start)) } return tempUint; } function toUint64(bytes memory _bytes, uint256 _start) internal pure returns (uint64) { require(_bytes.length >= _start + 8, "toUint64_outOfBounds"); uint64 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x8), _start)) } return tempUint; } function toUint96(bytes memory _bytes, uint256 _start) internal pure returns (uint96) { require(_bytes.length >= _start + 12, "toUint96_outOfBounds"); uint96 tempUint; assembly { tempUint := mload(add(add(_bytes, 0xc), _start)) } return tempUint; } function toUint128(bytes memory _bytes, uint256 _start) internal pure returns (uint128) { require(_bytes.length >= _start + 16, "toUint128_outOfBounds"); uint128 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x10), _start)) } return tempUint; } function toUint256(bytes memory _bytes, uint256 _start) internal pure returns (uint256) { require(_bytes.length >= _start + 32, "toUint256_outOfBounds"); uint256 tempUint; assembly { tempUint := mload(add(add(_bytes, 0x20), _start)) } return tempUint; } function toBytes32(bytes memory _bytes, uint256 _start) internal pure returns (bytes32) { require(_bytes.length >= _start + 32, "toBytes32_outOfBounds"); bytes32 tempBytes32; assembly { tempBytes32 := mload(add(add(_bytes, 0x20), _start)) } return tempBytes32; } function equal(bytes memory _preBytes, bytes memory _postBytes) internal pure returns (bool) { bool success = true; assembly { let length := mload(_preBytes) // if lengths don't match the arrays are not equal switch eq(length, mload(_postBytes)) case 1 { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 let mc := add(_preBytes, 0x20) let end := add(mc, length) for { let cc := add(_postBytes, 0x20) // the next line is the loop condition: // while(uint256(mc < end) + cb == 2) } eq(add(lt(mc, end), cb), 2) { mc := add(mc, 0x20) cc := add(cc, 0x20) } { // if any of these checks fails then arrays are not equal if iszero(eq(mload(mc), mload(cc))) { // unsuccess: success := 0 cb := 0 } } } default { // unsuccess: success := 0 } } return success; } function equalStorage( bytes storage _preBytes, bytes memory _postBytes ) internal view returns (bool) { bool success = true; assembly { // we know _preBytes_offset is 0 let fslot := sload(_preBytes.slot) // Decode the length of the stored array like in concatStorage(). let slength := div(and(fslot, sub(mul(0x100, iszero(and(fslot, 1))), 1)), 2) let mlength := mload(_postBytes) // if lengths don't match the arrays are not equal switch eq(slength, mlength) case 1 { // slength can contain both the length and contents of the array // if length < 32 bytes so let's prepare for that // v. http://solidity.readthedocs.io/en/latest/miscellaneous.html#layout-of-state-variables-in-storage if iszero(iszero(slength)) { switch lt(slength, 32) case 1 { // blank the last byte which is the length fslot := mul(div(fslot, 0x100), 0x100) if iszero(eq(fslot, mload(add(_postBytes, 0x20)))) { // unsuccess: success := 0 } } default { // cb is a circuit breaker in the for loop since there's // no said feature for inline assembly loops // cb = 1 - don't breaker // cb = 0 - break let cb := 1 // get the keccak hash to get the contents of the array mstore(0x0, _preBytes.slot) let sc := keccak256(0x0, 0x20) let mc := add(_postBytes, 0x20) let end := add(mc, mlength) // the next line is the loop condition: // while(uint256(mc < end) + cb == 2) for {} eq(add(lt(mc, end), cb), 2) { sc := add(sc, 1) mc := add(mc, 0x20) } { if iszero(eq(sload(sc), mload(mc))) { // unsuccess: success := 0 cb := 0 } } } } } default { // unsuccess: success := 0 } } return success; } }
{
"optimizer": {
"enabled": true,
"runs": 20000
},
"evmVersion": "paris",
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"uint32","name":"_localEidV2","type":"uint32"},{"internalType":"uint32","name":"_vid","type":"uint32"},{"internalType":"address[]","name":"_messageLibs","type":"address[]"},{"internalType":"address","name":"_priceFeed","type":"address"},{"internalType":"address[]","name":"_signers","type":"address[]"},{"internalType":"uint64","name":"_quorum","type":"uint64"},{"internalType":"address[]","name":"_admins","type":"address[]"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"bytes32","name":"executableHash","type":"bytes32"}],"name":"DVN_DuplicatedHash","type":"error"},{"inputs":[],"name":"DVN_InstructionExpired","type":"error"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"DVN_InvalidRole","type":"error"},{"inputs":[],"name":"DVN_InvalidSignatures","type":"error"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"DVN_InvalidTarget","type":"error"},{"inputs":[{"internalType":"uint32","name":"vid","type":"uint32"}],"name":"DVN_InvalidVid","type":"error"},{"inputs":[],"name":"DVN_OnlySelf","type":"error"},{"inputs":[],"name":"MultiSig_InvalidSigner","type":"error"},{"inputs":[],"name":"MultiSig_OnlySigner","type":"error"},{"inputs":[],"name":"MultiSig_QuorumIsZero","type":"error"},{"inputs":[{"internalType":"uint64","name":"signersSize","type":"uint64"},{"internalType":"uint64","name":"quorum","type":"uint64"}],"name":"MultiSig_SignersSizeIsLessThanQuorum","type":"error"},{"inputs":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"bool","name":"active","type":"bool"}],"name":"MultiSig_StateAlreadySet","type":"error"},{"inputs":[{"internalType":"address","name":"signer","type":"address"},{"internalType":"bool","name":"active","type":"bool"}],"name":"MultiSig_StateNotSet","type":"error"},{"inputs":[],"name":"MultiSig_UnorderedSigners","type":"error"},{"inputs":[{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_value","type":"uint256"}],"name":"Transfer_NativeFailed","type":"error"},{"inputs":[],"name":"Transfer_ToAddressIsZero","type":"error"},{"inputs":[],"name":"Worker_NotAllowed","type":"error"},{"inputs":[],"name":"Worker_OnlyMessageLib","type":"error"},{"inputs":[],"name":"Worker_RoleRenouncingDisabled","type":"error"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"_index","type":"uint256"},{"indexed":false,"internalType":"bytes","name":"_data","type":"bytes"}],"name":"ExecuteFailed","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint32","name":"vid","type":"uint32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"bytes","name":"signatures","type":"bytes"}],"indexed":false,"internalType":"struct ExecuteParam","name":"param","type":"tuple"},{"indexed":false,"internalType":"bytes32","name":"_hash","type":"bytes32"}],"name":"HashAlreadyUsed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","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":false,"internalType":"uint16","name":"multiplierBps","type":"uint16"}],"name":"SetDefaultMultiplierBps","type":"event"},{"anonymous":false,"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"uint64","name":"gas","type":"uint64"},{"internalType":"uint16","name":"multiplierBps","type":"uint16"},{"internalType":"uint128","name":"floorMarginUSD","type":"uint128"}],"indexed":false,"internalType":"struct IDVN.DstConfigParam[]","name":"params","type":"tuple[]"}],"name":"SetDstConfig","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"priceFeed","type":"address"}],"name":"SetPriceFeed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint32","name":"dstEid","type":"uint32"},{"indexed":false,"internalType":"uint8[]","name":"optionTypes","type":"uint8[]"}],"name":"SetSupportedOptionTypes","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"workerLib","type":"address"}],"name":"SetWorkerLib","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint64","name":"_quorum","type":"uint64"}],"name":"UpdateQuorum","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"_signer","type":"address"},{"indexed":false,"internalType":"bool","name":"_active","type":"bool"}],"name":"UpdateSigner","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"fee","type":"uint256"}],"name":"VerifierFeePaid","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"idx","type":"uint256"}],"name":"VerifySignaturesFailed","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"lib","type":"address"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"Withdraw","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"allowlistSize","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"bytes","name":"packetHeader","type":"bytes"},{"internalType":"bytes32","name":"payloadHash","type":"bytes32"},{"internalType":"uint64","name":"confirmations","type":"uint64"},{"internalType":"address","name":"sender","type":"address"}],"internalType":"struct ILayerZeroDVN.AssignJobParam","name":"_param","type":"tuple"},{"internalType":"bytes","name":"_options","type":"bytes"}],"name":"assignJob","outputs":[{"internalType":"uint256","name":"totalFee","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_dstEid","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint64","name":"_confirmations","type":"uint64"},{"internalType":"address","name":"_sender","type":"address"}],"name":"assignJob","outputs":[{"internalType":"uint256","name":"totalFee","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_sender","type":"address"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"bytes","name":"_cmd","type":"bytes"},{"internalType":"bytes","name":"_options","type":"bytes"}],"name":"assignJob","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"defaultMultiplierBps","outputs":[{"internalType":"uint16","name":"","type":"uint16"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"dstEid","type":"uint32"}],"name":"dstConfig","outputs":[{"internalType":"uint64","name":"gas","type":"uint64"},{"internalType":"uint16","name":"multiplierBps","type":"uint16"},{"internalType":"uint128","name":"floorMarginUSD","type":"uint128"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"vid","type":"uint32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"bytes","name":"signatures","type":"bytes"}],"internalType":"struct ExecuteParam[]","name":"_params","type":"tuple[]"}],"name":"execute","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_dstEid","type":"uint32"},{"internalType":"uint64","name":"_confirmations","type":"uint64"},{"internalType":"address","name":"_sender","type":"address"},{"internalType":"bytes","name":"_options","type":"bytes"}],"name":"getFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"_dstEid","type":"uint16"},{"internalType":"uint16","name":"","type":"uint16"},{"internalType":"uint64","name":"_confirmations","type":"uint64"},{"internalType":"address","name":"_sender","type":"address"}],"name":"getFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_sender","type":"address"},{"internalType":"bytes","name":"","type":"bytes"},{"internalType":"bytes","name":"_cmd","type":"bytes"},{"internalType":"bytes","name":"_options","type":"bytes"}],"name":"getFee","outputs":[{"internalType":"uint256","name":"fee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getSigners","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"}],"name":"getSupportedOptionTypes","outputs":[{"internalType":"uint8[]","name":"","type":"uint8[]"}],"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":"address","name":"_sender","type":"address"}],"name":"hasAcl","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","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":[{"internalType":"uint32","name":"_vid","type":"uint32"},{"internalType":"address","name":"_target","type":"address"},{"internalType":"bytes","name":"_callData","type":"bytes"},{"internalType":"uint256","name":"_expiration","type":"uint256"}],"name":"hashCallData","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"isSigner","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"localEidV2","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"priceFeed","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"quorum","outputs":[{"internalType":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"vid","type":"uint32"},{"internalType":"address","name":"target","type":"address"},{"internalType":"bytes","name":"callData","type":"bytes"},{"internalType":"uint256","name":"expiration","type":"uint256"},{"internalType":"bytes","name":"signatures","type":"bytes"}],"internalType":"struct ExecuteParam","name":"_param","type":"tuple"}],"name":"quorumChangeAdmin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"},{"internalType":"address","name":"","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_role","type":"bytes32"},{"internalType":"address","name":"_account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"_multiplierBps","type":"uint16"}],"name":"setDefaultMultiplierBps","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"uint32","name":"dstEid","type":"uint32"},{"internalType":"uint64","name":"gas","type":"uint64"},{"internalType":"uint16","name":"multiplierBps","type":"uint16"},{"internalType":"uint128","name":"floorMarginUSD","type":"uint128"}],"internalType":"struct IDVN.DstConfigParam[]","name":"_params","type":"tuple[]"}],"name":"setDstConfig","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bool","name":"_paused","type":"bool"}],"name":"setPaused","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_priceFeed","type":"address"}],"name":"setPriceFeed","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint64","name":"_quorum","type":"uint64"}],"name":"setQuorum","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"},{"internalType":"bool","name":"_active","type":"bool"}],"name":"setSigner","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint32","name":"_eid","type":"uint32"},{"internalType":"uint8[]","name":"_optionTypes","type":"uint8[]"}],"name":"setSupportedOptionTypes","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_workerFeeLib","type":"address"}],"name":"setWorkerFeeLib","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"signerSize","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_signer","type":"address"}],"name":"signers","outputs":[{"internalType":"bool","name":"","type":"bool"}],"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":"bytes32","name":"executableHash","type":"bytes32"}],"name":"usedHashes","outputs":[{"internalType":"bool","name":"used","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"_hash","type":"bytes32"},{"internalType":"bytes","name":"_signatures","type":"bytes"}],"name":"verifySignatures","outputs":[{"internalType":"bool","name":"","type":"bool"},{"internalType":"enum MultiSig.Errors","name":"","type":"uint8"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"vid","outputs":[{"internalType":"uint32","name":"","type":"uint32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_lib","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawFee","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_lib","type":"address"},{"internalType":"address payable","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawFeeFromUlnV2","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_token","type":"address"},{"internalType":"address","name":"_to","type":"address"},{"internalType":"uint256","name":"_amount","type":"uint256"}],"name":"withdrawToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"workerFeeLib","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
60c06040523480156200001157600080fd5b50604051620054c9380380620054c983398101604081905262000034916200052c565b6001805460ff61ffff60e81b01191661017760ed1b179055600280546001600160a01b0319166001600160a01b03861617905582828686612ee060008660005b8551811015620000d557620000cc7f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de878381518110620000b857620000b862000610565b60200260200101516200026960201b60201c565b60010162000074565b5060005b815181101562000126576200011d7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775838381518110620000b857620000b862000610565b600101620000d9565b505050505050806001600160401b03166000036200015757604051635f86e17760e01b815260040160405180910390fd5b60005b8251811015620001d15760008382815181106200017b576200017b62000610565b6020026020010151905060006001600160a01b0316816001600160a01b031603620001b957604051632e5fb71360e11b815260040160405180910390fd5b620001c660048262000317565b50506001016200015a565b506000620001e0600462000337565b9050816001600160401b0316816001600160401b031610156200022d576040516378e2c15760e11b81526001600160401b0380831660048301528316602482015260440160405180910390fd5b50600680546001600160401b0319166001600160401b03929092169190911790555050505063ffffffff92831660805250501660a05262000663565b7f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca82148015620002ba57506000828152602081815260408083206001600160a01b038516845290915290205460ff16155b15620003075760018054601590620002e290600160a81b90046001600160401b031662000626565b91906101000a8154816001600160401b0302191690836001600160401b031602179055505b62000313828262000342565b5050565b60006200032e836001600160a01b038416620003e2565b90505b92915050565b600062000331825490565b6000828152602081815260408083206001600160a01b038516845290915290205460ff1662000313576000828152602081815260408083206001600160a01b03851684529091529020805460ff191660011790556200039e3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b60008181526001830160205260408120546200042b5750815460018181018455600084815260208082209093018490558454848252828601909352604090209190915562000331565b50600062000331565b805163ffffffff811681146200044957600080fd5b919050565b634e487b7160e01b600052604160045260246000fd5b80516001600160a01b03811681146200044957600080fd5b600082601f8301126200048e57600080fd5b815160206001600160401b0380831115620004ad57620004ad6200044e565b8260051b604051601f19603f83011681018181108482111715620004d557620004d56200044e565b6040529384526020818701810194908101925087851115620004f657600080fd5b6020870191505b848210156200052157620005118262000464565b83529183019190830190620004fd565b979650505050505050565b600080600080600080600060e0888a0312156200054857600080fd5b620005538862000434565b9650620005636020890162000434565b60408901519096506001600160401b03808211156200058157600080fd5b6200058f8b838c016200047c565b96506200059f60608b0162000464565b955060808a0151915080821115620005b657600080fd5b620005c48b838c016200047c565b945060a08a015191508082168214620005dc57600080fd5b60c08a015191935080821115620005f257600080fd5b50620006018a828b016200047c565b91505092959891949750929550565b634e487b7160e01b600052603260045260246000fd5b60006001600160401b038281166002600160401b031981016200065957634e487b7160e01b600052601160045260246000fd5b6001019392505050565b60805160a051614e24620006a560003960008181610985015281816125ab015261273f0152600081816108c2015281816117d1015261231d0152614e246000f3fe6080604052600436106102e65760003560e01c806394cf795e11610184578063cd88b903116100d6578063e395eb5c1161008a578063f42ed2ed11610064578063f42ed2ed146109e7578063fd62e750146109fa578063fdb9b0f114610a0f57600080fd5b8063e395eb5c14610973578063f010cb23146109a7578063f3b4ebd0146109c757600080fd5b8063d2ae2104116100bb578063d2ae2104146108f9578063d547741f14610933578063dafe0ccc1461095357600080fd5b8063cd88b90314610890578063cf34c768146108b057600080fd5b8063b143044b11610138578063c5e193cd11610112578063c5e193cd14610822578063c7a823e014610842578063c7b2370b1461087057600080fd5b8063b143044b146107b0578063c358de0a146107d0578063c416aa51146107f057600080fd5b80639e944965116101695780639e944965146106c6578063a217fddf1461076b578063aef18bf71461078057600080fd5b806394cf795e1461069157806395d376d7146106b357600080fd5b806331cb61051161023d578063724e78da116101f15780637df73e27116101cb5780637df73e27146106005780638585c9451461062057806391d148541461064057600080fd5b8063724e78da1461056e578063736c0d5b1461058e578063741bef1a146105ae57600080fd5b806352d3b8711161022257806352d3b871146105165780635553fb8e146105365780635c975abb1461055657600080fd5b806331cb6105146104d657806336568abe146104f657600080fd5b80631703a0181161029f5780632de11376116102795780632de11376146104765780632f2ff15d1461049657806330bb3aac146104b657600080fd5b80631703a018146103d1578063248a9ca31461040b57806326e67a371461044957600080fd5b806301ffc9a7116102d057806301ffc9a7146103615780631095b6d71461039157806316c38b3c146103b157600080fd5b8062bf2e80146102eb57806301e336671461033f575b600080fd5b3480156102f757600080fd5b50600154610327907d010000000000000000000000000000000000000000000000000000000000900461ffff1681565b60405161ffff90911681526020015b60405180910390f35b34801561034b57600080fd5b5061035f61035a366004613d67565b610a2f565b005b34801561036d57600080fd5b5061038161037c366004613da8565b610a6a565b6040519015158152602001610336565b34801561039d57600080fd5b5061035f6103ac366004613d67565b610b03565b3480156103bd57600080fd5b5061035f6103cc366004613df8565b610c93565b3480156103dd57600080fd5b506006546103f29067ffffffffffffffff1681565b60405167ffffffffffffffff9091168152602001610336565b34801561041757600080fd5b5061043b610426366004613e15565b60009081526020819052604090206001015490565b604051908152602001610336565b34801561045557600080fd5b50610469610464366004613e42565b610cb8565b6040516103369190613e5d565b34801561048257600080fd5b50610381610491366004613ea4565b610d3f565b3480156104a257600080fd5b5061035f6104b1366004613ec1565b610e24565b3480156104c257600080fd5b5061043b6104d1366004613f4b565b610f78565b3480156104e257600080fd5b5061035f6104f1366004613fc3565b6110e3565b34801561050257600080fd5b5061035f610511366004613ec1565b611126565b34801561052257600080fd5b5061035f610531366004613ff1565b611158565b34801561054257600080fd5b5061043b610551366004614078565b611324565b34801561056257600080fd5b5060015460ff16610381565b34801561057a57600080fd5b5061035f610589366004613ea4565b61148f565b34801561059a57600080fd5b506103816105a9366004613ea4565b611534565b3480156105ba57600080fd5b506002546105db9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610336565b34801561060c57600080fd5b5061038161061b366004613ea4565b61153b565b34801561062c57600080fd5b5061035f61063b3660046140ce565b611548565b34801561064c57600080fd5b5061038161065b366004613ec1565b60009182526020828152604080842073ffffffffffffffffffffffffffffffffffffffff93909316845291905290205460ff1690565b34801561069d57600080fd5b506106a661158d565b60405161033691906140e9565b61043b6106c136600461414f565b61159e565b3480156106d257600080fd5b506107306106e1366004613e42565b60076020526000908152604090205467ffffffffffffffff81169068010000000000000000810461ffff16906a010000000000000000000090046fffffffffffffffffffffffffffffffff1683565b6040805167ffffffffffffffff909416845261ffff90921660208401526fffffffffffffffffffffffffffffffff1690820152606001610336565b34801561077757600080fd5b5061043b600081565b34801561078c57600080fd5b5061038161079b366004613e15565b60086020526000908152604090205460ff1681565b3480156107bc57600080fd5b5061035f6107cb3660046141fd565b61176e565b3480156107dc57600080fd5b5061035f6107eb36600461423f565b611a7e565b3480156107fc57600080fd5b506001546105db90610100900473ffffffffffffffffffffffffffffffffffffffff1681565b34801561082e57600080fd5b5061043b61083d366004614078565b611b2c565b34801561084e57600080fd5b5061086261085d36600461425a565b611cfe565b6040516103369291906142c8565b34801561087c57600080fd5b5061035f61088b366004613ea4565b611ed6565b34801561089c57600080fd5b5061035f6108ab366004614315565b611f7a565b3480156108bc57600080fd5b506108e47f000000000000000000000000000000000000000000000000000000000000000081565b60405163ffffffff9091168152602001610336565b34801561090557600080fd5b506001546103f2907501000000000000000000000000000000000000000000900467ffffffffffffffff1681565b34801561093f57600080fd5b5061035f61094e366004613ec1565b611fcb565b34801561095f57600080fd5b5061035f61096e366004613d67565b6120e0565b34801561097f57600080fd5b506108e47f000000000000000000000000000000000000000000000000000000000000000081565b3480156109b357600080fd5b5061043b6109c236600461435b565b612216565b3480156109d357600080fd5b5061035f6109e23660046143c6565b612252565b61043b6109f53660046143fb565b6124c7565b348015610a0657600080fd5b5061043b612679565b348015610a1b57600080fd5b5061043b610a2a3660046143fb565b612685565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775610a598161280a565b610a64848484612814565b50505050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b000000000000000000000000000000000000000000000000000000001480610afd57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775610b2d8161280a565b73ffffffffffffffffffffffffffffffffffffffff841660009081527f9b50f4667d2d24216ccbf0dce3a90c0f620fa4d895e7b069d80ff6247fd25620602052604090205460ff16610bab576040517f5ee08b9700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517ffd9be52200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301526024820184905285169063fd9be52290604401600060405180830381600087803b158015610c1b57600080fd5b505af1158015610c2f573d6000803e3d6000fd5b50506040805173ffffffffffffffffffffffffffffffffffffffff8089168252871660208201529081018590527f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb925060600190505b60405180910390a150505050565b6000610c9e8161280a565b8115610cb057610cac612844565b5050565b610cac6128c3565b63ffffffff8116600090815260036020908152604091829020805483518184028101840190945280845260609392830182828015610d3357602002820191906000526020600020906000905b825461010083900a900460ff16815260206001928301818104948501949093039092029101808411610d045790505b50505050509050919050565b73ffffffffffffffffffffffffffffffffffffffff811660009081527f93c430521711328044ae92d0f1f1286cf040bc4a382f1642bd89984e86630553602052604081205460ff1615610d9457506000919050565b6001547501000000000000000000000000000000000000000000900467ffffffffffffffff161580610e0a575073ffffffffffffffffffffffffffffffffffffffff821660009081527f4ac82e3087b7dedf7f532cbc6915c722df8c1e31f1388c318a617b52760eaf8b602052604090205460ff165b15610e1757506001919050565b506000919050565b919050565b817f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca811480610e7257507f4270fae16c6d150d00e80b689daca99e8073b1838ff2b6063a37be9d851283e481145b80610e9c57507f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de81145b15610edf57303314610eda576040517ffaba723a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610f69565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217758103610f2f57610eda7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561280a565b6040517f94fdc372000000000000000000000000000000000000000000000000000000008152600481018290526024015b60405180910390fd5b610f73838361291a565b505050565b600083610f8481610d3f565b610fba576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160c08101825260025473ffffffffffffffffffffffffffffffffffffffff908116825263ffffffff8a16602080840182905267ffffffffffffffff808c16858701528a8416606086015260065416608085015260015461ffff7d01000000000000000000000000000000000000000000000000000000000082041660a0860152600092835260079091529084902093517f7bfa20a9000000000000000000000000000000000000000000000000000000008152929361010090910490911691637bfa20a991611096918591908a908a906004016144f1565b602060405180830381865afa1580156110b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110d791906145be565b98975050505050505050565b30331461111c576040517ffaba723a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610cac82826129e0565b6040517fdec9f03100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756111828161280a565b60005b828110156112e557368484838181106111a0576111a06145d7565b905060800201905060405180606001604052808260200160208101906111c691906140ce565b67ffffffffffffffff1681526020016111e5606084016040850161423f565b61ffff1681526020016111fe6080840160608501614626565b6fffffffffffffffffffffffffffffffff169052600760006112236020850185613e42565b63ffffffff1681526020808201929092526040908101600020835181549385015194909201516fffffffffffffffffffffffffffffffff166a0100000000000000000000027fffffffffffff00000000000000000000000000000000ffffffffffffffffffff61ffff90951668010000000000000000027fffffffffffffffffffffffffffffffffffffffffffff0000000000000000000090941667ffffffffffffffff90931692909217929092179290921691909117905550600101611185565b507f7dd21e42791b013d1929e86f0c59085e4fca24251f0f1aa81917b3b1611766e08383604051611317929190614641565b60405180910390a1505050565b60008161133081610d3f565b611366576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160c08101825260025473ffffffffffffffffffffffffffffffffffffffff908116825261ffff808a16602080850182905267ffffffffffffffff808b168688015289851660608701526006541660808601526001547d010000000000000000000000000000000000000000000000000000000000810490931660a08601526000918252600781528582208651918201875291815294517f7bfa20a9000000000000000000000000000000000000000000000000000000008152939461010090920490921692637bfa20a99261144392869260040161474d565b602060405180830381865afa158015611460573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148491906145be565b979650505050505050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756114b98161280a565b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84169081179091556040519081527ff724a45d041687842411f2b977ef22ab8f43c8f1104f4592b42a00f9b34a643d906020015b60405180910390a15050565b6000610afd825b6000610afd600483612bb5565b303314611581576040517ffaba723a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61158a81612be7565b50565b60606115996004612d02565b905090565b60007f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de6115ca8161280a565b6115da60a0860160808701613ea4565b6115e381610d3f565b611619576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160c0810190915260025473ffffffffffffffffffffffffffffffffffffffff168152600090602080820190611654908a018a613e42565b63ffffffff16815260200161166f60808a0160608b016140ce565b67ffffffffffffffff16815260200161168e60a08a0160808b01613ea4565b73ffffffffffffffffffffffffffffffffffffffff908116825260065467ffffffffffffffff1660208084019190915260015461ffff7d010000000000000000000000000000000000000000000000000000000000820416604090940193909352929350610100909104169063df2b057e908390600790600090611714908d018d613e42565b63ffffffff1663ffffffff16815260200190815260200160002089896040518563ffffffff1660e01b815260040161174f94939291906144f1565b6020604051808303816000875af1158015611460573d6000803e3d6000fd5b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756117988161280a565b60005b82811015610a6457368484838181106117b6576117b66145d7565b90506020028101906117c89190614823565b905063ffffffff7f0000000000000000000000000000000000000000000000000000000000000000166117fe6020830183613e42565b63ffffffff161461180f5750611a76565b428160600135116118205750611a76565b60006118596118326020840184613e42565b6118426040850160208601613ea4565b61184f6040860186614861565b8660600135612216565b9050600061186e8261085d6080860186614861565b509050806118b1576040518481527fd6d90193101048cc1b6edcdc2348f5acf7a4a4a97d3e7b668b74cb7602ab3ebc9060200160405180910390a1505050611a76565b60006118d16118c36040860186614861565b6118cc916148c6565b612d0f565b9050801561196a5760008381526008602052604090205460ff1615611932577f9bb9bddbdf537a2104255307230b323d7982f4512ee8e5bd15df62ddca50ab978484604051611921929190614972565b60405180910390a150505050611a76565b600083815260086020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790555b60008061197d6040870160208801613ea4565b73ffffffffffffffffffffffffffffffffffffffff166119a06040880188614861565b6040516119ae929190614a38565b6000604051808303816000865af19150503d80600081146119eb576040519150601f19603f3d011682016040523d82523d6000602084013e6119f0565b606091505b509150915081611a6f578215611a3557600085815260086020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b7fdc8cdd96296241bbefda4a8e18ad2e0985a8da6495b34d409cfc4c886ee3b0cf8782604051611a66929190614a48565b60405180910390a15b5050505050505b60010161179b565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775611aa88161280a565b600180547fff0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d01000000000000000000000000000000000000000000000000000000000061ffff8516908102919091179091556040519081527f7af0ac740036ffb1c97b03697859d729e80a44ae5030543d64971c313565ab4d90602001611528565b60007f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de611b588161280a565b82611b6281610d3f565b611b98576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160c08101825260025473ffffffffffffffffffffffffffffffffffffffff908116825261ffff808b16602080850182905267ffffffffffffffff808c16868801528a851660608701526006541660808601526001547d010000000000000000000000000000000000000000000000000000000000810490931660a08601526000918252600781528582208651918201875291815294517fdf2b057e00000000000000000000000000000000000000000000000000000000815293946101009092049092169263df2b057e92611c7592869260040161474d565b6020604051808303816000875af1158015611c94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cb891906145be565b93507f87e46b0a6199bc734632187269a103c05714ee0adae5b28f30723955724f37ef84604051611ceb91815260200190565b60405180910390a1505050949350505050565b6006546000908190611d1b9067ffffffffffffffff166041614a90565b8314611d2d5750600090506001611ece565b6000611d86866040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b90506000805b60065467ffffffffffffffff16811015611ec2573660008888611db0856041614a90565b90611dbc866001614aa7565b611dc7906041614a90565b92611dd493929190614aba565b91509150600080611e1b8785858080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612df892505050565b90925090506000816004811115611e3457611e34614299565b14611e4d57600060019850985050505050505050611ece565b8573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1611611e9457600060029850985050505050505050611ece565b611e9d8261153b565b611eb557600060039850985050505050505050611ece565b5093505050600101611d8c565b50600160009350935050505b935093915050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775611f008161280a565b600180547fffffffffffffffffffffff0000000000000000000000000000000000000000ff1661010073ffffffffffffffffffffffffffffffffffffffff8516908102919091179091556040519081527f1399be28223800f8669b3ba5f8721d9fc16fc4e8d0bbf98378791c8c5a3015e090602001611528565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775611fa48161280a565b63ffffffff84166000908152600360205260409020611fc4908484613c87565b5050505050565b817f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca81148061201957507f4270fae16c6d150d00e80b689daca99e8073b1838ff2b6063a37be9d851283e481145b8061204357507f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de81145b1561208657303314612081576040517ffaba723a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6120d6565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217758103610f2f576120817fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561280a565b610f738383612e3d565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561210a8161280a565b73ffffffffffffffffffffffffffffffffffffffff841660009081527f9b50f4667d2d24216ccbf0dce3a90c0f620fa4d895e7b069d80ff6247fd25620602052604090205460ff16612188576040517f5ee08b9700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f07b18bde00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152602482018490528516906307b18bde90604401600060405180830381600087803b1580156121f857600080fd5b505af115801561220c573d6000803e3d6000fd5b5050505050505050565b60008585838686604051602001612231959493929190614ae4565b60405160208183030381529060405280519060200120905095945050505050565b4281606001351161228f576040517f0bbaf26300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b306122a06040830160208401613ea4565b73ffffffffffffffffffffffffffffffffffffffff1614612316576122cb6040820160208301613ea4565b6040517f1ce0bfcd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091166004820152602401610f60565b63ffffffff7f00000000000000000000000000000000000000000000000000000000000000001661234a6020830183613e42565b63ffffffff161461239d576123626020820182613e42565b6040517f2697e1c200000000000000000000000000000000000000000000000000000000815263ffffffff9091166004820152602401610f60565b60006123af6118326020840184613e42565b905060006123c48261085d6080860186614861565b509050806123fe576040517f15ecadee00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008281526008602052604090205460ff161561244a576040517f9d6a45a600000000000000000000000000000000000000000000000000000000815260048101839052602401610f60565b6000828152600860205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055610f73907fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775906124b590860186614861565b8101906124c29190613ea4565b61291a565b60007f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de6124f38161280a565b886124fd81610d3f565b612533576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160808101825260025473ffffffffffffffffffffffffffffffffffffffff90811682528c811660208084019190915260065467ffffffffffffffff168385015260015461ffff7d010000000000000000000000000000000000000000000000000000000000820416606085015263ffffffff7f000000000000000000000000000000000000000000000000000000000000000016600090815260079092529084902093517fbbc5a33b00000000000000000000000000000000000000000000000000000000815292936101009091049091169163bbc5a33b91612627918591908d908d908d908d90600401614b56565b6020604051808303816000875af1158015612646573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061266a91906145be565b9b9a5050505050505050505050565b60006115996004612f02565b60008761269181610d3f565b6126c7576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160808101825260025473ffffffffffffffffffffffffffffffffffffffff90811682528b811660208084019190915260065467ffffffffffffffff168385015260015461ffff7d010000000000000000000000000000000000000000000000000000000000820416606085015263ffffffff7f000000000000000000000000000000000000000000000000000000000000000016600090815260079092529084902093517fd358b30000000000000000000000000000000000000000000000000000000000815292936101009091049091169163d358b300916127bb918591908c908c908c908c90600401614b56565b602060405180830381865afa1580156127d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127fc91906145be565b9a9950505050505050505050565b61158a8133612f0c565b73ffffffffffffffffffffffffffffffffffffffff831661283957610f738282612fc4565b610f738383836130ca565b61284c613138565b600180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390a1565b6128cb6131a7565b600180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33612899565b7f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca82148015612977575060008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16155b156129d657600180546015906129af907501000000000000000000000000000000000000000000900467ffffffffffffffff16614c1c565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055505b610cac8282613213565b8015612a995773ffffffffffffffffffffffffffffffffffffffff8216612a33576040517f5cbf6e2600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612a3e600483613303565b612a94576040517f58c8d2a000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff831660048201528115156024820152604401610f60565b612afa565b612aa4600483613325565b612afa576040517f7e1e4ae200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff831660048201528115156024820152604401610f60565b6000612b066004612f02565b60065490915067ffffffffffffffff908116908216811115612b68576040517ff1c582ae00000000000000000000000000000000000000000000000000000000815267ffffffffffffffff808416600483015282166024820152604401610f60565b6040805173ffffffffffffffffffffffffffffffffffffffff8616815284151560208201527f863d338cad74814b108a06288ad5e0e80d56495e0332238b1d2cdcfa0ca8e5ce9101610c85565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260018301602052604081205415155b9392505050565b8067ffffffffffffffff16600003612c2b576040517f5f86e17700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000612c376004612f02565b90508167ffffffffffffffff168167ffffffffffffffff161015612c9b576040517ff1c582ae00000000000000000000000000000000000000000000000000000000815267ffffffffffffffff808316600483015283166024820152604401610f60565b600680547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001667ffffffffffffffff84169081179091556040519081527fb600f3cf7f38a4b49bb0c75f722ef69f7e3e39ef3bb4aa8207fd86e724a2324990602001611528565b60606000612be083613347565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f0223536e0000000000000000000000000000000000000000000000000000000014801590612da557507fffffffff0000000000000000000000000000000000000000000000000000000082167fab750e750000000000000000000000000000000000000000000000000000000014155b8015610afd57507fffffffff0000000000000000000000000000000000000000000000000000000082167f704316e500000000000000000000000000000000000000000000000000000000141592915050565b6000808251604103612e2e5760208301516040840151606085015160001a612e22878285856133a2565b94509450505050612e36565b506000905060025b9250929050565b7f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca82148015612e99575060008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff165b15612ef85760018054601590612ed1907501000000000000000000000000000000000000000000900467ffffffffffffffff16614c43565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055505b610cac8282613491565b6000610afd825490565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610cac57612f4a81613548565b612f55836020613567565b604051602001612f66929190614c85565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f08c379a0000000000000000000000000000000000000000000000000000000008252610f6091600401614d06565b73ffffffffffffffffffffffffffffffffffffffff8216613011576040517f6b7a931000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008273ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d806000811461306b576040519150601f19603f3d011682016040523d82523d6000602084013e613070565b606091505b5050905080610f73576040517f465bc83400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8416600482015260248101839052604401610f60565b73ffffffffffffffffffffffffffffffffffffffff8216613117576040517f6b7a931000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610f7373ffffffffffffffffffffffffffffffffffffffff841683836137aa565b60015460ff16156131a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610f60565b565b60015460ff166131a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610f60565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610cac5760008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff85168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556132a53390565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000612be08373ffffffffffffffffffffffffffffffffffffffff8416613837565b6000612be08373ffffffffffffffffffffffffffffffffffffffff8416613886565b606081600001805480602002602001604051908101604052809291908181526020018280548015610d3357602002820191906000526020600020905b8154815260200190600101908083116133835750505050509050919050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156133d95750600090506003613488565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561342d573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811661348157600060019250925050613488565b9150600090505b94509492505050565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff1615610cac5760008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6060610afd73ffffffffffffffffffffffffffffffffffffffff831660145b60606000613576836002614a90565b613581906002614aa7565b67ffffffffffffffff81111561359957613599614d19565b6040519080825280601f01601f1916602001820160405280156135c3576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106135fa576135fa6145d7565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061365d5761365d6145d7565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000613699846002614a90565b6136a4906001614aa7565b90505b6001811115613741577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106136e5576136e56145d7565b1a60f81b8282815181106136fb576136fb6145d7565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c9361373a81614d48565b90506136a7565b508315612be0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610f60565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610f73908490613979565b600081815260018301602052604081205461387e57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610afd565b506000610afd565b6000818152600183016020526040812054801561396f5760006138aa600183614d7d565b85549091506000906138be90600190614d7d565b90508181146139235760008660000182815481106138de576138de6145d7565b9060005260206000200154905080876000018481548110613901576139016145d7565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061393457613934614d90565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610afd565b6000915050610afd565b60006139db826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16613a889092919063ffffffff16565b90508051600014806139fc5750808060200190518101906139fc9190614dbf565b610f73576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610f60565b6060613a978484600085613a9f565b949350505050565b606082471015613b31576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610f60565b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051613b5a9190614ddc565b60006040518083038185875af1925050503d8060008114613b97576040519150601f19603f3d011682016040523d82523d6000602084013e613b9c565b606091505b50915091506114848783838760608315613c3e578251600003613c375773ffffffffffffffffffffffffffffffffffffffff85163b613c37576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610f60565b5081613a97565b613a978383815115613c535781518083602001fd5b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f609190614d06565b82805482825590600052602060002090601f01602090048101928215613d205791602002820160005b83821115613cf157833560ff1683826101000a81548160ff021916908360ff1602179055509260200192600101602081600001049283019260010302613cb0565b8015613d1e5782816101000a81549060ff0219169055600101602081600001049283019260010302613cf1565b505b50613d2c929150613d30565b5090565b5b80821115613d2c5760008155600101613d31565b73ffffffffffffffffffffffffffffffffffffffff8116811461158a57600080fd5b600080600060608486031215613d7c57600080fd5b8335613d8781613d45565b92506020840135613d9781613d45565b929592945050506040919091013590565b600060208284031215613dba57600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114612be057600080fd5b801515811461158a57600080fd5b600060208284031215613e0a57600080fd5b8135612be081613dea565b600060208284031215613e2757600080fd5b5035919050565b803563ffffffff81168114610e1f57600080fd5b600060208284031215613e5457600080fd5b612be082613e2e565b6020808252825182820181905260009190848201906040850190845b81811015613e9857835160ff1683529284019291840191600101613e79565b50909695505050505050565b600060208284031215613eb657600080fd5b8135612be081613d45565b60008060408385031215613ed457600080fd5b823591506020830135613ee681613d45565b809150509250929050565b803567ffffffffffffffff81168114610e1f57600080fd5b60008083601f840112613f1b57600080fd5b50813567ffffffffffffffff811115613f3357600080fd5b602083019150836020828501011115612e3657600080fd5b600080600080600060808688031215613f6357600080fd5b613f6c86613e2e565b9450613f7a60208701613ef1565b93506040860135613f8a81613d45565b9250606086013567ffffffffffffffff811115613fa657600080fd5b613fb288828901613f09565b969995985093965092949392505050565b60008060408385031215613fd657600080fd5b8235613fe181613d45565b91506020830135613ee681613dea565b6000806020838503121561400457600080fd5b823567ffffffffffffffff8082111561401c57600080fd5b818501915085601f83011261403057600080fd5b81358181111561403f57600080fd5b8660208260071b850101111561405457600080fd5b60209290920196919550909350505050565b803561ffff81168114610e1f57600080fd5b6000806000806080858703121561408e57600080fd5b61409785614066565b93506140a560208601614066565b92506140b360408601613ef1565b915060608501356140c381613d45565b939692955090935050565b6000602082840312156140e057600080fd5b612be082613ef1565b6020808252825182820181905260009190848201906040850190845b81811015613e9857835173ffffffffffffffffffffffffffffffffffffffff1683529284019291840191600101614105565b600060a0828403121561414957600080fd5b50919050565b60008060006040848603121561416457600080fd5b833567ffffffffffffffff8082111561417c57600080fd5b61418887838801614137565b9450602086013591508082111561419e57600080fd5b506141ab86828701613f09565b9497909650939450505050565b60008083601f8401126141ca57600080fd5b50813567ffffffffffffffff8111156141e257600080fd5b6020830191508360208260051b8501011115612e3657600080fd5b6000806020838503121561421057600080fd5b823567ffffffffffffffff81111561422757600080fd5b614233858286016141b8565b90969095509350505050565b60006020828403121561425157600080fd5b612be082614066565b60008060006040848603121561426f57600080fd5b83359250602084013567ffffffffffffffff81111561428d57600080fd5b6141ab86828701613f09565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b82151581526040810160048310614308577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8260208301529392505050565b60008060006040848603121561432a57600080fd5b61433384613e2e565b9250602084013567ffffffffffffffff81111561434f57600080fd5b6141ab868287016141b8565b60008060008060006080868803121561437357600080fd5b61437c86613e2e565b9450602086013561438c81613d45565b9350604086013567ffffffffffffffff8111156143a857600080fd5b6143b488828901613f09565b96999598509660600135949350505050565b6000602082840312156143d857600080fd5b813567ffffffffffffffff8111156143ef57600080fd5b613a9784828501614137565b60008060008060008060006080888a03121561441657600080fd5b873561442181613d45565b9650602088013567ffffffffffffffff8082111561443e57600080fd5b61444a8b838c01613f09565b909850965060408a013591508082111561446357600080fd5b61446f8b838c01613f09565b909650945060608a013591508082111561448857600080fd5b506144958a828b01613f09565b989b979a50959850939692959293505050565b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b6000610140614569838873ffffffffffffffffffffffffffffffffffffffff80825116835263ffffffff6020830151166020840152604082015167ffffffffffffffff808216604086015282606085015116606086015280608085015116608086015250505061ffff60a08201511660a08301525050565b6145aa60c08401875467ffffffffffffffff81168252604081811c61ffff16602084015260509190911c6fffffffffffffffffffffffffffffffff16910152565b8061012084015261148481840185876144a8565b6000602082840312156145d057600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b80356fffffffffffffffffffffffffffffffff81168114610e1f57600080fd5b60006020828403121561463857600080fd5b612be082614606565b6020808252818101839052600090604080840186845b878110156146d25763ffffffff61466d83613e2e565b16835267ffffffffffffffff614684868401613ef1565b168584015261ffff614697858401614066565b168484015260606fffffffffffffffffffffffffffffffff6146ba828501614606565b16908401526080928301929190910190600101614657565b5090979650505050505050565b60005b838110156146fa5781810151838201526020016146e2565b50506000910152565b6000815180845261471b8160208601602086016146df565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60006101406147c5838773ffffffffffffffffffffffffffffffffffffffff80825116835263ffffffff6020830151166020840152604082015167ffffffffffffffff808216604086015282606085015116606086015280608085015116608086015250505061ffff60a08201511660a08301525050565b61480660c08401865467ffffffffffffffff81168252604081811c61ffff16602084015260509190911c6fffffffffffffffffffffffffffffffff16910152565b8061012084015261481981840185614703565b9695505050505050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6183360301811261485757600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261489657600080fd5b83018035915067ffffffffffffffff8211156148b157600080fd5b602001915036819003821315612e3657600080fd5b7fffffffff0000000000000000000000000000000000000000000000000000000081358181169160048510156149065780818660040360031b1b83161692505b505092915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261494357600080fd5b830160208101925035905067ffffffffffffffff81111561496357600080fd5b803603821315612e3657600080fd5b6040815263ffffffff61498484613e2e565b1660408201526000602084013561499a81613d45565b73ffffffffffffffffffffffffffffffffffffffff1660608301526149c2604085018561490e565b60a060808501526149d760e0850182846144a8565b915050606085013560a08401526149f1608086018661490e565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08584030160c0860152614a268382846144a8565b93505050508260208301529392505050565b8183823760009101908152919050565b828152604060208201526000613a976040830184614703565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8082028115828204841417610afd57610afd614a61565b80820180821115610afd57610afd614a61565b60008085851115614aca57600080fd5b83861115614ad757600080fd5b5050820193919092039150565b7fffffffff000000000000000000000000000000000000000000000000000000008660e01b1681527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008560601b1660048201528360188201528183603883013760009101603801908152949350505050565b600061012073ffffffffffffffffffffffffffffffffffffffff808a511684528060208b01511660208501525067ffffffffffffffff60408a015116604084015261ffff60608a0151166060840152614be660808401895467ffffffffffffffff81168252604081811c61ffff16602084015260509190911c6fffffffffffffffffffffffffffffffff16910152565b8060e0840152614bf981840187896144a8565b9050828103610100840152614c0f8185876144a8565b9998505050505050505050565b600067ffffffffffffffff808316818103614c3957614c39614a61565b6001019392505050565b600067ffffffffffffffff821680614c5d57614c5d614a61565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0192915050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614cbd8160178501602088016146df565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614cfa8160288401602088016146df565b01602801949350505050565b602081526000612be06020830184614703565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600081614d5757614d57614a61565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b81810381811115610afd57610afd614a61565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b600060208284031215614dd157600080fd5b8151612be081613dea565b600082516148578184602087016146df56fea2646970667358221220198a6ed2fc72043001b01d1b1945eeab857e3b52b5e2dd6f3d5106e342b43a0e64736f6c63430008160033000000000000000000000000000000000000000000000000000000000000762f00000000000000000000000000000000000000000000000000000000000000ff00000000000000000000000000000000000000000000000000000000000000e00000000000000000000000003c2269811836af69497e5f486a85d7316753cf620000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000300000000000000000000000038de71124f7a447a01d67945a51edce9ff491251000000000000000000000000282b3386571f7f794450d5789911a9804fa346b4000000000000000000000000377530cda84dfb2673bf4d145dcf0c4d7fdcb5b6000000000000000000000000000000000000000000000000000000000000000300000000000000000000000023c022223d543adadda3c1c05553b63f1d15aa420000000000000000000000002f99b4a409af38f926e4cc68e5b932b7efab5a150000000000000000000000009398fbf6dfff6a92d5e41f1a997bf84f0203b92b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b52fa54fc261398058c3ac7b8dd442d7d8b9f0b6000000000000000000000000b8ff877ed78ba520ece21b1de7843a8a57ca47cb
Deployed Bytecode
0x6080604052600436106102e65760003560e01c806394cf795e11610184578063cd88b903116100d6578063e395eb5c1161008a578063f42ed2ed11610064578063f42ed2ed146109e7578063fd62e750146109fa578063fdb9b0f114610a0f57600080fd5b8063e395eb5c14610973578063f010cb23146109a7578063f3b4ebd0146109c757600080fd5b8063d2ae2104116100bb578063d2ae2104146108f9578063d547741f14610933578063dafe0ccc1461095357600080fd5b8063cd88b90314610890578063cf34c768146108b057600080fd5b8063b143044b11610138578063c5e193cd11610112578063c5e193cd14610822578063c7a823e014610842578063c7b2370b1461087057600080fd5b8063b143044b146107b0578063c358de0a146107d0578063c416aa51146107f057600080fd5b80639e944965116101695780639e944965146106c6578063a217fddf1461076b578063aef18bf71461078057600080fd5b806394cf795e1461069157806395d376d7146106b357600080fd5b806331cb61051161023d578063724e78da116101f15780637df73e27116101cb5780637df73e27146106005780638585c9451461062057806391d148541461064057600080fd5b8063724e78da1461056e578063736c0d5b1461058e578063741bef1a146105ae57600080fd5b806352d3b8711161022257806352d3b871146105165780635553fb8e146105365780635c975abb1461055657600080fd5b806331cb6105146104d657806336568abe146104f657600080fd5b80631703a0181161029f5780632de11376116102795780632de11376146104765780632f2ff15d1461049657806330bb3aac146104b657600080fd5b80631703a018146103d1578063248a9ca31461040b57806326e67a371461044957600080fd5b806301ffc9a7116102d057806301ffc9a7146103615780631095b6d71461039157806316c38b3c146103b157600080fd5b8062bf2e80146102eb57806301e336671461033f575b600080fd5b3480156102f757600080fd5b50600154610327907d010000000000000000000000000000000000000000000000000000000000900461ffff1681565b60405161ffff90911681526020015b60405180910390f35b34801561034b57600080fd5b5061035f61035a366004613d67565b610a2f565b005b34801561036d57600080fd5b5061038161037c366004613da8565b610a6a565b6040519015158152602001610336565b34801561039d57600080fd5b5061035f6103ac366004613d67565b610b03565b3480156103bd57600080fd5b5061035f6103cc366004613df8565b610c93565b3480156103dd57600080fd5b506006546103f29067ffffffffffffffff1681565b60405167ffffffffffffffff9091168152602001610336565b34801561041757600080fd5b5061043b610426366004613e15565b60009081526020819052604090206001015490565b604051908152602001610336565b34801561045557600080fd5b50610469610464366004613e42565b610cb8565b6040516103369190613e5d565b34801561048257600080fd5b50610381610491366004613ea4565b610d3f565b3480156104a257600080fd5b5061035f6104b1366004613ec1565b610e24565b3480156104c257600080fd5b5061043b6104d1366004613f4b565b610f78565b3480156104e257600080fd5b5061035f6104f1366004613fc3565b6110e3565b34801561050257600080fd5b5061035f610511366004613ec1565b611126565b34801561052257600080fd5b5061035f610531366004613ff1565b611158565b34801561054257600080fd5b5061043b610551366004614078565b611324565b34801561056257600080fd5b5060015460ff16610381565b34801561057a57600080fd5b5061035f610589366004613ea4565b61148f565b34801561059a57600080fd5b506103816105a9366004613ea4565b611534565b3480156105ba57600080fd5b506002546105db9073ffffffffffffffffffffffffffffffffffffffff1681565b60405173ffffffffffffffffffffffffffffffffffffffff9091168152602001610336565b34801561060c57600080fd5b5061038161061b366004613ea4565b61153b565b34801561062c57600080fd5b5061035f61063b3660046140ce565b611548565b34801561064c57600080fd5b5061038161065b366004613ec1565b60009182526020828152604080842073ffffffffffffffffffffffffffffffffffffffff93909316845291905290205460ff1690565b34801561069d57600080fd5b506106a661158d565b60405161033691906140e9565b61043b6106c136600461414f565b61159e565b3480156106d257600080fd5b506107306106e1366004613e42565b60076020526000908152604090205467ffffffffffffffff81169068010000000000000000810461ffff16906a010000000000000000000090046fffffffffffffffffffffffffffffffff1683565b6040805167ffffffffffffffff909416845261ffff90921660208401526fffffffffffffffffffffffffffffffff1690820152606001610336565b34801561077757600080fd5b5061043b600081565b34801561078c57600080fd5b5061038161079b366004613e15565b60086020526000908152604090205460ff1681565b3480156107bc57600080fd5b5061035f6107cb3660046141fd565b61176e565b3480156107dc57600080fd5b5061035f6107eb36600461423f565b611a7e565b3480156107fc57600080fd5b506001546105db90610100900473ffffffffffffffffffffffffffffffffffffffff1681565b34801561082e57600080fd5b5061043b61083d366004614078565b611b2c565b34801561084e57600080fd5b5061086261085d36600461425a565b611cfe565b6040516103369291906142c8565b34801561087c57600080fd5b5061035f61088b366004613ea4565b611ed6565b34801561089c57600080fd5b5061035f6108ab366004614315565b611f7a565b3480156108bc57600080fd5b506108e47f00000000000000000000000000000000000000000000000000000000000000ff81565b60405163ffffffff9091168152602001610336565b34801561090557600080fd5b506001546103f2907501000000000000000000000000000000000000000000900467ffffffffffffffff1681565b34801561093f57600080fd5b5061035f61094e366004613ec1565b611fcb565b34801561095f57600080fd5b5061035f61096e366004613d67565b6120e0565b34801561097f57600080fd5b506108e47f000000000000000000000000000000000000000000000000000000000000762f81565b3480156109b357600080fd5b5061043b6109c236600461435b565b612216565b3480156109d357600080fd5b5061035f6109e23660046143c6565b612252565b61043b6109f53660046143fb565b6124c7565b348015610a0657600080fd5b5061043b612679565b348015610a1b57600080fd5b5061043b610a2a3660046143fb565b612685565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775610a598161280a565b610a64848484612814565b50505050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f7965db0b000000000000000000000000000000000000000000000000000000001480610afd57507f01ffc9a7000000000000000000000000000000000000000000000000000000007fffffffff000000000000000000000000000000000000000000000000000000008316145b92915050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775610b2d8161280a565b73ffffffffffffffffffffffffffffffffffffffff841660009081527f9b50f4667d2d24216ccbf0dce3a90c0f620fa4d895e7b069d80ff6247fd25620602052604090205460ff16610bab576040517f5ee08b9700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517ffd9be52200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff84811660048301526024820184905285169063fd9be52290604401600060405180830381600087803b158015610c1b57600080fd5b505af1158015610c2f573d6000803e3d6000fd5b50506040805173ffffffffffffffffffffffffffffffffffffffff8089168252871660208201529081018590527f9b1bfa7fa9ee420a16e124f794c35ac9f90472acc99140eb2f6447c714cad8eb925060600190505b60405180910390a150505050565b6000610c9e8161280a565b8115610cb057610cac612844565b5050565b610cac6128c3565b63ffffffff8116600090815260036020908152604091829020805483518184028101840190945280845260609392830182828015610d3357602002820191906000526020600020906000905b825461010083900a900460ff16815260206001928301818104948501949093039092029101808411610d045790505b50505050509050919050565b73ffffffffffffffffffffffffffffffffffffffff811660009081527f93c430521711328044ae92d0f1f1286cf040bc4a382f1642bd89984e86630553602052604081205460ff1615610d9457506000919050565b6001547501000000000000000000000000000000000000000000900467ffffffffffffffff161580610e0a575073ffffffffffffffffffffffffffffffffffffffff821660009081527f4ac82e3087b7dedf7f532cbc6915c722df8c1e31f1388c318a617b52760eaf8b602052604090205460ff165b15610e1757506001919050565b506000919050565b919050565b817f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca811480610e7257507f4270fae16c6d150d00e80b689daca99e8073b1838ff2b6063a37be9d851283e481145b80610e9c57507f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de81145b15610edf57303314610eda576040517ffaba723a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610f69565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217758103610f2f57610eda7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561280a565b6040517f94fdc372000000000000000000000000000000000000000000000000000000008152600481018290526024015b60405180910390fd5b610f73838361291a565b505050565b600083610f8481610d3f565b610fba576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160c08101825260025473ffffffffffffffffffffffffffffffffffffffff908116825263ffffffff8a16602080840182905267ffffffffffffffff808c16858701528a8416606086015260065416608085015260015461ffff7d01000000000000000000000000000000000000000000000000000000000082041660a0860152600092835260079091529084902093517f7bfa20a9000000000000000000000000000000000000000000000000000000008152929361010090910490911691637bfa20a991611096918591908a908a906004016144f1565b602060405180830381865afa1580156110b3573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110d791906145be565b98975050505050505050565b30331461111c576040517ffaba723a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610cac82826129e0565b6040517fdec9f03100000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756111828161280a565b60005b828110156112e557368484838181106111a0576111a06145d7565b905060800201905060405180606001604052808260200160208101906111c691906140ce565b67ffffffffffffffff1681526020016111e5606084016040850161423f565b61ffff1681526020016111fe6080840160608501614626565b6fffffffffffffffffffffffffffffffff169052600760006112236020850185613e42565b63ffffffff1681526020808201929092526040908101600020835181549385015194909201516fffffffffffffffffffffffffffffffff166a0100000000000000000000027fffffffffffff00000000000000000000000000000000ffffffffffffffffffff61ffff90951668010000000000000000027fffffffffffffffffffffffffffffffffffffffffffff0000000000000000000090941667ffffffffffffffff90931692909217929092179290921691909117905550600101611185565b507f7dd21e42791b013d1929e86f0c59085e4fca24251f0f1aa81917b3b1611766e08383604051611317929190614641565b60405180910390a1505050565b60008161133081610d3f565b611366576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160c08101825260025473ffffffffffffffffffffffffffffffffffffffff908116825261ffff808a16602080850182905267ffffffffffffffff808b168688015289851660608701526006541660808601526001547d010000000000000000000000000000000000000000000000000000000000810490931660a08601526000918252600781528582208651918201875291815294517f7bfa20a9000000000000000000000000000000000000000000000000000000008152939461010090920490921692637bfa20a99261144392869260040161474d565b602060405180830381865afa158015611460573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061148491906145be565b979650505050505050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756114b98161280a565b600280547fffffffffffffffffffffffff00000000000000000000000000000000000000001673ffffffffffffffffffffffffffffffffffffffff84169081179091556040519081527ff724a45d041687842411f2b977ef22ab8f43c8f1104f4592b42a00f9b34a643d906020015b60405180910390a15050565b6000610afd825b6000610afd600483612bb5565b303314611581576040517ffaba723a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b61158a81612be7565b50565b60606115996004612d02565b905090565b60007f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de6115ca8161280a565b6115da60a0860160808701613ea4565b6115e381610d3f565b611619576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160c0810190915260025473ffffffffffffffffffffffffffffffffffffffff168152600090602080820190611654908a018a613e42565b63ffffffff16815260200161166f60808a0160608b016140ce565b67ffffffffffffffff16815260200161168e60a08a0160808b01613ea4565b73ffffffffffffffffffffffffffffffffffffffff908116825260065467ffffffffffffffff1660208084019190915260015461ffff7d010000000000000000000000000000000000000000000000000000000000820416604090940193909352929350610100909104169063df2b057e908390600790600090611714908d018d613e42565b63ffffffff1663ffffffff16815260200190815260200160002089896040518563ffffffff1660e01b815260040161174f94939291906144f1565b6020604051808303816000875af1158015611460573d6000803e3d6000fd5b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217756117988161280a565b60005b82811015610a6457368484838181106117b6576117b66145d7565b90506020028101906117c89190614823565b905063ffffffff7f00000000000000000000000000000000000000000000000000000000000000ff166117fe6020830183613e42565b63ffffffff161461180f5750611a76565b428160600135116118205750611a76565b60006118596118326020840184613e42565b6118426040850160208601613ea4565b61184f6040860186614861565b8660600135612216565b9050600061186e8261085d6080860186614861565b509050806118b1576040518481527fd6d90193101048cc1b6edcdc2348f5acf7a4a4a97d3e7b668b74cb7602ab3ebc9060200160405180910390a1505050611a76565b60006118d16118c36040860186614861565b6118cc916148c6565b612d0f565b9050801561196a5760008381526008602052604090205460ff1615611932577f9bb9bddbdf537a2104255307230b323d7982f4512ee8e5bd15df62ddca50ab978484604051611921929190614972565b60405180910390a150505050611a76565b600083815260086020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790555b60008061197d6040870160208801613ea4565b73ffffffffffffffffffffffffffffffffffffffff166119a06040880188614861565b6040516119ae929190614a38565b6000604051808303816000865af19150503d80600081146119eb576040519150601f19603f3d011682016040523d82523d6000602084013e6119f0565b606091505b509150915081611a6f578215611a3557600085815260086020526040902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690555b7fdc8cdd96296241bbefda4a8e18ad2e0985a8da6495b34d409cfc4c886ee3b0cf8782604051611a66929190614a48565b60405180910390a15b5050505050505b60010161179b565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775611aa88161280a565b600180547fff0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffff167d01000000000000000000000000000000000000000000000000000000000061ffff8516908102919091179091556040519081527f7af0ac740036ffb1c97b03697859d729e80a44ae5030543d64971c313565ab4d90602001611528565b60007f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de611b588161280a565b82611b6281610d3f565b611b98576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160c08101825260025473ffffffffffffffffffffffffffffffffffffffff908116825261ffff808b16602080850182905267ffffffffffffffff808c16868801528a851660608701526006541660808601526001547d010000000000000000000000000000000000000000000000000000000000810490931660a08601526000918252600781528582208651918201875291815294517fdf2b057e00000000000000000000000000000000000000000000000000000000815293946101009092049092169263df2b057e92611c7592869260040161474d565b6020604051808303816000875af1158015611c94573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190611cb891906145be565b93507f87e46b0a6199bc734632187269a103c05714ee0adae5b28f30723955724f37ef84604051611ceb91815260200190565b60405180910390a1505050949350505050565b6006546000908190611d1b9067ffffffffffffffff166041614a90565b8314611d2d5750600090506001611ece565b6000611d86866040517f19457468657265756d205369676e6564204d6573736167653a0a3332000000006020820152603c8101829052600090605c01604051602081830303815290604052805190602001209050919050565b90506000805b60065467ffffffffffffffff16811015611ec2573660008888611db0856041614a90565b90611dbc866001614aa7565b611dc7906041614a90565b92611dd493929190614aba565b91509150600080611e1b8785858080601f016020809104026020016040519081016040528093929190818152602001838380828437600092019190915250612df892505050565b90925090506000816004811115611e3457611e34614299565b14611e4d57600060019850985050505050505050611ece565b8573ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff1611611e9457600060029850985050505050505050611ece565b611e9d8261153b565b611eb557600060039850985050505050505050611ece565b5093505050600101611d8c565b50600160009350935050505b935093915050565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775611f008161280a565b600180547fffffffffffffffffffffff0000000000000000000000000000000000000000ff1661010073ffffffffffffffffffffffffffffffffffffffff8516908102919091179091556040519081527f1399be28223800f8669b3ba5f8721d9fc16fc4e8d0bbf98378791c8c5a3015e090602001611528565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775611fa48161280a565b63ffffffff84166000908152600360205260409020611fc4908484613c87565b5050505050565b817f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca81148061201957507f4270fae16c6d150d00e80b689daca99e8073b1838ff2b6063a37be9d851283e481145b8061204357507f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de81145b1561208657303314612081576040517ffaba723a00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6120d6565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c217758103610f2f576120817fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561280a565b610f738383612e3d565b7fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c2177561210a8161280a565b73ffffffffffffffffffffffffffffffffffffffff841660009081527f9b50f4667d2d24216ccbf0dce3a90c0f620fa4d895e7b069d80ff6247fd25620602052604090205460ff16612188576040517f5ee08b9700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040517f07b18bde00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8481166004830152602482018490528516906307b18bde90604401600060405180830381600087803b1580156121f857600080fd5b505af115801561220c573d6000803e3d6000fd5b5050505050505050565b60008585838686604051602001612231959493929190614ae4565b60405160208183030381529060405280519060200120905095945050505050565b4281606001351161228f576040517f0bbaf26300000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b306122a06040830160208401613ea4565b73ffffffffffffffffffffffffffffffffffffffff1614612316576122cb6040820160208301613ea4565b6040517f1ce0bfcd00000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff9091166004820152602401610f60565b63ffffffff7f00000000000000000000000000000000000000000000000000000000000000ff1661234a6020830183613e42565b63ffffffff161461239d576123626020820182613e42565b6040517f2697e1c200000000000000000000000000000000000000000000000000000000815263ffffffff9091166004820152602401610f60565b60006123af6118326020840184613e42565b905060006123c48261085d6080860186614861565b509050806123fe576040517f15ecadee00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008281526008602052604090205460ff161561244a576040517f9d6a45a600000000000000000000000000000000000000000000000000000000815260048101839052602401610f60565b6000828152600860205260409081902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff00166001179055610f73907fa49807205ce4d355092ef5a8a18f56e8913cf4a201fbe287825b095693c21775906124b590860186614861565b8101906124c29190613ea4565b61291a565b60007f724aface199fe5bed93ae8508474576a9adf3dc443b2c451842a2242919f19de6124f38161280a565b886124fd81610d3f565b612533576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160808101825260025473ffffffffffffffffffffffffffffffffffffffff90811682528c811660208084019190915260065467ffffffffffffffff168385015260015461ffff7d010000000000000000000000000000000000000000000000000000000000820416606085015263ffffffff7f000000000000000000000000000000000000000000000000000000000000762f16600090815260079092529084902093517fbbc5a33b00000000000000000000000000000000000000000000000000000000815292936101009091049091169163bbc5a33b91612627918591908d908d908d908d90600401614b56565b6020604051808303816000875af1158015612646573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061266a91906145be565b9b9a5050505050505050505050565b60006115996004612f02565b60008761269181610d3f565b6126c7576040517f4ab5ebcd00000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6040805160808101825260025473ffffffffffffffffffffffffffffffffffffffff90811682528b811660208084019190915260065467ffffffffffffffff168385015260015461ffff7d010000000000000000000000000000000000000000000000000000000000820416606085015263ffffffff7f000000000000000000000000000000000000000000000000000000000000762f16600090815260079092529084902093517fd358b30000000000000000000000000000000000000000000000000000000000815292936101009091049091169163d358b300916127bb918591908c908c908c908c90600401614b56565b602060405180830381865afa1580156127d8573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906127fc91906145be565b9a9950505050505050505050565b61158a8133612f0c565b73ffffffffffffffffffffffffffffffffffffffff831661283957610f738282612fc4565b610f738383836130ca565b61284c613138565b600180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016811790557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a258335b60405173ffffffffffffffffffffffffffffffffffffffff909116815260200160405180910390a1565b6128cb6131a7565b600180547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001690557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa33612899565b7f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca82148015612977575060008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16155b156129d657600180546015906129af907501000000000000000000000000000000000000000000900467ffffffffffffffff16614c1c565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055505b610cac8282613213565b8015612a995773ffffffffffffffffffffffffffffffffffffffff8216612a33576040517f5cbf6e2600000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b612a3e600483613303565b612a94576040517f58c8d2a000000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff831660048201528115156024820152604401610f60565b612afa565b612aa4600483613325565b612afa576040517f7e1e4ae200000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff831660048201528115156024820152604401610f60565b6000612b066004612f02565b60065490915067ffffffffffffffff908116908216811115612b68576040517ff1c582ae00000000000000000000000000000000000000000000000000000000815267ffffffffffffffff808416600483015282166024820152604401610f60565b6040805173ffffffffffffffffffffffffffffffffffffffff8616815284151560208201527f863d338cad74814b108a06288ad5e0e80d56495e0332238b1d2cdcfa0ca8e5ce9101610c85565b73ffffffffffffffffffffffffffffffffffffffff8116600090815260018301602052604081205415155b9392505050565b8067ffffffffffffffff16600003612c2b576040517f5f86e17700000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b6000612c376004612f02565b90508167ffffffffffffffff168167ffffffffffffffff161015612c9b576040517ff1c582ae00000000000000000000000000000000000000000000000000000000815267ffffffffffffffff808316600483015283166024820152604401610f60565b600680547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001667ffffffffffffffff84169081179091556040519081527fb600f3cf7f38a4b49bb0c75f722ef69f7e3e39ef3bb4aa8207fd86e724a2324990602001611528565b60606000612be083613347565b60007fffffffff0000000000000000000000000000000000000000000000000000000082167f0223536e0000000000000000000000000000000000000000000000000000000014801590612da557507fffffffff0000000000000000000000000000000000000000000000000000000082167fab750e750000000000000000000000000000000000000000000000000000000014155b8015610afd57507fffffffff0000000000000000000000000000000000000000000000000000000082167f704316e500000000000000000000000000000000000000000000000000000000141592915050565b6000808251604103612e2e5760208301516040840151606085015160001a612e22878285856133a2565b94509450505050612e36565b506000905060025b9250929050565b7f74845de37cfabd357633214b47fa91ccd19b05b7c5a08ac22c187f811fb62bca82148015612e99575060008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff165b15612ef85760018054601590612ed1907501000000000000000000000000000000000000000000900467ffffffffffffffff16614c43565b91906101000a81548167ffffffffffffffff021916908367ffffffffffffffff1602179055505b610cac8282613491565b6000610afd825490565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610cac57612f4a81613548565b612f55836020613567565b604051602001612f66929190614c85565b604080517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0818403018152908290527f08c379a0000000000000000000000000000000000000000000000000000000008252610f6091600401614d06565b73ffffffffffffffffffffffffffffffffffffffff8216613011576040517f6b7a931000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b60008273ffffffffffffffffffffffffffffffffffffffff168260405160006040518083038185875af1925050503d806000811461306b576040519150601f19603f3d011682016040523d82523d6000602084013e613070565b606091505b5050905080610f73576040517f465bc83400000000000000000000000000000000000000000000000000000000815273ffffffffffffffffffffffffffffffffffffffff8416600482015260248101839052604401610f60565b73ffffffffffffffffffffffffffffffffffffffff8216613117576040517f6b7a931000000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b610f7373ffffffffffffffffffffffffffffffffffffffff841683836137aa565b60015460ff16156131a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606401610f60565b565b60015460ff166131a5576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606401610f60565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff16610cac5760008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff85168452909152902080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff001660011790556132a53390565b73ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff16837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b6000612be08373ffffffffffffffffffffffffffffffffffffffff8416613837565b6000612be08373ffffffffffffffffffffffffffffffffffffffff8416613886565b606081600001805480602002602001604051908101604052809291908181526020018280548015610d3357602002820191906000526020600020905b8154815260200190600101908083116133835750505050509050919050565b6000807f7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a08311156133d95750600090506003613488565b6040805160008082526020820180845289905260ff881692820192909252606081018690526080810185905260019060a0016020604051602081039080840390855afa15801561342d573d6000803e3d6000fd5b50506040517fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0015191505073ffffffffffffffffffffffffffffffffffffffff811661348157600060019250925050613488565b9150600090505b94509492505050565b60008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516845290915290205460ff1615610cac5760008281526020818152604080832073ffffffffffffffffffffffffffffffffffffffff8516808552925280832080547fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0016905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6060610afd73ffffffffffffffffffffffffffffffffffffffff831660145b60606000613576836002614a90565b613581906002614aa7565b67ffffffffffffffff81111561359957613599614d19565b6040519080825280601f01601f1916602001820160405280156135c3576020820181803683370190505b5090507f3000000000000000000000000000000000000000000000000000000000000000816000815181106135fa576135fa6145d7565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053507f78000000000000000000000000000000000000000000000000000000000000008160018151811061365d5761365d6145d7565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a9053506000613699846002614a90565b6136a4906001614aa7565b90505b6001811115613741577f303132333435363738396162636465660000000000000000000000000000000085600f16601081106136e5576136e56145d7565b1a60f81b8282815181106136fb576136fb6145d7565b60200101907effffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916908160001a90535060049490941c9361373a81614d48565b90506136a7565b508315612be0576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152606401610f60565b6040805173ffffffffffffffffffffffffffffffffffffffff8416602482015260448082018490528251808303909101815260649091019091526020810180517bffffffffffffffffffffffffffffffffffffffffffffffffffffffff167fa9059cbb00000000000000000000000000000000000000000000000000000000179052610f73908490613979565b600081815260018301602052604081205461387e57508154600181810184556000848152602080822090930184905584548482528286019093526040902091909155610afd565b506000610afd565b6000818152600183016020526040812054801561396f5760006138aa600183614d7d565b85549091506000906138be90600190614d7d565b90508181146139235760008660000182815481106138de576138de6145d7565b9060005260206000200154905080876000018481548110613901576139016145d7565b6000918252602080832090910192909255918252600188019052604090208390555b855486908061393457613934614d90565b600190038181906000526020600020016000905590558560010160008681526020019081526020016000206000905560019350505050610afd565b6000915050610afd565b60006139db826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c65648152508573ffffffffffffffffffffffffffffffffffffffff16613a889092919063ffffffff16565b90508051600014806139fc5750808060200190518101906139fc9190614dbf565b610f73576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602a60248201527f5361666545524332303a204552433230206f7065726174696f6e20646964206e60448201527f6f742073756363656564000000000000000000000000000000000000000000006064820152608401610f60565b6060613a978484600085613a9f565b949350505050565b606082471015613b31576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152602660248201527f416464726573733a20696e73756666696369656e742062616c616e636520666f60448201527f722063616c6c00000000000000000000000000000000000000000000000000006064820152608401610f60565b6000808673ffffffffffffffffffffffffffffffffffffffff168587604051613b5a9190614ddc565b60006040518083038185875af1925050503d8060008114613b97576040519150601f19603f3d011682016040523d82523d6000602084013e613b9c565b606091505b50915091506114848783838760608315613c3e578251600003613c375773ffffffffffffffffffffffffffffffffffffffff85163b613c37576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606401610f60565b5081613a97565b613a978383815115613c535781518083602001fd5b806040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401610f609190614d06565b82805482825590600052602060002090601f01602090048101928215613d205791602002820160005b83821115613cf157833560ff1683826101000a81548160ff021916908360ff1602179055509260200192600101602081600001049283019260010302613cb0565b8015613d1e5782816101000a81549060ff0219169055600101602081600001049283019260010302613cf1565b505b50613d2c929150613d30565b5090565b5b80821115613d2c5760008155600101613d31565b73ffffffffffffffffffffffffffffffffffffffff8116811461158a57600080fd5b600080600060608486031215613d7c57600080fd5b8335613d8781613d45565b92506020840135613d9781613d45565b929592945050506040919091013590565b600060208284031215613dba57600080fd5b81357fffffffff0000000000000000000000000000000000000000000000000000000081168114612be057600080fd5b801515811461158a57600080fd5b600060208284031215613e0a57600080fd5b8135612be081613dea565b600060208284031215613e2757600080fd5b5035919050565b803563ffffffff81168114610e1f57600080fd5b600060208284031215613e5457600080fd5b612be082613e2e565b6020808252825182820181905260009190848201906040850190845b81811015613e9857835160ff1683529284019291840191600101613e79565b50909695505050505050565b600060208284031215613eb657600080fd5b8135612be081613d45565b60008060408385031215613ed457600080fd5b823591506020830135613ee681613d45565b809150509250929050565b803567ffffffffffffffff81168114610e1f57600080fd5b60008083601f840112613f1b57600080fd5b50813567ffffffffffffffff811115613f3357600080fd5b602083019150836020828501011115612e3657600080fd5b600080600080600060808688031215613f6357600080fd5b613f6c86613e2e565b9450613f7a60208701613ef1565b93506040860135613f8a81613d45565b9250606086013567ffffffffffffffff811115613fa657600080fd5b613fb288828901613f09565b969995985093965092949392505050565b60008060408385031215613fd657600080fd5b8235613fe181613d45565b91506020830135613ee681613dea565b6000806020838503121561400457600080fd5b823567ffffffffffffffff8082111561401c57600080fd5b818501915085601f83011261403057600080fd5b81358181111561403f57600080fd5b8660208260071b850101111561405457600080fd5b60209290920196919550909350505050565b803561ffff81168114610e1f57600080fd5b6000806000806080858703121561408e57600080fd5b61409785614066565b93506140a560208601614066565b92506140b360408601613ef1565b915060608501356140c381613d45565b939692955090935050565b6000602082840312156140e057600080fd5b612be082613ef1565b6020808252825182820181905260009190848201906040850190845b81811015613e9857835173ffffffffffffffffffffffffffffffffffffffff1683529284019291840191600101614105565b600060a0828403121561414957600080fd5b50919050565b60008060006040848603121561416457600080fd5b833567ffffffffffffffff8082111561417c57600080fd5b61418887838801614137565b9450602086013591508082111561419e57600080fd5b506141ab86828701613f09565b9497909650939450505050565b60008083601f8401126141ca57600080fd5b50813567ffffffffffffffff8111156141e257600080fd5b6020830191508360208260051b8501011115612e3657600080fd5b6000806020838503121561421057600080fd5b823567ffffffffffffffff81111561422757600080fd5b614233858286016141b8565b90969095509350505050565b60006020828403121561425157600080fd5b612be082614066565b60008060006040848603121561426f57600080fd5b83359250602084013567ffffffffffffffff81111561428d57600080fd5b6141ab86828701613f09565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b82151581526040810160048310614308577f4e487b7100000000000000000000000000000000000000000000000000000000600052602160045260246000fd5b8260208301529392505050565b60008060006040848603121561432a57600080fd5b61433384613e2e565b9250602084013567ffffffffffffffff81111561434f57600080fd5b6141ab868287016141b8565b60008060008060006080868803121561437357600080fd5b61437c86613e2e565b9450602086013561438c81613d45565b9350604086013567ffffffffffffffff8111156143a857600080fd5b6143b488828901613f09565b96999598509660600135949350505050565b6000602082840312156143d857600080fd5b813567ffffffffffffffff8111156143ef57600080fd5b613a9784828501614137565b60008060008060008060006080888a03121561441657600080fd5b873561442181613d45565b9650602088013567ffffffffffffffff8082111561443e57600080fd5b61444a8b838c01613f09565b909850965060408a013591508082111561446357600080fd5b61446f8b838c01613f09565b909650945060608a013591508082111561448857600080fd5b506144958a828b01613f09565b989b979a50959850939692959293505050565b8183528181602085013750600060208284010152600060207fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f840116840101905092915050565b6000610140614569838873ffffffffffffffffffffffffffffffffffffffff80825116835263ffffffff6020830151166020840152604082015167ffffffffffffffff808216604086015282606085015116606086015280608085015116608086015250505061ffff60a08201511660a08301525050565b6145aa60c08401875467ffffffffffffffff81168252604081811c61ffff16602084015260509190911c6fffffffffffffffffffffffffffffffff16910152565b8061012084015261148481840185876144a8565b6000602082840312156145d057600080fd5b5051919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b80356fffffffffffffffffffffffffffffffff81168114610e1f57600080fd5b60006020828403121561463857600080fd5b612be082614606565b6020808252818101839052600090604080840186845b878110156146d25763ffffffff61466d83613e2e565b16835267ffffffffffffffff614684868401613ef1565b168584015261ffff614697858401614066565b168484015260606fffffffffffffffffffffffffffffffff6146ba828501614606565b16908401526080928301929190910190600101614657565b5090979650505050505050565b60005b838110156146fa5781810151838201526020016146e2565b50506000910152565b6000815180845261471b8160208601602086016146df565b601f017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0169290920160200192915050565b60006101406147c5838773ffffffffffffffffffffffffffffffffffffffff80825116835263ffffffff6020830151166020840152604082015167ffffffffffffffff808216604086015282606085015116606086015280608085015116608086015250505061ffff60a08201511660a08301525050565b61480660c08401865467ffffffffffffffff81168252604081811c61ffff16602084015260509190911c6fffffffffffffffffffffffffffffffff16910152565b8061012084015261481981840185614703565b9695505050505050565b600082357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6183360301811261485757600080fd5b9190910192915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261489657600080fd5b83018035915067ffffffffffffffff8211156148b157600080fd5b602001915036819003821315612e3657600080fd5b7fffffffff0000000000000000000000000000000000000000000000000000000081358181169160048510156149065780818660040360031b1b83161692505b505092915050565b60008083357fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe184360301811261494357600080fd5b830160208101925035905067ffffffffffffffff81111561496357600080fd5b803603821315612e3657600080fd5b6040815263ffffffff61498484613e2e565b1660408201526000602084013561499a81613d45565b73ffffffffffffffffffffffffffffffffffffffff1660608301526149c2604085018561490e565b60a060808501526149d760e0850182846144a8565b915050606085013560a08401526149f1608086018661490e565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc08584030160c0860152614a268382846144a8565b93505050508260208301529392505050565b8183823760009101908152919050565b828152604060208201526000613a976040830184614703565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b8082028115828204841417610afd57610afd614a61565b80820180821115610afd57610afd614a61565b60008085851115614aca57600080fd5b83861115614ad757600080fd5b5050820193919092039150565b7fffffffff000000000000000000000000000000000000000000000000000000008660e01b1681527fffffffffffffffffffffffffffffffffffffffff0000000000000000000000008560601b1660048201528360188201528183603883013760009101603801908152949350505050565b600061012073ffffffffffffffffffffffffffffffffffffffff808a511684528060208b01511660208501525067ffffffffffffffff60408a015116604084015261ffff60608a0151166060840152614be660808401895467ffffffffffffffff81168252604081811c61ffff16602084015260509190911c6fffffffffffffffffffffffffffffffff16910152565b8060e0840152614bf981840187896144a8565b9050828103610100840152614c0f8185876144a8565b9998505050505050505050565b600067ffffffffffffffff808316818103614c3957614c39614a61565b6001019392505050565b600067ffffffffffffffff821680614c5d57614c5d614a61565b7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0192915050565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351614cbd8160178501602088016146df565b7f206973206d697373696e6720726f6c65200000000000000000000000000000006017918401918201528351614cfa8160288401602088016146df565b01602801949350505050565b602081526000612be06020830184614703565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600081614d5757614d57614a61565b507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff0190565b81810381811115610afd57610afd614a61565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052603160045260246000fd5b600060208284031215614dd157600080fd5b8151612be081613dea565b600082516148578184602087016146df56fea2646970667358221220198a6ed2fc72043001b01d1b1945eeab857e3b52b5e2dd6f3d5106e342b43a0e64736f6c63430008160033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000000000000000000000000000000000000000762f00000000000000000000000000000000000000000000000000000000000000ff00000000000000000000000000000000000000000000000000000000000000e00000000000000000000000003c2269811836af69497e5f486a85d7316753cf620000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000000300000000000000000000000038de71124f7a447a01d67945a51edce9ff491251000000000000000000000000282b3386571f7f794450d5789911a9804fa346b4000000000000000000000000377530cda84dfb2673bf4d145dcf0c4d7fdcb5b6000000000000000000000000000000000000000000000000000000000000000300000000000000000000000023c022223d543adadda3c1c05553b63f1d15aa420000000000000000000000002f99b4a409af38f926e4cc68e5b932b7efab5a150000000000000000000000009398fbf6dfff6a92d5e41f1a997bf84f0203b92b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000b52fa54fc261398058c3ac7b8dd442d7d8b9f0b6000000000000000000000000b8ff877ed78ba520ece21b1de7843a8a57ca47cb
-----Decoded View---------------
Arg [0] : _localEidV2 (uint32): 30255
Arg [1] : _vid (uint32): 255
Arg [2] : _messageLibs (address[]): 0x38dE71124f7a447a01D67945a51eDcE9FF491251,0x282b3386571f7f794450d5789911a9804FA346b4,0x377530cdA84DFb2673bF4d145DCF0C4D7fdcB5b6
Arg [3] : _priceFeed (address): 0x3c2269811836af69497E5F486A85D7316753cf62
Arg [4] : _signers (address[]): 0x23c022223d543ADAdDA3c1c05553b63f1D15aA42,0x2f99B4A409AF38F926e4CC68e5b932B7EFaB5A15,0x9398Fbf6dFfF6A92D5e41F1A997BF84F0203B92B
Arg [5] : _quorum (uint64): 2
Arg [6] : _admins (address[]): 0xB52Fa54FC261398058c3Ac7B8dD442D7d8B9F0B6,0xB8FF877ed78Ba520Ece21B1de7843A8a57cA47Cb
-----Encoded View---------------
18 Constructor Arguments found :
Arg [0] : 000000000000000000000000000000000000000000000000000000000000762f
Arg [1] : 00000000000000000000000000000000000000000000000000000000000000ff
Arg [2] : 00000000000000000000000000000000000000000000000000000000000000e0
Arg [3] : 0000000000000000000000003c2269811836af69497e5f486a85d7316753cf62
Arg [4] : 0000000000000000000000000000000000000000000000000000000000000160
Arg [5] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [6] : 00000000000000000000000000000000000000000000000000000000000001e0
Arg [7] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [8] : 00000000000000000000000038de71124f7a447a01d67945a51edce9ff491251
Arg [9] : 000000000000000000000000282b3386571f7f794450d5789911a9804fa346b4
Arg [10] : 000000000000000000000000377530cda84dfb2673bf4d145dcf0c4d7fdcb5b6
Arg [11] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [12] : 00000000000000000000000023c022223d543adadda3c1c05553b63f1d15aa42
Arg [13] : 0000000000000000000000002f99b4a409af38f926e4cc68e5b932b7efab5a15
Arg [14] : 0000000000000000000000009398fbf6dfff6a92d5e41f1a997bf84f0203b92b
Arg [15] : 0000000000000000000000000000000000000000000000000000000000000002
Arg [16] : 000000000000000000000000b52fa54fc261398058c3ac7b8dd442d7d8b9f0b6
Arg [17] : 000000000000000000000000b8ff877ed78ba520ece21b1de7843a8a57ca47cb
Deployed Bytecode Sourcemap
635:14531:63:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;874:34:57;;;;;;;;;;-1:-1:-1;874:34:57;;;;;;;;;;;;;;188:6:95;176:19;;;158:38;;146:2;131:18;874:34:57;;;;;;;;4773:214;;;;;;;;;;-1:-1:-1;4773:214:57;;;;;:::i;:::-;;:::i;:::-;;2732:202:39;;;;;;;;;;-1:-1:-1;2732:202:39;;;;;:::i;:::-;;:::i;:::-;;;1329:14:95;;1322:22;1304:41;;1292:2;1277:18;2732:202:39;1164:187:95;4310:273:57;;;;;;;;;;-1:-1:-1;4310:273:57;;;;;:::i;:::-;;:::i;3177:174::-;;;;;;;;;;-1:-1:-1;3177:174:57;;;;;:::i;:::-;;:::i;490:20:66:-;;;;;;;;;;-1:-1:-1;490:20:66;;;;;;;;;;;1899:18:95;1887:31;;;1869:50;;1857:2;1842:18;490:20:66;1725:200:95;4504:129:39;;;;;;;;;;-1:-1:-1;4504:129:39;;;;;:::i;:::-;4578:7;4604:12;;;;;;;;;;:22;;;;4504:129;;;;2261:25:95;;;2249:2;2234:18;4504:129:39;2115:177:95;5238:135:57;;;;;;;;;;-1:-1:-1;5238:135:57;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;2669:285::-;;;;;;;;;;-1:-1:-1;2669:285:57;;;;;:::i;:::-;;:::i;4351:135:63:-;;;;;;;;;;-1:-1:-1;4351:135:63;;;;;:::i;:::-;;:::i;11780:504::-;;;;;;;;;;-1:-1:-1;11780:504:63;;;;;:::i;:::-;;:::i;3759:113::-;;;;;;;;;;-1:-1:-1;3759:113:63;;;;;:::i;:::-;;:::i;6309:137:57:-;;;;;;;;;;-1:-1:-1;6309:137:57;;;;;:::i;:::-;;:::i;6046:354:63:-;;;;;;;;;;-1:-1:-1;6046:354:63;;;;;:::i;:::-;;:::i;12577:509::-;;;;;;;;;;-1:-1:-1;12577:509:63;;;;;:::i;:::-;;:::i;1615:84:42:-;;;;;;;;;;-1:-1:-1;1685:7:42;;;;1615:84;;3472:150:57;;;;;;;;;;-1:-1:-1;3472:150:57;;;;;:::i;:::-;;:::i;4455:102:66:-;;;;;;;;;;-1:-1:-1;4455:102:66;;;;;:::i;:::-;;:::i;914:24:57:-;;;;;;;;;;-1:-1:-1;914:24:57;;;;;;;;;;;7125:42:95;7113:55;;;7095:74;;7083:2;7068:18;914:24:57;6949:226:95;4563:113:66;;;;;;;;;;-1:-1:-1;4563:113:66;;;;;:::i;:::-;;:::i;3982:89:63:-;;;;;;;;;;-1:-1:-1;3982:89:63;;;;;:::i;:::-;;:::i;3021:145:39:-;;;;;;;;;;-1:-1:-1;3021:145:39;;;;;:::i;:::-;3107:4;3130:12;;;;;;;;;;;:29;;;;;;;;;;;;;;;;3021:145;4299:103:66;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;9179:549:63:-;;;;;;:::i;:::-;;:::i;906:52::-;;;;;;;;;;-1:-1:-1;906:52:63;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;9135:18:95;9123:31;;;9105:50;;9203:6;9191:19;;;9186:2;9171:18;;9164:47;9259:34;9247:47;9227:18;;;9220:75;9093:2;9078:18;906:52:63;8907:394:95;2153:49:39;;;;;;;;;;-1:-1:-1;2153:49:39;2198:4;2153:49;;964:62:63;;;;;;;;;;-1:-1:-1;964:62:63;;;;;:::i;:::-;;;;;;;;;;;;;;;;6698:1636;;;;;;;;;;-1:-1:-1;6698:1636:63;;;;;:::i;:::-;;:::i;3915:194:57:-;;;;;;;;;;-1:-1:-1;3915:194:57;;;;;:::i;:::-;;:::i;807:27::-;;;;;;;;;;-1:-1:-1;807:27:57;;;;;;;;;;;10063:635:63;;;;;;;;;;-1:-1:-1;10063:635:63;;;;;:::i;:::-;;:::i;2829:1163:66:-;;;;;;;;;;-1:-1:-1;2829:1163:66;;;;;:::i;:::-;;:::i;:::-;;;;;;;;:::i;3680:165:57:-;;;;;;;;;;-1:-1:-1;3680:165:57;;;;;:::i;:::-;;:::i;4993:::-;;;;;;;;;;-1:-1:-1;4993:165:57;;;;;:::i;:::-;;:::i;797:27:63:-;;;;;;;;;;;;;;;;;;12245:10:95;12233:23;;;12215:42;;12203:2;12188:18;797:27:63;12071:192:95;841:27:57;;;;;;;;;;-1:-1:-1;841:27:57;;;;;;;;;;;4689:137:63;;;;;;;;;;-1:-1:-1;4689:137:63;;;;;:::i;:::-;;:::i;8575:292::-;;;;;;;;;;-1:-1:-1;8575:292:63;;;;;:::i;:::-;;:::i;830:34::-;;;;;;;;;;;;;;;13937:257;;;;;;;;;;-1:-1:-1;13937:257:63;;;;;:::i;:::-;;:::i;5060:863::-;;;;;;;;;;-1:-1:-1;5060:863:63;;;;;:::i;:::-;;:::i;10892:539::-;;;;;;:::i;:::-;;:::i;4682:94:66:-;;;;;;;;;;;;;:::i;13280:500:63:-;;;;;;;;;;-1:-1:-1;13280:500:63;;;;;:::i;:::-;;:::i;4773:214:57:-;777:23;2631:16:39;2642:4;2631:10;:16::i;:::-;4936:44:57::1;4959:6;4967:3;4972:7;4936:22;:44::i;:::-;4773:214:::0;;;;:::o;2732:202:39:-;2817:4;2840:47;;;2855:32;2840:47;;:87;;-1:-1:-1;952:25:50;937:40;;;;2891:36:39;2833:94;2732:202;-1:-1:-1;;2732:202:39:o;4310:273:57:-;777:23;2631:16:39;2642:4;2631:10;:16::i;:::-;3130:29;;;3107:4;3130:29;;;:12;;:29;:12;:29;;;;;4415:68:57::1;;4460:23;;;;;;;;;;;;;;4415:68;4493:40;::::0;;;;:26:::1;15138:55:95::0;;;4493:40:57::1;::::0;::::1;15120:74:95::0;15210:18;;;15203:34;;;4493:26:57;::::1;::::0;::::1;::::0;15093:18:95;;4493:40:57::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;-1:-1:-1::0;;4548:28:57::1;::::0;;15460:42:95;15529:15;;;15511:34;;15581:15;;15576:2;15561:18;;15554:43;15613:18;;;15606:34;;;4548:28:57::1;::::0;-1:-1:-1;15438:2:95;15423:18;;-1:-1:-1;4548:28:57::1;;;;;;;;4310:273:::0;;;;:::o;3177:174::-;2198:4:39;2631:16;2198:4;2631:10;:16::i;:::-;3262:7:57::1;3258:87;;;3285:8;:6;:8::i;:::-;3177:174:::0;;:::o;3258:87::-:1;3324:10;:8;:10::i;5238:135::-:0;5340:26;;;;;;;:20;:26;;;;;;;;;5333:33;;;;;;;;;;;;;;;;;5307:14;;5333:33;;;5340:26;5333:33;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5238:135;;;:::o;2669:285::-;3130:29:39;;;2723:4:57;3130:29:39;;;:12;;:29;:12;:29;;;;;2739:209:57;;;-1:-1:-1;2792:5:57;;2669:285;-1:-1:-1;2669:285:57:o;2739:209::-;2818:13;;;;;;;:18;;:49;;-1:-1:-1;3130:29:39;;;3107:4;3130:29;;;:12;;:29;:12;:29;;;;;2840:27:57;2814:134;;;-1:-1:-1;2890:4:57;;2669:285;-1:-1:-1;2669:285:57:o;2814:134::-;-1:-1:-1;2932:5:57;;2669:285;-1:-1:-1;2669:285:57:o;2814:134::-;2669:285;;;:::o;4351:135:63:-;4435:5;646:22:57;2992:5:63;:18;:39;;;;711:21:57;3014:5:63;:17;2992:39;:68;;;;573:29:57;3035:5:63;:25;2992:68;2988:382;;;3117:4;3126:10;3109:27;3105:87;;3163:14;;;;;;;;;;;;;;3105:87;2988:382;;;777:23:57;3212:5:63;:19;3208:162;;3277:22;777:23:57;3277:10:63;:22::i;3208:162::-;3337:22;;;;;;;;2261:25:95;;;2234:18;;3337:22:63;;;;;;;;3208:162;4452:27:::1;4463:5;4470:8;4452:10;:27::i;:::-;4351:135:::0;;;:::o;11780:504::-;11955:11;11937:7;2295:15:57;2302:7;2295:6;:15::i;:::-;2290:73;;2333:19;;;;;;;;;;;;;;2290:73;12015:177:63::1;::::0;;::::1;::::0;::::1;::::0;;12049:9:::1;::::0;::::1;::::0;;::::1;12015:177:::0;;::::1;::::0;::::1;;::::0;;::::1;::::0;;;::::1;::::0;;::::1;::::0;;;;;;::::1;::::0;;;;12142:6:::1;::::0;::::1;12015:177:::0;;;;12049:9;12162:20;::::1;::::0;;::::1;;12015:177:::0;;;;11978:34:::1;12248:18:::0;;;:9:::1;:18:::0;;;;;;;12208:69;;;;;12015:177;;12049:9:::1;12219:12:::0;;::::1;::::0;;::::1;::::0;12208:31:::1;::::0;:69:::1;::::0;12015:177;;12248:18;12268:8;;;;12208:69:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;12202:75:::0;11780:504;-1:-1:-1;;;;;;;;11780:504:63:o;3759:113::-;3435:4;3444:10;3427:27;3423:79;;3477:14;;;;;;;;;;;;;;3423:79;3837:28:::1;3848:7;3857;3837:10;:28::i;6309:137:57:-:0;6408:31;;;;;;;;;;;;;;6046:354:63;777:23:57;2631:16:39;2642:4;2631:10;:16::i;:::-;6148:9:63::1;6143:215;6163:18:::0;;::::1;6143:215;;;6202:29;6234:7;;6242:1;6234:10;;;;;;;:::i;:::-;;;;;;6202:42;;6284:63;;;;;;;;6294:5;:9;;;;;;;;;;:::i;:::-;6284:63;;::::0;;::::1;;6305:19;::::0;;;::::1;::::0;::::1;;:::i;:::-;6284:63;;::::0;;::::1;;6326:20;::::0;;;::::1;::::0;::::1;;:::i;:::-;6284:63;;::::0;;6258:9:::1;:23;6268:12;;::::0;::::1;:5:::0;:12:::1;:::i;:::-;6258:23;;::::0;;::::1;::::0;;::::1;::::0;;;;;;;;-1:-1:-1;6258:23:63;:89;;;;;;::::1;::::0;;;;::::1;::::0;::::1;;::::0;::::1;::::0;::::1;::::0;;::::1;::::0;::::1;::::0;;;;::::1;::::0;;::::1;::::0;;;;;;;::::1;::::0;;;::::1;::::0;;;::::1;::::0;;-1:-1:-1;6258:89:63;6183:3:::1;6143:215;;;;6372:21;6385:7;;6372:21;;;;;;;:::i;:::-;;;;;;;;6046:354:::0;;;:::o;12577:509::-;12756:11;12738:7;2295:15:57;2302:7;2295:6;:15::i;:::-;2290:73;;2333:19;;;;;;;;;;;;;;2290:73;12816:177:63::1;::::0;;::::1;::::0;::::1;::::0;;12850:9:::1;::::0;::::1;::::0;;::::1;12816:177:::0;;::::1;::::0;;::::1;;::::0;;::::1;::::0;;;::::1;::::0;;::::1;::::0;;;;;;::::1;::::0;;;;12943:6:::1;::::0;::::1;12816:177:::0;;;;12850:9;12963:20;;;::::1;::::0;;::::1;12816:177:::0;;;;12779:34:::1;13049:18:::0;;;:9:::1;:18:::0;;;;;13069:9;;;;::::1;::::0;;;;;13009:70;;;;;12816:177;;12850:9:::1;13020:12:::0;;::::1;::::0;;::::1;::::0;13009:31:::1;::::0;:70:::1;::::0;12816:177;;13009:70:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;13003:76:::0;12577:509;-1:-1:-1;;;;;;;12577:509:63:o;3472:150:57:-;777:23;2631:16:39;2642:4;2631:10;:16::i;:::-;3554:9:57::1;:22:::0;;;::::1;;::::0;::::1;::::0;;::::1;::::0;;;3591:24:::1;::::0;7095:74:95;;;3591:24:57::1;::::0;7083:2:95;7068:18;3591:24:57::1;;;;;;;;3472:150:::0;;:::o;4455:102:66:-;4510:4;4533:17;4542:7;4563:113;4619:4;4642:27;:9;4661:7;4642:18;:27::i;3982:89:63:-;3435:4;3444:10;3427:27;3423:79;;3477:14;;;;;;;;;;;;;;3423:79;4045:19:::1;4056:7;4045:10;:19::i;:::-;3982:89:::0;:::o;4299:103:66:-;4342:16;4377:18;:9;:16;:18::i;:::-;4370:25;;4299:103;:::o;9179:549:63:-;9353:16;573:29:57;2631:16:39;2642:4;2631:10;:16::i;:::-;9329:13:63::1;::::0;;;::::1;::::0;::::1;;:::i;:::-;2295:15:57;2302:7;2295:6;:15::i;:::-;2290:73;;2333:19;;;;;;;;;;;;;;2290:73;9421:195:63::2;::::0;;::::2;::::0;::::2;::::0;;;9455:9:::2;::::0;::::2;;9421:195:::0;;9381:37:::2;::::0;9421:195:::2;::::0;;::::2;::::0;9478:13:::2;::::0;;::::2;:6:::0;:13:::2;:::i;:::-;9421:195;;::::0;;::::2;;9505:20;::::0;;;::::2;::::0;::::2;;:::i;:::-;9421:195;;::::0;;::::2;;9539:13;::::0;;;::::2;::::0;::::2;;:::i;:::-;9421:195;::::0;;::::2;::::0;;9566:6:::2;::::0;::::2;;9421:195;::::0;;::::2;::::0;;;;9566:6;9586:20;::::2;::::0;;::::2;;9421:195:::0;;;;;;;;9381:235;;-1:-1:-1;9566:6:63::2;9648:12:::0;;::::2;;::::0;9637:37:::2;::::0;9381:235;;9686:9:::2;::::0;9566:6:::2;::::0;9696:13:::2;::::0;;::::2;:6:::0;:13:::2;:::i;:::-;9686:24;;;;;;;;;;;;;;;9712:8;;9637:84;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;::::0;::::2;;;;6698:1636:::0;777:23:57;2631:16:39;2642:4;2631:10;:16::i;:::-;6793:9:63::1;6788:1540;6808:18:::0;;::::1;6788:1540;;;6847:27;6877:7;;6885:1;6877:10;;;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;6847:40:::0;-1:-1:-1;6943:16:63::1;6956:3;6943:16;:9;;::::0;::::1;6847:40:::0;6943:9:::1;:::i;:::-;:16;;;6939:63;;6979:8;;;6939:63;7074:15;7054:5;:16;;;:35;7050:82;;7109:8;;;7050:82;7188:12;7203:71;7216:9;;::::0;::::1;:5:::0;:9:::1;:::i;:::-;7227:12;::::0;;;::::1;::::0;::::1;;:::i;:::-;7241:14;;::::0;::::1;:5:::0;:14:::1;:::i;:::-;7257:5;:16;;;7203:12;:71::i;:::-;7188:86:::0;-1:-1:-1;7325:14:63::1;7345:40;7188:86:::0;7368:16:::1;;::::0;::::1;:5:::0;:16:::1;:::i;7345:40::-;7324:61;;;7404:9;7399:105;;7438:25;::::0;2261::95;;;7438::63::1;::::0;2249:2:95;2234:18;7438:25:63::1;;;;;;;7481:8;;;;;7399:105;7554:20;7577:40;7601:14;;::::0;::::1;:5:::0;:14:::1;:::i;:::-;7594:22;::::0;::::1;:::i;:::-;7577:16;:40::i;:::-;7554:63;;7635:15;7631:286;;;7674:16;::::0;;;:10:::1;:16;::::0;;;;;::::1;;7670:233;;;7719:28;7735:5;7742:4;7719:28;;;;;;;:::i;:::-;;;;;;;;7769:8;;;;;;7670:233;7824:16;::::0;;;:10:::1;:16;::::0;;;;:23;;;::::1;7843:4;7824:23;::::0;;7670:233:::1;7932:12;::::0;7970::::1;::::0;;;::::1;::::0;::::1;;:::i;:::-;:17;;7988:14;;::::0;::::1;:5:::0;:14:::1;:::i;:::-;7970:33;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;7931:72;;;;8022:7;8017:301;;8053:15;8049:162;;;8187:5;8168:16:::0;;;:10:::1;:16;::::0;;;;:24;;;::::1;::::0;;8049:162:::1;8278:25;8292:1;8295:7;8278:25;;;;;;;:::i;:::-;;;;;;;;8017:301;6833:1495;;;;;;6788:1540;6828:3;;6788:1540;;3915:194:57::0;777:23;2631:16:39;2642:4;2631:10;:16::i;:::-;4011:20:57::1;:37:::0;;;::::1;::::0;::::1;::::0;::::1;::::0;;::::1;::::0;;;::::1;::::0;;;4063:39:::1;::::0;158:38:95;;;4063:39:57::1;::::0;146:2:95;131:18;4063:39:57::1;14:188:95::0;10063:635:63;10269:16;573:29:57;2631:16:39;2642:4;2631:10;:16::i;:::-;10251:7:63::1;2295:15:57;2302:7;2295:6;:15::i;:::-;2290:73;;2333:19;;;;;;;;;;;;;;2290:73;10334:177:63::2;::::0;;::::2;::::0;::::2;::::0;;10368:9:::2;::::0;::::2;::::0;;::::2;10334:177:::0;;::::2;::::0;;::::2;;::::0;;::::2;::::0;;;::::2;::::0;;::::2;::::0;;;;;;::::2;::::0;;;;10461:6:::2;::::0;::::2;10334:177:::0;;;;10368:9;10481:20;;;::::2;::::0;;::::2;10334:177:::0;;;;10297:34:::2;10621:18:::0;;;:9:::2;:18:::0;;;;;10641:9;;;;::::2;::::0;;;;;10575:76;;;;;10334:177;;10368:9:::2;10586:12:::0;;::::2;::::0;;::::2;::::0;10575:37:::2;::::0;:76:::2;::::0;10334:177;;10575:76:::2;;;:::i;:::-;;;;;;;;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;10564:87;;10666:25;10682:8;10666:25;;;;2261::95::0;;2249:2;2234:18;;2115:177;10666:25:63::2;;;;;;;;10287:411;2657:1:39::1;10063:635:63::0;;;;;;;:::o;2829:1163:66:-;2977:6;;2919:4;;;;2969:20;;2977:6;;2987:2;2969:20;:::i;:::-;2947:42;;2943:110;;-1:-1:-1;3013:5:66;;-1:-1:-1;3020:21:66;3005:37;;2943:110;3063:21;3087:31;3112:5;4113:66;;28259::95;4113::66;;;28247:79:95;28342:12;;;28335:28;;;4077:7:66;;28379:12:95;;4113:66:66;;;;;;;;;;;;4103:77;;;;;;4096:84;;3998:189;;;;3087:31;3063:55;;3129:18;3219:9;3214:733;3238:6;;;;3234:10;;3214:733;;;3350:24;;3377:11;;3389:6;:1;3393:2;3389:6;:::i;:::-;3377:32;3397:5;:1;3401;3397:5;:::i;:::-;3396:12;;3406:2;3396:12;:::i;:::-;3377:32;;;;;;;:::i;:::-;3350:59;;;;3424:21;3447:24;3475:42;3492:13;3507:9;;3475:42;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3475:16:66;;-1:-1:-1;;;3475:42:66:i;:::-;3423:94;;-1:-1:-1;3423:94:66;-1:-1:-1;3545:26:66;3536:5;:35;;;;;;;;:::i;:::-;;3532:78;;3581:5;3588:21;3573:37;;;;;;;;;;;;;3532:78;3645:10;3628:27;;:13;:27;;;3624:72;;3665:5;3672:23;3657:39;;;;;;;;;;;;;3624:72;3795:23;3804:13;3795:8;:23::i;:::-;3790:73;;3828:5;3835:27;3820:43;;;;;;;;;;;;;3790:73;-1:-1:-1;3923:13:66;-1:-1:-1;;;3246:3:66;;3214:733;;;;3964:4;3970:14;3956:29;;;;;;2829:1163;;;;;;;:::o;3680:165:57:-;777:23;2631:16:39;2642:4;2631:10;:16::i;:::-;3768:12:57::1;:28:::0;;;::::1;;;::::0;::::1;::::0;;::::1;::::0;;;::::1;::::0;;;3811:27:::1;::::0;7095:74:95;;;3811:27:57::1;::::0;7083:2:95;7068:18;3811:27:57::1;6949:226:95::0;4993:165:57;777:23;2631:16:39;2642:4;2631:10;:16::i;:::-;5110:26:57::1;::::0;::::1;;::::0;;;:20:::1;:26;::::0;;;;:41:::1;::::0;5139:12;;5110:41:::1;:::i;:::-;;4993:165:::0;;;;:::o;4689:137:63:-;4774:5;646:22:57;2992:5:63;:18;:39;;;;711:21:57;3014:5:63;:17;2992:39;:68;;;;573:29:57;3035:5:63;:25;2992:68;2988:382;;;3117:4;3126:10;3109:27;3105:87;;3163:14;;;;;;;;;;;;;;3105:87;2988:382;;;777:23:57;3212:5:63;:19;3208:162;;3277:22;777:23:57;3277:10:63;:22::i;3208:162::-;4791:28:::1;4803:5;4810:8;4791:11;:28::i;8575:292::-:0;777:23:57;2631:16:39;2642:4;2631:10;:16::i;:::-;3130:29;;;3107:4;3130:29;;;:12;;:29;:12;:29;;;;;8697:93:63::1;;8756:23;;;;;;;;;;;;;;8697:93;8799:61;::::0;;;;:47:::1;15138:55:95::0;;;8799:61:63::1;::::0;::::1;15120:74:95::0;15210:18;;;15203:34;;;8799:47:63;::::1;::::0;::::1;::::0;15093:18:95;;8799:61:63::1;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;8575:292:::0;;;;:::o;13937:257::-;14095:7;14148:4;14154:7;14163:11;14176:9;;14131:55;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;14121:66;;;;;;14114:73;;13937:257;;;;;;;:::o;5060:863::-;5161:15;5140:6;:17;;;:36;5136:98;;5199:24;;;;;;;;;;;;;;5136:98;5272:4;5247:13;;;;;;;;:::i;:::-;:30;;;5243:100;;5318:13;;;;;;;;:::i;:::-;5300:32;;;;;7125:42:95;7113:55;;;5300:32:63;;;7095:74:95;7068:18;;5300:32:63;6949:226:95;5243:100:63;5356:17;5370:3;5356:17;:10;;;;:6;:10;:::i;:::-;:17;;;5352:81;;5411:10;;;;:6;:10;:::i;:::-;5396:26;;;;;12245:10:95;12233:23;;;5396:26:63;;;12215:42:95;12188:18;;5396:26:63;12071:192:95;5352:81:63;5481:12;5496:75;5509:10;;;;:6;:10;:::i;5496:75::-;5481:90;-1:-1:-1;5582:14:63;5602:41;5481:90;5625:17;;;;:6;:17;:::i;5602:41::-;5581:62;;;5658:9;5653:71;;5690:23;;;;;;;;;;;;;;5653:71;5737:16;;;;:10;:16;;;;;;;;5733:78;;;5776:24;;;;;;;;2261:25:95;;;2234:18;;5776:24:63;2115:177:95;5733:78:63;5821:16;;;;:10;:16;;;;;;;:23;;;;5840:4;5821:23;;;5854:62;;777:23:57;;5888:15:63;;;;:6;:15;:::i;:::-;5877:38;;;;;;;:::i;:::-;5854:10;:62::i;10892:539::-;11116:11;573:29:57;2631:16:39;2642:4;2631:10;:16::i;:::-;11098:7:63::1;2295:15:57;2302:7;2295:6;:15::i;:::-;2290:73;;2333:19;;;;;;;;;;;;;;2290:73;11186:135:63::2;::::0;;::::2;::::0;::::2;::::0;;11227:9:::2;::::0;::::2;::::0;;::::2;11186:135:::0;;;;::::2;;::::0;;::::2;::::0;;;;11271:6:::2;::::0;::::2;;11186:135:::0;;;;11227:9;11291:20;::::2;::::0;;::::2;;11186:135:::0;;;;11386:21:::2;11396:10;11386:21;11139:44;11386:21:::0;;;:9:::2;:21:::0;;;;;;;11337:87;;;;;11186:135;;11227:9:::2;11348:12:::0;;::::2;::::0;;::::2;::::0;11337:37:::2;::::0;:87:::2;::::0;11186:135;;11386:21;11409:4;;;;11415:8;;;;11337:87:::2;;;:::i;:::-;;;;;;;;;;;;;;;;;;;::::0;::::2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;11331:93:::0;10892:539;-1:-1:-1;;;;;;;;;;;10892:539:63:o;4682:94:66:-;4725:7;4751:18;:9;:16;:18::i;13280:500:63:-;13471:11;13453:7;2295:15:57;2302:7;2295:6;:15::i;:::-;2290:73;;2333:19;;;;;;;;;;;;;;2290:73;13541:135:63::1;::::0;;::::1;::::0;::::1;::::0;;13582:9:::1;::::0;::::1;::::0;;::::1;13541:135:::0;;;;::::1;;::::0;;::::1;::::0;;;;13626:6:::1;::::0;::::1;;13541:135:::0;;;;13582:9;13646:20;::::1;::::0;;::::1;;13541:135:::0;;;;13735:21:::1;13745:10;13735:21;13494:44;13735:21:::0;;;:9:::1;:21:::0;;;;;;;13692:81;;;;;13541:135;;13582:9:::1;13703:12:::0;;::::1;::::0;;::::1;::::0;13692:31:::1;::::0;:81:::1;::::0;13541:135;;13735:21;13758:4;;;;13764:8;;;;13692:81:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;13686:87:::0;13280:500;-1:-1:-1;;;;;;;;;;13280:500:63:o;3460:103:39:-;3526:30;3537:4;734:10:47;3526::39;:30::i;896:222:30:-;987:22;;;983:129;;1025:19;1032:3;1037:6;1025;:19::i;983:129::-;1075:26;1081:6;1089:3;1094:6;1075:5;:26::i;2186:115:42:-;1239:19;:17;:19::i;:::-;2255:4:::1;2245:14:::0;;;::::1;::::0;::::1;::::0;;2274:20:::1;734:10:47::0;2281:12:42::1;2274:20;::::0;7125:42:95;7113:55;;;7095:74;;7083:2;7068:18;2274:20:42::1;;;;;;;2186:115::o:0;2433:117::-;1486:16;:14;:16::i;:::-;2491:7:::1;:15:::0;;;::::1;::::0;;2521:22:::1;734:10:47::0;2530:12:42::1;655:96:47::0;5618:223:57;646:22;5703:5;:18;:47;;;;-1:-1:-1;3107:4:39;3130:12;;;;;;;;;;;:29;;;;;;;;;;;;;5725:25:57;5703:47;5699:93;;;5768:13;5766:15;;5768:13;;5766:15;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;5699:93;5801:33;5818:5;5825:8;5801:16;:33::i;1708:730:66:-;1782:7;1778:392;;;1809:21;;;1805:91;;1857:24;;;;;;;;;;;;;;1805:91;1914:22;:9;1928:7;1914:13;:22::i;:::-;1909:111;;1963:42;;;;;27599::95;27587:55;;1963:42:66;;;27569:74:95;27686:14;;27679:22;27659:18;;;27652:50;27542:18;;1963:42:66;27401:307:95;1909:111:66;1778:392;;;2055:25;:9;2072:7;2055:16;:25::i;:::-;2050:110;;2107:38;;;;;27599:42:95;27587:55;;2107:38:66;;;27569:74:95;27686:14;;27679:22;27659:18;;;27652:50;27542:18;;2107:38:66;27401:307:95;2050:110:66;2180:18;2208;:9;:16;:18::i;:::-;2254:6;;2180:47;;-1:-1:-1;2254:6:66;;;;;2274:21;;;-1:-1:-1;2270:117:66;;;2318:58;;;;;27893:18:95;27938:15;;;2318:58:66;;;27920:34:95;27990:15;;27970:18;;;27963:43;27856:18;;2318:58:66;27713:299:95;2270:117:66;2401:30;;;27599:42:95;27587:55;;27569:74;;27686:14;;27679:22;27674:2;27659:18;;27652:50;2401:30:66;;27542:18:95;2401:30:66;27401:307:95;8860:165:55;8993:23;;;8940:4;4351:19;;;:12;;;:19;;;;;;:24;;8963:55;8956:62;8860:165;-1:-1:-1;;;8860:165:55:o;2444:379:66:-;2503:7;:12;;2514:1;2503:12;2499:73;;2538:23;;;;;;;;;;;;;;2499:73;2581:18;2609;:9;:16;:18::i;:::-;2581:47;;2656:7;2642:21;;:11;:21;;;2638:117;;;2686:58;;;;;27893:18:95;27938:15;;;2686:58:66;;;27920:34:95;27990:15;;27970:18;;;27963:43;27856:18;;2686:58:66;27713:299:95;2638:117:66;2764:6;:16;;;;;;;;;;;;;2795:21;;1869:50:95;;;2795:21:66;;1857:2:95;1842:18;2795:21:66;1725:200:95;10259:300:55;10322:16;10350:22;10375:19;10383:3;10375:7;:19::i;14672:492:63:-;14742:4;14832:45;;;14848:29;14832:45;;;;:152;;-1:-1:-1;14941:43:63;;;14957:27;14941:43;;14832:152;:278;;;;-1:-1:-1;15048:62:63;;;15064:46;15048:62;;14813:297;14672:492;-1:-1:-1;;14672:492:63:o;2145:730:49:-;2226:7;2235:12;2263:9;:16;2283:2;2263:22;2259:610;;2599:4;2584:20;;2578:27;2648:4;2633:20;;2627:27;2705:4;2690:20;;2684:27;2301:9;2676:36;2746:25;2757:4;2676:36;2578:27;2627;2746:10;:25::i;:::-;2739:32;;;;;;;;;2259:610;-1:-1:-1;2818:1:49;;-1:-1:-1;2822:35:49;2259:610;2145:730;;;;;:::o;6011:224:57:-;646:22;6097:5;:18;:46;;;;-1:-1:-1;3107:4:39;3130:12;;;;;;;;;;;:29;;;;;;;;;;;;;6119:24:57;6093:92;;;6161:13;6159:15;;6161:13;;6159:15;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;6093:92;6194:34;6212:5;6219:8;6194:17;:34::i;9106:115:55:-;9169:7;9195:19;9203:3;4545:18;;4463:107;3844:479:39;3107:4;3130:12;;;;;;;;;;;:29;;;;;;;;;;;;;3927:390;;4115:28;4135:7;4115:19;:28::i;:::-;4214:38;4242:4;4249:2;4214:19;:38::i;:::-;4022:252;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;3970:336;;;;;;;;:::i;438:252:30:-;506:19;;;502:58;;534:26;;;;;;;;;;;;;;502:58;571:12;589:3;:8;;606:6;589:29;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;570:48;;;633:7;628:55;;649:34;;;;;15150:42:95;15138:55;;649:34:30;;;15120:74:95;15210:18;;;15203:34;;;15093:18;;649:34:30;14946:297:95;696:194:30;779:19;;;775:58;;807:26;;;;;;;;;;;;;;775:58;843:40;:27;;;871:3;876:6;843:27;:40::i;1767:106:42:-;1685:7;;;;1836:9;1828:38;;;;;;;30113:2:95;1828:38:42;;;30095:21:95;30152:2;30132:18;;;30125:30;30191:18;30171;;;30164:46;30227:18;;1828:38:42;29911:340:95;1828:38:42;1767:106::o;1945:::-;1685:7;;;;2003:41;;;;;;;30458:2:95;2003:41:42;;;30440:21:95;30497:2;30477:18;;;30470:30;30536:22;30516:18;;;30509:50;30576:18;;2003:41:42;30256:344:95;7587:233:39;3107:4;3130:12;;;;;;;;;;;:29;;;;;;;;;;;;;7665:149;;7708:6;:12;;;;;;;;;;;:29;;;;;;;;;;:36;;;;7740:4;7708:36;;;7790:12;734:10:47;;655:96;7790:12:39;7763:40;;7781:7;7763:40;;7775:4;7763:40;;;;;;;;;;7587:233;;:::o;8305:150:55:-;8375:4;8398:50;8403:3;8423:23;;;8398:4;:50::i;8623:156::-;8696:4;8719:53;8727:3;8747:23;;;8719:7;:53::i;5570:109::-;5626:16;5661:3;:11;;5654:18;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5570:109;;;:::o;5009:1456:49:-;5097:7;;6021:66;6008:79;;6004:161;;;-1:-1:-1;6119:1:49;;-1:-1:-1;6123:30:49;6103:51;;6004:161;6276:24;;;6259:14;6276:24;;;;;;;;;30832:25:95;;;30905:4;30893:17;;30873:18;;;30866:45;;;;30927:18;;;30920:34;;;30970:18;;;30963:34;;;6276:24:49;;30804:19:95;;6276:24:49;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;6276:24:49;;;;;;-1:-1:-1;;6314:20:49;;;6310:101;;6366:1;6370:29;6350:50;;;;;;;6310:101;6429:6;-1:-1:-1;6437:20:49;;-1:-1:-1;5009:1456:49;;;;;;;;:::o;7991:234:39:-;3107:4;3130:12;;;;;;;;;;;:29;;;;;;;;;;;;;8070:149;;;8144:5;8112:12;;;;;;;;;;;:29;;;;;;;;;;;:37;;;;;;8168:40;734:10:47;;8112:12:39;;8168:40;;8144:5;8168:40;7991:234;;:::o;2407:149:48:-;2465:13;2497:52;2509:22;;;343:2;1818:437;1893:13;1918:19;1950:10;1954:6;1950:1;:10;:::i;:::-;:14;;1963:1;1950:14;:::i;:::-;1940:25;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1940:25:48;;1918:47;;1975:15;:6;1982:1;1975:9;;;;;;;;:::i;:::-;;;;:15;;;;;;;;;;;2000;:6;2007:1;2000:9;;;;;;;;:::i;:::-;;;;:15;;;;;;;;;;-1:-1:-1;2030:9:48;2042:10;2046:6;2042:1;:10;:::i;:::-;:14;;2055:1;2042:14;:::i;:::-;2030:26;;2025:128;2062:1;2058;:5;2025:128;;;2096:8;2105:5;2113:3;2105:11;2096:21;;;;;;;:::i;:::-;;;;2084:6;2091:1;2084:9;;;;;;;;:::i;:::-;;;;:33;;;;;;;;;;-1:-1:-1;2141:1:48;2131:11;;;;;2065:3;;;:::i;:::-;;;2025:128;;;-1:-1:-1;2170:10:48;;2162:55;;;;;;;31600:2:95;2162:55:48;;;31582:21:95;;;31619:18;;;31612:30;31678:34;31658:18;;;31651:62;31730:18;;2162:55:48;31398:356:95;941:175:45;1050:58;;;15150:42:95;15138:55;;1050:58:45;;;15120:74:95;15210:18;;;;15203:34;;;1050:58:45;;;;;;;;;;15093:18:95;;;;1050:58:45;;;;;;;;;;1073:23;1050:58;;;1023:86;;1043:5;;1023:19;:86::i;2214:404:55:-;2277:4;4351:19;;;:12;;;:19;;;;;;2293:319;;-1:-1:-1;2335:23:55;;;;;;;;:11;:23;;;;;;;;;;;;;2515:18;;2493:19;;;:12;;;:19;;;;;;:40;;;;2547:11;;2293:319;-1:-1:-1;2596:5:55;2589:12;;2786:1388;2852:4;2989:19;;;:12;;;:19;;;;;;3023:15;;3019:1149;;3392:21;3416:14;3429:1;3416:10;:14;:::i;:::-;3464:18;;3392:38;;-1:-1:-1;3444:17:55;;3464:22;;3485:1;;3464:22;:::i;:::-;3444:42;;3518:13;3505:9;:26;3501:398;;3551:17;3571:3;:11;;3583:9;3571:22;;;;;;;;:::i;:::-;;;;;;;;;3551:42;;3722:9;3693:3;:11;;3705:13;3693:26;;;;;;;;:::i;:::-;;;;;;;;;;;;:38;;;;3805:23;;;:12;;;:23;;;;;:36;;;3501:398;3977:17;;:3;;:17;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;4069:3;:12;;:19;4082:5;4069:19;;;;;;;;;;;4062:26;;;4110:4;4103:11;;;;;;;3019:1149;4152:5;4145:12;;;;;5196:642:45;5615:23;5641:69;5669:4;5641:69;;;;;;;;;;;;;;;;;5649:5;5641:27;;;;:69;;;;;:::i;:::-;5615:95;;5728:10;:17;5749:1;5728:22;:56;;;;5765:10;5754:30;;;;;;;;;;;;:::i;:::-;5720:111;;;;;;;32533:2:95;5720:111:45;;;32515:21:95;32572:2;32552:18;;;32545:30;32611:34;32591:18;;;32584:62;32682:12;32662:18;;;32655:40;32712:19;;5720:111:45;32331:406:95;4108:223:46;4241:12;4272:52;4294:6;4302:4;4308:1;4311:12;4272:21;:52::i;:::-;4265:59;4108:223;-1:-1:-1;;;;4108:223:46:o;5165:446::-;5330:12;5387:5;5362:21;:30;;5354:81;;;;;;;32944:2:95;5354:81:46;;;32926:21:95;32983:2;32963:18;;;32956:30;33022:34;33002:18;;;32995:62;33093:8;33073:18;;;33066:36;33119:19;;5354:81:46;32742:402:95;5354:81:46;5446:12;5460:23;5487:6;:11;;5506:5;5513:4;5487:31;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5445:73;;;;5535:69;5562:6;5570:7;5579:10;5591:12;7851;7879:7;7875:418;;;7906:10;:17;7927:1;7906:22;7902:286;;1702:19;;;;8113:60;;;;;;;33643:2:95;8113:60:46;;;33625:21:95;33682:2;33662:18;;;33655:30;33721:31;33701:18;;;33694:59;33770:18;;8113:60:46;33441:353:95;8113:60:46;-1:-1:-1;8208:10:46;8201:17;;7875:418;8249:33;8257:10;8269:12;8980:17;;:21;8976:379;;9208:10;9202:17;9264:15;9251:10;9247:2;9243:19;9236:44;8976:379;9331:12;9324:20;;;;;;;;;;;:::i;-1:-1:-1:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;:::o;:::-;;;;;;;;;;;;;;;207:154:95;293:42;286:5;282:54;275:5;272:65;262:93;;351:1;348;341:12;366:456;443:6;451;459;512:2;500:9;491:7;487:23;483:32;480:52;;;528:1;525;518:12;480:52;567:9;554:23;586:31;611:5;586:31;:::i;:::-;636:5;-1:-1:-1;693:2:95;678:18;;665:32;706:33;665:32;706:33;:::i;:::-;366:456;;758:7;;-1:-1:-1;;;812:2:95;797:18;;;;784:32;;366:456::o;827:332::-;885:6;938:2;926:9;917:7;913:23;909:32;906:52;;;954:1;951;944:12;906:52;993:9;980:23;1043:66;1036:5;1032:78;1025:5;1022:89;1012:117;;1125:1;1122;1115:12;1356:118;1442:5;1435:13;1428:21;1421:5;1418:32;1408:60;;1464:1;1461;1454:12;1479:241;1535:6;1588:2;1576:9;1567:7;1563:23;1559:32;1556:52;;;1604:1;1601;1594:12;1556:52;1643:9;1630:23;1662:28;1684:5;1662:28;:::i;1930:180::-;1989:6;2042:2;2030:9;2021:7;2017:23;2013:32;2010:52;;;2058:1;2055;2048:12;2010:52;-1:-1:-1;2081:23:95;;1930:180;-1:-1:-1;1930:180:95:o;2297:163::-;2364:20;;2424:10;2413:22;;2403:33;;2393:61;;2450:1;2447;2440:12;2465:184;2523:6;2576:2;2564:9;2555:7;2551:23;2547:32;2544:52;;;2592:1;2589;2582:12;2544:52;2615:28;2633:9;2615:28;:::i;2654:639::-;2821:2;2873:21;;;2943:13;;2846:18;;;2965:22;;;2792:4;;2821:2;3044:15;;;;3018:2;3003:18;;;2792:4;3087:180;3101:6;3098:1;3095:13;3087:180;;;3166:13;;3181:4;3162:24;3150:37;;3242:15;;;;3207:12;;;;3123:1;3116:9;3087:180;;;-1:-1:-1;3284:3:95;;2654:639;-1:-1:-1;;;;;;2654:639:95:o;3298:247::-;3357:6;3410:2;3398:9;3389:7;3385:23;3381:32;3378:52;;;3426:1;3423;3416:12;3378:52;3465:9;3452:23;3484:31;3509:5;3484:31;:::i;3550:315::-;3618:6;3626;3679:2;3667:9;3658:7;3654:23;3650:32;3647:52;;;3695:1;3692;3685:12;3647:52;3731:9;3718:23;3708:33;;3791:2;3780:9;3776:18;3763:32;3804:31;3829:5;3804:31;:::i;:::-;3854:5;3844:15;;;3550:315;;;;;:::o;3870:171::-;3937:20;;3997:18;3986:30;;3976:41;;3966:69;;4031:1;4028;4021:12;4046:347;4097:8;4107:6;4161:3;4154:4;4146:6;4142:17;4138:27;4128:55;;4179:1;4176;4169:12;4128:55;-1:-1:-1;4202:20:95;;4245:18;4234:30;;4231:50;;;4277:1;4274;4267:12;4231:50;4314:4;4306:6;4302:17;4290:29;;4366:3;4359:4;4350:6;4342;4338:19;4334:30;4331:39;4328:59;;;4383:1;4380;4373:12;4398:689;4493:6;4501;4509;4517;4525;4578:3;4566:9;4557:7;4553:23;4549:33;4546:53;;;4595:1;4592;4585:12;4546:53;4618:28;4636:9;4618:28;:::i;:::-;4608:38;;4665:37;4698:2;4687:9;4683:18;4665:37;:::i;:::-;4655:47;;4752:2;4741:9;4737:18;4724:32;4765:31;4790:5;4765:31;:::i;:::-;4815:5;-1:-1:-1;4871:2:95;4856:18;;4843:32;4898:18;4887:30;;4884:50;;;4930:1;4927;4920:12;4884:50;4969:58;5019:7;5010:6;4999:9;4995:22;4969:58;:::i;:::-;4398:689;;;;-1:-1:-1;4398:689:95;;-1:-1:-1;5046:8:95;;4943:84;4398:689;-1:-1:-1;;;4398:689:95:o;5274:382::-;5339:6;5347;5400:2;5388:9;5379:7;5375:23;5371:32;5368:52;;;5416:1;5413;5406:12;5368:52;5455:9;5442:23;5474:31;5499:5;5474:31;:::i;:::-;5524:5;-1:-1:-1;5581:2:95;5566:18;;5553:32;5594:30;5553:32;5594:30;:::i;5661:650::-;5782:6;5790;5843:2;5831:9;5822:7;5818:23;5814:32;5811:52;;;5859:1;5856;5849:12;5811:52;5899:9;5886:23;5928:18;5969:2;5961:6;5958:14;5955:34;;;5985:1;5982;5975:12;5955:34;6023:6;6012:9;6008:22;5998:32;;6068:7;6061:4;6057:2;6053:13;6049:27;6039:55;;6090:1;6087;6080:12;6039:55;6130:2;6117:16;6156:2;6148:6;6145:14;6142:34;;;6172:1;6169;6162:12;6142:34;6225:7;6220:2;6210:6;6207:1;6203:14;6199:2;6195:23;6191:32;6188:45;6185:65;;;6246:1;6243;6236:12;6185:65;6277:2;6269:11;;;;;6299:6;;-1:-1:-1;5661:650:95;;-1:-1:-1;;;;5661:650:95:o;6316:159::-;6383:20;;6443:6;6432:18;;6422:29;;6412:57;;6465:1;6462;6455:12;6480:464;6563:6;6571;6579;6587;6640:3;6628:9;6619:7;6615:23;6611:33;6608:53;;;6657:1;6654;6647:12;6608:53;6680:28;6698:9;6680:28;:::i;:::-;6670:38;;6727:37;6760:2;6749:9;6745:18;6727:37;:::i;:::-;6717:47;;6783:37;6816:2;6805:9;6801:18;6783:37;:::i;:::-;6773:47;;6870:2;6859:9;6855:18;6842:32;6883:31;6908:5;6883:31;:::i;:::-;6480:464;;;;-1:-1:-1;6480:464:95;;-1:-1:-1;;6480:464:95:o;7180:184::-;7238:6;7291:2;7279:9;7270:7;7266:23;7262:32;7259:52;;;7307:1;7304;7297:12;7259:52;7330:28;7348:9;7330:28;:::i;7369:681::-;7540:2;7592:21;;;7662:13;;7565:18;;;7684:22;;;7511:4;;7540:2;7763:15;;;;7737:2;7722:18;;;7511:4;7806:218;7820:6;7817:1;7814:13;7806:218;;;7885:13;;7900:42;7881:62;7869:75;;7999:15;;;;7964:12;;;;7842:1;7835:9;7806:218;;8055:163;8122:5;8167:3;8158:6;8153:3;8149:16;8145:26;8142:46;;;8184:1;8181;8174:12;8142:46;-1:-1:-1;8206:6:95;8055:163;-1:-1:-1;8055:163:95:o;8223:679::-;8337:6;8345;8353;8406:2;8394:9;8385:7;8381:23;8377:32;8374:52;;;8422:1;8419;8412:12;8374:52;8462:9;8449:23;8491:18;8532:2;8524:6;8521:14;8518:34;;;8548:1;8545;8538:12;8518:34;8571:74;8637:7;8628:6;8617:9;8613:22;8571:74;:::i;:::-;8561:84;;8698:2;8687:9;8683:18;8670:32;8654:48;;8727:2;8717:8;8714:16;8711:36;;;8743:1;8740;8733:12;8711:36;;8782:60;8834:7;8823:8;8812:9;8808:24;8782:60;:::i;:::-;8223:679;;8861:8;;-1:-1:-1;8756:86:95;;-1:-1:-1;;;;8223:679:95:o;9306:388::-;9390:8;9400:6;9454:3;9447:4;9439:6;9435:17;9431:27;9421:55;;9472:1;9469;9462:12;9421:55;-1:-1:-1;9495:20:95;;9538:18;9527:30;;9524:50;;;9570:1;9567;9560:12;9524:50;9607:4;9599:6;9595:17;9583:29;;9667:3;9660:4;9650:6;9647:1;9643:14;9635:6;9631:27;9627:38;9624:47;9621:67;;;9684:1;9681;9674:12;9699:491;9818:6;9826;9879:2;9867:9;9858:7;9854:23;9850:32;9847:52;;;9895:1;9892;9885:12;9847:52;9935:9;9922:23;9968:18;9960:6;9957:30;9954:50;;;10000:1;9997;9990:12;9954:50;10039:91;10122:7;10113:6;10102:9;10098:22;10039:91;:::i;:::-;10149:8;;10013:117;;-1:-1:-1;9699:491:95;-1:-1:-1;;;;9699:491:95:o;10195:184::-;10253:6;10306:2;10294:9;10285:7;10281:23;10277:32;10274:52;;;10322:1;10319;10312:12;10274:52;10345:28;10363:9;10345:28;:::i;10384:477::-;10463:6;10471;10479;10532:2;10520:9;10511:7;10507:23;10503:32;10500:52;;;10548:1;10545;10538:12;10500:52;10584:9;10571:23;10561:33;;10645:2;10634:9;10630:18;10617:32;10672:18;10664:6;10661:30;10658:50;;;10704:1;10701;10694:12;10658:50;10743:58;10793:7;10784:6;10773:9;10769:22;10743:58;:::i;10866:184::-;10918:77;10915:1;10908:88;11015:4;11012:1;11005:15;11039:4;11036:1;11029:15;11055:478;11258:14;;11251:22;11233:41;;11221:2;11206:18;;11304:1;11293:13;;11283:201;;11340:77;11337:1;11330:88;11441:4;11438:1;11431:15;11469:4;11466:1;11459:15;11283:201;11520:6;11515:2;11504:9;11500:18;11493:34;11055:478;;;;;:::o;11538:528::-;11630:6;11638;11646;11699:2;11687:9;11678:7;11674:23;11670:32;11667:52;;;11715:1;11712;11705:12;11667:52;11738:28;11756:9;11738:28;:::i;:::-;11728:38;;11817:2;11806:9;11802:18;11789:32;11844:18;11836:6;11833:30;11830:50;;;11876:1;11873;11866:12;11830:50;11915:91;11998:7;11989:6;11978:9;11974:22;11915:91;:::i;12737:685::-;12833:6;12841;12849;12857;12865;12918:3;12906:9;12897:7;12893:23;12889:33;12886:53;;;12935:1;12932;12925:12;12886:53;12958:28;12976:9;12958:28;:::i;:::-;12948:38;;13036:2;13025:9;13021:18;13008:32;13049:31;13074:5;13049:31;:::i;:::-;13099:5;-1:-1:-1;13155:2:95;13140:18;;13127:32;13182:18;13171:30;;13168:50;;;13214:1;13211;13204:12;13168:50;13253:58;13303:7;13294:6;13283:9;13279:22;13253:58;:::i;:::-;12737:685;;;;-1:-1:-1;13330:8:95;13412:2;13397:18;13384:32;;12737:685;-1:-1:-1;;;;12737:685:95:o;13427:369::-;13519:6;13572:2;13560:9;13551:7;13547:23;13543:32;13540:52;;;13588:1;13585;13578:12;13540:52;13628:9;13615:23;13661:18;13653:6;13650:30;13647:50;;;13693:1;13690;13683:12;13647:50;13716:74;13782:7;13773:6;13762:9;13758:22;13716:74;:::i;13801:1140::-;13920:6;13928;13936;13944;13952;13960;13968;14021:3;14009:9;14000:7;13996:23;13992:33;13989:53;;;14038:1;14035;14028:12;13989:53;14077:9;14064:23;14096:31;14121:5;14096:31;:::i;:::-;14146:5;-1:-1:-1;14202:2:95;14187:18;;14174:32;14225:18;14255:14;;;14252:34;;;14282:1;14279;14272:12;14252:34;14321:58;14371:7;14362:6;14351:9;14347:22;14321:58;:::i;:::-;14398:8;;-1:-1:-1;14295:84:95;-1:-1:-1;14486:2:95;14471:18;;14458:32;;-1:-1:-1;14502:16:95;;;14499:36;;;14531:1;14528;14521:12;14499:36;14570:60;14622:7;14611:8;14600:9;14596:24;14570:60;:::i;:::-;14649:8;;-1:-1:-1;14544:86:95;-1:-1:-1;14737:2:95;14722:18;;14709:32;;-1:-1:-1;14753:16:95;;;14750:36;;;14782:1;14779;14772:12;14750:36;;14821:60;14873:7;14862:8;14851:9;14847:24;14821:60;:::i;:::-;13801:1140;;;;-1:-1:-1;13801:1140:95;;-1:-1:-1;13801:1140:95;;;;14795:86;;-1:-1:-1;;;13801:1140:95:o;16556:325::-;16644:6;16639:3;16632:19;16696:6;16689:5;16682:4;16677:3;16673:14;16660:43;;16748:1;16741:4;16732:6;16727:3;16723:16;16719:27;16712:38;16614:3;16870:4;16800:66;16795:2;16787:6;16783:15;16779:88;16774:3;16770:98;16766:109;16759:116;;16556:325;;;;:::o;16886:569::-;17171:4;17200:3;17212:46;17248:9;17240:6;15724:42;15805:2;15797:5;15791:12;15787:21;15782:3;15775:34;15870:10;15862:4;15855:5;15851:16;15845:23;15841:40;15834:4;15829:3;15825:14;15818:64;15928:4;15921:5;15917:16;15911:23;15953:18;16021:2;16007:12;16003:21;15996:4;15991:3;15987:14;15980:45;16086:2;16078:4;16071:5;16067:16;16061:23;16057:32;16050:4;16045:3;16041:14;16034:56;16151:2;16143:4;16136:5;16132:16;16126:23;16122:32;16115:4;16110:3;16106:14;16099:56;;;;16216:6;16208:4;16201:5;16197:16;16191:23;16187:36;16180:4;16175:3;16171:14;16164:60;15651:579;;;17212:46;17267:64;17326:3;17315:9;17311:19;17303:6;16323:12;16371:18;16356:34;;16344:47;;16431:2;16427:18;;;16447:6;16423:31;16416:4;16407:14;;16400:55;16493:2;16489:18;;;;16509:34;16485:59;16471:12;;16464:81;16235:316;17267:64;17368:2;17362:3;17351:9;17347:19;17340:31;17388:61;17445:2;17434:9;17430:18;17422:6;17414;17388:61;:::i;17460:184::-;17530:6;17583:2;17571:9;17562:7;17558:23;17554:32;17551:52;;;17599:1;17596;17589:12;17551:52;-1:-1:-1;17622:16:95;;17460:184;-1:-1:-1;17460:184:95:o;17649:::-;17701:77;17698:1;17691:88;17798:4;17795:1;17788:15;17822:4;17819:1;17812:15;17838:188;17906:20;;17966:34;17955:46;;17945:57;;17935:85;;18016:1;18013;18006:12;18031:186;18090:6;18143:2;18131:9;18122:7;18118:23;18114:32;18111:52;;;18159:1;18156;18149:12;18111:52;18182:29;18201:9;18182:29;:::i;18222:1056::-;18471:2;18523:21;;;18496:18;;;18579:22;;;18442:4;;18620:2;18638:18;;;18679:6;18442:4;18713:539;18727:6;18724:1;18721:13;18713:539;;;18819:10;18792:25;18810:6;18792:25;:::i;:::-;18788:42;18783:3;18776:55;18905:18;18869:34;18899:2;18891:6;18887:15;18869:34;:::i;:::-;18865:59;18860:2;18855:3;18851:12;18844:81;18999:6;18963:34;18993:2;18985:6;18981:15;18963:34;:::i;:::-;18959:47;18954:2;18949:3;18945:12;18938:69;19030:4;19109:34;19072:35;19103:2;19095:6;19091:15;19072:35;:::i;:::-;19068:76;19054:12;;;19047:98;19168:4;19192:12;;;;19227:15;;;;;18749:1;18742:9;18713:539;;;-1:-1:-1;19269:3:95;;18222:1056;-1:-1:-1;;;;;;;18222:1056:95:o;19283:250::-;19368:1;19378:113;19392:6;19389:1;19386:13;19378:113;;;19468:11;;;19462:18;19449:11;;;19442:39;19414:2;19407:10;19378:113;;;-1:-1:-1;;19525:1:95;19507:16;;19500:27;19283:250::o;19538:329::-;19579:3;19617:5;19611:12;19644:6;19639:3;19632:19;19660:76;19729:6;19722:4;19717:3;19713:14;19706:4;19699:5;19695:16;19660:76;:::i;:::-;19781:2;19769:15;19786:66;19765:88;19756:98;;;;19856:4;19752:109;;19538:329;-1:-1:-1;;19538:329:95:o;19872:542::-;20147:4;20176:3;20188:46;20224:9;20216:6;15724:42;15805:2;15797:5;15791:12;15787:21;15782:3;15775:34;15870:10;15862:4;15855:5;15851:16;15845:23;15841:40;15834:4;15829:3;15825:14;15818:64;15928:4;15921:5;15917:16;15911:23;15953:18;16021:2;16007:12;16003:21;15996:4;15991:3;15987:14;15980:45;16086:2;16078:4;16071:5;16067:16;16061:23;16057:32;16050:4;16045:3;16041:14;16034:56;16151:2;16143:4;16136:5;16132:16;16126:23;16122:32;16115:4;16110:3;16106:14;16099:56;;;;16216:6;16208:4;16201:5;16197:16;16191:23;16187:36;16180:4;16175:3;16171:14;16164:60;15651:579;;;20188:46;20243:64;20302:3;20291:9;20287:19;20279:6;16323:12;16371:18;16356:34;;16344:47;;16431:2;16427:18;;;16447:6;16423:31;16416:4;16407:14;;16400:55;16493:2;16489:18;;;;16509:34;16485:59;16471:12;;16464:81;16235:316;20243:64;20344:2;20338:3;20327:9;20323:19;20316:31;20364:44;20404:2;20393:9;20389:18;20381:6;20364:44;:::i;:::-;20356:52;19872:542;-1:-1:-1;;;;;;19872:542:95:o;20419:389::-;20518:4;20576:11;20563:25;20666:66;20655:8;20639:14;20635:29;20631:102;20611:18;20607:127;20597:155;;20748:1;20745;20738:12;20597:155;20769:33;;;;;20419:389;-1:-1:-1;;20419:389:95:o;20813:580::-;20890:4;20896:6;20956:11;20943:25;21046:66;21035:8;21019:14;21015:29;21011:102;20991:18;20987:127;20977:155;;21128:1;21125;21118:12;20977:155;21155:33;;21207:20;;;-1:-1:-1;21250:18:95;21239:30;;21236:50;;;21282:1;21279;21272:12;21236:50;21315:4;21303:17;;-1:-1:-1;21346:14:95;21342:27;;;21332:38;;21329:58;;;21383:1;21380;21373:12;21398:369;21556:66;21518:19;;21640:11;;;;21671:1;21663:10;;21660:101;;;21748:2;21742;21735:3;21732:1;21728:11;21725:1;21721:19;21717:28;21713:2;21709:37;21705:46;21696:55;;21660:101;;;21398:369;;;;:::o;21772:559::-;21830:5;21837:6;21897:3;21884:17;21979:66;21968:8;21952:14;21948:29;21944:102;21924:18;21920:127;21910:155;;22061:1;22058;22051:12;21910:155;22089:33;;22193:4;22180:18;;;-1:-1:-1;22141:21:95;;-1:-1:-1;22221:18:95;22210:30;;22207:50;;;22253:1;22250;22243:12;22207:50;22300:6;22284:14;22280:27;22273:5;22269:39;22266:59;;;22321:1;22318;22311:12;22336:1161;22557:2;22546:9;22539:21;22627:10;22600:25;22618:6;22600:25;:::i;:::-;22596:42;22591:2;22580:9;22576:18;22569:70;22520:4;22686;22678:6;22674:17;22661:31;22701;22726:5;22701:31;:::i;:::-;22779:42;22768:54;22763:2;22748:18;;22741:82;22866:55;22917:2;22905:15;;22909:6;22866:55;:::i;:::-;22958:4;22952:3;22941:9;22937:19;22930:33;22986:74;23055:3;23044:9;23040:19;23026:12;23012;22986:74;:::i;:::-;22972:88;;;23123:2;23115:6;23111:15;23098:29;23091:4;23080:9;23076:20;23069:59;23175:56;23226:3;23218:6;23214:16;23206:6;23175:56;:::i;:::-;23296:66;23284:9;23276:6;23272:22;23268:95;23262:3;23251:9;23247:19;23240:124;23381:65;23439:6;23423:14;23407;23381:65;:::i;:::-;23373:73;;;;;23484:6;23477:4;23466:9;23462:20;23455:36;22336:1161;;;;;:::o;23502:271::-;23685:6;23677;23672:3;23659:33;23641:3;23711:16;;23736:13;;;23711:16;23502:271;-1:-1:-1;23502:271:95:o;23778:288::-;23953:6;23942:9;23935:25;23996:2;23991;23980:9;23976:18;23969:30;23916:4;24016:44;24056:2;24045:9;24041:18;24033:6;24016:44;:::i;24071:184::-;24123:77;24120:1;24113:88;24220:4;24217:1;24210:15;24244:4;24241:1;24234:15;24260:168;24333:9;;;24364;;24381:15;;;24375:22;;24361:37;24351:71;;24402:18;;:::i;24433:125::-;24498:9;;;24519:10;;;24516:36;;;24532:18;;:::i;24563:331::-;24668:9;24679;24721:8;24709:10;24706:24;24703:44;;;24743:1;24740;24733:12;24703:44;24772:6;24762:8;24759:20;24756:40;;;24792:1;24789;24782:12;24756:40;-1:-1:-1;;24818:23:95;;;24863:25;;;;;-1:-1:-1;24563:331:95:o;25217:637::-;25490:66;25481:6;25476:3;25472:16;25468:89;25463:3;25456:102;25608:66;25599:6;25595:2;25591:15;25587:88;25583:1;25578:3;25574:11;25567:109;25706:6;25701:2;25696:3;25692:12;25685:28;25757:6;25749;25744:2;25739:3;25735:12;25722:42;25438:3;25787:16;;25805:2;25783:25;25817:13;;;25783:25;25217:637;-1:-1:-1;;;;25217:637:95:o;26119:1063::-;26474:4;26503:3;26525:42;26613:2;26604:6;26598:13;26594:22;26583:9;26576:41;26685:2;26677:4;26669:6;26665:17;26659:24;26655:33;26648:4;26637:9;26633:20;26626:63;;26757:18;26749:4;26741:6;26737:17;26731:24;26727:49;26720:4;26709:9;26705:20;26698:79;26845:6;26837:4;26829:6;26825:17;26819:24;26815:37;26808:4;26797:9;26793:20;26786:67;26862:64;26921:3;26910:9;26906:19;26898:6;16323:12;16371:18;16356:34;;16344:47;;16431:2;16427:18;;;16447:6;16423:31;16416:4;16407:14;;16400:55;16493:2;16489:18;;;;16509:34;16485:59;16471:12;;16464:81;16235:316;26862:64;26963:2;26957:3;26946:9;26942:19;26935:31;26989:61;27046:2;27035:9;27031:18;27023:6;27015;26989:61;:::i;:::-;26975:75;;27099:9;27091:6;27087:22;27081:3;27070:9;27066:19;27059:51;27127:49;27169:6;27161;27153;27127:49;:::i;:::-;27119:57;26119:1063;-1:-1:-1;;;;;;;;;26119:1063:95:o;27187:209::-;27225:3;27253:18;27306:2;27299:5;27295:14;27333:2;27324:7;27321:15;27318:41;;27339:18;;:::i;:::-;27388:1;27375:15;;27187:209;-1:-1:-1;;;27187:209:95:o;28402:253::-;28440:3;28484:18;28477:5;28473:30;28522:7;28512:41;;28533:18;;:::i;:::-;28582:66;28569:80;;28402:253;-1:-1:-1;;28402:253:95:o;28660:812::-;29071:25;29066:3;29059:38;29041:3;29126:6;29120:13;29142:75;29210:6;29205:2;29200:3;29196:12;29189:4;29181:6;29177:17;29142:75;:::i;:::-;29281:19;29276:2;29236:16;;;29268:11;;;29261:40;29326:13;;29348:76;29326:13;29410:2;29402:11;;29395:4;29383:17;;29348:76;:::i;:::-;29444:17;29463:2;29440:26;;28660:812;-1:-1:-1;;;;28660:812:95:o;29477:219::-;29626:2;29615:9;29608:21;29589:4;29646:44;29686:2;29675:9;29671:18;29663:6;29646:44;:::i;31008:184::-;31060:77;31057:1;31050:88;31157:4;31154:1;31147:15;31181:4;31178:1;31171:15;31197:196;31236:3;31264:5;31254:39;;31273:18;;:::i;:::-;-1:-1:-1;31320:66:95;31309:78;;31197:196::o;31759:128::-;31826:9;;;31847:11;;;31844:37;;;31861:18;;:::i;31892:184::-;31944:77;31941:1;31934:88;32041:4;32038:1;32031:15;32065:4;32062:1;32055:15;32081:245;32148:6;32201:2;32189:9;32180:7;32176:23;32172:32;32169:52;;;32217:1;32214;32207:12;32169:52;32249:9;32243:16;32268:28;32290:5;32268:28;:::i;33149:287::-;33278:3;33316:6;33310:13;33332:66;33391:6;33386:3;33379:4;33371:6;33367:17;33332:66;:::i
Swarm Source
ipfs://198a6ed2fc72043001b01d1b1945eeab857e3b52b5e2dd6f3d5106e342b43a0e
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in FRAX
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.