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

feat: add dynamic leverage #755

Merged
merged 22 commits into from
Sep 11, 2024
Merged

feat: add dynamic leverage #755

merged 22 commits into from
Sep 11, 2024

Conversation

cryptokage1996
Copy link
Contributor

@cryptokage1996 cryptokage1996 commented Aug 27, 2024

Enable users to adjust the leverage of an existing position when adding new collateral, allowing for flexibility in leverage management and improving user experience.

What has Changed?

  • previously user have no option to add collateral with different leverage for an open position, now user can specify different leverage value to open a consolidate position
  • add collateral flow is removed. if a user want to add more collateral to improve position health, user need to open consolidate position with leverage=1

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 43.31%. Comparing base (3361791) to head (6b4afe9).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #755      +/-   ##
==========================================
- Coverage   43.53%   43.31%   -0.23%     
==========================================
  Files         652      650       -2     
  Lines       21622    21570      -52     
==========================================
- Hits         9414     9342      -72     
- Misses      11090    11114      +24     
+ Partials     1118     1114       -4     
Components Coverage Δ
leveragelp_transactions 92.63% <ø> (-0.51%) ⬇️
leveragelp_lifecycle 88.04% <ø> (-0.26%) ⬇️
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 62.12% <ø> (ø)
masterchef_lifecycle 73.50% <ø> (ø)
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% <ø> (ø)

@cryptokage1996 cryptokage1996 marked this pull request as ready for review August 29, 2024 12:44
Copy link
Contributor

@amityadav0 amityadav0 left a comment

Choose a reason for hiding this comment

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

  1. Tests are failing
  2. Also we need to add validations in tests to verify if dynamic lev is working fine

x/leveragelp/keeper/position_open.go Show resolved Hide resolved
x/leveragelp/keeper/msg_server_open.go Show resolved Hide resolved
x/leveragelp/keeper/position_open.go Outdated Show resolved Hide resolved
x/leveragelp/types/position.go Show resolved Hide resolved
@cryptokage1996
Copy link
Contributor Author

cryptokage1996 commented Sep 2, 2024

  1. Tests are failing
  2. Also we need to add validations in tests to verify if dynamic lev is working fine

tests are updated already with different leverage for the same position , and also add collateral where lev = 1

@cosmic-vagabond
Copy link
Contributor

@cryptokage1996 updated_leverage value returns 1.0 for any positions:

$ elysd q leveragelp get-positions --limit 10 --reverse
pagination:
  next_key: FP//IHSVyrNtMx3LU/piXxdnFF2UAAAAAAAAPZM=
  total: "0"
positions:
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "4"
    collateral:
      amount: "194200"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "234539"
    leveraged_lp_amount: "324406279695491059"
    liabilities: "0"
    position_health: "10.990820512820512821"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "2"
    collateral:
      amount: "214900"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "215911"
    leveraged_lp_amount: "320336627582651552"
    liabilities: "0"
    position_health: "10.760012964763624577"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "5"
    collateral:
      amount: "91000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "129800"
    leveraged_lp_amount: "78157517208674003"
    liabilities: "0"
    position_health: "9.596347331583552056"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1lllj0q7a0d4hqg0dt7umjtcnfg9lk9x2xswh2m
    amm_pool_id: "2"
    collateral:
      amount: "52000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "99670"
    leveraged_lp_amount: "115987101305482367"
    liabilities: "0"
    position_health: "2.305073631867981749"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1lllj0q7a0d4hqg0dt7umjtcnfg9lk9x2xswh2m
    amm_pool_id: "4"
    collateral:
      amount: "117000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "83220"
    leveraged_lp_amount: "195983847012251436"
    liabilities: "0"
    position_health: "11.035207075431584318"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1lllj0q7a0d4hqg0dt7umjtcnfg9lk9x2xswh2m
    amm_pool_id: "5"
    collateral:
      amount: "2055000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "64217"
    leveraged_lp_amount: "2352907888468956596"
    liabilities: "0"
    position_health: "3.212467868491487409"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "6"
    collateral:
      amount: "600000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "60527"
    leveraged_lp_amount: "1035910779989163168"
    liabilities: "0"
    position_health: "2.400275960509099560"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "5"
    collateral:
      amount: "2000000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "55803"
    leveraged_lp_amount: "2393026781554085971"
    liabilities: "0"
    position_health: "2.665938528139388980"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "2"
    collateral:
      amount: "500000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "47412"
    leveraged_lp_amount: "1395963869360031133"
    liabilities: "0"
    position_health: "1.767783076923076923"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "4"
    collateral:
      amount: "6220000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "42059"
    leveraged_lp_amount: "15742474232626436335"
    liabilities: "0"
    position_health: "2.370525779492168703"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"

