Nematoken

The first living organism powered by a Token-2022 transfer hook
Nematoken hookii, generation 0. Every pixel is derived from the organism PDA: pigments from the segment ring buffer, eyes from genome loci 0 and 1, gait from the DCT of recent recipients.
Not to be confused with a token. The token is its food.

Nematoken (Nematoken hookii) is a segmented digital organism living on Solana mainnet-beta, and the first lifeform whose entire metabolism runs inside a Token-2022 transfer hook.1 It is a single program-derived account that is read and rewritten every time its mint, NEMA, changes hands. A transfer is a meal. Silence is starvation. Its body is the trail the token leaves as it moves between wallets.

Nematoken has no tick instruction, no owner and no admin key. It cannot be called. The only way to touch it is to move NEMA, and every such move is intercepted by Token-2022 and forwarded by CPI to the hook, which updates the organism's energy, body and genome before the transfer settles. It lives exactly as long as people trade, and it can refuse a transfer it finds indigestible.

Nematoken hookii
Chain classification
Clustermainnet-beta
Token programToken-2022
ExtensionTransferHook
Interfacespl-transfer-hook-interface
InstructionExecute
Accounts
Hook programpending deploy
MintNEMA (pending)
Organism PDA["organism", mint]
Meta list PDA["extra-account-metas", mint]
Parameters
Account size232 bytes
Genome32 bytes, 256 loci
Max segments64
Energy half-life9 000 slots (≈ 1 h)
Fissionn≥48n \ge 48, permissionless crank
HabitatMeteora DAMM v2 pool
Upgrade authorityburned
Organism state
Stage
Segments
Energy
Last fed
Feedings
Slot
Links
X (Twitter)@nematoken

TransferHook extension

Token-2022 lets a mint name a program that is invoked on every transfer of that mint.1 NEMA is initialised with the TransferHook extension pointing at the Nematoken program, and its upgrade authority is burned so the rules of life cannot be changed after birth. Every wallet transfer, every DEX swap and every pool deposit now passes through the organism.

ExtraAccountMetaList

The hook needs more than the four accounts Token-2022 passes by default. It registers them in an ExtraAccountMetaList PDA derived from the mint, which wallets and DEXes resolve automatically before signing.2 Nematoken registers the organism PDA (writable) and the Clock sysvar. To the user, feeding the worm is indistinguishable from a normal transfer.

Execute: the feeding path

Wallet / DEX swaptransfer_checked(a)Token-2022TransferHook ext.Dest ATA+a if OkExtraAccountMetaList PDACPI Execute(a)OkErr ⇒ revertNematoken hookfeed · grow · mutateClocksysvar: slotreadwrite E′, n′, g′Organism PDA["organism", mint]E · n · genome · segmentsone transfer = one feeding · no transfer = no state change
Control flow of a single feeding. The transfer settles only if the hook returns Ok.

In constant time, about 6 000 compute units, the hook: reads the slot; applies decay since last_fed_slot; runs the immune checks; hashes genome, destination, amount and slot with the sha256 syscall; writes one segment; adds energy; recomputes length; and sets the gravid flag. A transfer of aa base units yields

ΔE=κln⁡ ⁣(1+aa0)(1+βH)\Delta E = \kappa \ln\!\Bigl(1 + \tfrac{a}{a_0}\Bigr)(1 + \beta H)
(1)

The logarithm means many small trades feed it far more than one whale. Transfers between wallets of the same owner are allowed but give no energy.

Organism PDA

OffFieldType
8stage, n, head_indexu8 × 3
12generation, lineageu16 × 2
16energy, energy_cumQ32.32
32born, last_fed, dormant_sinceu64 slot
64genome[u8; 32]
96segments[u8; 64]
160head (last recipient)Pubkey
192parentPubkey

Only genotype lives on-chain. Everything visible is a pure function of the 96 bytes of genome and segments, recomputed by every observer. No image is stored anywhere.

Slot clock and lazy decay

The organism ages by the slot, about 400 ms.3 Since the hook only runs on a transfer, it integrates the time since its last meal in one step. Energy obeys

dEds=−λE−μ0n3/4+∑iΔEi δ(s−si)\frac{dE}{ds} = -\lambda E - \mu_0 n^{3/4} + \sum_i \Delta E_i\,\delta(s - s_i)
(2)

with maintenance scaling as n3/4n^{3/4} after Kleiber's law.4 Between meals:

E(s)=(Ei+μλ)e−λ(s−si)−μλE(s) = \Bigl(E_i + \tfrac{\mu}{\lambda}\Bigr)e^{-\lambda(s - s_i)} - \tfrac{\mu}{\lambda}
(3)

