@hyperbridge/sdk 1.0.0 → 1.2.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 +45 -3
- package/dist/browser/index.d.ts +2190 -0
- package/dist/browser/index.js +11662 -0
- package/dist/browser/index.js.map +1 -0
- package/dist/browser/web_bg.wasm +0 -0
- package/dist/node/index.d.ts +2190 -0
- package/dist/node/index.js +11613 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/node_bg.wasm +0 -0
- package/package.json +46 -16
- package/plugins/vite.d.ts +11 -0
- package/plugins/vite.js +55 -0
- package/dist/abis/erc6160.d.ts +0 -370
- package/dist/abis/erc6160.js +0 -238
- package/dist/abis/erc6160.js.map +0 -1
- package/dist/abis/evmHost.d.ts +0 -1752
- package/dist/abis/evmHost.js +0 -2250
- package/dist/abis/evmHost.js.map +0 -1
- package/dist/abis/handler.d.ts +0 -580
- package/dist/abis/handler.js +0 -750
- package/dist/abis/handler.js.map +0 -1
- package/dist/abis/pingModule.d.ts +0 -594
- package/dist/abis/pingModule.js +0 -765
- package/dist/abis/pingModule.js.map +0 -1
- package/dist/abis/tokenGateway.d.ts +0 -839
- package/dist/abis/tokenGateway.js +0 -471
- package/dist/abis/tokenGateway.js.map +0 -1
- package/dist/chain.d.ts +0 -83
- package/dist/chain.js +0 -34
- package/dist/chain.js.map +0 -1
- package/dist/chains/evm.d.ts +0 -86
- package/dist/chains/evm.js +0 -249
- package/dist/chains/evm.js.map +0 -1
- package/dist/chains/substrate.d.ts +0 -88
- package/dist/chains/substrate.js +0 -287
- package/dist/chains/substrate.js.map +0 -1
- package/dist/client.d.ts +0 -216
- package/dist/client.js +0 -774
- package/dist/client.js.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +0 -7
- package/dist/index.js.map +0 -1
- package/dist/queries.d.ts +0 -3
- package/dist/queries.js +0 -78
- package/dist/queries.js.map +0 -1
- package/dist/tests/hyperbridgeRequests.test.d.ts +0 -1
- package/dist/tests/hyperbridgeRequests.test.js +0 -415
- package/dist/tests/hyperbridgeRequests.test.js.map +0 -1
- package/dist/tests/postRequest.test.d.ts +0 -1
- package/dist/tests/postRequest.test.js +0 -293
- package/dist/tests/postRequest.test.js.map +0 -1
- package/dist/tests/setup.d.ts +0 -1
- package/dist/tests/setup.js +0 -6
- package/dist/tests/setup.js.map +0 -1
- package/dist/tests/tokenGateway.test.d.ts +0 -1
- package/dist/tests/tokenGateway.test.js +0 -85
- package/dist/tests/tokenGateway.test.js.map +0 -1
- package/dist/tests/xcmGateway.test.d.ts +0 -1
- package/dist/tests/xcmGateway.test.js +0 -71
- package/dist/tests/xcmGateway.test.js.map +0 -1
- package/dist/types/index.d.ts +0 -238
- package/dist/types/index.js +0 -30
- package/dist/types/index.js.map +0 -1
- package/dist/utils/mmr.d.ts +0 -13
- package/dist/utils/mmr.js +0 -153
- package/dist/utils/mmr.js.map +0 -1
- package/dist/utils/substrate.d.ts +0 -1913
- package/dist/utils/substrate.js +0 -361
- package/dist/utils/substrate.js.map +0 -1
- package/dist/utils/tokenGateway.d.ts +0 -68
- package/dist/utils/tokenGateway.js +0 -151
- package/dist/utils/tokenGateway.js.map +0 -1
- package/dist/utils/xcmGateway.d.ts +0 -81
- package/dist/utils/xcmGateway.js +0 -218
- package/dist/utils/xcmGateway.js.map +0 -1
- package/dist/utils.d.ts +0 -57
- package/dist/utils.js +0 -96
- package/dist/utils.js.map +0 -1
|
@@ -0,0 +1,2190 @@
|
|
|
1
|
+
import { ConsolaInstance } from 'consola';
|
|
2
|
+
import { GraphQLClient } from 'graphql-request';
|
|
3
|
+
import { Hex, Log, PublicClient } from 'viem';
|
|
4
|
+
import { ApiPromise } from '@polkadot/api';
|
|
5
|
+
import { SignerOptions } from '@polkadot/api/types';
|
|
6
|
+
import { Chain } from 'viem/chains';
|
|
7
|
+
|
|
8
|
+
type HexString = `0x${string}`;
|
|
9
|
+
interface IConfig {
|
|
10
|
+
source: IEvmConfig | ISubstrateConfig;
|
|
11
|
+
dest: IEvmConfig | ISubstrateConfig;
|
|
12
|
+
hyperbridge: IHyperbridgeConfig;
|
|
13
|
+
tracing?: boolean;
|
|
14
|
+
}
|
|
15
|
+
interface IEvmConfig {
|
|
16
|
+
rpcUrl: string;
|
|
17
|
+
stateMachineId: string;
|
|
18
|
+
host: string;
|
|
19
|
+
consensusStateId: string;
|
|
20
|
+
}
|
|
21
|
+
interface ISubstrateConfig {
|
|
22
|
+
wsUrl: string;
|
|
23
|
+
consensusStateId: string;
|
|
24
|
+
hasher: "Keccak" | "Blake2";
|
|
25
|
+
stateMachineId: string;
|
|
26
|
+
}
|
|
27
|
+
interface IHyperbridgeConfig {
|
|
28
|
+
wsUrl: string;
|
|
29
|
+
stateMachineId: string;
|
|
30
|
+
consensusStateId: string;
|
|
31
|
+
}
|
|
32
|
+
interface IPostRequest {
|
|
33
|
+
source: string;
|
|
34
|
+
dest: string;
|
|
35
|
+
from: HexString;
|
|
36
|
+
to: HexString;
|
|
37
|
+
nonce: bigint;
|
|
38
|
+
body: HexString;
|
|
39
|
+
timeoutTimestamp: bigint;
|
|
40
|
+
}
|
|
41
|
+
interface IGetRequest {
|
|
42
|
+
source: string;
|
|
43
|
+
dest: string;
|
|
44
|
+
from: HexString;
|
|
45
|
+
nonce: bigint;
|
|
46
|
+
height: bigint;
|
|
47
|
+
keys: HexString[];
|
|
48
|
+
timeoutTimestamp: bigint;
|
|
49
|
+
context: HexString;
|
|
50
|
+
}
|
|
51
|
+
interface GetResponseStorageValues {
|
|
52
|
+
key: HexString;
|
|
53
|
+
value: HexString;
|
|
54
|
+
}
|
|
55
|
+
interface IPostResponse {
|
|
56
|
+
post: IPostRequest;
|
|
57
|
+
response: string;
|
|
58
|
+
timeoutTimestamp: bigint;
|
|
59
|
+
}
|
|
60
|
+
type IMessage = {
|
|
61
|
+
Requests: HexString[];
|
|
62
|
+
} | {
|
|
63
|
+
Responses: HexString[];
|
|
64
|
+
};
|
|
65
|
+
type IndexerQueryClient = GraphQLClient;
|
|
66
|
+
interface ClientConfig {
|
|
67
|
+
pollInterval: number;
|
|
68
|
+
queryClient: IndexerQueryClient;
|
|
69
|
+
tracing?: boolean;
|
|
70
|
+
source: IEvmConfig | ISubstrateConfig;
|
|
71
|
+
dest: IEvmConfig | ISubstrateConfig;
|
|
72
|
+
hyperbridge: IHyperbridgeConfig;
|
|
73
|
+
}
|
|
74
|
+
interface RetryConfig {
|
|
75
|
+
maxRetries: number;
|
|
76
|
+
backoffMs: number;
|
|
77
|
+
logMessage?: string;
|
|
78
|
+
logger?: ConsolaInstance;
|
|
79
|
+
}
|
|
80
|
+
interface IsmpRequest {
|
|
81
|
+
source: string;
|
|
82
|
+
dest: string;
|
|
83
|
+
from: string;
|
|
84
|
+
to: string;
|
|
85
|
+
nonce: bigint;
|
|
86
|
+
body: string;
|
|
87
|
+
timeoutTimestamp: bigint;
|
|
88
|
+
storage_key?: string;
|
|
89
|
+
}
|
|
90
|
+
declare const RequestStatus: Readonly<{
|
|
91
|
+
SOURCE: "SOURCE";
|
|
92
|
+
SOURCE_FINALIZED: "SOURCE_FINALIZED";
|
|
93
|
+
HYPERBRIDGE_DELIVERED: "HYPERBRIDGE_DELIVERED";
|
|
94
|
+
HYPERBRIDGE_FINALIZED: "HYPERBRIDGE_FINALIZED";
|
|
95
|
+
DESTINATION: "DESTINATION";
|
|
96
|
+
TIMED_OUT: "TIMED_OUT";
|
|
97
|
+
HYPERBRIDGE_TIMED_OUT: "HYPERBRIDGE_TIMED_OUT";
|
|
98
|
+
}>;
|
|
99
|
+
type RequestStatus = typeof RequestStatus;
|
|
100
|
+
type RequestStatusKey = keyof typeof RequestStatus;
|
|
101
|
+
declare const TimeoutStatus: Readonly<{
|
|
102
|
+
PENDING_TIMEOUT: "PENDING_TIMEOUT";
|
|
103
|
+
DESTINATION_FINALIZED_TIMEOUT: "DESTINATION_FINALIZED_TIMEOUT";
|
|
104
|
+
HYPERBRIDGE_TIMED_OUT: "HYPERBRIDGE_TIMED_OUT";
|
|
105
|
+
HYPERBRIDGE_FINALIZED_TIMEOUT: "HYPERBRIDGE_FINALIZED_TIMEOUT";
|
|
106
|
+
TIMED_OUT: "TIMED_OUT";
|
|
107
|
+
}>;
|
|
108
|
+
type TimeoutStatus = typeof TimeoutStatus;
|
|
109
|
+
type TimeoutStatusKey = keyof typeof TimeoutStatus;
|
|
110
|
+
type AllStatusKey = RequestStatusKey | TimeoutStatusKey;
|
|
111
|
+
declare enum HyperClientStatus {
|
|
112
|
+
PENDING = "PENDING",
|
|
113
|
+
SOURCE_FINALIZED = "SOURCE_FINALIZED",
|
|
114
|
+
HYPERBRIDGE_FINALIZED = "HYPERBRIDGE_FINALIZED",
|
|
115
|
+
HYPERBRIDGE_VERIFIED = "HYPERBRIDGE_VERIFIED",
|
|
116
|
+
DESTINATION = "DESTINATION",
|
|
117
|
+
TIMED_OUT = "TIMED_OUT",
|
|
118
|
+
HYPERBRIDGE_TIMED_OUT = "HYPERBRIDGE_TIMED_OUT",
|
|
119
|
+
ERROR = "ERROR"
|
|
120
|
+
}
|
|
121
|
+
declare enum OrderStatus {
|
|
122
|
+
PLACED = "PLACED",
|
|
123
|
+
FILLED = "FILLED",
|
|
124
|
+
REDEEMED = "REDEEMED",
|
|
125
|
+
REFUNDED = "REFUNDED"
|
|
126
|
+
}
|
|
127
|
+
declare enum TeleportStatus {
|
|
128
|
+
TELEPORTED = "TELEPORTED",
|
|
129
|
+
RECEIVED = "RECEIVED",
|
|
130
|
+
REFUNDED = "REFUNDED"
|
|
131
|
+
}
|
|
132
|
+
interface TokenGatewayAssetTeleportedResponse {
|
|
133
|
+
tokenGatewayAssetTeleporteds: {
|
|
134
|
+
nodes: Array<{
|
|
135
|
+
id: string;
|
|
136
|
+
from: string;
|
|
137
|
+
to: string;
|
|
138
|
+
sourceChain: string;
|
|
139
|
+
destChain: string;
|
|
140
|
+
commitment: string;
|
|
141
|
+
amount: string;
|
|
142
|
+
usdValue: string;
|
|
143
|
+
assetId: string;
|
|
144
|
+
redeem: boolean;
|
|
145
|
+
status: TeleportStatus;
|
|
146
|
+
createdAt: string;
|
|
147
|
+
blockNumber: string;
|
|
148
|
+
blockTimestamp: string;
|
|
149
|
+
transactionHash: string;
|
|
150
|
+
statusMetadata: {
|
|
151
|
+
nodes: Array<{
|
|
152
|
+
status: TeleportStatus;
|
|
153
|
+
chain: string;
|
|
154
|
+
timestamp: string;
|
|
155
|
+
blockNumber: string;
|
|
156
|
+
blockHash: string;
|
|
157
|
+
transactionHash: string;
|
|
158
|
+
}>;
|
|
159
|
+
};
|
|
160
|
+
}>;
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
interface TokenGatewayAssetTeleportedWithStatus {
|
|
164
|
+
id: string;
|
|
165
|
+
from: string;
|
|
166
|
+
to: string;
|
|
167
|
+
sourceChain: string;
|
|
168
|
+
destChain: string;
|
|
169
|
+
commitment: string;
|
|
170
|
+
amount: bigint;
|
|
171
|
+
usdValue: string;
|
|
172
|
+
assetId: string;
|
|
173
|
+
redeem: boolean;
|
|
174
|
+
status: TeleportStatus;
|
|
175
|
+
createdAt: Date;
|
|
176
|
+
blockNumber: bigint;
|
|
177
|
+
blockTimestamp: bigint;
|
|
178
|
+
transactionHash: string;
|
|
179
|
+
statuses: Array<{
|
|
180
|
+
status: TeleportStatus;
|
|
181
|
+
metadata: {
|
|
182
|
+
blockHash: string;
|
|
183
|
+
blockNumber: number;
|
|
184
|
+
transactionHash: string;
|
|
185
|
+
timestamp: bigint;
|
|
186
|
+
};
|
|
187
|
+
}>;
|
|
188
|
+
}
|
|
189
|
+
interface BlockMetadata {
|
|
190
|
+
blockHash: string;
|
|
191
|
+
blockNumber: number;
|
|
192
|
+
transactionHash: string;
|
|
193
|
+
calldata?: string;
|
|
194
|
+
timestamp?: number;
|
|
195
|
+
}
|
|
196
|
+
interface PostRequestStatus {
|
|
197
|
+
status: RequestStatusKey;
|
|
198
|
+
metadata: Partial<BlockMetadata>;
|
|
199
|
+
}
|
|
200
|
+
interface PostRequestTimeoutStatus {
|
|
201
|
+
status: TimeoutStatusKey;
|
|
202
|
+
metadata?: Partial<BlockMetadata>;
|
|
203
|
+
}
|
|
204
|
+
interface StateMachineUpdate {
|
|
205
|
+
height: number;
|
|
206
|
+
chain: string;
|
|
207
|
+
blockHash: string;
|
|
208
|
+
blockNumber: number;
|
|
209
|
+
transactionHash: string;
|
|
210
|
+
transactionIndex: number;
|
|
211
|
+
stateMachineId: string;
|
|
212
|
+
timestamp: number;
|
|
213
|
+
}
|
|
214
|
+
interface RequestResponse {
|
|
215
|
+
requests: {
|
|
216
|
+
nodes: Array<{
|
|
217
|
+
source: string;
|
|
218
|
+
dest: string;
|
|
219
|
+
to: HexString;
|
|
220
|
+
from: HexString;
|
|
221
|
+
nonce: bigint;
|
|
222
|
+
body: HexString;
|
|
223
|
+
timeoutTimestamp: bigint;
|
|
224
|
+
statusMetadata: {
|
|
225
|
+
nodes: Array<{
|
|
226
|
+
blockHash: string;
|
|
227
|
+
blockNumber: string;
|
|
228
|
+
timestamp: string;
|
|
229
|
+
chain: string;
|
|
230
|
+
status: string;
|
|
231
|
+
transactionHash: string;
|
|
232
|
+
}>;
|
|
233
|
+
};
|
|
234
|
+
}>;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
interface GetRequestResponse {
|
|
238
|
+
getRequests: {
|
|
239
|
+
nodes: Array<{
|
|
240
|
+
source: string;
|
|
241
|
+
dest: string;
|
|
242
|
+
to: HexString;
|
|
243
|
+
from: HexString;
|
|
244
|
+
nonce: bigint;
|
|
245
|
+
height: bigint;
|
|
246
|
+
keys: HexString[];
|
|
247
|
+
context: HexString;
|
|
248
|
+
timeoutTimestamp: bigint;
|
|
249
|
+
statusMetadata: {
|
|
250
|
+
nodes: Array<{
|
|
251
|
+
blockHash: string;
|
|
252
|
+
blockNumber: string;
|
|
253
|
+
timestamp: string;
|
|
254
|
+
chain: string;
|
|
255
|
+
status: string;
|
|
256
|
+
transactionHash: string;
|
|
257
|
+
}>;
|
|
258
|
+
};
|
|
259
|
+
}>;
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
type RequestStatusWithMetadata = {
|
|
263
|
+
status: RequestStatus["SOURCE"];
|
|
264
|
+
metadata: {
|
|
265
|
+
blockHash: string;
|
|
266
|
+
blockNumber: number;
|
|
267
|
+
transactionHash: string;
|
|
268
|
+
timestamp?: number;
|
|
269
|
+
};
|
|
270
|
+
} | {
|
|
271
|
+
status: RequestStatus["SOURCE_FINALIZED"];
|
|
272
|
+
metadata: {
|
|
273
|
+
blockHash: string;
|
|
274
|
+
blockNumber: number;
|
|
275
|
+
transactionHash: string;
|
|
276
|
+
timestamp?: number;
|
|
277
|
+
};
|
|
278
|
+
} | {
|
|
279
|
+
status: RequestStatus["HYPERBRIDGE_DELIVERED"];
|
|
280
|
+
metadata: {
|
|
281
|
+
blockHash: string;
|
|
282
|
+
blockNumber: number;
|
|
283
|
+
transactionHash: string;
|
|
284
|
+
timestamp?: number;
|
|
285
|
+
};
|
|
286
|
+
} | {
|
|
287
|
+
status: RequestStatus["HYPERBRIDGE_FINALIZED"];
|
|
288
|
+
metadata: {
|
|
289
|
+
calldata: Hex;
|
|
290
|
+
blockHash: string;
|
|
291
|
+
blockNumber: number;
|
|
292
|
+
transactionHash: string;
|
|
293
|
+
timestamp?: number;
|
|
294
|
+
};
|
|
295
|
+
} | {
|
|
296
|
+
status: RequestStatus["DESTINATION"];
|
|
297
|
+
metadata: {
|
|
298
|
+
blockHash: string;
|
|
299
|
+
blockNumber: number;
|
|
300
|
+
transactionHash: string;
|
|
301
|
+
timestamp?: number;
|
|
302
|
+
};
|
|
303
|
+
} | {
|
|
304
|
+
status: TimeoutStatus["PENDING_TIMEOUT"];
|
|
305
|
+
metadata: {
|
|
306
|
+
blockHash: string;
|
|
307
|
+
blockNumber: number;
|
|
308
|
+
transactionHash: string;
|
|
309
|
+
};
|
|
310
|
+
} | {
|
|
311
|
+
status: TimeoutStatus["DESTINATION_FINALIZED_TIMEOUT"];
|
|
312
|
+
metadata: {
|
|
313
|
+
blockHash: string;
|
|
314
|
+
blockNumber: number;
|
|
315
|
+
transactionHash: string;
|
|
316
|
+
timestamp?: number;
|
|
317
|
+
};
|
|
318
|
+
} | {
|
|
319
|
+
status: TimeoutStatus["HYPERBRIDGE_TIMED_OUT"];
|
|
320
|
+
metadata: {
|
|
321
|
+
blockHash: string;
|
|
322
|
+
blockNumber: number;
|
|
323
|
+
transactionHash: string;
|
|
324
|
+
timestamp?: number;
|
|
325
|
+
};
|
|
326
|
+
} | {
|
|
327
|
+
status: TimeoutStatus["HYPERBRIDGE_FINALIZED_TIMEOUT"];
|
|
328
|
+
metadata: {
|
|
329
|
+
calldata: Hex;
|
|
330
|
+
blockHash: string;
|
|
331
|
+
blockNumber: number;
|
|
332
|
+
transactionHash: string;
|
|
333
|
+
timestamp?: number;
|
|
334
|
+
};
|
|
335
|
+
} | {
|
|
336
|
+
status: TimeoutStatus["TIMED_OUT"];
|
|
337
|
+
metadata: {
|
|
338
|
+
blockHash: string;
|
|
339
|
+
blockNumber: number;
|
|
340
|
+
transactionHash: string;
|
|
341
|
+
timestamp?: number;
|
|
342
|
+
};
|
|
343
|
+
};
|
|
344
|
+
interface GenericRequestWithStatuses {
|
|
345
|
+
source: string;
|
|
346
|
+
dest: string;
|
|
347
|
+
from: HexString;
|
|
348
|
+
nonce: bigint;
|
|
349
|
+
timeoutTimestamp: bigint;
|
|
350
|
+
statuses: Array<RequestStatusWithMetadata>;
|
|
351
|
+
}
|
|
352
|
+
interface PostRequestWithStatus extends GenericRequestWithStatuses {
|
|
353
|
+
to: HexString;
|
|
354
|
+
body: HexString;
|
|
355
|
+
}
|
|
356
|
+
interface GetRequestWithStatus extends GenericRequestWithStatuses {
|
|
357
|
+
height: bigint;
|
|
358
|
+
keys: HexString[];
|
|
359
|
+
context: HexString;
|
|
360
|
+
}
|
|
361
|
+
interface GetResponseByRequestIdResponse {
|
|
362
|
+
getResponses: {
|
|
363
|
+
nodes: Array<{
|
|
364
|
+
id: string;
|
|
365
|
+
commitment: string;
|
|
366
|
+
responseMessage: string[];
|
|
367
|
+
}>;
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
interface ResponseCommitmentWithValues {
|
|
371
|
+
commitment: string;
|
|
372
|
+
values: string[];
|
|
373
|
+
}
|
|
374
|
+
interface RequestCommitment {
|
|
375
|
+
requests: {
|
|
376
|
+
nodes: Array<{
|
|
377
|
+
id: string;
|
|
378
|
+
commitment: string;
|
|
379
|
+
}>;
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
interface StateMachineResponse {
|
|
383
|
+
stateMachineUpdateEvents: {
|
|
384
|
+
nodes: {
|
|
385
|
+
height: number;
|
|
386
|
+
chain: string;
|
|
387
|
+
blockHash: string;
|
|
388
|
+
blockNumber: number;
|
|
389
|
+
transactionHash: string;
|
|
390
|
+
transactionIndex: number;
|
|
391
|
+
stateMachineId: string;
|
|
392
|
+
createdAt: string;
|
|
393
|
+
}[];
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
interface AssetTeleported {
|
|
397
|
+
id: string;
|
|
398
|
+
from: string;
|
|
399
|
+
to: string;
|
|
400
|
+
amount: bigint;
|
|
401
|
+
dest: string;
|
|
402
|
+
commitment: string;
|
|
403
|
+
createdAt: Date;
|
|
404
|
+
blockNumber: number;
|
|
405
|
+
}
|
|
406
|
+
interface AssetTeleportedResponse {
|
|
407
|
+
assetTeleporteds: {
|
|
408
|
+
nodes: AssetTeleported[];
|
|
409
|
+
};
|
|
410
|
+
}
|
|
411
|
+
interface StateMachineIdParams {
|
|
412
|
+
stateId: {
|
|
413
|
+
Evm?: number;
|
|
414
|
+
Substrate?: HexString;
|
|
415
|
+
Polkadot?: number;
|
|
416
|
+
Kusama?: number;
|
|
417
|
+
};
|
|
418
|
+
consensusStateId: HexString;
|
|
419
|
+
}
|
|
420
|
+
/**
|
|
421
|
+
* Configuration for a blockchain chain
|
|
422
|
+
*/
|
|
423
|
+
interface ChainConfig {
|
|
424
|
+
/**
|
|
425
|
+
* The unique identifier for the chain
|
|
426
|
+
*/
|
|
427
|
+
chainId: number;
|
|
428
|
+
/**
|
|
429
|
+
* The RPC URL to connect to the chain
|
|
430
|
+
*/
|
|
431
|
+
rpcUrl: string;
|
|
432
|
+
/**
|
|
433
|
+
* The address of the IntentGateway contract on this chain
|
|
434
|
+
*/
|
|
435
|
+
intentGatewayAddress: string;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Represents token information for an order
|
|
439
|
+
*/
|
|
440
|
+
interface TokenInfo {
|
|
441
|
+
/**
|
|
442
|
+
* The address of the ERC20 token
|
|
443
|
+
* address(0) is used as a sentinel for the native token
|
|
444
|
+
*/
|
|
445
|
+
token: HexString;
|
|
446
|
+
/**
|
|
447
|
+
* The amount of the token
|
|
448
|
+
*/
|
|
449
|
+
amount: bigint;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Represents payment information for an order
|
|
453
|
+
*/
|
|
454
|
+
interface PaymentInfo extends TokenInfo {
|
|
455
|
+
/**
|
|
456
|
+
* The address to receive the output tokens
|
|
457
|
+
*/
|
|
458
|
+
beneficiary: HexString;
|
|
459
|
+
}
|
|
460
|
+
/**
|
|
461
|
+
* Represents an order in the IntentGateway
|
|
462
|
+
*/
|
|
463
|
+
interface Order {
|
|
464
|
+
/**
|
|
465
|
+
* The unique identifier for the order
|
|
466
|
+
*/
|
|
467
|
+
id?: string;
|
|
468
|
+
/**
|
|
469
|
+
* The address of the user who is initiating the transfer
|
|
470
|
+
*/
|
|
471
|
+
user: HexString;
|
|
472
|
+
/**
|
|
473
|
+
* The state machine identifier of the origin chain
|
|
474
|
+
*/
|
|
475
|
+
sourceChain: string;
|
|
476
|
+
/**
|
|
477
|
+
* The state machine identifier of the destination chain
|
|
478
|
+
*/
|
|
479
|
+
destChain: string;
|
|
480
|
+
/**
|
|
481
|
+
* The block number by which the order must be filled on the destination chain
|
|
482
|
+
*/
|
|
483
|
+
deadline: bigint;
|
|
484
|
+
/**
|
|
485
|
+
* The nonce of the order
|
|
486
|
+
*/
|
|
487
|
+
nonce: bigint;
|
|
488
|
+
/**
|
|
489
|
+
* Represents the dispatch fees associated with the IntentGateway
|
|
490
|
+
*/
|
|
491
|
+
fees: bigint;
|
|
492
|
+
/**
|
|
493
|
+
* The tokens that the filler will provide
|
|
494
|
+
*/
|
|
495
|
+
outputs: PaymentInfo[];
|
|
496
|
+
/**
|
|
497
|
+
* The tokens that are escrowed for the filler
|
|
498
|
+
*/
|
|
499
|
+
inputs: TokenInfo[];
|
|
500
|
+
/**
|
|
501
|
+
* A bytes array to store the calls if any
|
|
502
|
+
*/
|
|
503
|
+
callData: HexString;
|
|
504
|
+
/**
|
|
505
|
+
* The transaction hash of the order
|
|
506
|
+
*/
|
|
507
|
+
transactionHash?: HexString;
|
|
508
|
+
}
|
|
509
|
+
interface DecodedOrderPlacedLog extends Log {
|
|
510
|
+
eventName: string;
|
|
511
|
+
args: {
|
|
512
|
+
user: HexString;
|
|
513
|
+
sourceChain: Hex;
|
|
514
|
+
destChain: Hex;
|
|
515
|
+
deadline: bigint;
|
|
516
|
+
nonce: bigint;
|
|
517
|
+
fees: bigint;
|
|
518
|
+
outputs: Array<{
|
|
519
|
+
token: HexString;
|
|
520
|
+
amount: bigint;
|
|
521
|
+
beneficiary: HexString;
|
|
522
|
+
}>;
|
|
523
|
+
inputs: Array<{
|
|
524
|
+
token: HexString;
|
|
525
|
+
amount: bigint;
|
|
526
|
+
}>;
|
|
527
|
+
callData: HexString;
|
|
528
|
+
};
|
|
529
|
+
transactionHash: HexString;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Options for filling an order
|
|
533
|
+
*/
|
|
534
|
+
interface FillOptions {
|
|
535
|
+
/**
|
|
536
|
+
* The fee paid to the relayer for processing transactions
|
|
537
|
+
*/
|
|
538
|
+
relayerFee: bigint;
|
|
539
|
+
}
|
|
540
|
+
/**
|
|
541
|
+
* Options for canceling an order
|
|
542
|
+
*/
|
|
543
|
+
interface CancelOptions {
|
|
544
|
+
/**
|
|
545
|
+
* The fee paid to the relayer for processing transactions
|
|
546
|
+
*/
|
|
547
|
+
relayerFee: string;
|
|
548
|
+
/**
|
|
549
|
+
* Stores the height value
|
|
550
|
+
*/
|
|
551
|
+
height: string;
|
|
552
|
+
}
|
|
553
|
+
/**
|
|
554
|
+
* Represents a new deployment of IntentGateway
|
|
555
|
+
*/
|
|
556
|
+
interface NewDeployment {
|
|
557
|
+
/**
|
|
558
|
+
* Identifier for the state machine
|
|
559
|
+
*/
|
|
560
|
+
stateMachineId: HexString;
|
|
561
|
+
/**
|
|
562
|
+
* The gateway identifier
|
|
563
|
+
*/
|
|
564
|
+
gateway: HexString;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
567
|
+
* Represents the body of a request
|
|
568
|
+
*/
|
|
569
|
+
interface RequestBody {
|
|
570
|
+
/**
|
|
571
|
+
* Represents the commitment of an order
|
|
572
|
+
*/
|
|
573
|
+
commitment: HexString;
|
|
574
|
+
/**
|
|
575
|
+
* Stores the identifier for the beneficiary
|
|
576
|
+
*/
|
|
577
|
+
beneficiary: HexString;
|
|
578
|
+
/**
|
|
579
|
+
* An array of token identifiers
|
|
580
|
+
*/
|
|
581
|
+
tokens: TokenInfo[];
|
|
582
|
+
}
|
|
583
|
+
/**
|
|
584
|
+
* Represents the parameters for the IntentGateway module
|
|
585
|
+
*/
|
|
586
|
+
interface IntentGatewayParams {
|
|
587
|
+
/**
|
|
588
|
+
* The address of the host contract
|
|
589
|
+
*/
|
|
590
|
+
host: string;
|
|
591
|
+
/**
|
|
592
|
+
* Address of the dispatcher contract responsible for handling intents
|
|
593
|
+
*/
|
|
594
|
+
dispatcher: string;
|
|
595
|
+
}
|
|
596
|
+
/**
|
|
597
|
+
* Enum representing the different kinds of incoming requests
|
|
598
|
+
*/
|
|
599
|
+
declare enum RequestKind {
|
|
600
|
+
/**
|
|
601
|
+
* Identifies a request for redeeming an escrow
|
|
602
|
+
*/
|
|
603
|
+
RedeemEscrow = 0,
|
|
604
|
+
/**
|
|
605
|
+
* Identifies a request for recording new contract deployments
|
|
606
|
+
*/
|
|
607
|
+
NewDeployment = 1,
|
|
608
|
+
/**
|
|
609
|
+
* Identifies a request for updating parameters
|
|
610
|
+
*/
|
|
611
|
+
UpdateParams = 2
|
|
612
|
+
}
|
|
613
|
+
/**
|
|
614
|
+
* Configuration for the IntentFiller
|
|
615
|
+
*/
|
|
616
|
+
interface FillerConfig {
|
|
617
|
+
/**
|
|
618
|
+
* Policy for determining confirmation requirements
|
|
619
|
+
*/
|
|
620
|
+
confirmationPolicy: {
|
|
621
|
+
getConfirmationBlocks: (chainId: number, amount: bigint) => number;
|
|
622
|
+
};
|
|
623
|
+
/**
|
|
624
|
+
* Maximum number of orders to process concurrently
|
|
625
|
+
*/
|
|
626
|
+
maxConcurrentOrders?: number;
|
|
627
|
+
/**
|
|
628
|
+
* Minimum profitability threshold to consider filling an order
|
|
629
|
+
* Expressed as a percentage (e.g., 0.5 = 0.5%)
|
|
630
|
+
*/
|
|
631
|
+
minProfitabilityThreshold?: number;
|
|
632
|
+
/**
|
|
633
|
+
* Gas price strategy for each chain
|
|
634
|
+
* Maps chainId to a gas price strategy function
|
|
635
|
+
*/
|
|
636
|
+
gasPriceStrategy?: Record<string, () => Promise<string>>;
|
|
637
|
+
/**
|
|
638
|
+
* Maximum gas price willing to pay for each chain
|
|
639
|
+
* Maps chainId to maximum gas price in wei
|
|
640
|
+
*/
|
|
641
|
+
maxGasPrice?: Record<string, string>;
|
|
642
|
+
/**
|
|
643
|
+
* Retry configuration for failed transactions
|
|
644
|
+
*/
|
|
645
|
+
retryConfig?: {
|
|
646
|
+
/**
|
|
647
|
+
* Maximum number of retry attempts
|
|
648
|
+
*/
|
|
649
|
+
maxAttempts: number;
|
|
650
|
+
/**
|
|
651
|
+
* Initial delay between retries in ms
|
|
652
|
+
*/
|
|
653
|
+
initialDelayMs: number;
|
|
654
|
+
};
|
|
655
|
+
/**
|
|
656
|
+
* Configuration for the pending queue
|
|
657
|
+
*/
|
|
658
|
+
pendingQueueConfig?: {
|
|
659
|
+
/**
|
|
660
|
+
* Delay in milliseconds before rechecking an order for confirmations
|
|
661
|
+
* Default: 30000 (30 seconds)
|
|
662
|
+
*/
|
|
663
|
+
recheckDelayMs?: number;
|
|
664
|
+
/**
|
|
665
|
+
* Maximum number of times to recheck an order before giving up
|
|
666
|
+
* Default: 10
|
|
667
|
+
*/
|
|
668
|
+
maxRechecks?: number;
|
|
669
|
+
};
|
|
670
|
+
}
|
|
671
|
+
/**
|
|
672
|
+
* Result of an order execution attempt
|
|
673
|
+
*/
|
|
674
|
+
interface ExecutionResult {
|
|
675
|
+
/**
|
|
676
|
+
* Whether the execution was successful
|
|
677
|
+
*/
|
|
678
|
+
success: boolean;
|
|
679
|
+
/**
|
|
680
|
+
* The transaction hash if successful
|
|
681
|
+
*/
|
|
682
|
+
txHash?: string;
|
|
683
|
+
/**
|
|
684
|
+
* Error message if unsuccessful
|
|
685
|
+
*/
|
|
686
|
+
error?: string;
|
|
687
|
+
/**
|
|
688
|
+
* Gas used by the transaction
|
|
689
|
+
*/
|
|
690
|
+
gasUsed?: string;
|
|
691
|
+
/**
|
|
692
|
+
* Gas price used for the transaction
|
|
693
|
+
*/
|
|
694
|
+
gasPrice?: string;
|
|
695
|
+
/**
|
|
696
|
+
* Total transaction cost in wei
|
|
697
|
+
*/
|
|
698
|
+
txCost?: string;
|
|
699
|
+
/**
|
|
700
|
+
* Block number when the transaction was confirmed
|
|
701
|
+
*/
|
|
702
|
+
confirmedAtBlock?: number;
|
|
703
|
+
/**
|
|
704
|
+
* Timestamp when the transaction was confirmed
|
|
705
|
+
*/
|
|
706
|
+
confirmedAt?: Date;
|
|
707
|
+
/**
|
|
708
|
+
* Actual profitability achieved
|
|
709
|
+
*/
|
|
710
|
+
actualProfitability?: number;
|
|
711
|
+
/**
|
|
712
|
+
* Strategy used to fill the order
|
|
713
|
+
*/
|
|
714
|
+
strategyUsed?: string;
|
|
715
|
+
/**
|
|
716
|
+
* Any tokens exchanged during the fill process
|
|
717
|
+
*/
|
|
718
|
+
exchanges?: Array<{
|
|
719
|
+
fromToken: HexString;
|
|
720
|
+
toToken: HexString;
|
|
721
|
+
fromAmount: string;
|
|
722
|
+
toAmount: string;
|
|
723
|
+
exchangeRate: string;
|
|
724
|
+
}>;
|
|
725
|
+
/**
|
|
726
|
+
* The time it took to fill the order
|
|
727
|
+
*/
|
|
728
|
+
processingTimeMs?: number;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
731
|
+
* Represents a dispatch post for cross-chain communication
|
|
732
|
+
*/
|
|
733
|
+
interface DispatchPost {
|
|
734
|
+
/**
|
|
735
|
+
* Bytes representation of the destination state machine
|
|
736
|
+
*/
|
|
737
|
+
dest: HexString;
|
|
738
|
+
/**
|
|
739
|
+
* The destination module
|
|
740
|
+
*/
|
|
741
|
+
to: HexString;
|
|
742
|
+
/**
|
|
743
|
+
* The request body
|
|
744
|
+
*/
|
|
745
|
+
body: HexString;
|
|
746
|
+
/**
|
|
747
|
+
* Timeout for this request in seconds
|
|
748
|
+
*/
|
|
749
|
+
timeout: bigint;
|
|
750
|
+
/**
|
|
751
|
+
* The amount put up to be paid to the relayer,
|
|
752
|
+
* this is charged in `IIsmpHost.feeToken` to `msg.sender`
|
|
753
|
+
*/
|
|
754
|
+
fee: bigint;
|
|
755
|
+
/**
|
|
756
|
+
* Who pays for this request?
|
|
757
|
+
*/
|
|
758
|
+
payer: HexString;
|
|
759
|
+
}
|
|
760
|
+
interface DispatchGet {
|
|
761
|
+
/**
|
|
762
|
+
* Bytes representation of the destination state machine
|
|
763
|
+
*/
|
|
764
|
+
dest: HexString;
|
|
765
|
+
/**
|
|
766
|
+
* Height at which to read the state machine
|
|
767
|
+
*/
|
|
768
|
+
height: bigint;
|
|
769
|
+
/**
|
|
770
|
+
* Raw storage keys to fetch values from the counterparty
|
|
771
|
+
*/
|
|
772
|
+
keys: HexString[];
|
|
773
|
+
/**
|
|
774
|
+
* Timeout for this request in seconds
|
|
775
|
+
*/
|
|
776
|
+
timeout: bigint;
|
|
777
|
+
/**
|
|
778
|
+
* The amount put up to be paid to the relayer
|
|
779
|
+
*/
|
|
780
|
+
fee: bigint;
|
|
781
|
+
/**
|
|
782
|
+
* Context for the request
|
|
783
|
+
*/
|
|
784
|
+
context: HexString;
|
|
785
|
+
}
|
|
786
|
+
interface StateMachineHeight {
|
|
787
|
+
id: {
|
|
788
|
+
stateId: {
|
|
789
|
+
Evm?: number;
|
|
790
|
+
Substrate?: HexString;
|
|
791
|
+
Polkadot?: number;
|
|
792
|
+
Kusama?: number;
|
|
793
|
+
};
|
|
794
|
+
consensusStateId: HexString;
|
|
795
|
+
};
|
|
796
|
+
height: bigint;
|
|
797
|
+
}
|
|
798
|
+
/**
|
|
799
|
+
* The EvmHost protocol parameters
|
|
800
|
+
*/
|
|
801
|
+
interface HostParams {
|
|
802
|
+
/**
|
|
803
|
+
* The default timeout in seconds for messages. If messages are dispatched
|
|
804
|
+
* with a timeout value lower than this this value will be used instead
|
|
805
|
+
*/
|
|
806
|
+
defaultTimeout: bigint;
|
|
807
|
+
/**
|
|
808
|
+
* The default per byte fee
|
|
809
|
+
*/
|
|
810
|
+
perByteFee: bigint;
|
|
811
|
+
/**
|
|
812
|
+
* The cost for applications to access the hyperbridge state commitment.
|
|
813
|
+
* They might do so because the hyperbridge state contains the verified state commitments
|
|
814
|
+
* for all chains and they want to directly read the state of these chains state bypassing
|
|
815
|
+
* the ISMP protocol entirely.
|
|
816
|
+
*/
|
|
817
|
+
stateCommitmentFee: bigint;
|
|
818
|
+
/**
|
|
819
|
+
* The fee token contract address. This will typically be DAI.
|
|
820
|
+
* but we allow it to be configurable to prevent future regrets.
|
|
821
|
+
*/
|
|
822
|
+
feeToken: HexString;
|
|
823
|
+
/**
|
|
824
|
+
* The admin account, this only has the rights to freeze, or unfreeze the bridge
|
|
825
|
+
*/
|
|
826
|
+
admin: HexString;
|
|
827
|
+
/**
|
|
828
|
+
* Ismp message handler contract. This performs all verification logic
|
|
829
|
+
* needed to validate cross-chain messages before they are dispatched to local modules
|
|
830
|
+
*/
|
|
831
|
+
handler: HexString;
|
|
832
|
+
/**
|
|
833
|
+
* The authorized host manager contract, is itself an `IIsmpModule`
|
|
834
|
+
* which receives governance requests from the Hyperbridge chain to either
|
|
835
|
+
* withdraw revenue from the host or update its protocol parameters
|
|
836
|
+
*/
|
|
837
|
+
hostManager: HexString;
|
|
838
|
+
/**
|
|
839
|
+
* The local UniswapV2Router02 contract, used for swapping the native token to the feeToken.
|
|
840
|
+
*/
|
|
841
|
+
uniswapV2: HexString;
|
|
842
|
+
/**
|
|
843
|
+
* The unstaking period of Polkadot's validators. In order to prevent long-range attacks
|
|
844
|
+
*/
|
|
845
|
+
unStakingPeriod: bigint;
|
|
846
|
+
/**
|
|
847
|
+
* Minimum challenge period for state commitments in seconds
|
|
848
|
+
*/
|
|
849
|
+
challengePeriod: bigint;
|
|
850
|
+
/**
|
|
851
|
+
* The consensus client contract which handles consensus proof verification
|
|
852
|
+
*/
|
|
853
|
+
consensusClient: HexString;
|
|
854
|
+
/**
|
|
855
|
+
* State machines whose state commitments are accepted
|
|
856
|
+
*/
|
|
857
|
+
readonly stateMachines: readonly bigint[];
|
|
858
|
+
/**
|
|
859
|
+
* The state machine identifier for hyperbridge
|
|
860
|
+
*/
|
|
861
|
+
hyperbridge: HexString;
|
|
862
|
+
}
|
|
863
|
+
interface OrderStatusMetadata {
|
|
864
|
+
status: OrderStatus;
|
|
865
|
+
chain: string;
|
|
866
|
+
timestamp: bigint;
|
|
867
|
+
blockNumber: string;
|
|
868
|
+
transactionHash: string;
|
|
869
|
+
filler?: string;
|
|
870
|
+
}
|
|
871
|
+
interface OrderWithStatus {
|
|
872
|
+
id: string;
|
|
873
|
+
user: string;
|
|
874
|
+
sourceChain: string;
|
|
875
|
+
destChain: string;
|
|
876
|
+
commitment: string;
|
|
877
|
+
deadline: bigint;
|
|
878
|
+
nonce: bigint;
|
|
879
|
+
fees: bigint;
|
|
880
|
+
inputTokens: string[];
|
|
881
|
+
inputAmounts: bigint[];
|
|
882
|
+
inputValuesUSD: string[];
|
|
883
|
+
inputUSD: string;
|
|
884
|
+
outputTokens: string[];
|
|
885
|
+
outputAmounts: bigint[];
|
|
886
|
+
outputBeneficiaries: string[];
|
|
887
|
+
calldata: string;
|
|
888
|
+
status: OrderStatus;
|
|
889
|
+
createdAt: Date;
|
|
890
|
+
blockNumber: bigint;
|
|
891
|
+
blockTimestamp: bigint;
|
|
892
|
+
transactionHash: string;
|
|
893
|
+
statuses: Array<{
|
|
894
|
+
status: OrderStatus;
|
|
895
|
+
metadata: {
|
|
896
|
+
blockHash: string;
|
|
897
|
+
blockNumber: number;
|
|
898
|
+
transactionHash: string;
|
|
899
|
+
timestamp: bigint;
|
|
900
|
+
filler?: string;
|
|
901
|
+
};
|
|
902
|
+
}>;
|
|
903
|
+
}
|
|
904
|
+
interface OrderResponse {
|
|
905
|
+
orderPlaceds: {
|
|
906
|
+
nodes: Array<{
|
|
907
|
+
id: string;
|
|
908
|
+
user: string;
|
|
909
|
+
sourceChain: string;
|
|
910
|
+
destChain: string;
|
|
911
|
+
commitment: string;
|
|
912
|
+
deadline: string;
|
|
913
|
+
nonce: string;
|
|
914
|
+
fees: string;
|
|
915
|
+
inputTokens: string[];
|
|
916
|
+
inputAmounts: string[];
|
|
917
|
+
inputValuesUSD: string[];
|
|
918
|
+
inputUSD: string;
|
|
919
|
+
outputTokens: string[];
|
|
920
|
+
outputAmounts: string[];
|
|
921
|
+
outputBeneficiaries: string[];
|
|
922
|
+
calldata: string;
|
|
923
|
+
status: OrderStatus;
|
|
924
|
+
createdAt: string;
|
|
925
|
+
blockNumber: string;
|
|
926
|
+
blockTimestamp: string;
|
|
927
|
+
transactionHash: string;
|
|
928
|
+
statusMetadata: {
|
|
929
|
+
nodes: Array<{
|
|
930
|
+
status: OrderStatus;
|
|
931
|
+
chain: string;
|
|
932
|
+
timestamp: string;
|
|
933
|
+
blockNumber: string;
|
|
934
|
+
blockHash: string;
|
|
935
|
+
transactionHash: string;
|
|
936
|
+
filler?: string;
|
|
937
|
+
}>;
|
|
938
|
+
};
|
|
939
|
+
}>;
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
declare class AbortSignalInternal extends Error {
|
|
943
|
+
constructor(message: string);
|
|
944
|
+
static isError(error: unknown): error is AbortSignalInternal;
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
declare class ChainConfigService {
|
|
948
|
+
private rpcUrls;
|
|
949
|
+
constructor(env?: NodeJS.ProcessEnv);
|
|
950
|
+
getChainConfig(chain: string): ChainConfig;
|
|
951
|
+
getIntentGatewayAddress(chain: string): `0x${string}`;
|
|
952
|
+
getHostAddress(chain: string): `0x${string}`;
|
|
953
|
+
getWrappedNativeAssetWithDecimals(chain: string): {
|
|
954
|
+
asset: HexString;
|
|
955
|
+
decimals: number;
|
|
956
|
+
};
|
|
957
|
+
getDaiAsset(chain: string): HexString;
|
|
958
|
+
getUsdtAsset(chain: string): HexString;
|
|
959
|
+
getUsdcAsset(chain: string): HexString;
|
|
960
|
+
getChainId(chain: string): number;
|
|
961
|
+
getConsensusStateId(chain: string): HexString;
|
|
962
|
+
getHyperbridgeChainId(): number;
|
|
963
|
+
getRpcUrl(chain: string): string;
|
|
964
|
+
getUniswapRouterV2Address(chain: string): HexString;
|
|
965
|
+
getUniswapV2FactoryAddress(chain: string): HexString;
|
|
966
|
+
getBatchExecutorAddress(chain: string): HexString;
|
|
967
|
+
getUniversalRouterAddress(chain: string): HexString;
|
|
968
|
+
getUniswapV3RouterAddress(chain: string): HexString;
|
|
969
|
+
getUniswapV3FactoryAddress(chain: string): HexString;
|
|
970
|
+
getUniswapV3QuoterAddress(chain: string): HexString;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* The default address used as fallback when no address is provided.
|
|
975
|
+
* This represents the zero address in EVM chains.
|
|
976
|
+
*/
|
|
977
|
+
declare const DEFAULT_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
978
|
+
/**
|
|
979
|
+
* Parameters for an EVM chain.
|
|
980
|
+
*/
|
|
981
|
+
interface EvmChainParams {
|
|
982
|
+
/**
|
|
983
|
+
* The chain ID of the EVM chain.
|
|
984
|
+
*/
|
|
985
|
+
chainId: number;
|
|
986
|
+
/**
|
|
987
|
+
* The host address of the EVM chain.
|
|
988
|
+
*/
|
|
989
|
+
host: HexString;
|
|
990
|
+
/**
|
|
991
|
+
* The URL of the EVM chain.
|
|
992
|
+
*/
|
|
993
|
+
url: string;
|
|
994
|
+
}
|
|
995
|
+
/**
|
|
996
|
+
* Encapsulates an EVM chain.
|
|
997
|
+
*/
|
|
998
|
+
declare class EvmChain implements IChain {
|
|
999
|
+
private readonly params;
|
|
1000
|
+
private publicClient;
|
|
1001
|
+
private chainConfigService;
|
|
1002
|
+
constructor(params: EvmChainParams);
|
|
1003
|
+
get client(): PublicClient;
|
|
1004
|
+
get host(): HexString;
|
|
1005
|
+
get config(): ChainConfigService;
|
|
1006
|
+
/**
|
|
1007
|
+
* Derives the key for the request receipt.
|
|
1008
|
+
* @param {HexString} commitment - The commitment to derive the key from.
|
|
1009
|
+
* @returns {HexString} The derived key.
|
|
1010
|
+
*/
|
|
1011
|
+
requestReceiptKey(commitment: HexString): HexString;
|
|
1012
|
+
/**
|
|
1013
|
+
* Queries the request receipt.
|
|
1014
|
+
* @param {HexString} commitment - The commitment to query.
|
|
1015
|
+
* @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request.
|
|
1016
|
+
*/
|
|
1017
|
+
queryRequestReceipt(commitment: HexString): Promise<HexString | undefined>;
|
|
1018
|
+
/**
|
|
1019
|
+
* Queries the proof of the commitments.
|
|
1020
|
+
* @param {IMessage} message - The message to query.
|
|
1021
|
+
* @param {string} counterparty - The counterparty address.
|
|
1022
|
+
* @param {bigint} [at] - The block number to query at.
|
|
1023
|
+
* @returns {Promise<HexString>} The proof.
|
|
1024
|
+
*/
|
|
1025
|
+
queryProof(message: IMessage, counterparty: string, at?: bigint): Promise<HexString>;
|
|
1026
|
+
/**
|
|
1027
|
+
* Query and return the encoded storage proof for the provided keys at the given height.
|
|
1028
|
+
* @param {bigint} at - The block height at which to query the storage proof.
|
|
1029
|
+
* @param {HexString[]} keys - The keys for which to query the storage proof.
|
|
1030
|
+
* @returns {Promise<HexString>} The encoded storage proof.
|
|
1031
|
+
*/
|
|
1032
|
+
queryStateProof(at: bigint, keys: HexString[]): Promise<HexString>;
|
|
1033
|
+
/**
|
|
1034
|
+
* Returns the current timestamp of the chain.
|
|
1035
|
+
* @returns {Promise<bigint>} The current timestamp.
|
|
1036
|
+
*/
|
|
1037
|
+
timestamp(): Promise<bigint>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Get the latest state machine height for a given state machine ID.
|
|
1040
|
+
* @param {StateMachineIdParams} stateMachineId - The state machine ID.
|
|
1041
|
+
* @returns {Promise<bigint>} The latest state machine height.
|
|
1042
|
+
*/
|
|
1043
|
+
latestStateMachineHeight(stateMachineId: StateMachineIdParams): Promise<bigint>;
|
|
1044
|
+
/**
|
|
1045
|
+
* Get the state machine update time for a given state machine height.
|
|
1046
|
+
* @param {StateMachineHeight} stateMachineHeight - The state machine height.
|
|
1047
|
+
* @returns {Promise<bigint>} The statemachine update time in seconds.
|
|
1048
|
+
*/
|
|
1049
|
+
stateMachineUpdateTime(stateMachineHeight: StateMachineHeight): Promise<bigint>;
|
|
1050
|
+
/**
|
|
1051
|
+
* Get the challenge period for a given state machine id.
|
|
1052
|
+
* @param {StateMachineIdParams} stateMachineId - The state machine ID.
|
|
1053
|
+
* @returns {Promise<bigint>} The challenge period in seconds.
|
|
1054
|
+
*/
|
|
1055
|
+
challengePeriod(stateMachineId: StateMachineIdParams): Promise<bigint>;
|
|
1056
|
+
/**
|
|
1057
|
+
* Encodes an ISMP message for the EVM chain.
|
|
1058
|
+
* @param {IIsmpMessage} message The ISMP message to encode.
|
|
1059
|
+
* @returns {HexString} The encoded calldata.
|
|
1060
|
+
*/
|
|
1061
|
+
encode(message: IIsmpMessage): HexString;
|
|
1062
|
+
/**
|
|
1063
|
+
* Calculates the fee required to send a post request to the destination chain.
|
|
1064
|
+
* The fee is calculated based on the per-byte fee for the destination chain
|
|
1065
|
+
* multiplied by the size of the request body.
|
|
1066
|
+
*
|
|
1067
|
+
* @param request - The post request to calculate the fee for
|
|
1068
|
+
* @returns The total fee in wei required to send the post request
|
|
1069
|
+
*/
|
|
1070
|
+
quote(request: IPostRequest): Promise<bigint>;
|
|
1071
|
+
/**
|
|
1072
|
+
* Estimates the gas required for a post request execution on this chain.
|
|
1073
|
+
* This function generates mock proofs for the post request, creates a state override
|
|
1074
|
+
* with the necessary overlay root, and estimates the gas cost for executing the
|
|
1075
|
+
* handlePostRequests transaction on the handler contract.
|
|
1076
|
+
*
|
|
1077
|
+
* @param request - The post request to estimate gas for
|
|
1078
|
+
* @param paraId - The ID of the parachain (Hyperbridge) that will process the request
|
|
1079
|
+
* @returns The estimated gas amount in gas units
|
|
1080
|
+
*/
|
|
1081
|
+
estimateGas(request: IPostRequest): Promise<bigint>;
|
|
1082
|
+
/**
|
|
1083
|
+
* Gets the fee token address and decimals for the chain.
|
|
1084
|
+
* This function gets the fee token address and decimals for the chain.
|
|
1085
|
+
*
|
|
1086
|
+
* @returns The fee token address and decimals
|
|
1087
|
+
*/
|
|
1088
|
+
getFeeTokenWithDecimals(): Promise<{
|
|
1089
|
+
address: HexString;
|
|
1090
|
+
decimals: number;
|
|
1091
|
+
}>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Gets the nonce of the host.
|
|
1094
|
+
* This function gets the nonce of the host.
|
|
1095
|
+
*
|
|
1096
|
+
* @returns The nonce of the host
|
|
1097
|
+
*/
|
|
1098
|
+
getHostNonce(): Promise<bigint>;
|
|
1099
|
+
}
|
|
1100
|
+
/**
|
|
1101
|
+
* Slot for storing request commitments.
|
|
1102
|
+
*/
|
|
1103
|
+
declare const REQUEST_COMMITMENTS_SLOT = 0n;
|
|
1104
|
+
/**
|
|
1105
|
+
* Slot index for response commitments map
|
|
1106
|
+
*/
|
|
1107
|
+
declare const RESPONSE_COMMITMENTS_SLOT = 1n;
|
|
1108
|
+
/**
|
|
1109
|
+
* Slot index for requests receipts map
|
|
1110
|
+
*/
|
|
1111
|
+
declare const REQUEST_RECEIPTS_SLOT = 2n;
|
|
1112
|
+
/**
|
|
1113
|
+
* Slot index for response receipts map
|
|
1114
|
+
*/
|
|
1115
|
+
declare const RESPONSE_RECEIPTS_SLOT = 3n;
|
|
1116
|
+
/**
|
|
1117
|
+
* Slot index for state commitment map
|
|
1118
|
+
*/
|
|
1119
|
+
declare const STATE_COMMITMENTS_SLOT = 5n;
|
|
1120
|
+
/**
|
|
1121
|
+
* Derives the storage slot for a specific field in the StateCommitment struct
|
|
1122
|
+
*
|
|
1123
|
+
* struct StateCommitment {
|
|
1124
|
+
* uint256 timestamp; // slot + 0
|
|
1125
|
+
* bytes32 overlayRoot; // slot + 1
|
|
1126
|
+
* bytes32 stateRoot; // slot + 2
|
|
1127
|
+
* }
|
|
1128
|
+
*
|
|
1129
|
+
* @param stateMachineId - The state machine ID
|
|
1130
|
+
* @param height - The block height
|
|
1131
|
+
* @param field - The field index in the struct (0 for timestamp, 1 for overlayRoot, 2 for stateRoot)
|
|
1132
|
+
* @returns The storage slot for the specific field
|
|
1133
|
+
*/
|
|
1134
|
+
declare function getStateCommitmentFieldSlot(stateMachineId: bigint, height: bigint, field: 0 | 1 | 2): HexString;
|
|
1135
|
+
declare function getStateCommitmentSlot(stateMachineId: bigint, height: bigint): HexString;
|
|
1136
|
+
|
|
1137
|
+
/**
|
|
1138
|
+
* Generates a Merkle Mountain Range (MMR) root hash and proof for a post request.
|
|
1139
|
+
*
|
|
1140
|
+
* This function takes a post request and tree size, encodes it according to the PostRequest format,
|
|
1141
|
+
* and generates both the MMR root hash and a proof. The function builds an MMR with `treeSize` leaves,
|
|
1142
|
+
* where most leaves are variations of the encoded request (XORed with their index), except for the
|
|
1143
|
+
* last leaf, which is the unmodified request. The proof is generated for this unmodified leaf.
|
|
1144
|
+
*
|
|
1145
|
+
* @param postRequest - The post request to generate the MMR root and proof for
|
|
1146
|
+
* @param treeSize - Controls how many leaves will be added to the MMR (exactly `treeSize` leaves)
|
|
1147
|
+
* @returns An object containing:
|
|
1148
|
+
* - root: The MMR root hash as a hex string
|
|
1149
|
+
* - proof: An array of hex strings representing the MMR proof for the unmodified request
|
|
1150
|
+
* - index: The index of the unmodified request in the MMR
|
|
1151
|
+
* - kIndex: The k-index of the unmodified request in the MMR
|
|
1152
|
+
* - treeSize: The number of leaves in the MMR
|
|
1153
|
+
* - mmrSize: The size of the MMR in nodes
|
|
1154
|
+
*/
|
|
1155
|
+
declare function generateRootWithProof(postRequest: IPostRequest, treeSize: bigint): Promise<{
|
|
1156
|
+
root: HexString;
|
|
1157
|
+
proof: HexString[];
|
|
1158
|
+
index: bigint;
|
|
1159
|
+
kIndex: bigint;
|
|
1160
|
+
treeSize: bigint;
|
|
1161
|
+
mmrSize: bigint;
|
|
1162
|
+
}>;
|
|
1163
|
+
declare function __test(): Promise<string>;
|
|
1164
|
+
|
|
1165
|
+
type IStateMachine = {
|
|
1166
|
+
tag: "Evm";
|
|
1167
|
+
value: number;
|
|
1168
|
+
} | {
|
|
1169
|
+
tag: "Polkadot";
|
|
1170
|
+
value: number;
|
|
1171
|
+
} | {
|
|
1172
|
+
tag: "Kusama";
|
|
1173
|
+
value: number;
|
|
1174
|
+
} | {
|
|
1175
|
+
tag: "Substrate";
|
|
1176
|
+
value: number[];
|
|
1177
|
+
} | {
|
|
1178
|
+
tag: "Tendermint";
|
|
1179
|
+
value: number[];
|
|
1180
|
+
};
|
|
1181
|
+
|
|
1182
|
+
declare const ADDRESS_ZERO: HexString;
|
|
1183
|
+
declare const DUMMY_PRIVATE_KEY: HexString;
|
|
1184
|
+
/**
|
|
1185
|
+
* Calculates the commitment hash for a post request.
|
|
1186
|
+
* @param post The post request to calculate the commitment hash for.
|
|
1187
|
+
* @returns The commitment hash and the encode packed data.
|
|
1188
|
+
*/
|
|
1189
|
+
declare function postRequestCommitment(post: IPostRequest): {
|
|
1190
|
+
commitment: HexString;
|
|
1191
|
+
encodePacked: HexString;
|
|
1192
|
+
};
|
|
1193
|
+
declare function orderCommitment(order: Order): HexString;
|
|
1194
|
+
/**
|
|
1195
|
+
* Converts a bytes32 token address to bytes20 format
|
|
1196
|
+
* This removes the extra padded zeros from the address
|
|
1197
|
+
*/
|
|
1198
|
+
declare function bytes32ToBytes20(bytes32Address: string): HexString;
|
|
1199
|
+
declare function bytes20ToBytes32(bytes20Address: string): HexString;
|
|
1200
|
+
declare function hexToString(hex: string): string;
|
|
1201
|
+
/**
|
|
1202
|
+
* Calculates the commitment hash for a get request.
|
|
1203
|
+
* @param get The get request to calculate the commitment hash for.
|
|
1204
|
+
* @returns The commitment hash.
|
|
1205
|
+
*/
|
|
1206
|
+
declare function getRequestCommitment(get: IGetRequest): HexString;
|
|
1207
|
+
/**
|
|
1208
|
+
* Estimates the gas required for a post request transaction on the source chain.
|
|
1209
|
+
* This function constructs a post request, generates mock proofs, and estimates
|
|
1210
|
+
* the gas cost for executing the transaction on the source chain.
|
|
1211
|
+
*/
|
|
1212
|
+
declare function estimateGasForPost(params: {
|
|
1213
|
+
postRequest: IPostRequest;
|
|
1214
|
+
sourceClient: PublicClient;
|
|
1215
|
+
hostLatestStateMachineHeight: bigint;
|
|
1216
|
+
hostAddress: HexString;
|
|
1217
|
+
}): Promise<bigint>;
|
|
1218
|
+
/**
|
|
1219
|
+
* Constructs the request body for a redeem escrow operation.
|
|
1220
|
+
* This function encodes the order commitment, beneficiary address, and token inputs
|
|
1221
|
+
* to match the format expected by the IntentGateway contract.
|
|
1222
|
+
*/
|
|
1223
|
+
declare function constructRedeemEscrowRequestBody(order: Order, beneficiary: HexString): HexString;
|
|
1224
|
+
/**
|
|
1225
|
+
* Fetches the USD price of a token from CoinGecko with Defillama fallback
|
|
1226
|
+
* @param identifier - The ticker symbol of the token (e.g., "BTC", "ETH", "USDC") or contract address
|
|
1227
|
+
* @note This function will be replaced by internal price indexer
|
|
1228
|
+
* @returns The USD price of the token as a number (preserves decimals)
|
|
1229
|
+
*/
|
|
1230
|
+
declare function fetchTokenUsdPrice(identifier: string): Promise<number>;
|
|
1231
|
+
/**
|
|
1232
|
+
* Retrieves the storage slot for a contract call using debug_traceCall
|
|
1233
|
+
*
|
|
1234
|
+
* This function uses the Ethereum debug API to trace contract execution and identify
|
|
1235
|
+
* the storage slot accessed during the call. It's commonly used for ERC20 token state
|
|
1236
|
+
* mappings like balanceOf and allowance, but can work with any contract call that
|
|
1237
|
+
* performs SLOAD operations.
|
|
1238
|
+
*
|
|
1239
|
+
* @param client - The viem PublicClient instance connected to an RPC node with debug API enabled
|
|
1240
|
+
* @param tokenAddress - The address of the contract to trace
|
|
1241
|
+
* @param data - The full encoded function call data (method signature + encoded parameters)
|
|
1242
|
+
* @returns The storage slot as a hex string
|
|
1243
|
+
* @throws Error if the storage slot cannot be found or if debug API is not available
|
|
1244
|
+
*
|
|
1245
|
+
* @example
|
|
1246
|
+
* ```ts
|
|
1247
|
+
* import { ERC20Method, bytes20ToBytes32 } from '@hyperbridge/sdk'
|
|
1248
|
+
*
|
|
1249
|
+
* // Get balance storage slot for ERC20
|
|
1250
|
+
* const balanceData = ERC20Method.BALANCE_OF + bytes20ToBytes32(userAddress).slice(2)
|
|
1251
|
+
* const balanceSlot = await getStorageSlot(
|
|
1252
|
+
* client,
|
|
1253
|
+
* tokenAddress,
|
|
1254
|
+
* balanceData as HexString
|
|
1255
|
+
* )
|
|
1256
|
+
*
|
|
1257
|
+
* // Get allowance storage slot for ERC20
|
|
1258
|
+
* const allowanceData = ERC20Method.ALLOWANCE +
|
|
1259
|
+
* bytes20ToBytes32(ownerAddress).slice(2) +
|
|
1260
|
+
* bytes20ToBytes32(spenderAddress).slice(2)
|
|
1261
|
+
* const allowanceSlot = await getStorageSlot(
|
|
1262
|
+
* client,
|
|
1263
|
+
* tokenAddress,
|
|
1264
|
+
* allowanceData as HexString
|
|
1265
|
+
* )
|
|
1266
|
+
* ```
|
|
1267
|
+
*/
|
|
1268
|
+
declare function getStorageSlot(client: PublicClient, contractAddress: HexString, data: HexString): Promise<string>;
|
|
1269
|
+
|
|
1270
|
+
interface SubstrateChainParams {
|
|
1271
|
+
ws: string;
|
|
1272
|
+
hasher: "Keccak" | "Blake2";
|
|
1273
|
+
}
|
|
1274
|
+
declare class SubstrateChain implements IChain {
|
|
1275
|
+
private readonly params;
|
|
1276
|
+
api?: ApiPromise;
|
|
1277
|
+
constructor(params: SubstrateChainParams);
|
|
1278
|
+
connect(): Promise<void>;
|
|
1279
|
+
/**
|
|
1280
|
+
* Disconnects the Substrate chain connection.
|
|
1281
|
+
*/
|
|
1282
|
+
disconnect(): Promise<void>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Returns the storage key for a request receipt in the child trie
|
|
1285
|
+
* The request commitment is the key
|
|
1286
|
+
* @param key - The H256 hash key (as a 0x-prefixed hex string)
|
|
1287
|
+
* @returns The storage key as a hex string
|
|
1288
|
+
*/
|
|
1289
|
+
requestReceiptKey(key: HexString): HexString;
|
|
1290
|
+
/**
|
|
1291
|
+
* Returns the storage key for a request commitment in the child trie
|
|
1292
|
+
* The request commitment is the key
|
|
1293
|
+
* @param key - The H256 hash key (as a 0x-prefixed hex string)
|
|
1294
|
+
* @returns The storage key as a hex string
|
|
1295
|
+
*/
|
|
1296
|
+
requestCommitmentKey(key: HexString): HexString;
|
|
1297
|
+
/**
|
|
1298
|
+
* Queries a request commitment from the ISMP child trie storage.
|
|
1299
|
+
* @param {HexString} commitment - The commitment hash to look up.
|
|
1300
|
+
* @returns {Promise<HexString | undefined>} The commitment data if found, undefined otherwise.
|
|
1301
|
+
*/
|
|
1302
|
+
queryRequestCommitment(commitment: HexString): Promise<HexString | undefined>;
|
|
1303
|
+
/**
|
|
1304
|
+
* Queries the request receipt.
|
|
1305
|
+
* @param {HexString} commitment - The commitment to query.
|
|
1306
|
+
* @returns {Promise<HexString | undefined>} The relayer address responsible for delivering the request.
|
|
1307
|
+
*/
|
|
1308
|
+
queryRequestReceipt(commitment: HexString): Promise<HexString | undefined>;
|
|
1309
|
+
/**
|
|
1310
|
+
* Returns the current timestamp of the chain.
|
|
1311
|
+
* @returns {Promise<bigint>} The current timestamp.
|
|
1312
|
+
*/
|
|
1313
|
+
timestamp(): Promise<bigint>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Queries the proof of the commitments.
|
|
1316
|
+
* @param {IMessage} message - The message to query.
|
|
1317
|
+
* @param {string} counterparty - The counterparty address.
|
|
1318
|
+
* @param {bigint} [at] - The block number to query at.
|
|
1319
|
+
* @returns {Promise<HexString>} The proof.
|
|
1320
|
+
*/
|
|
1321
|
+
queryProof(message: IMessage, counterparty: string, at?: bigint): Promise<HexString>;
|
|
1322
|
+
/**
|
|
1323
|
+
* Submit an unsigned ISMP transaction to the chain. Resolves when the transaction is finalized.
|
|
1324
|
+
* @param message - The message to be submitted.
|
|
1325
|
+
* @returns A promise that resolves to an object containing the transaction hash, block hash, and block number.
|
|
1326
|
+
*/
|
|
1327
|
+
submitUnsigned(message: IIsmpMessage): Promise<{
|
|
1328
|
+
transactionHash: string;
|
|
1329
|
+
blockHash: string;
|
|
1330
|
+
blockNumber: number;
|
|
1331
|
+
timestamp: number;
|
|
1332
|
+
}>;
|
|
1333
|
+
/**
|
|
1334
|
+
* Query the state proof for a given set of keys at a specific block height.
|
|
1335
|
+
* @param at The block height to query the state proof at.
|
|
1336
|
+
* @param keys The keys to query the state proof for.
|
|
1337
|
+
* @returns The state proof as a hexadecimal string.
|
|
1338
|
+
*/
|
|
1339
|
+
queryStateProof(at: bigint, keys: HexString[]): Promise<HexString>;
|
|
1340
|
+
/**
|
|
1341
|
+
* Get the latest state machine height for a given state machine ID.
|
|
1342
|
+
* @param {StateMachineIdParams} stateMachineId - The state machine ID.
|
|
1343
|
+
* @returns {Promise<bigint>} The latest state machine height.
|
|
1344
|
+
*/
|
|
1345
|
+
latestStateMachineHeight(stateMachineId: StateMachineIdParams): Promise<bigint>;
|
|
1346
|
+
/**
|
|
1347
|
+
* Get the state machine update time for a given state machine height.
|
|
1348
|
+
* @param {StateMachineHeight} stateMachineheight - The state machine height.
|
|
1349
|
+
* @returns {Promise<bigint>} The statemachine update time in seconds.
|
|
1350
|
+
*/
|
|
1351
|
+
stateMachineUpdateTime(stateMachineHeight: StateMachineHeight): Promise<bigint>;
|
|
1352
|
+
/**
|
|
1353
|
+
* Get the challenge period for a given state machine id.
|
|
1354
|
+
* @param {StateMachineIdParams} stateMachineId - The state machine ID.
|
|
1355
|
+
* @returns {Promise<bigint>} The challenge period in seconds.
|
|
1356
|
+
*/
|
|
1357
|
+
challengePeriod(stateMachineId: StateMachineIdParams): Promise<bigint>;
|
|
1358
|
+
/**
|
|
1359
|
+
* Encode an ISMP calldata for a substrate chain.
|
|
1360
|
+
* @param message The ISMP message to encode.
|
|
1361
|
+
* @returns The encoded message as a hexadecimal string.
|
|
1362
|
+
*/
|
|
1363
|
+
encode(message: IIsmpMessage): HexString;
|
|
1364
|
+
/**
|
|
1365
|
+
* Returns the index of a pallet by its name, by looking up the pallets in the runtime metadata.
|
|
1366
|
+
* @param {string} name - The name of the pallet.
|
|
1367
|
+
* @returns {number} The index of the pallet.
|
|
1368
|
+
*/
|
|
1369
|
+
private getPalletIndex;
|
|
1370
|
+
}
|
|
1371
|
+
/**
|
|
1372
|
+
* Converts a state machine ID string to an enum value.
|
|
1373
|
+
* @param {string} id - The state machine ID string.
|
|
1374
|
+
* @returns {IStateMachine} The corresponding enum value.
|
|
1375
|
+
*/
|
|
1376
|
+
declare function convertStateMachineIdToEnum(id: string): IStateMachine;
|
|
1377
|
+
declare function encodeISMPMessage(message: IIsmpMessage): Uint8Array;
|
|
1378
|
+
|
|
1379
|
+
/**
|
|
1380
|
+
* Type representing an ISMP message.
|
|
1381
|
+
*/
|
|
1382
|
+
type IIsmpMessage = IRequestMessage | ITimeoutPostRequestMessage | IGetResponseMessage;
|
|
1383
|
+
interface IRequestMessage {
|
|
1384
|
+
/**
|
|
1385
|
+
* The kind of message.
|
|
1386
|
+
*/
|
|
1387
|
+
kind: "PostRequest";
|
|
1388
|
+
/**
|
|
1389
|
+
* The requests to be posted.
|
|
1390
|
+
*/
|
|
1391
|
+
requests: IPostRequest[];
|
|
1392
|
+
/**
|
|
1393
|
+
* The proof of the requests.
|
|
1394
|
+
*/
|
|
1395
|
+
proof: IProof;
|
|
1396
|
+
/**
|
|
1397
|
+
* The signer of the message.
|
|
1398
|
+
*/
|
|
1399
|
+
signer: HexString;
|
|
1400
|
+
}
|
|
1401
|
+
interface IGetRequestMessage {
|
|
1402
|
+
/**
|
|
1403
|
+
* The kind of message.
|
|
1404
|
+
*/
|
|
1405
|
+
kind: "GetRequest";
|
|
1406
|
+
/**
|
|
1407
|
+
* The requests to be posted.
|
|
1408
|
+
*/
|
|
1409
|
+
requests: IGetRequest[];
|
|
1410
|
+
/**
|
|
1411
|
+
* The proof of the requests.
|
|
1412
|
+
*/
|
|
1413
|
+
proof: IProof;
|
|
1414
|
+
/**
|
|
1415
|
+
* The signer of the message.
|
|
1416
|
+
*/
|
|
1417
|
+
signer: HexString;
|
|
1418
|
+
}
|
|
1419
|
+
interface IGetResponse {
|
|
1420
|
+
/**
|
|
1421
|
+
* The request that triggered this response.
|
|
1422
|
+
*/
|
|
1423
|
+
get: IGetRequest;
|
|
1424
|
+
/**
|
|
1425
|
+
* The response message.
|
|
1426
|
+
*/
|
|
1427
|
+
values: GetResponseStorageValues[];
|
|
1428
|
+
}
|
|
1429
|
+
interface IGetResponseMessage {
|
|
1430
|
+
/**
|
|
1431
|
+
* The kind of message.
|
|
1432
|
+
*/
|
|
1433
|
+
kind: "GetResponse";
|
|
1434
|
+
/**
|
|
1435
|
+
* The responses to be posted.
|
|
1436
|
+
*/
|
|
1437
|
+
responses: IGetResponse[];
|
|
1438
|
+
/**
|
|
1439
|
+
* The proof of the responses.
|
|
1440
|
+
*/
|
|
1441
|
+
proof: IProof;
|
|
1442
|
+
/**
|
|
1443
|
+
* The signer of the message.
|
|
1444
|
+
*/
|
|
1445
|
+
signer: HexString;
|
|
1446
|
+
}
|
|
1447
|
+
interface ITimeoutPostRequestMessage {
|
|
1448
|
+
/**
|
|
1449
|
+
* The kind of message.
|
|
1450
|
+
*/
|
|
1451
|
+
kind: "TimeoutPostRequest";
|
|
1452
|
+
/**
|
|
1453
|
+
* The requests to be posted.
|
|
1454
|
+
*/
|
|
1455
|
+
requests: IPostRequest[];
|
|
1456
|
+
/**
|
|
1457
|
+
* The proof of the requests.
|
|
1458
|
+
*/
|
|
1459
|
+
proof: IProof;
|
|
1460
|
+
}
|
|
1461
|
+
interface IProof {
|
|
1462
|
+
/**
|
|
1463
|
+
* The height of the proof.
|
|
1464
|
+
*/
|
|
1465
|
+
height: bigint;
|
|
1466
|
+
/**
|
|
1467
|
+
* The state machine identifier of the proof.
|
|
1468
|
+
*/
|
|
1469
|
+
stateMachine: string;
|
|
1470
|
+
/**
|
|
1471
|
+
* The associated consensus state identifier of the proof.
|
|
1472
|
+
*/
|
|
1473
|
+
consensusStateId: string;
|
|
1474
|
+
/**
|
|
1475
|
+
* The encoded storage proof
|
|
1476
|
+
*/
|
|
1477
|
+
proof: HexString;
|
|
1478
|
+
}
|
|
1479
|
+
/**
|
|
1480
|
+
* Interface representing a chain.
|
|
1481
|
+
*/
|
|
1482
|
+
interface IChain {
|
|
1483
|
+
timestamp(): Promise<bigint>;
|
|
1484
|
+
/**
|
|
1485
|
+
* Returns the state trie key for the request-receipt storage item for the given request commitment.
|
|
1486
|
+
*/
|
|
1487
|
+
requestReceiptKey(commitment: HexString): HexString;
|
|
1488
|
+
/**
|
|
1489
|
+
* Query and return the request-receipt for the given request commitment.
|
|
1490
|
+
*/
|
|
1491
|
+
queryRequestReceipt(commitment: HexString): Promise<HexString | undefined>;
|
|
1492
|
+
/**
|
|
1493
|
+
* Query and return the encoded storage proof for the provided keys at the given height.
|
|
1494
|
+
*/
|
|
1495
|
+
queryStateProof(at: bigint, keys: HexString[]): Promise<HexString>;
|
|
1496
|
+
queryProof(message: IMessage, counterparty: string, at?: bigint): Promise<HexString>;
|
|
1497
|
+
encode(message: IIsmpMessage): HexString;
|
|
1498
|
+
/**
|
|
1499
|
+
* Get the latest state machine height for a given state machine ID.
|
|
1500
|
+
*/
|
|
1501
|
+
latestStateMachineHeight(stateMachineId: StateMachineIdParams): Promise<bigint>;
|
|
1502
|
+
/**
|
|
1503
|
+
* Get the challenge period for a given state machine ID.
|
|
1504
|
+
*/
|
|
1505
|
+
challengePeriod(stateMachineId: StateMachineIdParams): Promise<bigint>;
|
|
1506
|
+
/**
|
|
1507
|
+
* Get the update time for a statemachine height.
|
|
1508
|
+
*/
|
|
1509
|
+
stateMachineUpdateTime(stateMachineHeight: StateMachineHeight): Promise<bigint>;
|
|
1510
|
+
}
|
|
1511
|
+
/**
|
|
1512
|
+
* Returns the chain interface for a given state machine identifier
|
|
1513
|
+
* @param chainConfig - Chain configuration
|
|
1514
|
+
* @returns Chain interface
|
|
1515
|
+
*/
|
|
1516
|
+
declare function getChain(chainConfig: IEvmConfig | ISubstrateConfig): Promise<IChain>;
|
|
1517
|
+
|
|
1518
|
+
/**
|
|
1519
|
+
* IndexerClient provides methods for interacting with the Hyperbridge indexer.
|
|
1520
|
+
*
|
|
1521
|
+
* This client facilitates querying and tracking cross-chain requests and their status
|
|
1522
|
+
* through the Hyperbridge protocol. It supports:
|
|
1523
|
+
*
|
|
1524
|
+
* - Querying state machine updates by block height or timestamp
|
|
1525
|
+
* - Retrieving request status information by transaction hash
|
|
1526
|
+
* - Monitoring request status changes through streaming interfaces
|
|
1527
|
+
* - Handling request timeout flows and related proof generation
|
|
1528
|
+
* - Tracking request finalization across source and destination chains
|
|
1529
|
+
*
|
|
1530
|
+
* The client implements automatic retries with exponential backoff for network
|
|
1531
|
+
* resilience and provides both simple query methods and advanced streaming
|
|
1532
|
+
* interfaces for real-time status tracking.
|
|
1533
|
+
*
|
|
1534
|
+
* The URLs provided in the configuration must point to archive nodes to allow the client to query for storage proofs
|
|
1535
|
+
* of potentially much older blocks. Regular nodes only store the state for recent blocks and will not be able
|
|
1536
|
+
* to provide the necessary proofs for cross-chain verification, especially in timeout scenarios.
|
|
1537
|
+
*
|
|
1538
|
+
* @example
|
|
1539
|
+
* ```typescript
|
|
1540
|
+
* const client = new IndexerClient({
|
|
1541
|
+
* url: "https://indexer.hyperbridge.xyz/graphql",
|
|
1542
|
+
* pollInterval: 2000,
|
|
1543
|
+
* source: {
|
|
1544
|
+
* stateMachineId: "EVM-1",
|
|
1545
|
+
* consensusStateId: "ETH0"
|
|
1546
|
+
* rpcUrl: "",
|
|
1547
|
+
* host: "0x87ea45..",
|
|
1548
|
+
* },
|
|
1549
|
+
* dest: {
|
|
1550
|
+
* stateMachineId: "EVM-42161",
|
|
1551
|
+
* consensusStateId: "ETH0"
|
|
1552
|
+
* rpcUrl: "",
|
|
1553
|
+
* host: "0x87ea42345..",
|
|
1554
|
+
* },
|
|
1555
|
+
* hyperbridge: {
|
|
1556
|
+
* stateMachineId: "POLKADOT-3367",
|
|
1557
|
+
* consensusStateId: "DOT0"
|
|
1558
|
+
* wsUrl: "ws://localhost:9944"
|
|
1559
|
+
* }
|
|
1560
|
+
* });
|
|
1561
|
+
*
|
|
1562
|
+
* // Query a request status
|
|
1563
|
+
* const status = await client.queryRequestWithStatus("0x1234...");
|
|
1564
|
+
*
|
|
1565
|
+
* // Stream status updates
|
|
1566
|
+
* for await (const update of client.postRequestStatusStream("0x1234...")) {
|
|
1567
|
+
* console.log(`Request status: ${update.status}`);
|
|
1568
|
+
* }
|
|
1569
|
+
* ```
|
|
1570
|
+
*/
|
|
1571
|
+
declare class IndexerClient {
|
|
1572
|
+
/**
|
|
1573
|
+
* GraphQL client used for making requests to the indexer
|
|
1574
|
+
*/
|
|
1575
|
+
private client;
|
|
1576
|
+
/**
|
|
1577
|
+
* Configuration for the IndexerClient including URLs, poll intervals, and chain-specific settings
|
|
1578
|
+
*/
|
|
1579
|
+
private config;
|
|
1580
|
+
private logger;
|
|
1581
|
+
/**
|
|
1582
|
+
* Default configuration for retry behavior when network requests fail
|
|
1583
|
+
* - maxRetries: Maximum number of retry attempts before failing
|
|
1584
|
+
* - backoffMs: Initial backoff time in milliseconds (doubles with each retry)
|
|
1585
|
+
*/
|
|
1586
|
+
private defaultRetryConfig;
|
|
1587
|
+
/**
|
|
1588
|
+
* Creates a new IndexerClient instance
|
|
1589
|
+
*/
|
|
1590
|
+
constructor(config: PartialClientConfig);
|
|
1591
|
+
/**
|
|
1592
|
+
* Query for a single state machine update event greater than or equal to the given height.
|
|
1593
|
+
* @params statemachineId - ID of the state machine
|
|
1594
|
+
* @params height - Starting block height
|
|
1595
|
+
* @params chain - The identifier for the chain where the state machine update should be queried (corresponds to a stateMachineId)
|
|
1596
|
+
* @returns Closest state machine update
|
|
1597
|
+
*/
|
|
1598
|
+
queryStateMachineUpdateByHeight({ statemachineId, height, chain, }: {
|
|
1599
|
+
statemachineId: string;
|
|
1600
|
+
chain: string;
|
|
1601
|
+
height: number;
|
|
1602
|
+
}): Promise<StateMachineUpdate | undefined>;
|
|
1603
|
+
/**
|
|
1604
|
+
* Query for a single state machine update event greater than or equal to the given timestamp.
|
|
1605
|
+
* @params statemachineId - ID of the state machine
|
|
1606
|
+
* @params timestamp - Starting block timestamp
|
|
1607
|
+
* @params chain - The identifier for the chain where the state machine update should be queried (corresponds to a stateMachineId)
|
|
1608
|
+
* @returns Closest state machine update
|
|
1609
|
+
*/
|
|
1610
|
+
queryStateMachineUpdateByTimestamp({ statemachineId, commitmentTimestamp, chain, }: {
|
|
1611
|
+
statemachineId: string;
|
|
1612
|
+
commitmentTimestamp: bigint;
|
|
1613
|
+
chain: string;
|
|
1614
|
+
}): Promise<StateMachineUpdate | undefined>;
|
|
1615
|
+
/**
|
|
1616
|
+
* Queries a request by CommitmentHash
|
|
1617
|
+
*
|
|
1618
|
+
* @param commitment_hash - Can be commitment
|
|
1619
|
+
* @returns Latest status and block metadata of the request
|
|
1620
|
+
*/
|
|
1621
|
+
queryPostRequest(commitment_hash: string): Promise<PostRequestWithStatus | undefined>;
|
|
1622
|
+
/**
|
|
1623
|
+
* Queries a request by any of its associated hashes and returns it alongside its statuses
|
|
1624
|
+
* Statuses will be one of SOURCE, HYPERBRIDGE_DELIVERED and DESTINATION
|
|
1625
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
1626
|
+
* @returns Latest status and block metadata of the request
|
|
1627
|
+
*/
|
|
1628
|
+
queryGetRequest(hash: string): Promise<GetRequestWithStatus | undefined>;
|
|
1629
|
+
/**
|
|
1630
|
+
* Queries the response associated with a specific request ID and returns its commitment
|
|
1631
|
+
* @param requestId - The ID of the request to find the associated response for
|
|
1632
|
+
* @returns The response associated with the given request ID, or undefined if not found
|
|
1633
|
+
*/
|
|
1634
|
+
queryResponseByRequestId(requestId: string): Promise<ResponseCommitmentWithValues | undefined>;
|
|
1635
|
+
/**
|
|
1636
|
+
* Enhances a request with finality events by querying state machine updates.
|
|
1637
|
+
*
|
|
1638
|
+
* This method augments a request object with additional inferred status events
|
|
1639
|
+
* that represent chain finality confirmations. It adds:
|
|
1640
|
+
* - SOURCE_FINALIZED: When the source chain has finalized the request
|
|
1641
|
+
* - HYPERBRIDGE_FINALIZED: When Hyperbridge has finalized the delivery confirmation
|
|
1642
|
+
*
|
|
1643
|
+
* The method also generates appropriate calldata for submitting cross-chain proofs
|
|
1644
|
+
* when applicable.
|
|
1645
|
+
*
|
|
1646
|
+
* @param request - The request to enhance with finality events
|
|
1647
|
+
* @returns The request with finality events added
|
|
1648
|
+
* @private
|
|
1649
|
+
*/
|
|
1650
|
+
private addRequestFinalityEvents;
|
|
1651
|
+
/**
|
|
1652
|
+
* Adds timeout finality events to a request by querying for relevant timeout proofs and
|
|
1653
|
+
* chain state necessary for timeout processing.
|
|
1654
|
+
*
|
|
1655
|
+
* This method enhances a request object with additional status events related to the
|
|
1656
|
+
* timeout flow, including:
|
|
1657
|
+
* - PENDING_TIMEOUT: When a request has passed its timeout timestamp
|
|
1658
|
+
* - DESTINATION_FINALIZED: When the destination chain has finalized the timeout timestamp
|
|
1659
|
+
* - HYPERBRIDGE_FINALIZED_TIMEOUT: When hyperbridge has finalized the timeout state
|
|
1660
|
+
*
|
|
1661
|
+
* The method also generates appropriate calldata for submitting timeout proofs.
|
|
1662
|
+
*
|
|
1663
|
+
* @param request - Request to fill timeout events for
|
|
1664
|
+
* @returns Request with timeout events filled in, including any proof calldata for timeout submissions
|
|
1665
|
+
* @private
|
|
1666
|
+
*/
|
|
1667
|
+
private addTimeoutFinalityEvents;
|
|
1668
|
+
/**
|
|
1669
|
+
* Queries a request returns it alongside its statuses,
|
|
1670
|
+
* including any finalization events.
|
|
1671
|
+
* @param hash - Commitment hash
|
|
1672
|
+
* @returns Full request data with all inferred status events, including SOURCE_FINALIZED and HYPERBRIDGE_FINALIZED
|
|
1673
|
+
* @remarks Unlike queryRequest(), this method adds derived finalization status events by querying state machine updates
|
|
1674
|
+
*/
|
|
1675
|
+
queryRequestWithStatus(hash: string): Promise<PostRequestWithStatus | undefined>;
|
|
1676
|
+
/**
|
|
1677
|
+
* Create a Stream of status updates for a post request.
|
|
1678
|
+
* Stream ends when either the request reaches the destination or times out.
|
|
1679
|
+
* If the stream yields TimeoutStatus.PENDING_TIMEOUT, use postRequestTimeoutStream() to begin timeout processing.
|
|
1680
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
1681
|
+
* @returns AsyncGenerator that emits status updates until a terminal state is reached
|
|
1682
|
+
* @example
|
|
1683
|
+
*
|
|
1684
|
+
* let client = new IndexerClient(config)
|
|
1685
|
+
* let stream = client.postRequestStatusStream(hash)
|
|
1686
|
+
*
|
|
1687
|
+
* // you can use a for-await-of loop
|
|
1688
|
+
* for await (const status of stream) {
|
|
1689
|
+
* console.log(status)
|
|
1690
|
+
* }
|
|
1691
|
+
*
|
|
1692
|
+
* // you can also use a while loop
|
|
1693
|
+
* while (true) {
|
|
1694
|
+
* const status = await stream.next()
|
|
1695
|
+
* if (status.done) {
|
|
1696
|
+
* break
|
|
1697
|
+
* }
|
|
1698
|
+
* console.log(status.value)
|
|
1699
|
+
* }
|
|
1700
|
+
*
|
|
1701
|
+
*/
|
|
1702
|
+
postRequestStatusStream(hash: HexString): AsyncGenerator<RequestStatusWithMetadata, void>;
|
|
1703
|
+
timeoutStream(timeoutTimestamp: bigint, chain: IChain): AsyncGenerator<RequestStatusWithMetadata, void>;
|
|
1704
|
+
/**
|
|
1705
|
+
* Create a Stream of status updates
|
|
1706
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
1707
|
+
* @returns AsyncGenerator that emits status updates until a terminal state is reached
|
|
1708
|
+
*/
|
|
1709
|
+
private postRequestStatusStreamInternal;
|
|
1710
|
+
private sleep_for;
|
|
1711
|
+
private sleep_for_interval;
|
|
1712
|
+
/**
|
|
1713
|
+
* Create a Stream of status updates for a get request.
|
|
1714
|
+
* Stream ends when either the request reaches the destination or times out.
|
|
1715
|
+
* If the stream yields TimeoutStatus.PENDING_TIMEOUT, use postRequestTimeoutStream() to begin timeout processing.
|
|
1716
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
1717
|
+
* @returns AsyncGenerator that emits status updates until a terminal state is reached
|
|
1718
|
+
* @example
|
|
1719
|
+
*
|
|
1720
|
+
* let client = new IndexerClient(config)
|
|
1721
|
+
* let stream = client.getRequestStatusStream(hash)
|
|
1722
|
+
*
|
|
1723
|
+
* // you can use a for-await-of loop
|
|
1724
|
+
* for await (const status of stream) {
|
|
1725
|
+
* console.log(status)
|
|
1726
|
+
* }
|
|
1727
|
+
*
|
|
1728
|
+
* // you can also use a while loop
|
|
1729
|
+
* while (true) {
|
|
1730
|
+
* const status = await stream.next()
|
|
1731
|
+
* if (status.done) {
|
|
1732
|
+
* break
|
|
1733
|
+
* }
|
|
1734
|
+
* console.log(status.value)
|
|
1735
|
+
* }
|
|
1736
|
+
*
|
|
1737
|
+
*/
|
|
1738
|
+
getRequestStatusStream(hash: HexString): AsyncGenerator<RequestStatusWithMetadata, void>;
|
|
1739
|
+
/**
|
|
1740
|
+
* Create a Stream of status updates
|
|
1741
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
1742
|
+
* @returns AsyncGenerator that emits status updates until a terminal state is reached
|
|
1743
|
+
*/
|
|
1744
|
+
private getRequestStatusStreamInternal;
|
|
1745
|
+
/**
|
|
1746
|
+
* Create a Stream of status updates for a timed out post request.
|
|
1747
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
1748
|
+
* @returns AsyncGenerator that emits status updates until a terminal state is reached
|
|
1749
|
+
* @example
|
|
1750
|
+
*
|
|
1751
|
+
* let client = new IndexerClient(config)
|
|
1752
|
+
* let stream = client.postRequestTimeoutStream(hash)
|
|
1753
|
+
*
|
|
1754
|
+
* // you can use a for-await-of loop
|
|
1755
|
+
* for await (const status of stream) {
|
|
1756
|
+
* console.log(status)
|
|
1757
|
+
* }
|
|
1758
|
+
*
|
|
1759
|
+
* // you can also use a while loop
|
|
1760
|
+
* while (true) {
|
|
1761
|
+
* const status = await stream.next()
|
|
1762
|
+
* if (status.done) {
|
|
1763
|
+
* break
|
|
1764
|
+
* }
|
|
1765
|
+
* console.log(status.value)
|
|
1766
|
+
* }
|
|
1767
|
+
*/
|
|
1768
|
+
postRequestTimeoutStream(hash: HexString): AsyncGenerator<PostRequestTimeoutStatus, void>;
|
|
1769
|
+
/**
|
|
1770
|
+
* Create a Stream of status updates for a timed out post request.
|
|
1771
|
+
* @param hash - Can be commitment, hyperbridge tx hash, source tx hash, destination tx hash, or timeout tx hash
|
|
1772
|
+
* @returns AsyncGenerator that emits status updates until a terminal state is reached
|
|
1773
|
+
*/
|
|
1774
|
+
postRequestTimeoutStreamInternal(hash: HexString, signal: AbortSignal): AsyncGenerator<PostRequestTimeoutStatus, void>;
|
|
1775
|
+
/**
|
|
1776
|
+
* Query for asset teleported events by sender, recipient, and destination chain
|
|
1777
|
+
* @param from - The sender address
|
|
1778
|
+
* @param to - The recipient address
|
|
1779
|
+
* @param dest - The destination chain ID
|
|
1780
|
+
* @returns The asset teleported event if found, undefined otherwise
|
|
1781
|
+
*/
|
|
1782
|
+
queryAssetTeleported(from: string, to: string, dest: string, blockNumber: number): Promise<AssetTeleported | undefined>;
|
|
1783
|
+
/**
|
|
1784
|
+
* Executes an async operation with exponential backoff retry
|
|
1785
|
+
* @param operation - Async function to execute
|
|
1786
|
+
* @param retryConfig - Optional retry configuration
|
|
1787
|
+
* @returns Result of the operation
|
|
1788
|
+
* @throws Last encountered error after all retries are exhausted
|
|
1789
|
+
*
|
|
1790
|
+
* @example
|
|
1791
|
+
* const result = await this.withRetry(() => this.queryStatus(hash));
|
|
1792
|
+
*/
|
|
1793
|
+
private withRetry;
|
|
1794
|
+
/**
|
|
1795
|
+
* Query for an order by its commitment hash
|
|
1796
|
+
* @param commitment - The commitment hash of the order
|
|
1797
|
+
* @returns The order with its status if found, undefined otherwise
|
|
1798
|
+
*/
|
|
1799
|
+
queryOrder(commitment: HexString): Promise<OrderWithStatus | undefined>;
|
|
1800
|
+
/**
|
|
1801
|
+
* Create a Stream of status updates for an order.
|
|
1802
|
+
* Stream ends when the order reaches a terminal state (FILLED, REDEEMED, or REFUNDED).
|
|
1803
|
+
* @param commitment - The commitment hash of the order
|
|
1804
|
+
* @returns AsyncGenerator that emits status updates until a terminal state is reached
|
|
1805
|
+
* @example
|
|
1806
|
+
*
|
|
1807
|
+
* let client = new IndexerClient(config)
|
|
1808
|
+
* let stream = client.orderStatusStream(commitment)
|
|
1809
|
+
*
|
|
1810
|
+
* // you can use a for-await-of loop
|
|
1811
|
+
* for await (const status of stream) {
|
|
1812
|
+
* console.log(status)
|
|
1813
|
+
* }
|
|
1814
|
+
*
|
|
1815
|
+
* // you can also use a while loop
|
|
1816
|
+
* while (true) {
|
|
1817
|
+
* const status = await stream.next()
|
|
1818
|
+
* if (status.done) {
|
|
1819
|
+
* break
|
|
1820
|
+
* }
|
|
1821
|
+
* console.log(status.value)
|
|
1822
|
+
* }
|
|
1823
|
+
*/
|
|
1824
|
+
orderStatusStream(commitment: HexString): AsyncGenerator<{
|
|
1825
|
+
status: OrderStatus;
|
|
1826
|
+
metadata: {
|
|
1827
|
+
blockHash: string;
|
|
1828
|
+
blockNumber: number;
|
|
1829
|
+
transactionHash: string;
|
|
1830
|
+
timestamp: bigint;
|
|
1831
|
+
filler?: string;
|
|
1832
|
+
};
|
|
1833
|
+
}, void>;
|
|
1834
|
+
tokenGatewayAssetTeleportedStatusStream(commitment: HexString): AsyncGenerator<{
|
|
1835
|
+
status: TeleportStatus;
|
|
1836
|
+
metadata: {
|
|
1837
|
+
blockHash: string;
|
|
1838
|
+
blockNumber: number;
|
|
1839
|
+
transactionHash: string;
|
|
1840
|
+
timestamp: bigint;
|
|
1841
|
+
};
|
|
1842
|
+
}, void>;
|
|
1843
|
+
private queryTokenGatewayAssetTeleported;
|
|
1844
|
+
/**
|
|
1845
|
+
* Aggregate transactions with commitment.
|
|
1846
|
+
* @param commitment
|
|
1847
|
+
* @returns an object containing the transaction hash, block hash, block number, timestamp.
|
|
1848
|
+
*/
|
|
1849
|
+
aggregateTransactionWithCommitment(commitment: HexString): Promise<Awaited<ReturnType<SubstrateChain["submitUnsigned"]>>>;
|
|
1850
|
+
waitOrAbort<T>(params: {
|
|
1851
|
+
signal: AbortSignal;
|
|
1852
|
+
promise: () => Promise<T>;
|
|
1853
|
+
predicate?: (a: T) => boolean;
|
|
1854
|
+
}): Promise<NonNullable<T>>;
|
|
1855
|
+
}
|
|
1856
|
+
interface PartialClientConfig extends Omit<ClientConfig, "pollInterval"> {
|
|
1857
|
+
pollInterval?: number;
|
|
1858
|
+
}
|
|
1859
|
+
|
|
1860
|
+
declare function createQueryClient(config: {
|
|
1861
|
+
url: string;
|
|
1862
|
+
}): GraphQLClient;
|
|
1863
|
+
/**
|
|
1864
|
+
* Queries a request by CommitmentHash
|
|
1865
|
+
*
|
|
1866
|
+
* @example
|
|
1867
|
+
* import { createQueryClient, queryRequest } from "@hyperbridge/sdk"
|
|
1868
|
+
*
|
|
1869
|
+
* const queryClient = createQueryClient({
|
|
1870
|
+
* url: "http://localhost:3000", // URL of the Hyperbridge indexer API
|
|
1871
|
+
* })
|
|
1872
|
+
* const commitmentHash = "0x...."
|
|
1873
|
+
* const request = await queryPostRequest({ commitmentHash, queryClient })
|
|
1874
|
+
*/
|
|
1875
|
+
declare function queryPostRequest(params: {
|
|
1876
|
+
commitmentHash: string;
|
|
1877
|
+
queryClient: IndexerQueryClient;
|
|
1878
|
+
}): Promise<PostRequestWithStatus | undefined>;
|
|
1879
|
+
/**
|
|
1880
|
+
* Queries a GET Request by CommitmentHash
|
|
1881
|
+
*
|
|
1882
|
+
* @example
|
|
1883
|
+
* import { createQueryClient, queryRequest } from "@hyperbridge/sdk"
|
|
1884
|
+
*
|
|
1885
|
+
* const queryClient = createQueryClient({
|
|
1886
|
+
* url: "http://localhost:3000", // URL of the Hyperbridge indexer API
|
|
1887
|
+
* })
|
|
1888
|
+
* const commitmentHash = "0x...."
|
|
1889
|
+
* const request = await queryGetRequest({ commitmentHash, queryClient })
|
|
1890
|
+
*/
|
|
1891
|
+
declare function queryGetRequest(params: {
|
|
1892
|
+
commitmentHash: string;
|
|
1893
|
+
queryClient: IndexerQueryClient;
|
|
1894
|
+
}): Promise<GetRequestWithStatus | undefined>;
|
|
1895
|
+
|
|
1896
|
+
/**
|
|
1897
|
+
* IntentGateway handles cross-chain intent operations between EVM chains.
|
|
1898
|
+
* It provides functionality for estimating fill orders, finding optimal swap protocols,
|
|
1899
|
+
* and checking order statuses across different chains.
|
|
1900
|
+
*/
|
|
1901
|
+
declare class IntentGateway {
|
|
1902
|
+
readonly source: EvmChain;
|
|
1903
|
+
readonly dest: EvmChain;
|
|
1904
|
+
/**
|
|
1905
|
+
* Creates a new IntentGateway instance for cross-chain operations.
|
|
1906
|
+
* @param source - The source EVM chain
|
|
1907
|
+
* @param dest - The destination EVM chain
|
|
1908
|
+
*/
|
|
1909
|
+
constructor(source: EvmChain, dest: EvmChain);
|
|
1910
|
+
/**
|
|
1911
|
+
* Estimates the total cost required to fill an order, including gas fees, relayer fees,
|
|
1912
|
+
* protocol fees, and swap operations.
|
|
1913
|
+
*
|
|
1914
|
+
* @param order - The order to estimate fill costs for
|
|
1915
|
+
* @returns The estimated total cost in the source chain's fee token
|
|
1916
|
+
*/
|
|
1917
|
+
estimateFillOrder(order: Order): Promise<bigint>;
|
|
1918
|
+
/**
|
|
1919
|
+
* Finds the best Uniswap protocol (V2 or V3) for swapping tokens given a desired output amount.
|
|
1920
|
+
* Compares liquidity and pricing across different protocols and fee tiers.
|
|
1921
|
+
*
|
|
1922
|
+
* @param chain - The chain identifier where the swap will occur
|
|
1923
|
+
* @param tokenIn - The address of the input token
|
|
1924
|
+
* @param tokenOut - The address of the output token
|
|
1925
|
+
* @param amountOut - The desired output amount
|
|
1926
|
+
* @returns Object containing the best protocol, required input amount, fee tier (for V3), and gas estimate
|
|
1927
|
+
*/
|
|
1928
|
+
findBestProtocolWithAmountOut(chain: string, tokenIn: HexString, tokenOut: HexString, amountOut: bigint): Promise<{
|
|
1929
|
+
protocol: "v2" | "v3" | null;
|
|
1930
|
+
amountIn: bigint;
|
|
1931
|
+
fee?: number;
|
|
1932
|
+
gasEstimate?: bigint;
|
|
1933
|
+
}>;
|
|
1934
|
+
/**
|
|
1935
|
+
* Finds the best Uniswap protocol (V2 or V3) for swapping tokens given an input amount.
|
|
1936
|
+
* Compares liquidity and pricing across different protocols and fee tiers.
|
|
1937
|
+
*
|
|
1938
|
+
* @param chain - The chain identifier where the swap will occur
|
|
1939
|
+
* @param tokenIn - The address of the input token
|
|
1940
|
+
* @param tokenOut - The address of the output token
|
|
1941
|
+
* @param amountIn - The input amount to swap
|
|
1942
|
+
* @returns Object containing the best protocol, expected output amount, fee tier (for V3), and gas estimate
|
|
1943
|
+
*/
|
|
1944
|
+
findBestProtocolWithAmountIn(chain: string, tokenIn: HexString, tokenOut: HexString, amountIn: bigint): Promise<{
|
|
1945
|
+
protocol: "v2" | "v3" | null;
|
|
1946
|
+
amountOut: bigint;
|
|
1947
|
+
fee?: number;
|
|
1948
|
+
gasEstimate?: bigint;
|
|
1949
|
+
}>;
|
|
1950
|
+
/**
|
|
1951
|
+
* Converts gas costs to the equivalent amount in the fee token (DAI).
|
|
1952
|
+
* Uses USD pricing to convert between native token gas costs and fee token amounts.
|
|
1953
|
+
*
|
|
1954
|
+
* @param gasEstimate - The estimated gas units
|
|
1955
|
+
* @param publicClient - The client for the chain to get gas prices
|
|
1956
|
+
* @param targetDecimals - The decimal places of the target fee token
|
|
1957
|
+
* @returns The gas cost converted to fee token amount
|
|
1958
|
+
* @private
|
|
1959
|
+
*/
|
|
1960
|
+
private convertGasToFeeToken;
|
|
1961
|
+
/**
|
|
1962
|
+
* Adjusts fee amounts between different decimal precisions.
|
|
1963
|
+
* Handles scaling up or down based on the decimal difference.
|
|
1964
|
+
*
|
|
1965
|
+
* @param feeInFeeToken - The fee amount to adjust
|
|
1966
|
+
* @param fromDecimals - The current decimal precision
|
|
1967
|
+
* @param toDecimals - The target decimal precision
|
|
1968
|
+
* @returns The adjusted fee amount with the target decimal precision
|
|
1969
|
+
*/
|
|
1970
|
+
adjustFeeDecimals(feeInFeeToken: bigint, fromDecimals: number, toDecimals: number): bigint;
|
|
1971
|
+
/**
|
|
1972
|
+
* Checks if an order has been filled by verifying the commitment status on-chain.
|
|
1973
|
+
* Reads the storage slot corresponding to the order's commitment hash.
|
|
1974
|
+
*
|
|
1975
|
+
* @param order - The order to check
|
|
1976
|
+
* @returns True if the order has been filled, false otherwise
|
|
1977
|
+
*/
|
|
1978
|
+
isOrderFilled(order: Order): Promise<boolean>;
|
|
1979
|
+
}
|
|
1980
|
+
|
|
1981
|
+
type HyperbridgeTxEvents = {
|
|
1982
|
+
kind: "Ready";
|
|
1983
|
+
transaction_hash: HexString;
|
|
1984
|
+
} | {
|
|
1985
|
+
kind: "Dispatched";
|
|
1986
|
+
transaction_hash: HexString;
|
|
1987
|
+
block_number: bigint;
|
|
1988
|
+
commitment: HexString;
|
|
1989
|
+
} | {
|
|
1990
|
+
kind: "Finalized";
|
|
1991
|
+
transaction_hash: HexString;
|
|
1992
|
+
block_number?: bigint;
|
|
1993
|
+
commitment?: HexString;
|
|
1994
|
+
} | {
|
|
1995
|
+
kind: "Error";
|
|
1996
|
+
error: unknown;
|
|
1997
|
+
};
|
|
1998
|
+
/**
|
|
1999
|
+
* Parameters for teleporting DOT from Polkadot relay chain to EVM-based destination
|
|
2000
|
+
*/
|
|
2001
|
+
type XcmGatewayParams = {
|
|
2002
|
+
/**
|
|
2003
|
+
* Destination state machine ID (chain ID) where assets will be teleported to
|
|
2004
|
+
* This value identifies the specific EVM chain in the destination network
|
|
2005
|
+
*/
|
|
2006
|
+
destination: number;
|
|
2007
|
+
/**
|
|
2008
|
+
* The recipient address on the destination chain (in hex format)
|
|
2009
|
+
* This is the EVM address that will receive the teleported assets
|
|
2010
|
+
*/
|
|
2011
|
+
recipient: HexString;
|
|
2012
|
+
/**
|
|
2013
|
+
* Amount of DOT to teleport
|
|
2014
|
+
* This will be converted to the appropriate format internally
|
|
2015
|
+
*/
|
|
2016
|
+
amount: number;
|
|
2017
|
+
/**
|
|
2018
|
+
* Request timeout value in blocks or timestamp
|
|
2019
|
+
* Specifies how long the teleport request remains valid before expiring
|
|
2020
|
+
*/
|
|
2021
|
+
timeout: bigint;
|
|
2022
|
+
/**
|
|
2023
|
+
* The parachain ID of the Hyperbridge
|
|
2024
|
+
*/
|
|
2025
|
+
paraId: number;
|
|
2026
|
+
};
|
|
2027
|
+
/**
|
|
2028
|
+
* Teleports DOT tokens from Polkadot relay chain to an EVM-based destination chain
|
|
2029
|
+
* using XCM (Cross-Consensus Message Format) and uses the indexer client to track
|
|
2030
|
+
* the transaction instead of polling hyperbridge blocks.
|
|
2031
|
+
*
|
|
2032
|
+
* This function initiates a teleport transaction, monitors its status through the indexer,
|
|
2033
|
+
* and yields events about the transaction's progress through a ReadableStream.
|
|
2034
|
+
* It handles the complete lifecycle of a teleport operation:
|
|
2035
|
+
* 1. Transaction preparation and signing
|
|
2036
|
+
* 2. Broadcasting to the relay chain
|
|
2037
|
+
* 3. Tracking the transaction via the indexer client
|
|
2038
|
+
* 4. Yielding events about transaction status
|
|
2039
|
+
*
|
|
2040
|
+
* Note: There is no guarantee that both Dispatched and Finalized events will be yielded.
|
|
2041
|
+
* Consumers should listen for either one of these events instead of expecting both.
|
|
2042
|
+
*
|
|
2043
|
+
* @param relayApi - Polkadot API instance connected to the relay chain
|
|
2044
|
+
* @param hyperbridge - Polkadot API instance connected to the Hyperbridge parachain
|
|
2045
|
+
* @param who - Sender's SS58Address address
|
|
2046
|
+
* @param options - Transaction signing options
|
|
2047
|
+
* @param params - Teleport parameters including destination, recipient, and amount
|
|
2048
|
+
* @param indexerClient - The indexer client to track the transaction
|
|
2049
|
+
* @param pollInterval - Optional polling interval in milliseconds (default: 2000)
|
|
2050
|
+
* @yields {HyperbridgeTxEvents} Stream of events indicating transaction status
|
|
2051
|
+
*/
|
|
2052
|
+
declare function teleportDot(param_: {
|
|
2053
|
+
relayApi: ApiPromise;
|
|
2054
|
+
hyperbridge: ApiPromise;
|
|
2055
|
+
who: string;
|
|
2056
|
+
xcmGatewayParams: XcmGatewayParams;
|
|
2057
|
+
indexerClient: IndexerClient;
|
|
2058
|
+
pollInterval?: number;
|
|
2059
|
+
options: Partial<SignerOptions>;
|
|
2060
|
+
}): Promise<ReadableStream<HyperbridgeTxEvents>>;
|
|
2061
|
+
|
|
2062
|
+
type Params = {
|
|
2063
|
+
/** Asset symbol for the teleport operation */
|
|
2064
|
+
symbol: string;
|
|
2065
|
+
/**
|
|
2066
|
+
* Destination state machine identifier (e.g., "EVM-1", "SUBSTRATE-cere")
|
|
2067
|
+
* that specifies the target blockchain or network
|
|
2068
|
+
*/
|
|
2069
|
+
destination: string;
|
|
2070
|
+
/**
|
|
2071
|
+
* Recipient address in hexadecimal format where the assets will be sent
|
|
2072
|
+
* on the destination chain
|
|
2073
|
+
*/
|
|
2074
|
+
recipient: HexString;
|
|
2075
|
+
/**
|
|
2076
|
+
* Amount of tokens to teleport, represented as a bigint to handle
|
|
2077
|
+
* large numeric values precisely
|
|
2078
|
+
*/
|
|
2079
|
+
amount: bigint;
|
|
2080
|
+
/**
|
|
2081
|
+
* Request timeout in block numbers or timestamp, after which the
|
|
2082
|
+
* teleport operation will be considered failed
|
|
2083
|
+
*/
|
|
2084
|
+
timeout: bigint;
|
|
2085
|
+
/**
|
|
2086
|
+
* Address of the token gateway contract on the destination chain
|
|
2087
|
+
* that will process the teleported assets
|
|
2088
|
+
*/
|
|
2089
|
+
tokenGatewayAddress: Uint8Array;
|
|
2090
|
+
/**
|
|
2091
|
+
* Fee paid to relayers who process the cross-chain transaction,
|
|
2092
|
+
* represented as a bigint
|
|
2093
|
+
*/
|
|
2094
|
+
relayerFee: bigint;
|
|
2095
|
+
/**
|
|
2096
|
+
* Optional call data to be executed on the destination chain
|
|
2097
|
+
* as part of the teleport operation
|
|
2098
|
+
*/
|
|
2099
|
+
callData?: Uint8Array;
|
|
2100
|
+
/**
|
|
2101
|
+
* Flag indicating whether to automatically redeem the tokens
|
|
2102
|
+
* for erc20
|
|
2103
|
+
*/
|
|
2104
|
+
redeem: boolean;
|
|
2105
|
+
};
|
|
2106
|
+
/**
|
|
2107
|
+
* Teleports assets from Substrate to other chains via the token gateway
|
|
2108
|
+
*
|
|
2109
|
+
* Note: There is no guarantee that both Dispatched and Finalized events will be yielded.
|
|
2110
|
+
* Consumers should listen for either one of these events instead of expecting both.
|
|
2111
|
+
*
|
|
2112
|
+
*
|
|
2113
|
+
* @param apiPromise - Polkadot API instance
|
|
2114
|
+
* @param who - SS58Address
|
|
2115
|
+
* @param params - Teleport parameters
|
|
2116
|
+
* @param params.symbol - Asset symbol
|
|
2117
|
+
* @param params.destination - Target state machine ID
|
|
2118
|
+
* @param params.recipient - Recipient address
|
|
2119
|
+
* @param params.amount - Amount to teleport
|
|
2120
|
+
* @param params.timeout - Operation timeout
|
|
2121
|
+
* @param params.tokenGatewayAddress - Gateway contract address
|
|
2122
|
+
* @param params.relayerFee - Fee for the relayer
|
|
2123
|
+
* @param params.redeem - Whether to redeem on arrival
|
|
2124
|
+
* @param params.callData - Optional additional call data
|
|
2125
|
+
* @param options - Signer options
|
|
2126
|
+
* @yields {HyperbridgeTxEvents} Stream of events indicating transaction status
|
|
2127
|
+
* @throws Error when asset ID is unknown or transaction fails
|
|
2128
|
+
*/
|
|
2129
|
+
declare function teleport(teleport_param: {
|
|
2130
|
+
who: string;
|
|
2131
|
+
params: Params;
|
|
2132
|
+
apiPromise: ApiPromise;
|
|
2133
|
+
options: Partial<SignerOptions>;
|
|
2134
|
+
}): Promise<ReadableStream<HyperbridgeTxEvents>>;
|
|
2135
|
+
|
|
2136
|
+
declare enum Chains {
|
|
2137
|
+
BSC_CHAPEL = "EVM-97",
|
|
2138
|
+
GNOSIS_CHIADO = "EVM-10200",
|
|
2139
|
+
HYPERBRIDGE_GARGANTUA = "KUSAMA-4009",
|
|
2140
|
+
SEPOLIA = "EVM-11155111"
|
|
2141
|
+
}
|
|
2142
|
+
type AddressMap = {
|
|
2143
|
+
[key: string]: {
|
|
2144
|
+
[K in Chains]?: `0x${string}`;
|
|
2145
|
+
};
|
|
2146
|
+
};
|
|
2147
|
+
type RpcMap = Record<Chains, string>;
|
|
2148
|
+
declare const chainIds: {
|
|
2149
|
+
readonly "EVM-97": 97;
|
|
2150
|
+
readonly "EVM-10200": 10200;
|
|
2151
|
+
readonly "KUSAMA-4009": 4009;
|
|
2152
|
+
readonly "EVM-11155111": 11155111;
|
|
2153
|
+
};
|
|
2154
|
+
type ChainId = typeof chainIds;
|
|
2155
|
+
declare const viemChains: Record<string, Chain>;
|
|
2156
|
+
declare const WrappedNativeDecimals: {
|
|
2157
|
+
"EVM-97": number;
|
|
2158
|
+
"EVM-10200": number;
|
|
2159
|
+
"EVM-11155111": number;
|
|
2160
|
+
};
|
|
2161
|
+
declare const assets: {
|
|
2162
|
+
"EVM-97": {
|
|
2163
|
+
WETH: string;
|
|
2164
|
+
DAI: string;
|
|
2165
|
+
USDC: string;
|
|
2166
|
+
USDT: string;
|
|
2167
|
+
};
|
|
2168
|
+
"EVM-10200": {
|
|
2169
|
+
WETH: string;
|
|
2170
|
+
DAI: string;
|
|
2171
|
+
USDC: string;
|
|
2172
|
+
USDT: string;
|
|
2173
|
+
};
|
|
2174
|
+
"EVM-11155111": {
|
|
2175
|
+
WETH: string;
|
|
2176
|
+
USDC: string;
|
|
2177
|
+
USDT: string;
|
|
2178
|
+
DAI: string;
|
|
2179
|
+
};
|
|
2180
|
+
};
|
|
2181
|
+
declare const addresses: AddressMap;
|
|
2182
|
+
declare const createRpcUrls: (env: NodeJS.ProcessEnv) => RpcMap;
|
|
2183
|
+
declare const consensusStateIds: {
|
|
2184
|
+
"EVM-97": string;
|
|
2185
|
+
"EVM-10200": string;
|
|
2186
|
+
"KUSAMA-4009": string;
|
|
2187
|
+
"EVM-11155111": string;
|
|
2188
|
+
};
|
|
2189
|
+
|
|
2190
|
+
export { ADDRESS_ZERO, AbortSignalInternal, type AllStatusKey, type AssetTeleported, type AssetTeleportedResponse, type BlockMetadata, type CancelOptions, type ChainConfig, ChainConfigService, type ChainId, Chains, type ClientConfig, DEFAULT_ADDRESS, DUMMY_PRIVATE_KEY, type DecodedOrderPlacedLog, type DispatchGet, type DispatchPost, EvmChain, type EvmChainParams, type ExecutionResult, type FillOptions, type FillerConfig, type GetRequestResponse, type GetRequestWithStatus, type GetResponseByRequestIdResponse, type GetResponseStorageValues, type HexString, type HostParams, HyperClientStatus, type HyperbridgeTxEvents, type IChain, type IConfig, type IEvmConfig, type IGetRequest, type IGetRequestMessage, type IGetResponse, type IGetResponseMessage, type IHyperbridgeConfig, type IIsmpMessage, type IMessage, type IPostRequest, type IPostResponse, type IProof, type IRequestMessage, type ISubstrateConfig, type ITimeoutPostRequestMessage, IndexerClient, type IndexerQueryClient, IntentGateway, type IntentGatewayParams, type IsmpRequest, type NewDeployment, type Order, type OrderResponse, OrderStatus, type OrderStatusMetadata, type OrderWithStatus, type Params, type PaymentInfo, type PostRequestStatus, type PostRequestTimeoutStatus, type PostRequestWithStatus, REQUEST_COMMITMENTS_SLOT, REQUEST_RECEIPTS_SLOT, RESPONSE_COMMITMENTS_SLOT, RESPONSE_RECEIPTS_SLOT, type RequestBody, type RequestCommitment, RequestKind, type RequestResponse, RequestStatus, type RequestStatusKey, type RequestStatusWithMetadata, type ResponseCommitmentWithValues, type RetryConfig, STATE_COMMITMENTS_SLOT, type StateMachineHeight, type StateMachineIdParams, type StateMachineResponse, type StateMachineUpdate, SubstrateChain, type SubstrateChainParams, TeleportStatus, TimeoutStatus, type TimeoutStatusKey, type TokenGatewayAssetTeleportedResponse, type TokenGatewayAssetTeleportedWithStatus, type TokenInfo, WrappedNativeDecimals, type XcmGatewayParams, __test, addresses, assets, bytes20ToBytes32, bytes32ToBytes20, chainIds, consensusStateIds, constructRedeemEscrowRequestBody, convertStateMachineIdToEnum, createQueryClient, createRpcUrls, encodeISMPMessage, estimateGasForPost, fetchTokenUsdPrice, generateRootWithProof, getChain, getRequestCommitment, getStateCommitmentFieldSlot, getStateCommitmentSlot, getStorageSlot, hexToString, orderCommitment, postRequestCommitment, queryGetRequest, queryPostRequest, teleport, teleportDot, viemChains };
|