Skip to content

Commit

Permalink
add metrics to track revenue shares
Browse files Browse the repository at this point in the history
  • Loading branch information
affanv14 committed Oct 3, 2024
1 parent ce94992 commit e3a56ac
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
3 changes: 3 additions & 0 deletions protocol/lib/metrics/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,9 @@ const (
UpdateSubaccounts = "update_subaccounts"
SubaccountOwner = "subaccount_owner"
MarketMapperRevenueDistribution = "market_mapper_revenue_distribution"
AffiliateRevenueShareDistribution = "affiliate_revenue_share_distribution"
UnconditionalRevenueShareDistribution = "unconditional_revenue_share_distribution"
NetFeesPostRevenueShareDistribution = "net_fees_post_revenue_share_distribution"

// Liquidation Daemon.
CheckCollateralizationForSubaccounts = "check_collateralization_for_subaccounts"
Expand Down
37 changes: 27 additions & 10 deletions protocol/x/subaccounts/keeper/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,17 +250,28 @@ func (k Keeper) DistributeFees(
return err
}

// emit a metric for the amount of fees transferred to the market mapper
if revShare.RevShareType == revsharetypes.REV_SHARE_TYPE_MARKET_MAPPER {
labels := []metrics.Label{
metrics.GetLabelForIntValue(metrics.MarketId, int(perpetual.Params.MarketId)),
}
metrics.AddSampleWithLabels(
metrics.MarketMapperRevenueDistribution,
metrics.GetMetricValueFromBigInt(revShare.QuoteQuantums),
labels...,
)
// emit a metric for revenue share
labels := []metrics.Label{}
var metricName string
switch revShare.RevShareType {
case revsharetypes.REV_SHARE_TYPE_MARKET_MAPPER:
labels = append(labels, metrics.GetLabelForIntValue(metrics.MarketId, int(perpetual.Params.MarketId)))
metricName = metrics.MarketMapperRevenueDistribution
case revsharetypes.REV_SHARE_TYPE_AFFILIATE:
labels = append(labels, metrics.GetLabelForStringValue(metrics.RecipientAddress, revShare.Recipient))
metricName = metrics.AffiliateRevenueShareDistribution
case revsharetypes.REV_SHARE_TYPE_UNCONDITIONAL:
labels = append(labels, metrics.GetLabelForStringValue(metrics.RecipientAddress, revShare.Recipient))
metricName = metrics.UnconditionalRevenueShareDistribution
default:
ctx.Logger().Error("invalid rev share type", "type", revShare.RevShareType)
continue
}
metrics.AddSampleWithLabels(
metricName,
metrics.GetMetricValueFromBigInt(revShare.QuoteQuantums),
labels...,
)
}

totalTakerFeeRevShareQuantums := big.NewInt(0)
Expand Down Expand Up @@ -289,6 +300,12 @@ func (k Keeper) DistributeFees(
panic("fee collector share is < 0")
}

// Emit fee colletor metric
metrics.AddSample(
metrics.NetFeesPostRevenueShareDistribution,
metrics.GetMetricValueFromBigInt(feeCollectorShare),
)

// Transfer fees to the fee collector
if err := k.TransferFees(
ctx,
Expand Down

0 comments on commit e3a56ac

Please sign in to comment.