From e3a56ac6ad49e560393a257716017775e1e1fceb Mon Sep 17 00:00:00 2001 From: affan Date: Thu, 3 Oct 2024 10:49:58 -0400 Subject: [PATCH] add metrics to track revenue shares --- protocol/lib/metrics/constants.go | 3 ++ protocol/x/subaccounts/keeper/transfer.go | 37 +++++++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/protocol/lib/metrics/constants.go b/protocol/lib/metrics/constants.go index a0f851eb58..92654d4f81 100644 --- a/protocol/lib/metrics/constants.go +++ b/protocol/lib/metrics/constants.go @@ -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" diff --git a/protocol/x/subaccounts/keeper/transfer.go b/protocol/x/subaccounts/keeper/transfer.go index ecf79952be..d46a8b5695 100644 --- a/protocol/x/subaccounts/keeper/transfer.go +++ b/protocol/x/subaccounts/keeper/transfer.go @@ -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) @@ -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,