Yield Basis 백서

Yield Basis

원문

bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 24쪽 중 24쪽

eward ] = r . reward_rate_integral self . reward_rate_integral_4_user [ user ] [ reward ] = r . reward_rate_integral . v self . user_rewards_integral [ user ] [ reward ] = r . user_rewards_integral d_reward = r . user_rewards_integral . v - self . claimed_rewards [ user ] [ reward ] self . claimed_rewards [ user ] [ reward ] = r . user_rewards_integral . v assert extcall reward . transfer ( user , d_reward , default_return_value = True ) return d_reward preview_claim() ​ Description: Preview the amount of rewards a user can claim without executing the claim. Returns: uint256 - Preview of claimable rewards. Input Type Description reward IERC20 Reward token to preview user address User to preview for 📄 View Source Code @external @view def preview_claim ( reward : IERC20 , user : address ) - > uint256 : d_reward : uint256 = 0 if reward == YB : d_reward = staticcall GC . preview_emissions ( self , block . timestamp ) else : d_reward = self . _get_vested_rewards ( reward ) r : RewardIntegrals = self . _checkpoint ( reward , d_reward , user ) return r . user_rewards_integral . v - self . claimed_rewards [ user ] [ reward ] add_reward() ​ Description: Adds a new reward token to the gauge. Only callable by owner. Emits: AddReward - When a new reward token is added. Input Type Description token IERC20 Reward token to add distributor address Address that can distribute rewards Requirements: Token must not be YB or LP_TOKEN Token must not already be added Distributor must not be zero address 📄 View Source Code @external @nonreentrant def add_reward ( token : IERC20 , distributor : address ) : assert token != YB , "YB" assert token != LP_TOKEN , "LP_TOKEN" assert distributor != empty ( address ) assert self . rewards [ token ] . distributor == empty ( address ) , "Already added" erc4626 . ownable . _check_owner ( ) self . rewards [ token ] . distributor = distributor reward_id : uint256 = self . reward_count self . reward_tokens [ reward_id ] = token self . reward_count = reward_id + 1 log AddReward ( token = token . address , distributor = distributor , id = reward_id ) deposit_reward() ​ Description: Deposits reward tokens into the gauge for distribution. Can be called by distributor or owner. Emits: DepositRewards - When rewards are deposited. Input Type Description token IERC20 Reward token to deposit amount uint256 Amount of tokens to deposit finish_time uint256 When reward distribution ends Requirements: Token must not be YB Amount must be greater than 0 Caller must be distributor or owner Finish time must be in the future 📄 View Source Code @external @nonreentrant def deposit_reward ( token : IERC20 , amount : uint256 , finish_time : uint256 ) : assert token != YB , "YB" assert amount > 0 , "No rewards" r : Reward = self . rewards [ token ] if msg . sender != r . distributor : erc4626 . ownable . _check_owner ( ) d_reward : uint256 = self . _vest_rewards ( token , False ) ri : RewardIntegrals = self . _checkpoint ( token , d_reward , empty ( address ) ) self . integral_inv_supply = ri . integral_inv_supply self . integral_inv_supply_4_token [ token ] = ri . integral_inv_supply . v self . reward_rate_integral [ token ] = ri . reward_rate_integral unused_rewards : uint256 = r . total - self . processed_rewards [ token ] if finish_time > 0 or unused_rewards == 0 : assert finish_time > block . timestamp , "Finishes in the past" r . finish_time = finish_time else : assert r . finish_time > block . timestamp , "Rate unknown" r . finish_time = block . timestamp + ( r . finish_time - block . timestamp ) * ( unused_rewards + amount ) // unused_rewards r . total += amount self . rewards [ token ] = r assert extcall token . transferFrom ( msg . sender , self , amount , default_return_value = True ) log DepositRewards ( token = token . address , distributor = msg . sender , amount = amount , finish_time = r . finish_time ) get_adjustment() ​ Description: Returns the adjustment factor based on the gauge's share of total LP supply. Used by GaugeController for weight calculations. Returns: uint256 - Adjustment factor (square root of gauge's LP share). 📄 View Source Code @external @view def get_adjustment ( ) - > uint256 : staked : uint256 = staticcall LP_TOKEN . balanceOf ( self ) supply : uint256 = staticcall LP_TOKEN . totalSupply ( ) return isqrt ( unsafe_div ( staked * 10 ** 36 , supply ) ) redeem() ​ Description: Redeems shares for LP tokens. Includes emergency-admin path for killed LT tokens — the emergency admin can withdraw user funds to their own wallet ( receiver must equal owner ). Returns: uint256 - Amount of LP tokens received. Emits: Withdraw - When tokens are withdrawn. Input Type Description shares uint256 Number of shares to redeem receiver address Address to receive tokens owner address Address that owns the shares Requirements: Shares must not exceed maximum redeem limit If LT is killed, only emergency admin can withdraw for others (and receiver must equal owner) 📄 View Source Code @external @nonreentrant def redeem ( shares : uint256 , receiver : address , owner : address ) - > uint256 : assert shares <= erc4626 . _max_redeem ( owner ) , "erc4626: redeem more than maximum" sender : address = msg . sender if staticcall LT ( LP_TOKEN . address ) . is_killed ( ) : if msg . sender == staticcall FACTORY . emergency_admin ( ) : assert receiver == owner , "receiver" sender = owner assets : uint256 = erc4626 . _preview_redeem ( shares ) self . _checkpoint_user ( owner ) erc4626 . _withdraw ( sender , receiver , owner , assets , shares ) erc4626 . _check_min_shares ( ) extcall GC . emit ( ) return assets transfer() and transferFrom() ​ Description: Transfer gauge shares between users. Updates checkpoints for both sender and receiver before the ERC-20 transfer, then triggers a GaugeController emit() . Returns: bool - True on success. Emits: Transfer - When shares are transferred. Input Type Description to address Recipient address amount uint256 Amount of shares to transfer Requirements: Sender must have sufficient balance For transferFrom : sufficient allowance must be approved 📄 View Source Code @external @nonreentrant def transfer ( to : address , amount : uint256 ) - > bool : self . _checkpoint_user ( msg . sender ) self . _checkpoint_user ( to ) erc4626 . erc20 . _transfer ( msg . sender , to , amount ) extcall GC . emit ( ) return True @external @nonreentrant def transferFrom ( owner : address , to : address , amount : uint256 ) - > bool : self . _checkpoint_user ( owner ) self . _checkpoint_user ( to ) erc4626 . erc20 . _spend_allowance ( owner , msg . sender , amount ) erc4626 . erc20 . _transfer ( owner , to , amount ) extcall GC . emit ( ) return True Reward Distribution Mechanics ​ The LiquidityGauge distributes rewards through integrals updated by _checkpoint() . Three integrals track state: the global inverse-supply integral (total deposit changes), the reward-rate integral (distribution rate per token), and the user reward integral (each user's accumulated rewards). YB is the primary reward, integrated with the GaugeController: GC.emit() runs on deposits and withdrawals, GC.preview_emissions() previews claims, and get_adjustment() supplies the weight adjustment. The gauge supports up to 8 additional reward tokens beyond YB. The owner adds them via add_reward() ; each has a designated distributor and streams over a set period, with the rate recomputed from remaining rewards and time. Emergency Controls ​ The gauge includes emergency functionality for when the underlying LT token is killed, allowing the emergency admin to withdraw user funds to their own wallet. Emergency mode is determined by LT.is_killed() , with restricted access ensuring only the emergency admin can withdraw for others, and emergency withdrawals must go to the emergency admin's wallet ( receiver == owner enforced). Integration with GaugeController ​ The LiquidityGauge integrates with the GaugeController through weight calculations via get_adjustment() , YB emissions triggered by GC.emit() , emission previews via GC.preview_emissions() for claim calculations, and checkpoint triggers during deposits/withdrawals that update gauge checkpoints. ERC4626 Compliance ​ The contract implements the ERC4626 vault standard: Standard functions — deposit() , withdraw() , mint() , redeem() Preview functions — previewDeposit() , previewWithdraw() , etc. Transfer functions — transfer() , transferFrom() with checkpoint updates Share calculations — Proper asset/share conversion with minimum shares Related ​ DAO: GaugeController — emits YB to this gauge via GC.emit() . DAO: YB Token — reward token. Core: LT — underlying LP token; kill-switch drives emergency-admin path. Action Flow: Stake/Unstake User: Stake yb-LP — user-level task. User: Gauges & Emissions — distribution mechanism. Overview Constants Public Variables Data Structs Events Function Documentation deposit() withdraw() claim() preview_claim() add_reward() deposit_reward() get_adjustment() redeem() transfer() and transferFrom() Reward Distribution Mechanics Emergency Controls Integration with GaugeController ERC4626 Compliance Related ## /dev/dao/fee-distributor On this page Multi-token fee distribution for veYB holders. FeeDistributor.vy receives admin-fee tokens from YieldBasis markets and distributes them to veYB voters by weekly epochs. New balances are smoothed over four future weeks ( OVER_WEEKS = 4 ) to avoid concentrating a large fee arrival into one claim window. Main flows ​ Function Use fill_epochs() Reads newly arrived balances for the current token set and allocates them across the next four weekly epochs. preview_distribution(week_shift) Returns the token amounts scheduled for a given week. preview_claim(receiver, epoch_count, use_vest) Simulates claimable tokens for a receiver. The source notes this must be exposed as a view call in ABI tooling. claim(receiver, epoch_count, use_vest) Claims epoch allocations for the receiver. add_token_set(token_set) Owner-only update that expands the tokens tracked for future distributions. kill_toggle(is_killed) Owner-only kill switch for epoch filling. Claim basis ​ For each epoch, the contract reads historical voting power from VotingEscrow : VE.getPastVotes(user, epoch) VE.getPastTotalSupply(epoch) Each token allocation is epoch_token_amount * user_votes / total_votes . Vesting escrows ​ Claims can route through cliff escrows when use_vest = True . If a receiver might be a cliff-style escrow and is not the caller, the contract can revert with Might be a vest ; use the vest-aware claim path for cliff recipients. Related ​ VotingEscrow Error Codes Event Catalog Main flows Claim basis Vesting escrows Related
프로젝트로 돌아가기