UNPKG

@robertprp/intents-sdk

Version:

Shogun Network Intent-based cross-chain swaps SDK

125 lines 5.19 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 {} 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 CANCEL_ORDER_DISCRIMINATOR = new Uint8Array([95, 129, 237, 240, 8, 49, 223, 132]); export function getCancelOrderDiscriminatorBytes() { return fixEncoderSize(getBytesEncoder(), 8).encode(CANCEL_ORDER_DISCRIMINATOR); } export function getCancelOrderInstructionDataEncoder() { return transformEncoder(getStructEncoder([['discriminator', fixEncoderSize(getBytesEncoder(), 8)]]), (value) => ({ ...value, discriminator: CANCEL_ORDER_DISCRIMINATOR, })); } export function getCancelOrderInstructionDataDecoder() { return getStructDecoder([['discriminator', fixDecoderSize(getBytesDecoder(), 8)]]); } export function getCancelOrderInstructionDataCodec() { return combineCodec(getCancelOrderInstructionDataEncoder(), getCancelOrderInstructionDataDecoder()); } export function getCancelOrderInstruction(input, config) { // Program address. const programAddress = config?.programAddress ?? SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS; // Original accounts. const originalAccounts = { user: { value: input.user ?? null, isWritable: true }, order: { value: input.order ?? null, isWritable: true }, guard: { value: input.guard ?? null, isWritable: false }, recoveredTokenMint: { value: input.recoveredTokenMint ?? null, isWritable: false, }, userRecoveredTokenAccount: { value: input.userRecoveredTokenAccount ?? null, isWritable: true, }, guardRecoveredTokenAccount: { value: input.guardRecoveredTokenAccount ?? null, isWritable: true, }, recoveredTokenProgram: { value: input.recoveredTokenProgram ?? null, isWritable: false, }, collateralTokenMint: { value: input.collateralTokenMint ?? null, isWritable: false, }, userCollateralTokenAccount: { value: input.userCollateralTokenAccount ?? 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.user), getAccountMeta(accounts.order), getAccountMeta(accounts.guard), getAccountMeta(accounts.recoveredTokenMint), getAccountMeta(accounts.userRecoveredTokenAccount), getAccountMeta(accounts.guardRecoveredTokenAccount), getAccountMeta(accounts.recoveredTokenProgram), getAccountMeta(accounts.collateralTokenMint), getAccountMeta(accounts.userCollateralTokenAccount), getAccountMeta(accounts.guardCollateralTokenAccount), getAccountMeta(accounts.collateralTokenProgram), ], programAddress, data: getCancelOrderInstructionDataEncoder().encode({}), }; return instruction; } export function parseCancelOrderInstruction(instruction) { if (instruction.accounts.length < 11) { // TODO: Coded error. throw new Error('Not enough accounts'); } let accountIndex = 0; const getNextAccount = () => { const accountMeta = instruction.accounts[accountIndex]; accountIndex += 1; return accountMeta; }; const getNextOptionalAccount = () => { const accountMeta = getNextAccount(); return accountMeta.address === SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS ? undefined : accountMeta; }; return { programAddress: instruction.programAddress, accounts: { user: getNextAccount(), order: getNextAccount(), guard: getNextAccount(), recoveredTokenMint: getNextAccount(), userRecoveredTokenAccount: getNextAccount(), guardRecoveredTokenAccount: getNextAccount(), recoveredTokenProgram: getNextAccount(), collateralTokenMint: getNextAccount(), userCollateralTokenAccount: getNextOptionalAccount(), guardCollateralTokenAccount: getNextAccount(), collateralTokenProgram: getNextAccount(), }, data: getCancelOrderInstructionDataDecoder().decode(instruction.data), }; } //# sourceMappingURL=cancelOrder.js.map