Lock transfer - #1649
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for transferring token balances into and out of protocol-level locks, and tightens token transfer semantics to respect “available balance” (total minus locked amounts). It also extends block-state lock tracking so lock/account/token references can be removed when a locked balance is depleted.
Changes:
- Add iteration/decoding support for all per-account locked balances in token-module state and use it to enforce “available balance” in normal transfers.
- Implement lock
Fund,Send, andReturnoperations in the scheduler by invoking new token-context operations (transfer_into_lock/transfer_from_lock) and emitting transfer events. - Add block-state APIs and storage support for removing lock balance references when an account no longer has any balance controlled by a lock.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
plt/plt-scheduler/src/token_module/key_value_state.rs |
Adds prefix-iteration decoding for per-account lock balances and refactors locked-balance decoding helper. |
plt/plt-scheduler/src/token_context.rs |
Enforces “available balance” in transfers and adds token-context operations for moving balances into/out of locks. |
plt/plt-scheduler/src/scheduler/plt_scheduler.rs |
Implements lock fund/send/return execution logic in meta updates (including reject mapping and events). |
plt/plt-scheduler/src/scheduler.rs |
Adds helper to map TokenTransferError into transaction failures/reject reasons. |
plt/plt-scheduler-types/src/types/tokens.rs |
Adds checked_add / checked_sub helpers to RawTokenAmount. |
plt/plt-block-state/src/entity/protocol_level_locks/p11.rs |
Adds remove_lock_balance_ref to lock state model. |
plt/plt-block-state/src/block_state.rs / plt/plt-block-state/src/block_state_interface.rs |
Wires remove_lock_balance_ref into the block state operations trait and P11 implementation. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## release/p11 #1649 +/- ##
===============================================
+ Coverage 63.97% 64.07% +0.09%
===============================================
Files 376 376
Lines 74408 75007 +599
Branches 3016 3013 -3
===============================================
+ Hits 47606 48064 +458
- Misses 23786 23930 +144
+ Partials 3016 3013 -3
|
limemloh
left a comment
There was a problem hiding this comment.
Have some comments, but nothing which can't be dealt with in another PR
Closes COR-2305, Closes COR-2395
Purpose
Implements the lock transfer operations. This also changes the behaviour of token transfers to validate the transfer amount against the "available" token balance of the sender account, which for protocol versions lower than 11 will never differ from the total token balance.
Checklist
hard-to-understand areas.