Skip to content

CUR2-1935: sui transfers fix#9517

Merged
tomfutago merged 12 commits intomainfrom
CUR2-1935-sui-transfers-fix
Apr 6, 2026
Merged

CUR2-1935: sui transfers fix#9517
tomfutago merged 12 commits intomainfrom
CUR2-1935-sui-transfers-fix

Conversation

@tomfutago
Copy link
Copy Markdown
Contributor

@tomfutago tomfutago commented Apr 2, 2026

Thank you for contributing to Spellbook 🪄

Please open the PR in draft and mark as ready when you want to request a review.

Description:

  • refactor baseline (per feat: add SUI USDC stablecoin transfer model #9521): reworked sui transfer lineage to follow event-native supply handling from sui.events (treasury::mint/treasury::burn) instead of heuristic supply tagging

  • tokens_sui_coin_object_history: kept lineage behavior but aligned branch config/windowing for the ci test slice used in this refactor

  • tokens_sui_object_event_deltas: refactored to optimise deleted-object handling to build anchors from active-window object ids first, then prune deleted rows that cannot survive downstream lag filtering

  • tokens_sui_owner_net_transfers: use object events to build tx context, so we don’t miss transfers when direct data is empty

  • tokens_sui_supply_events: added new event-native mint/burn model and removed tokens_sui_supply_signals; parses amount/coin/event direction directly from treasury events

  • tokens_sui_base_transfers: switched from supply-signal enrichment to a union of non-supply object lineage rows plus event-native supply rows, and adjusted supply dedupe/matching around tx+coin+direction+amount

  • tokens_sui_transfers: use raw from/to instead of filled-in from_resolved/to_resolved - this means more nulls, but fewer fake addresses/self-transfers

  • seed test records were added/updated to cover rows that were previously incorrect and are now corrected by this change


quick links for more information:

@github-actions github-actions Bot added WIP work in progress dbt: tokens covers the Tokens dbt subproject labels Apr 2, 2026
@tomfutago tomfutago marked this pull request as ready for review April 2, 2026 13:57
@cursor
Copy link
Copy Markdown

cursor Bot commented Apr 2, 2026

PR Summary

High Risk
Refactors core Sui transfer/supply accounting (mint/burn detection, base transfer assembly, and final from/to fields), which can materially change downstream balances and analytics. Also removes prod_exclude tags and shifts the start date window (currently set to 2026-01-01), increasing the risk of unintended production execution/coverage gaps if not reverted before merge.

Overview
Reworks Sui supply tracking to be event-native. Replaces the heuristic tokens_sui_supply_signals model with a new tokens_sui_supply_events model that parses treasury::mint/treasury::burn directly from sui.events (including per-event event_index, sender/recipient, and amount_raw).

Refactors tokens_sui_base_transfers composition. Base transfers now union non-supply object/owner-net lineage rows with the new event-native mint/burn rows, and introduces matching/ranking logic to drop legacy supply-like object rows when equivalent supply events exist (matched by tx+coin+amount+direction).

Tightens lineage and output semantics. tokens_sui_object_event_deltas changes deleted-object anchoring/pruning, tokens_sui_owner_net_transfers builds tx context from object events (not only direct transfers), and tokens_sui_transfers now surfaces raw from/to (allowing more nulls to avoid inferred/self-transfer artifacts). Seed expectations were updated accordingly.

Reviewed by Cursor Bugbot for commit 5b846fa. Configure here.

@github-actions github-actions Bot added ready-for-review this PR development is complete, please review and removed WIP work in progress labels Apr 2, 2026
@tomfutago tomfutago requested a review from 0xRobin April 2, 2026 13:59
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: CI test date accidentally committed to production code
    • Restored sui_transfer_start_date to 2023-04-12 and removed the temporary CI-only comment in all three affected Sui transfer models.

Create PR

Or push these changes by commenting:

@cursor push 5ba09020f2
Preview (5ba09020f2)
diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
@@ -12,7 +12,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with
 

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_owner_net_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_owner_net_transfers.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_owner_net_transfers.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_owner_net_transfers.sql
@@ -12,7 +12,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with
 

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_transfers.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_transfers.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_transfers.sql
@@ -13,7 +13,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with

You can send follow-ups to this agent here.

Copy link
Copy Markdown
Collaborator

@0xRobin 0xRobin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is a data quality fix, can we add seed test records that were previously incorrect and are now corrected by this change?

@tomfutago
Copy link
Copy Markdown
Contributor Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Window function inside CASE inflates candidate rank numbers
    • Replaced row_number() with a running SUM of candidate-only flags so candidate_rank increments only across candidate transfer types within each partition.

Create PR

Or push these changes by commenting:

@cursor push c0a4e7bc20
Preview (c0a4e7bc20)
diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
@@ -231,9 +231,20 @@
         'ownership_balance_topup',
         'ownership_balance_spend'
       )
