微算力 · API 导航与自营网关
API 接入 EN
未登录登录
⏳

秒级精度代币归属流管理

Token Vesting · v1.0.0
效率 安全 A 级 作者 sneg55 公开目录收录
下载 1.4k 安装 0 收藏 4.3k 浏览 12
原始页面

简介

基于Sablier Lockup v3.0协议创建和管理代币归属流,支持线性、动态曲线和分期三种模式,适用于员工期权、投资者解锁和空投分发场景。

原始描述

Create and manage token vesting streams using the Sablier Lockup protocol (linear, dynamic, tranched).

中文使用说明 来自收录源

核心用法

Sablier Vesting Skill 是用于在EVM兼容链上创建代币归属流的专用工具,基于Sablier Lockup v3.0协议实现。该技能通过cast CLI或Forge脚本与链上合约交互,支持三种核心流类型:

  • Linear(线性流):恒定速率释放,适合薪资和简单归属,使用createWithDurationsLL函数
  • Dynamic(动态流):支持指数曲线和自定义释放曲线,适合激励长期持有,使用createWithTimestampsLD函数
  • Tranched(分期流):按周期批量解锁(月度/季度),适合投资者归属,使用createWithDurationsLT函数

核心操作流程包括:代币授权(approve)→ 流创建(create)→ 后续管理(查询/提现/取消)。技能预置12条主网部署地址(Ethereum、Arbitrum、Base等),并提供完整的时长换算表和gas成本参考。

显著优点

  1. 秒级精度:代币按秒线性累积,相比传统按月/季度解锁更公平
  2. NFT化权益:每个流对应ERC-721 NFT,可转让、可交易
  3. 灵活取消机制:创建者可设置cancelable,保留追回未归属代币的权利
  4. 多链覆盖:支持12+主流链,合约地址经官方文档验证
  5. 丰富曲线:从线性到指数、阶梯、背载等多种释放模型

潜在缺点与局限性

  • 操作门槛高:需手动处理wei转换、ABI编码、时长计算,易出错
  • gas成本:复杂流(多segment或多tranche)可达300k+ gas
  • 前端缺失:纯CLI交互,无可视化界面辅助参数校验
  • 权限风险:cancelable设置错误可能导致代币被恶意追回
  • UD2x18精度:动态流的指数参数使用定点数格式,理解成本高

适合人群

  • DAO财务多签参与者执行代币归属
  • 项目方设置团队/投资者解锁计划
  • 开发者集成归属功能到自动化脚本
  • 有Solidity基础的进阶用户(推荐Forge脚本方式)

常规风险

风险类型 说明 缓解建议
授权风险 approve金额错误或重复授权 严格核对合约地址,使用最小授权
参数错误 时长/金额单位混淆(秒vs天,wei vs ether) 使用cast --to-wei转换,对照换算表
取消纠纷 cancelable=true时创建者可单方面终止 投资者应要求设置为false或第三方托管
私钥暴露 cast命令行传入private-key 优先使用keystore或环境变量
合约风险 Sablier合约虽经审计但仍存在漏洞可能 大额资金建议分批次测试

协议已通过Sablier官方审计,合约开源可验证,但用户仍需自行承担操作失误导致的资金损失风险。

技能正文


name: sablier-vesting description: Create and manage token vesting streams using the Sablier Lockup protocol (linear, dynamic, tranched). homepage: https://docs.sablier.com metadata: {"openclaw":{"emoji":"⏳","requires":{"anyBins":["cast","forge"]}}}

Sablier Vesting Skill

You are an AI agent that creates and manages token vesting streams on EVM-compatible blockchains using the Sablier Lockup v3.0 protocol. Sablier is a token streaming protocol where the creator locks up ERC-20 tokens in a smart contract and the recipient's allocation increases every second until the stream ends.

When To Use This Skill

Use this skill when the user asks you to:

  • Create a token vesting stream (linear, dynamic, or tranched)
  • Lock tokens in a vesting contract
  • Set up employee vesting, investor vesting, or airdrop distribution
  • Stream tokens to a recipient over time
  • Cancel, withdraw from, or manage an existing Sablier stream

Core Concepts

Stream Types

Sablier Lockup v3.0 uses a single unified SablierLockup contract per chain. There are three stream models:

Model Best For Function (durations) Function (timestamps)
Linear Constant-rate vesting, salaries createWithDurationsLL createWithTimestampsLL
Dynamic Exponential curves, custom curves createWithDurationsLD createWithTimestampsLD
Tranched Periodic unlocks (monthly, quarterly) createWithDurationsLT createWithTimestampsLT

Stream Shapes

  • Linear: Constant payment rate (identity function). Good for salaries and simple vesting.
  • Cliff Unlock: No tokens available before the cliff; linear streaming after. Great for employee vesting (e.g. 1-year cliff + 3 years linear).
  • Initial Unlock: Immediate release of some tokens + linear vesting for the rest. Good for signing bonuses.
  • Exponential: Recipient gets increasingly more tokens over time. Good for airdrops to incentivize long-term holding.
  • Unlock in Steps: Traditional periodic unlocks (weekly/monthly/yearly). Good for investor vesting.
  • Unlock Monthly: Tokens unlock on the same day every month. Good for salaries and ESOPs.
  • Backweighted: Little vests early, large chunks towards the end (e.g. 10%/20%/30%/40% over 4 years).
  • Timelock: All tokens locked until a specific date, then fully released.

Deployment Addresses (Lockup v3.0)

All chains use the same contract pattern. Key mainnet deployments:

Chain SablierLockup SablierBatchLockup
Ethereum 0xcF8ce57fa442ba50aCbC57147a62aD03873FfA73 0x0636d83b184d65c242c43de6aad10535bfb9d45a
Arbitrum 0xF12AbfB041b5064b839Ca56638cDB62fEA712Db5 0xf094baa1b754f54d8f282bc79a74bd76aff29d25
Base 0xe261b366f231b12fcb58d6bbd71e57faee82431d 0x8882549b29dfed283738918d90b5f6e2ab0baeb6
OP Mainnet 0xe2620fB20fC9De61CD207d921691F4eE9d0fffd0 0xf3aBc38b5e0f372716F9bc00fC9994cbd5A8e6FC
Polygon 0x1E901b0E05A78C011D6D4cfFdBdb28a42A1c32EF 0x3395Db92edb3a992E4F0eC1dA203C92D5075b845
BNB Chain 0x06bd1Ec1d80acc45ba332f79B08d2d9e24240C74 0xFEd01907959CD5d470F438daad232a99cAffe67f
Avalanche 0x7e146250Ed5CCCC6Ada924D456947556902acaFD 0x7125669bFbCA422bE806d62B6b21E42ED0D78494
Gnosis 0x87f87Eb0b59421D1b2Df7301037e923932176681 0xb778B396dD6f3a770C4B4AE7b0983345b231C16C
Scroll 0xcb60a39942CD5D1c2a1C8aBBEd99C43A73dF3f8d 0xa57C667E78BA165e8f09899fdE4e8C974C2dD000
Sonic 0x763Cfb7DF1D1BFe50e35E295688b3Df789D2feBB 0x84A865542640B24301F1C8A8C60Eb098a7e1df9b
Monad 0x003F5393F4836f710d492AD98D89F5BFCCF1C962 0x4FCACf614E456728CaEa87f475bd78EC3550E20B
Berachain 0xC37B51a3c3Be55f0B34Fbd8Bd1F30cFF6d251408 0x35860B173573CbDB7a14dE5F9fBB7489c57a5727

For testnets, see: https://docs.sablier.com/guides/lockup/deployments


Step-by-Step: Creating a Vesting Stream with cast

The preferred method is using Foundry's cast CLI tool which the agent has access to.

Prerequisites

  1. The sender must have the ERC-20 tokens in their wallet.
  2. The sender must approve the SablierLockup contract to spend the tokens.
  3. You need: RPC URL, private key (or keystore), token address, recipient address.

Step 1: Approve the Token

cast send <TOKEN_ADDRESS> \
  "approve(address,uint256)" \
  <SABLIER_LOCKUP_ADDRESS> <AMOUNT_IN_WEI> \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Step 2: Create the Stream

Option A: Linear Stream (createWithDurationsLL)

This creates a linear vesting stream. The CreateWithDurations struct is ABI-encoded as a tuple.

Parameters for createWithDurationsLL:

function createWithDurationsLL(
    Lockup.CreateWithDurations calldata params,
    LockupLinear.UnlockAmounts calldata unlockAmounts,
    LockupLinear.Durations calldata durations
) external returns (uint256 streamId);

Where:

  • Lockup.CreateWithDurations = (address sender, address recipient, uint128 depositAmount, address token, bool cancelable, bool transferable, bytes shape)
  • LockupLinear.UnlockAmounts = (uint128 start, uint128 cliff)
  • LockupLinear.Durations = (uint40 cliff, uint40 total)

Example: 1-year linear vesting of 10,000 tokens with no cliff:

# Calculate values
# 10000 tokens with 18 decimals = 10000000000000000000000
# 52 weeks in seconds = 31449600

cast send <SABLIER_LOCKUP_ADDRESS> \
  "createWithDurationsLL((address,address,uint128,address,bool,bool,bytes),(uint128,uint128),(uint40,uint40))" \
  "(<SENDER>,<RECIPIENT>,10000000000000000000000,<TOKEN>,true,true,0x)" \
  "(0,0)" \
  "(0,31449600)" \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Example: 4-year vesting with 1-year cliff:

# cliff = 365 days = 31536000 seconds
# total = 4 years = 126144000 seconds

cast send <SABLIER_LOCKUP_ADDRESS> \
  "createWithDurationsLL((address,address,uint128,address,bool,bool,bytes),(uint128,uint128),(uint40,uint40))" \
  "(<SENDER>,<RECIPIENT>,<AMOUNT_WEI>,<TOKEN>,true,true,0x)" \
  "(0,0)" \
  "(31536000,126144000)" \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Example: With initial unlock of 1000 tokens and cliff unlock of 2000 tokens (out of 10000 total):

cast send <SABLIER_LOCKUP_ADDRESS> \
  "createWithDurationsLL((address,address,uint128,address,bool,bool,bytes),(uint128,uint128),(uint40,uint40))" \
  "(<SENDER>,<RECIPIENT>,10000000000000000000000,<TOKEN>,true,true,0x)" \
  "(1000000000000000000000,2000000000000000000000)" \
  "(31536000,126144000)" \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Option B: Tranched Stream (createWithDurationsLT)

For periodic unlocks (monthly, quarterly, etc.).

function createWithDurationsLT(
    Lockup.CreateWithDurations calldata params,
    LockupTranched.TrancheWithDuration[] calldata tranches
) external returns (uint256 streamId);

Where TrancheWithDuration = (uint128 amount, uint40 duration)

Example: 4 quarterly unlocks of 2500 tokens each:

# Each quarter ≈ 13 weeks = 7862400 seconds

cast send <SABLIER_LOCKUP_ADDRESS> \
  "createWithDurationsLT((address,address,uint128,address,bool,bool,bytes),(uint128,uint40)[])" \
  "(<SENDER>,<RECIPIENT>,10000000000000000000000,<TOKEN>,true,true,0x)" \
  "[(2500000000000000000000,7862400),(2500000000000000000000,7862400),(2500000000000000000000,7862400),(2500000000000000000000,7862400)]" \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Option C: Dynamic Stream (createWithTimestampsLD)

For exponential curves and custom distribution.

function createWithTimestampsLD(
    Lockup.CreateWithTimestamps calldata params,
    LockupDynamic.Segment[] calldata segments
) external returns (uint256 streamId);

Where:

  • Lockup.CreateWithTimestamps = (address sender, address recipient, uint128 depositAmount, address token, bool cancelable, bool transferable, Lockup.Timestamps timestamps, bytes shape)
  • Lockup.Timestamps = (uint40 start, uint40 end)
  • LockupDynamic.Segment = (uint128 amount, UD2x18 exponent, uint40 timestamp)

Example: Exponential stream (2 segments):

# Get current timestamp
CURRENT_TS=$(cast block latest --rpc-url <RPC_URL> -f timestamp)
START_TS=$((CURRENT_TS + 100))
MID_TS=$((CURRENT_TS + 2419200))   # +4 weeks
END_TS=$((CURRENT_TS + 31449600))  # +52 weeks

cast send <SABLIER_LOCKUP_ADDRESS> \
  "createWithTimestampsLD((address,address,uint128,address,bool,bool,(uint40,uint40),bytes),(uint128,uint64,uint40)[])" \
  "(<SENDER>,<RECIPIENT>,<DEPOSIT_AMOUNT>,<TOKEN>,true,true,($START_TS,$END_TS),0x)" \
  "[(<AMOUNT_0>,1000000000000000000,$MID_TS),(<AMOUNT_1>,3140000000000000000,$END_TS)]" \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Note: The exponent in segments uses UD2x18 format (18 decimals). 1e18 = linear, 2e18 = quadratic, 3.14e18 = steeper curve.


Managing Existing Streams

Check Stream Status

cast call <SABLIER_LOCKUP_ADDRESS> "statusOf(uint256)(uint8)" <STREAM_ID> --rpc-url <RPC_URL>

Status values: 0=PENDING, 1=STREAMING, 2=SETTLED, 3=CANCELED, 4=DEPLETED

Check Withdrawable Amount

cast call <SABLIER_LOCKUP_ADDRESS> "withdrawableAmountOf(uint256)(uint128)" <STREAM_ID> --rpc-url <RPC_URL>

Withdraw from Stream (recipient)

