Skip to content

Commit

Permalink
use accounts v2 from imports + add submodule + update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
livingrockrises committed Oct 11, 2023
1 parent 7bb88f8 commit 3c46f19
Show file tree
Hide file tree
Showing 17 changed files with 780 additions and 1,103 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "biconomy-sa-v2"]
path = scw-contracts
url = https://github.com/bcnmy/scw-contracts
13 changes: 13 additions & 0 deletions contracts/test/accounts/BiconomyAccountFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

// Could also use published package or added submodule.

import {SmartAccountFactory} from "@biconomy-devx/account-contracts-v2/contracts/smart-account/factory/SmartAccountFactory.sol";

contract BiconomyAccountFactory is SmartAccountFactory {
constructor(
address _basicImplementation,
address _newOwner
) SmartAccountFactory(_basicImplementation, _newOwner) {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

import "@biconomy/account-contracts/contracts/smart-contract-wallet/SmartAccount.sol";
import {SmartAccount} from "@biconomy-devx/account-contracts-v2/contracts/smart-account/SmartAccount.sol";
import {IEntryPoint} from "@account-abstraction/contracts/interfaces/IEntryPoint.sol";

// Could also use published package or added submodule.

contract BiconomyAccountImplementation is SmartAccount {
/**
Expand Down
File renamed without changes.
10 changes: 0 additions & 10 deletions contracts/test/wallets/BiconomyAccountFactory.sol

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"typescript": "^5.0.4"
},
"dependencies": {
"@biconomy-devx/account-contracts-v2": "^2.0.2",
"@account-abstraction/contracts": "^0.6.0",
"@biconomy/account-contracts": "^2.0.0",
"@chainlink/contracts": "^0.6.0",
Expand Down
1 change: 1 addition & 0 deletions scw-contracts
Submodule scw-contracts added at 3bf128
2 changes: 1 addition & 1 deletion test/TokenPaymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ contract TokenPaymasterTest is Test {
console2.log(priceToLog);

smartAccount = new BiconomyAccountImplementation(_ep);
smartAccountFactory = new BiconomyAccountFactory(address(smartAccount));
smartAccountFactory = new BiconomyAccountFactory(address(smartAccount), users[4]);

address accountAddress = smartAccountFactory.deployCounterFactualAccount(charlie, 0);
console2.log(" smart account address ", accountAddress);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
EntryPoint__factory,
TestToken,
} from "../../../account-abstraction/typechain";
import { EcdsaOwnershipRegistryModule, EcdsaOwnershipRegistryModule__factory } from "@biconomy-devx/account-contracts-v2/dist/types";

export const AddressZero = ethers.constants.AddressZero;
import { arrayify, parseEther } from "ethers/lib/utils";
Expand Down Expand Up @@ -77,7 +78,7 @@ export const encodeERC20Approval = (
spender: string,
amount: BigNumber
) => {
return account.interface.encodeFunctionData("executeCall", [
return account.interface.encodeFunctionData("execute_ncC", [
token.address,
0,
token.interface.encodeFunctionData("approve", [spender, amount]),
Expand All @@ -97,6 +98,7 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
let oracleAggregator: ChainlinkOracleAggregator;

let smartWalletImp: BiconomyAccountImplementation;
let ecdsaModule: EcdsaOwnershipRegistryModule;
let walletFactory: BiconomyAccountFactory;
const abi = ethers.utils.defaultAbiCoder;

Expand Down Expand Up @@ -125,6 +127,8 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
deployer
).deploy(walletOwnerAddress);

ecdsaModule = await new EcdsaOwnershipRegistryModule__factory(deployer).deploy();

const MockToken = await ethers.getContractFactory("MockToken");
token = await MockToken.deploy();
await token.deployed();
Expand Down Expand Up @@ -166,14 +170,24 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
).deploy(entryPoint.address);

walletFactory = await new BiconomyAccountFactory__factory(deployer).deploy(
smartWalletImp.address
smartWalletImp.address,
walletOwnerAddress
);

await walletFactory.deployCounterFactualAccount(walletOwnerAddress, 0);
await walletFactory.connect(deployer).addStake(entryPoint.address, 86400, { value: parseEther("2") })

const ecdsaOwnershipSetupData =
ecdsaModule.interface.encodeFunctionData(
"initForSmartAccount",
[walletOwnerAddress]
);

const smartAccountDeploymentIndex = 0;

await walletFactory.deployCounterFactualAccount(ecdsaModule.address, ecdsaOwnershipSetupData, smartAccountDeploymentIndex);

const expected = await walletFactory.getAddressForCounterFactualAccount(
walletOwnerAddress,
0
ecdsaModule.address, ecdsaOwnershipSetupData, smartAccountDeploymentIndex
);

await token.mint(walletOwnerAddress, ethers.utils.parseEther("1000000"));
Expand All @@ -182,13 +196,9 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {

paymasterAddress = sampleTokenPaymaster.address;

await sampleTokenPaymaster
.connect(deployer)
.addStake(1, { value: parseEther("2") });

await entryPoint.depositTo(paymasterAddress, { value: parseEther("2") });

await sampleTokenPaymaster.addStake(100, {
await sampleTokenPaymaster.addStake(86400, {
value: parseEther("10")
});
});
Expand Down Expand Up @@ -265,6 +275,13 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
"nonce"
);

const signatureWithModuleAddress = ethers.utils.defaultAbiCoder.encode(
["bytes", "address"],
[userOp.signature, ecdsaModule.address]
);

userOp.signature = signatureWithModuleAddress

await environment.sendUserOperation(userOp, entryPoint.address);

const ev = await getUserOpEvent(entryPoint);
Expand Down
44 changes: 37 additions & 7 deletions test/bundler-integration/token-paymaster/btpm-undeployed-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
MockPriceFeed__factory,
MockToken,
} from "../../../typechain-types";
import { EcdsaOwnershipRegistryModule, EcdsaOwnershipRegistryModule__factory } from "@biconomy-devx/account-contracts-v2/dist/types";

import { fillAndSign } from "../../../account-abstraction/test/UserOp";
import {
Expand Down Expand Up @@ -77,7 +78,7 @@ export const encodeERC20Approval = (
spender: string,
amount: BigNumber
) => {
return account.interface.encodeFunctionData("executeCall", [
return account.interface.encodeFunctionData("execute_ncC", [
token.address,
0,
token.interface.encodeFunctionData("approve", [spender, amount]),
Expand All @@ -96,7 +97,9 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
let sampleTokenPaymaster: BiconomyTokenPaymaster;
let oracleAggregator: ChainlinkOracleAggregator;

// Could also use published package or added submodule (for Account Implementation and Factory)
let smartWalletImp: BiconomyAccountImplementation;
let ecdsaModule: EcdsaOwnershipRegistryModule;
let walletFactory: BiconomyAccountFactory;
let environment: BundlerTestEnvironment;

Expand Down Expand Up @@ -125,6 +128,8 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
deployer
).deploy(walletOwnerAddress);

ecdsaModule = await new EcdsaOwnershipRegistryModule__factory(deployer).deploy();

const MockToken = await ethers.getContractFactory("MockToken");
token = await MockToken.deploy();
await token.deployed();
Expand Down Expand Up @@ -162,12 +167,22 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
).deploy(entryPoint.address);

walletFactory = await new BiconomyAccountFactory__factory(deployer).deploy(
smartWalletImp.address
smartWalletImp.address,
walletOwnerAddress
);

await walletFactory.connect(deployer).addStake(entryPoint.address, 86400, { value: parseEther("2") })

const ecdsaOwnershipSetupData =
ecdsaModule.interface.encodeFunctionData(
"initForSmartAccount",
[walletOwnerAddress]
);

const smartAccountDeploymentIndex = 0;

const expected = await walletFactory.getAddressForCounterFactualAccount(
walletOwnerAddress,
0
ecdsaModule.address, ecdsaOwnershipSetupData, smartAccountDeploymentIndex
);

await token.mint(walletOwnerAddress, ethers.utils.parseEther("1000000"));
Expand Down Expand Up @@ -210,10 +225,18 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
const AccountFactory = await ethers.getContractFactory(
"SmartAccountFactory"
);
const ecdsaOwnershipSetupData = ecdsaModule.interface.encodeFunctionData(
"initForSmartAccount",
[owner]
);

const smartAccountDeploymentIndex = 0;

const deploymentData = AccountFactory.interface.encodeFunctionData(
"deployCounterFactualAccount",
[owner, 0]
"deployCounterFactualAccount",
[ecdsaModule.address, ecdsaOwnershipSetupData, smartAccountDeploymentIndex]
);


const userOp1 = await fillAndSign(
{
Expand All @@ -222,7 +245,7 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
callGasLimit: 200000, // need to pass this because for undeployed account it wouldn't estimate accurately
initCode: hexConcat([walletFactory.address, deploymentData]),
nonce: 0,
preVerificationGas: 50000,
preVerificationGas: 60000,
callData: encodeERC20Approval(
userSCW,
token,
Expand Down Expand Up @@ -266,6 +289,13 @@ describe("Biconomy Token Paymaster (with Bundler)", function () {
"nonce"
);

const signatureWithModuleAddress = ethers.utils.defaultAbiCoder.encode(
["bytes", "address"],
[userOp.signature, ecdsaModule.address]
);

userOp.signature = signatureWithModuleAddress

await environment.sendUserOperation(userOp, entryPoint.address);

const ev = await getUserOpEvent(entryPoint);
Expand Down
Loading

0 comments on commit 3c46f19

Please sign in to comment.