@hyperbridge/core 1.2.1 → 1.4.0

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.
@@ -0,0 +1,388 @@
1
+ // Copyright (C) Polytope Labs Ltd.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ // Licensed under the Apache License, Version 2.0 (the "License");
5
+ // you may not use this file except in compliance with the License.
6
+ // You may obtain a copy of the License at
7
+ //
8
+ // http://www.apache.org/licenses/LICENSE-2.0
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software
11
+ // distributed under the License is distributed on an "AS IS" BASIS,
12
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ // See the License for the specific language governing permissions and
14
+ // limitations under the License.
15
+ pragma solidity ^0.8.24;
16
+
17
+ /**
18
+ * @notice Tokens that must be received for a valid order fulfillment
19
+ */
20
+ struct PaymentInfo {
21
+ /// @dev The address to receive the output tokens
22
+ bytes32 beneficiary;
23
+ /// @dev The assets to be provided by the filler
24
+ TokenInfo[] assets;
25
+ /// @dev Optional calldata to be executed on the destination chain
26
+ bytes call;
27
+ }
28
+
29
+ /**
30
+ * @notice Tokens that must be escrowed for an order
31
+ */
32
+ struct TokenInfo {
33
+ /// @dev The address of the ERC20 token on the destination chain
34
+ /// @dev address(0) used as a sentinel for the native token
35
+ bytes32 token;
36
+ /// @dev The amount of the token to be sent
37
+ uint256 amount;
38
+ }
39
+
40
+ /**
41
+ * @notice Information for executing calls before an order is placed on the destination chain
42
+ * @dev Used to specify pre-dispatch operations with associated assets
43
+ */
44
+ struct DispatchInfo {
45
+ /// @dev Assets to execute a predispatch call with
46
+ TokenInfo[] assets;
47
+ /// @dev The actual call data to be executed
48
+ bytes call;
49
+ }
50
+
51
+ /**
52
+ * @dev Represents an order in the IntentGateway module.
53
+ * @param Order The structure defining an order.
54
+ */
55
+ struct Order {
56
+ /// @dev The address of the user who is initiating the transfer
57
+ bytes32 user;
58
+ /// @dev The state machine identifier of the origin chain
59
+ bytes source;
60
+ /// @dev The state machine identifier of the destination chain
61
+ bytes destination;
62
+ /// @dev The block number by which the order must be filled on the destination chain
63
+ uint256 deadline;
64
+ /// @dev The nonce of the order
65
+ uint256 nonce;
66
+ /// @dev Represents the dispatch fees associated with the IntentGateway.
67
+ uint256 fees;
68
+ /// @dev Optional session key used to select winning solver.
69
+ address session;
70
+ /// @dev The predispatch information for the order
71
+ /// This is used to encode any calls before the order is placed
72
+ DispatchInfo predispatch;
73
+ /// @dev The tokens that are escrowed for the filler.
74
+ TokenInfo[] inputs;
75
+ /// @dev The filler output, ie the tokens that the filler will provide
76
+ PaymentInfo output;
77
+ }
78
+
79
+ /**
80
+ * @dev Request from hyperbridge for sweeping accumulated dust
81
+ */
82
+ struct SweepDust {
83
+ /// @dev The address of the beneficiary of the protocol fee
84
+ address beneficiary;
85
+ /// @dev The tokens to be withdrawn
86
+ TokenInfo[] outputs;
87
+ }
88
+
89
+ /**
90
+ * @dev Struct to define the parameters for the IntentGateway module.
91
+ */
92
+ struct Params {
93
+ /// @dev The address of the host contract
94
+ address host;
95
+ /// @dev Address of the dispatcher contract responsible for handling intents.
96
+ address dispatcher;
97
+ /// @dev Flag indicating whether solver selection is enabled.
98
+ bool solverSelection;
99
+ /// @dev The percentage of surplus (in basis points) that goes to the protocol. The rest goes to beneficiary.
100
+ /// 10000 = 100%, 5000 = 50%, etc.
101
+ uint256 surplusShareBps;
102
+ /// @dev The protocol fee in basis points charged on order inputs.
103
+ /// 10000 = 100%, 100 = 1%, etc.
104
+ uint256 protocolFeeBps;
105
+ }
106
+
107
+ /**
108
+ * @dev Struct to define the destination fee parameters.
109
+ */
110
+ struct DestinationFee {
111
+ /// @dev The percentage of fee (in basis points) charged for the destination chain.
112
+ /// 10000 = 100%, 5000 = 50%, etc.
113
+ uint256 destinationFeeBps;
114
+ /// @dev The state machine ID associated with the destination fee.
115
+ bytes32 stateMachineId;
116
+ }
117
+
118
+ /**
119
+ * @dev Struct to define a parameter update request from Hyperbridge
120
+ * @notice Contains both general parameters and destination-specific fee configurations
121
+ */
122
+ struct ParamsUpdate {
123
+ /// @dev The general parameters for the IntentGateway module
124
+ Params params;
125
+ /// @dev The destination fee parameters for specific chains
126
+ DestinationFee[] destinationFees;
127
+ }
128
+
129
+ /**
130
+ * @dev Struct representing the body of a request.
131
+ */
132
+ struct RequestBody {
133
+ /// @dev Represents the commitment of an order. This is typically a hash that uniquely identifies the order.
134
+ bytes32 commitment;
135
+ /// @dev Stores the identifier for the beneficiary.
136
+ bytes32 beneficiary;
137
+ /// @dev An array of token identifiers. Each element in the array represents a unique token involved in the order.
138
+ TokenInfo[] tokens;
139
+ }
140
+
141
+ /**
142
+ * @notice A struct representing the options for filling an intent.
143
+ * @dev This struct is used to specify various parameters and options
144
+ * when filling an intent in the IntentGateway contract.
145
+ */
146
+ struct FillOptions {
147
+ /// @dev The fee paid in feeTokens to the relayer for processing transactions.
148
+ uint256 relayerFee;
149
+ /// @dev The fee paid in native tokens for cross-chain dispatch.
150
+ uint256 nativeDispatchFee;
151
+ /// @dev The output tokens with amounts the solver is willing to give
152
+ /// @dev Must be strictly >= the amounts requested in order.output.assets
153
+ TokenInfo[] outputs;
154
+ }
155
+
156
+ /**
157
+ * @notice A struct representing the options for selecting a solver
158
+ * @dev This struct is used to specify various parameters and options
159
+ * when selecting a solver.
160
+ */
161
+ struct SelectOptions {
162
+ /// @dev The commitment hash of the order.
163
+ bytes32 commitment;
164
+ /// @dev The solver address to select.
165
+ address solver;
166
+ /// @dev The EIP-712 signature from the session key that signed SelectSolver(commitment, solver)
167
+ bytes signature;
168
+ }
169
+
170
+ /**
171
+ * @dev Struct representing the options for canceling an intent.
172
+ */
173
+ struct CancelOptions {
174
+ /// @dev The fee paid to the relayer for processing transactions.
175
+ uint256 relayerFee;
176
+ /// @dev Stores the height value.
177
+ uint256 height;
178
+ }
179
+
180
+ /**
181
+ * @dev Request from hyperbridge for adding a new deployment of IntentGateway
182
+ */
183
+ struct NewDeployment {
184
+ /// @dev Identifier for the state machine.
185
+ bytes stateMachineId;
186
+ /// @dev An address variable to store the gateway identifier.
187
+ address gateway;
188
+ }
189
+
190
+ /**
191
+ * @title IIntentGatewayV2
192
+ * @author Polytope Labs (hello@polytope.technology)
193
+ * @notice Interface for the IntentGatewayV2 contract
194
+ * @dev Defines all external functions, events, and errors for cross-chain intent fulfillment
195
+ */
196
+ interface IIntentGatewayV2 {
197
+ // ============================================
198
+ // Errors
199
+ // ============================================
200
+
201
+ /// @notice Thrown when an unauthorized action is attempted.
202
+ error Unauthorized();
203
+
204
+ /// @notice Thrown when an invalid input is provided.
205
+ error InvalidInput();
206
+
207
+ /// @notice Thrown when an action is attempted on an expired order.
208
+ error Expired();
209
+
210
+ /// @notice Thrown when there are insufficient native tokens to complete an action.
211
+ error InsufficientNativeToken();
212
+
213
+ /// @notice Thrown when an action is attempted on an order that has not yet expired.
214
+ error NotExpired();
215
+
216
+ /// @notice Thrown when an action is attempted on an order that has already been filled.
217
+ error Filled();
218
+
219
+ /// @notice Thrown when an action is attempted on an order that has been cancelled.
220
+ error Cancelled();
221
+
222
+ /// @notice Thrown when an action is attempted on the wrong chain.
223
+ error WrongChain();
224
+
225
+ /// @notice Thrown when an action is attempted on an unknown order.
226
+ error UnknownOrder();
227
+
228
+ // ============================================
229
+ // Events
230
+ // ============================================
231
+
232
+ /**
233
+ * @notice Emitted when an order is placed.
234
+ * @param user The address of the user who is initiating the transfer
235
+ * @param source The state machine identifier of the origin chain
236
+ * @param destination The state machine identifier of the destination chain
237
+ * @param deadline The block number by which the order must be filled
238
+ * @param nonce The nonce of the order
239
+ * @param fees The dispatch fees associated with the order
240
+ * @param session Optional session key used to select winning solver
241
+ * @param beneficiary The address to receive the output tokens
242
+ * @param predispatch The predispatch assets for the order
243
+ * @param inputs The tokens that are escrowed for the filler (amounts reflect values after protocol fee deduction)
244
+ * @param outputs The tokens that the filler will provide
245
+ */
246
+ event OrderPlaced(
247
+ bytes32 user,
248
+ bytes source,
249
+ bytes destination,
250
+ uint256 deadline,
251
+ uint256 nonce,
252
+ uint256 fees,
253
+ address session,
254
+ bytes32 beneficiary,
255
+ TokenInfo[] predispatch,
256
+ TokenInfo[] inputs,
257
+ TokenInfo[] outputs
258
+ );
259
+
260
+ /**
261
+ * @notice Emitted when an order is filled.
262
+ * @param commitment The unique identifier of the order
263
+ * @param filler The address of the entity that filled the order
264
+ */
265
+ event OrderFilled(bytes32 indexed commitment, address filler);
266
+
267
+ /**
268
+ * @notice Emitted when an escrow is released.
269
+ * @param commitment The unique identifier of the order
270
+ */
271
+ event EscrowReleased(bytes32 indexed commitment);
272
+
273
+ /**
274
+ * @notice Emitted when an escrow is refunded.
275
+ * @param commitment The unique identifier of the order
276
+ */
277
+ event EscrowRefunded(bytes32 indexed commitment);
278
+
279
+ /**
280
+ * @notice Emitted when parameters are updated.
281
+ * @param previous The previous parameters
282
+ * @param current The current parameters
283
+ */
284
+ event ParamsUpdated(Params previous, Params current);
285
+
286
+ /**
287
+ * @notice Emitted when a new deployment is added.
288
+ * @param stateMachineId The state machine identifier
289
+ * @param gateway The gateway identifier
290
+ */
291
+ event NewDeploymentAdded(bytes stateMachineId, address gateway);
292
+
293
+ /**
294
+ * @notice Emitted when dust is collected.
295
+ * @param token The token address
296
+ * @param amount The amount of dust collected
297
+ */
298
+ event DustCollected(address token, uint256 amount);
299
+
300
+ /**
301
+ * @notice Emitted when dust is swept to a beneficiary.
302
+ * @param token The token address
303
+ * @param amount The amount swept
304
+ * @param beneficiary The beneficiary of the funds
305
+ */
306
+ event DustSwept(address token, uint256 amount, address beneficiary);
307
+
308
+ // ============================================
309
+ // Constants
310
+ // ============================================
311
+
312
+ /**
313
+ * @notice EIP-712 type hash for SelectSolver message
314
+ */
315
+ function SELECT_SOLVER_TYPEHASH() external view returns (bytes32);
316
+
317
+ /**
318
+ * @notice EIP-712 domain separator
319
+ */
320
+ function DOMAIN_SEPARATOR() external view returns (bytes32);
321
+
322
+ // ============================================
323
+ // Functions
324
+ // ============================================
325
+
326
+ /**
327
+ * @notice Returns the host contract address.
328
+ * @return address The address of the IsmpHost contract
329
+ */
330
+ function host() external view returns (address);
331
+
332
+ /**
333
+ * @notice Fetch the IntentGateway contract instance for a chain.
334
+ * @param stateMachineId The state machine identifier
335
+ * @return address The gateway address for the given state machine
336
+ */
337
+ function instance(bytes calldata stateMachineId) external view returns (address);
338
+
339
+ /**
340
+ * @notice Sets the parameters for the IntentGateway module.
341
+ * @param p The parameters to be set, encapsulated in a Params struct
342
+ */
343
+ function setParams(Params memory p) external;
344
+
345
+ /**
346
+ * @notice Returns the current parameters of the module.
347
+ * @return Params A struct containing the module's current parameters
348
+ */
349
+ function params() external view returns (Params memory);
350
+
351
+ /**
352
+ * @notice Calculates the commitment slot hash for storage proof verification.
353
+ * @param commitment The commitment hash
354
+ * @return bytes The calculated commitment slot hash
355
+ */
356
+ function calculateCommitmentSlotHash(bytes32 commitment) external pure returns (bytes memory);
357
+
358
+ /**
359
+ * @notice Places an order for cross-chain intent fulfillment.
360
+ * @dev If protocolFeeBps is configured, a protocol fee is deducted from each input token amount.
361
+ * The full input amounts are escrowed, but the OrderPlaced event emits reduced amounts (after fee).
362
+ * Protocol fees are retained as dust and can be swept via SweepDust requests.
363
+ * @param order The order to be placed
364
+ * @param graffiti The arbitrary data used for identification purposes
365
+ */
366
+ function placeOrder(Order memory order, bytes32 graffiti) external payable;
367
+
368
+ /**
369
+ * @notice Selects a solver for an order (when solver selection is enabled).
370
+ * @param options The options for selecting a solver
371
+ * @return sessionKey The recovered session key address
372
+ */
373
+ function select(SelectOptions calldata options) external returns (address sessionKey);
374
+
375
+ /**
376
+ * @notice Fills an order with the specified options.
377
+ * @param order The order to be filled
378
+ * @param options The options to be used when filling the order
379
+ */
380
+ function fillOrder(Order calldata order, FillOptions calldata options) external payable;
381
+
382
+ /**
383
+ * @notice Cancels an order after it has expired.
384
+ * @param order The order to be cancelled
385
+ * @param options The cancellation options
386
+ */
387
+ function cancelOrder(Order calldata order, CancelOptions calldata options) external payable;
388
+ }
@@ -15,33 +15,33 @@
15
15
  pragma solidity ^0.8.17;
