Skip to content

Commit b4a798f

Browse files
Rahul MagantiRahulMaganti47
Rahul Maganti
authored andcommitted
evm: natspec changes and additions
1 parent e3f27fc commit b4a798f

File tree

6 files changed

+151
-11
lines changed

6 files changed

+151
-11
lines changed

evm/src/NttManager/NttManager.sol

+16
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,22 @@ import "../interfaces/ITransceiver.sol";
1717

1818
import {NttManagerState} from "./NttManagerState.sol";
1919

20+
/// @title NttManager
21+
/// @notice The NttManager contract is responsible for managing the token
22+
/// and associated transceivers.
23+
///
24+
/// @dev Each NttManager contract is associated with a single token but
25+
/// can be responsible for multiple transceivers.
26+
///
27+
/// @dev When transferring tokens, the NttManager contract will either
28+
/// lock the tokens or burn them, depending on the mode.
29+
///
30+
/// @dev To initiate a transfer, the user calls the transfer function with:
31+
/// - the amount
32+
/// - the recipient chain
33+
/// - the recipient address
34+
/// - (optional) a flag to indicate whether the transfer should be queued
35+
/// if the rate limit is exceeded
2036
contract NttManager is INttManager, NttManagerState {
2137
using BytesParsing for bytes;
2238
using SafeERC20 for IERC20;

evm/src/Transceiver/Transceiver.sol

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ import "../libraries/Implementation.sol";
1111
import "../interfaces/INttManager.sol";
1212
import "../interfaces/ITransceiver.sol";
1313

14+
/// @title Transceiver
15+
/// @notice This contract is a base contract for Transceivers.
16+
/// @dev The Transceiver provides basic functionality for transmitting / receiving NTT messages.
17+
/// The contract supports pausing via an admin or owner and is upgradable.
18+
///
19+
/// @dev The interface for receiving messages is not enforced by this contract.
20+
/// Instead, inheriting contracts should implement their own receiving logic,
21+
/// based on the verification model and serde logic associated with message handling.
1422
abstract contract Transceiver is
1523
ITransceiver,
1624
PausableOwnable,

evm/src/interfaces/INttManager.sol

+39-4
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,22 @@ import "../libraries/TransceiverStructs.sol";
77
import "./INttManagerState.sol";
88

99
interface INttManager is INttManagerState {
10+
/// @notice The mode is either LOCKING or BURNING. In LOCKING mode, the NttManager locks the
11+
/// tokens of the sender and mints an equivalent amount on the target chain. In BURNING
12+
/// mode, the NttManager burns the tokens of the sender and mints an equivalent amount
13+
/// on the target chain.LOCKING mode preserves the total supply of the tokens.
1014
enum Mode {
1115
LOCKING,
1216
BURNING
1317
}
1418

15-
// @dev Information about attestations for a given message.
19+
/// @notice Information about attestations for a given message.
20+
/// @dev The fields are as follows:
21+
/// - executed: whether the message has been executed.
22+
/// - attested: bitmap of transceivers that have attested to this message.
23+
/// (NOTE: might contain disabled transceivers)
1624
struct AttestationInfo {
17-
// whether this message has been executed
1825
bool executed;
19-
// bitmap of transceivers that have attested to this message (NOTE: might contain disabled transceivers)
2026
uint64 attestedTransceivers;
2127
}
2228

@@ -43,12 +49,41 @@ interface INttManager is INttManagerState {
4349
/// @param mode The mode.
4450
error InvalidMode(uint8 mode);
4551

52+
/// @notice Error when the refund to the sender fails.
53+
/// @dev Selector 0x2ca23714.
54+
/// @param refundAmount The refund amount.
4655
error RefundFailed(uint256 refundAmount);
47-
error TransceiverAlreadyAttestedToMessage(bytes32 nttManagerMessageHash);
56+
57+
/// @notice Error when the tranceiver already attested to the message.
58+
/// To ensure the client does not continue to initiate calls to the ateestationReceived function.
59+
/// @dev Selector 0x2113894.
60+
/// @param nttManagerMessageHash The hash of the message.
61+
error TrasceiverAlreadyAttestedToMessage(bytes32 nttManagerMessageHash);
62+
63+
/// @notice Error when the message is not approved.
64+
/// @dev Selector 0x451c4fb0.
65+
/// @param msgHash The hash of the message.
4866
error MessageNotApproved(bytes32 msgHash);
67+
68+
/// @notice Error when trying to execute a message on an unintended target chain.
69+
/// @dev Selector 0x3dcb204a.
70+
/// @param targetChain The target chain.
71+
/// @param thisChain The current chain.
4972
error InvalidTargetChain(uint16 targetChain, uint16 thisChain);
73+
74+
/// @notice Error when the transfer amount is zero.
75+
/// @dev Selector 0x9993626a.
5076
error ZeroAmount();
77+
78+
/// @notice Error when the recipient is invalid.
79+
/// @dev Selector 0x9c8d2cd2.
5180
error InvalidRecipient();
81+
82+
/// @@notice Error when the amount burned is different than the balance difference,
83+
/// since NTT does not support burn fees.
84+
/// @dev Selector 0x02156a8f.
85+
/// @param burnAmount The amount burned.
86+
/// @param balanceDiff The balance after burning.
5287
error BurnAmountDifferentThanBalanceDiff(uint256 burnAmount, uint256 balanceDiff);
5388

5489
/// @notice Transfer a given amount to a recipient on a given chain. This function is called

evm/src/interfaces/IWormholeTransceiver.sol

+39-4
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,64 @@ import "../libraries/TransceiverStructs.sol";
66
import "./IWormholeTransceiverState.sol";
77

88
interface IWormholeTransceiver is IWormholeTransceiverState {
9+
/// @notice The instruction for the WormholeTransceiver contract
10+
/// to skip delivery via the relayer.
911
struct WormholeTransceiverInstruction {
1012
bool shouldSkipRelayerSend;
1113
}
1214

15+
/// @notice Emitted when a relayed message is received.
16+
/// @dev Topic0
17+
/// 0xf557dbbb087662f52c815f6c7ee350628a37a51eae9608ff840d996b65f87475
18+
/// @param digest The digest of the message.
19+
/// @param emitterChainId The chain ID of the emitter.
20+
/// @param emitterAddress The address of the emitter.
1321
event ReceivedRelayedMessage(bytes32 digest, uint16 emitterChainId, bytes32 emitterAddress);
22+
23+
/// @notice Emitted when a message is received.
24+
/// @dev Topic0
25+
/// 0xf6fc529540981400dc64edf649eb5e2e0eb5812a27f8c81bac2c1d317e71a5f0.
26+
/// @param digest The digest of the message.
27+
/// @param emitterChainId The chain ID of the emitter.
28+
/// @param emitterAddress The address of the emitter.
29+
/// @param sequence The sequence of the message.
1430
event ReceivedMessage(
1531
bytes32 digest, uint16 emitterChainId, bytes32 emitterAddress, uint64 sequence
1632
);
33+
34+
/// @notice Emitted when a message is sent from the transceiver.
35+
/// @dev Topic0
36+
/// 0x53b3e029c5ead7bffc739118953883859d30b1aaa086e0dca4d0a1c99cd9c3f5.
37+
/// @param recipientChain The chain ID of the recipient.
38+
/// @param message The message.
1739
event SendTransceiverMessage(
1840
uint16 recipientChain, TransceiverStructs.TransceiverMessage message
1941
);
2042

43+
/// @notice Error when the relaying configuration is invalid. (e.g. chainId is not registered)
44+
/// @dev Selector: 0x9449a36c.
45+
/// @param chainId The chain ID that is invalid.
2146
error InvalidRelayingConfig(uint16 chainId);
47+
48+
/// @notice Error when the peer transceiver is invalid.
49+
/// @dev Selector: 0x79b1ce56.
50+
/// @param chainId The chain ID of the peer.
51+
/// @param peerAddress The address of the invalid peer.
2252
error InvalidWormholePeer(uint16 chainId, bytes32 peerAddress);
53+
54+
/// @notice Error when the VAA has already been consumed.
55+
/// @dev Selector: 0x406e719e.
56+
/// @param vaaHash The hash of the VAA.
2357
error TransferAlreadyCompleted(bytes32 vaaHash);
2458

25-
/// @notice Receive an attested message from the verification layer. This function should verify
26-
/// the `encodedVm` and then deliver the attestation to the transceiver NttManager contract.
59+
/// @notice Receive an attested message from the verification layer.
60+
/// This function should verify the `encodedVm` and then deliver the attestation
61+
/// to the transceiver NttManager contract.
2762
/// @param encodedMessage The attested message.
2863
function receiveMessage(bytes memory encodedMessage) external;
2964

30-
/// @notice Parses the encoded instruction and returns the instruction struct. This instruction
31-
/// is specific to the WormholeTransceiver contract.
65+
/// @notice Parses the encoded instruction and returns the instruction struct.
66+
/// This instruction is specific to the WormholeTransceiver contract.
3267
/// @param encoded The encoded instruction.
3368
/// @return instruction The parsed `WormholeTransceiverInstruction`.
3469
function parseWormholeTransceiverInstruction(bytes memory encoded)

evm/src/interfaces/IWormholeTransceiverState.sol

+48
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,65 @@ pragma solidity >=0.8.8 <0.9.0;
44
import "../libraries/TransceiverStructs.sol";
55

66
interface IWormholeTransceiverState {
7+
/// @notice Emitted when a message is sent from the transceiver.
8+
/// @dev Topic0
9+
/// 0x375a56c053c4d19a2e3445e97b7a28bf4e908617ce6d766e1e03a9d3f5276271.
10+
/// @param relayingType The type of relaying.
11+
/// @param deliveryPayment The amount of ether sent along with the tx to cover the delivery fee.
712
event RelayingInfo(uint8 relayingType, uint256 deliveryPayment);
13+
14+
/// @notice Emitted when a peer transceiver is set.
15+
/// @dev Topic0
16+
/// 0xa559263ee060c7a2560843b3a064ff0376c9753ae3e2449b595a3b615d326466.
17+
/// @param chainId The chain ID of the peer.
18+
/// @param peerContract The address of the peer contract.
819
event SetWormholePeer(uint16 chainId, bytes32 peerContract);
20+
21+
/// @notice Emitted when relaying is enabled for the given chain.
22+
/// @dev Topic0
23+
/// 0x528b18a533e892b5401d1fb63597275df9d2bb45b13e7695c3147cd07b9746c3.
24+
/// @param chainId The chain ID to set.
25+
/// @param isEvm A boolean indicating whether relaying is enabled.
926
event SetIsWormholeRelayingEnabled(uint16 chainId, bool isRelayingEnabled);
27+
28+
/// @notice Emitted when special relaying is enabled for the given chain.
29+
/// @dev Topic0
30+
/// 0x0fe301480713b2c2072ee91b3bcfcbf2c0014f0447c89046f020f0f80727003c.
31+
/// @param chainId The chain ID to set.
1032
event SetIsSpecialRelayingEnabled(uint16 chainId, bool isRelayingEnabled);
33+
34+
/// @notice Emitted when the chain is EVM compatible.
35+
/// @dev Topic0
36+
/// 0x50bbeb4e180e8f9e429f6ef6b53496616c747fe502441c4f423d5fc9ec958d9c.
37+
/// @param chainId The chain ID to set.
1138
event SetIsWormholeEvmChain(uint16 chainId);
1239

40+
/// @notice Additonal messages are not allowed.
41+
/// @dev Selector: 0xc504ea29.
1342
error UnexpectedAdditionalMessages();
43+
44+
/// @notice Error if the VAA is invalid.
45+
/// @dev Selector: 0x8ee2e336.
46+
/// @param reason The reason the VAA is invalid.
1447
error InvalidVaa(string reason);
48+
49+
/// @notice Error if the peer has already been set.
50+
/// @dev Selector: 0xb55eeae9.
51+
/// @param chainId The chain ID of the peer.
52+
/// @param peerAddress The address of the peer.
1553
error PeerAlreadySet(uint16 chainId, bytes32 peerAddress);
54+
55+
/// @notice Error the peer contract cannot be the zero address.
56+
/// @dev Selector: 0x26e0c7de.
1657
error InvalidWormholePeerZeroAddress();
58+
59+
/// @notice The chain ID cannot be zero.
60+
/// @dev Selector: 0x3dd98b24.
1761
error InvalidWormholeChainIdZero();
62+
63+
/// @notice The caller is not the relayer.
64+
/// @dev Selector: 0x1c269589.
65+
/// @param caller The caller.
1866
error CallerNotRelayer(address caller);
1967

2068
/// @notice Get the corresponding Transceiver contract on other chains that have been registered

evm/src/libraries/RateLimiter.sol

+1-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import "../libraries/TrimmedAmount.sol";
99

1010
abstract contract RateLimiter is IRateLimiter, IRateLimiterEvents {
1111
using TrimmedAmountLib for TrimmedAmount;
12-
/**
13-
* @dev The duration it takes for the limits to fully replenish
14-
*/
1512

13+
/// @dev The duration (in seconds) it takes for the limits to fully replenish.
1614
uint64 public immutable rateLimitDuration;
1715

1816
/// =============== STORAGE ===============================================

0 commit comments

Comments
 (0)