> For the complete documentation index, see [llms.txt](https://docs.endless.link/endless/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.endless.link/endless/devbuild/technical-documentation/token-locking-distribution.md).

# Token Locking & Distribution

<figure><img src="/files/CLFzi4cUZPZhXz0PX3mm" alt=""><figcaption><p>Locking &#x26; Distribution</p></figcaption></figure>

## Design Purpose

Due to the comparatively massive volumes sold during early-stage rounds, projects may encounter extreme selling pressure after the IDO and after the token has been posted on Centralized Exchange – CEX / Decentralized Exchange – DEX. It significantly lowers the price of tokens by increasing the total amount of tokens in circulation.

For the Token Economy to stay sustainable & effective, the majority of tokens must be kept by investors rather than being sold on the market. Members can stop the value of its token from sinking by locking up tokens. Additionally, it prevents team members from selling their tokens as soon as trade begins, safeguarding holders’ interests.

Endless's `locking_coin_ex` contract manages token distribution via a locking and unlocking mechanism, ensuring gradual token release over a defined period to control circulation.

The contract allows any user to:

* Lock any amount of any fungible token, including native EDS.
* Specify the recipient account for unlocked tokens.
* Define a two-stage release plan:
  * Specify a portion of tokens for immediate release at a designated epoch.
  * Release the remaining tokens linearly over a stipulated epoch interval.
* The recipient invokes the `do_claim` function to fetch the released asset.

## API

The following are the main API interfaces provided by this contract:

### View Functions

#### Query total lock amount

`total_locks(token_address: address): u128`

* Function: Query the total locked amount for the specified token address.
* Parameters: token\_address - The token address.
* Return value: Total locked amount.

#### List all stakers

`public fun get_all_stakers(token_address: address): vector<address>`

* Function: Query all staker addresses for the specified token address.
* Parameters: token\_address - The token address.
* Return value: List of staker addresses.

#### Query one of staker's token locking amount

`public fun staking_amount(token_address: address, recipient: address): u128`

* Function: Query the staking amount for the specified staker at the specified token address.
* Parameters: token\_address - The token address, recipient - The staker address.
* Return value: Staking amount.

#### UnLockInfo

the structure contains receiver's address when release, and next release plan(amount and related epoch)

```rust
struct UnlockInfo has drop {
    address: address,
    unlocked: u128,
    unlock_list: vector<UnlockAt>,
}
```

#### List all staker's token release-plan

`public fun get_all_stakers_unlock_info(token_address: address): vector<UnlockInfo>`

* Function: Query the unlock information for all stakers at the specified token address.
* Parameters: token\_address - The token address.
* Return value: List of unlock information.

#### Query one of staker's token release-plan

`public fun get_unlock_info(token_address: address, sender: address): UnlockInfo`

* Function: Query the unlock information for the specified staker at the specified token address.
* Parameters: token\_address - The token address, sender - The staker address.
* Return value: Unlock information.

### Management Functions

#### Add Locking Plan

`public entry fun add_locking_plan_from_unlocked_balance(sender: &signer, token_address: address, receiver: address, total_coins: u128, first_unlock_bps: u64, first_unlock_epoch: u64, stable_unlock_interval: u64, stable_unlock_periods: u64)`

* Function: Add a locking plan from the unlocked balance.
* Parameters:
  * sender - The signer,
  * token\_address - The token address,
  * receiver - The receiver address,
  * total\_coins - The total locked amount,
  * first\_unlock\_bps - The first unlock percentage,
  * first\_unlock\_epoch - The first unlock epoch,
  * stable\_unlock\_interval - The stable unlock interval,
  * stable\_unlock\_periods - The number of stable unlock periods.

#### Add Locking Plan

`public entry fun add_locking_plan(sender: &signer, token_address: address, receiver: address, total_coins: u128, first_unlock_bps: u64, first_unlock_epoch: u64, stable_unlock_interval: u64, stable_unlock_periods: u64)`

* Function: Add a locking plan.
* Parameters:
  * sender - The signer,
  * token\_address - The token address,
  * receiver - The receiver address,
  * total\_coins - The total locked amount,
  * first\_unlock\_bps - The first unlock percentage,
  * first\_unlock\_epoch - The first unlock epoch,
  * stable\_unlock\_interval - The stable unlock interval,
  * stable\_unlock\_periods - The number of stable unlock periods.

#### Claim leased tokens

`public entry fun claim(sender: &signer, token_address: address, amount: u128)`

* Function: Claim unlocked tokens.
* Parameters:
  * sender - The signer,
  * token\_address - The token address,
  * amount - The claim amount.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.endless.link/endless/devbuild/technical-documentation/token-locking-distribution.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
