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
@@ -1,10 +1,26 @@
1
1
  import {GenLayerClient} from "../types/clients";
2
- import {TransactionHash, TransactionStatus, GenLayerTransaction} from "../types/transactions";
2
+ import {
3
+ TransactionHash,
4
+ TransactionStatus,
5
+ GenLayerTransaction,
6
+ GenLayerRawTransaction,
7
+ transactionsStatusNameToNumber,
8
+ transactionsStatusNumberToName,
9
+ transactionResultNumberToName,
10
+ VoteType,
11
+ voteTypeNumberToName,
12
+ DecodedCallData,
13
+ DecodedDeployData,
14
+ } from "../types/transactions";
3
15
  import {transactionsConfig} from "../config/transactions";
4
16
  import {sleep} from "../utils/async";
5
- import {SimulatorChain} from "@/types";
17
+ import {GenLayerChain} from "@/types";
18
+ import {b64ToArray, calldataToUserFriendlyJson, resultToUserFriendlyJson} from "@/utils/jsonifier";
19
+ import {Abi, PublicClient, fromRlp, fromHex, Hex, Address} from "viem";
20
+ import * as calldataAbi from "@/abi/calldata";
21
+ import {localnet} from "@/chains/localnet";
6
22
 
7
- export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
23
+ export const receiptActions = (client: GenLayerClient<GenLayerChain>, publicClient: PublicClient) => ({
8
24
  waitForTransactionReceipt: async ({
9
25
  hash,
10
26
  status = TransactionStatus.ACCEPTED,
@@ -16,16 +32,23 @@ export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
16
32
  interval?: number;
17
33
  retries?: number;
18
34
  }): Promise<GenLayerTransaction> => {
19
- const transaction = await client.getTransaction({hash});
35
+ const transaction = await client.getTransaction({
36
+ hash,
37
+ });
20
38
 
21
39
  if (!transaction) {
22
40
  throw new Error("Transaction not found");
23
41
  }
24
-
42
+ const transactionStatusString = String(transaction.status);
43
+ const transactionStatusFinalized = transactionsStatusNameToNumber[TransactionStatus.FINALIZED];
44
+ const requestedStatus = transactionsStatusNameToNumber[status];
25
45
  if (
26
- transaction.status === status ||
27
- (status === TransactionStatus.ACCEPTED && transaction.status === TransactionStatus.FINALIZED)
46
+ transactionStatusString === requestedStatus ||
47
+ (status === TransactionStatus.ACCEPTED && transactionStatusString === transactionStatusFinalized)
28
48
  ) {
49
+ if (client.chain.id === localnet.id) {
50
+ return _decodeLocalnetTransaction(transaction as unknown as GenLayerTransaction);
51
+ }
29
52
  return transaction;
30
53
  }
31
54
 
@@ -34,7 +57,7 @@ export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
34
57
  }
35
58
 
36
59
  await sleep(interval);
37
- return transactionActions(client).waitForTransactionReceipt({
60
+ return receiptActions(client, publicClient).waitForTransactionReceipt({
38
61
  hash,
39
62
  status,
40
63
  interval,
@@ -42,3 +65,145 @@ export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
42
65
  });
43
66
  },
44
67
  });
68
+
69
+ export const transactionActions = (client: GenLayerClient<GenLayerChain>, publicClient: PublicClient) => ({
70
+ getTransaction: async ({hash}: {hash: TransactionHash}): Promise<GenLayerTransaction> => {
71
+ const transaction = (await publicClient.readContract({
72
+ address: client.chain.consensusDataContract?.address as Address,
73
+ abi: client.chain.consensusDataContract?.abi as Abi,
74
+ functionName: "getTransactionData",
75
+ args: [
76
+ hash,
77
+ Math.round(new Date().getTime() / 1000), // unix seconds
78
+ ],
79
+ })) as unknown as GenLayerRawTransaction;
80
+ return _decodeTransaction(transaction);
81
+ },
82
+ });
83
+
84
+ const _decodeInputData = (
85
+ rlpEncodedAppData: Hex | undefined | null,
86
+ recipient: Address,
87
+ ): DecodedDeployData | DecodedCallData | null => {
88
+ if (!rlpEncodedAppData || rlpEncodedAppData === "0x" || rlpEncodedAppData.length <= 2) {
89
+ return null;
90
+ }
91
+ try {
92
+ const rlpDecodedArray = fromRlp(rlpEncodedAppData) as Hex[];
93
+
94
+ if (rlpDecodedArray.length === 3) {
95
+ return {
96
+ code: fromHex(rlpDecodedArray[0], "string") as `0x${string}`,
97
+ constructorArgs:
98
+ rlpDecodedArray[1] && rlpDecodedArray[1] !== "0x"
99
+ ? calldataAbi.decode(fromHex(rlpDecodedArray[1], "bytes"))
100
+ : null,
101
+ leaderOnly: rlpDecodedArray[2] === "0x01",
102
+ type: "deploy",
103
+ contractAddress: recipient,
104
+ };
105
+ } else if (rlpDecodedArray.length === 2) {
106
+ return {
107
+ callData:
108
+ rlpDecodedArray[0] && rlpDecodedArray[0] !== "0x"
109
+ ? calldataAbi.decode(fromHex(rlpDecodedArray[0], "bytes"))
110
+ : null,
111
+ leaderOnly: rlpDecodedArray[1] === "0x01",
112
+ type: "call",
113
+ };
114
+ } else {
115
+ console.warn(
116
+ "[decodeInputData] WRITE: Unexpected RLP array length:",
117
+ rlpDecodedArray.length,
118
+ rlpDecodedArray,
119
+ );
120
+ return null;
121
+ }
122
+ } catch (e) {
123
+ console.error(
124
+ "[decodeInputData] Error during comprehensive decoding:",
125
+ e,
126
+ "Raw RLP App Data:",
127
+ rlpEncodedAppData,
128
+ );
129
+ return null;
130
+ }
131
+ };
132
+
133
+ const _decodeTransaction = (tx: GenLayerRawTransaction): GenLayerTransaction => {
134
+ const txDataDecoded = _decodeInputData(tx.txData, tx.recipient);
135
+
136
+ const decodedTx = {
137
+ ...tx,
138
+ txData: tx.txData,
139
+ txDataDecoded: txDataDecoded,
140
+
141
+ currentTimestamp: tx.currentTimestamp.toString(),
142
+ numOfInitialValidators: tx.numOfInitialValidators.toString(),
143
+ txSlot: tx.txSlot.toString(),
144
+ createdTimestamp: tx.createdTimestamp.toString(),
145
+ lastVoteTimestamp: tx.lastVoteTimestamp.toString(),
146
+ queuePosition: tx.queuePosition.toString(),
147
+ numOfRounds: tx.numOfRounds.toString(),
148
+
149
+ readStateBlockRange: {
150
+ ...tx.readStateBlockRange,
151
+ activationBlock: tx.readStateBlockRange.activationBlock.toString(),
152
+ processingBlock: tx.readStateBlockRange.processingBlock.toString(),
153
+ proposalBlock: tx.readStateBlockRange.proposalBlock.toString(),
154
+ },
155
+
156
+ statusName:
157
+ transactionsStatusNumberToName[String(tx.status) as keyof typeof transactionsStatusNumberToName],
158
+ resultName:
159
+ transactionResultNumberToName[String(tx.result) as keyof typeof transactionResultNumberToName],
160
+
161
+ lastRound: {
162
+ ...tx.lastRound,
163
+ round: tx.lastRound.round.toString(),
164
+ leaderIndex: tx.lastRound.leaderIndex.toString(),
165
+ votesCommitted: tx.lastRound.votesCommitted.toString(),
166
+ votesRevealed: tx.lastRound.votesRevealed.toString(),
167
+ appealBond: tx.lastRound.appealBond.toString(),
168
+ rotationsLeft: tx.lastRound.rotationsLeft.toString(),
169
+ validatorVotesName: tx.lastRound.validatorVotes.map(
170
+ vote => voteTypeNumberToName[String(vote) as keyof typeof voteTypeNumberToName],
171
+ ) as VoteType[],
172
+ },
173
+ };
174
+ return decodedTx as GenLayerTransaction;
175
+ };
176
+
177
+ const _decodeLocalnetTransaction = (tx: GenLayerTransaction): GenLayerTransaction => {
178
+ try {
179
+ const leaderReceipt = tx.consensus_data?.leader_receipt;
180
+ if (leaderReceipt) {
181
+ if (leaderReceipt.result) {
182
+ leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
183
+ }
184
+ if (leaderReceipt.calldata) {
185
+ leaderReceipt.calldata = {
186
+ base64: leaderReceipt.calldata as string,
187
+ ...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata as string)),
188
+ };
189
+ }
190
+ if (leaderReceipt.eq_outputs) {
191
+ leaderReceipt.eq_outputs = Object.fromEntries(
192
+ Object.entries(leaderReceipt.eq_outputs).map(([key, value]) => {
193
+ const decodedValue = new TextDecoder().decode(b64ToArray(String(value)));
194
+ return [key, resultToUserFriendlyJson(decodedValue)];
195
+ }),
196
+ );
197
+ }
198
+ }
199
+ if (tx.data?.calldata) {
200
+ tx.data.calldata = {
201
+ base64: tx.data.calldata as string,
202
+ ...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata as string)),
203
+ };
204
+ }
205
+ } catch (e) {
206
+ console.error("Error in _decodeLocalnetTransaction:", e);
207
+ }
208
+ return tx;
209
+ };
@@ -1,2 +1 @@
1
- export type {Account} from "viem";
2
- export type Address = `0x${string}` & {length: 42};
1
+ export type {Account, Address} from "viem";
@@ -1,8 +1,14 @@
1
1
  import {Chain} from "viem";
