Skip to content

Commit

Permalink
Merge pull request Anastasia-Labs#29 from hadelive/linear-vesting
Browse files Browse the repository at this point in the history
docs: update linear vesting documentation
  • Loading branch information
hadelive authored Feb 19, 2024
2 parents 48544df + 296187d commit b52c199
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 1 deletion.
83 changes: 83 additions & 0 deletions pages/linear_vesting.mdx
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.
2 changes: 1 addition & 1 deletion pages/single_asset_staking.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ As the name suggests, it allows for a single asset, which can be any Cardano Nat

Instead of a fixed percentage based return, the staking reward obtained is not known beforehand. Because its determined by the total amount of assets staked till the end of the staking period and the total rewards locked before staking begins. Eligible participants are then given rewards propotional to their share of stake (`(userStake * totalRewards) / totalStake`).

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).
These 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).

# Overview

Expand Down

0 comments on commit b52c199

Please sign in to comment.