Fix/lp share price mechanism#39
Merged
EmeditWeb merged 6 commits intoJun 27, 2026
Merged
Conversation
…tline integration tests - Make MockReputation stateful with storage-backed score tracking - Make MockLiquidityPool stateful with call-tracking and query functions - Add MockLiquidityPoolEmpty for insufficient-liquidity test scenario - Add helper methods to TestCtx for querying mock state - Un-ignore and implement assertions for 5 previously TODO-stubbed tests: test_loan_funding_debits_liquidity_pool test_repayment_credited_to_liquidity_pool test_guarantee_transferred_to_pool_on_default test_insufficient_liquidity_rejects_loan_creation test_multi_contract_integration_full_flow
Member
|
I'd run ci checks |
Member
|
LGTM |
9 tasks
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.
Fix liquidity pool share price mechanism with deposit/withdraw and integration tests" --body "$(cat /tmp/pr_body Closes #16
Overhauls the liquidity pool's share price mechanism so that deposit and withdrawal are priced consistently through a single
calculate_share_price_internalhelper, and wires up the creditline contract integration tests to actually verify liquidity pool and reputation interactions.Changes
Liquidity Pool Contract (
contracts/liquidity-pool-contract/src/lib.rs)deposit()- now issues shares at the current share price:shares = (amount * PRECISION) / share_price. Previously used a proportional formula that behaved differently on first vs subsequent deposits.withdraw()- now returns tokens using the share price:amount = (shares * share_price) / PRECISION. Previously usedshares * total_liquidity / total_shares.calculate_withdrawal()- updated to use share price; returns 0 whenshares == 0.calculate_share_price_internal()- extracted shared logic into a single helper:total_liquidity * PRECISION / total_shares. ReturnsPRECISION(1.0) when pool is empty.get_share_price()- new public query function.accumulate_interest()- new public function callingdistribute_interest_internal, making yield accrual explicit for LPs.get_pool_stats()- delegates to the shared helper instead of duplicating the formula.Types (
contracts/liquidity-pool-contract/src/types.rs)SHARE_PRICE_PRECISION = 10_000constant, replacing inline uses ofTOTAL_BPSfor share price math.Integration Tests (
contracts/creditline-contract/src/tests.rs)fund_loan,receive_repayment,receive_guaranteewith assertion helpers.lp_id/rep_id(was_lp_id/_rep_id); adds 6 helper methods for mock state.#[ignore]):test_loan_funding_debits_liquidity_pooltest_repayment_credited_to_liquidity_pooltest_guarantee_transferred_to_pool_on_defaulttest_insufficient_liquidity_rejects_loan_creationtest_multi_contract_integration_full_flow