Skip to content

Conversation

@jusbar23
Copy link
Contributor

@jusbar23 jusbar23 commented Oct 2, 2025

Changelist

  • Don't attribute any more revenue if user has exceeded the 30d cap
  • Use the new 30d affiliate volume window to calculate tier
  • Interpret overrides as being the highest tier

Test Plan

  • Unit tests

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Summary by CodeRabbit

  • New Features

    • Affiliate info now includes 30-day rolling referred volume.
    • Fees respect a referee minimum fee tier override from affiliate parameters.
    • Enforced 30-day caps on affiliate revenue/volume attribution per referred user.
    • Affiliate parameters are included in genesis and exposed via queries.
  • Chores

    • Renamed affiliate parameter fields to quote-quantum terminology across APIs and schemas; updated testnet defaults.
    • Updated protobufs and indexer codegen to match new fields.
    • Revised affiliate-parameters CLI script: new args/defaults and payload keys.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
protocol/x/affiliates/keeper/grpc_query_test.go (1)

78-83: Inconsistent 1e18 scaling in delegation amount (may cause flaky expectations later)

In Success you scale by 1e18; here you don’t. It’s benign now (tier-0 is 0) but will break if requirements change.

Apply for consistency:

-                err := stakingKeeper.SetDelegation(ctx,
-                    stakingtypes.NewDelegation(constants.AliceAccAddress.String(),
-                        constants.AliceValAddress.String(), math.LegacyNewDecFromBigInt(
-                            big.NewInt(int64(types.DefaultAffiliateTiers.Tiers[0].ReqStakedWholeCoins)),
-                        ),
-                    ),
-                )
+                err := stakingKeeper.SetDelegation(ctx,
+                    stakingtypes.NewDelegation(constants.AliceAccAddress.String(),
+                        constants.AliceValAddress.String(), math.LegacyNewDecFromBigInt(
+                            new(big.Int).Mul(
+                                big.NewInt(int64(types.DefaultAffiliateTiers.Tiers[0].ReqStakedWholeCoins)),
+                                big.NewInt(1e18),
+                            ),
+                        ),
+                    ),
+                )
🧹 Nitpick comments (2)
protocol/x/affiliates/keeper/keeper_test.go (1)

668-669: Consider simplifying the test structure or adding multi-affiliate test cases.

The test structure now uses expectedReferrer and expectedAttributedVolume arrays to support multiple referrers, but all test cases only verify a single affiliate. This suggests either:

  1. The array structure is over-engineered for the current test cases and could be simplified to single values, or
  2. Additional test cases covering multiple distinct affiliates would better justify the array-based approach.

If the intent is to test scenarios where fills involve multiple different affiliates (not just multiple referees under one affiliate), consider adding such test cases to validate the per-referrer aggregation logic more thoroughly.

Also applies to: 1062-1067

protocol/x/affiliates/keeper/grpc_query_test.go (1)

107-111: Avoid hard-coding last-tier index and fee share; derive from DefaultAffiliateTiers

Prevents breakage if tiers change.

-                Tier:                      4,
-                FeeSharePpm:               250_000,
+                Tier:                      uint32(len(types.DefaultAffiliateTiers.Tiers) - 1),
+                FeeSharePpm:               types.DefaultAffiliateTiers.Tiers[len(types.DefaultAffiliateTiers.Tiers)-1].TakerFeeSharePpm,

Optional: rename this case from "Whitelisted" to "Overrides" for clarity.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c8255c1 and 10eb146.

