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

[Perpetual] net open interest was added #804

Merged
merged 7 commits into from
Sep 20, 2024
Merged

[Perpetual] net open interest was added #804

merged 7 commits into from
Sep 20, 2024

Conversation

fenriz07
Copy link
Contributor

@fenriz07 fenriz07 commented Sep 18, 2024

Net open interest was added to the next queries

  • show-pool
  • list-pool

Makefile Outdated Show resolved Hide resolved
Copy link

codecov bot commented Sep 19, 2024

Codecov Report

Attention: Patch coverage is 88.23529% with 4 lines in your changes missing coverage. Please review.

Project coverage is 42.69%. Comparing base (aa9ced8) to head (6dc4945).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #804      +/-   ##
==========================================
+ Coverage   42.63%   42.69%   +0.06%     
==========================================
  Files         672      673       +1     
  Lines       22813    22844      +31     
==========================================
+ Hits         9726     9753      +27     
- Misses      11913    11915       +2     
- Partials     1174     1176       +2     
Components Coverage Δ
leveragelp_transactions 92.63% <ø> (ø)
leveragelp_lifecycle 88.04% <ø> (ø)
leveragelp_keeper 86.58% <ø> (ø)
leveragelp_queries 19.28% <ø> (ø)
accountedpool_transactions 100.00% <ø> (ø)
accountedpool_lifecycle ∅ <ø> (∅)
accountedpool_queries 68.42% <ø> (ø)
amm_transactions 57.93% <ø> (ø)
amm_lifecycle 79.16% <ø> (ø)
amm_keeper 61.13% <ø> (ø)
amm_queries 29.94% <ø> (ø)
assetprofile_transactions 78.82% <ø> (ø)
assetprofile_lifecycle ∅ <ø> (∅)
assetprofile_keeper 83.33% <ø> (ø)
assetprofile_queries 47.41% <ø> (ø)
burner_transactions 0.00% <ø> (ø)
burner_lifecycle ∅ <ø> (∅)
burner_keeper 100.00% <ø> (ø)
burner_queries 63.54% <ø> (ø)
clock_transactions 30.00% <ø> (ø)
clock_lifecycle ∅ <ø> (∅)
clock_keeper 76.92% <ø> (ø)
clock_queries ∅ <ø> (∅)
commitment_transactions 48.83% <ø> (ø)
commitment_lifecycle ∅ <ø> (∅)
commitment_keeper 19.60% <ø> (ø)
commitment_queries 9.33% <ø> (ø)
epochs_transactions ∅ <ø> (∅)
epochs_lifecycle 100.00% <ø> (ø)
epochs_keeper 81.81% <ø> (ø)
epochs_queries 85.71% <ø> (ø)
estaking_transactions 48.64% <ø> (ø)
estaking_lifecycle 73.23% <ø> (ø)
estaking_keeper 63.05% <ø> (ø)
estaking_queries 55.31% <ø> (ø)
incentive_transactions 0.00% <ø> (ø)
incentive_lifecycle ∅ <ø> (∅)
incentive_keeper 0.00% <ø> (ø)
incentive_queries ∅ <ø> (∅)
masterchef_transactions 64.78% <ø> (ø)
masterchef_lifecycle 69.78% <ø> (ø)
masterchef_keeper 89.47% <ø> (ø)
masterchef_queries 45.97% <ø> (ø)
oracle_transactions 31.91% <ø> (ø)
oracle_lifecycle 0.00% <ø> (ø)
oracle_keeper 63.88% <ø> (ø)
oracle_queries 34.90% <ø> (ø)
parameter_transactions 15.11% <ø> (ø)
parameter_lifecycle ∅ <ø> (∅)
parameter_keeper 75.00% <ø> (ø)
parameter_queries 60.00% <ø> (ø)
stablestake_transactions 73.91% <ø> (ø)
stablestake_lifecycle 75.00% <ø> (ø)
stablestake_keeper 71.42% <ø> (ø)
stablestake_queries 13.04% <ø> (ø)
tier_transactions 28.57% <ø> (ø)
tier_lifecycle 100.00% <ø> (ø)
tier_keeper 90.47% <ø> (ø)
tier_queries 20.32% <ø> (ø)
tokenomics_transactions 72.32% <ø> (ø)
tokenomics_lifecycle ∅ <ø> (∅)
tokenomics_keeper 83.33% <ø> (ø)
tokenomics_queries 70.96% <ø> (ø)
transferhook_transactions ∅ <ø> (∅)
transferhook_lifecycle ∅ <ø> (∅)
transferhook_keeper 100.00% <ø> (ø)
transferhook_queries 60.00% <ø> (ø)
tradeshield_transactions 2.94% <ø> (ø)
tradeshield_lifecycle ∅ <ø> (∅)
tradeshield_keeper 75.00% <ø> (ø)
tradeshield_queries 1.80% <ø> (ø)

