@nathamcrewott/vestlang
v0.3.3
Published
A domain-specific language for modeling vesting schedules
Maintainers
Readme
@nathamcrewott/vestlang
A domain-specific language for modeling vesting schedules.
Installation
npm install @nathamcrewott/vestlangUsage
import { parse, normalizeProgram, evaluateStatement } from "@nathamcrewott/vestlang";
const source = "VEST FROM EVENT grant OVER 4 years EVERY 1 month CLIFF 1 year";
const program = normalizeProgram(parse(source));
const schedule = evaluateStatement(program[0], {
events: { grantDate: "2024-01-01" },
grantQuantity: 10000,
asOf: "2028-01-01",
allocation_type: "CUMULATIVE_ROUND_DOWN",
});
console.log(schedule.installments);API
Parsing
parse(source: string)- Parse vestlang source into a raw AST
Normalization
normalizeProgram(program)- Normalize a parsed program into its canonical, deterministic shape
Evaluation
evaluateStatement(statement, context)- Evaluate a single statementevaluateProgram(program, context)- Evaluate an entire programevaluateStatementAsOf(statement, context)- Evaluate a statement as of a specific date
Inference (the inverse of evaluation)
inferSchedule(input)- Reconstruct a vestlang program from observed{ date, amount }vesting tranches via matching-pursuit decomposition. Returns{ dsl, program, decomposition, diagnostics }, wherediagnosticsreports the residual error and any fallbacks taken.
Stringify
stringify(node)- Render an AST node back to vestlang DSL sourcestringifyProgram(program)- Render a whole program to DSL sourcestringifyStatement(statement)- Render a single statement to DSL source
Linting
lintProgram(program, options?)- Lint a normalized programlintText(source, parser, options?)- Lint source text
Types
The package exports commonly used types:
Programs & statements
Program- A normalized list of statementsRawProgram- A parsed-but-not-yet-normalized program (the output ofparse)Statement- A single vesting statementSchedule- A vesting schedule
Evaluation
EvaluationContextInput- Input context for evaluationEvaluatedSchedule- Result of evaluating a scheduleInstallment- A single vesting installmentResolvedInstallment/UnresolvedInstallment/ImpossibleInstallment- The installment statesVestedResult- Vested/unvested quantities produced by evaluationBlocker- A blocking condition preventing vestingOCTDate- An ISOYYYY-MM-DDdate string
Linting
Diagnostic- A single lint findingLintResult- The result of a lint runLintOptions- Lint configuration
Inference
InferInput- Input toinferSchedule(tranches, plus optionalgrantDate/ policy hints)InferResult- Output ofinferSchedule(dsl,program,decomposition,diagnostics)TrancheInput- A single observed{ date, amount }trancheComponent- A decomposition component:UniformComponent|SingleTrancheComponent|CliffUniformComponent
License
MIT
