@biconomy/abstractjs
Version:
SDK for Biconomy integration with support for account abstraction, smart accounts, ERC-4337.
83 lines • 3.26 kB
JavaScript
import { createPublicClient } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { toMultichainNexusAccount } from "./index.js";
import { createMeeClient } from "../clients/createMeeClient.js";
import deployGasTank, {} from "./decorators/deployGasTank.js";
import { getGasTankAddress as getGasTankAddressDecorator } from "./decorators/getGasTankAddress.js";
import { getGasTankBalance as getGasTankBalanceDecorator } from "./decorators/getGasTankBalance.js";
import { getGasTankNonce as getGasTankNonceDecorator } from "./decorators/getGasTankNonce.js";
import { sponsorSupertransaction as sponsorSupertransactionDecorator } from "./decorators/sponsorSupertransaction.js";
import withdrawFromGasTank, {} from "./decorators/withdrawFromGasTank.js";
/**
* Creates a gas tank account for sponsorship
*
* @param parameters - {@link GasTankAccountParams} Configuration for gas tank account
* @param parameters.signer - The signer instance used for account
* @param parameters.chain - chain for the gas tank account
* @param parameters.privateKey - EOA private key for the gas tank account
*
* @returns Promise resolving to {@link GasTankAccount} instance
*
* @example
* const account = await toGasTankAccount({
* privateKey: '0xprivate_key,
* chain: base,
* transport: http()
* });
*/
export async function toGasTankAccount(params) {
const { chainConfiguration, privateKey, options } = params;
const { chain, transport } = chainConfiguration;
const mcNexus = await toMultichainNexusAccount({
signer: privateKeyToAccount(privateKey),
chainConfigurations: [chainConfiguration]
});
const publicClient = createPublicClient({
chain,
transport
});
const meeClient = await createMeeClient({
account: mcNexus,
...(options?.mee?.url ? { url: options.mee.url } : {}),
...(options?.mee?.apiKey ? { apiKey: options.mee.apiKey } : {})
});
const getAddress = () => getGasTankAddressDecorator(mcNexus, { chainId: chain.id });
const getBalance = (params) => getGasTankBalanceDecorator(mcNexus, {
chainId: chain.id,
tokenAddress: params.tokenAddress
});
const signSponsorship = (params) => sponsorSupertransactionDecorator(mcNexus, {
chainId: chain.id,
quote: params.quote
});
const getNonce = () => getGasTankNonceDecorator(mcNexus, { chainId: chain.id });
const isDeployed = () => {
return mcNexus.deploymentOn(chain.id, true).isDeployed();
};
const deploy = (params) => deployGasTank(mcNexus, {
meeClient,
chainId: chain.id,
tokenAddress: params.tokenAddress,
amount: params.amount,
confirmations: params.confirmations || 2
});
const withdraw = (params) => withdrawFromGasTank(mcNexus, {
meeClient,
chainId: chain.id,
tokenAddress: params.tokenAddress,
recipient: params.recipient,
amount: params.amount,
confirmations: params.confirmations || 2
});
return {
publicClient,
isDeployed,
getAddress,
getBalance,
getNonce,
signSponsorship,
deploy,
withdraw
};
}
//# sourceMappingURL=toGasTankAccount.js.map