@accessprotocol/distributor
Version:
Access Protocol Distributor Library
35 lines (34 loc) • 1.3 kB
JavaScript
import { PublicKey, SystemProgram } from "@solana/web3.js";
import { PROGRAM_ID } from "../programId";
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
import { newClaimRaw } from "../raw_instructions";
/**
* Creates claim instructions for both unlocked and locked tokens.
* Returns both instructions if both amounts are > 0, otherwise returns the relevant one.
*/
export function newClaim(amountUnlocked, amountLocked, proof, distributor, claimant, mint, programId = PROGRAM_ID, tokenProgram = TOKEN_PROGRAM_ID, systemProgram = SystemProgram.programId) {
// Get claim status PDA
const claimStatus = PublicKey.findProgramAddressSync([
Buffer.from("ClaimStatus"),
claimant.toBuffer(),
distributor.toBuffer(),
], programId)[0];
// Get distributor's token vault
const from = getAssociatedTokenAddressSync(mint, distributor, true);
// Get claimant's token account
const to = getAssociatedTokenAddressSync(mint, claimant, true);
return newClaimRaw({
amountUnlocked,
amountLocked,
proof,
}, {
distributor,
claimStatus,
from,
to,
claimant,
tokenProgram,
systemProgram,
}, programId);
}