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.
- package/CHANGELOG.md +2 -0
- package/dist/chains/index.cjs +2 -2
- package/dist/chains/index.d.cts +2 -2
- package/dist/chains/index.d.ts +2 -2
- package/dist/chains/index.js +3 -3
- package/dist/chains-BYSCF33g.d.cts +18 -0
- package/dist/chains-BYSCF33g.d.ts +18 -0
- package/dist/chunk-7YZQQWJZ.js +4056 -0
- package/dist/chunk-AZSICIZ3.cjs +132 -0
- package/dist/chunk-FPFZLPXI.cjs +4056 -0
- package/dist/chunk-RS7NCSOQ.js +132 -0
- package/dist/index-BM9hOtGg.d.cts +13 -0
- package/dist/index-C7Colsnk.d.ts +13 -0
- package/dist/index-DvSbRKD5.d.ts +370 -0
- package/dist/index-kDM_9wW1.d.cts +370 -0
- package/dist/index.cjs +315 -130
- package/dist/index.d.cts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +306 -121
- package/dist/types/index.cjs +18 -2
- package/dist/types/index.d.cts +3 -3
- package/dist/types/index.d.ts +3 -3
- package/dist/types/index.js +19 -3
- package/package.json +2 -2
- package/src/accounts/IAccountActions.ts +2 -2
- package/src/accounts/actions.ts +10 -4
- package/src/chains/actions.ts +5 -5
- package/src/chains/index.ts +1 -1
- package/src/chains/localnet.ts +4 -3
- package/src/chains/testnet.ts +4015 -0
- package/src/client/client.ts +64 -21
- package/src/contracts/actions.ts +185 -137
- package/src/transactions/actions.ts +145 -21
- package/src/types/accounts.ts +1 -2
- package/src/types/chains.ts +8 -2
- package/src/types/clients.ts +14 -13
- package/src/types/transactions.ts +249 -8
- package/src/wallet/actions.ts +4 -4
- package/src/wallet/connect.ts +12 -14
- package/tests/client.test.ts +105 -45
- package/dist/chains-C5PI_Nr_.d.cts +0 -13
- package/dist/chains-C5PI_Nr_.d.ts +0 -13
- package/dist/chunk-I6HC44KD.cjs +0 -72
- package/dist/chunk-K72OSU5N.js +0 -28
- package/dist/chunk-WEXFFND6.js +0 -72
- package/dist/chunk-YDFRDDP5.cjs +0 -28
- package/dist/index-B8E0qiOq.d.cts +0 -13
- package/dist/index-BCbofn6t.d.cts +0 -188
- package/dist/index-Ctmshvtv.d.ts +0 -188
- package/dist/index-ZoW0HQ_m.d.ts +0 -13
- package/src/chains/simulator.ts +0 -30
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import * as viem from 'viem';
|
|
2
2
|
import { Account, Address } from 'viem';
|
|
3
|
-
import {
|
|
4
|
-
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-
|
|
3
|
+
import { G as GenLayerChain } from './chains-BYSCF33g.js';
|
|
4
|
+
import { G as GenLayerClient, C as CalldataEncodable, T as TransactionDataElement } from './index-DvSbRKD5.js';
|
|
5
5
|
import * as abitype from 'abitype';
|
|
6
|
-
import * as
|
|
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-
|
|
8
|
+
export { i as chains } from './index-C7Colsnk.js';
|
|
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<
|
|
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
|
-
|
|
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>;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
import {
|
|
2
2
|
chains_exports,
|
|
3
3
|
localnet,
|
|
4
|
-
|
|
5
|
-
} from "./chunk-
|
|
4
|
+
testnet
|
|
5
|
+
} from "./chunk-7YZQQWJZ.js";
|
|
6
6
|
import {
|
|
7
|
-
CalldataAddress
|
|
8
|
-
|
|
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 {
|
|
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 ({
|
|
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
|
|
415
|
-
client
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
};
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
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
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
}
|
|
503
|
-
return
|
|
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
|
|
@@ -564,25 +630,34 @@ function resultToUserFriendlyJson(cd64) {
|
|
|
564
630
|
}
|
|
565
631
|
|
|
566
632
|
// src/transactions/actions.ts
|
|
567
|
-
|
|
633
|
+
import { fromRlp, fromHex as fromHex2 } from "viem";
|
|
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({
|
|
641
|
+
const transaction = await client.getTransaction({
|
|
642
|
+
hash
|
|
643
|
+
});
|
|
575
644
|
if (!transaction) {
|
|
576
645
|
throw new Error("Transaction not found");
|
|
577
646
|
}
|
|
578
|
-
|
|
579
|
-
|
|
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
|
+
}
|
|
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
|
|
660
|
+
return receiptActions(client, publicClient).waitForTransactionReceipt({
|
|
586
661
|
hash,
|
|
587
662
|
status,
|
|
588
663
|
interval,
|
|
@@ -590,8 +665,96 @@ 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: 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
|
+
};
|
|
593
721
|
var _decodeTransaction = (tx) => {
|
|
594
|
-
|
|
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) => {
|
|
595
758
|
try {
|
|
596
759
|
const leaderReceipt = tx.consensus_data?.leader_receipt;
|
|
597
760
|
if (leaderReceipt) {
|
|
@@ -613,14 +776,14 @@ var _decodeTransaction = (tx) => {
|
|
|
613
776
|
);
|
|
614
777
|
}
|
|
615
778
|
}
|
|
616
|
-
if (tx.data
|
|
779
|
+
if (tx.data?.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
|
|
786
|
+
console.error("Error in _decodeLocalnetTransaction:", e);
|
|
624
787
|
}
|
|
625
788
|
return tx;
|
|
626
789
|
};
|
|
@@ -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",
|
|
@@ -734,8 +895,8 @@ function walletActions(client) {
|
|
|
734
895
|
function chainActions(client) {
|
|
735
896
|
return {
|
|
736
897
|
initializeConsensusSmartContract: async (forceReset = false) => {
|
|
737
|
-
if (client.chain?.id !==
|
|
738
|
-
|
|
898
|
+
if (client.chain?.id !== testnet.id) {
|
|
899
|
+
return;
|
|
739
900
|
}
|
|
740
901
|
if (!forceReset && client.chain.consensusMainContract?.address && client.chain.consensusMainContract?.abi) {
|
|
741
902
|
return;
|
|
@@ -762,14 +923,10 @@ function chainActions(client) {
|
|
|
762
923
|
}
|
|
763
924
|
|
|
764
925
|
// src/client/client.ts
|
|
765
|
-
var
|
|
766
|
-
const chainConfig = config.chain || 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
|
-
|
|
772
|
-
async request({ method, params }) {
|
|
928
|
+
return {
|
|
929
|
+
async request({ method, params = [] }) {
|
|
773
930
|
if (method.startsWith("eth_") && isAddress) {
|
|
774
931
|
try {
|
|
775
932
|
return await window.ethereum?.request({ method, params });
|
|
@@ -778,8 +935,11 @@ var createClient = (config = { chain: localnet }) => {
|
|
|
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(
|
|
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: localnet }) => {
|
|
|
803
963
|
}
|
|
804
964
|
}
|
|
805
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
|
+
);
|
|
806
976
|
const baseClient = createViemClient({
|
|
807
977
|
chain: chainConfig,
|
|
808
|
-
transport:
|
|
978
|
+
transport: customTransport,
|
|
809
979
|
...config.account ? { account: config.account } : {}
|
|
810
|
-
})
|
|
811
|
-
baseClient.
|
|
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) => {
|
|
812
994
|
console.error("Failed to initialize consensus smart contract:", error);
|
|
813
995
|
});
|
|
814
|
-
return
|
|
996
|
+
return finalClient;
|
|
997
|
+
};
|
|
998
|
+
var createPublicClient = (chainConfig, customTransport) => {
|
|
999
|
+
return createPublicViemClient({ chain: chainConfig, transport: customTransport });
|
|
815
1000
|
};
|
|
816
1001
|
|
|
817
1002
|
// src/accounts/account.ts
|
package/dist/types/index.cjs
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
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
|
-
|
|
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;
|
package/dist/types/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { S as
|
|
3
|
-
export {
|
|
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';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { S as
|
|
3
|
-
export {
|
|
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-DvSbRKD5.js';
|
|
3
|
+
export { G as GenLayerChain } from '../chains-BYSCF33g.js';
|
package/dist/types/index.js
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CalldataAddress,
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
TransactionResult,
|
|
4
|
+
TransactionResultNameToNumber,
|
|
5
|
+
TransactionStatus,
|
|
6
|
+
VoteType,
|
|
7
|
+
transactionResultNumberToName,
|
|
8
|
+
transactionsStatusNameToNumber,
|
|
9
|
+
transactionsStatusNumberToName,
|
|
10
|
+
voteTypeNameToNumber,
|
|
11
|
+
voteTypeNumberToName
|
|
12
|
+
} from "../chunk-RS7NCSOQ.js";
|
|
5
13
|
import "../chunk-MLKGABMK.js";
|
|
6
14
|
export {
|
|
7
15
|
CalldataAddress,
|
|
8
|
-
|
|
16
|
+
TransactionResult,
|
|
17
|
+
TransactionResultNameToNumber,
|
|
18
|
+
TransactionStatus,
|
|
19
|
+
VoteType,
|
|
20
|
+
transactionResultNumberToName,
|
|
21
|
+
transactionsStatusNameToNumber,
|
|
22
|
+
transactionsStatusNumberToName,
|
|
23
|
+
voteTypeNameToNumber,
|
|
24
|
+
voteTypeNumberToName
|
|
9
25
|
};
|