-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
MarginMaintenanceRate: perpetualFuturesPosition.MarginMaintenanceRate(baseMetricsRate, quoteMetricsRate), | ||
EffectiveMargin: sdk.NewCoin("uusd", perpetualFuturesPosition.EffectiveMarginInMetrics(baseMetricsRate, quoteMetricsRate)), | ||
EffectiveMargin: sdk.NewCoin("uusd", types.NormalToMicroInt(perpetualFuturesPosition.EffectiveMarginInMetrics(baseMetricsRate, quoteMetricsRate))), | ||
}, nil | ||
} | ||
|
There was a problem hiding this comment.
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:
- Avoid using
sdk.Coin
directly in theMakeQueriedPositions
function to reduce coupling with the Cosmos SDK; instead, create a new type for representing profit/loss and effective margin amounts. - Use the
types.NormalToMicroInt
function to convert from normal integers to microintegers consistently for profit/loss amounts and effective margin in thePosition
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 |
There was a problem hiding this comment.
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
andTestClosePerpetualFuturesPosition
, 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 inTestOpenPerpetualFuturesPosition
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 inTestClosePerpetualFuturesPosition
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
close issue #504