Skip to content

Commit

Permalink
config file to define whitelisted address
Browse files Browse the repository at this point in the history
  • Loading branch information
eerkaijun committed Dec 16, 2023
1 parent 12f7201 commit 126898e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
7 changes: 7 additions & 0 deletions paymaster/src/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// If set to true, all transactions will be sponsored
export const whitelistAll: Boolean = true;

// Whitelisted addresses for paymaster to sponsor transactions
export const whitelistedAddresses: string[] = [
// add addresses here
];
11 changes: 9 additions & 2 deletions paymaster/src/rpcMethods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BigNumberish, ethers } from 'ethers';
import { paymasterAbi } from './abis';
import { BytesLike } from '@ethersproject/bytes';
import { whitelistAll, whitelistedAddresses } from './config';
import dotenv from 'dotenv';
dotenv.config();

Expand Down Expand Up @@ -29,8 +30,14 @@ export async function sponsorTransaction(userOp: UserOperation): Promise<UserOpe
provider
);

/// NOTE: Define additional transaction sponsor logic here if needed
/// For example, it could be a list of whitelisted addresses
// If user address is not whitelisted for gas sponsor, return
if (
!whitelistAll && !whitelistedAddresses.map(
address => address.toLowerCase()
).includes(userOp.sender.toLowerCase())
) {
return userOp;
}

const coder = new ethers.AbiCoder();
const validAfter = (await provider.getBlock('latest'))?.timestamp;
Expand Down

0 comments on commit 126898e

Please sign in to comment.