📒 Files selected for processing (2)
  • protocol/x/affiliates/keeper/grpc_query_test.go (3 hunks)
  • protocol/x/affiliates/keeper/keeper_test.go (16 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
protocol/x/affiliates/keeper/keeper_test.go (7)
indexer/packages/v4-protos/src/codegen/dydxprotocol/affiliates/tx.ts (2)
  • MsgUpdateAffiliateParameters (78-84)
  • MsgUpdateAffiliateParameters (399-445)
indexer/packages/v4-protos/src/codegen/dydxprotocol/affiliates/affiliates.ts (2)
  • AffiliateParameters (79-94)
  • AffiliateParameters (350-405)
protocol/x/affiliates/types/affiliates.pb.go (3)
  • AffiliateParameters (241-250)
  • AffiliateParameters (254-254)
  • AffiliateParameters (255-257)
protocol/x/affiliates/types/expected_keepers.go (1)
  • StatsKeeper (10-15)
indexer/packages/v4-protos/src/codegen/dydxprotocol/stats/stats.ts (2)
  • UserStats (125-137)
  • UserStats (510-574)
protocol/x/stats/types/stats.pb.go (3)
  • UserStats (356-365)
  • UserStats (369-369)
  • UserStats (370-372)
protocol/x/affiliates/keeper/keeper.go (1)
  • Keeper (20-27)
protocol/x/affiliates/keeper/grpc_query_test.go (2)
protocol/x/affiliates/types/constants.go (1)
  • DefaultAffiliateTiers (4-32)
protocol/dtypes/serializable_int.go (1)
  • NewIntFromUint64 (36-40)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (36)
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-socks / (socks) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-vulcan / (vulcan) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-roundtable / (roundtable) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-comlink / (comlink) Build and Push
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-bazooka-lambda / (bazooka) Build and Push Lambda
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-auxo-lambda / (auxo) Build and Push Lambda
  • GitHub Check: (Public Testnet) Build and Push ECS Services / call-build-and-push-ecs-service-ender / (ender) Build and Push
  • GitHub Check: call-build-ecs-service-socks / (socks) Check docker image build
  • GitHub Check: call-build-ecs-service-vulcan / (vulcan) Check docker image build
  • GitHub Check: call-build-ecs-service-roundtable / (roundtable) Check docker image build
  • GitHub Check: call-build-ecs-service-ender / (ender) Check docker image build
  • GitHub Check: call-build-ecs-service-comlink / (comlink) Check docker image build
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-auxo-lambda / (auxo) Build and Push Lambda
  • GitHub Check: check-build-auxo
  • GitHub Check: check-build-bazooka
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-vulcan / (vulcan) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-roundtable / (roundtable) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-bazooka-lambda / (bazooka) Build and Push Lambda
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-comlink / (comlink) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-socks / (socks) Build and Push
  • GitHub Check: (Mainnet) Build and Push ECS Services / call-build-and-push-ecs-service-ender / (ender) Build and Push
  • GitHub Check: test / run_command
  • GitHub Check: test-coverage-upload
  • GitHub Check: test-race
  • GitHub Check: unit-end-to-end-and-integration
  • GitHub Check: liveness-test
  • GitHub Check: build-and-push-mainnet
  • GitHub Check: container-tests
  • GitHub Check: build
  • GitHub Check: golangci-lint
  • GitHub Check: build-and-push-testnet
  • GitHub Check: check-sample-pregenesis-up-to-date
  • GitHub Check: benchmark
  • GitHub Check: run_command
  • GitHub Check: Analyze (go)
  • GitHub Check: Summary
🔇 Additional comments (9)
protocol/x/affiliates/keeper/keeper_test.go (7)

142-147: LGTM!

The addition of UpdateAffiliateParameters correctly initializes the 30-day attributable volume cap before testing affiliate behavior.


173-177: LGTM!

The migration to StatsKeeper.SetUserStats correctly sets up the affiliate's referred volume to exceed the tier threshold, enabling proper tier progression testing.


270-274: LGTM!

Correctly uses StatsKeeper.SetUserStats to pre-populate affiliate referred volume at the tier 2 threshold for testing tier qualification logic.


703-709: LGTM!

The consistent use of StatsKeeper.SetUserStats to pre-initialize affiliate volumes before testing aggregation logic correctly simulates existing 30-day rolling window state. The comments clearly explain the test scenarios involving volume caps.

Also applies to: 738-745, 820-827, 869-876, 929-935, 994-999


1096-1106: LGTM!

The assertions correctly validate the renamed parameter fields using the updated getter methods that align with the quote-quantum nomenclature from the protobuf definitions.


1-1108: Well-structured migration to StatsKeeper-driven state management.

The test file successfully migrates from direct state mutations to StatsKeeper-driven setup, which provides better alignment with the actual system behavior where stats drive affiliate state transitions. The field naming updates consistently reflect the shift from notional/revenue to quote-quantum nomenclature across all test cases.

The enhanced test structure with per-referrer tracking arrays provides good extensibility, though most cases currently only test single-affiliate scenarios.


808-852: Cannot run test due to build errors – please verify fill totals vs. expectedVolume
Two fills of 100 000 000 000 each sum to 200 000 000 000, but expectedVolume is 300 000 000 000. Run the test locally (TestAggregateAffiliateReferredVolumeForFills/2_referrals,_takers_not_referred,_maker_referred) to confirm whether expectedVolume should be 200 000 000 000 or a fill notional updated.

protocol/x/affiliates/keeper/grpc_query_test.go (2)

32-40: Switch to ReferredVolume_30DRolling looks correct

Using dtypes.NewIntFromUint64 and the 30D metric aligns with the keeper changes. Expected 0 baseline matches DefaultAffiliateTiers.Tiers[0].


66-74: LGTM on updated expectations

ReferredVolume_30DRolling and SerializableInt usage are consistent with the new 30D window.

@jusbar23 jusbar23 merged commit 1b53602 into main Oct 10, 2025
54 of 55 checks passed
@jusbar23 jusbar23 deleted the add_user_stats branch October 10, 2025 17:55
@coderabbitai coderabbitai bot mentioned this pull request Oct 10, 2025
6 tasks
@jusbar23
Copy link
Contributor Author

https://github.com/Mergifyio backport release/protocol/v9.x
https://github.com/Mergifyio backport release/indexer/v9.x

@mergify
Copy link
Contributor

mergify bot commented Oct 22, 2025

backport release/protocol/v9.x

✅ Backports have been created

@jusbar23
Copy link
Contributor Author

https://github.com/Mergifyio backport release/indexer/v9.x

@mergify
Copy link
Contributor

mergify bot commented Oct 22, 2025

backport release/indexer/v9.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Oct 22, 2025
(cherry picked from commit 1b53602)

# Conflicts:
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/affiliates/affiliates.ts
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/stats/stats.ts
#	proto/dydxprotocol/affiliates/affiliates.proto
#	proto/dydxprotocol/stats/stats.proto
#	protocol/scripts/affiliates/update_affiliate_parameters.py
#	protocol/scripts/genesis/sample_pregenesis.json
#	protocol/testing/testnet/genesis.json
#	protocol/x/affiliates/keeper/grpc_query_test.go
#	protocol/x/affiliates/keeper/keeper.go
#	protocol/x/affiliates/keeper/keeper_test.go
#	protocol/x/affiliates/types/affiliates.pb.go
#	protocol/x/affiliates/types/constants.go
#	protocol/x/affiliates/types/expected_keepers.go
#	protocol/x/affiliates/types/keys.go
#	protocol/x/affiliates/types/query.pb.go
#	protocol/x/revshare/keeper/revshare.go
#	protocol/x/revshare/keeper/revshare_test.go
#	protocol/x/stats/keeper/keeper.go
#	protocol/x/stats/types/stats.pb.go
mergify bot pushed a commit that referenced this pull request Oct 22, 2025
(cherry picked from commit 1b53602)

# Conflicts:
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/affiliates/affiliates.ts
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/stats/stats.ts
#	proto/dydxprotocol/affiliates/affiliates.proto
#	proto/dydxprotocol/stats/stats.proto
#	protocol/scripts/affiliates/update_affiliate_parameters.py
#	protocol/scripts/genesis/sample_pregenesis.json
#	protocol/testing/testnet/genesis.json
#	protocol/x/affiliates/keeper/grpc_query_test.go
#	protocol/x/affiliates/keeper/keeper.go
#	protocol/x/affiliates/keeper/keeper_test.go
#	protocol/x/affiliates/types/affiliates.pb.go
#	protocol/x/affiliates/types/constants.go
#	protocol/x/affiliates/types/expected_keepers.go
#	protocol/x/affiliates/types/keys.go
#	protocol/x/affiliates/types/query.pb.go
#	protocol/x/revshare/keeper/revshare.go
#	protocol/x/revshare/keeper/revshare_test.go
#	protocol/x/stats/keeper/keeper.go
#	protocol/x/stats/types/stats.pb.go
@jusbar23
Copy link
Contributor Author

https://github.com/Mergifyio backport release/protocol/v9.x

@mergify
Copy link
Contributor

mergify bot commented Oct 23, 2025

backport release/protocol/v9.x

✅ Backports have been created

@jusbar23
Copy link
Contributor Author

https://github.com/Mergifyio backport release/indexer/v9.x

@mergify
Copy link
Contributor

mergify bot commented Oct 23, 2025

backport release/indexer/v9.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants