Crates.io | cw-vesting |
lib.rs | cw-vesting |
version | 2.6.0 |
source | src |
created_at | 2023-07-03 15:49:16.889807 |
updated_at | 2024-11-07 23:53:31.394609 |
description | A CosmWasm vesting contract. |
homepage | |
repository | https://github.com/DA0-DA0/dao-contracts |
max_upload_size | |
id | 907142 |
size | 198,409 |
This contract enables the creation of native && cw20 token streams, which allows a payment to be vested continuously over time.
Key features include:
To instantiate a new instance of this contract you may specify a contract owner, as well as payment parameters.
cw-payroll-factory
can be used if you wish to instantiate many cw-vesting
contracts and query them.
The owner
of a contract is optional. Contracts without owners are not able to be canceled. The owner can be set to the DAO making the payment or a neutral third party.
This package uses the curve implementation from wynd-utils.
It supports 2 types of curves that represent the vesting schedule:
(time, vested)
pointsPiecsewise Curves can be used to create more complicated vesting schedules. For example, let's say we have a schedule that vests 50% over 1 month and the remaining 50% over 1 year. We can implement this complex schedule with a Piecewise Linear curve.
Piecewise Linear curves take a steps
parameter which is a list of
tuples (timestamp, vested)
. It will then linearally interpolate
between those points to create the vesting curve. For example, given
the points (0, 0), (2, 2), (4, 8)
, it would create a vesting curve
that looks like this:
8 +----------------------------------------------------------------------+
| + + + + + + + ** |
7 |-+ ** +-|
| *** |
| ** |
6 |-+ ** +-|
| *** |
5 |-+ ** +-|
| ** |
| *** |
4 |-+ ** +-|
| ** |
3 |-+ *** +-|
| ** |
| ** |
2 |-+ ***** +-|
| ******* |
1 |-+ ******** +-|
| ******* |
| ******* + + + + + + |
0 +----------------------------------------------------------------------+
0 0.5 1 1.5 2 2.5 3 3.5 4
As you can see, it travels through (0, 0)
in a straight line to (2, 2)
, then increases its slope and travels to (4, 8)
.
A curve where 50% vests the first month starting January 1st 2023, and the remaining 50% vests over the next year. For 100 Juno.
{
"piecewise_linear": [
(1672531200, "0"),
(1675209600, "50000000"),
(1706745600, "100000000")
]
}
If vesting native tokens, you need to include the exact amount in native funds that you are vesting when you instantiate the contract.
A cw20 vesting payment can be funded using the cw20 Send / Receive flow. This involves triggering a Send message from the cw20 token contract, with a Receive callback that's sent to the vesting contract.
Vesting payments can be claimed continuously at any point after the start time by triggering a Distribute message.
Anyone can call the distribute message, allowing for agents such as CronCat to automatically trigger payouts.
This contract allows for underlying native tokens to be staked if they match the staking token of the native chain (i.e. $JUNO on Juno Network).
Delegate
, Undelegate
, Redelegate
, and SetWithdrawAddress
can
only be called by the recipient
. WithdrawDelegatorReward
can be
called by anyone to allow for easy auto-compounding. Due to
limitations to our ability to inspect the SDK's state from CosmWasm,
only funds that may be redelegated immediately (w/o an unbonding
period) may be redelegated.
While this contract allows for delegating native tokens, it does not allow for voting. As such, be sure to pick validators you delegate to wisely when using this contract.
This vesting contract supports optional cancellation. For example, if an employee has to leave a company for whatever reason, the company can vote to have the employee salary canceled.
This is only possible if an owner
address is set upon contract
instantiation, otherwise the vesting contract cannot be altered by
either party.
When a contract is cancelled, the following happens:
Delegate
are Redelegate
are disabled.Undelegate
are made permissionless (allowing anyone to
undelegate the contract's staked tokens).It is imagined that frontends will prompt visitors to execute undelegations, or a bot will do so. The contract can not automatically undelegate as that would allow a malicious vest receiver to stake to many validators and make cancelation run out of gas, preventing the contract from being cancelable and allowing them to continue to receive funds.
This contract can be used with stable coins such as $USDC. It does not yet support auto swapping to stables, however this feature can be enabled with other contracts or tools like CronCat.
DAOs always have an option of swapping to stables before creating a vesting contract ensuring no price slippage. For example, a proposal to pay someone 50% $USDC could contain three messages:
Thank you to Wynd DAO for their previous work on cw20-vesting and their curve package which informed and inspired this contract's design.