Verified contractPartial
Vyper_contract
Address0x94555c8be71545adff49ca1bb95f4debaf720f15
- Balance
0 ETH
- Transactions
92
- Compiler
vyper 0.2.12
- Same code
16 more contracts
Details
- Compiler
- vyper 0.2.12+commit.2c6842c
- Language
- vyper
- EVM version
- berlin
- License
- Not stated
- Match
- Partialcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 13,297,785
- Creation transaction
- 0x5f371e651a…1d4457e10e
- Main copy (most transactions)
- 0xda42dec0…fb5ad448
Vyper_contract.vy
# @version 0.2.12
"""
@title Liquidity Gauge LIX
@author Lixir Finance
@license MIT
"""
from vyper.interfaces import ERC20
implements: ERC20
interface Controller:
def gauge_relative_weight(addr: address, time: uint256) -> uint256: view
def voting_escrow() -> address: view
def checkpoint(): nonpayable
def checkpoint_gauge(addr: address): nonpayable
interface Distributor:
# lifted from Minter
def lix() -> address: view
def controller() -> address: view
def distributed(user: address, gauge: address) -> uint256: view
# these two are lifted from CRV20
def future_epoch_time_write() -> uint256: nonpayable
def rate() -> uint256: view
interface VotingEscrow:
def user_point_epoch(addr: address) -> uint256: view
def user_point_history__ts(addr: address, epoch: uint256) -> uint256: view
interface ERC20Extended:
def symbol() -> String[26]: view
interface LixirRegistry:
def isGovOrDelegate(account: address) -> bool: view
# Interface for checking whether address belongs to a whitelisted
# type of a smart wallet.
# When new types are added - the whole contract is changed
# The check() method is modifying to be able to use caching
# for individual wallet addresses
interface SmartWalletChecker:
def check(addr: address) -> bool: nonpayable
event Deposit:
provider: indexed(address)
value: uint256
event Withdraw:
provider: indexed(address)
value: uint256
event UpdateLiquidityLimit:
user: address
original_balance: uint256
original_supply: uint256
working_balance: uint256
working_supply: uint256
event Transfer:
_from: indexed(address)
_to: indexed(address)
_value: uint256
event Approval:
_owner: indexed(address)
_spender: indexed(address)
_value: uint256
TOKENLESS_PRODUCTION: constant(uint256) = 40
WEEK: constant(uint256) = 604800
distributor: public(address) # minter: public(address)
lix_token: public(address)
lp_token: public(address)
controller: public(address)
voting_escrow: public(address)
future_epoch_time: public(uint256)
balanceOf: public(HashMap[address, uint256])
totalSupply: public(uint256)
allowance: public(HashMap[address, HashMap[address, uint256]])
name: public(String[64])
symbol: public(String[32])
working_balances: public(HashMap[address, uint256])
working_supply: public(uint256)
# The goal is to be able to calculate ∫(rate * balance / totalSupply dt) from 0 till checkpoint
# All values are kept in units of being multiplied by 1e18
period: public(int128)
period_timestamp: public(uint256[100000000000000000000000000000])
# 1e18 * ∫(rate(t) / totalSupply(t) dt) from 0 till checkpoint
integrate_inv_supply: public(uint256[100000000000000000000000000000]) # bump epoch when rate() changes
# 1e18 * ∫(rate(t) / totalSupply(t) dt) from (last_action) till checkpoint
integrate_inv_supply_of: public(HashMap[address, uint256])
integrate_checkpoint_of: public(HashMap[address, uint256])
# ∫(balance * rate(t) / totalSupply(t) dt) from 0 till checkpoint
# Units: rate * t = already number of coins per address to issue
integrate_fraction: public(HashMap[address, uint256])
distribution_rate: public(uint256) # inflation_rate: public(uint256)
# Checker for whitelisted (smart contract) wallets which are allowed to deposit
# The goal is to prevent tokenizing the escrow
future_smart_wallet_checker: public(address)
smart_wallet_checker: public(address) # veCRV uses this on mainnet: 0xca719728ef172d0961768581fdf35cb116e0b7a4
registry: public(address)
is_killed: public(bool)
@external
def __init__(_lp_token: address, _distributor: address, _registry: address):
"""
@notice Contract constructor
@param _lp_token Liquidity Pool contract address
@param _distributor Distributor contract address
@param _registry Registry
"""
symbol: String[26] = ERC20Extended(_lp_token).symbol()
self.name = concat("Lixir Finance ", symbol, " Gauge Deposit")
self.symbol = concat(symbol, "-gauge")
lix_token: address = Distributor(_distributor).lix()
controller: address = Distributor(_distributor).controller()
self.lp_token = _lp_token
self.distributor = _distributor
self.registry = _registry
self.lix_token = lix_token
self.controller = controller
self.voting_escrow = Controller(controller).voting_escrow()
self.period_timestamp[0] = block.timestamp
self.distribution_rate = Distributor(_distributor).rate()
self.future_epoch_time = Distributor(_distributor).future_epoch_time_write()
@view
@external
def decimals() -> uint256:
"""
@notice Get the number of decimals for this token
@dev Implemented as a view method to reduce gas costs
@return uint256 decimal places
"""
return 18
@view
@external
def integrate_checkpoint() -> uint256:
return self.period_timestamp[self.period]
@external
def commit_smart_wallet_checker(addr: address):
"""
@notice Set an external contract to check for approved smart contract wallets
@param addr Address of Smart contract checker
"""
assert LixirRegistry(self.registry).isGovOrDelegate(msg.sender)
self.future_smart_wallet_checker = addr
@external
def apply_smart_wallet_checker():
"""
@notice Apply setting external contract to check approved smart contract wallets
"""
assert LixirRegistry(self.registry).isGovOrDelegate(msg.sender)
self.smart_wallet_checker = self.future_smart_wallet_checker
@internal
def assert_not_contract(addr: address):
"""
@notice Check if the call is from a whitelisted smart contract, revert if not
@param addr Address to be checked
"""
if addr.is_contract:
checker: address = self.smart_wallet_checker
if checker != ZERO_ADDRESS:
if SmartWalletChecker(checker).check(addr):
return
raise "Smart contract depositors not allowed"
@internal
def _update_liquidity_limit(addr: address, l: uint256, L: uint256):
"""
@notice Calculate limits which depend on the amount of CRV token per-user.
Effectively it calculates working balances to apply amplification
of CRV production by CRV
@param addr User address
@param l User's amount of liquidity (LP tokens)
@param L Total amount of liquidity (LP tokens)
"""
# To be called after totalSupply is updated
_voting_escrow: address = self.voting_escrow
voting_balance: uint256 = ERC20(_voting_escrow).balanceOf(addr)
voting_total: uint256 = ERC20(_voting_escrow).totalSupply()
lim: uint256 = l * TOKENLESS_PRODUCTION / 100
if voting_total > 0:
lim += L * voting_balance / voting_total * (100 - TOKENLESS_PRODUCTION) / 100
lim = min(l, lim)
old_bal: uint256 = self.working_balances[addr]
self.working_balances[addr] = lim
_working_supply: uint256 = self.working_supply + lim - old_bal
self.working_supply = _working_supply
log UpdateLiquidityLimit(addr, l, L, lim, _working_supply)
@internal
def _checkpoint(addr: address):
"""
@notice Checkpoint for a user
@param addr User address
"""
_period: int128 = self.period
_period_time: uint256 = self.period_timestamp[_period]
_integrate_inv_supply: uint256 = self.integrate_inv_supply[_period]
rate: uint256 = self.distribution_rate
new_rate: uint256 = rate
prev_future_epoch: uint256 = self.future_epoch_time
if prev_future_epoch >= _period_time:
_dist: address = self.distributor
self.future_epoch_time = Distributor(self.distributor).future_epoch_time_write()
new_rate = Distributor(self.distributor).rate()
self.distribution_rate = new_rate
if self.is_killed:
# Stop distributing inflation as soon as killed
rate = 0
# Update integral of 1/supply
if block.timestamp > _period_time:
_working_supply: uint256 = self.working_supply
_controller: address = self.controller
Controller(_controller).checkpoint_gauge(self)
prev_week_time: uint256 = _period_time
week_time: uint256 = min((_period_time + WEEK) / WEEK * WEEK, block.timestamp)
for i in range(500):
dt: uint256 = week_time - prev_week_time
w: uint256 = Controller(_controller).gauge_relative_weight(self, prev_week_time / WEEK * WEEK)
if _working_supply > 0:
if prev_future_epoch >= prev_week_time and prev_future_epoch < week_time:
# If we went across one or multiple epochs, apply the rate
# of the first epoch until it ends, and then the rate of
# the last epoch.
# If more than one epoch is crossed - the gauge gets less,
# but that'd meen it wasn't called for more than 1 year
_integrate_inv_supply += rate * w * (prev_future_epoch - prev_week_time) / _working_supply
rate = new_rate
_integrate_inv_supply += rate * w * (week_time - prev_future_epoch) / _working_supply
else:
_integrate_inv_supply += rate * w * dt / _working_supply
# On precisions of the calculation
# rate ~= 10e18
# last_weight > 0.01 * 1e18 = 1e16 (if pool weight is 1%)
# _working_supply ~= TVL * 1e18 ~= 1e26 ($100M for example)
# The largest loss is at dt = 1
# Loss is 1e-9 - acceptable
if week_time == block.timestamp:
break
prev_week_time = week_time
week_time = min(week_time + WEEK, block.timestamp)
_period += 1
self.period = _period
self.period_timestamp[_period] = block.timestamp
self.integrate_inv_supply[_period] = _integrate_inv_supply
# Update user-specific integrals
_working_balance: uint256 = self.working_balances[addr]
self.integrate_fraction[addr] += _working_balance * (_integrate_inv_supply - self.integrate_inv_supply_of[addr]) / 10 ** 18
self.integrate_inv_supply_of[addr] = _integrate_inv_supply
self.integrate_checkpoint_of[addr] = block.timestamp
@external
def user_checkpoint(addr: address) -> bool:
"""
@notice Record a checkpoint for `addr`
@param addr User address
@return bool success
"""
assert (msg.sender == addr) or (msg.sender == self.distributor) # dev: unauthorized
self._checkpoint(addr)
self._update_liquidity_limit(addr, self.balanceOf[addr], self.totalSupply)
return True
@external
def claimable_tokens(addr: address) -> uint256:
"""
@notice Get the number of claimable tokens per user
@dev This function should be manually changed to "view" in the ABI
@return uint256 number of claimable tokens per user
"""
self._checkpoint(addr)
return self.integrate_fraction[addr] - Distributor(self.distributor).distributed(addr, self)
@external
def kick(addr: address):
"""
@notice Kick `addr` for abusing their boost
@dev Only if either they had another voting event, or their voting escrow lock expired
@param addr Address to kick
"""
_voting_escrow: address = self.voting_escrow
t_last: uint256 = self.integrate_checkpoint_of[addr]
t_ve: uint256 = VotingEscrow(_voting_escrow).user_point_history__ts(
addr, VotingEscrow(_voting_escrow).user_point_epoch(addr)
)
_balance: uint256 = self.balanceOf[addr]
assert ERC20(_voting_escrow).balanceOf(addr) == 0 or t_ve > t_last # dev: kick not allowed
assert self.working_balances[addr] > _balance * TOKENLESS_PRODUCTION / 100 # dev: kick not needed
self._checkpoint(addr)
self._update_liquidity_limit(addr, self.balanceOf[addr], self.totalSupply)
@external
@nonreentrant('lock')
def deposit(_value: uint256, _addr: address = msg.sender, args: Bytes[128] = b""):
"""
@notice Deposit `_value` LP tokens
@param _value Number of tokens to deposit
@param _addr Address to deposit for
"""
self.assert_not_contract(msg.sender)
self._checkpoint(_addr)
if _value != 0:
total_supply: uint256 = self.totalSupply
total_supply += _value
new_balance: uint256 = self.balanceOf[_addr] + _value
self.balanceOf[_addr] = new_balance
self.totalSupply = total_supply
self._update_liquidity_limit(_addr, new_balance, total_supply)
if len(args) != 0:
raw_call(
self.lp_token,
concat(
method_id("permit(address,address,uint256,uint256,uint8,bytes32,bytes32)"),
convert(_addr, bytes32),
convert(self, bytes32),
convert(_value, bytes32),
args
)
)
ERC20(self.lp_token).transferFrom(_addr, self, _value)
else:
ERC20(self.lp_token).transferFrom(msg.sender, self, _value)
log Deposit(_addr, _value)
log Transfer(ZERO_ADDRESS, _addr, _value)
@external
@nonreentrant('lock')
def withdraw(_value: uint256):
"""
@notice Withdraw `_value` LP tokens
@param _value Number of tokens to withdraw
"""
self._checkpoint(msg.sender)
if _value != 0:
total_supply: uint256 = self.totalSupply
total_supply -= _value
new_balance: uint256 = self.balanceOf[msg.sender] - _value
self.balanceOf[msg.sender] = new_balance
self.totalSupply = total_supply
self._update_liquidity_limit(msg.sender, new_balance, total_supply)
# TODO doesn't this need to check that _value is correct? How do you stop someone from just withdrawing everything when they don't have the balance??
ERC20(self.lp_token).transfer(msg.sender, _value)
log Withdraw(msg.sender, _value)
log Transfer(msg.sender, ZERO_ADDRESS, _value)
@internal
def _transfer(_from: address, _to: address, _value: uint256):
self._checkpoint(_from)
self._checkpoint(_to)
if _value != 0:
total_supply: uint256 = self.totalSupply
new_balance: uint256 = self.balanceOf[_from] - _value
self.balanceOf[_from] = new_balance
self._update_liquidity_limit(_from, new_balance, total_supply)
new_balance = self.balanceOf[_to] + _value
self.balanceOf[_to] = new_balance
self._update_liquidity_limit(_to, new_balance, total_supply)
log Transfer(_from, _to, _value)
@external
@nonreentrant('lock')
def transfer(_to : address, _value : uint256) -> bool:
"""
@notice Transfer token for a specified address
@param _to The address to transfer to.
@param _value The amount to be transferred.
"""
self.assert_not_contract(_to)
self._transfer(msg.sender, _to, _value)
return True
@external
@nonreentrant('lock')
def transferFrom(_from : address, _to : address, _value : uint256) -> bool:
"""
@notice Transfer tokens from one address to another.
@param _from address The address which you want to send tokens from
@param _to address The address which you want to transfer to
@param _value uint256 the amount of tokens to be transferred
"""
self.assert_not_contract(_to)
_allowance: uint256 = self.allowance[_from][msg.sender]
if _allowance != MAX_UINT256:
self.allowance[_from][msg.sender] = _allowance - _value
self._transfer(_from, _to, _value)
return True
@external
def approve(_spender : address, _value : uint256) -> bool:
"""
@notice Approve the passed address to transfer the specified amount of
tokens on behalf of msg.sender
@dev Beware that changing an allowance via this method brings the risk
that someone may use both the old and new allowance by unfortunate
transaction ordering. This may be mitigated with the use of
{incraseAllowance} and {decreaseAllowance}.
https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
@param _spender The address which will transfer the funds
@param _value The amount of tokens that may be transferred
@return bool success
"""
self.assert_not_contract(_spender)
self.allowance[msg.sender][_spender] = _value
log Approval(msg.sender, _spender, _value)
return True
@external
def increaseAllowance(_spender: address, _added_value: uint256) -> bool:
"""
@notice Increase the allowance granted to `_spender` by the caller
@dev This is alternative to {approve} that can be used as a mitigation for
the potential race condition
@param _spender The address which will transfer the funds
@param _added_value The amount of to increase the allowance
@return bool success
"""
self.assert_not_contract(_spender)
allowance: uint256 = self.allowance[msg.sender][_spender] + _added_value
self.allowance[msg.sender][_spender] = allowance
log Approval(msg.sender, _spender, allowance)
return True
@external
def decreaseAllowance(_spender: address, _subtracted_value: uint256) -> bool:
"""
@notice Decrease the allowance granted to `_spender` by the caller
@dev This is alternative to {approve} that can be used as a mitigation for
the potential race condition
@param _spender The address which will transfer the funds
@param _subtracted_value The amount of to decrease the allowance
@return bool success
"""
allowance: uint256 = self.allowance[msg.sender][_spender] - _subtracted_value
self.allowance[msg.sender][_spender] = allowance
log Approval(msg.sender, _spender, allowance)
return True
@external
def set_killed(_is_killed: bool):
"""
@notice Set the killed status for this contract
@dev When killed, the gauge always yields a rate of 0 and so cannot mint CRV
@param _is_killed Killed status to set
"""
assert LixirRegistry(self.registry).isGovOrDelegate(msg.sender)
self.is_killed = _is_killedCompiler settingsShow
{
"evmVersion": "berlin",
"search_paths": [
"."
]
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.