Program
Events
The fourteen events of the kodama program with their fields and the instruction that emits each, how they are carried in a transaction, and how to decode them.
How events are carried
The program emits every event with Anchor's emit_cpi!. An event is not a log line. It is an inner instruction: the program calls itself, and the call's data is the event.
| Part of the inner instruction | Holds |
|---|---|
| Program | The kodama program |
| First account | The event authority, the address with seeds __event_authority, as the signer |
| Data, bytes 0 to 7 | The tag e445a52e51cb9a1d, the same for every event |
| Data, bytes 8 to 15 | The event's discriminator |
| Data, from byte 16 | The event's fields in order, Borsh encoded: addresses as 32 bytes, integers little-endian, bool as one byte |
Only the program can sign for its event authority, so an inner instruction with that signer is an event the program emitted. This is why every instruction takes event_authority and program as its last two accounts.
Events sit in a transaction's inner instructions, under the instruction that emitted them and in the order they were emitted. They are there whatever else the transaction logs.
Which instruction emits which event
| Event | Emitted by | When |
|---|---|---|
TreePrepared | prepare_tree | Always |
Planted | plant | Always |
EchoRecorded | echoed_buy | Always, accepted or not |
MovedIn | move_in | Always |
Watered | water | Always |
PoolRegistered | harvest | The first harvest after graduation |
Harvested | harvest | Always |
CoinFeesBurned | harvest | When coins were burned |
DayClosed | close_day | Always |
Settled | settle | Always |
Picked | pick | Always |
MovedOut | move_out | Always |
PlanterClaimed | claim_planter | Always |
EchoClaimed | claim_echo | Always |
One harvest emits its events in the order PoolRegistered, Harvested, CoinFeesBurned.
Settled comes only from the settle instruction. When move_in, move_out, water or pick settles a kodama's day on the way, no event marks it: the kodama's fruit_ready on its Kodama account is the amount.
Decode events in TypeScript
decodeEventCpi in backend/src/program/index.ts takes one instruction and returns the event it carries, null when it is not an event of this program, and throws when the tag is there without the event authority as signer. The module below reads a confirmed transaction and returns its events. Its paths are written from the repo's root.
import anchor from '@coral-xyz/anchor'
import { Connection, TransactionInstruction } from '@solana/web3.js'
import { createKodamaProgram, decodeEventCpi, programAddresses, type DecodedEvent } from './backend/src/program/index.js'
const connection = new Connection('https://api.mainnet-beta.solana.com', 'confirmed')
const program = createKodamaProgram({ connection })
const eventAuthority = programAddresses(program.programId).eventAuthority()
export async function eventsOf(signature: string): Promise<DecodedEvent[]> {
const tx = await connection.getTransaction(signature, { commitment: 'confirmed', maxSupportedTransactionVersion: 0 })
if (!tx?.meta || tx.meta.err) return []
const keys = tx.transaction.message.getAccountKeys({ accountKeysFromLookups: tx.meta.loadedAddresses })
const events: DecodedEvent[] = []
for (const group of tx.meta.innerInstructions ?? []) {
for (const inner of group.instructions) {
const programId = keys.get(inner.programIdIndex)
if (!programId) continue
const instruction = new TransactionInstruction({
programId,
data: anchor.utils.bytes.bs58.decode(inner.data),
keys: inner.accounts.map((index) => {
const pubkey = keys.get(index)!
return { pubkey, isSigner: pubkey.equals(eventAuthority), isWritable: false }
}),
})
const event = decodeEventCpi(program, instruction)
if (event) events.push(event)
}
}
return events
}
export async function closedDays(signature: string) {
const days: { tree: string; dayIndex: bigint; fruit: bigint; wateredKodama: bigint }[] = []
for (const event of await eventsOf(signature)) {
if (event.name !== 'dayClosed') continue
days.push({
tree: event.data.tree.toBase58(),
dayIndex: BigInt(event.data.dayIndex.toString()),
fruit: BigInt(event.data.fruit.toString()),
wateredKodama: BigInt(event.data.wateredKodama.toString()),
})
}
return days
}An RPC answer carries no signer flags for inner instructions. In a transaction that succeeded, the program has already refused any event call its event authority did not sign, so the module marks that address as the signer and skips failed transactions.
Decoded names are camelCase: the event DayClosed is dayClosed and its field new_day_index is newDayIndex. u64 and i64 fields are BN, addresses are PublicKey.
The API's live events are made from these events, each kept only when its inner instruction sits directly under an instruction of the kodama program and names the event authority first.
TreePrepared
Discriminator [152, 225, 89, 43, 248, 170, 48, 63].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The new Tree. |
mint | Pubkey | The coin's future mint. |
planter | Pubkey | The wallet that prepared the tree. |
purse | Pubkey | The tree's Purse. |
platform_config | Pubkey | The tree's LaunchLab PlatformConfig. |
day_index | u64 | The day the tree was prepared in. |
Planted
Discriminator [47, 153, 90, 135, 19, 17, 38, 85].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
mint | Pubkey | The coin's mint. |
planter | Pubkey | The planter. |
pool | Pubkey | The coin's LaunchLab pool. |
first_buy_lamports | u64 | The first_buy argument: lamports offered for the first buy. 0 for none. |
at | i64 | The Unix time, in seconds. |
EchoRecorded
Discriminator [31, 5, 158, 101, 220, 54, 176, 148].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
mint | Pubkey | The coin's mint. |
owner | Pubkey | The echo_owner argument: the wallet whose echo the buy named. |
buyer | Pubkey | The wallet that bought. |
buy_lamports | u64 | Lamports of wrapped SOL the buy spent. |
echo_lamports | u64 | Lamports recorded as owed to the echo's kodama. 0 when not accepted. |
accepted | bool | True when owner had coins in the tree and the share was recorded. |
at | i64 | The Unix time, in seconds. |
MovedIn
Discriminator [64, 85, 14, 60, 31, 38, 211, 83].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
owner | Pubkey | The wallet that moved in. |
amount | u64 | Coins moved in, in base units. |
day_index | u64 | The tree's open day. The coins count from the day after. |
Watered
Discriminator [250, 1, 192, 208, 151, 73, 143, 133].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
owner | Pubkey | The kodama's wallet. |
coins | u64 | The coins the watering recorded: the kodama's coins counting that day. |
day_index | u64 | The day watered. |
PoolRegistered
Discriminator [77, 114, 165, 230, 33, 230, 135, 215].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
mint | Pubkey | The coin's mint. |
cpmm_pool | Pubkey | The graduated CPMM pool now written on the Tree. |
fee_key_mint | Pubkey | The mint of the Fee Key now written on the Tree. |
Harvested
Discriminator [249, 229, 78, 151, 106, 185, 149, 11].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
mint | Pubkey | The coin's mint. |
day_index | u64 | The tree's open day, whose fruit the harvest joined. |
fees_lamports | u64 | Trade fees collected: the platform fee vault and the pool's creator fee. |
fruit_lamports | u64 | Lamports added to the day's fruit, liquidity fees included. |
planter_lamports | u64 | Lamports added to the planter's waiting share. |
burner_lamports | u64 | Lamports sent to the Burner. |
echo_lamports | u64 | Lamports added to the tree's echo reserve. |
liquidity_fruit_lamports | u64 | Liquidity fees collected through the Fee Key. |
at | i64 | The Unix time, in seconds. |
fruit_lamports + planter_lamports + burner_lamports + echo_lamports equals fees_lamports + liquidity_fruit_lamports.
CoinFeesBurned
Discriminator [108, 122, 29, 161, 87, 1, 92, 239].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
mint | Pubkey | The coin's mint. |
amount | u64 | Coins burned, in base units. |
at | i64 | The Unix time, in seconds. |
DayClosed
Discriminator [152, 8, 69, 146, 232, 175, 151, 96].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
day_index | u64 | The day that closed. |
new_day_index | u64 | The day now open. |
fruit | u64 | The closed day's fruit in lamports, as written on its Day. For a day nobody watered, the fruit carried forward. |
watered_coins | u64 | The counting coins of the kodama who watered. 0 when nobody did. |
watered_kodama | u64 | How many kodama watered. 0 when nobody did. |
carried | u64 | The tree's carried fruit as the new day opens, in lamports. |
watered_kodama above 0 means a Day account now exists for day_index.
Settled
Discriminator [232, 210, 40, 17, 142, 124, 145, 238].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
owner | Pubkey | The wallet of the kodama settled. |
fruit | u64 | Lamports added to the kodama's fruit_ready. 0 when it was already settled. |
Picked
Discriminator [171, 128, 93, 55, 122, 245, 64, 29].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
owner | Pubkey | The kodama's wallet. |
amount | u64 | Lamports of fruit paid. |
MovedOut
Discriminator [149, 60, 196, 174, 60, 48, 197, 156].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
owner | Pubkey | The wallet that moved out. |
amount | u64 | Coins moved out, in base units. |
day_index | u64 | The tree's open day. |
PlanterClaimed
Discriminator [21, 237, 8, 31, 20, 92, 63, 85].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
planter | Pubkey | The planter. |
amount | u64 | Lamports paid. |
EchoClaimed
Discriminator [133, 2, 20, 222, 164, 164, 249, 136].
| Field | Type | Meaning |
|---|---|---|
tree | Pubkey | The Tree. |
owner | Pubkey | The wallet that claimed. |
amount | u64 | Lamports of echo share paid. |