编译器
0.8.24+commit.e11b9ed9
文件 1 的 15:Address.sol
pragma solidity ^0.8.20;
library Address {
error AddressInsufficientBalance(address account);
error AddressEmptyCode(address target);
error FailedInnerCall();
function sendValue(address payable recipient, uint256 amount) internal {
if (address(this).balance < amount) {
revert AddressInsufficientBalance(address(this));
}
(bool success, ) = recipient.call{value: amount}("");
if (!success) {
revert FailedInnerCall();
}
}
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0);
}
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
if (address(this).balance < value) {
revert AddressInsufficientBalance(address(this));
}
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata);
}
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata
) internal view returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
if (returndata.length == 0 && target.code.length == 0) {
revert AddressEmptyCode(target);
}
return returndata;
}
}
function verifyCallResult(bool success, bytes memory returndata) internal pure returns (bytes memory) {
if (!success) {
_revert(returndata);
} else {
return returndata;
}
}
function _revert(bytes memory returndata) private pure {
if (returndata.length > 0) {
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert FailedInnerCall();
}
}
}
文件 2 的 15:Context.sol
pragma solidity ^0.8.20;
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;
}
}
文件 3 的 15:Errors.sol
pragma solidity ^0.8.20;
contract Errors {
error NotWhitelisted(address token, uint16 targetChain);
error ChainDisabled(uint16 chainId);
error InvalidWormhole(address wh);
error InvalidTokenBridgeRelayer(address tbr);
error Unsupported();
}
文件 4 的 15:Events.sol
pragma solidity ^0.8.20;
contract Events {
event WormholeERC20DepositEvent(
address user,
address token,
uint256 amount,
uint16 targetChain,
bytes32 forwarder,
uint64 messageSequence
);
event WormholeETHDepositEvent(
address user,
uint256 amount,
uint16 targetChain,
bytes32 forwarder,
uint64 messageSequence
);
}
文件 5 的 15:IERC20.sol
pragma solidity ^0.8.20;
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 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);
}
文件 6 的 15:IERC20Permit.sol
pragma solidity ^0.8.20;
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);
}
文件 7 的 15:ITokenBridge.sol
pragma solidity ^0.8.20;
import { IWETH } from "./IWETH.sol";
import { IWormhole } from "./IWormhole.sol";
interface ITokenBridge {
struct Transfer {
uint8 payloadID;
uint256 amount;
bytes32 tokenAddress;
uint16 tokenChain;
bytes32 to;
uint16 toChain;
uint256 fee;
}
struct TransferWithPayload {
uint8 payloadID;
uint256 amount;
bytes32 tokenAddress;
uint16 tokenChain;
bytes32 to;
uint16 toChain;
bytes32 fromAddress;
bytes payload;
}
struct AssetMeta {
uint8 payloadID;
bytes32 tokenAddress;
uint16 tokenChain;
uint8 decimals;
bytes32 symbol;
bytes32 name;
}
struct RegisterChain {
bytes32 module;
uint8 action;
uint16 chainId;
uint16 emitterChainID;
bytes32 emitterAddress;
}
struct UpgradeContract {
bytes32 module;
uint8 action;
uint16 chainId;
bytes32 newContract;
}
struct RecoverChainId {
bytes32 module;
uint8 action;
uint256 evmChainId;
uint16 newChainId;
}
event ContractUpgraded(
address indexed oldContract,
address indexed newContract
);
event TransferRedeemed(
uint16 indexed emitterChainId,
bytes32 indexed emitterAddress,
uint64 indexed sequence
);
function _parseTransferCommon(
bytes memory encoded
) external pure returns (Transfer memory transfer);
function attestToken(
address tokenAddress,
uint32 nonce
) external payable returns (uint64 sequence);
function wrapAndTransferETH(
uint16 recipientChain,
bytes32 recipient,
uint256 arbiterFee,
uint32 nonce
) external payable returns (uint64 sequence);
function wrapAndTransferETHWithPayload(
uint16 recipientChain,
bytes32 recipient,
uint32 nonce,
bytes memory payload
) external payable returns (uint64 sequence);
function transferTokens(
address token,
uint256 amount,
uint16 recipientChain,
bytes32 recipient,
uint256 arbiterFee,
uint32 nonce
) external payable returns (uint64 sequence);
function transferTokensWithPayload(
address token,
uint256 amount,
uint16 recipientChain,
bytes32 recipient,
uint32 nonce,
bytes memory payload
) external payable returns (uint64 sequence);
function updateWrapped(
bytes memory encodedVm
) external returns (address token);
function createWrapped(
bytes memory encodedVm
) external returns (address token);
function completeTransferWithPayload(
bytes memory encodedVm
) external returns (bytes memory);
function completeTransferAndUnwrapETHWithPayload(
bytes memory encodedVm
) external returns (bytes memory);
function completeTransfer(bytes memory encodedVm) external;
function completeTransferAndUnwrapETH(bytes memory encodedVm) external;
function encodeAssetMeta(
AssetMeta memory meta
) external pure returns (bytes memory encoded);
function encodeTransfer(
Transfer memory transfer
) external pure returns (bytes memory encoded);
function encodeTransferWithPayload(
TransferWithPayload memory transfer
) external pure returns (bytes memory encoded);
function parsePayloadID(
bytes memory encoded
) external pure returns (uint8 payloadID);
function parseAssetMeta(
bytes memory encoded
) external pure returns (AssetMeta memory meta);
function parseTransfer(
bytes memory encoded
) external pure returns (Transfer memory transfer);
function parseTransferWithPayload(
bytes memory encoded
) external pure returns (TransferWithPayload memory transfer);
function governanceActionIsConsumed(
bytes32 hash
) external view returns (bool);
function isInitialized(address impl) external view returns (bool);
function isTransferCompleted(bytes32 hash) external view returns (bool);
function wormhole() external view returns (IWormhole);
function chainId() external view returns (uint16);
function evmChainId() external view returns (uint256);
function isFork() external view returns (bool);
function governanceChainId() external view returns (uint16);
function governanceContract() external view returns (bytes32);
function wrappedAsset(
uint16 tokenChainId,
bytes32 tokenAddress
) external view returns (address);
function bridgeContracts(uint16 chainId_) external view returns (bytes32);
function tokenImplementation() external view returns (address);
function WETH() external view returns (IWETH);
function outstandingBridged(address token) external view returns (uint256);
function isWrappedAsset(address token) external view returns (bool);
function finality() external view returns (uint8);
function implementation() external view returns (address);
function initialize() external;
function registerChain(bytes memory encodedVM) external;
function upgrade(bytes memory encodedVM) external;
function submitRecoverChainId(bytes memory encodedVM) external;
function parseRegisterChain(
bytes memory encoded
) external pure returns (RegisterChain memory chain);
function parseUpgrade(
bytes memory encoded
) external pure returns (UpgradeContract memory chain);
function parseRecoverChainId(
bytes memory encodedRecoverChainId
) external pure returns (RecoverChainId memory rci);
}
文件 8 的 15:ITokenBridgeRelayer.sol
pragma solidity ^0.8.20;
import { IWETH } from "./IWETH.sol";
import { IWormhole } from "./IWormhole.sol";
import { ITokenBridge } from "./ITokenBridge.sol";
interface ITokenBridgeRelayer {
struct TransferWithRelay {
uint8 payloadId;
uint256 targetRelayerFee;
uint256 toNativeTokenAmount;
bytes32 targetRecipient;
}
struct SwapRateUpdate {
address token;
uint256 value;
}
event TransferRedeemed(
uint16 indexed emitterChainId,
bytes32 indexed emitterAddress,
uint64 indexed sequence
);
event SwapExecuted(
address indexed recipient,
address indexed relayer,
address indexed token,
uint256 tokenAmount,
uint256 nativeAmount
);
function transferTokensWithRelay(
address token,
uint256 amount,
uint256 toNativeTokenAmount,
uint16 targetChain,
bytes32 targetRecipient,
uint32 batchId
) external payable returns (uint64 messageSequence);
function wrapAndTransferEthWithRelay(
uint256 toNativeTokenAmount,
uint16 targetChain,
bytes32 targetRecipient,
uint32 batchId
) external payable returns (uint64 messageSequence);
function completeTransferWithRelay(
bytes calldata encodedTransferMessage
) external payable;
function encodeTransferWithRelay(
TransferWithRelay memory transfer
) external pure returns (bytes memory encoded);
function decodeTransferWithRelay(
bytes memory encoded
) external pure returns (TransferWithRelay memory transfer);
function calculateMaxSwapAmountIn(
address token
) external view returns (uint256);
function calculateNativeSwapAmountOut(
address token,
uint256 toNativeAmount
) external view returns (uint256);
function bytes32ToAddress(bytes32 address_) external pure returns (address);
function updateWormholeFinality(
uint16 chainId_,
uint8 newWormholeFinality
) external;
function submitOwnershipTransferRequest(
uint16 chainId_,
address newOwner
) external;
function cancelOwnershipTransferRequest(uint16 chainId_) external;
function confirmOwnershipTransferRequest() external;
function updateOwnerAssistant(
uint16 chainId_,
address newAssistant
) external;
function updateFeeRecipient(
uint16 chainId_,
address newFeeRecipient
) external;
function updateUnwrapWethFlag(uint16 chainId_, bool unwrapWeth_) external;
function registerContract(
uint16 chainId_,
bytes32 contractAddress
) external;
function registerToken(uint16 chainId_, address token) external;
function deregisterToken(uint16 chainId_, address token) external;
function updateRelayerFee(uint16 chainId_, uint256 amount) external;
function updateRelayerFeePrecision(
uint16 chainId_,
uint256 relayerFeePrecision_
) external;
function updateSwapRate(
uint16 chainId_,
SwapRateUpdate[] calldata swapRateUpdate
) external;
function updateSwapRatePrecision(
uint16 chainId_,
uint256 swapRatePrecision_
) external;
function updateMaxNativeSwapAmount(
uint16 chainId_,
address token,
uint256 maxAmount
) external;
function setPauseForTransfers(uint16 chainId_, bool paused) external;
function owner() external view returns (address);
function pendingOwner() external view returns (address);
function ownerAssistant() external view returns (address);
function feeRecipient() external view returns (address);
function tokenBridge() external view returns (ITokenBridge);
function wormhole() external view returns (IWormhole);
function WETH() external view returns (IWETH);
function unwrapWeth() external view returns (bool);
function chainId() external view returns (uint16);
function getPaused() external view returns (bool);
function relayerFeePrecision() external view returns (uint256);
function relayerFee(uint16 chainId_) external view returns (uint256);
function calculateRelayerFee(
uint16 targetChainId,
address token,
uint8 decimals
) external view returns (uint256 feeInTokenDenomination);
function swapRatePrecision() external view returns (uint256);
function swapRate(address token) external view returns (uint256);
function nativeSwapRate(address token) external view returns (uint256);
function maxNativeSwapAmount(address token) external view returns (uint256);
function getRegisteredContract(
uint16 emitterChainId
) external view returns (bytes32);
function isAcceptedToken(address token) external view returns (bool);
function getAcceptedTokensList() external view returns (address[] memory);
}
文件 9 的 15:IWETH.sol
pragma solidity ^0.8.20;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
interface IWETH is IERC20 {
function deposit() external payable;
function withdraw(uint256 amount) external;
function balanceOf() external returns (uint256);
}
文件 10 的 15:IWormhole.sol
pragma solidity ^0.8.20;
interface IWormhole {
struct GuardianSet {
address[] keys;
uint32 expirationTime;
}
struct Signature {
bytes32 r;
bytes32 s;
uint8 v;
uint8 guardianIndex;
}
struct VM {
uint8 version;
uint32 timestamp;
uint32 nonce;
uint16 emitterChainId;
bytes32 emitterAddress;
uint64 sequence;
uint8 consistencyLevel;
bytes payload;
uint32 guardianSetIndex;
Signature[] signatures;
bytes32 hash;
}
struct ContractUpgrade {
bytes32 module;
uint8 action;
uint16 chain;
address newContract;
}
struct GuardianSetUpgrade {
bytes32 module;
uint8 action;
uint16 chain;
GuardianSet newGuardianSet;
uint32 newGuardianSetIndex;
}
struct SetMessageFee {
bytes32 module;
uint8 action;
uint16 chain;
uint256 messageFee;
}
struct TransferFees {
bytes32 module;
uint8 action;
uint16 chain;
uint256 amount;
bytes32 recipient;
}
struct RecoverChainId {
bytes32 module;
uint8 action;
uint256 evmChainId;
uint16 newChainId;
}
event LogMessagePublished(
address indexed sender,
uint64 sequence,
uint32 nonce,
bytes payload,
uint8 consistencyLevel
);
event ContractUpgraded(
address indexed oldContract,
address indexed newContract
);
event GuardianSetAdded(uint32 indexed index);
function publishMessage(
uint32 nonce,
bytes memory payload,
uint8 consistencyLevel
) external payable returns (uint64 sequence);
function initialize() external;
function parseAndVerifyVM(
bytes calldata encodedVM
) external view returns (VM memory vm, bool valid, string memory reason);
function verifyVM(
VM memory vm
) external view returns (bool valid, string memory reason);
function verifySignatures(
bytes32 hash,
Signature[] memory signatures,
GuardianSet memory guardianSet
) external pure returns (bool valid, string memory reason);
function parseVM(
bytes memory encodedVM
) external pure returns (VM memory vm);
function quorum(
uint256 numGuardians
) external pure returns (uint256 numSignaturesRequiredForQuorum);
function getGuardianSet(
uint32 index
) external view returns (GuardianSet memory);
function getCurrentGuardianSetIndex() external view returns (uint32);
function getGuardianSetExpiry() external view returns (uint32);
function governanceActionIsConsumed(
bytes32 hash
) external view returns (bool);
function isInitialized(address impl) external view returns (bool);
function chainId() external view returns (uint16);
function isFork() external view returns (bool);
function governanceChainId() external view returns (uint16);
function governanceContract() external view returns (bytes32);
function messageFee() external view returns (uint256);
function evmChainId() external view returns (uint256);
function nextSequence(address emitter) external view returns (uint64);
function parseContractUpgrade(
bytes memory encodedUpgrade
) external pure returns (ContractUpgrade memory cu);
function parseGuardianSetUpgrade(
bytes memory encodedUpgrade
) external pure returns (GuardianSetUpgrade memory gsu);
function parseSetMessageFee(
bytes memory encodedSetMessageFee
) external pure returns (SetMessageFee memory smf);
function parseTransferFees(
bytes memory encodedTransferFees
) external pure returns (TransferFees memory tf);
function parseRecoverChainId(
bytes memory encodedRecoverChainId
) external pure returns (RecoverChainId memory rci);
function submitContractUpgrade(bytes memory _vm) external;
function submitSetMessageFee(bytes memory _vm) external;
function submitNewGuardianSet(bytes memory _vm) external;
function submitTransferFees(bytes memory _vm) external;
function submitRecoverChainId(bytes memory _vm) external;
}
文件 11 的 15:Ownable.sol
pragma solidity ^0.8.20;
import {Context} from "../utils/Context.sol";
abstract contract Ownable is Context {
address private _owner;
error OwnableUnauthorizedAccount(address account);
error OwnableInvalidOwner(address owner);
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
constructor(address initialOwner) {
if (initialOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(initialOwner);
}
modifier onlyOwner() {
_checkOwner();
_;
}
function owner() public view virtual returns (address) {
return _owner;
}
function _checkOwner() internal view virtual {
if (owner() != _msgSender()) {
revert OwnableUnauthorizedAccount(_msgSender());
}
}
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
function transferOwnership(address newOwner) public virtual onlyOwner {
if (newOwner == address(0)) {
revert OwnableInvalidOwner(address(0));
}
_transferOwnership(newOwner);
}
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
文件 12 的 15:ReentrancyGuard.sol
pragma solidity ^0.8.20;
abstract contract ReentrancyGuard {
uint256 private constant NOT_ENTERED = 1;
uint256 private constant ENTERED = 2;
uint256 private _status;
error ReentrancyGuardReentrantCall();
constructor() {
_status = NOT_ENTERED;
}
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
if (_status == ENTERED) {
revert ReentrancyGuardReentrantCall();
}
_status = ENTERED;
}
function _nonReentrantAfter() private {
_status = NOT_ENTERED;
}
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == ENTERED;
}
}
文件 13 的 15:RizeWormholeV1.sol
pragma solidity ^0.8.20;
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
import { ReentrancyGuard } from "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import { IWormhole } from "./interfaces/IWormhole.sol";
import { ITokenBridgeRelayer } from "./interfaces/ITokenBridgeRelayer.sol";
import { Storage } from "./Storage.sol";
import { Events } from "./Events.sol";
import { Errors } from "./Errors.sol";
contract RizeWormholeV1 is Ownable, ReentrancyGuard, Storage {
constructor(address wh, address tbr) Ownable(msg.sender) {
if (wh == address(0)) {
revert Errors.InvalidWormhole(wh);
}
if (tbr == address(0)) {
revert Errors.InvalidTokenBridgeRelayer(tbr);
}
_wormhole = wh;
_tokenBridgeRelayer = tbr;
}
function depositETH(
uint16 targetChain
) external payable nonReentrant returns (uint64 messageSequence) {
bytes32 forwarder = forwarderByChainId(targetChain);
messageSequence = tokenBridgeRelayer().wrapAndTransferEthWithRelay{
value: msg.value
}(0, targetChain, forwarder, 0);
emit Events.WormholeETHDepositEvent(
msg.sender,
msg.value,
targetChain,
forwarder,
messageSequence
);
}
function depositToken(
address token,
uint256 amount,
uint16 targetChain
) external nonReentrant returns (uint64 messageSequence) {
if (!isTokenWhitelisted(token, targetChain)) {
revert Errors.NotWhitelisted(token, targetChain);
}
bytes32 forwarder = forwarderByChainId(targetChain);
SafeERC20.safeTransferFrom(
IERC20(token),
msg.sender,
address(this),
amount
);
SafeERC20.safeIncreaseAllowance(
IERC20(token),
address(tokenBridgeRelayer()),
amount
);
messageSequence = tokenBridgeRelayer().transferTokensWithRelay(
token,
amount,
0,
targetChain,
forwarder,
0
);
emit Events.WormholeERC20DepositEvent(
msg.sender,
token,
amount,
targetChain,
forwarder,
messageSequence
);
}
function wormhole() public view returns (IWormhole) {
return IWormhole(_wormhole);
}
function tokenBridgeRelayer() public view returns (ITokenBridgeRelayer) {
return ITokenBridgeRelayer(_tokenBridgeRelayer);
}
function isTokenWhitelisted(
address token,
uint16 whChainId
) public view returns (bool) {
return _tokens[token] && _targetChains[whChainId];
}
function isChainEnabled(uint16 whChainId) public view returns (bool) {
return _targetChains[whChainId];
}
function forwarderByChainId(
uint16 whChainId
) public view returns (bytes32) {
if (!isChainEnabled(whChainId)) {
revert Errors.ChainDisabled(whChainId);
}
bytes32 forwarder = _forwarders[whChainId];
if (forwarder == bytes32(0)) {
revert Errors.ChainDisabled(whChainId);
}
return forwarder;
}
function setWormhole(address wh) external onlyOwner nonReentrant {
if (wh == address(0)) {
revert Errors.InvalidWormhole(wh);
}
_wormhole = wh;
}
function setTokenBridgeRelayer(
address tbr
) external onlyOwner nonReentrant {
if (tbr == address(0)) {
revert Errors.InvalidTokenBridgeRelayer(tbr);
}
_tokenBridgeRelayer = tbr;
}
function addToken(address token) external onlyOwner nonReentrant {
_tokens[token] = true;
}
function removeToken(address token) external onlyOwner nonReentrant {
_tokens[token] = false;
}
function addChain(
uint16 whChainId,
bytes32 forwarder
) external onlyOwner nonReentrant {
_targetChains[whChainId] = true;
_forwarders[whChainId] = forwarder;
}
function removeChain(uint16 whChainId) external onlyOwner nonReentrant {
_targetChains[whChainId] = false;
}
function withdrawToken(
IERC20 token,
uint256 amount
) external onlyOwner nonReentrant {
SafeERC20.safeTransfer(token, owner(), amount);
}
fallback() external payable {
revert Errors.Unsupported();
}
receive() external payable {
revert Errors.Unsupported();
}
}
文件 14 的 15:SafeERC20.sol
pragma solidity ^0.8.20;
import {IERC20} from "../IERC20.sol";
import {IERC20Permit} from "../extensions/IERC20Permit.sol";
import {Address} from "../../../utils/Address.sol";
library SafeERC20 {
using Address for address;
error SafeERC20FailedOperation(address token);
error SafeERC20FailedDecreaseAllowance(address spender, uint256 currentAllowance, uint256 requestedDecrease);
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transfer, (to, value)));
}
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
forceApprove(token, spender, oldAllowance + value);
}
function safeDecreaseAllowance(IERC20 token, address spender, uint256 requestedDecrease) internal {
unchecked {
uint256 currentAllowance = token.allowance(address(this), spender);
if (currentAllowance < requestedDecrease) {
revert SafeERC20FailedDecreaseAllowance(spender, currentAllowance, requestedDecrease);
}
forceApprove(token, spender, currentAllowance - requestedDecrease);
}
}
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeCall(token.approve, (spender, value));
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeCall(token.approve, (spender, 0)));
_callOptionalReturn(token, approvalCall);
}
}
function _callOptionalReturn(IERC20 token, bytes memory data) private {
bytes memory returndata = address(token).functionCall(data);
if (returndata.length != 0 && !abi.decode(returndata, (bool))) {
revert SafeERC20FailedOperation(address(token));
}
}
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(token).code.length > 0;
}
}
文件 15 的 15:Storage.sol
pragma solidity ^0.8.20;
contract Storage {
address public _wormhole;
address public _tokenBridgeRelayer;
mapping(address => bool) public _tokens;
mapping(uint16 => bool) public _targetChains;
mapping(uint16 => bytes32) public _forwarders;
}
{
"compilationTarget": {
"contracts/RizeWormholeV1.sol": "RizeWormholeV1"
},
"evmVersion": "paris",
"libraries": {},
"metadata": {
"bytecodeHash": "ipfs",
"useLiteralContent": true
},
"optimizer": {
"enabled": false,
"runs": 200
},
"remappings": []
}
[{"inputs":[{"internalType":"address","name":"wh","type":"address"},{"internalType":"address","name":"tbr","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[{"internalType":"address","name":"target","type":"address"}],"name":"AddressEmptyCode","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"AddressInsufficientBalance","type":"error"},{"inputs":[{"internalType":"uint16","name":"chainId","type":"uint16"}],"name":"ChainDisabled","type":"error"},{"inputs":[],"name":"FailedInnerCall","type":"error"},{"inputs":[{"internalType":"address","name":"tbr","type":"address"}],"name":"InvalidTokenBridgeRelayer","type":"error"},{"inputs":[{"internalType":"address","name":"wh","type":"address"}],"name":"InvalidWormhole","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint16","name":"targetChain","type":"uint16"}],"name":"NotWhitelisted","type":"error"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"OwnableInvalidOwner","type":"error"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"OwnableUnauthorizedAccount","type":"error"},{"inputs":[],"name":"ReentrancyGuardReentrantCall","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"SafeERC20FailedOperation","type":"error"},{"inputs":[],"name":"Unsupported","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"address","name":"token","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"targetChain","type":"uint16"},{"indexed":false,"internalType":"bytes32","name":"forwarder","type":"bytes32"},{"indexed":false,"internalType":"uint64","name":"messageSequence","type":"uint64"}],"name":"WormholeERC20DepositEvent","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"user","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"targetChain","type":"uint16"},{"indexed":false,"internalType":"bytes32","name":"forwarder","type":"bytes32"},{"indexed":false,"internalType":"uint64","name":"messageSequence","type":"uint64"}],"name":"WormholeETHDepositEvent","type":"event"},{"stateMutability":"payable","type":"fallback"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"}],"name":"_forwarders","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"","type":"uint16"}],"name":"_targetChains","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_tokenBridgeRelayer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"_tokens","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_wormhole","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"whChainId","type":"uint16"},{"internalType":"bytes32","name":"forwarder","type":"bytes32"}],"name":"addChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"addToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"targetChain","type":"uint16"}],"name":"depositETH","outputs":[{"internalType":"uint64","name":"messageSequence","type":"uint64"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"uint16","name":"targetChain","type":"uint16"}],"name":"depositToken","outputs":[{"internalType":"uint64","name":"messageSequence","type":"uint64"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint16","name":"whChainId","type":"uint16"}],"name":"forwarderByChainId","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"whChainId","type":"uint16"}],"name":"isChainEnabled","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"},{"internalType":"uint16","name":"whChainId","type":"uint16"}],"name":"isTokenWhitelisted","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint16","name":"whChainId","type":"uint16"}],"name":"removeChain","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"removeToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"renounceOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"tbr","type":"address"}],"name":"setTokenBridgeRelayer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"wh","type":"address"}],"name":"setWormhole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"tokenBridgeRelayer","outputs":[{"internalType":"contract ITokenBridgeRelayer","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"contract IERC20","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"withdrawToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"wormhole","outputs":[{"internalType":"contract IWormhole","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}]