ETH Price: $3,914.03 (-0.34%)

Contract

0xF27D53f21d024643d50de50183932F17638229F6
Transaction Hash
Method
Block
From
To
User_checkpoint1291818962024-12-12 0:16:0929 hrs ago1733962569IN
0xF27D53f2...7638229F6
0 ETH0.0000003189250.00100075
Claim_rewards1291214142024-12-10 14:40:052 days ago1733841605IN
0xF27D53f2...7638229F6
0 ETH0.0001012311321.50000058
Deposit1290875032024-12-09 19:49:433 days ago1733773783IN
0xF27D53f2...7638229F6
0 ETH0.000000504190.00100071
Deposit1290681452024-12-09 9:04:273 days ago1733735067IN
0xF27D53f2...7638229F6
0 ETH0.0000018621240.00010056
Deposit1288797412024-12-05 0:24:198 days ago1733358259IN
0xF27D53f2...7638229F6
0 ETH0.0000012130560.0001007
User_checkpoint1288794942024-12-05 0:16:058 days ago1733357765IN
0xF27D53f2...7638229F6
0 ETH0.0000011282380.00107778
Deposit1288524652024-12-04 9:15:078 days ago1733303707IN
0xF27D53f2...7638229F6
0 ETH0.0000017665470.0001005
Deposit1288517582024-12-04 8:51:338 days ago1733302293IN
0xF27D53f2...7638229F6
0 ETH0.0000006414730.00010068
Deposit1288178872024-12-03 14:02:319 days ago1733234551IN
0xF27D53f2...7638229F6
0 ETH0.0000004856750.00010169
Claim_rewards1288175992024-12-03 13:52:559 days ago1733233975IN
0xF27D53f2...7638229F6
0 ETH0.000100889251.5000011
Deposit1288140402024-12-03 11:54:179 days ago1733226857IN
0xF27D53f2...7638229F6
0 ETH0.0000005345470.00100142
Deposit1287383852024-12-01 17:52:2711 days ago1733075547IN
0xF27D53f2...7638229F6
0 ETH0.0000008688920.0010007
Deposit1287016022024-11-30 21:26:2112 days ago1733001981IN
0xF27D53f2...7638229F6
0 ETH0.0000004189650.0010007
Deposit1287004412024-11-30 20:47:3912 days ago1732999659IN
0xF27D53f2...7638229F6
0 ETH0.0000001569330.00010071
Deposit1286992332024-11-30 20:07:2312 days ago1732997243IN
0xF27D53f2...7638229F6
0 ETH0.0000004619410.00100057
Deposit1286767382024-11-30 7:37:3312 days ago1732952253IN
0xF27D53f2...7638229F6
0 ETH0.0000007510510.00100048
Deposit1286742302024-11-30 6:13:5712 days ago1732947237IN
0xF27D53f2...7638229F6
0 ETH0.0000023595150.00100041
Deposit1286446462024-11-29 13:47:4913 days ago1732888069IN
0xF27D53f2...7638229F6
0 ETH0.0000002397490.00040881
Claim_rewards1286050732024-11-28 15:48:4314 days ago1732808923IN
0xF27D53f2...7638229F6
0 ETH0.0001069901171.50000028
Withdraw1286050712024-11-28 15:48:3914 days ago1732808919IN
0xF27D53f2...7638229F6
0 ETH0.0003778794471.50000028
Deposit1286047052024-11-28 15:36:2714 days ago1732808187IN
0xF27D53f2...7638229F6
0 ETH0.0004676116571.5000003
Permit1286029622024-11-28 14:38:2114 days ago1732804701IN
0xF27D53f2...7638229F6
0 ETH0.0000024091140.00044652
User_checkpoint1285770932024-11-28 0:16:0315 days ago1732752963IN
0xF27D53f2...7638229F6
0 ETH0.0000017810790.00869482
Deposit1285211212024-11-26 17:10:1916 days ago1732641019IN
0xF27D53f2...7638229F6
0 ETH0.0000015886170.0010006
Deposit1285211192024-11-26 17:10:1516 days ago1732641015IN
0xF27D53f2...7638229F6
0 ETH0.0000014523060.0010006
View all transactions

Latest 25 internal transactions (View All)

Advanced mode:
Parent Transaction Hash Block From To
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075572282023-07-30 10:33:53501 days ago1690713233
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075562252023-07-30 10:00:27501 days ago1690711227
0xF27D53f2...7638229F6
0 ETH
1075561822023-07-30 9:59:01501 days ago1690711141
0xF27D53f2...7638229F6
0 ETH
1075561822023-07-30 9:59:01501 days ago1690711141
0xF27D53f2...7638229F6
0 ETH
1075561822023-07-30 9:59:01501 days ago1690711141
0xF27D53f2...7638229F6
0 ETH
1075561822023-07-30 9:59:01501 days ago1690711141
0xF27D53f2...7638229F6
0 ETH
1075561822023-07-30 9:59:01501 days ago1690711141
0xF27D53f2...7638229F6
0 ETH
1075561822023-07-30 9:59:01501 days ago1690711141
0xF27D53f2...7638229F6
0 ETH
View All Internal Transactions

Latest 25 Deposits

