Repository navigation
feat(builder): add withCliffDate() for Date/ISO cliff configuration - #1118
Open
arkhindi12 wants to merge 1 commit into
Open
arkhindi12 wants to merge 1 commit into
arkhindi12 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
StreamBuilder.withCliffDate(date: Date | string | number)so callers can configure a vesting cliff from aDate, 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 manualMath.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 existingstartTime(). 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
startTimeis set to the cliff end so nothing accrues before it. That is the model already documented forCliffReachedinsrc/events.tsand used byexamples/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-DDstring, numeric seconds, numeric stringstartTimerounding stays integral.startTime(seconds)for bothbuild()andtoContractArgs()Date, non-integer, negativereset()clears it;clone()preserves itFull suite:
1856 passed, 1 failed— the single failure issrc/tests/custom-fetch.test.ts > keeps non-2xx status visible so 429s still map to RateLimitError(10s timeout). It fails identically on a cleanmainwith this change stashed, so it is pre-existing and unrelated.npx tsc -p tsconfig.json --noEmitexits 0.Notes
No new dependencies, no API removed, no change to existing
startTime()semantics.