编译器
0.8.22+commit.4fc1097e
文件 1 的 31:AccessControl.sol
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
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;
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
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)
)
)
);
}
}
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}
文件 2 的 31:Address.sol
pragma solidity ^0.8.1;
library Address {
function isContract(address account) internal view returns (bool) {
return account.code.length > 0;
}
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");
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
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");
}
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);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
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);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
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);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
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 {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}
文件 3 的 31:Context.sol
pragma solidity ^0.8.0;
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;
}
}
文件 4 的 31:DVN.sol
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 { 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 {
uint32 public immutable vid;
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);
event VerifierFeePaid(uint256 fee);
constructor(
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;
}
modifier onlySelfOrAdmin(bytes32 _role) {
if (_role == ALLOWLIST || _role == DENYLIST || _role == MESSAGE_LIB_ROLE) {
if (address(this) != msg.sender) {
revert DVN_OnlySelf();
}
} else if (_role == ADMIN_ROLE) {
_checkRole(ADMIN_ROLE);
} else {
revert DVN_InvalidRole(_role);
}
_;
}
modifier onlySelf() {
if (address(this) != msg.sender) {
revert DVN_OnlySelf();
}
_;
}
function setSigner(address _signer, bool _active) external onlySelf {
_setSigner(_signer, _active);
}
function setQuorum(uint64 _quorum) external onlySelf {
_setQuorum(_quorum);
}
function grantRole(bytes32 _role, address _account) public override onlySelfOrAdmin(_role) {
_grantRole(_role, _account);
}
function revokeRole(bytes32 _role, address _account) public override onlySelfOrAdmin(_role) {
_revokeRole(_role, _account);
}
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);
}
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)));
}
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);
}
function execute(ExecuteParam[] calldata _params) external onlyRole(ADMIN_ROLE) {
for (uint256 i = 0; i < _params.length; ++i) {
ExecuteParam calldata param = _params[i];
if (param.vid != vid) {
continue;
}
if (param.expiration <= block.timestamp) {
continue;
}
bytes32 hash = hashCallData(param.vid, param.target, param.callData, param.expiration);
(bool sigsValid, ) = verifySignatures(hash, param.signatures);
if (!sigsValid) {
emit VerifySignaturesFailed(i);
continue;
}
bool shouldCheckHash = _shouldCheckHash(bytes4(param.callData));
if (shouldCheckHash) {
if (usedHashes[hash]) {
emit HashAlreadyUsed(param, hash);
continue;
} else {
usedHashes[hash] = true;
}
}
(bool success, bytes memory rtnData) = param.target.call(param.callData);
if (!success) {
if (shouldCheckHash) {
usedHashes[hash] = false;
}
emit ExecuteFailed(i, rtnData);
}
}
}
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);
}
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);
}
function assignJob(
uint16 _dstEid,
uint16 ,
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
);
totalFee = IDVNFeeLib(workerFeeLib).getFeeOnSend(params, dstConfig[_dstEid], bytes(""));
emit VerifierFeePaid(totalFee);
}
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
);
return IDVNFeeLib(workerFeeLib).getFee(params, dstConfig[_dstEid], _options);
}
function getFee(
uint16 _dstEid,
uint16 ,
uint64 _confirmations,
address _sender
) public view onlyAcl(_sender) returns (uint256 fee) {
IDVNFeeLib.FeeParams memory params = IDVNFeeLib.FeeParams(
priceFeed,
_dstEid,
_confirmations,
_sender,
quorum,
defaultMultiplierBps
);
return IDVNFeeLib(workerFeeLib).getFee(params, dstConfig[_dstEid], bytes(""));
}
function hashCallData(
uint32 _vid,
address _target,
bytes calldata _callData,
uint256 _expiration
) public pure returns (bytes32) {
return keccak256(abi.encodePacked(_vid, _target, _expiration, _callData));
}
function _shouldCheckHash(bytes4 _functionSig) internal pure returns (bool) {
return
_functionSig != IReceiveUlnE2.verify.selector &&
_functionSig != ILayerZeroUltraLightNodeV2.updateHash.selector;
}
}
文件 5 的 31:ECDSA.sol
pragma solidity ^0.8.0;
import "../Strings.sol";
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return;
} 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");
}
}
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
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);
}
}
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
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);
}
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
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;
}
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}
文件 6 的 31:ERC165.sol
pragma solidity ^0.8.0;
import "./IERC165.sol";
abstract contract ERC165 is IERC165 {
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}
文件 7 的 31:IAccessControl.sol
pragma solidity ^0.8.0;
interface IAccessControl {
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
function hasRole(bytes32 role, address account) external view returns (bool);
function getRoleAdmin(bytes32 role) external view returns (bytes32);
function grantRole(bytes32 role, address account) external;
function revokeRole(bytes32 role, address account) external;
function renounceRole(bytes32 role, address account) external;
}
文件 8 的 31:IDVN.sol
pragma solidity >=0.8.0;
import { IWorker } from "../../interfaces/IWorker.sol";
import { ILayerZeroDVN } from "./ILayerZeroDVN.sol";
interface IDVN is IWorker, ILayerZeroDVN {
struct DstConfigParam {
uint32 dstEid;
uint64 gas;
uint16 multiplierBps;
uint128 floorMarginUSD;
}
struct DstConfig {
uint64 gas;
uint16 multiplierBps;
uint128 floorMarginUSD;
}
event SetDstConfig(DstConfigParam[] params);
function dstConfig(uint32 _dstEid) external view returns (uint64, uint16, uint128);
}
文件 9 的 31:IDVNFeeLib.sol
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;
}
error DVN_UnsupportedOptionType(uint8 optionType);
error DVN_EidNotSupported(uint32 eid);
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);
}
文件 10 的 31:IERC165.sol
pragma solidity ^0.8.0;
interface IERC165 {
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}
文件 11 的 31:IERC20.sol
pragma solidity ^0.8.0;
interface IERC20 {
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}
文件 12 的 31:IERC20Permit.sol
pragma solidity ^0.8.0;
interface IERC20Permit {
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
function nonces(address owner) external view returns (uint256);
function DOMAIN_SEPARATOR() external view returns (bytes32);
}
文件 13 的 31:ILayerZeroDVN.sol
pragma solidity >=0.8.0;
interface ILayerZeroDVN {
struct AssignJobParam {
uint32 dstEid;
bytes packetHeader;
bytes32 payloadHash;
uint64 confirmations;
address sender;
}
function assignJob(AssignJobParam calldata _param, bytes calldata _options) external payable returns (uint256 fee);
function getFee(
uint32 _dstEid,
uint64 _confirmations,
address _sender,
bytes calldata _options
) external view returns (uint256 fee);
}
文件 14 的 31:ILayerZeroEndpointV2.sol
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;
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;
}
文件 15 的 31:ILayerZeroUltraLightNodeV2.sol
pragma solidity >=0.7.0;
pragma abicoder v2;
interface ILayerZeroUltraLightNodeV2 {
function validateTransactionProof(
uint16 _srcChainId,
address _dstAddress,
uint _gasLimit,
bytes32 _lookupHash,
bytes32 _blockData,
bytes calldata _transactionProof
) external;
function updateHash(uint16 _srcChainId, bytes32 _lookupHash, uint _confirmations, bytes32 _blockData) external;
function withdrawNative(address payable _to, uint _amount) external;
function withdrawZRO(address _to, uint _amount) external;
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);
}
文件 16 的 31:IMessageLib.sol
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);
function version() external view returns (uint64 major, uint8 minor, uint8 endpointVersion);
function messageLibType() external view returns (MessageLibType);
}
文件 17 的 31:IMessageLibManager.sol
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 _timeout) 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);
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 _gracePeriod) 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);
}
文件 18 的 31:IMessagingChannel.sol
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);
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);
}
文件 19 的 31:IMessagingComposer.sol
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;
}
文件 20 的 31:IMessagingContext.sol
pragma solidity >=0.8.0;
interface IMessagingContext {
function isSendingMessage() external view returns (bool);
function getSendContext() external view returns (uint32 dstEid, address sender);
}
文件 21 的 31:IReceiveUlnE2.sol
pragma solidity >=0.8.0;
interface IReceiveUlnE2 {
function verify(bytes calldata _packetHeader, bytes32 _payloadHash, uint64 _confirmations) external;
function commitVerification(bytes calldata _packetHeader, bytes32 _payloadHash) external;
}
文件 22 的 31:ISendLib.sol
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;
}
文件 23 的 31:IWorker.sol
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);
}
文件 24 的 31:Math.sol
pragma solidity ^0.8.0;
library Math {
enum Rounding {
Down,
Up,
Zero
}
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
function average(uint256 a, uint256 b) internal pure returns (uint256) {
return (a & b) + (a ^ b) / 2;
}
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
return a == 0 ? 0 : (a - 1) / b + 1;
}
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
uint256 prod0;
uint256 prod1;
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
if (prod1 == 0) {
return prod0 / denominator;
}
require(denominator > prod1, "Math: mulDiv overflow");
uint256 remainder;
assembly {
remainder := mulmod(x, y, denominator)
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
uint256 twos = denominator & (~denominator + 1);
assembly {
denominator := div(denominator, twos)
prod0 := div(prod0, twos)
twos := add(div(sub(0, twos), twos), 1)
}
prod0 |= prod1 * twos;
uint256 inverse = (3 * denominator) ^ 2;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
inverse *= 2 - denominator * inverse;
result = prod0 * inverse;
return result;
}
}
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;
}
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
uint256 result = 1 << (log2(a) >> 1);
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);
}
}
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);
}
}
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;
}
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);
}
}
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;
}
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);
}
}
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;
}
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);
}
}
}
文件 25 的 31:MultiSig.sol
pragma solidity ^0.8.20;
import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
abstract contract MultiSig {
enum Errors {
NoError,
SignatureError,
DuplicatedSigner,
SignerNotInCommittee
}
mapping(address signer => bool active) public signers;
uint64 public signerSize;
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);
event UpdateSigner(address _signer, bool _active);
event UpdateQuorum(uint64 _quorum);
modifier onlySigner() {
if (!signers[msg.sender]) {
revert MultiSig_OnlySigner();
}
_;
}
constructor(address[] memory _signers, uint64 _quorum) {
if (_quorum == 0) {
revert MultiSig_QuorumIsZero();
}
if (_signers.length < _quorum) {
revert MultiSig_SignersSizeIsLessThanQuorum(uint64(_signers.length), _quorum);
}
address lastSigner = address(0);
for (uint256 i = 0; i < _signers.length; i++) {
address signer = _signers[i];
if (signer <= lastSigner) {
revert MultiSig_UnorderedSigners();
}
signers[signer] = true;
lastSigner = signer;
}
signerSize = uint64(_signers.length);
quorum = _quorum;
}
function _setSigner(address _signer, bool _active) internal {
if (signers[_signer] == _active) {
revert MultiSig_StateAlreadySet(_signer, _active);
}
signers[_signer] = _active;
uint64 _signerSize = _active ? signerSize + 1 : signerSize - 1;
uint64 _quorum = quorum;
if (_signerSize < _quorum) {
revert MultiSig_SignersSizeIsLessThanQuorum(_signerSize, _quorum);
}
signerSize = _signerSize;
emit UpdateSigner(_signer, _active);
}
function _setQuorum(uint64 _quorum) internal {
if (_quorum == 0) {
revert MultiSig_QuorumIsZero();
}
uint64 _signerSize = signerSize;
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);
for (uint256 i = 0; i < quorum; i++) {
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);
if (!signers[currentSigner]) return (false, Errors.SignerNotInCommittee);
lastSigner = currentSigner;
}
return (true, Errors.NoError);
}
function _getEthSignedMessageHash(bytes32 _messageHash) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _messageHash));
}
}
文件 26 的 31:Pausable.sol
pragma solidity ^0.8.0;
import "../utils/Context.sol";
abstract contract Pausable is Context {
event Paused(address account);
event Unpaused(address account);
bool private _paused;
constructor() {
_paused = false;
}
modifier whenNotPaused() {
_requireNotPaused();
_;
}
modifier whenPaused() {
_requirePaused();
_;
}
function paused() public view virtual returns (bool) {
return _paused;
}
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}
文件 27 的 31:SafeERC20.sol
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
function safeApprove(IERC20 token, address spender, uint256 value) internal {
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
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));
}
}
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);
}
}
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");
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
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");
}
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}
文件 28 的 31:SignedMath.sol
pragma solidity ^0.8.0;
library SignedMath {
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
function average(int256 a, int256 b) internal pure returns (int256) {
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
function abs(int256 n) internal pure returns (uint256) {
unchecked {
return uint256(n >= 0 ? n : -n);
}
}
}
文件 29 的 31:Strings.sol
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
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);
}
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}
文件 30 的 31:Transfer.sol
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);
}
}
}
文件 31 的 31:Worker.sol
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(
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);
}
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 onlyAcl(address _sender) {
if (!hasAcl(_sender)) {
revert Worker_NotAllowed();
}
_;
}
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;
}
}
function setPaused(bool _paused) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (_paused) {
_pause();
} else {
_unpause();
}
}
function setPriceFeed(address _priceFeed) external onlyRole(ADMIN_ROLE) {
priceFeed = _priceFeed;
emit SetPriceFeed(_priceFeed);
}
function setWorkerFeeLib(address _workerFeeLib) external onlyRole(ADMIN_ROLE) {
workerFeeLib = _workerFeeLib;
emit SetWorkerLib(_workerFeeLib);
}
function setDefaultMultiplierBps(uint16 _multiplierBps) external onlyRole(ADMIN_ROLE) {
defaultMultiplierBps = _multiplierBps;
emit SetDefaultMultiplierBps(_multiplierBps);
}
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);
}
function withdrawToken(address _token, address _to, uint256 _amount) external onlyRole(ADMIN_ROLE) {
Transfer.nativeOrToken(_token, _to, _amount);
}
function setSupportedOptionTypes(uint32 _eid, uint8[] calldata _optionTypes) external onlyRole(ADMIN_ROLE) {
supportedOptionTypes[_eid] = _optionTypes;
}
function getSupportedOptionTypes(uint32 _eid) external view returns (uint8[] memory) {
return supportedOptionTypes[_eid];
}
function _grantRole(bytes32 _role, address _account) internal override {
if (_role == ALLOWLIST && !hasRole(_role, _account)) {
++allowlistSize;
}
super._grantRole(_role, _account);
}
function _revokeRole(bytes32 _role, address _account) internal override {
if (_role == ALLOWLIST && hasRole(_role, _account)) {
--allowlistSize;
}
super._revokeRole(_role, _account);
}
function renounceRole(bytes32 , address ) public pure override {
revert Worker_RoleRenouncingDisabled();
}
}
{
"compilationTarget": {
"contracts/uln/dvn/DVN.sol": "DVN"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs"
},
"optimizer": {
"enabled": true,
"runs": 20000
},
"remappings": []
}
[{"inputs":[{"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_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":[],"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":[],"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":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"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":[],"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":"uint64","name":"","type":"uint64"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"signer","type":"address"}],"name":"signers","outputs":[{"internalType":"bool","name":"active","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"}]