UNPKG

@uniswap/smart-wallet-sdk

Version:

⚒️ An SDK for building applications with smart wallets on Uniswap

90 lines 3.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SmartWallet = void 0; const tslib_1 = require("tslib"); const viem_1 = require("viem"); const MinimalDelegationEntry_json_1 = tslib_1.__importDefault(require("../abis/MinimalDelegationEntry.json")); const constants_1 = require("./constants"); const utils_1 = require("./utils"); const batchedCallPlanner_1 = require("./utils/batchedCallPlanner"); /** * Main SDK class for interacting with Uniswap smart wallet contracts */ class SmartWallet { /** * Creates method parameters for executing a simple batch of calls through a smart wallet * @param calls Array of calls to encode * @param options Basic options for the execution * @returns Method parameters with calldata and value */ static encodeBatchedCall(calls, options = {}) { const planner = new utils_1.CallPlanner(calls); const batchedCallPlanner = new batchedCallPlanner_1.BatchedCallPlanner(planner, options.revertOnFailure); const encoded = (0, viem_1.encodeFunctionData)({ abi: MinimalDelegationEntry_json_1.default, functionName: '0x99e1d016', // execute(((address,uint256,bytes)[],bool)) args: [batchedCallPlanner.toBatchedCall()] }); return { calldata: encoded, value: planner.value }; } /** * ERC7821 compatible entrypoint for executing batched calls through the contract * @deprecated use encodeBatchedCall instead unless you need to use the ERC7821 entrypoint */ static encodeERC7821BatchedCall(calls, options = {}) { const mode = this.getModeFromOptions(options); if (mode != constants_1.ModeType.BATCHED_CALL && mode != constants_1.ModeType.BATCHED_CALL_CAN_REVERT) { throw new Error(`Invalid mode: ${mode}`); } const planner = new utils_1.CallPlanner(calls); const executionData = planner.encode(); const encoded = this._encodeERC7821Execute(mode, executionData); return { calldata: encoded, value: planner.value }; } /** * Creates a call to execute a method through a smart wallet * @dev can be refactored to return a Transaction object as well * @param methodParameters The method parameters to execute * @param chainId The chain ID for the smart wallet * @returns The call to execute */ static createExecute(methodParameters, chainId) { const address = constants_1.SMART_WALLET_ADDRESSES[chainId]; if (!address) { throw new Error(`Smart wallet not found for chainId: ${chainId}`); } return { to: address, data: methodParameters.calldata, value: methodParameters.value }; } /** * Get the mode type from the options */ static getModeFromOptions(options) { if (options.revertOnFailure) { return constants_1.ModeType.BATCHED_CALL; } return constants_1.ModeType.BATCHED_CALL_CAN_REVERT; } /** Internal methods */ static _encodeERC7821Execute(mode, data) { return (0, viem_1.encodeFunctionData)({ abi: MinimalDelegationEntry_json_1.default, functionName: '0xe9ae5c53', // execute(bytes32,bytes) args: [ mode, data ] }); } } exports.SmartWallet = SmartWallet; //# sourceMappingURL=smartWallet.js.map