Skip to content

Feat/deepbook#1

Merged
funkiirabu merged 4 commits into
mainfrom
feat/deepbook
Jan 25, 2026
Merged

Feat/deepbook#1
funkiirabu merged 4 commits into
mainfrom
feat/deepbook

Conversation

@funkiirabu
Copy link
Copy Markdown
Member

@funkiirabu funkiirabu commented Jan 25, 2026

Note

Deferred future work

  • Marks DeepBook integration and Marketplace v2 (Bid System) as ⏸️ deferred across README.md, LOANS.md, MARKETPLACE.md, PLAN.md, and spec/tide-core-v1.md
  • Adds/updates spec/deepbook-integration-v1.md with a simplified 3-phase roadmap (rates + liquidity via BalanceManager, flash liquidations (keep only), DEEP rewards) and removal/deferment of complex features
  • Adds spec/marketplace-v2.md as deferred reference; updates links/status labels in related docs

Current v1 stance

  • Reaffirms treasury-funded loans, fixed 5% APR, standard liquidations; documents clear criteria to revisit DeepBook (≥50% utilization, 3+ issuers, demand for dynamic rates)

Scope

  • Documentation/spec-only changes; no contract code changes

Written by Cursor Bugbot for commit 82f65f9. This will update automatically on new commits. Configure here.

@funkiirabu funkiirabu merged commit 9a1b411 into main Jan 25, 2026
2 checks passed
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 5 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

This PR is being reviewed by Cursor Bugbot

Details

You are on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle.

To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.

│ │ loan_vault::liquidate(vault, loan_id, borrowed_sui) │ │
│ │ → Returns: SupporterPass │ │
│ └────────────────────────────┬────────────────────────────────────┘ │
│ │ │
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Duplicate error code values make debugging ambiguous

Medium Severity

EInsufficientLiquidity and EInsufficientProceeds are both assigned the value 3. When an error occurs, it will be impossible to distinguish between these two different failure conditions, making debugging difficult and potentially causing incorrect error handling in callers.

Fix in Cursor Fix in Web

Advanced integration allowing SupporterPass collateral to enable margin trading on DeepBook.

**Warning:** This is high-complexity and should only be considered after Phases 1-4 are stable.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

DEEP rewards can be claimed multiple times

High Severity

The claim_deep function lacks any mechanism to track whether a pass has already claimed for the current distribution round. A user could call this function repeatedly with the same SupporterPass to drain the entire DEEP pool. The DeepRewardsPool struct has no field tracking claims, and the function doesn't update any state to prevent re-claiming.

Additional Locations (1)

Fix in Cursor Fix in Web

let amount = coin.value();
balance_manager::deposit(balance_manager, coin);
pool.outstanding = pool.outstanding - amount;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Repay function accounting mismatch causes underflow

Medium Severity

The repay function subtracts the full repayment amount from pool.outstanding, but outstanding only tracks principal (incremented by borrowed amount in borrow). Since loans accrue interest via get_rate(), repayments include principal plus interest. This asymmetry causes pool.outstanding to underflow when total repayments exceed total principal borrowed.

Additional Locations (1)

Fix in Cursor Fix in Web

assert!(
vault.deepbook_exposure() + amount <= vault.bridge_config.max_deepbook_exposure,
EExceedsMaxExposure,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No validation that balance_manager matches the pool

High Severity

The TideLendingPool stores balance_manager_id to track its associated BalanceManager, but deposit_liquidity, withdraw_liquidity, borrow, and repay all accept balance_manager as a separate parameter without validating that object::id(balance_manager) == pool.balance_manager_id. A caller could pass a mismatched balance manager, causing funds to flow to/from the wrong account while the pool's accounting is updated incorrectly.

Additional Locations (2)

Fix in Cursor Fix in Web

coin::from_balance(deep, ctx)
pool.distribution_amount = amount;
pool.snapshot_epoch = ctx.epoch();
pool.snapshot_total_shares = capital_vault.total_shares();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Division by zero when total shares is zero

Medium Severity

The start_distribution function sets snapshot_total_shares from capital_vault.total_shares() without checking if it's zero. If called when there are no backers, claim_deep will crash with a division by zero when computing share_bps = (pass.shares * 10000) / pool.snapshot_total_shares.

Additional Locations (1)

Fix in Cursor Fix in Web

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.

1 participant