import { ChainType } from '../../utils/chainType.js'; import type { SolanaProvider, SolanaProviderOptions } from './type.js'; import type { StepExecutorOptions } from '../types.js'; import { isAddress } from './isAddress.js'; import { getSolanaBalance } from './getSolanaBalance.js'; import { getSNSAddress } from './getSolanaAddress.js'; import { SolanaStepExecutor } from './SolanaStepExecutor.js'; export function Solana(options?: SolanaProviderOptions): SolanaProvider { const _options: SolanaProviderOptions = options ?? {}; return { get type() { return ChainType.SVM as any; }, isAddress, resolveAddress: getSNSAddress, getBalance: getSolanaBalance as any, async getStepExecutor( options: StepExecutorOptions, ): Promise { if (!_options.getWalletAdapter) { throw new Error(`getWalletAdapter is not provided.`); } const walletAdapter = await _options.getWalletAdapter(); const executor = new SolanaStepExecutor({ routeId: options.routeId, walletAdapter: walletAdapter, executionOptions: { ...options.executionOptions, }, }); return executor; }, setOptions(options: SolanaProviderOptions) { Object.assign(_options, options); }, }; }