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/support sponsorship policy ids #31

Merged
merged 2 commits into from
Oct 13, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "create a new account and send a useroperation.",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc",
"clean": "rm -rf dist",
"build": "rimraf dist && tsc",
"clean": "rimraf dist",
"format": "prettier --write src/**/*.ts",
"lint": "eslint src/**/*.ts"
},
Expand All @@ -14,5 +14,8 @@
"dotenv": "^16.3.1",
"typescript": "^5.1.6",
"abstractionkit": "^0.2.0"
},
"devDependencies": {
"rimraf": "^6.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "create a new account and send a useroperation.",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc",
"clean": "rm -rf dist",
"build": "rimraf dist && tsc",
"clean": "rimraf dist",
"format": "prettier --write src/**/*.ts",
"lint": "eslint src/**/*.ts"
},
Expand All @@ -14,5 +14,8 @@
"dotenv": "^16.3.1",
"typescript": "^5.1.6",
"abstractionkit": "^0.2.0"
},
"devDependencies": {
"rimraf": "^6.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ PUBLIC_ADDRESS=
PRIVATE_KEY=

#get early access to Candide's Paymaster sponsor policies on our Discord
PAYMASTER_RPC=
PAYMASTER_RPC=

#Sponsorship policy ID (leave blank if you want to get sponsored by public policies if your userop is eligible)
SPONSORSHIP_POLICY_ID=
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "create a new account and send a useroperation and pay gas with erc20 token using a paymaster.",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc",
"clean": "rm -rf dist",
"build": "rimraf dist && tsc",
"clean": "rimraf dist",
"format": "prettier --write src/**/*.ts",
"lint": "eslint src/**/*.ts"
},
Expand All @@ -15,5 +15,8 @@
"ethers": "^6.6.7",
"typescript": "^5.1.6",
"abstractionkit": "^0.2.0"
},
"devDependencies": {
"rimraf": "^6.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ async function main(): Promise<void> {
const ownerPublicAddress = process.env.PUBLIC_ADDRESS as string
const ownerPrivateKey = process.env.PRIVATE_KEY as string
const paymasterRPC = process.env.PAYMASTER_RPC as string;

const sponsorshipPolicyId = process.env.SPONSORSHIP_POLICY_ID as string;

//initializeNewAccount only needed when the smart account
//have not been deployed yet for its first useroperation.
//You can store the accountAddress to use it to initialize
Expand Down Expand Up @@ -73,7 +74,7 @@ async function main(): Promise<void> {
)

let [paymasterUserOperation, _sponsorMetadata] = await paymaster.createSponsorPaymasterUserOperation(
userOperation, bundlerUrl)
userOperation, bundlerUrl, sponsorshipPolicyId) // sponsorshipPolicyId will have no effect if empty
userOperation = paymasterUserOperation;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "create a new account and send a useroperation and pay gas with erc20 token using a paymaster.",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc",
"clean": "rm -rf dist",
"build": "rimraf dist && tsc",
"clean": "rimraf dist",
"format": "prettier --write src/**/*.ts",
"lint": "eslint src/**/*.ts"
},
Expand All @@ -15,5 +15,8 @@
"ethers": "^6.6.7",
"typescript": "^5.1.6",
"abstractionkit": "^0.2.0"
},
"devDependencies": {
"rimraf": "^6.0.1"
}
}
7 changes: 5 additions & 2 deletions examples/SafeAccountExamples/SocialRecovery/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "Add an onchain Guardian using the Social Recovery Module",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc",
"clean": "rm -rf dist",
"build": "rimraf dist && tsc",
"clean": "rimraf dist",
"format": "prettier --write src/**/*.ts",
"lint": "eslint src/**/*.ts"
},
Expand All @@ -15,5 +15,8 @@
"ethers": "^6.6.7",
"typescript": "^5.1.6",
"abstractionkit": "^0.2.0"
},
"devDependencies": {
"rimraf": "^6.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"description": "create a new account and send a useroperation.",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc",
"clean": "rm -rf dist",
"build": "rimraf dist && tsc",
"clean": "rimraf dist",
"format": "prettier --write src/**/*.ts",
"lint": "eslint src/**/*.ts"
},
Expand All @@ -16,5 +16,8 @@
"ethers": "^6.11.0",
"typescript": "^5.1.6",
"abstractionkit": "^0.2.0"
},
"devDependencies": {
"rimraf": "^6.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,6 @@ async function main(): Promise<void> {
let [paymasterUserOperation, _sponsorMetadata] = await paymaster.createSponsorPaymasterUserOperation(
userOperation,
bundlerUrl,
//{
// verificationGasLimitPercentageMultiplier:130
//}
)
userOperation = paymasterUserOperation;

Expand Down
7 changes: 5 additions & 2 deletions examples/UsingBundlerRPC/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
"description": "an example for using the toolkit with the a bundler RPC",
"main": "dist/index.js",
"scripts": {
"build": "rm -rf dist && tsc",
"clean": "rm -rf dist",
"build": "rimraf dist && tsc",
"clean": "rimraf dist",
"format": "prettier --write .",
"lint": "eslint src/**/*.ts"
},
"license": "MIT",
"dependencies": {
"abstractionkit": "^0.1.13",
"typescript": "^5.1.6"
},
"devDependencies": {
"rimraf": "^6.0.1"
}
}
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"unpkg": "dist/index.umd.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "rm -rf dist && microbundle --tsconfig tsconfig.json --no-sourcemap",
"clean": "rm -rf dist",
"build": "rimraf dist && microbundle --tsconfig tsconfig.json --no-sourcemap",
"clean": "rimraf dist",
"format": "prettier --write src/*.ts src/**/*.ts src/**/**/*.ts",
"lint": "eslint -f unix \"src/**/*.{ts,tsx}\"",
"test": "jest"
Expand Down Expand Up @@ -52,7 +52,8 @@
"lint-staged": ">=10",
"microbundle": "^0.15.1",
"prettier": "3.0.0",
"typescript": "^5.1.6"
"typescript": "^5.1.6",
"rimraf": "^6.0.1"
},
"lint-staged": {
"*.js": "eslint --cache --fix",
Expand Down
17 changes: 9 additions & 8 deletions src/paymaster/CandidePaymaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -597,32 +597,33 @@ export class CandidePaymaster extends Paymaster {
async createSponsorPaymasterUserOperation(
userOperation: UserOperationV7,
bundlerRpc: string,
overrides?: CreatePaymasterUserOperationOverrides,
sponsorshipPolicyId?: string,
): Promise<[UserOperationV7, SponsorMetadata | undefined]>;
async createSponsorPaymasterUserOperation(
userOperation: UserOperationV6,
bundlerRpc: string,
overrides?: CreatePaymasterUserOperationOverrides,
sponsorshipPolicyId?: string,
): Promise<[UserOperationV6, SponsorMetadata | undefined]>;
async createSponsorPaymasterUserOperation(
userOperation: UserOperationV7 | UserOperationV6,
bundlerRpc: string,
overrides: CreatePaymasterUserOperationOverrides = {},
sponsorshipPolicyId?: string,
): Promise<[UserOperationV7 | UserOperationV6, SponsorMetadata | undefined]> {
const createPaymasterUserOperationOverrides = overrides;
const context: CandidePaymasterContext = {};
if (sponsorshipPolicyId && sponsorshipPolicyId.trim().length > 0){
context["sponsorshipPolicyId"] = sponsorshipPolicyId;
}
if ("initCode" in userOperation) {
return await this.createPaymasterUserOperation(
userOperation as UserOperationV6,
bundlerRpc,
{},
createPaymasterUserOperationOverrides,
context
);
} else {
return await this.createPaymasterUserOperation(
userOperation as UserOperationV7,
bundlerRpc,
{},
createPaymasterUserOperationOverrides,
context
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/paymaster/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { StateOverrideSet } from "../types";

export interface CandidePaymasterContext {
token?: string;
sponsorshipPolicyId?: string;
}

export interface PrependTokenPaymasterApproveAccount {
Expand Down
Loading