2
+ import {Address} from "./accounts";
2
3
 
3
- export type SimulatorChain = Chain & {
4
+ export type GenLayerChain = Chain & {
4
5
  consensusMainContract: {
5
- address: string;
6
+ address: Address;
7
+ abi: any[];
8
+ bytecode: string;
9
+ } | null;
10
+ consensusDataContract: {
11
+ address: Address;
6
12
  abi: any[];
7
13
  bytecode: string;
8
14
  } | null;
@@ -1,6 +1,6 @@
1
1
  import {Transport, Client, PublicActions, WalletActions} from "viem";
2
2
  import {GenLayerTransaction, TransactionHash, TransactionStatus} from "./transactions";
3
- import {SimulatorChain} from "./chains";
3
+ import {GenLayerChain} from "./chains";
4
4
  import {Address, Account} from "./accounts";
5
5
  import {CalldataEncodable} from "./calldata";
6
6
  import {ContractSchema} from "./contracts";
@@ -9,31 +9,32 @@ import {SnapSource} from "@/types/snapSource";
9
9
  import {MetaMaskClientResult} from "@/types/metamaskClientResult";
10
10
 
11
11
  export type GenLayerMethod =
12
- | {method: "sim_fundAccount"; params: [address: string, amount: number]}
12
+ | {method: "sim_fundAccount"; params: [address: Address, amount: number]}
13
13
  | {method: "eth_getTransactionByHash"; params: [hash: TransactionHash]}
14
14
  | {method: "eth_call"; params: [requestParams: any, blockNumberOrHash: string]}
15
15
  | {method: "eth_sendRawTransaction"; params: [signedTransaction: string]}
16
- | {method: "gen_getContractSchema"; params: [address: string]}
16
+ | {method: "gen_getContractSchema"; params: [address: Address]}
17
17
  | {method: "gen_getContractSchemaForCode"; params: [contractCode: string]}
18
- | {method: "sim_getTransactionsForAddress"; params: [address: string, filter?: "all" | "from" | "to"]}
19
- | {method: "eth_getTransactionCount"; params: [address: string, block: string]};
18
+ | {method: "sim_getTransactionsForAddress"; params: [address: Address, filter?: "all" | "from" | "to"]}
19
+ | {method: "eth_getTransactionCount"; params: [address: Address, block: string]}
20
+ | {method: "gen_call"; params: [requestParams: any]};
20
21
 
21
22
  /*
22
- Take all the properties from PublicActions<Transport, TSimulatorChain>
23
+ Take all the properties from PublicActions<Transport, TGenLayerChain>
23
24
  Remove the transport, readContract, and getTransaction properties
24
25
  The resulting type will have everything from PublicActions EXCEPT those
25
26
  two properties which are added later
26
27
  */
27
- export type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<
28
- Client<Transport, TSimulatorChain>,
28
+ export type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<
29
+ Client<Transport, TGenLayerChain>,
29
30
  "transport" | "getTransaction" | "readContract"
30
31
  > &
31
- Omit<WalletActions<TSimulatorChain>, "deployContract" | "writeContract"> &
32
+ Omit<WalletActions<TGenLayerChain>, "deployContract" | "writeContract"> &
32
33
  Omit<
33
- PublicActions<Transport, TSimulatorChain>,
34
+ PublicActions<Transport, TGenLayerChain>,
34
35
  "readContract" | "getTransaction" | "waitForTransactionReceipt"
35
36
  > & {
36
- request: Client<Transport, TSimulatorChain>["request"] & {
37
+ request: Client<Transport, TGenLayerChain>["request"] & {
37
38
  <TMethod extends GenLayerMethod>(
38
39
  args: Extract<GenLayerMethod, {method: TMethod["method"]}>,
39
40
  ): Promise<unknown>;
@@ -66,14 +67,14 @@ export type GenLayerClient<TSimulatorChain extends SimulatorChain> = Omit<
66
67
  consensusMaxRotations?: number;
67
68
  }) => Promise<`0x${string}`>;
68
69
  getTransaction: (args: {hash: TransactionHash}) => Promise<GenLayerTransaction>;
69
- getCurrentNonce: (args: {address: string}) => Promise<number>;
70
+ getCurrentNonce: (args: {address: Address}) => Promise<number>;
70
71
  waitForTransactionReceipt: (args: {
71
72
  hash: TransactionHash;
72
73
  status?: TransactionStatus;
73
74
  interval?: number;
74
75
  retries?: number;
75
76
  }) => Promise<GenLayerTransaction>;
76
- getContractSchema: (address: string) => Promise<ContractSchema>;
77
+ getContractSchema: (address: Address) => Promise<ContractSchema>;
77
78
  getContractSchemaForCode: (contractCode: string | Uint8Array) => Promise<ContractSchema>;
78
79
  initializeConsensusSmartContract: (forceReset?: boolean) => Promise<void>;
79
80
  connect: (network?: Network, snapSource?: SnapSource) => Promise<void>;
@@ -1,22 +1,226 @@
1
- export type TransactionHash = `0x${string}` & {length: 66};
1
+ import {Hex} from "viem";
2
+ import {Address} from "./accounts";
3
+
4
+ export type Hash = `0x${string}` & {length: 66};
5
+ export type TransactionHash = Hash;
2
6
 
3
7
  export enum TransactionStatus {
8
+ UNINITIALIZED = "UNINITIALIZED",
4
9
  PENDING = "PENDING",
5
- CANCELED = "CANCELED",
6
10
  PROPOSING = "PROPOSING",
7
11
  COMMITTING = "COMMITTING",
8
12
  REVEALING = "REVEALING",
9
13
  ACCEPTED = "ACCEPTED",
10
- FINALIZED = "FINALIZED",
11
14
  UNDETERMINED = "UNDETERMINED",
15
+ FINALIZED = "FINALIZED",
16
+ CANCELED = "CANCELED",
17
+ APPEAL_REVEALING = "APPEAL_REVEALING",
18
+ APPEAL_COMMITTING = "APPEAL_COMMITTING",
19
+ READY_TO_FINALIZE = "READY_TO_FINALIZE",
20
+ VALIDATORS_TIMEOUT = "VALIDATORS_TIMEOUT",
21
+ LEADER_TIMEOUT = "LEADER_TIMEOUT",
22
+ }
23
+
24
+ export enum TransactionResult {
25
+ SUCCESS = "SUCCESS",
26
+ FAILURE = "FAILURE",
12
27
  }
13
28
 
29
+ export enum TransactionResult {
30
+ IDLE = "IDLE",
31
+ AGREE = "AGREE",
32
+ DISAGREE = "DISAGREE",
33
+ TIMEOUT = "TIMEOUT",
34
+ DETERMINISTIC_VIOLATION = "DETERMINISTIC_VIOLATION",
35
+ NO_MAJORITY = "NO_MAJORITY",
36
+ MAJORITY_AGREE = "MAJORITY_AGREE",
37
+ MAJORITY_DISAGREE = "MAJORITY_DISAGREE",
38
+ }
39
+
40
+ export const transactionsStatusNumberToName = {
41
+ "0": TransactionStatus.UNINITIALIZED,
42
+ "1": TransactionStatus.PENDING,
43
+ "2": TransactionStatus.PROPOSING,
44
+ "3": TransactionStatus.COMMITTING,
45
+ "4": TransactionStatus.REVEALING,
46
+ "5": TransactionStatus.ACCEPTED,
47
+ "6": TransactionStatus.UNDETERMINED,
48
+ "7": TransactionStatus.FINALIZED,
49
+ "8": TransactionStatus.CANCELED,
50
+ "9": TransactionStatus.APPEAL_REVEALING,
51
+ "10": TransactionStatus.APPEAL_COMMITTING,
52
+ "11": TransactionStatus.READY_TO_FINALIZE,
53
+ "12": TransactionStatus.VALIDATORS_TIMEOUT,
54
+ "13": TransactionStatus.LEADER_TIMEOUT,
55
+ };
56
+
57
+ export const transactionsStatusNameToNumber = {
58
+ [TransactionStatus.UNINITIALIZED]: "0",
59
+ [TransactionStatus.PENDING]: "1",
60
+ [TransactionStatus.PROPOSING]: "2",
61
+ [TransactionStatus.COMMITTING]: "3",
62
+ [TransactionStatus.REVEALING]: "4",
63
+ [TransactionStatus.ACCEPTED]: "5",
64
+ [TransactionStatus.UNDETERMINED]: "6",
65
+ [TransactionStatus.FINALIZED]: "7",
66
+ [TransactionStatus.CANCELED]: "8",
67
+ [TransactionStatus.APPEAL_REVEALING]: "9",
68
+ [TransactionStatus.APPEAL_COMMITTING]: "10",
69
+ [TransactionStatus.READY_TO_FINALIZE]: "11",
70
+ [TransactionStatus.VALIDATORS_TIMEOUT]: "12",
71
+ [TransactionStatus.LEADER_TIMEOUT]: "13",
72
+ };
73
+
74
+ export const transactionResultNumberToName = {
75
+ "0": TransactionResult.IDLE,
76
+ "1": TransactionResult.AGREE,
77
+ "2": TransactionResult.DISAGREE,
78
+ "3": TransactionResult.TIMEOUT,
79
+ "4": TransactionResult.DETERMINISTIC_VIOLATION,
80
+ "5": TransactionResult.NO_MAJORITY,
81
+ "6": TransactionResult.MAJORITY_AGREE,
82
+ "7": TransactionResult.MAJORITY_DISAGREE,
83
+ };
84
+
85
+ export const TransactionResultNameToNumber = {
86
+ [TransactionResult.IDLE]: "0",
87
+ [TransactionResult.AGREE]: "1",
88
+ [TransactionResult.DISAGREE]: "2",
89
+ [TransactionResult.TIMEOUT]: "3",
90
+ [TransactionResult.DETERMINISTIC_VIOLATION]: "4",
91
+ [TransactionResult.NO_MAJORITY]: "5",
92
+ [TransactionResult.MAJORITY_AGREE]: "6",
93
+ [TransactionResult.MAJORITY_DISAGREE]: "7",
94
+ };
95
+
96
+ export enum VoteType {
97
+ NOT_VOTED = "NOT_VOTED",
98
+ AGREE = "AGREE",
99
+ DISAGREE = "DISAGREE",
100
+ TIMEOUT = "TIMEOUT",
101
+ DETERMINISTIC_VIOLATION = "DETERMINISTIC_VIOLATION",
102
+ }
103
+
104
+ export const voteTypeNumberToName = {
105
+ "0": VoteType.NOT_VOTED,
106
+ "1": VoteType.AGREE,
107
+ "2": VoteType.DISAGREE,
108
+ "3": VoteType.TIMEOUT,
109
+ "4": VoteType.DETERMINISTIC_VIOLATION,
110
+ };
111
+
112
+ export const voteTypeNameToNumber = {
113
+ [VoteType.NOT_VOTED]: "0",
114
+ [VoteType.AGREE]: "1",
115
+ [VoteType.DISAGREE]: "2",
116
+ [VoteType.TIMEOUT]: "3",
117
+ [VoteType.DETERMINISTIC_VIOLATION]: "4",
118
+ };
119
+
120
+ export type TransactionType = "deploy" | "call";
121
+
122
+ export type DecodedDeployData = {
123
+ code?: Hex;
124
+ constructorArgs?: any; // Type this more strictly if possible
125
+ leaderOnly?: boolean;
126
+ type?: TransactionType;
127
+ contractAddress?: Address;
128
+ };
129
+
130
+ export type DecodedCallData = {
131
+ callData?: any; // Type this more strictly if possible
132
+ leaderOnly?: boolean;
133
+ type: TransactionType;
134
+ };
135
+
136
+ // TODO: make localnet compatible with testnet and unify the types
14
137
  export type GenLayerTransaction = {
15
- hash: TransactionHash;
16
- status: TransactionStatus;
17
- from_address?: string;
18
- to_address?: string;
138
+ // currentTimestamp: testnet
139
+ currentTimestamp?: string;
140
+
141
+ // from_address: localnet // sender: testnet
142
+ from_address?: Address;
143
+ sender?: Address;
144
+
145
+ // to_address: localnet // recipient: testnet
146
+ to_address?: Address;
147
+ recipient?: Address;
148
+
149
+ // numOfInitialValidators: testnet
150
+ numOfInitialValidators?: string;
151
+
152
+ // txSlot: testnet
153
+ txSlot?: string;
154
+
155
+ // createdTimestamp: testnet
156
+ createdTimestamp?: string;
157
+
158
+ // lastVoteTimestamp: testnet
159
+ lastVoteTimestamp?: string;
160
+
161
+ // randomSeed: testnet
162
+ randomSeed?: Hash;
163
+
164
+ // result: testnet
165
+ result?: number;
166
+ resultName?: TransactionResult;
167
+
168
+ // data: localnet // txData: testnet
19
169
  data?: Record<string, unknown>;
170
+ txData?: Hex;
171
+ txDataDecoded?: DecodedDeployData | DecodedCallData;
172
+ // txReceipt: testnet
173
+ txReceipt?: Hash;
174
+
175
+ // messages: testnet
176
+ messages?: unknown[];
177
+
178
+ // queueType: testnet
179
+ queueType?: number;
180
+
181
+ // queuePosition: testnet
182
+ queuePosition?: string;
183
+
184
+ // activator: testnet
185
+ activator?: Address;
186
+
187
+ // lastLeader: testnet
188
+ lastLeader?: Address;
189
+
190
+ // status: localnet: TransactionStatus // status: testnet: number
191
+ status?: TransactionStatus | number;
192
+ statusName?: TransactionStatus;
193
+
194
+ // hash: localnet // txId: testnet// hash: localnet // txId: testnet
195
+ hash?: TransactionHash;
196
+ txId?: TransactionHash;
197
+
198
+ // readStateBlockRange: testnet
199
+ readStateBlockRange?: {
200
+ activationBlock: string;
201
+ processingBlock: string;
202
+ proposalBlock: string;
203
+ };
204
+
205
+ // numOfRounds: testnet
206
+ numOfRounds?: string;
207
+
208
+ // lastRound: testnet
209
+ lastRound?: {
210
+ round: string;
211
+ leaderIndex: string;
212
+ votesCommitted: string;
213
+ votesRevealed: string;
214
+ appealBond: string;
215
+ rotationsLeft: string;
216
+ result: number;
217
+ roundValidators: Address[];
218
+ validatorVotesHash: Hash[];
219
+ validatorVotes: number[];
220
+ validatorVotesName: VoteType[];
221
+ };
222
+
223
+ // consensus_data: localnet // leader_receipt: testnet
20
224
  consensus_data?: {
21
225
  final: boolean;
22
226
  leader_receipt?: {
@@ -31,6 +235,7 @@ export type GenLayerTransaction = {
31
235
  node_config: Record<string, unknown>;
32
236
  pending_transactions: unknown[];
33
237
  vote: string;
238
+ result: string;
34
239
  };
35
240
  validators?: Record<string, unknown>[];
36
241
  votes?: Record<string, string>;
@@ -45,4 +250,41 @@ export type GenLayerTransaction = {
45
250
  v?: number;
46
251
  };
47
252
 
48
- export type TransactionDataElement = string | number | bigint | boolean | Uint8Array;
253
+ export type GenLayerRawTransaction = {
254
+ currentTimestamp: bigint;
255
+ sender: Address;
256
+ recipient: Address;
257
+ numOfInitialValidators: bigint;
258
+ txSlot: bigint;
259
+ createdTimestamp: bigint;
260
+ lastVoteTimestamp: bigint;
261
+ randomSeed: Hash;
262
+ result: number;
263
+ txData: Hex | undefined | null;
264
+ txReceipt: Hash;
265
+ messages: unknown[];
266
+ queueType: number;
267
+ queuePosition: bigint;
268
+ activator: Address;
269
+ lastLeader: Address;
270
+ status: number;
271
+ txId: Hash;
272
+ readStateBlockRange: {
273
+ activationBlock: bigint;
274
+ processingBlock: bigint;
275
+ proposalBlock: bigint;
276
+ };
277
+ numOfRounds: bigint;
278
+ lastRound: {
279
+ round: bigint;
280
+ leaderIndex: bigint;
281
+ votesCommitted: bigint;
282
+ votesRevealed: bigint;
283
+ appealBond: bigint;
284
+ rotationsLeft: bigint;
285
+ result: number;
286
+ roundValidators: Address[];
287
+ validatorVotesHash: Hash[];
288
+ validatorVotes: number[];
289
+ };
290
+ };
@@ -0,0 +1,47 @@
1
+ import {calldata} from "@/abi";
2
+
3
+
4
+ export function b64ToArray(b64: string): Uint8Array {
5
+ return Uint8Array.from(atob(b64 as string), (c) => c.charCodeAt(0));
6
+ }
7
+
8
+ export function calldataToUserFriendlyJson(cd: Uint8Array): any {
9
+ return {
10
+ raw: Array.from(cd),
11
+ readable: calldata.toString(calldata.decode(cd)),
12
+ };
13
+ }
14
+
15
+ const RESULT_CODES = new Map([
16
+ [0, 'return'],
17
+ [1, 'rollback'],
18
+ [2, 'contract_error'],
19
+ [3, 'error'],
20
+ [4, 'none'],
21
+ [5, 'no_leaders'],
22
+ ]);
23
+
24
+ export function resultToUserFriendlyJson(cd64: string): any {
25
+ const raw = b64ToArray(cd64);
26
+
27
+ const code = RESULT_CODES.get(raw[0]);
28
+ let status: string;
29
+ let payload: string | null = null;
30
+
31
+ if (code === undefined) {
32
+ status = '<unknown>';
33
+ } else {
34
+ status = code;
35
+ if ([1, 2].includes(raw[0])) {
36
+ payload = new TextDecoder('utf-8').decode(raw.slice(1));
37
+ } else if (raw[0] == 0) {
38
+ payload = calldataToUserFriendlyJson(raw.slice(1));
39
+ }
40
+ }
41
+
42
+ return {
43
+ raw: cd64,
44
+ status,
45
+ payload,
46
+ };
47
+ }
@@ -1,8 +1,8 @@
1
- import { connect } from "./connect";
2
- import {GenLayerClient, SimulatorChain, Network, SnapSource} from "@/types";
3
- import { metamaskClient } from "@/wallet/metamaskClient";
1
+ import {connect} from "./connect";
2
+ import {GenLayerClient, GenLayerChain, Network, SnapSource} from "@/types";
3
+ import {metamaskClient} from "@/wallet/metamaskClient";
4
4
 
5
- export function walletActions(client: GenLayerClient<SimulatorChain>) {
5
+ export function walletActions(client: GenLayerClient<GenLayerChain>) {
6
6
  return {
7
7
  connect: (network: Network, snapSource: SnapSource) => connect(client, network, snapSource),
8
8
  metamaskClient: (snapSource: SnapSource = "npm") => metamaskClient(snapSource),