@hyperbridge/core 1.0.0 → 1.1.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.
- package/README.md +3 -1
- package/contracts/apps/HyperApp.sol +69 -19
- package/contracts/apps/IntentGateway.sol +290 -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
|
|
|
@@ -17,6 +17,8 @@ import {PostRequest, PostResponse, GetRequest} from "../libraries/Message.sol";
|
|
|
17
17
|
import {DispatchPost, DispatchPostResponse, DispatchGet, IDispatcher} from "../interfaces/IDispatcher.sol";
|
|
18
18
|
import {IApp, IncomingPostRequest, IncomingPostResponse, IncomingGetResponse} from "../interfaces/IApp.sol";
|
|
19
19
|
|
|
20
|
+
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|
21
|
+
|
|
20
22
|
/**
|
|
21
23
|
* @dev Uniswap interface for estimating fees in the native token
|
|
22
24
|
*/
|
|
@@ -65,19 +67,6 @@ abstract contract HyperApp is IApp {
|
|
|
65
67
|
return request.fee + (len * IDispatcher(host()).perByteFee(request.dest));
|
|
66
68
|
}
|
|
67
69
|
|
|
68
|
-
/**
|
|
69
|
-
* @dev returns the quoted fee in the native token for dispatching a POST request
|
|
70
|
-
*/
|
|
71
|
-
function quoteNative(DispatchPost memory request) public view returns (uint256) {
|
|
72
|
-
uint256 fee = quote(request);
|
|
73
|
-
address _host = host();
|
|
74
|
-
address _uniswap = IDispatcher(_host).uniswapV2Router();
|
|
75
|
-
address[] memory path = new address[](2);
|
|
76
|
-
path[0] = IUniswapV2Router02(_uniswap).WETH();
|
|
77
|
-
path[1] = IDispatcher(_host).feeToken();
|
|
78
|
-
return IUniswapV2Router02(_uniswap).getAmountsIn(fee, path)[0];
|
|
79
|
-
}
|
|
80
|
-
|
|
81
70
|
/**
|
|
82
71
|
* @dev returns the quoted fee in the feeToken for dispatching a GET request
|
|
83
72
|
*/
|
|
@@ -90,9 +79,17 @@ abstract contract HyperApp is IApp {
|
|
|
90
79
|
}
|
|
91
80
|
|
|
92
81
|
/**
|
|
93
|
-
* @dev returns the quoted fee in the
|
|
82
|
+
* @dev returns the quoted fee in the feeToken for dispatching a POST response
|
|
94
83
|
*/
|
|
95
|
-
function
|
|
84
|
+
function quote(DispatchPostResponse memory response) public view returns (uint256) {
|
|
85
|
+
uint256 len = 32 > response.response.length ? 32 : response.response.length;
|
|
86
|
+
return response.fee + (len * IDispatcher(host()).perByteFee(response.request.source));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @dev returns the quoted fee in the native token for dispatching a POST request
|
|
91
|
+
*/
|
|
92
|
+
function quoteNative(DispatchPost memory request) public view returns (uint256) {
|
|
96
93
|
uint256 fee = quote(request);
|
|
97
94
|
address _host = host();
|
|
98
95
|
address _uniswap = IDispatcher(_host).uniswapV2Router();
|
|
@@ -103,11 +100,16 @@ abstract contract HyperApp is IApp {
|
|
|
103
100
|
}
|
|
104
101
|
|
|
105
102
|
/**
|
|
106
|
-
* @dev returns the quoted fee in the
|
|
103
|
+
* @dev returns the quoted fee in the native token for dispatching a GET request
|
|
107
104
|
*/
|
|
108
|
-
function
|
|
109
|
-
uint256
|
|
110
|
-
|
|
105
|
+
function quoteNative(DispatchGet memory request) public view returns (uint256) {
|
|
106
|
+
uint256 fee = quote(request);
|
|
107
|
+
address _host = host();
|
|
108
|
+
address _uniswap = IDispatcher(_host).uniswapV2Router();
|
|
109
|
+
address[] memory path = new address[](2);
|
|
110
|
+
path[0] = IUniswapV2Router02(_uniswap).WETH();
|
|
111
|
+
path[1] = IDispatcher(_host).feeToken();
|
|
112
|
+
return IUniswapV2Router02(_uniswap).getAmountsIn(fee, path)[0];
|
|
111
113
|
}
|
|
112
114
|
|
|
113
115
|
/**
|
|
@@ -123,6 +125,54 @@ abstract contract HyperApp is IApp {
|
|
|
123
125
|
return IUniswapV2Router02(_uniswap).getAmountsIn(fee, path)[0];
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
/**
|
|
129
|
+
* @notice Dispatches a POST request using the fee token for payment
|
|
130
|
+
* @dev Handles fee token approval and transfer before dispatching the request to the Host.
|
|
131
|
+
* If the payer is not this contract, transfers fee tokens from the payer to this contract first.
|
|
132
|
+
* @param request The POST request to dispatch containing destination, body, timeout, and fee parameters
|
|
133
|
+
* @param payer The address that will pay the fee token. If different from this contract, must have approved this contract to spend the fee amount
|
|
134
|
+
*/
|
|
135
|
+
function dispatchWithFeeToken(DispatchPost memory request, address payer) internal {
|
|
136
|
+
address hostAddr = host();
|
|
137
|
+
address feeToken = IDispatcher(hostAddr).feeToken();
|
|
138
|
+
uint256 fee = quote(request);
|
|
139
|
+
if (payer != address(this)) IERC20(feeToken).transferFrom(payer, address(this), fee);
|
|
140
|
+
IERC20(feeToken).approve(hostAddr, fee);
|
|
141
|
+
IDispatcher(hostAddr).dispatch(request);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @notice Dispatches a POST response using the fee token for payment
|
|
146
|
+
* @dev Handles fee token approval and transfer before dispatching the response to the Host.
|
|
147
|
+
* If the payer is not this contract, transfers fee tokens from the payer to this contract first.
|
|
148
|
+
* @param response The POST response to dispatch containing the original request, response data, timeout, and fee parameters
|
|
149
|
+
* @param payer The address that will pay the fee token. If different from this contract, must have approved this contract to spend the fee amount
|
|
150
|
+
*/
|
|
151
|
+
function dispatchWithFeeToken(DispatchPostResponse memory response, address payer) internal {
|
|
152
|
+
address hostAddr = host();
|
|
153
|
+
address feeToken = IDispatcher(hostAddr).feeToken();
|
|
154
|
+
uint256 fee = quote(response);
|
|
155
|
+
if (payer != address(this)) IERC20(feeToken).transferFrom(payer, address(this), fee);
|
|
156
|
+
IERC20(feeToken).approve(hostAddr, fee);
|
|
157
|
+
IDispatcher(hostAddr).dispatch(response);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* @notice Dispatches a GET request using the fee token for payment
|
|
162
|
+
* @dev Handles fee token approval and transfer before dispatching the request to the Host.
|
|
163
|
+
* If the payer is not this contract, transfers fee tokens from the payer to this contract first.
|
|
164
|
+
* @param request The GET request to dispatch containing destination, keys, height, timeout, and fee parameters
|
|
165
|
+
* @param payer The address that will pay the fee token. If different from this contract, must have approved this contract to spend the fee amount
|
|
166
|
+
*/
|
|
167
|
+
function dispatchWithFeeToken(DispatchGet memory request, address payer) internal {
|
|
168
|
+
address hostAddr = host();
|
|
169
|
+
address feeToken = IDispatcher(hostAddr).feeToken();
|
|
170
|
+
uint256 fee = quote(request);
|
|
171
|
+
if (payer != address(this)) IERC20(feeToken).transferFrom(payer, address(this), fee);
|
|
172
|
+
IERC20(feeToken).approve(hostAddr, fee);
|
|
173
|
+
IDispatcher(hostAddr).dispatch(request);
|
|
174
|
+
}
|
|
175
|
+
|
|
126
176
|
/**
|
|
127
177
|
* @notice Callback for receiving incoming POST requests
|
|
128
178
|
* @dev Called by the Host when a new POST request is received for this app.
|
|
@@ -0,0 +1,290 @@
|
|
|
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 Struct for predispatch information
|
|
43
|
+
*/
|
|
44
|
+
struct PredispatchInfo {
|
|
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
|
+
*/
|
|
54
|
+
struct Order {
|
|
55
|
+
/// @dev The address of the user who is initiating the transfer
|
|
56
|
+
bytes32 user;
|
|
57
|
+
/// @dev The state machine identifier of the origin chain
|
|
58
|
+
bytes sourceChain;
|
|
59
|
+
/// @dev The state machine identifier of the destination chain
|
|
60
|
+
bytes destChain;
|
|
61
|
+
/// @dev The block number by which the order must be filled on the destination chain
|
|
62
|
+
uint256 deadline;
|
|
63
|
+
/// @dev The nonce of the order
|
|
64
|
+
uint256 nonce;
|
|
65
|
+
/// @dev Represents the dispatch fees associated with the IntentGateway.
|
|
66
|
+
uint256 fees;
|
|
67
|
+
/// @dev The tokens that the filler will provide.
|
|
68
|
+
PaymentInfo[] outputs;
|
|
69
|
+
/// @dev The tokens that are escrowed for the filler.
|
|
70
|
+
TokenInfo[] inputs;
|
|
71
|
+
/// @dev The predispatch information for the order
|
|
72
|
+
PredispatchInfo predispatch;
|
|
73
|
+
/// @dev A bytes array to store the calls if any.
|
|
74
|
+
bytes callData;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* @dev Struct to define the parameters for the IntentGateway module.
|
|
79
|
+
*/
|
|
80
|
+
struct Params {
|
|
81
|
+
/// @dev The address of the host contract
|
|
82
|
+
address host;
|
|
83
|
+
/// @dev Address of the dispatcher contract responsible for handling intents.
|
|
84
|
+
address dispatcher;
|
|
85
|
+
/// @dev Protocol fee in basis points (BPS) deducted from filler-provided tokens
|
|
86
|
+
uint256 protocolFeeBps;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @notice A struct representing the options for filling an intent.
|
|
91
|
+
*/
|
|
92
|
+
struct FillOptions {
|
|
93
|
+
/// @dev The fee paid to the relayer for processing transactions.
|
|
94
|
+
uint256 relayerFee;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* @dev Struct representing the options for canceling an intent.
|
|
99
|
+
*/
|
|
100
|
+
struct CancelOptions {
|
|
101
|
+
/// @dev The fee paid to the relayer for processing transactions.
|
|
102
|
+
uint256 relayerFee;
|
|
103
|
+
/// @dev Stores the height value.
|
|
104
|
+
uint256 height;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* @title IIntentGatewayV2
|
|
109
|
+
* @author Polytope Labs (hello@polytope.technology)
|
|
110
|
+
* @notice Interface for the IntentGatewayV2 contract
|
|
111
|
+
* @dev The IntentGateway allows for the creation and fulfillment of cross-chain orders.
|
|
112
|
+
*/
|
|
113
|
+
interface IIntentGateway {
|
|
114
|
+
/**
|
|
115
|
+
* @dev Enum representing the different kinds of incoming requests that can be executed.
|
|
116
|
+
*/
|
|
117
|
+
enum RequestKind {
|
|
118
|
+
/// @dev Identifies a request for redeeming an escrow.
|
|
119
|
+
RedeemEscrow,
|
|
120
|
+
/// @dev Identifies a request for recording new contract deployments
|
|
121
|
+
NewDeployment,
|
|
122
|
+
/// @dev Identifies a request for updating parameters.
|
|
123
|
+
UpdateParams,
|
|
124
|
+
/// @dev Identifies a request for refunding an escrow.
|
|
125
|
+
RefundEscrow,
|
|
126
|
+
/// @dev Identifies a request for collecting fees.
|
|
127
|
+
CollectFees
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/// @notice Thrown when an unauthorized action is attempted.
|
|
131
|
+
error Unauthorized();
|
|
132
|
+
|
|
133
|
+
/// @notice Thrown when an invalid input is provided.
|
|
134
|
+
error InvalidInput();
|
|
135
|
+
|
|
136
|
+
/// @notice Thrown when an action is attempted on an expired order.
|
|
137
|
+
error Expired();
|
|
138
|
+
|
|
139
|
+
/// @notice Thrown when there are insufficient native tokens to complete an action.
|
|
140
|
+
error InsufficientNativeToken();
|
|
141
|
+
|
|
142
|
+
/// @notice Thrown when an action is attempted on an order that has not yet expired.
|
|
143
|
+
error NotExpired();
|
|
144
|
+
|
|
145
|
+
/// @notice Thrown when an action is attempted on an order that has already been filled.
|
|
146
|
+
error Filled();
|
|
147
|
+
|
|
148
|
+
/// @notice Thrown when an action is attempted on an order that has been cancelled.
|
|
149
|
+
error Cancelled();
|
|
150
|
+
|
|
151
|
+
/// @notice Thrown when an action is attempted on the wrong chain.
|
|
152
|
+
error WrongChain();
|
|
153
|
+
|
|
154
|
+
/// @notice Thrown when an action is attempted on an unknown order.
|
|
155
|
+
error UnknownOrder();
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @dev Emitted when an order is placed.
|
|
159
|
+
*/
|
|
160
|
+
event OrderPlaced(
|
|
161
|
+
/// @dev The address of the user who is initiating the transfer
|
|
162
|
+
bytes32 user,
|
|
163
|
+
/// @dev The state machine identifier of the origin chain
|
|
164
|
+
bytes sourceChain,
|
|
165
|
+
/// @dev The state machine identifier of the destination chain
|
|
166
|
+
bytes destChain,
|
|
167
|
+
/// @dev The block number by which the order must be filled on the destination chain
|
|
168
|
+
uint256 deadline,
|
|
169
|
+
/// @dev The nonce of the order
|
|
170
|
+
uint256 nonce,
|
|
171
|
+
/// @dev Represents the dispatch fees associated with the IntentGateway.
|
|
172
|
+
uint256 fees,
|
|
173
|
+
/// @dev Assets that were used to execute a predispatch call
|
|
174
|
+
TokenInfo[] predispatch,
|
|
175
|
+
/// @dev The tokens that are escrowed for the filler.
|
|
176
|
+
TokenInfo[] inputs,
|
|
177
|
+
/// @dev The tokens that the filler will provide.
|
|
178
|
+
PaymentInfo[] outputs
|
|
179
|
+
);
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @notice Event emitted when an order is filled.
|
|
183
|
+
* @param commitment The order commitment hash
|
|
184
|
+
* @param filler The address of the filler
|
|
185
|
+
*/
|
|
186
|
+
event OrderFilled(bytes32 commitment, address filler);
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* @notice Event emitted when escrow is released.
|
|
190
|
+
* @param commitment The order commitment hash
|
|
191
|
+
*/
|
|
192
|
+
event EscrowReleased(bytes32 commitment);
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* @notice Event emitted when escrow is refunded.
|
|
196
|
+
* @param commitment The order commitment hash
|
|
197
|
+
*/
|
|
198
|
+
event EscrowRefunded(bytes32 commitment);
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* @notice Event emitted when parameters are updated.
|
|
202
|
+
* @param previous The previous parameters
|
|
203
|
+
* @param current The new parameters
|
|
204
|
+
*/
|
|
205
|
+
event ParamsUpdated(Params previous, Params current);
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* @notice Event emitted when a new deployment is added.
|
|
209
|
+
* @param stateMachineId The state machine identifier
|
|
210
|
+
* @param gateway The gateway address
|
|
211
|
+
*/
|
|
212
|
+
event NewDeploymentAdded(bytes stateMachineId, bytes32 gateway);
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* @dev Emitted when dust is collected from predispatch swaps.
|
|
216
|
+
* @param token The token contract address of the dust, address(0) for native currency.
|
|
217
|
+
* @param amount The amount of dust collected.
|
|
218
|
+
*/
|
|
219
|
+
event DustCollected(address token, uint256 amount);
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* @dev Emitted when protocol fee is collected from a filler.
|
|
223
|
+
* @param token The token contract address of the fee, address(0) for native currency.
|
|
224
|
+
* @param amount The amount of protocol fee collected.
|
|
225
|
+
* @param chain The chain where the funds are stored.
|
|
226
|
+
*/
|
|
227
|
+
event FeeCollected(address token, uint256 amount, bytes chain);
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* @dev Emitted when protocol revenue is withdrawn.
|
|
231
|
+
* @param token The token contract address of the fee, address(0) for native currency.
|
|
232
|
+
* @param amount The amount of protocol revenue collected.
|
|
233
|
+
* @param beneficiary The beneficiary of the funds
|
|
234
|
+
*/
|
|
235
|
+
event RevenueWithdrawn(address token, uint256 amount, address beneficiary);
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* @notice Returns the host address.
|
|
239
|
+
* @return The host contract address
|
|
240
|
+
*/
|
|
241
|
+
function host() external view returns (address);
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* @notice Returns the instance address for a given state machine.
|
|
245
|
+
* @param stateMachineId The state machine identifier
|
|
246
|
+
* @return The instance address
|
|
247
|
+
*/
|
|
248
|
+
function instance(bytes calldata stateMachineId) external view returns (bytes32);
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* @notice Returns the current gateway parameters.
|
|
252
|
+
* @return The current parameters
|
|
253
|
+
*/
|
|
254
|
+
function params() external view returns (Params memory);
|
|
255
|
+
|
|
256
|
+
/**
|
|
257
|
+
* @notice Calculates the commitment slot hash for an order.
|
|
258
|
+
* @param commitment The order commitment
|
|
259
|
+
* @return The slot hash
|
|
260
|
+
*/
|
|
261
|
+
function calculateCommitmentSlotHash(bytes32 commitment) external pure returns (bytes32);
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* @notice Places a new order.
|
|
265
|
+
* @param order The order details
|
|
266
|
+
* @param graffiti Additional data
|
|
267
|
+
*/
|
|
268
|
+
function placeOrder(Order memory order, bytes32 graffiti) external payable;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* @notice Fills an existing order.
|
|
272
|
+
* @param order The order to fill
|
|
273
|
+
* @param options Fill options including relayer fee
|
|
274
|
+
*/
|
|
275
|
+
function fillOrder(Order calldata order, FillOptions memory options) external payable;
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* @notice Cancels an order (for expired orders).
|
|
279
|
+
* @param order The order to cancel
|
|
280
|
+
* @param options Cancel options including height and relayer fee
|
|
281
|
+
*/
|
|
282
|
+
function cancelOrder(Order calldata order, CancelOptions memory options) external payable;
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* @notice Cancels a limit order (for orders with deadline = 0).
|
|
286
|
+
* @param order The order to cancel
|
|
287
|
+
* @param options Cancel options including relayer fee
|
|
288
|
+
*/
|
|
289
|
+
function cancelLimitOrder(Order calldata order, CancelOptions memory options) external payable;
|
|
290
|
+
}
|
|
@@ -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