UNPKG

@robertprp/intents-sdk

Version:

Shogun Network Intent-based cross-chain swaps SDK

146 lines 6.16 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 { SOURCE_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 ?? SOURCE_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 }, collateralTokenMint: { value: input.collateralTokenMint ?? null, isWritable: false, }, adminCollateralTokenAccount: { value: input.adminCollateralTokenAccount ?? null, isWritable: true, }, guardCollateralTokenAccount: { value: input.guardCollateralTokenAccount ?? null, isWritable: true, }, collateralTokenProgram: { value: input.collateralTokenProgram ?? 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.collateralTokenMint), getAccountMeta(accounts.adminCollateralTokenAccount), getAccountMeta(accounts.guardCollateralTokenAccount), getAccountMeta(accounts.collateralTokenProgram), ], programAddress, data: getCollectProtocolFeesInstructionDataEncoder().encode({}), }; return instruction; } export function getCollectProtocolFeesInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SOURCE_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 }, collateralTokenMint: { value: input.collateralTokenMint ?? null, isWritable: false, }, adminCollateralTokenAccount: { value: input.adminCollateralTokenAccount ?? null, isWritable: true, }, guardCollateralTokenAccount: { value: input.guardCollateralTokenAccount ?? null, isWritable: true, }, collateralTokenProgram: { value: input.collateralTokenProgram ?? 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.collateralTokenMint), getAccountMeta(accounts.adminCollateralTokenAccount), getAccountMeta(accounts.guardCollateralTokenAccount), getAccountMeta(accounts.collateralTokenProgram), ], 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(), collateralTokenMint: getNextAccount(), adminCollateralTokenAccount: getNextAccount(), guardCollateralTokenAccount: getNextAccount(), collateralTokenProgram: getNextAccount(), }, data: getCollectProtocolFeesInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=collectProtocolFees.js.map