Skip to content

Conversation

@youngkidwarrior
Copy link
Collaborator

@youngkidwarrior youngkidwarrior commented Oct 4, 2025

Why:
- Track SEND balances and hodler verification to support rewards
  logic while preserving precision.
- Keep balances/weights as string|bigint end‑to‑end to avoid Number
  coercion and on‑chain precision loss.
- Use a token_key for reliable upserts (ERC‑20 and native) under a
  single unique key; avoid NULL‑uniqueness pitfalls and complex
  partial indexes.
- Update only on deposits in receive triggers; internal transfers are
  handled by workflows, preventing double counting.
- Do not backfill send_token_hodler into past distributions; require
  it only for new distributions (id >= 21).

Changes:
- Temporal workflows
  - Add readBalanceActivity and persistBalanceActivity (SEND‑only,
    gated via base chain and sendTokenAddress).
  - Add upsertSendTokenHodlerVerificationActivity and apply to both
    sender and receiver post‑confirmation.
  - Fix dvError handling; remove stray casts; wire error handling via
    isRetryableDBError.
- Types & lint
  - Widen Supabase overrides so writes accept number|string|bigint for
    token_balances.balance and distribution_verifications.weight; keep
    generated Row types as number.
  - Remove problematic casts/usages; escape quotes; simplify imports;
    fix onScrub prop usage; yarn lint passes cleanly.
- Schema & migrations
  - Create token_balances with RLS, generated token_key, and unique
    (user_id,token_key) for simple upserts; add helpful indexes.
  - Add deposit‑only trigger on send_account_receives to upsert native
    balances; exclude internal transfers (sender is a Send Account).
  - Fix backfill CTE scope (eth_dep) to avoid relation errors; keep
    new hodler backfill a no‑op.
- Tests
  - Add pgtap test asserting send_token_hodler exists for all
    distributions with id >= 21.

Test plan:
- yarn lint → no errors.
- yarn supabase test → distribution_send_token_hodler_test passes; other
  tag tests remain unchanged.
- Manual: run a SEND transfer; verify:
  - token_balances upserted for both addresses (correct user, chain,
    token/native), RLS allows owner to read.
  - distribution_verifications upserted for both parties with type
    send_token_hodler and weight preserved as string|bigint.

Copy link
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Why:
- Track SEND balances and hodler verification to support rewards
  logic while preserving precision.
- Keep balances/weights as string|bigint end‑to‑end to avoid Number
  coercion and on‑chain precision loss.
- Use a token_key for reliable upserts (ERC‑20 and native) under a
  single unique key; avoid NULL‑uniqueness pitfalls and complex
  partial indexes.
- Update only on deposits in receive triggers; internal transfers are
  handled by workflows, preventing double counting.
- Do not backfill send_token_hodler into past distributions; require
  it only for new distributions (id >= 21).

Changes:
- Temporal workflows
  - Add readBalanceActivity and persistBalanceActivity (SEND‑only,
    gated via base chain and sendTokenAddress).
  - Add upsertSendTokenHodlerVerificationActivity and apply to both
    sender and receiver post‑confirmation.
  - Fix dvError handling; remove stray casts; wire error handling via
    isRetryableDBError.
- Types & lint
  - Widen Supabase overrides so writes accept number|string|bigint for
    token_balances.balance and distribution_verifications.weight; keep
    generated Row types as number.
  - Remove problematic casts/usages; escape quotes; simplify imports;
    fix onScrub prop usage; yarn lint passes cleanly.
- Schema & migrations
  - Create token_balances with RLS, generated token_key, and unique
    (user_id,token_key) for simple upserts; add helpful indexes.
  - Add deposit‑only trigger on send_account_receives to upsert native
    balances; exclude internal transfers (sender is a Send Account).
  - Fix backfill CTE scope (eth_dep) to avoid relation errors; keep
    new hodler backfill a no‑op.
- Tests
  - Add pgtap test asserting send_token_hodler exists for all
    distributions with id >= 21.

Test plan:
- yarn lint → no errors.
- yarn supabase test → distribution_send_token_hodler_test passes; other
  tag tests remain unchanged.
- Manual: run a SEND transfer; verify:
  - token_balances upserted for both addresses (correct user, chain,
    token/native), RLS allows owner to read.
  - distribution_verifications upserted for both parties with type
    send_token_hodler and weight preserved as string|bigint.
@youngkidwarrior youngkidwarrior force-pushed the temporal-driven_send_balances_hodler_dv branch from ff481c0 to 13989b0 Compare October 4, 2025 04:18
@youngkidwarrior youngkidwarrior changed the title chore(migration): reorder enum change and re-add FK; qualify trigger function db/workflows: hodler verify + token balances RLS Oct 4, 2025
@github-actions
Copy link

github-actions bot commented Oct 4, 2025

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants