Smart Contract Documentation
Comprehensive documentation of the TRIBE MemeLaunchpad smart contract functions, data structures, and behavior.
Key Components
TokenInfo Struct
Stores token metadata and state:
struct TokenInfo {
string name;
string symbol;
address creator;
uint256 totalSupply;
uint256 curveSupply;
uint256 maxCurveSupply;
uint256 creatorBought;
bool isUnlocked;
bool isCompleted;
uint256 tradingVolume;
}
Comment Struct
On-chain comment data:
struct Comment {
address user;
string text;
uint256 timestamp;
}
Core Functions
Token Creation
This section expands on how creators launch new meme tokens on Tribe. It explains the minimal requirements (name, symbol, image, optional claim link), how the contract deploys a new ERC‑20 token, initializes supply distribution, applies creator buy‑limits, and registers the token as a new Tribe. The narrative emphasizes effortless, permissionless launch and the role of Intuition claim links for Tribe‑Oriented tokens.
createToken(string memory name, string memory symbol, string memory image, string memory claimLink)
Deploys a new meme token and registers it with the launchpad.
Steps:
- User calls
createToken() - New ERC-20 deployment
- Launchpad set as minter
- Mint 30% supply (300M tokens) to launchpad
- Register token in mappings
Parameters:
name- Token namesymbol- Token symbolimage- Token image URLclaimLink- Optional Intuition claim link (for Tribe-Oriented tokens)
Returns:
address- Address of deployed token
State Changes:
- New token contract deployed
- Token registered in
tokensmapping - Added to
allTokensarray - Initial state: Locked
Events:
event TokenCreated(address indexed token, address indexed creator, string name, string symbol);
Buying Tokens
This section elaborates on the user buying experience during the bonding‑curve phase. It explains how users purchase tokens with TRUST, how the contract calculates price, how slippage protection works, how the 2% fee is handled, and how buying contributes to the points system. The explanation reinforces Tribe's fair‑launch philosophy where all users interact with the same curve under transparent rules.
buyTokens(address token, uint256 minTokensOut)
Purchase tokens via the bonding curve using TRUST.
Steps:
- Payable function (receives TRUST)
- Calculate tokens from TRUST
- Quadratic pricing calculation
- Slippage enforcement via
minTokensOut - 2% fee → treasury
- Check unlock status
- Creator limit checks
- Holder tracking
- Points system update
- Emit
TokensBoughtevent
Parameters:
token- Token contract addressminTokensOut- Minimum tokens expected (slippage protection)
Requirements:
- Token must exist
- Token must be unlocked (or creator buying to unlock)
- Sufficient ETH sent
- Slippage protection must pass
- Creator limit not exceeded (if creator)
State Changes:
- Token supply increased
- Trading volume updated
- Creator purchase tracked (if applicable)
- Unlock status checked
Events:
event TokensBought(address indexed token, address indexed buyer, uint256 ethAmount, uint256 tokensAmount);
Selling Tokens
This section expands on the selling process, detailing how users can exit positions by selling tokens back into the bonding curve. It describes how the curve determines TRUST return based on current supply, how tokens are burned after selling, how fees are routed to the treasury, and how this mechanism keeps token economics balanced before DEX migration.
sellTokens(address token, uint256 amount, uint256 minTrustOut)
Sell tokens back to the bonding curve.
Steps:
- User approves tokens
- ETH returned via curve price (calculated in TRUST)
- 2% fee → treasury
- Tokens burned
Parameters:
token- Token contract addressamount- Amount of tokens to sellminEthOut- Minimum ETH expected (slippage protection)
Requirements:
- Token must exist
- Token must be unlocked
- User must have approved tokens
- User must have sufficient balance
- Slippage protection must pass
State Changes:
- Token supply decreased
- Trading volume updated
- Tokens burned
Events:
event TokensSold(address indexed token, address indexed seller, uint256 tokensAmount, uint256 ethAmount);
Comment System
addComment(address token, string memory text)
Add an on-chain comment to a token.
Steps:
- Validate token exists
- Require 0.025 ETH payment
- Create Comment struct
- Add to token's comment array
- Emit
CommentAddedevent
Parameters:
token- Token contract addresstext- Comment text
Requirements:
- Token must exist
- Must send exactly 0.025 ETH
- Comment text not empty
State Changes:
- Comment added to
comments[token]array
Events:
event CommentAdded(address indexed token, address indexed user, string text, uint256 timestamp);
Liquidity Migration
Triggered when bonding curve completes (700M tokens distributed):
Steps:
- 30% held tokens (300M) added to DEX
- All TRUST balance used
- Uses router
addLiquidityETH() - LP tokens permanently locked in contract
Parameters:
token- Token contract address
Requirements:
- Token must exist
- Token must be in completed state
- Router must be set
- Sufficient tokens and ETH available
State Changes:
- Token liquidity added to DEX
- LP tokens stored in contract
- Token now trades on DEX
Events:
event LiquidityMigrated(address indexed token, uint256 tokenAmount, uint256 ethAmount, address lpToken);
View Functions
getTokenInfo(address token)
Returns complete token information.
Returns: TokenInfo struct
getComments(address token)
Returns all comments for a token.
Returns: Comment[] array
getAllTokens()
Returns array of all token addresses.
Returns: address[] array
getCurrentPrice(address token)
Calculates current token price from bonding curve.
Returns: uint256 price in ETH
Admin Functions
setTreasury(address newTreasury)
Update treasury address for fee routing.
Access: Admin only
setRouter(address newRouter)
Update DEX router address.
Access: Admin only
approveRouter(address token)
Approve router to spend tokens for liquidity.
Access: Admin only
transferOwnership(address newOwner)
Transfer contract ownership.
Access: Owner only
Security Features
Reentrancy Guards
All state-changing functions protected with reentrancy guards:
modifier nonReentrant() {
require(!locked, "ReentrancyGuard: reentrant call");
locked = true;
_;
locked = false;
}
Creator Limits
- Maximum 20% of curve supply
- Must buy 2% to unlock
- Enforced in
buyTokens()function
Unlock Enforcement
- Tokens locked until creator buys 2%
- Public trading blocked during locked state
- Checked in all trading functions
Valid Token Checks
All functions validate token existence:
require(tokens[token].creator != address(0), "Token does not exist");
Exact Fee Checks
Fee calculations verified:
require(fee == (amount * 2) / 100, "Fee calculation error");
Router Validation
Router address validated before use:
require(router != address(0), "Router not set");
Storage Mappings
mapping(address => TokenInfo) public tokens;
mapping(address => address) public tokenCreators;
mapping(address => Comment[]) public comments;
address[] public allTokens;
Constants
TREASURY_FEE_BPS = 200(2%)COMMENT_FEE = 0.025 etherCURVE_SUPPLY_PERCENT = 70(70% for curve)LIQUIDITY_SUPPLY_PERCENT = 30(30% for liquidity)CREATOR_UNLOCK_PERCENT = 2(2% unlock requirement)CREATOR_MAX_PERCENT = 20(20% max purchase)
Next Steps
- Review API Integration for frontend usage
- Check Security for best practices
- See Deployment Workflow for setup