DEX Batch Distribution
Batch-distribute ERC-20 tokens or native currency to up to 200 recipients in one transaction, directly through Spraay Protocol or through a DEX hook that ties the payout to a pool.
What this does
Spraay is push-based distribution. Instead of recipients claiming rewards from a farm or merkle tree, the sender chooses recipients off-chain and delivers to all of them in one transaction. No claim step, no unclaimed dust.
This skill covers the @spraay/dex-adapters npm package (0.4.1 or later): a generic adapter for direct Spraay calls, plus adapters for DEX hook integrations.
Install
npm install @spraay/dex-adapters@^0.4.1 viem
Supported adapters
| Adapter | Import path | Chains | What it calls |
|---|---|---|---|
| Generic | @spraay/dex-adapters/generic |
Base, BNB Chain | The Spraay contract directly |
| Uniswap V4 | @spraay/dex-adapters/uniswap-v4 |
Base, BNB Chain | BatchDistributeHook (permissions: afterInitialize + afterDonate) |
| PancakeSwap Infinity | @spraay/dex-adapters/pancakeswap |
BNB Chain, Base | BatchDistributeHook (ICLHook) |
| SushiSwap | @spraay/dex-adapters/sushiswap |
Base | Spraay directly, for launchpad-style holder rewards. No Sushi contract is involved |
| Balancer v3 | @spraay/dex-adapters/balancer |
Base | BatchDistributeHook |
These are SDK adapters. They are not official integrations by those DEX teams.
How it works
Each adapter wraps Spraay's on-chain batch functions (sprayToken, sprayETH, sprayEqual). The hook adapters route the batch through a hook contract so the payout is attributed on-chain to a pool. The hooks do not intercept swaps or liquidity.
- Fee: 30 bps, charged on top of the distributed amount.
- Recipient limit: 200 per transaction.
- Gas: one transaction instead of one per recipient. The saving grows with batch size; very small batches can use more gas than separate transfers. Use
estimateCostfor real numbers.
Quick start: generic adapter (direct Spraay calls)
import { createPublicClient, createWalletClient, http, parseUnits } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { base } from 'viem/chains'
import { distribute, estimateCost } from '@spraay/dex-adapters/generic'
const account = privateKeyToAccount(process.env.SPRAAY_SENDER_PRIVATE_KEY as `0x${string}`)
const publicClient = createPublicClient({ chain: base, transport: http() })
const walletClient = createWalletClient({ account, chain: base, transport: http() })
const USDC = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913' // USDC on Base
const recipients = ['0xAbc...', '0xDef...'] as const
const amounts = [parseUnits('100', 6), parseUnits('250', 6)]
// Fee breakdown, and gas figures when `account` is given
const quote = await estimateCost({
token: USDC, recipients, amounts,
chain: base, publicClient, account,
})
// Approves exactly amount + fee if needed, simulates, then sends
const { hash, approvalHash } = await distribute({
token: USDC, recipients, amounts,
chain: base, walletClient, publicClient,
})
Gas (read this before sending on Base)
On Base, the Spraay contract requires 150,000 gas to remain before each transfer. A gas limit based on the gas a call uses can revert with Insufficient gas.
- From 0.4.1 the SDK estimates each distribution and sends it with 20% headroom. Unused gas is not charged.
- If you build transactions yourself, use
eth_estimateGasand add headroom. Do not use gas-used times a multiplier. - Pass
gastodistributeto set the limit yourself. estimateCostreturnsgas(minimum limit that passes),gasLimit(what the SDK would send), andgasCost(an upper bound). When the RPC supportseth_simulateV1it also returnsgasUsedEstimateandexpectedGasCost, the realistic figures. On Base none of these include the L1 data fee.- Gas can only be estimated once the ERC-20 allowance exists.
- BNB Chain has no such gas floor.
Partial delivery on Base
On Base, a recipient whose transfer fails is skipped, and that recipient's amount and fee are returned to the sender, normally in the same transaction. Native currency that the sender cannot receive is held for the sender to claim (claimRefund). A successful transaction does not mean every recipient was paid. After each distribution, check the receipt for RecipientFailed events (and BatchRefunded when using a hook) and report any skipped recipients.
Uniswap V4 adapter
Every hook distribution must reference a pool that was initialized with the hook, and the sender must be an operator of that hook.
Option A: your own hook and pool. You are the owner and operator.
import { zeroAddress } from 'viem'
import { base } from 'viem/chains'
import { deployHook, distribute, getPoolId } from '@spraay/dex-adapters/uniswap-v4'
// 1. Deploy once per chain. Mines a CREATE2 salt for the 0x...1010 permission flags.
const { address: hook } = await deployHook({
chain: base, walletClient, publicClient, operator: account.address,
})
// 2. Create a pool with the hook (PoolManager.initialize or PositionManager), then derive its id.
const poolId = getPoolId({
currency0: zeroAddress, currency1: TOKEN, fee: 3000, tickSpacing: 60, hooks: hook,
})
// 3. Distribute. The hook forwards the batch to Spraay in the same transaction.
await distribute({
hook, poolId, token: TOKEN, recipients, amounts,
chain: base, walletClient, publicClient,
})
Option B: the canonical hook on Base. Distributions on this deployment are operator-only. Without operator access the SDK throws NOT_OPERATOR. Request access by opening an issue at github.com/plagtech/spraay-uniswap-v4-hook.
PancakeSwap Infinity adapter
import { zeroAddress } from 'viem'
import { bsc } from 'viem/chains'
import {
deployHook, distribute, encodeCLPoolParameters, getPoolId, PANCAKESWAP_INFINITY,
} from '@spraay/dex-adapters/pancakeswap'
const { address: hook } = await deployHook({
chain: bsc, walletClient, publicClient, operator: account.address,
})
const poolKey = {
currency0: zeroAddress, // BNB
currency1: TOKEN,
hooks: hook!,
poolManager: PANCAKESWAP_INFINITY[56].clPoolManager,
fee: 3000,
parameters: encodeCLPoolParameters(60),
}
// ... initialize the pool via CLPoolManager / CLPositionManager ...
const poolId = getPoolId(poolKey)
await distribute({
hook: hook!, poolId, token: TOKEN, recipients, amounts,
chain: bsc, walletClient, publicClient,
})
Verified contract addresses
Always take addresses from the SDK (@spraay/dex-adapters) rather than typing them by hand.
Spraay contract
- Base:
0x4B1d57EBFaBDF3F21F30f210a1d95f649E9edD4c - BNB Chain:
0x3093a2951FB77b3beDfB8BA20De645F7413432C1
BatchDistributeHook (Uniswap V4), canonical
- Base:
0x2aB86A34661C0629C62A0f1980c96D41Ea471010(verified on Basescan and Sourcify) - BNB Chain: not deployed
Uniswap V4 PoolManager
- Base:
0x498581fF718922c3f8e6A244956aF099B2652b2b - BNB Chain:
0x28e2Ea090877bF75740558f6BFB36A5ffeE9e9dF
Superseded on Base. Do not use: Spraay 0x1646452F98E36A3c9Cfc3eDD8868221E207B5eEC and hook 0xB9c1aB7BD023C784c19B8e9F10CE9CDEd9fF9010.
Live pool on Base
A native ETH / USDC pool (fee 3000, tick spacing 60) uses the canonical hook. It holds a small test position.
- PoolId:
0x1e2f50bab1ef6f8b8b59cebf2d787d46ab8f9a29a8be78450c0214a608b2bc79 - Distribution through the hook: https://basescan.org/tx/0xf040b24f660e041a0a3ce66ecb386f90f71982ed75c51af07ff356097d16ef9a
- Distribution through SDK 0.4.1: https://basescan.org/tx/0xa0b539caf1857e6d13b880de3b6113c414f6a00ec98d8fe3ff0adef9c42d4ae4
Push vs pull: when to use this
| Pull (farms, donate, merkle) | Push (Spraay) | |
|---|---|---|
| Who pays gas | Each recipient on claim | Sender, once per batch |
| Eligible recipients | On-chain positions or proofs | Any address |
| Allocation logic | On-chain | Off-chain, sender decides |
| Recipient action | Must claim | None |
| Best for | Open continuous incentives | Airdrops, holder rewards, revenue shares, targeted payouts |
The two models work together: a pool can run farms while the operator pushes one-off or targeted payouts through Spraay.
Safety rules
- Always call
estimateCostbefore distributing, and show the user the total cost including the 30 bps fee. - Approvals are bounded to exactly amount + fee. Never request an infinite approval.
- Verify recipient addresses off-chain before batching.
- Test with dust amounts on mainnet before a large distribution.
- After sending, check the receipt for skipped recipients (see "Partial delivery on Base").
- Leave gas limits to the SDK, or use
eth_estimateGasplus headroom. - Private keys in environment variables only, never hardcoded or logged.
- Fee-on-transfer and rebasing tokens are not supported.
Resources
- SDK: https://www.npmjs.com/package/@spraay/dex-adapters
- SDK source: https://github.com/plagtech/spraay-dex-adapters
- Uniswap V4 hook repo: https://github.com/plagtech/spraay-uniswap-v4-hook
- Spraay Protocol: https://spraay.app
- Publisher: Plagtech (https://plagtech.net)
