@wuwei-labs/srsly
Version:
[](https://www.npmjs.com/package/ts-sdk-example)
155 lines • 6.71 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
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.RESET_RENTAL_DISCRIMINATOR = void 0;
exports.getResetRentalDiscriminatorBytes = getResetRentalDiscriminatorBytes;
exports.getResetRentalInstructionDataEncoder = getResetRentalInstructionDataEncoder;
exports.getResetRentalInstructionDataDecoder = getResetRentalInstructionDataDecoder;
exports.getResetRentalInstructionDataCodec = getResetRentalInstructionDataCodec;
exports.getResetRentalInstructionAsync = getResetRentalInstructionAsync;
exports.getResetRentalInstruction = getResetRentalInstruction;
exports.parseResetRentalInstruction = parseResetRentalInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.RESET_RENTAL_DISCRIMINATOR = new Uint8Array([
139, 185, 76, 32, 61, 143, 163, 183,
]);
function getResetRentalDiscriminatorBytes() {
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.RESET_RENTAL_DISCRIMINATOR);
}
function getResetRentalInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)]]), (value) => ({ ...value, discriminator: exports.RESET_RENTAL_DISCRIMINATOR }));
}
function getResetRentalInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([
['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
]);
}
function getResetRentalInstructionDataCodec() {
return (0, kit_1.combineCodec)(getResetRentalInstructionDataEncoder(), getResetRentalInstructionDataDecoder());
}
async function getResetRentalInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
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 },
rentalState: { value: input.rentalState ?? null, isWritable: false },
contract: { value: input.contract ?? null, isWritable: true },
rentalAuthority: {
value: input.rentalAuthority ?? null,
isWritable: false,
},
sageProgram: { value: input.sageProgram ?? 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.sageProgram.value) {
accounts.sageProgram.value =
'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi';
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.fleet),
getAccountMeta(accounts.gameId),
getAccountMeta(accounts.starbase),
getAccountMeta(accounts.starbasePlayer),
getAccountMeta(accounts.rentalState),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.sageProgram),
],
programAddress,
data: getResetRentalInstructionDataEncoder().encode({}),
};
return instruction;
}
function getResetRentalInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
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 },
rentalState: { value: input.rentalState ?? null, isWritable: false },
contract: { value: input.contract ?? null, isWritable: true },
rentalAuthority: {
value: input.rentalAuthority ?? null,
isWritable: false,
},
sageProgram: { value: input.sageProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.sageProgram.value) {
accounts.sageProgram.value =
'sAgezwJpDb1aHvzNr3o24cKjsETmFEKghBEyJ1askDi';
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.fleet),
getAccountMeta(accounts.gameId),
getAccountMeta(accounts.starbase),
getAccountMeta(accounts.starbasePlayer),
getAccountMeta(accounts.rentalState),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.sageProgram),
],
programAddress,
data: getResetRentalInstructionDataEncoder().encode({}),
};
return instruction;
}
function parseResetRentalInstruction(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: {
fleet: getNextAccount(),
gameId: getNextAccount(),
starbase: getNextAccount(),
starbasePlayer: getNextAccount(),
rentalState: getNextAccount(),
contract: getNextAccount(),
rentalAuthority: getNextAccount(),
sageProgram: getNextAccount(),
},
data: getResetRentalInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=resetRental.js.map