@uniswap/smart-wallet-sdk
Version:
⚒️ An SDK for building applications with smart wallets on Uniswap
60 lines • 1.71 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CallPlanner = exports.CALL_ABI_PARAMS = void 0;
const viem_1 = require("viem");
// Define the ABI parameter type for the call tuple
exports.CALL_ABI_PARAMS = [
{
type: 'tuple[]',
components: [
{ type: 'address', name: 'to' },
{ type: 'uint256', name: 'value' },
{ type: 'bytes', name: 'data' }
]
}
];
/**
* CallPlanner is used to encode a series Calls
*/
class CallPlanner {
/**
* Create a new CallPlanner
* @param calls optionally initialize with a list of calls
*/
constructor(calls = []) {
this.calls = calls;
}
/**
* Get the total value of the calls
*/
get value() {
return this.calls.reduce((acc, call) => {
// Convert string values to bigint
const callValue = typeof call.value === 'string'
? BigInt(call.value || '0')
: (call.value || 0n);
return acc + callValue;
}, 0n);
}
/**
* abi encode the Calls[]
*/
encode() {
if (this.calls.length === 0) {
throw new Error("No calls to encode");
}
return (0, viem_1.encodeAbiParameters)(exports.CALL_ABI_PARAMS, [this.calls]);
}
/**
* 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.calls.push({ to, value, data });
return this;
}
}
exports.CallPlanner = CallPlanner;
//# sourceMappingURL=callPlanner.js.map