@cryptokage1996
Copy link
Contributor Author

cryptokage1996 commented Sep 3, 2024

@cryptokage1996 updated_leverage value returns 1.0 for any positions:

$ elysd q leveragelp get-positions --limit 10 --reverse
pagination:
  next_key: FP//IHSVyrNtMx3LU/piXxdnFF2UAAAAAAAAPZM=
  total: "0"
positions:
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "4"
    collateral:
      amount: "194200"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "234539"
    leveraged_lp_amount: "324406279695491059"
    liabilities: "0"
    position_health: "10.990820512820512821"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "2"
    collateral:
      amount: "214900"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "215911"
    leveraged_lp_amount: "320336627582651552"
    liabilities: "0"
    position_health: "10.760012964763624577"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "5"
    collateral:
      amount: "91000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "129800"
    leveraged_lp_amount: "78157517208674003"
    liabilities: "0"
    position_health: "9.596347331583552056"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1lllj0q7a0d4hqg0dt7umjtcnfg9lk9x2xswh2m
    amm_pool_id: "2"
    collateral:
      amount: "52000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "99670"
    leveraged_lp_amount: "115987101305482367"
    liabilities: "0"
    position_health: "2.305073631867981749"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1lllj0q7a0d4hqg0dt7umjtcnfg9lk9x2xswh2m
    amm_pool_id: "4"
    collateral:
      amount: "117000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "83220"
    leveraged_lp_amount: "195983847012251436"
    liabilities: "0"
    position_health: "11.035207075431584318"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1lllj0q7a0d4hqg0dt7umjtcnfg9lk9x2xswh2m
    amm_pool_id: "5"
    collateral:
      amount: "2055000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "64217"
    leveraged_lp_amount: "2352907888468956596"
    liabilities: "0"
    position_health: "3.212467868491487409"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "6"
    collateral:
      amount: "600000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "60527"
    leveraged_lp_amount: "1035910779989163168"
    liabilities: "0"
    position_health: "2.400275960509099560"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "5"
    collateral:
      amount: "2000000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "55803"
    leveraged_lp_amount: "2393026781554085971"
    liabilities: "0"
    position_health: "2.665938528139388980"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "2"
    collateral:
      amount: "500000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "47412"
    leveraged_lp_amount: "1395963869360031133"
    liabilities: "0"
    position_health: "1.767783076923076923"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "4"
    collateral:
      amount: "6220000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "42059"
    leveraged_lp_amount: "15742474232626436335"
    liabilities: "0"
    position_health: "2.370525779492168703"
    stop_loss_price: "0.000000000000000000"
  updated_leverage: "1.000000000000000000"

@cosmic-vagabond this will be fixed after #758 is merged refrence

@cosmic-vagabond
Copy link
Contributor

@cryptokage1996 ran another test and the updated_leveragelp field still returned 1.0 and the liabilities field is at 0

the stablestake module data are part of the localnet snapshot now:

$ elysd q stablestake params
params:
  deposit_denom: uusdc
  epoch_length: "1000"
  health_gain_factor: "1.000000000000000000"
  interest_rate: "0.142569539564666733"
  interest_rate_decrease: "0.010000000000000000"
  interest_rate_increase: "0.010000000000000000"
  interest_rate_max: "0.170000000000000000"
  interest_rate_min: "0.120000000000000000"
  redemption_rate: "1.000000000000000000"
  total_value: "5903011403801"
- position:
    address: elys1llljqay4e2ek6vcaedfl5cjlzan3ghv597l59z
    amm_pool_id: "4"
    collateral:
      amount: "6220000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "42059"
    leveraged_lp_amount: "15742474232626436335"
    liabilities: "0"
    position_health: "2.370525779492168703"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "10388074"
  updated_leverage: "1.000000000000000000"

cc @amityadav0

@cosmic-vagabond
Copy link
Contributor

@cryptokage1996 please have a look at the latest test result using the stablestake module data:

pagination:
  next_key: FP//J4Pde2twIe1fubkvE0oL+xTKAAAAAAABhVY=
  total: "0"
positions:
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "4"
    collateral:
      amount: "194200"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "234539"
    leveraged_lp_amount: "324406279695491059"
    liabilities: "20499382"
    position_health: "0.010442656271296374"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "0.214068000000000000"
  updated_leverage: "0.000000000000000000"
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "2"
    collateral:
      amount: "214900"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "215911"
    leveraged_lp_amount: "320336627582651552"
    liabilities: "22684460"
    position_health: "0.010266896368703509"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "0.232899000000000000"
  updated_leverage: "0.000000000000000000"
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "5"
    collateral:
      amount: "91000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "129800"
    leveraged_lp_amount: "78157517208674003"
    liabilities: "9605796"
    position_health: "0.009082953666723716"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "0.087249000000000000"
  updated_leverage: "0.000000000000000000"

