feat(contracts): add atomic batch_transfer function for multi-recipient key distribution --- - #853
Merged
Merged
Conversation
…ic multi-recipient transfers Adds batch_transfer_keys(creator, from, transfers: Vec<(Address, u32)>) so any holder can distribute keys to up to 10 recipients in one signed, atomic transaction. Validates batch size, zero quantities, and self-transfers up front, settles dividend checkpoints for the sender and each recipient, and emits a BatchTransferCompletedEvent with the ordered pairs and total. Replaces the earlier merge-corroded implementation that was dropped when the fork main was reset to upstream. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
… rustfmt Chains that fit within rustfmt's single-line width are kept horizontal; reformat the recipient balance increment to match `cargo fmt --check`. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
… main merge The upstream main merge (price-oracle events) spliced new event definitions inside batch_transfer_completed_topics, dropping its closing brace and breaking parsing of events.rs. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
…le merge Upstream main added CallerNotApproved = 67 while this branch added BatchTransferSizeExceeded = 67, colliding discriminants. Move the batch transfer errors after it and renumber to 68/69. 🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The existing
transferfunction only supports a single recipient per transaction. This PR addsbatch_transferaccepting up to 10(recipient, quantity)pairs, processing all transfers atomically in one signed transaction — useful for team allocations and community rewards. Any failure panics and rolls back the entire batch.Closes #799
What changed
contracts/accesslayer/src/lib.rsbatch_transfer(key_id: BytesN<32>, transfers: Vec<(Address, u32)>) -> Result<(), Error>key_idBatchSizeExceedediftransfers.len()is 0 or greater than 10InsufficientBalanceif the caller's balance is less than the total before any transfer is appliedInvalidRecipientif any entry is invalid, rolling back the batchbatch_transfer_completedwithkey_id, the full list of(recipient, quantity)pairs, andtotal_transferredTests
InsufficientBalance— no balances mutatedBatchSizeExceeded— no balances mutatedInvalidRecipient— entire batch rolled backbatch_transfer_completedevent emitted with correctkey_id, pairs, and totalHow to verify
cargo test -p accesslayer-contracts -- batch_transfer --nocaptureInsufficientBalancepanic with no balance changesBatchSizeExceededpanicInvalidRecipientpanic with all balances unchangedbatch_transfer_completedevent fields match the submitted transfers and totalcargo testand confirm all tests passChecklist
batch_transferacceptsVec<(Address, u32)>with 1–10 entriesBatchSizeExceededpanic on vec length 0 or > 10InsufficientBalancepanic if insufficientInvalidRecipientpanic rolls back entire batchbatch_transfer_completedevent emitted withkey_id, pairs, andtotal_transferredcargo testpasses with no warnings