@robertprp/intents-sdk
Version:
Shogun Network Intent-based cross-chain swaps SDK
127 lines • 5.42 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 { getProgramDerivedAddress } from '@solana/kit';
import { combineCodec, fixDecoderSize, fixEncoderSize, getBytesDecoder, getBytesEncoder, getStructDecoder, getStructEncoder, transformEncoder, } from '@solana/kit';
import {} from '@solana/kit';
import {} from '@solana/kit';
import { SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS } from '../programs/index.js';
import { getAccountMetaFactory } from '../shared/index.js';
export const INITIALIZE_DISCRIMINATOR = new Uint8Array([175, 175, 109, 31, 13, 152, 155, 237]);
export function getInitializeDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(INITIALIZE_DISCRIMINATOR);
}
export function getInitializeInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({
...value,
discriminator: INITIALIZE_DISCRIMINATOR,
}));
}
export function getInitializeInstructionDataDecoder() {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getInitializeInstructionDataCodec() {
return combineCodec(getInitializeInstructionDataEncoder(), getInitializeInstructionDataDecoder());
}
export async function getInitializeInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
initialAdmin: { value: input.initialAdmin ?? null, isWritable: true },
adminSingleton: { value: input.adminSingleton ?? null, isWritable: true },
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
program: { value: input.program ?? null, isWritable: false },
programData: { value: input.programData ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.adminSingleton.value) {
accounts.adminSingleton.value = await getProgramDerivedAddress({
programAddress,
seeds: [getBytesEncoder().encode(new Uint8Array([97, 100, 109, 105, 110]))],
});
}
if (!accounts.systemProgram.value) {
accounts.systemProgram.value = '11111111111111111111111111111111';
}
if (!accounts.program.value) {
accounts.program.value =
'43cctGU9QJ4WEPzLoNEvo3TPiv6nMUG9puN2pXQSnB6V';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.initialAdmin),
getAccountMeta(accounts.adminSingleton),
getAccountMeta(accounts.systemProgram),
getAccountMeta(accounts.program),
getAccountMeta(accounts.programData),
],
programAddress,
data: getInitializeInstructionDataEncoder().encode({}),
};
return instruction;
}
export function getInitializeInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
initialAdmin: { value: input.initialAdmin ?? null, isWritable: true },
adminSingleton: { value: input.adminSingleton ?? null, isWritable: true },
systemProgram: { value: input.systemProgram ?? null, isWritable: false },
program: { value: input.program ?? null, isWritable: false },
programData: { value: input.programData ?? null, isWritable: false },
};
const accounts = originalAccounts;
// Resolve default values.
if (!accounts.systemProgram.value) {
accounts.systemProgram.value = '11111111111111111111111111111111';
}
if (!accounts.program.value) {
accounts.program.value =
'43cctGU9QJ4WEPzLoNEvo3TPiv6nMUG9puN2pXQSnB6V';
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [
getAccountMeta(accounts.initialAdmin),
getAccountMeta(accounts.adminSingleton),
getAccountMeta(accounts.systemProgram),
getAccountMeta(accounts.program),
getAccountMeta(accounts.programData),
],
programAddress,
data: getInitializeInstructionDataEncoder().encode({}),
};
return instruction;
}
export function parseInitializeInstruction(instruction) {
if (instruction.accounts.length < 5) {
// 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: {
initialAdmin: getNextAccount(),
adminSingleton: getNextAccount(),
systemProgram: getNextAccount(),
program: getNextAccount(),
programData: getNextAccount(),
},
data: getInitializeInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=initialize.js.map