this time over, we can see the liabilities values are on, but for all the positions I tested on the updated_leverage value sticks to zero

@cryptokage1996
Copy link
Contributor Author

cryptokage1996 commented Sep 9, 2024

@cryptokage1996 please have a look at the latest test result using the stablestake module data:

pagination:
  next_key: FP//J4Pde2twIe1fubkvE0oL+xTKAAAAAAABhVY=
  total: "0"
positions:
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "4"
    collateral:
      amount: "194200"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "234539"
    leveraged_lp_amount: "324406279695491059"
    liabilities: "20499382"
    position_health: "0.010442656271296374"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "0.214068000000000000"
  updated_leverage: "0.000000000000000000"
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "2"
    collateral:
      amount: "214900"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "215911"
    leveraged_lp_amount: "320336627582651552"
    liabilities: "22684460"
    position_health: "0.010266896368703509"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "0.232899000000000000"
  updated_leverage: "0.000000000000000000"
- position:
    address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z
    amm_pool_id: "5"
    collateral:
      amount: "91000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "129800"
    leveraged_lp_amount: "78157517208674003"
    liabilities: "9605796"
    position_health: "0.009082953666723716"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "0.087249000000000000"
  updated_leverage: "0.000000000000000000"

this time over, we can see the liabilities values are on, but for all the positions I tested on the updated_leverage value sticks to zero

@cosmic-vagabond ,

if you look closely into the response for any position

for eg lets pick a position with address elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z (last position)

if you see there position health

- position: address: elys1llll3p0zvykqhxtqhlfw4qu6p9llrxrgskhx0z amm_pool_id: "5" collateral: amount: "91000" denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65 id: "129800" leveraged_lp_amount: "78157517208674003" liabilities: "9605796" position_health: "0.009082953666723716" stop_loss_price: "0.000000000000000000" position_usd_value: "0.087249000000000000" updated_leverage: "0.000000000000000000"

position health is calculated = exitAmountAfterFee / Liabilities

So, position health is less than 1. which means Liabilities > exitAmountAfterFee.

updated leverage = exitAmountAfterFee / (exitAmountAfterFee - liabilities)

(exitAmountAfterFee - liabilities) is negative.

if (exitAmountAfterFee - liabilities) is not positive we will set updated_leverage as zero.

@cosmic-vagabond
Copy link
Contributor

@cryptokage1996 you are right those are zombi positions, I wonder though why the bot did not liquidate them cc @amityadav0 @fenriz07

@cryptokage1996 I created a new position and queried it and now I can see a positive value for updated_leverage:

$ elysd q leveragelp get-position elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg 267440
locked_lp_token: "684995039043291093975"
position:
  position:
    address: elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg
    amm_pool_id: "2"
    collateral:
      amount: "100000000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "267440"
    leveraged_lp_amount: "684995039043291093975"
    liabilities: "419599731"
    position_health: "1.186897798559360850"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "498.021997000000000000"
  updated_leverage: "6.350517810847240757"

this is the command I used for created the position:

elysd tx leveragelp open 5 ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65 100000000 2 0 --from validator --fees 1000000uelys --gas auto -y

So I wonder why even though the position was created with a 5x leverage we ends up with a 6.35x leverage, there was no price movement at all and the position size is about 500usdc it should cause too much slippage neither.

@cosmic-vagabond
Copy link
Contributor

@cryptokage1996 ’s test results:

locked_lp_token: "684995039043291093975"
position:
  position:
    address: elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg
    amm_pool_id: "2"
    collateral:
      amount: "100000000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "267440"
    leveraged_lp_amount: "684995039043291093975"
    liabilities: "400024194"
    position_health: "1.244979689903456189"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "498.021997000000000000"
  updated_leverage: "5.081971041738558159"

consolidation:

locked_lp_token: "822062343926682604879"
position:
  position:
    address: elys1g3qnq7apxv964cqj0hza0pnwsw3q920lcc5lyg
    amm_pool_id: "2"
    collateral:
      amount: "110010000"
      denom: ibc/2180E84E20F5679FCC760D8C165B60F42065DEF7F46A72B447CFF1B7DC6C0A65
    id: "267440"
    leveraged_lp_amount: "822062343926682604879"
    liabilities: "490065776"
    position_health: "1.219583540149108474"
    stop_loss_price: "0.000000000000000000"
  position_usd_value: "597.676154000000000000"
  updated_leverage: "5.55407540711361500

@cosmic-vagabond cosmic-vagabond merged commit b5a0597 into main Sep 11, 2024
68 of 71 checks passed
@cosmic-vagabond cosmic-vagabond deleted the feat/dynamic-leverage branch September 11, 2024 13: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.

3 participants