solmash-whitelist-sdk-v2
Version:
A sdk for interacting Solmash Whitelist program
229 lines (217 loc) • 5.39 kB
text/typescript
import { BN, Program } from "@project-serum/anchor";
import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_PROGRAM_ID } from "@solana/spl-token";
import { PublicKey, SystemProgram, TransactionInstruction } from "@solana/web3.js";
import { SolmashWhitelist } from "./idl";
export class SolmashWhitelistInstructions {
constructor(readonly program: Program<SolmashWhitelist>) {}
async getInitAuctionInstruction(
auction: PublicKey,
auctionVault: PublicKey,
auctionVaultTokenAccount: PublicKey,
creator: PublicKey,
initParams: {
name: string;
enabled: boolean;
preSaleStartTime: BN;
preSaleEndTime: BN;
ticketsInPool: BN;
tokenQuantityPerTicket: BN;
ticketPriceInSol: BN;
ticketPriceInBid: BN;
claimTime: BN;
auctionToken: PublicKey;
bidToken: PublicKey;
},
): Promise<TransactionInstruction> {
const {
auctionToken,
bidToken,
claimTime,
enabled,
name,
preSaleEndTime,
preSaleStartTime,
ticketPriceInBid,
ticketPriceInSol,
ticketsInPool,
tokenQuantityPerTicket,
} = initParams;
return this.program.methods
.initAuction({
auctionToken,
bidToken,
claimTime,
enabled,
name,
preSaleEndTime,
preSaleStartTime,
ticketPriceInBid,
ticketPriceInSol,
ticketsInPool,
tokenQuantityPerTicket,
})
.accounts({
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
auction,
auctionToken,
auctionVault,
auctionVaultTokenAccount,
creator,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
})
.instruction();
}
async getAddTokenInstruction(
auction: PublicKey,
auctionToken: PublicKey,
auctionVault: PublicKey,
auctionVaultTokenAccount: PublicKey,
creator: PublicKey,
creatorAuctionTokenAccount: PublicKey,
): Promise<TransactionInstruction> {
return this.program.methods
.addToken()
.accounts({
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
auction,
auctionToken,
auctionVault,
auctionVaultTokenAccount,
creator,
creatorAuctionTokenAccount,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
})
.instruction();
}
async getWithdrawFundsInstruction(
auction: PublicKey,
auctionBidTokenAccount: PublicKey,
auctionToken: PublicKey,
auctionVault: PublicKey,
auctionVaultTokenAccount: PublicKey,
bidToken: PublicKey,
creator: PublicKey,
creatorAuctionTokenAccount: PublicKey,
creatorBidTokenAccount: PublicKey,
withdrawSol: boolean,
): Promise<TransactionInstruction> {
return this.program.methods
.withdrawFunds(withdrawSol)
.accounts({
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
auction,
auctionBidTokenAccount,
auctionToken,
auctionVault,
auctionVaultTokenAccount,
bidToken,
creator,
creatorAuctionTokenAccount,
creatorBidTokenAccount,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
})
.instruction();
}
async getWhitelistInstruction(
auction: PublicKey,
buyerPda: PublicKey,
creator: PublicKey,
whitelistUser: PublicKey,
): Promise<TransactionInstruction> {
return this.program.methods
.whitelist()
.accounts({
auction,
buyerPda,
creator,
systemProgram: SystemProgram.programId,
whitelistUser,
})
.instruction();
}
// async getPreSaleBuyUsingSplInstruction(
// auction: PublicKey,
// auctionVault: PublicKey,
// auctionVaultBidTokenAccount: PublicKey,
// bidToken: PublicKey,
// buyer: PublicKey,
// buyerBidTokenAccount: PublicKey,
// buyerPda: PublicKey,
// ): Promise<TransactionInstruction> {
// return this.program.methods
// .preSaleBuyUsingSpl()
// .accounts({
// associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
// auction,
// auctionVault,
// auctionVaultBidTokenAccount,
// bidToken,
// buyer,
// buyerBidTokenAccount,
// buyerPda,
// clock: SYSVAR_CLOCK_PUBKEY,
// systemProgram: SystemProgram.programId,
// tokenProgram: TOKEN_PROGRAM_ID,
// })
// .instruction();
// }
async getPreSaleBuyUsingSolInstruction(
auction: PublicKey,
auctionVault: PublicKey,
buyer: PublicKey,
buyerPda: PublicKey,
): Promise<TransactionInstruction> {
return this.program.methods
.preSaleBuyUsingSol()
.accounts({
auction,
auctionVault,
buyer,
buyerPda,
systemProgram: SystemProgram.programId,
})
.instruction();
}
async getClaimTokensInstruction(
auction: PublicKey,
auctionToken: PublicKey,
auctionVault: PublicKey,
auctionVaultTokenAccount: PublicKey,
buyer: PublicKey,
buyerAuctionTokenAccount: PublicKey,
buyerPda: PublicKey,
): Promise<TransactionInstruction> {
return this.program.methods
.claimTokens()
.accounts({
associatedTokenProgram: ASSOCIATED_TOKEN_PROGRAM_ID,
auction,
auctionToken,
auctionVault,
auctionVaultTokenAccount,
buyer,
buyerAuctionTokenAccount,
buyerPda,
systemProgram: SystemProgram.programId,
tokenProgram: TOKEN_PROGRAM_ID,
})
.instruction();
}
async getChangeTimeInstruction(
auction: PublicKey,
creator: PublicKey,
newStartTime: BN,
newEndTime: BN,
): Promise<TransactionInstruction> {
return this.program.methods
.changeTime(newStartTime, newEndTime)
.accounts({
auction,
creator,
})
.instruction();
}
}