@alchemy/aa-core
Version:
viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts
38 lines • 1.64 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.upgradeAccount = void 0;
const isSmartAccountClient_js_1 = require("../../client/isSmartAccountClient.js");
const account_js_1 = require("../../errors/account.js");
const client_js_1 = require("../../errors/client.js");
const sendUserOperation_js_1 = require("./sendUserOperation.js");
const waitForUserOperationTransacation_js_1 = require("./waitForUserOperationTransacation.js");
const upgradeAccount = async (client, args) => {
const { account = client.account, upgradeTo, overrides, waitForTx, context, } = args;
if (!account) {
throw new account_js_1.AccountNotFoundError();
}
if (!(0, isSmartAccountClient_js_1.isBaseSmartAccountClient)(client)) {
throw new client_js_1.IncompatibleClientError("BaseSmartAccountClient", "upgradeAccount", client);
}
const { implAddress: accountImplAddress, initializationData } = upgradeTo;
const encodeUpgradeData = await account.encodeUpgradeToAndCall({
upgradeToAddress: accountImplAddress,
upgradeToInitData: initializationData,
});
const result = await (0, sendUserOperation_js_1.sendUserOperation)(client, {
uo: {
target: account.address,
data: encodeUpgradeData,
},
account,
overrides,
context,
});
let hash = result.hash;
if (waitForTx) {
hash = await (0, waitForUserOperationTransacation_js_1.waitForUserOperationTransaction)(client, result);
}
return hash;
};
exports.upgradeAccount = upgradeAccount;
//# sourceMappingURL=upgradeAccount.js.map