@robertprp/intents-sdk
Version:
Shogun Network Intent-based cross-chain swaps SDK
53 lines (45 loc) • 2.27 kB
text/typescript
/**
* 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 { type Address } from '@solana/kit';
import { type SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM, type SolanaError } from '@solana/kit';
import { isProgramError } from '@solana/kit';
import { SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS } from '../programs/index.js';
/** InstructionNotFound: Ed25519Program instruction */
export const SOURCE_CHAIN_GUARD_ERROR__INSTRUCTION_NOT_FOUND = 0x1770; // 6000
/** SigVerificationFailed: Signature verification failed */
export const SOURCE_CHAIN_GUARD_ERROR__SIG_VERIFICATION_FAILED = 0x1771; // 6001
/** InvalidSigner: Invalid signer */
export const SOURCE_CHAIN_GUARD_ERROR__INVALID_SIGNER = 0x1772; // 6002
export type SourceChainGuardError =
| typeof SOURCE_CHAIN_GUARD_ERROR__INSTRUCTION_NOT_FOUND
| typeof SOURCE_CHAIN_GUARD_ERROR__INVALID_SIGNER
| typeof SOURCE_CHAIN_GUARD_ERROR__SIG_VERIFICATION_FAILED;
let sourceChainGuardErrorMessages: Record<SourceChainGuardError, string> | undefined;
if (process.env.NODE_ENV !== 'production') {
sourceChainGuardErrorMessages = {
[SOURCE_CHAIN_GUARD_ERROR__INSTRUCTION_NOT_FOUND]: `Ed25519Program instruction`,
[SOURCE_CHAIN_GUARD_ERROR__INVALID_SIGNER]: `Invalid signer`,
[SOURCE_CHAIN_GUARD_ERROR__SIG_VERIFICATION_FAILED]: `Signature verification failed`,
};
}
export function getSourceChainGuardErrorMessage(code: SourceChainGuardError): string {
if (process.env.NODE_ENV !== 'production') {
return (sourceChainGuardErrorMessages as Record<SourceChainGuardError, string>)[code];
}
return 'Error message not available in production bundles.';
}
export function isSourceChainGuardError<TProgramErrorCode extends SourceChainGuardError>(
error: unknown,
transactionMessage: {
instructions: Record<number, { programAddress: Address }>;
},
code?: TProgramErrorCode,
): error is SolanaError<typeof SOLANA_ERROR__INSTRUCTION_ERROR__CUSTOM> &
Readonly<{ context: Readonly<{ code: TProgramErrorCode }> }> {
return isProgramError<TProgramErrorCode>(error, transactionMessage, SOURCE_CHAIN_GUARD_PROGRAM_ADDRESS, code);
}