diff --git a/.changeset/giant-worms-flow.md b/.changeset/giant-worms-flow.md new file mode 100644 index 00000000000..7ee26897357 --- /dev/null +++ b/.changeset/giant-worms-flow.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/abi-typegen": patch +--- + +feat: make `typegen` factories an object instance diff --git a/packages/abi-typegen/src/templates/contract/factory.hbs b/packages/abi-typegen/src/templates/contract/factory.hbs index 4cafc771cc7..eaf2adcbde2 100644 --- a/packages/abi-typegen/src/templates/contract/factory.hbs +++ b/packages/abi-typegen/src/templates/contract/factory.hbs @@ -8,33 +8,31 @@ const _abi = {{abiJsonString}}; const _storageSlots: StorageSlot[] = {{storageSlotsJsonString}}; -export class {{capitalizedName}}__factory { - static readonly abi = _abi; +export const {{capitalizedName}}__factory = { + abi: _abi, - static readonly storageSlots = _storageSlots; + storageSlots: _storageSlots, - static createInterface(): {{capitalizedName}}Interface { + createInterface(): {{capitalizedName}}Interface { return new Interface(_abi) as unknown as {{capitalizedName}}Interface - } + }, - static connect( + connect( id: string | AbstractAddress, accountOrProvider: Account | Provider ): {{capitalizedName}} { return new Contract(id, _abi, accountOrProvider) as unknown as {{capitalizedName}} - } + }, - static async deployContract( + async deployContract( bytecode: BytesLike, wallet: Account, options: DeployContractOptions = {} ): Promise<{{capitalizedName}}> { const factory = new ContractFactory(bytecode, _abi, wallet); - const { storageSlots } = {{capitalizedName}}__factory; - const contract = await factory.deployContract({ - storageSlots, + storageSlots: _storageSlots, ...options, }); diff --git a/packages/abi-typegen/src/templates/predicate/factory.hbs b/packages/abi-typegen/src/templates/predicate/factory.hbs index c1feb742ec9..f224fb0b3cc 100644 --- a/packages/abi-typegen/src/templates/predicate/factory.hbs +++ b/packages/abi-typegen/src/templates/predicate/factory.hbs @@ -52,18 +52,16 @@ const _abi = {{abiJsonString}} const _bin = '{{hexlifiedBinString}}' -export class {{capitalizedName}}__factory { +export const {{capitalizedName}}__factory = { - static readonly abi = _abi - static readonly bin = _bin; + abi: _abi, + bin: _bin, - static createInstance(provider: Provider, predicateData?: {{capitalizedName}}Inputs, configurables?: {{capitalizedName}}Configurables) { - - const { abi, bin } = {{capitalizedName}}__factory + createInstance(provider: Provider, predicateData?: {{capitalizedName}}Inputs, configurables?: {{capitalizedName}}Configurables) { const predicate = new Predicate<{{capitalizedName}}Inputs>({ - bytecode: bin, - abi, + bytecode: _bin, + abi: _abi, provider, inputData: predicateData, configurableConstants: configurables, diff --git a/packages/abi-typegen/src/templates/script/factory.hbs b/packages/abi-typegen/src/templates/script/factory.hbs index d975e5a49e8..163cab215ec 100644 --- a/packages/abi-typegen/src/templates/script/factory.hbs +++ b/packages/abi-typegen/src/templates/script/factory.hbs @@ -55,19 +55,17 @@ const _abi = {{abiJsonString}} const _bin = '{{hexlifiedBinString}}' -export class {{capitalizedName}}__factory { +export const {{capitalizedName}}__factory = { - static readonly abi = _abi - static readonly bin = _bin + abi: _abi, + bin: _bin, - static createInstance(wallet: Account) { - - const { abi, bin } = {{capitalizedName}}__factory + createInstance(wallet: Account) { const script = new Script< {{capitalizedName}}Inputs, {{capitalizedName}}Output - >(bin, abi, wallet); + >(_bin, _abi, wallet); return script; diff --git a/packages/abi-typegen/test/fixtures/templates/contract/factory.hbs b/packages/abi-typegen/test/fixtures/templates/contract/factory.hbs index 952e91c5f42..ed48315619c 100644 --- a/packages/abi-typegen/test/fixtures/templates/contract/factory.hbs +++ b/packages/abi-typegen/test/fixtures/templates/contract/factory.hbs @@ -59,33 +59,31 @@ const _abi = { const _storageSlots: StorageSlot[] = []; -export class MyContractAbi__factory { - static readonly abi = _abi; +export const MyContractAbi__factory = { + abi: _abi, - static readonly storageSlots = _storageSlots; + storageSlots: _storageSlots, - static createInterface(): MyContractAbiInterface { + createInterface(): MyContractAbiInterface { return new Interface(_abi) as unknown as MyContractAbiInterface - } + }, - static connect( + connect( id: string | AbstractAddress, accountOrProvider: Account | Provider ): MyContractAbi { return new Contract(id, _abi, accountOrProvider) as unknown as MyContractAbi - } + }, - static async deployContract( + async deployContract( bytecode: BytesLike, wallet: Account, options: DeployContractOptions = {} ): Promise { const factory = new ContractFactory(bytecode, _abi, wallet); - const { storageSlots } = MyContractAbi__factory; - const contract = await factory.deployContract({ - storageSlots, + storageSlots: _storageSlots, ...options, }); diff --git a/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/factory.hbs b/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/factory.hbs index fc0cb34b886..663936c43e3 100644 --- a/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/factory.hbs +++ b/packages/abi-typegen/test/fixtures/templates/predicate-with-configurable/factory.hbs @@ -94,18 +94,16 @@ const _abi = { const _bin = '0x000' -export class MyPredicateAbi__factory { +export const MyPredicateAbi__factory = { - static readonly abi = _abi - static readonly bin = _bin; + abi: _abi, + bin: _bin, - static createInstance(provider: Provider, predicateData?: MyPredicateAbiInputs, configurables?: MyPredicateAbiConfigurables) { - - const { abi, bin } = MyPredicateAbi__factory + createInstance(provider: Provider, predicateData?: MyPredicateAbiInputs, configurables?: MyPredicateAbiConfigurables) { const predicate = new Predicate({ - bytecode: bin, - abi, + bytecode: _bin, + abi: _abi, provider, inputData: predicateData, configurableConstants: configurables, diff --git a/packages/abi-typegen/test/fixtures/templates/predicate/factory.hbs b/packages/abi-typegen/test/fixtures/templates/predicate/factory.hbs index 7d3e2c7f49a..3ec1939f45a 100644 --- a/packages/abi-typegen/test/fixtures/templates/predicate/factory.hbs +++ b/packages/abi-typegen/test/fixtures/templates/predicate/factory.hbs @@ -83,18 +83,16 @@ const _abi = { const _bin = '0x000' -export class MyPredicateAbi__factory { +export const MyPredicateAbi__factory = { - static readonly abi = _abi - static readonly bin = _bin; + abi: _abi, + bin: _bin, - static createInstance(provider: Provider, predicateData?: MyPredicateAbiInputs, configurables?: MyPredicateAbiConfigurables) { - - const { abi, bin } = MyPredicateAbi__factory + createInstance(provider: Provider, predicateData?: MyPredicateAbiInputs, configurables?: MyPredicateAbiConfigurables) { const predicate = new Predicate({ - bytecode: bin, - abi, + bytecode: _bin, + abi: _abi, provider, inputData: predicateData, configurableConstants: configurables, diff --git a/packages/abi-typegen/test/fixtures/templates/script-with-configurable/factory.hbs b/packages/abi-typegen/test/fixtures/templates/script-with-configurable/factory.hbs index 3fc28762edd..51c5cc63942 100644 --- a/packages/abi-typegen/test/fixtures/templates/script-with-configurable/factory.hbs +++ b/packages/abi-typegen/test/fixtures/templates/script-with-configurable/factory.hbs @@ -93,19 +93,17 @@ const _abi = { const _bin = '0x000' -export class MyScriptAbi__factory { +export const MyScriptAbi__factory = { - static readonly abi = _abi - static readonly bin = _bin + abi: _abi, + bin: _bin, - static createInstance(wallet: Account) { - - const { abi, bin } = MyScriptAbi__factory + createInstance(wallet: Account) { const script = new Script< MyScriptAbiInputs, MyScriptAbiOutput - >(bin, abi, wallet); + >(_bin, _abi, wallet); return script; diff --git a/packages/abi-typegen/test/fixtures/templates/script/factory.hbs b/packages/abi-typegen/test/fixtures/templates/script/factory.hbs index 9c15f1fe962..ba65d8dcfb6 100644 --- a/packages/abi-typegen/test/fixtures/templates/script/factory.hbs +++ b/packages/abi-typegen/test/fixtures/templates/script/factory.hbs @@ -79,19 +79,17 @@ const _abi = { const _bin = '0x000' -export class MyScriptAbi__factory { +export const MyScriptAbi__factory = { - static readonly abi = _abi - static readonly bin = _bin + abi: _abi, + bin: _bin, - static createInstance(wallet: Account) { - - const { abi, bin } = MyScriptAbi__factory + createInstance(wallet: Account) { const script = new Script< MyScriptAbiInputs, MyScriptAbiOutput - >(bin, abi, wallet); + >(_bin, _abi, wallet); return script;