-
Notifications
You must be signed in to change notification settings - Fork 178
Add Vesting #425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add Vesting #425
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
1b90b72
Add vesting
immrsd 3339094
Add function for uint validation
immrsd 3712400
Minor Governor fixes
immrsd 14efb47
Support Vesting
immrsd b66b2c6
Add vesting generators
immrsd 2db8cfb
Add vesting page
immrsd 3247bcd
Add Vesting test cases
immrsd 5248e17
Fix issues
immrsd 6d7bbc4
Fix test snapshots
immrsd 4d5a3d5
Update changelog
immrsd 2112bbf
Fix compilation issue
immrsd 17645fd
Fix tips
immrsd 5e093d8
Apply style to datetime-local
ericglau f823667
Add guards for unhandled new contract kinds
immrsd f2f6270
Merge branch 'vesting-wallet' of github.com:immrsd/contracts-wizard i…
immrsd 5481389
Update changelog date
ericglau 600ab6a
Fix vesting generate options
immrsd 6e9cedf
Merge branch 'vesting-wallet' of github.com:immrsd/contracts-wizard i…
immrsd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { infoOptions } from '../set-info'; | ||
| import type { VestingOptions } from '../vesting'; | ||
| import { generateAlternatives } from './alternatives'; | ||
|
|
||
| const blueprint = { | ||
| name: ['MyVesting'], | ||
| startDate: ['2024-12-31T23:59'], | ||
| duration: ['90 days', '1 year'], | ||
| cliffDuration: ['0 seconds', '30 day'], | ||
| schedule: ['linear', 'custom'] as const, | ||
| info: infoOptions | ||
| }; | ||
|
|
||
| export function* generateVestingOptions(): Generator<Required<VestingOptions>> { | ||
| yield* generateAlternatives(blueprint); | ||
| } |
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ const secondsForUnit = { second, minute, hour, day, week, month, year }; | |
| export function durationToTimestamp(duration: string): number { | ||
| const match = duration.trim().match(durationPattern); | ||
|
|
||
| if (!match) { | ||
| if (!match || match.length < 2) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there cases where a happy
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| throw new Error('Bad duration format'); | ||
| } | ||
|
|
||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import test from 'ava'; | ||
| import { OptionsError, vesting } from '.'; | ||
| import { buildVesting, VestingOptions } from './vesting'; | ||
| import { printContract } from './print'; | ||
|
|
||
| const defaults: VestingOptions = { | ||
| name: 'MyVesting', | ||
| startDate: '', | ||
| duration: '0 day', | ||
| cliffDuration: '0 day', | ||
| schedule: 'linear' | ||
| }; | ||
|
|
||
| const CUSTOM_NAME = 'CustomVesting'; | ||
| const CUSTOM_DATE = '2024-12-31T23:59'; | ||
| const CUSTOM_DURATION = '36 months'; | ||
| const CUSTOM_CLIFF = '90 days'; | ||
|
|
||
| // | ||
| // Test helpers | ||
| // | ||
|
|
||
| function testVesting(title: string, opts: Partial<VestingOptions>) { | ||
| test(title, t => { | ||
| const c = buildVesting({ | ||
| ...defaults, | ||
| ...opts | ||
| }); | ||
| t.snapshot(printContract(c)); | ||
| }); | ||
| } | ||
|
|
||
| function testAPIEquivalence(title: string, opts?: VestingOptions) { | ||
| test(title, t => { | ||
| t.is(vesting.print(opts), printContract(buildVesting({ | ||
| ...defaults, | ||
| ...opts | ||
| }))); | ||
| }); | ||
| } | ||
|
|
||
| // | ||
| // Snapshot tests | ||
| // | ||
|
|
||
| testVesting('custom name', { | ||
| name: CUSTOM_NAME, | ||
| }); | ||
|
|
||
| testVesting('custom start date', { | ||
| startDate: CUSTOM_DATE | ||
| }); | ||
|
|
||
| testVesting('custom duration', { | ||
| duration: CUSTOM_DURATION | ||
| }); | ||
|
|
||
| testVesting('custom cliff', { | ||
| duration: CUSTOM_DURATION, | ||
| cliffDuration: CUSTOM_CLIFF | ||
| }); | ||
|
|
||
| testVesting('custom schedule', { | ||
| schedule: 'custom' | ||
| }); | ||
|
|
||
| testVesting('all custom settings', { | ||
| startDate: CUSTOM_DATE, | ||
| duration: CUSTOM_DURATION, | ||
| cliffDuration: CUSTOM_CLIFF, | ||
| schedule: 'custom' | ||
| }); | ||
|
|
||
| // | ||
| // API tests | ||
| // | ||
|
|
||
| testAPIEquivalence('API custom name', { | ||
| ...defaults, | ||
| name: CUSTOM_NAME | ||
| }); | ||
|
|
||
| testAPIEquivalence('API custom start date', { | ||
| ...defaults, | ||
| startDate: CUSTOM_DATE | ||
| }); | ||
|
|
||
| testAPIEquivalence('API custom duration', { | ||
| ...defaults, | ||
| duration: CUSTOM_DURATION | ||
| }); | ||
|
|
||
| testAPIEquivalence('API custom cliff', { | ||
| ...defaults, | ||
| duration: CUSTOM_DURATION, | ||
| cliffDuration: CUSTOM_CLIFF | ||
| }); | ||
|
|
||
| testAPIEquivalence('API custom schedule', { | ||
| ...defaults, | ||
| schedule: 'custom' | ||
| }); | ||
|
|
||
| testAPIEquivalence('API all custom settings', { | ||
| ...defaults, | ||
| startDate: CUSTOM_DATE, | ||
| duration: CUSTOM_DURATION, | ||
| cliffDuration: CUSTOM_CLIFF, | ||
| schedule: 'custom' | ||
| }); | ||
|
|
||
| test('Vesting API isAccessControlRequired', async t => { | ||
| t.is(vesting.isAccessControlRequired({}), true); | ||
| }); | ||
|
|
||
| test('cliff too high', async t => { | ||
| const error = t.throws(() => buildVesting({ | ||
| ...defaults, | ||
| duration: '20 days', | ||
| cliffDuration: '21 days' | ||
| })); | ||
| t.is((error as OptionsError).messages.cliffDuration, 'Cliff duration must be less than or equal to the total duration'); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
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.

Uh oh!
There was an error while loading. Please reload this page.