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

account abstraction template #261

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "ethcode",
"displayName": "ETHcode",
"description": "Ethereum IDE for VS Code",
"version": "0.3.0",
"version": "0.4.2",
"publisher": "7finney",
"categories": [
"Debuggers",
Expand Down Expand Up @@ -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": [
Expand Down
11 changes: 11 additions & 0 deletions src/contracts/ERC4337/ERC4337TokenPaymaster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// paymaster for ERC4337
import { ERC4337TokenPaymaterType } from "../../types";

export const ERC4337TokenPaymaster: ERC4337TokenPaymaterType = {
TokenPaymaster:
"https://raw.githubusercontent.com/Aniket6990/Smart-contracts/main/TokenPaymaster.sol",
};

export const TokenPaymasterMessages = {
TokenPaymaster: "TokenPaymaster contract is created successfully.",
};
11 changes: 11 additions & 0 deletions src/contracts/ERC4337/ERC4337VerifyPaymaster.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// paymaster for ERC4337
import { ERC4337VerifyPaymaterType } from "../../types";

export const ERC4337VerifyPaymaster: ERC4337VerifyPaymaterType = {
VerifyingPaymaster:
"https://raw.githubusercontent.com/Aniket6990/Smart-contracts/main/VerifyingPaymaster.sol",
};

export const VerifyPaymasterMessages = {
VerifyingPaymaster: "VerifyingPaymaster contract is created successfully.",
};
14 changes: 14 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
exportKeyPair,
} from "./utils/wallet";
import {
createERC4337TokenPaymaster,
createERC4337VerifyPaymaster,
createERC4907Contract,
parseBatchCompiledJSON,
parseCompiledJSONPayload,
Expand Down Expand Up @@ -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);
Expand Down
32 changes: 31 additions & 1 deletion src/lib/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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), []);
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -102,4 +130,6 @@ export {
createUserERC4907ContractFile,
createERC4907ContractInterface,
createERC4907ContractFile,
createVerifyPaymasterFile,
createTokenPaymasterFile,
};
8 changes: 8 additions & 0 deletions src/types/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ export interface ERC4907ContractType {
contract: string;
ERC4907Contract: string;
}

export interface ERC4337TokenPaymaterType {
TokenPaymaster: string;
}

export interface ERC4337VerifyPaymaterType {
VerifyingPaymaster: string;
}
// Typeguard

export function isConstructorInputValue(
Expand Down
56 changes: 56 additions & 0 deletions src/utils/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { CompiledJSONOutput, IFunctionQP, isHardhatProject } from "../types";
import {
createERC4907ContractFile,
createERC4907ContractInterface,
createTokenPaymasterFile,
createUserERC4907ContractFile,
createVerifyPaymasterFile,
getDirectoriesRecursive,
} from "../lib/file";
import {
Expand All @@ -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 => {
Expand Down Expand Up @@ -157,6 +167,8 @@ const selectContract = (context: ExtensionContext) => {
quickPick.show();
};

//ERC4907 contract creation

const createERC4907Contract = async (context: ExtensionContext) => {
const path_ =
workspace.workspaceFolders !== undefined &&
Expand Down Expand Up @@ -188,9 +200,53 @@ const createERC4907Contract = async (context: ExtensionContext) => {
);
};

const createERC4337VerifyPaymaster = async (context: ExtensionContext) => {
const path_ =
workspace.workspaceFolders !== undefined &&
workspace.workspaceFolders[0].uri.fsPath;
const dir = path.join(path_.toString(), "contracts", "VerifyPaymaster");
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });

// paymaster folder path
const VerifyingPaymasterPath = path.join(dir, "VerifyingPaymaster.sol");
//file creation , async process

// 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 = path.join(path_.toString(), "contracts", "TokenPaymaster");

if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, { recursive: true });
}

const TokenPaymasterPath = path.join(dir, "TokenPaymaster.sol");
//file creation , async process

// creating TokenPaymaster contract
await createTokenPaymasterFile(
TokenPaymasterPath,
ERC4337TokenPaymaster.TokenPaymaster,
TokenPaymasterMessages.TokenPaymaster
);
};

export {
parseBatchCompiledJSON,
parseCompiledJSONPayload,
selectContract,
createERC4907Contract,
createERC4337VerifyPaymaster,
createERC4337TokenPaymaster,
};
36 changes: 34 additions & 2 deletions src/utils/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -310,4 +340,6 @@ export {
getDeployedInputs,
getGasEstimates,
fetchERC4907Contracts,
fetchVerifyPaymasterContracts,
fetchTokenPaymasterContracts,
};
8 changes: 1 addition & 7 deletions src/utils/networks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
getFunctionInputs,
getGasEstimates,
} from "./functions";

import { errors } from "../config/errors";
import { selectContract } from "./contracts";

Expand Down Expand Up @@ -202,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...");
Expand Down