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)

142 lines 6.08 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, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit'; import { SRSLY_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory } from '../shared'; export const NORMALIZE_ADMIN_DISCRIMINATOR = new Uint8Array([ 26, 134, 185, 168, 82, 175, 6, 182, ]); export function getNormalizeAdminDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(NORMALIZE_ADMIN_DISCRIMINATOR); } export function getNormalizeAdminInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: NORMALIZE_ADMIN_DISCRIMINATOR })); } export function getNormalizeAdminInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ]); } export function getNormalizeAdminInstructionDataCodec() { return combineCodec(getNormalizeAdminInstructionDataEncoder(), getNormalizeAdminInstructionDataDecoder()); } export async function getNormalizeAdminInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: false }, contract: { value: input.contract ?? null, isWritable: true }, rentalState: { value: input.rentalState ?? null, isWritable: true }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: true }, thread: { value: input.thread ?? null, isWritable: true }, antegenProgram: { value: input.antegenProgram ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. 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.antegenProgram.value) { accounts.antegenProgram.value = 'AgThdyi1P5RkVeZD2rQahTvs8HePJoGFFxKtvok5s2J1'; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.admin), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalState), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.thread), getAccountMeta(accounts.antegenProgram), getAccountMeta(accounts.systemProgram), ], programAddress, data: getNormalizeAdminInstructionDataEncoder().encode({}), }; return instruction; } export function getNormalizeAdminInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: false }, contract: { value: input.contract ?? null, isWritable: true }, rentalState: { value: input.rentalState ?? null, isWritable: true }, rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: true }, thread: { value: input.thread ?? null, isWritable: true }, antegenProgram: { value: input.antegenProgram ?? null, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isWritable: false }, }; const accounts = originalAccounts; // Resolve default values. if (!accounts.antegenProgram.value) { accounts.antegenProgram.value = 'AgThdyi1P5RkVeZD2rQahTvs8HePJoGFFxKtvok5s2J1'; } if (!accounts.systemProgram.value) { accounts.systemProgram.value = '11111111111111111111111111111111'; } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.admin), getAccountMeta(accounts.contract), getAccountMeta(accounts.rentalState), getAccountMeta(accounts.rentalAuthority), getAccountMeta(accounts.thread), getAccountMeta(accounts.antegenProgram), getAccountMeta(accounts.systemProgram), ], programAddress, data: getNormalizeAdminInstructionDataEncoder().encode({}), }; return instruction; } export function parseNormalizeAdminInstruction(instruction) { if (instruction.accounts.length < 7) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; return { programAddress: instruction.programAddress, accounts: { admin: getNextAccount(), contract: getNextAccount(), rentalState: getNextAccount(), rentalAuthority: getNextAccount(), thread: getNextAccount(), antegenProgram: getNextAccount(), systemProgram: getNextAccount(), }, data: getNormalizeAdminInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=normalizeAdmin.js.map