L2 Txn Hash L1 Deposit Txn Value Token
0x89eead4cce60cfd39457e71d1dbc65fad21623b515b4cdd6c27638e867a09d102024-12-12 0:13:5729 hrs ago1733962437653.780059452402017476 Balancer (BAL)
0x27661aea4ca35903bbc1214b97d43e1db68edbbce8753a9ddfdc75050747fc132024-12-05 0:10:298 days ago1733357429653.245677490401231781 Balancer (BAL)
0xedfcff50eaed818d035d074be8163a6d042b3e85701c8a5d2b7efa03628924ac2024-11-28 0:15:0115 days ago1732752901928.779138150923701896 Balancer (BAL)
0x3e43bcd2f2fcebdfda85813a4d6c65ac52fbc41cb51ccd773875768f100196f32024-11-21 0:09:5722 days ago1732147797931.066703674200518583 Balancer (BAL)
0x192eb1d5dbb4f1c0b3e0b2d92ed8d86d02ca3391fdceb01ab31324ad0e6721152024-11-14 0:15:0129 days ago1731543301282.218121757490904259 Balancer (BAL)
0xd850b371a9279991e886d98edc45cd8f6d692bb4fd49fbac455b6679eaa015172024-11-07 0:09:5936 days ago1730938199282.135375387234353327 Balancer (BAL)
0xbc5febb39000f8ef230d2ee96a8d7d2b4dcacca3ae0a2b236029a1568d14bc882024-10-31 0:08:1543 days ago1730333295745.988456169978971499 Balancer (BAL)
0xe98cce97e63f774548b263b70a0482bdeb6dee9f7ec2679f84bbf4a1158d75812024-10-24 0:08:0950 days ago1729728489743.141764507044516699 Balancer (BAL)
0xa05f1c4b187789a48f69874c5c18e6bb148f72f7bffc677844063347a25ecb902024-10-17 0:08:1357 days ago1729123693732.578969914038984058 Balancer (BAL)
0xcce815de2c5c469739a0703f79af4a43068ca6673adea168a856f4ad815cc2ad2024-10-10 0:08:1364 days ago1728518893731.838117877734815282 Balancer (BAL)
0x85350ab05af5dbf44337cda08cea2fe77683f855a0c64b308fdef78f4353c1a82024-10-03 0:08:1171 days ago1727914091672.20019390090623195 Balancer (BAL)
0x483bb30db2716538bcf1f61e8b08b6fd0e577ef48874ea92aeeab764227782e02024-09-26 0:10:0378 days ago1727309403672.428815521206820912 Balancer (BAL)
0x76757c2a91d2c609efbb4e6d52447e98c081145129229417ee1d77164e4d13d82024-09-19 0:08:1785 days ago1726704497727.835853124757778563 Balancer (BAL)
0x24bf8cbcb7d6a0753f1ddd7e95a405baffa67c03363d48100c83849f472ef4f92024-09-12 0:08:1392 days ago1726099693727.040470663194291722 Balancer (BAL)
0xfe10eb3efaef584bd99b9eae99673c74e619c0dfa2bf87f546464eb6cff027272024-09-05 0:08:2199 days ago1725494901793.827417760614399633 Balancer (BAL)
0x635ac467804d06301536bf2af9a022a3b5bb2550344bab39550b47ba97496b312024-08-29 0:08:09106 days ago1724890089814.79687143965265975 Balancer (BAL)
0x74faba763244456ad645256597f247b08720c0be0ee27c9bac308194b6bce6e22024-08-22 0:08:15113 days ago1724285295652.196239199337979437 Balancer (BAL)
0x41030aa439bfe3f547e8c7a8be6b5ab0bbe06edf4b68c02f897b36491839336a2024-08-15 0:08:31120 days ago1723680511661.875782641975535724 Balancer (BAL)
0xa4397c7ff6801e3532e14a045dc715c6500a341446062ccfe041f5db8c6b4d652024-08-08 0:08:17127 days ago1723075697896.859051489892963861 Balancer (BAL)
0x1d656d424604d6f812ef01da17029410366cf331725868a216e699603864770b2024-08-01 0:08:21134 days ago1722470901907.409158774554078695 Balancer (BAL)
0xa4fd250f8f848bf05b7b9cd08a40f6b9d72875f1ba57996f65c962435f2b94802024-07-25 0:08:09141 days ago1721866089840.607406012615123466 Balancer (BAL)
0x66a74f7fbb8134afdfdfc21b556d4bb3566538e4dc1f0463896a673d05d3b11b2024-07-18 0:08:13148 days ago1721261293845.691075259770567333 Balancer (BAL)
0x032b60afc1329efb7dac04c781d606ed8d49627ad4187006628cb01fa975bd2d2024-07-11 0:08:27155 days ago17206565071,049.20023506349792948 Balancer (BAL)
0x2a9d71e59c7a03823f80548a11ebd1138ac2b6f2599d8e335583901b8b6baa102024-07-04 0:08:09162 days ago17200516891,046.213118174167757895 Balancer (BAL)
0xd067d3f934aae517791d45e3d777f8e947d81cfd40a1a7e70d17099e39c269b62024-06-27 0:08:19169 days ago1719446899923.723014999487645346 Balancer (BAL)
View All Deposits

Loading...
Loading

Minimal Proxy Contract for 0x81cfae226343b24ba12ec6521db2c79e7aeeb310

Contract Name:
Vyper_contract

Compiler Version
vyper:0.3.3

Optimization Enabled:
N/A

Other Settings:
default evmVersion, MIT license

Contract Source Code (Vyper language format)

# @version 0.3.3
"""
@title Child Liquidity Gauge
@license MIT
@author Curve Finance
"""
from vyper.interfaces import ERC20

