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