import { ChainType } from '../../utils/chainType.js'; import type { TVMProvider, TVMProviderOptions } from './types.js'; import type { StepExecutorOptions } from '../types.js'; import { isAddress } from './isAddress.js'; import { getTONBalance } from './getTONBalance.js'; import { getTONAddress } from './getTONAddress.js'; import { TVMStepExecutor } from './TVMStepExecutor.js'; export function TVM(options?: TVMProviderOptions): TVMProvider { const _options: TVMProviderOptions = options ?? {}; return { get type() { return ChainType.TVM as any; }, isAddress, resolveAddress: getTONAddress, getBalance: getTONBalance 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 TVMStepExecutor({ routeId: options.routeId, walletAdapter: walletAdapter, executionOptions: { ...options.executionOptions, slippage: _options.slippage, }, }); return executor; }, setOptions(options: TVMProviderOptions) { Object.assign(_options, options); }, }; }