@hyperbridge/core 1.0.0 → 1.0.1
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/README.md +3 -1
- package/contracts/apps/IntentGateway.sol +228 -0
- package/contracts/apps/TokenGateway.sol +142 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|

|
|
4
4
|
[](https://www.npmjs.com/package/@hyperbridge/core)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Hyperbridge SDK for EVM environments. This contains libraries & interfaces for working with hyperbridge contracts. These contracts can be used for sending data (Post requests), pulling data (Get requests), and working with token transfers (TokenGateway & IntentGateway)
|
|
7
7
|
|
|
8
8
|
### Interfaces
|
|
9
9
|
|
|
@@ -22,6 +22,8 @@
|
|
|
22
22
|
|
|
23
23
|
- [`HyperApp`](contracts/apps/HyperApp.sol) - Abstract base contract that implements `IApp` for building cross-chain applications with built-in fee estimation and host authorization
|
|
24
24
|
- [`HyperFungibleToken`](contracts/apps/HyperFungibleToken.sol) - Abstract ERC20 token implementation with gateway-restricted minting and burning capabilities for cross-chain bridging
|
|
25
|
+
- [`ITokenGateway`](contracts/apps/TokenGateway.sol) - Interface for the TokenGateway contract that enables transfers of hyper-fungible tokens using Hyperbridge. Supports both ERC20 token custody and ERC6160 token burn-and-mint mechanisms
|
|
26
|
+
- [`IIntentGateway`](contracts/apps/IntentGateway.sol) - Interface for the IntentGateway contract that facilitates cross-chain intent-based orders. Allows users to place orders that can be filled by market makers across different chains
|
|
25
27
|
|
|
26
28
|
## License
|
|
27
29
|
|
|
@@ -0,0 +1,228 @@
|
|
|
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.17;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @notice Tokens that must be received for a valid order fulfillment
|
|
19
|
+
*/
|
|
20
|
+
struct PaymentInfo {
|
|
21
|
+
/// @dev The address of the ERC20 token on the destination chain
|
|
22
|
+
/// @dev address(0) used as a sentinel for the native token
|
|
23
|
+
bytes32 token;
|
|
24
|
+
/// @dev The amount of the token to be sent
|
|
25
|
+
uint256 amount;
|
|
26
|
+
/// @dev The address to receive the output tokens
|
|
27
|
+
bytes32 beneficiary;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @notice Tokens that must be escrowed for an order
|
|
32
|
+
*/
|
|
33
|
+
struct TokenInfo {
|
|
34
|
+
/// @dev The address of the ERC20 token on the destination chain
|
|
35
|
+
/// @dev address(0) used as a sentinel for the native token
|
|
36
|
+
bytes32 token;
|
|
37
|
+
/// @dev The amount of the token to be sent
|
|
38
|
+
uint256 amount;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @dev Represents an order in the IntentGateway module.
|
|
43
|
+
* @param Order The structure defining an order.
|
|
44
|
+
*/
|
|
45
|
+
struct Order {
|
|
46
|
+
/// @dev The address of the user who is initiating the transfer
|
|
47
|
+
bytes32 user;
|
|
48
|
+
/// @dev The state machine identifier of the origin chain
|
|
49
|
+
bytes sourceChain;
|
|
50
|
+
/// @dev The state machine identifier of the destination chain
|
|
51
|
+
bytes destChain;
|
|
52
|
+
/// @dev The block number by which the order must be filled on the destination chain
|
|
53
|
+
uint256 deadline;
|
|
54
|
+
/// @dev The nonce of the order
|
|
55
|
+
uint256 nonce;
|
|
56
|
+
/// @dev Represents the dispatch fees associated with the IntentGateway.
|
|
57
|
+
uint256 fees;
|
|
58
|
+
/// @dev The tokens that the filler will provide.
|
|
59
|
+
PaymentInfo[] outputs;
|
|
60
|
+
/// @dev The tokens that are escrowed for the filler.
|
|
61
|
+
TokenInfo[] inputs;
|
|
62
|
+
/// @dev A bytes array to store the calls if any.
|
|
63
|
+
bytes callData;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @dev Struct to define the parameters for the IntentGateway module.
|
|
68
|
+
*/
|
|
69
|
+
struct Params {
|
|
70
|
+
/// @dev The address of the host contract
|
|
71
|
+
address host;
|
|
72
|
+
/// @dev Address of the dispatcher contract responsible for handling intents.
|
|
73
|
+
address dispatcher;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* @notice A struct representing the options for filling an intent.
|
|
78
|
+
* @dev This struct is used to specify various parameters and options
|
|
79
|
+
* when filling an intent in the IntentGateway contract.
|
|
80
|
+
*/
|
|
81
|
+
struct FillOptions {
|
|
82
|
+
/// @dev The fee paid to the relayer for processing transactions.
|
|
83
|
+
uint256 relayerFee;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* @dev Struct representing the options for canceling an intent.
|
|
88
|
+
*/
|
|
89
|
+
struct CancelOptions {
|
|
90
|
+
/// @dev The fee paid to the relayer for processing transactions.
|
|
91
|
+
uint256 relayerFee;
|
|
92
|
+
/// @dev Stores the height value.
|
|
93
|
+
uint256 height;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* @title IIntentGateway
|
|
98
|
+
* @author Polytope Labs (hello@polytope.technology)
|
|
99
|
+
*
|
|
100
|
+
* @dev Interface for the IntentGateway that allows for the creation and fulfillment of cross-chain orders.
|
|
101
|
+
*/
|
|
102
|
+
interface IIntentGateway {
|
|
103
|
+
/**
|
|
104
|
+
* @dev Emitted when an order is placed.
|
|
105
|
+
*/
|
|
106
|
+
event OrderPlaced(
|
|
107
|
+
/// @dev The address of the user who is initiating the transfer
|
|
108
|
+
bytes32 user,
|
|
109
|
+
/// @dev The state machine identifier of the origin chain
|
|
110
|
+
bytes sourceChain,
|
|
111
|
+
/// @dev The state machine identifier of the destination chain
|
|
112
|
+
bytes destChain,
|
|
113
|
+
/// @dev The block number by which the order must be filled on the destination chain
|
|
114
|
+
uint256 deadline,
|
|
115
|
+
/// @dev The nonce of the order
|
|
116
|
+
uint256 nonce,
|
|
117
|
+
/// @dev Represents the dispatch fees associated with the IntentGateway.
|
|
118
|
+
uint256 fees,
|
|
119
|
+
/// @dev The tokens that the filler will provide.
|
|
120
|
+
PaymentInfo[] outputs,
|
|
121
|
+
/// @dev The tokens that are escrowed for the filler.
|
|
122
|
+
TokenInfo[] inputs,
|
|
123
|
+
/// @dev A bytes array to store the calls if any.
|
|
124
|
+
bytes callData
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @dev Emitted when an order is filled.
|
|
129
|
+
* @param commitment The unique identifier of the order.
|
|
130
|
+
* @param filler The address of the entity that filled the order.
|
|
131
|
+
*/
|
|
132
|
+
event OrderFilled(bytes32 indexed commitment, address filler);
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* @dev Emitted when an escrow is released.
|
|
136
|
+
* @param commitment The unique identifier of the order.
|
|
137
|
+
*/
|
|
138
|
+
event EscrowReleased(bytes32 indexed commitment);
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* @dev Emitted when an escrow is refunded.
|
|
142
|
+
* @param commitment The unique identifier of the order.
|
|
143
|
+
*/
|
|
144
|
+
event EscrowRefunded(bytes32 indexed commitment);
|
|
145
|
+
|
|
146
|
+
/// @notice Thrown when an unauthorized action is attempted.
|
|
147
|
+
error Unauthorized();
|
|
148
|
+
|
|
149
|
+
/// @notice Thrown when an invalid input is provided.
|
|
150
|
+
error InvalidInput();
|
|
151
|
+
|
|
152
|
+
/// @notice Thrown when an action is attempted on an expired order.
|
|
153
|
+
error Expired();
|
|
154
|
+
|
|
155
|
+
/// @notice Thrown when there are insufficient native tokens to complete an action.
|
|
156
|
+
error InsufficientNativeToken();
|
|
157
|
+
|
|
158
|
+
/// @notice Thrown when an action is attempted on an order that has not yet expired.
|
|
159
|
+
error NotExpired();
|
|
160
|
+
|
|
161
|
+
/// @notice Thrown when an action is attempted on an order that has already been filled.
|
|
162
|
+
error Filled();
|
|
163
|
+
|
|
164
|
+
/// @notice Thrown when an action is attempted on the wrong chain.
|
|
165
|
+
error WrongChain();
|
|
166
|
+
|
|
167
|
+
/// @notice Thrown when an action is attempted on an unknown order.
|
|
168
|
+
error UnknownOrder();
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @notice Fallback function to receive ether
|
|
172
|
+
* @dev This function is called when ether is sent to the contract without data
|
|
173
|
+
* @custom:note The function is marked payable to allow receiving ether
|
|
174
|
+
*/
|
|
175
|
+
receive() external payable;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* @dev Should return the `IsmpHost` address for the current chain.
|
|
179
|
+
* The `IsmpHost` is an immutable contract that will never change.
|
|
180
|
+
*/
|
|
181
|
+
function host() external view returns (address);
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* @dev Fetch the IntentGateway contract instance for a chain.
|
|
185
|
+
*/
|
|
186
|
+
function instance(bytes calldata stateMachineId) external view returns (bytes32);
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @notice Retrieves the current parameter settings for the IntentGateway module
|
|
190
|
+
* @dev Returns a struct containing all configurable parameters
|
|
191
|
+
* @return Params A struct containing the module's current parameters
|
|
192
|
+
*/
|
|
193
|
+
function params() external view returns (Params memory);
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @notice Calculates the commitment slot hash required for storage queries.
|
|
197
|
+
* @dev The commitment slot hash is used as part of the proof verification process
|
|
198
|
+
* @param commitment The commitment value as a bytes32 hash
|
|
199
|
+
* @return bytes The calculated commitment slot hash
|
|
200
|
+
*/
|
|
201
|
+
function calculateCommitmentSlotHash(bytes32 commitment) external pure returns (bytes memory);
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* @notice Places an order with the given order details.
|
|
205
|
+
* @dev This function allows users to place an order by providing the order details.
|
|
206
|
+
* @param order The order details to be placed.
|
|
207
|
+
* @param graffiti Additional data that can be attached to the order
|
|
208
|
+
*/
|
|
209
|
+
function placeOrder(Order memory order, bytes32 graffiti) external payable;
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* @notice Fills an order with the specified options.
|
|
213
|
+
* @param order The order to be filled.
|
|
214
|
+
* @param options The options to be used when filling the order.
|
|
215
|
+
* @dev This function is payable and can accept Ether.
|
|
216
|
+
*/
|
|
217
|
+
function fillOrder(Order calldata order, FillOptions memory options) external payable;
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* @notice Cancels an existing order.
|
|
221
|
+
* @param order The order to be canceled.
|
|
222
|
+
* @param options Additional options for the cancellation process.
|
|
223
|
+
* @dev This function can only be called by the order owner and requires a payment.
|
|
224
|
+
* It will initiate a storage query on the source chain to verify the order has not
|
|
225
|
+
* yet been filled. If the order has not been filled, the tokens will be released.
|
|
226
|
+
*/
|
|
227
|
+
function cancelOrder(Order calldata order, CancelOptions memory options) external payable;
|
|
228
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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.17;
|
|
16
|
+
|
|
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;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Params for the TokenGateway contract
|
|
40
|
+
struct TokenGatewayParams {
|
|
41
|
+
// address of the IsmpHost contract on this chain
|
|
42
|
+
address host;
|
|
43
|
+
// dispatcher for delegating external calls
|
|
44
|
+
address dispatcher;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @title ITokenGateway
|
|
49
|
+
* @author Polytope Labs (hello@polytope.technology)
|
|
50
|
+
*
|
|
51
|
+
* @notice Interface for the TokenGateway contract that allows users to send either ERC20 or hyper-fungible tokens
|
|
52
|
+
* using Hyperbridge as a message-passing layer.
|
|
53
|
+
*
|
|
54
|
+
* @dev ERC20 tokens are custodied in exchange for hyper-fungible tokens to be minted on the destination chain,
|
|
55
|
+
* Otherwise if hyper-fungible tokens are sent, then it simply performs a burn-and-mint.
|
|
56
|
+
*/
|
|
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
|
+
);
|
|
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
|
+
);
|
|
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
|
+
);
|
|
101
|
+
|
|
102
|
+
// @dev Unexpected zero address
|
|
103
|
+
error ZeroAddress();
|
|
104
|
+
|
|
105
|
+
// @dev Provided amount was invalid
|
|
106
|
+
error InvalidAmount();
|
|
107
|
+
|
|
108
|
+
// @dev Provided token was unknown
|
|
109
|
+
error UnknownAsset();
|
|
110
|
+
|
|
111
|
+
// @dev Protocol invariant violated
|
|
112
|
+
error InconsistentState();
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @dev Read the protocol parameters
|
|
116
|
+
*/
|
|
117
|
+
function params() external view returns (TokenGatewayParams memory);
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @dev Fetch the address for an ERC20 asset
|
|
121
|
+
*/
|
|
122
|
+
function erc20(bytes32 assetId) external view returns (address);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @dev Fetch the address for a hyper-fungible asset
|
|
126
|
+
*/
|
|
127
|
+
function erc6160(bytes32 assetId) external view returns (address);
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* @dev Fetch the TokenGateway instance for a destination.
|
|
131
|
+
*/
|
|
132
|
+
function instance(bytes calldata destination) external view returns (address);
|
|
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;
|
|
142
|
+
}
|
package/package.json
CHANGED