Skip to content

Conversation

@liobrasil
Copy link
Contributor

@liobrasil liobrasil commented Dec 4, 2025

Problem

When a deposit exceeds the rate limit cap, the excess amount is queued for async processing—but there's currently no way to query these queued balances. This creates confusion about the whereabouts of user assets.

Example:
Position 1 deposited 500K FLOW, but our 5% deposit rate limit only allowed 50K to process immediately. The remaining 450K is safely queued and will auto-process via asyncUpdatePosition() — however, this balance was invisible when querying position details.

Solution

This PR adds:

  • A queuedDepositAmounts mapping to track pending deposit balances
  • A get_queued_deposits.cdc script to query these balances
  • A syncQueuedDepositAmounts() function to handle legacy positions that had queued deposits before tracking was introduced

@liobrasil liobrasil requested a review from a team as a code owner December 4, 2025 16:54
@liobrasil liobrasil marked this pull request as draft December 4, 2025 16:54
@liobrasil liobrasil force-pushed the lionel/queued-deposits-getter branch from f212b9e to dd78d79 Compare January 7, 2026 17:56
@liobrasil liobrasil marked this pull request as ready for review January 7, 2026 17:56
@liobrasil liobrasil changed the title [WIP] add queuedDepositAmounts mapping to track and query deposit amounts for scripts Add queuedDepositAmounts mapping to track and query deposit amounts for scripts Jan 7, 2026
@liobrasil
Copy link
Contributor Author

⚠️ Testing Limitations & Deployment Notes

What the tests cover

The integration test (queued_deposits_integration_test.cdc) validates:

  • ✅ New deposits exceeding limit are queued correctly
  • get_queued_deposits.cdc script returns correct values
  • ✅ Partial async processing updates tracking correctly
  • ✅ Full async processing removes tracking entries

What the tests do NOT cover

  1. Legacy migration scenario - The test creates fresh positions where queuedDepositAmounts is tracked from the start. It does not simulate the production scenario where Position 1 has 450K FLOW in queuedDeposits but empty queuedDepositAmounts.

  2. syncQueuedDepositAmounts function - The new sync function is not directly tested. Its logic was code-reviewed but should be validated on testnet before mainnet deployment.

  3. Adding to existing queue - The else branch in the deposit path (adding to an existing queue) is not explicitly tested.

Production Deployment Steps

# 1. Deploy updated contract
flow project deploy --network mainnet

# 2. IMMEDIATELY sync Position 1 (and any other affected positions)
flow transactions send cadence/transactions/flow-credit-market/pool-management/sync_queued_deposit_amounts.cdc 1 --network mainnet --signer <protocol-account>

# 3. Verify
flow scripts execute cadence/scripts/flow-credit-market/get_queued_deposits.cdc 1 --network mainnet
# Expected: {Type<@FlowToken.Vault>(): 450000.0} (approximately)

⚠️ Important: Until the sync transaction is run, getQueuedDeposits(pid: 1) will return {} even though 450K FLOW exists in the queue.

@liobrasil liobrasil self-assigned this Jan 9, 2026
liobrasil and others added 3 commits January 13, 2026 14:24
…osit amounts for scripts

feat(get_queued_deposits): create script to retrieve queued deposit balances for a given position ID
- getQueuedDeposits now falls back to actual vault balance for positions
  that had queued deposits before queuedDepositAmounts tracking was added
- Auto-sync tracking on next deposit to legacy queue

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…tests

- Add syncQueuedDepositAmounts(pid) function to rebuild tracking from actual vault balances
- Simplify deposit path to always sync tracking from vault balance after deposit
- Add integration test for queued deposits lifecycle (queue → partial drain → full drain)
- Add test helper for getQueuedDeposits script
- Add sync_queued_deposit_amounts.cdc transaction for production migration

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@liobrasil liobrasil force-pushed the lionel/queued-deposits-getter branch from ab3212b to 57e3971 Compare January 13, 2026 18:25
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