@hyperlane-xyz/core 3.11.0-beta-0 → 3.20.0-beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/contracts/client/MailboxClient.sol +39 -0
- package/contracts/hooks/warp-route/RateLimitedHook.sol +58 -0
- package/contracts/interfaces/hooks/IPostDispatchHook.sol +2 -1
- package/contracts/isms/TrustedRelayerIsm.sol +27 -0
- package/contracts/isms/warp-route/RateLimitedIsm.sol +53 -0
- package/contracts/libs/RateLimited.sol +107 -0
- package/contracts/test/TestPostDispatchHook.sol +11 -7
- package/contracts/token/HypNative.sol +9 -1
- package/contracts/token/extensions/HypNativeScaled.sol +8 -1
- package/contracts/token/libs/TokenRouter.sol +63 -7
- package/dist/buildArtifact.d.ts +1 -0
- package/dist/buildArtifact.js +2 -0
- package/{buildArtifact.json → dist/buildArtifact.json} +1 -1
- package/dist/contracts/hooks/index.d.ts +2 -0
- package/dist/contracts/hooks/index.d.ts.map +1 -1
- package/dist/contracts/hooks/warp-route/RateLimitedHook.d.ts +521 -0
- package/dist/contracts/hooks/warp-route/RateLimitedHook.d.ts.map +1 -0
- package/dist/contracts/hooks/warp-route/RateLimitedHook.js +2 -0
- package/dist/contracts/hooks/warp-route/RateLimitedHook.js.map +1 -0
- package/dist/contracts/hooks/warp-route/index.d.ts +2 -0
- package/dist/contracts/hooks/warp-route/index.d.ts.map +1 -0
- package/dist/contracts/hooks/warp-route/index.js +2 -0
- package/dist/contracts/hooks/warp-route/index.js.map +1 -0
- package/dist/contracts/isms/TrustedRelayerIsm.d.ts +95 -0
- package/dist/contracts/isms/TrustedRelayerIsm.d.ts.map +1 -0
- package/dist/contracts/isms/TrustedRelayerIsm.js +2 -0
- package/dist/contracts/isms/TrustedRelayerIsm.js.map +1 -0
- package/dist/contracts/isms/index.d.ts +3 -0
- package/dist/contracts/isms/index.d.ts.map +1 -1
- package/dist/contracts/isms/warp-route/RateLimitedIsm.d.ts +491 -0
- package/dist/contracts/isms/warp-route/RateLimitedIsm.d.ts.map +1 -0
- package/dist/contracts/isms/warp-route/RateLimitedIsm.js +2 -0
- package/dist/contracts/isms/warp-route/RateLimitedIsm.js.map +1 -0
- package/dist/contracts/isms/warp-route/index.d.ts +2 -0
- package/dist/contracts/isms/warp-route/index.d.ts.map +1 -0
- package/dist/contracts/isms/warp-route/index.js +2 -0
- package/dist/contracts/isms/warp-route/index.js.map +1 -0
- package/dist/contracts/libs/RateLimited.d.ts +304 -0
- package/dist/contracts/libs/RateLimited.d.ts.map +1 -0
- package/dist/contracts/libs/RateLimited.js +2 -0
- package/dist/contracts/libs/RateLimited.js.map +1 -0
- package/dist/contracts/libs/index.d.ts +1 -0
- package/dist/contracts/libs/index.d.ts.map +1 -1
- package/dist/contracts/test/TestPostDispatchHook.d.ts +20 -1
- package/dist/contracts/test/TestPostDispatchHook.d.ts.map +1 -1
- package/dist/contracts/token/HypERC20.d.ts +9 -8
- package/dist/contracts/token/HypERC20.d.ts.map +1 -1
- package/dist/contracts/token/HypERC20Collateral.d.ts +9 -8
- package/dist/contracts/token/HypERC20Collateral.d.ts.map +1 -1
- package/dist/contracts/token/HypERC20CollateralVaultDeposit.d.ts +9 -8
- package/dist/contracts/token/HypERC20CollateralVaultDeposit.d.ts.map +1 -1
- package/dist/contracts/token/HypERC721.d.ts +9 -8
- package/dist/contracts/token/HypERC721.d.ts.map +1 -1
- package/dist/contracts/token/HypERC721Collateral.d.ts +9 -8
- package/dist/contracts/token/HypERC721Collateral.d.ts.map +1 -1
- package/dist/contracts/token/HypNative.d.ts +9 -8
- package/dist/contracts/token/HypNative.d.ts.map +1 -1
- package/dist/contracts/token/extensions/FastHypERC20.d.ts +9 -8
- package/dist/contracts/token/extensions/FastHypERC20.d.ts.map +1 -1
- package/dist/contracts/token/extensions/FastHypERC20Collateral.d.ts +9 -8
- package/dist/contracts/token/extensions/FastHypERC20Collateral.d.ts.map +1 -1
- package/dist/contracts/token/extensions/HypERC721URICollateral.d.ts +9 -8
- package/dist/contracts/token/extensions/HypERC721URICollateral.d.ts.map +1 -1
- package/dist/contracts/token/extensions/HypERC721URIStorage.d.ts +9 -8
- package/dist/contracts/token/extensions/HypERC721URIStorage.d.ts.map +1 -1
- package/dist/contracts/token/extensions/HypNativeScaled.d.ts +9 -8
- package/dist/contracts/token/extensions/HypNativeScaled.d.ts.map +1 -1
- package/dist/contracts/token/libs/FastTokenRouter.d.ts +9 -8
- package/dist/contracts/token/libs/FastTokenRouter.d.ts.map +1 -1
- package/dist/contracts/token/libs/TokenRouter.d.ts +9 -8
- package/dist/contracts/token/libs/TokenRouter.d.ts.map +1 -1
- package/dist/factories/contracts/Mailbox__factory.d.ts +1 -1
- package/dist/factories/contracts/Mailbox__factory.js +1 -1
- package/dist/factories/contracts/hooks/MerkleTreeHook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/MerkleTreeHook__factory.js +1 -1
- package/dist/factories/contracts/hooks/OPStackHook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/OPStackHook__factory.js +1 -1
- package/dist/factories/contracts/hooks/PausableHook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/PausableHook__factory.js +1 -1
- package/dist/factories/contracts/hooks/ProtocolFee__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/ProtocolFee__factory.js +1 -1
- package/dist/factories/contracts/hooks/aggregation/ERC5164Hook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/aggregation/ERC5164Hook__factory.js +1 -1
- package/dist/factories/contracts/hooks/aggregation/StaticAggregationHookFactory__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/aggregation/StaticAggregationHookFactory__factory.js +1 -1
- package/dist/factories/contracts/hooks/aggregation/StaticAggregationHook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/aggregation/StaticAggregationHook__factory.js +1 -1
- package/dist/factories/contracts/hooks/igp/InterchainGasPaymaster__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/igp/InterchainGasPaymaster__factory.js +1 -1
- package/dist/factories/contracts/hooks/index.d.ts +1 -0
- package/dist/factories/contracts/hooks/index.d.ts.map +1 -1
- package/dist/factories/contracts/hooks/index.js +1 -0
- package/dist/factories/contracts/hooks/index.js.map +1 -1
- package/dist/factories/contracts/hooks/layer-zero/LayerZeroV1Hook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/layer-zero/LayerZeroV1Hook__factory.js +1 -1
- package/dist/factories/contracts/hooks/layer-zero/LayerZeroV2Hook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/layer-zero/LayerZeroV2Hook__factory.js +1 -1
- package/dist/factories/contracts/hooks/routing/DestinationRecipientRoutingHook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/routing/DestinationRecipientRoutingHook__factory.js +1 -1
- package/dist/factories/contracts/hooks/routing/DomainRoutingHook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/routing/DomainRoutingHook__factory.js +1 -1
- package/dist/factories/contracts/hooks/routing/FallbackDomainRoutingHook__factory.d.ts +1 -1
- package/dist/factories/contracts/hooks/routing/FallbackDomainRoutingHook__factory.js +1 -1
- package/dist/factories/contracts/hooks/warp-route/RateLimitedHook__factory.d.ts +329 -0
- package/dist/factories/contracts/hooks/warp-route/RateLimitedHook__factory.d.ts.map +1 -0
- package/dist/factories/contracts/hooks/warp-route/RateLimitedHook__factory.js +442 -0
- package/dist/factories/contracts/hooks/warp-route/RateLimitedHook__factory.js.map +1 -0
- package/dist/factories/contracts/hooks/warp-route/index.d.ts +2 -0
- package/dist/factories/contracts/hooks/warp-route/index.d.ts.map +1 -0
- package/dist/factories/contracts/hooks/warp-route/index.js +5 -0
- package/dist/factories/contracts/hooks/warp-route/index.js.map +1 -0
- package/dist/factories/contracts/isms/TrustedRelayerIsm__factory.d.ts +81 -0
- package/dist/factories/contracts/isms/TrustedRelayerIsm__factory.d.ts.map +1 -0
- package/dist/factories/contracts/isms/TrustedRelayerIsm__factory.js +118 -0
- package/dist/factories/contracts/isms/TrustedRelayerIsm__factory.js.map +1 -0
- package/dist/factories/contracts/isms/index.d.ts +2 -0
- package/dist/factories/contracts/isms/index.d.ts.map +1 -1
- package/dist/factories/contracts/isms/index.js +2 -0
- package/dist/factories/contracts/isms/index.js.map +1 -1
- package/dist/factories/contracts/isms/multisig/ValidatorAnnounce__factory.d.ts +1 -1
- package/dist/factories/contracts/isms/multisig/ValidatorAnnounce__factory.js +1 -1
- package/dist/factories/contracts/isms/routing/DefaultFallbackRoutingIsm__factory.d.ts +1 -1
- package/dist/factories/contracts/isms/routing/DefaultFallbackRoutingIsm__factory.js +1 -1
- package/dist/factories/contracts/isms/routing/DomainRoutingIsmFactory.sol/DomainRoutingIsmFactory__factory.d.ts +1 -1
- package/dist/factories/contracts/isms/routing/DomainRoutingIsmFactory.sol/DomainRoutingIsmFactory__factory.js +1 -1
- package/dist/factories/contracts/isms/routing/InterchainAccountIsm__factory.d.ts +1 -1
- package/dist/factories/contracts/isms/routing/InterchainAccountIsm__factory.js +1 -1
- package/dist/factories/contracts/isms/warp-route/RateLimitedIsm__factory.d.ts +301 -0
- package/dist/factories/contracts/isms/warp-route/RateLimitedIsm__factory.d.ts.map +1 -0
- package/dist/factories/contracts/isms/warp-route/RateLimitedIsm__factory.js +405 -0
- package/dist/factories/contracts/isms/warp-route/RateLimitedIsm__factory.js.map +1 -0
- package/dist/factories/contracts/isms/warp-route/index.d.ts +2 -0
- package/dist/factories/contracts/isms/warp-route/index.d.ts.map +1 -0
- package/dist/factories/contracts/isms/warp-route/index.js +5 -0
- package/dist/factories/contracts/isms/warp-route/index.js.map +1 -0
- package/dist/factories/contracts/libs/RateLimited__factory.d.ts +195 -0
- package/dist/factories/contracts/libs/RateLimited__factory.d.ts.map +1 -0
- package/dist/factories/contracts/libs/RateLimited__factory.js +266 -0
- package/dist/factories/contracts/libs/RateLimited__factory.js.map +1 -0
- package/dist/factories/contracts/libs/index.d.ts +1 -0
- package/dist/factories/contracts/libs/index.d.ts.map +1 -1
- package/dist/factories/contracts/libs/index.js +1 -0
- package/dist/factories/contracts/libs/index.js.map +1 -1
- package/dist/factories/contracts/middleware/InterchainAccountRouter__factory.d.ts +1 -1
- package/dist/factories/contracts/middleware/InterchainAccountRouter__factory.js +1 -1
- package/dist/factories/contracts/middleware/InterchainQueryRouter__factory.d.ts +1 -1
- package/dist/factories/contracts/middleware/InterchainQueryRouter__factory.js +1 -1
- package/dist/factories/contracts/middleware/liquidity-layer/LiquidityLayerRouter__factory.d.ts +1 -1
- package/dist/factories/contracts/middleware/liquidity-layer/LiquidityLayerRouter__factory.js +1 -1
- package/dist/factories/contracts/middleware/liquidity-layer/adapters/CircleBridgeAdapter__factory.d.ts +1 -1
- package/dist/factories/contracts/middleware/liquidity-layer/adapters/CircleBridgeAdapter__factory.js +1 -1
- package/dist/factories/contracts/middleware/liquidity-layer/adapters/PortalAdapter__factory.d.ts +1 -1
- package/dist/factories/contracts/middleware/liquidity-layer/adapters/PortalAdapter__factory.js +1 -1
- package/dist/factories/contracts/mock/MockHyperlaneEnvironment__factory.d.ts +1 -1
- package/dist/factories/contracts/mock/MockHyperlaneEnvironment__factory.d.ts.map +1 -1
- package/dist/factories/contracts/mock/MockHyperlaneEnvironment__factory.js +1 -1
- package/dist/factories/contracts/mock/MockHyperlaneEnvironment__factory.js.map +1 -1
- package/dist/factories/contracts/mock/MockMailbox__factory.d.ts +1 -1
- package/dist/factories/contracts/mock/MockMailbox__factory.d.ts.map +1 -1
- package/dist/factories/contracts/mock/MockMailbox__factory.js +1 -1
- package/dist/factories/contracts/mock/MockMailbox__factory.js.map +1 -1
- package/dist/factories/contracts/test/TestGasRouter__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestGasRouter__factory.js +1 -1
- package/dist/factories/contracts/test/TestInterchainGasPaymaster__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestInterchainGasPaymaster__factory.js +1 -1
- package/dist/factories/contracts/test/TestMailbox__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestMailbox__factory.js +1 -1
- package/dist/factories/contracts/test/TestMerkleTreeHook__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestMerkleTreeHook__factory.js +1 -1
- package/dist/factories/contracts/test/TestPostDispatchHook__factory.d.ts +15 -1
- package/dist/factories/contracts/test/TestPostDispatchHook__factory.d.ts.map +1 -1
- package/dist/factories/contracts/test/TestPostDispatchHook__factory.js +20 -1
- package/dist/factories/contracts/test/TestPostDispatchHook__factory.js.map +1 -1
- package/dist/factories/contracts/test/TestQuerySender__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestQuerySender__factory.js +1 -1
- package/dist/factories/contracts/test/TestQuery__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestQuery__factory.js +1 -1
- package/dist/factories/contracts/test/TestRouter__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestRouter__factory.js +1 -1
- package/dist/factories/contracts/test/TestSendReceiver__factory.d.ts +1 -1
- package/dist/factories/contracts/test/TestSendReceiver__factory.js +1 -1
- package/dist/factories/contracts/token/HypERC20CollateralVaultDeposit__factory.d.ts +31 -1
- package/dist/factories/contracts/token/HypERC20CollateralVaultDeposit__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/HypERC20CollateralVaultDeposit__factory.js +40 -1
- package/dist/factories/contracts/token/HypERC20CollateralVaultDeposit__factory.js.map +1 -1
- package/dist/factories/contracts/token/HypERC20Collateral__factory.d.ts +31 -1
- package/dist/factories/contracts/token/HypERC20Collateral__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/HypERC20Collateral__factory.js +40 -1
- package/dist/factories/contracts/token/HypERC20Collateral__factory.js.map +1 -1
- package/dist/factories/contracts/token/HypERC20__factory.d.ts +31 -1
- package/dist/factories/contracts/token/HypERC20__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/HypERC20__factory.js +40 -1
- package/dist/factories/contracts/token/HypERC20__factory.js.map +1 -1
- package/dist/factories/contracts/token/HypERC721Collateral__factory.d.ts +31 -1
- package/dist/factories/contracts/token/HypERC721Collateral__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/HypERC721Collateral__factory.js +40 -1
- package/dist/factories/contracts/token/HypERC721Collateral__factory.js.map +1 -1
- package/dist/factories/contracts/token/HypERC721__factory.d.ts +31 -1
- package/dist/factories/contracts/token/HypERC721__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/HypERC721__factory.js +40 -1
- package/dist/factories/contracts/token/HypERC721__factory.js.map +1 -1
- package/dist/factories/contracts/token/HypNative__factory.d.ts +31 -1
- package/dist/factories/contracts/token/HypNative__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/HypNative__factory.js +40 -1
- package/dist/factories/contracts/token/HypNative__factory.js.map +1 -1
- package/dist/factories/contracts/token/extensions/FastHypERC20Collateral__factory.d.ts +31 -1
- package/dist/factories/contracts/token/extensions/FastHypERC20Collateral__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/extensions/FastHypERC20Collateral__factory.js +40 -1
- package/dist/factories/contracts/token/extensions/FastHypERC20Collateral__factory.js.map +1 -1
- package/dist/factories/contracts/token/extensions/FastHypERC20__factory.d.ts +31 -1
- package/dist/factories/contracts/token/extensions/FastHypERC20__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/extensions/FastHypERC20__factory.js +40 -1
- package/dist/factories/contracts/token/extensions/FastHypERC20__factory.js.map +1 -1
- package/dist/factories/contracts/token/extensions/HypERC721URICollateral__factory.d.ts +31 -1
- package/dist/factories/contracts/token/extensions/HypERC721URICollateral__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/extensions/HypERC721URICollateral__factory.js +40 -1
- package/dist/factories/contracts/token/extensions/HypERC721URICollateral__factory.js.map +1 -1
- package/dist/factories/contracts/token/extensions/HypERC721URIStorage__factory.d.ts +31 -1
- package/dist/factories/contracts/token/extensions/HypERC721URIStorage__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/extensions/HypERC721URIStorage__factory.js +40 -1
- package/dist/factories/contracts/token/extensions/HypERC721URIStorage__factory.js.map +1 -1
- package/dist/factories/contracts/token/extensions/HypNativeScaled__factory.d.ts +31 -1
- package/dist/factories/contracts/token/extensions/HypNativeScaled__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/extensions/HypNativeScaled__factory.js +40 -1
- package/dist/factories/contracts/token/extensions/HypNativeScaled__factory.js.map +1 -1
- package/dist/factories/contracts/token/libs/FastTokenRouter__factory.d.ts +30 -0
- package/dist/factories/contracts/token/libs/FastTokenRouter__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/libs/FastTokenRouter__factory.js +39 -0
- package/dist/factories/contracts/token/libs/FastTokenRouter__factory.js.map +1 -1
- package/dist/factories/contracts/token/libs/TokenRouter__factory.d.ts +30 -0
- package/dist/factories/contracts/token/libs/TokenRouter__factory.d.ts.map +1 -1
- package/dist/factories/contracts/token/libs/TokenRouter__factory.js +39 -0
- package/dist/factories/contracts/token/libs/TokenRouter__factory.js.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -92,6 +92,10 @@ abstract contract MailboxClient is OwnableUpgradeable {
|
|
|
92
92
|
return mailbox.latestDispatchedId() == id;
|
|
93
93
|
}
|
|
94
94
|
|
|
95
|
+
function _isDelivered(bytes32 id) internal view returns (bool) {
|
|
96
|
+
return mailbox.delivered(id);
|
|
97
|
+
}
|
|
98
|
+
|
|
95
99
|
function _metadata(
|
|
96
100
|
uint32 /*_destinationDomain*/
|
|
97
101
|
) internal view virtual returns (bytes memory) {
|
|
@@ -123,6 +127,24 @@ abstract contract MailboxClient is OwnableUpgradeable {
|
|
|
123
127
|
);
|
|
124
128
|
}
|
|
125
129
|
|
|
130
|
+
function _dispatch(
|
|
131
|
+
uint32 _destinationDomain,
|
|
132
|
+
bytes32 _recipient,
|
|
133
|
+
uint256 _value,
|
|
134
|
+
bytes memory _messageBody,
|
|
135
|
+
bytes memory _hookMetadata,
|
|
136
|
+
IPostDispatchHook _hook
|
|
137
|
+
) internal virtual returns (bytes32) {
|
|
138
|
+
return
|
|
139
|
+
mailbox.dispatch{value: _value}(
|
|
140
|
+
_destinationDomain,
|
|
141
|
+
_recipient,
|
|
142
|
+
_messageBody,
|
|
143
|
+
_hookMetadata,
|
|
144
|
+
_hook
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
126
148
|
function _quoteDispatch(
|
|
127
149
|
uint32 _destinationDomain,
|
|
128
150
|
bytes32 _recipient,
|
|
@@ -137,4 +159,21 @@ abstract contract MailboxClient is OwnableUpgradeable {
|
|
|
137
159
|
hook
|
|
138
160
|
);
|
|
139
161
|
}
|
|
162
|
+
|
|
163
|
+
function _quoteDispatch(
|
|
164
|
+
uint32 _destinationDomain,
|
|
165
|
+
bytes32 _recipient,
|
|
166
|
+
bytes memory _messageBody,
|
|
167
|
+
bytes calldata _hookMetadata,
|
|
168
|
+
IPostDispatchHook _hook
|
|
169
|
+
) internal view virtual returns (uint256) {
|
|
170
|
+
return
|
|
171
|
+
mailbox.quoteDispatch(
|
|
172
|
+
_destinationDomain,
|
|
173
|
+
_recipient,
|
|
174
|
+
_messageBody,
|
|
175
|
+
_hookMetadata,
|
|
176
|
+
_hook
|
|
177
|
+
);
|
|
178
|
+
}
|
|
140
179
|
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
pragma solidity >=0.8.0;
|
|
3
|
+
import {MailboxClient} from "contracts/client/MailboxClient.sol";
|
|
4
|
+
import {IPostDispatchHook} from "contracts/interfaces/hooks/IPostDispatchHook.sol";
|
|
5
|
+
import {Message} from "contracts/libs/Message.sol";
|
|
6
|
+
import {TokenMessage} from "contracts/token/libs/TokenMessage.sol";
|
|
7
|
+
import {RateLimited} from "contracts/libs/RateLimited.sol";
|
|
8
|
+
|
|
9
|
+
contract RateLimitedHook is IPostDispatchHook, MailboxClient, RateLimited {
|
|
10
|
+
using Message for bytes;
|
|
11
|
+
using TokenMessage for bytes;
|
|
12
|
+
|
|
13
|
+
mapping(bytes32 messageId => bool validated) public messageValidated;
|
|
14
|
+
|
|
15
|
+
modifier validateMessageOnce(bytes calldata _message) {
|
|
16
|
+
bytes32 messageId = _message.id();
|
|
17
|
+
require(!messageValidated[messageId], "MessageAlreadyValidated");
|
|
18
|
+
_;
|
|
19
|
+
messageValidated[messageId] = true;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constructor(
|
|
23
|
+
address _mailbox,
|
|
24
|
+
uint256 _maxCapacity
|
|
25
|
+
) MailboxClient(_mailbox) RateLimited(_maxCapacity) {}
|
|
26
|
+
|
|
27
|
+
/// @inheritdoc IPostDispatchHook
|
|
28
|
+
function hookType() external pure returns (uint8) {
|
|
29
|
+
return uint8(IPostDispatchHook.Types.Rate_Limited_Hook);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/// @inheritdoc IPostDispatchHook
|
|
33
|
+
function supportsMetadata(bytes calldata) external pure returns (bool) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Verify a message, rate limit, and increment the sender's limit.
|
|
39
|
+
* @dev ensures that this gets called by the Mailbox
|
|
40
|
+
*/
|
|
41
|
+
function postDispatch(
|
|
42
|
+
bytes calldata,
|
|
43
|
+
bytes calldata _message
|
|
44
|
+
) external payable validateMessageOnce(_message) {
|
|
45
|
+
require(_isLatestDispatched(_message.id()), "InvalidDispatchedMessage");
|
|
46
|
+
|
|
47
|
+
uint256 newAmount = _message.body().amount();
|
|
48
|
+
validateAndConsumeFilledLevel(newAmount);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/// @inheritdoc IPostDispatchHook
|
|
52
|
+
function quoteDispatch(
|
|
53
|
+
bytes calldata,
|
|
54
|
+
bytes calldata
|
|
55
|
+
) external pure returns (uint256) {
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.8.0;
|
|
3
|
+
|
|
4
|
+
// ============ Internal Imports ============
|
|
5
|
+
import {IInterchainSecurityModule} from "../interfaces/IInterchainSecurityModule.sol";
|
|
6
|
+
import {Message} from "../libs/Message.sol";
|
|
7
|
+
import {Mailbox} from "../Mailbox.sol";
|
|
8
|
+
|
|
9
|
+
contract TrustedRelayerIsm is IInterchainSecurityModule {
|
|
10
|
+
using Message for bytes;
|
|
11
|
+
|
|
12
|
+
uint8 public immutable moduleType = uint8(Types.NULL);
|
|
13
|
+
Mailbox public immutable mailbox;
|
|
14
|
+
address public immutable trustedRelayer;
|
|
15
|
+
|
|
16
|
+
constructor(address _mailbox, address _trustedRelayer) {
|
|
17
|
+
mailbox = Mailbox(_mailbox);
|
|
18
|
+
trustedRelayer = _trustedRelayer;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function verify(
|
|
22
|
+
bytes calldata,
|
|
23
|
+
bytes calldata message
|
|
24
|
+
) external view returns (bool) {
|
|
25
|
+
return mailbox.processor(message.id()) == trustedRelayer;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.8.0;
|
|
3
|
+
|
|
4
|
+
import {IMailbox} from "contracts/interfaces/IMailbox.sol";
|
|
5
|
+
import {MailboxClient} from "contracts/client/MailboxClient.sol";
|
|
6
|
+
import {RateLimited} from "contracts/libs/RateLimited.sol";
|
|
7
|
+
import {IInterchainSecurityModule} from "contracts/interfaces/IInterchainSecurityModule.sol";
|
|
8
|
+
import {Message} from "contracts/libs/Message.sol";
|
|
9
|
+
import {TokenMessage} from "contracts/token/libs/TokenMessage.sol";
|
|
10
|
+
|
|
11
|
+
contract RateLimitedIsm is
|
|
12
|
+
MailboxClient,
|
|
13
|
+
RateLimited,
|
|
14
|
+
IInterchainSecurityModule
|
|
15
|
+
{
|
|
16
|
+
using Message for bytes;
|
|
17
|
+
using TokenMessage for bytes;
|
|
18
|
+
|
|
19
|
+
mapping(bytes32 messageId => bool validated) public messageValidated;
|
|
20
|
+
|
|
21
|
+
modifier validateMessageOnce(bytes calldata _message) {
|
|
22
|
+
bytes32 messageId = _message.id();
|
|
23
|
+
require(!messageValidated[messageId], "MessageAlreadyValidated");
|
|
24
|
+
messageValidated[messageId] = true;
|
|
25
|
+
_;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
constructor(
|
|
29
|
+
address _mailbox,
|
|
30
|
+
uint256 _maxCapacity
|
|
31
|
+
) MailboxClient(_mailbox) RateLimited(_maxCapacity) {}
|
|
32
|
+
|
|
33
|
+
/// @inheritdoc IInterchainSecurityModule
|
|
34
|
+
function moduleType() external pure returns (uint8) {
|
|
35
|
+
return uint8(IInterchainSecurityModule.Types.UNUSED);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Verify a message, rate limit, and increment the sender's limit.
|
|
40
|
+
* @dev ensures that this gets called by the Mailbox
|
|
41
|
+
*/
|
|
42
|
+
function verify(
|
|
43
|
+
bytes calldata,
|
|
44
|
+
bytes calldata _message
|
|
45
|
+
) external validateMessageOnce(_message) returns (bool) {
|
|
46
|
+
require(_isDelivered(_message.id()), "InvalidDeliveredMessage");
|
|
47
|
+
|
|
48
|
+
uint256 newAmount = _message.body().amount();
|
|
49
|
+
validateAndConsumeFilledLevel(newAmount);
|
|
50
|
+
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
pragma solidity >=0.8.0;
|
|
3
|
+
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @title RateLimited
|
|
7
|
+
* @notice A contract used to keep track of an address sender's token amount limits.
|
|
8
|
+
* @dev Implements a modified token bucket algorithm where the bucket is full in the beginning and gradually refills
|
|
9
|
+
* See: https://dev.to/satrobit/rate-limiting-using-the-token-bucket-algorithm-3cjh
|
|
10
|
+
**/
|
|
11
|
+
contract RateLimited is OwnableUpgradeable {
|
|
12
|
+
uint256 public constant DURATION = 1 days; // 86400
|
|
13
|
+
uint256 public filledLevel; /// @notice Current filled level
|
|
14
|
+
uint256 public refillRate; /// @notice Tokens per second refill rate
|
|
15
|
+
uint256 public lastUpdated; /// @notice Timestamp of the last time an action has been taken TODO prob can be uint40
|
|
16
|
+
|
|
17
|
+
event RateLimitSet(uint256 _oldCapacity, uint256 _newCapacity);
|
|
18
|
+
|
|
19
|
+
constructor(uint256 _capacity) {
|
|
20
|
+
_transferOwnership(msg.sender);
|
|
21
|
+
setRefillRate(_capacity);
|
|
22
|
+
filledLevel = _capacity;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
error RateLimitExceeded(uint256 newLimit, uint256 targetLimit);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @return The max capacity where the bucket will no longer refill
|
|
29
|
+
*/
|
|
30
|
+
function maxCapacity() public view returns (uint256) {
|
|
31
|
+
return refillRate * DURATION;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Calculates the refilled amount based on time and refill rate
|
|
36
|
+
*
|
|
37
|
+
* Consider an example where there is a 1e18 max token limit per day (86400s)
|
|
38
|
+
* If half of the tokens has been used, and half a day (43200s) has passed,
|
|
39
|
+
* then there should be a refill of 0.5e18
|
|
40
|
+
*
|
|
41
|
+
* To calculate:
|
|
42
|
+
* Refilled = Elapsed * RefilledRate
|
|
43
|
+
* Elapsed = timestamp - Limit.lastUpdated
|
|
44
|
+
* RefilledRate = Capacity / DURATION
|
|
45
|
+
*
|
|
46
|
+
* If half of the day (43200) has passed, then
|
|
47
|
+
* (86400 - 43200) * (1e18 / 86400) = 0.5e18
|
|
48
|
+
*/
|
|
49
|
+
function calculateRefilledAmount() internal view returns (uint256) {
|
|
50
|
+
uint256 elapsed = block.timestamp - lastUpdated;
|
|
51
|
+
return elapsed * refillRate;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Calculates the adjusted fill level based on time
|
|
56
|
+
*/
|
|
57
|
+
function calculateCurrentLevel() public view returns (uint256) {
|
|
58
|
+
uint256 _capacity = maxCapacity();
|
|
59
|
+
require(_capacity > 0, "RateLimitNotSet");
|
|
60
|
+
|
|
61
|
+
if (block.timestamp > lastUpdated + DURATION) {
|
|
62
|
+
// If last update is in the previous window, return the max capacity
|
|
63
|
+
return _capacity;
|
|
64
|
+
} else {
|
|
65
|
+
// If within the window, refill the capacity
|
|
66
|
+
uint256 replenishedLevel = filledLevel + calculateRefilledAmount();
|
|
67
|
+
|
|
68
|
+
// Only return _capacity, in the case where newCurrentCapcacity overflows
|
|
69
|
+
return replenishedLevel > _capacity ? _capacity : replenishedLevel;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Sets the refill rate by giving a capacity
|
|
75
|
+
* @param _capacity new maximum capacity to set
|
|
76
|
+
*/
|
|
77
|
+
function setRefillRate(
|
|
78
|
+
uint256 _capacity
|
|
79
|
+
) public onlyOwner returns (uint256) {
|
|
80
|
+
uint256 _oldRefillRate = refillRate;
|
|
81
|
+
uint256 _newRefillRate = _capacity / DURATION;
|
|
82
|
+
refillRate = _newRefillRate;
|
|
83
|
+
|
|
84
|
+
emit RateLimitSet(_oldRefillRate, _newRefillRate);
|
|
85
|
+
|
|
86
|
+
return _newRefillRate;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Validate an amount and decreases the currentCapacity
|
|
91
|
+
* @param _newAmount The amount to consume the fill level
|
|
92
|
+
* @return The new filled level
|
|
93
|
+
*/
|
|
94
|
+
function validateAndConsumeFilledLevel(
|
|
95
|
+
uint256 _newAmount
|
|
96
|
+
) public returns (uint256) {
|
|
97
|
+
uint256 adjustedFilledLevel = calculateCurrentLevel();
|
|
98
|
+
require(_newAmount <= adjustedFilledLevel, "RateLimitExceeded");
|
|
99
|
+
|
|
100
|
+
// Reduce the filledLevel and update lastUpdated
|
|
101
|
+
uint256 _filledLevel = adjustedFilledLevel - _newAmount;
|
|
102
|
+
filledLevel = _filledLevel;
|
|
103
|
+
lastUpdated = block.timestamp;
|
|
104
|
+
|
|
105
|
+
return _filledLevel;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
2
|
pragma solidity >=0.8.0;
|
|
3
|
+
import {Message} from "../libs/Message.sol";
|
|
3
4
|
|
|
4
5
|
import {IPostDispatchHook} from "../interfaces/hooks/IPostDispatchHook.sol";
|
|
5
6
|
import {AbstractPostDispatchHook} from "../hooks/libs/AbstractPostDispatchHook.sol";
|
|
6
7
|
|
|
7
8
|
contract TestPostDispatchHook is AbstractPostDispatchHook {
|
|
9
|
+
using Message for bytes;
|
|
10
|
+
|
|
8
11
|
// ============ Public Storage ============
|
|
9
12
|
|
|
10
13
|
// test fees for quoteDispatch
|
|
11
14
|
uint256 public fee = 0;
|
|
12
15
|
|
|
16
|
+
// used to keep track of dispatched message
|
|
17
|
+
mapping(bytes32 messageId => bool dispatched) public messageDispatched;
|
|
18
|
+
|
|
13
19
|
// ============ External Functions ============
|
|
14
20
|
|
|
15
21
|
/// @inheritdoc IPostDispatchHook
|
|
@@ -29,16 +35,14 @@ contract TestPostDispatchHook is AbstractPostDispatchHook {
|
|
|
29
35
|
|
|
30
36
|
// ============ Internal functions ============
|
|
31
37
|
function _postDispatch(
|
|
32
|
-
bytes calldata
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// test - empty
|
|
38
|
+
bytes calldata /*metadata*/,
|
|
39
|
+
bytes calldata message
|
|
40
|
+
) internal override {
|
|
41
|
+
messageDispatched[message.id()] = true;
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
function _quoteDispatch(
|
|
40
|
-
bytes calldata
|
|
41
|
-
/*metadata*/
|
|
45
|
+
bytes calldata /*metadata*/,
|
|
42
46
|
bytes calldata /*message*/
|
|
43
47
|
) internal view override returns (uint256) {
|
|
44
48
|
return fee;
|
|
@@ -45,7 +45,15 @@ contract HypNative is TokenRouter {
|
|
|
45
45
|
) public payable virtual override returns (bytes32 messageId) {
|
|
46
46
|
require(msg.value >= _amount, "Native: amount exceeds msg.value");
|
|
47
47
|
uint256 gasPayment = msg.value - _amount;
|
|
48
|
-
return
|
|
48
|
+
return
|
|
49
|
+
_transferRemote(
|
|
50
|
+
_destination,
|
|
51
|
+
_recipient,
|
|
52
|
+
_amount,
|
|
53
|
+
gasPayment,
|
|
54
|
+
bytes(""),
|
|
55
|
+
address(0)
|
|
56
|
+
);
|
|
49
57
|
}
|
|
50
58
|
|
|
51
59
|
function balanceOf(
|
|
@@ -30,7 +30,14 @@ contract HypNativeScaled is HypNative {
|
|
|
30
30
|
uint256 gasPayment = msg.value - _amount;
|
|
31
31
|
uint256 scaledAmount = _amount / scale;
|
|
32
32
|
return
|
|
33
|
-
_transferRemote(
|
|
33
|
+
_transferRemote(
|
|
34
|
+
_destination,
|
|
35
|
+
_recipient,
|
|
36
|
+
scaledAmount,
|
|
37
|
+
gasPayment,
|
|
38
|
+
bytes(""),
|
|
39
|
+
address(0)
|
|
40
|
+
);
|
|
34
41
|
}
|
|
35
42
|
|
|
36
43
|
/**
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
pragma solidity >=0.8.0;
|
|
3
3
|
|
|
4
|
+
import {IPostDispatchHook} from "../../interfaces/hooks/IPostDispatchHook.sol";
|
|
4
5
|
import {GasRouter} from "../../client/GasRouter.sol";
|
|
5
6
|
import {MailboxClient} from "../../client/MailboxClient.sol";
|
|
6
7
|
import {TypeCasts} from "../../libs/TypeCasts.sol";
|
|
@@ -56,31 +57,86 @@ abstract contract TokenRouter is GasRouter {
|
|
|
56
57
|
uint256 _amountOrId
|
|
57
58
|
) external payable virtual returns (bytes32 messageId) {
|
|
58
59
|
return
|
|
59
|
-
_transferRemote(
|
|
60
|
+
_transferRemote(
|
|
61
|
+
_destination,
|
|
62
|
+
_recipient,
|
|
63
|
+
_amountOrId,
|
|
64
|
+
msg.value,
|
|
65
|
+
bytes(""),
|
|
66
|
+
address(0)
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* @notice Transfers `_amountOrId` token to `_recipient` on `_destination` domain with a specified hook
|
|
72
|
+
* @dev Delegates transfer logic to `_transferFromSender` implementation.
|
|
73
|
+
* @dev The metadata is the token metadata, and is DIFFERENT than the hook metadata.
|
|
74
|
+
* @dev Emits `SentTransferRemote` event on the origin chain.
|
|
75
|
+
* @param _destination The identifier of the destination chain.
|
|
76
|
+
* @param _recipient The address of the recipient on the destination chain.
|
|
77
|
+
* @param _amountOrId The amount or identifier of tokens to be sent to the remote recipient.
|
|
78
|
+
* @param _hookMetadata The metadata passed into the hook
|
|
79
|
+
* @param _hook The post dispatch hook to be called by the Mailbox
|
|
80
|
+
* @return messageId The identifier of the dispatched message.
|
|
81
|
+
*/
|
|
82
|
+
function transferRemote(
|
|
83
|
+
uint32 _destination,
|
|
84
|
+
bytes32 _recipient,
|
|
85
|
+
uint256 _amountOrId,
|
|
86
|
+
bytes calldata _hookMetadata,
|
|
87
|
+
address _hook
|
|
88
|
+
) external payable virtual returns (bytes32 messageId) {
|
|
89
|
+
return
|
|
90
|
+
_transferRemote(
|
|
91
|
+
_destination,
|
|
92
|
+
_recipient,
|
|
93
|
+
_amountOrId,
|
|
94
|
+
msg.value,
|
|
95
|
+
_hookMetadata,
|
|
96
|
+
_hook
|
|
97
|
+
);
|
|
60
98
|
}
|
|
61
99
|
|
|
62
100
|
/**
|
|
63
101
|
* @notice Transfers `_amountOrId` token to `_recipient` on `_destination` domain.
|
|
64
102
|
* @dev Delegates transfer logic to `_transferFromSender` implementation.
|
|
103
|
+
* @dev The metadata is the token metadata, and is DIFFERENT than the hook metadata.
|
|
65
104
|
* @dev Emits `SentTransferRemote` event on the origin chain.
|
|
66
105
|
* @param _destination The identifier of the destination chain.
|
|
67
106
|
* @param _recipient The address of the recipient on the destination chain.
|
|
68
107
|
* @param _amountOrId The amount or identifier of tokens to be sent to the remote recipient.
|
|
69
108
|
* @param _gasPayment The amount of native token to pay for interchain gas.
|
|
109
|
+
* @param _hookMetadata The metadata passed into the hook
|
|
110
|
+
* @param _hook The post dispatch hook to be called by the Mailbox
|
|
70
111
|
* @return messageId The identifier of the dispatched message.
|
|
71
112
|
*/
|
|
72
113
|
function _transferRemote(
|
|
73
114
|
uint32 _destination,
|
|
74
115
|
bytes32 _recipient,
|
|
75
116
|
uint256 _amountOrId,
|
|
76
|
-
uint256 _gasPayment
|
|
117
|
+
uint256 _gasPayment,
|
|
118
|
+
bytes memory _hookMetadata,
|
|
119
|
+
address _hook
|
|
77
120
|
) internal returns (bytes32 messageId) {
|
|
78
121
|
bytes memory metadata = _transferFromSender(_amountOrId);
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
122
|
+
|
|
123
|
+
if (address(_hook) == address(0)) {
|
|
124
|
+
messageId = _dispatch(
|
|
125
|
+
_destination,
|
|
126
|
+
_gasPayment,
|
|
127
|
+
TokenMessage.format(_recipient, _amountOrId, metadata)
|
|
128
|
+
);
|
|
129
|
+
} else {
|
|
130
|
+
messageId = _dispatch(
|
|
131
|
+
_destination,
|
|
132
|
+
_recipient,
|
|
133
|
+
_gasPayment,
|
|
134
|
+
TokenMessage.format(_recipient, _amountOrId, metadata),
|
|
135
|
+
_hookMetadata,
|
|
136
|
+
IPostDispatchHook(_hook)
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
84
140
|
emit SentTransferRemote(_destination, _recipient, _amountOrId);
|
|
85
141
|
}
|
|
86
142
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const buildArtifact: any
|