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

v1.7.75: Add buffer and use oraclePrice to determine collateral movement #445

Conversation

jaredvu
Copy link
Contributor

@jaredvu jaredvu commented Jun 14, 2024

Description

  • AccountTransformer

    • remove calculateIsolatedMarginTransferAmount. Moved calculation for transfer amount into MarginModeCalculator
    • Utilize new getShouldTransferCollateral and calculateIsolatedMarginTranasferAmount
  • MarginModeCalculator

    • Add 4 new helper functions
    • getIsIncreasingPositionSize which is used in getShouldTransferCollateral
    • calculateIsolatedMarginTransferAmount which caps the targetLeverage to 98% of Max Leverage and returns getTransferAmountFromTargetLeverage
  • TradeInputCalculator

    • Update ISOLATED switch cases to return correct values
    • utilize getShouldTransferCollateral to determine whether to calculateIsolatedMarginTransferAmount
    • Save value to summary.isolatedMarginTransferAmount
  • TradeInput

    • add isolatedMarginTransferAmount to TradeInputSummary
  • TradingStateMachine

    • make subaccountNumber required, it should never be null
  • SubaccountSupervisor

    • Remove naive transfer amount math and read directly from trade.summary.isolatedMarginTransferAmount
  • Constants

    • add MAX_LEVERAGE_BUFFER_PERCENT
  • IsolatedMarginModeTests

    • Update test to include summary.isolatedMarginTransferAmount comparison

@jaredvu jaredvu requested review from ruixhuang and prashanDYDX June 14, 2024 22:38
Copy link

linear bot commented Jun 14, 2024

mobile-build-bot and others added 4 commits June 14, 2024 22:39
…ate-oracleprice-and' of github.com:dydxprotocol/v4-abacus into jared/tra-404-update-collateral-calculation-to-incorporate-oracleprice-and
// Cap targetLeverage to 98% of max leverage
val adjustedTargetLeverage = if (maxLeverageForMarket != null) {
val cappedLeverage = maxLeverageForMarket * MAX_LEVERAGE_BUFFER_PERCENT
if (targetLeverage > cappedLeverage) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Can simplify with min()

val initialMarginFraction = parser.asDouble(parser.value(market, "configs.initialMarginFraction"))
val effectiveImf = parser.asDouble(parser.value(market, "configs.effectiveInitialMarginFraction"))

val maxLeverageForMarket = if (effectiveImf != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Safer to check effectiveImf != 0.. Same on the next condition

@jaredvu jaredvu changed the title Add buffer and use oraclePrice to determine collateral movement v1.7.75: Add buffer and use oraclePrice to determine collateral movement Jun 14, 2024
@jaredvu jaredvu merged commit 306c4d1 into main Jun 14, 2024
4 checks passed
@jaredvu jaredvu deleted the jared/tra-404-update-collateral-calculation-to-incorporate-oracleprice-and branch June 14, 2024 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants