Skip to content

Commit

Permalink
feat: upgrade dotnet, upgrade deps, add nowait mode, add whitelist, a…
Browse files Browse the repository at this point in the history
…dd amount ignore limit per pool
  • Loading branch information
CumpsD committed Dec 25, 2024
1 parent 3bc35f8 commit 669729c
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 38 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM mcr.microsoft.com/dotnet/runtime:8.0.8 AS base
FROM mcr.microsoft.com/dotnet/runtime:9.0.0 AS base
USER $APP_UID
WORKDIR /app

FROM mcr.microsoft.com/dotnet/sdk:8.0.402 AS build
FROM mcr.microsoft.com/dotnet/sdk:9.0.100 AS build

ARG BUILD_CONFIGURATION=Release
ARG BUILD_NUMBER
Expand Down
20 changes: 19 additions & 1 deletion chainflip-lp/Configuration/BotConfiguration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace ChainflipLp.Configuration
{
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;

Expand Down Expand Up @@ -78,9 +79,21 @@ public bool? AnnounceTickChanges
get; init;
}

public int? AmountIgnoreLimit
{
get; init;
}

[Required]
[NotNull]
public int? AmountIgnoreLimit
public List<string>? Whitelist
{
get; init;
}

[Required]
[NotNull]
public bool? NoWaitMode
{
get; init;
}
Expand Down Expand Up @@ -143,5 +156,10 @@ public int? MaxSellTick
{
get; init;
}

