Skip to content

Commit c5f4370

Browse files
RahulMaganti47Rahul Maganti
and
Rahul Maganti
authored
add documentation, natspec plus refactors (#186)
* IManagerEvents: add natpsec for manager events * IRateLimiterEvents: add natspec for rate limiter events * IRateLimiterEvents: add natspec for errors * IRateLimiter: add natspec for rate limiter structs * EndpointStructs: cleanup + add natspec * forge fmt --------- Co-authored-by: Rahul Maganti <rahulmaganti@Rahuls-MacBook-Pro.local>
1 parent e00fcd7 commit c5f4370

File tree

4 files changed

+144
-25
lines changed

4 files changed

+144
-25
lines changed

evm/src/interfaces/IManagerEvents.sol

+53
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,69 @@ pragma solidity >=0.8.8 <0.9.0;
44
import "../libraries/NormalizedAmount.sol";
55

66
interface IManagerEvents {
7+
/// @notice Emitted when a message is sent from the manager.
8+
/// @dev Topic0
9+
/// 0x71ec1d4b53baa86365b6523ea136c9fe0f72c36c721e7e28e9efac2c23b39d98.
10+
/// @param recipient The recipient of the message.
11+
/// @param amount The amount transferred.
12+
/// @param recipientChain The chain ID of the recipient.
13+
/// @param msgSequence The unique sequence ID of the message.
714
event TransferSent(
815
bytes32 recipient, uint256 amount, uint16 recipientChain, uint64 msgSequence
916
);
17+
18+
/// @notice Emitted when the sibling contract is updated.
19+
/// @dev Topic0
20+
/// 0x51b8437a7e22240c473f4cbdb4ed3a4f4bf5a9e7b3c511d7cfe0197325735700.
21+
/// @param chainId_ The chain ID of the sibling contract.
22+
/// @param oldSiblingContract The old sibling contract address.
23+
/// @param siblingContract The new sibling contract address.
1024
event SiblingUpdated(
1125
uint16 indexed chainId_, bytes32 oldSiblingContract, bytes32 siblingContract
1226
);
27+
28+
/// @notice Emitted when a message has been attested to.
29+
/// @dev Topic0
30+
/// 0x35a2101eaac94b493e0dfca061f9a7f087913fde8678e7cde0aca9897edba0e5.
31+
/// @param digest The digest of the message.
32+
/// @param endpoint The address of the endpoint.
33+
/// @param index The index of the endpoint in the bitmap.
1334
event MessageAttestedTo(bytes32 digest, address endpoint, uint8 index);
35+
36+
/// @notice Emmitted when the threshold required endpoints is changed.
37+
/// @dev Topic0
38+
/// 0x2a855b929b9a53c6fb5b5ed248b27e502b709c088e036a5aa17620c8fc5085a9.
39+
/// @param oldThreshold The old threshold.
40+
/// @param threshold The new threshold.
1441
event ThresholdChanged(uint8 oldThreshold, uint8 threshold);
42+
43+
/// @notice Emitted when an endpoint is removed from the manager.
44+
/// @dev Topic0
45+
/// 0xc6289e62021fd0421276d06677862d6b328d9764cdd4490ca5ac78b173f25883.
46+
/// @param endpoint The address of the endpoint.
47+
/// @param endpointsNum The current number of endpoints.
48+
/// @param threshold The current threshold of endpoints.
1549
event EndpointAdded(address endpoint, uint256 endpointsNum, uint8 threshold);
50+
51+
/// @notice Emitted when an endpoint is removed from the manager.
52+
/// @dev Topic0
53+
/// 0x638e631f34d9501a3ff0295873b29f50d0207b5400bf0e48b9b34719e6b1a39e.
54+
/// @param endpoint The address of the endpoint.
55+
/// @param threshold The current threshold of endpoints.
1656
event EndpointRemoved(address endpoint, uint8 threshold);
57+
58+
/// @notice Emitted when a message has already been executed to
59+
/// notify client of against retries.
60+
/// @dev Topic0
61+
/// 0x4069dff8c9df7e38d2867c0910bd96fd61787695e5380281148c04932d02bef2.
62+
/// @param sourceManager The address of the source manager.
63+
/// @param msgHash The keccak-256 hash of the message.
1764
event MessageAlreadyExecuted(bytes32 indexed sourceManager, bytes32 indexed msgHash);
65+
66+
/// @notice Emitted when a transfer has been redeemed
67+
/// (either minted or unlocked on the recipient chain).
68+
/// @dev Topic0
69+
/// 0x504e6efe18ab9eed10dc6501a417f5b12a2f7f2b1593aed9b89f9bce3cf29a91.
70+
/// @param digest The digest of the message.
1871
event TransferRedeemed(bytes32 digest);
1972
}

evm/src/interfaces/IRateLimiter.sol

+46
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,60 @@ import "../libraries/NormalizedAmount.sol";
55
import "../libraries/EndpointStructs.sol";
66

77
interface IRateLimiter {
8+
/// @notice Not enough capacity to send the transfer.
9+
/// @dev Selector 0x26fb55dd.
10+
/// @param currentCapacity The current capacity.
11+
/// @param amount The amount of the transfer.
812
error NotEnoughCapacity(uint256 currentCapacity, uint256 amount);
13+
14+
/// @notice Outbound transfer is not longer queued.
15+
/// @dev Selector 0xbfd5f462.
16+
/// @param queueSequence The sequence of the queue.
917
error OutboundQueuedTransferNotFound(uint64 queueSequence);
18+
19+
/// @notice Cannot complete the outbound transfer, the transfer is still queued.
20+
/// @dev Selector 0xc06cf05f.
21+
/// @param queueSequence The sequence of the queue.
22+
/// @param transferTimestamp The timestamp of when the transfer was queued.
1023
error OutboundQueuedTransferStillQueued(uint64 queueSequence, uint256 transferTimestamp);
24+
25+
/// @notice The inbound transfer is not longer queued.
26+
/// @dev Selector 0xc06f2bc0.
27+
/// @param digest The digest of the transfer.
1128
error InboundQueuedTransferNotFound(bytes32 digest);
29+
30+
/// @notice The transfer is still queued.
31+
/// @dev Selector 0xe5b9ce80.
32+
/// @param digest The digest of the transfer.
33+
/// @param transferTimestamp The timestamp of the transfer.
1234
error InboundQueuedTransferStillQueued(bytes32 digest, uint256 transferTimestamp);
35+
36+
/// @notice The new capacity cannot exceed the limit.
37+
/// @dev Selector 0x0f85ba52.
38+
/// @param newCurrentCapacity The new current capacity.
39+
/// @param newLimit The new limit.
1340
error CapacityCannotExceedLimit(NormalizedAmount newCurrentCapacity, NormalizedAmount newLimit);
1441

42+
/// @notice Parameters used in determining rate limits and queuing.
43+
/// @dev
44+
/// - limit: current rate limit value.
45+
/// - currentCapacity: the current capacity left.
46+
/// - lastTxTimestamp: the timestamp of when the
47+
/// capacity was previously consumption.
1548
struct RateLimitParams {
1649
NormalizedAmount limit;
1750
NormalizedAmount currentCapacity;
1851
uint64 lastTxTimestamp;
1952
}
2053

54+
/// @notice Parameters for an outbound queued transfer.
55+
/// @dev
56+
/// - recipient: the recipient of the transfer.
57+
/// - amount: the amount of the transfer, normalized.
58+
/// - txTimestamp: the timestamp of the transfer.
59+
/// - recipientChain: the chain of the recipient.
60+
/// - sender: the sender of the transfer.
61+
/// - endpointInstructions: additional instructions to be forwarded to the recipient chain.
2162
struct OutboundQueuedTransfer {
2263
bytes32 recipient;
2364
NormalizedAmount amount;
@@ -27,6 +68,11 @@ interface IRateLimiter {
2768
bytes endpointInstructions;
2869
}
2970

71+
/// @notice Parameters for an inbound queued transfer.
72+
/// @dev
73+
/// - amount: the amount of the transfer, normalized.
74+
/// - txTimestamp: the timestamp of the transfer.
75+
/// - recipient: the recipient of the transfer.
3076
struct InboundQueuedTransfer {
3177
NormalizedAmount amount;
3278
uint64 txTimestamp;

evm/src/interfaces/IRateLimiterEvents.sol

+16
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,24 @@ pragma solidity >=0.8.8 <0.9.0;
44
import "../libraries/NormalizedAmount.sol";
55

66
interface IRateLimiterEvents {
7+
/// @notice Emitted when an inbound transfer is queued
8+
/// @dev Topic0
9+
/// 0x7f63c9251d82a933210c2b6d0b0f116252c3c116788120e64e8e8215df6f3162.
10+
/// @param digest The digest of the message.
711
event InboundTransferQueued(bytes32 digest);
12+
13+
/// @notice Emitted whenn an outbound transfer is queued.
14+
/// @dev Topic0
15+
/// 0x69add1952a6a6b9cb86f04d05f0cb605cbb469a50ae916139d34495a9991481f.
16+
/// @param queueSequence The location of the transfer in the queue.
817
event OutboundTransferQueued(uint64 queueSequence);
18+
19+
/// @notice Emitted when an outbound transfer is rate limited.
20+
/// @dev Topic0
21+
/// 0x754d657d1363ee47d967b415652b739bfe96d5729ccf2f26625dcdbc147db68b.
22+
/// @param sender The initial sender of the transfer.
23+
/// @param amount The amount to be transferred.
24+
/// @param currentCapacity The capacity left for transfers within the 24-hour window.
925
event OutboundTransferRateLimited(
1026
address indexed sender, uint64 sequence, uint256 amount, uint256 currentCapacity
1127
);

evm/src/libraries/EndpointStructs.sol

+29-25
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@ library EndpointStructs {
88
using BytesParsing for bytes;
99
using NormalizedAmountLib for NormalizedAmount;
1010

11+
/// @notice Error thrown when the payload length exceeds the allowed maximum.
12+
/// @dev Selector 0xa3419691.
13+
/// @param size The size of the payload.
1114
error PayloadTooLong(uint256 size);
15+
16+
/// @notice Error thrown when the prefix of an encoded message
17+
/// does not match the expected value.
18+
/// @dev Selector 0x56d2569d.
19+
/// @param prefix The prefix that was found in the encoded message.
1220
error IncorrectPrefix(bytes4 prefix);
1321
error UnorderedInstructions();
1422

@@ -50,11 +58,9 @@ library EndpointStructs {
5058
return abi.encodePacked(m.sequence, m.sender, payloadLength, m.payload);
5159
}
5260

53-
/*
54-
* @dev Parse a ManagerMessage.
55-
*
56-
* @params encoded The byte array corresponding to the encoded message
57-
*/
61+
/// @notice Parse a ManagerMessage.
62+
/// @param encoded The byte array corresponding to the encoded message
63+
/// @return managerMessage The parsed ManagerMessage struct.
5864
function parseManagerMessage(bytes memory encoded)
5965
public
6066
pure
@@ -104,11 +110,9 @@ library EndpointStructs {
104110
);
105111
}
106112

107-
/*
108-
* @dev Parse a NativeTokenTransfer.
109-
*
110-
* @params encoded The byte array corresponding to the encoded message
111-
*/
113+
/// @dev Parse a NativeTokenTransfer.
114+
/// @param encoded The byte array corresponding to the encoded message
115+
/// @return nativeTokenTransfer The parsed NativeTokenTransfer struct.
112116
function parseNativeTokenTransfer(bytes memory encoded)
113117
public
114118
pure
@@ -154,13 +158,12 @@ library EndpointStructs {
154158
bytes endpointPayload;
155159
}
156160

157-
/*
158-
* @dev Encodes an Endpoint message for communication between the Manager and the Endpoint.
159-
*
160-
* @param m The EndpointMessage struct containing the message details.
161-
* @return encoded The byte array corresponding to the encoded message.
162-
* @throws PayloadTooLong if the length of endpointId, managerPayload, or endpointPayload exceeds the allowed maximum.
163-
*/
161+
// @notice Encodes an Endpoint message for communication between the
162+
// Manager and the Endpoint.
163+
// @param m The EndpointMessage struct containing the message details.
164+
// @return encoded The byte array corresponding to the encoded message.
165+
// @custom:throw PayloadTooLong if the length of endpointId, managerPayload,
166+
// or endpointPayload exceeds the allowed maximum.
164167
function encodeEndpointMessage(
165168
bytes4 prefix,
166169
EndpointMessage memory m
@@ -203,13 +206,11 @@ library EndpointStructs {
203206
return (endpointMessage, encoded);
204207
}
205208

206-
/*
207-
* @dev Parses an encoded message and extracts information into an EndpointMessage struct.
208-
*
209-
* @param encoded The encoded bytes containing information about the EndpointMessage.
210-
* @return endpointMessage The parsed EndpointMessage struct.
211-
* @throws IncorrectPrefix if the prefix of the encoded message does not match the expected prefix.
212-
*/
209+
/// @dev Parses an encoded message and extracts information into an EndpointMessage struct.
210+
/// @param encoded The encoded bytes containing information about the EndpointMessage.
211+
/// @return endpointMessage The parsed EndpointMessage struct.
212+
/// @custom:throw IncorrectPrefix if the prefix of the encoded message does not
213+
/// match the expected prefix.
213214
function parseEndpointMessage(
214215
bytes4 expectedPrefix,
215216
bytes memory encoded
@@ -238,7 +239,10 @@ library EndpointStructs {
238239
encoded.checkLength(offset);
239240
}
240241

241-
/// @dev Parses the payload of an Endpoint message and returns the parsed ManagerMessage struct.
242+
/// @dev Parses the payload of an Endpoint message and returns
243+
/// the parsed ManagerMessage struct.
244+
/// @param expectedPrefix The prefix that should be encoded in the manager message.
245+
/// @param payload The payload sent across the wire.
242246
function parseEndpointAndManagerMessage(
243247
bytes4 expectedPrefix,
244248
bytes memory payload

0 commit comments

Comments
 (0)