UNPKG

zksync-ethers

Version:

A Web3 library for interacting with the ZkSync Layer 2 scaling solution.

68 lines 2.25 kB
import { ethers } from 'ethers'; import IPaymasterFlowABI from '../abi/IPaymasterFlow.json'; /** * The ABI for the `IPaymasterFlow` interface, which is utilized * for encoding input parameters for paymaster flows. * @readonly */ export const PAYMASTER_FLOW_ABI = new ethers.Interface(IPaymasterFlowABI); /** * Returns encoded input for an approval-based paymaster. * * @param paymasterInput The input data for the paymaster. */ export function getApprovalBasedPaymasterInput(paymasterInput) { return PAYMASTER_FLOW_ABI.encodeFunctionData('approvalBased', [ paymasterInput.token, paymasterInput.minimalAllowance, paymasterInput.innerInput, ]); } /** * Returns encoded input for a general-based paymaster. * * @param paymasterInput The input data for the paymaster. */ export function getGeneralPaymasterInput(paymasterInput) { return PAYMASTER_FLOW_ABI.encodeFunctionData('general', [ paymasterInput.innerInput, ]); } /** * Returns a correctly-formed {@link PaymasterParams|paymasterParams} object for common paymaster flows. * * @param paymasterAddress The non-zero paymaster address. * @param paymasterInput The input data for the paymaster. * * @example Create general-based parameters. * * const paymasterAddress = "0x0a67078A35745947A37A552174aFe724D8180c25"; * const paymasterParams = utils.getPaymasterParams(paymasterAddress, { * type: "General", * innerInput: new Uint8Array(), * }); * * @example Create approval-based parameters. * * const result = utils.getPaymasterParams("0x0a67078A35745947A37A552174aFe724D8180c25", { * type: "ApprovalBased", * token: "0x65C899B5fb8Eb9ae4da51D67E1fc417c7CB7e964", * minimalAllowance: BigInt(1), * innerInput: new Uint8Array(), * }); */ export function getPaymasterParams(paymasterAddress, paymasterInput) { if (paymasterInput.type === 'General') { return { paymaster: paymasterAddress, paymasterInput: getGeneralPaymasterInput(paymasterInput), }; } else { return { paymaster: paymasterAddress, paymasterInput: getApprovalBasedPaymasterInput(paymasterInput), }; } } //# sourceMappingURL=paymaster-utils.js.map