Home / Market / DEX Batch Distribution

DEX Batch Distribution

Batch-distribute ERC-20 tokens or native currency to up to 200 recipients in one transaction through Spraay Protocol, directly or via Uniswap V4 and PancakeSwap hooks, using the @spraay/dex-adapters SDK.

skill★ 00 dlclawhubMIT-0Install in CosmosUpstream Source

Documentation & Preview

--- name: dex-batch-distribution description: Batch-distribute ERC-20 tokens or native currency to up to 200 recipients in one transaction through Spraay Protocol, directly or via Uniswap V4 and PancakeSwap hooks, using the @spraay/dex-adapters SDK. version: 1.1.0 metadata: openclaw: homepage: https://github.com/plagtech/spraay-dex-adapters requires: bins:

envVars:

required: false description: Private key of the wallet that funds and sends distributions. Only needed when sending from a script with a local account; not needed with a browser or injected wallet. Never hardcode or log it.

---

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.

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.

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

BatchDistributeHook (Uniswap V4), canonical

Uniswap V4 PoolManager

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.

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

Resources