public void Test(TestJson testJson) { TestSimulator sim = new(testJson); ITailGasPriceCalculator tailGas = testJson.TailGasType switch { TailGasType.Any => new ConstantTailGasPriceCalculator(0.GWei()), TailGasType.Constant80 => new ConstantTailGasPriceCalculator(80.GWei()), _ => throw new ArgumentOutOfRangeException() }; IBundleSource selector = testJson.SelectorType switch { SelectorType.V1 => new V1Selector(sim, sim), SelectorType.V2 => new V2Selector(sim, sim, tailGas, testJson.MaxGasLimitRatio), _ => throw new ArgumentOutOfRangeException() }; IEnumerable <MevBundle> selected = selector.GetBundles(_blockHeader, testJson.GasLimit !.Value); SimulatedMevBundle[]? simulated = sim.Simulate(_blockHeader, testJson.GasLimit !.Value, selected).ToArray(); long totalGasUsedByBundles = simulated.Sum(s => s.GasUsed); long gasLeftForTransactions = testJson.GasLimit !.Value - totalGasUsedByBundles; IEnumerable <Transaction>?txs = sim.GetTransactions(_blockHeader, gasLeftForTransactions); UInt256 totalProfit = simulated.Aggregate <SimulatedMevBundle, UInt256>(0, (profit, x) => profit + x.Profit); totalProfit += txs.Aggregate <Transaction, UInt256>(0, (profit, x) => profit + (x.GasPrice * (UInt256)x.GasLimit)); totalProfit.Should().Be(testJson.OptimalProfit !.Value, testJson.Description); }
public V2Selector( IBundleSource bundleSource, IBundleSimulator bundleSimulator, ITailGasPriceCalculator tailGasPriceCalculator, long maxBundlesGasUsedRatio = 100) { _bundleSource = bundleSource; _bundleSimulator = bundleSimulator; _tailGasPriceCalculator = tailGasPriceCalculator; _maxBundlesGasUsedRatio = maxBundlesGasUsedRatio; }