@abstract-foundation/agw-client
Version:
Abstract Global Wallet Client SDK
52 lines • 2.16 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBatchTransactionObject = getBatchTransactionObject;
exports.sendTransactionBatch = sendTransactionBatch;
const viem_1 = require("viem");
const AGWAccount_js_1 = require("../abis/AGWAccount.js");
const constants_js_1 = require("../constants.js");
const utils_js_1 = require("../utils.js");
const sendPrivyTransaction_js_1 = require("./sendPrivyTransaction.js");
const sendTransactionInternal_js_1 = require("./sendTransactionInternal.js");
function getBatchTransactionObject(address, parameters) {
const { calls, paymaster, paymasterInput } = parameters;
const batchCalls = (0, utils_js_1.formatCalls)(calls);
const batchCallData = (0, viem_1.encodeFunctionData)({
abi: AGWAccount_js_1.default,
functionName: "batchCall",
args: [batchCalls],
});
const totalValue = batchCalls.reduce((sum, call) => sum + BigInt(call.value), BigInt(0));
return {
to: address,
data: batchCallData,
value: totalValue,
paymaster: paymaster,
paymasterInput: paymasterInput,
type: "eip712",
};
}
async function sendTransactionBatch(client, signerClient, publicClient, parameters, isPrivyCrossApp = false, customPaymasterHandler = undefined) {
const { calls, ...rest } = parameters;
if (calls.length === 0) {
throw new Error("No calls provided");
}
if (isPrivyCrossApp) {
const signedTx = await (0, sendPrivyTransaction_js_1.signPrivyTransaction)(client, {
...rest,
calls: (0, utils_js_1.encodeCalls)(calls),
});
return await publicClient.sendRawTransaction({
serializedTransaction: signedTx,
});
}
const batchTransaction = getBatchTransactionObject(client.account.address, {
calls,
...rest,
});
return (0, sendTransactionInternal_js_1.sendTransactionInternal)(client, signerClient, publicClient, {
...batchTransaction,
...rest,
}, constants_js_1.EOA_VALIDATOR_ADDRESS, {}, customPaymasterHandler);
}
//# sourceMappingURL=sendTransactionBatch.js.map