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: single-side liquidity provision #345

Merged

Conversation

kerber0x
Copy link
Contributor

Description and Motivation

Enables single-side liquidity provision. Closes #310

Related Issues


Checklist:

  • I have read Migaloo's contribution guidelines.
  • My pull request has a sound title and description (not something vague like Update index.md)
  • All existing and new tests are passing.
  • I updated/added relevant documentation.
  • The code is formatted properly cargo fmt --all --.
  • Clippy doesn't report any issues cargo clippy -- -D warnings.
  • I have regenerated the schemas if needed cargo schema.

Copy link

codecov bot commented Apr 26, 2024

Codecov Report

Attention: Patch coverage is 96.77996% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 90.08%. Comparing base (deebeee) to head (5f5b6a8).
Report is 4 commits behind head on release/v2_contracts.

Files Patch % Lines
...quidity_hub/pool-manager/src/liquidity/commands.rs 93.44% 8 Missing ⚠️
...ty_hub/pool-manager/src/tests/integration_tests.rs 98.92% 4 Missing ⚠️
...ontracts/liquidity_hub/pool-manager/src/helpers.rs 76.92% 3 Missing ⚠️
...ts/liquidity_hub/pool-manager/src/swap/commands.rs 77.77% 2 Missing ⚠️
...ntracts/liquidity_hub/pool-manager/src/contract.rs 95.83% 1 Missing ⚠️
Additional details and impacted files
@@                   Coverage Diff                    @@
##           release/v2_contracts     #345      +/-   ##
========================================================
+ Coverage                 89.86%   90.08%   +0.21%     
========================================================
  Files                       261      261              
  Lines                     27339    27784     +445     
========================================================
+ Hits                      24569    25029     +460     
+ Misses                     2770     2755      -15     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@0xFable 0xFable left a comment

Choose a reason for hiding this comment

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

LGTM, nice small change

@0xFable
Copy link
Contributor

0xFable commented Apr 29, 2024

I like this implementation but on second view it looks like Osmosis does do a swap before provision rather than only providing to one side.
Additionally looks like Wynd did that too.
The behaviour of single provision and only providing to one side is similar to Uniswap. Do we want maybe to add an option to do the swap?
https://medium.com/osmosis-community-updates/single-asset-lp-67fb48abce53

Copy link
Contributor

@nseguias nseguias left a comment

Choose a reason for hiding this comment

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

Looks good. Would be nice to make sure that we get the same amount of LP tokens when providing single sided liquidity VS swapping 50% of the assets in the pool and then providing liquidity in the correct ratio

@@ -98,19 +120,19 @@ pub fn provide_liquidity(

share
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

if there's no else case can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's an else case

@kerber0x
Copy link
Contributor Author

I like this implementation but on second view it looks like Osmosis does do a swap before provision rather than only providing to one side. Additionally looks like Wynd did that too. The behaviour of single provision and only providing to one side is similar to Uniswap. Do we want maybe to add an option to do the swap? https://medium.com/osmosis-community-updates/single-asset-lp-67fb48abce53

Good point. Let's explore doing it this way.

@kerber0x kerber0x added the Do not merge To be added to PRs that are waiting for something else to be completed label Apr 30, 2024
@kerber0x kerber0x force-pushed the feat/allow-single-asset-liquidity-provision branch from c87ebaa to 5b550a5 Compare May 1, 2024 09:39
Copy link

github-actions bot commented May 1, 2024

Schema generation had missing jobs:

contracts/liquidity_hub/pool-manager/schema/pool-manager.json
contracts/liquidity_hub/pool-manager/schema/raw/execute.json

Please run just schemas locally and upload the generated schemas.

@kerber0x kerber0x requested review from nseguias and 0xFable May 1, 2024 09:45
Copy link

github-actions bot commented May 1, 2024

Schema generation had missing jobs:

contracts/liquidity_hub/pool-manager/schema/pool-manager.json
contracts/liquidity_hub/pool-manager/schema/raw/execute.json

Please run just schemas locally and upload the generated schemas.

@kerber0x kerber0x removed the Do not merge To be added to PRs that are waiting for something else to be completed label May 1, 2024
@kerber0x kerber0x force-pushed the feat/allow-single-asset-liquidity-provision branch from cfaf507 to a694b5d Compare May 1, 2024 10:33
Copy link
Contributor

@0xFable 0xFable left a comment

Choose a reason for hiding this comment

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

LGTM nice job adding good coverage over it and finding the issue with fees ⭐

@@ -99,36 +103,60 @@ pub fn perform_swap(
if offer_asset.denom == pools[0].denom {
pair_info.assets[0].amount += offer_amount;
pair_info.assets[1].amount -= swap_computation.return_amount;
pair_info.assets[1].amount -= swap_computation.protocol_fee_amount;
Copy link
Contributor

Choose a reason for hiding this comment

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

Great spot on this

Copy link
Contributor

@nseguias nseguias left a comment

Choose a reason for hiding this comment

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

Nicely done, made a few general comments but it's looking good ser

ContractError::AssetMismatch {}
);

let receiver = receiver.unwrap_or_else(|| info.sender.to_string());
Copy link
Contributor

Choose a reason for hiding this comment

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

we want to validate the address is correct here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch

packages/white-whale-std/src/pool_manager.rs Show resolved Hide resolved
@kerber0x kerber0x merged commit d196218 into release/v2_contracts May 2, 2024
7 checks passed
@kerber0x kerber0x deleted the feat/allow-single-asset-liquidity-provision branch May 2, 2024 08:18
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