// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)pragmasolidity ^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.
*/abstractcontractContext{
function_msgSender() internalviewvirtualreturns (address) {
returnmsg.sender;
}
function_msgData() internalviewvirtualreturns (bytescalldata) {
returnmsg.data;
}
function_contextSuffixLength() internalviewvirtualreturns (uint256) {
return0;
}
}
Contract Source Code
File 2 of 25: ERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/ERC20.sol)pragmasolidity ^0.8.0;import"./IERC20.sol";
import"./extensions/IERC20Metadata.sol";
import"../../utils/Context.sol";
/**
* @dev Implementation of the {IERC20} interface.
*
* This implementation is agnostic to the way tokens are created. This means
* that a supply mechanism has to be added in a derived contract using {_mint}.
* For a generic mechanism see {ERC20PresetMinterPauser}.
*
* TIP: For a detailed writeup see our guide
* https://forum.openzeppelin.com/t/how-to-implement-erc20-supply-mechanisms/226[How
* to implement supply mechanisms].
*
* The default value of {decimals} is 18. To change this, you should override
* this function so it returns a different value.
*
* We have followed general OpenZeppelin Contracts guidelines: functions revert
* instead returning `false` on failure. This behavior is nonetheless
* conventional and does not conflict with the expectations of ERC20
* applications.
*
* Additionally, an {Approval} event is emitted on calls to {transferFrom}.
* This allows applications to reconstruct the allowance for all accounts just
* by listening to said events. Other implementations of the EIP may not emit
* these events, as it isn't required by the specification.
*
* Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
* functions have been added to mitigate the well-known issues around setting
* allowances. See {IERC20-approve}.
*/contractERC20isContext, IERC20, IERC20Metadata{
mapping(address=>uint256) private _balances;
mapping(address=>mapping(address=>uint256)) private _allowances;
uint256private _totalSupply;
stringprivate _name;
stringprivate _symbol;
/**
* @dev Sets the values for {name} and {symbol}.
*
* All two of these values are immutable: they can only be set once during
* construction.
*/constructor(stringmemory name_, stringmemory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev Returns the name of the token.
*/functionname() publicviewvirtualoverridereturns (stringmemory) {
return _name;
}
/**
* @dev Returns the symbol of the token, usually a shorter version of the
* name.
*/functionsymbol() publicviewvirtualoverridereturns (stringmemory) {
return _symbol;
}
/**
* @dev Returns the number of decimals used to get its user representation.
* For example, if `decimals` equals `2`, a balance of `505` tokens should
* be displayed to a user as `5.05` (`505 / 10 ** 2`).
*
* Tokens usually opt for a value of 18, imitating the relationship between
* Ether and Wei. This is the default value returned by this function, unless
* it's overridden.
*
* NOTE: This information is only used for _display_ purposes: it in
* no way affects any of the arithmetic of the contract, including
* {IERC20-balanceOf} and {IERC20-transfer}.
*/functiondecimals() publicviewvirtualoverridereturns (uint8) {
return18;
}
/**
* @dev See {IERC20-totalSupply}.
*/functiontotalSupply() publicviewvirtualoverridereturns (uint256) {
return _totalSupply;
}
/**
* @dev See {IERC20-balanceOf}.
*/functionbalanceOf(address account) publicviewvirtualoverridereturns (uint256) {
return _balances[account];
}
/**
* @dev See {IERC20-transfer}.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - the caller must have a balance of at least `amount`.
*/functiontransfer(address to, uint256 amount) publicvirtualoverridereturns (bool) {
address owner = _msgSender();
_transfer(owner, to, amount);
returntrue;
}
/**
* @dev See {IERC20-allowance}.
*/functionallowance(address owner, address spender) publicviewvirtualoverridereturns (uint256) {
return _allowances[owner][spender];
}
/**
* @dev See {IERC20-approve}.
*
* NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on
* `transferFrom`. This is semantically equivalent to an infinite approval.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionapprove(address spender, uint256 amount) publicvirtualoverridereturns (bool) {
address owner = _msgSender();
_approve(owner, spender, amount);
returntrue;
}
/**
* @dev See {IERC20-transferFrom}.
*
* Emits an {Approval} event indicating the updated allowance. This is not
* required by the EIP. See the note at the beginning of {ERC20}.
*
* NOTE: Does not update the allowance if the current allowance
* is the maximum `uint256`.
*
* Requirements:
*
* - `from` and `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
* - the caller must have allowance for ``from``'s tokens of at least
* `amount`.
*/functiontransferFrom(addressfrom, address to, uint256 amount) publicvirtualoverridereturns (bool) {
address spender = _msgSender();
_spendAllowance(from, spender, amount);
_transfer(from, to, amount);
returntrue;
}
/**
* @dev Atomically increases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
*/functionincreaseAllowance(address spender, uint256 addedValue) publicvirtualreturns (bool) {
address owner = _msgSender();
_approve(owner, spender, allowance(owner, spender) + addedValue);
returntrue;
}
/**
* @dev Atomically decreases the allowance granted to `spender` by the caller.
*
* This is an alternative to {approve} that can be used as a mitigation for
* problems described in {IERC20-approve}.
*
* Emits an {Approval} event indicating the updated allowance.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `spender` must have allowance for the caller of at least
* `subtractedValue`.
*/functiondecreaseAllowance(address spender, uint256 subtractedValue) publicvirtualreturns (bool) {
address owner = _msgSender();
uint256 currentAllowance = allowance(owner, spender);
require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
unchecked {
_approve(owner, spender, currentAllowance - subtractedValue);
}
returntrue;
}
/**
* @dev Moves `amount` of tokens from `from` to `to`.
*
* This internal function is equivalent to {transfer}, and can be used to
* e.g. implement automatic token fees, slashing mechanisms, etc.
*
* Emits a {Transfer} event.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `from` must have a balance of at least `amount`.
*/function_transfer(addressfrom, address to, uint256 amount) internalvirtual{
require(from!=address(0), "ERC20: transfer from the zero address");
require(to !=address(0), "ERC20: transfer to the zero address");
_beforeTokenTransfer(from, to, amount);
uint256 fromBalance = _balances[from];
require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
unchecked {
_balances[from] = fromBalance - amount;
// Overflow not possible: the sum of all balances is capped by totalSupply, and the sum is preserved by// decrementing then incrementing.
_balances[to] += amount;
}
emit Transfer(from, to, amount);
_afterTokenTransfer(from, to, amount);
}
/** @dev Creates `amount` tokens and assigns them to `account`, increasing
* the total supply.
*
* Emits a {Transfer} event with `from` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
*/function_mint(address account, uint256 amount) internalvirtual{
require(account !=address(0), "ERC20: mint to the zero address");
_beforeTokenTransfer(address(0), account, amount);
_totalSupply += amount;
unchecked {
// Overflow not possible: balance + amount is at most totalSupply + amount, which is checked above.
_balances[account] += amount;
}
emit Transfer(address(0), account, amount);
_afterTokenTransfer(address(0), account, amount);
}
/**
* @dev Destroys `amount` tokens from `account`, reducing the
* total supply.
*
* Emits a {Transfer} event with `to` set to the zero address.
*
* Requirements:
*
* - `account` cannot be the zero address.
* - `account` must have at least `amount` tokens.
*/function_burn(address account, uint256 amount) internalvirtual{
require(account !=address(0), "ERC20: burn from the zero address");
_beforeTokenTransfer(account, address(0), amount);
uint256 accountBalance = _balances[account];
require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
unchecked {
_balances[account] = accountBalance - amount;
// Overflow not possible: amount <= accountBalance <= totalSupply.
_totalSupply -= amount;
}
emit Transfer(account, address(0), amount);
_afterTokenTransfer(account, address(0), amount);
}
/**
* @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens.
*
* This internal function is equivalent to `approve`, and can be used to
* e.g. set automatic allowances for certain subsystems, etc.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `owner` cannot be the zero address.
* - `spender` cannot be the zero address.
*/function_approve(address owner, address spender, uint256 amount) internalvirtual{
require(owner !=address(0), "ERC20: approve from the zero address");
require(spender !=address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
/**
* @dev Updates `owner` s allowance for `spender` based on spent `amount`.
*
* Does not update the allowance amount in case of infinite allowance.
* Revert if not enough allowance is available.
*
* Might emit an {Approval} event.
*/function_spendAllowance(address owner, address spender, uint256 amount) internalvirtual{
uint256 currentAllowance = allowance(owner, spender);
if (currentAllowance !=type(uint256).max) {
require(currentAllowance >= amount, "ERC20: insufficient allowance");
unchecked {
_approve(owner, spender, currentAllowance - amount);
}
}
}
/**
* @dev Hook that is called before any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* will be transferred to `to`.
* - when `from` is zero, `amount` tokens will be minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_beforeTokenTransfer(addressfrom, address to, uint256 amount) internalvirtual{}
/**
* @dev Hook that is called after any transfer of tokens. This includes
* minting and burning.
*
* Calling conditions:
*
* - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens
* has been transferred to `to`.
* - when `from` is zero, `amount` tokens have been minted for `to`.
* - when `to` is zero, `amount` of ``from``'s tokens have been burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/function_afterTokenTransfer(addressfrom, address to, uint256 amount) internalvirtual{}
}
// SPDX-License-Identifier: MIT OR Apache-2.0pragmasolidity >=0.7.6;libraryExcessivelySafeCall{
uint256constant LOW_28_MASK =0x00000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
/// @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 _value The value in wei to send 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.functionexcessivelySafeCall(address _target,
uint256 _gas,
uint256 _value,
uint16 _maxCopy,
bytesmemory _calldata
) internalreturns (bool, bytesmemory) {
// set up for assembly calluint256 _toCopy;
bool _success;
bytesmemory _returnData =newbytes(_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 contractassembly {
_success :=call(
_gas, // gas
_target, // recipient
_value, // ether valueadd(_calldata, 0x20), // inlocmload(_calldata), // inlen0, // outloc0// outlen
)
// limit our copy to 256 bytes
_toCopy :=returndatasize()
ifgt(_toCopy, _maxCopy) {
_toCopy := _maxCopy
}
// Store the length of the copied bytesmstore(_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.functionexcessivelySafeStaticCall(address _target,
uint256 _gas,
uint16 _maxCopy,
bytesmemory _calldata
) internalviewreturns (bool, bytesmemory) {
// set up for assembly calluint256 _toCopy;
bool _success;
bytesmemory _returnData =newbytes(_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 contractassembly {
_success :=staticcall(
_gas, // gas
_target, // recipientadd(_calldata, 0x20), // inlocmload(_calldata), // inlen0, // outloc0// outlen
)
// limit our copy to 256 bytes
_toCopy :=returndatasize()
ifgt(_toCopy, _maxCopy) {
_toCopy := _maxCopy
}
// Store the length of the copied bytesmstore(_returnData, _toCopy)
// copy the bytes from returndata[0:_toCopy]returndatacopy(add(_returnData, 0x20), 0, _toCopy)
}
return (_success, _returnData);
}
/**
* @notice Swaps function selectors in encoded contract calls
* @dev Allows reuse of encoded calldata for functions with identical
* argument types but different names. It simply swaps out the first 4 bytes
* for the new selector. This function modifies memory in place, and should
* only be used with caution.
* @param _newSelector The new 4-byte selector
* @param _buf The encoded contract args
*/functionswapSelector(bytes4 _newSelector, bytesmemory _buf) internalpure{
require(_buf.length>=4);
uint256 _mask = LOW_28_MASK;
assembly {
// load the first word oflet _word :=mload(add(_buf, 0x20))
// mask out the top 4 bytes// /x
_word :=and(_word, _mask)
_word :=or(_newSelector, _word)
mstore(add(_buf, 0x20), _word)
}
}
}
Contract Source Code
File 5 of 25: IERC20.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)pragmasolidity ^0.8.0;/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/interfaceIERC20{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed 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.
*/eventApproval(addressindexed owner, addressindexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (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.
*/functiontransfer(address to, uint256 amount) externalreturns (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.
*/functionallowance(address owner, address spender) externalviewreturns (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.
*/functionapprove(address spender, uint256 amount) externalreturns (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.
*/functiontransferFrom(addressfrom, address to, uint256 amount) externalreturns (bool);
}
Contract Source Code
File 6 of 25: IERC20Metadata.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol)pragmasolidity ^0.8.0;import"../IERC20.sol";
/**
* @dev Interface for the optional metadata functions from the ERC20 standard.
*
* _Available since v4.1._
*/interfaceIERC20MetadataisIERC20{
/**
* @dev Returns the name of the token.
*/functionname() externalviewreturns (stringmemory);
/**
* @dev Returns the symbol of the token.
*/functionsymbol() externalviewreturns (stringmemory);
/**
* @dev Returns the decimals places of the token.
*/functiondecimals() externalviewreturns (uint8);
}
Contract Source Code
File 7 of 25: IMessageChannel.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.23;import {IMessageStruct} from"./IMessageStruct.sol";
interfaceIMessageChannelisIMessageStruct{
/*
/// @notice LaunchPad is the function that user or DApps send omni-chain message to other chain
/// Once the message is sent, the Relay will validate the message and send it to the target chain
/// @dev 1. we will call the LaunchPad.Launch function to emit the message
/// @dev 2. the message will be sent to the destination chain
/// @param earliestArrivalTimestamp The earliest arrival time for the message
/// set to 0, vizing will forward the information ASAP.
/// @param latestArrivalTimestamp The latest arrival time for the message
/// set to 0, vizing will forward the information ASAP.
/// @param relayer the specify relayer for your message
/// set to 0, all the relayers will be able to forward the message
/// @param sender The sender address for the message
/// most likely the address of the EOA, the user of some DApps
/// @param value native token amount, will be sent to the target contract
/// @param destChainid The destination chain id for the message
/// @param additionParams The addition params for the message
/// if not in expert mode, set to 0 (`new bytes(0)`)
/// @param message Arbitrary information
///
/// bytes
/// message = abi.encodePacked(
/// byte1 uint256 uint24 uint64 bytes
/// messageType, activateContract, executeGasLimit, maxFeePerGas, signature
/// )
///
*/functionLaunch(uint64 earliestArrivalTimestamp,
uint64 latestArrivalTimestamp,
address relayer,
address sender,
uint256 value,
uint64 destChainid,
bytescalldata additionParams,
bytescalldata message
) externalpayable;
////// bytes byte1 uint256 uint24 uint64 bytes/// message = abi.encodePacked(messageType, activateContract, executeGasLimit, maxFeePerGas, signature)///functionlaunchMultiChain(
launchEnhanceParams calldata params
) externalpayable;
/// @notice batch landing message to the chain, execute the landing message/// @dev trusted relayer will call this function to send omni-chain message to the Station/// @param params the landing message params/// @param proofs the proof of the validated messagefunctionLanding(
landingParams[] calldata params,
bytes[][] calldata proofs
) externalpayable;
/// @notice similar to the Landing function, but with gasLimitfunctionLandingSpecifiedGas(
landingParams[] calldata params,
uint24 gasLimit,
bytes[][] calldata proofs
) externalpayable;
/// @dev feel free to call this function before pass message to the Station,/// this method will return the protocol fee that the message need to pay, longer message will pay morefunctionestimateGas(uint256[] calldata value,
uint64[] calldata destChainid,
bytes[] calldata additionParams,
bytes[] calldata message
) externalviewreturns (uint256);
functionestimateGas(uint256 value,
uint64 destChainid,
bytescalldata additionParams,
bytescalldata message
) externalviewreturns (uint256);
functionestimatePrice(address sender,
uint64 destChainid
) externalviewreturns (uint64);
functiongasSystemAddr() externalviewreturns (address);
/// @dev get the message launch nonce of the sender on the specific chain/// @param chainId the chain id of the sender/// @param sender the address of the senderfunctionGetNonceLaunch(uint64 chainId,
address sender
) externalviewreturns (uint32);
/// @dev get the message landing nonce of the sender on the specific chain/// @param chainId the chain id of the sender/// @param sender the address of the senderfunctionGetNonceLanding(uint64 chainId,
address sender
) externalviewreturns (uint32);
/// @dev get the version of the Station/// @return the version of the Station, like "v1.0.0"functionVersion() externalviewreturns (stringmemory);
/// @dev get the chainId of current Station/// @return chainId, defined in the L2SupportLib.solfunctionChainid() externalviewreturns (uint64);
functionminArrivalTime() externalviewreturns (uint64);
functionmaxArrivalTime() externalviewreturns (uint64);
functionexpertLandingHook(bytes1 hook) externalviewreturns (address);
functionexpertLaunchHook(bytes1 hook) externalviewreturns (address);
}
Contract Source Code
File 8 of 25: IMessageDashboard.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.23;import {IMessageStruct} from"./IMessageStruct.sol";
interfaceIMessageDashboardisIMessageStruct{
/// @dev Only owner can call this function to stop or restart the engine/// @param stop true is stop, false is startfunctionPauseEngine(bool stop) external;
/// @notice return the states of the engine/// @return 0x01 is stop, 0x02 is startfunctionengineState() externalviewreturns (uint8);
/// @notice return the states of the engine & Landing PadfunctionpadState() externalviewreturns (uint8, uint8);
// function mptRoot() external view returns (bytes32);/// @dev withdraw the protocol fee from the contract, only owner can call this function/// @param amount the amount of the withdraw protocol feefunctionWithdraw(uint256 amount, address to) external;
/// @dev set the payment system address, only owner can call this function/// @param gasSystemAddress the address of the payment systemfunctionsetGasSystem(address gasSystemAddress) external;
functionsetExpertLaunchHooks(bytes1[] calldata ids,
address[] calldata hooks
) external;
functionsetExpertLandingHooks(bytes1[] calldata ids,
address[] calldata hooks
) external;
/// notice reset the permission of the contract, only owner can call this functionfunctionroleConfiguration(bytes32 role,
address[] calldata accounts,
bool[] calldata states
) external;
functionstationAdminSetRole(bytes32 role,
address[] calldata accounts,
bool[] calldata states
) external;
/// @notice transfer the ownership of the contract, only owner can call this functionfunctiontransferOwnership(address newOwner) external;
}
// SPDX-License-Identifier: MITpragmasolidity ^0.8.23;import {IMessageStruct} from"./IMessageStruct.sol";
interfaceIMessageSimulationisIMessageStruct{
/// @dev for sequencer to simulate the landing message, call this function before call Landing/// @param params the landing message params/// check the revert message "SimulateResult" to get the result of the simulation/// for example, if the result is [true, false, true], it means the first and third message is valid, the second message is invalidfunctionSimulateLanding(landingParams[] calldata params) externalpayable;
/// @dev call this function off-chain to estimate the gas of excute the landing message/// @param params the landing message params/// @return the result of the estimation, true is valid, false is invalidfunctionEstimateExecuteGas(
landingParams[] calldata params
) externalreturns (bool[] memory);
}
// SPDX-License-Identifier: MITpragmasolidity ^0.8.23;interfaceIVizingGasSystemChannel{
/*
/// @notice Estimate how many native token we should spend to exchange the amountOut in the destChainid
/// @param destChainid The chain id of the destination chain
/// @param amountOut The value we want to receive in the destination chain
/// @return amountIn the native token amount on the source chain we should spend
*/functionexactOutput(uint64 destChainid,
uint256 amountOut
) externalviewreturns (uint256 amountIn);
/*
/// @notice Estimate how many native token we could get in the destChainid if we input the amountIn
/// @param destChainid The chain id of the destination chain
/// @param amountIn The value we spent in the source chain
/// @return amountOut the native token amount the destination chain will receive
*/functionexactInput(uint64 destChainid,
uint256 amountIn
) externalviewreturns (uint256 amountOut);
/*
/// @notice Estimate the gas fee we should pay to vizing
/// @param destChainid The chain id of the destination chain
/// @param message The message we want to send to the destination chain
*/functionestimateGas(uint256 amountOut,
uint64 destChainid,
bytescalldata message
) externalviewreturns (uint256);
/*
/// @notice Estimate the gas fee & native token we should pay to vizing
/// @param amountOut amountOut in the destination chain
/// @param destChainid The chain id of the destination chain
/// @param message The message we want to send to the destination chain
*/functionbatchEstimateTotalFee(uint256[] calldata amountOut,
uint64[] calldata destChainid,
bytes[] calldata message
) externalviewreturns (uint256 totalFee);
/*
/// @notice Estimate the total fee we should pay to vizing
/// @param value The value we spent in the source chain
/// @param destChainid The chain id of the destination chain
/// @param message The message we want to send to the destination chain
*/functionestimateTotalFee(uint256 value,
uint64 destChainid,
bytescalldata message
) externalviewreturns (uint256 totalFee);
/*
/// @notice Estimate the gas price we need to encode in message
/// @param sender most likely the address of the DApp, which forward the message from user
/// @param destChainid The chain id of the destination chain
*/functionestimatePrice(address targetContract,
uint64 destChainid
) externalviewreturns (uint64);
/*
/// @notice Estimate the gas price we need to encode in message
/// @param destChainid The chain id of the destination chain
*/functionestimatePrice(uint64 destChainid) externalviewreturns (uint64);
/*
/// @notice Calculate the fee for the native token transfer
/// @param amount The value we spent in the source chain
*/functioncomputeTradeFee(uint64 destChainid,
uint256 amountOut
) externalviewreturns (uint256 fee);
/*
/// @notice Calculate the fee for the native token transfer
/// @param amount The value we spent in the source chain
*/functioncomputeTradeFee(address targetContract,
uint64 destChainid,
uint256 amountOut
) externalviewreturns (uint256 fee);
}
Contract Source Code
File 16 of 25: MessageEmitter.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.23;import {IMessageStruct} from"./interface/IMessageStruct.sol";
import {IMessageChannel} from"./interface/IMessageChannel.sol";
import {IMessageEmitter} from"./interface/IMessageEmitter.sol";
import {IMessageReceiver} from"./interface/IMessageReceiver.sol";
import {IVizingGasSystemChannel} from"./interface/IVizingGasSystemChannel.sol";
abstractcontractMessageEmitterisIMessageEmitter{
/// @dev bellow are the default parameters for the OmniToken,/// we **Highly recommended** to use immutable variables to store these parameters/// @notice minArrivalTime the minimal arrival timestamp for the omni-chain message/// @notice maxArrivalTime the maximal arrival timestamp for the omni-chain message/// @notice minGasLimit the minimal gas limit for target chain execute omni-chain message/// @notice maxGasLimit the maximal gas limit for target chain execute omni-chain message/// @notice defaultBridgeMode the default mode for the omni-chain message,/// in OmniToken, we use MessageTypeLib.ARBITRARY_ACTIVATE (0x02), target chain will **ACTIVATE** the message/// @notice selectedRelayer the specify relayer for your message/// set to 0, all the relayers will be able to forward the message/// see https://docs.vizing.com/docs/BuildOnVizing/ContractfunctionminArrivalTime() externalviewvirtualoverridereturns (uint64) {}
functionmaxArrivalTime() externalviewvirtualoverridereturns (uint64) {}
functionminGasLimit() externalviewvirtualoverridereturns (uint24) {}
functionmaxGasLimit() externalviewvirtualoverridereturns (uint24) {}
functiondefaultBridgeMode()
externalviewvirtualoverridereturns (bytes1)
{}
functionselectedRelayer()
externalviewvirtualoverridereturns (address)
{}
IMessageChannel public LaunchPad;
constructor(address _LaunchPad) {
__LaunchPadInit(_LaunchPad);
}
/*
/// rewrite set LaunchPad address function
/// @notice call this function to reset the LaunchPad contract address
/// @param _LaunchPad The new LaunchPad contract address
*/function__LaunchPadInit(address _LaunchPad) internalvirtual{
LaunchPad = IMessageChannel(_LaunchPad);
}
/*
/// @notice call this function to packet the message before sending it to the LandingPad contract
/// @param mode the emitter mode, check MessageTypeLib.sol for more details
/// eg: 0x02 for ARBITRARY_ACTIVATE, your message will be activated on the target chain
/// @param gasLimit the gas limit for executing the specific function on the target contract
/// @param targetContract the target contract address on the destination chain
/// @param message the message to be sent to the target contract
/// @return the packed message
/// see https://docs.vizing.com/docs/BuildOnVizing/Contract
*/function_packetMessage(bytes1 mode,
address targetContract,
uint24 gasLimit,
uint64 price,
bytesmemory message
) internalpurereturns (bytesmemory) {
returnabi.encodePacked(
mode,
uint256(uint160(targetContract)),
gasLimit,
price,
message
);
}
/*
/// @notice use this function to send the ERC20 token to the destination chain
/// @param tokenSymbol The token symbol
/// @param sender The sender address for the message
/// @param receiver The receiver address for the message
/// @param amount The amount of tokens to be sent
/// see https://docs.vizing.com/docs/DApp/Omni-ERC20-Transfer
*/function_packetAdditionParams(bytes1 mode,
bytes1 tokenSymbol,
address sender,
address receiver,
uint256 amount
) internalpurereturns (bytesmemory) {
returnabi.encodePacked(mode, tokenSymbol, sender, receiver, amount);
}
/*
/// @notice Calculate the amount of native tokens obtained on the target chain
/// @param value The value we send to vizing on the source chain
*/function_computeTradeFee(uint64 destChainid,
uint256 value
) internalviewreturns (uint256 amountIn) {
return
IVizingGasSystemChannel(LaunchPad.gasSystemAddr()).computeTradeFee(
destChainid,
value
);
}
/*
/// @notice Fetch the nonce of the user with specific destination chain
/// @param destChainid The chain id of the destination chain
/// see https://docs.vizing.com/docs/BuildOnVizing/Contract
*/function_fetchNonce(uint64 destChainid
) internalviewvirtualreturns (uint32 nonce) {
nonce = LaunchPad.GetNonceLaunch(destChainid, msg.sender);
}
/*
/// @notice Estimate the gas price we need to encode in message
/// @param destChainid The chain id of the destination chain
/// see https://docs.vizing.com/docs/BuildOnVizing/Contract
*/function_fetchPrice(uint64 destChainid
) internalviewvirtualreturns (uint64) {
return
IVizingGasSystemChannel(LaunchPad.gasSystemAddr()).estimatePrice(
destChainid
);
}
/*
/// @notice Estimate the gas price we need to encode in message
/// @param targetContract The target contract address on the destination chain
/// @param destChainid The chain id of the destination chain
/// see https://docs.vizing.com/docs/BuildOnVizing/Contract
*/function_fetchPrice(address targetContract,
uint64 destChainid
) internalviewvirtualreturns (uint64) {
return
IVizingGasSystemChannel(LaunchPad.gasSystemAddr()).estimatePrice(
targetContract,
destChainid
);
}
/*
/// @notice similar to uniswap Swap Router
/// @notice Estimate how many native token we should spend to exchange the amountOut in the destChainid
/// @param destChainid The chain id of the destination chain
/// @param amountOut The value we want to exchange in the destination chain
/// @return amountIn the native token amount on the source chain we should spend
/// see https://docs.vizing.com/docs/BuildOnVizing/Contract
*/function_exactOutput(uint64 destChainid,
uint256 amountOut
) internalviewreturns (uint256 amountIn) {
return
IVizingGasSystemChannel(LaunchPad.gasSystemAddr()).exactOutput(
destChainid,
amountOut
);
}
/*
/// @notice similar to uniswap Swap Router
/// @notice Estimate how many native token we could get in the destChainid if we input the amountIn
/// @param destChainid The chain id of the destination chain
/// @param amountIn The value we spent in the source chain
/// @return amountOut the native token amount the destination chain will receive
/// see https://docs.vizing.com/docs/BuildOnVizing/Contract
*/function_exactInput(uint64 destChainid,
uint256 amountIn
) internalviewreturns (uint256 amountOut) {
return
IVizingGasSystemChannel(LaunchPad.gasSystemAddr()).exactInput(
destChainid,
amountIn
);
}
/*
/// @notice Estimate the gas price we need to encode in message
/// @param value The native token that value target address will receive in the destination chain
/// @param destChainid The chain id of the destination chain
/// @param additionParams The addition params for the message
/// if not in expert mode, set to 0 (`new bytes(0)`)
/// @param message The message we want to send to the destination chain
/// see https://docs.vizing.com/docs/BuildOnVizing/Contract
*/function_estimateVizingGasFee(uint256 value,
uint64 destChainid,
bytesmemory additionParams,
bytesmemory message
) internalviewreturns (uint256 vizingGasFee) {
return
LaunchPad.estimateGas(value, destChainid, additionParams, message);
}
/*
/// @notice **Highly recommend** to call this function in your frontend program
/// @notice Estimate the gas price we need to encode in message
/// @param value The native token that value target address will receive in the destination chain
/// @param destChainid The chain id of the destination chain
/// @param additionParams The addition params for the message
/// if not in expert mode, set to 0 (`new bytes(0)`)
/// @param message The message we want to send to the destination chain
/// see https://docs.vizing.com/docs/BuildOnVizing/Contract
*/functionestimateVizingGasFee(uint256 value,
uint64 destChainid,
bytescalldata additionParams,
bytescalldata message
) externalviewreturns (uint256 vizingGasFee) {
return
_estimateVizingGasFee(value, destChainid, additionParams, message);
}
}
Contract Source Code
File 17 of 25: MessageReceiver.sol
// SPDX-License-Identifier: MITpragmasolidity ^0.8.23;import {IMessageChannel} from"./interface/IMessageChannel.sol";
import {IMessageReceiver} from"./interface/IMessageReceiver.sol";
abstractcontractMessageReceiverisIMessageReceiver{
errorLandingPadAccessDenied();
errorNotImplement();
IMessageChannel public LandingPad;
modifieronlyVizingPad() {
if (msg.sender!=address(LandingPad)) revert LandingPadAccessDenied();
_;
}
constructor(address _LandingPad) {
__LandingPadInit(_LandingPad);
}
/*
/// rewrite set LandingPad address function
/// @notice call this function to reset the LaunchPad contract address
/// @param _LaunchPad The new LaunchPad contract address
*/function__LandingPadInit(address _LandingPad) internalvirtual{
LandingPad = IMessageChannel(_LandingPad);
}
/// @notice the standard function to receive the omni-chain messagefunctionreceiveStandardMessage(uint64 srcChainId,
uint256 srcContract,
bytescalldata message
) externalpayablevirtualoverrideonlyVizingPad{
_receiveMessage(srcChainId, srcContract, message);
}
/// @dev override this function to handle the omni-chain message/// @param srcChainId the source chain id/// @param srcContract the source contract address/// @param message the message from the source chainfunction_receiveMessage(uint64 srcChainId,
uint256 srcContract,
bytescalldata message
) internalvirtual{
(srcChainId, srcContract, message);
revert NotImplement();
}
}
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)pragmasolidity ^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.
*/abstractcontractOwnableisContext{
addressprivate _owner;
eventOwnershipTransferred(addressindexed previousOwner, addressindexed 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.
*/modifieronlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/functionowner() publicviewvirtualreturns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/function_checkOwner() internalviewvirtual{
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.
*/functionrenounceOwnership() publicvirtualonlyOwner{
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/functiontransferOwnership(address newOwner) publicvirtualonlyOwner{
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) internalvirtual{
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
Contract Source Code
File 21 of 25: Pausable.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)pragmasolidity ^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.
*/abstractcontractPausableisContext{
/**
* @dev Emitted when the pause is triggered by `account`.
*/eventPaused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/eventUnpaused(address account);
boolprivate _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.
*/modifierwhenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/modifierwhenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/functionpaused() publicviewvirtualreturns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/function_requireNotPaused() internalviewvirtual{
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/function_requirePaused() internalviewvirtual{
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/function_pause() internalvirtualwhenNotPaused{
_paused =true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/function_unpause() internalvirtualwhenPaused{
_paused =false;
emit Unpaused(_msgSender());
}
}
Contract Source Code
File 22 of 25: ReentrancyGuard.sol
// SPDX-License-Identifier: MIT// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)pragmasolidity ^0.8.0;/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/abstractcontractReentrancyGuard{
// Booleans are more expensive than uint256 or any type that takes up a full// word because each write operation emits an extra SLOAD to first read the// slot's contents, replace the bits taken up by the boolean, and then write// back. This is the compiler's defense against contract upgrades and// pointer aliasing, and it cannot be disabled.// The values being non-zero value makes deployment a bit more expensive,// but in exchange the refund on every call to nonReentrant will be lower in// amount. Since refunds are capped to a percentage of the total// transaction's gas, it is best to keep them low in cases like this one, to// increase the likelihood of the full refund coming into effect.uint256privateconstant _NOT_ENTERED =1;
uint256privateconstant _ENTERED =2;
uint256private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/modifiernonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function_nonReentrantBefore() private{
// On the first call to nonReentrant, _status will be _NOT_ENTEREDrequire(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function_nonReentrantAfter() private{
// By storing the original value once again, a refund is triggered (see// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/function_reentrancyGuardEntered() internalviewreturns (bool) {
return _status == _ENTERED;
}
}