public int? AmountIgnoreLimit
{
get; init;
}
}
}
6 changes: 4 additions & 2 deletions chainflip-lp/Model/OrderManager/CleanupDustOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public partial class OrderManager
"quote_asset": { "chain": "Ethereum", "asset": "USDC" },
"side": "REPLACE_SIDE",
"id": "REPLACE_ID",
"sell_amount": "0"
"sell_amount": "0",
"wait_for": "REPLACE_WAIT_FOR"
}
}
""";
Expand Down Expand Up @@ -82,7 +83,8 @@ private async Task CleanupDustOrder(
.Replace("REPLACE_CHAIN", chain)
.Replace("REPLACE_ASSET", asset)
.Replace("REPLACE_ID", order.Id)
.Replace("REPLACE_SIDE", side);
.Replace("REPLACE_SIDE", side)
.Replace("REPLACE_WAIT_FOR", _configuration.NoWaitMode.Value ? "NoWait" : "Finalized");

var response = await client.PostAsync(
string.Empty,
Expand Down
4 changes: 2 additions & 2 deletions chainflip-lp/Model/OrderManager/OrderManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private async Task NotifyTelegram(
try
{
var message = await telegramClient
.SendMessageAsync(
.SendRequest(
new SendMessageRequest
{
ChatId = new ChatId(_configuration.TelegramChannelId.Value),
Expand All @@ -116,7 +116,7 @@ private async Task NotifyTelegram(
return;

await telegramClient
.SetMessageReactionAsync(
.SendRequest(
new SetMessageReactionRequest
{
ChatId = new ChatId(_configuration.TelegramChannelId.Value),
Expand Down
6 changes: 4 additions & 2 deletions chainflip-lp/Model/OrderManager/PlaceBuyOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public partial class OrderManager
"tick": REPLACE_BUY_TICK,
"amount_change": {
"increase": "REPLACE_AMOUNT"
}
},
"wait_for": "REPLACE_WAIT_FOR"
}
}
""";
Expand Down Expand Up @@ -159,7 +160,8 @@ private async Task PlaceBuyOrder(
.Replace("REPLACE_ASSET", pool.Asset)
.Replace("REPLACE_ID", GenerateAssetId(pool.Chain, pool.Asset, "buy"))
.Replace("REPLACE_AMOUNT", balance)
.Replace("REPLACE_BUY_TICK", pool.MinBuyTick.Value.ToString());
.Replace("REPLACE_BUY_TICK", pool.MinBuyTick.Value.ToString())
.Replace("REPLACE_WAIT_FOR", _configuration.NoWaitMode.Value ? "NoWait" : "Finalized");

var response = await client.PostAsync(
string.Empty,
Expand Down
6 changes: 4 additions & 2 deletions chainflip-lp/Model/OrderManager/PlaceSellOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public partial class OrderManager
"tick": REPLACE_SELL_TICK,
"amount_change": {
"increase": "REPLACE_AMOUNT"
}
},
"wait_for": "REPLACE_WAIT_FOR"
}
}
""";
Expand Down Expand Up @@ -88,7 +89,8 @@ private async Task PlaceSellOrder(
.Replace("REPLACE_ASSET", pool.Asset)
.Replace("REPLACE_ID", GenerateAssetId(pool.Chain, pool.Asset, "sell"))
.Replace("REPLACE_AMOUNT", balance)
.Replace("REPLACE_SELL_TICK", pool.MinSellTick.Value.ToString());
.Replace("REPLACE_SELL_TICK", pool.MinSellTick.Value.ToString())
.Replace("REPLACE_WAIT_FOR", _configuration.NoWaitMode.Value ? "NoWait" : "Finalized");

var response = await client.PostAsync(
string.Empty,
Expand Down
11 changes: 8 additions & 3 deletions chainflip-lp/Model/OrderManager/UpdateBuyOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public partial class OrderManager
"tick": REPLACE_BUY_TICK,
"amount_change": {
"increase": "0x0"
}
},
"wait_for": "REPLACE_WAIT_FOR"
}
}
""";
Expand All @@ -40,13 +41,16 @@ private async Task UpdateBuyOrders(
ITelegramBotClient telegramClient,
CancellationToken cancellationToken)
{
var amountIgnoreLimit = ourOrders.AmountIgnoreLimit ?? _configuration.AmountIgnoreLimit ?? 0;

var otherOrders = allPoolOrders
.Where(x =>
x.Chain == ourOrders.Chain &&
x.Asset == ourOrders.Asset)
.SelectMany(x => x.Buys)
.Where(x => x.Amount.ToNumeric() > _configuration.AmountIgnoreLimit.Value)
.Where(x => x.Amount.ToNumeric() > amountIgnoreLimit)
.Where(x => x.LiquidityProvider != _configuration.LpAccount)
.Where(x => !_configuration.Whitelist.Contains(x.LiquidityProvider))
.Where(x => x.Tick <= ourOrders.MaxBuyTick)
.ToList();

Expand Down Expand Up @@ -111,7 +115,8 @@ private async Task UpdateBuyOrder(
.Replace("REPLACE_CHAIN", chain)
.Replace("REPLACE_ASSET", asset)
.Replace("REPLACE_ID", GenerateAssetId(chain, asset, "buy"))
.Replace("REPLACE_BUY_TICK", newTick.ToString());
.Replace("REPLACE_BUY_TICK", newTick.ToString())
.Replace("REPLACE_WAIT_FOR", _configuration.NoWaitMode.Value ? "NoWait" : "Finalized");

var response = await client.PostAsync(
string.Empty,
Expand Down
11 changes: 8 additions & 3 deletions chainflip-lp/Model/OrderManager/UpdateSellOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public partial class OrderManager
"tick": REPLACE_SELL_TICK,
"amount_change": {
"increase": "0x0"
}
},
"wait_for": "REPLACE_WAIT_FOR"
}
}
""";
Expand All @@ -40,13 +41,16 @@ private async Task UpdateSellOrders(
ITelegramBotClient telegramClient,
CancellationToken cancellationToken)
{
var amountIgnoreLimit = ourOrders.AmountIgnoreLimit ?? _configuration.AmountIgnoreLimit ?? 0;

var otherOrders = allPoolOrders
.Where(x =>
x.Chain == ourOrders.Chain &&
x.Asset == ourOrders.Asset)
.SelectMany(x => x.Sells)
.Where(x => x.Amount.ToNumeric() > _configuration.AmountIgnoreLimit.Value)
.Where(x => x.Amount.ToNumeric() > amountIgnoreLimit)
.Where(x => x.LiquidityProvider != _configuration.LpAccount)
.Where(x => !_configuration.Whitelist.Contains(x.LiquidityProvider))
.Where(x => x.Tick >= ourOrders.MaxSellTick)
.ToList();

Expand Down Expand Up @@ -111,7 +115,8 @@ private async Task UpdateSellOrder(
.Replace("REPLACE_CHAIN", chain)
.Replace("REPLACE_ASSET", asset)
.Replace("REPLACE_ID", GenerateAssetId(chain, asset, "sell"))
.Replace("REPLACE_SELL_TICK", newTick.ToString());
.Replace("REPLACE_SELL_TICK", newTick.ToString())
.Replace("REPLACE_WAIT_FOR", _configuration.NoWaitMode.Value ? "NoWait" : "Finalized");

var response = await client.PostAsync(
string.Empty,
Expand Down
1 change: 1 addition & 0 deletions chainflip-lp/Model/PoolOrders/PoolOrders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public partial class PoolOrders

public string Chain => _pool.Chain;
public string Asset => _pool.Asset;
public int? AmountIgnoreLimit => _pool.AmountIgnoreLimit;

public IEnumerable<Order> Buys => _poolOrders.Result.LimitOrders.Buys;

Expand Down
4 changes: 4 additions & 0 deletions chainflip-lp/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ await account.PlaceOrders(
private async Task WaitForNextLoop(CancellationToken ct)
{
var delay = _configuration.QueryDelay.Value.RandomizeTime();

if (_configuration.NoWaitMode.Value)
delay = 4000;

_logger.LogInformation("Waiting {QueryDelay}ms for next check.", delay);
await Task.Delay(delay, ct);
}
Expand Down
8 changes: 7 additions & 1 deletion chainflip-lp/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
{
"Bot": {
"TelegramToken": "7085961150:AAEPMX3o5Lh99E2qg5iUh6ePmu6xM2jgYaI",
"AmountIgnoreLimit": 0
"AmountIgnoreLimit": 0,
"NoWaitMode": "false",
"Whitelist": [
"cFLBKavxvThwqLWNr7cTwtqhYD6jDqXM31d6QoTLvuK4X78ve",
"cFJYzUFU97Y849kbKvyj7br1CUumnbqWHJKDcfPFoKRqq6Zxz",
"cFN1G2P1ogDXGX897LrMv3XNRcTQ2pYbXWiaF9D7eqkAgS4aC"
]
},

"Serilog": {
Expand Down
36 changes: 18 additions & 18 deletions chainflip-lp/chainflip-lp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TargetFramework>net8.0</TargetFramework>
<RuntimeFrameworkVersion>8.0.8</RuntimeFrameworkVersion>
<TargetFramework>net9.0</TargetFramework>
<RuntimeFrameworkVersion>9.0.0</RuntimeFrameworkVersion>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>

<AssemblyName>$(MSBuildProjectName)</AssemblyName>
Expand Down Expand Up @@ -53,28 +53,28 @@

<ItemGroup>
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
<PackageReference Include="Destructurama.JsonNet" Version="3.0.0" />
<PackageReference Include="Destructurama.JsonNet" Version="4.0.0" />
<PackageReference Include="Humanizer.Core" Version="2.14.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="8.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageReference Include="Nethereum.Hex" Version="4.26.0" />
<PackageReference Include="Nethereum.Util" Version="4.26.0" />
<PackageReference Include="Polly" Version="8.4.2" />
<PackageReference Include="Serilog" Version="4.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.0" />
<PackageReference Include="Nethereum.Hex" Version="4.27.1" />
<PackageReference Include="Nethereum.Util" Version="4.27.1" />
<PackageReference Include="Polly" Version="8.5.0" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.Process" Version="3.0.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.3" />
<PackageReference Include="Serilog.Extensions.Logging" Version="9.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Telegram.Bot" Version="20.0.0-alpha.3" />
<PackageReference Include="Telegram.Bot" Version="22.2.0" />
<PackageReference Include="xxHashSharp" Version="1.0.0" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"sdk": {
"version": "8.0.402"
"version": "9.0.100"
},
"clr": {
"version": "8.0.8"
"version": "9.0.0"
}
}

0 comments on commit 669729c

Please sign in to comment.