UNPKG

@wuwei-labs/srsly

Version:
116 lines 5.23 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, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getI64Decoder, getI64Encoder, getOptionDecoder, getOptionEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, } from '@solana/kit'; import { SRSLY_PROGRAM_ADDRESS } from '../programs'; import { getAccountMetaFactory } from '../shared'; export const UPDATE_CONTRACT_DISCRIMINATOR = new Uint8Array([78, 184, 162, 174, 233, 5, 40, 82]); export function getUpdateContractDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_CONTRACT_DISCRIMINATOR); } export function getUpdateContractInstructionDataEncoder() { return transformEncoder(getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['rate', getOptionEncoder(getU64Encoder())], ['durationMinSeconds', getOptionEncoder(getI64Encoder())], ['durationMaxSeconds', getOptionEncoder(getI64Encoder())], ['cancelDelayMin', getOptionEncoder(getI64Encoder())], ['reservationsDisabled', getOptionEncoder(getBooleanEncoder())], ['toClose', getOptionEncoder(getBooleanEncoder())], ['contestedThreshold', getOptionEncoder(getU8Encoder())], ]), value => ({ ...value, discriminator: UPDATE_CONTRACT_DISCRIMINATOR })); } export function getUpdateContractInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['rate', getOptionDecoder(getU64Decoder())], ['durationMinSeconds', getOptionDecoder(getI64Decoder())], ['durationMaxSeconds', getOptionDecoder(getI64Decoder())], ['cancelDelayMin', getOptionDecoder(getI64Decoder())], ['reservationsDisabled', getOptionDecoder(getBooleanDecoder())], ['toClose', getOptionDecoder(getBooleanDecoder())], ['contestedThreshold', getOptionDecoder(getU8Decoder())], ]); } export function getUpdateContractInstructionDataCodec() { return combineCodec(getUpdateContractInstructionDataEncoder(), getUpdateContractInstructionDataDecoder()); } export async function getUpdateContractInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { authority: { value: input.authority ?? null, isWritable: true }, config: { value: input.config ?? null, isWritable: false }, contract: { value: input.contract ?? null, isWritable: true }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; // Resolve default values. if (!accounts.config.value) { accounts.config.value = await getProgramDerivedAddress({ programAddress, seeds: [getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103]))], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.authority), getAccountMeta(accounts.config), getAccountMeta(accounts.contract), ], data: getUpdateContractInstructionDataEncoder().encode(args), programAddress, }); } export function getUpdateContractInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { authority: { value: input.authority ?? null, isWritable: true }, config: { value: input.config ?? null, isWritable: false }, contract: { value: input.contract ?? null, isWritable: true }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.authority), getAccountMeta(accounts.config), getAccountMeta(accounts.contract), ], data: getUpdateContractInstructionDataEncoder().encode(args), programAddress, }); } export function parseUpdateContractInstruction(instruction) { if (instruction.accounts.length < 3) { // 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: { authority: getNextAccount(), config: getNextAccount(), contract: getNextAccount(), }, data: getUpdateContractInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=updateContract.js.map