From 4e99c263b42c7440260879cd6a4131d4f15d8575 Mon Sep 17 00:00:00 2001 From: Andri Joos <andri@joos.io> Date: Wed, 20 Nov 2024 23:54:16 +0100 Subject: [PATCH] add PotatoMarketplaceMock --- .../Interfaces/IPotatoMarketplace.cs | 13 ++++++++ .../Marketplaces/PotatoMarketplaceMock.cs | 32 +++++++++++++++++++ Frontend/Program.cs | 3 ++ 3 files changed, 48 insertions(+) create mode 100644 Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs create mode 100644 Frontend/Marketplaces/PotatoMarketplaceMock.cs diff --git a/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs b/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs new file mode 100644 index 0000000..757223d --- /dev/null +++ b/Frontend/Marketplaces/Interfaces/IPotatoMarketplace.cs @@ -0,0 +1,13 @@ +using Frontend.Assets; + +namespace Frontend.Marketplaces.Interfaces +{ + public interface IPotatoMarketPlace + { + public double PotatoPrice { get; } + public double PotatoKgToChf(double kg); + public double ChfToPotatoKg(double chf); + public PotatoTransaction Buy(double amountInChf); + public double Sell(PotatoTransaction transaction); + } +} diff --git a/Frontend/Marketplaces/PotatoMarketplaceMock.cs b/Frontend/Marketplaces/PotatoMarketplaceMock.cs new file mode 100644 index 0000000..fb3accf --- /dev/null +++ b/Frontend/Marketplaces/PotatoMarketplaceMock.cs @@ -0,0 +1,32 @@ +using Frontend.Assets; +using Frontend.Marketplaces.Interfaces; + +namespace Frontend.Marketplaces; + +public class PotatoMarketplaceMock() : IPotatoMarketPlace +{ + private const double potatoKgPrice = 2.02; // source: https://www.blw.admin.ch/blw/de/home/markt/marktbeobachtung/kartoffeln.html + + public double PotatoPrice => potatoKgPrice; + + public double ChfToPotatoKg(double chf) + { + return chf / potatoKgPrice; + } + + public double PotatoKgToChf(double kg) + { + return kg * potatoKgPrice; + } + + public PotatoTransaction Buy(double amountInChf) + { + var amountInKg = ChfToPotatoKg(amountInChf); + return new() { Weight = amountInKg }; + } + + public double Sell(PotatoTransaction transaction) + { + return PotatoKgToChf(transaction.Weight); + } +} diff --git a/Frontend/Program.cs b/Frontend/Program.cs index 4e9f8a5..2bf5552 100644 --- a/Frontend/Program.cs +++ b/Frontend/Program.cs @@ -1,6 +1,8 @@ using Frontend; using Frontend.AssetStores; using Frontend.BackgroundServices; +using Frontend.Marketplaces; +using Frontend.Marketplaces.Interfaces; using Frontend.Metrics; using Microsoft.EntityFrameworkCore; using OpenTelemetry.Metrics; @@ -28,6 +30,7 @@ builder.Services.AddHostedService<PrometheusService>(); builder.Services.AddSingleton<Erc20TokenMetrics>(); builder.Services.AddSingleton<EthMetrics>(); builder.Services.AddSingleton<PotatoStorageMetrics>(); +builder.Services.AddSingleton<IPotatoMarketPlace>(sp => new PotatoMarketplaceMock()); builder.Services.AddSingleton(provider => new TokenClient( chainApiUrl, -- GitLab