360 Secure SkillHub
360 安全技能中心

DEX Batch Distribution

该 Skill 提供 TypeScript SDK 用法,通过 Spraay Protocol 在 Base 与 BNB Chain 批量分发 ERC-20 或原生代币,并说明 Uniswap V4、PancakeSwap、SushiSwap、Balancer 适配。包含费用估算、Gas 限制、部分失败退款与安全检查注意事项。

分类:自动化
plagtech
plagtech
热度 8.79
最近更新 2026-12-01 03:48:15

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add plagtech/dex-batch-distribution
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
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":["node","npm"]},"envVars":[{"name":"SPRAAY_SENDER_PRIVATE_KEY","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.

  • 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 estimateCost for 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_estimateGas and add headroom. Do not use gas-used times a multiplier.
  • Pass gas to distribute to set the limit yourself.
  • estimateCost returns gas (minimum limit that passes), gasLimit (what the SDK would send), and gasCost (an upper bound). When the RPC supports eth_simulateV1 it also returns gasUsedEstimate and expectedGasCost, 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.

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 estimateCost before 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_estimateGas plus headroom.
  • Private keys in environment variables only, never hardcoded or logged.
  • Fee-on-transfer and rebasing tokens are not supported.

Resources