16
16
 
17
17
  struct TeleportParams {
18
- // amount to be sent
19
- uint256 amount;
20
- // Relayer fee
21
- uint256 relayerFee;
22
- // The token identifier to send
23
- bytes32 assetId;
24
- // Redeem ERC20 on the destination?
25
- bool redeem;
26
- // recipient address
27
- bytes32 to;
28
- // recipient state machine
29
- bytes dest;
30
- // request timeout in seconds
31
- uint64 timeout;
32
- // Amount of native token to pay for dispatching the request
33
- // if 0 will use the `IIsmpHost.feeToken`
34
- uint256 nativeCost;
35
- // destination contract call data
36
- bytes data;
18
+ // amount to be sent
19
+ uint256 amount;
20
+ // Relayer fee
21
+ uint256 relayerFee;
22
+ // The token identifier to send
23
+ bytes32 assetId;
24
+ // Redeem ERC20 on the destination?
25
+ bool redeem;
26
+ // recipient address
27
+ bytes32 to;
28
+ // recipient state machine
29
+ bytes dest;
30
+ // request timeout in seconds
31
+ uint64 timeout;
32
+ // Amount of native token to pay for dispatching the request
33
+ // if 0 will use the `IIsmpHost.feeToken`
34
+ uint256 nativeCost;
35
+ // destination contract call data
36
+ bytes data;
37
37
  }
