Skip to content

Commit

Permalink
HOTFIX: Alternate Sepolia RPC for Setup (#102)
Browse files Browse the repository at this point in the history
The standard sepolia rpc is totally down (cf https://chainlist.org/chain/11155111). So we switch to an alternate. This is a hotfix, we hope to introduce an RPC pool to avoid these issues in the future.
  • Loading branch information
bh2smith authored Nov 4, 2024
1 parent 7e1449f commit 8e03f6b
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 12 deletions.
8 changes: 5 additions & 3 deletions examples/send-tx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ async function main(): Promise<void> {
] = await Promise.all([loadEnv(), loadArgs()]);
const chainId = 11155111;
const txManager = await NearSafe.create({
accountId: nearAccountId,
mpcContractId,
mpc: {
accountId: nearAccountId,
mpcContractId,
privateKey: nearAccountPrivateKey,
},
pimlicoKey,
privateKey: nearAccountPrivateKey,
safeSaltNonce: DEFAULT_SAFE_SALT_NONCE,
});
const deployed = await txManager.safeDeployed(chainId);
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const USER_OP_IDENTIFIER = toHex(DOMAIN_SEPARATOR, { size: 16 });
export const DEFAULT_SAFE_SALT_NONCE = BigInt(USER_OP_IDENTIFIER).toString();

export const SENTINEL_OWNERS = "0x0000000000000000000000000000000000000001";

export const DEFAULT_SETUP_RPC = "https://ethereum-sepolia-rpc.publicnode.com";
16 changes: 11 additions & 5 deletions src/lib/safe.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {
Address,
concat,
createPublicClient,
encodeFunctionData,
encodePacked,
getAddress,
getCreate2Address,
Hash,
Hex,
http,
keccak256,
parseAbi,
PublicClient,
Expand All @@ -15,7 +17,11 @@ import {
} from "viem";

import { SAFE_DEPLOYMENTS } from "../_gen/deployments";
import { SENTINEL_OWNERS, USER_OP_IDENTIFIER } from "../constants";
import {
DEFAULT_SETUP_RPC,
SENTINEL_OWNERS,
USER_OP_IDENTIFIER,
} from "../constants";
import {
Deployment,
GasPrice,
Expand All @@ -35,15 +41,15 @@ import {
*/
export class SafeContractSuite {
// Used only for stateless contract reads.
dummyClient: PublicClient;
setupClient: PublicClient;
singleton: Deployment;
proxyFactory: Deployment;
m4337: Deployment;
moduleSetup: Deployment;
entryPoint: Deployment;

constructor() {
this.dummyClient = getClient(11155111);
constructor(rpcUrl: string = DEFAULT_SETUP_RPC) {
this.setupClient = createPublicClient({ transport: http(rpcUrl) });
const deployments = SAFE_DEPLOYMENTS;
this.singleton = deployments.singleton;
this.proxyFactory = deployments.proxyFactory;
Expand All @@ -66,7 +72,7 @@ export class SafeContractSuite {
const initCode = encodePacked(
["bytes", "uint256"],
[
(await this.dummyClient.readContract({
(await this.setupClient.readContract({
address: this.proxyFactory.address,
abi: this.proxyFactory.abi,
functionName: "proxyCreationCode",
Expand Down
5 changes: 3 additions & 2 deletions src/near-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface NearSafeConfig {
// Safe Config:
pimlicoKey: string;
safeSaltNonce?: string;
setupRpc?: string;
}

export class NearSafe {
Expand All @@ -55,12 +56,12 @@ export class NearSafe {
* @returns {Promise<NearSafe>} - A promise that resolves to a new `NearSafe` instance.
*/
static async create(config: NearSafeConfig): Promise<NearSafe> {
const { pimlicoKey } = config;
const { pimlicoKey, setupRpc } = config;
const safeSaltNonce = config.safeSaltNonce || DEFAULT_SAFE_SALT_NONCE;

// const nearAdapter = await mockAdapter();
const nearAdapter = await setupAdapter(config.mpc);
const safePack = new SafeContractSuite();
const safePack = new SafeContractSuite(setupRpc);

const setup = safePack.getSetup([nearAdapter.address]);
const safeAddress = await safePack.addressForSetup(setup, safeSaltNonce);
Expand Down
7 changes: 7 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import {
toBytes,
keccak256,
serializeSignature,
createPublicClient,
http,
} from "viem";

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

export const PLACEHOLDER_SIG = encodePacked(["uint48", "uint48"], [0, 0]);
Expand Down Expand Up @@ -65,6 +68,10 @@ export async function isContract(
}

export function getClient(chainId: number): PublicClient {
// TODO(bh2smith)
if (chainId === 11155111) {
return createPublicClient({ transport: http(DEFAULT_SETUP_RPC) });
}
return Network.fromChainId(chainId).client;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe("Near Safe Requests", () => {
method: "eth_signTypedData_v4",
params: [adapter.mpcAddress, typedDataString],
});

console.log(evmData);
expect(() => decodeTxData({ ...evmData })).not.toThrow();

expect(evmData).toStrictEqual({
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/ethers-safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import { ethers } from "ethers";
import { Address, Hash, Hex } from "viem";

import { DEFAULT_SETUP_RPC } from "../../src";
import {
GasPrice,
MetaTransaction,
Expand Down Expand Up @@ -46,7 +47,7 @@ export class ContractSuite {

static async init(): Promise<ContractSuite> {
// TODO - this is a cheeky hack.
const provider = new ethers.JsonRpcProvider("https://rpc2.sepolia.org");
const provider = new ethers.JsonRpcProvider(DEFAULT_SETUP_RPC);
const safeDeployment = (fn: DeploymentFunction): Promise<ethers.Contract> =>
getDeployment(fn, { provider, version: "1.4.1" });
const m4337Deployment = async (
Expand Down

0 comments on commit 8e03f6b

Please sign in to comment.