diff --git a/lib/airdrop/sql.test.ts b/lib/airdrop/sql.test.ts index 8b75ce2..7d81122 100644 --- a/lib/airdrop/sql.test.ts +++ b/lib/airdrop/sql.test.ts @@ -245,6 +245,32 @@ describe("weightedSpendQuery against PGlite", () => { expect(Number(rows[1].community_total)).toBe(300); }); + it("ref count input capped at 10 (11 refs same as 10)", async () => { + await resetFixtures(); + const refInserts = Array.from({ length: 11 }, (_, i) => + `('ref${i}', '2026-07-01')` + ).join(","); + const buyInserts = Array.from({ length: 11 }, (_, i) => + `('ref${i}', 'buy', 60, '${IN_CAMPAIGN}')` + ).join(","); + const relInserts = Array.from({ length: 11 }, (_, i) => + `('alice', 'ref${i}')` + ).join(","); + + await db.exec(` + INSERT INTO pl_activations (address, activated_at) VALUES + ('alice', '2026-07-01'), ${refInserts}; + INSERT INTO pl_points (address, action, points, created_at) VALUES + ('alice', 'buy', 100, '${IN_CAMPAIGN}'), ${buyInserts}; + INSERT INTO pl_referrals (referrer_address, referred_address) VALUES ${relInserts}; + `); + + const rows = await runQuery(config); + const alice = rows.find(r => r.address === "alice")!; + expect(Number(alice.qualified_refs)).toBe(11); + expect(Number(alice.multiplier)).toBe(3.0); + }); + it("multiplier is capped at REFERRAL_MULTIPLIER_CAP", async () => { await resetFixtures(); const refInserts = Array.from({ length: 20 }, (_, i) => diff --git a/package-lock.json b/package-lock.json index 3ad95d8..683641f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "plotlink", - "version": "1.41.2", + "version": "1.41.3", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "plotlink", - "version": "1.41.2", + "version": "1.41.3", "workspaces": [ "packages/*" ], diff --git a/package.json b/package.json index 4f86885..5925730 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "plotlink", - "version": "1.41.2", + "version": "1.41.3", "private": true, "workspaces": [ "packages/*" diff --git a/supabase/migrations/00041_weighted_spend_function.sql b/supabase/migrations/00041_weighted_spend_function.sql index e7290e3..293e093 100644 --- a/supabase/migrations/00041_weighted_spend_function.sql +++ b/supabase/migrations/00041_weighted_spend_function.sql @@ -51,11 +51,11 @@ AS $$ COALESCE(qr.ref_count, 0) AS qualified_refs, eb.has_fc_bonus, LEAST( - 1 + (COALESCE(qr.ref_count, 0) + eb.has_fc_bonus) * p_multiplier_per_ref, + 1 + LEAST(COALESCE(qr.ref_count, 0) + eb.has_fc_bonus, 10) * p_multiplier_per_ref, p_multiplier_cap ) AS multiplier, eb.buy_volume * LEAST( - 1 + (COALESCE(qr.ref_count, 0) + eb.has_fc_bonus) * p_multiplier_per_ref, + 1 + LEAST(COALESCE(qr.ref_count, 0) + eb.has_fc_bonus, 10) * p_multiplier_per_ref, p_multiplier_cap ) AS weighted_spend FROM eligible_buys eb