@account-kit/infra
Version:
adapters for @aa-sdk/core for interacting with alchemy services
37 lines • 1.71 kB
JavaScript
import { AccountNotFoundError, IncompatibleClientError, deepHexlify, } from "@aa-sdk/core";
import { isAlchemySmartAccountClient } from "../client/isAlchemySmartAccountClient.js";
/**
* Simulates user operation changes including asset changes for a specified user operation and returns the resulting state changes.
*
* @example
* ```ts
* import { simulateUserOperationChanges, createAlchemyPublicRpcClient } from "@account-kit/infra";
*
* const client = createAlchemyPublicRpcClient(...);
* const response = await simulateUserOperationChanges(client, {
* uo: ...
* });
* ```
*
* @param {Client<Transport, TChain, TAccount, AlchemyRpcSchema>} client The client instance used to send the simulation request
* @param {SendUserOperationParameters<TAccount>} args The parameters of the user operation including the account and other overrides
* @returns {Promise<SimulateUserOperationAssetChangesResponse>} A promise that resolves to the response of the simulation showing the asset changes
*/
export const simulateUserOperationChanges = async (client, { account = client.account, overrides, ...params }) => {
if (!account) {
throw new AccountNotFoundError();
}
if (!isAlchemySmartAccountClient(client)) {
throw new IncompatibleClientError("AlchemySmartAccountClient", "SimulateUserOperationAssetChanges", client);
}
const uoStruct = deepHexlify(await client.buildUserOperation({
...params,
account,
overrides,
}));
return client.request({
method: "alchemy_simulateUserOperationAssetChanges",
params: [uoStruct, account.getEntryPoint().address],
});
};
//# sourceMappingURL=simulateUserOperationChanges.js.map