genlayer-js 0.9.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 (51) hide show
  1. package/CHANGELOG.md +2 -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 +315 -130
  17. package/dist/index.d.cts +6 -6
  18. package/dist/index.d.ts +6 -6
  19. package/dist/index.js +306 -121
  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 +145 -21
  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 +249 -8
  38. package/src/wallet/actions.ts +4 -4
  39. package/src/wallet/connect.ts +12 -14
  40. package/tests/client.test.ts +105 -45
  41. package/dist/chains-C5PI_Nr_.d.cts +0 -13
  42. package/dist/chains-C5PI_Nr_.d.ts +0 -13
  43. package/dist/chunk-I6HC44KD.cjs +0 -72
  44. package/dist/chunk-K72OSU5N.js +0 -28
  45. package/dist/chunk-WEXFFND6.js +0 -72
  46. package/dist/chunk-YDFRDDP5.cjs +0 -28
  47. package/dist/index-B8E0qiOq.d.cts +0 -13
  48. package/dist/index-BCbofn6t.d.cts +0 -188
  49. package/dist/index-Ctmshvtv.d.ts +0 -188
  50. package/dist/index-ZoW0HQ_m.d.ts +0 -13
  51. package/src/chains/simulator.ts +0 -30
package/dist/index.cjs CHANGED
@@ -2,22 +2,32 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkI6HC44KDcjs = require('./chunk-I6HC44KD.cjs');
5
+ var _chunkFPFZLPXIcjs = require('./chunk-FPFZLPXI.cjs');
6
6
 
7
7
 
8
- var _chunkYDFRDDP5cjs = require('./chunk-YDFRDDP5.cjs');
8
+
9
+
10
+
11
+
12
+ var _chunkAZSICIZ3cjs = require('./chunk-AZSICIZ3.cjs');
9
13
 
10
14
 
11
15
  var _chunk75ZPJI57cjs = require('./chunk-75ZPJI57.cjs');
12
16
 
13
17
  // src/client/client.ts
18
+
19
+
20
+
21
+
22
+
23
+
14
24
  var _viem = require('viem');
15
25
 
16
26
  // src/accounts/actions.ts
