π§βπ»Smart Contract
The UniswapFirstBuy
contract is a pivotal part of the 0xFair Lab ecosystem, designed to facilitate fair and secure token launches. This contract, being an Ownable
contract, grants exclusive control to the owner (usually the deploying entity) over certain functions, enhancing security and governance.
Mainnet smart contract is deployed here.
Key Features of the UniswapFirstBuy Contract
Contribution and Token Tracking:
totalEthContributed
: Tracks the total ETH contributed by participants.totalTokensBought
: Records the total number of tokens bought through the contract.maxContribution
: Limits the maximum ETH contribution, ensuring fair participation and preventing large-scale whale manipulation.
Allowlist Management:
firstBuyAllowlist
: Holds the address of the allowlist contract, ensuring that only pre-approved participants can contribute.
Token Integration:
tokenAddress
andtoken
: These represent the address and interface of the token being launched, integrating the token directly with the contract.
Launch State Controls:
isOpen
: Indicates if the contract is open for contributions.isLiquidityAdded
: Ensures that the launch process can only be executed once.
Uniswap Integration:
uniswapV2Router
: An immutable instance of the Uniswap V2 Router, enabling the contract to interact with Uniswap for token swaps.
Contribution Tracking:
ethContributions
: A mapping to track the ETH contributed by each address.
Contract Workflow
Initialization:
The contract is deployed with the Uniswap V2 Router address, establishing the connection to Uniswap.
Configuration:
The contract owner sets the token address, maximum contribution limit, and the allowlist address.
Token Launch:
The
launchToken
function is called by the owner, adding liquidity to Uniswap and buying tokens with the accumulated ETH contributions.This function turns off further contributions by setting
isOpen
to false and marksisLiquidityAdded
as true.
Contributions:
Participants can contribute ETH by sending it directly to the contract.
The contract checks for allowlist inclusion, contribution limits, and open state before accepting ETH.
Token Purchase:
buyTokensWithEth
is triggered internally, using ETH to buy tokens on Uniswap.The contract calculates the new total tokens bought and updates the balance.
Token Withdrawal:
Participants can withdraw their tokens through
withdrawTokens
.The contract calculates the token amount based on the participantβs ETH contribution and sends the tokens to them.
Token Distribution Calculation:
calculateTokenAmount
determines the number of tokens a user can withdraw, based on their contribution and the total tokens bought.
Conclusion
The UniswapFirstBuy
contract is meticulously designed to ensure a fair, transparent, and secure token launch experience. By automating critical processes and enforcing strict guidelines, it plays a crucial role in upholding the integrity and fairness of every launch on 0xFair Lab.
Last updated