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

[Draft] custom paymaster handler & zyfi integration #51

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

0xSulpiride
Copy link

@0xSulpiride 0xSulpiride commented Jan 28, 2025

Description

Added paymaster plugin support that enables developers to create external paymaster plugins that integrate with SDK easily.

Key changes:

  • New CustomPaymasterHandler type and integration in transaction flow
  • Example implementation with ZyFi's paymaster API

wip: add paymaster handler to passkey clients

Additional context

With these changes users can start using external paymasters easily with just 2-3 lines of code

import { zksyncSsoConnector, callPolicy } from "zksync-sso/connector";
import { zksyncSepoliaTestnet } from "viem/chains";
import { createConfig, connect } from "@wagmi/core";
import { erc20Abi } from "viem";
import { createZyfiPaymaster } from "zksync-sso/paymaster";

const zksyncConnectorWithSession = zksyncSsoConnector({
  authServerUrl: "http://localhost:3002/confirm",
  session: {
    feeLimit: parseEther("0.1"),
    transfers: [
      {
        to: testTransferTarget,
        valueLimit: parseEther("1"),
      },
    ],
  },
  paymasterHandler: createZyfiPaymaster({
    apiKey: 'xxxxx-xxxxx-xxxx',
    sponsorshipRatio: 100
  }),
});
const zksyncConnector = zksyncSsoConnector({
  authServerUrl: "http://localhost:3002/confirm",
  paymasterHandler: createZyfiPaymaster({ apiKey: 'xxxxx-xxxxx-xxxx' }),
});
const wagmiConfig = createConfig({
  chains: [chain],
  connectors: [zksyncConnector],
  transports: {
    [chain.id]: http(),
  },
});

How it works:

customPaymasterHandler acts as a middleware which is triggered just before signing a transaction.
Simplest paymaster handler will just add static paymaster and paymasterInput to a transaction.

const zksyncConnector = zksyncSsoConnector({
  authServerUrl: "http://localhost:3002/confirm",
  paymasterHandler: async () => ({
    paymaster: PaymasterContract.address,
    paymasterInput: getGeneralPaymasterInput({ innerInput: "0x" }),
  }),
});

The more complex one, like ZyFi's, will send the transaction to some backend service and can fetch not only paymasterInput, but also gas fees since some paymasters may rely on exact values of these fields to account for ERC20 tokens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant