library / AI and blockchain / SI0009
LP token classifier
Give it mint addresses and it returns a label and a score for each: LP-like or another kind of mint. One call reads the accounts, the decoding is local, and the model is a short function you can refit on your own labels.
What an LP token is on chain
An LP token is an ordinary SPL token. A pool program mints it when someone deposits liquidity and burns it on withdrawal, so its supply follows the pool's shares. The token program has no field that labels a mint as an LP mint, so a classifier has to work from what the mint account does hold.
A mint account holds the mint authority, the supply, the decimals, an initialized flag and the freeze authority. The mint authority carries the useful signal. A pool program signs for its mint through a program-derived address, and such an address has no private key: its 32 bytes lie off the ed25519 curve, where a wallet's key lies on it. A mint with an off-curve authority is minted by a program. An LP mint fits that, and so do other program-controlled mints, so the score gives a shortlist.
Three flags and what they mean
| Flag | Where it is read | Effect on the score |
|---|---|---|
| offCurve | mint authority at bytes 4 to 35, when the authority tag at byte 0 is 1 | raises it |
| noAuthority | authority tag at byte 0 is 0, so the supply can never change | lowers it sharply |
| freezeAuthority | freeze tag at byte 46 is 1, so the mint has a freeze authority | lowers it |
A pool that mints shares on every deposit needs a live mint authority, so a fixed-supply mint is unlikely to be an LP mint. The freeze flag is a guess about habit: pool shares usually carry no freeze authority, while issued tokens with a compliance role often do. A freeze authority means someone could freeze the mint's accounts, and says nothing about whether any are frozen. Both flags are priors you can test against labels.
The layout is the SPL mint: a 4-byte authority tag and 32 bytes at offset 0, the u64 supply at 36, decimals at 44, the initialized byte at 45, then the freeze tag and key. A Token-2022 mint starts with the same 82 bytes. With extensions it pads to 165 bytes, writes a type byte of 1 and appends the extension records, which this file does not decode.
The classifier file
The file takes 1 to 100 mint addresses as arguments, reads them with one getMultipleAccounts call, checks that each account is a mint, extracts the flags and prints one JSON line per mint. Set CARBIUM_KEY first; the file exits with a message when it is missing. CARBIUM_RPC_URL overrides the endpoint, which defaults to https://services.carbium.sh.
// SI0009 · LP token classifier// https://carbium.sh/library/si/lp-token-classifier// Copyright (c) Carbium Corporation. MIT License (LICENSE). Keep this notice.// SPDX-License-Identifier: MIT// Scores SPL mints as LP-like from the mint account alone. Run: CARBIUM_KEY=... node main.ts <mint> [<mint> ...]import { address, createDefaultRpcTransport, createSolanaRpcFromTransport, getAddressDecoder } from "@solana/kit";const key = process.env.CARBIUM_KEY;if (!key) { console.error("Set CARBIUM_KEY to your Carbium API key."); process.exit(1);}const url = process.env.CARBIUM_RPC_URL ?? "https://services.carbium.sh";const rpc = createSolanaRpcFromTransport(createDefaultRpcTransport({ url, headers: { "x-api-key": key } }));const TOKEN = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";const TOKEN_2022 = "TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb";// Hand-set starting weights, not trained. Refit them on labelled mints.const W = { bias: -2, offCurve: 3, freezeAuthority: -1.5, noAuthority: -3 };const decoder = getAddressDecoder();const P = 2n ** 255n - 19n;function pow(b: bigint, e: bigint): bigint { let r = 1n; b %= P; for (; e > 0n; e >>= 1n, b = (b * b) % P) if (e & 1n) r = (r * b) % P; return r;}const D = (P - ((121665n * pow(121666n, P - 2n)) % P)) % P;// True when the 32 bytes decompress to an ed25519 point, which a program-derived address never does.function onCurve(bytes: ArrayLike<number>): boolean { let y = 0n; for (let i = 31; i >= 0; i--) y = (y << 8n) | BigInt(bytes[i] as number); y &= (1n << 255n) - 1n; if (y >= P) return false; const y2 = (y * y) % P; const x2 = (((y2 + P - 1n) % P) * pow((D * y2 + 1n) % P, P - 2n)) % P; return x2 === 0n || pow(x2, (P - 1n) / 2n) === 1n;}function readMint(owner: string, data: Uint8Array) { const classic = owner === TOKEN && data.length === 82; const extended = owner === TOKEN_2022 && (data.length === 82 || (data.length > 165 && data[165] === 1)); if (!(classic || extended) || data[45] !== 1) return null; const view = new DataView(data.buffer, data.byteOffset, data.byteLength); const authority = view.getUint32(0, true) === 1 ? data.subarray(4, 36) : null; return { authority: authority && decoder.decode(authority), offCurve: authority !== null && !onCurve(authority), freezeAuthority: view.getUint32(46, true) === 1, decimals: data[44], supply: view.getBigUint64(36, true), };}// 100 addresses fit every plan; a Pro key can raise this to 300.const mints = process.argv.slice(2);if (mints.length < 1 || mints.length > 100) { console.error("Pass 1 to 100 mint addresses."); process.exit(1);}const { value } = await rpc.getMultipleAccounts(mints.map((m) => address(m)), { encoding: "base64" }).send();value.forEach((account, i) => { const mint = mints[i]; const m = account && readMint(account.owner, Buffer.from(account.data[0], "base64")); if (!m) { console.log(JSON.stringify({ mint, label: "not-a-mint" })); return; } const z = W.bias + W.offCurve * +m.offCurve + W.freezeAuthority * +m.freezeAuthority + W.noAuthority * +(m.authority === null); const p = 1 / (1 + Math.exp(-z)); const label = p >= 0.5 ? "lp-like" : "other-mint"; console.log(JSON.stringify({ mint, label, p: +p.toFixed(2), authority: m.authority, freezeAuthority: m.freezeAuthority, decimals: m.decimals, supply: String(m.supply) }));});
run: node main.ts
Every line starts with mint and label (lp-like, other-mint or not-a-mint). Only mint lines add the score p, authority (the address or null), freezeAuthority (true when the mint has one), decimals and supply as a string, since a u64 does not fit a JSON number safely. An address with no account, a token account and a wallet all come back as not-a-mint lines that carry only mint and label.
onCurve is the one piece of math. It reads the 32 bytes as a compressed ed25519 point and asks whether the implied x squared has a square root modulo 2^255 - 19, the same decompression test the Solana runtime uses to decide whether a key is on the curve. It is written with BigInt so the file needs nothing beyond kit.
Weights, threshold and fitting
The score is a logistic regression with four numbers: bias -2, offCurve +3, freezeAuthority -1.5 and noAuthority -3. p is the sigmoid of their sum, and the label is lp-like at 0.5 or above.
| Mint case | Sum | p |
|---|---|---|
| program authority, no freeze authority | 1.0 | 0.73 |
| program authority, freeze authority set | -0.5 | 0.38 |
| wallet authority, no freeze authority | -2.0 | 0.12 |
| wallet authority, freeze authority set | -3.5 | 0.03 |
| no mint authority | -5.0 or lower | 0.01 or lower |
These weights are set by hand. Nothing here was trained, and the 0.5 cut is a convention. To fit them, run the flag extraction over mints you have labelled, write the three flags and the label to rows, fit a logistic regression with any trainer and paste the four coefficients in. The labels come from you; this file ships none.
Read cost
getMultipleAccounts charges 10 cells per pubkey (1,000 cells for 100 pubkeys, 1,001 when the body is over 4 KiB) and takes up to 300 pubkeys, but the 1,024-cell burst caps a call at 100 pubkeys below Pro. So 300 per call works only on Pro. Account reads run at 0.5, 15, 50 and 400 req/s on Free, Dev, Business and Pro, and the per-plan limits cover the rest. A batch spends the budget of many reads at once, so size batches to your plan.
Where it ends
- A program-derived authority is shared by every program-controlled mint. Vault share tokens, wrapped assets and receipt tokens look the same as an LP mint here, and the score cannot name the pool.
- A mint holds no pool fields. Finding the two tokens behind an LP mint needs the pool program's account that references the mint, and with it that program's layout, which this file does not have.
- Some pool designs record a position as an NFT or a plain account instead of a fungible LP mint. Those never reach this file.
- An LP mint whose authority was handed to a wallet or revoked scores low. The model sees control, and a pool's purpose does not show in it.
- getTokenLargestAccounts is not served and answers -32601, which means do not retry, so holder concentration is not available as an input through Carbium.
- Token-2022 extensions are not decoded. Only the base mint fields are read.
- The weights are untrained, and the file is read-only: it signs and sends nothing.
When it goes wrong
| what goes wrong | what to do |
|---|---|
| Every mint comes back not-a-mint. | Check that each address is a mint and not a token account or a wallet. The file accepts 82 bytes under the token program, or the same base under Token-2022 with a type byte of 1 at offset 165 when the mint has extensions. |
| address() throws before any request is made. | kit checks each string for 32-byte base58 locally. Remove or correct the bad entry and run the batch again. |
| A call with more than 100 addresses is refused. | Split the list into chunks of at most 100 on Free, Dev and Business, and 300 on Pro. The file stops at 100 before it sends anything; raise that check to 300 on a Pro key. |
| A large batch returns 429. | Read the retry-after hint, wait that long and send the same batch again. Limits are per account, so other keys on the account spend the same budget. |
| A mint you know is an LP mint scores below 0.5. | Print its flags. Its authority is probably a wallet or revoked, which the model reads as not pool-shaped. Add labelled examples and refit the weights. |
| A holder-concentration check built on getTokenLargestAccounts answers -32601. | Do not retry. The method is not served. Drop that input, or take holders from a source you control. |
Questions
Can the mint account tell me which two tokens are in the pool?
No. A mint holds no pool fields. You need the pool program's account that references this mint, read with that program's layout.
Why only three flags?
They are the fields in the mint account that point at who controls it. Decimals and supply are printed, and you can add them as inputs once you have labels to fit them against.
How many mints can one call classify?
100 per call below Pro and 300 on Pro, because the 1,024-cell burst caps a call at 100 pubkeys on the other plans. The file refuses more than 100 before it sends anything; raise that check to 300 on a Pro key.
Does it need a keypair?
No. It only reads accounts, so nothing is signed. The one secret is your Carbium key.