feat(token): add batch_mint() function for multi-recipient minting#39
Merged
Merged
Conversation
- Add Recipient struct for type-safe batch operations - Implement batch_mint() function with admin-only access - Validate contract is not paused before batch mint - Validate all recipient amounts are positive (atomic revert) - Emit individual mint events per recipient for indexing - Update total supply atomically once at end of batch - Add SDK batchMint() method with [address, amount][] interface - Add 8 comprehensive tests: * Single recipient mint * Five recipients mint * Ten recipients mint * Empty list fails * Zero amount causes full revert * Negative amount causes full revert * Paused state prevents batch mint * Atomic supply update verification - Optimized for gas efficiency on airdrops and initial distributions Closes BCPathway#12
|
@ACodehunter Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
@ACodehunter please fix issues |
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
Adds a
batch_mint()function to the token contract for efficient multi-recipient minting, as specified in Issue #12. This enables gas-efficient token distributions and airdrops.Problem
Currently, minting to multiple addresses requires separate transactions for each recipient. This is expensive on gas and slow for initial token distributions or airdrops.
Solution
Implemented
batch_mint()that mints tokens to multiple recipients in a single atomic transaction.Changes
Contract Updates (lib.rs)
New Types
Recipientstruct: Type-safe representation of mint recipients with address and amountNew Functions
batch_mint(recipients: Vec<Recipient>): Mint to multiple recipients atomicallySDK Updates (client.ts)
batchMint(recipients: [string, bigint][], source: Keypair): SDK wrapper for batch mintingTests (test.rs)
Added 8 comprehensive tests:
Success Cases
Failure Cases
Supply Verification
Acceptance Criteria
batch_mint()works with 1, 5, and 10 recipientsImplementation Details
Two-Pass Validation
The function uses a two-pass approach:
This ensures atomicity - if any recipient has an invalid amount, the entire batch reverts before any state changes.
Gas Efficiency
Event Emissions
Each recipient gets their own mint event with:
This allows indexers to track individual mints within a batch.
Usage Example
Contract (Rust)
SDK (TypeScript)
Use Cases
Closes #12