diff --git a/.changeset/strange-buses-smell.md b/.changeset/strange-buses-smell.md new file mode 100644 index 0000000000..ea073f4ccc --- /dev/null +++ b/.changeset/strange-buses-smell.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/abi-typegen": patch +--- + +chore: mimic `JsonAbi` interface from `abi-coder` in `abi-typegen` diff --git a/packages/abi-typegen/src/abi/Abi.test.ts b/packages/abi-typegen/src/abi/Abi.test.ts index 7fc76c5f5e..ec48cd4250 100644 --- a/packages/abi-typegen/src/abi/Abi.test.ts +++ b/packages/abi-typegen/src/abi/Abi.test.ts @@ -5,7 +5,7 @@ import { getTypegenForcProject, } from '../../test/fixtures/forc-projects/index'; import { ProgramTypeEnum } from '../types/enums/ProgramTypeEnum'; -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; +import type { JsonAbiType } from '../types/interfaces/JsonAbi'; import * as parseConfigurablesMod from '../utils/parseConfigurables'; import * as parseFunctionsMod from '../utils/parseFunctions'; import * as parseTypesMod from '../utils/parseTypes'; @@ -63,7 +63,7 @@ describe('Abi.ts', () => { } function getRawTypeFor(params: { type: string }) { - const rawAbiType: IRawAbiTypeRoot = { + const rawAbiType: JsonAbiType = { typeId: 1, type: params.type, components: null, diff --git a/packages/abi-typegen/src/abi/Abi.ts b/packages/abi-typegen/src/abi/Abi.ts index 84a8a29e9f..179654d2a4 100644 --- a/packages/abi-typegen/src/abi/Abi.ts +++ b/packages/abi-typegen/src/abi/Abi.ts @@ -4,8 +4,8 @@ import { normalizeString } from '@fuel-ts/utils'; import type { ProgramTypeEnum } from '../types/enums/ProgramTypeEnum'; import type { IConfigurable } from '../types/interfaces/IConfigurable'; import type { IFunction } from '../types/interfaces/IFunction'; -import type { IRawAbi } from '../types/interfaces/IRawAbi'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbi } from '../types/interfaces/JsonAbi'; import { parseConfigurables } from '../utils/parseConfigurables'; import { parseFunctions } from '../utils/parseFunctions'; import { parseTypes } from '../utils/parseTypes'; @@ -22,7 +22,7 @@ export class Abi { public commonTypesInUse: string[] = []; - public rawContents: IRawAbi; + public rawContents: JsonAbi; public hexlifiedBinContents?: string; public storageSlotsContents?: string; @@ -33,7 +33,7 @@ export class Abi { constructor(params: { filepath: string; programType: ProgramTypeEnum; - rawContents: IRawAbi; + rawContents: JsonAbi; hexlifiedBinContents?: string; storageSlotsContents?: string; outputDir: string; diff --git a/packages/abi-typegen/src/abi/configurable/Configurable.test.ts b/packages/abi-typegen/src/abi/configurable/Configurable.test.ts index 3122d5263f..db66630325 100644 --- a/packages/abi-typegen/src/abi/configurable/Configurable.test.ts +++ b/packages/abi-typegen/src/abi/configurable/Configurable.test.ts @@ -2,8 +2,8 @@ import { AbiTypegenProjectsEnum, getTypegenForcProject, } from '../../../test/fixtures/forc-projects/index'; -import type { IRawAbiTypeRoot } from '../../types/interfaces/IRawAbiType'; import type { IType } from '../../types/interfaces/IType'; +import type { JsonAbiType } from '../../types/interfaces/JsonAbi'; import * as findTypeMod from '../../utils/findType'; import { Configurable } from './Configurable'; @@ -13,7 +13,7 @@ import { Configurable } from './Configurable'; */ describe('Configurable.ts', () => { function mockAllDeps() { - const rawAbiType: IRawAbiTypeRoot = { + const rawAbiType: JsonAbiType = { typeId: 1, type: 'mockType', components: null, diff --git a/packages/abi-typegen/src/abi/configurable/Configurable.ts b/packages/abi-typegen/src/abi/configurable/Configurable.ts index 8df4057776..fdd1fab7c7 100644 --- a/packages/abi-typegen/src/abi/configurable/Configurable.ts +++ b/packages/abi-typegen/src/abi/configurable/Configurable.ts @@ -1,14 +1,14 @@ import type { IConfigurable } from '../../types/interfaces/IConfigurable'; -import type { IRawAbiConfigurable } from '../../types/interfaces/IRawAbiConfigurable'; import type { IType } from '../../types/interfaces/IType'; +import type { JsonAbiConfigurable } from '../../types/interfaces/JsonAbi'; import { findType } from '../../utils/findType'; export class Configurable implements IConfigurable { public name: string; public type: IType; - public rawAbiConfigurable: IRawAbiConfigurable; + public rawAbiConfigurable: JsonAbiConfigurable; - constructor(params: { types: IType[]; rawAbiConfigurable: IRawAbiConfigurable }) { + constructor(params: { types: IType[]; rawAbiConfigurable: JsonAbiConfigurable }) { const { types, rawAbiConfigurable } = params; this.name = rawAbiConfigurable.name; diff --git a/packages/abi-typegen/src/abi/functions/Function.ts b/packages/abi-typegen/src/abi/functions/Function.ts index e479d31ff1..f898e15062 100644 --- a/packages/abi-typegen/src/abi/functions/Function.ts +++ b/packages/abi-typegen/src/abi/functions/Function.ts @@ -1,4 +1,4 @@ -import type { IFunction, IRawAbiFunction, IFunctionAttributes } from '../../index'; +import type { IFunction, JsonAbiFunction, IFunctionAttributes } from '../../index'; import { TargetEnum } from '../../types/enums/TargetEnum'; import type { IType } from '../../types/interfaces/IType'; import { findType } from '../../utils/findType'; @@ -8,10 +8,10 @@ import { EmptyType } from '../types/EmptyType'; export class Function implements IFunction { public name: string; public types: IType[]; - public rawAbiFunction: IRawAbiFunction; + public rawAbiFunction: JsonAbiFunction; public attributes: IFunctionAttributes; - constructor(params: { types: IType[]; rawAbiFunction: IRawAbiFunction }) { + constructor(params: { types: IType[]; rawAbiFunction: JsonAbiFunction }) { this.rawAbiFunction = params.rawAbiFunction; this.types = params.types; this.name = params.rawAbiFunction.name; diff --git a/packages/abi-typegen/src/abi/types/AType.ts b/packages/abi-typegen/src/abi/types/AType.ts index ebdf434aa0..94f3b0ecaf 100644 --- a/packages/abi-typegen/src/abi/types/AType.ts +++ b/packages/abi-typegen/src/abi/types/AType.ts @@ -1,12 +1,12 @@ -import type { IRawAbiTypeRoot } from '../../types/interfaces/IRawAbiType'; import type { ITypeAttributes } from '../../types/interfaces/IType'; +import type { JsonAbiType } from '../../types/interfaces/JsonAbi'; export class AType { - public rawAbiType: IRawAbiTypeRoot; + public rawAbiType: JsonAbiType; public attributes: ITypeAttributes; public requiredFuelsMembersImports: string[]; - constructor(params: { rawAbiType: IRawAbiTypeRoot }) { + constructor(params: { rawAbiType: JsonAbiType }) { this.rawAbiType = params.rawAbiType; this.attributes = { inputLabel: 'unknown', diff --git a/packages/abi-typegen/src/abi/types/ArrayType.test.ts b/packages/abi-typegen/src/abi/types/ArrayType.test.ts index aac57706da..3516400f4d 100644 --- a/packages/abi-typegen/src/abi/types/ArrayType.test.ts +++ b/packages/abi-typegen/src/abi/types/ArrayType.test.ts @@ -2,7 +2,7 @@ import { AbiTypegenProjectsEnum, getTypegenForcProject, } from '../../../test/fixtures/forc-projects'; -import type { IRawAbiTypeRoot } from '../../types/interfaces/IRawAbiType'; +import type { JsonAbiType } from '../../types/interfaces/JsonAbi'; import { findType } from '../../utils/findType'; import { makeType } from '../../utils/makeType'; import * as parseTypeArgumentsMod from '../../utils/parseTypeArguments'; @@ -32,7 +32,7 @@ describe('ArrayType.ts', () => { const project = getTypegenForcProject(AbiTypegenProjectsEnum.STRUCT_WITH_ARRAY); const rawTypes = project.abiContents.types; - const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType })); + const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType })); // validating `struct B`, with simple tuples on property `x` const b = findType({ types, typeId: 0 }) as ArrayType; @@ -50,7 +50,7 @@ describe('ArrayType.ts', () => { const project = getTypegenForcProject(AbiTypegenProjectsEnum.ARRAY_WITH_GENERICS); const rawTypes = project.abiContents.types; - const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType })); + const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType })); const a = findType({ types, typeId: 1 }) as ArrayType; diff --git a/packages/abi-typegen/src/abi/types/EmptyType.ts b/packages/abi-typegen/src/abi/types/EmptyType.ts index 29ef9a97b5..346dde2bb8 100644 --- a/packages/abi-typegen/src/abi/types/EmptyType.ts +++ b/packages/abi-typegen/src/abi/types/EmptyType.ts @@ -1,4 +1,4 @@ -import type { IRawAbiTypeRoot } from '../..'; +import type { JsonAbiType } from '../..'; import type { IType } from '../../types/interfaces/IType'; import { AType } from './AType'; @@ -10,7 +10,7 @@ export class EmptyType extends AType implements IType { static MATCH_REGEX: RegExp = /^\(\)$/m; - constructor(params: { rawAbiType: IRawAbiTypeRoot }) { + constructor(params: { rawAbiType: JsonAbiType }) { super(params); this.attributes = { /** diff --git a/packages/abi-typegen/src/abi/types/EnumType.test.ts b/packages/abi-typegen/src/abi/types/EnumType.test.ts index 3208e700c6..7e462ff837 100644 --- a/packages/abi-typegen/src/abi/types/EnumType.test.ts +++ b/packages/abi-typegen/src/abi/types/EnumType.test.ts @@ -3,7 +3,7 @@ import { getTypegenForcProject, } from '../../../test/fixtures/forc-projects/index'; import { TargetEnum } from '../../types/enums/TargetEnum'; -import type { IRawAbiTypeRoot } from '../../types/interfaces/IRawAbiType'; +import type { JsonAbiType } from '../../types/interfaces/JsonAbi'; import { findType } from '../../utils/findType'; import { makeType } from '../../utils/makeType'; @@ -23,7 +23,7 @@ describe('EnumType.ts', () => { abiContents: { types: rawTypes }, } = getTypegenForcProject(project); - const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType })); + const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType })); return { types }; } diff --git a/packages/abi-typegen/src/abi/types/EnumType.ts b/packages/abi-typegen/src/abi/types/EnumType.ts index d679565573..72e1e0d9ce 100644 --- a/packages/abi-typegen/src/abi/types/EnumType.ts +++ b/packages/abi-typegen/src/abi/types/EnumType.ts @@ -1,4 +1,4 @@ -import type { IRawAbiTypeComponent } from '../../index'; +import type { JsonAbiArgument } from '../../index'; import type { TargetEnum } from '../../types/enums/TargetEnum'; import type { IType } from '../../types/interfaces/IType'; import { extractStructName } from '../../utils/extractStructName'; @@ -58,7 +58,7 @@ export class EnumType extends AType implements IType { const { components } = this.rawAbiType; // `components` array guaranteed to always exist for structs/enums - const enumComponents = components as IRawAbiTypeComponent[]; + const enumComponents = components as JsonAbiArgument[]; if (!enumComponents.every(({ type }) => typeHash[type] === EmptyType.swayType)) { return undefined; @@ -73,7 +73,7 @@ export class EnumType extends AType implements IType { const { components } = this.rawAbiType; // `components` array guaranteed to always exist for structs/enums - const enumComponents = components as IRawAbiTypeComponent[]; + const enumComponents = components as JsonAbiArgument[]; const attributeKey: 'inputLabel' | 'outputLabel' = `${target}Label`; diff --git a/packages/abi-typegen/src/abi/types/EvmAddressType.test.ts b/packages/abi-typegen/src/abi/types/EvmAddressType.test.ts index a3345fc121..53ec490eb9 100644 --- a/packages/abi-typegen/src/abi/types/EvmAddressType.test.ts +++ b/packages/abi-typegen/src/abi/types/EvmAddressType.test.ts @@ -2,7 +2,7 @@ import { AbiTypegenProjectsEnum, getTypegenForcProject, } from '../../../test/fixtures/forc-projects/index'; -import type { IRawAbiTypeRoot } from '../../index'; +import type { JsonAbiType } from '../../index'; import { findType } from '../../utils/findType'; import { makeType } from '../../utils/makeType'; import * as parseTypeArgumentsMod from '../../utils/parseTypeArguments'; @@ -21,7 +21,7 @@ describe('EvmAddressType.ts', () => { const project = getTypegenForcProject(AbiTypegenProjectsEnum.EVM_ADDRESS); const rawTypes = project.abiContents.types; - const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType })); + const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType })); const suitableForEvmAddress = EvmAddressType.isSuitableFor({ type: EvmAddressType.swayType }); const suitableForStruct = EvmAddressType.isSuitableFor({ type: StructType.swayType }); diff --git a/packages/abi-typegen/src/abi/types/OptionType.test.ts b/packages/abi-typegen/src/abi/types/OptionType.test.ts index f85d78a822..c827dea99d 100644 --- a/packages/abi-typegen/src/abi/types/OptionType.test.ts +++ b/packages/abi-typegen/src/abi/types/OptionType.test.ts @@ -2,7 +2,7 @@ import { AbiTypegenProjectsEnum, getTypegenForcProject, } from '../../../test/fixtures/forc-projects/index'; -import type { IRawAbiTypeRoot } from '../../index'; +import type { JsonAbiType } from '../../index'; import { findType } from '../../utils/findType'; import { makeType } from '../../utils/makeType'; @@ -20,7 +20,7 @@ describe('OptionType.ts', () => { const project = getTypegenForcProject(AbiTypegenProjectsEnum.OPTION_SIMPLE); const rawTypes = project.abiContents.types; - const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType })); + const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType })); return { types }; } diff --git a/packages/abi-typegen/src/abi/types/ResultType.test.ts b/packages/abi-typegen/src/abi/types/ResultType.test.ts index 14e7633879..80cdf1488a 100644 --- a/packages/abi-typegen/src/abi/types/ResultType.test.ts +++ b/packages/abi-typegen/src/abi/types/ResultType.test.ts @@ -2,7 +2,7 @@ import { AbiTypegenProjectsEnum, getTypegenForcProject, } from '../../../test/fixtures/forc-projects/index'; -import type { IRawAbiTypeRoot } from '../../index'; +import type { JsonAbiType } from '../../index'; import { parseTypes } from '../../utils/parseTypes'; import { EnumType } from './EnumType'; @@ -17,7 +17,7 @@ describe('ResultType.ts', () => { */ function getResultType() { const project = getTypegenForcProject(AbiTypegenProjectsEnum.FULL); - const rawTypes = project.abiContents.types as IRawAbiTypeRoot[]; + const rawTypes = project.abiContents.types as JsonAbiType[]; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return parseTypes({ rawAbiTypes: [rawTypes.find((t) => t.type === 'enum Result')!] })[0]; } diff --git a/packages/abi-typegen/src/abi/types/StructType.test.ts b/packages/abi-typegen/src/abi/types/StructType.test.ts index 05237215cd..e3609138a5 100644 --- a/packages/abi-typegen/src/abi/types/StructType.test.ts +++ b/packages/abi-typegen/src/abi/types/StructType.test.ts @@ -2,7 +2,7 @@ import { AbiTypegenProjectsEnum, getTypegenForcProject, } from '../../../test/fixtures/forc-projects/index'; -import type { IRawAbiTypeRoot } from '../../index'; +import type { JsonAbiType } from '../../index'; import { TargetEnum } from '../../types/enums/TargetEnum'; import { findType } from '../../utils/findType'; import { makeType } from '../../utils/makeType'; @@ -24,7 +24,7 @@ describe('StructType.ts', () => { const project = getTypegenForcProject(AbiTypegenProjectsEnum.STRUCT_SIMPLE); const rawTypes = project.abiContents.types; - const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType })); + const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType })); const suitableForStruct = StructType.isSuitableFor({ type: StructType.swayType }); const suitableForU16 = StructType.isSuitableFor({ type: U16Type.swayType }); diff --git a/packages/abi-typegen/src/abi/types/StructType.ts b/packages/abi-typegen/src/abi/types/StructType.ts index a5d871e2fe..c4b972e891 100644 --- a/packages/abi-typegen/src/abi/types/StructType.ts +++ b/packages/abi-typegen/src/abi/types/StructType.ts @@ -1,4 +1,4 @@ -import type { IRawAbiTypeComponent } from '../../index'; +import type { JsonAbiArgument } from '../../index'; import type { TargetEnum } from '../../types/enums/TargetEnum'; import type { IType } from '../../types/interfaces/IType'; import { extractStructName } from '../../utils/extractStructName'; @@ -46,7 +46,7 @@ export class StructType extends AType implements IType { const { components } = this.rawAbiType; // `components` array guaranteed to always exist for structs/enums - const structComponents = components as IRawAbiTypeComponent[]; + const structComponents = components as JsonAbiArgument[]; // loop through all components const members = structComponents.map((component) => { diff --git a/packages/abi-typegen/src/abi/types/TupleType.test.ts b/packages/abi-typegen/src/abi/types/TupleType.test.ts index 51b8eded04..792b275a96 100644 --- a/packages/abi-typegen/src/abi/types/TupleType.test.ts +++ b/packages/abi-typegen/src/abi/types/TupleType.test.ts @@ -2,7 +2,7 @@ import { AbiTypegenProjectsEnum, getTypegenForcProject, } from '../../../test/fixtures/forc-projects/index'; -import type { IRawAbiTypeRoot } from '../../index'; +import type { JsonAbiType } from '../../index'; import { findType } from '../../utils/findType'; import { makeType } from '../../utils/makeType'; import * as parseTypeArgumentsMod from '../../utils/parseTypeArguments'; @@ -20,7 +20,7 @@ describe('TupleType.ts', () => { const project = getTypegenForcProject(AbiTypegenProjectsEnum.TUPLE_SIMPLE); const rawTypes = project.abiContents.types; - const types = rawTypes.map((rawAbiType: IRawAbiTypeRoot) => makeType({ rawAbiType })); + const types = rawTypes.map((rawAbiType: JsonAbiType) => makeType({ rawAbiType })); const suitableForTuple = TupleType.isSuitableFor({ type: TupleType.swayType }); const suitableForArray = TupleType.isSuitableFor({ type: ArrayType.swayType }); diff --git a/packages/abi-typegen/src/abi/types/U8Type.ts b/packages/abi-typegen/src/abi/types/U8Type.ts index a7012a38dc..e66a666140 100644 --- a/packages/abi-typegen/src/abi/types/U8Type.ts +++ b/packages/abi-typegen/src/abi/types/U8Type.ts @@ -1,4 +1,4 @@ -import type { IRawAbiTypeRoot } from '../../index'; +import type { JsonAbiType } from '../../index'; import type { IType } from '../../types/interfaces/IType'; import { AType } from './AType'; @@ -10,7 +10,7 @@ export class U8Type extends AType implements IType { public static MATCH_REGEX: RegExp = /^u8$/m; - constructor(params: { rawAbiType: IRawAbiTypeRoot }) { + constructor(params: { rawAbiType: JsonAbiType }) { super(params); this.attributes = { inputLabel: `BigNumberish`, diff --git a/packages/abi-typegen/src/index.ts b/packages/abi-typegen/src/index.ts index dac4e45922..bc0ad033a0 100644 --- a/packages/abi-typegen/src/index.ts +++ b/packages/abi-typegen/src/index.ts @@ -6,8 +6,4 @@ export * from './types/enums/ProgramTypeEnum'; export * from './types/interfaces/IConfigurable'; export * from './types/interfaces/IFile'; export * from './types/interfaces/IFunction'; -export * from './types/interfaces/IRawAbi'; -export * from './types/interfaces/IRawAbiConfigurable'; -export * from './types/interfaces/IRawAbiFunction'; -export * from './types/interfaces/IRawAbiType'; -export * from './types/interfaces/IRawAbiLoggedTypes'; +export * from './types/interfaces/JsonAbi'; diff --git a/packages/abi-typegen/src/types/interfaces/IConfigurable.ts b/packages/abi-typegen/src/types/interfaces/IConfigurable.ts index f399707316..c655751f68 100644 --- a/packages/abi-typegen/src/types/interfaces/IConfigurable.ts +++ b/packages/abi-typegen/src/types/interfaces/IConfigurable.ts @@ -1,8 +1,8 @@ -import type { IRawAbiConfigurable } from './IRawAbiConfigurable'; import type { IType } from './IType'; +import type { JsonAbiConfigurable } from './JsonAbi'; export interface IConfigurable { name: string; type: IType; - rawAbiConfigurable: IRawAbiConfigurable; + rawAbiConfigurable: JsonAbiConfigurable; } diff --git a/packages/abi-typegen/src/types/interfaces/IFunction.ts b/packages/abi-typegen/src/types/interfaces/IFunction.ts index ad95898b88..db7c6db103 100644 --- a/packages/abi-typegen/src/types/interfaces/IFunction.ts +++ b/packages/abi-typegen/src/types/interfaces/IFunction.ts @@ -1,5 +1,5 @@ -import type { IRawAbiFunction } from './IRawAbiFunction'; import type { IType } from './IType'; +import type { JsonAbiFunction } from './JsonAbi'; export interface IFunctionAttributes { inputs: string; @@ -10,7 +10,7 @@ export interface IFunctionAttributes { export interface IFunction { types: IType[]; name: string; - rawAbiFunction: IRawAbiFunction; + rawAbiFunction: JsonAbiFunction; attributes: IFunctionAttributes; getDeclaration(): string; } diff --git a/packages/abi-typegen/src/types/interfaces/IRawAbi.ts b/packages/abi-typegen/src/types/interfaces/IRawAbi.ts deleted file mode 100644 index ee8753614f..0000000000 --- a/packages/abi-typegen/src/types/interfaces/IRawAbi.ts +++ /dev/null @@ -1,13 +0,0 @@ -import type { IRawAbiConfigurable } from './IRawAbiConfigurable'; -import type { IRawAbiFunction } from './IRawAbiFunction'; -import type { IRawAbiLoggedTypes } from './IRawAbiLoggedTypes'; -import type { IRawAbiMessagesType } from './IRawAbiMessagesType'; -import type { IRawAbiTypeRoot } from './IRawAbiType'; - -export interface IRawAbi { - types: IRawAbiTypeRoot[]; - functions: IRawAbiFunction[]; - loggedTypes: IRawAbiLoggedTypes[]; - configurables: IRawAbiConfigurable[]; - messagesTypes: IRawAbiMessagesType[]; -} diff --git a/packages/abi-typegen/src/types/interfaces/IRawAbiConfigurable.ts b/packages/abi-typegen/src/types/interfaces/IRawAbiConfigurable.ts deleted file mode 100644 index 2dc6194c35..0000000000 --- a/packages/abi-typegen/src/types/interfaces/IRawAbiConfigurable.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface IRawAbiConfigurable { - name: string; - configurableType: IRawAbiConfigurableType; - offset: number; -} - -export interface IRawAbiConfigurableType { - name: string; - type: number; - typeArguments: null | IRawAbiConfigurableType[]; -} diff --git a/packages/abi-typegen/src/types/interfaces/IRawAbiFunction.ts b/packages/abi-typegen/src/types/interfaces/IRawAbiFunction.ts deleted file mode 100644 index d034d79d18..0000000000 --- a/packages/abi-typegen/src/types/interfaces/IRawAbiFunction.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface IRawAbiFunction { - name: string; - inputs: IRawAbiFunctionIO[]; - output: IRawAbiFunctionIO; -} - -export interface IRawAbiFunctionIO { - name: string; - type: number; - typeArguments: null | IRawAbiFunctionIO[]; -} diff --git a/packages/abi-typegen/src/types/interfaces/IRawAbiLoggedTypes.ts b/packages/abi-typegen/src/types/interfaces/IRawAbiLoggedTypes.ts deleted file mode 100644 index 5e9e09e3c1..0000000000 --- a/packages/abi-typegen/src/types/interfaces/IRawAbiLoggedTypes.ts +++ /dev/null @@ -1,5 +0,0 @@ -import type { IRawAbiFunctionIO } from './IRawAbiFunction'; - -export interface IRawAbiLoggedTypes extends IRawAbiFunctionIO { - logId: string; -} diff --git a/packages/abi-typegen/src/types/interfaces/IRawAbiMessagesType.ts b/packages/abi-typegen/src/types/interfaces/IRawAbiMessagesType.ts deleted file mode 100644 index 4d6993cb35..0000000000 --- a/packages/abi-typegen/src/types/interfaces/IRawAbiMessagesType.ts +++ /dev/null @@ -1,8 +0,0 @@ -export interface IRawAbiMessagesType { - messageDataType: IRawAbiMessageDataType; -} - -export interface IRawAbiMessageDataType { - type: number; - typeArguments: null | IRawAbiMessageDataType[]; -} diff --git a/packages/abi-typegen/src/types/interfaces/IRawAbiType.ts b/packages/abi-typegen/src/types/interfaces/IRawAbiType.ts deleted file mode 100644 index 252ee87c3a..0000000000 --- a/packages/abi-typegen/src/types/interfaces/IRawAbiType.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface IRawAbiTypeRoot { - type: string; // type name - typeId: number; // type id (others will reference it) - components: null | IRawAbiTypeComponent[]; - typeParameters: null | number[]; -} - -export interface IRawAbiTypeComponent { - name: string; // type name - type: number; // foreing key for `typeId` (on `root` nodes) - typeArguments: null | IRawAbiTypeComponent[]; -} diff --git a/packages/abi-typegen/src/types/interfaces/IType.ts b/packages/abi-typegen/src/types/interfaces/IType.ts index 94560ad5f1..99eefe4fd7 100644 --- a/packages/abi-typegen/src/types/interfaces/IType.ts +++ b/packages/abi-typegen/src/types/interfaces/IType.ts @@ -1,4 +1,4 @@ -import type { IRawAbiTypeRoot } from './IRawAbiType'; +import type { JsonAbiType } from './JsonAbi'; export interface ITypeAttributes { inputLabel: string; @@ -12,7 +12,7 @@ export interface ITypeAttributes { export interface IType { name: string; attributes: ITypeAttributes; - rawAbiType: IRawAbiTypeRoot; + rawAbiType: JsonAbiType; requiredFuelsMembersImports: string[]; parseComponentsAttributes(params: { types: IType[] }): ITypeAttributes; diff --git a/packages/abi-typegen/src/types/interfaces/JsonAbi.ts b/packages/abi-typegen/src/types/interfaces/JsonAbi.ts new file mode 100644 index 0000000000..2e481d27aa --- /dev/null +++ b/packages/abi-typegen/src/types/interfaces/JsonAbi.ts @@ -0,0 +1,57 @@ +/** + * Types for Fuel JSON ABI Format as defined on: + * https://github.com/FuelLabs/fuel-specs/blob/master/src/abi/json-abi-format.md + */ +export interface JsonAbi { + readonly types: readonly JsonAbiType[]; + readonly loggedTypes: readonly JsonAbiLoggedType[]; + readonly functions: readonly JsonAbiFunction[]; + readonly messagesTypes: readonly JsonAbiMessagesType[]; + readonly configurables: readonly JsonAbiConfigurable[]; + readonly encoding?: string; +} + +export interface JsonAbiType { + readonly typeId: number; + readonly type: string; + readonly components: readonly JsonAbiArgument[] | null; + readonly typeParameters: readonly number[] | null; +} + +export interface JsonAbiArgument { + readonly type: number; + readonly name: string; + readonly typeArguments: readonly JsonAbiArgument[] | null; +} + +export interface JsonAbiArgumentWithoutName { + readonly type: number; + readonly typeArguments: readonly JsonAbiArgumentWithoutName[] | null; +} + +export interface JsonAbiLoggedType { + readonly logId: string; + readonly loggedType: JsonAbiArgument; +} + +export interface JsonAbiMessagesType { + readonly messageDataType: JsonAbiArgumentWithoutName; +} + +export interface JsonAbiFunction { + readonly name: string; + readonly inputs: readonly JsonAbiArgument[]; + readonly output: JsonAbiArgument; + readonly attributes: readonly JsonAbiFunctionAttribute[] | null; +} + +export interface JsonAbiFunctionAttribute { + readonly name: string; + readonly arguments: ReadonlyArray; +} + +export interface JsonAbiConfigurable { + name: string; + configurableType: JsonAbiArgument; + offset: number; +} diff --git a/packages/abi-typegen/src/utils/extractStructName.test.ts b/packages/abi-typegen/src/utils/extractStructName.test.ts index 0e70135454..897ff890c8 100644 --- a/packages/abi-typegen/src/utils/extractStructName.test.ts +++ b/packages/abi-typegen/src/utils/extractStructName.test.ts @@ -1,7 +1,7 @@ import { EnumType } from '../abi/types/EnumType'; import { GenericType } from '../abi/types/GenericType'; import { StructType } from '../abi/types/StructType'; -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; +import type { JsonAbiType } from '../types/interfaces/JsonAbi'; import { extractStructName } from './extractStructName'; @@ -12,7 +12,7 @@ describe('extractStructName.ts', () => { /* Test helpers */ - function makeType(typeId: number, type: string): IRawAbiTypeRoot { + function makeType(typeId: number, type: string): JsonAbiType { return { typeId, type, diff --git a/packages/abi-typegen/src/utils/extractStructName.ts b/packages/abi-typegen/src/utils/extractStructName.ts index 4e4dd813d1..0d3ab5a723 100644 --- a/packages/abi-typegen/src/utils/extractStructName.ts +++ b/packages/abi-typegen/src/utils/extractStructName.ts @@ -1,8 +1,8 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors'; -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; +import type { JsonAbiType } from '../types/interfaces/JsonAbi'; -export function extractStructName(params: { rawAbiType: IRawAbiTypeRoot; regex: RegExp }) { +export function extractStructName(params: { rawAbiType: JsonAbiType; regex: RegExp }) { const { rawAbiType, regex } = params; const matches = rawAbiType.type.match(regex); diff --git a/packages/abi-typegen/src/utils/findType.test.ts b/packages/abi-typegen/src/utils/findType.test.ts index 2f7fd78a66..b15dc9b9ae 100644 --- a/packages/abi-typegen/src/utils/findType.test.ts +++ b/packages/abi-typegen/src/utils/findType.test.ts @@ -1,7 +1,7 @@ import { safeExec } from '@fuel-ts/errors/test-utils'; -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiType } from '../types/interfaces/JsonAbi'; import { findType } from './findType'; import { makeType } from './makeType'; @@ -11,7 +11,7 @@ import { makeType } from './makeType'; */ describe('findType.ts', () => { test('should find type', () => { - const rawAbiType: IRawAbiTypeRoot = { + const rawAbiType: JsonAbiType = { type: 'u8', typeId: 1, components: null, diff --git a/packages/abi-typegen/src/utils/makeConfigurable.ts b/packages/abi-typegen/src/utils/makeConfigurable.ts index 54936972f2..db5d6ea1ec 100644 --- a/packages/abi-typegen/src/utils/makeConfigurable.ts +++ b/packages/abi-typegen/src/utils/makeConfigurable.ts @@ -1,10 +1,10 @@ import { Configurable } from '../abi/configurable/Configurable'; -import type { IRawAbiConfigurable } from '../types/interfaces/IRawAbiConfigurable'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiConfigurable } from '../types/interfaces/JsonAbi'; export function makeConfigurable(params: { types: IType[]; - rawAbiConfigurable: IRawAbiConfigurable; + rawAbiConfigurable: JsonAbiConfigurable; }) { const { types, rawAbiConfigurable } = params; return new Configurable({ types, rawAbiConfigurable }); diff --git a/packages/abi-typegen/src/utils/makeFunction.test.ts b/packages/abi-typegen/src/utils/makeFunction.test.ts index d1ad5f1b15..aca082c573 100644 --- a/packages/abi-typegen/src/utils/makeFunction.test.ts +++ b/packages/abi-typegen/src/utils/makeFunction.test.ts @@ -1,6 +1,5 @@ -import type { IRawAbiFunction } from '../types/interfaces/IRawAbiFunction'; -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiFunction, JsonAbiType } from '../types/interfaces/JsonAbi'; import { makeFunction } from './makeFunction'; import { makeType } from './makeType'; @@ -10,14 +9,14 @@ import { makeType } from './makeType'; */ describe('functions.ts', () => { test('should instantiate a new Function instance', () => { - const rawU8: IRawAbiTypeRoot = { + const rawU8: JsonAbiType = { typeId: 1, type: 'u8', components: null, typeParameters: null, }; - const rawU16: IRawAbiTypeRoot = { + const rawU16: JsonAbiType = { typeId: 2, type: 'u16', components: null, @@ -29,7 +28,7 @@ describe('functions.ts', () => { const types: IType[] = [typeU8, typeU16]; - const rawAbiFunction: IRawAbiFunction = { + const rawAbiFunction: JsonAbiFunction = { name: 'f1', inputs: [{ name: 'u8', type: 1, typeArguments: null }], output: { name: 'u8', type: 1, typeArguments: null }, diff --git a/packages/abi-typegen/src/utils/makeFunction.ts b/packages/abi-typegen/src/utils/makeFunction.ts index 97b263c946..e60a6c5cdb 100644 --- a/packages/abi-typegen/src/utils/makeFunction.ts +++ b/packages/abi-typegen/src/utils/makeFunction.ts @@ -1,8 +1,8 @@ import { Function } from '../abi/functions/Function'; -import type { IRawAbiFunction } from '../types/interfaces/IRawAbiFunction'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiFunction } from '../types/interfaces/JsonAbi'; -export function makeFunction(params: { types: IType[]; rawAbiFunction: IRawAbiFunction }) { +export function makeFunction(params: { types: IType[]; rawAbiFunction: JsonAbiFunction }) { const { types, rawAbiFunction } = params; return new Function({ types, rawAbiFunction }); } diff --git a/packages/abi-typegen/src/utils/makeType.test.ts b/packages/abi-typegen/src/utils/makeType.test.ts index 29c96c0936..004e35eed0 100644 --- a/packages/abi-typegen/src/utils/makeType.test.ts +++ b/packages/abi-typegen/src/utils/makeType.test.ts @@ -1,7 +1,7 @@ import { safeExec } from '@fuel-ts/errors/test-utils'; import type { ArrayType } from '../abi/types/ArrayType'; -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; +import type { JsonAbiType } from '../types/interfaces/JsonAbi'; import { makeType } from './makeType'; @@ -10,7 +10,7 @@ import { makeType } from './makeType'; */ describe('makeType.ts', () => { test('should create a new Type instance just fine', () => { - const rawAbiType: IRawAbiTypeRoot = { + const rawAbiType: JsonAbiType = { typeId: 1, type: 'u64', components: null, @@ -21,7 +21,7 @@ describe('makeType.ts', () => { }); test('should throw for unsupported types', async () => { - const rawAbiType: IRawAbiTypeRoot = { + const rawAbiType: JsonAbiType = { typeId: 1, type: 'non existent', components: null, diff --git a/packages/abi-typegen/src/utils/makeType.ts b/packages/abi-typegen/src/utils/makeType.ts index 63345cc171..ae2bffc04c 100644 --- a/packages/abi-typegen/src/utils/makeType.ts +++ b/packages/abi-typegen/src/utils/makeType.ts @@ -1,10 +1,10 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors'; -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; +import type { JsonAbiType } from '../types/interfaces/JsonAbi'; import { supportedTypes } from './supportedTypes'; -export function makeType(params: { rawAbiType: IRawAbiTypeRoot }) { +export function makeType(params: { rawAbiType: JsonAbiType }) { const { rawAbiType } = params; const { type } = rawAbiType; diff --git a/packages/abi-typegen/src/utils/parseConfigurables.ts b/packages/abi-typegen/src/utils/parseConfigurables.ts index 3484bf3cd0..66a2a4b7f3 100644 --- a/packages/abi-typegen/src/utils/parseConfigurables.ts +++ b/packages/abi-typegen/src/utils/parseConfigurables.ts @@ -1,12 +1,12 @@ import type { IConfigurable } from '../types/interfaces/IConfigurable'; -import type { IRawAbiConfigurable } from '../types/interfaces/IRawAbiConfigurable'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiConfigurable } from '../types/interfaces/JsonAbi'; import { makeConfigurable } from './makeConfigurable'; export function parseConfigurables(params: { types: IType[]; - rawAbiConfigurables: IRawAbiConfigurable[]; + rawAbiConfigurables: readonly JsonAbiConfigurable[]; }) { const { types, rawAbiConfigurables } = params; diff --git a/packages/abi-typegen/src/utils/parseFunctions.test.ts b/packages/abi-typegen/src/utils/parseFunctions.test.ts index e3533a5333..54f0e8697e 100644 --- a/packages/abi-typegen/src/utils/parseFunctions.test.ts +++ b/packages/abi-typegen/src/utils/parseFunctions.test.ts @@ -1,6 +1,5 @@ -import type { IRawAbiFunction } from '../types/interfaces/IRawAbiFunction'; -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiFunction, JsonAbiType } from '../types/interfaces/JsonAbi'; import { makeType } from './makeType'; import { parseFunctions } from './parseFunctions'; @@ -10,14 +9,14 @@ import { parseFunctions } from './parseFunctions'; */ describe('functions.ts', () => { test('should parse an array of raw abi functions', () => { - const rawU8: IRawAbiTypeRoot = { + const rawU8: JsonAbiType = { typeId: 1, type: 'u8', components: null, typeParameters: null, }; - const rawU16: IRawAbiTypeRoot = { + const rawU16: JsonAbiType = { typeId: 2, type: 'u16', components: null, @@ -29,13 +28,13 @@ describe('functions.ts', () => { const types: IType[] = [typeU8, typeU16]; - const rawF1: IRawAbiFunction = { + const rawF1: JsonAbiFunction = { name: 'f1', inputs: [{ name: 'u8', type: 1, typeArguments: null }], output: { name: 'u8', type: 1, typeArguments: null }, }; - const rawF2: IRawAbiFunction = { + const rawF2: JsonAbiFunction = { name: 'f2', inputs: [{ name: 'u16', type: 2, typeArguments: null }], output: { name: 'u16', type: 2, typeArguments: null }, diff --git a/packages/abi-typegen/src/utils/parseFunctions.ts b/packages/abi-typegen/src/utils/parseFunctions.ts index 3fce38cb90..c0cace772c 100644 --- a/packages/abi-typegen/src/utils/parseFunctions.ts +++ b/packages/abi-typegen/src/utils/parseFunctions.ts @@ -1,10 +1,13 @@ import type { IFunction } from '../types/interfaces/IFunction'; -import type { IRawAbiFunction } from '../types/interfaces/IRawAbiFunction'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiFunction } from '../types/interfaces/JsonAbi'; import { makeFunction } from './makeFunction'; -export function parseFunctions(params: { types: IType[]; rawAbiFunctions: IRawAbiFunction[] }) { +export function parseFunctions(params: { + types: IType[]; + rawAbiFunctions: readonly JsonAbiFunction[]; +}) { const { types, rawAbiFunctions } = params; const functions: IFunction[] = rawAbiFunctions.map((rawAbiFunction) => makeFunction({ types, rawAbiFunction }) diff --git a/packages/abi-typegen/src/utils/parseTypeArguments.test.ts b/packages/abi-typegen/src/utils/parseTypeArguments.test.ts index 994c98ed92..dbb7b115f8 100644 --- a/packages/abi-typegen/src/utils/parseTypeArguments.test.ts +++ b/packages/abi-typegen/src/utils/parseTypeArguments.test.ts @@ -3,7 +3,7 @@ import { getTypegenForcProject, } from '../../test/fixtures/forc-projects/index'; import { TargetEnum } from '../types/enums/TargetEnum'; -import type { IRawAbiTypeRoot, IRawAbiTypeComponent } from '../types/interfaces/IRawAbiType'; +import type { JsonAbiType, JsonAbiArgument } from '../types/interfaces/JsonAbi'; import { makeType } from './makeType'; import { parseTypeArguments } from './parseTypeArguments'; @@ -12,7 +12,7 @@ import { parseTypeArguments } from './parseTypeArguments'; Sample ABI with components in both fashions: — WITH and WITHOUT `typeArguments` */ -const defautRawTypes: IRawAbiTypeRoot[] = [ +const defautRawTypes: JsonAbiType[] = [ { typeId: 0, type: 'bool', @@ -77,7 +77,7 @@ describe('parseTypeArguments.ts', () => { function getTypeComponents(params: { typeId: number }) { const found = defautRawTypes.find((rt) => rt.typeId === params.typeId); - return (found as IRawAbiTypeRoot).components as IRawAbiTypeComponent[]; + return (found as JsonAbiType).components as JsonAbiArgument[]; } /* diff --git a/packages/abi-typegen/src/utils/parseTypeArguments.ts b/packages/abi-typegen/src/utils/parseTypeArguments.ts index f7e9820f6c..e2d0673b1c 100644 --- a/packages/abi-typegen/src/utils/parseTypeArguments.ts +++ b/packages/abi-typegen/src/utils/parseTypeArguments.ts @@ -1,6 +1,6 @@ import type { TargetEnum } from '../types/enums/TargetEnum'; -import type { IRawAbiTypeComponent } from '../types/interfaces/IRawAbiType'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiArgument } from '../types/interfaces/JsonAbi'; import { findType } from './findType'; @@ -10,7 +10,7 @@ import { findType } from './findType'; export function parseTypeArguments(params: { types: IType[]; target: TargetEnum; - typeArguments: IRawAbiTypeComponent[]; + typeArguments: readonly JsonAbiArgument[]; parentTypeId?: number; }): string { const { types, typeArguments, parentTypeId, target } = params; @@ -40,7 +40,7 @@ export function parseTypeArguments(params: { types, target, parentTypeId: typeArgument.type, - typeArguments: typeArgument.typeArguments, + typeArguments: typeArgument.typeArguments as JsonAbiArgument[], }); buffer.push(nestedParsed); diff --git a/packages/abi-typegen/src/utils/parseTypes.test.ts b/packages/abi-typegen/src/utils/parseTypes.test.ts index 63213bb2bb..b7765a9f96 100644 --- a/packages/abi-typegen/src/utils/parseTypes.test.ts +++ b/packages/abi-typegen/src/utils/parseTypes.test.ts @@ -1,4 +1,4 @@ -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; +import type { JsonAbiType } from '../types/interfaces/JsonAbi'; import { parseTypes } from './parseTypes'; @@ -7,21 +7,21 @@ import { parseTypes } from './parseTypes'; */ describe('types.ts', () => { test('should parse an array of raw abi types', () => { - const rawU8: IRawAbiTypeRoot = { + const rawU8: JsonAbiType = { typeId: 1, type: 'u8', components: null, typeParameters: null, }; - const rawStr: IRawAbiTypeRoot = { + const rawStr: JsonAbiType = { typeId: 2, type: 'str[2]', components: null, typeParameters: null, }; - const rawVec: IRawAbiTypeRoot = { + const rawVec: JsonAbiType = { typeId: 3, type: 'struct RawVec', components: null, diff --git a/packages/abi-typegen/src/utils/parseTypes.ts b/packages/abi-typegen/src/utils/parseTypes.ts index 628b2699cb..671a91df90 100644 --- a/packages/abi-typegen/src/utils/parseTypes.ts +++ b/packages/abi-typegen/src/utils/parseTypes.ts @@ -1,10 +1,10 @@ -import type { IRawAbiTypeRoot } from '../types/interfaces/IRawAbiType'; import type { IType } from '../types/interfaces/IType'; +import type { JsonAbiType } from '../types/interfaces/JsonAbi'; import { makeType } from './makeType'; import { shouldSkipAbiType } from './shouldSkipAbiType'; -export function parseTypes(params: { rawAbiTypes: IRawAbiTypeRoot[] }) { +export function parseTypes(params: { rawAbiTypes: readonly JsonAbiType[] }) { const types: IType[] = []; // First we parse all ROOT nodes diff --git a/packages/abi-typegen/test/fixtures/forc-projects/index.ts b/packages/abi-typegen/test/fixtures/forc-projects/index.ts index bdf2506619..062629811a 100644 --- a/packages/abi-typegen/test/fixtures/forc-projects/index.ts +++ b/packages/abi-typegen/test/fixtures/forc-projects/index.ts @@ -1,7 +1,7 @@ import { getForcProject } from '@fuel-ts/utils/test-utils'; import { join } from 'path'; -import type { IRawAbi } from '../../../src/index'; +import type { JsonAbi } from '../../../src/index'; export enum AbiTypegenProjectsEnum { ARRAY_OF_ENUMS = 'array-of-enums', @@ -34,7 +34,7 @@ export const getTypegenForcProject = ( project: AbiTypegenProjectsEnum, build: 'release' | 'debug' = 'release' ) => - getForcProject({ + getForcProject({ projectDir: join(__dirname, project), projectName: project, build, diff --git a/packages/abi-typegen/test/utils/getNewAbiTypegen.ts b/packages/abi-typegen/test/utils/getNewAbiTypegen.ts index e7b5af2401..fcaa23cebb 100644 --- a/packages/abi-typegen/test/utils/getNewAbiTypegen.ts +++ b/packages/abi-typegen/test/utils/getNewAbiTypegen.ts @@ -1,4 +1,4 @@ -import type { IFile, IRawAbiTypeRoot, IRawAbiConfigurable } from '../../src/index'; +import type { IFile, JsonAbiType, JsonAbiConfigurable } from '../../src/index'; import { AbiTypeGen } from '../../src/index'; import { ProgramTypeEnum } from '../../src/types/enums/ProgramTypeEnum'; @@ -17,7 +17,7 @@ export function getNewAbiTypegen( includeBinFiles = false, } = params; - const optionType: IRawAbiTypeRoot = { + const optionType: JsonAbiType = { typeId: 3, type: 'enum Option', components: [ @@ -35,7 +35,7 @@ export function getNewAbiTypegen( typeParameters: [2], }; - const types: IRawAbiTypeRoot[] = [ + const types: JsonAbiType[] = [ { typeId: 1, type: 'u8', @@ -72,7 +72,7 @@ export function getNewAbiTypegen( const functions = includeMainFunction ? [main] : []; - const configurables: IRawAbiConfigurable[] = [ + const configurables: JsonAbiConfigurable[] = [ { name: 'configurable', configurableType: {