Gauge

Gauge is a voting contract for liquidity pools, with each liquidity pool having its own Gauge contract.

rescueERC20

Rescues tokens stuck in the contract.

function rescueERC20(
    address tokenAddress, 
    address to, 
    uint256 amount) onlyOwner external

Parameters:

NameTypeDescription

tokenAddress

address

Address of the token to be rescued.

to

address

Address that will receive the tokens.

amount

uint

Amount of tokens to be rescued.

setParams

Sets parameters (weight, base, and slope) of the Gauge contract.

  • weight: Weight determines the how much reward user can earn in Farm contract. The higher the weight, the lower the reward.

  • base : Base reward rate.

  • slope : Slope of reward rate.

Please refer to Point voting to learn more about ratePoint calculation.

function setParams(
    uint _weight, 
    uint _base, 
    uint _slope) external onlyOwner

Parameters:

NameTypeDescription

_weight

uint

New weight.

_base

uint

New base reward rate.

_slope

uint

New slope of the reward rate.

balanceOf

Retrieves the user's latest balance, i.e., balance recorded in the user's latest checkpoint.

function balanceOf(
    address account) public view returns (uint)

Parameters:

NameTypeDescription

account

address

User's address.

Return Values:

NameTypeDescription

balance

uint

User's latest balance.

balanceOfAt

Retrieves the user's balance at a given week. If no checkpoint is recorded at the given week, it searches for the latest checkpoint among previous ones.

function balanceOfAt(
    address account, 
    uint week) external view returns (uint)

Parameters:

NameTypeDescription

account

address

User's address.

week

uint

The week to find out the user's balance.

Return Values:

NameTypeDescription

balance

uint

User's balance at the given week.

totalSupplyAt

Total supply at a given week.

function totalSupplyAt(
    uint week) public view returns (uint)

Parameters:

NameTypeDescription

week

uint

The week to find out the total supply.

Return Values:

NameTypeDescription

totalSupply

uint

Total supply.

tick

This function serves the purpose of updating the contract's state, specifically handling the transition to a new week. Below is an introduction to what the tick function does:

  1. Week Update:

    • The function first calculates the current week based on the current timestamp divided by the duration of a week (1 week). The result is stored in the _week variable.

  2. Checkpoint and Total Supply Update:

    • If the calculated _week is greater than the current thisWeek stored in the contract, it means a new week has begun.

    • For each week between the current thisWeek and the new _week (exclusive), the function updates the total supply checkpoint (_totalSupplyAt) with the current totalSupply.

    • The thisWeek is then updated to the new _week.

  3. Reward Rate Update:

    • The function calls the internal _updateRewardRate function to update the reward rate recorded in the associated Farm contract based on the latest total supply and the configured slope and base values.

function tick() public

updateTotalSupply

Update latest total supply and trigger tick.

function updateTotalSupply(
    uint _totalSupply) internal

Parameters:

NameTypeDescription

_totalSupply

uint

New total supply.

nextRewardRate

Compute new reward rate base on latest totalSupply, slope and base. The formula is as follows:

newRewardRate = totalSupply * slope / REWARD_RATE_BASE_UNIT + base;
  • totalSupply: This represents the total supply of the sGov token in the Gauge contract. It's the sum of all the sGov tokens deposited by users.

  • slope: This is a configurable parameter that determines the rate at which the reward rate increases based on the total supply. A higher slope means a faster increase in the reward rate.

  • REWARD_RATE_BASE_UNIT: This is a constant value set as 1e18 representing the base unit for the reward rate. It's used to ensure that the result is in the correct units.

  • base: This is another configurable parameter that represents the base reward rate. It's the minimum reward rate that the contract will provide, irrespective of the total supply.

Please refer to Point voting to learn more about reward rate calculation.

function nextRewardRate() public view returns (uint newRewardRate)

Return Values:

NameTypeDescription

newRewardRate

uint

New reward rate.

deposit