@cosmic-vagabond
Copy link
Contributor

@fenriz07 can you share a test result in comment of the updated CLI query thanks

@fenriz07
Copy link
Contributor Author

fenriz07 commented Sep 19, 2024

$ elysd q perpetual list-pool --output=json | jq

response:

{
  "pool": [
    {
      "amm_pool_id": "2",
      "health": "0.883351042402733204",
      "enabled": true,
      "closed": false,
      "borrow_interest_rate": "0.000000535466554908",
      "pool_assets_long": [
        {
          "liabilities": "3931813932907",
          "custody": "0",
          "take_profit_liabilities": "3605857570107",
          "take_profit_custody": "0",
          "asset_balance": "1062716517114",
          "block_borrow_interest": "0",
          "asset_denom": "ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65"
        },
        {
          "liabilities": "0",
          "custody": "563524739564",
          "take_profit_liabilities": "0",
          "take_profit_custody": "394720462935",
          "asset_balance": "-563584155567",
          "block_borrow_interest": "0",
          "asset_denom": "ibc/E2D2F6ADCC68AA3384B2F5DFACCA437923D137C14E86FB8A10207CF3BED0C8D4"
        }
      ],
      "pool_assets_short": [
        {
          "liabilities": "0",
          "custody": "25521549362",
          "take_profit_liabilities": "0",
          "take_profit_custody": "758800649",
          "asset_balance": "-13515873900",
          "block_borrow_interest": "0",
          "asset_denom": "ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65"
        },
        {
          "liabilities": "3173650598",
          "custody": "0",
          "take_profit_liabilities": "758578518",
          "take_profit_custody": "0",
          "asset_balance": "0",
          "block_borrow_interest": "0",
          "asset_denom": "ibc/E2D2F6ADCC68AA3384B2F5DFACCA437923D137C14E86FB8A10207CF3BED0C8D4"
        }
      ],
      "last_height_borrow_interest_rate_computed": "9865471",
      "funding_rate": "0.001000000000000000",
      "net_open_interest": "3928640282309"
    },
    {
      "amm_pool_id": "4",
      "health": "1.000010318825890871",
      "enabled": true,
      "closed": false,
      "borrow_interest_rate": "0.000000219967299502",
      "pool_assets_long": [
        {
          "liabilities": "-200000000",
          "custody": "0",
          "take_profit_liabilities": "-186115695",
          "take_profit_custody": "0",
          "asset_balance": "6781429",
          "block_borrow_interest": "0",
          "asset_denom": "ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65"
        },
        {
          "liabilities": "0",
          "custody": "0",
          "take_profit_liabilities": "0",
          "take_profit_custody": "-445632798",
          "asset_balance": "0",
          "block_borrow_interest": "0",
          "asset_denom": "ibc/B4314D0E670CB43C88A5DCA09F76E5E812BD831CC2FEC6E434C9E5A9D1F57953"
        }
      ],
      "pool_assets_short": [
        {
          "liabilities": "0",
          "custody": "0",
          "take_profit_liabilities": "0",
          "take_profit_custody": "0",
          "asset_balance": "320805",
          "block_borrow_interest": "0",
          "asset_denom": "ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65"
        },
        {
          "liabilities": "0",
          "custody": "0",
          "take_profit_liabilities": "-1",
          "take_profit_custody": "0",
          "asset_balance": "0",
          "block_borrow_interest": "0",
          "asset_denom": "ibc/B4314D0E670CB43C88A5DCA09F76E5E812BD831CC2FEC6E434C9E5A9D1F57953"
        }
      ],
      "last_height_borrow_interest_rate_computed": "9865471",
      "funding_rate": "0.000000000000000000",
      "net_open_interest": "-200000000"
    }
  ],
  "pagination": { "next_key": null, "total": "0" }
}

