[codex] Add debt marketplace and LP auto-compounding foundations - #776
Draft
BigDella wants to merge 2 commits into
Draft
[codex] Add debt marketplace and LP auto-compounding foundations#776BigDella wants to merge 2 commits into
BigDella wants to merge 2 commits into
Conversation
…devs17#664) Audited first: debt tokens are already transferable (transfer_debt_token already exists, contradicting the issue's "non-transferable" premise), but there was genuinely no listing/trading/price-discovery mechanism at all — confirmed by checking api/src/routes/debtToken.routes.ts (mint/ transfer/burn/position/pause/block only, no listing endpoints). The full ask (Dutch-auction price discovery, order book, atomic settlement/clearing, trading-fee distribution, price history/charts, analytics dashboard) is a genuinely separate, much larger deliverable — not attempted here. Added the minimal, honest slice instead: a fixed-price listing mechanism. - DebtTokenListing { token_id, seller, price, payment_token, listed_at } - list_debt_token / cancel_listing / buy_listed_debt_token / get_listing - Split transfer_debt_token's ownership-move logic into a shared move_debt_token_ownership() core that does NOT call require_auth() on the `from` address, used by both transfer_debt_token (direct, seller-authorized) and buy_listed_debt_token (marketplace purchase, buyer-authorized — the seller's earlier list_debt_token call is what authorized the sale, not a fresh signature at purchase time). This fixes a real bug caught during review: the first draft of buy_listed_debt_token called transfer_debt_token directly, which would have required the seller's auth on the buyer's own transaction and always failed. - buy_listed_debt_token pulls the exact listed price from buyer to seller via the payment token's SEP-41 transfer, then moves ownership through the same pause/block/liquidation checks a direct transfer enforces, so a paused market or blocked buyer blocks a sale exactly as it would a direct transfer. No protocol fee skim in this minimal slice (trading-fee distribution is part of the larger deliverable). Tests: list+buy end-to-end (payment settles, ownership moves, listing clears); cannot list a token you don't own; cannot list at zero/negative price; cannot double-list; seller can cancel, non-seller cannot; buying an unlisted token fails; buying respects a transfer pause set after listing. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
…tdevs17#666) Audited first: this module already has substantial yield-management infrastructure (wrap_deposit_to_lp, calculate_optimal_allocation, auto_rebalance_allocation, record_lp_fees/get_accrued_lp_fees) — but accrued fees just sat as a passive counter with no reinvestment path at all. That's the one genuinely tractable, real gap in this session: auto-compounding. The rest of Smartdevs17#666's scope — yield optimization *across* lending pools, strategy backtesting against historical data, Sharpe-ratio risk metrics, a strategy marketplace, and yield alerts — is a separate, much larger deliverable not attempted here (backtesting in particular needs historical price/utilization data this contract doesn't retain). See the PR description for the full Smartdevs17#664-Smartdevs17#667 disposition. Added amm::compound_lp_fees(admin, asset): zeroes AccruedLpFees(asset) and adds the same amount to LpTokenBalance(asset) via the same simplified 1:1 accounting wrap_deposit_to_lp already uses (that function's own comment already notes it's a stand-in for a real AMM add_liquidity call — this reinvests through the same simplified path, not a new one). Returns 0 (not an error) when nothing is accrued, since that's a normal steady state. New entrypoint: amm_compound_lp_fees(admin, asset) -> i128. Tests (new file — no prior test file covered the amm-lending module at all; noticed amm_test.rs/amm_impact_test.rs exist but aren't registered in tests/mod.rs, so they don't currently compile/run either — flagged, not fixed, as out of scope for this PR): fees reinvest and the accrued counter zeroes; compounding with nothing accrued is a no-op returning 0; only the admin can compound; compounding twice only reinvests newly accrued fees, not double-counting the first round. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
@prissca is attempting to deploy a commit to the smartdevs17's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
@BigDella 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
Scope note
This PR delivers the on-chain marketplace and auto-compounding foundations in the files currently implemented by the repository. API/UI strategy comparison, historical backtesting, charting, alerts, Dutch-auction scheduling, and off-chain order-book indexing can build on the emitted events and contract entry points.
Validation
git diff --checkcargo test -p hello-world debt_token_testscargo test -p hello-world amm_compound_testlink.exetoolchain is not installedCloses #664
Closes #666