@biconomy/sdk
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
65 lines • 2.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getQuote = void 0;
const getQuote = async (client, params) => {
const { account: account_ = client.account, instructions, feeToken } = params;
const resolvedInstructions = (await Promise.all(instructions.flatMap((instructions_) => typeof instructions_ === "function"
? instructions_()
: instructions_))).flat();
const validUserOps = resolvedInstructions.every((userOp) => account_.deploymentOn(userOp.chainId));
const validPaymentAccount = account_.deploymentOn(feeToken.chainId);
if (!validPaymentAccount || !validUserOps) {
console.log(resolvedInstructions.map((x) => x.chainId));
throw Error("Account is not deployed on necessary chain(s)");
}
const userOpResults = await Promise.all(resolvedInstructions.map((userOp) => {
const deployment = account_.deploymentOn(userOp.chainId);
if (deployment) {
return Promise.all([
deployment.encodeExecuteBatch(userOp.calls),
deployment.getNonce(),
deployment.isDeployed(),
deployment.getInitCode(),
deployment.address,
userOp.calls
.map((tx) => tx.gasLimit)
.reduce((curr, acc) => curr + acc)
.toString(),
userOp.chainId.toString()
]);
}
return null;
}));
const validUserOpResults = userOpResults.filter(Boolean);
const userOps = validUserOpResults.map(([callData, nonce_, isAccountDeployed, initCode, sender, callGasLimit, chainId]) => ({
sender,
callData,
callGasLimit,
nonce: nonce_.toString(),
chainId,
...(!isAccountDeployed && initCode ? { initCode } : {})
}));
const [nonce, isAccountDeployed, initCode] = await Promise.all([
validPaymentAccount.getNonce(),
validPaymentAccount.isDeployed(),
validPaymentAccount.getInitCode()
]);
const paymentInfo = {
sender: validPaymentAccount.address,
token: feeToken.address,
nonce: nonce.toString(),
chainId: feeToken.chainId.toString(),
...(!isAccountDeployed && initCode ? { initCode } : {})
};
const quoteRequest = {
userOps,
paymentInfo
};
return await client.request({
path: "v1/quote",
body: quoteRequest
});
};
exports.getQuote = getQuote;
exports.default = exports.getQuote;
//# sourceMappingURL=getQuote.js.map