Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

evm: add TransceiverRegistry #7

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions evm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ struct AttestationInfo {

// Integrator (message recipient) => message digest -> attestation info
mapping(address => mapping(bytes32 => AttestationInfo)) perIntegratorAttestations;

struct IntegratorConfig {
bool isInitialized;
address admin;
address pending_admin;
}

// Integrator address => configuration information
// Used by Router to maintain admin information
mapping(address => IntegratorConfig) integratorConfigs
```

## Development
Expand Down
564 changes: 546 additions & 18 deletions evm/src/Router.sol

Large diffs are not rendered by default.

467 changes: 467 additions & 0 deletions evm/src/TransceiverRegistry.sol

Large diffs are not rendered by default.

20 changes: 0 additions & 20 deletions evm/src/interfaces/IRouter.sol

This file was deleted.

57 changes: 57 additions & 0 deletions evm/src/interfaces/IRouterAdmin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;

interface IRouterAdmin {
/// @notice Transfers admin privileges from the current admin to another contract.
/// @dev The msg.sender must be the current admin contract.
/// @param integrator The address of the integrator contract.
/// @param newAdmin The address of the new admin.
function updateAdmin(address integrator, address newAdmin) external;

/// @notice Starts the two step process of transferring admin privileges from the current admin to another contract.
/// @dev The msg.sender must be the current admin contract.
/// @param integrator The address of the integrator contract.
/// @param newAdmin The address of the new admin.
function transferAdmin(address integrator, address newAdmin) external;

/// @notice Completes the two step process of transferring admin privileges from the current admin to another contract.
/// @dev The msg.sender must be the current admin contract.
/// @param integrator The address of the integrator contract.
function claimAdmin(address integrator) external;

/// @notice Clears the current admin. THIS IS NOT REVERSIBLE.
/// This ensures that the Integrator configuration becomes immutable.
/// @dev The msg.sender must be the current admin contract.
/// @param integrator The address of the integrator contract.
function discardAdmin(address integrator) external;

/// @notice Adds the given transceiver to the given chain for the integrator's list of transceivers.
/// This does NOT enable the transceiver for sending or receiving.
/// @param integrator The address of the integrator contract.
/// @param transceiver The address of the Transceiver contract.
function addTransceiver(address integrator, address transceiver) external returns (uint8 index);

/// @notice This enables the sending of messages from the given transceiver on the given chain.
/// @param integrator The address of the integrator contract.
/// @param transceiver The address of the Transceiver contract.
/// @param chain The chain ID of the Transceiver contract.
function enableSendTransceiver(address integrator, uint16 chain, address transceiver) external;

/// @notice This enables the receiving of messages by the given transceiver on the given chain.
/// @param integrator The address of the integrator contract.
/// @param transceiver The address of the Transceiver contract.
/// @param chain The chain ID of the Transceiver contract.
function enableRecvTransceiver(address integrator, uint16 chain, address transceiver) external;

/// @notice This disables the sending of messages from the given transceiver on the given chain.
/// @param integrator The address of the integrator contract.
/// @param transceiver The address of the Transceiver contract.
/// @param chain The chain ID of the Transceiver contract.
function disableSendTransceiver(address integrator, uint16 chain, address transceiver) external;

/// @notice This disables the receiving of messages by the given transceiver on the given chain.
/// @param integrator The address of the integrator contract.
/// @param transceiver The address of the Transceiver contract.
/// @param chain The chain ID of the Transceiver contract.
function disableRecvTransceiver(address integrator, uint16 chain, address transceiver) external;
}
74 changes: 74 additions & 0 deletions evm/src/interfaces/IRouterIntegrator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;

import "./IMessageSequence.sol";
import "../libraries/UniversalAddress.sol";

interface IRouterIntegrator is IMessageSequence {
/// @notice This is the first thing an integrator should do. It registers the integrator with the router
/// and sets the administrator contract for that integrator. The admin address is used to manage the transceivers.
/// @dev The msg.sender needs to be the integrator contract.
/// @param initialAdmin The address of the admin.
function register(address initialAdmin) external;

/// @notice Send a message to another chain.
/// @param dstChain The Wormhole chain ID of the recipient.
/// @param dstAddr The universal address of the peer on the recipient chain.
/// @param payloadHash keccak256 of a message to be sent to the recipient chain.
/// @return uint64 The sequence number of the message.
/// @param refundAddress The source chain refund address passed to the Transceiver.
function sendMessage(uint16 dstChain, UniversalAddress dstAddr, bytes32 payloadHash, address refundAddress)
external
payable
returns (uint64);

/// @notice Receive a message and mark it executed.
/// @param srcChain The Wormhole chain ID of the sender.
/// @param srcAddr The universal address of the peer on the sending chain.
/// @param sequence The sequence number of the message (per integrator).
/// @param dstChain The Wormhole chain ID of the destination.
/// @param dstAddr The destination address of the message.
/// @param payloadHash The keccak256 of payload from the integrator.
/// @return (uint128, uint128) The enabled bitmap, and the attested bitmap, respectively.
function recvMessage(
uint16 srcChain,
UniversalAddress srcAddr,
uint64 sequence,
uint16 dstChain,
UniversalAddress dstAddr,
panoel marked this conversation as resolved.
Show resolved Hide resolved
bytes32 payloadHash
) external payable returns (uint128, uint128);

/// @notice Execute a message without requiring any attestations.
/// @param srcChain The Wormhole chain ID of the sender.
/// @param srcAddr The universal address of the peer on the sending chain.
/// @param sequence The sequence number of the message (per integrator).
/// @param dstChain The Wormhole chain ID of the destination.
/// @param dstAddr The destination address of the message.
/// @param payloadHash The keccak256 of payload from the integrator.
function execMessage(
uint16 srcChain,
UniversalAddress srcAddr,
uint64 sequence,
uint16 dstChain,
UniversalAddress dstAddr,
bytes32 payloadHash
) external;

/// @notice Retrieve the status of a message.
/// @param srcChain The Wormhole chain ID of the sender.
/// @param srcAddr The universal address of the message.
/// @param sequence The sequence number of the message.
/// @param dstChain The Wormhole chain ID of the destination.
/// @param dstAddr The destination address of the message.
/// @param payloadHash The keccak256 of payload from the integrator.
/// @return (uint128, uint128, bool) The enabled bitmap, the attested bitmap, if the message was executed.
function getMessageStatus(
uint16 srcChain,
UniversalAddress srcAddr,
uint64 sequence,
uint16 dstChain,
UniversalAddress dstAddr,
bytes32 payloadHash
) external returns (uint128, uint128, bool);
}
22 changes: 22 additions & 0 deletions evm/src/interfaces/IRouterTransceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;

import "../libraries/UniversalAddress.sol";

interface IRouterTransceiver {
/// @notice Called by a Transceiver contract to attest to a message.
/// @param srcChain The Wormhole chain ID of the sender.
/// @param srcAddr The universal address of the peer on the sending chain.
/// @param sequence The sequence number of the message (per integrator).
/// @param dstChain The Wormhole chain ID of the destination.
/// @param dstAddr The destination address of the message.
/// @param payloadHash The keccak256 of payload from the integrator.
function attestMessage(
uint16 srcChain,
UniversalAddress srcAddr,
uint64 sequence,
uint16 dstChain,
UniversalAddress dstAddr,
bytes32 payloadHash
) external;
}
36 changes: 36 additions & 0 deletions evm/src/interfaces/ITransceiver.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.13;

import "../libraries/UniversalAddress.sol";

interface ITransceiver {
/// @notice The caller is not the Router.
/// @dev Selector: 0xfb217bcd.
/// @param caller The address of the caller.
error CallerNotRouter(address caller);

/// @notice Returns the string type of the transceiver. E.g. "wormhole", "axelar", etc.
function getTransceiverType() external view returns (string memory);

/// @notice Fetch the delivery price for a given recipient chain transfer.
/// @param recipientChain The Wormhole chain ID of the target chain.
/// @return deliveryPrice The cost of delivering a message to the recipient chain,
/// in this chain's native token.
function quoteDeliveryPrice(uint16 recipientChain) external view returns (uint256);

/// @dev Send a message to another chain.
/// @param srcAddr The universal address of the sender.
/// @param sequence The per-integrator sequence number associated with the message.
/// @param dstChain The Wormhole chain ID of the recipient.
/// @param dstAddr The universal address of the recipient.
/// @param payloadHash The hash of the message to be sent to the recipient chain.
/// @param refundAddr The address of the refund recipient.
function sendMessage(
panoel marked this conversation as resolved.
Show resolved Hide resolved
UniversalAddress srcAddr,
uint64 sequence,
uint16 dstChain,
UniversalAddress dstAddr,
bytes32 payloadHash,
address refundAddr
) external payable;
}
Loading
Loading