@robertprp/intents-sdk
Version:
Shogun Network Intent-based cross-chain swaps SDK
91 lines • 3.94 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 { SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS } from '../programs/index.js';
import { getAccountMetaFactory } from '../shared/index.js';
export const ACCEPT_ADMIN_DISCRIMINATOR = new Uint8Array([112, 42, 45, 90, 116, 181, 13, 170]);
export function getAcceptAdminDiscriminatorBytes() {
return fixEncoderSize(getBytesEncoder(), 8).encode(ACCEPT_ADMIN_DISCRIMINATOR);
}
export function getAcceptAdminInstructionDataEncoder() {
return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({
...value,
discriminator: ACCEPT_ADMIN_DISCRIMINATOR,
}));
}
export function getAcceptAdminInstructionDataDecoder() {
return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]);
}
export function getAcceptAdminInstructionDataCodec() {
return combineCodec(getAcceptAdminInstructionDataEncoder(), getAcceptAdminInstructionDataDecoder());
}
export async function getAcceptAdminInstructionAsync(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
pendingAdmin: { value: input.pendingAdmin ?? null, isWritable: true },
adminSingleton: { value: input.adminSingleton ?? null, isWritable: true },
};
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]))],
});
}
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [getAccountMeta(accounts.pendingAdmin), getAccountMeta(accounts.adminSingleton)],
programAddress,
data: getAcceptAdminInstructionDataEncoder().encode({}),
};
return instruction;
}
export function getAcceptAdminInstruction(input, config) {
// Program address.
const programAddress = config?.programAddress ?? SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS;
// Original accounts.
const originalAccounts = {
pendingAdmin: { value: input.pendingAdmin ?? null, isWritable: true },
adminSingleton: { value: input.adminSingleton ?? null, isWritable: true },
};
const accounts = originalAccounts;
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
const instruction = {
accounts: [getAccountMeta(accounts.pendingAdmin), getAccountMeta(accounts.adminSingleton)],
programAddress,
data: getAcceptAdminInstructionDataEncoder().encode({}),
};
return instruction;
}
export function parseAcceptAdminInstruction(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: {
pendingAdmin: getNextAccount(),
adminSingleton: getNextAccount(),
},
data: getAcceptAdminInstructionDataDecoder().decode(instruction.data),
};
}
//# sourceMappingURL=acceptAdmin.js.map