diff --git a/.env.sample b/.env.sample index 50a26eb482e506a5c2ce939548d3245ecb31a778..ab73312266c639475cfc9d54b9fecd47e5bcce80 100644 --- a/.env.sample +++ b/.env.sample @@ -1,7 +1,8 @@ API_URL=https://sepolia.infura.io/v3/{yourApiKey} ACCOUNT_PRIVATE_KEY= +MARKETPLACE_ACCOUNT_PRIVATE_KEY= POSTGRES_HOST=postgres POSTGRES_PORT=5432 POSTGRES_DB=roesticoin POSTGRES_USER=roesticoin -PROMETHEUS_BASE_URL=http://prometheus:9000 +PROMETHEUS_BASE_URL=http://prometheus:9090 diff --git a/Frontend/Functions/LiquidityFunction.cs b/Frontend/Functions/LiquidityFunction.cs index fdc7cb27a4043fae9f6bb44c6f93eda47796ff06..0aef7fffb339576f3f6825bdd9737e76b42a0353 100644 --- a/Frontend/Functions/LiquidityFunction.cs +++ b/Frontend/Functions/LiquidityFunction.cs @@ -3,7 +3,7 @@ using Nethereum.Contracts; namespace Frontend.Functions; -[Function("liquiditry", "uint128")] +[Function("liquidity", "uint128")] public class LiquidityFunction : FunctionMessage{ } \ No newline at end of file diff --git a/Frontend/PoolV3Client.cs b/Frontend/PoolV3Client.cs index 1bb3b6f9ba2a418249bf5ec10368aa04e01d0c65..ddf6ed12701af5ecfbb2811a299d77ee8096fb82 100644 --- a/Frontend/PoolV3Client.cs +++ b/Frontend/PoolV3Client.cs @@ -199,13 +199,7 @@ public class PoolV3Client SqrtPriceLimitX96 = sqrtPriceLimitX96, }; var exactInputSingleFunctionTxnReceipt = await contractHandler.SendRequestAndWaitForReceiptAsync(exactInputSingleFunction); - var swapEvent = exactInputSingleFunctionTxnReceipt.DecodeAllEvents<SwapEventDTO>(); - if (swapEvent.Count > 0) - { - var receivedAmount = swapEvent[0].Event.AmountOut; - return Web3.Convert.FromWei(receivedAmount); - } - throw new Exception("Swap event not found in transaction receipt"); + return 0.0m; } /// <summary> @@ -237,7 +231,7 @@ public class PoolV3Client amount = (double)(liquidity * BigInteger.Pow(2, 96) * (sqrtPriceX96 - desiredSqrtPriceX96)) / (double)(desiredSqrtPriceX96 * sqrtPriceX96); balance = await Token0Client.BalanceOf(_account.Address); } - amount *= 1.0 + (double)await QueryPoolFee() / 1000.0; // add the pool fees + //amount *= 1.0 + (double)await QueryPoolFee() / 100000.0; // add the pool fees var bigIntAmount = new BigInteger(amount); if (balance < bigIntAmount) diff --git a/Frontend/Rebalancer.cs b/Frontend/Rebalancer.cs index 2f57019f987a3259cca134ffa0957c4373e4802b..665c5a40f918fa06d1fa6316cd34c86aa66016d7 100644 --- a/Frontend/Rebalancer.cs +++ b/Frontend/Rebalancer.cs @@ -77,10 +77,12 @@ public class Rebalancer } if (Math.Abs(1 - currentPrice / desiredPrice) > _threshold) { - _logger.LogDebug("Must rebalance: Mean price {}, desired price {}", currentPrice, desiredPrice); + _logger.LogInformation("Must rebalance: Mean price {}, desired price {}", currentPrice, desiredPrice); var quoteAfterSwap = await _pool.PerformSwapTowardsDesiredQuote(desiredPrice); - _logger.LogDebug("Quote afert swap: {}", quoteAfterSwap); + _logger.LogInformation("Quote afert swap: {}", quoteAfterSwap); RebalanceTradeExecutedCount++; + }else{ + _logger.LogInformation("Pool is balanced enough: Mean price {}, desired price {}", currentPrice, desiredPrice); } } @@ -92,36 +94,36 @@ public class Rebalancer var token1Reserve = await Token1Reserve(); if (token0ReservesInToken1 / token1Reserve > 2) // token0 is ROC , token1 is WETH, our reserves in ROC are twice as big as in WETH { - _logger.LogDebug("Must rebalance reserves: Token0 reserves {}(expressed in token1), Token1 reserves {}(expressed in token1)", token0ReservesInToken1, token1Reserve); + _logger.LogInformation("Must rebalance reserves: Token0 reserves {}(expressed in token1), Token1 reserves {}(expressed in token1)", token0ReservesInToken1, token1Reserve); var amountToAdjustInToken1 = (token0ReservesInToken1 - token1Reserve) / 2; var amountToAdjustInToken0 = amountToAdjustInToken1 / meanPoolPrice; - _logger.LogDebug("Half of the difference is {}(expressed in token0) or {}(expressed in token1). Sell it", amountToAdjustInToken0,amountToAdjustInToken1); + _logger.LogInformation("Half of the difference is {}(expressed in token0) or {}(expressed in token1). Sell it", amountToAdjustInToken0,amountToAdjustInToken1); var transactionToSell= await _potatoStorage.RemovePotatoes((double)amountToAdjustInToken0); var result= await _potatoMarket.Sell(transactionToSell, _account.Address); if(result){ - _logger.LogDebug("Potatoes sold successfully, burn the torken representation"); + _logger.LogInformation("Potatoes sold successfully, burn the torken representation"); await _token0Client.Burn(Web3.Convert.ToWei(transactionToSell.Weight), new CancellationToken()); }else{ _logger.LogError("Potatoes not sold successfully, keep the token representation"); } }else if(token1Reserve/token0ReservesInToken1 >2){ - _logger.LogDebug("Must rebalance reserves: Token0 reserves {}(expressed in token1), Token1 reserves {}(expressed in token1)", token0ReservesInToken1, token1Reserve); + _logger.LogInformation("Must rebalance reserves: Token0 reserves {}(expressed in token1), Token1 reserves {}(expressed in token1)", token0ReservesInToken1, token1Reserve); var amountToAdjustInToken1 = (token1Reserve - token0ReservesInToken1) / 2; var amountToAdjustInToken0 = amountToAdjustInToken1 / meanPoolPrice; - _logger.LogDebug("Half of the difference is {}(expressed in token0) or {}(expressed in token1). Buy it", amountToAdjustInToken0,amountToAdjustInToken1); + _logger.LogInformation("Half of the difference is {}(expressed in token0) or {}(expressed in token1). Buy it", amountToAdjustInToken0,amountToAdjustInToken1); await _token1Client.ApproveAsync(_potatoMarket.Address,Web3.Convert.ToWei(amountToAdjustInToken1)); var buyTransaction= await _potatoMarket.Buy(_account.Address); if(buyTransaction!=null){ - _logger.LogDebug("Potatoes bought successfully, mint the token representation"); + _logger.LogInformation("Potatoes bought successfully, mint the token representation"); await _potatoStorage.AddPotatoes(buyTransaction); await _token0Client.Mint(_account.Address,Web3.Convert.ToWei(buyTransaction.Weight),new CancellationToken()); }else{ - _logger.LogDebug("Potatoes bought successfully, mint the token representation"); + _logger.LogInformation("Potatoes bought successfully, mint the token representation"); } }else{ - _logger.LogDebug("Reserves are balanced enough: Token0 reserves {}[token1], Token1 reserves {}[token1]", token0ReservesInToken1, token1Reserve); + _logger.LogInformation("Reserves are balanced enough: Token0 reserves {}[token1], Token1 reserves {}[token1]", token0ReservesInToken1, token1Reserve); } } @@ -132,7 +134,7 @@ public class Rebalancer var tokenReserve = await Token0Reserve(); if(Math.Abs(rwaSupply-tokenSupply) < EPSIOLON){ - _logger.LogDebug("Token supply matches RWA supply"); + _logger.LogInformation("Token supply matches RWA supply"); return; } @@ -140,9 +142,9 @@ public class Rebalancer { var shouldBurn = tokenSupply - rwaSupply; var burnable = Math.Min(shouldBurn,tokenReserve); // we cannot burn mor then we control - _logger.LogDebug("Should burn {} tokens, currently controlling {} tokens",shouldBurn,tokenReserve); + _logger.LogInformation("Should burn {} tokens, currently controlling {} tokens",shouldBurn,tokenReserve); await _token0Client.Burn(Web3.Convert.ToWei(burnable), new CancellationToken()); - _logger.LogDebug("Burned {} tokens",burnable); + _logger.LogInformation("Burned {} tokens",burnable); if(burnable < shouldBurn){ _logger.LogError("Trigger rebalancing reserves and try again"); await MaintainLiquidReservesAsync(); @@ -151,7 +153,7 @@ public class Rebalancer } else if (rwaSupply > tokenSupply) { - _logger.LogDebug("Must mint {} tokens", rwaSupply - tokenSupply); + _logger.LogInformation("Must mint {} tokens", rwaSupply - tokenSupply); await _token0Client.Mint(_account.Address, Web3.Convert.ToWei(rwaSupply - tokenSupply), new CancellationToken()); }