@biconomy/sdk
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
48 lines • 1.76 kB
JavaScript
import { http, concatHex, createWalletClient, encodeAbiParameters, publicActions } from "viem";
import { PREFIX } from "./signQuote.js";
export const FUSION_NATIVE_TRANSFER_PREFIX = "0x150b7a02";
/**
* Signs a fusion quote
* @param client - The Mee client to use
* @param params - The parameters for the fusion quote
* @returns The signed quote
* @example
* const signedQuote = await signFusionQuote(meeClient, {
* quote: quotePayload,
* account: smartAccount
* })
*/
export const signFusionQuote = async (client, params) => {
const { account: account_ = client.account, quote, executionMode = "fusion-with-onchain-tx", trigger: { call: call_, chain } } = params;
// If the data field is empty, a prefix must be added in order for the
// chain not to reject the transaction. This is done in cases when the
// user is using the transfer of native gas to the SCA as the trigger
// transaction
const call = {
...call_,
data: concatHex([
call_.data ?? FUSION_NATIVE_TRANSFER_PREFIX,
PREFIX[executionMode],
quote.hash
])
};
const signer = account_.signer;
const masterClient = createWalletClient({
account: signer,
chain,
transport: http()
}).extend(publicActions);
const hash = await masterClient.sendTransaction(call);
const receipt = await masterClient.waitForTransactionReceipt({ hash });
const signature = concatHex([
PREFIX[executionMode],
encodeAbiParameters([{ type: "bytes32" }, { type: "uint256" }], [hash, BigInt(chain.id)])
]);
return {
receipt,
...quote,
signature
};
};
export default signFusionQuote;
//# sourceMappingURL=signFusionQuote.js.map