Skip to content

Commit

Permalink
refactor!: move chain definitions out of aa-sdk core
Browse files Browse the repository at this point in the history
  • Loading branch information
moldy530 committed Jun 24, 2024
1 parent 6d1dea9 commit cd0809e
Show file tree
Hide file tree
Showing 34 changed files with 312 additions and 325 deletions.
2 changes: 1 addition & 1 deletion aa-sdk/core/src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { sepolia } from "@aa-sdk/core";
import { sepolia } from "viem/chains";
import { getEntryPoint } from "../entrypoint/index.js";
import { stringToIndex } from "../utils/index.js";

Expand Down
6 changes: 3 additions & 3 deletions aa-sdk/core/src/account/__tests__/simple.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
type Address,
type Chain,
} from "viem";
import { sepolia } from "viem/chains";
import { describe, it } from "vitest";
import { sepolia } from "../../chains/index.js";
import { createBundlerClientFromExisting } from "../../client/bundlerClient.js";
import { createSmartAccountClient } from "../../client/smartAccountClient.js";
import { LocalAccountSigner } from "../../signer/local-account.js";
Expand Down Expand Up @@ -96,14 +96,14 @@ describe("Account Simple Tests", async () => {
chain: Chain;
}) =>
createSmartAccountClient({
transport: http(`${chain.rpcUrls.alchemy.http[0]}/${"test"}`),
transport: http(`https://test.com`),
chain: chain,
account: await createSimpleSmartAccount({
chain,
signer,
accountAddress: "0x1234567890123456789012345678901234567890",
factoryAddress: getDefaultSimpleAccountFactoryAddress(chain),
transport: http(`${chain.rpcUrls.alchemy.http[0]}/${"test"}`),
transport: http(`https://test.com`),
}),
});
});
194 changes: 0 additions & 194 deletions aa-sdk/core/src/chains/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion aa-sdk/core/src/client/smartAccountClient.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { polygonMumbai } from "@aa-sdk/core";
import { custom, type Transaction } from "viem";
import { polygonMumbai } from "viem/chains";
import type { SpyInstance } from "vitest";
import * as receiptActions from "../actions/bundler/getUserOperationReceipt.js";
import type { UserOperationReceipt } from "../types.js";
Expand Down
3 changes: 1 addition & 2 deletions aa-sdk/core/src/ens/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { Chain } from "viem/chains";
import * as chains from "viem/chains";
import { mainnet } from "../chains/index.js";
import { mainnet, type Chain } from "viem/chains";

export const ChainsById: Map<number, chains.Chain> = new Map(
Object.values(chains).map((x) => [x.id, x])
Expand Down
23 changes: 0 additions & 23 deletions aa-sdk/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,6 @@ export { sendTransactions } from "./actions/smartAccount/sendTransactions.js";
export { sendUserOperation } from "./actions/smartAccount/sendUserOperation.js";
export type * from "./actions/smartAccount/types.js";
export { waitForUserOperationTransaction } from "./actions/smartAccount/waitForUserOperationTransacation.js";
export {
arbitrum,
arbitrumGoerli,
arbitrumSepolia,
base,
baseGoerli,
baseSepolia,
fraxtal,
fraxtalSepolia,
goerli,
mainnet,
optimism,
optimismGoerli,
optimismSepolia,
polygon,
polygonAmoy,
polygonMumbai,
sepolia,
zora,
zoraSepolia,
} from "./chains/index.js";
export type * from "./client/bundlerClient.js";
export {
createBundlerClient,
Expand Down Expand Up @@ -136,7 +115,6 @@ export { split, type SplitTransportParams } from "./transport/split.js";
export type * from "./types.js";
export type * from "./utils/index.js";
export {
AlchemyChainMap,
BigNumberishRangeSchema,
BigNumberishSchema,
ChainSchema,
Expand All @@ -154,7 +132,6 @@ export {
concatPaymasterAndData,
deepHexlify,
filterUndefined,
getChain,
getDefaultSimpleAccountFactoryAddress,
getDefaultUserOperationFeeOptions,
isBigNumberish,
Expand Down
4 changes: 2 additions & 2 deletions aa-sdk/core/src/signer/__tests__/wallet-client.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { polygonMumbai } from "@aa-sdk/core";
import { createWalletClient, http } from "viem";
import { mnemonicToAccount } from "viem/accounts";
import { WalletClientSigner } from "../wallet-client.js";
Expand All @@ -10,7 +9,8 @@ describe("Wallet Client Signer Tests", () => {
const wallet = mnemonicToAccount(dummyMnemonic);
const walletClient = createWalletClient({
account: wallet,
transport: http(`${polygonMumbai.rpcUrls.alchemy.http[0]}/test`),
// just a nonsense URL
transport: http(`https://rpc.testnet.viem.io`),
});

const smartAccountSigner: WalletClientSigner = new WalletClientSigner(
Expand Down
7 changes: 3 additions & 4 deletions aa-sdk/core/src/utils/defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
baseGoerli,
baseSepolia,
fraxtal,
fraxtalSepolia,
goerli,
mainnet,
optimism,
Expand All @@ -19,11 +18,11 @@ import {
sepolia,
zora,
zoraSepolia,
} from "../chains/index.js";
} from "viem/chains";
import { defaultEntryPointVersion } from "../entrypoint/index.js";
import type { EntryPointVersion } from "../entrypoint/types.js";
import { DefaultFactoryNotDefinedError } from "../errors/account.js";
import type { UserOperationFeeOptions } from "../types";
import type { UserOperationFeeOptions } from "../types.js";

/**
* Utility method returning the default simple account factory address given a {@link Chain} object
Expand Down Expand Up @@ -51,7 +50,7 @@ export const getDefaultSimpleAccountFactoryAddress = (
case baseGoerli.id:
case baseSepolia.id:
case fraxtal.id:
case fraxtalSepolia.id:
case 2523:
case zora.id:
case zoraSepolia.id:
return "0x15Ba39375ee2Ab563E8873C8390be6f2E2F50232";
Expand Down
23 changes: 0 additions & 23 deletions aa-sdk/core/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,7 @@
import type { Chain } from "viem";
import { toHex } from "viem";
import * as chains from "viem/chains";
import * as alchemyChains from "../chains/index.js";
import type { PromiseOrValue } from "../types.js";
import type { RecordableKeys } from "./types.js";

export const AlchemyChainMap = new Map<number, Chain>(
Object.values(alchemyChains).map((c) => [c.id, c])
);

/**
* Utility method for converting a chainId to a {@link Chain} object
*
* @param chainId - the chainId to convert
* @returns a {@link Chain} object for the given chainId
* @throws if the chainId is not found
*/
export const getChain = (chainId: number): Chain => {
for (const chain of Object.values(chains)) {
if (chain.id === chainId) {
return AlchemyChainMap.get(chain.id) ?? chain;
}
}
throw new Error("could not find chain");
};

/**
* Utility function that allows for piping a series of async functions together
*
Expand Down
Loading

0 comments on commit cd0809e

Please sign in to comment.