38
38
 
39
39
  // Params for the TokenGateway contract
40
40
  struct TokenGatewayParams {
41
- // address of the IsmpHost contract on this chain
42
- address host;
43
- // dispatcher for delegating external calls
44
- address dispatcher;
41
+ // address of the IsmpHost contract on this chain
42
+ address host;
43
+ // dispatcher for delegating external calls
44
+ address dispatcher;
45
45
  }
46
46
 
47
47
  /**
@@ -55,88 +55,88 @@ struct TokenGatewayParams {
55
55
  * Otherwise if hyper-fungible tokens are sent, then it simply performs a burn-and-mint.
56
56
  */
57
57
  interface ITokenGateway {
58
- // User has received some assets
59
- event AssetReceived(
60
- // The amount that was provided to the user
61
- uint256 amount,
62
- // The associated request commitment
63
- bytes32 commitment,
64
- // The source of the funds
65
- bytes32 indexed from,
66
- // The beneficiary of the funds
67
- address indexed beneficiary,
68
- // The provided assetId
69
- bytes32 indexed assetId
70
- );
58
+ // User has received some assets
59
+ event AssetReceived(
60
+ // The amount that was provided to the user
61
+ uint256 amount,
62
+ // The associated request commitment
63
+ bytes32 commitment,
64
+ // The source of the funds
65
+ bytes32 indexed from,
66
+ // The beneficiary of the funds
67
+ address indexed beneficiary,
68
+ // The provided assetId
69
+ bytes32 indexed assetId
70
+ );
71
71
 
72
- // User has sent some assets
73
- event AssetTeleported(
74
- // The beneficiary of the funds
75
- bytes32 to,
76
- // The destination chain
77
- string dest,
78
- // The amount that was requested to be sent
79
- uint256 amount,
80
- // The associated request commitment
81
- bytes32 commitment,
82
- // The source of the funds
83
- address indexed from,
84
- // The provided assetId
85
- bytes32 indexed assetId,
86
- // Flag to redeem funds from the TokenGateway
87
- bool redeem
88
- );
72
+ // User has sent some assets
73
+ event AssetTeleported(
74
+ // The beneficiary of the funds
75
+ bytes32 to,
76
+ // The destination chain
77
+ string dest,
78
+ // The amount that was requested to be sent
79
+ uint256 amount,
80
+ // The associated request commitment
81
+ bytes32 commitment,
82
+ // The source of the funds
83
+ address indexed from,
84
+ // The provided assetId
85
+ bytes32 indexed assetId,
86
+ // Flag to redeem funds from the TokenGateway
87
+ bool redeem
88
+ );
89
89
 
90
- // User assets could not be delivered and have been refunded.
91
- event AssetRefunded(
92
- // The amount that was requested to be sent
93
- uint256 amount,
94
- // The associated request commitment
95
- bytes32 commitment,
96
- // The beneficiary of the funds
97
- address indexed beneficiary,
98
- // The provided assetId
99
- bytes32 indexed assetId
100
- );
90
+ // User assets could not be delivered and have been refunded.
91
+ event AssetRefunded(
92
+ // The amount that was requested to be sent
93
+ uint256 amount,
94
+ // The associated request commitment
95
+ bytes32 commitment,
96
+ // The beneficiary of the funds
97
+ address indexed beneficiary,
98
+ // The provided assetId
99
+ bytes32 indexed assetId
100
+ );
101
101
 
102
- // @dev Unexpected zero address
103
- error ZeroAddress();
102
+ // @dev Unexpected zero address
103
+ error ZeroAddress();
104
104
 
105
- // @dev Provided amount was invalid
106
- error InvalidAmount();
105
+ // @dev Provided amount was invalid
106
+ error InvalidAmount();
107
107
 
108
- // @dev Provided token was unknown
109
- error UnknownAsset();
108
+ // @dev Provided token was unknown
109
+ error UnknownAsset();
110
110
 
111
- // @dev Protocol invariant violated
112
- error InconsistentState();
111
+ // @dev Protocol invariant violated
112
+ error InconsistentState();
113
113
 
114
- /**
115
- * @dev Read the protocol parameters
116
- */
117
- function params() external view returns (TokenGatewayParams memory);
114
+ /**
115
+ * @dev Read the protocol parameters
116
+ */
117
+ function params() external view returns (TokenGatewayParams memory);
118
118
 
119
- /**
120
- * @dev Fetch the address for an ERC20 asset
121
- */
122
- function erc20(bytes32 assetId) external view returns (address);
119
+ /**
120
+ * @dev Fetch the address for an ERC20 asset
121
+ */
122
+ function erc20(bytes32 assetId) external view returns (address);
123
123
 
124
- /**
125
- * @dev Fetch the address for a hyper-fungible asset
126
- */
127
- function erc6160(bytes32 assetId) external view returns (address);
124
+ /**
125
+ * @dev Fetch the address for a hyper-fungible asset
126
+ */
127
+ function erc6160(bytes32 assetId) external view returns (address);
128
128
 
129
- /**
130
- * @dev Fetch the TokenGateway instance for a destination.
131
- */
132
- function instance(bytes calldata destination) external view returns (address);
129
+ /**
130
+ * @dev Fetch the TokenGateway instance for a destination.
131
+ */
132
+ function instance(bytes calldata destination) external view returns (address);
133
133
 
134
- /**
135
- * @dev Teleports a local ERC20/hyper-fungible asset to the destination chain. Allows users to pay
136
- * the Hyperbridge fees in the native token or `IIsmpHost.feeToken`
137
- *
138
- * @notice If a request times out, users can request a refund permissionlessly through
139
- * `HandlerV1.handlePostRequestTimeouts`.
140
- */
141
- function teleport(TeleportParams calldata teleportParams) external payable;
134
+ /**
135
+ * @dev Teleports a local ERC20/hyper-fungible asset to the destination chain. Allows users to pay
136
+ * the Hyperbridge fees in the native token or `IIsmpHost.feeToken`
137
+ *
138
+ * @notice If a request times out, users can request a refund permissionlessly through
139
+ * `HandlerV1.handlePostRequestTimeouts`.
140
+ */
141
+ function teleport(TeleportParams calldata teleportParams) external payable;
142
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperbridge/core",
3
- "version": "1.2.1",
3
+ "version": "1.4.0",
4
4
  "description": "Hyperbridge Solidity SDK for dispatching & receiving cross-chain messages",
5
5
  "author": "Polytope Labs <hello@polytope.technology>",
6
6
  "license": "Apache-2.0",