Use for vote-escrowed in DAO governance proposals, Gauges Voting
Not transferable
To increase veToken, only can do by
add more Token Staking
extend lock duration
Only way to get Ve token is staking
It will be fixed-term Staking
Can stake
min 1 weeks
max 4 years
The amount of VeToken recieved will be decided by formula
maxWeekLocked here = 208 weeks = 4 years
Â
So for example, If we Staking 2 Token in 4 weeks we will reiecve:
Week1 , Ve Amount = (2*4)/208 = 0.0380769231
Week2 , Ve Amount = (2*3)/208 = 0.0285576923
Benefits
Weekly Rewards
Revenue Sharing based on how much staking Token. 5% of v3 trading fee revenue
Token Pool Rewards ( the emission will decided by gauge emission)
Gauges Voting Participation every epoch ( epoch = 2 weeks)
To Vote on farms, Reward Pools, Token emission
Farm boost. up to 2x
Particiate in IFO sales
Â
Vetoken Diagram Details explain
Deposit/WithDraw
Deposit:
In addition to the createLock function, we also have functions for increasing the token lock amount and adjusting the lock's end time after it has already been created.
Increse Lock Amount
Increase Time End
These functions both require user has locked, but for here we only consider createLock function, increaseLockAmount & IncreaseTimeEnd is almost same
Â
DepositFor Function: this function is called after createLock/Increse Lock Amount / Increase Time End called. This function to perform lock for user
This function will exec these steps:
increase Lock Balance Of User
Call _checkpoint function that we will explain details below
Update done, transfer token to locked
If Farm Booster is set, update state for Farm Booster as well
Â
Withdraw:
For this we have 2 functions:
earlyWithdraw : This function allow us can withdraw before end time lock.
*We can config Penalty for early withdraw in the function setEarlyWithdrawConfig
withdrawAll : This function only called when lock has expired.
Â
_unlock Function: this function is called after earlyWithdraw/withdrawAll called. This function to perform unlock for user
This function will exec these steps:
update new amount of Lock
2. call _checkpoint function
Â
_checkpoint
This function is used for to update balance Lock, VeToken remain of Specific User Or Update Globally for all user
To store Point (VeToken Balance) of User at that time. Contract use a struct
Â
( 208 here is stands for MAX_LOCK_WEEKS)
Â
This function will execute steps:
Update prev balance to Points History (Balance here is amount Ve Token = amountLocked * remainWeekLocked/208)
Increase User Epoch, update new balance
Also update to global variable: Total Supply of Ve Token
Â
Get Balance Of User
Â
There are 2 ways to Get Balance:
By Time_stamp ( _balanceOf )
It’s quite simple here, just apply formula :
in case, timeStamp < lockStart it will return 0 instead of Negative Number
Â
By Block_number ( _balanceOfAt )
This function allows users to check their balance at a specific block number. It's more complex than GetBalanceByTime because we cannot directly retrieve the timestamp of a past block. Therefore, the solution involves storing historical snapshots of user balances for each block number (this variable is updated whenever the _checkpoint function is called). We can then use binary search to find the closest block number to the desired one and calculate the user's VE amount based on that snapshot.
Â
To do that we will have 3 variables:
Â
userEpoch
it’s epoch of User. it will increase incrementally like 1,2,3…,n, this epoch will +1 when _checkpoint is called
userPointHistory: mapping(address => Point[]) public userPointHistory;
we will use userEpoch to index for the userPointHistory Actually we can reduce number Of Variables by just index by Block_number but i guess $CAKE team use it to save memory used
Â
globalEpoch; pointHistory:Point[] public pointHistory;
Same with User State Data; we have globalEpoch & pointHistory present for state of total users
Â
Then This function will execute steps:
Binary Search to find most recent user Epoch to block Number → Get the State Point Of User
Calculate timestamp of block_number
Can’t get exact number but solution here is we can get the nearly number by formula:
With :
To Get BlockTime’ & blockNumber’
→ Binary Search to find most recent Global Epoch to block Number → Get the State Point Of Total User
Apply Formula:
Â
Â
Â
Get Total Supply
Â
Almost same logic with Get Balance ones
Â
Â
Â
Thena
Â
PermissionsRegistry.sol : To handle Entities & Roles of all contracts
Entities:
thenaMultisig
address public thenaMultisig // Control this contract. This is the main multisig 4/6
Before adding Gauge, we need to whitelist token in the Gauge first
VOTER_ADMIN
_init Voter V3 Contract : Due to wrong init in V3 contract, after creating Voter V3 contract we need to call this function to update minter & permissionRegistry Address
→ Wrong here: when they assign minter & permissionRegistry Address = owner
claimBribes(address[] memory _bribes, address[][] memory _tokens, uint256 _tokenId): claim bribes rewards given a TokenID ( also there’s same function claimBribes(address[] memory _bribes, address[][] memory _tokens) that claim bribes rewards given an address)
Â
claimFees(address[] memory _fees, address[][] memory _tokens, uint256 _tokenId): claim fees rewards given a TokenID ( also there’s same function claimFees(address[] memory _bribes, address[][] memory _tokens) that claim fees rewards given an address
Â
Â
Â
Comparison to BaseX
Â
VoterV3.sol
_reset function
Thena
BaseX
Â
_vote → BaseX seems no need to check isAlive[_gauge], remove usedWeights