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

test(x/perp): Include checks for the queryResp.MarginRatioIndex in 'TestOpenPositionsAndCloseCmd'. #809

Closed
2 tasks done
Unique-Divine opened this issue Aug 9, 2022 · 0 comments
Assignees

Comments

@Unique-Divine
Copy link
Member

Unique-Divine commented Aug 9, 2022

The Problem

A missing sdk.Dec field doesn't appear as a blank string; It ends up becoming zero, which can be misleading. Here's an example response from when a trader opened and then closed the position on a test chain.

{
  "block_number": 2830, 
  "margin_ratio_index": 0.0, 
  "margin_ratio_mark": 0.1, 
  "position": {
    "block_number": 2830, 
    "last_update_cumulative_premium_fraction": -174.20833333320226, 
    "margin": 1.0, 
    "open_notional": 10.0, 
    "pair": {"token0": "ubtc", "token1": "unusd"}, 
    "size": 0.000499999999999835, 
    "trader_address": "nibi1htxgm8eapmt23cmrh22lx4yy2ghfy8kkhsg8qr"},     
    "position_notional": 10.0, 
    "unrealized_pnl": 0.0
}

Notice that the margin ratio based on the index price, margin_ratio_index is zero because the test was run without a price feed.

How to Fix it - set gogoproto.nullable to true

According to the Protocol Buffer specification, you should be able to tell whether a field is set or unset. With the option nullable=false this feature is lost, since your non-nullable fields will always be set. It can be seen as a layer on top of Protocol Buffers, where before and after marshalling all non-nullable fields are set and they cannot be unset. - https://pkg.go.dev/github.com/gogo/protobuf/gogoproto

Tasks

  • Fix this
  • Test the fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant