@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
138 lines • 6.11 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, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
import { SRSLY_PROGRAM_ADDRESS } from '../programs';
import { expectAddress, getAccountMetaFactory } from '../shared';
export const RELEASE_RENTAL_DISCRIMINATOR = new Uint8Array([99, 35, 221, 147, 185, 205, 23, 12]);
export function getReleaseRentalDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(RELEASE_RENTAL_DISCRIMINATOR);
}
export function getReleaseRentalInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), value => ({ ...value, discriminator: RELEASE_RENTAL_DISCRIMINATOR }));
}
export function getReleaseRentalInstructionDataDecoder() {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getReleaseRentalInstructionDataCodec() {
return combineCodec(getReleaseRentalInstructionDataEncoder(), getReleaseRentalInstructionDataDecoder());
}
export async function getReleaseRentalInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
signer: { value: input.signer ?? null, isWritable: true },
fleet: { value: input.fleet ?? null, isWritable: true },
gameId: { value: input.gameId ?? null, isWritable: false },
starbase: { value: input.starbase ?? null, isWritable: false },
starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true },
contract: { value: input.contract ?? null, isWritable: false },
rentalAuthority: {
value: input.rentalAuthority ?? null,
isWritable: false,
},
sageProgram: { value: input.sageProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.contract.value) {
accounts.contract.value = await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(new Uint8Array([114, 101, 110, 116, 97, 108, 95, 99, 111, 110, 116, 114, 97, 99, 116])),
getAddressEncoder().encode(expectAddress(accounts.fleet.value)),
],
});
}
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,
])),
],
});
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.signer),
getAccountMeta(accounts.fleet),
getAccountMeta(accounts.gameId),
getAccountMeta(accounts.starbase),
getAccountMeta(accounts.starbasePlayer),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.sageProgram),
],
data: getReleaseRentalInstructionDataEncoder().encode({}),
programAddress,
});
}
export function getReleaseRentalInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
signer: { value: input.signer ?? null, isWritable: true },
fleet: { value: input.fleet ?? null, isWritable: true },
gameId: { value: input.gameId ?? null, isWritable: false },
starbase: { value: input.starbase ?? null, isWritable: false },
starbasePlayer: { value: input.starbasePlayer ?? null, isWritable: true },
contract: { value: input.contract ?? null, isWritable: false },
rentalAuthority: {
value: input.rentalAuthority ?? null,
isWritable: false,
},
sageProgram: { value: input.sageProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.signer),
getAccountMeta(accounts.fleet),
getAccountMeta(accounts.gameId),
getAccountMeta(accounts.starbase),
getAccountMeta(accounts.starbasePlayer),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.sageProgram),
],
data: getReleaseRentalInstructionDataEncoder().encode({}),
programAddress,
});
}
export function parseReleaseRentalInstruction(instruction) {
if (instruction.accounts.length < 8) {
// 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: {
signer: getNextAccount(),
fleet: getNextAccount(),
gameId: getNextAccount(),
starbase: getNextAccount(),
starbasePlayer: getNextAccount(),
contract: getNextAccount(),
rentalAuthority: getNextAccount(),
sageProgram: getNextAccount(),
},
data: getReleaseRentalInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=releaseRental.js.map