Skip to content

Preload vesting contracts if before TDE#21

Merged
pkoch merged 1 commit intomasterfrom
feat/split-off-preload-from-tde
Mar 1, 2026
Merged

Preload vesting contracts if before TDE#21
pkoch merged 1 commit intomasterfrom
feat/split-off-preload-from-tde

Conversation

@pkoch
Copy link
Member

@pkoch pkoch commented Mar 1, 2026

Summary by CodeRabbit

  • New Features

    • Added configuration options for TDE disbursement block tracking and batch execution.
    • Added timestamp configuration for controlling disbursement eligibility.
  • Changes

    • Refactored TDE distribution workflow with improved environment setup and log fetching.
    • Removed directly calling vesting contract functionality.
  • Chores

    • Optimized internal variable naming and module organization.

@coderabbitai
Copy link

coderabbitai bot commented Mar 1, 2026

📝 Walkthrough

Walkthrough

Refactored TDE initial distribution scripts to introduce modular setup utilities, implement time-aware disbursement filtering, and simplify contract management by removing vesting logic. Added environment variables for deployment tracking and timestamp configuration while reorganizing disbursement workflows into dedicated functions.

Changes

Cohort / File(s) Summary
Environment Configuration
script/initial-distribution/.env.example
Added three environment variables: TDE_DISBURSEMENT_DEPLOYMENT_BLOCK, BATCH_CALLER_ADDRESS, and TDE_DATETIME for timestamped distribution control.
Utility Refactoring
script/initial-distribution/src/findPendingRows.ts
Renamed internal variables (counts → logCountsByKey, pending → pendingRows) for clarity; no algorithmic changes.
Core Distribution Script
script/initial-distribution/src/tde.ts
Refactored to use modular setupTdeEnvironment flow; replaced manual event pagination with centralized fetchDisbursementLogs; introduced time-based filtering (disbursableRows vs. skipped) to determine which rows are eligible for disbursement; simplified contract setup and approval logic.
New Module
script/initial-distribution/src/tdeSetup.ts
New file exporting four functions: setupTdeEnvironment (initializes chain context and contract instances), ensureAllowance (manages ERC20 approvals), disburseAll (executes batched disbursement transactions), and fetchDisbursementLogs (retrieves Disbursed event logs).
Removal
script/initial-distribution/src/vesting.ts
Completely removed; deleted VestingEntry type and functions readVestingContracts and ensureVestingContracts that were managing vesting contract creation and querying.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 Whiskers twitch with glee
Time-aware distribution flows so clean,
Vesting contracts bid goodbye,
Setup modules unified—
The TDE scripts now aligned! ✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title mentions preloading vesting contracts, but the changeset removes all vesting-related logic entirely and instead introduces TDE distribution setup with timestamp-based filtering. Update the title to reflect the actual changes, such as 'Refactor TDE distribution with timestamp filtering and batch execution' or 'Implement modular TDE setup with dynamic disbursement filtering'.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/split-off-preload-from-tde

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@script/initial-distribution/src/tde.ts`:
- Around line 56-58: The sequence ensureDelegation(batchConfig);
disburseAll(batchConfig, tdeDisbursementAddress, disbursableRows);
clearDelegation(batchConfig); must ensure clearDelegation always runs; wrap the
disbursement call in a try/finally so clearDelegation(batchConfig) is invoked in
the finally block (after ensureDelegation and regardless of errors from
disburseAll). Update the code around the calls to use try { await
disburseAll(...); } finally { await clearDelegation(batchConfig); } and preserve
awaiting ensureDelegation(...) before the try.

ℹ️ Review info

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00b313d and a552cb2.

📒 Files selected for processing (5)
  • script/initial-distribution/.env.example
  • script/initial-distribution/src/findPendingRows.ts
  • script/initial-distribution/src/tde.ts
  • script/initial-distribution/src/tdeSetup.ts
  • script/initial-distribution/src/vesting.ts
💤 Files with no reviewable changes (1)
  • script/initial-distribution/src/vesting.ts
📜 Review details
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-03-01T13:52:37.088Z
Learnt from: pkoch
Repo: idos-network/contracts PR: 19
File: script/initial-distribution/src/tde.ts:38-48
Timestamp: 2026-03-01T13:52:37.088Z
Learning: In script/initial-distribution, when using getContract({ client: walletClient }), it is possible to call read.* methods on the resulting contract even if walletClient is not explicitly extended with publicActions (as observed in tde.ts and cca.ts with viem 2.23.x). Treat this as an intentional pattern to verify: - confirm that the behavior is supported by the specific viem version and contract bindings, - document any assumptions about publicActions not being required for read operations, - ensure there are no security implications (e.g., unintended read access) and that access controls are still correct, - consider adding comments or tests that demonstrate expected usage and edge cases, and - if this behavior is relied upon in other files, apply the same pattern consistently within the script/initial-distribution directory.

Applied to files:

  • script/initial-distribution/src/findPendingRows.ts
  • script/initial-distribution/src/tde.ts
  • script/initial-distribution/src/tdeSetup.ts
📚 Learning: 2026-02-23T19:57:43.946Z
Learnt from: pkoch
Repo: idos-network/contracts PR: 13
File: src/WhaleDisburser.sol:23-28
Timestamp: 2026-02-23T19:57:43.946Z
Learning: In src/WhaleDisburser.sol, the disburse function intentionally has no access control. Anyone can call disburse(IERC20 token, address beneficiary, uint256 totalAmount, uint64 vestingStart), which is by design. The function uses safeTransferFrom(msg.sender, ...) so it only pulls from the caller's own balance, and no external funds are at risk.

Applied to files:

  • script/initial-distribution/src/tde.ts
🧬 Code graph analysis (3)
script/initial-distribution/src/findPendingRows.ts (1)
script/initial-distribution/src/csv.ts (1)
  • DisbursementRow (11-15)
script/initial-distribution/src/tde.ts (6)
script/initial-distribution/src/tdeSetup.ts (4)
  • setupTdeEnvironment (16-62)
  • fetchDisbursementLogs (100-118)
  • ensureAllowance (64-79)
  • disburseAll (81-98)
script/initial-distribution/src/csv.ts (2)
  • DisbursementRow (11-15)
  • loadDisbursementCsv (34-55)
script/initial-distribution/src/modalities.ts (2)
  • EVMModality (21-32)
  • EVMModality (33-33)
script/initial-distribution/src/findPendingRows.ts (1)
  • findPendingRows (8-31)
script/initial-distribution/src/lib.ts (1)
  • sumOf (53-55)
script/initial-distribution/src/batch.ts (1)
  • ensureDelegation (165-192)
script/initial-distribution/src/tdeSetup.ts (5)
script/initial-distribution/src/lib.ts (6)
  • requireEnv (3-7)
  • ensureHex (10-16)
  • iso8601ToTimestamp (44-51)
  • receiptFor (70-77)
  • paginatedGetEvents (135-149)
  • requiredArgs (20-31)
script/initial-distribution/src/chains.ts (1)
  • chainSetup (36-51)
script/initial-distribution/src/batch.ts (1)
  • BatchCallerConfig (38-42)
script/initial-distribution/src/abis.ts (2)
  • tdeDisbursementAbi (203-255)
  • erc20Abi (276-323)
script/initial-distribution/src/csv.ts (1)
  • DisbursementRow (11-15)
🔇 Additional comments (3)
script/initial-distribution/src/findPendingRows.ts (1)

12-30: Good rename and count-tracking cleanup.

logCountsByKey/pendingRows makes intent clearer, and the decrement logic still correctly handles duplicate disbursements.

script/initial-distribution/.env.example (1)

22-29: Config additions are clear and aligned with runtime behavior.

These new env vars are well-described and map cleanly to deployment-block scanning, batch execution, and TDE-time filtering.

script/initial-distribution/src/tdeSetup.ts (1)

40-50: ⚠️ Potential issue | 🔴 Critical

Fix contract instantiation for read operations: walletClient does not support .read methods.

getContract({ client: walletClient }) does not include .read methods in viem v2.23.x—only publicClient or { public: publicClient, wallet: walletClient } provide read access. Lines 40–50 call contract.read.IDOS_TOKEN() and line 71 calls contract.read.allowance() on walletClient-only instances, which violates viem's API contract.

Fix by either:

  1. Extending walletClient with publicActions: walletClient.extend(publicActions)
  2. Creating read contracts with publicClient: getContract({ client: publicClient, ... })
  3. Using the dual-client pattern: getContract({ client: { public: publicClient, wallet: walletClient }, ... })
⛔ Skipped due to learnings
Learnt from: pkoch
Repo: idos-network/contracts PR: 19
File: script/initial-distribution/src/tde.ts:38-48
Timestamp: 2026-03-01T13:52:37.088Z
Learning: In the idos-network/contracts repository, the team uses `getContract({ client: walletClient })` and successfully calls `.read.*` methods on the resulting contract instances in viem 2.23.x, even though the walletClient is not explicitly extended with publicActions. This pattern is used throughout script/initial-distribution/src/ (tde.ts, cca.ts).

@pkoch pkoch merged commit 57b0cea into master Mar 1, 2026
3 checks passed
@pkoch pkoch deleted the feat/split-off-preload-from-tde branch March 1, 2026 18:24
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.

1 participant