Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OTE-849] Add metrics to track revenue shares #2449

Merged
merged 2 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions protocol/lib/metrics/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,8 @@ const (
UpdateSubaccounts = "update_subaccounts"
SubaccountOwner = "subaccount_owner"
MarketMapperRevenueDistribution = "market_mapper_revenue_distribution"
RevenueShareDistribution = "revenue_share_distribution"
NetFeesPostRevenueShareDistribution = "net_fees_post_revenue_share_distribution"

// Liquidation Daemon.
CheckCollateralizationForSubaccounts = "check_collateralization_for_subaccounts"
Expand Down Expand Up @@ -410,6 +412,9 @@ const (
ValidatorNumMatchedTakerOrders = "validator_num_matched_taker_orders"
ValidatorVolumeQuoteQuantums = "validator_volume_quote_quantums"

// x/revshare
RevShareType = "rev_share_type"

// x/acocuntplus
TimestampNonce = "timestamp_nonce"

Expand Down
15 changes: 15 additions & 0 deletions protocol/x/revshare/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,18 @@ type RevSharesForFill struct {
FeeSourceToRevSharePpm map[RevShareFeeSource]uint32
AllRevShares []RevShare
}

func (r RevShareType) String() string {
switch r {
case REV_SHARE_TYPE_UNSPECIFIED:
return "REV_SHARE_TYPE_UNSPECIFIED"
case REV_SHARE_TYPE_MARKET_MAPPER:
return "REV_SHARE_TYPE_MARKET_MAPPER"
case REV_SHARE_TYPE_UNCONDITIONAL:
return "REV_SHARE_TYPE_UNCONDITIONAL"
case REV_SHARE_TYPE_AFFILIATE:
return "REV_SHARE_TYPE_AFFILIATE"
default:
return "UNKNOWN"
}
}
16 changes: 15 additions & 1 deletion protocol/x/subaccounts/keeper/transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,15 @@ func (k Keeper) DistributeFees(
return err
}

// emit a metric for the amount of fees transferred to the market mapper
// Emit revenue share
metrics.AddSampleWithLabels(
metrics.RevenueShareDistribution,
metrics.GetMetricValueFromBigInt(revShare.QuoteQuantums),
metrics.GetLabelForStringValue(metrics.RevShareType, revShare.RevShareType.String()),
metrics.GetLabelForStringValue(metrics.RecipientAddress, revShare.Recipient),
)

// Old metric which is being kept for now to ensure data continuity
if revShare.RevShareType == revsharetypes.REV_SHARE_TYPE_MARKET_MAPPER {
labels := []metrics.Label{
metrics.GetLabelForIntValue(metrics.MarketId, int(perpetual.Params.MarketId)),
Expand Down Expand Up @@ -289,6 +297,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
Loading