17
27
  function accountActions(client) {
18
28
  return {
19
29
  fundAccount: async ({ address, amount }) => {
20
- if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !== _chunkI6HC44KDcjs.localnet.id) {
30
+ if (_optionalChain([client, 'access', _ => _.chain, 'optionalAccess', _2 => _2.id]) !== _chunkFPFZLPXIcjs.localnet.id) {
21
31
  throw new Error("Client is not connected to the localnet");
22
32
  }
23
33
  return client.request({
@@ -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 || _optionalChain([client, 'access', _3 => _3.account, 'optionalAccess', _4 => _4.address]);
30
43
  if (!addressToUse) {
31
44
  throw new Error("No address provided and no account is connected");
@@ -168,7 +181,7 @@ function encodeImpl(to, data) {
168
181
  }
169
182
  } else if (data instanceof Map) {
170
183
  encodeMap(to, data);
171
- } else if (data instanceof _chunkYDFRDDP5cjs.CalldataAddress) {
184
+ } else if (data instanceof _chunkAZSICIZ3cjs.CalldataAddress) {
172
185
  to.push(SPECIAL_ADDR);
173
186
  for (const c of data.bytes) {
174
187
  to.push(c);
@@ -217,7 +230,7 @@ function decodeImpl(data, index) {
217
230
  case BigInt(SPECIAL_ADDR): {
218
231
  const res = data.slice(index.i, index.i + 20);
219
232
  index.i += 20;
220
- return new (0, _chunkYDFRDDP5cjs.CalldataAddress)(res);
233
+ return new (0, _chunkAZSICIZ3cjs.CalldataAddress)(res);
221
234
  }
222
235
  }
223
236
  const type = Number(cur & 0xffn) & (1 << BITS_IN_TYPE) - 1;
@@ -329,7 +342,7 @@ function toStringImpl(data, to) {
329
342
  to.push("]");
330
343
  } else if (data instanceof Map) {
331
344
  toStringImplMap(data.entries(), to);
332
- } else if (data instanceof _chunkYDFRDDP5cjs.CalldataAddress) {
345
+ } else if (data instanceof _chunkAZSICIZ3cjs.CalldataAddress) {
333
346
  to.push("addr#");
334
347
  for (const c of data.bytes) {
335
348
  to.push(c.toString(16));
@@ -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 !== _chunkFPFZLPXIcjs.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 !== _chunkFPFZLPXIcjs.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: [_viem.toHex.call(void 0, 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 = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _5 => _5.address]), () => ( _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.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 = _viem.fromHex.call(void 0, 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: _viem.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 = _nullishCoalesce(_optionalChain([account, 'optionalAccess', _5 => _5.address]), () => ( _optionalChain([client, 'access', _6 => _6.account, 'optionalAccess', _7 => _7.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 = _viem.fromHex.call(void 0, 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(_viem.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 (!_optionalChain([client, 'access', _8 => _8.chain, 'access', _9 => _9.consensusMainContract, 'optionalAccess', _10 => _10.address])) {
461
- throw new Error(
462
- "Consensus main contract not initialized. Please ensure client is properly initialized."
463
- );
464
- }
465
- const encodedData = _viem.encodeFunctionData.call(void 0, {
466
- abi: _optionalChain([client, 'access', _11 => _11.chain, 'access', _12 => _12.consensusMainContract, 'optionalAccess', _13 => _13.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: _optionalChain([client, 'access', _14 => _14.chain, 'access', _15 => _15.consensusMainContract, 'optionalAccess', _16 => _16.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 (!_optionalChain([client, 'access', _8 => _8.chain, 'access', _9 => _9.consensusMainContract, 'optionalAccess', _10 => _10.address])) {
518
+ throw new Error("Consensus main contract not initialized. Please ensure client is properly initialized.");
519
+ }
520
+ const encodedData = _viem.encodeFunctionData.call(void 0, {
521
+ abi: _optionalChain([client, 'access', _11 => _11.chain, 'access', _12 => _12.consensusMainContract, 'optionalAccess', _13 => _13.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: _optionalChain([client, 'access', _14 => _14.chain, 'access', _15 => _15.consensusMainContract, 'optionalAccess', _16 => _16.address]),
535
+ data: encodedData,
536
+ type: "legacy",
537
+ nonce: Number(nonce),
538
+ value: _nullishCoalesce(value, () => ( 0n))
539
+ });
540
+ if (_optionalChain([senderAccount, 'optionalAccess', _17 => _17.type]) !== "local") {
541
+ const formattedRequest = {
542
+ from: transactionRequest.from,
543
+ to: transactionRequest.to,
480
544
  data: encodedData,
481
- type: "legacy",
482
- nonce,
483
- value: _nullishCoalesce(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 (_optionalChain([senderAccount, 'optionalAccess', _17 => _17.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 (!_optionalChain([senderAccount, 'optionalAccess', _18 => _18.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 (!_optionalChain([senderAccount, 'optionalAccess', _18 => _18.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 = _viem.parseEventLogs.call(void 0, {
562
+ abi: _optionalChain([client, 'access', _19 => _19.chain, 'access', _20 => _20.consensusMainContract, 'optionalAccess', _21 => _21.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
@@ -564,25 +630,34 @@ function resultToUserFriendlyJson(cd64) {
564
630
  }
565
631
 
566
632
  // src/transactions/actions.ts
567
- var transactionActions = (client) => ({
633
+
634
+ var receiptActions = (client, publicClient) => ({
568
635
  waitForTransactionReceipt: async ({
569
636
  hash,
570
637
  status = "ACCEPTED" /* ACCEPTED */,
571
638
  interval = transactionsConfig.waitInterval,
572
639
  retries = transactionsConfig.retries
573
640
  }) => {
574
- const transaction = await client.getTransaction({ hash });
641
+ const transaction = await client.getTransaction({
642
+ hash
643
+ });
575
644
  if (!transaction) {
576
645
  throw new Error("Transaction not found");
577
646
  }
578
- if (transaction.status === status || status === "ACCEPTED" /* ACCEPTED */ && transaction.status === "FINALIZED" /* FINALIZED */) {
579
- return _decodeTransaction(transaction);
647
+ const transactionStatusString = String(transaction.status);
648
+ const transactionStatusFinalized = _chunkAZSICIZ3cjs.transactionsStatusNameToNumber["FINALIZED" /* FINALIZED */];
649
+ const requestedStatus = _chunkAZSICIZ3cjs.transactionsStatusNameToNumber[status];
650
+ if (transactionStatusString === requestedStatus || status === "ACCEPTED" /* ACCEPTED */ && transactionStatusString === transactionStatusFinalized) {
651
+ if (client.chain.id === _chunkFPFZLPXIcjs.localnet.id) {
652
+ return _decodeLocalnetTransaction(transaction);
653
+ }
654
+ return transaction;
580
655
  }
581
656
  if (retries === 0) {
582
657
  throw new Error("Transaction status is not " + status);
583
658
  }
584
659
  await sleep(interval);
585
- return transactionActions(client).waitForTransactionReceipt({
660
+ return receiptActions(client, publicClient).waitForTransactionReceipt({
586
661
  hash,
587
662
  status,
588
663
  interval,
@@ -590,10 +665,98 @@ var transactionActions = (client) => ({
590
665
  });
591
666
  }
592
667
  });
668
+ var transactionActions = (client, publicClient) => ({
669
+ getTransaction: async ({ hash }) => {
670
+ const transaction = await publicClient.readContract({
671
+ address: _optionalChain([client, 'access', _22 => _22.chain, 'access', _23 => _23.consensusDataContract, 'optionalAccess', _24 => _24.address]),
672
+ abi: _optionalChain([client, 'access', _25 => _25.chain, 'access', _26 => _26.consensusDataContract, 'optionalAccess', _27 => _27.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 = _viem.fromRlp.call(void 0, rlpEncodedAppData);
689
+ if (rlpDecodedArray.length === 3) {
690
+ return {
691
+ code: _viem.fromHex.call(void 0, rlpDecodedArray[0], "string"),
692
+ constructorArgs: rlpDecodedArray[1] && rlpDecodedArray[1] !== "0x" ? decode(_viem.fromHex.call(void 0, 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(_viem.fromHex.call(void 0, 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
+ };
593
721
  var _decodeTransaction = (tx) => {
594
- if (!tx.data) return 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: _chunkAZSICIZ3cjs.transactionsStatusNumberToName[String(tx.status)],
741
+ resultName: _chunkAZSICIZ3cjs.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) => _chunkAZSICIZ3cjs.voteTypeNumberToName[String(vote)]
752
+ )
753
+ }
754
+ };
755
+ return decodedTx;
756
+ };
757
+ var _decodeLocalnetTransaction = (tx) => {
595
758
  try {
596
- const leaderReceipt = _optionalChain([tx, 'access', _19 => _19.consensus_data, 'optionalAccess', _20 => _20.leader_receipt]);
759
+ const leaderReceipt = _optionalChain([tx, 'access', _28 => _28.consensus_data, 'optionalAccess', _29 => _29.leader_receipt]);
597
760
  if (leaderReceipt) {
598
761
  if (leaderReceipt.result) {
599
762
  leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
@@ -613,14 +776,14 @@ var _decodeTransaction = (tx) => {
613
776
  );
614
777
  }
615
778
  }
616
- if (tx.data.calldata) {
779
+ if (_optionalChain([tx, 'access', _30 => _30.data, 'optionalAccess', _31 => _31.calldata])) {
617
780
  tx.data.calldata = {
618
781
  base64: tx.data.calldata,
619
782
  ...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata))
620
783
  };
621
784
  }
622
785
  } catch (e) {
623
- console.error("Error decoding transaction:", e);
786
+ console.error("Error in _decodeLocalnetTransaction:", e);
624
787
  }
625
788
  return tx;
626
789
  };
@@ -633,7 +796,7 @@ var snapID = {
633
796
 
634
797
  // src/wallet/connect.ts
635
798
  var networks = {
636
- localnet: _chunkI6HC44KDcjs.localnet
799
+ localnet: _chunkFPFZLPXIcjs.localnet
637
800
  };
638
801
  var connect = async (client, network = "localnet", snapSource = "npm") => {
639
802
  if (!window.ethereum) {
@@ -652,7 +815,7 @@ var connect = async (client, network = "localnet", snapSource = "npm") => {
652
815
  chainName: selectedNetwork.name,
653
816
  rpcUrls: selectedNetwork.rpcUrls.default.http,
654
817
  nativeCurrency: selectedNetwork.nativeCurrency,
655
- blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _21 => _21.blockExplorers, 'optionalAccess', _22 => _22.default, 'access', _23 => _23.url])]
818
+ blockExplorerUrls: [_optionalChain([selectedNetwork, 'access', _32 => _32.blockExplorers, 'optionalAccess', _33 => _33.default, 'access', _34 => _34.url])]
656
819
  };
657
820
  const currentChainId = await window.ethereum.request({ method: "eth_chainId" });
658
821
  if (currentChainId !== chainIdHex) {
@@ -667,9 +830,7 @@ var connect = async (client, network = "localnet", snapSource = "npm") => {
667
830
  }
668
831
  const id = snapSource === "local" ? snapID.local : snapID.npm;
669
832
  const installedSnaps = await window.ethereum.request({ method: "wallet_getSnaps" });
670
- const isGenLayerSnapInstalled = Object.values(installedSnaps).some(
671
- (snap) => snap.id === id
672
- );
833
+ const isGenLayerSnapInstalled = Object.values(installedSnaps).some((snap) => snap.id === id);
673
834
  if (!isGenLayerSnapInstalled) {
674
835
  await window.ethereum.request({
675
836
  method: "wallet_requestSnaps",
@@ -688,10 +849,10 @@ var metamaskClient = async (snapSource = "npm") => {
688
849
  }
689
850
  const isFlask = async () => {
690
851
  try {
691
- const clientVersion = await _optionalChain([window, 'access', _24 => _24.ethereum, 'optionalAccess', _25 => _25.request, 'call', _26 => _26({
852
+ const clientVersion = await _optionalChain([window, 'access', _35 => _35.ethereum, 'optionalAccess', _36 => _36.request, 'call', _37 => _37({
692
853
  method: "web3_clientVersion"
693
854
  })]);
694
- return _optionalChain([clientVersion, 'optionalAccess', _27 => _27.includes, 'call', _28 => _28("flask")]);
855
+ return _optionalChain([clientVersion, 'optionalAccess', _38 => _38.includes, 'call', _39 => _39("flask")]);
695
856
  } catch (error) {
696
857
  console.error("Error detecting Flask:", error);
697
858
  return false;
@@ -699,7 +860,7 @@ var metamaskClient = async (snapSource = "npm") => {
699
860
  };
700
861
  const installedSnaps = async () => {
701
862
  try {
702
- return await _optionalChain([window, 'access', _29 => _29.ethereum, 'optionalAccess', _30 => _30.request, 'call', _31 => _31({
863
+ return await _optionalChain([window, 'access', _40 => _40.ethereum, 'optionalAccess', _41 => _41.request, 'call', _42 => _42({
703
864
  method: "wallet_getSnaps"
704
865
  })]);
705
866
  } catch (error) {
@@ -734,10 +895,10 @@ function walletActions(client) {
734
895
  function chainActions(client) {
735
896
  return {
736
897
  initializeConsensusSmartContract: async (forceReset = false) => {
737
- if (_optionalChain([client, 'access', _32 => _32.chain, 'optionalAccess', _33 => _33.id]) !== _chunkI6HC44KDcjs.simulator.id) {
738
- throw new Error("Client is not connected to the simulator");
898
+ if (_optionalChain([client, 'access', _43 => _43.chain, 'optionalAccess', _44 => _44.id]) !== _chunkFPFZLPXIcjs.testnet.id) {
899
+ return;
739
900
  }
740
- if (!forceReset && _optionalChain([client, 'access', _34 => _34.chain, 'access', _35 => _35.consensusMainContract, 'optionalAccess', _36 => _36.address]) && _optionalChain([client, 'access', _37 => _37.chain, 'access', _38 => _38.consensusMainContract, 'optionalAccess', _39 => _39.abi])) {
901
+ if (!forceReset && _optionalChain([client, 'access', _45 => _45.chain, 'access', _46 => _46.consensusMainContract, 'optionalAccess', _47 => _47.address]) && _optionalChain([client, 'access', _48 => _48.chain, 'access', _49 => _49.consensusMainContract, 'optionalAccess', _50 => _50.abi])) {
741
902
  return;
742
903
  }
743
904
  const contractsResponse = await fetch(client.chain.rpcUrls.default.http[0], {
@@ -762,24 +923,23 @@ function chainActions(client) {
762
923
  }
763
924
 
764
925
  // src/client/client.ts
765
- var createClient = (config = { chain: _chunkI6HC44KDcjs.localnet }) => {
766
- const chainConfig = config.chain || _chunkI6HC44KDcjs.localnet;
767
- if (config.endpoint) {
768
- chainConfig.rpcUrls.default.http = [config.endpoint];
769
- }
926
+ var getCustomTransportConfig = (config) => {
770
927
  const isAddress = typeof config.account !== "object";
771
- const customTransport = {
772
- async request({ method, params }) {
928
+ return {
929
+ async request({ method, params = [] }) {
773
930
  if (method.startsWith("eth_") && isAddress) {
774
931
  try {
775
- return await _optionalChain([window, 'access', _40 => _40.ethereum, 'optionalAccess', _41 => _41.request, 'call', _42 => _42({ method, params })]);
932
+ return await _optionalChain([window, 'access', _51 => _51.ethereum, 'optionalAccess', _52 => _52.request, 'call', _53 => _53({ method, params })]);
776
933
  } catch (err) {
777
934
  console.warn(`Error using window.ethereum for method ${method}:`, err);
778
935
  throw err;
779
936
  }
780
937
  } else {
938
+ if (!config.chain) {
939
+ throw new Error("Chain is not set");
940
+ }
781
941
  try {
782
- const response = await fetch(chainConfig.rpcUrls.default.http[0], {
942
+ const response = await fetch(config.chain.rpcUrls.default.http[0], {
783
943
  method: "POST",
784
944
  headers: {
785
945
  "Content-Type": "application/json"
@@ -803,15 +963,40 @@ var createClient = (config = { chain: _chunkI6HC44KDcjs.localnet }) => {
803
963
  }
804
964
  }
805
965
  };
966
+ };
967
+ var createClient = (config = { chain: _chunkFPFZLPXIcjs.localnet }) => {
968
+ const chainConfig = config.chain || _chunkFPFZLPXIcjs.localnet;
969
+ if (config.endpoint) {
970
+ chainConfig.rpcUrls.default.http = [config.endpoint];
971
+ }
972
+ const customTransport = _viem.custom.call(void 0, getCustomTransportConfig(config));
973
+ const publicClient = createPublicClient(chainConfig, customTransport).extend(
974
+ _viem.publicActions
975
+ );
806
976
  const baseClient = _viem.createClient.call(void 0, {
807
977
  chain: chainConfig,
808
- transport: _viem.custom.call(void 0, customTransport),
978
+ transport: customTransport,
809
979
  ...config.account ? { account: config.account } : {}
810
- }).extend(_viem.publicActions).extend(_viem.walletActions).extend((client) => accountActions(client)).extend((client) => transactionActions(client)).extend((client) => contractActions(client)).extend((client) => chainActions(client)).extend((client) => walletActions(client));
811
- baseClient.initializeConsensusSmartContract().catch((error) => {
980
+ });
981
+ const clientWithBasicActions = baseClient.extend(_viem.publicActions).extend(_viem.walletActions).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) => {
812
994
  console.error("Failed to initialize consensus smart contract:", error);
813
995
  });
814
- return overrideContractActions(baseClient);
996
+ return finalClient;
997
+ };
998
+ var createPublicClient = (chainConfig, customTransport) => {
999
+ return _viem.createPublicClient.call(void 0, { chain: chainConfig, transport: customTransport });
815
1000
  };
816
1001
 
817
1002
  // src/accounts/account.ts
@@ -828,4 +1013,4 @@ var createAccount = (accountPrivateKey) => {
828
1013
 
829
1014
 
830
1015
 
831
- exports.abi = abi_exports; exports.chains = _chunkI6HC44KDcjs.chains_exports; exports.createAccount = createAccount; exports.createClient = createClient; exports.generatePrivateKey = generatePrivateKey;
1016
+ exports.abi = abi_exports; exports.chains = _chunkFPFZLPXIcjs.chains_exports; exports.createAccount = createAccount; exports.createClient = createClient; exports.generatePrivateKey = generatePrivateKey;
package/dist/index.d.cts CHANGED
@@ -1,11 +1,11 @@
1
1
  import * as viem from 'viem';
2
2
  import { Account, Address } from 'viem';
3
- import { S as SimulatorChain } from './chains-C5PI_Nr_.cjs';
4
- import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-BCbofn6t.cjs';
3
+ import { G as GenLayerChain } from './chains-BYSCF33g.cjs';
4
+ import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-kDM_9wW1.cjs';
5
5
  import * as abitype from 'abitype';
6
- import * as viem__types_experimental_eip7702_types_authorization from 'viem/_types/experimental/eip7702/types/authorization';
6
+ import * as viem__types_types_authorization from 'viem/_types/types/authorization';
7
7
  import * as viem_accounts from 'viem/accounts';
8
- export { i as chains } from './index-B8E0qiOq.cjs';
8
+ export { i as chains } from './index-BM9hOtGg.cjs';
9
9
 
10
10
  interface ClientConfig {
11
11
  chain?: {
@@ -31,7 +31,7 @@ interface ClientConfig {
31
31
  endpoint?: string;
32
32
  account?: Account | Address;
33
33
  }
34
- declare const createClient: (config?: ClientConfig) => GenLayerClient<SimulatorChain>;
34
+ declare const createClient: (config?: ClientConfig) => GenLayerClient<GenLayerChain>;
35
35
 
36
36
  declare const generatePrivateKey: () => `0x${string}`;
37
37
  declare const createAccount: (accountPrivateKey?: `0x${string}`) => {
@@ -40,7 +40,7 @@ declare const createAccount: (accountPrivateKey?: `0x${string}`) => {
40
40
  sign: (parameters: {
41
41
  hash: viem.Hash;
42
42
  }) => Promise<viem.Hex>;
43
- experimental_signAuthorization: (parameters: viem__types_experimental_eip7702_types_authorization.Authorization) => Promise<viem_accounts.SignAuthorizationReturnType>;
43
+ signAuthorization: (parameters: viem__types_types_authorization.AuthorizationRequest) => Promise<viem_accounts.SignAuthorizationReturnType>;
44
44
  signMessage: ({ message }: {
45
45
  message: viem.SignableMessage;
46
46
  }) => Promise<viem.Hex>;