@uniswap/smart-wallet-sdk
Version:
⚒️ An SDK for building applications with smart wallets on Uniswap
67 lines • 1.95 kB
JavaScript
import { encodeAbiParameters } from 'viem';
// Define the ABI parameter type for the call tuple
export const 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`
*/
export 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 encodeAbiParameters(BATCHED_CALL_ABI_PARAMS, [
{
calls: this.callPlanner.calls,
revertOnFailure: this.revertOnFailure
}
]);
}
toBatchedCall() {
return {
calls: this.callPlanner.calls,
revertOnFailure: this.revertOnFailure
};
}
}
//# sourceMappingURL=batchedCallPlanner.js.map