genlayer-js 0.8.0 → 0.9.1

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/chains/index.cjs +2 -2
  3. package/dist/chains/index.d.cts +2 -2
  4. package/dist/chains/index.d.ts +2 -2
  5. package/dist/chains/index.js +3 -3
  6. package/dist/chains-BYSCF33g.d.cts +18 -0
  7. package/dist/chains-BYSCF33g.d.ts +18 -0
  8. package/dist/chunk-7YZQQWJZ.js +4056 -0
  9. package/dist/chunk-AZSICIZ3.cjs +132 -0
  10. package/dist/chunk-FPFZLPXI.cjs +4056 -0
  11. package/dist/chunk-RS7NCSOQ.js +132 -0
  12. package/dist/index-BM9hOtGg.d.cts +13 -0
  13. package/dist/index-C7Colsnk.d.ts +13 -0
  14. package/dist/index-DvSbRKD5.d.ts +370 -0
  15. package/dist/index-kDM_9wW1.d.cts +370 -0
  16. package/dist/index.cjs +393 -134
  17. package/dist/index.d.cts +6 -6
  18. package/dist/index.d.ts +6 -6
  19. package/dist/index.js +385 -126
  20. package/dist/types/index.cjs +18 -2
  21. package/dist/types/index.d.cts +3 -3
  22. package/dist/types/index.d.ts +3 -3
  23. package/dist/types/index.js +19 -3
  24. package/package.json +2 -2
  25. package/src/accounts/IAccountActions.ts +2 -2
  26. package/src/accounts/actions.ts +10 -4
  27. package/src/chains/actions.ts +5 -5
  28. package/src/chains/index.ts +1 -1
  29. package/src/chains/localnet.ts +4 -3
  30. package/src/chains/testnet.ts +4015 -0
  31. package/src/client/client.ts +64 -21
  32. package/src/contracts/actions.ts +185 -137
  33. package/src/transactions/actions.ts +173 -8
  34. package/src/types/accounts.ts +1 -2
  35. package/src/types/chains.ts +8 -2
  36. package/src/types/clients.ts +14 -13
  37. package/src/types/transactions.ts +250 -8
  38. package/src/utils/jsonifier.ts +47 -0
  39. package/src/wallet/actions.ts +4 -4
  40. package/src/wallet/connect.ts +12 -14
  41. package/tests/client.test.ts +105 -45
  42. package/dist/chains-C5PI_Nr_.d.cts +0 -13
  43. package/dist/chains-C5PI_Nr_.d.ts +0 -13
  44. package/dist/chunk-I6HC44KD.cjs +0 -72
  45. package/dist/chunk-K72OSU5N.js +0 -28
  46. package/dist/chunk-WEXFFND6.js +0 -72
  47. package/dist/chunk-YDFRDDP5.cjs +0 -28
  48. package/dist/index-B8E0qiOq.d.cts +0 -13
  49. package/dist/index-BfeTR7rO.d.cts +0 -187
  50. package/dist/index-CODAJePj.d.ts +0 -187
  51. package/dist/index-ZoW0HQ_m.d.ts +0 -13
  52. package/src/chains/simulator.ts +0 -30
package/dist/index.js CHANGED
@@ -1,17 +1,27 @@
1
1
  import {
2
2
  chains_exports,
3
3
  localnet,
4
- simulator
5
- } from "./chunk-WEXFFND6.js";
4
+ testnet
5
+ } from "./chunk-7YZQQWJZ.js";
6
6
  import {
7
- CalldataAddress
8
- } from "./chunk-K72OSU5N.js";
7
+ CalldataAddress,
8
+ transactionResultNumberToName,
9
+ transactionsStatusNameToNumber,
10
+ transactionsStatusNumberToName,
11
+ voteTypeNumberToName
12
+ } from "./chunk-RS7NCSOQ.js";
9
13
  import {
10
14
  __export
11
15
  } from "./chunk-MLKGABMK.js";
12
16
 
13
17
  // src/client/client.ts