@fenriz07
Copy link
Contributor Author

fenriz07 commented Sep 19, 2024

elysd q perpetual show-pool 2 --output=json | jq

response:

{
  "pool": {
    "amm_pool_id": "2",
    "health": "0.883351042402733204",
    "enabled": true,
    "closed": false,
    "borrow_interest_rate": "0.000000535466554908",
    "pool_assets_long": [
      {
        "liabilities": "3931813932907",
        "custody": "0",
        "take_profit_liabilities": "3605857570107",
        "take_profit_custody": "0",
        "asset_balance": "1062716517114",
        "block_borrow_interest": "0",
        "asset_denom": "ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65"
      },
      {
        "liabilities": "0",
        "custody": "563524739564",
        "take_profit_liabilities": "0",
        "take_profit_custody": "394720462935",
        "asset_balance": "-563584155567",
        "block_borrow_interest": "0",
        "asset_denom": "ibc/E2D2F6ADCC68AA3384B2F5DFACCA437923D137C14E86FB8A10207CF3BED0C8D4"
      }
    ],
    "pool_assets_short": [
      {
        "liabilities": "0",
        "custody": "25521549362",
        "take_profit_liabilities": "0",
        "take_profit_custody": "758800649",
        "asset_balance": "-13515873900",
        "block_borrow_interest": "0",
        "asset_denom": "ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65"
      },
      {
        "liabilities": "3173650598",
        "custody": "0",
        "take_profit_liabilities": "758578518",
        "take_profit_custody": "0",
        "asset_balance": "0",
        "block_borrow_interest": "0",
        "asset_denom": "ibc/E2D2F6ADCC68AA3384B2F5DFACCA437923D137C14E86FB8A10207CF3BED0C8D4"
      }
    ],
    "last_height_borrow_interest_rate_computed": "9865494",
    "funding_rate": "0.001000000000000000",
    "net_open_interest": "3928640282309"
  }
}

@cosmic-vagabond

assetLiabilitiesShort = assetLiabilitiesShort.Add(asset.Liabilities)
}

netOpenInterest := assetLiabilitiesLong.Sub(assetLiabilitiesShort)
Copy link
Contributor

Choose a reason for hiding this comment

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

@fenriz07 there is one thing that is not right and I realized we are doing it wrong with the existing update funding rate function here https://github.com/elys-network/elys/blob/main/x/perpetual/keeper/update_funding_rate.go as well, we have to make sure that all liabilities amount that we are cumulating within assetLiabilitiesLong and assetLiabilitiesShort are using the same denom USDC if not they must be swapped to USDC the same way we do here https://github.com/elys-network/elys/blob/main/x/perpetual/keeper/keeper.go
can you update both get net open interest and update funding rate functions to reflect that? thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

this issue mentioned above will be handle as part of a separate PR, everything else looks good

@cosmic-vagabond cosmic-vagabond merged commit 2dff667 into main Sep 20, 2024
11 checks passed
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.

3 participants