@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
226 lines • 9.63 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, getBytesDecoder, getBytesEncoder, getProgramDerivedAddress, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, transformEncoder, } from '@solana/kit';
import { SRSLY_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory } from '../shared';
export const CREATE_CONFIG_DISCRIMINATOR = new Uint8Array([201, 207, 243, 114, 75, 111, 47, 189]);
export function getCreateConfigDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(CREATE_CONFIG_DISCRIMINATOR);
}
export function getCreateConfigInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['recentSlot', getU64Encoder()],
]), value => ({ ...value, discriminator: CREATE_CONFIG_DISCRIMINATOR }));
}
export function getCreateConfigInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['recentSlot', getU64Decoder()],
]);
}
export function getCreateConfigInstructionDataCodec() {
return combineCodec(getCreateConfigInstructionDataEncoder(), getCreateConfigInstructionDataDecoder());
}
export async function getCreateConfigInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
authority: { value: input.authority ?? null, isWritable: true },
config: { value: input.config ?? null, isWritable: true },
mint: { value: input.mint ?? null, isWritable: false },
vault: { value: input.vault ?? null, isWritable: true },
vaultTokenAccount: {
value: input.vaultTokenAccount ?? null,
isWritable: true,
},
lookupTable: { value: input.lookupTable ?? null, isWritable: true },
sageProgram: { value: input.sageProgram ?? null, isWritable: false },
antegenProgram: { value: input.antegenProgram ?? null, isWritable: false },
altProgram: { value: input.altProgram ?? null, isWritable: false },
srslyProgram: { value: input.srslyProgram ?? null, isWritable: false },
slyvaultProgram: {
value: input.slyvaultProgram ?? 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.altProgram.value) {
accounts.altProgram.value =
'AddressLookupTab1e1111111111111111111111111';
}
if (!accounts.srslyProgram.value) {
accounts.srslyProgram.value =
'SRSLYxcFnjd5jG2DpJw4as6UEyjwJQK1U4J1TD1hvZH';
}
if (!accounts.slyvaultProgram.value) {
accounts.slyvaultProgram.value =
'VLTukwau1TDGhQUgBJfSSojSMv3BfnMHKrewnGN98M3';
}
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.authority),
getAccountMeta(accounts.config),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.vault),
getAccountMeta(accounts.vaultTokenAccount),
getAccountMeta(accounts.lookupTable),
getAccountMeta(accounts.sageProgram),
getAccountMeta(accounts.antegenProgram),
getAccountMeta(accounts.altProgram),
getAccountMeta(accounts.srslyProgram),
getAccountMeta(accounts.slyvaultProgram),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getCreateConfigInstructionDataEncoder().encode(args),
programAddress,
});
}
export function getCreateConfigInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
authority: { value: input.authority ?? null, isWritable: true },
config: { value: input.config ?? null, isWritable: true },
mint: { value: input.mint ?? null, isWritable: false },
vault: { value: input.vault ?? null, isWritable: true },
vaultTokenAccount: {
value: input.vaultTokenAccount ?? null,
isWritable: true,
},
lookupTable: { value: input.lookupTable ?? null, isWritable: true },
sageProgram: { value: input.sageProgram ?? null, isWritable: false },
antegenProgram: { value: input.antegenProgram ?? null, isWritable: false },
altProgram: { value: input.altProgram ?? null, isWritable: false },
srslyProgram: { value: input.srslyProgram ?? null, isWritable: false },
slyvaultProgram: {
value: input.slyvaultProgram ?? 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.altProgram.value) {
accounts.altProgram.value =
'AddressLookupTab1e1111111111111111111111111';
}
if (!accounts.srslyProgram.value) {
accounts.srslyProgram.value =
'SRSLYxcFnjd5jG2DpJw4as6UEyjwJQK1U4J1TD1hvZH';
}
if (!accounts.slyvaultProgram.value) {
accounts.slyvaultProgram.value =
'VLTukwau1TDGhQUgBJfSSojSMv3BfnMHKrewnGN98M3';
}
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.authority),
getAccountMeta(accounts.config),
getAccountMeta(accounts.mint),
getAccountMeta(accounts.vault),
getAccountMeta(accounts.vaultTokenAccount),
getAccountMeta(accounts.lookupTable),
getAccountMeta(accounts.sageProgram),
getAccountMeta(accounts.antegenProgram),
getAccountMeta(accounts.altProgram),
getAccountMeta(accounts.srslyProgram),
getAccountMeta(accounts.slyvaultProgram),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getCreateConfigInstructionDataEncoder().encode(args),
programAddress,
});
}
export function parseCreateConfigInstruction(instruction) {
if (instruction.accounts.length < 14) {
// 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: {
authority: getNextAccount(),
config: getNextAccount(),
mint: getNextAccount(),
vault: getNextAccount(),
vaultTokenAccount: getNextAccount(),
lookupTable: getNextAccount(),
sageProgram: getNextAccount(),
antegenProgram: getNextAccount(),
altProgram: getNextAccount(),
srslyProgram: getNextAccount(),
slyvaultProgram: getNextAccount(),
tokenProgram: getNextAccount(),
associatedTokenProgram: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getCreateConfigInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=createConfig.js.map