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: taking bundler and paymaster as user provided parameters #12

Merged
merged 6 commits into from
Jan 2, 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
11 changes: 4 additions & 7 deletions src/gasless-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class GaslessProvider extends ProviderWrapper {
protected readonly _signerPk: `0x${string}`,
protected readonly _wrappedProvider: EIP1193Provider,
public readonly chain: string,
protected readonly _pimlicoApiKey: string,
protected readonly bundlerClient: PimlicoBundlerClient,
protected readonly paymasterClient: PimlicoPaymasterClient,
protected readonly publicClient: ReturnType<typeof createPublicClient>,
Expand All @@ -38,7 +37,6 @@ export class GaslessProvider extends ProviderWrapper {
_signerPk: `0x${string}`,
_wrappedProvider: EIP1193Provider,
chain: string,
_pimlicoApiKey: string,
bundlerClient: PimlicoBundlerClient,
paymasterClient: PimlicoPaymasterClient,
publicClient: ReturnType<typeof createPublicClient>,
Expand Down Expand Up @@ -76,7 +74,6 @@ export class GaslessProvider extends ProviderWrapper {
_signerPk,
_wrappedProvider,
chain,
_pimlicoApiKey,
bundlerClient,
paymasterClient,
publicClient,
Expand Down Expand Up @@ -104,8 +101,8 @@ export class GaslessProvider extends ProviderWrapper {
// Parse the transaction
const parsedTxn = ethers.utils.parseTransaction(tx);

// Get gas prices from pimlico
const gasPrices = await this.bundlerClient.getUserOperationGasPrice();
// Get gas prices
const { maxFeePerGas, maxPriorityFeePerGas } = await this.publicClient.estimateFeesPerGas();

// Generate calldata
// This calldata is hardcoded as it is calldata for pimlico to execute
Expand All @@ -132,8 +129,8 @@ export class GaslessProvider extends ProviderWrapper {
nonce: this._nonce,
initCode: this._nonce === 0n ? this._initCode : '0x',
callData,
maxFeePerGas: gasPrices.fast.maxFeePerGas,
maxPriorityFeePerGas: gasPrices.fast.maxPriorityFeePerGas,
maxFeePerGas: maxFeePerGas as bigint,
maxPriorityFeePerGas: maxPriorityFeePerGas as bigint,
// dummy signature, needs to be there so the SimpleAccount doesn't immediately revert because of invalid signature length
signature: constants.dummySignature as Hex,
};
Expand Down
20 changes: 6 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ extendProvider(async (provider, config, networkName) => {
return provider;
}

const pimlicoApiKey = netConfig.pimlicoApiKey;
if (pimlicoApiKey === undefined) {
log(`No pimlico api key, skipping`);
const sponsoredTransaction = netConfig.sponsoredTransaction;
if (sponsoredTransaction === undefined) {
log(`No configuration for sponsored transactions set, skipping`);
return provider;
}

Expand All @@ -39,20 +39,12 @@ extendProvider(async (provider, config, networkName) => {
});

const bundlerClient = createPimlicoBundlerClient({
transport: http(`https://api.pimlico.io/v1/${networkName}/rpc?apikey=${pimlicoApiKey}`),
transport: http(sponsoredTransaction.bundlerUrl),
});

const paymasterClient = createPimlicoPaymasterClient({
transport: http(`https://api.pimlico.io/v2/${networkName}/rpc?apikey=${pimlicoApiKey}`),
transport: http(sponsoredTransaction.paymasterUrl),
});

return await GaslessProvider.create(
signer,
provider,
networkName,
pimlicoApiKey,
bundlerClient,
paymasterClient,
publicClient,
);
return await GaslessProvider.create(signer, provider, networkName, bundlerClient, paymasterClient, publicClient);
});
10 changes: 8 additions & 2 deletions src/type-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ import 'hardhat/types/runtime';

declare module 'hardhat/types/config' {
export interface HttpNetworkUserConfig {
pimlicoApiKey?: string;
sponsoredTransaction?: {
bundlerUrl: string;
paymasterUrl: string;
};
}

export interface HttpNetworkConfig {
pimlicoApiKey?: string;
sponsoredTransaction?: {
bundlerUrl: string;
paymasterUrl: string;
};
}
}
5 changes: 4 additions & 1 deletion test/fixture-projects/hardhat-project/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ const config: HardhatUserConfig = {
defaultNetwork: 'hardhat',
networks: {
localhost: {
pimlicoApiKey: 'foo',
sponsoredTransaction: {
bundlerUrl: 'http://localhost:3000',
paymasterUrl: 'http://localhost:3001',
},
},
},
};
Expand Down
8 changes: 6 additions & 2 deletions test/project.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@ describe('Integration tests examples', function () {
describe('HardhatConfig extension', function () {
useEnvironment('hardhat-project');

it('Should add the pimlicoApiKey to the config', function () {
assert.equal(this.hre.config.networks.localhost.pimlicoApiKey, 'foo');
it('Should add the bundlerUrl to the config', function () {
assert.equal(this.hre.config.networks.localhost.sponsoredTransaction?.bundlerUrl, 'http://localhost:3000');
});

it('Should add the paymasterUrl to the config', function () {
assert.equal(this.hre.config.networks.localhost.sponsoredTransaction?.paymasterUrl, 'http://localhost:3001');
});
});
});