@wuwei-labs/srsly
Version:
[](https://www.npmjs.com/package/ts-sdk-example)
215 lines • 9.25 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 CANCEL_RENTAL_DISCRIMINATOR = new Uint8Array([
97, 204, 63, 8, 84, 34, 28, 43,
]);
export function getCancelRentalDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(CANCEL_RENTAL_DISCRIMINATOR);
}
export function getCancelRentalInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CANCEL_RENTAL_DISCRIMINATOR }));
}
export function getCancelRentalInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
]);
}
export function getCancelRentalInstructionDataCodec() {
return combineCodec(getCancelRentalInstructionDataEncoder(), getCancelRentalInstructionDataDecoder());
}
export async function getCancelRentalInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
borrower: { value: input.borrower ?? null, isWritable: false },
borrowerTokenAccount: {
value: input.borrowerTokenAccount ?? null,
isWritable: true,
},
rentalThread: { value: input.rentalThread ?? null, isWritable: false },
contract: { value: input.contract ?? null, isWritable: false },
rentalState: { value: input.rentalState ?? null, isWritable: true },
rentalTokenAccount: {
value: input.rentalTokenAccount ?? null,
isWritable: true,
},
rentalAuthority: {
value: input.rentalAuthority ?? null,
isWritable: false,
},
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.borrowerTokenAccount.value) {
accounts.borrowerTokenAccount.value = await getProgramDerivedAddress({
programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
seeds: [
getAddressEncoder().encode(expectAddress(accounts.borrower.value)),
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,
])),
getBytesEncoder().encode(new Uint8Array([
140, 119, 241, 156, 255, 59, 87, 34, 56, 120, 33, 198, 221, 208,
211, 20, 190, 93, 159, 12, 154, 136, 45, 46, 161, 10, 152, 60, 85,
252, 217, 191,
])),
],
});
}
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,
])),
],
});
}
if (!accounts.rentalState.value) {
accounts.rentalState.value = await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(new Uint8Array([
114, 101, 110, 116, 97, 108, 95, 115, 116, 97, 116, 101,
])),
getAddressEncoder().encode(expectAddress(accounts.contract.value)),
getAddressEncoder().encode(expectAddress(accounts.borrower.value)),
],
});
}
if (!accounts.rentalThread.value) {
accounts.rentalThread.value = await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(new Uint8Array([116, 104, 114, 101, 97, 100])),
getAddressEncoder().encode(expectAddress(accounts.rentalAuthority.value)),
getAddressEncoder().encode(expectAddress(accounts.rentalState.value)),
],
});
}
if (!accounts.rentalTokenAccount.value) {
accounts.rentalTokenAccount.value = await getProgramDerivedAddress({
programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
seeds: [
getAddressEncoder().encode(expectAddress(accounts.rentalState.value)),
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,
])),
getBytesEncoder().encode(new Uint8Array([
140, 119, 241, 156, 255, 59, 87, 34, 56, 120, 33, 198, 221, 208,
211, 20, 190, 93, 159, 12, 154, 136, 45, 46, 161, 10, 152, 60, 85,
252, 217, 191,
])),
],
});
}
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.borrower),
getAccountMeta(accounts.borrowerTokenAccount),
getAccountMeta(accounts.rentalThread),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalState),
getAccountMeta(accounts.rentalTokenAccount),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.tokenProgram),
],
programAddress,
data: getCancelRentalInstructionDataEncoder().encode({}),
};
return instruction;
}
export function getCancelRentalInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
borrower: { value: input.borrower ?? null, isWritable: false },
borrowerTokenAccount: {
value: input.borrowerTokenAccount ?? null,
isWritable: true,
},
rentalThread: { value: input.rentalThread ?? null, isWritable: false },
contract: { value: input.contract ?? null, isWritable: false },
rentalState: { value: input.rentalState ?? null, isWritable: true },
rentalTokenAccount: {
value: input.rentalTokenAccount ?? null,
isWritable: true,
},
rentalAuthority: {
value: input.rentalAuthority ?? null,
isWritable: false,
},
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.tokenProgram.value) {
accounts.tokenProgram.value =
'TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.borrower),
getAccountMeta(accounts.borrowerTokenAccount),
getAccountMeta(accounts.rentalThread),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalState),
getAccountMeta(accounts.rentalTokenAccount),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.tokenProgram),
],
programAddress,
data: getCancelRentalInstructionDataEncoder().encode({}),
};
return instruction;
}
export function parseCancelRentalInstruction(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: {
borrower: getNextAccount(),
borrowerTokenAccount: getNextAccount(),
rentalThread: getNextAccount(),
contract: getNextAccount(),
rentalState: getNextAccount(),
rentalTokenAccount: getNextAccount(),
rentalAuthority: getNextAccount(),
tokenProgram: getNextAccount(),
},
data: getCancelRentalInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=cancelRental.js.map