UNPKG

@robertprp/intents-sdk

Version:

Shogun Network Intent-based cross-chain swaps SDK

140 lines 5.9 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 { 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 COLLECT_PROTOCOL_FEES_DISCRIMINATOR = new Uint8Array([22, 67, 23, 98, 150, 178, 70, 220]); export function getCollectProtocolFeesDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(COLLECT_PROTOCOL_FEES_DISCRIMINATOR); } export function getCollectProtocolFeesInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: COLLECT_PROTOCOL_FEES_DISCRIMINATOR, })); } export function getCollectProtocolFeesInstructionDataDecoder() { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getCollectProtocolFeesInstructionDataCodec() { return combineCodec(getCollectProtocolFeesInstructionDataEncoder(), getCollectProtocolFeesInstructionDataDecoder()); } export async function getCollectProtocolFeesInstructionAsync(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: false }, guard: { value: input.guard ?? null, isWritable: true }, feeTokenMint: { value: input.feeTokenMint ?? null, isWritable: false }, adminFeeTokenAccount: { value: input.adminFeeTokenAccount ?? null, isWritable: true, }, guardFeeTokenAccount: { value: input.guardFeeTokenAccount ?? null, isWritable: true, }, feeTokenProgram: { value: input.feeTokenProgram ?? 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]))], }); } const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.admin), getAccountMeta(accounts.adminSingleton), getAccountMeta(accounts.guard), getAccountMeta(accounts.feeTokenMint), getAccountMeta(accounts.adminFeeTokenAccount), getAccountMeta(accounts.guardFeeTokenAccount), getAccountMeta(accounts.feeTokenProgram), ], programAddress, data: getCollectProtocolFeesInstructionDataEncoder().encode({}), }; return instruction; } export function getCollectProtocolFeesInstruction(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: false }, guard: { value: input.guard ?? null, isWritable: true }, feeTokenMint: { value: input.feeTokenMint ?? null, isWritable: false }, adminFeeTokenAccount: { value: input.adminFeeTokenAccount ?? null, isWritable: true, }, guardFeeTokenAccount: { value: input.guardFeeTokenAccount ?? null, isWritable: true, }, feeTokenProgram: { value: input.feeTokenProgram ?? null, isWritable: false, }, }; const accounts = originalAccounts; const getAccountMeta = getAccountMetaFactory(programAddress, 'programId'); const instruction = { accounts: [ getAccountMeta(accounts.admin), getAccountMeta(accounts.adminSingleton), getAccountMeta(accounts.guard), getAccountMeta(accounts.feeTokenMint), getAccountMeta(accounts.adminFeeTokenAccount), getAccountMeta(accounts.guardFeeTokenAccount), getAccountMeta(accounts.feeTokenProgram), ], programAddress, data: getCollectProtocolFeesInstructionDataEncoder().encode({}), }; return instruction; } export function parseCollectProtocolFeesInstruction(instruction) { if (instruction.accounts.length < 7) { // 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(), guard: getNextAccount(), feeTokenMint: getNextAccount(), adminFeeTokenAccount: getNextAccount(), guardFeeTokenAccount: getNextAccount(), feeTokenProgram: getNextAccount(), }, data: getCollectProtocolFeesInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=collectProtocolFees.js.map