Skip to content

feat(usdc-pool): support partial withdrawals and cap yield rate changes - #454

Open
comandanto wants to merge 1 commit into
thisisouvik:mainfrom
comandanto:feat/usdc-pool-partial-withdrawals
Open

comandanto wants to merge 1 commit into
thisisouvik:mainfrom
comandanto:feat/usdc-pool-partial-withdrawals

Conversation

@comandanto

Copy link
Copy Markdown

Description

UsdcLendingPoolContract::withdraw could only close a depositor's whole position, and set_yield_rate let the admin change annual_yield_bps by any amount in one call. withdraw now takes an amount of principal, so a depositor can withdraw part of the position and keep the rest earning. set_yield_rate now limits a single update to 500 bps.

Related Issue

Closes #421

Motivation and Context

Liquidity providers had to exit completely to access part of their funds, and the admin could shock the yield rate with no notice.

Changes:

  • contracts/usdc_lending_pool/src/lib.rs: withdraw(env, depositor, amount). It pays amount principal plus all accrued yield. Remaining principal is stored with the current yield index, so it keeps accruing and no yield is paid twice. Full withdrawal still removes the record. Panics: "amount must be > 0", "amount exceeds deposited principal". set_yield_rate panics with "yield rate change exceeds max step" when the change is above MAX_YIELD_RATE_CHANGE_BPS (500).
  • contracts/usdc_lending_pool/src/test.rs: existing withdraw tests pass the full principal; added tests for partial withdrawal (balances, pool totals, continued accrual, backing), partial then full close, zero and over-principal amounts, and the rate step limit (max step up/down, over the step in both directions).
  • lib/contracts/usdc-lending-pool.ts: withdraw wrapper takes amountStroops.

Note: the withdraw signature change is breaking for callers of the contract ABI.

How Has This Been Tested?

Run on Windows (stable Rust, wasm32-unknown-unknown installed), from contracts/:

cargo test -p usdc_lending_pool   -> test result: ok. 39 passed; 0 failed
cargo test                        -> all crates ok, 0 failed (incl. lending 135 passed, usdc_lending_pool 39 passed)
cargo clippy -p usdc_lending_pool -- -D warnings                 -> Finished, no warnings
cargo clippy -p usdc_lending_pool --all-targets -- -D warnings   -> Finished, no warnings
cargo build --target wasm32-unknown-unknown --release            -> Finished `release` profile

cargo fmt -p usdc_lending_pool --check reports 9 diffs, the same count as on unmodified main, so they are pre-existing and I did not reformat unrelated code. I did not run the TypeScript build; the TS change is a one-line signature update of the wrapper, which has no callers in the repo.

Screenshots (if appropriate):

n/a

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change) (withdraw now requires an amount argument)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation. (n/a, behaviour is documented in the contract doc comments, which are updated)
  • I have updated the documentation accordingly. (n/a, see above)
  • I have read the CONTRIBUTING document.

Closes thisisouvik#421

withdraw now takes an amount of principal. The requested principal and all
accrued yield are paid out, the remainder stays deposited and keeps earning
from the current yield index. Withdrawing the full principal closes the
position as before.

set_yield_rate now rejects updates that move annual_yield_bps by more than
500 bps in a single call.
@vercel

vercel Bot commented Oct 25, 2026

Copy link
Copy Markdown

@comandanto is attempting to deploy a commit to the thisisouvik's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Oct 25, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e66b8e97-9533-4e0c-829e-36cb0b1f56f9
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

Support Partial Withdrawals and Yield Cap Guards in UsdcLendingPoolContract

1 participant