Smart Contract
A smart contract is a program that automatically executes and enforces agreement conditions on the blockchain. Its code is stored and executed in the network, without intermediaries, according to predefined rules.General Information
Blockchain: SolanaRepository: https://github.com/whalescorp/holders-vesting-sol/\\\\ Language:Rust
License: MIT
Contract Operation Flowchart
(1).png?fit=max&auto=format&n=Ev4p22cRFxlmwX97&q=85&s=f5335b5c36df7f9d9b819d41585f4046)
- Vesting Creation:
- User initiates vesting creation.
- Information is passed to the Issuer and then to the database (DB), where the record is saved with “PENDING” status.
- Contract Deployment:
- Database notifies ChainManager about the need for contract deployment.
- ChainManager initiates contract deployment on the blockchain.
- After successful deployment, the status is updated to “ACTIVE”.
- Deposit Funding:
- User deposits tokens into the contract.
- This action is registered in the database.
- Token Distribution:
- A portion of tokens is paid out to the user.
- ChainManager receives information from the blockchain that the payout has been completed.
- ChainManager notifies the Issuer that the payout has been completed.
- Issuer passes information about the payout and updated balance to the database and decides whether to initiate the next cycle.
Contract Roles
- Config Authority:
- Responsible for creating and managing vesting configurations.
- Has the right to set the controller.
- Controller:
- Participant who manages a specific configuration and can perform vesting-related operations.
- Can create new vestings and add or remove beneficiaries.
- Grantor:
- Person or address that creates a specific vesting.
- Can add beneficiaries and initiate payouts.
- Beneficiary:
- Receives tokens according to the vesting schedule.
- Can participate in receiving tokens during their distribution.
Main Operations and Scenarios
- Configuration creation (
create_config) - initialization of a new vesting configuration with specific parameters, including configurator and controller. - Controller change (
set_controller) - updating the controller for an existing configuration. - Vesting creation (
create_vesting) - initialization of a new vesting, defining parameters such as token distribution time, nominal amount, and inflation. - Adding beneficiary (
add_beneficiary) - adds a new beneficiary to an existing vesting, while checking that the number of beneficiaries does not exceed maximum limits. - Removing beneficiary (
remove_beneficiary) - removes a beneficiary from the vesting recipients list, ensuring that minimum requirements for the number of beneficiaries are met. - Token claim (
claim) - allows a beneficiary to request tokens according to vesting conditions, checking available funds and time constraints.
Inflation Calculation
TheVestingV0 structure has an inflation_rate_per_interval field that is responsible for the inflation percentage. This parameter allows setting inflation rates for a given interval.The
total_release_amount_with_inflation_at method in the VestingV0 structure calculates the total amount of tokens that can be released, taking into account the specified inflation:
Data Structure
Config
bump: Used to ensure account uniqueness (method for working with addresses).seqno: Sequential configuration number.authority: Configuration owner address.controller: Address of the controller managing the configuration.
Vesting
bump: Like inConfig, used to avoid collisions when creating an account.seqno: Sequential vesting number.config: Reference to the configuration account with which the vesting is associated.mint: Address of the token to be vested.grantor: Address of the vesting creator.beneficiaries: List of token recipient addresses.started_at: Vesting start time in Unix timestamp format.cliff_until: End time of the “cliff” period (time block during which tokens cannot be received).release_interval: Time interval between token releases.nominal_release_amount: Nominal amount to be released.inflation_rate_per_interval: Inflation percentage for each interval.total_transferred_amount: Amount that has already been transferred to beneficiaries.
Gas
Contract Creation and Maintenance
In Holders, when creating contracts in Solana, RentExemption is applied - a one-time payment for 2 years that permanently reserves space. The cost of RentExemption in Solana depends on storage size (in bytes) and the current allocation rate in the network. On average, the price is approximately 0.0023 SOL for every 10 KB. When closing an account, you can request a refund of the cost since the allocation is no longer needed.The approximate cost of creating such a contract is approximately 0.015 SOL (2 USD at Sol/USDT rate of $139).