@abstract-foundation/agw-client
Version:
Abstract Global Wallet Client SDK
55 lines • 2.3 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 sendPrivyTransaction_js_1 = require("./sendPrivyTransaction.js");
const sendTransactionInternal_js_1 = require("./sendTransactionInternal.js");
function getBatchTransactionObject(address, parameters) {
const { calls, paymaster, paymasterInput } = parameters;
const batchCalls = calls.map((tx) => {
if (!tx.to)
throw new Error('Transaction target (to) is required');
return {
target: tx.to,
allowFailure: false,
value: BigInt(tx.value ?? 0),
callData: tx.data ?? '0x',
};
});
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));
const batchTransaction = {
to: address,
data: batchCallData,
value: totalValue,
paymaster: paymaster,
paymasterInput: paymasterInput,
type: 'eip712',
};
return batchTransaction;
}
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, parameters);
return await publicClient.sendRawTransaction({
serializedTransaction: signedTx,
});
}
const batchTransaction = getBatchTransactionObject(client.account.address, parameters);
return (0, sendTransactionInternal_js_1.sendTransactionInternal)(client, signerClient, publicClient, {
...batchTransaction,
...rest,
}, constants_js_1.EOA_VALIDATOR_ADDRESS, {}, customPaymasterHandler);
}
//# sourceMappingURL=sendTransactionBatch.js.map