implements: ERC20


interface ERC20Extended:
    def symbol() -> String[26]: view

interface Minter:
    def minted(_user: address, _gauge: address) -> uint256: view
    def getBalancerToken() -> address: view

interface ERC1271:
    def isValidSignature(_hash: bytes32, _signature: Bytes[65]) -> bytes32: view

interface AuthorizerAdaptor:
    def getVault() -> address: view

interface VotingEscrowDelegationProxy:
    def totalSupply() -> uint256: view
    def adjustedBalanceOf(_account: address) -> uint256: view


event Approval:
    _owner: indexed(address)
    _spender: indexed(address)
    _value: uint256

event Transfer:
    _from: indexed(address)
    _to: indexed(address)
    _value: uint256

event Deposit:
    _user: indexed(address)
    _value: uint256

event Withdraw:
    _user: indexed(address)
    _value: uint256

event UpdateLiquidityLimit:
    _user: indexed(address)
    _original_balance: uint256
    _original_supply: uint256
    _working_balance: uint256
    _working_supply: uint256


struct Reward:
    distributor: address
    period_finish: uint256
    rate: uint256
    last_update: uint256
    integral: uint256


DOMAIN_TYPE_HASH: constant(bytes32) = keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)")
PERMIT_TYPE_HASH: constant(bytes32) = keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)")
ERC1271_MAGIC_VAL: constant(bytes32) = 0x1626ba7e00000000000000000000000000000000000000000000000000000000

MAX_REWARDS: constant(uint256) = 8
TOKENLESS_PRODUCTION: constant(uint256) = 40
WEEK: constant(uint256) = 86400 * 7


BAL: immutable(address)
BAL_PSEUDO_MINTER: immutable(address)
VE_DELEGATION_PROXY: immutable(address)
BAL_VAULT: immutable(address)
AUTHORIZER_ADAPTOR: immutable(address)

DOMAIN_SEPARATOR: public(bytes32)
nonces: public(HashMap[address, uint256])

name: public(String[64])
symbol: public(String[32])

_allowance: HashMap[address, HashMap[address, uint256]]
balanceOf: public(HashMap[address, uint256])
totalSupply: public(uint256)

lp_token: public(address)
version: public(String[128])
factory: public(address)

working_balances: public(HashMap[address, uint256])
working_supply: public(uint256)

period: public(uint256)
period_timestamp: public(HashMap[uint256, uint256])

integrate_checkpoint_of: public(HashMap[address, uint256])
integrate_fraction: public(HashMap[address, uint256])
integrate_inv_supply: public(HashMap[uint256, uint256])
integrate_inv_supply_of: public(HashMap[address, uint256])

# For tracking external rewards
reward_count: public(uint256)
reward_tokens: public(address[MAX_REWARDS])
reward_data: public(HashMap[address, Reward])
# claimant -> default reward receiver
rewards_receiver: public(HashMap[address, address])
# reward token -> claiming address -> integral
reward_integral_for: public(HashMap[address, HashMap[address, uint256]])
# user -> token -> [uint128 claimable amount][uint128 claimed amount]
claim_data: HashMap[address, HashMap[address, uint256]]

is_killed: public(bool)
inflation_rate: public(HashMap[uint256, uint256])


@external
def __init__(
    _voting_escrow_delegation_proxy: address,
    _bal_pseudo_minter: address,
    _authorizer_adaptor: address,
    _version: String[128]
):
    self.lp_token = 0x000000000000000000000000000000000000dEaD
    self.version = _version
    self.factory = 0x000000000000000000000000000000000000dEaD

    VE_DELEGATION_PROXY = _voting_escrow_delegation_proxy
    BAL_PSEUDO_MINTER = _bal_pseudo_minter
    BAL = Minter(_bal_pseudo_minter).getBalancerToken()
    AUTHORIZER_ADAPTOR = _authorizer_adaptor
    BAL_VAULT = AuthorizerAdaptor(_authorizer_adaptor).getVault()


@internal
def _checkpoint(_user: address):
    """
    @notice Checkpoint a user calculating their BAL entitlement
    @param _user User address
    """
    period: uint256 = self.period
    period_time: uint256 = self.period_timestamp[period]
    integrate_inv_supply: uint256 = self.integrate_inv_supply[period]

    # If killed, we skip accumulating inflation in `integrate_inv_supply`
    if block.timestamp > period_time and not self.is_killed:

        working_supply: uint256 = self.working_supply
        prev_week_time: uint256 = period_time
        week_time: uint256 = min((period_time + WEEK) / WEEK * WEEK, block.timestamp)

        for i in range(256):
            dt: uint256 = week_time - prev_week_time

            if working_supply != 0:
                # we don't have to worry about crossing inflation epochs
                # and if we miss any weeks, those weeks inflation rates will be 0 for sure
                # but that means no one interacted with the gauge for that long
                integrate_inv_supply += self.inflation_rate[prev_week_time / WEEK] * 10 ** 18 * dt / working_supply

            if week_time == block.timestamp:
                break
            prev_week_time = week_time
            week_time = min(week_time + WEEK, block.timestamp)

    # check BAL balance and increase weekly inflation rate by delta for the rest of the week
    bal_balance: uint256 = ERC20(BAL).balanceOf(self)
    if bal_balance != 0:
        current_week: uint256 = block.timestamp / WEEK
        self.inflation_rate[current_week] += bal_balance / ((current_week + 1) * WEEK - block.timestamp)
        ERC20(BAL).transfer(BAL_PSEUDO_MINTER, bal_balance)

    period += 1
    self.period = period
    self.period_timestamp[period] = block.timestamp
    self.integrate_inv_supply[period] = integrate_inv_supply

    working_balance: uint256 = self.working_balances[_user]
    self.integrate_fraction[_user] += working_balance * (integrate_inv_supply - self.integrate_inv_supply_of[_user]) / 10 ** 18
    self.integrate_inv_supply_of[_user] = integrate_inv_supply
    self.integrate_checkpoint_of[_user] = block.timestamp


@internal
def _update_liquidity_limit(_user: address, _user_balance: uint256, _total_supply: uint256):
    """
    @notice Calculate working balances to apply amplification of BAL production.
    @param _user The user address
    @param _user_balance User's amount of liquidity (LP tokens)
    @param _total_supply Total amount of liquidity (LP tokens)
    """
    working_balance: uint256 = _user_balance * TOKENLESS_PRODUCTION / 100

    ve: address = VE_DELEGATION_PROXY
    if ve != ZERO_ADDRESS:
        ve_ts: uint256 = VotingEscrowDelegationProxy(ve).totalSupply()
        if ve_ts != 0:
            ve_user_balance: uint256 = VotingEscrowDelegationProxy(ve).adjustedBalanceOf(_user)
            working_balance += _total_supply * ve_user_balance / ve_ts * (100 - TOKENLESS_PRODUCTION) / 100
            working_balance = min(_user_balance, working_balance)

    old_working_balance: uint256 = self.working_balances[_user]
    self.working_balances[_user] = working_balance

    working_supply: uint256 = self.working_supply + working_balance - old_working_balance
    self.working_supply = working_supply

    log UpdateLiquidityLimit(_user, _user_balance, _total_supply, working_balance, working_supply)


@view
@internal
def _all_indexes() -> DynArray[uint256, MAX_REWARDS]:
    indexes: DynArray[uint256, MAX_REWARDS] = []
    for i in range(MAX_REWARDS):
        if i >= self.reward_count:
            break
        indexes.append(i)

    return indexes


@internal
def _checkpoint_rewards(
    _user: address,
    _total_supply: uint256,
    _claim: bool,
    _receiver: address,
    _input_reward_indexes: DynArray[uint256, MAX_REWARDS]
):
    """
    @notice Claim pending rewards and checkpoint rewards for a user
    """
    user_balance: uint256 = 0
    receiver: address = _receiver
    if _user != ZERO_ADDRESS:
        user_balance = self.balanceOf[_user]
        if _claim and _receiver == ZERO_ADDRESS:
            # if receiver is not explicitly declared, check if a default receiver is set
            receiver = self.rewards_receiver[_user]
            if receiver == ZERO_ADDRESS:
                # if no default receiver is set, direct claims to the user
                receiver = _user

    reward_count: uint256 = self.reward_count
    reward_indexes: DynArray[uint256, MAX_REWARDS] = []
    if len(_input_reward_indexes) == 0:
        reward_indexes = self._all_indexes()
    else:
        reward_indexes = _input_reward_indexes

    for i in reward_indexes:
        assert i < reward_count, "INVALID_REWARD_INDEX"

        token: address = self.reward_tokens[i]

        integral: uint256 = self.reward_data[token].integral
        last_update: uint256 = min(block.timestamp, self.reward_data[token].period_finish)
        duration: uint256 = last_update - self.reward_data[token].last_update
        if duration != 0:
            self.reward_data[token].last_update = last_update
            if _total_supply != 0:
                integral += duration * self.reward_data[token].rate * 10**18 / _total_supply
                self.reward_data[token].integral = integral

        if _user != ZERO_ADDRESS:
            integral_for: uint256 = self.reward_integral_for[token][_user]
            new_claimable: uint256 = 0

            if integral_for < integral:
                self.reward_integral_for[token][_user] = integral
                new_claimable = user_balance * (integral - integral_for) / 10**18

            claim_data: uint256 = self.claim_data[_user][token]
            total_claimable: uint256 = shift(claim_data, -128) + new_claimable
            if total_claimable > 0:
                total_claimed: uint256 = claim_data % 2**128
                if _claim:
                    response: Bytes[32] = raw_call(
                        token,
                        _abi_encode(
                            receiver,
                            total_claimable,
                            method_id=method_id("transfer(address,uint256)")
                        ),
                        max_outsize=32,
                    )
                    if len(response) != 0:
                        assert convert(response, bool), "TRANSFER_FAILURE"
                    self.claim_data[_user][token] = total_claimed + total_claimable
                elif new_claimable > 0:
                    self.claim_data[_user][token] = total_claimed + shift(total_claimable, 128)


