@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
261 lines • 11.9 kB
JavaScript
"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.CANCEL_RENTAL_DISCRIMINATOR = void 0;
exports.getCancelRentalDiscriminatorBytes = getCancelRentalDiscriminatorBytes;
exports.getCancelRentalInstructionDataEncoder = getCancelRentalInstructionDataEncoder;
exports.getCancelRentalInstructionDataDecoder = getCancelRentalInstructionDataDecoder;
exports.getCancelRentalInstructionDataCodec = getCancelRentalInstructionDataCodec;
exports.getCancelRentalInstructionAsync = getCancelRentalInstructionAsync;
exports.getCancelRentalInstruction = getCancelRentalInstruction;
exports.parseCancelRentalInstruction = parseCancelRentalInstruction;
const kit_1 = require("@solana/kit");
const programs_1 = require("../programs");
const shared_1 = require("../shared");
exports.CANCEL_RENTAL_DISCRIMINATOR = new Uint8Array([97, 204, 63, 8, 84, 34, 28, 43]);
function getCancelRentalDiscriminatorBytes() {
return (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8).encode(exports.CANCEL_RENTAL_DISCRIMINATOR);
}
function getCancelRentalInstructionDataEncoder() {
return (0, kit_1.transformEncoder)((0, kit_1.getStructEncoder)([
['discriminator', (0, kit_1.fixEncoderSize)((0, kit_1.getBytesEncoder)(), 8)],
['cancelDelay', (0, kit_1.getI64Encoder)()],
]), value => ({ ...value, discriminator: exports.CANCEL_RENTAL_DISCRIMINATOR }));
}
function getCancelRentalInstructionDataDecoder() {
return (0, kit_1.getStructDecoder)([
['discriminator', (0, kit_1.fixDecoderSize)((0, kit_1.getBytesDecoder)(), 8)],
['cancelDelay', (0, kit_1.getI64Decoder)()],
]);
}
function getCancelRentalInstructionDataCodec() {
return (0, kit_1.combineCodec)(getCancelRentalInstructionDataEncoder(), getCancelRentalInstructionDataDecoder());
}
async function getCancelRentalInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
borrower: { value: input.borrower ?? null, isWritable: true },
config: { value: input.config ?? null, isWritable: false },
mint: { value: input.mint ?? null, isWritable: false },
borrowerState: { value: input.borrowerState ?? null, isWritable: true },
borrowerTokenAccount: {
value: input.borrowerTokenAccount ?? null,
isWritable: true,
},
contract: { value: input.contract ?? null, isWritable: true },
rentalState: { value: input.rentalState ?? null, isWritable: true },
contractTokenAccount: {
value: input.contractTokenAccount ?? null,
isWritable: true,
},
fleet: { value: input.fleet ?? null, isWritable: false },
rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: true },
contractThread: { value: input.contractThread ?? null, isWritable: true },
antegenProgram: { value: input.antegenProgram ?? null, isWritable: false },
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
associatedTokenProgram: {
value: input.associatedTokenProgram ?? null,
isWritable: false,
},
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
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]))],
});
}
if (!accounts.borrowerState.value) {
accounts.borrowerState.value = await (0, kit_1.getProgramDerivedAddress)({
programAddress,
seeds: [
(0, kit_1.getBytesEncoder)().encode(new Uint8Array([98, 111, 114, 114, 111, 119, 101, 114, 95, 115, 116, 97, 116, 101])),
(0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.borrower.value)),
],
});
}
if (!accounts.borrowerTokenAccount.value) {
accounts.borrowerTokenAccount.value = await (0, kit_1.getProgramDerivedAddress)({
programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
seeds: [
(0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.borrower.value)),
(0, kit_1.getBytesEncoder)().encode(new Uint8Array([
6, 221, 246, 225, 215, 101, 161, 147, 217, 203, 225, 70, 206, 235, 121, 172, 28, 180,
133, 237, 95, 91, 55, 145, 58, 140, 245, 133, 126, 255, 0, 169,
])),
(0, kit_1.getAddressEncoder)().encode((0, shared_1.expectAddress)(accounts.mint.value)),
],
});
}
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.antegenProgram.value) {
accounts.antegenProgram.value =
'AgTv5w1UvUb6zeqkThwMrztGu9hpepBu8YLghuR4dpSx';
}
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
if (!accounts.associatedTokenProgram.value) {
accounts.associatedTokenProgram.value =
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
'11111111111111111111111111111111';
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.borrower),
getAccountMeta(accounts.config),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.borrowerState),
getAccountMeta(accounts.borrowerTokenAccount),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalState),
getAccountMeta(accounts.contractTokenAccount),
getAccountMeta(accounts.fleet),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.contractThread),
getAccountMeta(accounts.antegenProgram),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getCancelRentalInstructionDataEncoder().encode(args),
programAddress,
});
}
function getCancelRentalInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? programs_1.SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
borrower: { value: input.borrower ?? null, isWritable: true },
config: { value: input.config ?? null, isWritable: false },
mint: { value: input.mint ?? null, isWritable: false },
borrowerState: { value: input.borrowerState ?? null, isWritable: true },
borrowerTokenAccount: {
value: input.borrowerTokenAccount ?? null,
isWritable: true,
},
contract: { value: input.contract ?? null, isWritable: true },
rentalState: { value: input.rentalState ?? null, isWritable: true },
contractTokenAccount: {
value: input.contractTokenAccount ?? null,
isWritable: true,
},
fleet: { value: input.fleet ?? null, isWritable: false },
rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: true },
contractThread: { value: input.contractThread ?? null, isWritable: true },
antegenProgram: { value: input.antegenProgram ?? null, isWritable: false },
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
associatedTokenProgram: {
value: input.associatedTokenProgram ?? null,
isWritable: false,
},
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input };
// Resolve default values.
if (!accounts.antegenProgram.value) {
accounts.antegenProgram.value =
'AgTv5w1UvUb6zeqkThwMrztGu9hpepBu8YLghuR4dpSx';
}
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
if (!accounts.associatedTokenProgram.value) {
accounts.associatedTokenProgram.value =
'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL';
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value =
'11111111111111111111111111111111';
}
const getAccountMeta = (0, shared_1.getAccountMetaFactory)(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.borrower),
getAccountMeta(accounts.config),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.borrowerState),
getAccountMeta(accounts.borrowerTokenAccount),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalState),
getAccountMeta(accounts.contractTokenAccount),
getAccountMeta(accounts.fleet),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.contractThread),
getAccountMeta(accounts.antegenProgram),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getCancelRentalInstructionDataEncoder().encode(args),
programAddress,
});
}
function parseCancelRentalInstruction(instruction) {
if (instruction.accounts.length < 15) {
// TODO: Coded error.
throw new Error('Not enough accounts');
}
let accountIndex = 0;
const getNextAccount = () => {
const accountMeta = instruction.accounts[accountIndex];
accountIndex += 1;
return accountMeta;
};
const getNextOptionalAccount = () => {
const accountMeta = getNextAccount();
return accountMeta.address === programs_1.SRSLY_PROGRAM_ADDRESS ? undefined : accountMeta;
};
return {
programAddress: instruction.programAddress,
accounts: {
borrower: getNextAccount(),
config: getNextAccount(),
mint: getNextAccount(),
borrowerState: getNextAccount(),
borrowerTokenAccount: getNextAccount(),
contract: getNextAccount(),
rentalState: getNextAccount(),
contractTokenAccount: getNextAccount(),
fleet: getNextAccount(),
rentalAuthority: getNextAccount(),
contractThread: getNextOptionalAccount(),
antegenProgram: getNextAccount(),
tokenProgram: getNextAccount(),
associatedTokenProgram: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getCancelRentalInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=cancelRental.js.map