genlayer-js 0.9.0 → 0.9.2

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 (53) hide show
  1. package/CHANGELOG.md +4 -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-4FVQ3G7J.js +8039 -0
  9. package/dist/chunk-GACCNOPJ.js +138 -0
  10. package/dist/chunk-H4ZYXVV2.cjs +138 -0
  11. package/dist/chunk-SMCXL465.cjs +8039 -0
  12. package/dist/index-B52a6DSr.d.cts +13 -0
  13. package/dist/index-B_gpaVzJ.d.cts +374 -0
  14. package/dist/index-DNvW8slT.d.ts +13 -0
  15. package/dist/index-to6d0Hzj.d.ts +374 -0
  16. package/dist/index.cjs +4508 -290
  17. package/dist/index.d.cts +6 -6
  18. package/dist/index.d.ts +6 -6
  19. package/dist/index.js +4507 -289
  20. package/dist/types/index.cjs +20 -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 +21 -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 +3989 -5
  30. package/src/chains/studionet.ts +4015 -0
  31. package/src/chains/testnetAsimov.ts +4015 -0
  32. package/src/client/client.ts +64 -21
  33. package/src/contracts/actions.ts +198 -127
  34. package/src/transactions/actions.ts +158 -23
  35. package/src/types/accounts.ts +1 -2
  36. package/src/types/chains.ts +8 -2
  37. package/src/types/clients.ts +14 -13
  38. package/src/types/network.ts +1 -1
  39. package/src/types/transactions.ts +254 -8
  40. package/src/wallet/actions.ts +4 -4
  41. package/src/wallet/connect.ts +18 -16
  42. package/tests/client.test.ts +105 -45
  43. package/dist/chains-C5PI_Nr_.d.cts +0 -13
  44. package/dist/chains-C5PI_Nr_.d.ts +0 -13
  45. package/dist/chunk-I6HC44KD.cjs +0 -72
  46. package/dist/chunk-K72OSU5N.js +0 -28
  47. package/dist/chunk-WEXFFND6.js +0 -72
  48. package/dist/chunk-YDFRDDP5.cjs +0 -28
  49. package/dist/index-B8E0qiOq.d.cts +0 -13
  50. package/dist/index-BCbofn6t.d.cts +0 -188
  51. package/dist/index-Ctmshvtv.d.ts +0 -188
  52. package/dist/index-ZoW0HQ_m.d.ts +0 -13
  53. package/src/chains/simulator.ts +0 -30
@@ -1,11 +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";
6
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";
7
22
 