@internal
def _transfer(_from: address, _to: address, _value: uint256):
    if _value == 0:
        return
    total_supply: uint256 = self.totalSupply

    has_rewards: bool = self.reward_count != 0
    for addr in [_from, _to]:
        self._checkpoint(addr)
        # We need to checkpoint all of the rewards before affecting the gauge token balance for a user,
        # but to do it safely we need to skip making external calls. Therefore, we set _claim to False.
        self._checkpoint_rewards(addr, total_supply, False, ZERO_ADDRESS, [])

    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 deposit(_value: uint256, _user: address = msg.sender):
    """
    @notice Deposit `_value` LP tokens
    @param _value Number of tokens to deposit
    @param _user The account to send gauge tokens to
    """
    self._checkpoint(_user)
    if _value == 0:
        return

    total_supply: uint256 = self.totalSupply
    new_balance: uint256 = self.balanceOf[_user] + _value

    if self.reward_count != 0:
        # We need to checkpoint all of the rewards before affecting the gauge token balance for a user,
        # but to do it safely we need to skip making external calls. Therefore, we set _claim to False.
        self._checkpoint_rewards(_user, total_supply, False, ZERO_ADDRESS, [])

    total_supply += _value

    self.balanceOf[_user] = new_balance
    self.totalSupply = total_supply

    self._update_liquidity_limit(_user, new_balance, total_supply)

    ERC20(self.lp_token).transferFrom(msg.sender, self, _value)

    log Deposit(_user, _value)
    log Transfer(ZERO_ADDRESS, _user, _value)


@external
@nonreentrant("lock")
def withdraw(_value: uint256, _user: address = msg.sender):
    """
    @notice Withdraw `_value` LP tokens
    @param _value Number of tokens to withdraw
    @param _user The account to send LP tokens to
    """
    self._checkpoint(_user)
    if _value == 0:
        return

    total_supply: uint256 = self.totalSupply
    new_balance: uint256 = self.balanceOf[msg.sender] - _value

    if self.reward_count != 0:
        # We need to checkpoint all of the rewards before affecting the gauge token balance for a user,
        # but to do it safely we need to skip making external calls. Therefore, we set _claim to False.
        self._checkpoint_rewards(_user, total_supply, False, ZERO_ADDRESS, [])

    total_supply -= _value

    self.balanceOf[msg.sender] = new_balance
    self.totalSupply = total_supply

    self._update_liquidity_limit(msg.sender, new_balance, total_supply)

    ERC20(self.lp_token).transfer(_user, _value)

    log Withdraw(_user, _value)
    log Transfer(msg.sender, ZERO_ADDRESS, _value)


@view
@internal
def _get_allowance(owner: address, spender: address) -> uint256:
    """
     @dev Override to grant the Vault infinite allowance, causing for Gauge Tokens to not require approval.
     This is sound as the Vault already provides authorization mechanisms when initiating token transfers, which this
     contract inherits.
    """
    if (spender == BAL_VAULT):
        return MAX_UINT256
    return self._allowance[owner][spender]

@external
@nonreentrant("lock")
def transferFrom(_from: address, _to: address, _value: uint256) -> bool:
    """
    @notice Transfer tokens from one address to another
    @param _from The address which you want to send tokens from
    @param _to The address which you want to transfer to
    @param _value the amount of tokens to be transferred
    @return bool success
    """
    allowance: uint256 = self._get_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
         {increaseAllowance} 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._allowance[msg.sender][_spender] = _value

    log Approval(msg.sender, _spender, _value)
    return True


@external
def permit(
    _owner: address,
    _spender: address,
    _value: uint256,
    _deadline: uint256,
    _v: uint8,
    _r: bytes32,
    _s: bytes32
) -> bool:
    """
    @notice Approves spender by owner's signature to expend owner's tokens.
        See https://eips.ethereum.org/EIPS/eip-2612.
    @dev Inspired by https://github.com/yearn/yearn-vaults/blob/main/contracts/Vault.vy#L753-L793
    @dev Supports smart contract wallets which implement ERC1271
        https://eips.ethereum.org/EIPS/eip-1271
    @param _owner The address which is a source of funds and has signed the Permit.
    @param _spender The address which is allowed to spend the funds.
    @param _value The amount of tokens to be spent.
    @param _deadline The timestamp after which the Permit is no longer valid.
    @param _v The bytes[64] of the valid secp256k1 signature of permit by owner
    @param _r The bytes[0:32] of the valid secp256k1 signature of permit by owner
    @param _s The bytes[32:64] of the valid secp256k1 signature of permit by owner
    @return True, if transaction completes successfully
    """
    assert _owner != ZERO_ADDRESS, "INVALID_OWNER"
    assert block.timestamp <= _deadline, "DEADLINE_EXPIRED"

    nonce: uint256 = self.nonces[_owner]
    digest: bytes32 = keccak256(
        concat(
            b"\x19\x01",
            self.DOMAIN_SEPARATOR,
            keccak256(_abi_encode(PERMIT_TYPE_HASH, _owner, _spender, _value, nonce, _deadline))
        )
    )

    if _owner.is_contract:
        sig: Bytes[65] = concat(_abi_encode(_r, _s), slice(convert(_v, bytes32), 31, 1))
        assert ERC1271(_owner).isValidSignature(digest, sig) == ERC1271_MAGIC_VAL, "INVALID_SIG"
    else:
        recovered_address: address = ecrecover(digest, convert(_v, uint256), convert(_r, uint256), convert(_s, uint256))
        assert recovered_address == _owner,"INVALID_SIG"

    self._allowance[_owner][_spender] = _value
    self.nonces[_owner] = nonce + 1

    log Approval(_owner, _spender, _value)
    return True


