@qorechain/evm 0.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.
package/dist/index.js ADDED
@@ -0,0 +1,967 @@
1
+ import { http, createPublicClient, defineChain, createWalletClient, custom, BaseError, ContractFunctionRevertedError, decodeErrorResult, getAddress, webSocket } from 'viem';
2
+ import { privateKeyToAccount } from 'viem/accounts';
3
+
4
+ // src/client.ts
5
+ function resolveRpcUrl(opts) {
6
+ const url = opts.rpcUrl ?? opts.endpoints?.evmRpc;
7
+ if (!url) {
8
+ throw new Error("createEvmClient: provide `rpcUrl` or `endpoints.evmRpc`");
9
+ }
10
+ return url;
11
+ }
12
+ function resolveWsUrl(opts) {
13
+ return opts.wsUrl ?? opts.endpoints?.evmWs;
14
+ }
15
+ async function createEvmClient(opts) {
16
+ const rpcUrl = resolveRpcUrl(opts);
17
+ const wsUrl = resolveWsUrl(opts);
18
+ const transport = opts.transport ?? http(rpcUrl);
19
+ const decimals = opts.decimals ?? 18;
20
+ let chainId = opts.chainId;
21
+ if (chainId === void 0) {
22
+ const probe = createPublicClient({ transport });
23
+ chainId = await probe.getChainId();
24
+ }
25
+ const chain = defineChain({
26
+ id: chainId,
27
+ name: "QoreChain EVM",
28
+ nativeCurrency: { name: "QOR", symbol: "QOR", decimals },
29
+ rpcUrls: {
30
+ default: {
31
+ http: [rpcUrl],
32
+ ...wsUrl ? { webSocket: [wsUrl] } : {}
33
+ }
34
+ }
35
+ });
36
+ const publicClient = createPublicClient({ chain, transport });
37
+ const getWalletClient = (account) => createWalletClient({ account, chain, transport });
38
+ return {
39
+ publicClient,
40
+ getWalletClient,
41
+ chain,
42
+ getChainId: async () => chainId
43
+ };
44
+ }
45
+ function evmAccountFromPrivateKey(privateKey) {
46
+ return privateKeyToAccount(privateKey);
47
+ }
48
+
49
+ // src/abi.ts
50
+ var ERC20_ABI = [
51
+ {
52
+ type: "function",
53
+ name: "name",
54
+ stateMutability: "view",
55
+ inputs: [],
56
+ outputs: [{ name: "", type: "string" }]
57
+ },
58
+ {
59
+ type: "function",
60
+ name: "symbol",
61
+ stateMutability: "view",
62
+ inputs: [],
63
+ outputs: [{ name: "", type: "string" }]
64
+ },
65
+ {
66
+ type: "function",
67
+ name: "decimals",
68
+ stateMutability: "view",
69
+ inputs: [],
70
+ outputs: [{ name: "", type: "uint8" }]
71
+ },
72
+ {
73
+ type: "function",
74
+ name: "totalSupply",
75
+ stateMutability: "view",
76
+ inputs: [],
77
+ outputs: [{ name: "", type: "uint256" }]
78
+ },
79
+ {
80
+ type: "function",
81
+ name: "balanceOf",
82
+ stateMutability: "view",
83
+ inputs: [{ name: "account", type: "address" }],
84
+ outputs: [{ name: "", type: "uint256" }]
85
+ },
86
+ {
87
+ type: "function",
88
+ name: "allowance",
89
+ stateMutability: "view",
90
+ inputs: [
91
+ { name: "owner", type: "address" },
92
+ { name: "spender", type: "address" }
93
+ ],
94
+ outputs: [{ name: "", type: "uint256" }]
95
+ },
96
+ {
97
+ type: "function",
98
+ name: "transfer",
99
+ stateMutability: "nonpayable",
100
+ inputs: [
101
+ { name: "to", type: "address" },
102
+ { name: "amount", type: "uint256" }
103
+ ],
104
+ outputs: [{ name: "", type: "bool" }]
105
+ },
106
+ {
107
+ type: "function",
108
+ name: "approve",
109
+ stateMutability: "nonpayable",
110
+ inputs: [
111
+ { name: "spender", type: "address" },
112
+ { name: "amount", type: "uint256" }
113
+ ],
114
+ outputs: [{ name: "", type: "bool" }]
115
+ },
116
+ {
117
+ type: "event",
118
+ name: "Transfer",
119
+ inputs: [
120
+ { indexed: true, name: "from", type: "address" },
121
+ { indexed: true, name: "to", type: "address" },
122
+ { indexed: false, name: "value", type: "uint256" }
123
+ ]
124
+ },
125
+ {
126
+ type: "event",
127
+ name: "Approval",
128
+ inputs: [
129
+ { indexed: true, name: "owner", type: "address" },
130
+ { indexed: true, name: "spender", type: "address" },
131
+ { indexed: false, name: "value", type: "uint256" }
132
+ ]
133
+ }
134
+ ];
135
+ var ERC721_ABI = [
136
+ {
137
+ type: "function",
138
+ name: "name",
139
+ stateMutability: "view",
140
+ inputs: [],
141
+ outputs: [{ name: "", type: "string" }]
142
+ },
143
+ {
144
+ type: "function",
145
+ name: "symbol",
146
+ stateMutability: "view",
147
+ inputs: [],
148
+ outputs: [{ name: "", type: "string" }]
149
+ },
150
+ {
151
+ type: "function",
152
+ name: "balanceOf",
153
+ stateMutability: "view",
154
+ inputs: [{ name: "owner", type: "address" }],
155
+ outputs: [{ name: "", type: "uint256" }]
156
+ },
157
+ {
158
+ type: "function",
159
+ name: "ownerOf",
160
+ stateMutability: "view",
161
+ inputs: [{ name: "tokenId", type: "uint256" }],
162
+ outputs: [{ name: "", type: "address" }]
163
+ },
164
+ {
165
+ type: "function",
166
+ name: "tokenURI",
167
+ stateMutability: "view",
168
+ inputs: [{ name: "tokenId", type: "uint256" }],
169
+ outputs: [{ name: "", type: "string" }]
170
+ },
171
+ {
172
+ type: "function",
173
+ name: "getApproved",
174
+ stateMutability: "view",
175
+ inputs: [{ name: "tokenId", type: "uint256" }],
176
+ outputs: [{ name: "", type: "address" }]
177
+ },
178
+ {
179
+ type: "function",
180
+ name: "isApprovedForAll",
181
+ stateMutability: "view",
182
+ inputs: [
183
+ { name: "owner", type: "address" },
184
+ { name: "operator", type: "address" }
185
+ ],
186
+ outputs: [{ name: "", type: "bool" }]
187
+ },
188
+ {
189
+ type: "function",
190
+ name: "approve",
191
+ stateMutability: "nonpayable",
192
+ inputs: [
193
+ { name: "to", type: "address" },
194
+ { name: "tokenId", type: "uint256" }
195
+ ],
196
+ outputs: []
197
+ },
198
+ {
199
+ type: "function",
200
+ name: "setApprovalForAll",
201
+ stateMutability: "nonpayable",
202
+ inputs: [
203
+ { name: "operator", type: "address" },
204
+ { name: "approved", type: "bool" }
205
+ ],
206
+ outputs: []
207
+ },
208
+ {
209
+ type: "function",
210
+ name: "transferFrom",
211
+ stateMutability: "nonpayable",
212
+ inputs: [
213
+ { name: "from", type: "address" },
214
+ { name: "to", type: "address" },
215
+ { name: "tokenId", type: "uint256" }
216
+ ],
217
+ outputs: []
218
+ },
219
+ {
220
+ type: "function",
221
+ name: "safeTransferFrom",
222
+ stateMutability: "nonpayable",
223
+ inputs: [
224
+ { name: "from", type: "address" },
225
+ { name: "to", type: "address" },
226
+ { name: "tokenId", type: "uint256" }
227
+ ],
228
+ outputs: []
229
+ },
230
+ {
231
+ type: "function",
232
+ name: "safeTransferFrom",
233
+ stateMutability: "nonpayable",
234
+ inputs: [
235
+ { name: "from", type: "address" },
236
+ { name: "to", type: "address" },
237
+ { name: "tokenId", type: "uint256" },
238
+ { name: "data", type: "bytes" }
239
+ ],
240
+ outputs: []
241
+ },
242
+ {
243
+ type: "event",
244
+ name: "Transfer",
245
+ inputs: [
246
+ { indexed: true, name: "from", type: "address" },
247
+ { indexed: true, name: "to", type: "address" },
248
+ { indexed: true, name: "tokenId", type: "uint256" }
249
+ ]
250
+ },
251
+ {
252
+ type: "event",
253
+ name: "Approval",
254
+ inputs: [
255
+ { indexed: true, name: "owner", type: "address" },
256
+ { indexed: true, name: "approved", type: "address" },
257
+ { indexed: true, name: "tokenId", type: "uint256" }
258
+ ]
259
+ },
260
+ {
261
+ type: "event",
262
+ name: "ApprovalForAll",
263
+ inputs: [
264
+ { indexed: true, name: "owner", type: "address" },
265
+ { indexed: true, name: "operator", type: "address" },
266
+ { indexed: false, name: "approved", type: "bool" }
267
+ ]
268
+ }
269
+ ];
270
+ var ERC1155_ABI = [
271
+ {
272
+ type: "function",
273
+ name: "balanceOf",
274
+ stateMutability: "view",
275
+ inputs: [
276
+ { name: "account", type: "address" },
277
+ { name: "id", type: "uint256" }
278
+ ],
279
+ outputs: [{ name: "", type: "uint256" }]
280
+ },
281
+ {
282
+ type: "function",
283
+ name: "balanceOfBatch",
284
+ stateMutability: "view",
285
+ inputs: [
286
+ { name: "accounts", type: "address[]" },
287
+ { name: "ids", type: "uint256[]" }
288
+ ],
289
+ outputs: [{ name: "", type: "uint256[]" }]
290
+ },
291
+ {
292
+ type: "function",
293
+ name: "uri",
294
+ stateMutability: "view",
295
+ inputs: [{ name: "id", type: "uint256" }],
296
+ outputs: [{ name: "", type: "string" }]
297
+ },
298
+ {
299
+ type: "function",
300
+ name: "isApprovedForAll",
301
+ stateMutability: "view",
302
+ inputs: [
303
+ { name: "account", type: "address" },
304
+ { name: "operator", type: "address" }
305
+ ],
306
+ outputs: [{ name: "", type: "bool" }]
307
+ },
308
+ {
309
+ type: "function",
310
+ name: "setApprovalForAll",
311
+ stateMutability: "nonpayable",
312
+ inputs: [
313
+ { name: "operator", type: "address" },
314
+ { name: "approved", type: "bool" }
315
+ ],
316
+ outputs: []
317
+ },
318
+ {
319
+ type: "function",
320
+ name: "safeTransferFrom",
321
+ stateMutability: "nonpayable",
322
+ inputs: [
323
+ { name: "from", type: "address" },
324
+ { name: "to", type: "address" },
325
+ { name: "id", type: "uint256" },
326
+ { name: "amount", type: "uint256" },
327
+ { name: "data", type: "bytes" }
328
+ ],
329
+ outputs: []
330
+ },
331
+ {
332
+ type: "function",
333
+ name: "safeBatchTransferFrom",
334
+ stateMutability: "nonpayable",
335
+ inputs: [
336
+ { name: "from", type: "address" },
337
+ { name: "to", type: "address" },
338
+ { name: "ids", type: "uint256[]" },
339
+ { name: "amounts", type: "uint256[]" },
340
+ { name: "data", type: "bytes" }
341
+ ],
342
+ outputs: []
343
+ },
344
+ {
345
+ type: "event",
346
+ name: "TransferSingle",
347
+ inputs: [
348
+ { indexed: true, name: "operator", type: "address" },
349
+ { indexed: true, name: "from", type: "address" },
350
+ { indexed: true, name: "to", type: "address" },
351
+ { indexed: false, name: "id", type: "uint256" },
352
+ { indexed: false, name: "value", type: "uint256" }
353
+ ]
354
+ },
355
+ {
356
+ type: "event",
357
+ name: "ApprovalForAll",
358
+ inputs: [
359
+ { indexed: true, name: "account", type: "address" },
360
+ { indexed: true, name: "operator", type: "address" },
361
+ { indexed: false, name: "approved", type: "bool" }
362
+ ]
363
+ }
364
+ ];
365
+ var IQORE_PQC_ABI = [
366
+ {
367
+ type: "function",
368
+ name: "pqcVerify",
369
+ stateMutability: "view",
370
+ inputs: [
371
+ { name: "pubkey", type: "bytes" },
372
+ { name: "signature", type: "bytes" },
373
+ { name: "message", type: "bytes" }
374
+ ],
375
+ outputs: [{ name: "valid", type: "bool" }]
376
+ },
377
+ {
378
+ type: "function",
379
+ name: "pqcKeyStatus",
380
+ stateMutability: "view",
381
+ inputs: [{ name: "account", type: "address" }],
382
+ outputs: [
383
+ { name: "registered", type: "bool" },
384
+ { name: "algorithmId", type: "uint8" },
385
+ { name: "pubkey", type: "bytes" }
386
+ ]
387
+ }
388
+ ];
389
+ var IQORE_AI_ABI = [
390
+ {
391
+ type: "function",
392
+ name: "aiRiskScore",
393
+ stateMutability: "view",
394
+ inputs: [{ name: "txData", type: "bytes" }],
395
+ outputs: [
396
+ { name: "score", type: "uint256" },
397
+ { name: "level", type: "uint8" }
398
+ ]
399
+ },
400
+ {
401
+ type: "function",
402
+ name: "aiAnomalyCheck",
403
+ stateMutability: "view",
404
+ inputs: [
405
+ { name: "sender", type: "address" },
406
+ { name: "amount", type: "uint256" }
407
+ ],
408
+ outputs: [
409
+ { name: "anomalyScore", type: "uint256" },
410
+ { name: "flagged", type: "bool" }
411
+ ]
412
+ }
413
+ ];
414
+ var IQORE_CONSENSUS_ABI = [
415
+ {
416
+ type: "function",
417
+ name: "rlConsensusParams",
418
+ stateMutability: "view",
419
+ inputs: [],
420
+ outputs: [
421
+ { name: "blockTime", type: "uint256" },
422
+ { name: "baseGasPrice", type: "uint256" },
423
+ { name: "validatorSetSize", type: "uint256" },
424
+ { name: "epoch", type: "uint256" }
425
+ ]
426
+ }
427
+ ];
428
+
429
+ // src/erc20.ts
430
+ function balanceOf(client, token, account) {
431
+ return client.readContract({
432
+ address: token,
433
+ abi: ERC20_ABI,
434
+ functionName: "balanceOf",
435
+ args: [account]
436
+ });
437
+ }
438
+ function allowance(client, token, owner, spender) {
439
+ return client.readContract({
440
+ address: token,
441
+ abi: ERC20_ABI,
442
+ functionName: "allowance",
443
+ args: [owner, spender]
444
+ });
445
+ }
446
+ async function metadata(client, token) {
447
+ const [name2, symbol2, decimals] = await Promise.all([
448
+ client.readContract({ address: token, abi: ERC20_ABI, functionName: "name" }),
449
+ client.readContract({ address: token, abi: ERC20_ABI, functionName: "symbol" }),
450
+ client.readContract({ address: token, abi: ERC20_ABI, functionName: "decimals" })
451
+ ]);
452
+ return { name: name2, symbol: symbol2, decimals };
453
+ }
454
+ function transfer(client, token, to, amount) {
455
+ return client.writeContract({
456
+ address: token,
457
+ abi: ERC20_ABI,
458
+ functionName: "transfer",
459
+ args: [to, amount],
460
+ account: client.account,
461
+ chain: client.chain
462
+ });
463
+ }
464
+ function approve(client, token, spender, amount) {
465
+ return client.writeContract({
466
+ address: token,
467
+ abi: ERC20_ABI,
468
+ functionName: "approve",
469
+ args: [spender, amount],
470
+ account: client.account,
471
+ chain: client.chain
472
+ });
473
+ }
474
+ var erc20 = {
475
+ balanceOf,
476
+ allowance,
477
+ metadata,
478
+ transfer,
479
+ approve
480
+ };
481
+
482
+ // src/erc721.ts
483
+ function balanceOf2(client, token, owner) {
484
+ return client.readContract({
485
+ address: token,
486
+ abi: ERC721_ABI,
487
+ functionName: "balanceOf",
488
+ args: [owner]
489
+ });
490
+ }
491
+ function ownerOf(client, token, tokenId) {
492
+ return client.readContract({
493
+ address: token,
494
+ abi: ERC721_ABI,
495
+ functionName: "ownerOf",
496
+ args: [tokenId]
497
+ });
498
+ }
499
+ function tokenURI(client, token, tokenId) {
500
+ return client.readContract({
501
+ address: token,
502
+ abi: ERC721_ABI,
503
+ functionName: "tokenURI",
504
+ args: [tokenId]
505
+ });
506
+ }
507
+ function getApproved(client, token, tokenId) {
508
+ return client.readContract({
509
+ address: token,
510
+ abi: ERC721_ABI,
511
+ functionName: "getApproved",
512
+ args: [tokenId]
513
+ });
514
+ }
515
+ function isApprovedForAll(client, token, owner, operator) {
516
+ return client.readContract({
517
+ address: token,
518
+ abi: ERC721_ABI,
519
+ functionName: "isApprovedForAll",
520
+ args: [owner, operator]
521
+ });
522
+ }
523
+ function name(client, token) {
524
+ return client.readContract({
525
+ address: token,
526
+ abi: ERC721_ABI,
527
+ functionName: "name"
528
+ });
529
+ }
530
+ function symbol(client, token) {
531
+ return client.readContract({
532
+ address: token,
533
+ abi: ERC721_ABI,
534
+ functionName: "symbol"
535
+ });
536
+ }
537
+ async function metadata2(client, token) {
538
+ const [n, s] = await Promise.all([name(client, token), symbol(client, token)]);
539
+ return { name: n, symbol: s };
540
+ }
541
+ function approve2(client, token, to, tokenId) {
542
+ return client.writeContract({
543
+ address: token,
544
+ abi: ERC721_ABI,
545
+ functionName: "approve",
546
+ args: [to, tokenId],
547
+ account: client.account,
548
+ chain: client.chain
549
+ });
550
+ }
551
+ function setApprovalForAll(client, token, operator, approved) {
552
+ return client.writeContract({
553
+ address: token,
554
+ abi: ERC721_ABI,
555
+ functionName: "setApprovalForAll",
556
+ args: [operator, approved],
557
+ account: client.account,
558
+ chain: client.chain
559
+ });
560
+ }
561
+ function transferFrom(client, token, from, to, tokenId) {
562
+ return client.writeContract({
563
+ address: token,
564
+ abi: ERC721_ABI,
565
+ functionName: "transferFrom",
566
+ args: [from, to, tokenId],
567
+ account: client.account,
568
+ chain: client.chain
569
+ });
570
+ }
571
+ function safeTransferFrom(client, token, from, to, tokenId, data) {
572
+ if (data !== void 0) {
573
+ return client.writeContract({
574
+ address: token,
575
+ abi: ERC721_ABI,
576
+ functionName: "safeTransferFrom",
577
+ args: [from, to, tokenId, data],
578
+ account: client.account,
579
+ chain: client.chain
580
+ });
581
+ }
582
+ return client.writeContract({
583
+ address: token,
584
+ abi: ERC721_ABI,
585
+ functionName: "safeTransferFrom",
586
+ args: [from, to, tokenId],
587
+ account: client.account,
588
+ chain: client.chain
589
+ });
590
+ }
591
+ var erc721 = {
592
+ balanceOf: balanceOf2,
593
+ ownerOf,
594
+ tokenURI,
595
+ getApproved,
596
+ isApprovedForAll,
597
+ name,
598
+ symbol,
599
+ metadata: metadata2,
600
+ approve: approve2,
601
+ setApprovalForAll,
602
+ transferFrom,
603
+ safeTransferFrom
604
+ };
605
+
606
+ // src/erc1155.ts
607
+ function balanceOf3(client, token, account, id) {
608
+ return client.readContract({
609
+ address: token,
610
+ abi: ERC1155_ABI,
611
+ functionName: "balanceOf",
612
+ args: [account, id]
613
+ });
614
+ }
615
+ function balanceOfBatch(client, token, accounts, ids) {
616
+ return client.readContract({
617
+ address: token,
618
+ abi: ERC1155_ABI,
619
+ functionName: "balanceOfBatch",
620
+ args: [accounts, ids]
621
+ });
622
+ }
623
+ function uri(client, token, id) {
624
+ return client.readContract({
625
+ address: token,
626
+ abi: ERC1155_ABI,
627
+ functionName: "uri",
628
+ args: [id]
629
+ });
630
+ }
631
+ function isApprovedForAll2(client, token, account, operator) {
632
+ return client.readContract({
633
+ address: token,
634
+ abi: ERC1155_ABI,
635
+ functionName: "isApprovedForAll",
636
+ args: [account, operator]
637
+ });
638
+ }
639
+ function setApprovalForAll2(client, token, operator, approved) {
640
+ return client.writeContract({
641
+ address: token,
642
+ abi: ERC1155_ABI,
643
+ functionName: "setApprovalForAll",
644
+ args: [operator, approved],
645
+ account: client.account,
646
+ chain: client.chain
647
+ });
648
+ }
649
+ function safeTransferFrom2(client, token, from, to, id, amount, data = "0x") {
650
+ return client.writeContract({
651
+ address: token,
652
+ abi: ERC1155_ABI,
653
+ functionName: "safeTransferFrom",
654
+ args: [from, to, id, amount, data],
655
+ account: client.account,
656
+ chain: client.chain
657
+ });
658
+ }
659
+ function safeBatchTransferFrom(client, token, from, to, ids, amounts, data = "0x") {
660
+ return client.writeContract({
661
+ address: token,
662
+ abi: ERC1155_ABI,
663
+ functionName: "safeBatchTransferFrom",
664
+ args: [from, to, ids, amounts, data],
665
+ account: client.account,
666
+ chain: client.chain
667
+ });
668
+ }
669
+ var erc1155 = {
670
+ balanceOf: balanceOf3,
671
+ balanceOfBatch,
672
+ uri,
673
+ isApprovedForAll: isApprovedForAll2,
674
+ setApprovalForAll: setApprovalForAll2,
675
+ safeTransferFrom: safeTransferFrom2,
676
+ safeBatchTransferFrom
677
+ };
678
+
679
+ // src/fees.ts
680
+ async function estimateEip1559Fees(client) {
681
+ const { maxFeePerGas, maxPriorityFeePerGas } = await client.estimateFeesPerGas();
682
+ return { maxFeePerGas, maxPriorityFeePerGas };
683
+ }
684
+ function gasPrice(client) {
685
+ return client.getGasPrice();
686
+ }
687
+ var fees = {
688
+ estimateEip1559Fees,
689
+ gasPrice
690
+ };
691
+
692
+ // src/contracts.ts
693
+ function deployContract(client, { abi, bytecode, args }) {
694
+ return client.deployContract({
695
+ abi,
696
+ bytecode,
697
+ args,
698
+ account: client.account,
699
+ chain: client.chain
700
+ });
701
+ }
702
+ function readContract(client, params) {
703
+ return client.readContract(params);
704
+ }
705
+ function writeContract(client, params) {
706
+ const p = params;
707
+ return client.writeContract({
708
+ account: client.account,
709
+ chain: client.chain,
710
+ ...p
711
+ });
712
+ }
713
+ var PRECOMPILE_ADDRESSES = {
714
+ /** CrossVM Bridge precompile. */
715
+ crossVmBridge: "0x0000000000000000000000000000000000000901",
716
+ /** PQC signature verification (`IQorePQC.pqcVerify`). */
717
+ pqcVerify: "0x0000000000000000000000000000000000000A01",
718
+ /** PQC key registration status (`IQorePQC.pqcKeyStatus`). */
719
+ pqcKeyStatus: "0x0000000000000000000000000000000000000A02",
720
+ /** AI transaction risk score (`IQoreAI.aiRiskScore`). */
721
+ aiRiskScore: "0x0000000000000000000000000000000000000B01",
722
+ /** AI anomaly check (`IQoreAI.aiAnomalyCheck`). */
723
+ aiAnomalyCheck: "0x0000000000000000000000000000000000000B02",
724
+ /** Consensus parameters (`IQoreConsensus.rlConsensusParams`). */
725
+ rlConsensusParams: "0x0000000000000000000000000000000000000C01"
726
+ };
727
+ var addr = (a) => getAddress(a);
728
+ function pqcVerify(client, { pubkey, signature, message }) {
729
+ return client.readContract({
730
+ address: addr(PRECOMPILE_ADDRESSES.pqcVerify),
731
+ abi: IQORE_PQC_ABI,
732
+ functionName: "pqcVerify",
733
+ args: [pubkey, signature, message]
734
+ });
735
+ }
736
+ async function pqcKeyStatus(client, account) {
737
+ const [registered, algorithmId, pubkey] = await client.readContract({
738
+ address: addr(PRECOMPILE_ADDRESSES.pqcKeyStatus),
739
+ abi: IQORE_PQC_ABI,
740
+ functionName: "pqcKeyStatus",
741
+ args: [account]
742
+ });
743
+ return { registered, algorithmId, pubkey };
744
+ }
745
+ async function aiRiskScore(client, txData) {
746
+ const [score, level] = await client.readContract({
747
+ address: addr(PRECOMPILE_ADDRESSES.aiRiskScore),
748
+ abi: IQORE_AI_ABI,
749
+ functionName: "aiRiskScore",
750
+ args: [txData]
751
+ });
752
+ return { score, level };
753
+ }
754
+ async function aiAnomalyCheck(client, { sender, amount }) {
755
+ const [anomalyScore, flagged] = await client.readContract({
756
+ address: addr(PRECOMPILE_ADDRESSES.aiAnomalyCheck),
757
+ abi: IQORE_AI_ABI,
758
+ functionName: "aiAnomalyCheck",
759
+ args: [sender, amount]
760
+ });
761
+ return { anomalyScore, flagged };
762
+ }
763
+ async function rlConsensusParams(client) {
764
+ const [blockTime, baseGasPrice, validatorSetSize, epoch] = await client.readContract({
765
+ address: addr(PRECOMPILE_ADDRESSES.rlConsensusParams),
766
+ abi: IQORE_CONSENSUS_ABI,
767
+ functionName: "rlConsensusParams"
768
+ });
769
+ return { blockTime, baseGasPrice, validatorSetSize, epoch };
770
+ }
771
+ var precompiles = {
772
+ pqcVerify,
773
+ pqcKeyStatus,
774
+ aiRiskScore,
775
+ aiAnomalyCheck,
776
+ rlConsensusParams
777
+ };
778
+ function resolveProvider(provider) {
779
+ if (provider) return provider;
780
+ if (typeof window === "undefined") {
781
+ throw new Error(
782
+ "EVM wallet: no browser `window` available. Run in a browser, or pass `provider` explicitly."
783
+ );
784
+ }
785
+ const injected = window.ethereum;
786
+ if (!injected) {
787
+ throw new Error(
788
+ "EVM wallet: no injected EIP-1193 provider found (window.ethereum). Install MetaMask, or pass `provider`."
789
+ );
790
+ }
791
+ return injected;
792
+ }
793
+ function toHexChainId(chainId) {
794
+ return `0x${chainId.toString(16)}`;
795
+ }
796
+ async function requestAccounts(provider) {
797
+ const accounts = await provider.request({
798
+ method: "eth_requestAccounts"
799
+ });
800
+ if (!accounts || accounts.length === 0) {
801
+ throw new Error("EVM wallet: provider returned no accounts");
802
+ }
803
+ return accounts;
804
+ }
805
+ async function addQoreChainNetwork(provider, network, opts = {}) {
806
+ const chainId = opts.chainId ?? Number(await provider.request({ method: "eth_chainId" }));
807
+ await provider.request({
808
+ method: "wallet_addEthereumChain",
809
+ params: [
810
+ {
811
+ chainId: toHexChainId(chainId),
812
+ chainName: network.coin.display === "QOR" ? "QoreChain EVM" : network.coin.display,
813
+ nativeCurrency: {
814
+ name: network.coin.display,
815
+ symbol: network.coin.display,
816
+ decimals: 18
817
+ },
818
+ rpcUrls: [network.endpoints.evmRpc],
819
+ ...opts.blockExplorerUrl ? { blockExplorerUrls: [opts.blockExplorerUrl] } : {}
820
+ }
821
+ ]
822
+ });
823
+ }
824
+ async function switchChain(provider, chainId) {
825
+ await provider.request({
826
+ method: "wallet_switchEthereumChain",
827
+ params: [{ chainId: toHexChainId(chainId) }]
828
+ });
829
+ }
830
+ async function getEvmWalletClient(opts = {}) {
831
+ const provider = resolveProvider(opts.provider);
832
+ const accounts = await requestAccounts(provider);
833
+ const address = accounts[0];
834
+ const chainId = opts.chainId ?? Number(await provider.request({ method: "eth_chainId" }));
835
+ const decimals = opts.decimals ?? 18;
836
+ const chain = defineChain({
837
+ id: chainId,
838
+ name: "QoreChain EVM",
839
+ nativeCurrency: { name: "QOR", symbol: "QOR", decimals },
840
+ rpcUrls: { default: { http: [] } }
841
+ });
842
+ const walletClient = createWalletClient({
843
+ account: address,
844
+ chain,
845
+ transport: custom(provider)
846
+ });
847
+ return { walletClient, address, provider, chain };
848
+ }
849
+ function discoverEvmProviders(timeoutMs = 200) {
850
+ if (typeof window === "undefined") return Promise.resolve([]);
851
+ return new Promise((resolve) => {
852
+ const found = /* @__PURE__ */ new Map();
853
+ const onAnnounce = (event) => {
854
+ const detail = event.detail;
855
+ if (detail?.info?.uuid) found.set(detail.info.uuid, detail);
856
+ };
857
+ window.addEventListener("eip6963:announceProvider", onAnnounce);
858
+ window.dispatchEvent(new Event("eip6963:requestProvider"));
859
+ setTimeout(() => {
860
+ window.removeEventListener(
861
+ "eip6963:announceProvider",
862
+ onAnnounce
863
+ );
864
+ resolve([...found.values()]);
865
+ }, timeoutMs);
866
+ });
867
+ }
868
+ function extractRevertData(err) {
869
+ const e = err;
870
+ const d = e?.data ?? e?.cause?.data;
871
+ if (typeof d === "string" && d.startsWith("0x")) return d;
872
+ if (d && typeof d === "object" && "data" in d) {
873
+ const inner = d.data;
874
+ if (typeof inner === "string" && inner.startsWith("0x")) return inner;
875
+ }
876
+ return void 0;
877
+ }
878
+ function decodeEvmError(error, abi) {
879
+ if (error instanceof BaseError) {
880
+ const revert = error.walk(
881
+ (e) => e instanceof ContractFunctionRevertedError
882
+ );
883
+ if (revert instanceof ContractFunctionRevertedError) {
884
+ const data2 = revert.data;
885
+ if (data2?.errorName === "Error") {
886
+ const reason = data2.args?.[0] ?? revert.reason ?? "reverted";
887
+ return { message: `reverted: ${reason}`, kind: "revert", errorName: "Error" };
888
+ }
889
+ if (data2?.errorName === "Panic") {
890
+ return {
891
+ message: `panic: ${String(data2.args?.[0])}`,
892
+ kind: "panic",
893
+ errorName: "Panic",
894
+ args: data2.args
895
+ };
896
+ }
897
+ if (data2?.errorName) {
898
+ return {
899
+ message: `custom error ${data2.errorName}(${(data2.args ?? []).map((a) => String(a)).join(", ")})`,
900
+ kind: "custom_error",
901
+ errorName: data2.errorName,
902
+ args: data2.args
903
+ };
904
+ }
905
+ if (revert.reason) {
906
+ return { message: `reverted: ${revert.reason}`, kind: "revert" };
907
+ }
908
+ }
909
+ const data = extractRevertData(error);
910
+ if (data && abi) {
911
+ try {
912
+ const decoded = decodeErrorResult({ abi, data });
913
+ return {
914
+ message: `custom error ${decoded.errorName}(${(decoded.args ?? []).map((a) => String(a)).join(", ")})`,
915
+ kind: "custom_error",
916
+ errorName: decoded.errorName,
917
+ args: decoded.args,
918
+ data
919
+ };
920
+ } catch {
921
+ }
922
+ }
923
+ const deepest = error.walk();
924
+ return {
925
+ message: deepest.shortMessage ?? error.shortMessage ?? error.message,
926
+ kind: "execution",
927
+ data
928
+ };
929
+ }
930
+ if (error instanceof Error) {
931
+ return { message: error.message, kind: "rpc" };
932
+ }
933
+ return { message: String(error), kind: "unknown" };
934
+ }
935
+ function resolveTransport(opts) {
936
+ if (opts.transport) return opts.transport;
937
+ const url = opts.wsUrl ?? opts.endpoints?.evmWs;
938
+ if (!url) {
939
+ throw new Error(
940
+ "createEvmSubscriptionClient: provide `wsUrl`, `endpoints.evmWs`, or a `transport`"
941
+ );
942
+ }
943
+ return webSocket(url);
944
+ }
945
+ function createEvmSubscriptionClient(opts) {
946
+ const transport = resolveTransport(opts);
947
+ return createPublicClient({ transport, chain: opts.chain });
948
+ }
949
+ function watchBlocks(client, args) {
950
+ return client.watchBlocks(args);
951
+ }
952
+ function watchEvent(client, args) {
953
+ return client.watchEvent(args);
954
+ }
955
+ function watchContractEvent(client, args) {
956
+ return client.watchContractEvent(args);
957
+ }
958
+ function watchPendingTransactions(client, args) {
959
+ return client.watchPendingTransactions(args);
960
+ }
961
+
962
+ // src/index.ts
963
+ var VERSION = "0.3.0";
964
+
965
+ export { ERC1155_ABI, ERC20_ABI, ERC721_ABI, IQORE_AI_ABI, IQORE_CONSENSUS_ABI, IQORE_PQC_ABI, PRECOMPILE_ADDRESSES, VERSION, addQoreChainNetwork, aiAnomalyCheck, aiRiskScore, allowance, approve, balanceOf, createEvmClient, createEvmSubscriptionClient, decodeEvmError, deployContract, discoverEvmProviders, erc1155, erc20, erc721, estimateEip1559Fees, evmAccountFromPrivateKey, fees, gasPrice, getEvmWalletClient, metadata, pqcKeyStatus, pqcVerify, precompiles, readContract, requestAccounts, rlConsensusParams, switchChain, toHexChainId, transfer, watchBlocks, watchContractEvent, watchEvent, watchPendingTransactions, writeContract };
966
+ //# sourceMappingURL=index.js.map
967
+ //# sourceMappingURL=index.js.map