From 6514e137aa0ec4d16f8ccb6469c0b92fe3d864ab Mon Sep 17 00:00:00 2001 From: Cho Young-Hwi Date: Thu, 26 Mar 2026 07:11:26 +0000 Subject: [PATCH 1/3] [#272] Update StoryFactory mainnet address and clean up orphan storylines Update mainnet fallback to v4b factory (0x9D2AE1E...8744Cf) deployed at block 43840298 (symbol-collision fix). Add migration to delete orphan storyline IDs 25-33 from first E2E attempt. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/contracts/constants.ts | 6 ++-- packages/sdk/src/constants.ts | 4 +-- .../00025_cleanup_orphan_storylines.sql | 35 +++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 supabase/migrations/00025_cleanup_orphan_storylines.sql diff --git a/lib/contracts/constants.ts b/lib/contracts/constants.ts index 69d4db8b..36352e17 100644 --- a/lib/contracts/constants.ts +++ b/lib/contracts/constants.ts @@ -24,14 +24,14 @@ export const EXPLORER_URL = IS_TESTNET // PlotLink contracts // --------------------------------------------------------------------------- -/** Deployment block for the v4 StoryFactory (J-curve + real PLOT) on Base mainnet */ -export const DEPLOYMENT_BLOCK = BigInt(43_824_790); +/** Deployment block for the v4b StoryFactory (symbol-collision fix) on Base mainnet */ +export const DEPLOYMENT_BLOCK = BigInt(43_840_298); /** StoryFactory — storyline + plot management */ export const STORY_FACTORY = (process.env.NEXT_PUBLIC_CONTRACT_ADDRESS ?? (IS_TESTNET ? "0xfa5489b6710Ba2f8406b37fA8f8c3018e51FA229" - : "0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d")) as `0x${string}`; + : "0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf")) as `0x${string}`; /** ZapPlotLinkV2 — one-click buy (ETH/USDC/HUNT -> PLOT -> storyline token via Uniswap V4 + MCV2) * Testnet: disabled (V1 contract incompatible with V2 ABI) */ diff --git a/packages/sdk/src/constants.ts b/packages/sdk/src/constants.ts index bb40033d..739e0aa2 100644 --- a/packages/sdk/src/constants.ts +++ b/packages/sdk/src/constants.ts @@ -26,7 +26,7 @@ export const DEPLOYMENT_BLOCK = BigInt(20_000_000); * Deployment block for PlotLink contracts on Base mainnet. * Used as the default fromBlock for mainnet event log queries. */ -export const DEPLOYMENT_BLOCK_MAINNET = BigInt(43_824_790); +export const DEPLOYMENT_BLOCK_MAINNET = BigInt(43_840_298); /** Supported chain IDs for the PlotLink SDK. */ export const SUPPORTED_CHAIN_IDS = new Set([BASE_SEPOLIA_CHAIN_ID, BASE_MAINNET_CHAIN_ID]); @@ -41,7 +41,7 @@ export const STORY_FACTORY_ADDRESS = /** StoryFactory — storyline + plot management (Base mainnet). */ export const STORY_FACTORY_MAINNET_ADDRESS = - "0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d" as const; + "0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf" as const; /** MCV2_Bond — bonding curve trading (Base Sepolia). */ export const MCV2_BOND_ADDRESS = diff --git a/supabase/migrations/00025_cleanup_orphan_storylines.sql b/supabase/migrations/00025_cleanup_orphan_storylines.sql new file mode 100644 index 00000000..80aa7c69 --- /dev/null +++ b/supabase/migrations/00025_cleanup_orphan_storylines.sql @@ -0,0 +1,35 @@ +-- [#549] Clean up orphan storylines 25-33 from first E2E attempt +-- +-- These were created on the old v4 factory (0x92c3bd44...) with wrong +-- content hashes during initial E2E testing. The new v4b factory +-- (0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf) has the correct data. + +-- 1. Delete plots for orphan storylines +DELETE FROM plots WHERE storyline_id BETWEEN 25 AND 33; + +-- 2. Delete donations for orphan storylines +DELETE FROM donations WHERE storyline_id BETWEEN 25 AND 33; + +-- 3. Delete ratings for orphan storylines +DELETE FROM ratings WHERE storyline_id BETWEEN 25 AND 33; + +-- 4. Delete comments for orphan storylines +DELETE FROM comments WHERE storyline_id BETWEEN 25 AND 33; + +-- 5. Delete page views for orphan storylines +DELETE FROM page_views WHERE storyline_id BETWEEN 25 AND 33; + +-- 6. Delete trade history for orphan storylines +DELETE FROM trade_history WHERE storyline_id BETWEEN 25 AND 33; + +-- 7. Delete the orphan storylines themselves +DELETE FROM storylines WHERE storyline_id BETWEEN 25 AND 33; + +-- 8. Clean up backfill_failures for orphan storylines +DELETE FROM backfill_failures WHERE storyline_id BETWEEN 25 AND 33; + +-- 9. Clean up notification_queue for orphan storylines (skip if table doesn't exist) +DO $$ BEGIN + DELETE FROM notification_queue WHERE storyline_id BETWEEN 25 AND 33; +EXCEPTION WHEN undefined_table THEN NULL; +END $$; From 43f592d6daef96f93ea9f16c284679e6338f1b6b Mon Sep 17 00:00:00 2001 From: Cho Young-Hwi Date: Thu, 26 Mar 2026 07:16:28 +0000 Subject: [PATCH 2/3] [#272] Scope orphan deletes by contract address and reset backfill cursor Address T2a review feedback: - Scope all DELETE statements to old v4 factory (0x92c3bd44...) to avoid accidentally deleting non-orphan rows - Reset backfill_cursor to block 43840297 (one before v4b deploy) so backfill picks up events from the new factory Co-Authored-By: Claude Opus 4.6 (1M context) --- .../00025_cleanup_orphan_storylines.sql | 61 +++++++++++++------ 1 file changed, 41 insertions(+), 20 deletions(-) diff --git a/supabase/migrations/00025_cleanup_orphan_storylines.sql b/supabase/migrations/00025_cleanup_orphan_storylines.sql index 80aa7c69..2e718f2f 100644 --- a/supabase/migrations/00025_cleanup_orphan_storylines.sql +++ b/supabase/migrations/00025_cleanup_orphan_storylines.sql @@ -1,29 +1,45 @@ -- [#549] Clean up orphan storylines 25-33 from first E2E attempt +-- and reset backfill cursor for the v4b factory redeployment. -- --- These were created on the old v4 factory (0x92c3bd44...) with wrong --- content hashes during initial E2E testing. The new v4b factory --- (0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf) has the correct data. - --- 1. Delete plots for orphan storylines -DELETE FROM plots WHERE storyline_id BETWEEN 25 AND 33; - --- 2. Delete donations for orphan storylines -DELETE FROM donations WHERE storyline_id BETWEEN 25 AND 33; - --- 3. Delete ratings for orphan storylines -DELETE FROM ratings WHERE storyline_id BETWEEN 25 AND 33; - --- 4. Delete comments for orphan storylines -DELETE FROM comments WHERE storyline_id BETWEEN 25 AND 33; - --- 5. Delete page views for orphan storylines -DELETE FROM page_views WHERE storyline_id BETWEEN 25 AND 33; +-- Storylines 25-33 were created on the old v4 factory (0x92c3bd44...) +-- with wrong content hashes during initial E2E testing. The new v4b +-- factory (0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf) has correct data. + +-- Scope all deletes to the old v4 factory to avoid touching data from +-- any other contract. + +-- 1. Delete plots for orphan storylines on old factory +DELETE FROM plots + WHERE storyline_id BETWEEN 25 AND 33 + AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + +-- 2. Delete donations for orphan storylines on old factory +DELETE FROM donations + WHERE storyline_id BETWEEN 25 AND 33 + AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + +-- 3. Delete ratings for orphan storylines on old factory +DELETE FROM ratings + WHERE storyline_id BETWEEN 25 AND 33 + AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + +-- 4. Delete comments for orphan storylines on old factory +DELETE FROM comments + WHERE storyline_id BETWEEN 25 AND 33 + AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + +-- 5. Delete page views for orphan storylines on old factory +DELETE FROM page_views + WHERE storyline_id BETWEEN 25 AND 33 + AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); -- 6. Delete trade history for orphan storylines DELETE FROM trade_history WHERE storyline_id BETWEEN 25 AND 33; --- 7. Delete the orphan storylines themselves -DELETE FROM storylines WHERE storyline_id BETWEEN 25 AND 33; +-- 7. Delete the orphan storylines on old factory (last, after FK-dependent deletes) +DELETE FROM storylines + WHERE storyline_id BETWEEN 25 AND 33 + AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); -- 8. Clean up backfill_failures for orphan storylines DELETE FROM backfill_failures WHERE storyline_id BETWEEN 25 AND 33; @@ -33,3 +49,8 @@ DO $$ BEGIN DELETE FROM notification_queue WHERE storyline_id BETWEEN 25 AND 33; EXCEPTION WHEN undefined_table THEN NULL; END $$; + +-- 10. Reset backfill cursor to just before the v4b factory deployment block +-- so the backfill picks up events from the new factory (deployed at 43840298) +UPDATE backfill_cursor SET last_block = 43840297 WHERE id = 1; +UPDATE backfill_cursor SET last_block = 43840297 WHERE id = 2; From 1abeba456b660393a5ec8e185156953b4a1f2c1a Mon Sep 17 00:00:00 2001 From: Cho Young-Hwi Date: Thu, 26 Mar 2026 07:19:52 +0000 Subject: [PATCH 3/3] [#272] Fix migration scoping to v4b factory, not old v4 Orphan storylines 25-33 were created on the new v4b factory (0x9D2AE1E9...) during the first E2E attempt, not the old v4. Correct the contract_address filter accordingly. Co-Authored-By: Claude Opus 4.6 (1M context) --- .../00025_cleanup_orphan_storylines.sql | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/supabase/migrations/00025_cleanup_orphan_storylines.sql b/supabase/migrations/00025_cleanup_orphan_storylines.sql index 2e718f2f..1b632c74 100644 --- a/supabase/migrations/00025_cleanup_orphan_storylines.sql +++ b/supabase/migrations/00025_cleanup_orphan_storylines.sql @@ -1,45 +1,46 @@ -- [#549] Clean up orphan storylines 25-33 from first E2E attempt -- and reset backfill cursor for the v4b factory redeployment. -- --- Storylines 25-33 were created on the old v4 factory (0x92c3bd44...) --- with wrong content hashes during initial E2E testing. The new v4b --- factory (0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf) has correct data. +-- Storylines 25-33 were created on the v4b factory +-- (0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf) during the first E2E +-- attempt with wrong content hashes. They need to be removed so the +-- backfill can re-index clean data from the same factory. --- Scope all deletes to the old v4 factory to avoid touching data from +-- Scope all deletes to the v4b factory to avoid touching data from -- any other contract. --- 1. Delete plots for orphan storylines on old factory +-- 1. Delete plots for orphan storylines on v4b factory DELETE FROM plots WHERE storyline_id BETWEEN 25 AND 33 - AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + AND lower(contract_address) = lower('0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf'); --- 2. Delete donations for orphan storylines on old factory +-- 2. Delete donations for orphan storylines on v4b factory DELETE FROM donations WHERE storyline_id BETWEEN 25 AND 33 - AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + AND lower(contract_address) = lower('0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf'); --- 3. Delete ratings for orphan storylines on old factory +-- 3. Delete ratings for orphan storylines on v4b factory DELETE FROM ratings WHERE storyline_id BETWEEN 25 AND 33 - AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + AND lower(contract_address) = lower('0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf'); --- 4. Delete comments for orphan storylines on old factory +-- 4. Delete comments for orphan storylines on v4b factory DELETE FROM comments WHERE storyline_id BETWEEN 25 AND 33 - AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + AND lower(contract_address) = lower('0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf'); --- 5. Delete page views for orphan storylines on old factory +-- 5. Delete page views for orphan storylines on v4b factory DELETE FROM page_views WHERE storyline_id BETWEEN 25 AND 33 - AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + AND lower(contract_address) = lower('0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf'); -- 6. Delete trade history for orphan storylines DELETE FROM trade_history WHERE storyline_id BETWEEN 25 AND 33; --- 7. Delete the orphan storylines on old factory (last, after FK-dependent deletes) +-- 7. Delete the orphan storylines on v4b factory (last, after FK-dependent deletes) DELETE FROM storylines WHERE storyline_id BETWEEN 25 AND 33 - AND lower(contract_address) = lower('0x92c3bd44fda84e632c3c3cb31387d0c0c1de618d'); + AND lower(contract_address) = lower('0x9D2AE1E99D0A6300bfcCF41A82260374e38744Cf'); -- 8. Clean up backfill_failures for orphan storylines DELETE FROM backfill_failures WHERE storyline_id BETWEEN 25 AND 33;