feat(cketh): act on a sweep's outcome - #11331
Conversation
1dc38bb to
d411b16
Compare
A sweep now owns the deposits it takes: they are marked taken when the request is accepted, dropped if its transaction fails (funds stay at the deposit addresses; retrying is DEFI-2981), and released once it moved them, so the pair can be armed again. A gauge reports where the queue's entries stand.
a99a713 to
f4a9467
Compare
There was a problem hiding this comment.
Pull request overview
Adds lifecycle tracking for ckERC20 sweep-queue deposits.
Changes:
- Marks deposits as in flight when assigned to a sweep.
- Removes deposits after successful or failed finalization.
- Exposes sweepable and in-flight queue metrics with tests.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
state/tests.rs |
Adds sweep lifecycle and nonce tests. |
state/automatic_deposits/tests.rs |
Tests queue ownership and outcomes. |
state/automatic_deposits/mod.rs |
Implements sweep tracking and queue depth. |
state/audit.rs |
Applies sweep lifecycle events. |
state.rs |
Handles finalized sweep outcomes. |
main.rs |
Exports sweep queue metrics. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
✅ No security or compliance issues detected. Reviewed everything up to f4a9467. Security Overview
Detected Code Changes
|
mbjorkqvist
left a comment
There was a problem hiding this comment.
Thanks @gregorydemay!
| assert_eq!( | ||
| entry.swept_by, None, | ||
| "BUG: {request:?} was already taken by another sweep" | ||
| ); |
There was a problem hiding this comment.
IIUC, this could also occur if the deposits vec named the same pair twice. Adding some validation to SweepRequest::deposits (at construction and deserialization), which is currently missing, would help. Perhaps changing the type to pub deposits: BTreeMap<(Account, Address), DepositAddress> would be enough?
| #[test] | ||
| fn should_report_a_dropped_deposit_as_unknown_rather_than_awaiting_a_sweep() { | ||
| let mut deposits = queued(); | ||
| assert_matches!(status(&deposits), Some(DepositStatus::AwaitingSweep(_))); | ||
| deposits.record_sweep_scheduled(SweepId(0), &[swept(usdc())]); | ||
|
|
||
| deposits.record_sweep_failed(SweepId(0), &[swept(usdc())]); | ||
|
|
||
| assert_eq!(status(&deposits), None); | ||
| } | ||
|
|
||
| #[test] | ||
| fn should_let_a_pair_whose_sweep_failed_be_armed_again() { | ||
| let mut deposits = queued(); | ||
| deposits.record_sweep_scheduled(SweepId(0), &[swept(usdc())]); | ||
| deposits.record_sweep_failed(SweepId(0), &[swept(usdc())]); | ||
|
|
||
| let armed = deposits.watch_deposit(ts(0), account(0), usdc(), deposit_address(&account(0))); | ||
|
|
||
| assert_matches!(armed, Ok(_)); | ||
| } |
There was a problem hiding this comment.
This currently happens rather silently, and a user may end up wondering what happened to their deposit. Would it make sense to make this visible in the minter dashboard somehow (probably not in this PR, and maybe it's already tracked somewhere)?
Why
What