@accessprotocol/distributor
Version:
Access Protocol Distributor Library
17 lines (16 loc) • 1.21 kB
JavaScript
import { SystemProgram } from "@solana/web3.js";
import { PROGRAM_ID } from "../programId";
import { ASSOCIATED_TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { MerkleDistributor } from "../accounts/MerkleDistributor";
import { getAssociatedTokenAddressSync } from "@solana/spl-token";
import { newDistributorRaw } from "../raw_instructions";
/**
* Creates a new MerkleDistributor.
* After creating this MerkleDistributor, the token_vault should be seeded with max_total_claim tokens.
*/
export function newDistributor(version, root, maxTotalClaim, maxNumNodes, startVestingTs, endVestingTs, mint, creator, programId = PROGRAM_ID, systemProgram = SystemProgram.programId, associatedTokenProgram = ASSOCIATED_TOKEN_PROGRAM_ID, tokenProgram = TOKEN_PROGRAM_ID) {
const distributor = MerkleDistributor.getAddress(creator, mint, version, programId);
const tokenVault = getAssociatedTokenAddressSync(mint, distributor, true);
return newDistributorRaw({ version, root, maxTotalClaim, maxNumNodes, startVestingTs, endVestingTs }, { distributor, mint, tokenVault, creator, systemProgram, associatedTokenProgram, tokenProgram }, programId);
}