Skip to content

Commit

Permalink
feat: tweak swapduration
Browse files Browse the repository at this point in the history
  • Loading branch information
CumpsD committed Aug 31, 2024
1 parent 7967521 commit fc27284
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions chainflip-insights/Feeders/Swap/SwapFeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public class SwapFeeder : IFeeder
}

swapChannelByDepositChannelId {
blockByIssuedBlockId {
timestamp
}
swapChannelBeneficiariesByDepositChannelId {
nodes {
brokerCommissionRateBps
Expand Down
12 changes: 10 additions & 2 deletions chainflip-insights/Feeders/Swap/SwapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ public string ProtocolDeltaUsdPercentageFormatted

public double? BurnUsd { get; }

public DateTimeOffset DepositChannelIssuedTimestamp { get; }
public DateTimeOffset? PreDepositTimestamp { get; }
public DateTimeOffset DepositTimestamp { get; }
public DateTimeOffset EgressTimestamp { get; }
Expand Down Expand Up @@ -118,8 +119,14 @@ public TimeSpan SwapDuration
{
get
{
var estimatedStart = PreDepositTimestamp.HasValue
? DepositChannelIssuedTimestamp > PreDepositTimestamp.Value
? DepositChannelIssuedTimestamp
: PreDepositTimestamp.Value
: DepositChannelIssuedTimestamp;

var offset = PreDepositTimestamp.HasValue
? DepositTimestamp.Subtract(PreDepositTimestamp.Value) / 2
? DepositTimestamp.Subtract(estimatedStart) / 2
: new TimeSpan(0);

return EgressTimestamp - DepositTimestamp + offset;
Expand Down Expand Up @@ -185,7 +192,8 @@ public SwapInfo(
.Sum(x => x.Data.FeeValueUsd ?? 0) + LiquidityFeesUsd;

Broker = GetBroker(swap);


DepositChannelIssuedTimestamp = DateTimeOffset.Parse(swap.SwapChannel.Block.StateChainTimestamp);
PreDepositTimestamp = string.IsNullOrWhiteSpace(swap.PreDeposit?.StateChainTimestamp)
? null
: DateTimeOffset.Parse(swap.PreDeposit.StateChainTimestamp);
Expand Down
5 changes: 4 additions & 1 deletion chainflip-insights/Feeders/Swap/SwapsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,16 @@ public class BlockTime

public class SwapChannelByDepositChannelId
{
[JsonPropertyName("blockByIssuedBlockId")]
public Block Block { get; set; }

[JsonPropertyName("brokerByBrokerId")]
public BrokerByBrokerId Broker { get; set; }

[JsonPropertyName("swapChannelBeneficiariesByDepositChannelId")]
public BeneficiariesByDepositChannelId Beneficiaries { get; set; }
}

public class BeneficiariesByDepositChannelId
{
[JsonPropertyName("nodes")]
Expand Down

0 comments on commit fc27284

Please sign in to comment.