-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor and enhance testing utilities
- Loading branch information
1 parent
fa2dc15
commit 4d9c157
Showing
18 changed files
with
1,176 additions
and
1,258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,87 @@ | ||
/* | ||
* Copyright (c) 2022, Circle Internet Financial Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// SPDX-License-Identifier: Apache 2 | ||
pragma solidity ^0.8.0; | ||
|
||
import "./IRelayer.sol"; | ||
import "./IReceiver.sol"; | ||
interface IMessageTransmitter { | ||
event MessageSent(bytes message); | ||
|
||
/** | ||
* @title IMessageTransmitter | ||
* @notice Interface for message transmitters, which both relay and receive messages. | ||
*/ | ||
interface IMessageTransmitter is IRelayer, IReceiver { | ||
/** | ||
* @notice Emitted when tokens are minted | ||
* @param _mintRecipient recipient address of minted tokens | ||
* @param _amount amount of minted tokens | ||
* @param _mintToken contract address of minted token | ||
*/ | ||
event MintAndWithdraw( | ||
address _mintRecipient, | ||
uint256 _amount, | ||
address _mintToken | ||
); | ||
|
||
/** | ||
* @notice Receive a message. Messages with a given nonce | ||
* can only be broadcast once for a (sourceDomain, destinationDomain) | ||
* pair. The message body of a valid message is passed to the | ||
* specified recipient for further processing. | ||
* | ||
* @dev Attestation format: | ||
* A valid attestation is the concatenated 65-byte signature(s) of exactly | ||
* `thresholdSignature` signatures, in increasing order of attester address. | ||
* ***If the attester addresses recovered from signatures are not in | ||
* increasing order, signature verification will fail.*** | ||
* If incorrect number of signatures or duplicate signatures are supplied, | ||
* signature verification will fail. | ||
* | ||
* Message format: | ||
* Field Bytes Type Index | ||
* version 4 uint32 0 | ||
* sourceDomain 4 uint32 4 | ||
* destinationDomain 4 uint32 8 | ||
* nonce 8 uint64 12 | ||
* sender 32 bytes32 20 | ||
* recipient 32 bytes32 52 | ||
* messageBody dynamic bytes 84 | ||
* @param _message Message bytes | ||
* @param _attestation Concatenated 65-byte signature(s) of `_message`, in increasing order | ||
* of the attester address recovered from signatures. | ||
* @return success bool, true if successful | ||
*/ | ||
function receiveMessage( | ||
bytes memory _message, | ||
bytes calldata _attestation | ||
) external returns (bool success); | ||
|
||
function attesterManager() external view returns (address); | ||
|
||
function availableNonces(uint32 domain) external view returns (uint64); | ||
|
||
function getNumEnabledAttesters() external view returns (uint256); | ||
|
||
function isEnabledAttester(address _attester) external view returns (bool); | ||
|
||
function localDomain() external view returns (uint32); | ||
|
||
function maxMessageBodySize() external view returns (uint256); | ||
|
||
function owner() external view returns (address); | ||
|
||
function paused() external view returns (bool); | ||
|
||
function pauser() external view returns (address); | ||
|
||
function rescuer() external view returns (address); | ||
|
||
function version() external view returns (uint32); | ||
|
||
// owner only methods | ||
function transferOwnership(address newOwner) external; | ||
|
||
function updateAttesterManager(address _newAttesterManager) external; | ||
|
||
// attester manager only methods | ||
function getEnabledAttester(uint256 _index) external view returns (address); | ||
|
||
function disableAttester(address _attester) external; | ||
|
||
function enableAttester(address _attester) external; | ||
|
||
function setSignatureThreshold(uint256 newSignatureThreshold) external; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,84 @@ | ||
/* | ||
* Copyright (c) 2022, Circle Internet Financial Limited. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
// SPDX-License-Identifier: Apache 2 | ||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @title TokenMessenger | ||
* @notice Sends messages and receives messages to/from MessageTransmitters | ||
* and to/from TokenMinters | ||
*/ | ||
import {IMessageTransmitter} from "./IMessageTransmitter.sol"; | ||
import {ITokenMinter} from "./ITokenMinter.sol"; | ||
|
||
interface ITokenMessenger { | ||
/** | ||
/** | ||
* @notice Deposits and burns tokens from sender to be minted on destination domain. | ||
* Emits a `DepositForBurn` event. | ||
* @dev reverts if: | ||
* - given burnToken is not supported | ||
* - given destinationDomain has no CircleBridge registered | ||
* - transferFrom() reverts. For example, if sender's burnToken balance or approved allowance | ||
* to this contract is less than `amount`. | ||
* - burn() reverts. For example, if `amount` is 0. | ||
* - MessageTransmitter returns false or reverts. | ||
* @param _amount amount of tokens to burn | ||
* @param _destinationDomain destination domain (ETH = 0, AVAX = 1) | ||
* @param _mintRecipient address of mint recipient on destination domain | ||
* @param _burnToken address of contract to burn deposited tokens, on local domain | ||
* @return _nonce unique nonce reserved by message | ||
*/ | ||
function depositForBurn( | ||
uint256 _amount, | ||
uint32 _destinationDomain, | ||
bytes32 _mintRecipient, | ||
address _burnToken | ||
) external returns (uint64 _nonce); | ||
|
||
/** | ||
* @notice Deposits and burns tokens from sender to be minted on destination domain. The mint | ||
* on the destination domain must be called by `destinationCaller`. | ||
* WARNING: if the `destinationCaller` does not represent a valid address as bytes32, then it will not be possible | ||
* on the destination domain must be called by `_destinationCaller`. | ||
* WARNING: if the `_destinationCaller` does not represent a valid address as bytes32, then it will not be possible | ||
* to broadcast the message on the destination domain. This is an advanced feature, and the standard | ||
* depositForBurn() should be preferred for use cases where a specific destination caller is not required. | ||
* Emits a `DepositForBurn` event. | ||
* @dev reverts if: | ||
* - given destinationCaller is zero address | ||
* - given burnToken is not supported | ||
* - given destinationDomain has no TokenMessenger registered | ||
* - given destinationDomain has no CircleBridge registered | ||
* - transferFrom() reverts. For example, if sender's burnToken balance or approved allowance | ||
* to this contract is less than `amount`. | ||
* - burn() reverts. For example, if `amount` is 0. | ||
* - MessageTransmitter returns false or reverts. | ||
* @param amount amount of tokens to burn | ||
* @param destinationDomain destination domain | ||
* @param mintRecipient address of mint recipient on destination domain | ||
* @param burnToken address of contract to burn deposited tokens, on local domain | ||
* @param destinationCaller caller on the destination domain, as bytes32 | ||
* @return nonce unique nonce reserved by message | ||
* @param _amount amount of tokens to burn | ||
* @param _destinationDomain destination domain | ||
* @param _mintRecipient address of mint recipient on destination domain | ||
* @param _burnToken address of contract to burn deposited tokens, on local domain | ||
* @param _destinationCaller caller on the destination domain, as bytes32 | ||
* @return _nonce unique nonce reserved by message | ||
*/ | ||
function depositForBurnWithCaller( | ||
uint256 amount, | ||
uint32 destinationDomain, | ||
bytes32 mintRecipient, | ||
address burnToken, | ||
bytes32 destinationCaller | ||
) external returns (uint64 nonce); | ||
} | ||
uint256 _amount, | ||
uint32 _destinationDomain, | ||
bytes32 _mintRecipient, | ||
address _burnToken, | ||
bytes32 _destinationCaller | ||
) external returns (uint64 _nonce); | ||
|
||
function localMessageTransmitter() external view returns (IMessageTransmitter); | ||
|
||
function localMinter() external view returns (ITokenMinter); | ||
|
||
function messageBodyVersion() external view returns (uint32); | ||
|
||
function owner() external view returns (address); | ||
|
||
function pendingOwner() external view returns (address); | ||
|
||
function rescuer() external view returns (address); | ||
|
||
function remoteTokenMessengers(uint32 domain) external view returns (bytes32); | ||
|
||
function addRemoteTokenMessenger(uint32 domain, bytes32 tokenMessenger) external; | ||
|
||
function handleReceiveMessage(uint32 _remoteDomain, bytes32 _sender, bytes memory messageBody) | ||
external | ||
view | ||
returns (bool); | ||
|
||
// owner only methods | ||
function transferOwnership(address newOwner) external; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// SPDX-License-Identifier: Apache 2 | ||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @title ITokenMinter | ||
* @notice interface for minter of tokens that are mintable, burnable, and interchangeable | ||
* across domains. | ||
*/ | ||
interface ITokenMinter { | ||
function tokenController() external view returns (address); | ||
|
||
function burnLimitsPerMessage(address token) external view returns (uint256); | ||
|
||
function remoteTokensToLocalTokens(bytes32 sourceIdHash) external view returns (address); | ||
|
||
function linkTokenPair(address localToken, uint32 remoteDomain, bytes32 remoteToken) external; | ||
} |
Oops, something went wrong.