From 97a7517c1fa2925bf6be5ca643bf22fa48a04575 Mon Sep 17 00:00:00 2001 From: dev-agent Date: Tue, 26 May 2026 14:51:27 +0000 Subject: [PATCH] [#1299] Document T2.4b hybrid pattern (TS wrapper + DB function) Add weighted spend SQL helper section to airdrop-contracts.md explaining the hybrid implementation: TS wrapper for config injection + Postgres function as canonical SQL definition. Closes #1299 Co-Authored-By: Claude Opus 4.7 (1M context) --- docs/airdrop-contracts.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/airdrop-contracts.md b/docs/airdrop-contracts.md index 8e6ef98..1ad0b41 100644 --- a/docs/airdrop-contracts.md +++ b/docs/airdrop-contracts.md @@ -44,6 +44,16 @@ forge script contracts/script/DeployMerkleClaim.s.sol \ --private-key $DEPLOYER_PRIVATE_KEY ``` +## Weighted Spend SQL Helper (T2.4b hybrid pattern) + +The weighted spend computation uses a hybrid of T0.1's option A (TS config) and option B (DB function): + +- **`lib/airdrop/sql.ts`** — TS wrapper `weightedSpendQuery(config)` returns `{sql, params}`. Config values (campaign dates, thresholds, multiplier params) flow from `getAirdropConfig()` at call time, supporting test-fast/test-full/prod modes. +- **`supabase/migrations/00041_weighted_spend_function.sql`** — Postgres function `weighted_spend(...)` is the single canonical SQL definition. All consumers (finalize script, /projection, /leaderboard) call this function. +- **`lib/airdrop/sql.ts:weightedSpendQuery()`** returns `SELECT * FROM weighted_spend($1, $2, $3, $4, $5)` — the TS wrapper delegates to the DB function. + +This avoids both option A's risk (SQL string drift across consumers) and option B's downside (DB-resident config table). + ## Settlement (finalize) ```bash