8
- export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
23
+ export const receiptActions = (client: GenLayerClient<GenLayerChain>, publicClient: PublicClient) => ({
9
24
  waitForTransactionReceipt: async ({
10
25
  hash,
11
26
  status = TransactionStatus.ACCEPTED,
@@ -17,17 +32,24 @@ export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
17
32
  interval?: number;
18
33
  retries?: number;
19
34
  }): Promise<GenLayerTransaction> => {
20
- const transaction = await client.getTransaction({hash});
35
+ const transaction = await client.getTransaction({
36
+ hash,
37
+ });
21
38
 
22
39
  if (!transaction) {
23
40
  throw new Error("Transaction not found");
24
41
  }
25
-
42
+ const transactionStatusString = String(transaction.status);
43
+ const transactionStatusFinalized = transactionsStatusNameToNumber[TransactionStatus.FINALIZED];
44
+ const requestedStatus = transactionsStatusNameToNumber[status];
26
45
  if (
27
- transaction.status === status ||
28
- (status === TransactionStatus.ACCEPTED && transaction.status === TransactionStatus.FINALIZED)
46
+ transactionStatusString === requestedStatus ||
47
+ (status === TransactionStatus.ACCEPTED && transactionStatusString === transactionStatusFinalized)
29
48
  ) {
30
- return _decodeTransaction(transaction);
49
+ if (client.chain.id === localnet.id) {
50
+ return _decodeLocalnetTransaction(transaction as unknown as GenLayerTransaction);
51
+ }
52
+ return transaction;
31
53
  }
32
54
 
33
55
  if (retries === 0) {
@@ -35,7 +57,7 @@ export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
35
57
  }
36
58
 
37
59
  await sleep(interval);
38
- return transactionActions(client).waitForTransactionReceipt({
60
+ return receiptActions(client, publicClient).waitForTransactionReceipt({
39
61
  hash,
40
62
  status,
41
63
  interval,
@@ -44,42 +66,155 @@ export const transactionActions = (client: GenLayerClient<SimulatorChain>) => ({
44
66
  },
45
67
  });
46
68
 
47
- const _decodeTransaction = (tx: GenLayerTransaction): GenLayerTransaction => {
48
- if (!tx.data) return tx;
69
+ export const transactionActions = (client: GenLayerClient<GenLayerChain>, publicClient: PublicClient) => ({
70
+ getTransaction: async ({hash}: {hash: TransactionHash}): Promise<GenLayerTransaction> => {
71
+ // TODO: remove this once DXP-298 is merged
72
+ if (client.chain.id === localnet.id) {
73
+ const transaction = await client.getTransaction({hash});
74
+ const localnetStatus =
75
+ (transaction.status as string) === "ACTIVATED" ? TransactionStatus.PENDING : transaction.status;
49
76
 
77
+ transaction.status = Number(transactionsStatusNameToNumber[localnetStatus as TransactionStatus]);
78
+ transaction.statusName = localnetStatus as TransactionStatus;
79
+ return _decodeLocalnetTransaction(transaction as unknown as GenLayerTransaction);
80
+ }
81
+ const transaction = (await publicClient.readContract({
82
+ address: client.chain.consensusDataContract?.address as Address,
83
+ abi: client.chain.consensusDataContract?.abi as Abi,
84
+ functionName: "getTransactionData",
85
+ args: [
86
+ hash,
87
+ Math.round(new Date().getTime() / 1000), // unix seconds
88
+ ],
89
+ })) as unknown as GenLayerRawTransaction;
90
+ return _decodeTransaction(transaction);
91
+ },
92
+ });
93
+
94
+ const _decodeInputData = (
95
+ rlpEncodedAppData: Hex | undefined | null,
96
+ recipient: Address,
97
+ ): DecodedDeployData | DecodedCallData | null => {
98
+ if (!rlpEncodedAppData || rlpEncodedAppData === "0x" || rlpEncodedAppData.length <= 2) {
99
+ return null;
100
+ }
101
+ try {
102
+ const rlpDecodedArray = fromRlp(rlpEncodedAppData) as Hex[];
103
+
104
+ if (rlpDecodedArray.length === 3) {
105
+ return {
106
+ code: fromHex(rlpDecodedArray[0], "string") as `0x${string}`,
107
+ constructorArgs:
108
+ rlpDecodedArray[1] && rlpDecodedArray[1] !== "0x"
109
+ ? calldataAbi.decode(fromHex(rlpDecodedArray[1], "bytes"))
110
+ : null,
111
+ leaderOnly: rlpDecodedArray[2] === "0x01",
112
+ type: "deploy",
113
+ contractAddress: recipient,
114
+ };
115
+ } else if (rlpDecodedArray.length === 2) {
116
+ return {
117
+ callData:
118
+ rlpDecodedArray[0] && rlpDecodedArray[0] !== "0x"
119
+ ? calldataAbi.decode(fromHex(rlpDecodedArray[0], "bytes"))
120
+ : null,
121
+ leaderOnly: rlpDecodedArray[1] === "0x01",
122
+ type: "call",
123
+ };
124
+ } else {
125
+ console.warn(
126
+ "[decodeInputData] WRITE: Unexpected RLP array length:",
127
+ rlpDecodedArray.length,
128
+ rlpDecodedArray,
129
+ );
130
+ return null;
131
+ }
132
+ } catch (e) {
133
+ console.error(
134
+ "[decodeInputData] Error during comprehensive decoding:",
135
+ e,
136
+ "Raw RLP App Data:",
137
+ rlpEncodedAppData,
138
+ );
139
+ return null;
140
+ }
141
+ };
142
+
143
+ const _decodeTransaction = (tx: GenLayerRawTransaction): GenLayerTransaction => {
144
+ const txDataDecoded = _decodeInputData(tx.txData, tx.recipient);
145
+
146
+ const decodedTx = {
147
+ ...tx,
148
+ txData: tx.txData,
149
+ txDataDecoded: txDataDecoded,
150
+
151
+ currentTimestamp: tx.currentTimestamp.toString(),
152
+ numOfInitialValidators: tx.numOfInitialValidators.toString(),
153
+ txSlot: tx.txSlot.toString(),
154
+ createdTimestamp: tx.createdTimestamp.toString(),
155
+ lastVoteTimestamp: tx.lastVoteTimestamp.toString(),
156
+ queuePosition: tx.queuePosition.toString(),
157
+ numOfRounds: tx.numOfRounds.toString(),
158
+
159
+ readStateBlockRange: {
160
+ ...tx.readStateBlockRange,
161
+ activationBlock: tx.readStateBlockRange.activationBlock.toString(),
162
+ processingBlock: tx.readStateBlockRange.processingBlock.toString(),
163
+ proposalBlock: tx.readStateBlockRange.proposalBlock.toString(),
164
+ },
165
+
166
+ statusName:
167
+ transactionsStatusNumberToName[String(tx.status) as keyof typeof transactionsStatusNumberToName],
168
+ resultName:
169
+ transactionResultNumberToName[String(tx.result) as keyof typeof transactionResultNumberToName],
170
+
171
+ lastRound: {
172
+ ...tx.lastRound,
173
+ round: tx.lastRound.round.toString(),
174
+ leaderIndex: tx.lastRound.leaderIndex.toString(),
175
+ votesCommitted: tx.lastRound.votesCommitted.toString(),
176
+ votesRevealed: tx.lastRound.votesRevealed.toString(),
177
+ appealBond: tx.lastRound.appealBond.toString(),
178
+ rotationsLeft: tx.lastRound.rotationsLeft.toString(),
179
+ validatorVotesName: tx.lastRound.validatorVotes.map(
180
+ vote => voteTypeNumberToName[String(vote) as keyof typeof voteTypeNumberToName],
181
+ ) as VoteType[],
182
+ },
183
+ };
184
+ return decodedTx as GenLayerTransaction;
185
+ };
186
+
187
+ const _decodeLocalnetTransaction = (tx: GenLayerTransaction): GenLayerTransaction => {
188
+ if (!tx.data) return tx;
50
189
  try {
51
190
  const leaderReceipt = tx.consensus_data?.leader_receipt;
52
191
  if (leaderReceipt) {
53
- if (leaderReceipt.result) {
192
+ if (leaderReceipt.result && typeof leaderReceipt.result === "string") {
54
193
  leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
55
194
  }
56
-
57
- if (leaderReceipt.calldata) {
195
+ if (leaderReceipt.calldata && typeof leaderReceipt.calldata === "string") {
58
196
  leaderReceipt.calldata = {
59
- base64: leaderReceipt.calldata,
60
- ...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata)),
197
+ base64: leaderReceipt.calldata as string,
198
+ ...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata as string)),
61
199
  };
62
200
  }
63
-
64
201
  if (leaderReceipt.eq_outputs) {
65
202
  leaderReceipt.eq_outputs = Object.fromEntries(
66
203
  Object.entries(leaderReceipt.eq_outputs).map(([key, value]) => {
67
204
  const decodedValue = new TextDecoder().decode(b64ToArray(String(value)));
68
205
  return [key, resultToUserFriendlyJson(decodedValue)];
69
- })
206
+ }),
70
207
  );
71
208
  }
72
209
  }
73
-
74
- if (tx.data.calldata) {
210
+ if (tx.data?.calldata && typeof tx.data.calldata === "string") {
75
211
  tx.data.calldata = {
76
212
  base64: tx.data.calldata as string,
77
213
  ...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata as string)),
78
214
  };
79
215
  }
80
216
  } catch (e) {
81
- console.error("Error decoding transaction:", e);
217
+ console.error("Error in _decodeLocalnetTransaction:", e);
82
218
  }
83
-
84
219
  return tx;
85
- }
220
+ };
@@ -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 +1 @@
1
- export type Network = 'localnet' | 'testnet' | 'mainnet';
1
+ export type Network = "localnet" | "studionet" | "testnetAsimov" | "mainnet";
@@ -1,22 +1,231 @@
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",
27
+ }
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 enum TransactionHashVariant {
123
+ LATEST_FINAL = "latest-final",
124
+ LATEST_NONFINAL = "latest-nonfinal",
12
125
  }
