import { TOKEN_PROGRAM_ID } from "@solana/spl-token"; import { SystemProgram, TransactionInstruction } from "@solana/web3.js"; import { PublicKey } from "@solana/web3.js"; import { getAta, getBountyVaultPda, getGlobalConfigPda } from "../pda"; import { BASKETS_V3_PROGRAM_ID } from "../../constants"; export const CLAIM_BOUNTY_HANDLER_DISCRIMINATOR = Buffer.from([13, 252, 98, 119, 169, 40, 250, 254]); export function claimBountyIx(params: { keeper: PublicKey; basket: PublicKey; intent: PublicKey; bountyMint: PublicKey; bountyDepositor: PublicKey; rentPayer: PublicKey; keepers: PublicKey[]; }): TransactionInstruction { const { keeper, basket, intent, bountyMint, bountyDepositor, rentPayer, keepers } = params; let bountyVault = getBountyVaultPda(); let globalConfig = getGlobalConfigPda(); let keeperBountyAta = getAta(keeper, bountyMint); let basketBountyAta = getAta(basket, bountyMint); let bountyVaultAta = getAta(bountyVault, bountyMint); let bountyDepositorAta = getAta(bountyDepositor, bountyMint); const data = CLAIM_BOUNTY_HANDLER_DISCRIMINATOR; const keys = [ { pubkey: keeper, isSigner: true, isWritable: true }, { pubkey: basket, isSigner: false, isWritable: true }, { pubkey: intent, isSigner: false, isWritable: true }, { pubkey: bountyMint, isSigner: false, isWritable: false }, { pubkey: keeperBountyAta, isSigner: false, isWritable: true }, { pubkey: basketBountyAta, isSigner: false, isWritable: true }, { pubkey: bountyVault, isSigner: false, isWritable: true }, { pubkey: bountyVaultAta, isSigner: false, isWritable: true }, { pubkey: bountyDepositorAta, isSigner: false, isWritable: true }, { pubkey: rentPayer, isSigner: false, isWritable: true }, { pubkey: globalConfig, isSigner: false, isWritable: false }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ]; keepers.forEach((keeperPubkey) => { keys.push({ pubkey: keeperPubkey, isWritable: true, isSigner: false }); const remKeeperATA = getAta(keeperPubkey, bountyMint); keys.push({ pubkey: remKeeperATA, isWritable: true, isSigner: false }); }); return new TransactionInstruction({ keys, programId: BASKETS_V3_PROGRAM_ID, data, }); }