Skip to content

Commit

Permalink
Merge pull request #144 from bcnmy/feat/paymaster-imports
Browse files Browse the repository at this point in the history
features/paymaster-impots
  • Loading branch information
livingrockrises authored Oct 23, 2023
2 parents 0337ca6 + 4e49c17 commit 1d5fdc7
Show file tree
Hide file tree
Showing 10 changed files with 265 additions and 150 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/push_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ jobs:
- name: Create a fake .secret file
run: echo "primary twist rack vendor diagram image used route theme frown either will" > .secret
- name: Install dependencies
run: yarn install --frozen-lockfile && yarn build
run: yarn install --frozen-lockfile
- name: Update submodule
run: git submodule update --init --recursive && git submodule sync
- name: Create a fake .secret file inside submodule
run: cd biconomy-paymasters && echo "primary twist rack vendor diagram image used route theme frown either will" > .secret && cd ..
- name: Install submodules dependencies
run: cd biconomy-paymasters && yarn install --frozen-lockfile && npx hardhat compile && cd ..
- name: build after submodule is built
run: yarn build
- name: Lint sources
run:
yarn run lint
Expand All @@ -43,7 +51,19 @@ jobs:
run: echo "primary twist rack vendor diagram image used route theme frown either will" > .secret

- name: Install dependencies
run: yarn install --frozen-lockfile && yarn build
run: yarn install --frozen-lockfile

- name: Update submodule
run: git submodule update --init --recursive && git submodule sync

- name: Create a fake .secret file inside submodule
run: cd biconomy-paymasters && echo "primary twist rack vendor diagram image used route theme frown either will" > .secret && cd ..

- name: Install submodules dependencies
run: cd biconomy-paymasters && yarn install --frozen-lockfile && npx hardhat compile && cd ..

- name: build after submodule is built
run: yarn build

- name: Run Hardhat Tests
run: yarn test
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "lib/forge-std"]
path = lib/forge-std
url = https://github.com/foundry-rs/forge-std
[submodule "biconomy-paymasters"]
path = biconomy-paymasters
url = https://github.com/bcnmy/biconomy-paymasters.git
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ Below are the commands you can use for various tasks:

### 🧪 Testing

#### Note if there are issue on paymaster dependencies follow below steps
i. go to submodule directory: biconomy-paymasters
ii. run `yarn` followed by `npx hardhat compile`

to init or update submodules
`git submodule update --remote`
`git submodule update --init`

Run regular tests:

```shell
Expand Down
1 change: 1 addition & 0 deletions biconomy-paymasters
Submodule biconomy-paymasters added at 7bb88f
5 changes: 5 additions & 0 deletions contracts/smart-account/test/TestPaymaster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;

// Mock sol file to get the artifacts generated for this package
import {VerifyingSingletonPaymaster} from "../../../biconomy-paymasters/contracts/verifying/VerifyingSingletonPaymaster.sol";
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@biconomy/account-contracts",
"version": "2.0.1",
"name": "@biconomy/modular-smart-account",
"version": "2.0.0",
"description": "Smart Contract Wallet (SCW) contracts for Biconomy SDK. Enables Account Abstraction, Smart Account, ERC4337, and ERC6900 functionalities.",
"main": "index.js",
"engines": {
Expand Down
22 changes: 22 additions & 0 deletions src/deploy/04_deploy_verifying_paymaster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { DeployFunction } from "hardhat-deploy/types";
import { HardhatRuntimeEnvironment } from "hardhat/types";
import { getEntryPoint } from "../../test/utils/setupHelper";

const deploy: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
const { deployments, getNamedAccounts } = hre;
const { deploy } = deployments;
const { deployer } = await getNamedAccounts();

const entryPoint = await getEntryPoint();

await deploy("VerifyingSingletonPaymaster", {
from: deployer,
args: [deployer, entryPoint.address, deployer],
log: true,
deterministicDeployment: true, // Needed for bundler tests to ensure the entrypoint address does not change b/w tests
autoMine: true,
});
};

deploy.tags = ["verifying-paymaster", "main-suite"];
export default deploy;
26 changes: 23 additions & 3 deletions test/bundler-integration/smart-account/SA.UserOps.specs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ import {
getMockToken,
getEcdsaOwnershipRegistryModule,
getSmartAccountWithModule,
getVerifyingPaymaster,
} from "../../utils/setupHelper";
import { makeEcdsaModuleUserOp } from "../../utils/userOp";
import {
makeEcdsaModuleUserOp,
makeEcdsaModuleUserOpWithPaymaster,
} from "../../utils/userOp";
import { BundlerTestEnvironment } from "../environment/bundlerEnvironment";
import { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";

Expand Down Expand Up @@ -76,10 +80,21 @@ describe("UserOps (with Bundler)", async () => {

await mockToken.mint(userSA.address, ethers.utils.parseEther("1000000"));

const verifyingPaymasterContract = await getVerifyingPaymaster();

await verifyingPaymasterContract.depositFor(await deployer.getAddress(), {
value: ethers.utils.parseEther("2"),
});

await verifyingPaymasterContract.addStake(86400, {
value: ethers.utils.parseEther("2"),
});

return {
entryPoint: await getEntryPoint(),
smartAccountImplementation: await getSmartAccountImplementation(),
smartAccountFactory: await getSmartAccountFactory(),
verifyingPaymaster: verifyingPaymasterContract,
mockToken: mockToken,
ecdsaModule: ecdsaModule,
userSA: userSA,
Expand All @@ -88,14 +103,15 @@ describe("UserOps (with Bundler)", async () => {

describe("validateUserOp ", async () => {
it("Can validate a userOp via proper Authorization Module", async () => {
const { entryPoint, mockToken, userSA, ecdsaModule } = await setupTests();
const { entryPoint, mockToken, userSA, ecdsaModule, verifyingPaymaster } =
await setupTests();

const charlieTokenBalanceBefore = await mockToken.balanceOf(
charlie.address
);
const tokenAmountToTransfer = ethers.utils.parseEther("0.5345");

const userOp = await makeEcdsaModuleUserOp(
const userOp = await makeEcdsaModuleUserOpWithPaymaster(
"execute_ncC",
[
mockToken.address,
Expand All @@ -106,6 +122,10 @@ describe("UserOps (with Bundler)", async () => {
smartAccountOwner,
entryPoint,
ecdsaModule.address,
verifyingPaymaster,
deployer,
0,
0,
{
preVerificationGas: 50000,
}
Expand Down
11 changes: 11 additions & 0 deletions test/utils/setupHelper.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import hre, { deployments, ethers } from "hardhat";
import { Wallet, Contract, BytesLike } from "ethers";
import { EntryPoint__factory } from "../../typechain-types";
import { VerifyingSingletonPaymaster__factory } from "../../biconomy-paymasters/typechain-types";
import type { SignerWithAddress } from "@nomiclabs/hardhat-ethers/signers";
import solc from "solc";

Expand All @@ -12,6 +13,16 @@ export const getEntryPoint = async () => {
);
};

export const getVerifyingPaymaster = async () => {
const VerifyingPaymasterDeployment = await deployments.get(
"VerifyingSingletonPaymaster"
);
return VerifyingSingletonPaymaster__factory.connect(
VerifyingPaymasterDeployment.address,
ethers.provider.getSigner()
);
};

export const getSmartAccountImplementation = async () => {
const SmartAccountImplDeployment = await deployments.get("SmartAccount");
const SmartAccountImpl = await hre.ethers.getContractFactory("SmartAccount");
Expand Down
Loading

0 comments on commit 1d5fdc7

Please sign in to comment.