-      then row_number() over (
+      then sum(
+        case
+          when o.transfer_type in (
+            'object_created',
+            'object_deleted',
+            'ownership_balance_topup',
+            'ownership_balance_spend'
+          ) then 1
+          else 0
+        end
+      ) over (
         partition by o.tx_digest, o.coin_type_normalized, o.amount_raw, o.transfer_direction
         order by o.unique_key
+        rows between unbounded preceding and current row
       )
       else cast(null as bigint)
     end as candidate_rank

You can send follow-ups to the cloud agent here.

@tomfutago
Copy link
Copy Markdown
Contributor Author

bugbot run

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Test-only start date committed across all production models
    • Restored sui_transfer_start_date from the CI test value 2026-01-01 to the production value 2023-04-12 in all eight affected Sui transfer models.

Create PR

Or push these changes by commenting:

@cursor push 54a03b74cd
Preview (54a03b74cd)
diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/sui_coin_info.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/sui_coin_info.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/sui_coin_info.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/sui_coin_info.sql
@@ -10,7 +10,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 -- ranking policy:
 -- choose the most recent metadata snapshot first (checkpoint/version),

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_base_transfers.sql
@@ -12,7 +12,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with
 

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_coin_object_history.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_coin_object_history.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_coin_object_history.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_coin_object_history.sql
@@ -12,7 +12,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with
 

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_direct_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_direct_transfers.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_direct_transfers.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_direct_transfers.sql
@@ -12,7 +12,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with
 

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_object_event_deltas.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_object_event_deltas.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_object_event_deltas.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_object_event_deltas.sql
@@ -12,7 +12,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with
 

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_owner_net_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_owner_net_transfers.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_owner_net_transfers.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_owner_net_transfers.sql
@@ -12,7 +12,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with
 

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_supply_events.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_supply_events.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_supply_events.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_supply_events.sql
@@ -12,7 +12,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with
 

diff --git a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_transfers.sql b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_transfers.sql
--- a/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_transfers.sql
+++ b/dbt_subprojects/tokens/models/transfers_and_balances/sui/tokens_sui_transfers.sql
@@ -13,7 +13,7 @@
   )
 }}
 
-{% set sui_transfer_start_date = '2026-01-01' %} -- just ci test
+{% set sui_transfer_start_date = '2023-04-12' %}
 
 with

You can send follow-ups to the cloud agent here.

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 5b846fa. Configure here.

@tomfutago tomfutago requested a review from 0xRobin April 6, 2026 10:35
Copy link
Copy Markdown
Collaborator

@0xRobin 0xRobin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@tomfutago tomfutago merged commit d0809f7 into main Apr 6, 2026
2 of 3 checks passed
@tomfutago tomfutago deleted the CUR2-1935-sui-transfers-fix branch April 6, 2026 12:04
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

dbt: tokens covers the Tokens dbt subproject ready-for-review this PR development is complete, please review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants