@hyperbridge/sdk 2.2.3 → 2.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2072 @@
1
+ import { encodeAbiParameters, encodeFunctionData, decodeFunctionData, decodeAbiParameters, numberToBytes, bytesToBigInt } from 'viem';
2
+ import '@polkadot/api';
3
+ import { hexToU8a, u8aToHex } from '@polkadot/util';
4
+ import '@polkadot/util-crypto';
5
+ import { Struct, Vector, u8, Bytes } from 'scale-ts';
6
+ import 'p-queue';
7
+
8
+ // src/protocols/intents/decode-utils.ts
9
+
10
+ // src/abis/erc7281.ts
11
+ var ABI = [
12
+ {
13
+ name: "execute",
14
+ type: "function",
15
+ inputs: [
16
+ { name: "mode", type: "bytes32" },
17
+ { name: "executionData", type: "bytes" }
18
+ ],
19
+ outputs: []
20
+ },
21
+ {
22
+ name: "Call",
23
+ type: "tuple",
24
+ components: [
25
+ { name: "target", type: "address" },
26
+ { name: "value", type: "uint256" },
27
+ { name: "data", type: "bytes" }
28
+ ]
29
+ }
30
+ ];
31
+ var erc7281_default = { ABI };
32
+
33
+ // src/protocols/intents/types.ts
34
+ var ERC7821_BATCH_MODE = "0x0100000000000000000000000000000000000000000000000000000000000000";
35
+
36
+ // src/protocols/intents/decode-utils.ts
37
+ function encodeERC7821ExecuteBatch(calls) {
38
+ const executionData = encodeAbiParameters(
39
+ [{ type: "tuple[]", components: erc7281_default.ABI[1].components }],
40
+ [calls.map((call) => ({ target: call.target, value: call.value, data: call.data }))]
41
+ );
42
+ return encodeFunctionData({
43
+ abi: erc7281_default.ABI,
44
+ functionName: "execute",
45
+ args: [ERC7821_BATCH_MODE, executionData]
46
+ });
47
+ }
48
+ function decodeERC7821ExecuteBatch(callData) {
49
+ try {
50
+ const decoded = decodeFunctionData({ abi: erc7281_default.ABI, data: callData });
51
+ if (decoded.functionName !== "execute" || !decoded.args || decoded.args.length < 2) return null;
52
+ const executionData = decoded.args[1];
53
+ const [calls] = decodeAbiParameters(
54
+ [{ type: "tuple[]", components: erc7281_default.ABI[1].components }],
55
+ executionData
56
+ );
57
+ return calls.map((call) => ({
58
+ target: call.target,
59
+ value: call.value,
60
+ data: call.data
61
+ }));
62
+ } catch {
63
+ return null;
64
+ }
65
+ }
66
+
67
+ // src/abis/IntentGatewayV2.ts
68
+ var ABI2 = [
69
+ {
70
+ type: "constructor",
71
+ inputs: [
72
+ {
73
+ name: "admin",
74
+ type: "address",
75
+ internalType: "address"
76
+ }
77
+ ],
78
+ stateMutability: "nonpayable"
79
+ },
80
+ {
81
+ type: "receive",
82
+ stateMutability: "payable"
83
+ },
84
+ {
85
+ type: "function",
86
+ name: "DOMAIN_SEPARATOR",
87
+ inputs: [],
88
+ outputs: [
89
+ {
90
+ name: "",
91
+ type: "bytes32",
92
+ internalType: "bytes32"
93
+ }
94
+ ],
95
+ stateMutability: "view"
96
+ },
97
+ {
98
+ type: "function",
99
+ name: "SELECT_SOLVER_TYPEHASH",
100
+ inputs: [],
101
+ outputs: [
102
+ {
103
+ name: "",
104
+ type: "bytes32",
105
+ internalType: "bytes32"
106
+ }
107
+ ],
108
+ stateMutability: "view"
109
+ },
110
+ {
111
+ type: "function",
112
+ name: "_destinationProtocolFees",
113
+ inputs: [
114
+ {
115
+ name: "",
116
+ type: "bytes32",
117
+ internalType: "bytes32"
118
+ }
119
+ ],
120
+ outputs: [
121
+ {
122
+ name: "",
123
+ type: "uint256",
124
+ internalType: "uint256"
125
+ }
126
+ ],
127
+ stateMutability: "view"
128
+ },
129
+ {
130
+ type: "function",
131
+ name: "_filled",
132
+ inputs: [
133
+ {
134
+ name: "",
135
+ type: "bytes32",
136
+ internalType: "bytes32"
137
+ }
138
+ ],
139
+ outputs: [
140
+ {
141
+ name: "",
142
+ type: "address",
143
+ internalType: "address"
144
+ }
145
+ ],
146
+ stateMutability: "view"
147
+ },
148
+ {
149
+ type: "function",
150
+ name: "_instances",
151
+ inputs: [
152
+ {
153
+ name: "",
154
+ type: "bytes32",
155
+ internalType: "bytes32"
156
+ }
157
+ ],
158
+ outputs: [
159
+ {
160
+ name: "",
161
+ type: "address",
162
+ internalType: "address"
163
+ }
164
+ ],
165
+ stateMutability: "view"
166
+ },
167
+ {
168
+ type: "function",
169
+ name: "_nonce",
170
+ inputs: [],
171
+ outputs: [
172
+ {
173
+ name: "",
174
+ type: "uint256",
175
+ internalType: "uint256"
176
+ }
177
+ ],
178
+ stateMutability: "view"
179
+ },
180
+ {
181
+ type: "function",
182
+ name: "_orders",
183
+ inputs: [
184
+ {
185
+ name: "",
186
+ type: "bytes32",
187
+ internalType: "bytes32"
188
+ },
189
+ {
190
+ name: "",
191
+ type: "address",
192
+ internalType: "address"
193
+ }
194
+ ],
195
+ outputs: [
196
+ {
197
+ name: "",
198
+ type: "uint256",
199
+ internalType: "uint256"
200
+ }
201
+ ],
202
+ stateMutability: "view"
203
+ },
204
+ {
205
+ type: "function",
206
+ name: "_partialFills",
207
+ inputs: [
208
+ {
209
+ name: "",
210
+ type: "bytes32",
211
+ internalType: "bytes32"
212
+ },
213
+ {
214
+ name: "",
215
+ type: "bytes32",
216
+ internalType: "bytes32"
217
+ }
218
+ ],
219
+ outputs: [
220
+ {
221
+ name: "",
222
+ type: "uint256",
223
+ internalType: "uint256"
224
+ }
225
+ ],
226
+ stateMutability: "view"
227
+ },
228
+ {
229
+ type: "function",
230
+ name: "calculateCommitmentSlotHash",
231
+ inputs: [
232
+ {
233
+ name: "commitment",
234
+ type: "bytes32",
235
+ internalType: "bytes32"
236
+ }
237
+ ],
238
+ outputs: [
239
+ {
240
+ name: "",
241
+ type: "bytes",
242
+ internalType: "bytes"
243
+ }
244
+ ],
245
+ stateMutability: "pure"
246
+ },
247
+ {
248
+ type: "function",
249
+ name: "cancelOrder",
250
+ inputs: [
251
+ {
252
+ name: "order",
253
+ type: "tuple",
254
+ internalType: "struct Order",
255
+ components: [
256
+ {
257
+ name: "user",
258
+ type: "bytes32",
259
+ internalType: "bytes32"
260
+ },
261
+ {
262
+ name: "source",
263
+ type: "bytes",
264
+ internalType: "bytes"
265
+ },
266
+ {
267
+ name: "destination",
268
+ type: "bytes",
269
+ internalType: "bytes"
270
+ },
271
+ {
272
+ name: "deadline",
273
+ type: "uint256",
274
+ internalType: "uint256"
275
+ },
276
+ {
277
+ name: "nonce",
278
+ type: "uint256",
279
+ internalType: "uint256"
280
+ },
281
+ {
282
+ name: "fees",
283
+ type: "uint256",
284
+ internalType: "uint256"
285
+ },
286
+ {
287
+ name: "session",
288
+ type: "address",
289
+ internalType: "address"
290
+ },
291
+ {
292
+ name: "predispatch",
293
+ type: "tuple",
294
+ internalType: "struct DispatchInfo",
295
+ components: [
296
+ {
297
+ name: "assets",
298
+ type: "tuple[]",
299
+ internalType: "struct TokenInfo[]",
300
+ components: [
301
+ {
302
+ name: "token",
303
+ type: "bytes32",
304
+ internalType: "bytes32"
305
+ },
306
+ {
307
+ name: "amount",
308
+ type: "uint256",
309
+ internalType: "uint256"
310
+ }
311
+ ]
312
+ },
313
+ {
314
+ name: "call",
315
+ type: "bytes",
316
+ internalType: "bytes"
317
+ }
318
+ ]
319
+ },
320
+ {
321
+ name: "inputs",
322
+ type: "tuple[]",
323
+ internalType: "struct TokenInfo[]",
324
+ components: [
325
+ {
326
+ name: "token",
327
+ type: "bytes32",
328
+ internalType: "bytes32"
329
+ },
330
+ {
331
+ name: "amount",
332
+ type: "uint256",
333
+ internalType: "uint256"
334
+ }
335
+ ]
336
+ },
337
+ {
338
+ name: "output",
339
+ type: "tuple",
340
+ internalType: "struct PaymentInfo",
341
+ components: [
342
+ {
343
+ name: "beneficiary",
344
+ type: "bytes32",
345
+ internalType: "bytes32"
346
+ },
347
+ {
348
+ name: "assets",
349
+ type: "tuple[]",
350
+ internalType: "struct TokenInfo[]",
351
+ components: [
352
+ {
353
+ name: "token",
354
+ type: "bytes32",
355
+ internalType: "bytes32"
356
+ },
357
+ {
358
+ name: "amount",
359
+ type: "uint256",
360
+ internalType: "uint256"
361
+ }
362
+ ]
363
+ },
364
+ {
365
+ name: "call",
366
+ type: "bytes",
367
+ internalType: "bytes"
368
+ }
369
+ ]
370
+ }
371
+ ]
372
+ },
373
+ {
374
+ name: "options",
375
+ type: "tuple",
376
+ internalType: "struct CancelOptions",
377
+ components: [
378
+ {
379
+ name: "relayerFee",
380
+ type: "uint256",
381
+ internalType: "uint256"
382
+ },
383
+ {
384
+ name: "height",
385
+ type: "uint64",
386
+ internalType: "uint64"
387
+ }
388
+ ]
389
+ }
390
+ ],
391
+ outputs: [],
392
+ stateMutability: "payable"
393
+ },
394
+ {
395
+ type: "function",
396
+ name: "eip712Domain",
397
+ inputs: [],
398
+ outputs: [
399
+ {
400
+ name: "fields",
401
+ type: "bytes1",
402
+ internalType: "bytes1"
403
+ },
404
+ {
405
+ name: "name",
406
+ type: "string",
407
+ internalType: "string"
408
+ },
409
+ {
410
+ name: "version",
411
+ type: "string",
412
+ internalType: "string"
413
+ },
414
+ {
415
+ name: "chainId",
416
+ type: "uint256",
417
+ internalType: "uint256"
418
+ },
419
+ {
420
+ name: "verifyingContract",
421
+ type: "address",
422
+ internalType: "address"
423
+ },
424
+ {
425
+ name: "salt",
426
+ type: "bytes32",
427
+ internalType: "bytes32"
428
+ },
429
+ {
430
+ name: "extensions",
431
+ type: "uint256[]",
432
+ internalType: "uint256[]"
433
+ }
434
+ ],
435
+ stateMutability: "view"
436
+ },
437
+ {
438
+ type: "function",
439
+ name: "fillOrder",
440
+ inputs: [
441
+ {
442
+ name: "order",
443
+ type: "tuple",
444
+ internalType: "struct Order",
445
+ components: [
446
+ {
447
+ name: "user",
448
+ type: "bytes32",
449
+ internalType: "bytes32"
450
+ },
451
+ {
452
+ name: "source",
453
+ type: "bytes",
454
+ internalType: "bytes"
455
+ },
456
+ {
457
+ name: "destination",
458
+ type: "bytes",
459
+ internalType: "bytes"
460
+ },
461
+ {
462
+ name: "deadline",
463
+ type: "uint256",
464
+ internalType: "uint256"
465
+ },
466
+ {
467
+ name: "nonce",
468
+ type: "uint256",
469
+ internalType: "uint256"
470
+ },
471
+ {
472
+ name: "fees",
473
+ type: "uint256",
474
+ internalType: "uint256"
475
+ },
476
+ {
477
+ name: "session",
478
+ type: "address",
479
+ internalType: "address"
480
+ },
481
+ {
482
+ name: "predispatch",
483
+ type: "tuple",
484
+ internalType: "struct DispatchInfo",
485
+ components: [
486
+ {
487
+ name: "assets",
488
+ type: "tuple[]",
489
+ internalType: "struct TokenInfo[]",
490
+ components: [
491
+ {
492
+ name: "token",
493
+ type: "bytes32",
494
+ internalType: "bytes32"
495
+ },
496
+ {
497
+ name: "amount",
498
+ type: "uint256",
499
+ internalType: "uint256"
500
+ }
501
+ ]
502
+ },
503
+ {
504
+ name: "call",
505
+ type: "bytes",
506
+ internalType: "bytes"
507
+ }
508
+ ]
509
+ },
510
+ {
511
+ name: "inputs",
512
+ type: "tuple[]",
513
+ internalType: "struct TokenInfo[]",
514
+ components: [
515
+ {
516
+ name: "token",
517
+ type: "bytes32",
518
+ internalType: "bytes32"
519
+ },
520
+ {
521
+ name: "amount",
522
+ type: "uint256",
523
+ internalType: "uint256"
524
+ }
525
+ ]
526
+ },
527
+ {
528
+ name: "output",
529
+ type: "tuple",
530
+ internalType: "struct PaymentInfo",
531
+ components: [
532
+ {
533
+ name: "beneficiary",
534
+ type: "bytes32",
535
+ internalType: "bytes32"
536
+ },
537
+ {
538
+ name: "assets",
539
+ type: "tuple[]",
540
+ internalType: "struct TokenInfo[]",
541
+ components: [
542
+ {
543
+ name: "token",
544
+ type: "bytes32",
545
+ internalType: "bytes32"
546
+ },
547
+ {
548
+ name: "amount",
549
+ type: "uint256",
550
+ internalType: "uint256"
551
+ }
552
+ ]
553
+ },
554
+ {
555
+ name: "call",
556
+ type: "bytes",
557
+ internalType: "bytes"
558
+ }
559
+ ]
560
+ }
561
+ ]
562
+ },
563
+ {
564
+ name: "options",
565
+ type: "tuple",
566
+ internalType: "struct FillOptions",
567
+ components: [
568
+ {
569
+ name: "relayerFee",
570
+ type: "uint256",
571
+ internalType: "uint256"
572
+ },
573
+ {
574
+ name: "nativeDispatchFee",
575
+ type: "uint256",
576
+ internalType: "uint256"
577
+ },
578
+ {
579
+ name: "outputs",
580
+ type: "tuple[]",
581
+ internalType: "struct TokenInfo[]",
582
+ components: [
583
+ {
584
+ name: "token",
585
+ type: "bytes32",
586
+ internalType: "bytes32"
587
+ },
588
+ {
589
+ name: "amount",
590
+ type: "uint256",
591
+ internalType: "uint256"
592
+ }
593
+ ]
594
+ }
595
+ ]
596
+ }
597
+ ],
598
+ outputs: [],
599
+ stateMutability: "payable"
600
+ },
601
+ {
602
+ type: "function",
603
+ name: "host",
604
+ inputs: [],
605
+ outputs: [
606
+ {
607
+ name: "",
608
+ type: "address",
609
+ internalType: "address"
610
+ }
611
+ ],
612
+ stateMutability: "view"
613
+ },
614
+ {
615
+ type: "function",
616
+ name: "instance",
617
+ inputs: [
618
+ {
619
+ name: "stateMachineId",
620
+ type: "bytes",
621
+ internalType: "bytes"
622
+ }
623
+ ],
624
+ outputs: [
625
+ {
626
+ name: "",
627
+ type: "address",
628
+ internalType: "address"
629
+ }
630
+ ],
631
+ stateMutability: "view"
632
+ },
633
+ {
634
+ type: "function",
635
+ name: "onAccept",
636
+ inputs: [
637
+ {
638
+ name: "incoming",
639
+ type: "tuple",
640
+ internalType: "struct IncomingPostRequest",
641
+ components: [
642
+ {
643
+ name: "request",
644
+ type: "tuple",
645
+ internalType: "struct PostRequest",
646
+ components: [
647
+ {
648
+ name: "source",
649
+ type: "bytes",
650
+ internalType: "bytes"
651
+ },
652
+ {
653
+ name: "dest",
654
+ type: "bytes",
655
+ internalType: "bytes"
656
+ },
657
+ {
658
+ name: "nonce",
659
+ type: "uint64",
660
+ internalType: "uint64"
661
+ },
662
+ {
663
+ name: "from",
664
+ type: "bytes",
665
+ internalType: "bytes"
666
+ },
667
+ {
668
+ name: "to",
669
+ type: "bytes",
670
+ internalType: "bytes"
671
+ },
672
+ {
673
+ name: "timeoutTimestamp",
674
+ type: "uint64",
675
+ internalType: "uint64"
676
+ },
677
+ {
678
+ name: "body",
679
+ type: "bytes",
680
+ internalType: "bytes"
681
+ }
682
+ ]
683
+ },
684
+ {
685
+ name: "relayer",
686
+ type: "address",
687
+ internalType: "address"
688
+ }
689
+ ]
690
+ }
691
+ ],
692
+ outputs: [],
693
+ stateMutability: "nonpayable"
694
+ },
695
+ {
696
+ type: "function",
697
+ name: "onGetResponse",
698
+ inputs: [
699
+ {
700
+ name: "incoming",
701
+ type: "tuple",
702
+ internalType: "struct IncomingGetResponse",
703
+ components: [
704
+ {
705
+ name: "response",
706
+ type: "tuple",
707
+ internalType: "struct GetResponse",
708
+ components: [
709
+ {
710
+ name: "request",
711
+ type: "tuple",
712
+ internalType: "struct GetRequest",
713
+ components: [
714
+ {
715
+ name: "source",
716
+ type: "bytes",
717
+ internalType: "bytes"
718
+ },
719
+ {
720
+ name: "dest",
721
+ type: "bytes",
722
+ internalType: "bytes"
723
+ },
724
+ {
725
+ name: "nonce",
726
+ type: "uint64",
727
+ internalType: "uint64"
728
+ },
729
+ {
730
+ name: "from",
731
+ type: "bytes",
732
+ internalType: "bytes"
733
+ },
734
+ {
735
+ name: "timeoutTimestamp",
736
+ type: "uint64",
737
+ internalType: "uint64"
738
+ },
739
+ {
740
+ name: "keys",
741
+ type: "bytes[]",
742
+ internalType: "bytes[]"
743
+ },
744
+ {
745
+ name: "height",
746
+ type: "uint64",
747
+ internalType: "uint64"
748
+ },
749
+ {
750
+ name: "context",
751
+ type: "bytes",
752
+ internalType: "bytes"
753
+ }
754
+ ]
755
+ },
756
+ {
757
+ name: "values",
758
+ type: "tuple[]",
759
+ internalType: "struct StorageValue[]",
760
+ components: [
761
+ {
762
+ name: "key",
763
+ type: "bytes",
764
+ internalType: "bytes"
765
+ },
766
+ {
767
+ name: "value",
768
+ type: "bytes",
769
+ internalType: "bytes"
770
+ }
771
+ ]
772
+ }
773
+ ]
774
+ },
775
+ {
776
+ name: "relayer",
777
+ type: "address",
778
+ internalType: "address"
779
+ }
780
+ ]
781
+ }
782
+ ],
783
+ outputs: [],
784
+ stateMutability: "nonpayable"
785
+ },
786
+ {
787
+ type: "function",
788
+ name: "onGetTimeout",
789
+ inputs: [
790
+ {
791
+ name: "",
792
+ type: "tuple",
793
+ internalType: "struct GetRequestTimeout",
794
+ components: [
795
+ {
796
+ name: "request",
797
+ type: "tuple",
798
+ internalType: "struct GetRequest",
799
+ components: [
800
+ {
801
+ name: "source",
802
+ type: "bytes",
803
+ internalType: "bytes"
804
+ },
805
+ {
806
+ name: "dest",
807
+ type: "bytes",
808
+ internalType: "bytes"
809
+ },
810
+ {
811
+ name: "nonce",
812
+ type: "uint64",
813
+ internalType: "uint64"
814
+ },
815
+ {
816
+ name: "from",
817
+ type: "bytes",
818
+ internalType: "bytes"
819
+ },
820
+ {
821
+ name: "timeoutTimestamp",
822
+ type: "uint64",
823
+ internalType: "uint64"
824
+ },
825
+ {
826
+ name: "keys",
827
+ type: "bytes[]",
828
+ internalType: "bytes[]"
829
+ },
830
+ {
831
+ name: "height",
832
+ type: "uint64",
833
+ internalType: "uint64"
834
+ },
835
+ {
836
+ name: "context",
837
+ type: "bytes",
838
+ internalType: "bytes"
839
+ }
840
+ ]
841
+ },
842
+ {
843
+ name: "relayer",
844
+ type: "address",
845
+ internalType: "address"
846
+ }
847
+ ]
848
+ }
849
+ ],
850
+ outputs: [],
851
+ stateMutability: "nonpayable"
852
+ },
853
+ {
854
+ type: "function",
855
+ name: "onPostRequestTimeout",
856
+ inputs: [
857
+ {
858
+ name: "",
859
+ type: "tuple",
860
+ internalType: "struct PostRequestTimeout",
861
+ components: [
862
+ {
863
+ name: "request",
864
+ type: "tuple",
865
+ internalType: "struct PostRequest",
866
+ components: [
867
+ {
868
+ name: "source",
869
+ type: "bytes",
870
+ internalType: "bytes"
871
+ },
872
+ {
873
+ name: "dest",
874
+ type: "bytes",
875
+ internalType: "bytes"
876
+ },
877
+ {
878
+ name: "nonce",
879
+ type: "uint64",
880
+ internalType: "uint64"
881
+ },
882
+ {
883
+ name: "from",
884
+ type: "bytes",
885
+ internalType: "bytes"
886
+ },
887
+ {
888
+ name: "to",
889
+ type: "bytes",
890
+ internalType: "bytes"
891
+ },
892
+ {
893
+ name: "timeoutTimestamp",
894
+ type: "uint64",
895
+ internalType: "uint64"
896
+ },
897
+ {
898
+ name: "body",
899
+ type: "bytes",
900
+ internalType: "bytes"
901
+ }
902
+ ]
903
+ },
904
+ {
905
+ name: "relayer",
906
+ type: "address",
907
+ internalType: "address"
908
+ }
909
+ ]
910
+ }
911
+ ],
912
+ outputs: [],
913
+ stateMutability: "nonpayable"
914
+ },
915
+ {
916
+ type: "function",
917
+ name: "params",
918
+ inputs: [],
919
+ outputs: [
920
+ {
921
+ name: "",
922
+ type: "tuple",
923
+ internalType: "struct Params",
924
+ components: [
925
+ {
926
+ name: "host",
927
+ type: "address",
928
+ internalType: "address"
929
+ },
930
+ {
931
+ name: "dispatcher",
932
+ type: "address",
933
+ internalType: "address"
934
+ },
935
+ {
936
+ name: "solverSelection",
937
+ type: "bool",
938
+ internalType: "bool"
939
+ },
940
+ {
941
+ name: "surplusShareBps",
942
+ type: "uint256",
943
+ internalType: "uint256"
944
+ },
945
+ {
946
+ name: "protocolFeeBps",
947
+ type: "uint256",
948
+ internalType: "uint256"
949
+ },
950
+ {
951
+ name: "priceOracle",
952
+ type: "address",
953
+ internalType: "address"
954
+ }
955
+ ]
956
+ }
957
+ ],
958
+ stateMutability: "view"
959
+ },
960
+ {
961
+ type: "function",
962
+ name: "placeOrder",
963
+ inputs: [
964
+ {
965
+ name: "order",
966
+ type: "tuple",
967
+ internalType: "struct Order",
968
+ components: [
969
+ {
970
+ name: "user",
971
+ type: "bytes32",
972
+ internalType: "bytes32"
973
+ },
974
+ {
975
+ name: "source",
976
+ type: "bytes",
977
+ internalType: "bytes"
978
+ },
979
+ {
980
+ name: "destination",
981
+ type: "bytes",
982
+ internalType: "bytes"
983
+ },
984
+ {
985
+ name: "deadline",
986
+ type: "uint256",
987
+ internalType: "uint256"
988
+ },
989
+ {
990
+ name: "nonce",
991
+ type: "uint256",
992
+ internalType: "uint256"
993
+ },
994
+ {
995
+ name: "fees",
996
+ type: "uint256",
997
+ internalType: "uint256"
998
+ },
999
+ {
1000
+ name: "session",
1001
+ type: "address",
1002
+ internalType: "address"
1003
+ },
1004
+ {
1005
+ name: "predispatch",
1006
+ type: "tuple",
1007
+ internalType: "struct DispatchInfo",
1008
+ components: [
1009
+ {
1010
+ name: "assets",
1011
+ type: "tuple[]",
1012
+ internalType: "struct TokenInfo[]",
1013
+ components: [
1014
+ {
1015
+ name: "token",
1016
+ type: "bytes32",
1017
+ internalType: "bytes32"
1018
+ },
1019
+ {
1020
+ name: "amount",
1021
+ type: "uint256",
1022
+ internalType: "uint256"
1023
+ }
1024
+ ]
1025
+ },
1026
+ {
1027
+ name: "call",
1028
+ type: "bytes",
1029
+ internalType: "bytes"
1030
+ }
1031
+ ]
1032
+ },
1033
+ {
1034
+ name: "inputs",
1035
+ type: "tuple[]",
1036
+ internalType: "struct TokenInfo[]",
1037
+ components: [
1038
+ {
1039
+ name: "token",
1040
+ type: "bytes32",
1041
+ internalType: "bytes32"
1042
+ },
1043
+ {
1044
+ name: "amount",
1045
+ type: "uint256",
1046
+ internalType: "uint256"
1047
+ }
1048
+ ]
1049
+ },
1050
+ {
1051
+ name: "output",
1052
+ type: "tuple",
1053
+ internalType: "struct PaymentInfo",
1054
+ components: [
1055
+ {
1056
+ name: "beneficiary",
1057
+ type: "bytes32",
1058
+ internalType: "bytes32"
1059
+ },
1060
+ {
1061
+ name: "assets",
1062
+ type: "tuple[]",
1063
+ internalType: "struct TokenInfo[]",
1064
+ components: [
1065
+ {
1066
+ name: "token",
1067
+ type: "bytes32",
1068
+ internalType: "bytes32"
1069
+ },
1070
+ {
1071
+ name: "amount",
1072
+ type: "uint256",
1073
+ internalType: "uint256"
1074
+ }
1075
+ ]
1076
+ },
1077
+ {
1078
+ name: "call",
1079
+ type: "bytes",
1080
+ internalType: "bytes"
1081
+ }
1082
+ ]
1083
+ }
1084
+ ]
1085
+ },
1086
+ {
1087
+ name: "graffiti",
1088
+ type: "bytes32",
1089
+ internalType: "bytes32"
1090
+ }
1091
+ ],
1092
+ outputs: [],
1093
+ stateMutability: "payable"
1094
+ },
1095
+ {
1096
+ type: "function",
1097
+ name: "quote",
1098
+ inputs: [
1099
+ {
1100
+ name: "request",
1101
+ type: "tuple",
1102
+ internalType: "struct DispatchPost",
1103
+ components: [
1104
+ {
1105
+ name: "dest",
1106
+ type: "bytes",
1107
+ internalType: "bytes"
1108
+ },
1109
+ {
1110
+ name: "to",
1111
+ type: "bytes",
1112
+ internalType: "bytes"
1113
+ },
1114
+ {
1115
+ name: "body",
1116
+ type: "bytes",
1117
+ internalType: "bytes"
1118
+ },
1119
+ {
1120
+ name: "timeout",
1121
+ type: "uint64",
1122
+ internalType: "uint64"
1123
+ },
1124
+ {
1125
+ name: "fee",
1126
+ type: "uint256",
1127
+ internalType: "uint256"
1128
+ },
1129
+ {
1130
+ name: "payer",
1131
+ type: "address",
1132
+ internalType: "address"
1133
+ }
1134
+ ]
1135
+ }
1136
+ ],
1137
+ outputs: [
1138
+ {
1139
+ name: "",
1140
+ type: "uint256",
1141
+ internalType: "uint256"
1142
+ }
1143
+ ],
1144
+ stateMutability: "view"
1145
+ },
1146
+ {
1147
+ type: "function",
1148
+ name: "quote",
1149
+ inputs: [
1150
+ {
1151
+ name: "request",
1152
+ type: "tuple",
1153
+ internalType: "struct DispatchGet",
1154
+ components: [
1155
+ {
1156
+ name: "dest",
1157
+ type: "bytes",
1158
+ internalType: "bytes"
1159
+ },
1160
+ {
1161
+ name: "height",
1162
+ type: "uint64",
1163
+ internalType: "uint64"
1164
+ },
1165
+ {
1166
+ name: "keys",
1167
+ type: "bytes[]",
1168
+ internalType: "bytes[]"
1169
+ },
1170
+ {
1171
+ name: "timeout",
1172
+ type: "uint64",
1173
+ internalType: "uint64"
1174
+ },
1175
+ {
1176
+ name: "fee",
1177
+ type: "uint256",
1178
+ internalType: "uint256"
1179
+ },
1180
+ {
1181
+ name: "context",
1182
+ type: "bytes",
1183
+ internalType: "bytes"
1184
+ },
1185
+ {
1186
+ name: "payer",
1187
+ type: "address",
1188
+ internalType: "address"
1189
+ }
1190
+ ]
1191
+ }
1192
+ ],
1193
+ outputs: [
1194
+ {
1195
+ name: "",
1196
+ type: "uint256",
1197
+ internalType: "uint256"
1198
+ }
1199
+ ],
1200
+ stateMutability: "view"
1201
+ },
1202
+ {
1203
+ type: "function",
1204
+ name: "select",
1205
+ inputs: [
1206
+ {
1207
+ name: "options",
1208
+ type: "tuple",
1209
+ internalType: "struct SelectOptions",
1210
+ components: [
1211
+ {
1212
+ name: "commitment",
1213
+ type: "bytes32",
1214
+ internalType: "bytes32"
1215
+ },
1216
+ {
1217
+ name: "solver",
1218
+ type: "address",
1219
+ internalType: "address"
1220
+ },
1221
+ {
1222
+ name: "signature",
1223
+ type: "bytes",
1224
+ internalType: "bytes"
1225
+ }
1226
+ ]
1227
+ }
1228
+ ],
1229
+ outputs: [
1230
+ {
1231
+ name: "",
1232
+ type: "address",
1233
+ internalType: "address"
1234
+ }
1235
+ ],
1236
+ stateMutability: "nonpayable"
1237
+ },
1238
+ {
1239
+ type: "function",
1240
+ name: "init",
1241
+ inputs: [
1242
+ {
1243
+ name: "p",
1244
+ type: "tuple",
1245
+ internalType: "struct Params",
1246
+ components: [
1247
+ {
1248
+ name: "host",
1249
+ type: "address",
1250
+ internalType: "address"
1251
+ },
1252
+ {
1253
+ name: "dispatcher",
1254
+ type: "address",
1255
+ internalType: "address"
1256
+ },
1257
+ {
1258
+ name: "solverSelection",
1259
+ type: "bool",
1260
+ internalType: "bool"
1261
+ },
1262
+ {
1263
+ name: "surplusShareBps",
1264
+ type: "uint256",
1265
+ internalType: "uint256"
1266
+ },
1267
+ {
1268
+ name: "protocolFeeBps",
1269
+ type: "uint256",
1270
+ internalType: "uint256"
1271
+ },
1272
+ {
1273
+ name: "priceOracle",
1274
+ type: "address",
1275
+ internalType: "address"
1276
+ }
1277
+ ]
1278
+ },
1279
+ {
1280
+ name: "deployments",
1281
+ type: "tuple[]",
1282
+ internalType: "struct Deployment[]",
1283
+ components: [
1284
+ {
1285
+ name: "chain",
1286
+ type: "bytes",
1287
+ internalType: "bytes"
1288
+ },
1289
+ {
1290
+ name: "gateway",
1291
+ type: "address",
1292
+ internalType: "address"
1293
+ }
1294
+ ]
1295
+ }
1296
+ ],
1297
+ outputs: [],
1298
+ stateMutability: "nonpayable"
1299
+ },
1300
+ {
1301
+ type: "event",
1302
+ name: "DestinationProtocolFeeUpdated",
1303
+ inputs: [
1304
+ {
1305
+ name: "chain",
1306
+ type: "string",
1307
+ indexed: false,
1308
+ internalType: "string"
1309
+ },
1310
+ {
1311
+ name: "feeBps",
1312
+ type: "uint256",
1313
+ indexed: false,
1314
+ internalType: "uint256"
1315
+ }
1316
+ ],
1317
+ anonymous: false
1318
+ },
1319
+ {
1320
+ type: "event",
1321
+ name: "DustCollected",
1322
+ inputs: [
1323
+ {
1324
+ name: "token",
1325
+ type: "address",
1326
+ indexed: false,
1327
+ internalType: "address"
1328
+ },
1329
+ {
1330
+ name: "amount",
1331
+ type: "uint256",
1332
+ indexed: false,
1333
+ internalType: "uint256"
1334
+ }
1335
+ ],
1336
+ anonymous: false
1337
+ },
1338
+ {
1339
+ type: "event",
1340
+ name: "DustSwept",
1341
+ inputs: [
1342
+ {
1343
+ name: "token",
1344
+ type: "address",
1345
+ indexed: false,
1346
+ internalType: "address"
1347
+ },
1348
+ {
1349
+ name: "amount",
1350
+ type: "uint256",
1351
+ indexed: false,
1352
+ internalType: "uint256"
1353
+ },
1354
+ {
1355
+ name: "beneficiary",
1356
+ type: "address",
1357
+ indexed: false,
1358
+ internalType: "address"
1359
+ }
1360
+ ],
1361
+ anonymous: false
1362
+ },
1363
+ {
1364
+ type: "event",
1365
+ name: "EIP712DomainChanged",
1366
+ inputs: [],
1367
+ anonymous: false
1368
+ },
1369
+ {
1370
+ type: "event",
1371
+ name: "EscrowRefunded",
1372
+ inputs: [
1373
+ {
1374
+ name: "commitment",
1375
+ type: "bytes32",
1376
+ indexed: true,
1377
+ internalType: "bytes32"
1378
+ },
1379
+ {
1380
+ name: "tokens",
1381
+ type: "tuple[]",
1382
+ indexed: false,
1383
+ internalType: "struct TokenInfo[]",
1384
+ components: [
1385
+ {
1386
+ name: "token",
1387
+ type: "bytes32",
1388
+ internalType: "bytes32"
1389
+ },
1390
+ {
1391
+ name: "amount",
1392
+ type: "uint256",
1393
+ internalType: "uint256"
1394
+ }
1395
+ ]
1396
+ }
1397
+ ],
1398
+ anonymous: false
1399
+ },
1400
+ {
1401
+ type: "event",
1402
+ name: "EscrowReleased",
1403
+ inputs: [
1404
+ {
1405
+ name: "commitment",
1406
+ type: "bytes32",
1407
+ indexed: true,
1408
+ internalType: "bytes32"
1409
+ },
1410
+ {
1411
+ name: "tokens",
1412
+ type: "tuple[]",
1413
+ indexed: false,
1414
+ internalType: "struct TokenInfo[]",
1415
+ components: [
1416
+ {
1417
+ name: "token",
1418
+ type: "bytes32",
1419
+ internalType: "bytes32"
1420
+ },
1421
+ {
1422
+ name: "amount",
1423
+ type: "uint256",
1424
+ internalType: "uint256"
1425
+ }
1426
+ ]
1427
+ }
1428
+ ],
1429
+ anonymous: false
1430
+ },
1431
+ {
1432
+ type: "event",
1433
+ name: "DeploymentAdded",
1434
+ inputs: [
1435
+ {
1436
+ name: "chain",
1437
+ type: "string",
1438
+ indexed: false,
1439
+ internalType: "string"
1440
+ },
1441
+ {
1442
+ name: "gateway",
1443
+ type: "address",
1444
+ indexed: false,
1445
+ internalType: "address"
1446
+ }
1447
+ ],
1448
+ anonymous: false
1449
+ },
1450
+ {
1451
+ type: "event",
1452
+ name: "OrderFilled",
1453
+ inputs: [
1454
+ {
1455
+ name: "commitment",
1456
+ type: "bytes32",
1457
+ indexed: true,
1458
+ internalType: "bytes32"
1459
+ },
1460
+ {
1461
+ name: "filler",
1462
+ type: "address",
1463
+ indexed: false,
1464
+ internalType: "address"
1465
+ },
1466
+ {
1467
+ name: "outputs",
1468
+ type: "tuple[]",
1469
+ indexed: false,
1470
+ internalType: "struct TokenInfo[]",
1471
+ components: [
1472
+ {
1473
+ name: "token",
1474
+ type: "bytes32",
1475
+ internalType: "bytes32"
1476
+ },
1477
+ {
1478
+ name: "amount",
1479
+ type: "uint256",
1480
+ internalType: "uint256"
1481
+ }
1482
+ ]
1483
+ },
1484
+ {
1485
+ name: "inputs",
1486
+ type: "tuple[]",
1487
+ indexed: false,
1488
+ internalType: "struct TokenInfo[]",
1489
+ components: [
1490
+ {
1491
+ name: "token",
1492
+ type: "bytes32",
1493
+ internalType: "bytes32"
1494
+ },
1495
+ {
1496
+ name: "amount",
1497
+ type: "uint256",
1498
+ internalType: "uint256"
1499
+ }
1500
+ ]
1501
+ }
1502
+ ],
1503
+ anonymous: false
1504
+ },
1505
+ {
1506
+ type: "event",
1507
+ name: "OrderPlaced",
1508
+ inputs: [
1509
+ {
1510
+ name: "user",
1511
+ type: "bytes32",
1512
+ indexed: false,
1513
+ internalType: "bytes32"
1514
+ },
1515
+ {
1516
+ name: "source",
1517
+ type: "string",
1518
+ indexed: false,
1519
+ internalType: "string"
1520
+ },
1521
+ {
1522
+ name: "destination",
1523
+ type: "string",
1524
+ indexed: false,
1525
+ internalType: "string"
1526
+ },
1527
+ {
1528
+ name: "deadline",
1529
+ type: "uint256",
1530
+ indexed: false,
1531
+ internalType: "uint256"
1532
+ },
1533
+ {
1534
+ name: "nonce",
1535
+ type: "uint256",
1536
+ indexed: false,
1537
+ internalType: "uint256"
1538
+ },
1539
+ {
1540
+ name: "fees",
1541
+ type: "uint256",
1542
+ indexed: false,
1543
+ internalType: "uint256"
1544
+ },
1545
+ {
1546
+ name: "session",
1547
+ type: "address",
1548
+ indexed: false,
1549
+ internalType: "address"
1550
+ },
1551
+ {
1552
+ name: "beneficiary",
1553
+ type: "bytes32",
1554
+ indexed: false,
1555
+ internalType: "bytes32"
1556
+ },
1557
+ {
1558
+ name: "predispatch",
1559
+ type: "tuple[]",
1560
+ indexed: false,
1561
+ internalType: "struct TokenInfo[]",
1562
+ components: [
1563
+ {
1564
+ name: "token",
1565
+ type: "bytes32",
1566
+ internalType: "bytes32"
1567
+ },
1568
+ {
1569
+ name: "amount",
1570
+ type: "uint256",
1571
+ internalType: "uint256"
1572
+ }
1573
+ ]
1574
+ },
1575
+ {
1576
+ name: "inputs",
1577
+ type: "tuple[]",
1578
+ indexed: false,
1579
+ internalType: "struct TokenInfo[]",
1580
+ components: [
1581
+ {
1582
+ name: "token",
1583
+ type: "bytes32",
1584
+ internalType: "bytes32"
1585
+ },
1586
+ {
1587
+ name: "amount",
1588
+ type: "uint256",
1589
+ internalType: "uint256"
1590
+ }
1591
+ ]
1592
+ },
1593
+ {
1594
+ name: "outputs",
1595
+ type: "tuple[]",
1596
+ indexed: false,
1597
+ internalType: "struct TokenInfo[]",
1598
+ components: [
1599
+ {
1600
+ name: "token",
1601
+ type: "bytes32",
1602
+ internalType: "bytes32"
1603
+ },
1604
+ {
1605
+ name: "amount",
1606
+ type: "uint256",
1607
+ internalType: "uint256"
1608
+ }
1609
+ ]
1610
+ }
1611
+ ],
1612
+ anonymous: false
1613
+ },
1614
+ {
1615
+ type: "event",
1616
+ name: "ParamsUpdated",
1617
+ inputs: [
1618
+ {
1619
+ name: "previous",
1620
+ type: "tuple",
1621
+ indexed: false,
1622
+ internalType: "struct Params",
1623
+ components: [
1624
+ {
1625
+ name: "host",
1626
+ type: "address",
1627
+ internalType: "address"
1628
+ },
1629
+ {
1630
+ name: "dispatcher",
1631
+ type: "address",
1632
+ internalType: "address"
1633
+ },
1634
+ {
1635
+ name: "solverSelection",
1636
+ type: "bool",
1637
+ internalType: "bool"
1638
+ },
1639
+ {
1640
+ name: "surplusShareBps",
1641
+ type: "uint256",
1642
+ internalType: "uint256"
1643
+ },
1644
+ {
1645
+ name: "protocolFeeBps",
1646
+ type: "uint256",
1647
+ internalType: "uint256"
1648
+ },
1649
+ {
1650
+ name: "priceOracle",
1651
+ type: "address",
1652
+ internalType: "address"
1653
+ }
1654
+ ]
1655
+ },
1656
+ {
1657
+ name: "current",
1658
+ type: "tuple",
1659
+ indexed: false,
1660
+ internalType: "struct Params",
1661
+ components: [
1662
+ {
1663
+ name: "host",
1664
+ type: "address",
1665
+ internalType: "address"
1666
+ },
1667
+ {
1668
+ name: "dispatcher",
1669
+ type: "address",
1670
+ internalType: "address"
1671
+ },
1672
+ {
1673
+ name: "solverSelection",
1674
+ type: "bool",
1675
+ internalType: "bool"
1676
+ },
1677
+ {
1678
+ name: "surplusShareBps",
1679
+ type: "uint256",
1680
+ internalType: "uint256"
1681
+ },
1682
+ {
1683
+ name: "protocolFeeBps",
1684
+ type: "uint256",
1685
+ internalType: "uint256"
1686
+ },
1687
+ {
1688
+ name: "priceOracle",
1689
+ type: "address",
1690
+ internalType: "address"
1691
+ }
1692
+ ]
1693
+ }
1694
+ ],
1695
+ anonymous: false
1696
+ },
1697
+ {
1698
+ type: "event",
1699
+ name: "PartialFill",
1700
+ inputs: [
1701
+ {
1702
+ name: "commitment",
1703
+ type: "bytes32",
1704
+ indexed: true,
1705
+ internalType: "bytes32"
1706
+ },
1707
+ {
1708
+ name: "filler",
1709
+ type: "address",
1710
+ indexed: false,
1711
+ internalType: "address"
1712
+ },
1713
+ {
1714
+ name: "outputs",
1715
+ type: "tuple[]",
1716
+ indexed: false,
1717
+ internalType: "struct TokenInfo[]",
1718
+ components: [
1719
+ {
1720
+ name: "token",
1721
+ type: "bytes32",
1722
+ internalType: "bytes32"
1723
+ },
1724
+ {
1725
+ name: "amount",
1726
+ type: "uint256",
1727
+ internalType: "uint256"
1728
+ }
1729
+ ]
1730
+ },
1731
+ {
1732
+ name: "inputs",
1733
+ type: "tuple[]",
1734
+ indexed: false,
1735
+ internalType: "struct TokenInfo[]",
1736
+ components: [
1737
+ {
1738
+ name: "token",
1739
+ type: "bytes32",
1740
+ internalType: "bytes32"
1741
+ },
1742
+ {
1743
+ name: "amount",
1744
+ type: "uint256",
1745
+ internalType: "uint256"
1746
+ }
1747
+ ]
1748
+ }
1749
+ ],
1750
+ anonymous: false
1751
+ },
1752
+ {
1753
+ type: "error",
1754
+ name: "Cancelled",
1755
+ inputs: []
1756
+ },
1757
+ {
1758
+ type: "error",
1759
+ name: "UnknownInstance",
1760
+ inputs: []
1761
+ },
1762
+ {
1763
+ type: "error",
1764
+ name: "ECDSAInvalidSignature",
1765
+ inputs: []
1766
+ },
1767
+ {
1768
+ type: "error",
1769
+ name: "ECDSAInvalidSignatureLength",
1770
+ inputs: [
1771
+ {
1772
+ name: "length",
1773
+ type: "uint256",
1774
+ internalType: "uint256"
1775
+ }
1776
+ ]
1777
+ },
1778
+ {
1779
+ type: "error",
1780
+ name: "ECDSAInvalidSignatureS",
1781
+ inputs: [
1782
+ {
1783
+ name: "s",
1784
+ type: "bytes32",
1785
+ internalType: "bytes32"
1786
+ }
1787
+ ]
1788
+ },
1789
+ {
1790
+ type: "error",
1791
+ name: "Expired",
1792
+ inputs: []
1793
+ },
1794
+ {
1795
+ type: "error",
1796
+ name: "Filled",
1797
+ inputs: []
1798
+ },
1799
+ {
1800
+ type: "error",
1801
+ name: "InsufficientNativeToken",
1802
+ inputs: []
1803
+ },
1804
+ {
1805
+ type: "error",
1806
+ name: "InvalidInput",
1807
+ inputs: []
1808
+ },
1809
+ {
1810
+ type: "error",
1811
+ name: "InvalidShortString",
1812
+ inputs: []
1813
+ },
1814
+ {
1815
+ type: "error",
1816
+ name: "NotExpired",
1817
+ inputs: []
1818
+ },
1819
+ {
1820
+ type: "error",
1821
+ name: "SafeERC20FailedOperation",
1822
+ inputs: [
1823
+ {
1824
+ name: "token",
1825
+ type: "address",
1826
+ internalType: "address"
1827
+ }
1828
+ ]
1829
+ },
1830
+ {
1831
+ type: "error",
1832
+ name: "StringTooLong",
1833
+ inputs: [
1834
+ {
1835
+ name: "str",
1836
+ type: "string",
1837
+ internalType: "string"
1838
+ }
1839
+ ]
1840
+ },
1841
+ {
1842
+ type: "error",
1843
+ name: "Unauthorized",
1844
+ inputs: []
1845
+ },
1846
+ {
1847
+ type: "error",
1848
+ name: "UnauthorizedCall",
1849
+ inputs: []
1850
+ },
1851
+ {
1852
+ type: "error",
1853
+ name: "UnexpectedCall",
1854
+ inputs: []
1855
+ },
1856
+ {
1857
+ type: "error",
1858
+ name: "UnknownOrder",
1859
+ inputs: []
1860
+ },
1861
+ {
1862
+ type: "error",
1863
+ name: "WrongChain",
1864
+ inputs: []
1865
+ }
1866
+ ];
1867
+ var IntentGatewayV2_default = { ABI: ABI2 };
1868
+
1869
+ // src/chains/intentsCoprocessor.ts
1870
+ new TextEncoder().encode("intents::bid::");
1871
+ new TextEncoder().encode("intents::phantom::order::");
1872
+ Struct({ filler: Bytes(32), user_op: Vector(u8) });
1873
+ var PackedUserOperationCodec = Struct({
1874
+ sender: Bytes(20),
1875
+ // address is 20 bytes
1876
+ nonce: Bytes(32),
1877
+ // uint256 as 32 bytes
1878
+ initCode: Vector(u8),
1879
+ // variable length bytes
1880
+ callData: Vector(u8),
1881
+ // variable length bytes
1882
+ accountGasLimits: Bytes(32),
1883
+ // bytes32
1884
+ preVerificationGas: Bytes(32),
1885
+ // uint256 as 32 bytes
1886
+ gasFees: Bytes(32),
1887
+ // bytes32
1888
+ paymasterAndData: Vector(u8),
1889
+ // variable length bytes
1890
+ signature: Vector(u8)
1891
+ // variable length bytes
1892
+ });
1893
+ function encodeUserOpScale(userOp) {
1894
+ const encoded = PackedUserOperationCodec.enc({
1895
+ sender: hexToU8a(userOp.sender),
1896
+ nonce: numberToBytes(userOp.nonce, { size: 32 }),
1897
+ initCode: Array.from(hexToU8a(userOp.initCode)),
1898
+ callData: Array.from(hexToU8a(userOp.callData)),
1899
+ accountGasLimits: hexToU8a(userOp.accountGasLimits),
1900
+ preVerificationGas: numberToBytes(userOp.preVerificationGas, { size: 32 }),
1901
+ gasFees: hexToU8a(userOp.gasFees),
1902
+ paymasterAndData: Array.from(hexToU8a(userOp.paymasterAndData)),
1903
+ signature: Array.from(hexToU8a(userOp.signature))
1904
+ });
1905
+ return u8aToHex(encoded);
1906
+ }
1907
+ function decodeUserOpScale(hex) {
1908
+ const decoded = PackedUserOperationCodec.dec(hexToU8a(hex));
1909
+ return {
1910
+ sender: u8aToHex(new Uint8Array(decoded.sender)),
1911
+ nonce: bytesToBigInt(new Uint8Array(decoded.nonce)),
1912
+ initCode: u8aToHex(new Uint8Array(decoded.initCode)),
1913
+ callData: u8aToHex(new Uint8Array(decoded.callData)),
1914
+ accountGasLimits: u8aToHex(new Uint8Array(decoded.accountGasLimits)),
1915
+ preVerificationGas: bytesToBigInt(new Uint8Array(decoded.preVerificationGas)),
1916
+ gasFees: u8aToHex(new Uint8Array(decoded.gasFees)),
1917
+ paymasterAndData: u8aToHex(new Uint8Array(decoded.paymasterAndData)),
1918
+ signature: u8aToHex(new Uint8Array(decoded.signature))
1919
+ };
1920
+ }
1921
+ var injectedFetch;
1922
+ function setAggregationFetch(fetchImpl) {
1923
+ injectedFetch = fetchImpl;
1924
+ }
1925
+ function rpcFetch() {
1926
+ const f = injectedFetch ?? globalThis.fetch;
1927
+ if (typeof f !== "function") {
1928
+ throw new Error("No fetch available; call setAggregationFetch() before using the aggregation helpers");
1929
+ }
1930
+ return f;
1931
+ }
1932
+ async function rpcCall(url, payload) {
1933
+ let lastErr;
1934
+ for (let attempt = 0; attempt < 4; attempt++) {
1935
+ if (attempt > 0) await new Promise((resolve) => setTimeout(resolve, 150 * attempt));
1936
+ let timer;
1937
+ try {
1938
+ const timeout = new Promise((_, reject) => {
1939
+ timer = setTimeout(() => reject(new Error(`rpc timeout: ${url}`)), 12e3);
1940
+ });
1941
+ const response = await Promise.race([
1942
+ rpcFetch()(url, {
1943
+ method: "POST",
1944
+ headers: { accept: "application/json", "content-type": "application/json" },
1945
+ body: JSON.stringify(payload)
1946
+ }),
1947
+ timeout
1948
+ ]);
1949
+ return await response.json();
1950
+ } catch (err) {
1951
+ lastErr = err;
1952
+ } finally {
1953
+ if (timer) clearTimeout(timer);
1954
+ }
1955
+ }
1956
+ throw lastErr;
1957
+ }
1958
+ var FILL_ORDER_ABI = IntentGatewayV2_default.ABI;
1959
+ function weightedMedian(entries) {
1960
+ const sorted = [...entries].sort((a, b) => a.price < b.price ? -1 : a.price > b.price ? 1 : 0);
1961
+ const totalWeight = sorted.reduce((acc, e) => e.weight > 0n ? acc + e.weight : acc, 0n);
1962
+ if (totalWeight === 0n) {
1963
+ return sorted[Math.floor(sorted.length / 2)].price;
1964
+ }
1965
+ let cumulative = 0n;
1966
+ for (const entry of sorted) {
1967
+ if (entry.weight <= 0n) continue;
1968
+ cumulative += entry.weight;
1969
+ if (cumulative * 2n >= totalWeight) return entry.price;
1970
+ }
1971
+ return sorted[sorted.length - 1].price;
1972
+ }
1973
+ function extractFillData(callData, gatewayAddress) {
1974
+ const calls = decodeERC7821ExecuteBatch(callData);
1975
+ if (!calls) return null;
1976
+ const normalized = gatewayAddress.toLowerCase();
1977
+ for (const call of calls) {
1978
+ if (call.target.toLowerCase() !== normalized) continue;
1979
+ try {
1980
+ const decoded = decodeFunctionData({ abi: FILL_ORDER_ABI, data: call.data });
1981
+ if (decoded.functionName !== "fillOrder" || !decoded.args || decoded.args.length < 2) continue;
1982
+ const order = decoded.args[0];
1983
+ const options = decoded.args[1];
1984
+ const outputToken = order?.output?.assets?.[0]?.token;
1985
+ const outputs = options?.outputs;
1986
+ if (!outputToken || !outputs?.length) continue;
1987
+ return { order, options, outputToken, solverAmount: outputs[0].amount };
1988
+ } catch {
1989
+ continue;
1990
+ }
1991
+ }
1992
+ return null;
1993
+ }
1994
+ async function fetchBidsForOrder(nodeUrl, commitment) {
1995
+ const data = await rpcCall(nodeUrl, { id: 1, jsonrpc: "2.0", method: "intents_getBidsForOrder", params: [commitment] });
1996
+ return Array.isArray(data.result) ? data.result : [];
1997
+ }
1998
+ async function ethCallUint(evmRpcUrl, to, data) {
1999
+ try {
2000
+ const result = await rpcCall(evmRpcUrl, { id: 1, jsonrpc: "2.0", method: "eth_call", params: [{ to, data }, "latest"] });
2001
+ if (result.error || !result.result || result.result === "0x") return 0n;
2002
+ return BigInt(result.result);
2003
+ } catch {
2004
+ return 0n;
2005
+ }
2006
+ }
2007
+ async function getTotalSolverBalance(evmRpcUrl, chain, token, solver, yieldVaults) {
2008
+ const padded = solver.replace("0x", "").padStart(64, "0");
2009
+ const raw = await ethCallUint(evmRpcUrl, token, `0x70a08231${padded}`);
2010
+ const vaults = yieldVaults[chain]?.[token.toLowerCase()] ?? [];
2011
+ const vaultBalances = await Promise.all(
2012
+ vaults.map((v) => ethCallUint(evmRpcUrl, v, `0xce96cb77${padded}`))
2013
+ // maxWithdraw(address)
2014
+ );
2015
+ return vaultBalances.reduce((acc, b) => acc + b, raw);
2016
+ }
2017
+ async function sweepSolverLiquidity(evmRpcUrls, yieldVaults, solver) {
2018
+ const balances = [];
2019
+ for (const [chain, tokens] of Object.entries(yieldVaults)) {
2020
+ const url = evmRpcUrls[chain];
2021
+ if (!url) continue;
2022
+ for (const token of Object.keys(tokens)) {
2023
+ const balance = await getTotalSolverBalance(url, chain, token, solver, yieldVaults);
2024
+ if (balance === 0n) continue;
2025
+ balances.push({ solver, chain, tokenAddress: token, balance });
2026
+ }
2027
+ }
2028
+ return balances;
2029
+ }
2030
+ function toAddress(token) {
2031
+ const hex = token.toLowerCase().replace(/^0x/, "");
2032
+ const addr = hex.length > 40 ? hex.slice(-40) : hex.padStart(40, "0");
2033
+ return `0x${addr}`;
2034
+ }
2035
+ async function aggregatePhantomBids(params) {
2036
+ const { nodeUrl, evmRpcUrls, chain, gatewayAddress, commitment, yieldVaults, logger } = params;
2037
+ const extractFill = params.extractFill ?? extractFillData;
2038
+ const destUrl = evmRpcUrls[chain];
2039
+ if (!destUrl) return null;
2040
+ const bids = await fetchBidsForOrder(nodeUrl, commitment);
2041
+ if (bids.length === 0) return null;
2042
+ const quotes = [];
2043
+ const lpBalances = [];
2044
+ for (const bid of bids) {
2045
+ if (!bid.user_op) continue;
2046
+ try {
2047
+ const decoded = decodeUserOpScale(bid.user_op);
2048
+ const solver = decoded.sender;
2049
+ const fillData = extractFill(decoded.callData, gatewayAddress);
2050
+ if (!fillData) continue;
2051
+ const outputTokenAddress = toAddress(fillData.outputToken);
2052
+ const weight = await getTotalSolverBalance(destUrl, chain, outputTokenAddress, solver, yieldVaults);
2053
+ quotes.push({ price: fillData.solverAmount, weight });
2054
+ lpBalances.push(...await sweepSolverLiquidity(evmRpcUrls, yieldVaults, solver));
2055
+ } catch (err) {
2056
+ logger?.warn({ err, filler: bid.filler }, "Failed to process bid for price snapshot");
2057
+ }
2058
+ }
2059
+ if (quotes.length === 0) return null;
2060
+ const sortedPrices = quotes.map((q) => q.price).sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
2061
+ return {
2062
+ lowestPrice: sortedPrices[0],
2063
+ highestPrice: sortedPrices[sortedPrices.length - 1],
2064
+ medianPrice: weightedMedian(quotes),
2065
+ bidCount: quotes.length,
2066
+ lpBalances
2067
+ };
2068
+ }
2069
+
2070
+ export { FILL_ORDER_ABI, IntentGatewayV2_default as IntentGatewayV2, aggregatePhantomBids, decodeERC7821ExecuteBatch, decodeUserOpScale, encodeERC7821ExecuteBatch, encodeUserOpScale, extractFillData, fetchBidsForOrder, setAggregationFetch, weightedMedian };
2071
+ //# sourceMappingURL=intents-helpers.js.map
2072
+ //# sourceMappingURL=intents-helpers.js.map