Skip to content

Conversation

@mergify
Copy link
Contributor

@mergify mergify bot commented Oct 24, 2025

Changelist

Using the configured leverage for a subaccount, validate that the user has enough collateral on order placement to satisfy the scaled IMR requirements. Remember that the MMR, or liquidation level, does not change with leverage, so all that matters here is scaling the IMR to ensure that the net collateral is sufficient.

Test Plan

Added leverage_e2e_test to check a case where Alice and Bob place the exact same trade, but Alice has a lower leverage configured and thus the order placement fails at the collateral check phase.

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

    • Per‑perpetual IMF override configurable per subaccount; CLI/txs and protobufs now surface custom_imf_ppm/customImfPpm.
  • Improvements

    • Leverage/config storage and validation moved to subaccounts service and exposed via keeper APIs.
    • Margin, collateral, pricing and liquidation flows accept per‑subaccount IMF overrides (default used when unset).
    • Queries and CLI produce deterministic, ordered leverage listings; validation errors added for leverage rules.
  • Tests

    • New end‑to‑end leverage tests for configuration and order behavior.

This is an automatic backport of pull request #3141 done by [Mergify](https://mergify.com).

(cherry picked from commit d5af215)

# Conflicts:
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts
#	indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/tx.ts
#	proto/dydxprotocol/clob/query.proto
#	proto/dydxprotocol/clob/tx.proto
#	protocol/x/clob/ante/clob.go
#	protocol/x/clob/client/cli/tx_update_leverage.go
#	protocol/x/clob/e2e/app_test.go
#	protocol/x/clob/keeper/grpc_query_leverage.go
#	protocol/x/clob/keeper/leverage.go
#	protocol/x/clob/types/clob_keeper.go
#	protocol/x/clob/types/leverage.go
#	protocol/x/clob/types/query.pb.go
#	protocol/x/clob/types/tx.pb.go
@mergify mergify bot requested a review from a team as a code owner October 24, 2025 18:59
@mergify mergify bot added the conflicts label Oct 24, 2025
@mergify
Copy link
Contributor Author

mergify bot commented Oct 24, 2025

Cherry-pick of d5af215 has failed:

On branch mergify/bp/release/protocol/v9.x/pr-3141
Your branch is up to date with 'origin/release/protocol/v9.x'.

You are currently cherry-picking commit d5af215c.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	modified:   indexer/packages/v4-protos/src/codegen/dydxprotocol/bundle.ts
	new file:   indexer/packages/v4-protos/src/codegen/dydxprotocol/subaccounts/leverage.ts
	modified:   indexer/packages/v4-protos/src/codegen/gogoproto/bundle.ts
	modified:   indexer/packages/v4-protos/src/codegen/google/bundle.ts
	new file:   proto/dydxprotocol/subaccounts/leverage.proto
	modified:   protocol/daemons/liquidation/client/sub_task_runner.go
	modified:   protocol/mocks/ClobKeeper.go
	modified:   protocol/testutil/app/app.go
	modified:   protocol/testutil/keeper/listing.go
	modified:   protocol/x/clob/keeper/keeper.go
	new file:   protocol/x/clob/keeper/leverage_e2e_test.go
	modified:   protocol/x/clob/keeper/liquidations.go
	modified:   protocol/x/clob/types/expected_keepers.go
	modified:   protocol/x/perpetuals/lib/lib.go
	modified:   protocol/x/perpetuals/lib/lib_test.go
	modified:   protocol/x/perpetuals/types/liquidity_tier.go
	modified:   protocol/x/perpetuals/types/liquidity_tier_test.go
	new file:   protocol/x/subaccounts/keeper/leverage.go
	modified:   protocol/x/subaccounts/keeper/margining.go
	modified:   protocol/x/subaccounts/keeper/subaccount.go
	modified:   protocol/x/subaccounts/lib/updates.go
	modified:   protocol/x/subaccounts/lib/updates_test.go
	modified:   protocol/x/subaccounts/types/errors.go
	modified:   protocol/x/subaccounts/types/keys.go
	new file:   protocol/x/subaccounts/types/leverage.pb.go
	modified:   protocol/x/subaccounts/types/settled_update.go

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	both modified:   indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts
	both modified:   indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/tx.ts
	both modified:   proto/dydxprotocol/clob/query.proto
	both modified:   proto/dydxprotocol/clob/tx.proto
	both modified:   protocol/x/clob/ante/clob.go
	deleted by us:   protocol/x/clob/client/cli/tx_update_leverage.go
	both modified:   protocol/x/clob/e2e/app_test.go
	deleted by us:   protocol/x/clob/keeper/grpc_query_leverage.go
	deleted by us:   protocol/x/clob/keeper/leverage.go
	both modified:   protocol/x/clob/types/clob_keeper.go
	deleted by us:   protocol/x/clob/types/leverage.go
	both modified:   protocol/x/clob/types/query.pb.go
	both modified:   protocol/x/clob/types/tx.pb.go

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 24, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

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.

2 participants