Skip to content

Commit

Permalink
Add allocation fee to drain delegate operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Groxan committed Jun 29, 2024
1 parent 5b7a317 commit 5567ecc
Show file tree
Hide file tree
Showing 12 changed files with 7,034 additions and 1,041 deletions.
5 changes: 5 additions & 0 deletions Tzkt.Api/Models/Operations/DrainDelegateOperation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public class DrainDelegateOperation : Operation
/// </summary>
public long Fee { get; set; }

/// <summary>
/// The amount of funds burned from the drained baker for account creation (micro tez)
/// </summary>
public long AllocationFee { get; set; }

#region injecting
/// <summary>
/// Injected historical quote at the time of operation
Expand Down
4 changes: 2 additions & 2 deletions Tzkt.Api/Repositories/BalanceHistoryRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");

Expand Down Expand Up @@ -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 ");
Expand Down
13 changes: 13 additions & 0 deletions Tzkt.Api/Repositories/OperationRepository.DrainDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});
}
Expand All @@ -67,6 +68,7 @@ public async Task<IEnumerable<DrainDelegateOperation>> GetDrainDelegates(Block b
Target = Accounts.GetAlias(row.TargetId),
Amount = row.Amount,
Fee = row.Fee,
AllocationFee = row.AllocationFee,
Quote = Quotes.Get(quote, block.Level)
});
}
Expand Down Expand Up @@ -108,6 +110,7 @@ public async Task<IEnumerable<DrainDelegateOperation>> GetDrainDelegates(
Target = Accounts.GetAlias(row.TargetId),
Amount = row.Amount,
Fee = row.Fee,
AllocationFee = row.AllocationFee,
Quote = Quotes.Get(quote, row.Level)
});
}
Expand Down Expand Up @@ -139,6 +142,7 @@ public async Task<object[][]> GetDrainDelegates(
case "target": columns.Add(@"o.""TargetId"""); break;
case "amount": columns.Add(@"o.""Amount"""); break;
case "fee": columns.Add(@"o.""Fee"""); break;
case "allocationFee": columns.Add(@"o.""AllocationFee"""); break;
case "block":
columns.Add(@"b.""Hash""");
joins.Add(@"INNER JOIN ""Blocks"" as b ON b.""Level"" = o.""Level""");
Expand Down Expand Up @@ -209,6 +213,10 @@ public async Task<object[][]> GetDrainDelegates(
foreach (var row in rows)
result[j++][i] = row.Fee;
break;
case "allocationFee":
foreach (var row in rows)
result[j++][i] = row.AllocationFee;
break;
case "quote":
foreach (var row in rows)
result[j++][i] = Quotes.Get(quote, row.Level);
Expand Down Expand Up @@ -244,6 +252,7 @@ public async Task<object[]> GetDrainDelegates(
case "target": columns.Add(@"o.""TargetId"""); break;
case "amount": columns.Add(@"o.""Amount"""); break;
case "fee": columns.Add(@"o.""Fee"""); break;
case "allocationFee": columns.Add(@"o.""AllocationFee"""); break;
case "block":
columns.Add(@"b.""Hash""");
joins.Add(@"INNER JOIN ""Blocks"" as b ON b.""Level"" = o.""Level""");
Expand Down Expand Up @@ -311,6 +320,10 @@ public async Task<object[]> GetDrainDelegates(
foreach (var row in rows)
result[j++] = row.Fee;
break;
case "allocationFee":
foreach (var row in rows)
result[j++] = row.AllocationFee;
break;
case "quote":
foreach (var row in rows)
result[j++] = Quotes.Get(quote, row.Level);
Expand Down
2 changes: 1 addition & 1 deletion Tzkt.Api/Repositories/ReportRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,7 @@ void UnionDrainDelegateOps(StringBuilder sql)
sql.Append(@"null::integer as ""Received"", ");
sql.Append(@"null::integer as ""From"", ");
sql.Append(@"""Amount"" as ""Sent"", ");
sql.Append(@"""Fee"" as ""Fee"", ");
sql.Append(@"(""Fee"" + ""AllocationFee"") as ""Fee"", ");
sql.Append(@"""TargetId"" as ""To"" ");

sql.Append(@"FROM ""DrainDelegateOps"" ");
Expand Down
4 changes: 2 additions & 2 deletions Tzkt.Api/Services/Home/HomeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ SELECT SUM(""BakerFee"")::bigint AS fee, 0::bigint AS burn FROM ""DalPublishComm
UNION ALL
SELECT SUM(""BakerFee"")::bigint AS fee, 0::bigint AS burn FROM ""DelegationOps"" WHERE ""Level"" >= {currPeriod}
UNION ALL
SELECT SUM(""Fee"")::bigint AS fee, 0::bigint AS burn FROM ""DrainDelegateOps"" WHERE ""Level"" >= {currPeriod}
SELECT SUM(""Fee"")::bigint AS fee, SUM(""AllocationFee"")::bigint AS burn FROM ""DrainDelegateOps"" WHERE ""Level"" >= {currPeriod}
UNION ALL
SELECT SUM(""BakerFee"")::bigint AS fee, SUM(COALESCE(""StorageFee"", 0))::bigint AS burn FROM ""IncreasePaidStorageOps"" WHERE ""Level"" >= {currPeriod}
UNION ALL
Expand Down Expand Up @@ -431,7 +431,7 @@ SELECT SUM(""BakerFee"")::bigint AS fee, 0::bigint AS burn FROM ""DalPublishComm
UNION ALL
SELECT SUM(""BakerFee"")::bigint AS fee, 0::bigint AS burn FROM ""DelegationOps"" WHERE ""Level"" >= {prevPeriod} AND ""Level"" < {currPeriod}
UNION ALL
SELECT SUM(""Fee"")::bigint AS fee, 0::bigint AS burn FROM ""DrainDelegateOps"" WHERE ""Level"" >= {prevPeriod} AND ""Level"" < {currPeriod}
SELECT SUM(""Fee"")::bigint AS fee, SUM(""AllocationFee"")::bigint AS burn FROM ""DrainDelegateOps"" WHERE ""Level"" >= {prevPeriod} AND ""Level"" < {currPeriod}
UNION ALL
SELECT SUM(""BakerFee"")::bigint AS fee, SUM(COALESCE(""StorageFee"", 0))::bigint AS burn FROM ""IncreasePaidStorageOps"" WHERE ""Level"" >= {prevPeriod} AND ""Level"" < {currPeriod}
UNION ALL
Expand Down
Loading

0 comments on commit 5567ecc

Please sign in to comment.