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

  1. 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.

  2. The instruction

    Choose the instruction the hook will call. A hook describes exactly one.

  3. 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.

    RoleMeaning
    Fixed valueThe same bytes in every run. Type them as hex.
    Amount inThe run's amount in. Mark the argument that carries the amount.
    Minimum outThe run's minimum out, for an instruction that takes one.
    Caller argumentA value each run supplies.
    Seat argumentA value each run supplies, on a seat hook.

    Under Accounts, give each account a role.

    RoleMeaning
    Stage authorityThe account that signs as the user. Pook's stage takes its place.
    Stage inThe token account the amount is paid from.
    Stage outThe token account the result arrives in.
    SeatThe owner of a position that stays open. Seat hooks only.
    Fixed address, Program, SysvarOne address, the same in every run. Common programs and sysvars are filled in for you.
    Caller suppliesAn account each run names.

    Roles Pook fills read Filled by Pook beside them, and roles a run fills read Filled by each run.

  4. The hook

    Name and describe it.

    FieldWhat to enter
    Nameprotocol.action, lowercase, such as yourname.supply. It is how people run the hook, and it can be published once.
    ProtocolThe protocol's name as people know it.
    LabelThe action in a word or two: Swap, Supply, Stake.
    KindFlow when the asset goes in and comes back in one run. Seat when a position stays open.
    What goes in and what comes backOne sentence. It shows beside the hook everywhere.
    ProgramThe program's address. It is filled from the IDL.
    Mint in, Mint outA mint address to fix the asset, or empty to let each run name it.
  5. 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.

  6. 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.

  7. 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.

TypeScript
// 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

  1. Open your hook

    Find it in the registry and open it, with the author's wallet connected.

  2. Read what is claimable

    The panel Your author's share lists a Claimable amount for each asset the hook has earned in.

  3. Claim

    Press Claim and approve the transaction. The stages are Sign in your wallet, Submitted and Confirmed, and the amounts arrive in your wallet.

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.