UNPKG

@robertprp/intents-sdk

Version:

Shogun Network Intent-based cross-chain swaps SDK

98 lines 4.09 kB
/** * 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 { getAddressDecoder, getAddressEncoder, 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 SET_ADMIN_DISCRIMINATOR = new Uint8Array([251, 163, 0, 52, 91, 194, 187, 92]); export function getSetAdminDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(SET_ADMIN_DISCRIMINATOR); } export function getSetAdminInstructionDataEncoder() { return transformEncoder(getStructEncoder([ ['discriminator', fixEncoderSize(getBytesEncoder(), 8)], ['newAdmin', getAddressEncoder()], ]), (value) => ({ ...value, discriminator: SET_ADMIN_DISCRIMINATOR })); } export function getSetAdminInstructionDataDecoder() { return getStructDecoder([ ['discriminator', fixDecoderSize(getBytesDecoder(), 8)], ['newAdmin', getAddressDecoder()], ]); } export function getSetAdminInstructionDataCodec() { return combineCodec(getSetAdminInstructionDataEncoder(), getSetAdminInstructionDataDecoder()); } export async function getSetAdminInstructionAsync(input, config) { // Program address. const programAddress = config?.programAddress ?? SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: true }, adminSingleton: { value: input.adminSingleton ?? null, isWritable: true }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; // 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.admin), getAccountMeta(accounts.adminSingleton)], programAddress, data: getSetAdminInstructionDataEncoder().encode(args), }; return instruction; } export function getSetAdminInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SINGLE_CHAIN_GUARD_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { admin: { value: input.admin ?? null, isWritable: true }, adminSingleton: { value: input.adminSingleton ?? null, isWritable: true }, }; const accounts = originalAccounts; // Original args. const args = { ...input }; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [getAccountMeta(accounts.admin), getAccountMeta(accounts.adminSingleton)], programAddress, data: getSetAdminInstructionDataEncoder().encode(args), }; return instruction; } export function parseSetAdminInstruction(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: { admin: getNextAccount(), adminSingleton: getNextAccount(), }, data: getSetAdminInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=setAdmin.js.map