14
- import { createClient as createViemClient, publicActions, custom, walletActions as walletActions2 } from "viem";
18
+ import {
19
+ createClient as createViemClient,
20
+ createPublicClient as createPublicViemClient,
21
+ publicActions,
22
+ custom,
23
+ walletActions as walletActions2
24
+ } from "viem";
15
25
 
16
26
  // src/accounts/actions.ts
17
27
  function accountActions(client) {
@@ -25,7 +35,10 @@ function accountActions(client) {
25
35
  params: [address, amount]
26
36
  });
27
37
  },
28
- getCurrentNonce: async ({ address, block = "latest" }) => {
38
+ getCurrentNonce: async ({
39
+ address,
40
+ block = "latest"
41
+ }) => {
29
42
  const addressToUse = address || client.account?.address;
30
43
  if (!addressToUse) {
31
44
  throw new Error("No address provided and no account is connected");
@@ -366,7 +379,7 @@ function serialize(data) {
366
379
  }
367
380
 
368
381
  // src/contracts/actions.ts
369
- import { fromHex, toHex as toHex2, zeroAddress, encodeFunctionData } from "viem";
382
+ import { fromHex, toHex as toHex2, zeroAddress, encodeFunctionData, parseEventLogs } from "viem";
370
383
  function makeCalldataObject(method, args, kwargs) {
371
384
  let ret = {};
372
385
  if (method) {
@@ -393,9 +406,12 @@ function makeCalldataObject(method, args, kwargs) {
393
406
  }
394
407
  return ret;
395
408
  }
396
- var contractActions = (client) => {
409
+ var contractActions = (client, publicClient) => {
397
410
  return {
398
411
  getContractSchema: async (address) => {
412
+ if (client.chain.id !== localnet.id) {
413
+ throw new Error("Contract schema is not supported on this network");
414
+ }
399
415
  const schema = await client.request({
400
416
  method: "gen_getContractSchema",
401
417
  params: [address]
@@ -403,104 +419,154 @@ var contractActions = (client) => {
403
419
  return schema;
404
420
  },
405
421
  getContractSchemaForCode: async (contractCode) => {
422
+ if (client.chain.id !== localnet.id) {
423
+ throw new Error("Contract schema is not supported on this network");
424
+ }
406
425
  const schema = await client.request({
407
426
  method: "gen_getContractSchemaForCode",
408
427
  params: [toHex2(contractCode)]
409
428
  });
410
429
  return schema;
430
+ },
431
+ readContract: async (args) => {
432
+ const { account, address, functionName, args: callArgs, kwargs, leaderOnly = false } = args;
433
+ const encodedData = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
434
+ const serializedData = serialize(encodedData);
435
+ const senderAddress = account?.address ?? client.account?.address;
436
+ const requestParams = {
437
+ type: "read",
438
+ to: address,
439
+ from: senderAddress,
440
+ data: serializedData,
441
+ transaction_hash_variant: "latest-final"
442
+ };
443
+ const result = await client.request({
444
+ method: "gen_call",
445
+ params: [requestParams]
446
+ });
447
+ const prefixedResult = `0x${result}`;
448
+ if (args.rawReturn) {
449
+ return prefixedResult;
450
+ }
451
+ const resultBinary = fromHex(prefixedResult, "bytes");
452
+ return decode(resultBinary);
453
+ },
454
+ writeContract: async (args) => {
455
+ const {
456
+ account,
457
+ address,
458
+ functionName,
459
+ args: callArgs,
460
+ kwargs,
461
+ value = 0n,
462
+ leaderOnly = false,
463
+ consensusMaxRotations = client.chain.defaultConsensusMaxRotations
464
+ } = args;
465
+ const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
466
+ const serializedData = serialize(data);
467
+ return _sendTransaction({
468
+ client,
469
+ publicClient,
470
+ recipient: address,
471
+ data: serializedData,
472
+ senderAccount: account || client.account,
473
+ consensusMaxRotations,
474
+ value
475
+ });
476
+ },
477
+ deployContract: async (args) => {
478
+ const {
479
+ account,
480
+ code,
481
+ args: constructorArgs,
482
+ kwargs,
483
+ leaderOnly = false,
484
+ consensusMaxRotations = client.chain.defaultConsensusMaxRotations
485
+ } = args;
486
+ const data = [
487
+ code,
488
+ encode(makeCalldataObject(void 0, constructorArgs, kwargs)),
489
+ leaderOnly
490
+ ];
491
+ const serializedData = serialize(data);
492
+ return _sendTransaction({
493
+ client,
494
+ publicClient,
495
+ recipient: zeroAddress,
496
+ data: serializedData,
497
+ senderAccount: account || client.account,
498
+ consensusMaxRotations
499
+ });
411
500
  }
412
501
  };
413
502
  };
414
- var overrideContractActions = (client) => {
415
- client.readContract = async (args) => {
416
- const {
417
- account,
418
- address,
419
- functionName,
420
- args: callArgs,
421
- kwargs,
422
- stateStatus = "ACCEPTED" /* ACCEPTED */
423
- } = args;
424
- const encodedData = encode(makeCalldataObject(functionName, callArgs, kwargs));
425
- const serializedData = serializeOne(encodedData);
426
- const senderAddress = account?.address ?? client.account?.address;
427
- const requestParams = {
428
- to: address,
429
- from: senderAddress,
430
- data: serializedData
431
- };
432
- const result = await client.request({
433
- method: "eth_call",
434
- params: [requestParams, stateStatus == "FINALIZED" /* FINALIZED */ ? "finalized" : "latest"]
435
- });
436
- if (args.rawReturn) {
437
- return result;
438
- }
439
- const resultBinary = fromHex(result, "bytes");
440
- return decode(resultBinary);
441
- };
442
- client.writeContract = async (args) => {
443
- const { account, address, functionName, args: callArgs, kwargs, value = 0n, leaderOnly = false, consensusMaxRotations = client.chain.defaultConsensusMaxRotations } = args;
444
- const data = [encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
445
- const serializedData = serialize(data);
446
- return _sendTransaction(address, serializedData, account || client.account, consensusMaxRotations, value);
447
- };
448
- client.deployContract = async (args) => {
449
- const { account, code, args: constructorArgs, kwargs, leaderOnly = false, consensusMaxRotations = client.chain.defaultConsensusMaxRotations } = args;
450
- const data = [code, encode(makeCalldataObject(void 0, constructorArgs, kwargs)), leaderOnly];
451
- const serializedData = serialize(data);
452
- return _sendTransaction(zeroAddress, serializedData, account || client.account, consensusMaxRotations);
453
- };
454
- const _sendTransaction = async (recipient, data, senderAccount, consensusMaxRotations, value) => {
455
- if (!senderAccount) {
456
- throw new Error(
457
- "No account set. Configure the client with an account or pass an account to this function."
458
- );
459
- }
460
- if (!client.chain.consensusMainContract?.address) {
461
- throw new Error(
462
- "Consensus main contract not initialized. Please ensure client is properly initialized."
463
- );
464
- }
465
- const encodedData = encodeFunctionData({
466
- abi: client.chain.consensusMainContract?.abi,
467
- functionName: "addTransaction",
468
- args: [
469
- senderAccount.address,
470
- recipient,
471
- client.chain.defaultNumberOfInitialValidators,
472
- consensusMaxRotations,
473
- data
474
- ]
475
- });
476
- const nonce = await client.getCurrentNonce({ address: senderAccount.address });
477
- const transactionRequest = await client.prepareTransactionRequest({
478
- account: senderAccount,
479
- to: client.chain.consensusMainContract?.address,
503
+ var _sendTransaction = async ({
504
+ client,
505
+ publicClient,
506
+ recipient,
507
+ data,
508
+ senderAccount,
509
+ consensusMaxRotations,
510
+ value
511
+ }) => {
512
+ if (!senderAccount) {
513
+ throw new Error(
514
+ "No account set. Configure the client with an account or pass an account to this function."
515
+ );
516
+ }
517
+ if (!client.chain.consensusMainContract?.address) {
518
+ throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
519
+ }
520
+ const encodedData = encodeFunctionData({
521
+ abi: client.chain.consensusMainContract?.abi,
522
+ functionName: "addTransaction",
523
+ args: [
524
+ senderAccount.address,
525
+ recipient,
526
+ client.chain.defaultNumberOfInitialValidators,
527
+ consensusMaxRotations,
528
+ data
529
+ ]
530
+ });
531
+ const nonce = await client.getCurrentNonce({ address: senderAccount.address });
532
+ const transactionRequest = await client.prepareTransactionRequest({
533
+ account: senderAccount,
534
+ to: client.chain.consensusMainContract?.address,
535
+ data: encodedData,
536
+ type: "legacy",
537
+ nonce: Number(nonce),
538
+ value: value ?? 0n
539
+ });
540
+ if (senderAccount?.type !== "local") {
541
+ const formattedRequest = {
542
+ from: transactionRequest.from,
543
+ to: transactionRequest.to,
480
544
  data: encodedData,
481
- type: "legacy",
482
- nonce,
483
- value: value ?? 0n
545
+ value: transactionRequest.value ? `0x${transactionRequest.value.toString(16)}` : "0x0"
546
+ };
547
+ return await client.request({
548
+ method: "eth_sendTransaction",
549
+ params: [formattedRequest]
484
550
  });
485
- if (senderAccount?.type !== "local") {
486
- const formattedRequest = {
487
- from: transactionRequest.from,
488
- to: transactionRequest.to,
489
- data: encodedData,
490
- value: transactionRequest.value ? `0x${transactionRequest.value.toString(16)}` : "0x0"
491
- };
492
- return await client.request({
493
- method: "eth_sendTransaction",
494
- params: [formattedRequest]
495
- });
496
- }
497
- if (!senderAccount?.signTransaction) {
498
- throw new Error("Account does not support signTransaction");
499
- }
500
- const serializedTransaction = await senderAccount.signTransaction(transactionRequest);
501
- return client.sendRawTransaction({ serializedTransaction });
502
- };
503
- return client;
551
+ }
552
+ if (!senderAccount?.signTransaction) {
553
+ throw new Error("Account does not support signTransaction");
554
+ }
555
+ const serializedTransaction = await senderAccount.signTransaction(transactionRequest);
556
+ const txHash = await client.sendRawTransaction({ serializedTransaction });
557
+ const receipt = await publicClient.waitForTransactionReceipt({ hash: txHash });
558
+ if (receipt.status === "reverted") {
559
+ throw new Error("Transaction reverted");
560
+ }
561
+ const newTxEvents = parseEventLogs({
562
+ abi: client.chain.consensusMainContract?.abi,
563
+ eventName: "NewTransaction",
564
+ logs: receipt.logs
565
+ });
566
+ if (newTxEvents.length === 0) {
567
+ throw new Error("Transaction not processed by consensus");
568
+ }
569
+ return newTxEvents[0].args["txId"];
504
570
  };
505
571
 
506
572
  // src/config/transactions.ts
@@ -514,26 +580,84 @@ async function sleep(ms) {
514
580
  return new Promise((resolve) => setTimeout(resolve, ms));
515
581
  }
516
582
 
583
+ // src/abi/index.ts
584
+ var abi_exports = {};
585
+ __export(abi_exports, {
586
+ calldata: () => calldata,
587
+ transactions: () => transactions
588
+ });
589
+ var calldata = calldata_exports;
590
+ var transactions = transactions_exports;
591
+
592
+ // src/utils/jsonifier.ts
593
+ function b64ToArray(b64) {
594
+ return Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
595
+ }
596
+ function calldataToUserFriendlyJson(cd) {
597
+ return {
598
+ raw: Array.from(cd),
599
+ readable: calldata.toString(calldata.decode(cd))
600
+ };
601
+ }
602
+ var RESULT_CODES = /* @__PURE__ */ new Map([
603
+ [0, "return"],
604
+ [1, "rollback"],
605
+ [2, "contract_error"],
606
+ [3, "error"],
607
+ [4, "none"],
608
+ [5, "no_leaders"]
609
+ ]);
610
+ function resultToUserFriendlyJson(cd64) {
611
+ const raw = b64ToArray(cd64);
612
+ const code = RESULT_CODES.get(raw[0]);
613
+ let status;
614
+ let payload = null;
615
+ if (code === void 0) {
616
+ status = "<unknown>";
617
+ } else {
618
+ status = code;
619
+ if ([1, 2].includes(raw[0])) {
620
+ payload = new TextDecoder("utf-8").decode(raw.slice(1));
621
+ } else if (raw[0] == 0) {
622
+ payload = calldataToUserFriendlyJson(raw.slice(1));
623
+ }
624
+ }
625
+ return {
626
+ raw: cd64,
627
+ status,
628
+ payload
629
+ };
630
+ }
631
+
517
632
  // src/transactions/actions.ts
518
- var transactionActions = (client) => ({
633
+ import { fromRlp, fromHex as fromHex2 } from "viem";
634
+ var receiptActions = (client, publicClient) => ({
519
635
  waitForTransactionReceipt: async ({
520
636
  hash,
521
637
  status = "ACCEPTED" /* ACCEPTED */,
522
638
  interval = transactionsConfig.waitInterval,
523
639
  retries = transactionsConfig.retries
524
640
  }) => {
525
- const transaction = await client.getTransaction({ hash });
641
+ const transaction = await client.getTransaction({
642
+ hash
643
+ });
526
644
  if (!transaction) {
527
645
  throw new Error("Transaction not found");
528
646
  }
529
- if (transaction.status === status || status === "ACCEPTED" /* ACCEPTED */ && transaction.status === "FINALIZED" /* FINALIZED */) {
647
+ const transactionStatusString = String(transaction.status);
648
+ const transactionStatusFinalized = transactionsStatusNameToNumber["FINALIZED" /* FINALIZED */];
649
+ const requestedStatus = transactionsStatusNameToNumber[status];
650
+ if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && transactionStatusString === transactionStatusFinalized) {
651
+ if (client.chain.id === localnet.id) {
652
+ return _decodeLocalnetTransaction(transaction);
653
+ }
530
654
  return transaction;
531
655
  }
532
656
  if (retries === 0) {
533
657
  throw new Error("Transaction status is not " + status);
534
658
  }
535
659
  await sleep(interval);
536
- return transactionActions(client).waitForTransactionReceipt({
660
+ return receiptActions(client, publicClient).waitForTransactionReceipt({
537
661
  hash,
538
662
  status,
539
663
  interval,
@@ -541,6 +665,128 @@ var transactionActions = (client) => ({
541
665
  });
542
666
  }
543
667
  });
668
+ var transactionActions = (client, publicClient) => ({
669
+ getTransaction: async ({ hash }) => {
670
+ const transaction = await publicClient.readContract({
671
+ address: client.chain.consensusDataContract?.address,
672
+ abi: client.chain.consensusDataContract?.abi,
673
+ functionName: "getTransactionData",
674
+ args: [
675
+ hash,
676
+ Math.round((/* @__PURE__ */ new Date()).getTime() / 1e3)
677
+ // unix seconds
678
+ ]
679
+ });
680
+ return _decodeTransaction(transaction);
681
+ }
682
+ });
683
+ var _decodeInputData = (rlpEncodedAppData, recipient) => {
684
+ if (!rlpEncodedAppData || rlpEncodedAppData === "0x" || rlpEncodedAppData.length <= 2) {
685
+ return null;
686
+ }
687
+ try {
688
+ const rlpDecodedArray = fromRlp(rlpEncodedAppData);
689
+ if (rlpDecodedArray.length === 3) {
690
+ return {
691
+ code: fromHex2(rlpDecodedArray[0], "string"),
692
+ constructorArgs: rlpDecodedArray[1] && rlpDecodedArray[1] !== "0x" ? decode(fromHex2(rlpDecodedArray[1], "bytes")) : null,
693
+ leaderOnly: rlpDecodedArray[2] === "0x01",
694
+ type: "deploy",
695
+ contractAddress: recipient
696
+ };
697
+ } else if (rlpDecodedArray.length === 2) {
698
+ return {
699
+ callData: rlpDecodedArray[0] && rlpDecodedArray[0] !== "0x" ? decode(fromHex2(rlpDecodedArray[0], "bytes")) : null,
700
+ leaderOnly: rlpDecodedArray[1] === "0x01",
701
+ type: "call"
702
+ };
703
+ } else {
704
+ console.warn(
705
+ "[decodeInputData] WRITE: Unexpected RLP array length:",
706
+ rlpDecodedArray.length,
707
+ rlpDecodedArray
708
+ );
709
+ return null;
710
+ }
711
+ } catch (e) {
712
+ console.error(
713
+ "[decodeInputData] Error during comprehensive decoding:",
714
+ e,
715
+ "Raw RLP App Data:",
716
+ rlpEncodedAppData
717
+ );
718
+ return null;
719
+ }
720
+ };
721
+ var _decodeTransaction = (tx) => {
722
+ const txDataDecoded = _decodeInputData(tx.txData, tx.recipient);
723
+ const decodedTx = {
724
+ ...tx,
725
+ txData: tx.txData,
726
+ txDataDecoded,
727
+ currentTimestamp: tx.currentTimestamp.toString(),
728
+ numOfInitialValidators: tx.numOfInitialValidators.toString(),
729
+ txSlot: tx.txSlot.toString(),
730
+ createdTimestamp: tx.createdTimestamp.toString(),
731
+ lastVoteTimestamp: tx.lastVoteTimestamp.toString(),
732
+ queuePosition: tx.queuePosition.toString(),
733
+ numOfRounds: tx.numOfRounds.toString(),
734
+ readStateBlockRange: {
735
+ ...tx.readStateBlockRange,
736
+ activationBlock: tx.readStateBlockRange.activationBlock.toString(),
737
+ processingBlock: tx.readStateBlockRange.processingBlock.toString(),
738
+ proposalBlock: tx.readStateBlockRange.proposalBlock.toString()
739
+ },
740
+ statusName: transactionsStatusNumberToName[String(tx.status)],
741
+ resultName: transactionResultNumberToName[String(tx.result)],
742
+ lastRound: {
743
+ ...tx.lastRound,
744
+ round: tx.lastRound.round.toString(),
745
+ leaderIndex: tx.lastRound.leaderIndex.toString(),
746
+ votesCommitted: tx.lastRound.votesCommitted.toString(),
747
+ votesRevealed: tx.lastRound.votesRevealed.toString(),
748
+ appealBond: tx.lastRound.appealBond.toString(),
749
+ rotationsLeft: tx.lastRound.rotationsLeft.toString(),
750
+ validatorVotesName: tx.lastRound.validatorVotes.map(
751
+ (vote) => voteTypeNumberToName[String(vote)]
752
+ )
753
+ }
754
+ };
755
+ return decodedTx;
756
+ };
757
+ var _decodeLocalnetTransaction = (tx) => {
758
+ try {
759
+ const leaderReceipt = tx.consensus_data?.leader_receipt;
760
+ if (leaderReceipt) {
761
+ if (leaderReceipt.result) {
762
+ leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
763
+ }
764
+ if (leaderReceipt.calldata) {
765
+ leaderReceipt.calldata = {
766
+ base64: leaderReceipt.calldata,
767
+ ...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata))
768
+ };
769
+ }
770
+ if (leaderReceipt.eq_outputs) {
771
+ leaderReceipt.eq_outputs = Object.fromEntries(
772
+ Object.entries(leaderReceipt.eq_outputs).map(([key, value]) => {
773
+ const decodedValue = new TextDecoder().decode(b64ToArray(String(value)));
774
+ return [key, resultToUserFriendlyJson(decodedValue)];
775
+ })
776
+ );
777
+ }
778
+ }
779
+ if (tx.data?.calldata) {
780
+ tx.data.calldata = {
781
+ base64: tx.data.calldata,
782
+ ...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
783
+ };
784
+ }
785
+ } catch (e) {
786
+ console.error("Error in _decodeLocalnetTransaction:", e);
787
+ }
788
+ return tx;
789
+ };
544
790
 
545
791
  // src/config/snapID.ts
546
792
  var snapID = {
@@ -584,9 +830,7 @@ var connect = async (client, network = "localnet", snapSource = "npm") => {
584
830
  }
585
831
  const id = snapSource === "local" ? snapID.local : snapID.npm;
586
832
  const installedSnaps = await window.ethereum.request({ method: "wallet_getSnaps" });
587
- const isGenLayerSnapInstalled = Object.values(installedSnaps).some(
588
- (snap) => snap.id === id
589
- );
833
+ const isGenLayerSnapInstalled = Object.values(installedSnaps).some((snap) => snap.id === id);
590
834
  if (!isGenLayerSnapInstalled) {
591
835
  await window.ethereum.request({
592
836
  method: "wallet_requestSnaps",
@@ -651,8 +895,8 @@ function walletActions(client) {
651
895
  function chainActions(client) {
652
896
  return {
653
897
  initializeConsensusSmartContract: async (forceReset = false) => {
654
- if (client.chain?.id !== simulator.id) {
655
- throw new Error("Client is not connected to the simulator");
898
+ if (client.chain?.id !== testnet.id) {
899
+ return;
656
900
  }
657
901
  if (!forceReset && client.chain.consensusMainContract?.address && client.chain.consensusMainContract?.abi) {
658
902
  return;
@@ -679,14 +923,10 @@ function chainActions(client) {
679
923
  }
680
924
 
681
925
  // src/client/client.ts
682
- var createClient = (config = { chain: localnet }) => {
683
- const chainConfig = config.chain || localnet;
684
- if (config.endpoint) {
685
- chainConfig.rpcUrls.default.http = [config.endpoint];
686
- }
926
+ var getCustomTransportConfig = (config) => {
687
927
  const isAddress = typeof config.account !== "object";
688
- const customTransport = {
689
- async request({ method, params }) {
928
+ return {
929
+ async request({ method, params = [] }) {
690
930
  if (method.startsWith("eth_") && isAddress) {
691
931
  try {
692
932
  return await window.ethereum?.request({ method, params });
@@ -695,8 +935,11 @@ var createClient = (config = { chain: localnet }) => {
695
935
  throw err;
696
936
  }
697
937
  } else {
938
+ if (!config.chain) {
939
+ throw new Error("Chain is not set");
940
+ }
698
941
  try {
699
- const response = await fetch(chainConfig.rpcUrls.default.http[0], {
942
+ const response = await fetch(config.chain.rpcUrls.default.http[0], {
700
943
  method: "POST",
701
944
  headers: {
702
945
  "Content-Type": "application/json"
@@ -720,15 +963,40 @@ var createClient = (config = { chain: localnet }) => {
720
963
  }
721
964
  }
722
965
  };
966
+ };
967
+ var createClient = (config = { chain: localnet }) => {
968
+ const chainConfig = config.chain || localnet;
969
+ if (config.endpoint) {
970
+ chainConfig.rpcUrls.default.http = [config.endpoint];
971
+ }
972
+ const customTransport = custom(getCustomTransportConfig(config));
973
+ const publicClient = createPublicClient(chainConfig, customTransport).extend(
974
+ publicActions
975
+ );
723
976
  const baseClient = createViemClient({
724
977
  chain: chainConfig,
725
- transport: custom(customTransport),
978
+ transport: customTransport,
726
979
  ...config.account ? { account: config.account } : {}
727
- }).extend(publicActions).extend(walletActions2).extend((client) => accountActions(client)).extend((client) => transactionActions(client)).extend((client) => contractActions(client)).extend((client) => chainActions(client)).extend((client) => walletActions(client));
728
- baseClient.initializeConsensusSmartContract().catch((error) => {
980
+ });
981
+ const clientWithBasicActions = baseClient.extend(publicActions).extend(walletActions2).extend((client) => accountActions(client));
982
+ const clientWithAllActions = {
983
+ ...clientWithBasicActions,
984
+ ...contractActions(clientWithBasicActions, publicClient),
985
+ ...chainActions(clientWithBasicActions),
986
+ ...walletActions(clientWithBasicActions),
987
+ ...transactionActions(clientWithBasicActions, publicClient)
988
+ };
989
+ const finalClient = {
990
+ ...clientWithAllActions,
991
+ ...receiptActions(clientWithAllActions, publicClient)
992
+ };
993
+ finalClient.initializeConsensusSmartContract().catch((error) => {
729
994
  console.error("Failed to initialize consensus smart contract:", error);
730
995
  });
731
- return overrideContractActions(baseClient);
996
+ return finalClient;
997
+ };
998
+ var createPublicClient = (chainConfig, customTransport) => {
999
+ return createPublicViemClient({ chain: chainConfig, transport: customTransport });
732
1000
  };
733
1001
 
734
1002
  // src/accounts/account.ts
@@ -739,15 +1007,6 @@ var createAccount = (accountPrivateKey) => {
739
1007
  const account = privateKeyToAccount(privateKey);
740
1008
  return account;
741
1009
  };
742
-
743
- // src/abi/index.ts
744
- var abi_exports = {};
745
- __export(abi_exports, {
746
- calldata: () => calldata,
747
- transactions: () => transactions
748
- });
749
- var calldata = calldata_exports;
750
- var transactions = transactions_exports;
751
1010
  export {
752
1011
  abi_exports as abi,
753
1012
  chains_exports as chains,
@@ -1,9 +1,25 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkYDFRDDP5cjs = require('../chunk-YDFRDDP5.cjs');
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+ var _chunkAZSICIZ3cjs = require('../chunk-AZSICIZ3.cjs');
5
13
  require('../chunk-75ZPJI57.cjs');
6
14
 
7
15
 
8
16
 
9
- exports.CalldataAddress = _chunkYDFRDDP5cjs.CalldataAddress; exports.TransactionStatus = _chunkYDFRDDP5cjs.TransactionStatus;
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+ exports.CalldataAddress = _chunkAZSICIZ3cjs.CalldataAddress; exports.TransactionResult = _chunkAZSICIZ3cjs.TransactionResult; exports.TransactionResultNameToNumber = _chunkAZSICIZ3cjs.TransactionResultNameToNumber; exports.TransactionStatus = _chunkAZSICIZ3cjs.TransactionStatus; exports.VoteType = _chunkAZSICIZ3cjs.VoteType; exports.transactionResultNumberToName = _chunkAZSICIZ3cjs.transactionResultNumberToName; exports.transactionsStatusNameToNumber = _chunkAZSICIZ3cjs.transactionsStatusNameToNumber; exports.transactionsStatusNumberToName = _chunkAZSICIZ3cjs.transactionsStatusNumberToName; exports.voteTypeNameToNumber = _chunkAZSICIZ3cjs.voteTypeNameToNumber; exports.voteTypeNumberToName = _chunkAZSICIZ3cjs.voteTypeNumberToName;
@@ -1,3 +1,3 @@
1
- export { A as Address, a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, G as GenLayerClient, b as GenLayerMethod, j as GenLayerTransaction, M as MethodDescription, N as Network, S as SnapSource, k as TransactionDataElement, h as TransactionHash, i as TransactionStatus } from '../index-BfeTR7rO.cjs';
2
- export { S as SimulatorChain } from '../chains-C5PI_Nr_.cjs';
3
- export { Account } from 'viem';
1
+ export { Account, Address } from 'viem';
2
+ export { a as CalldataAddress, C as CalldataEncodable, f as ContractMethod, e as ContractMethodBase, c as ContractParamsArraySchemaElement, d as ContractParamsSchema, g as ContractSchema, p as DecodedCallData, D as DecodedDeployData, G as GenLayerClient, b as GenLayerMethod, r as GenLayerRawTransaction, q as GenLayerTransaction, H as Hash, M as MethodDescription, N as Network, S as SnapSource, h as TransactionHash, j as TransactionResult, m as TransactionResultNameToNumber, i as TransactionStatus, o as TransactionType, V as VoteType, l as transactionResultNumberToName, k as transactionsStatusNameToNumber, t as transactionsStatusNumberToName, n as voteTypeNameToNumber, v as voteTypeNumberToName } from '../index-kDM_9wW1.cjs';
3
+ export { G as GenLayerChain } from '../chains-BYSCF33g.cjs';