@biconomy/sdk
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
103 lines • 4.09 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.installModule = installModule;
const viem_1 = require("viem");
const account_abstraction_1 = require("viem/account-abstraction");
const utils_1 = require("viem/utils");
const AccountNotFound_1 = require("../../../account/utils/AccountNotFound.js");
const Utils_1 = require("../../../account/utils/Utils.js");
const constants_1 = require("../../../constants/index.js");
const supportsModule_1 = require("./supportsModule.js");
async function installModule(client, parameters) {
const { account: account_ = client.account, maxFeePerGas, maxPriorityFeePerGas, nonce, module: { address, initData, type } } = parameters;
if (!account_) {
throw new AccountNotFound_1.AccountNotFoundError({
docsPath: "/nexus-client/methods#sendtransaction"
});
}
const account = (0, utils_1.parseAccount)(account_);
const calls = [
{
to: account.address,
value: BigInt(0),
data: (0, viem_1.encodeFunctionData)({
abi: [
{
name: "installModule",
type: "function",
stateMutability: "nonpayable",
inputs: [
{
type: "uint256",
name: "moduleTypeId"
},
{
type: "address",
name: "module"
},
{
type: "bytes",
name: "initData"
}
],
outputs: []
}
],
functionName: "installModule",
args: [(0, supportsModule_1.parseModuleTypeId)(type), (0, viem_1.getAddress)(address), initData ?? "0x"]
})
}
];
if ((0, Utils_1.addressEquals)(address, constants_1.SMART_SESSIONS_ADDRESS)) {
const nexusAccount = account;
if (nexusAccount?.validatorAddress) {
calls.push({
to: nexusAccount.validatorAddress,
value: BigInt(0),
data: (0, viem_1.encodeFunctionData)({
abi: [
{
name: "addSafeSender",
type: "function",
stateMutability: "nonpayable",
inputs: [
{
type: "address",
name: "sender"
}
],
outputs: []
}
],
functionName: "addSafeSender",
args: [address]
})
});
}
const publicClient = account?.client;
const trustedAttesters = await (0, constants_1.findTrustedAttesters)({
client: publicClient,
accountAddress: account.address
});
const needToAddTrustAttesters = trustedAttesters.length === 0;
if (needToAddTrustAttesters && nexusAccount?.attesters?.length) {
const trustAttestersAction = (0, constants_1.getTrustAttestersAction)({
attesters: nexusAccount.attesters,
threshold: 1
});
calls.push({
to: trustAttestersAction.target,
value: trustAttestersAction.value.valueOf(),
data: trustAttestersAction.callData
});
}
}
return (0, utils_1.getAction)(client, account_abstraction_1.sendUserOperation, "sendUserOperation")({
calls,
maxFeePerGas,
maxPriorityFeePerGas,
nonce,
account
});
}
//# sourceMappingURL=installModule.js.map