Feature/bnb auto mass payouts #183
Open
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.
Auto-Mass Payouts (BNB Chain Hackathon)
Auto-Mass Payouts lets ops teams orchestrate high-volume vendor, affiliate, or reward disbursements on the BNB Smart Chain testnet. The system combines a gas-efficient Foundry contract suite with a Supabase-driven Next.js control panel so every batch comes with verifiable blockchain receipts and human-friendly analytics.
Repository layout
contracts/MassPayoutcontract, mock BEP-20 USDT token, Forge tests, and a deployment script for BNB testnet.frontend/frontend/.env.exampleQuick start
curl -L https://foundry.paradigm.xyz | bash), Node 20+, npm.frontend/.env.exampletofrontend/.env.local, then fill in contract addresses plus Supabase + scheduler credentials.MassPayout+MockUSDTon BNB Smart Chain testnet and mint demo balances.batchesfor executed payouts andscheduled_batchesfor queued jobs (schemas below)./api/run-schedulerfire due jobs automatically.Smart contracts
MassPayout.sol
PayoutExecuted,ScheduledPayoutCreated,ScheduledPayoutExecuted, andScheduledPayoutCancelledfor full off-chain observability.Ownable,SafeERC20, andAddresshelpers for safety.sendERC20,sendNative) plus scheduled flows (scheduleERC20,scheduleNative,executeScheduled, andcancelScheduled).executeAfter.Mock tokens
MockUSDT(6 decimals) deploys alongside the protocol and exposes afaucet(address,uint256)helper plus ademoFaucet()that mints a fixed 1,000 tokens to the caller for effortless funding during demos. Native BNB payouts draw directly from your wallet balance.Tests & config
contracts/foundry.toml) enablesvia-irfor stack-depth friendliness and optimizer runs.contracts/test/MassPayout.t.solcover ERC-20 payouts, native payouts, length mismatches, and funding checks.Deployment script
contracts/script/DeployMassPayout.s.soldeploys MassPayout plus the mock USDT token in a single broadcast. It readsMASS_PAYOUT_OWNERfrom the environment and prints all addresses.Example:
After deployment, copy the printed addresses into
.env/frontend/.env.localso the UI knows which contracts to call.Minting test liquidity
Call the faucet helpers to mint tokens to any wallet:
(Adjust decimals: USDT uses 6.)
Frontend (Next.js)
Product UX highlights inside
frontend/:datetime-localpicker and show when the batch will fire.address,amount. A themed helper card links topublic/sample-recipients.csvso vendors know exactly what to send./api/run-schedulerendpoint andSCHEDULER_*env vars keep scheduled payouts self-driving, plus a cheat sheet for CSV expectations.Supabase schema
Create a table that matches the payload inserted by
/api/batches:Enable Row Level Security if desired and grant the service-role key
insertprivileges. The client never sees this key—the Next.js API route owns it.Schedule metadata lives in a sibling table and drives the automation worker:
Automation worker
POST /api/run-scheduler(lives in the Next.js app) checks Supabase for due entries, executes up to five schedules per run, and writes backexecuted,executed_tx, andexecuted_at.SCHEDULER_PRIVATE_KEY,SCHEDULER_RPC_URL, and optionallySCHEDULER_WEBHOOK_TOKENso only your cron job can trigger the route. The UI’s automation checklist mirrors these variables.x-cron-tokenheader when a secret is configured.Supabase (Postgres) cron example
Supabase ships with the
pg_cron+pg_netextensions, so you can schedule the HTTP call straight from the database:The call uses the same
x-cron-tokenthe API route expects. Adjust the cadence and URL to match your deployment; Supabase will handle retries and logging in thecron.job_run_detailstable.CSV template
The UI expects a minimal structure:
Upload any CSV/TSV following this pattern or share
frontend/public/sample-recipients.csvwith your ops team. The UI highlights parsing errors inline and lets you continue editing rows manually.Testing & quality gates
cd contracts && forge testcd frontend && npm run lintForge test suite
Latest
forge testrun (contracts) – 21 passing cases:test_SendERC20MassPayouttest_SendNativeMassPayouttest_DemoFaucetMintsThousandTokenstest_SendERC20RevertsOnZeroRecipienttest_SendNativeRevertsOnZeroAmounttest_RevertWhenLengthMismatchtest_RevertWhenInsufficientNativeValuetest_EstimateTotalSumsArraytest_ScheduleAndExecuteERC20test_ScheduleAndExecuteNativetest_ScheduleERC20RevertsWhenExecuteAfterPasttest_ScheduleNativeRevertsWhenExecuteAfterPasttest_ScheduleNativeRevertsWhenValueMismatchtest_ScheduleERC20RevertsOnDuplicateParameterstest_ExecuteScheduledRevertsWhenMissingtest_ExecuteScheduledRevertsWhenNotReadytest_ExecuteScheduledRevertsWhenRecipientMismatchtest_ExecuteScheduledRevertsWhenAlreadyExecutedtest_CancelScheduleRefundstest_CancelScheduleRevertsWhenNotCreatortest_CancelScheduleRevertsWhenAlreadyExecuted