Skip to content

feat(builder): add withCliffDate() for Date/ISO cliff configuration - #1118

Open
arkhindi12 wants to merge 1 commit into
conduit-protocol:mainfrom
arkhindi12:feat/builder-cliff-date-1064
Open

arkhindi12 wants to merge 1 commit into
conduit-protocol:mainfrom
arkhindi12:feat/builder-cliff-date-1064

Conversation

@arkhindi12

Copy link
Copy Markdown
Contributor

Summary

Adds StreamBuilder.withCliffDate(date: Date | string | number) so callers can configure a vesting cliff from a Date, an ISO-8601/date string, or raw Unix seconds, without hand-computing timestamps.

Closes #1064.

Why

The issue asks for .withCliffDate() alongside the existing timestamp path. The manual Math.floor(date.getTime() / 1000) conversion is the usual source of two bugs: milliseconds passed where seconds are expected, and a date interpreted in the wrong timezone.

How

withCliffDate() resolves its argument to integer Unix seconds and delegates to the existing startTime(). Everything downstream — the past-date guard, build() output, toContractArgs(), reset(), clone() — is therefore the same code path as .startTime(seconds), not a parallel implementation. There is no new state on the builder.

A vesting cliff here is a client-side scheduling convention rather than contract state: the stream's startTime is set to the cliff end so nothing accrues before it. That is the model already documented for CliffReached in src/events.ts and used by examples/vesting-schedule.ts, so the method name matches existing vocabulary.

One detail worth flagging: a digit-only string is read as absolute Unix seconds, not passed to new Date(). new Date("1893456000") parses as a year, which would silently produce a 1970s cliff; there is a test pinning this.

Tests

New file src/tests/builder-cliff-date.test.ts, 16 cases:

  • Date, ISO string, YYYY-MM-DD string, numeric seconds, numeric string
  • sub-second truncation; startTime rounding stays integral
  • equivalence with .startTime(seconds) for both build() and toContractArgs()
  • rejection: past date, empty/blank string, unparseable string, invalid Date, non-integer, negative
  • reset() clears it; clone() preserves it
$ npx vitest run src/tests/builder-cliff-date.test.ts
 Test Files  1 passed (1)
      Tests  16 passed (16)

Full suite: 1856 passed, 1 failed — the single failure is src/tests/custom-fetch.test.ts > keeps non-2xx status visible so 429s still map to RateLimitError (10s timeout). It fails identically on a clean main with this change stashed, so it is pre-existing and unrelated.

npx tsc -p tsconfig.json --noEmit exits 0.

Notes

No new dependencies, no API removed, no change to existing startTime() semantics.

Configuring a cliff previously required hand-computing Unix seconds, which
invites timezone and seconds-vs-milliseconds mistakes. withCliffDate()
accepts a Date, an ISO/date string, or raw seconds and delegates to
startTime(), so the resulting validation, build() output, contract args,
reset() and clone() behaviour are all identical to the existing path.

A vesting cliff is a client-side scheduling convention rather than contract
state (see the CliffReached docs in events.ts): the stream's startTime is set
to the cliff end so nothing accrues before it. This method only removes the
manual conversion step.

Digit-only strings are read as absolute Unix seconds rather than being handed
to new Date(), which would parse them as a year.

Refs conduit-protocol#1064

This branch has not been deployed

No deployments
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.

src/builder.ts: implement fluent builder method for stream cliff configuration with date parsing

1 participant