13
126
 
127
+ export type DecodedDeployData = {
128
+ code?: Hex;
129
+ constructorArgs?: any; // Type this more strictly if possible
130
+ leaderOnly?: boolean;
131
+ type?: TransactionType;
132
+ contractAddress?: Address;
133
+ };
134
+
135
+ export type DecodedCallData = {
136
+ callData?: any; // Type this more strictly if possible
137
+ leaderOnly?: boolean;
138
+ type: TransactionType;
139
+ };
140
+
141
+ // TODO: make localnet compatible with testnet and unify the types
14
142
  export type GenLayerTransaction = {
15
- hash: TransactionHash;
16
- status: TransactionStatus;
17
- from_address?: string;
18
- to_address?: string;
143
+ // currentTimestamp: testnet
144
+ currentTimestamp?: string;
145
+
146
+ // from_address: localnet // sender: testnet
147
+ from_address?: Address;
148
+ sender?: Address;
149
+
150
+ // to_address: localnet // recipient: testnet
151
+ to_address?: Address;
152
+ recipient?: Address;
153
+
154
+ // numOfInitialValidators: testnet
155
+ numOfInitialValidators?: string;
156
+
157
+ // txSlot: testnet
158
+ txSlot?: string;
159
+
160
+ // createdTimestamp: testnet
161
+ createdTimestamp?: string;
162
+
163
+ // lastVoteTimestamp: testnet
164
+ lastVoteTimestamp?: string;
165
+
166
+ // randomSeed: testnet
167
+ randomSeed?: Hash;
168
+
169
+ // result: testnet
170
+ result?: number;
171
+ resultName?: TransactionResult;
172
+
173
+ // data: localnet // txData: testnet
19
174
  data?: Record<string, unknown>;
175
+ txData?: Hex;
176
+ txDataDecoded?: DecodedDeployData | DecodedCallData;
177
+ // txReceipt: testnet
178
+ txReceipt?: Hash;
179
+
180
+ // messages: testnet
181
+ messages?: unknown[];
182
+
183
+ // queueType: testnet
184
+ queueType?: number;
185
+
186
+ // queuePosition: testnet
187
+ queuePosition?: string;
188
+
189
+ // activator: testnet
190
+ activator?: Address;
191
+
192
+ // lastLeader: testnet
193
+ lastLeader?: Address;
194
+
195
+ // status: localnet: TransactionStatus // status: testnet: number
196
+ status?: TransactionStatus | number;
197
+ statusName?: TransactionStatus;
198
+
199
+ // hash: localnet // txId: testnet// hash: localnet // txId: testnet
200
+ hash?: TransactionHash;
201
+ txId?: TransactionHash;
202
+
203
+ // readStateBlockRange: testnet
204
+ readStateBlockRange?: {
205
+ activationBlock: string;
206
+ processingBlock: string;
207
+ proposalBlock: string;
208
+ };
209
+
210
+ // numOfRounds: testnet
211
+ numOfRounds?: string;
212
+
213
+ // lastRound: testnet
214
+ lastRound?: {
215
+ round: string;
216
+ leaderIndex: string;
217
+ votesCommitted: string;
218
+ votesRevealed: string;
219
+ appealBond: string;
220
+ rotationsLeft: string;
221
+ result: number;
222
+ roundValidators: Address[];
223
+ validatorVotesHash: Hash[];
224
+ validatorVotes: number[];
225
+ validatorVotesName: VoteType[];
226
+ };
227
+
228
+ // consensus_data: localnet // leader_receipt: testnet
20
229
  consensus_data?: {
21
230
  final: boolean;
22
231
  leader_receipt?: {
@@ -46,4 +255,41 @@ export type GenLayerTransaction = {
46
255
  v?: number;
47
256
  };
48
257
 
49
- export type TransactionDataElement = string | number | bigint | boolean | Uint8Array;
258
+ export type GenLayerRawTransaction = {
259
+ currentTimestamp: bigint;
260
+ sender: Address;
261
+ recipient: Address;
262
+ numOfInitialValidators: bigint;
263
+ txSlot: bigint;
264
+ createdTimestamp: bigint;
265
+ lastVoteTimestamp: bigint;
266
+ randomSeed: Hash;
267
+ result: number;
268
+ txData: Hex | undefined | null;
269
+ txReceipt: Hash;
270
+ messages: unknown[];
271
+ queueType: number;
272
+ queuePosition: bigint;
273
+ activator: Address;
274
+ lastLeader: Address;
275
+ status: number;
276
+ txId: Hash;
277
+ readStateBlockRange: {
278
+ activationBlock: bigint;
279
+ processingBlock: bigint;
280
+ proposalBlock: bigint;
281
+ };
282
+ numOfRounds: bigint;
283
+ lastRound: {
284
+ round: bigint;
285
+ leaderIndex: bigint;
286
+ votesCommitted: bigint;
287
+ votesRevealed: bigint;
288
+ appealBond: bigint;
289
+ rotationsLeft: bigint;
290
+ result: number;
291
+ roundValidators: Address[];
292
+ validatorVotesHash: Hash[];
293
+ validatorVotes: number[];
294
+ };
295
+ };
@@ -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),