smart-chain-fr / tokenomia

Tokenomia is built for the Cardashift ICO, it aims to simplify the use of Native Tokens and Smart Contracts above the Cardano Platform. Cardashift is a community-driven startup platform that raises funds, builds and accelerates startups that solve social and environmental problems.
Apache License 2.0
76 stars 27 forks source link

Vesting Feature Improvement #74

Open devfull opened 2 years ago

devfull commented 2 years ago

Overview

This task is to fix and improve the vesting feature. The current data structure used in the native script generation module has several flaws.

Changed Specification

The new specification gives the following datatypes. Note the proximity between PrivateSale and PrivateSaleTranche.

type Allocation = Natural

newtype InvestorAddress = InvestorAddress { unInvestorAddress :: Text }

data TrancheProperties = TrancheProperties
    { proportion :: Ratio Natural
    , unlockTime :: POSIXTime
    }

data PrivateSale = PrivateSale
    { tranchesProperties :: NonEmpty TrancheProperties
    , assetClass :: AssetClass
    , allocationByAddress :: NEMap InvestorAddress Allocation
    }

data PrivateSaleTranche = PrivateSaleTranche
    { trancheUnlockTime :: POSIXTime
    , trancheAssetClass :: AssetClass
    , trancheAllocationByAddress :: NEMap InvestorAddress Allocation
    }

data NativeScript = NativeScript
    { requireSignature :: PubKeyHash
    , requireTimeAfter :: POSIXTime
    }

data NativeScriptInfo = NativeScriptInfo
    { requiring :: NativeScript
    , recipient :: Recipient
    }

data DatabaseOutput = DatabaseOutput
    { lockedAssetClass :: AssetClass
    , lockedFunds :: NEMap InvestorAddress (NonEmpty NativeScriptInfo)
    }

Features

The resolution of this issue requires the following tasks:

Minimum UTxO

The calculation of the minimum UTxO is a feature frequently needed. The issue is furthermore to improve the way of obtaining this value by not depending anymore on cardano-cli and use instead Cardano.Api.

For user-friendliness, calculateMinimumUTxO is reimplemented for accepting simple value or asset class instead of fully constructed TxOut that requires valid address. This implies the following tasks:

The validity of the calculation is based on the source Cardano/Api/Fees.hs and the documentation from cardano-ledger (after fixing a small typo with input-output-hk/cardano-ledger#3012).

Tests

In order to write the tests, the following extra components are required: