From 682ebe088156d8f89f3202bdd263465a8a8577e1 Mon Sep 17 00:00:00 2001 From: Aniket Singh Date: Sat, 3 Dec 2022 22:57:59 +0530 Subject: [PATCH 1/3] account abstraction template --- package.json | 12 +- .../ERC4337/ERC4337TokenPaymaster.ts | 38 +++ .../ERC4337/ERC4337VerifyPaymaster.ts | 29 +++ src/extension.ts | 14 ++ src/lib/file.ts | 32 ++- src/types/types.ts | 23 ++ src/utils/contracts.ts | 230 ++++++++++++++++++ src/utils/functions.ts | 36 ++- src/utils/networks.ts | 1 - 9 files changed, 410 insertions(+), 5 deletions(-) create mode 100644 src/contracts/ERC4337/ERC4337TokenPaymaster.ts create mode 100644 src/contracts/ERC4337/ERC4337VerifyPaymaster.ts diff --git a/package.json b/package.json index 8488fb69..4fafef4d 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ethcode", "displayName": "ETHcode", "description": "Ethereum IDE for VS Code", - "version": "0.3.0", + "version": "0.3.1", "publisher": "7finney", "categories": [ "Debuggers", @@ -146,6 +146,16 @@ "command": "ethcode.rental.create", "title": "Create new ERC4907 contract", "category": "Ethcode" + }, + { + "command": "ethcode.verifypaymaster.create", + "title": "Create new ERC4337 VerifyPaymaster contracts", + "category": "Ethcode" + }, + { + "command": "ethcode.tokenpaymaster.create", + "title": "Create new ERC4337 TokenPaymaster contracts", + "category": "Ethcode" } ], "keybindings": [ diff --git a/src/contracts/ERC4337/ERC4337TokenPaymaster.ts b/src/contracts/ERC4337/ERC4337TokenPaymaster.ts new file mode 100644 index 00000000..4c721d89 --- /dev/null +++ b/src/contracts/ERC4337/ERC4337TokenPaymaster.ts @@ -0,0 +1,38 @@ +// paymaster for ERC4337 +import { ERC4337TokenPaymaterType } from "../../types"; + +export const ERC4337TokenPaymaster: ERC4337TokenPaymaterType = { + SimpleAccount: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/samples/SimpleAccount.sol", + BaseAccount: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/core/BaseAccount.sol", + BasePaymaster: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/core/BasePaymaster.sol", + TokenPaymaster: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/samples/TokenPaymaster.sol", + IAccount: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IAccount.sol", + IEntryPoint: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IEntryPoint.sol", + IPaymaster: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IPaymaster.sol", + UserOption: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/UserOperation.sol", + IStakeManager: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IStakeManager.sol", + IAggregator: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IAggregator.sol", +}; + +export const TokenPaymasterMessages = { + SimpleAccount: "SimpleAccount contract is created successfully.", + BaseAccount: "BaseAccount contract is created successfully.", + BasePaymaster: "BasePaymaster contract is created successfully.", + TokenPaymaster: "TokenPaymaster contract is created successfully.", + IAccount: "IAccount interface is created successfully.", + IEntryPoint: "IEntryPoint interface is created successfully.", + IPaymaster: "IPaymaster interface is created successfully.", + UserOperation: "UserOption contract is created successfully.", + IStakeManager: "IStakeManager interface is created successfully.", + IAggregator: "IPaymaster interface is created successfully.", +}; diff --git a/src/contracts/ERC4337/ERC4337VerifyPaymaster.ts b/src/contracts/ERC4337/ERC4337VerifyPaymaster.ts new file mode 100644 index 00000000..fb16d175 --- /dev/null +++ b/src/contracts/ERC4337/ERC4337VerifyPaymaster.ts @@ -0,0 +1,29 @@ +// paymaster for ERC4337 +import { ERC4337VerifyPaymaterType } from "../../types"; + +export const ERC4337VerifyPaymaster: ERC4337VerifyPaymaterType = { + UserOption: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/UserOperation.sol", + IStakeManager: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IStakeManager.sol", + IPaymaster: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IPaymaster.sol", + IEntrypoint: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IEntryPoint.sol", + IAggregator: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IAggregator.sol", + VerifyingPaymaster: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/samples/VerifyingPaymaster.sol", + BasePaymaster: + "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/core/BasePaymaster.sol", +}; + +export const VerifyPaymasterMessages = { + UserOperation: "UserOption contract is created successfully.", + IStakeManager: "IStakeManager interface is created successfully.", + IPaymaster: "IPaymaster interface is created successfully.", + IEntryPoint: "IPaymaster interface is created successfully.", + IAggregator: "IPaymaster interface is created successfully.", + VerifyingPaymaster: "VerifyingPaymaster contract is created successfully.", + BasePaymaster: "BasePaymaster contract is created successfully.", +}; diff --git a/src/extension.ts b/src/extension.ts index 22fc3796..f9946fd0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -18,6 +18,8 @@ import { exportKeyPair, } from "./utils/wallet"; import { + createERC4337TokenPaymaster, + createERC4337VerifyPaymaster, createERC4907Contract, parseBatchCompiledJSON, parseCompiledJSONPayload, @@ -57,9 +59,21 @@ export async function activate(context: vscode.ExtensionContext) { updateSelectedNetwork(context); }), + // create ERC4907 contract commands.registerCommand("ethcode.rental.create", () => { createERC4907Contract(context); }), + + //create ERC4337 VerifyPaymaster contracts + commands.registerCommand("ethcode.verifypaymaster.create", () => { + createERC4337VerifyPaymaster(context); + }), + + //create ERC4337 TokenPaymaster contracts + commands.registerCommand("ethcode.tokenpaymaster.create", () => { + createERC4337TokenPaymaster(context); + }), + // Select Ethereum Account commands.registerCommand("ethcode.account.select", () => { selectAccount(context); diff --git a/src/lib/file.ts b/src/lib/file.ts index 7142b793..46fb788d 100644 --- a/src/lib/file.ts +++ b/src/lib/file.ts @@ -3,7 +3,11 @@ import * as path from "path"; import { JsonFragment } from "@ethersproject/abi"; import { logger } from "./index"; import { CompiledJSONOutput } from "../types/output"; -import { fetchERC4907Contracts } from "../utils/functions"; +import { + fetchERC4907Contracts, + fetchTokenPaymasterContracts, + fetchVerifyPaymasterContracts, +} from "../utils/functions"; const flatten = (lists: any) => { return lists.reduce((a: any, b: any) => a.concat(b), []); @@ -70,6 +74,7 @@ const createDeployedFile = ( logger.success(`Created deployed json format of ${contract.name} contract`); }; +// Create file functions for ERC4907 contract const createUserERC4907ContractFile = async ( fileName: string, uri: string, @@ -94,6 +99,29 @@ const createERC4907ContractFile = async (fileName: string, uri: string) => { fs.writeFileSync(fileName, filedata); logger.success(`ERC4907 contract file is created successfully.`); }; + +//create file function for ERC4337 VerifyPaymaster contract +const createVerifyPaymasterFile = async ( + fileName: string, + uri: string, + message: string +) => { + const filedata = await fetchVerifyPaymasterContracts(uri); + fs.writeFileSync(fileName, filedata); + logger.log(message); +}; + +//create file function for ERC4337 TokenPaymaster contract +const createTokenPaymasterFile = async ( + fileName: string, + uri: string, + message: string +) => { + const filedata = await fetchTokenPaymasterContracts(uri); + fs.writeFileSync(fileName, filedata); + logger.log(message); +}; + export { writeConstructor, writeFunction, @@ -102,4 +130,6 @@ export { createUserERC4907ContractFile, createERC4907ContractInterface, createERC4907ContractFile, + createVerifyPaymasterFile, + createTokenPaymasterFile, }; diff --git a/src/types/types.ts b/src/types/types.ts index 573a88a8..32f2935b 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -117,6 +117,29 @@ export interface ERC4907ContractType { contract: string; ERC4907Contract: string; } + +export interface ERC4337TokenPaymaterType { + SimpleAccount: string; + BaseAccount: string; + BasePaymaster: string; + TokenPaymaster: string; + IAccount: string; + IEntryPoint: string; + IPaymaster: string; + UserOption: string; + IStakeManager: string; + IAggregator: string; +} + +export interface ERC4337VerifyPaymaterType { + UserOption: string; + IStakeManager: string; + IPaymaster: string; + IEntrypoint: string; + IAggregator: string; + VerifyingPaymaster: string; + BasePaymaster: string; +} // Typeguard export function isConstructorInputValue( diff --git a/src/utils/contracts.ts b/src/utils/contracts.ts index b9fb3eec..a320333a 100644 --- a/src/utils/contracts.ts +++ b/src/utils/contracts.ts @@ -7,7 +7,9 @@ import { CompiledJSONOutput, IFunctionQP, isHardhatProject } from "../types"; import { createERC4907ContractFile, createERC4907ContractInterface, + createTokenPaymasterFile, createUserERC4907ContractFile, + createVerifyPaymasterFile, getDirectoriesRecursive, } from "../lib/file"; import { @@ -16,6 +18,14 @@ import { createDeployed, } from "./functions"; import { ERC4907ContractUrls } from "../contracts/ERC4907/ERC4907"; +import { + ERC4337TokenPaymaster, + TokenPaymasterMessages, +} from "../contracts/ERC4337/ERC4337TokenPaymaster"; +import { + ERC4337VerifyPaymaster, + VerifyPaymasterMessages, +} from "../contracts/ERC4337/ERC4337VerifyPaymaster"; import axios from "axios"; const parseBatchCompiledJSON = (context: ExtensionContext): void => { @@ -157,6 +167,8 @@ const selectContract = (context: ExtensionContext) => { quickPick.show(); }; +//ERC4907 contract creation + const createERC4907Contract = async (context: ExtensionContext) => { const path_ = workspace.workspaceFolders !== undefined && @@ -188,9 +200,227 @@ const createERC4907Contract = async (context: ExtensionContext) => { ); }; +const createERC4337VerifyPaymaster = async (context: ExtensionContext) => { + const path_ = + workspace.workspaceFolders !== undefined && + workspace.workspaceFolders[0].uri.fsPath; + const dir_interface = path.join( + path_.toString(), + "contracts", + "VerifyPaymaster/interfaces" + ); + const dir_core = path.join( + path_.toString(), + "contracts", + "VerifyPaymaster/core" + ); + const dir_paymaster = path.join( + path_.toString(), + "contracts", + "VerifyPaymaster/paymaster" + ); + if (!fs.existsSync(dir_interface)) { + fs.mkdirSync(dir_interface, { recursive: true }); + } + if (!fs.existsSync(dir_paymaster)) { + fs.mkdirSync(dir_paymaster, { recursive: true }); + } + if (!fs.existsSync(dir_core)) { + fs.mkdirSync(dir_core, { recursive: true }); + } + //interfaces folder path + const userOptionPath = path.join(dir_interface, "UserOperation.sol"); + const IStakeManagerPath = path.join(dir_interface, "IStakeManager.sol"); + const IPaymasterPath = path.join(dir_interface, "IPaymaster.sol"); + const IEntrypointPath = path.join(dir_interface, "IEntryPoint.sol"); + const IAggregatorPath = path.join(dir_interface, "IAggregator.sol"); + + // paymaster folder path + const VerifyingPaymasterPath = path.join( + dir_paymaster, + "VerifyingPaymaster.sol" + ); + // core folder path + const BasePaymaster = path.join(dir_core, "BasePaymaster.sol"); + //file creation , async process + + //creating useroption contract + await createVerifyPaymasterFile( + userOptionPath, + ERC4337VerifyPaymaster.UserOption, + VerifyPaymasterMessages.UserOperation + ); + + // creating IStakeManager interface + await createVerifyPaymasterFile( + IStakeManagerPath, + ERC4337VerifyPaymaster.IStakeManager, + VerifyPaymasterMessages.IStakeManager + ); + + // creating IPaymasterPath interface + await createVerifyPaymasterFile( + IPaymasterPath, + ERC4337VerifyPaymaster.IPaymaster, + VerifyPaymasterMessages.IPaymaster + ); + + // creating IEntrypointPath interface + await createVerifyPaymasterFile( + IEntrypointPath, + ERC4337VerifyPaymaster.IEntrypoint, + VerifyPaymasterMessages.IEntryPoint + ); + + // creating IAggregatorPath interface + await createVerifyPaymasterFile( + IAggregatorPath, + ERC4337VerifyPaymaster.IAggregator, + VerifyPaymasterMessages.IAggregator + ); + + // creating VerifyingPaymaster contract + await createVerifyPaymasterFile( + VerifyingPaymasterPath, + ERC4337VerifyPaymaster.VerifyingPaymaster, + VerifyPaymasterMessages.VerifyingPaymaster + ); + + // creating BasePaymaster contract + await createVerifyPaymasterFile( + BasePaymaster, + ERC4337VerifyPaymaster.BasePaymaster, + VerifyPaymasterMessages.BasePaymaster + ); +}; + +const createERC4337TokenPaymaster = async (context: ExtensionContext) => { + const path_ = + workspace.workspaceFolders !== undefined && + workspace.workspaceFolders[0].uri.fsPath; + const dir_interface = path.join( + path_.toString(), + "contracts", + "TokenPaymaster/interfaces" + ); + const dir_core = path.join( + path_.toString(), + "contracts", + "TokenPaymaster/core" + ); + const dir_paymaster = path.join( + path_.toString(), + "contracts", + "TokenPaymaster/paymaster" + ); + if (!fs.existsSync(dir_paymaster)) { + fs.mkdirSync(dir_paymaster, { recursive: true }); + } + if (!fs.existsSync(dir_core)) { + fs.mkdirSync(dir_core, { recursive: true }); + } + if (!fs.existsSync(dir_interface)) { + fs.mkdirSync(dir_interface, { recursive: true }); + } + + // paymaster folder path + const SimpleAccountPath = path.join(dir_paymaster, "SimpleAccount.sol"); + const TokenPaymasterPath = path.join(dir_paymaster, "TokenPaymaster.sol"); + // core folder path + const BasePaymasterPath = path.join(dir_core, "BasePaymaster.sol"); + const BaseAccountPath = path.join(dir_core, "BaseAccount.sol"); + // interfaces folder path + const IAccountPath = path.join(dir_interface, "IAccount.sol"); + const IEntryPointPath = path.join(dir_interface, "IEntryPoint.sol"); + const IPaymasterPath = path.join(dir_interface, "IPaymaster.sol"); + const userOptionPath = path.join(dir_interface, "UserOperation.sol"); + const IStakeManagerPath = path.join(dir_interface, "IStakeManager.sol"); + const IAggregatorPath = path.join(dir_interface, "IAggregator.sol"); + //file creation , async process + + // creating SimpleAccount contract + await createTokenPaymasterFile( + SimpleAccountPath, + ERC4337TokenPaymaster.SimpleAccount, + TokenPaymasterMessages.SimpleAccount + ); + + // creating TokenPaymaster contract + await createTokenPaymasterFile( + TokenPaymasterPath, + ERC4337TokenPaymaster.TokenPaymaster, + TokenPaymasterMessages.TokenPaymaster + ); + + // creating BaseAccount contract + await createTokenPaymasterFile( + BaseAccountPath, + ERC4337TokenPaymaster.BaseAccount, + TokenPaymasterMessages.BaseAccount + ); + + // creating BasePaymaster contract + await createTokenPaymasterFile( + BasePaymasterPath, + ERC4337TokenPaymaster.BasePaymaster, + TokenPaymasterMessages.BasePaymaster + ); + + // creating IAccount interface + await createTokenPaymasterFile( + IAccountPath, + ERC4337TokenPaymaster.IAccount, + TokenPaymasterMessages.IAccount + ); + + // creating IEntryPoint interface + await createTokenPaymasterFile( + IEntryPointPath, + ERC4337TokenPaymaster.IEntryPoint, + TokenPaymasterMessages.IEntryPoint + ); + + // creating IPaymaster interface + await createTokenPaymasterFile( + IPaymasterPath, + ERC4337TokenPaymaster.IPaymaster, + TokenPaymasterMessages.IPaymaster + ); + + // creating IPaymaster interface + await createTokenPaymasterFile( + IPaymasterPath, + ERC4337TokenPaymaster.IPaymaster, + TokenPaymasterMessages.IPaymaster + ); + + //creating useroption contract + await createTokenPaymasterFile( + userOptionPath, + ERC4337VerifyPaymaster.UserOption, + VerifyPaymasterMessages.UserOperation + ); + + // creating IStakeManager interface + await createTokenPaymasterFile( + IStakeManagerPath, + ERC4337VerifyPaymaster.IStakeManager, + VerifyPaymasterMessages.IStakeManager + ); + + // creating IAggregator interface + await createTokenPaymasterFile( + IAggregatorPath, + ERC4337VerifyPaymaster.IAggregator, + VerifyPaymasterMessages.IAggregator + ); +}; + export { parseBatchCompiledJSON, parseCompiledJSONPayload, selectContract, createERC4907Contract, + createERC4337VerifyPaymaster, + createERC4337TokenPaymaster, }; diff --git a/src/utils/functions.ts b/src/utils/functions.ts index 4a6d8f4d..85f4e793 100644 --- a/src/utils/functions.ts +++ b/src/utils/functions.ts @@ -288,19 +288,49 @@ const getGasEstimates = async ( return estimate; }; +// fetch contracts of ERC4907 const fetchERC4907Contracts = async (uri: string) => { const response = await axios .get(uri) .then((res) => { - console.log(res); return res.data; }) .catch((err) => { - console.log("an error occoured while fetch files:", err); + logger.log("An error occoured while creating ERC4907 contract:"); }); return response; }; +//fetch contracts for ERC4337 verifyPaymaster +const fetchVerifyPaymasterContracts = async (uri: string) => { + const response = await axios + .get(uri) + .then((res) => { + return res.data; + }) + .catch((err) => { + logger.log( + "An error occoured while creating VerifyPaymaster contract:", + err + ); + }); + return response; +}; + +const fetchTokenPaymasterContracts = async (uri: string) => { + const response = await axios + .get(uri) + .then((res) => { + return res.data; + }) + .catch((err) => { + logger.log( + "An error occoured while creating TokenPaymaster contract:", + err + ); + }); + return response; +}; export { createFunctionInput, createDeployed, @@ -310,4 +340,6 @@ export { getDeployedInputs, getGasEstimates, fetchERC4907Contracts, + fetchVerifyPaymasterContracts, + fetchTokenPaymasterContracts, }; diff --git a/src/utils/networks.ts b/src/utils/networks.ts index 90d9d5a9..850a29ab 100644 --- a/src/utils/networks.ts +++ b/src/utils/networks.ts @@ -16,7 +16,6 @@ import { getFunctionInputs, getGasEstimates, } from "./functions"; - import { errors } from "../config/errors"; import { selectContract } from "./contracts"; From 77e645fb72aa1a7632b0b67f3f0036f258ce944c Mon Sep 17 00:00:00 2001 From: Aniket Singh Date: Sat, 3 Dec 2022 23:05:32 +0530 Subject: [PATCH 2/3] conflict fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4fafef4d..bf71d9ac 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "ethcode", "displayName": "ETHcode", "description": "Ethereum IDE for VS Code", - "version": "0.3.1", + "version": "0.4.2", "publisher": "7finney", "categories": [ "Debuggers", From 4d0169c83756f42ef9800d02e6c83d5abb91efa6 Mon Sep 17 00:00:00 2001 From: Aniket Singh Date: Sun, 4 Dec 2022 07:22:31 +0530 Subject: [PATCH 3/3] code redefined --- .../ERC4337/ERC4337TokenPaymaster.ts | 29 +-- .../ERC4337/ERC4337VerifyPaymaster.ts | 20 +- src/types/types.ts | 15 -- src/utils/contracts.ts | 210 ++---------------- src/utils/networks.ts | 7 +- 5 files changed, 21 insertions(+), 260 deletions(-) diff --git a/src/contracts/ERC4337/ERC4337TokenPaymaster.ts b/src/contracts/ERC4337/ERC4337TokenPaymaster.ts index 4c721d89..169f0692 100644 --- a/src/contracts/ERC4337/ERC4337TokenPaymaster.ts +++ b/src/contracts/ERC4337/ERC4337TokenPaymaster.ts @@ -2,37 +2,10 @@ import { ERC4337TokenPaymaterType } from "../../types"; export const ERC4337TokenPaymaster: ERC4337TokenPaymaterType = { - SimpleAccount: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/samples/SimpleAccount.sol", - BaseAccount: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/core/BaseAccount.sol", - BasePaymaster: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/core/BasePaymaster.sol", TokenPaymaster: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/samples/TokenPaymaster.sol", - IAccount: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IAccount.sol", - IEntryPoint: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IEntryPoint.sol", - IPaymaster: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IPaymaster.sol", - UserOption: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/UserOperation.sol", - IStakeManager: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IStakeManager.sol", - IAggregator: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IAggregator.sol", + "https://raw.githubusercontent.com/Aniket6990/Smart-contracts/main/TokenPaymaster.sol", }; export const TokenPaymasterMessages = { - SimpleAccount: "SimpleAccount contract is created successfully.", - BaseAccount: "BaseAccount contract is created successfully.", - BasePaymaster: "BasePaymaster contract is created successfully.", TokenPaymaster: "TokenPaymaster contract is created successfully.", - IAccount: "IAccount interface is created successfully.", - IEntryPoint: "IEntryPoint interface is created successfully.", - IPaymaster: "IPaymaster interface is created successfully.", - UserOperation: "UserOption contract is created successfully.", - IStakeManager: "IStakeManager interface is created successfully.", - IAggregator: "IPaymaster interface is created successfully.", }; diff --git a/src/contracts/ERC4337/ERC4337VerifyPaymaster.ts b/src/contracts/ERC4337/ERC4337VerifyPaymaster.ts index fb16d175..cedc26a0 100644 --- a/src/contracts/ERC4337/ERC4337VerifyPaymaster.ts +++ b/src/contracts/ERC4337/ERC4337VerifyPaymaster.ts @@ -2,28 +2,10 @@ import { ERC4337VerifyPaymaterType } from "../../types"; export const ERC4337VerifyPaymaster: ERC4337VerifyPaymaterType = { - UserOption: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/UserOperation.sol", - IStakeManager: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IStakeManager.sol", - IPaymaster: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IPaymaster.sol", - IEntrypoint: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IEntryPoint.sol", - IAggregator: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/interfaces/IAggregator.sol", VerifyingPaymaster: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/samples/VerifyingPaymaster.sol", - BasePaymaster: - "https://raw.githubusercontent.com/eth-infinitism/account-abstraction/develop/contracts/core/BasePaymaster.sol", + "https://raw.githubusercontent.com/Aniket6990/Smart-contracts/main/VerifyingPaymaster.sol", }; export const VerifyPaymasterMessages = { - UserOperation: "UserOption contract is created successfully.", - IStakeManager: "IStakeManager interface is created successfully.", - IPaymaster: "IPaymaster interface is created successfully.", - IEntryPoint: "IPaymaster interface is created successfully.", - IAggregator: "IPaymaster interface is created successfully.", VerifyingPaymaster: "VerifyingPaymaster contract is created successfully.", - BasePaymaster: "BasePaymaster contract is created successfully.", }; diff --git a/src/types/types.ts b/src/types/types.ts index 32f2935b..c4722938 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -119,26 +119,11 @@ export interface ERC4907ContractType { } export interface ERC4337TokenPaymaterType { - SimpleAccount: string; - BaseAccount: string; - BasePaymaster: string; TokenPaymaster: string; - IAccount: string; - IEntryPoint: string; - IPaymaster: string; - UserOption: string; - IStakeManager: string; - IAggregator: string; } export interface ERC4337VerifyPaymaterType { - UserOption: string; - IStakeManager: string; - IPaymaster: string; - IEntrypoint: string; - IAggregator: string; VerifyingPaymaster: string; - BasePaymaster: string; } // Typeguard diff --git a/src/utils/contracts.ts b/src/utils/contracts.ts index a320333a..3c1807a1 100644 --- a/src/utils/contracts.ts +++ b/src/utils/contracts.ts @@ -204,216 +204,42 @@ const createERC4337VerifyPaymaster = async (context: ExtensionContext) => { const path_ = workspace.workspaceFolders !== undefined && workspace.workspaceFolders[0].uri.fsPath; - const dir_interface = path.join( - path_.toString(), - "contracts", - "VerifyPaymaster/interfaces" - ); - const dir_core = path.join( - path_.toString(), - "contracts", - "VerifyPaymaster/core" - ); - const dir_paymaster = path.join( - path_.toString(), - "contracts", - "VerifyPaymaster/paymaster" - ); - if (!fs.existsSync(dir_interface)) { - fs.mkdirSync(dir_interface, { recursive: true }); - } - if (!fs.existsSync(dir_paymaster)) { - fs.mkdirSync(dir_paymaster, { recursive: true }); - } - if (!fs.existsSync(dir_core)) { - fs.mkdirSync(dir_core, { recursive: true }); - } - //interfaces folder path - const userOptionPath = path.join(dir_interface, "UserOperation.sol"); - const IStakeManagerPath = path.join(dir_interface, "IStakeManager.sol"); - const IPaymasterPath = path.join(dir_interface, "IPaymaster.sol"); - const IEntrypointPath = path.join(dir_interface, "IEntryPoint.sol"); - const IAggregatorPath = path.join(dir_interface, "IAggregator.sol"); - - // paymaster folder path - const VerifyingPaymasterPath = path.join( - dir_paymaster, - "VerifyingPaymaster.sol" - ); - // core folder path - const BasePaymaster = path.join(dir_core, "BasePaymaster.sol"); - //file creation , async process - - //creating useroption contract - await createVerifyPaymasterFile( - userOptionPath, - ERC4337VerifyPaymaster.UserOption, - VerifyPaymasterMessages.UserOperation - ); - - // creating IStakeManager interface - await createVerifyPaymasterFile( - IStakeManagerPath, - ERC4337VerifyPaymaster.IStakeManager, - VerifyPaymasterMessages.IStakeManager - ); - - // creating IPaymasterPath interface - await createVerifyPaymasterFile( - IPaymasterPath, - ERC4337VerifyPaymaster.IPaymaster, - VerifyPaymasterMessages.IPaymaster - ); - - // creating IEntrypointPath interface - await createVerifyPaymasterFile( - IEntrypointPath, - ERC4337VerifyPaymaster.IEntrypoint, - VerifyPaymasterMessages.IEntryPoint - ); - - // creating IAggregatorPath interface - await createVerifyPaymasterFile( - IAggregatorPath, - ERC4337VerifyPaymaster.IAggregator, - VerifyPaymasterMessages.IAggregator - ); + const dir = path.join(path_.toString(), "contracts", "VerifyPaymaster"); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); - // creating VerifyingPaymaster contract - await createVerifyPaymasterFile( - VerifyingPaymasterPath, - ERC4337VerifyPaymaster.VerifyingPaymaster, - VerifyPaymasterMessages.VerifyingPaymaster - ); + // paymaster folder path + const VerifyingPaymasterPath = path.join(dir, "VerifyingPaymaster.sol"); + //file creation , async process - // creating BasePaymaster contract - await createVerifyPaymasterFile( - BasePaymaster, - ERC4337VerifyPaymaster.BasePaymaster, - VerifyPaymasterMessages.BasePaymaster - ); + // creating VerifyingPaymaster contract + await createVerifyPaymasterFile( + VerifyingPaymasterPath, + ERC4337VerifyPaymaster.VerifyingPaymaster, + VerifyPaymasterMessages.VerifyingPaymaster + ); + } }; const createERC4337TokenPaymaster = async (context: ExtensionContext) => { const path_ = workspace.workspaceFolders !== undefined && workspace.workspaceFolders[0].uri.fsPath; - const dir_interface = path.join( - path_.toString(), - "contracts", - "TokenPaymaster/interfaces" - ); - const dir_core = path.join( - path_.toString(), - "contracts", - "TokenPaymaster/core" - ); - const dir_paymaster = path.join( - path_.toString(), - "contracts", - "TokenPaymaster/paymaster" - ); - if (!fs.existsSync(dir_paymaster)) { - fs.mkdirSync(dir_paymaster, { recursive: true }); - } - if (!fs.existsSync(dir_core)) { - fs.mkdirSync(dir_core, { recursive: true }); - } - if (!fs.existsSync(dir_interface)) { - fs.mkdirSync(dir_interface, { recursive: true }); + const dir = path.join(path_.toString(), "contracts", "TokenPaymaster"); + + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); } - // paymaster folder path - const SimpleAccountPath = path.join(dir_paymaster, "SimpleAccount.sol"); - const TokenPaymasterPath = path.join(dir_paymaster, "TokenPaymaster.sol"); - // core folder path - const BasePaymasterPath = path.join(dir_core, "BasePaymaster.sol"); - const BaseAccountPath = path.join(dir_core, "BaseAccount.sol"); - // interfaces folder path - const IAccountPath = path.join(dir_interface, "IAccount.sol"); - const IEntryPointPath = path.join(dir_interface, "IEntryPoint.sol"); - const IPaymasterPath = path.join(dir_interface, "IPaymaster.sol"); - const userOptionPath = path.join(dir_interface, "UserOperation.sol"); - const IStakeManagerPath = path.join(dir_interface, "IStakeManager.sol"); - const IAggregatorPath = path.join(dir_interface, "IAggregator.sol"); + const TokenPaymasterPath = path.join(dir, "TokenPaymaster.sol"); //file creation , async process - // creating SimpleAccount contract - await createTokenPaymasterFile( - SimpleAccountPath, - ERC4337TokenPaymaster.SimpleAccount, - TokenPaymasterMessages.SimpleAccount - ); - // creating TokenPaymaster contract await createTokenPaymasterFile( TokenPaymasterPath, ERC4337TokenPaymaster.TokenPaymaster, TokenPaymasterMessages.TokenPaymaster ); - - // creating BaseAccount contract - await createTokenPaymasterFile( - BaseAccountPath, - ERC4337TokenPaymaster.BaseAccount, - TokenPaymasterMessages.BaseAccount - ); - - // creating BasePaymaster contract - await createTokenPaymasterFile( - BasePaymasterPath, - ERC4337TokenPaymaster.BasePaymaster, - TokenPaymasterMessages.BasePaymaster - ); - - // creating IAccount interface - await createTokenPaymasterFile( - IAccountPath, - ERC4337TokenPaymaster.IAccount, - TokenPaymasterMessages.IAccount - ); - - // creating IEntryPoint interface - await createTokenPaymasterFile( - IEntryPointPath, - ERC4337TokenPaymaster.IEntryPoint, - TokenPaymasterMessages.IEntryPoint - ); - - // creating IPaymaster interface - await createTokenPaymasterFile( - IPaymasterPath, - ERC4337TokenPaymaster.IPaymaster, - TokenPaymasterMessages.IPaymaster - ); - - // creating IPaymaster interface - await createTokenPaymasterFile( - IPaymasterPath, - ERC4337TokenPaymaster.IPaymaster, - TokenPaymasterMessages.IPaymaster - ); - - //creating useroption contract - await createTokenPaymasterFile( - userOptionPath, - ERC4337VerifyPaymaster.UserOption, - VerifyPaymasterMessages.UserOperation - ); - - // creating IStakeManager interface - await createTokenPaymasterFile( - IStakeManagerPath, - ERC4337VerifyPaymaster.IStakeManager, - VerifyPaymasterMessages.IStakeManager - ); - - // creating IAggregator interface - await createTokenPaymasterFile( - IAggregatorPath, - ERC4337VerifyPaymaster.IAggregator, - VerifyPaymasterMessages.IAggregator - ); }; export { diff --git a/src/utils/networks.ts b/src/utils/networks.ts index 850a29ab..865203c6 100644 --- a/src/utils/networks.ts +++ b/src/utils/networks.ts @@ -201,12 +201,7 @@ const callContractMethod = async (context: vscode.ExtensionContext) => { result = await contract[abiItem.name as string](...params); } } else { - const found: any = abiItem.inputs?.find( - (e: any) => e.type === "uint256" - ); - result = await contract[abiItem.name as string](...params, { - value: found.value, - }); + result = await contract[abiItem.name as string](...params); } logger.success("Waiting for confirmation...");