xHalfLife Protocol:Smart Contract For Vesting

XDefiLabs
4 min readMar 1, 2021

Mathematically, you have no choices other than xHalfLife.

1. Practices of Streaming Protocols On Ethereum Blockchain: A Brief History

In 2020H1, in order to increase users and attractiveness, Compound.finance tokenized its governance power by rewarding banking behaviors on its lending system, allowing users to participate in the voting activities to approve improvement plans.

This $COMP farming greatly simplified compound interest calculations block by blocks: Only new activities from users (Deposit/withdraw funds, or claim $COMP earnings ) will cause claimable $COMP transferred to users’ wallets, with gas cost paid by users themselves. The compound interest calculation on the Ethereum blockchain is continuous, but gas consumption is greatly reduced by this lazy claiming scheme.

In 2020Q2, Mainframe announced the acquisition of Sablier Protocol. Sablier is a real-time financial protocol on Ethereum that supports continuous, autonomous, and trustless payroll. In the form of linear unlocking, it was widely used on agreements between creditors (employees) and the debtors(employers), so it was also modified to simulate loan issuing patterns: Debtors issue tokenized loans and obliged to pay coupons to creditors on a block basis.

In 2020Q3, Sushiswap tokenizes its liquidity providers’ revenue to a unified $SUSHI tokens. With some codes modified from YAM, it still designs a webpage with LP farming revenue which is jumping every second. Theoretically, the mining contract exchanges the potential reward cashflows on LP token (liquidity service commitment certificate) to a $SUSHI bond ( which generates a set of future $SUSHI interests).

2. xHalfLife Protocol: Thoughts, Improvements, and Implementation

2.1 Highly Unstable APY In Early Stages Of DEX Tokens’ Farming

Farming projects have always faced a dilemma: Higher APY means extraordinary farming attractiveness which may cause rapid accumulation of TVL(Total Value Locked), but soon it will be converted to higher potential dumping power. Considering the case of $SUSHI, within a few days after launching, many LP pools are eligible for ~1400% APY in the early stages. After Chef quitted the SushiSwap team, a sudden dump on ETH itself ( about -40%) happened, which caused SUSHI-ETH liquidity to collapse, $SUSHI price reduced by 96%. Highly unstable tokenomics always lead to the problem of lacking confidence.

2.2 xHalfLife: Mathematically No Other Choices

The most commonly used vesting scheme among Internet companies is 4–6 years of linear or accelerated vesting (there are examples of 1/6 reward per year for 6 years, and examples of 15%-25%-25%-35% for 4 years).

At the end of 2020, after taking conventional vesting into consideration, the SushiSwap dev team maintained the confidence of SushiSwap holders by embedding the repurchase codes into their smart contracts, and 2/3 of the farming revenue will be vested for 6 months. The problem is, after 6 months later, vesting income will still be a considerable dumping power if the projects make no progress during this period. Comparatively, Filecoin mining designed a 25% released + 75% linearly vesting strategy which smooths the token distribution on the time span, but if someone backtraced many continuously released cash flows, for Solidity it will directly lead to “out of gas error”: Backtracking 6 months’ reward from every block means writing a “for” clause computing historical states involving over 1.2 million blocks.

How can we simplify vesting schemes and get rid of the highly gas-consuming loop? A compromising approach is computing rewards off-chain and push statistics back periodically ( just like what balancer.exchange did on distributing their $BAL), but the final solution on-chain is xHalfLife: Choosing half-life parameters, distributing rewards that are exponentially decayed on the continuous time span.

The vesting scheme of xHalfLife is strongly inspired by the decay of radioactive particles and the law of drug concentration falling in the blood: their state is only related to the previous moment T0: when the status of the previous moment is A0, the status in the next moment is A0* (1- mu*t), where mu is a parameter directly related to halflife period. The reason why the drug concentration is mentioned is that in order to ensure the adequate effect of the drug, people must take the drug on time repetitively to add up the concentration in the blood, which means status a may be increased from A0 to A0+a at arbitrarily any time, which is consistent with the logic that “DeFi farmers increase their continuous farming rewards at any time”.

“You don’t consider historical state paths”. It is an important feature of exponential distribution (continuously distributed), geometric distribution (discretely distributed), and Markovian random process ( continuous or discrete). Without considering the historical state, XDEX farmers earn rewards vested in xHalfLife vesting protocol to ensure the stability of the total tokenomics, and also get rid of computing on historical states million times on the Ethereum blockchain when they want to extract their earnings.

2.3 Implementation

The parameters of the xHalfLife protocol have 4 parameters: StartBlock, K, ratio, and eps. User’s funds are divided into two accounts: Vested Income and Withdrawable Income.

Any new fund goes directly to Vested Income first. From blockheight at StartBlock, whenever the blockchain height can be divisible by K, if Vested Income exceeds eps, smart contract will transfer the ratio*Vested Income to Withdrawable Income.

The halflife period is estimated as -K / log_2(1-ratio) * 13.1 seconds.

3 xHalfLife: Applications

In the xDeFi&Labs seed round financing process, the team led by the CTO won the championship at Dorahacks&BSC Beijing Hackathon in 2020 with the full implementation of xHalfLife. Founders of xDeFi&Labs continued to share ideas of xHalfLife to the community and investors since XDEX tokens are vested for XDEX farmers, teams, and investors by calling the exact same smart contract with different parameters.

The whole team is also actively seeking opportunities to integrate xHalfLife protocols to IXO platforms to meet different vesting requirements in different financing activities.

--

--