Deposits sGOV tokens on behalf of a user. This function plays a crucial role in the liquidity mining mechanism, where users deposit sGov tokens to earn additional rewards. Below is an introduction to what the deposit function does:

  1. Token Transfer:

    • Transfers the specified amount of sGov tokens from the sender's address to the Gauge contract. This requires prior approval of the sGov token by the user.

  2. Checkpoint Update:

    • Records a new checkpoint for the user, updating their balance with the deposited amount. This allows the contract to keep track of the user's historical balances.

  3. Total Supply Update:

    • Updates the total supply of sGov tokens in the Gauge by adding the deposited amount. This is essential for calculating the reward rates accurately.

Please refer to Boost section to learn more about performing a deposit to Gauge.

function deposit(
    uint amount, 
    address to) external

Parameters:

NameTypeDescription

amount

uint

Amount of sGOV tokens to deposit.

to

address

Address that owns the amount of sGOV tokens.

applyWithdrawal

This function allows users to initiate the process of withdrawing their sGov tokens from the Gauge. This function introduces a delay of one week before the actual withdrawal occurs. Users must call this function to express their intent to withdraw, and the withdrawal will be processed after the specified delay. Below is an introduction to what the applyWithdrawal function does:

  1. Checkpoint Update:

    • Updates the user's checkpoint by reducing their recorded balance by the withdrawal amount. This reflects the intention to withdraw in the historical balance records.

  2. Total Supply Update:

    • Decreases the total supply of sGov tokens in the Gauge, accounting for the pending withdrawal. This ensures accurate reward rate calculations.

  3. Pending Withdrawal Record:

    • Records the withdrawal amount as pending for the user. This amount will be available for withdrawal after the specified delay.

  4. Week to Withdraw Update:

    • Sets the week when the user can complete the withdrawal. The withdrawal delay is one week, so it will be processed in the subsequent week.

function applyWithdrawal(
    uint amount) external

Parameters:

NameTypeDescription

amount

uint

Amount of sGOV tokens to withdraw.

withdraw

The withdraw function in the Gauge contract allows users to complete their withdrawal of sGov tokens. This function is typically called after a one-week delay from the time the user initiated the withdrawal by calling the applyWithdrawal function. The purpose of the delay is to allow for a period during which the user's withdrawal request can be processed and confirmed. Below is an introduction to what the withdraw function does:

  1. Requirements:

    • Ensures that the withdrawal can only be completed after the specified one-week delay has passed. Also Ensures that the withdrawal amount is non-zero.

  2. Amount Calculation:

    • Retrieves the amount of sGov tokens that was previously marked as pending for withdrawal.

  3. Pending Withdrawal Clearing:

    • Clears the pending withdrawal amount for the user after successfully completing the withdrawal.

  4. Token Transfer:

    • Transfers the withdrawn sGov tokens from the Gauge contract to the user's address.

function withdraw() external returns (uint amount)

Return Values:

NameTypeDescription

amount

uint

Amount of sGOV tokens withdrawn.

bonus

This function calculates the bonus ratio for a user based on their latest balance of sGov tokens. The bonus ratio is designed to provide additional rewards to users with smaller balances, encouraging broader participation. The formula for calculating the bonus is as follows:

_bonus = (balance * BONUS_MULTIPLIER / totalSupply).sqrt();
_bonus = _bonus > MAX_BONUS ? MAX_BONUS : _bonus;
  • balance: Represents the user's latest balance of sGov tokens.

  • BONUS_MULTIPLIER: A constant factor used to scale the bonus calculation which is set as 22.5e36.

  • totalSupply: Refers to the total supply of sGov tokens in the Gauge contract.

  • _bonus: The calculated bonus ratio for the user.

  • MAX_BONUS: The max bonus ratio is set as 1.5e18 . Bonus ratio approaches max when the user's balance gets closer to 1/10 of total supply.

The formula computes a preliminary bonus value, adjusts it using the square root operation, and then caps the final bonus ratio at a specified maximum value (MAX_BONUS). The intention is to incentivize users with smaller balances by providing a non-linear bonus that diminishes as the user's balance increases.

function bonus(
    address user) external view returns (uint _bonus)

Parameters:

NameTypeDescription

user

address

User's address.

Return Values:

NameTypeDescription

_bonus

uint

User's bonus ratio.

Last updated