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

Add Main Paymaster Example Components #495

Closed
wants to merge 2 commits into from

Conversation

cpcramer
Copy link
Contributor

@cpcramer cpcramer commented May 20, 2024

What changed? Why?

  • Add paymaster proxy route.
  • Add paymaster documentation guide.
  • Add frontend styling.
  • Add willSponsor helper function for client side verification.
  • General refactoring and cleanup.
Screenshot 2024-05-21 at 9 12 37 AM

Notes to reviewers

How has it been tested?

@cpcramer cpcramer force-pushed the paul/add-paymaster-main-components branch 2 times, most recently from 85dfebd to 4050d09 Compare May 20, 2024 23:34
Comment on lines +13 to +14
'<rootDir>/app/api/paymasterProxy',
'<rootDir>/app/paymaster-bundler/utils/',
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are so specific because some unrelated tests are failing which will need to be fixed. Once the tests are fixed I can update this to be <rootDir>/app/

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting..... if that's the case also open a public issue on Github so we don't forget to fix it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking here #496

import { baseSepolia } from 'viem/chains';

const paymasterService = process.env.NEXT_PUBLIC_PAYMASTER_URL ?? '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this in the config?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was originally in the constants.ts file. I figured that it wasn't necessary to assign a const to the env variable when I can just access the env whenever I needed it.

It looked like:
const PAYMASTER_SERVICE_URL = process.env.NEXT_PUBLIC_PAYMASTER_URL

chainId,
entrypoint,
userOp,
}: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Types are easier to read when are more explicit as their own variable.

like

type dude = { ... }

and than you use dude

Copy link
Contributor Author

@cpcramer cpcramer May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to look like:

type ChainId = number;
type Entrypoint = string;
type UserOp = UserOperation<'v0.6'>;

type WillSponsorParams = {
}: {
  chainId: ChainId;
  entrypoint: Entrypoint;
  userOp: UserOp;
};

export const willSponsor = async ({
  chainId,
  entrypoint,
  userOp,
}: WillSponsorParams)

if (calldata.functionName !== 'executeBatch') return false;
if (!calldata.args || calldata.args.length == 0) return false;

const calls = calldata.args[0] as {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Each type should have his own variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to:

type CallDataTargetAddress = Address;
type CallDataValue = bigint;
type CallData = Hex;

  const calls = calldata.args[0] as {
    target: CallDataTargetAddress;
    value: CallDataValue;
    data: CallData;
  }

* Checks if the call data in the user operation is valid and meets sponsorship criteria.
*
*/
function isValidCallData(userOp: UserOperation<'v0.6'>): boolean {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UserOperation<'v0.6'> what's this?

Copy link
Contributor Author

@cpcramer cpcramer May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this looks weird but it's a type that UserOperation extends called EntryPointVersion...there is a type error if this is omitted.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the documentation - export type EntryPointVersion = "v0.6" | "v0.7"


/**
* Checks if the call data in the user operation is valid and meets sponsorship criteria.
*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why an empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow, should I add more to the function comment?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait - Updated to remove the empty * line

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      • > @@@@

Copy link

@esmaili76000 esmaili76000 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~~~~~~~~~~~~~~~~

@cpcramer cpcramer changed the title 🚧 Add Main Paymaster Example Components Add Main Paymaster Example Components May 21, 2024
@cpcramer cpcramer force-pushed the paul/add-paymaster-main-components branch 3 times, most recently from 7e7c9b6 to 8fd3286 Compare May 21, 2024 13:12
@cpcramer cpcramer force-pushed the paul/add-paymaster-main-components branch from 8fd3286 to 44826a9 Compare May 21, 2024 14:06
@cpcramer cpcramer requested a review from Zizzamia May 21, 2024 14:21
import { ENTRYPOINT_ADDRESS_V06 } from 'permissionless';
import { paymasterActionsEip7677 } from 'permissionless/experimental';
import { createClient, http } from 'viem';
import { createPublicClient } from 'viem';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why two lines to import from viem, just do one line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, fixed!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • @

@Zizzamia Zizzamia closed this May 23, 2024
@Zizzamia Zizzamia deleted the paul/add-paymaster-main-components branch May 23, 2024 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants