Compute vote-escrow decay weight
In a vote-escrow system your weight is the locked balance scaled by the time remaining, so it decays every second toward zero at unlock. The lock balance is not the vote.
Procedure
Read the lock:
cast call $VE "locked(address)(int128,uint256)" $WHO --rpc-url $RPC returns (amount, end).
cast call $VE "balanceOf(address)(uint256)" $WHO --rpc-url $RPC returns the current decayed weight.
Reproduce the decay. Curve's formula is weight = amount * (end - now) / MAXTIME, where MAXTIME = 4 years (126144000 seconds).
Worked example: amount = 1000e18, end - now = 2 years = 63072000, so weight = 1000 * 63072000 / 126144000 = 500.
Verify against the contract:
python3 -c "print(1000*63072000//126144000)" -> 500, matching balanceOf.
Extend the lock to raise weight: increase_unlock_time resets to a longer end and raises balanceOf; re-read after the transaction.
For a future date, project: weight_t = amount * (end - t) / MAXTIME for t < end, else 0.
Aggregate for voting: only the current balanceOf counts, so a snapshot taken near an unlock has materially less weight than a month earlier.
Convert the unlock timestamp to a date and state it, so the decay is anchored to a calendar, not a raw block.
If the lock is transferable (a veNFT), check the current owner: the weight follows the NFT, not the original locker.
For a vote, read balanceOf at the snapshot block, not at execution time, since weight decays between them.
Pitfalls
Treating the locked amount as voting power in a tokenomics or concentration analysis; the decayed balance is the correct figure and is often far lower.
Forgetting the decay is continuous, so two reads a week apart differ; always tag a ve-weight figure with its timestamp.
Assuming MAXTIME is four years for every project; some forks change it, so read the constant from the contract.
Counting an expired lock (past end) as still locked; after expiry balanceOf is 0 and the tokens are withdrawable.
Comparing ve-weight across protocols as if interchangeable; each uses its own lock duration and scale.
Assuming the lock can be extended to full weight instantly; increase_unlock_time is capped at MAXTIME from now.
Forgetting that a withdrawn lock leaves balanceOf at 0 while the tokens have left the ve contract.
Reading the clock from the local machine rather than the chain; time in the formula is the block timestamp.
Verification
python3 -c "amt=1000; end=63072000; print(amt*end//126144000)"
# 500, equal to cast call $VE "balanceOf(address)(uint256)" at the same timestamp
Report the locked amount, the unlock time, the decayed weight, and the formula's result at the same timestamp, with both readings shown.
1---2name: compute-vote-escrow-decay-weight3description: Use when measuring locking voting power (veCRV-style) at a future date or comparing locks. Computes the linear decay to unlock and the resulting weight, not the locked balance.4metadata:5 source: https://skillmd.com/skills/jiayaoqijia/compute-vote-escrow-decay-weight6---78# Compute vote-escrow decay weight910In a vote-escrow system your weight is the locked balance scaled by the time remaining, so it decays every second toward zero at unlock. The lock balance is not the vote.1112## Procedure13141. Read the lock:15 `cast call $VE "locked(address)(int128,uint256)" $WHO --rpc-url $RPC` returns (amount, end).16 `cast call $VE "balanceOf(address)(uint256)" $WHO --rpc-url $RPC` returns the current decayed weight.172. Reproduce the decay. Curve's formula is `weight = amount * (end - now) / MAXTIME`, where `MAXTIME = 4 years` (126144000 seconds).18 Worked example: amount = 1000e18, end - now = 2 years = 63072000, so weight = 1000 * 63072000 / 126144000 = 500.193. Verify against the contract:20 `python3 -c "print(1000*63072000//126144000)"` -> `500`, matching `balanceOf`.214. Extend the lock to raise weight: `increase_unlock_time` resets to a longer end and raises `balanceOf`; re-read after the transaction.225. For a future date, project: `weight_t = amount * (end - t) / MAXTIME` for `t < end`, else 0.236. Aggregate for voting: only the current `balanceOf` counts, so a snapshot taken near an unlock has materially less weight than a month earlier.24257. Convert the unlock timestamp to a date and state it, so the decay is anchored to a calendar, not a raw block.268. If the lock is transferable (a veNFT), check the current owner: the weight follows the NFT, not the original locker.279. For a vote, read `balanceOf` at the snapshot block, not at execution time, since weight decays between them.2829## Pitfalls3031- Treating the locked amount as voting power in a tokenomics or concentration analysis; the decayed balance is the correct figure and is often far lower.32- Forgetting the decay is continuous, so two reads a week apart differ; always tag a ve-weight figure with its timestamp.33- Assuming `MAXTIME` is four years for every project; some forks change it, so read the constant from the contract.34- Counting an expired lock (past `end`) as still locked; after expiry `balanceOf` is 0 and the tokens are withdrawable.35- Comparing ve-weight across protocols as if interchangeable; each uses its own lock duration and scale.3637- Assuming the lock can be extended to full weight instantly; `increase_unlock_time` is capped at `MAXTIME` from now.38- Forgetting that a withdrawn lock leaves `balanceOf` at 0 while the tokens have left the ve contract.39- Reading the clock from the local machine rather than the chain; time in the formula is the block timestamp.4041## Verification4243 python3 -c "amt=1000; end=63072000; print(amt*end//126144000)"44 # 500, equal to cast call $VE "balanceOf(address)(uint256)" at the same timestamp4546Report the locked amount, the unlock time, the decayed weight, and the formula's result at the same timestamp, with both readings shown.