Coin
The Coin
contract is the core contract for the freee.fun Coins Protocol. It is an non-upgradeable ERC20 contract that allows for the creation of media coins.
Overview
The Coin
contract implements the ICoin
interface, which extends several standard interfaces:
IERC165
: Standard interface detectionIERC7572
: Standard for protocol-specific metadata
Each coin is created with a Uniswap V3 liquidity pool, enabling immediate trading functionality.
Key Features
ERC20 Functionality: Basic token transfers, approvals, and balance tracking
Trading: Built-in buy and sell functions with Uniswap V3 integration. Allows for owners to trade without approvals on uniswap.
Reward Distribution: Mechanisms for distributing rewards to creators, referrers, and the protocol
Metadata Management: Updatable contract metadata via URI
Multi-Ownership: Support for multiple owners with permission control
Core Functions
Trading
Buy
This function allows users to buy coins using ETH or the configured trading currency (typically WETH). The buyer sends the currency and receives selected coins in return.
Parameters:
recipient
: The address that will receive the purchased coinsorderSize
: The amount of currency to spend (in wei)minAmountOut
: Minimum amount of coins to receive (slippage protection)sqrtPriceLimitX96
: Price limit for the UniswapV3 swap (0 for no limit)tradeReferrer
: Address that receives a portion of the trading fee (optional)
Returns:
The actual amount of currency spent and coins purchased
Sell
This function allows users to sell their coins in exchange for ETH or the configured trading currency.
Parameters:
recipient
: The address that will receive the currency proceedsorderSize
: The amount of coins to sellminAmountOut
: Minimum amount of currency to receive (slippage protection)sqrtPriceLimitX96
: Price limit for the UniswapV3 swap (0 for no limit)tradeReferrer
: Address that receives a portion of the trading fee (optional)
Returns:
The actual amount of coins sold and currency received
Burn
Allows users to burn their own tokens, permanently removing them from circulation.
Management Functions
setContractURI
Updates the coin's metadata URI. This can only be called by an owner of the coin.
setPayoutRecipient
Updates the address that receives creator rewards. This can only be called by owner of the coin.
Query Functions
These functions provide access to coin's information:
tokenURI
: Returns the coin's metadata URIplatformReferrer
: Returns the address of the platform referrer who earns fees from trades
Events
The contract emits various events to track important actions:
TokensPurchased
Emitted when coins are purchased, tracking the buyer, recipient, trade referrer, amount of coins purchased, currency used, fees paid, and total amount spent.
TokensSold
Emitted when coins are sold, tracking the seller, recipient, trade referrer, amount of coins sold, currency received, fees paid, and total amount received.
TokensTransferred
Emitted on any token transfer, providing detailed information about the transfer including updated balances.
TradeRewardsDistributed
Emitted when trade rewards are distributed, tracking all reward recipients and amounts.
LiquidityRewardsDistributed
Emitted when market rewards (from liquidity pool fees) are distributed.
MetadataUpdated
Emitted when the contract metadata URI is updated.
PayoutRecipientChanged
Emitted when the payout recipient is updated.
Error Handling
The contract defines several custom errors that provide specific information about failed operations:
AddressZero
: Operation attempted with a zero addressInsufficientFunds
: Insufficient funds for the operationInsufficientLiquidity
: Insufficient liquidity for a transactionSlippageBoundsExceeded
: Slippage bounds exceeded during a transactionInitialOrderSizeTooLarge
: Initial order size too largeEthAmountMismatch
: ETH value doesn't match the currency amountEthAmountTooSmall
: ETH amount too small for the transactionERC20TransferAmountMismatch
: Unexpected ERC20 transfer amountEthTransferInvalid
: Invalid ETH transferEthTransferFailed
: ETH transfer failedOnlyPool
: Operation only available to the Uniswap poolOnlyWeth
: Operation only available to WETHInvalidCurrencyLowerTick
: Invalid tick configurationInvalidWethLowerTick
: Invalid WETH tick configuration
Last updated