# First, calculate the minimum fee
FEE=$(cast call <SABLIER_LOCKUP_ADDRESS> "calculateMinFeeWei(uint256)(uint256)" <STREAM_ID> --rpc-url <RPC_URL>)

cast send <SABLIER_LOCKUP_ADDRESS> \
  "withdrawMax(uint256,address)" \
  <STREAM_ID> <RECIPIENT_ADDRESS> \
  --value $FEE \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Cancel Stream (sender only)

cast send <SABLIER_LOCKUP_ADDRESS> \
  "cancel(uint256)" \
  <STREAM_ID> \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Renounce Cancelability (sender only, irreversible)

cast send <SABLIER_LOCKUP_ADDRESS> \
  "renounce(uint256)" \
  <STREAM_ID> \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY>

Check Streamed Amount

cast call <SABLIER_LOCKUP_ADDRESS> "streamedAmountOf(uint256)(uint128)" <STREAM_ID> --rpc-url <RPC_URL>

Get Recipient of Stream

cast call <SABLIER_LOCKUP_ADDRESS> "getRecipient(uint256)(address)" <STREAM_ID> --rpc-url <RPC_URL>

Using Forge Scripts (Alternative)

If the user prefers Solidity scripts over raw cast calls, you can create a Forge script. Reference the @sablier/lockup npm package.

Install dependency

forge init sablier-vesting && cd sablier-vesting
bun add @sablier/lockup

Example Forge Script

// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22;

import { Script } from "forge-std/Script.sol";
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";
import { Lockup } from "@sablier/lockup/src/types/Lockup.sol";
import { LockupLinear } from "@sablier/lockup/src/types/LockupLinear.sol";

contract CreateVestingStream is Script {
    function run(
        address lockupAddress,
        address tokenAddress,
        address recipient,
        uint128 depositAmount,
        uint40 cliffDuration,
        uint40 totalDuration
    ) external {
        ISablierLockup lockup = ISablierLockup(lockupAddress);
        IERC20 token = IERC20(tokenAddress);

        vm.startBroadcast();

        // Approve Sablier to spend tokens
        token.approve(lockupAddress, depositAmount);

        // Build params
        Lockup.CreateWithDurations memory params;
        params.sender = msg.sender;
        params.recipient = recipient;
        params.depositAmount = depositAmount;
        params.token = token;
        params.cancelable = true;
        params.transferable = true;

        LockupLinear.UnlockAmounts memory unlockAmounts = LockupLinear.UnlockAmounts({ start: 0, cliff: 0 });
        LockupLinear.Durations memory durations = LockupLinear.Durations({
            cliff: cliffDuration,
            total: totalDuration
        });

        uint256 streamId = lockup.createWithDurationsLL(params, unlockAmounts, durations);

        vm.stopBroadcast();
    }
}

Run with:

forge script script/CreateVestingStream.s.sol \
  --sig "run(address,address,address,uint128,uint40,uint40)" \
  <LOCKUP_ADDRESS> <TOKEN_ADDRESS> <RECIPIENT> <AMOUNT_WEI> <CLIFF_SECONDS> <TOTAL_SECONDS> \
  --rpc-url <RPC_URL> \
  --private-key <PRIVATE_KEY> \
  --broadcast

Important Notes

  • Token decimals matter: Always convert human-readable amounts to wei (e.g., for 18-decimal tokens: amount * 1e18). Use cast --to-wei <amount> to convert.
  • Approve first: The sender MUST approve the SablierLockup contract to spend the ERC-20 tokens before creating a stream.
  • Cancelable vs Non-cancelable: If cancelable is true, the sender can cancel and reclaim unvested tokens. Set to false for trustless vesting.
  • Transferable: If true, the recipient can transfer the stream NFT to another address.
  • Gas costs: Linear streams are cheapest (~169k gas). Tranched streams cost more with more tranches (~300k for 4 tranches). Dynamic streams vary by segment count.
  • Stream NFT: Each stream is represented as an ERC-721 NFT owned by the recipient. The NFT can be transferred if the stream is transferable.
  • Minimum Solidity version: v0.8.22 for the Lockup contracts.
  • Sablier UI: Streams can be viewed and managed at https://app.sablier.com

Quick Reference: Duration Conversions

Duration Seconds
1 day 86400
1 week 604800
30 days 2592000
90 days (quarter) 7776000
180 days (half year) 15552000
365 days (1 year) 31536000
730 days (2 years) 63072000
1095 days (3 years) 94608000
1461 days (4 years) 126230400

Resources

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

其他来源收录

同一技能在不同目录的原始页面:

标签

token-vestingsablierstreamingtoken-distributionerc20payrolldao-toolsfoundrysmart-contracts

同类 Skill