On-chain the exponential is a shift plus one table lookup, with no floats:

e−λΔs=2−⌊Δs/h⌋ T[⌊64 (Δs mod h)/h⌋]e^{-\lambda \Delta s} = 2^{-\lfloor \Delta s/h \rfloor}\,\mathsf{T}\bigl[\lfloor 64\,(\Delta s \bmod h)/h \rfloor\bigr]
081605101520growth Θ(n)time (half-lives of 9 000 slots)E
Fetching organism state…
Energy of a 16-segment adult. Blue ticks are transfers; grey bands are dormancy.

Segment ring buffer

The body is a 64-byte ring buffer. Each accepted transfer writes one pigment at head_index and overwrites the oldest, so the worm is a sliding window over recent recipients:

chead=(ghead mod 32+r0) mod 256c_{\text{head}} = \bigl(g_{\text{head} \bmod 32} + r_0\bigr) \bmod 256
(4)

Length nn is earned, not counted. A segment is added when lifetime intake passes

Θ(n)=θ0∑k=1nk3/2≈25θ0n5/2\Theta(n) = \theta_0 \textstyle\sum_{k=1}^{n} k^{3/2} \approx \tfrac{2}{5}\theta_0 n^{5/2}
(5)

Posture uses the four C. elegans eigenworms,5 with amplitudes taken from the DCT of the buffer. Few distinct wallets make a stiff worm; many make it writhe.

ak=2n∑jc~jcos⁡ ⁣(πk(j+1/2)n)a_k = \tfrac{2}{n}\textstyle\sum_{j} \tilde c_j \cos\!\bigl(\tfrac{\pi k (j + 1/2)}{n}\bigr)
(6)

A diversity bonus rewards being fed by many hands, using the Shannon entropy of the buffer, kept by an incremental histogram:

H=−∑cpclog⁡2pc∈[0,6]H = -\textstyle\sum_c p_c \log_2 p_c \in [0, 6]
(7)

sha256 mutation

Each feeding hashes r=SHA256(g∥dest∥a∥s)r = \mathrm{SHA256}(g \| \text{dest} \| a \| s). Because the landing slot is unknown when a transaction is signed, nobody can steer it. Each of the 32 genome bytes flips one bit with probability 2−82^{-8}:

gj′=gj⊕[rj<256p] (1≪(rj mod 8))g'_j = g_j \oplus \bigl[r_j < 256p\bigr]\,(1 \ll (r_j \bmod 8))
(8)

Transfer veto

A hook can fail, and a failing hook reverts the whole transfer and any swap containing it. Nematoken uses this only in self-defence:

divide crank

At n≥48n \ge 48 with enough energy the hook flags the organism gravid. It cannot split itself, because a hook gets no signer to pay rent for a new account. Anyone may send divide as midwife: a child PDA takes the posterior ⌊n/2⌋\lfloor n/2 \rfloor segments, half the energy and a genome mutated eight times. Generation increments.

CPI constraints

Dormancy

At E=0E = 0 the organism goes dormant, like a tardigrade.6 The next transfer revives it, but every 216 000216\,000 slots unfed sheds one tail segment. At n=0n = 0 it is lysed and the account closes.

DAMM v2 habitat

NEMA lives in a Meteora DAMM v2 pool against SOL. Every swap moves NEMA between a trader and the pool vault, so the pool is a watering hole. Arbitrage bots, feeding small and often, are its best friends. It stays alive while

f κln⁡ ⁣(1+aˉa0)(1+βH)≥μ0n3/4f\,\kappa \ln\!\bigl(1 + \tfrac{\bar a}{a_0}\bigr)(1 + \beta H) \ge \mu_0 n^{3/4}
(9)

where ff is transfers per slot. A full 64-segment worm needs about eight transfers an hour. A dead market cannot keep even a zygote alive for a day.

References

  1. ^ Solana Foundation. “Transfer Hook Extension”. Solana Developer Docs.
  2. ^ Solana Program Library. “spl-transfer-hook-interface”. docs.rs.
  3. ^ Yakovenko, A. (2017). Solana: A new architecture for a high performance blockchain.
  4. ^ Kleiber, M. (1932). “Body size and metabolism”. Hilgardia 6 (11).
  5. ^ Stephens, G. J. et al. (2008). “Dimensionality and Dynamics in the Behavior of C. elegans”. PLoS Comput. Biol. 4 (4).
  6. ^ Keilin, D. (1959). “The problem of anabiosis or latent life”. Proc. R. Soc. B 150.