@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
207 lines • 9.29 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 CLAIM_BORROWER_DISCRIMINATOR = new Uint8Array([110, 181, 137, 36, 71, 243, 38, 219]);
export function getClaimBorrowerDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(CLAIM_BORROWER_DISCRIMINATOR);
}
export function getClaimBorrowerInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), value => ({ ...value, discriminator: CLAIM_BORROWER_DISCRIMINATOR }));
}
export function getClaimBorrowerInstructionDataDecoder() {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getClaimBorrowerInstructionDataCodec() {
return combineCodec(getClaimBorrowerInstructionDataEncoder(), getClaimBorrowerInstructionDataDecoder());
}
export async function getClaimBorrowerInstructionAsync(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 },
borrower: { value: input.borrower ?? null, isWritable: true },
borrowerState: { value: input.borrowerState ?? null, isWritable: true },
borrowerManagedTokenAccount: {
value: input.borrowerManagedTokenAccount ?? null,
isWritable: true,
},
destinationTokenAccount: {
value: input.destinationTokenAccount ?? null,
isWritable: true,
},
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
associatedTokenProgram: {
value: input.associatedTokenProgram ?? null,
isWritable: false,
},
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// 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.borrowerState.value) {
accounts.borrowerState.value = await getProgramDerivedAddress({
programAddress,
seeds: [
getBytesEncoder().encode(new Uint8Array([98, 111, 114, 114, 111, 119, 101, 114, 95, 115, 116, 97, 116, 101])),
getAddressEncoder().encode(expectAddress(accounts.borrower.value)),
],
});
}
if (!accounts.borrowerManagedTokenAccount.value) {
accounts.borrowerManagedTokenAccount.value = await getProgramDerivedAddress({
programAddress: 'ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL',
seeds: [
getAddressEncoder().encode(expectAddress(accounts.borrowerState.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.destinationTokenAccount.value) {
accounts.destinationTokenAccount.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,
])),
getAddressEncoder().encode(expectAddress(accounts.mint.value)),
],
});
}
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.borrower),
getAccountMeta(accounts.borrowerState),
getAccountMeta(accounts.borrowerManagedTokenAccount),
getAccountMeta(accounts.destinationTokenAccount),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getClaimBorrowerInstructionDataEncoder().encode({}),
programAddress,
});
}
export function getClaimBorrowerInstruction(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 },
borrower: { value: input.borrower ?? null, isWritable: true },
borrowerState: { value: input.borrowerState ?? null, isWritable: true },
borrowerManagedTokenAccount: {
value: input.borrowerManagedTokenAccount ?? null,
isWritable: true,
},
destinationTokenAccount: {
value: input.destinationTokenAccount ?? null,
isWritable: true,
},
tokenProgram: { value: input.tokenProgram ?? null, isWritable: false },
associatedTokenProgram: {
value: input.associatedTokenProgram ?? null,
isWritable: false,
},
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
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.borrower),
getAccountMeta(accounts.borrowerState),
getAccountMeta(accounts.borrowerManagedTokenAccount),
getAccountMeta(accounts.destinationTokenAccount),
getAccountMeta(accounts.tokenProgram),
getAccountMeta(accounts.associatedTokenProgram),
getAccountMeta(accounts.systemProgram),
],
data: getClaimBorrowerInstructionDataEncoder().encode({}),
programAddress,
});
}
export function parseClaimBorrowerInstruction(instruction) {
if (instruction.accounts.length < 10) {
// 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(),
borrower: getNextAccount(),
borrowerState: getNextAccount(),
borrowerManagedTokenAccount: getNextAccount(),
destinationTokenAccount: getNextAccount(),
tokenProgram: getNextAccount(),
associatedTokenProgram: getNextAccount(),
systemProgram: getNextAccount(),
},
data: getClaimBorrowerInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=claimBorrower.js.map