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)

152 lines 6.75 kB
"use strict"; /** * 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 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.NORMALIZE_ADMIN_DISCRIMINATOR = void 0; exports.getNormalizeAdminDiscriminatorBytes = getNormalizeAdminDiscriminatorBytes; exports.getNormalizeAdminInstructionDataEncoder = getNormalizeAdminInstructionDataEncoder; exports.getNormalizeAdminInstructionDataDecoder = getNormalizeAdminInstructionDataDecoder; exports.getNormalizeAdminInstructionDataCodec = getNormalizeAdminInstructionDataCodec; exports.getNormalizeAdminInstructionAsync = getNormalizeAdminInstructionAsync; exports.getNormalizeAdminInstruction = getNormalizeAdminInstruction; exports.parseNormalizeAdminInstruction = parseNormalizeAdminInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); exports.NORMALIZE_ADMIN_DISCRIMINATOR = new Uint8Array([ 26, 134, 185, 168, 82, 175, 6, 182, ]); function getNormalizeAdminDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.NORMALIZE_ADMIN_DISCRIMINATOR); } function getNormalizeAdminInstructionDataEncoder() { return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), (value) => ({ ...value, discriminator: exports.NORMALIZE_ADMIN_DISCRIMINATOR })); } function getNormalizeAdminInstructionDataDecoder() { return (0, kit_1.getStructDecoder)([ ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ]); } function getNormalizeAdminInstructionDataCodec() { return (0, kit_1.combineCodec)(getNormalizeAdminInstructionDataEncoder(), getNormalizeAdminInstructionDataDecoder()); } async function getNormalizeAdminInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.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 (0, kit_1.getProgramDerivedAddress)({ programAddress, seeds: [ (0, kit_1.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 = (0, shared_1.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; } function getNormalizeAdminInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.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 = (0, shared_1.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; } 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