@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
60 lines • 2.36 kB
JavaScript
import { isBaseSmartAccountClient } from "../../client/isSmartAccountClient.js";
import { AccountNotFoundError } from "../../errors/account.js";
import { IncompatibleClientError } from "../../errors/client.js";
import { bigIntMax, bigIntMultiply } from "../../utils/index.js";
import { _runMiddlewareStack } from "./internal/runMiddlewareStack.js";
import { _sendUserOperation } from "./internal/sendUserOperation.js";
export async function dropAndReplaceUserOperation(client, args) {
const { account = client.account, uoToDrop, overrides, context } = args;
if (!account) {
throw new AccountNotFoundError();
}
if (!isBaseSmartAccountClient(client)) {
throw new IncompatibleClientError("BaseSmartAccountClient", "dropAndReplaceUserOperation", client);
}
const entryPoint = account.getEntryPoint();
const uoToSubmit = (entryPoint.version === "0.6.0"
? {
initCode: uoToDrop.initCode,
sender: uoToDrop.sender,
nonce: uoToDrop.nonce,
callData: uoToDrop.callData,
signature: await account.getDummySignature(),
}
: {
...(uoToDrop.factory &&
uoToDrop.factoryData
? {
factory: uoToDrop.factory,
factoryData: uoToDrop
.factoryData,
}
: {}),
sender: uoToDrop.sender,
nonce: uoToDrop.nonce,
callData: uoToDrop.callData,
signature: await account.getDummySignature(),
});
const { maxFeePerGas, maxPriorityFeePerGas } = await _runMiddlewareStack(client, {
uo: uoToSubmit,
overrides,
account,
});
const _overrides = {
...overrides,
maxFeePerGas: bigIntMax(BigInt(maxFeePerGas ?? 0n), bigIntMultiply(uoToDrop.maxFeePerGas, 1.1)),
maxPriorityFeePerGas: bigIntMax(BigInt(maxPriorityFeePerGas ?? 0n), bigIntMultiply(uoToDrop.maxPriorityFeePerGas, 1.1)),
};
const uoToSend = await _runMiddlewareStack(client, {
uo: uoToSubmit,
overrides: _overrides,
account,
});
return _sendUserOperation(client, {
uoStruct: uoToSend,
account,
context,
overrides: _overrides,
});
}
//# sourceMappingURL=dropAndReplaceUserOperation.js.map