-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathIRateLimiter.sol
113 lines (98 loc) · 4.62 KB
/
IRateLimiter.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// SPDX-License-Identifier: Apache 2
pragma solidity >=0.8.8 <0.9.0;
import "../libraries/TrimmedAmount.sol";
import "../libraries/TransceiverStructs.sol";
interface IRateLimiter {
/// @notice Not enough capacity to send the transfer.
/// @dev Selector 0x26fb55dd.
/// @param currentCapacity The current capacity.
/// @param amount The amount of the transfer.
error NotEnoughCapacity(uint256 currentCapacity, uint256 amount);
/// @notice Outbound transfer is not longer queued.
/// @dev Selector 0xbfd5f462.
/// @param queueSequence The sequence of the queue.
error OutboundQueuedTransferNotFound(uint64 queueSequence);
/// @notice Cannot complete the outbound transfer, the transfer is still queued.
/// @dev Selector 0xc06cf05f.
/// @param queueSequence The sequence of the queue.
/// @param transferTimestamp The timestamp of when the transfer was queued.
error OutboundQueuedTransferStillQueued(uint64 queueSequence, uint256 transferTimestamp);
/// @notice The inbound transfer is not longer queued.
/// @dev Selector 0xc06f2bc0.
/// @param digest The digest of the transfer.
error InboundQueuedTransferNotFound(bytes32 digest);
/// @notice The transfer is still queued.
/// @dev Selector 0xe5b9ce80.
/// @param digest The digest of the transfer.
/// @param transferTimestamp The timestamp of the transfer.
error InboundQueuedTransferStillQueued(bytes32 digest, uint256 transferTimestamp);
/// @notice The new capacity cannot exceed the limit.
/// @dev Selector 0x0f85ba52.
/// @param newCurrentCapacity The new current capacity.
/// @param newLimit The new limit.
error CapacityCannotExceedLimit(TrimmedAmount newCurrentCapacity, TrimmedAmount newLimit);
/// @notice If the rate limiting behaviour isn't explicitly defined in the constructor.
/// @dev Selector 0xe543ef05.
error UndefinedRateLimiting();
/// @notice Parameters used in determining rate limits and queuing.
/// @dev
/// - limit: current rate limit value.
/// - currentCapacity: the current capacity left.
/// - lastTxTimestamp: the timestamp of when the
/// capacity was previously consumption.
struct RateLimitParams {
TrimmedAmount limit;
TrimmedAmount currentCapacity;
uint64 lastTxTimestamp;
}
/// @notice Parameters for an outbound queued transfer.
/// @dev
/// - recipient: the recipient of the transfer.
/// - amount: the amount of the transfer, trimmed.
/// - txTimestamp: the timestamp of the transfer.
/// - recipientChain: the chain of the recipient.
/// - sender: the sender of the transfer.
/// - transceiverInstructions: additional instructions to be forwarded to the recipient chain.
/// - sourceChain: the chain of the sender.
struct OutboundQueuedTransfer {
bytes32 recipient;
bytes32 refundAddress;
TrimmedAmount amount;
uint64 txTimestamp;
uint16 recipientChain;
address sender;
bytes transceiverInstructions;
uint16 sourceChain;
}
/// @notice Parameters for an inbound queued transfer.
/// @dev
/// - amount: the amount of the transfer, trimmed.
/// - txTimestamp: the timestamp of the transfer.
/// - recipient: the recipient of the transfer.
/// - sourceChain: the chain of the sender.
struct InboundQueuedTransfer {
TrimmedAmount amount;
uint64 txTimestamp;
address recipient;
uint16 sourceChain;
}
/// @notice Returns the currently remaining outbound capacity allowed
/// before transfers are queued (if desired)
function getCurrentOutboundCapacity() external view returns (uint256);
/// @notice Returns the queued transfer details for a given sequence in the outbound queue
/// @param queueSequence The position of the transfer in the outbound queue
function getOutboundQueuedTransfer(
uint64 queueSequence
) external view returns (OutboundQueuedTransfer memory);
/// @notice Returns the currently remaining inbound capacity allowed from a given chain
/// before transfers are queued auutomatically
/// @param chainId The Wormhole chain ID of the peer
function getCurrentInboundCapacity(
uint16 chainId
) external view returns (uint256);
/// @notice Returns the queued transfer details for a given message digest in the inbound queue
/// @param digest The digest of the transfer in the inbound queue
function getInboundQueuedTransfer(
bytes32 digest
) external view returns (InboundQueuedTransfer memory);
}