@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
299 lines • 13.4 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 { addDecoderSizePrefix, addEncoderSizePrefix, combineCodec, fixDecoderSize, fixEncoderSize, getAddressEncoder, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU32Decoder, getU32Encoder, getU64Decoder, getU64Encoder, getUtf8Decoder, getUtf8Encoder, transformEncoder, } from '@solana/kit';
import { SRSLY_PROGRAM_ADDRESS } from '../programs';
import { expectAddress, getAccountMetaFactory } from '../shared';
export const CREATE_CONTRACT_THREAD_DISCRIMINATOR = new Uint8Array([
233, 57, 214, 37, 246, 233, 143, 139,
]);
export function getCreateContractThreadDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(CREATE_CONTRACT_THREAD_DISCRIMINATOR);
}
export function getCreateContractThreadInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['lamports', getU64Encoder()],
['paymentsFreq', addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())],
]), value => ({
...value,
discriminator: CREATE_CONTRACT_THREAD_DISCRIMINATOR,
}));
}
export function getCreateContractThreadInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['lamports', getU64Decoder()],
['paymentsFreq', addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())],
]);
}
export function getCreateContractThreadInstructionDataCodec() {
return combineCodec(getCreateContractThreadInstructionDataEncoder(), getCreateContractThreadInstructionDataDecoder());
}
export async function getCreateContractThreadInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
payer: { value: input.payer ?? null, isWritable: true },
config: { value: input.config ?? null, isWritable: false },
mint: { value: input.mint ?? null, isWritable: false },
contract: { value: input.contract ?? null, isWritable: true },
rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: true },
contractThread: { value: input.contractThread ?? null, isWritable: true },
fiber0: { value: input.fiber0 ?? null, isWritable: true },
closeRentalFiber: {
value: input.closeRentalFiber ?? null,
isWritable: true,
},
owner: { value: input.owner ?? null, isWritable: false },
contractTokenAccount: {
value: input.contractTokenAccount ?? null,
isWritable: true,
},
ownerTokenAccount: {
value: input.ownerTokenAccount ?? null,
isWritable: true,
},
activeRental: { value: input.activeRental ?? null, isWritable: false },
queuedRental: { value: input.queuedRental ?? null, isWritable: false },
sageProgram: { value: input.sageProgram ?? null, isWritable: false },
antegenProgram: { value: input.antegenProgram ?? null, isWritable: false },
fiberProgram: { value: input.fiberProgram ?? 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 getProgramDerivedAddress({
programAddress,
seeds: [getBytesEncoder().encode(new Uint8Array([99, 111, 110, 102, 105, 103]))],
});
}
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.ownerTokenAccount.value) {
accounts.ownerTokenAccount.value = await getProgramDerivedAddress({
programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
seeds: [
getAddressEncoder().encode(expectAddress(accounts.owner.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,
])),
getAddressEncoder().encode(expectAddress(accounts.mint.value)),
],
});
}
if (!accounts.activeRental.value) {
accounts.activeRental.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)),
getBytesEncoder().encode(new Uint8Array([97, 99, 116, 105, 118, 101])),
],
});
}
if (!accounts.queuedRental.value) {
accounts.queuedRental.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)),
getBytesEncoder().encode(new Uint8Array([113, 117, 101, 117, 101, 100])),
],
});
}
if (!accounts.antegenProgram.value) {
accounts.antegenProgram.value =
'AgTv5w1UvUb6zeqkThwMrztGu9hpepBu8YLghuR4dpSx';
}
if (!accounts.fiberProgram.value) {
accounts.fiberProgram.value =
'AgFv5afjW9DmSPkiEvJ1er5bAAmRUqaBeTB6Cr8e1hKx';
}
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 = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.payer),
getAccountMeta(accounts.config),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.contractThread),
getAccountMeta(accounts.fiber0),
getAccountMeta(accounts.closeRentalFiber),
getAccountMeta(accounts.owner),
getAccountMeta(accounts.contractTokenAccount),
getAccountMeta(accounts.ownerTokenAccount),
getAccountMeta(accounts.activeRental),
getAccountMeta(accounts.queuedRental),
getAccountMeta(accounts.sageProgram),
getAccountMeta(accounts.antegenProgram),
getAccountMeta(accounts.fiberProgram),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getCreateContractThreadInstructionDataEncoder().encode(args),
programAddress,
});
}
export function getCreateContractThreadInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
payer: { value: input.payer ?? null, isWritable: true },
config: { value: input.config ?? null, isWritable: false },
mint: { value: input.mint ?? null, isWritable: false },
contract: { value: input.contract ?? null, isWritable: true },
rentalAuthority: { value: input.rentalAuthority ?? null, isWritable: true },
contractThread: { value: input.contractThread ?? null, isWritable: true },
fiber0: { value: input.fiber0 ?? null, isWritable: true },
closeRentalFiber: {
value: input.closeRentalFiber ?? null,
isWritable: true,
},
owner: { value: input.owner ?? null, isWritable: false },
contractTokenAccount: {
value: input.contractTokenAccount ?? null,
isWritable: true,
},
ownerTokenAccount: {
value: input.ownerTokenAccount ?? null,
isWritable: true,
},
activeRental: { value: input.activeRental ?? null, isWritable: false },
queuedRental: { value: input.queuedRental ?? null, isWritable: false },
sageProgram: { value: input.sageProgram ?? null, isWritable: false },
antegenProgram: { value: input.antegenProgram ?? null, isWritable: false },
fiberProgram: { value: input.fiberProgram ?? 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.fiberProgram.value) {
accounts.fiberProgram.value =
'AgFv5afjW9DmSPkiEvJ1er5bAAmRUqaBeTB6Cr8e1hKx';
}
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 = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [
getAccountMeta(accounts.payer),
getAccountMeta(accounts.config),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.contract),
getAccountMeta(accounts.rentalAuthority),
getAccountMeta(accounts.contractThread),
getAccountMeta(accounts.fiber0),
getAccountMeta(accounts.closeRentalFiber),
getAccountMeta(accounts.owner),
getAccountMeta(accounts.contractTokenAccount),
getAccountMeta(accounts.ownerTokenAccount),
getAccountMeta(accounts.activeRental),
getAccountMeta(accounts.queuedRental),
getAccountMeta(accounts.sageProgram),
getAccountMeta(accounts.antegenProgram),
getAccountMeta(accounts.fiberProgram),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getCreateContractThreadInstructionDataEncoder().encode(args),
programAddress,
});
}
export function parseCreateContractThreadInstruction(instruction) {
if (instruction.accounts.length < 19) {
// 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: {
payer: getNextAccount(),
config: getNextAccount(),
mint: getNextAccount(),
contract: getNextAccount(),
rentalAuthority: getNextAccount(),
contractThread: getNextAccount(),
fiber0: getNextAccount(),
closeRentalFiber: getNextAccount(),
owner: getNextAccount(),
contractTokenAccount: getNextAccount(),
ownerTokenAccount: getNextAccount(),
activeRental: getNextAccount(),
queuedRental: getNextAccount(),
sageProgram: getNextAccount(),
antegenProgram: getNextAccount(),
fiberProgram: getNextAccount(),
tokenProgram: getNextAccount(),
associatedTokenProgram: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getCreateContractThreadInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=createContractThread.js.map