Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/airdrop/sql.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "plotlink",
"version": "1.41.2",
"version": "1.41.3",
"private": true,
"workspaces": [
"packages/*"
Expand Down
4 changes: 2 additions & 2 deletions supabase/migrations/00041_weighted_spend_function.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading