Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/transactions/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {sleep} from "../utils/async";
import {GenLayerChain} from "@/types";
import {Abi, PublicClient, Address} from "viem";
import {localnet} from "@/chains/localnet";
import {studionet} from "@/chains/studionet";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

🧩 Analysis chain

Studionet import is appropriate; verify chain-id uniqueness.

Several code paths compare by chain.id. If localnet and studionet share the same id (snippets show 61_999 for both), comparisons may be ambiguous. Prefer a helper like isSimulatorChain(chain) or compare by reference/name.

Run to confirm actual ids:


🏁 Script executed:

#!/bin/bash
rg -nP -C2 '(?s)export const\s+(localnet|studionet)\b.*?id:\s*([0-9_]+)' src/chains

Length of output: 0


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "PWD: $(pwd)"
echo
echo "rg version:"
rg --version || true

echo
echo "---- listing top-level src dir (if present) ----"
[ -d src ] && ls -la src | sed -n '1,200p' || echo "no src dir"

echo
echo "---- searching repo for exact tokens 'studionet' or 'localnet' ----"
rg -n --hidden --no-ignore -S '\bstudionet\b|\blocalnet\b' || true

echo
echo "---- searching for 'export const <name> =' definitions under src ----"
rg -nP --hidden 'export\s+const\s+\w+\s*=' src || true

echo
echo "---- searching for 'id:' numeric/object properties anywhere under src ----"
rg -nP --hidden '\bid\s*:\s*[0-9_]+\b' -C2 src || true

echo
echo "---- searching for 'chain.id' usages (comparisons/reads) under src ----"
rg -nP --hidden '\bchain\.id\b' -C2 src || true

echo
echo "---- listing src/chains directory (if exists) ----"
[ -d src/chains ] && ls -la src/chains || echo "src/chains not found"

Length of output: 11227


Duplicate chain.id (61_999) for localnet and studionet — make comparisons unambiguous

Both src/chains/localnet.ts and src/chains/studionet.ts define id: 61_999. Code compares client.chain.id to localnet.id/studionet.id (notably src/transactions/actions.ts, src/contracts/actions.ts, src/accounts/actions.ts), causing ambiguous/incorrect matches. Either assign unique ids or replace id-based checks with a helper (e.g. isSimulatorChain(chain)) or compare by reference/name.

🤖 Prompt for AI Agents
In src/transactions/actions.ts around line 14 the import and subsequent checks
rely on chain.id which is ambiguous because both localnet and studionet use id
61_999; replace id-based comparisons with an unambiguous check: create and
export a helper (e.g. isSimulatorChain(chain) or isLocalSimulator(chainName)) in
the chains module that returns true for simulator chains by name or an explicit
exported flag on each chain, then update this file (and similarly
src/contracts/actions.ts and src/accounts/actions.ts) to call that helper
instead of comparing client.chain.id to localnet.id/studionet.id; ensure to
update imports to use the helper and remove any id-based logic or alternatively
give localnet/studionet unique ids if you prefer the id approach (pick one
solution and apply consistently).

import {decodeLocalnetTransaction, decodeTransaction, simplifyTransactionReceipt} from "./decoders";


Expand Down Expand Up @@ -90,6 +91,26 @@ export const transactionActions = (client: GenLayerClient<GenLayerChain>, public
})) as unknown as GenLayerRawTransaction;
return decodeTransaction(transaction);
},
getStudioTransactionByHash: async ({hash, full}: {hash: TransactionHash; full?: boolean}): Promise<GenLayerTransaction> => {
const transaction = await client.request(
full !== undefined
? { method: "sim_getTransactionByHash", params: [hash, full] }
: { method: "sim_getTransactionByHash", params: [hash] }
) as unknown as GenLayerTransaction;

if (client.chain.id === localnet.id || client.chain.id === studionet.id) {
return decodeLocalnetTransaction(transaction);
}
return transaction;
},
getTransactionStatus: async ({hash}: {hash: TransactionHash}): Promise<TransactionStatus> => {
const status = await client.request({
method: "gen_getTransactionStatus",
params: [hash],
}) as unknown as TransactionStatus;

return status;
},
estimateTransactionGas: async (transactionParams: {
from?: Address;
to: Address;
Expand Down
4 changes: 4 additions & 0 deletions src/types/clients.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import {MetaMaskClientResult} from "@/types/metamaskClientResult";
export type GenLayerMethod =
| {method: "sim_fundAccount"; params: [address: Address, amount: number]}
| {method: "eth_getTransactionByHash"; params: [hash: TransactionHash]}
| {method: "sim_getTransactionByHash"; params: [hash: TransactionHash, full?: boolean]}
| {method: "gen_getTransactionStatus"; params: [hash: TransactionHash]}
| {method: "eth_call"; params: [requestParams: any, blockNumberOrHash: string]}
| {method: "eth_sendRawTransaction"; params: [signedTransaction: string]}
| {method: "gen_getContractSchema"; params: [address: Address]}
Expand Down Expand Up @@ -80,6 +82,8 @@ export type GenLayerClient<TGenLayerChain extends GenLayerChain> = Omit<
consensusMaxRotations?: number;
}) => Promise<`0x${string}`>;
getTransaction: (args: {hash: TransactionHash}) => Promise<GenLayerTransaction>;
getStudioTransactionByHash: (args: {hash: TransactionHash; full?: boolean}) => Promise<GenLayerTransaction>;
getTransactionStatus: (args: {hash: TransactionHash}) => Promise<TransactionStatus>;
getCurrentNonce: (args: {address: Address}) => Promise<number>;
estimateTransactionGas: (transactionParams: {
from?: Address;
Expand Down