Skip to content

feat: add SIP-010 fungible token batch transfer contract (Clarity 4)#1

Open
cocoa007 wants to merge 2 commits into
pbtc21:masterfrom
cocoa007:feat/send-many-ft
Open

feat: add SIP-010 fungible token batch transfer contract (Clarity 4)#1
cocoa007 wants to merge 2 commits into
pbtc21:masterfrom
cocoa007:feat/send-many-ft

Conversation

@cocoa007
Copy link
Copy Markdown

@cocoa007 cocoa007 commented Feb 16, 2026

What

Adds send-many-ft.clar — a generic contract for batch SIP-010 fungible token transfers. Works with any SIP-010 token, no per-token deployment needed.

Key Pattern: Trait as Fold Accumulator

The main challenge: Clarity's fold helpers have a fixed (element, accumulator) signature and can't access trait parameters from the outer scope.

Solution: Pass the <ft-trait> itself as the fold accumulator. The fold helper receives it as a parameter, calls contract-call? token transfer directly, and returns the trait for the next iteration. Counts are tracked via data-vars.

;; Trait flows through as accumulator
(fold send-ft entries token)

;; Fold helper receives trait, can call it
(define-private (send-ft (entry {...}) (token <ft-trait>))
  (match (contract-call? token transfer ...)
    success (begin (var-set ok-count (+ (var-get ok-count) u1)) token)
    error   (begin (var-set fail-count (+ (var-get fail-count) u1)) token)))

Clarity 4 Post Conditions

Uses restrict-assets? with with-ft — caller passes the token name for the post condition:

(restrict-assets? sender
  ((with-ft (contract-of token) token-name total-amount))
  ;; body
)

If actual transfers exceed total-amount, the entire tx rolls back. No client-side post conditions needed.

Interface

(send-many
  token          ;; <ft-trait> — any SIP-010 token
  token-name     ;; (string-ascii 128) — the define-fungible-token name
  l1 l2 l3       ;; three lists (5000+5000+4995 = 14,995 max)
  total-amount)  ;; uint — sum of all amounts (for post-condition)

Returns {ok: uint, fail: uint} — successful and failed transfer counts.

Features

  • Generic: single deployment, works with any SIP-010 token
  • 14,995 recipients per tx: same 3-list pattern as send-many.clar
  • Fault-tolerant: failed transfers don't abort the batch
  • In-contract post conditions: Clarity 4 restrict-assets? enforces limits
  • Event emission: BatchTransfer print with full summary

- send-many-ft.clar: template contract for batch FT transfers
- Uses restrict-assets? with with-ft for in-contract post conditions
- Same 3-list pattern (5000+5000+4995 = 14,995 recipients/tx)
- Fault-tolerant: failed transfers increment fail counter, batch continues
- deploy-ft.ts: deployment script with token substitution

Deploy one per token (like nft-airdrop.clar per campaign).
contract-call? requires compile-time contract refs in Clarity,
so the template has .token-placeholder replaced at deploy time.

Signed-by: cocoa007.btc (BTC: bc1qv8dt3v9kx3l7r9mnz2gj9r9n9k63frn6w6zmrt)
- send-many-ft.clar is now fully generic — works with any SIP-010 token
- Key pattern: trait is the fold accumulator, so fold helper can call
  contract-call? on it directly. Counts tracked via data-vars.
- Caller passes token-name (string-ascii) for restrict-assets? post condition
- Removed deploy-ft.ts (no template substitution needed)
- Single deployment, works for all SIP-010 tokens

Signed-by: cocoa007.btc (BTC: bc1qv8dt3v9kx3l7r9mnz2gj9r9n9k63frn6w6zmrt)
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.

1 participant