@wuwei-labs/srsly
Version:
TypeScript SDK for SRSLY
65 lines • 2.88 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, getAddressDecoder, getAddressEncoder, getBytesDecoder, getBytesEncoder, getOptionDecoder, getOptionEncoder, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
import { SRSLY_PROGRAM_ADDRESS } from '../programs';
import { getAccountMetaFactory } from '../shared';
export const SET_DELEGATE_DISCRIMINATOR = new Uint8Array([242, 30, 46, 76, 108, 235, 128, 181]);
export function getSetDelegateDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(SET_DELEGATE_DISCRIMINATOR);
}
export function getSetDelegateInstructionDataEncoder() {
return transformEncoder(getStructEncoder([
['discriminator', fixEncoderSize(getBytesEncoder(), 8)],
['delegate', getOptionEncoder(getAddressEncoder())],
]), value => ({ ...value, discriminator: SET_DELEGATE_DISCRIMINATOR }));
}
export function getSetDelegateInstructionDataDecoder() {
return getStructDecoder([
['discriminator', fixDecoderSize(getBytesDecoder(), 8)],
['delegate', getOptionDecoder(getAddressDecoder())],
]);
}
export function getSetDelegateInstructionDataCodec() {
return combineCodec(getSetDelegateInstructionDataEncoder(), getSetDelegateInstructionDataDecoder());
}
export function getSetDelegateInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SRSLY_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
owner: { value: input.owner ?? null, isWritable: true },
contract: { value: input.contract ?? null, isWritable: true },
};
const accounts = originalAccounts;
// Original args.
const args = { ...input };
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
return Object.freeze({
accounts: [getAccountMeta(accounts.owner), getAccountMeta(accounts.contract)],
data: getSetDelegateInstructionDataEncoder().encode(args),
programAddress,
});
}
export function parseSetDelegateInstruction(instruction) {
if (instruction.accounts.length < 2) {
// 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: { owner: getNextAccount(), contract: getNextAccount() },
data: getSetDelegateInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=setDelegate.js.map