Skip to content

refactor: extract shared deposit validation from manual flow#174

Open
lpahlavi wants to merge 1 commit intomainfrom
lpahlavi/defi-2780-extract-deposit-validation
Open

refactor: extract shared deposit validation from manual flow#174
lpahlavi wants to merge 1 commit intomainfrom
lpahlavi/defi-2780-extract-deposit-validation

Conversation

@lpahlavi
Copy link
Copy Markdown
Contributor

@lpahlavi lpahlavi commented Apr 24, 2026

Summary

Extracts shared deposit validation logic from the manual deposit flow in preparation for the automatic deposit flow.

Changes:

  • rpc::get_transaction: removes the cycles_to_attach parameter — cycles are now fixed via GET_TRANSACTION_CYCLES constant in constants.rs, since the automatic flow also needs to call it with the same amount
  • New deposit::fetch_and_validate_deposit: shared async helper encapsulating the full validation pipeline — fetch transaction via RPC, validate it targets the deposit address, check minimum amount, compute amount_to_mint. Takes a fee: Lamport parameter so both manual (manual_deposit_fee) and automatic (automated_deposit_fee) flows can reuse it
  • try_accept_deposit: simplified to call fetch_and_validate_deposit; cycle charging now only adds deposit_consolidation_fee on success (not on every call)
  • Tests: split runtime_with_time_and_cycles into two helpers — one for valid-deposit tests (charges RPC cost + consolidation fee) and one for failure tests (charges RPC cost only)

No behavior change for valid deposits.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings April 24, 2026 10:05
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copilot AI review requested due to automatic review settings April 24, 2026 11:21
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Extracts the core "fetch tx → validate → accept" logic from
`try_accept_deposit` into a new `fetch_and_validate_deposit` helper in
`deposit/mod.rs`, so the upcoming automatic deposit flow can reuse it
with a different fee.

- `get_transaction` no longer takes a `cycles_to_attach` parameter;
  cycles are fixed via a new `GET_TRANSACTION_CYCLES` constant
- `fetch_and_validate_deposit` takes a `fee: Lamport` parameter so both
  manual (`manual_deposit_fee`) and automatic (`automated_deposit_fee`)
  flows can reuse it
- Cycle charging in `try_accept_deposit` now only adds
  `deposit_consolidation_fee` on success, not on every call

No behavior change for valid deposits.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lpahlavi lpahlavi force-pushed the lpahlavi/defi-2780-extract-deposit-validation branch from 9b3c56f to 6dd2b9b Compare April 24, 2026 13:43
Copilot AI review requested due to automatic review settings April 24, 2026 13:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

lpahlavi added a commit that referenced this pull request Apr 24, 2026
Squashed from lpahlavi/defi-2780-extract-deposit-validation:

- Add `fetch_and_validate_deposit` shared helper to `deposit/mod.rs`
- Extract `GET_TRANSACTION_CYCLES` constant (50 B cycles)
- Remove `cycles_to_attach` parameter from `get_transaction` — it now
  uses the constant internally
- Refactor `try_accept_deposit` to delegate to `fetch_and_validate_deposit`
- Fix `Burn(#[n(0)])` → `Burn(#[n(1)])` in `Memo` cbor annotation

Note: the `meta.err` / `TransactionFailed` removal from #174 was NOT
cherry-picked; that is a bug in #174 that should be fixed separately.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lpahlavi lpahlavi marked this pull request as ready for review April 24, 2026 15:15
@lpahlavi lpahlavi requested a review from a team as a code owner April 24, 2026 15:15
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.

2 participants