import { PublicKey, SystemProgram, SYSVAR_RENT_PUBKEY, TransactionInstruction } from '@solana/web3.js'; import { ASSOCIATED_TOKEN_PROGRAM_ID, TOKEN_2022_PROGRAM_ID, TOKEN_PROGRAM_ID } from '@solana/spl-token'; import { BASKETS_V3_PROGRAM_ID } from '../../constants'; import { GlobalConfig, GlobalConfigLayout } from '../../layouts/config'; import { getAta, getBountyVaultPda, getGlobalConfigPda } from '../pda'; const CREATE_GLOBAL_CONFIG_DISCRIMINATOR = Buffer.from([62, 50, 47, 241, 153, 49, 252, 239]); const EDIT_GLOBAL_CONFIG_DISCRIMINATOR = Buffer.from([209, 246, 241, 219, 204, 153, 103, 175]); export function createGlobalConfigIx(params: { admin: PublicKey; }): TransactionInstruction { const { admin } = params; let globalConfig = getGlobalConfigPda(); const data = CREATE_GLOBAL_CONFIG_DISCRIMINATOR; const keys = [ { pubkey: admin, isSigner: true, isWritable: true }, { pubkey: globalConfig, isSigner: false, isWritable: true }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: SYSVAR_RENT_PUBKEY, isSigner: false, isWritable: false }, ]; return new TransactionInstruction({ keys, programId: BASKETS_V3_PROGRAM_ID, data, }); } export function editGlobalConfigIx( params: { signer: PublicKey; config: GlobalConfig; }): TransactionInstruction { const discriminator = EDIT_GLOBAL_CONFIG_DISCRIMINATOR; let globalConfig = getGlobalConfigPda(); const buffer = Buffer.alloc(GlobalConfigLayout.span); const len = GlobalConfigLayout.encode(params.config, buffer); const data = Buffer.concat([discriminator, buffer.slice(0, len)]); let bountyMint = params.config.bountyMint; let bountyVault = getBountyVaultPda(); let bountyVaultAta = getAta(bountyVault, bountyMint); const keys = [ { pubkey: params.signer, isSigner: true, isWritable: true }, { pubkey: globalConfig, isSigner: false, isWritable: true }, { pubkey: bountyMint, isSigner: false, isWritable: false }, { pubkey: bountyVault, isSigner: false, isWritable: false }, { pubkey: bountyVaultAta, isSigner: false, isWritable: true }, { pubkey: SystemProgram.programId, isSigner: false, isWritable: false }, { pubkey: TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: TOKEN_2022_PROGRAM_ID, isSigner: false, isWritable: false }, { pubkey: ASSOCIATED_TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }, ]; return new TransactionInstruction({ keys, programId: BASKETS_V3_PROGRAM_ID, data, }); }