UNPKG

@wuwei-labs/srsly

Version:

[![npm version](https://img.shields.io/npm/v/ts-sdk-example.svg)](https://www.npmjs.com/package/ts-sdk-example)

209 lines 8.98 kB
/** * This code was AUTOGENERATED using the codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun codama to update it. * * @see https://github.com/codama-idl/codama */ import { combineCodec, fixDecoderSize, fixEncoderSize, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit'; import { SRSLY_PROGRAM_ADDRESS } from '../programs'; import { expectAddress, getAccountMetaFactory, } from '../shared'; export const CLOSE_CONTRACT_DISCRIMINATOR = new Uint8Array([ 37, 244, 34, 168, 92, 202, 80, 106, ]); export function getCloseContractDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CLOSE_CONTRACT_DISCRIMINATOR); } export function getCloseContractInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CLOSE_CONTRACT_DISCRIMINATOR })); } export function getCloseContractInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getCloseContractInstructionDataCodec() { return combineCodec(getCloseContractInstructionDataEncoder(), getCloseContractInstructionDataDecoder()); } export async function getCloseContractInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { owner: { value: input.owner ?? null, isWritable: true }, ownerTokenAccount: { value: input.ownerTokenAccount ?? null, isWritable: true, }, rentalTokenAccount: { value: input.rentalTokenAccount ?? null, isWritable: true, }, rentalState: { value: input.rentalState ?? null, isWritable: true }, fleet: { value: input.fleet ?? null, isWritable: true }, gameId: { value: input.gameId ?? null, isWritable: false }, starbase: { value: input.starbase ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, contract: { value: input.contract ?? null, isWritable: true }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.ownerTokenAccount.value) { accounts.ownerTokenAccount.value = await getProgramDerivedAddress({ programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL', seeds: [ getAddressEncoder().encode(expectAddress(accounts.owner.value)), getBytesEncoder().encode(new Uint8Array([ 6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180, 133, 237, 95, 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169, ])), getBytesEncoder().encode(new Uint8Array([ 140, 119, 241, 156, 255, 59, 87, 34, 56, 120, 33, 198, 221, 208, 211, 20, 190, 93, 159, 12, 154, 136, 45, 46, 161, 10, 152, 60, 85, 252, 217, 191, ])), ], }); } if (!accounts.rentalAuthority.value) { accounts.rentalAuthority.value = await getProgramDerivedAddress({ programAddress, seeds: [ getBytesEncoder().encode(new Uint8Array([ 114, 101, 110, 116, 97, 108, 95, 97, 117, 116, 104, 111, 114, 105, 116, 121, ])), ], }); } if (!accounts.sageProgram.value) { accounts.sageProgram.value = 'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi'; } if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.owner), getAccountMeta(accounts.ownerTokenAccount), getAccountMeta(accounts.rentalTokenAccount), getAccountMeta(accounts.rentalState), getAccountMeta(accounts.fleet), getAccountMeta(accounts.gameId), getAccountMeta(accounts.starbase), getAccountMeta(accounts.starbasePlayer), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.sageProgram), getAccountMeta(accounts.tokenProgram), ], programAddress, data: getCloseContractInstructionDataEncoder().encode({}), }; return instruction; } export function getCloseContractInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { owner: { value: input.owner ?? null, isWritable: true }, ownerTokenAccount: { value: input.ownerTokenAccount ?? null, isWritable: true, }, rentalTokenAccount: { value: input.rentalTokenAccount ?? null, isWritable: true, }, rentalState: { value: input.rentalState ?? null, isWritable: true }, fleet: { value: input.fleet ?? null, isWritable: true }, gameId: { value: input.gameId ?? null, isWritable: false }, starbase: { value: input.starbase ?? null, isWritable: false }, starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true }, contract: { value: input.contract ?? null, isWritable: true }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: false, }, sageProgram: { value: input.sageProgram ?? null, isWritable: false }, tokenProgram: { value: input.tokenProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.sageProgram.value) { accounts.sageProgram.value = 'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi'; } if (!accounts.tokenProgram.value) { accounts.tokenProgram.value = 'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.owner), getAccountMeta(accounts.ownerTokenAccount), getAccountMeta(accounts.rentalTokenAccount), getAccountMeta(accounts.rentalState), getAccountMeta(accounts.fleet), getAccountMeta(accounts.gameId), getAccountMeta(accounts.starbase), getAccountMeta(accounts.starbasePlayer), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.sageProgram), getAccountMeta(accounts.tokenProgram), ], programAddress, data: getCloseContractInstructionDataEncoder().encode({}), }; return instruction; } export function parseCloseContractInstruction(instruction) { if (instruction.accounts.length < 12) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SRSLY_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { owner: getNextAccount(), ownerTokenAccount: getNextOptionalAccount(), rentalTokenAccount: getNextOptionalAccount(), rentalState: getNextOptionalAccount(), fleet: getNextAccount(), gameId: getNextOptionalAccount(), starbase: getNextOptionalAccount(), starbasePlayer: getNextOptionalAccount(), contract: getNextAccount(), rentalAuthority: getNextAccount(), sageProgram: getNextAccount(), tokenProgram: getNextOptionalAccount(), }, data: getCloseContractInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=closeContract.js.map