Skip to main content

BunniToken

BunniToken is an ERC20 token contract that represents a user's Liquidity Provider (LP) position in the Bunni ecosystem. It extends the standard ERC20 functionality with additional features such as referral rewards, account locking, and metadata management.

Inheritance

BunniToken inherits from the following interfaces:

  • IERC20: Standard ERC20 interface
  • IERC20Referrer: Interface for tracking referrers of token holders
  • IERC20Lockable: Interface for account locking, which is useful for implementing transferless staking contracts
  • IOwnable: Interface for ownership management
  • IUnlockCallback: Uniswap v4 unlock callback interface

State Variables

metadataURI

string public metadataURI;

A URI pointing to the metadata associated with this token.

Functions

hub

function hub() external view returns (IBunniHub);

Returns the address of the BunniHub contract associated with this token.

token0

function token0() external view returns (Currency);

Returns the address of the first token in the pair.

token1

function token1() external view returns (Currency);

Returns the address of the second token in the pair.

poolManager

function poolManager() external view returns (IPoolManager);

Returns the address of the Uniswap v4 PoolManager contract associated with this token.

mint

function mint(address to, uint256 amount, uint24 referrer) external;

Mints new tokens to the specified address. Can only be called by the BunniHub contract.

ParameterTypeDescription
toaddressThe address to receive the minted tokens
amountuint256The amount of tokens to mint
referreruint24The referrer ID associated with this mint operation

burn (from BunniHub)

function burn(address from, uint256 amount) external;

Burns tokens from a specified address. Can only be called by the BunniHub contract.

ParameterTypeDescription
fromaddressThe address to burn tokens from
amountuint256The amount of tokens to burn

burn (from user)

function burn(uint256 amount) external;

Burns tokens from the caller's address.

ParameterTypeDescription
amountuint256The amount of tokens to burn

initialize

function initialize(address owner_, string calldata metadataURI_) external;

Initializes the BunniToken contract. Can only be called once, typically by the BunniHub contract during deployment.

ParameterTypeDescription
owner_addressThe initial owner of the contract
metadataURI_stringThe initial metadata URI for the token

setMetadataURI

function setMetadataURI(string calldata metadataURI_) external;

Sets the metadata URI for the token. Can only be called by the contract owner.

ParameterTypeDescription
metadataURI_stringThe new URI for token metadata

distributeReferralRewards

function distributeReferralRewards(bool isToken0, uint256 amount) external;

Distributes referral rewards to all referrers. Can be called by anyone, but typically called by the hook contract.

ParameterTypeDescription
isToken0boolWhether the rewards are in token0 or token1
amountuint256The amount of rewards to distribute

claimReferralRewards

function claimReferralRewards(uint24 referrer) external returns (uint256 reward0, uint256 reward1);

Claims referral rewards for a given referrer ID. Can be called by anyone.

ParameterTypeDescription
referreruint24The referrer ID to claim rewards for

Returns:

  • reward0: The amount of token0 rewards claimed
  • reward1: The amount of token1 rewards claimed

getClaimableReferralRewards

function getClaimableReferralRewards(uint24 referrer) external view returns (uint256 reward0, uint256 reward1);

Returns the amount of referral rewards claimable by a given referrer ID.

ParameterTypeDescription
referreruint24The referrer ID to check rewards for

Returns:

  • reward0: The amount of token0 rewards claimable
  • reward1: The amount of token1 rewards claimable

scoreOf

function scoreOf(uint24 referrer) external view returns (uint256 score);

Returns the score of a referrer. The score is the sum of all balances of accounts that have the referrer as their referrer.

ParameterTypeDescription
referreruint24The referrer whose score is to be returned

Returns:

  • score: The score of the referrer

referrerOf

function referrerOf(address account) external view returns (uint24 referrer);

Returns the referrer of an account. Default referrer is 0.

ParameterTypeDescription
accountaddressThe account whose referrer is to be returned

Returns:

  • referrer: The referrer of the account

lock

function lock(IERC20Unlocker unlocker, bytes calldata data) external;

Locks the caller's account, preventing any transfers from the account until it's unlocked.

ParameterTypeDescription
unlockerIERC20UnlockerThe address that will be able to unlock the account
databytesAdditional data with no specified format

unlock

function unlock(address account) external;

Unlocks a previously locked account. Can only be called by the designated unlocker for the account.

ParameterTypeDescription
accountaddressThe account to unlock

isLocked

function isLocked(address account) external view returns (bool);

Checks if an account is locked.

ParameterTypeDescription
accountaddressThe account to check

Returns:

  • bool: True if the account is locked, false otherwise

unlockerOf

function unlockerOf(address account) external view returns (IERC20Unlocker unlocker);

Returns the unlocker of an account.

ParameterTypeDescription
accountaddressThe account whose unlocker is to be returned

Returns:

  • unlocker: The unlocker of the account

Events

SetMetadataURI

event SetMetadataURI(string newURI);

Emitted when the metadata URI is updated.

ParameterTypeDescription
newURIstringThe new metadata URI

Lock

event Lock(address indexed account, IERC20Unlocker indexed unlocker);

Emitted when an account is locked.

ParameterTypeIndexedDescription
accountaddressYesThe account that was locked
unlockerIERC20UnlockerYesThe address designated as the unlocker for the account

Unlock

event Unlock(address indexed account, IERC20Unlocker indexed unlocker);

Emitted when an account is unlocked.

ParameterTypeIndexedDescription
accountaddressYesThe account that was unlocked
unlockerIERC20UnlockerYesThe address that performed the unlock operation