forked from Anastasia-Labs/production-grade-dapps
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Anastasia-Labs#29 from hadelive/linear-vesting
docs: update linear vesting documentation
- Loading branch information
Showing
2 changed files
with
84 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,83 @@ | ||
# Linear Vesting | ||
|
||
## Introduction | ||
|
||
Linear Vesting contract aims at providing a reliable mechanism for releasing Cardano Native Tokens gradually over a specified timeframe, with customization options to fit different requirements. | ||
|
||
With so many projects launching on Cardano, many a times, there arises a requirement of vesting a project's own tokens to either their core team or supporters of the project. Vesting assets to beneficiary in proportion to the elapsed time, i.e. Linear Vesting is a very straightforward and common preference. While there definitely exist more complex vesting requirements, we hope that the contract here will help those looking for something simple for their use case. Or serve as a reference for those who want to build more elaborate arrangements. | ||
|
||
This project is funded by the Cardano Treasury in [Catalyst Fund 10](https://projectcatalyst.io/funds/10/f10-developer-ecosystem-the-evolution/anastasia-labs-open-source-production-grade-dapps). | ||
|
||
## Key Features | ||
|
||
### Script | ||
|
||
```hs | ||
pvalidateVestingScript :: Term s (PVestingDatum :--> PVestingRedeemer :--> PScriptContext :--> PUnit) | ||
``` | ||
|
||
The linear vesting validator is not a parameterized one. All its customization needs are fulfilled by the datum (`VestingDatum`) of the locked UTxO. | ||
|
||
### VestingDatum: | ||
|
||
This data structure holds the details of the vesting arrangement, including the beneficiary's address, the asset class of the tokens being vested, the total quantity of tokens, the start and end of the vesting period, the earliest point at which tokens can be unlocked, and the total number of installments. | ||
|
||
```hs | ||
data VestingDatum = VestingDatum | ||
{ beneficiary :: Address | ||
, vestingAsset :: AssetClass | ||
, totalVestingQty :: Integer | ||
, vestingPeriodStart :: Integer | ||
, vestingPeriodEnd :: Integer | ||
, firstUnlockPossibleAfter :: Integer | ||
, totalInstallments :: Integer | ||
} | ||
``` | ||
|
||
### VestingRedeemer: | ||
|
||
A single UTxO at the validator address corresponds to a single vesting arrangement. There can be multiple such UTxOs present there to facilitate multiple vestings. A single vesting UTxO can however only release tokens of a single Fungible Token, specified by `vestingAsset` field. | ||
|
||
After `firstUnlockPossibleAfter` and before `vestingPeriodEnd`, beneficiary can claim the vested asset in proportion to the time that has passed after `vestingPeriodStart`. The remaining assets needs to be sent back to the validator address with the original datum intact otherwise the validation will fail. This spending tx requires `PartialUnlock` redeemer. | ||
|
||
```hs | ||
data VestingRedeemer | ||
= PartialUnlock | ||
| FullUnlock | ||
``` | ||
|
||
After the `vestingPeriodEnd`, beneficiary can claim the entire remaining balance at the UTxO using `FullUnlock` redeemer. | ||
|
||
```mermaid | ||
sequenceDiagram | ||
participant P as Project | ||
participant V as Vesting Contract | ||
participant B as Beneficiary | ||
|
||
P->>V: Create Vesting UTxO with VestingDatum | ||
|
||
loop During Vesting Period | ||
B->>V: Request Partial Unlock | ||
V->>B: Release tokens proportional to elapsed time | ||
end | ||
|
||
Note over B,V: After vestingPeriodEnd | ||
|
||
B->>V: Request Full Unlock | ||
V->>B: Release all remaining tokens | ||
``` | ||
|
||
import { Callout } from "nextra/components"; | ||
|
||
<Callout type="warning" emoji="⚠️"> | ||
An important thing to note about the validator is that it only allows one | ||
script input to be spent in a single tx. Allowing more than one script input | ||
to be spent within it, could result in a critical vulnerability in the form of | ||
[Double Satisfaction | ||
Attack](https://plutus.readthedocs.io/en/latest/reference/writing-scripts/common-weaknesses/double-satisfaction.html?highlight=double#unique-outputs) | ||
by spending two vesting UTxOs with the exact datum. | ||
</Callout> | ||
|
||
## Conclusion | ||
|
||
This resource aims to provide a clear understanding of the Linear Vesting contract's functionality, its components, and the operational flow, supplemented by a visual representation to aid in comprehension. |
This file contains 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