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

Feature/fix metrics type handling #507

Merged
merged 4 commits into from
Apr 27, 2023

Conversation

taiki1frsh
Copy link
Collaborator

close issue #504

  • Removed unnecessary functions
  • Added tests for the functions named "InMetrics"
  • Added clarification comment on the files
  • Fixed num types in InMetrics functions

MarginMaintenanceRate: perpetualFuturesPosition.MarginMaintenanceRate(baseMetricsRate, quoteMetricsRate),
EffectiveMargin: sdk.NewCoin("uusd", perpetualFuturesPosition.EffectiveMarginInMetrics(baseMetricsRate, quoteMetricsRate)),
EffectiveMargin: sdk.NewCoin("uusd", types.NormalToMicroInt(perpetualFuturesPosition.EffectiveMarginInMetrics(baseMetricsRate, quoteMetricsRate))),
}, nil
}

Choose a reason for hiding this comment

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

The code patch adds comments explaining the meaning and units of the variables "InMetrics" and points out that it's not calculated in micro-case. There seem to be two improvements that can be made:

  1. Avoid using sdk.Coin directly in the MakeQueriedPositions function to reduce coupling with the Cosmos SDK; instead, create a new type for representing profit/loss and effective margin amounts.
  2. Use the types.NormalToMicroInt function to convert from normal integers to microintegers consistently for profit/loss amounts and effective margin in the Position function.

@@ -153,6 +154,7 @@ func (suite *KeeperTestSuite) TestClosePerpetualFuturesPosition() {
QuoteDenom: "uusdc",
}

// TODO: Check the returning amount to the owner
positions := []struct {
positionId string
margin sdk.Coin

Choose a reason for hiding this comment

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

Based on the code patch provided, here are some observations and suggestions:

Observations:

  • The code patch seems to be a test suite written in Golang.
  • There are two test functions, TestOpenPerpetualFuturesPosition and TestClosePerpetualFuturesPosition, which contain test cases for opening and closing of perpetual futures positions.
  • There are two newly added comments which contain TODO statements.

Suggestions:

  • The TODO statement in TestOpenPerpetualFuturesPosition suggests adding a failure case when there is a lack of available asset in the pool. It is important to add such cases as it helps ensure proper handling of edge cases and can improve the robustness of the code.
  • The TODO statement in TestClosePerpetualFuturesPosition suggests checking the returning amount to the owner. Adding this check would help ensure that the correct amount is returned to the owner after the position is closed.
  • It is recommended to perform thorough testing of the code to identify any potential bugs or issues before deployment to production.

@@ -16,6 +16,7 @@ func (suite *KeeperTestSuite) TestOpenPerpetualFuturesPosition() {
QuoteDenom: "uusdc",
}

// TODO: add failure case due to the lack of the available asset in the pool
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you implement all TODOs on this PR?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I asked @Senna46 to implement in the other branch.
So, please skip now.

t.Errorf("expected %v, got %v", tc.exp, err)
}
}
})
}
}

// TODO: impl TestRemaingMarginInMetrics
Copy link
Contributor

Choose a reason for hiding this comment

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

Could remove this since it's implemented

@taiki1frsh taiki1frsh merged commit 3704eb5 into newDevelop Apr 27, 2023
@taiki1frsh taiki1frsh deleted the feature/fix_metrics_type_handling branch April 27, 2023 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants