public void Update(IExchangeEventEntity entity) { switch (entity.Type) { case ExchangeEventType.TokenPurchase: EthLiquidity = EthLiquidity + entity.EthAmount; TokenLiquidity = TokenLiquidity - entity.TokenAmount; break; case ExchangeEventType.EthPurchase: EthLiquidity = EthLiquidity - entity.EthAmount; TokenLiquidity = TokenLiquidity + entity.TokenAmount; break; case ExchangeEventType.AddLiquidity: EthLiquidity = EthLiquidity + entity.EthAmount; TokenLiquidity = TokenLiquidity + entity.TokenAmount; break; case ExchangeEventType.RemoveLiquidity: EthLiquidity = EthLiquidity - entity.EthAmount; TokenLiquidity = TokenLiquidity - entity.TokenAmount; break; } }
public async Task AddOrUpdateAsync(IExchangeEventEntity entity) { await _collection.FindOneAndReplaceAsync <MongoExchangeEventEntity>( e => e.Id.Equals(entity.Id), (MongoExchangeEventEntity)entity, new FindOneAndReplaceOptions <MongoExchangeEventEntity> { IsUpsert = true }); }
private ExchangeEvent Map(IExchangeEventEntity entity) { var exchangeEvent = new ExchangeEvent(); switch (entity.Type) { case ExchangeEventType.EthPurchase: exchangeEvent.EthAmount = -entity.EthAmount; exchangeEvent.TokenAmount = entity.TokenAmount; break; case ExchangeEventType.TokenPurchase: exchangeEvent.EthAmount = entity.EthAmount; exchangeEvent.TokenAmount = -entity.TokenAmount; break; case ExchangeEventType.AddLiquidity: exchangeEvent.EthAmount = entity.EthAmount; exchangeEvent.TokenAmount = entity.TokenAmount; break; case ExchangeEventType.RemoveLiquidity: exchangeEvent.EthAmount = -entity.EthAmount; exchangeEvent.TokenAmount = -entity.TokenAmount; break; default: throw new ArgumentException("Unknown event type", nameof(entity.Type)); } exchangeEvent.Block = entity.BlockNumber; exchangeEvent.Event = entity.Type; exchangeEvent.Timestamp = entity.Timestamp.ToUnixTimestamp(); exchangeEvent.Tx = entity.TxHash; exchangeEvent.User = entity.CallerAddress; exchangeEvent.Fee = entity.EthFee; return(exchangeEvent); }
private bool IsEthOrTokenPurchaseEvent(IExchangeEventEntity entity) { return(entity.Type == ExchangeEventType.EthPurchase || entity.Type == ExchangeEventType.TokenPurchase); }