From 333c709c2c6700a28c88ad04b28fa16366a9868b Mon Sep 17 00:00:00 2001 From: David Hintermann <David.Hintermann@ost.ch> Date: Tue, 26 Nov 2024 09:43:53 +0000 Subject: [PATCH] wip: swap async --- Frontend/BackgroundServices/PrometheusService.cs | 2 +- Frontend/Functions/SwapExactInputSingleFunction.cs | 4 ++-- Frontend/PoolV3Client.cs | 6 +++--- Frontend/Program.cs | 2 ++ 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Frontend/BackgroundServices/PrometheusService.cs b/Frontend/BackgroundServices/PrometheusService.cs index cf94bca..098fb2c 100644 --- a/Frontend/BackgroundServices/PrometheusService.cs +++ b/Frontend/BackgroundServices/PrometheusService.cs @@ -40,7 +40,7 @@ public class PrometheusService : BackgroundService }; _erc20TokenMetrics.CreateMetrics(); _ethMetrics.CreateMetrics(); - PoolV3Client poolClient = new(chainSettings.Uniswap.RocEthPoolAddress, web3); + PoolV3Client poolClient = new( web3,chainSettings); _poolMetrics.CreateMetrics(poolClient); } diff --git a/Frontend/Functions/SwapExactInputSingleFunction.cs b/Frontend/Functions/SwapExactInputSingleFunction.cs index c729446..2dd799e 100644 --- a/Frontend/Functions/SwapExactInputSingleFunction.cs +++ b/Frontend/Functions/SwapExactInputSingleFunction.cs @@ -4,7 +4,7 @@ using Nethereum.Contracts; using HexBigInteger = Nethereum.Hex.HexTypes.HexBigInteger; namespace Frontend.Functions; - +[Function("swapExactInputSingle", "uint256")] public class SwapExactInputSingleFunction : FunctionMessage { [Parameter("address", "tokenIn", 1)] @@ -23,7 +23,7 @@ public class SwapExactInputSingleFunction : FunctionMessage public string Recipient { get; set; } [Parameter("uint256", "deadline", 6)] - public HexBigInteger Deadline { get; set; } + public BigInteger Deadline { get; set; } [Parameter("uint24", "fee", 7)] public uint Fee { get; set; } diff --git a/Frontend/PoolV3Client.cs b/Frontend/PoolV3Client.cs index 4a70635..eddb65d 100644 --- a/Frontend/PoolV3Client.cs +++ b/Frontend/PoolV3Client.cs @@ -19,7 +19,7 @@ public class PoolV3Client private string? token1Address = null; private uint? poolFeeTier = null; - public PoolV3Client(string poolAddress, Web3 web3, ChainSettings chainSettings) + public PoolV3Client(Web3 web3, ChainSettings chainSettings) { _pool = web3.Eth.GetContract( @@ -31,7 +31,7 @@ public class PoolV3Client "uniswapV3Pool.abi.json" ) ), - poolAddress + chainSettings.Uniswap.RocEthPoolAddress ); _web3 = web3; _chainSettings = chainSettings; @@ -107,7 +107,7 @@ public class PoolV3Client AmountIn = Web3.Convert.ToWei(amount), AmountOutMinimum = Web3.Convert.ToWei(amountOutMinimum), // Set your minimum amount out Recipient = account.Address, - Deadline = new HexBigInteger(DateTimeOffset.UtcNow.ToUnixTimeSeconds() + 90), // 1:30 minutes from now + Deadline = new BigInteger(DateTimeOffset.UtcNow.ToUnixTimeSeconds() + 90), // 1:30 minutes from now Fee = await getPoolFeeTier(), SqrtPriceLimitX96 = sqrtPriceLimitX96 }; diff --git a/Frontend/Program.cs b/Frontend/Program.cs index f8ec992..e4dc332 100644 --- a/Frontend/Program.cs +++ b/Frontend/Program.cs @@ -46,6 +46,8 @@ builder.Services.AddSingleton(provider => new TokenClient( chainId )); +builder.Services.AddSingleton(provider=>account); + builder.Services.AddSingleton(provider => new Web3(account, chainApiUrl)); builder.Services.AddSingleton<PoolMetrics>(); -- GitLab