UNPKG

@biconomy/abstractjs

Version:

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

78 lines 2.73 kB
/** * Create a one click deposit template. Can be customized with type parameters to add additional parameters to the template. * @param params - The parameters for the template * @param params.sourceChainInstructions - The instructions for the source chain * @param params.bridgeInstructions - The instructions for the bridge * @param params.destChainInstructions - The instructions for the destination chain * @returns A function that returns the instructions for the template * * @example * const oneClick = createOneClickDepositTemplate<{ amount: bigint }>({ * sourceChainInstructions: async ({ sourceChain, destChain, amount }) => { * ... * }, * bridgeInstructions: async ({ sourceChain, destChain, amount }) => { * ... * }, * destChainInstructions: async ({ sourceChain, destChain, amount }) => { * ... * } * }) * const instructions = await oneClick({ * sourceChain: paymentChain, * destChain: targetChain, * amount: amountConsumed * }) * const fusionQuote = await meeClient.getFusionQuote({ * instructions, * ... * }) */ export const createOneClickDepositTemplate = (params) => { return async (depositParams) => { const { sourceChain, destChain, ...restParams } = depositParams; const typedRestParams = restParams; const sourceInstructions = await params.sourceChainInstructions?.({ sourceChain, destChain, ...typedRestParams }); const bridgeInstructions = await params.bridgeInstructions?.({ sourceChain, destChain, ...typedRestParams }); const destInstructions = await params.destChainInstructions?.({ sourceChain, destChain, ...typedRestParams }); const allInstructions = []; if (sourceInstructions) { if (Array.isArray(sourceInstructions)) { allInstructions.push(...sourceInstructions.flat()); } else { allInstructions.push(sourceInstructions); } } if (bridgeInstructions) { if (Array.isArray(bridgeInstructions)) { allInstructions.push(...bridgeInstructions.flat()); } else { allInstructions.push(bridgeInstructions); } } if (destInstructions) { if (Array.isArray(destInstructions)) { allInstructions.push(...destInstructions.flat()); } else { allInstructions.push(destInstructions); } } return allInstructions; }; }; //# sourceMappingURL=createOneClickDepositTemplate.js.map