@lifi/sdk
Version:
LI.FI Any-to-Any Cross-Chain-Swap SDK
40 lines • 1.45 kB
JavaScript
import { ChainType } from '@lifi/types';
import { parseAccount } from 'viem/accounts';
import { getAction } from 'viem/utils';
import { config } from '../../config.js';
export async function getCapabilities(client, parameters = {}) {
const account_raw = parameters?.account ?? client.account;
if (!account_raw) {
throw new Error('Account not found');
}
const account = parseAccount(account_raw);
const capabilities_raw = await client.request({
method: 'wallet_getCapabilities',
params: [account.address],
}, {
dedupe: true,
retryCount: 0,
});
const capabilities = {};
for (const [key, value] of Object.entries(capabilities_raw)) {
capabilities[Number(key)] = value;
}
return capabilities;
}
export async function isBatchingSupported({ client, chainId, }) {
const _client = client ??
(await config.getProvider(ChainType.EVM)?.getWalletClient?.());
if (!_client) {
throw new Error('WalletClient is not provided.');
}
try {
const capabilities = (await getAction(_client, getCapabilities, 'getCapabilities')(undefined));
return capabilities[chainId]?.atomicBatch?.supported ?? false;
}
catch {
// If the wallet does not support getCapabilities or the call fails,
// we assume that atomic batch is not supported
return false;
}
}
//# sourceMappingURL=isBatchingSupported.js.map