@external
@nonreentrant("lock")
def transfer(_to: address, _value: uint256) -> bool:
    """
    @notice Transfer token to a specified address
    @param _to The address to transfer to
    @param _value The amount to be transferred
    @return bool success
    """
    self._transfer(msg.sender, _to, _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
    """
    allowance: uint256 = self._get_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._get_allowance(msg.sender, _spender) - _subtracted_value
    self._allowance[msg.sender][_spender] = allowance

    log Approval(msg.sender, _spender, allowance)
    return True


@external
def user_checkpoint(addr: address) -> bool:
    """
    @notice Record a checkpoint for `addr`
    @param addr User address
    @return bool success
    """
    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] - Minter(BAL_PSEUDO_MINTER).minted(addr, self)


@view
@external
def claimed_reward(_addr: address, _token: address) -> uint256:
    """
    @notice Get the number of already-claimed reward tokens for a user
    @param _addr Account to get reward amount for
    @param _token Token to get reward amount for
    @return uint256 Total amount of `_token` already claimed by `_addr`
    """
    return self.claim_data[_addr][_token] % 2**128


@view
@external
def claimable_reward(_user: address, _reward_token: address) -> uint256:
    """
    @notice Get the number of claimable reward tokens for a user
    @param _user Account to get reward amount for
    @param _reward_token Token to get reward amount for
    @return uint256 Claimable reward token amount
    """
    integral: uint256 = self.reward_data[_reward_token].integral
    total_supply: uint256 = self.totalSupply
    if total_supply != 0:
        last_update: uint256 = min(block.timestamp, self.reward_data[_reward_token].period_finish)
        duration: uint256 = last_update - self.reward_data[_reward_token].last_update
        integral += (duration * self.reward_data[_reward_token].rate * 10**18 / total_supply)

    integral_for: uint256 = self.reward_integral_for[_reward_token][_user]
    new_claimable: uint256 = self.balanceOf[_user] * (integral - integral_for) / 10**18

    return shift(self.claim_data[_user][_reward_token], -128) + new_claimable


@external
def set_rewards_receiver(_receiver: address):
    """
    @notice Set the default reward receiver for the caller.
    @dev When set to ZERO_ADDRESS, rewards are sent to the caller
    @param _receiver Receiver address for any rewards claimed via `claim_rewards`
    """
    self.rewards_receiver[msg.sender] = _receiver


@external
@nonreentrant('lock')
def claim_rewards(
    _addr: address = msg.sender,
    _receiver: address = ZERO_ADDRESS,
    _reward_indexes: DynArray[uint256, MAX_REWARDS] = []
):
    """
    @notice Claim available reward tokens for `_addr`
    @param _addr Address to claim for
    @param _receiver Address to transfer rewards to - if set to
                     ZERO_ADDRESS, uses the default reward receiver
                     for the caller
    @param _reward_indexes Array with indexes of the rewards to be checkpointed (all of them by default)
    """
    if _receiver != ZERO_ADDRESS:
        assert _addr == msg.sender, "CANNOT_REDIRECT_CLAIM"  # dev: cannot redirect when claiming for another user
    self._checkpoint_rewards(_addr, self.totalSupply, True, _receiver, _reward_indexes)


@external
def add_reward(_reward_token: address, _distributor: address):
    """
    @notice Set the active reward contract.
    @dev The reward token cannot be BAL, since it is transferred automatically to the pseudo minter during checkpoints.
    """
    assert msg.sender == AUTHORIZER_ADAPTOR, "SENDER_NOT_ALLOWED"  # dev: only owner
    assert _reward_token != BAL, "CANNOT_ADD_BAL_REWARD"

    reward_count: uint256 = self.reward_count
    assert reward_count < MAX_REWARDS, "MAX_REWARDS_REACHED"
    assert self.reward_data[_reward_token].distributor == ZERO_ADDRESS, "REWARD_ALREADY_EXISTS"

    self.reward_data[_reward_token].distributor = _distributor
    self.reward_tokens[reward_count] = _reward_token
    self.reward_count = reward_count + 1


@external
def set_reward_distributor(_reward_token: address, _distributor: address):
    current_distributor: address = self.reward_data[_reward_token].distributor

    assert msg.sender in [current_distributor, AUTHORIZER_ADAPTOR], "SENDER_NOT_ALLOWED"
    assert current_distributor != ZERO_ADDRESS, "REWARD_NOT_ADDED"
    assert _distributor != ZERO_ADDRESS, "INVALID_DISTRIBUTOR"

    self.reward_data[_reward_token].distributor = _distributor


@external
@nonreentrant("lock")
def deposit_reward_token(_reward_token: address, _amount: uint256):
    assert msg.sender == self.reward_data[_reward_token].distributor, "SENDER_NOT_ALLOWED"

    # It is safe to checkpoint all the existing rewards as long as `_claim` is set to false (i.e. no external calls).
    self._checkpoint_rewards(ZERO_ADDRESS, self.totalSupply, False, ZERO_ADDRESS, [])

    response: Bytes[32] = raw_call(
        _reward_token,
        _abi_encode(
            msg.sender,
            self,
            _amount,
            method_id=method_id("transferFrom(address,address,uint256)")
        ),
        max_outsize=32,
    )
    if len(response) != 0:
        assert convert(response, bool), "TRANSFER_FROM_FAILURE"

    period_finish: uint256 = self.reward_data[_reward_token].period_finish
    if block.timestamp >= period_finish:
        self.reward_data[_reward_token].rate = _amount / WEEK
    else:
        remaining: uint256 = period_finish - block.timestamp
        leftover: uint256 = remaining * self.reward_data[_reward_token].rate
        self.reward_data[_reward_token].rate = (_amount + leftover) / WEEK

    self.reward_data[_reward_token].last_update = block.timestamp
    self.reward_data[_reward_token].period_finish = block.timestamp + WEEK


@external
def killGauge():
    """
    @notice Kills the gauge so it always yields a rate of 0 and so cannot mint BAL
    """
    assert msg.sender == AUTHORIZER_ADAPTOR, "SENDER_NOT_ALLOWED"  # dev: only owner

    self.is_killed = True


@external
def unkillGauge():
    """
    @notice Unkills the gauge so it can mint BAL again
    """
    assert msg.sender == AUTHORIZER_ADAPTOR, "SENDER_NOT_ALLOWED"  # dev: only owner

    self.is_killed = False


@view
@external
def decimals() -> uint256:
    """
    @notice Returns the number of decimals the token uses
    """
    return 18


@view
@external
def allowance(owner: address, spender: address) -> uint256:
    """
     @notice Get `spender`'s current allowance from `owner` 
    """
    return self._get_allowance(owner, spender)


@view
@external
def integrate_checkpoint() -> uint256:
    return self.period_timestamp[self.period]


@view
@external
def bal_token() -> address:
    return BAL


@view
@external
def bal_pseudo_minter() -> address:
    return BAL_PSEUDO_MINTER


@view
@external
def voting_escrow_delegation_proxy() -> address:
    return VE_DELEGATION_PROXY


@view
@external
def authorizer_adaptor() -> address:
    """
    @notice Return the authorizer adaptor address.
    """
    return AUTHORIZER_ADAPTOR


@external
def initialize(_lp_token: address, _version: String[128]):
    assert self.lp_token == ZERO_ADDRESS, "ALREADY_INITIALIZED"  # dev: already initialzed

    self.lp_token = _lp_token
    self.version = _version
    self.factory = msg.sender

    symbol: String[26] = ERC20Extended(_lp_token).symbol()
    name: String[64] = concat("Balancer ", symbol, " Gauge Deposit")

    self.name = name
    self.symbol = concat(symbol, "-gauge")

    self.period_timestamp[0] = block.timestamp
    self.DOMAIN_SEPARATOR = keccak256(
        _abi_encode(
            DOMAIN_TYPE_HASH,
            keccak256(name),
            keccak256(self.version),
            chain.id,
            self
        )
    )

Contract ABI

[{"name":"Approval","inputs":[{"name":"_owner","type":"address","indexed":true},{"name":"_spender","type":"address","indexed":true},{"name":"_value","type":"uint256","indexed":false}],"anonymous":false,"type":"event"},{"name":"Transfer","inputs":[{"name":"_from","type":"address","indexed":true},{"name":"_to","type":"address","indexed":true},{"name":"_value","type":"uint256","indexed":false}],"anonymous":false,"type":"event"},{"name":"Deposit","inputs":[{"name":"_user","type":"address","indexed":true},{"name":"_value","type":"uint256","indexed":false}],"anonymous":false,"type":"event"},{"name":"Withdraw","inputs":[{"name":"_user","type":"address","indexed":true},{"name":"_value","type":"uint256","indexed":false}],"anonymous":false,"type":"event"},{"name":"UpdateLiquidityLimit","inputs":[{"name":"_user","type":"address","indexed":true},{"name":"_original_balance","type":"uint256","indexed":false},{"name":"_original_supply","type":"uint256","indexed":false},{"name":"_working_balance","type":"uint256","indexed":false},{"name":"_working_supply","type":"uint256","indexed":false}],"anonymous":false,"type":"event"},{"stateMutability":"nonpayable","type":"constructor","inputs":[{"name":"_voting_escrow_delegation_proxy","type":"address"},{"name":"_bal_pseudo_minter","type":"address"},{"name":"_authorizer_adaptor","type":"address"},{"name":"_version","type":"string"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"deposit","inputs":[{"name":"_value","type":"uint256"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"deposit","inputs":[{"name":"_value","type":"uint256"},{"name":"_user","type":"address"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"withdraw","inputs":[{"name":"_value","type":"uint256"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"withdraw","inputs":[{"name":"_value","type":"uint256"},{"name":"_user","type":"address"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"transferFrom","inputs":[{"name":"_from","type":"address"},{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"outputs":[{"name":"","type":"bool"}]},{"stateMutability":"nonpayable","type":"function","name":"approve","inputs":[{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"}],"outputs":[{"name":"","type":"bool"}]},{"stateMutability":"nonpayable","type":"function","name":"permit","inputs":[{"name":"_owner","type":"address"},{"name":"_spender","type":"address"},{"name":"_value","type":"uint256"},{"name":"_deadline","type":"uint256"},{"name":"_v","type":"uint8"},{"name":"_r","type":"bytes32"},{"name":"_s","type":"bytes32"}],"outputs":[{"name":"","type":"bool"}]},{"stateMutability":"nonpayable","type":"function","name":"transfer","inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"outputs":[{"name":"","type":"bool"}]},{"stateMutability":"nonpayable","type":"function","name":"increaseAllowance","inputs":[{"name":"_spender","type":"address"},{"name":"_added_value","type":"uint256"}],"outputs":[{"name":"","type":"bool"}]},{"stateMutability":"nonpayable","type":"function","name":"decreaseAllowance","inputs":[{"name":"_spender","type":"address"},{"name":"_subtracted_value","type":"uint256"}],"outputs":[{"name":"","type":"bool"}]},{"stateMutability":"nonpayable","type":"function","name":"user_checkpoint","inputs":[{"name":"addr","type":"address"}],"outputs":[{"name":"","type":"bool"}]},{"stateMutability":"nonpayable","type":"function","name":"claimable_tokens","inputs":[{"name":"addr","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"claimed_reward","inputs":[{"name":"_addr","type":"address"},{"name":"_token","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"claimable_reward","inputs":[{"name":"_user","type":"address"},{"name":"_reward_token","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"nonpayable","type":"function","name":"set_rewards_receiver","inputs":[{"name":"_receiver","type":"address"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"claim_rewards","inputs":[],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"claim_rewards","inputs":[{"name":"_addr","type":"address"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"claim_rewards","inputs":[{"name":"_addr","type":"address"},{"name":"_receiver","type":"address"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"claim_rewards","inputs":[{"name":"_addr","type":"address"},{"name":"_receiver","type":"address"},{"name":"_reward_indexes","type":"uint256[]"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"add_reward","inputs":[{"name":"_reward_token","type":"address"},{"name":"_distributor","type":"address"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"set_reward_distributor","inputs":[{"name":"_reward_token","type":"address"},{"name":"_distributor","type":"address"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"deposit_reward_token","inputs":[{"name":"_reward_token","type":"address"},{"name":"_amount","type":"uint256"}],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"killGauge","inputs":[],"outputs":[]},{"stateMutability":"nonpayable","type":"function","name":"unkillGauge","inputs":[],"outputs":[]},{"stateMutability":"view","type":"function","name":"decimals","inputs":[],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"allowance","inputs":[{"name":"owner","type":"address"},{"name":"spender","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"integrate_checkpoint","inputs":[],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"bal_token","inputs":[],"outputs":[{"name":"","type":"address"}]},{"stateMutability":"view","type":"function","name":"bal_pseudo_minter","inputs":[],"outputs":[{"name":"","type":"address"}]},{"stateMutability":"view","type":"function","name":"voting_escrow_delegation_proxy","inputs":[],"outputs":[{"name":"","type":"address"}]},{"stateMutability":"view","type":"function","name":"authorizer_adaptor","inputs":[],"outputs":[{"name":"","type":"address"}]},{"stateMutability":"nonpayable","type":"function","name":"initialize","inputs":[{"name":"_lp_token","type":"address"},{"name":"_version","type":"string"}],"outputs":[]},{"stateMutability":"view","type":"function","name":"DOMAIN_SEPARATOR","inputs":[],"outputs":[{"name":"","type":"bytes32"}]},{"stateMutability":"view","type":"function","name":"nonces","inputs":[{"name":"arg0","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"name","inputs":[],"outputs":[{"name":"","type":"string"}]},{"stateMutability":"view","type":"function","name":"symbol","inputs":[],"outputs":[{"name":"","type":"string"}]},{"stateMutability":"view","type":"function","name":"balanceOf","inputs":[{"name":"arg0","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"totalSupply","inputs":[],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"lp_token","inputs":[],"outputs":[{"name":"","type":"address"}]},{"stateMutability":"view","type":"function","name":"version","inputs":[],"outputs":[{"name":"","type":"string"}]},{"stateMutability":"view","type":"function","name":"factory","inputs":[],"outputs":[{"name":"","type":"address"}]},{"stateMutability":"view","type":"function","name":"working_balances","inputs":[{"name":"arg0","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"working_supply","inputs":[],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"period","inputs":[],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"period_timestamp","inputs":[{"name":"arg0","type":"uint256"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"integrate_checkpoint_of","inputs":[{"name":"arg0","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"integrate_fraction","inputs":[{"name":"arg0","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"integrate_inv_supply","inputs":[{"name":"arg0","type":"uint256"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"integrate_inv_supply_of","inputs":[{"name":"arg0","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"reward_count","inputs":[],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"reward_tokens","inputs":[{"name":"arg0","type":"uint256"}],"outputs":[{"name":"","type":"address"}]},{"stateMutability":"view","type":"function","name":"reward_data","inputs":[{"name":"arg0","type":"address"}],"outputs":[{"name":"","type":"tuple","components":[{"name":"distributor","type":"address"},{"name":"period_finish","type":"uint256"},{"name":"rate","type":"uint256"},{"name":"last_update","type":"uint256"},{"name":"integral","type":"uint256"}]}]},{"stateMutability":"view","type":"function","name":"rewards_receiver","inputs":[{"name":"arg0","type":"address"}],"outputs":[{"name":"","type":"address"}]},{"stateMutability":"view","type":"function","name":"reward_integral_for","inputs":[{"name":"arg0","type":"address"},{"name":"arg1","type":"address"}],"outputs":[{"name":"","type":"uint256"}]},{"stateMutability":"view","type":"function","name":"is_killed","inputs":[],"outputs":[{"name":"","type":"bool"}]},{"stateMutability":"view","type":"function","name":"inflation_rate","inputs":[{"name":"arg0","type":"uint256"}],"outputs":[{"name":"","type":"uint256"}]}]

Block Transaction Difficulty Gas Used Reward
View All Blocks Produced

Block Uncle Number Difficulty Gas Used Reward
View All Uncles
Loading...
Loading
Loading...
Loading

Validator Index Block Amount
View All Withdrawals

Transaction Hash Block Value Eth2 PubKey Valid
View All Deposits
[ Download: CSV Export  ]
[ Download: CSV Export  ]
[ Download: CSV Export  ]

A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.