import { ChainType } from '../../utils/chainType.js'; import type { MVMProvider, MVMProviderOptions } from './types.js'; import type { StepExecutorOptions } from '../types.js'; import { isAddress } from './isAddress.js'; import { getMVMBalance } from './getMVMBalance.js'; import { useMVMAddress } from './getMVMAddress.js'; import { MVMStepExecutor } from './MVMStepExecutor.js'; export function MVM(options?: MVMProviderOptions): MVMProvider { const _options: MVMProviderOptions = options ?? {}; return { get type() { return ChainType.MVM as any; }, isAddress, resolveAddress: useMVMAddress, getBalance: getMVMBalance 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 MVMStepExecutor({ routeId: options.routeId, walletAdapter: walletAdapter, mevProtection: _options.mevProtection, transactionMode: _options.transactionMode, customGasPrice: _options.customGasPrice, maxGasCap: _options.maxGasCap, executionOptions: { ...options.executionOptions, slippage: _options.slippage, }, }); return executor; }, setOptions(options: MVMProviderOptions) { Object.assign(_options, options); }, }; }