Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        void Add <T>(IBundleSource <T> bundleSource)
            where T : Bundle
        {
            var result = bundleSource.GetBundles(GetBundleFactory <T>(), application);

            Tuple <object, CreateBundleContainer> existingTuple;

            if (bundleSourceResultsByType.TryGetValue(typeof(T), out existingTuple))
            {
                var existingResult = (IEnumerable <T>)existingTuple.Item1;
                var existingAction = existingTuple.Item2;
                // Concat the two bundle collections.
                // Keep the existing initialization action.
                bundleSourceResultsByType[typeof(T)] = Tuple.Create(
                    (object)existingResult.Concat(result),
                    existingAction
                    );
            }
            else
            {
                bundleSourceResultsByType[typeof(T)] = Tuple.Create <object, CreateBundleContainer>(
                    result,
                    CreateBundleContainer <T>
                    );
            }
        }
Exemplo n.º 3
0
 public V2Selector(
     IBundleSource bundleSource,
     IBundleSimulator bundleSimulator,
     ITailGasPriceCalculator tailGasPriceCalculator,
     long maxBundlesGasUsedRatio = 100)
 {
     _bundleSource           = bundleSource;
     _bundleSimulator        = bundleSimulator;
     _tailGasPriceCalculator = tailGasPriceCalculator;
     _maxBundlesGasUsedRatio = maxBundlesGasUsedRatio;
 }
Exemplo n.º 4
0
 public V1Selector(IBundleSource bundleSource, IBundleSimulator bundleSimulator)
 {
     _bundleSource    = bundleSource;
     _bundleSimulator = bundleSimulator;
 }
Exemplo n.º 5
0
 public BundleTxSource(IBundleSource bundleSource, ITimestamper timestamper, TimeSpan?timeout = null)
 {
     _bundleSource = bundleSource;
     _timestamper  = timestamper;
     _timeout      = timeout ?? DefaultTimeout;
 }