UNPKG

@biconomy/abstractjs

Version:

SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.

81 lines 3.65 kB
import { resolveInstructions } from "../../../account/utils/resolveInstructions.js"; import { prepareInstructions } from "./getFusionQuote.js"; import { getQuote } from "./getQuote.js"; export const DEFAULT_VERIFICATION_GAS_LIMIT_FOR_MM_DTK = 200000n; /** * Gets a quote for a permit-enabled transaction from the MEE service. * This method is used when the payment token supports ERC20Permit, allowing for * gasless approvals and more efficient transactions. * * @param client - The base MEE client instance * @param parameters - Parameters for the permit quote request * @param parameters.trigger - Payment token and amount information * @param parameters.instructions - Array of transaction instructions to execute * @param [parameters.account] - Optional account to use (defaults to client.account) * * @returns Promise resolving to quote payload with permit-specific trigger information * * * @throws Will throw an error if: * - The trigger parameters are invalid * - The quote request fails */ export const getMmDtkQuote = async (client, parameters) => { const { account: account_ = client.account, trigger, cleanUps, instructions, batch = true, gasLimit, verificationGasLimit, delegatorSmartAccount, ...rest } = parameters; const resolvedInstructions = await resolveInstructions(instructions); const sender = delegatorSmartAccount.address; const spender = account_.addressOn(trigger.chainId, true); // By default the trigger amount will be deposited to sca account. // if a custom recipient is defined ? It will deposit to the recipient address const recipient = trigger.recipientAddress || spender; const { triggerGasLimit, triggerAmount, batchedInstructions } = await prepareInstructions(client, { resolvedInstructions, trigger, owner: sender, spender, recipient, account: account_, batch }); const triggerInfo = { tokenAddress: trigger.tokenAddress, chainId: trigger.chainId, gasLimit: triggerGasLimit, amount: triggerAmount, // Amount without fees and fees will be added below ...(trigger.approvalAmount ? { approvalAmount: trigger.approvalAmount } : {}), ...(trigger.recipientAddress ? { recipientAddress: trigger.recipientAddress } : {}) }; // using the quote-permit endpoint as the redeemed permission // will aprove whatever is required to be approved, so the // rest is similar to the regular permit fusion mode const quote = await getQuote(client, { path: "quote-permit", eoa: sender, // it is not an EOA, but a smart account in this case, however param is named `eoa` for backward compatibility, see `GetQuoteParams` type for more details instructions: batchedInstructions, gasLimit: gasLimit || triggerGasLimit, batch, verificationGasLimit: verificationGasLimit || DEFAULT_VERIFICATION_GAS_LIMIT_FOR_MM_DTK, ...(cleanUps ? { cleanUps } : {}), ...rest }, "mm-dtk", triggerInfo); // For useMaxAvailableFunds case, fees will be taken from max available funds. // else it will be explicitly defined here let fees = trigger.useMaxAvailableFunds ? 0n : BigInt(quote.paymentInfo.tokenWeiAmount); if (rest.sponsorship) { // For sponsorship, user will never pay fee. So the trigger amount never include fees fees = 0n; } triggerInfo.amount += fees; return { quote, trigger: triggerInfo }; }; export default getMmDtkQuote; //# sourceMappingURL=getMmDtkQuote.js.map