genlayer-js 0.9.1 → 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.
@@ -3,7 +3,7 @@ import {GenLayerChain} from "@/types";
3
3
 
4
4
  // chains/localnet.ts
5
5
  const TESTNET_JSON_RPC_URL = " http://34.32.169.58:9151";
6
-
6
+ const EXPLORER_URL = "https://explorer-asimov.genlayer.com/";
7
7
  const CONSENSUS_MAIN_CONTRACT = {
8
8
  address: "0x174782d5819dD26F3d6967c995EE43db7DB824F8" as Address,
9
9
  abi: [
@@ -3988,9 +3988,9 @@ const CONSENSUS_DATA_CONTRACT = {
3988
3988
  bytecode: "",
3989
3989
  };
3990
3990
 
3991
- export const testnet: GenLayerChain = defineChain({
3991
+ export const testnetAsimov: GenLayerChain = defineChain({
3992
3992
  id: 0x107d,
3993
- name: "Genlayer Testnet",
3993
+ name: "Genlayer Asimov Testnet",
3994
3994
  rpcUrls: {
3995
3995
  default: {
3996
3996
  http: [TESTNET_JSON_RPC_URL],
@@ -4003,8 +4003,8 @@ export const testnet: GenLayerChain = defineChain({
4003
4003
  },
4004
4004
  blockExplorers: {
4005
4005
  default: {
4006
- name: "GenLayer Explorer",
4007
- url: "https://explorer-asimov.genlayer.com",
4006
+ name: "GenLayer Asimov Explorer",
4007
+ url: EXPLORER_URL,
4008
4008
  },
4009
4009
  },
4010
4010
  testnet: true,
@@ -1,7 +1,15 @@
1
1
  import * as calldata from "@/abi/calldata";
2
2
  import {serialize} from "@/abi/transactions";
3
3
  import {localnet} from "@/chains/localnet";
4
- import {Account, ContractSchema, GenLayerChain, GenLayerClient, CalldataEncodable, Address} from "@/types";
4
+ import {
5
+ Account,
6
+ ContractSchema,
7
+ GenLayerChain,
8
+ GenLayerClient,
9
+ CalldataEncodable,
10
+ Address,
11
+ TransactionHashVariant,
12
+ } from "@/types";
5
13
  import {fromHex, toHex, zeroAddress, encodeFunctionData, PublicClient, parseEventLogs} from "viem";
6
14
 
7
15
  function makeCalldataObject(
@@ -71,8 +79,17 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
71
79
  kwargs?: Map<string, CalldataEncodable> | {[key: string]: CalldataEncodable};
72
80
  rawReturn?: RawReturn;
73
81
  leaderOnly?: boolean;
82
+ transactionHashVariant?: TransactionHashVariant;
74
83
  }): Promise<RawReturn extends true ? `0x${string}` : CalldataEncodable> => {
75
- const {account, address, functionName, args: callArgs, kwargs, leaderOnly = false} = args;
84
+ const {
85
+ account,
86
+ address,
87
+ functionName,
88
+ args: callArgs,
89
+ kwargs,
90
+ leaderOnly = false,
91
+ transactionHashVariant = TransactionHashVariant.LATEST_FINAL,
92
+ } = args;
76
93
  const encodedData = [calldata.encode(makeCalldataObject(functionName, callArgs, kwargs)), leaderOnly];
77
94
  const serializedData = serialize(encodedData);
78
95
 
@@ -83,7 +100,7 @@ export const contractActions = (client: GenLayerClient<GenLayerChain>, publicCli
83
100
  to: address,
84
101
  from: senderAddress,
85
102
  data: serializedData,
86
- transaction_hash_variant: "latest-final",
103
+ transaction_hash_variant: transactionHashVariant,
87
104
  };
88
105
  const result = await client.request({
89
106
  method: "gen_call",
@@ -233,6 +250,12 @@ const _sendTransaction = async ({
233
250
  const serializedTransaction = await senderAccount.signTransaction(transactionRequest);
234
251
 
235
252
  const txHash = await client.sendRawTransaction({serializedTransaction: serializedTransaction});
253
+
254
+ // TODO: remove this once DXP-298 is merged
255
+ if (client.chain.id === localnet.id) {
256
+ return txHash;
257
+ }
258
+
236
259
  const receipt = await publicClient.waitForTransactionReceipt({hash: txHash});
237
260
 
238
261
  if (receipt.status === "reverted") {
@@ -68,6 +68,16 @@ export const receiptActions = (client: GenLayerClient<GenLayerChain>, publicClie
68
68
 
69
69
  export const transactionActions = (client: GenLayerClient<GenLayerChain>, publicClient: PublicClient) => ({
70
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;
76
+
77
+ transaction.status = Number(transactionsStatusNameToNumber[localnetStatus as TransactionStatus]);
78
+ transaction.statusName = localnetStatus as TransactionStatus;
79
+ return _decodeLocalnetTransaction(transaction as unknown as GenLayerTransaction);
80
+ }
71
81
  const transaction = (await publicClient.readContract({
72
82
  address: client.chain.consensusDataContract?.address as Address,
73
83
  abi: client.chain.consensusDataContract?.abi as Abi,
@@ -175,13 +185,14 @@ const _decodeTransaction = (tx: GenLayerRawTransaction): GenLayerTransaction =>
175
185
  };
176
186
 
177
187
  const _decodeLocalnetTransaction = (tx: GenLayerTransaction): GenLayerTransaction => {
188
+ if (!tx.data) return tx;
178
189
  try {
179
190
  const leaderReceipt = tx.consensus_data?.leader_receipt;
180
191
  if (leaderReceipt) {
181
- if (leaderReceipt.result) {
192
+ if (leaderReceipt.result && typeof leaderReceipt.result === "string") {
182
193
  leaderReceipt.result = resultToUserFriendlyJson(leaderReceipt.result);
183
194
  }
184
- if (leaderReceipt.calldata) {
195
+ if (leaderReceipt.calldata && typeof leaderReceipt.calldata === "string") {
185
196
  leaderReceipt.calldata = {
186
197
  base64: leaderReceipt.calldata as string,
187
198
  ...calldataToUserFriendlyJson(b64ToArray(leaderReceipt.calldata as string)),
@@ -196,7 +207,7 @@ const _decodeLocalnetTransaction = (tx: GenLayerTransaction): GenLayerTransactio
196
207
  );
197
208
  }
198
209
  }
199
- if (tx.data?.calldata) {
210
+ if (tx.data?.calldata && typeof tx.data.calldata === "string") {
200
211
  tx.data.calldata = {
201
212
  base64: tx.data.calldata as string,
202
213
  ...calldataToUserFriendlyJson(b64ToArray(tx.data.calldata as string)),
@@ -1 +1 @@
1
- export type Network = 'localnet' | 'testnet' | 'mainnet';
1
+ export type Network = "localnet" | "studionet" | "testnetAsimov" | "mainnet";
@@ -119,6 +119,11 @@ export const voteTypeNameToNumber = {
119
119
 
120
120
  export type TransactionType = "deploy" | "call";
121
121
 
122
+ export enum TransactionHashVariant {
123
+ LATEST_FINAL = "latest-final",
124
+ LATEST_NONFINAL = "latest-nonfinal",
125
+ }
126
+
122
127
  export type DecodedDeployData = {
123
128
  code?: Hex;
124
129
  constructorArgs?: any; // Type this more strictly if possible
@@ -1,4 +1,6 @@
1
1
  import {localnet} from "@/chains/localnet";
2
+ import {studionet} from "@/chains/studionet";
3
+ import {testnetAsimov} from "@/chains/testnetAsimov";
2
4
  import {GenLayerClient, GenLayerChain} from "@/types";
3
5
  import {Network} from "@/types/network";
4
6
  import {SnapSource} from "@/types/snapSource";
@@ -6,17 +8,19 @@ import {snapID} from "@/config/snapID";
6
8
 
7
9
  const networks = {
8
10
  localnet,
11
+ studionet,
12
+ testnetAsimov,
9
13
  };
10
14
 
11
15
  export const connect = async (
12
16
  client: GenLayerClient<GenLayerChain>,
13
- network: Network = "localnet",
17
+ network: Network = "studionet",
14
18
  snapSource: SnapSource = "npm",
15
19
  ): Promise<void> => {
16
20
  if (!window.ethereum) {
17
21
  throw new Error("MetaMask is not installed.");
18
22
  }
19
- if (network === "testnet" || network === "mainnet") {
23
+ if (network === "mainnet") {
20
24
  throw new Error(`${network} is not available yet. Please use localnet.`);
21
25
  }
22
26
 
@@ -1,13 +0,0 @@
1
- import { G as GenLayerChain } from './chains-BYSCF33g.cjs';
2
-
3
- declare const localnet: GenLayerChain;
4
-
5
- declare const testnet: GenLayerChain;
6
-
7
- declare const index_localnet: typeof localnet;
8
- declare const index_testnet: typeof testnet;
9
- declare namespace index {
10
- export { index_localnet as localnet, index_testnet as testnet };
11
- }
12
-
13
- export { index as i, localnet as l, testnet as t };
@@ -1,13 +0,0 @@
1
- import { G as GenLayerChain } from './chains-BYSCF33g.js';
2
-
3
- declare const localnet: GenLayerChain;
4
-
5
- declare const testnet: GenLayerChain;
6
-
7
- declare const index_localnet: typeof localnet;
8
- declare const index_testnet: typeof testnet;
9
- declare namespace index {
10
- export { index_localnet as localnet, index_testnet as testnet };
11
- }
12
-
13
- export { index as i, localnet as l, testnet as t };