Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/devx 349 wallet client signer support #339

Merged
merged 7 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 3 additions & 1 deletion packages/account/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"dependencies": {
"@account-abstraction/contracts": "^0.6.0",
"@account-abstraction/utils": "^0.4.0",
"@alchemy/aa-core": "^1.2.2",
"@biconomy-devx/account-contracts-v2": "npm:@biconomy-devx/account-contracts-v2@^1.0.0",
"@biconomy/bundler": "^3.1.1",
"@biconomy/common": "^3.1.1",
Expand All @@ -50,6 +51,7 @@
"@ethersproject/providers": "^5.7.2",
"ethers": "^5.7.0",
"loglevel": "^1.8.1",
"lru-cache": "^10.0.1"
"lru-cache": "^10.0.1",
"viem": "^1.19.11"
}
}
3 changes: 2 additions & 1 deletion packages/account/src/utils/Types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { BaseValidationModule, ModuleInfo } from "@biconomy/modules";
import { Provider } from "@ethersproject/providers";
import { GasOverheads } from "./Preverificaiton";
import { UserOperation, ChainId } from "@biconomy/core-types";
import { WalletClientSigner } from "@alchemy/aa-core";

export type EntryPointAddresses = {
[address: string]: string;
Expand Down Expand Up @@ -84,7 +85,7 @@ type RequireAtLeastOne<T, Keys extends keyof T = keyof T> = Pick<T, Exclude<keyo
type ConditionalValidationProps = RequireAtLeastOne<
{
defaultValidationModule: BaseValidationModule;
signer: Signer;
signer: Signer | WalletClientSigner;
},
"defaultValidationModule" | "signer"
>;
Expand Down

This file was deleted.

251 changes: 246 additions & 5 deletions packages/account/tests/SmartAccountV2.local.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,22 @@ import {

import { BiconomySmartAccountV2 } from "../src/BiconomySmartAccountV2";
import { ChainId, UserOperation } from "@biconomy/core-types";
import { ECDSAOwnershipValidationModule } from "@biconomy/modules";
import { DEFAULT_ECDSA_OWNERSHIP_MODULE, ECDSAOwnershipValidationModule } from "@biconomy/modules";
import { MultiChainValidationModule } from "@biconomy/modules";
import { BaseValidationModule } from "@biconomy/modules";
import { ECDSAOwnershipRegistryModule_v100 } from "@biconomy/common";
import { MultiChainValidationModule_v100 } from "@biconomy/common";
import { createWalletClient, http } from "viem";
import { localhost } from "viem/chains";
import { SmartAccountSigner, WalletClientSigner } from "@alchemy/aa-core";

const provider = new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545");
const signer = provider.getSigner();
const SENTINEL_MODULE = "0x0000000000000000000000000000000000000001";

const MUMBAI = "https://rpc-mumbai.maticvigil.com";
const testPrivKey = "";

describe("BiconomySmartAccountV2 API Specs", () => {
let owner: Wallet;
let factoryOwner: Wallet;
Expand Down Expand Up @@ -361,8 +367,243 @@ describe("BiconomySmartAccountV2 API Specs", () => {
expect(address).toBe(accountAPI.accountAddress);
}, 10000);

// TODO
// 1. sendSignedUserOp()
// 2. sendUserOp()
// 3. sending userOps using a paymaster
// it("Create and setup ECDSA module with WalletClientSigner", async () => {
VGabriel45 marked this conversation as resolved.
Show resolved Hide resolved

// const wallet = privateKeyToAccount(`0x${testPrivKey}`)

// const walletClient = createWalletClient({
// account: wallet,
// chain: polygonMumbai,
// transport: http(MUMBAI),
// });

// let owner = new WalletClientSigner(
// walletClient,
// "json-rpc"
// );

// let account = await BiconomySmartAccountV2.create({
// chainId: ChainId.POLYGON_MUMBAI,
// entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
// signer: owner,
// });

// const counterFactualAddress = await account.getAccountAddress();
// console.log("Counterfactual address ", counterFactualAddress);

// const module = await ECDSAOwnershipValidationModule.create({
// signer: owner,
// moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
// })

// account.setActiveValidationModule(module);

// });

// it("Create and setup ECDSA module with ethersV5 Signer", async () => {

// const provider = new ethers.providers.JsonRpcProvider(MUMBAI);
// const owner: Signer = new ethers.Wallet(testPrivKey, provider);

// const module = await ECDSAOwnershipValidationModule.create({
// signer: owner,
// moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
// })

// let account = await BiconomySmartAccountV2.create({
// chainId: ChainId.POLYGON_MUMBAI,
// entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
// signer: owner,
// defaultValidationModule: module,
// activeValidationModule: module
// });

// const counterFactualAddress = await account.getAccountAddress();
// console.log("Counterfactual address ", counterFactualAddress);

// expect(counterFactualAddress).toBeDefined();

// expect(module.getAddress()).toBe(DEFAULT_ECDSA_OWNERSHIP_MODULE);

// });

// it("Send user op with ethersV5 signer", async () => {

// const provider = new ethers.providers.JsonRpcProvider(MUMBAI);
// const owner: Signer = new ethers.Wallet(testPrivKey, provider);

// const bundler: IBundler = new Bundler({
// bundlerUrl: "https://bundler.biconomy.io/api/v2/80001/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
// chainId: ChainId.POLYGON_MUMBAI,
// entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
// })

// const module = await ECDSAOwnershipValidationModule.create({
// signer: owner,
// moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
// })

// const newAccount = await BiconomySmartAccountV2.create({
// chainId: ChainId.POLYGON_MUMBAI,
// entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
// signer: owner,
// bundler,
// defaultValidationModule: module,
// activeValidationModule: module
// });

// const accountAddress = await newAccount.getAccountAddress();

// const prefund = {
// to: accountAddress,
// value: ethers.utils.parseEther("0.1"),
// }

// const prefundResp = await owner.sendTransaction(prefund);
// prefundResp.wait();

// const tx = {
// to: await Wallet.createRandom().getAddress(),
// data: "0x"
// }

// const userOp = await newAccount.buildUserOp([tx]);
// const res = await newAccount.sendUserOp(userOp);
// const txhash = await res.waitForTxHash();

// console.log("txhash ", txhash);

// expect(txhash).toBeDefined();

// });

// it("Send user op with WalletClientSigner signer", async () => {

// const wallet = privateKeyToAccount(`0x${testPrivKey}`)

// const walletClient = createWalletClient({
// account: wallet,
// transport: http("https://rpc-mumbai.maticvigil.com"),
// });

// let owner = new WalletClientSigner(
// walletClient,
// "json-rpc"
// );

// const bundler: IBundler = new Bundler({
// bundlerUrl: "https://bundler.biconomy.io/api/v2/80001/nJPK7B3ru.dd7f7861-190d-41bd-af80-6877f74b8f44",
// chainId: ChainId.POLYGON_MUMBAI,
// entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
// })

// const module = await ECDSAOwnershipValidationModule.create({
// signer: owner,
// moduleAddress: DEFAULT_ECDSA_OWNERSHIP_MODULE
// })

// const newAccount = await BiconomySmartAccountV2.create({
// chainId: ChainId.POLYGON_MUMBAI,
// entryPointAddress: DEFAULT_ENTRYPOINT_ADDRESS,
// signer: owner,
// bundler,
// defaultValidationModule: module,
// activeValidationModule: module
// });

// const accountAddress: `0x${string}` = await newAccount.getAccountAddress() as `0x${string}`;

// const prefundResp = await walletClient.sendTransaction({
// account: wallet,
// to: accountAddress,
// value: 100000000000000000n,
// chain: polygonMumbai
// });

// const tx = {
// to: await Wallet.createRandom().getAddress(),
// data: "0x"
// }

// const userOp = await newAccount.buildUserOp([tx]);
// const res = await newAccount.sendUserOp(userOp);
// const txhash = await res.waitForTxHash();

// console.log("txhash ", txhash);

// expect(txhash).toBeDefined();
// });

it("Create smart account with default module (ECDSA) without creating instance or providing module name", async () => {

const account: BiconomySmartAccountV2 = await BiconomySmartAccountV2.create({
chainId: ChainId.GANACHE,
rpcUrl: "http://127.0.0.1:8545",
entryPointAddress: entryPoint.address,
signer,
});

const address = await account.getAccountAddress();
console.log("Module Abstraction Test - Account address ", address);

expect(address).toBe(account.accountAddress);

const module = account.activeValidationModule;
console.log(`ACTIVE MODULE - ${module.getAddress()}`);

expect(module.getAddress()).toBe(DEFAULT_ECDSA_OWNERSHIP_MODULE);

}, 10000);

it("Create smart account with ECDSA module without creating instance", async () => {

const account: BiconomySmartAccountV2 = await BiconomySmartAccountV2.create({
chainId: ChainId.GANACHE,
rpcUrl: "http://127.0.0.1:8545",
entryPointAddress: entryPoint.address,
signer,
});

const address = await account.getAccountAddress();
console.log("Module Abstraction Test - Account address ", address);

expect(address).toBe(account.accountAddress);

const module = account.activeValidationModule as ECDSAOwnershipValidationModule;

console.log(`ACTIVE MODULE - ${module.getAddress()}`);

expect(module.getAddress()).toBe(DEFAULT_ECDSA_OWNERSHIP_MODULE);
}, 10000);

it("Create smart account with default module using WalletClientSigner as signer", async () => {

const walletClient = createWalletClient({
chain: localhost,
transport: http("http://127.0.0.1:8545"),
});

const smartAccountSigner: SmartAccountSigner = new WalletClientSigner(
livingrockrises marked this conversation as resolved.
Show resolved Hide resolved
walletClient,
"json-rpc"
);

const account: BiconomySmartAccountV2 = await BiconomySmartAccountV2.create({
chainId: ChainId.GANACHE,
rpcUrl: "http://127.0.0.1:8545",
entryPointAddress: entryPoint.address,
signer: smartAccountSigner,
});

const address = await account.getAccountAddress();
console.log("Module Abstraction Test - Account address ", address);

expect(address).toBe(account.accountAddress);

const module = account.activeValidationModule;
console.log(`ACTIVE MODULE - ${module.getAddress()}`);

expect(module.getAddress()).toBe(DEFAULT_ECDSA_OWNERSHIP_MODULE);

}, 10000);
});
1 change: 1 addition & 0 deletions packages/modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"access": "public"
},
"dependencies": {
"@alchemy/aa-core": "^1.2.2",
"@biconomy/common": "^3.1.1",
"@biconomy/core-types": "^3.1.1",
"@biconomy/node-client": "^3.1.1",
Expand Down
Loading
Loading