@solana-developers/helpers
Version:
Solana helper functions
128 lines • 3.07 kB
TypeScript
/**
* This is a port of the anchor command `anchor idl convert` to TypeScript.
*/
import { Idl } from "@coral-xyz/anchor";
export interface LegacyIdl {
version: string;
name: string;
docs?: string[];
constants: LegacyIdlConst[];
instructions: LegacyIdlInstruction[];
accounts: LegacyIdlTypeDefinition[];
types: LegacyIdlTypeDefinition[];
events?: LegacyIdlEvent[];
errors?: LegacyIdlErrorCode[];
metadata?: any;
}
interface LegacyIdlConst {
name: string;
type: LegacyIdlType;
value: string;
}
interface LegacyIdlInstruction {
name: string;
docs?: string[];
accounts: LegacyIdlAccountItem[];
args: LegacyIdlField[];
returns?: LegacyIdlType;
}
interface LegacyIdlTypeDefinition {
name: string;
docs?: string[];
type: LegacyIdlTypeDefinitionTy;
}
type LegacyIdlTypeDefinitionTy = {
kind: "struct";
fields: LegacyIdlField[];
} | {
kind: "enum";
variants: LegacyIdlEnumVariant[];
} | {
kind: "alias";
value: LegacyIdlType;
};
interface LegacyIdlField {
name: string;
docs?: string[];
type: LegacyIdlType;
}
interface LegacyIdlEnumVariant {
name: string;
fields?: LegacyEnumFields;
}
type LegacyEnumFields = LegacyIdlField[] | LegacyIdlType[];
interface LegacyIdlEvent {
name: string;
fields: LegacyIdlEventField[];
}
interface LegacyIdlEventField {
name: string;
type: LegacyIdlType;
index: boolean;
}
interface LegacyIdlErrorCode {
code: number;
name: string;
msg?: string;
}
type LegacyIdlAccountItem = LegacyIdlAccount | LegacyIdlAccounts;
interface LegacyIdlAccount {
name: string;
isMut: boolean;
isSigner: boolean;
isOptional?: boolean;
docs?: string[];
pda?: LegacyIdlPda;
relations: string[];
}
interface LegacyIdlAccounts {
name: string;
accounts: LegacyIdlAccountItem[];
}
interface LegacyIdlPda {
seeds: LegacyIdlSeed[];
programId?: LegacyIdlSeed;
}
type LegacyIdlSeed = {
kind: "const";
type: LegacyIdlType;
value: any;
} | {
kind: "arg";
type: LegacyIdlType;
path: string;
} | {
kind: "account";
type: LegacyIdlType;
account?: string;
path: string;
};
type LegacyIdlType = "bool" | "u8" | "i8" | "u16" | "i16" | "u32" | "i32" | "u64" | "i64" | "u128" | "i128" | "f32" | "f64" | "bytes" | "string" | "publicKey" | {
vec: LegacyIdlType;
} | {
option: LegacyIdlType;
} | {
defined: string;
} | {
array: [LegacyIdlType, number];
} | {
generic: string;
} | {
definedWithTypeArgs: {
name: string;
args: LegacyIdlDefinedTypeArg[];
};
};
type LegacyIdlDefinedTypeArg = {
generic: string;
} | {
value: string;
} | {
type: LegacyIdlType;
};
export declare function convertLegacyIdl(legacyIdl: LegacyIdl, programAddress?: string): Idl;
export declare function getIdlSpecType(idl: any): IdlSpec;
export type IdlSpec = "0.1.0" | "legacy";
export declare function formatIdl(idl: any, programAddress?: string): Idl;
export {};
//# sourceMappingURL=convertLegacyIdl.d.ts.map