feat(hook): add useLiquidityPool and useLiquidityPoolActions - #260
Merged
Conversation
Adds new hooks for native AMM liquidity pool interactions. Updates the Asset union to include 'liquidity_pool_shares', removing the need for forced type casts and lint suppressions in parseHorizonBalance. Updates the useBalance selector to correctly match LP positions. Exports isNativeAsset, isIssuedAsset, and isLiquidityPoolShares type guards. Includes comprehensive tests with mocked adapters and updates to the documentation and CHANGELOG.
|
@johdanike Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🎯 Summary
Introduces support for Stellar's native AMM liquidity pools by adding the
useLiquidityPoolanduseLiquidityPoolActionshooks. This PR also resolves a foundational type-level bug by formally introducing"liquidity_pool_shares"to theAssetunion, allowing the library to accurately track and expose LP balances.📋 Technical Scope & Changes
"liquidity_pool_shares"to theAssetunion. Removed theas anyandas Balanceforced casts inparseHorizonBalancealong with their lint suppressions.isNativeAsset,isIssuedAsset, and a newly createdisLiquidityPoolSharesguard from the main entry point to allow consumers to narrow theBalanceunion.useBalanceUpdate: Added a third branch to the selector so it can successfully match and return LP positions.useLiquidityPool: Fetchesreserves,total_shares,fee_bp, andtotal_trustlines.useLiquidityPoolActions: Implementsdepositandwithdrawflows.depositstrictly requiresminPriceandmaxPrice, whilewithdrawstrictly requiresminAmountAandminAmountB. Omitting these boundaries is rejected (no defaults) to ensure strict slippage protection. No float arithmetic is used for prices/reserves.res.successful.docs/hooks/use-liquidity-pool.md(which notes theuseAddTrustlineprerequisite) and updateddocs/reference/types.mdandCHANGELOG.md.serverMockandadapterMockon the testnet.✅ Acceptance Criteria
Assetunion includes"liquidity_pool_shares"as anycast and lint suppression atutils/index.tsare goneuseBalancecan select and return an LP share balanceisNativeAsset,isIssuedAsset, andisLiquidityPoolSharesare exporteduseLiquidityPoolreturns reserves, total shares, and feestatusderived fromres.successfulCHANGELOG.mdanddocs/reference/types.mdupdatedpnpm test,pnpm lint,pnpm typecheck, andpnpm buildall pass locallyCloses #199