Skip to content

Commit

Permalink
feat: make entry point contract as an optional param to SCA class
Browse files Browse the repository at this point in the history
  • Loading branch information
denniswon committed Oct 31, 2023
1 parent 96a3f8c commit 0317d23
Show file tree
Hide file tree
Showing 27 changed files with 91 additions and 108 deletions.
1 change: 0 additions & 1 deletion packages/accounts/src/kernel-zerodev/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const provider = new KernelAccountProvider(
new KernelSmartContractAccount({
owner,
index: 0n,
entryPointAddress,
chain,
factoryAddress: KERNEL_ACCOUNT_FACTORY_ADDRESS,
rpcClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe("Kernel Account Tests", () => {
validatorAddress: "0x180D6465F921C7E0DEA0040107D342c87455fFF5" as Address,
accountFactoryAddress:
"0x5D006d3880645ec6e254E18C1F879DAC9Dd71A39" as Address,
entryPointAddress,
};

const owner = LocalAccountSigner.privateKeyToAccountSigner(config.privateKey);
Expand All @@ -51,7 +50,6 @@ describe("Kernel Account Tests", () => {
function account(index: bigint, owner = mockOwner) {
const accountParams: KernelSmartAccountParams = {
rpcClient: provider.rpcClient,
entryPointAddress: config.entryPointAddress,
chain: config.chain,
owner: owner,
factoryAddress: config.accountFactoryAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ describe("Kernel Account Tests", () => {
function account(index: bigint, owner = mockOwner) {
const accountParams: KernelSmartAccountParams = {
rpcClient: provider.rpcClient,
entryPointAddress: config.entryPointAddress,
chain: config.chain,
owner: owner,
factoryAddress: config.accountFactoryAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { polygonMumbai, type Chain } from "viem/chains";
import { describe, it } from "vitest";
import { LightSmartContractAccount } from "../account.js";
import { getDefaultLightAccountFactoryAddress } from "../utils.js";

describe("Light Account Tests", () => {
const dummyMnemonic =
Expand Down Expand Up @@ -91,7 +92,7 @@ const givenConnectedProvider = ({
entryPointAddress: dummyEntryPointAddress,
chain,
owner,
factoryAddress: "0xLIGHT_ACCOUNT_FACTORY_ADDRESS",
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient: provider,
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
LocalAccountSigner,
SmartAccountProvider,
getDefaultEntryPointAddress,
type SmartAccountSigner,
} from "@alchemy/aa-core";
import { isAddress, type Address, type Chain, type Hash } from "viem";
Expand All @@ -17,8 +16,6 @@ import {
} from "./constants.js";

const chain = sepolia;
const entryPointAddress = getDefaultEntryPointAddress(chain);
const factoryAddress = getDefaultLightAccountFactoryAddress(chain);

describe("Light Account Tests", () => {
const owner: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner(
Expand Down Expand Up @@ -194,10 +191,9 @@ const givenConnectedProvider = ({
}).connect(
(provider) =>
new LightSmartContractAccount({
entryPointAddress,
chain,
owner,
factoryAddress,
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient: provider,
accountAddress,
})
Expand Down
6 changes: 1 addition & 5 deletions packages/alchemy/e2e-tests/simple-account.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
SimpleSmartContractAccount,
getDefaultEntryPointAddress,
getDefaultSimpleAccountFactoryAddress,
type SmartAccountSigner,
} from "@alchemy/aa-core";
Expand All @@ -11,8 +10,6 @@ import { AlchemyProvider } from "../src/provider.js";
import { API_KEY, OWNER_MNEMONIC, PAYMASTER_POLICY_ID } from "./constants.js";

const chain = polygonMumbai;
const entryPointAddress = getDefaultEntryPointAddress(chain);
const factoryAddress = getDefaultSimpleAccountFactoryAddress(chain);

describe("Simple Account Tests", () => {
const ownerAccount = mnemonicToAccount(OWNER_MNEMONIC);
Expand Down Expand Up @@ -174,10 +171,9 @@ const givenConnectedProvider = ({
}).connect(
(provider) =>
new SimpleSmartContractAccount({
entryPointAddress,
chain,
owner,
factoryAddress,
factoryAddress: getDefaultSimpleAccountFactoryAddress(chain),
rpcClient: provider,
accountAddress,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/alchemy/src/__tests__/provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const givenConnectedProvider = ({
entryPointAddress: dummyEntryPointAddress,
chain,
owner,
factoryAddress: "0xSIMPLE_ACCOUNT_FACTORY_ADDRESS",
factoryAddress: AACoreModule.getDefaultSimpleAccountFactoryAddress(chain),
rpcClient: provider,
});

Expand Down
8 changes: 2 additions & 6 deletions packages/core/e2e-tests/simple-account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import { generatePrivateKey } from "viem/accounts";
import { polygonMumbai } from "viem/chains";
import { SimpleSmartContractAccount } from "../src/account/simple.js";
import {
getDefaultEntryPointAddress,
getDefaultSimpleAccountFactoryAddressAddress,
getDefaultSimpleAccountFactoryAddress,
type SmartAccountSigner,
} from "../src/index.js";
import { SmartAccountProvider } from "../src/provider/base.js";
import { LocalAccountSigner } from "../src/signer/local-account.js";
import { API_KEY, OWNER_MNEMONIC, RPC_URL } from "./constants.js";

const chain = polygonMumbai;
const entryPointAddress = getDefaultEntryPointAddress(chain);
const factoryAddress = getDefaultSimpleAccountFactoryAddressAddress(chain);

describe("Simple Account Tests", () => {
const owner: SmartAccountSigner =
Expand Down Expand Up @@ -77,10 +74,9 @@ const givenConnectedProvider = ({
}).connect(
(provider) =>
new SimpleSmartContractAccount({
entryPointAddress,
chain,
owner,
factoryAddress,
factoryAddress: getDefaultSimpleAccountFactoryAddress(chain),
rpcClient: provider,
accountAddress,
})
Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/account/__tests__/simple.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { polygonMumbai, type Chain } from "viem/chains";
import { describe, it } from "vitest";
import { getDefaultSimpleAccountFactoryAddress } from "../../index.js";
import { SmartAccountProvider } from "../../provider/base.js";
import { LocalAccountSigner } from "../../signer/local-account.js";
import { type SmartAccountSigner } from "../../signer/types.js";
Expand All @@ -11,6 +12,7 @@ describe("Account Simple Tests", () => {
"test test test test test test test test test test test test";
const owner: SmartAccountSigner =
LocalAccountSigner.mnemonicToAccountSigner(dummyMnemonic);

const chain = polygonMumbai;

it("should correctly sign the message", async () => {
Expand Down Expand Up @@ -55,10 +57,9 @@ const givenConnectedProvider = ({
chain,
}).connect((provider) => {
const account = new SimpleSmartContractAccount({
entryPointAddress: "0xENTRYPOINT_ADDRESS",
chain,
owner,
factoryAddress: "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
factoryAddress: getDefaultSimpleAccountFactoryAddress(chain),
rpcClient: provider,
});

Expand Down
24 changes: 20 additions & 4 deletions packages/core/src/account/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { Logger } from "../logger.js";
import type { SmartAccountSigner } from "../signer/types.js";
import { wrapSignatureWith6492 } from "../signer/utils.js";
import type { BatchUserOperationCallData } from "../types.js";
import { getDefaultEntryPointAddress } from "../utils/defaults.js";
import type { ISmartContractAccount, SignTypedDataParams } from "./types.js";

export enum DeploymentState {
Expand All @@ -31,10 +32,24 @@ export interface BaseSmartAccountParams<
TTransport extends SupportedTransports = Transport
> {
rpcClient: string | PublicErc4337Client<TTransport>;
entryPointAddress: Address;
factoryAddress: Address;
owner?: SmartAccountSigner | undefined;
chain: Chain;

/**
* The address of the entry point contract.
* If not provided, the default entry point contract will be used.
* Check out https://docs.alchemy.com/reference/eth-supportedentrypoints for all the supported entrypoints
*/
entryPointAddress?: Address;

/**
* Owner account signer for the account if there is one.
*/
owner?: SmartAccountSigner | undefined;

/**
* The address of the account if it is already deployed.
*/
accountAddress?: Address;
}

Expand All @@ -57,7 +72,8 @@ export abstract class BaseSmartContractAccount<
| PublicErc4337Client<HttpTransport>;

constructor(params: BaseSmartAccountParams<TTransport>) {
this.entryPointAddress = params.entryPointAddress;
this.entryPointAddress =
params.entryPointAddress ?? getDefaultEntryPointAddress(params.chain);

const rpcUrl =
typeof params.rpcClient === "string"
Expand Down Expand Up @@ -99,7 +115,7 @@ export abstract class BaseSmartContractAccount<
this.owner = params.owner;

this.entryPoint = getContract({
address: params.entryPointAddress,
address: this.entryPointAddress,
abi: EntryPointAbi,
// Need to cast this as PublicClient or else it breaks ABI typing.
// This is valid because our PublicClient is a subclass of PublicClient
Expand Down
6 changes: 1 addition & 5 deletions packages/ethers/e2e-tests/simple-account.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {
SimpleSmartContractAccount,
getChain,
getDefaultEntryPointAddress,
getDefaultSimpleAccountFactoryAddress,
type Address,
} from "@alchemy/aa-core";
Expand All @@ -13,8 +12,6 @@ import { convertWalletToAccountSigner } from "../src/utils.js";
import { API_KEY, OWNER_MNEMONIC, RPC_URL } from "./constants.js";

const chain = polygonMumbai;
const entryPointAddress = getDefaultEntryPointAddress(chain);
const factoryAddress = getDefaultSimpleAccountFactoryAddress(chain);

describe("Simple Account Tests", async () => {
const alchemy = new Alchemy({
Expand Down Expand Up @@ -74,10 +71,9 @@ const givenConnectedProvider = ({
EthersProviderAdapter.fromEthersProvider(alchemyProvider).connectToAccount(
(rpcClient) =>
new SimpleSmartContractAccount({
entryPointAddress,
chain: getChain(alchemyProvider.network.chainId),
owner: convertWalletToAccountSigner(owner),
factoryAddress,
factoryAddress: getDefaultSimpleAccountFactoryAddress(chain),
rpcClient,
accountAddress,
})
Expand Down
11 changes: 8 additions & 3 deletions packages/ethers/src/__tests__/provider-adapter.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { SimpleSmartContractAccount, getChain } from "@alchemy/aa-core";
import {
SimpleSmartContractAccount,
getChain,
getDefaultSimpleAccountFactoryAddress,
} from "@alchemy/aa-core";
import { Wallet } from "@ethersproject/wallet";
import { Alchemy, Network, type AlchemyProvider } from "alchemy-sdk";
import { EthersProviderAdapter } from "../../src/provider-adapter.js";
Expand Down Expand Up @@ -37,10 +41,11 @@ const givenConnectedProvider = ({
EthersProviderAdapter.fromEthersProvider(alchemyProvider).connectToAccount(
(rpcClient) => {
const account = new SimpleSmartContractAccount({
entryPointAddress: "0xENTRYPOINT_ADDRESS",
chain: getChain(alchemyProvider.network.chainId),
owner: convertWalletToAccountSigner(owner),
factoryAddress: "0xSIMPLE_ACCOUNT_FACTORY_ADDRESS",
factoryAddress: getDefaultSimpleAccountFactoryAddress(
getChain(alchemyProvider.network.chainId)
),
rpcClient,
});

Expand Down
11 changes: 8 additions & 3 deletions site/packages/aa-ethers/provider-adapter/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ Notable differences between `EthersProviderAdapter` and `JsonRpcProvider` are im

```ts [example.ts]
import { provider } from "./ethers-provider";
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from "@alchemy/aa-accounts";
import { LocalAccountSigner, type SmartAccountSigner } from "@alchemy/aa-core";
import { sepolia } from "viem/chains";
// [!code focus:99]
// EIP-1193 compliant requests
const chainId = await provider.send("eth_chainId", []);
Expand All @@ -43,9 +49,8 @@ const owner: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner(
const signer = provider.connectToAccount(
(rpcClient) =>
new LightSmartContractAccount({
entryPointAddress: entryPointAddress,
chain: polygonMumbai,
factoryAddress: "0xfactoryAddress",
chain: sepolia,
factoryAddress: getDefaultLightAccountFactoryAddress(sepolia),
rpcClient,
owner,
})
Expand Down
8 changes: 3 additions & 5 deletions site/smart-accounts/signers/capsule.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,16 @@ import { sepolia } from "viem/chains";
import { capsuleSigner } from "./capsule";

const chain = sepolia;
const entryPointAddress = getDefaultEntryPointAddress(chain);
const factoryAddress = getDefaultLightAccountFactoryAddress(chain);

const provider = new AlchemyProvider({
apiKey: "ALCHEMY_API_KEY",
chain,
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
entryPointAddress,
chain: rpcClient.chain,
chain,
owner: capsuleSigner,
factoryAddress,
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient,
})
);
Expand Down
8 changes: 3 additions & 5 deletions site/smart-accounts/signers/dynamic.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,16 @@ import { sepolia } from "viem/chains";
import { dynamicSigner } from "./dynamic";

const chain = sepolia;
const entryPointAddress = getDefaultEntryPointAddress(chain);
const factoryAddress = getDefaultLightAccountFactoryAddress(chain);

const provider = new AlchemyProvider({
apiKey: "ALCHEMY_API_KEY",
chain,
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
entryPointAddress,
chain: rpcClient.chain,
chain,
owner: dynamicSigner,
factoryAddress,
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient,
})
);
Expand Down
8 changes: 5 additions & 3 deletions site/smart-accounts/signers/fireblocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ Let's see it in action with `aa-alchemy` and `LightSmartContractAccount` from `a

```ts [example.ts]
import { AlchemyProvider } from "@alchemy/aa-alchemy";
import { LightSmartContractAccount } from "@alchemy/aa-accounts";
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from "@alchemy/aa-accounts";
import { sepolia } from "viem/chains";
import { fireblocksSigner } from "./fireblocks";

Expand All @@ -66,10 +69,9 @@ const provider = new AlchemyProvider({
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
entryPointAddress: "0x...",
chain: rpcClient.chain,
owner: fireblocksSigner,
factoryAddress: "0x...",
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient,
})
);
Expand Down
10 changes: 6 additions & 4 deletions site/smart-accounts/signers/lit.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ We can link our `SmartAccountSigner` to a `LightSmartContractAccount` from `aa-a

```ts [example.ts]
import { AlchemyProvider } from "@alchemy/aa-alchemy";
import { LightSmartContractAccount } from "@alchemy/aa-accounts";
import {
LightSmartContractAccount,
getDefaultLightAccountFactoryAddress,
} from "@alchemy/aa-accounts";
import { litSigner } from "./lit";

const chain = sepolia;
Expand All @@ -87,10 +90,9 @@ const provider = new AlchemyProvider({
}).connect(
(rpcClient) =>
new LightSmartContractAccount({
entryPointAddress: "0x...",
chain: rpcClient.chain,
chain,
owner: litSigner,
factoryAddress: "0x...",
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
rpcClient,
})
);
Expand Down
Loading

0 comments on commit 0317d23

Please sign in to comment.