From 5567ecc13776e43a88071ec30bb26548814b414e Mon Sep 17 00:00:00 2001
From: Maksim Strebkov <257byte@gmail.com>
Date: Sat, 29 Jun 2024 15:14:17 +0300
Subject: [PATCH] Add allocation fee to drain delegate operations
---
.../Operations/DrainDelegateOperation.cs | 5 +
.../Repositories/BalanceHistoryRepository.cs | 4 +-
.../OperationRepository.DrainDelegate.cs | 13 +
Tzkt.Api/Repositories/ReportRepository.cs | 2 +-
Tzkt.Api/Services/Home/HomeService.cs | 4 +-
...0240629103331_DrainDelegateExt.Designer.cs | 6933 +++++++++++++++++
.../20240629103331_DrainDelegateExt.cs | 29 +
.../Migrations/TzktContextModelSnapshot.cs | 5 +-
.../Operations/DrainDelegateOperation.cs | 1 +
Tzkt.Sync.Tests/Database/StatisticsTests.cs | 1 +
.../Commits/Operations/DrainDelegateCommit.cs | 51 +-
.../Handlers/Proto19/Validation/Validator.cs | 1027 +--
12 files changed, 7034 insertions(+), 1041 deletions(-)
create mode 100644 Tzkt.Data/Migrations/20240629103331_DrainDelegateExt.Designer.cs
create mode 100644 Tzkt.Data/Migrations/20240629103331_DrainDelegateExt.cs
diff --git a/Tzkt.Api/Models/Operations/DrainDelegateOperation.cs b/Tzkt.Api/Models/Operations/DrainDelegateOperation.cs
index 9c7d56429..27e348d48 100644
--- a/Tzkt.Api/Models/Operations/DrainDelegateOperation.cs
+++ b/Tzkt.Api/Models/Operations/DrainDelegateOperation.cs
@@ -52,6 +52,11 @@ public class DrainDelegateOperation : Operation
///
public long Fee { get; set; }
+ ///
+ /// The amount of funds burned from the drained baker for account creation (micro tez)
+ ///
+ public long AllocationFee { get; set; }
+
#region injecting
///
/// Injected historical quote at the time of operation
diff --git a/Tzkt.Api/Repositories/BalanceHistoryRepository.cs b/Tzkt.Api/Repositories/BalanceHistoryRepository.cs
index 8b6ec6532..9264eced0 100644
--- a/Tzkt.Api/Repositories/BalanceHistoryRepository.cs
+++ b/Tzkt.Api/Repositories/BalanceHistoryRepository.cs
@@ -915,7 +915,7 @@ void SumDrainDelegateOps(StringBuilder sql, int from, int to)
sql.Append(sql.Length == 0 ? "SELECT " : "UNION ALL SELECT ");
#region delegate
- sql.Append(@"SUM(-""Amount"" - ""Fee"") as ""Change"" ");
+ sql.Append(@"SUM(-""Amount"" - ""Fee"" - ""AllocationFee"") as ""Change"" ");
sql.Append(@"FROM ""DrainDelegateOps"" ");
sql.Append(@"WHERE ""DelegateId"" = @account ");
@@ -1782,7 +1782,7 @@ void UnionDrainDelegateOps(StringBuilder sql)
#region delegate
sql.Append(@"""Level"" as ""Level"", ");
- sql.Append(@"(-""Amount"" - ""Fee"") as ""Change"" ");
+ sql.Append(@"(-""Amount"" - ""Fee"" - ""AllocationFee"") as ""Change"" ");
sql.Append(@"FROM ""DrainDelegateOps"" ");
sql.Append(@"WHERE ""DelegateId"" = @account ");
diff --git a/Tzkt.Api/Repositories/OperationRepository.DrainDelegate.cs b/Tzkt.Api/Repositories/OperationRepository.DrainDelegate.cs
index e78dd86b7..e1e9018ac 100644
--- a/Tzkt.Api/Repositories/OperationRepository.DrainDelegate.cs
+++ b/Tzkt.Api/Repositories/OperationRepository.DrainDelegate.cs
@@ -41,6 +41,7 @@ INNER JOIN ""Blocks"" as b
Target = Accounts.GetAlias(row.TargetId),
Amount = row.Amount,
Fee = row.Fee,
+ AllocationFee = row.AllocationFee,
Quote = Quotes.Get(quote, row.Level)
});
}
@@ -67,6 +68,7 @@ public async Task> GetDrainDelegates(Block b
Target = Accounts.GetAlias(row.TargetId),
Amount = row.Amount,
Fee = row.Fee,
+ AllocationFee = row.AllocationFee,
Quote = Quotes.Get(quote, block.Level)
});
}
@@ -108,6 +110,7 @@ public async Task> GetDrainDelegates(
Target = Accounts.GetAlias(row.TargetId),
Amount = row.Amount,
Fee = row.Fee,
+ AllocationFee = row.AllocationFee,
Quote = Quotes.Get(quote, row.Level)
});
}
@@ -139,6 +142,7 @@ public async Task