Guides
Publish a hook from an IDL
The Publish page builds a hook from a program's IDL in the browser: it reads the instructions, you mark which values each run fills, it checks the result against the chain, and your wallet signs. This guide goes through each step, then shows how to claim what the hook earns.
To write the same record as code, see Write a hook.
What you need
- The program's ID, or its IDL as JSON. A program that has published its Anchor IDL on chain needs only the ID.
- A wallet with enough SOL for the rent of the hook's account and one network fee. This wallet becomes the hook's author and receives its share of every run.
- One instruction in mind, and what it does with money: which argument is the amount, which account pays, which account receives.
Build the hook
The program
Open Publish. Paste the program ID or the IDL JSON into the first box and press Read the IDL. The builder lists the program's instructions.
The instruction
Choose the instruction the hook will call. A hook describes exactly one.
Slots
A slot is a place a run fills. Everything else is fixed for good when the hook is published.
Under Arguments, give each argument a role.
Role Meaning Fixed value The same bytes in every run. Type them as hex. Amount in The run's amount in. Mark the argument that carries the amount. Minimum out The run's minimum out, for an instruction that takes one. Caller argument A value each run supplies. Seat argument A value each run supplies, on a seat hook. Under Accounts, give each account a role.
Role Meaning Stage authority The account that signs as the user. Pook's stage takes its place. Stage in The token account the amount is paid from. Stage out The token account the result arrives in. Seat The owner of a position that stays open. Seat hooks only. Fixed address, Program, Sysvar One address, the same in every run. Common programs and sysvars are filled in for you. Caller supplies An account each run names. Roles Pook fills read Filled by Pook beside them, and roles a run fills read Filled by each run.
The hook
Name and describe it.
Field What to enter Name protocol.action, lowercase, such asyourname.supply. It is how people run the hook, and it can be published once.Protocol The protocol's name as people know it. Label The action in a word or two: Swap, Supply, Stake. Kind Flow when the asset goes in and comes back in one run. Seat when a position stays open. What goes in and what comes back One sentence. It shows beside the hook everywhere. Program The program's address. It is filled from the IDL. Mint in, Mint out A mint address to fix the asset, or empty to let each run name it. Check the record
The hook so far, on the right, builds the record as you go: the program, the data with its slots, the accounts with theirs. Under it, a list names anything still to do, such as marking the amount argument or the stage out account.
Simulate
When nothing is left to do, type a Sample amount in, in the mint's smallest unit, and press Simulate. The builder sends the instruction to the chain with the stage in place and reports Simulation passed or Simulation failed, with the compute used and the Program logs.
A failure shows the target program's own message. A wrong role or a wrong fixed address reads there the way the program reports it.
Publish
Connect the wallet that will be the author and press Publish. Approve the transaction. The stages are Build the transaction, Sign in your wallet, Submitted and Published.
When it reads that your hook is published, press Open the hook. It is in the registry and can be run. Its run screen asks for the accounts you marked Caller supplies and, when the hook returns an asset, for a Minimum out.
Publishing writes one account. Its address is derived from the name, and its contents are what The hook so far showed. It cannot be edited after this. A new version is a new hook under a new name.
With the SDK
The same three calls are in the SDK.
// Read a program's instructions
const idl = await pook.parseIdl({ programId: 'KLend2g3cP87fffoy8q1mQqGKjrxjC8boSyAYavgmjD' })
idl.instructions // [{ name, discriminator, args: [{ name, type, offset, length }], accounts: [{ index, name, writable, signer }] }]
// Check a definition against the chain
const sim = await pook.simulateHook({ hook, sampleAmountIn: '1000000' })
// Publish it
const { tx, signature } = await pook.publishHook({ hook })hook is a definition from defineHook. Write a hook builds one from the instruction parseIdl returns here. A definition written as code can also name companion instructions, for protocols that need another instruction beside the main one. The builder publishes hooks without companions.
What an author earns
Every run through your hook pays you the author's share of its run fee, in the asset the run returned. It is paid inside the run, into an account the program keeps for you and that asset. Fees and POOK has the formula.
Claim your share
Open your hook
Find it in the registry and open it, with the author's wallet connected.
Read what is claimable
The panel Your author's share lists a Claimable amount for each asset the hook has earned in.
Claim
Press Claim and approve the transaction. The stages are Sign in your wallet, Submitted and Confirmed, and the amounts arrive in your wallet.
const author = signer.publicKey
// What each hook has earned, by asset
const { hooks } = await pook.authorFees(author)
// [{ hookId, mint, assetSymbol, decimals, claimableAmount, totalEarnedAmount, lastClaimedAt }]
const claimable = hooks.filter((h) => BigInt(h.claimableAmount) > 0n)
// One claim pays out one asset
const mint = claimable[0].mint
const claim = await pook.claimAuthorFees({
hookIds: claimable.filter((h) => h.mint === mint).map((h) => h.hookId),
mint,
})
claim.tx.status // 'confirmed'Only the author's wallet can sign a claim. A claim pays out everything collected for that asset across all the author's hooks, to the author's wallet. Claims are public: the chain shows the author's address on the hook and on each claim.