@biconomy/abstractjs
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
73 lines • 2.77 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOnChainQuote = void 0;
const batchInstructions_1 = require("../../../account/utils/batchInstructions.js");
const resolveInstructions_1 = require("../../../account/utils/resolveInstructions.js");
const getFusionQuote_1 = require("./getFusionQuote.js");
const getQuote_1 = require("./getQuote.js");
const getOnChainQuote = async (client, parameters) => {
const { account: account_ = client.account, trigger, cleanUps, instructions, gasLimit, ...rest } = parameters;
const resolvedInstructions = await (0, resolveInstructions_1.resolveInstructions)(instructions);
if (trigger.call) {
const batchedInstructions = await (0, batchInstructions_1.batchInstructions)({
account: account_,
instructions: resolvedInstructions
});
const quote = await (0, getQuote_1.getQuote)(client, {
path: "quote",
eoa: account_.signer.address,
instructions: batchedInstructions,
gasLimit: gasLimit || getQuote_1.DEFAULT_GAS_LIMIT,
...(cleanUps ? { cleanUps } : {}),
...rest
});
return {
quote,
trigger
};
}
const sender = account_.signer.address;
const scaAddress = account_.addressOn(trigger.chainId, true);
const recipient = trigger.recipientAddress || scaAddress;
const { triggerGasLimit, triggerAmount, batchedInstructions } = await (0, getFusionQuote_1.prepareInstructions)(client, {
resolvedInstructions,
trigger,
sender,
scaAddress,
recipient,
account: account_
});
const quote = await (0, getQuote_1.getQuote)(client, {
path: "quote-permit",
eoa: account_.signer.address,
instructions: batchedInstructions,
gasLimit: gasLimit || triggerGasLimit,
...(cleanUps ? { cleanUps } : {}),
...rest
});
let fees = trigger.useMaxAvailableFunds
? 0n
: BigInt(quote.paymentInfo.tokenWeiAmount);
if (rest.sponsorship) {
fees = 0n;
}
const amount = triggerAmount + fees;
return {
quote,
trigger: {
tokenAddress: trigger.tokenAddress,
chainId: trigger.chainId,
gasLimit: triggerGasLimit,
amount,
...(trigger.approvalAmount
? { approvalAmount: trigger.approvalAmount }
: {}),
...(trigger.recipientAddress
? { recipientAddress: trigger.recipientAddress }
: {})
}
};
};
exports.getOnChainQuote = getOnChainQuote;
exports.default = exports.getOnChainQuote;
//# sourceMappingURL=getOnChainQuote.js.map