@accessprotocol/distributor
Version:
Access Protocol Distributor Library
30 lines (29 loc) • 1.47 kB
JavaScript
import { TransactionInstruction } from "@solana/web3.js"; // eslint-disable-line @typescript-eslint/no-unused-vars
import * as borsh from "@coral-xyz/borsh"; // eslint-disable-line @typescript-eslint/no-unused-vars
import { PROGRAM_ID } from "../programId";
export const layout = borsh.struct([
borsh.u64("amountUnlocked"),
borsh.u64("amountLocked"),
borsh.vec(borsh.array(borsh.u8(), 32), "proof"),
]);
export function newClaim(args, accounts, programId = PROGRAM_ID) {
const keys = [
{ pubkey: accounts.distributor, isSigner: false, isWritable: true },
{ pubkey: accounts.claimStatus, isSigner: false, isWritable: true },
{ pubkey: accounts.from, isSigner: false, isWritable: true },
{ pubkey: accounts.to, isSigner: false, isWritable: true },
{ pubkey: accounts.claimant, isSigner: true, isWritable: true },
{ pubkey: accounts.tokenProgram, isSigner: false, isWritable: false },
{ pubkey: accounts.systemProgram, isSigner: false, isWritable: false },
];
const identifier = Buffer.from([78, 177, 98, 123, 210, 21, 187, 83]);
const buffer = Buffer.alloc(1000);
const len = layout.encode({
amountUnlocked: args.amountUnlocked,
amountLocked: args.amountLocked,
proof: args.proof,
}, buffer);
const data = Buffer.concat([identifier, buffer]).slice(0, 8 + len);
const ix = new TransactionInstruction({ keys, programId, data });
return ix;
}