Onchain events
The events that record launches, trades and fee claims, and how to read them.
Launches#
The launch factory emits TokenLaunched once per launch, at the end of the launch transaction. It carries everything needed to follow the new token: its address, the wallet that launched it, its pool and the locked position.
event TokenLaunched(
address indexed token,
address indexed deployer,
address indexed dexFactory,
address pairToken,
address pool,
uint256 dexId,
uint256 launchConfigId,
uint256 positionId,
uint256 restrictionsEndBlock,
uint256 initialBuyAmount
)
// topic0 0xdb51ea9ad51ab453a65a4cb7e60c3cb378c9501bb002609f8f97778fb6c4235a- deployer is the wallet that sent the launch; pairToken is WETH; dexFactory is the Uniswap V3 factory.
- positionId is the liquidity NFT that the locker now holds for good.
- restrictionsEndBlock is the last block of the early-block limits.
- initialBuyAmount is the creator buy in wei: the value sent minus the launch fee.
Trades#
Every buy and sell is a Swap event of the token’s Uniswap V3 pool, the standard V3 event. The amounts are from the pool’s side: positive is what it received, negative is what it paid out.
event Swap(
address indexed sender,
address indexed recipient,
int256 amount0,
int256 amount1,
uint160 sqrtPriceX96,
uint128 liquidity,
int24 tick
)
// topic0 0xc42079f94a6350d7e6235f29174924f928cc2ac818eb64fed8004e115fbcca67- The pool orders its two tokens by address. The launch token is token0 when its address is lower than WETH's, otherwise token1.
- WETH flowing into the pool is a buy of the token; WETH flowing out is a sell.
- sender is usually the swap router, and on sells so is recipient, so the wallet that traded is the transaction's from address.
- sqrtPriceX96 is the price after the trade. Squared and divided by 2^192 it gives token1 per token0; both tokens have 18 decimals.
Fee claims#
Pool fees pile up in the locked position until someone collects them. The locker then emits FeesClaimed with the split it paid: the recipient amounts went to the token’s fee wallet, the protocol amounts to the treasury. Fees come in both of the pool’s tokens, WETH from buys and the launch token from sells.
event FeesClaimed(
address indexed token,
address indexed caller,
address token0,
address token1,
uint256 recipientAmount0,
uint256 recipientAmount1,
uint256 protocolAmount0,
uint256 protocolAmount1
)
// topic0 0x1547f2bd1a244399782ebde22047e2ede698ecdc4d6c7d4b3c4e2435f1e47f7aHolders#
The token is a plain ERC-20. Every balance change emits Transfer, the launch mint from the zero address included, so holders can be followed from the token’s first block. balanceOf at any block gives the same answer.
event Transfer(address indexed from, address indexed to, uint256 value)
// topic0 0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efGraduation#
No event marks graduation. graduationStatus(token) on the factory computes it at the moment it is read: the ETH paired in the locked position, the threshold, and whether the first has reached the second. It moves nothing on chain, and because it follows the pool, sells can take a graduated token back under the threshold.
Reading them in code#
A whole file you can run with Node, as in Set up. It lists the launches of the last 10,000 blocks and the recent trades of one token, each marked as a buy or a sell. For older history, step back 10,000 blocks at a time.
import { createPublicClient, formatEther, http, parseAbi } from "viem";
import { giwaSepolia } from "viem/chains";
const client = createPublicClient({ chain: giwaSepolia, transport: http() });
const [launched, swapped] = parseAbi([
"event TokenLaunched(address indexed token, address indexed deployer, address indexed dexFactory, address pairToken, address pool, uint256 dexId, uint256 launchConfigId, uint256 positionId, uint256 restrictionsEndBlock, uint256 initialBuyAmount)",
"event Swap(address indexed sender, address indexed recipient, int256 amount0, int256 amount1, uint160 sqrtPriceX96, uint128 liquidity, int24 tick)",
]);
// The RPC answers at most 10,000 blocks per request, about 2.8 hours of chain.
const toBlock = await client.getBlockNumber();
const fromBlock = toBlock - 9_999n;
// strict: true skips logs that do not decode, so every argument below is set.
const launches = await client.getLogs({ address: "0xb3B575A35844CB4Ad77beB243f6daadC9Ad42e0e", event: launched, fromBlock, toBlock, strict: true });
for (const { args } of launches) console.log("launched", args.token, "pool", args.pool);
// One token's trades are its pool's Swap events. The pool orders its tokens by address, and its
// amounts are what it received (positive) or paid out (negative); WETH in is a buy.
const token = "0x58fb4d3da82f5d610ad36e6e39e674c17b32ffd1"; // deus cat
const pool = "0x3be84d789357ff44FFC8301A76585b6556660E24"; // its pool, from TokenLaunched or getPool
const tokenIsToken0 = BigInt(token) < BigInt("0x4200000000000000000000000000000000000006"); // vs WETH
const swaps = await client.getLogs({ address: pool, event: swapped, fromBlock, toBlock, strict: true });
for (const { args, transactionHash } of swaps) {
const weth = tokenIsToken0 ? args.amount1 : args.amount0;
console.log(weth > 0n ? "buy" : "sell", formatEther(weth < 0n ? -weth : weth), "ETH", transactionHash);
}