UNPKG

@wuwei-labs/srsly

Version:
126 lines 6.05 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.UPDATE_CONTRACT_DISCRIMINATOR = void 0; exports.getUpdateContractDiscriminatorBytes = getUpdateContractDiscriminatorBytes; exports.getUpdateContractInstructionDataEncoder = getUpdateContractInstructionDataEncoder; exports.getUpdateContractInstructionDataDecoder = getUpdateContractInstructionDataDecoder; exports.getUpdateContractInstructionDataCodec = getUpdateContractInstructionDataCodec; exports.getUpdateContractInstructionAsync = getUpdateContractInstructionAsync; exports.getUpdateContractInstruction = getUpdateContractInstruction; exports.parseUpdateContractInstruction = parseUpdateContractInstruction; const kit_1 = require("@solana/kit"); const programs_1 = require("../programs"); const shared_1 = require("../shared"); exports.UPDATE_CONTRACT_DISCRIMINATOR = new Uint8Array([78, 184, 162, 174, 233, 5, 40, 82]); function getUpdateContractDiscriminatorBytes() { return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.UPDATE_CONTRACT_DISCRIMINATOR); } function getUpdateContractInstructionDataEncoder() { return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([ ['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)], ['rate', (0, kit_1.getOptionEncoder)((0, kit_1.getU64Encoder)())], ['durationMinSeconds', (0, kit_1.getOptionEncoder)((0, kit_1.getI64Encoder)())], ['durationMaxSeconds', (0, kit_1.getOptionEncoder)((0, kit_1.getI64Encoder)())], ['cancelDelayMin', (0, kit_1.getOptionEncoder)((0, kit_1.getI64Encoder)())], ['reservationsDisabled', (0, kit_1.getOptionEncoder)((0, kit_1.getBooleanEncoder)())], ['toClose', (0, kit_1.getOptionEncoder)((0, kit_1.getBooleanEncoder)())], ['contestedThreshold', (0, kit_1.getOptionEncoder)((0, kit_1.getU8Encoder)())], ]), value => ({ ...value, discriminator: exports.UPDATE_CONTRACT_DISCRIMINATOR })); } function getUpdateContractInstructionDataDecoder() { return (0, kit_1.getStructDecoder)([ ['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)], ['rate', (0, kit_1.getOptionDecoder)((0, kit_1.getU64Decoder)())], ['durationMinSeconds', (0, kit_1.getOptionDecoder)((0, kit_1.getI64Decoder)())], ['durationMaxSeconds', (0, kit_1.getOptionDecoder)((0, kit_1.getI64Decoder)())], ['cancelDelayMin', (0, kit_1.getOptionDecoder)((0, kit_1.getI64Decoder)())], ['reservationsDisabled', (0, kit_1.getOptionDecoder)((0, kit_1.getBooleanDecoder)())], ['toClose', (0, kit_1.getOptionDecoder)((0, kit_1.getBooleanDecoder)())], ['contestedThreshold', (0, kit_1.getOptionDecoder)((0, kit_1.getU8Decoder)())], ]); } function getUpdateContractInstructionDataCodec() { return (0, kit_1.combineCodec)(getUpdateContractInstructionDataEncoder(), getUpdateContractInstructionDataDecoder()); } async function getUpdateContractInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.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 (0, kit_1.getProgramDerivedAddress)({ programAddress, seeds: [(0, kit_1.getBytesEncoder)().encode(new Uint8Array([99, 111, 110, 102, 105, 103]))], }); } const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.authority), getAccountMeta(accounts.config), getAccountMeta(accounts.contract), ], data: getUpdateContractInstructionDataEncoder().encode(args), programAddress, }); } function getUpdateContractInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? programs_1.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 = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId'); return Object.freeze({ accounts: [ getAccountMeta(accounts.authority), getAccountMeta(accounts.config), getAccountMeta(accounts.contract), ], data: getUpdateContractInstructionDataEncoder().encode(args), programAddress, }); } 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