Skip to content

Commit

Permalink
Deployed: viem migration bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bh2smith committed Sep 16, 2024
1 parent 8e291cd commit 6e69d4d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
4 changes: 2 additions & 2 deletions examples/send-tx.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import dotenv from "dotenv";
import { ethers } from "ethers";
import { setupAdapter } from "near-ca";

import { loadArgs, loadEnv } from "./cli";
import { TransactionManager } from "../src";
Expand All @@ -19,7 +18,8 @@ async function main(): Promise<void> {
pimlicoKey,
privateKey: nearAccountPrivateKey,
});

const deployed = await txManager.safeDeployed(chainId);
console.log("Deployed?", deployed)

Check failure on line 22 in examples/send-tx.ts

View workflow job for this annotation

GitHub Actions / types

Missing semicolon
const transactions = [
// TODO: Replace dummy transaction with real user transaction.
{
Expand Down
7 changes: 3 additions & 4 deletions src/tx-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Erc4337Bundler } from "./lib/bundler";
import { encodeMulti } from "./lib/multisend";
import { ContractSuite } from "./lib/safe";
import { MetaTransaction, UserOperation, UserOperationReceipt } from "./types";
import { packSignature } from "./util";
import { isContract, packSignature } from "./util";

export class TransactionManager {
readonly nearAdapter: NearEthAdapter;
Expand Down Expand Up @@ -177,12 +177,11 @@ export class TransactionManager {
}

async safeDeployed(chainId: number): Promise<boolean> {
// Early exit if already known.
if (chainId in this.deployedChains) {
return true;
}
const provider = Network.fromChainId(chainId).client;
const deployed =
(await provider.getCode({ address: this.address })) !== "0x";
const deployed = await isContract(this.address, chainId);
if (deployed) {
this.deployedChains.add(chainId);
}
Expand Down
18 changes: 12 additions & 6 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Hex, concatHex, encodePacked, toHex } from "viem";
import { Address, Hex, concatHex, encodePacked, toHex } from "viem";

import { PaymasterData, MetaTransaction } from "./types";

Check failure on line 3 in src/util.ts

View workflow job for this annotation

GitHub Actions / types

There should be at least one empty line between import groups
import { Network } from "near-ca";

Check failure on line 4 in src/util.ts

View workflow job for this annotation

GitHub Actions / types

`near-ca` import should occur before import of `viem`

export const PLACEHOLDER_SIG = encodePacked(["uint48", "uint48"], [0, 0]);

Expand All @@ -24,15 +25,20 @@ export function packPaymasterData(data: PaymasterData): Hex {
return (
data.paymaster
? concatHex([
data.paymaster!,
toHex(BigInt(data.paymasterVerificationGasLimit || 0n), { size: 16 }),
toHex(BigInt(data.paymasterPostOpGasLimit || 0n), { size: 16 }),
data.paymasterData || "0x",
])
data.paymaster!,
toHex(BigInt(data.paymasterVerificationGasLimit || 0n), { size: 16 }),
toHex(BigInt(data.paymasterPostOpGasLimit || 0n), { size: 16 }),
data.paymasterData || "0x",
])
: "0x"
) as Hex;
}

export function containsValue(transactions: MetaTransaction[]): boolean {
return transactions.some((tx) => tx.value !== "0");
}

export async function isContract(address: Address, chainId: number): Promise<boolean> {
const client = Network.fromChainId(chainId).client;
return !!(await client.getCode({ address }));
}

0 comments on commit 6e69d4d

Please sign in to comment.