@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
122 lines • 6.27 kB
JavaScript
/**
* 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, getAddressDecoder, getAddressEncoder, getBooleanDecoder, getBooleanEncoder, getBytesDecoder, getBytesEncoder, getF32Decoder, getF32Encoder, getI64Decoder, getI64Encoder, getOptionDecoder, getOptionEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU16Decoder, getU16Encoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, } from '@solana/kit';
import { SRSLY_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory } from '../shared';
export const UPDATE_CONFIG_DISCRIMINATOR = new Uint8Array([29, 158, 252, 191, 10, 83, 219, 99]);
export function getUpdateConfigDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(UPDATE_CONFIG_DISCRIMINATOR);
}
export function getUpdateConfigInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['admin', getOptionEncoder(getAddressEncoder())],
['stardustToAtlas', getOptionEncoder(getU64Encoder())],
['serviceFeeBps', getOptionEncoder(getU64Encoder())],
['baseBps', getOptionEncoder(getU16Encoder())],
['rentalDurationMinSeconds', getOptionEncoder(getI64Encoder())],
['rentalDurationMaxSeconds', getOptionEncoder(getI64Encoder())],
['atlasMint', getOptionEncoder(getAddressEncoder())],
['reservationsEnabled', getOptionEncoder(getBooleanEncoder())],
['pointsPerDay', getOptionEncoder(getU64Encoder())],
['cancellationPenalty', getOptionEncoder(getU64Encoder())],
['minCaptureThreshold', getOptionEncoder(getU64Encoder())],
['weightBase', getOptionEncoder(getU32Encoder())],
['weightMultiplier', getOptionEncoder(getF32Encoder())],
['maxWeight', getOptionEncoder(getU8Encoder())],
['captureRateBps', getOptionEncoder(getU64Encoder())],
['atlasPerPoint', getOptionEncoder(getU64Encoder())],
['contestedMultiplierMaxBps', getOptionEncoder(getU16Encoder())],
]), value => ({ ...value, discriminator: UPDATE_CONFIG_DISCRIMINATOR }));
}
export function getUpdateConfigInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['admin', getOptionDecoder(getAddressDecoder())],
['stardustToAtlas', getOptionDecoder(getU64Decoder())],
['serviceFeeBps', getOptionDecoder(getU64Decoder())],
['baseBps', getOptionDecoder(getU16Decoder())],
['rentalDurationMinSeconds', getOptionDecoder(getI64Decoder())],
['rentalDurationMaxSeconds', getOptionDecoder(getI64Decoder())],
['atlasMint', getOptionDecoder(getAddressDecoder())],
['reservationsEnabled', getOptionDecoder(getBooleanDecoder())],
['pointsPerDay', getOptionDecoder(getU64Decoder())],
['cancellationPenalty', getOptionDecoder(getU64Decoder())],
['minCaptureThreshold', getOptionDecoder(getU64Decoder())],
['weightBase', getOptionDecoder(getU32Decoder())],
['weightMultiplier', getOptionDecoder(getF32Decoder())],
['maxWeight', getOptionDecoder(getU8Decoder())],
['captureRateBps', getOptionDecoder(getU64Decoder())],
['atlasPerPoint', getOptionDecoder(getU64Decoder())],
['contestedMultiplierMaxBps', getOptionDecoder(getU16Decoder())],
]);
}
export function getUpdateConfigInstructionDataCodec() {
return combineCodec(getUpdateConfigInstructionDataEncoder(), getUpdateConfigInstructionDataDecoder());
}
export async function getUpdateConfigInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
admin: { value: input.admin ?? null, isWritable: false },
config: { value: input.config ?? null, isWritable: true },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input, admin: input.adminArg };
// 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.admin), getAccountMeta(accounts.config)],
data: getUpdateConfigInstructionDataEncoder().encode(args),
programAddress,
});
}
export function getUpdateConfigInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
admin: { value: input.admin ?? null, isWritable: false },
config: { value: input.config ?? null, isWritable: true },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input, admin: input.adminArg };
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [getAccountMeta(accounts.admin), getAccountMeta(accounts.config)],
data: getUpdateConfigInstructionDataEncoder().encode(args),
programAddress,
});
}
export function parseUpdateConfigInstruction(instruction) {
if (instruction.accounts.length < 2) {
// 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(), config: getNextAccount() },
data: getUpdateConfigInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=updateConfig.js.map