@uniswap/smart-wallet-sdk
Version:
⚒️ An SDK for building applications with smart wallets on Uniswap
71 lines • 2.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BatchedCallPlanner = exports.BATCHED_CALL_ABI_PARAMS = void 0;
const viem_1 = require("viem");
// Define the ABI parameter type for the call tuple
exports.BATCHED_CALL_ABI_PARAMS = [
{
type: 'tuple',
components: [
{
type: 'tuple[]',
components: [
{ type: 'address', name: 'to' },
{ type: 'uint256', name: 'value' },
{ type: 'bytes', name: 'data' }
],
name: 'calls'
},
{ type: 'bool', name: 'revertOnFailure' }
]
}
];
/**
* BatchedCallPlanner is used to encode a BatchedCall, which are `calls` and `revertOnFailure`
*/
class BatchedCallPlanner {
/**
* Create a new BatchedCallPlanner
* @param callPlanner optionally initialize with a CallPlanner
* @param revertOnFailure optionally initialize with a boolean for revertOnFailure
*/
constructor(callPlanner, revertOnFailure = true) {
this.callPlanner = callPlanner;
this.revertOnFailure = revertOnFailure;
}
/**
* Get the total value of the calls
*/
get value() {
return this.callPlanner.value;
}
/**
* Add a command to execute a call
* @param to The target address of the call
* @param value The ETH value to send with the call
* @param data The calldata for the call
*/
add(to, value, data) {
this.callPlanner.add(to, value, data);
return this;
}
/**
* Encode the BatchedCall
*/
encode() {
return (0, viem_1.encodeAbiParameters)(exports.BATCHED_CALL_ABI_PARAMS, [
{
calls: this.callPlanner.calls,
revertOnFailure: this.revertOnFailure
}
]);
}
toBatchedCall() {
return {
calls: this.callPlanner.calls,
revertOnFailure: this.revertOnFailure
};
}
}
exports.BatchedCallPlanner = BatchedCallPlanner;
//# sourceMappingURL=batchedCallPlanner.js.map