From 2bfac73742db4888bedacf151f1566b435f561c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luiz=20Est=C3=A1cio?= Date: Fri, 11 Mar 2022 18:18:07 -0700 Subject: [PATCH] feat: change typechain imports to fuels (#184) --- package-lock.json | 2 ++ .../example-contract/src/example-contract.test.ts | 6 ++++++ packages/fuels/package.json | 1 + packages/fuels/src/index.ts | 1 + .../typechain-target-fuels/example/types/Demo.d.ts | 14 +++++++++----- .../example/types/Token.d.ts | 14 +++++++++----- .../example/types/factories/Demo__factory.ts | 6 ++---- .../example/types/factories/Token__factory.ts | 6 ++---- .../typechain-target-fuels/src/codegen/index.ts | 12 +++--------- 9 files changed, 35 insertions(+), 27 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5963ed0d22a..589e7418d69 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25827,6 +25827,7 @@ "license": "Apache-2.0", "dependencies": { "@ethersproject/bignumber": "^5.6.0", + "@ethersproject/bytes": "^5.6.0", "@fuel-ts/abi-coder": "0.3.0", "@fuel-ts/constants": "0.3.0", "@fuel-ts/contract": "0.3.0", @@ -36263,6 +36264,7 @@ "version": "file:packages/fuels", "requires": { "@ethersproject/bignumber": "^5.6.0", + "@ethersproject/bytes": "^5.6.0", "@fuel-ts/abi-coder": "0.3.0", "@fuel-ts/constants": "0.3.0", "@fuel-ts/contract": "0.3.0", diff --git a/packages/example-contract/src/example-contract.test.ts b/packages/example-contract/src/example-contract.test.ts index f01690a0e5b..948a822f691 100644 --- a/packages/example-contract/src/example-contract.test.ts +++ b/packages/example-contract/src/example-contract.test.ts @@ -21,5 +21,11 @@ describe('ExampleContract', () => { // Assert expect(result.toNumber()).toEqual(1337); + + // Try co call from the factory + const contractInstance = ExampleContractAbi__factory.connect(contract.id, wallet); + const resultInstance = await contractInstance.functions.return_input(1337); + + expect(resultInstance.toNumber()).toBe(1337); }); }); diff --git a/packages/fuels/package.json b/packages/fuels/package.json index 3ffdb026c9c..d6f53469c67 100644 --- a/packages/fuels/package.json +++ b/packages/fuels/package.json @@ -11,6 +11,7 @@ "license": "Apache-2.0", "dependencies": { "@ethersproject/bignumber": "^5.6.0", + "@ethersproject/bytes": "^5.6.0", "@fuel-ts/abi-coder": "0.3.0", "@fuel-ts/constants": "0.3.0", "@fuel-ts/contract": "0.3.0", diff --git a/packages/fuels/src/index.ts b/packages/fuels/src/index.ts index d7c55178fbf..4bd4f90e9dc 100644 --- a/packages/fuels/src/index.ts +++ b/packages/fuels/src/index.ts @@ -1,3 +1,4 @@ +export * from '@ethersproject/bytes'; export * from '@ethersproject/bignumber'; export * from '@fuel-ts/abi-coder'; export * from '@fuel-ts/constants'; diff --git a/packages/typechain-target-fuels/example/types/Demo.d.ts b/packages/typechain-target-fuels/example/types/Demo.d.ts index a6c2a8195a2..c1f512732b2 100644 --- a/packages/typechain-target-fuels/example/types/Demo.d.ts +++ b/packages/typechain-target-fuels/example/types/Demo.d.ts @@ -2,11 +2,15 @@ /* tslint:disable */ /* eslint-disable */ -import { Interface, FunctionFragment, DecodedValue } from "@fuel-ts/abi-coder"; -import { Contract, Overrides } from "@fuel-ts/contract"; -import { Provider } from "@fuel-ts/providers"; -import { BigNumberish } from "@ethersproject/bignumber"; -import { BytesLike } from "@ethersproject/bytes"; +import type { + Interface, + FunctionFragment, + DecodedValue, + Contract, + Overrides, + BigNumberish, + BytesLike, +} from "fuels"; export type PersonStruct = { name: string; address: string }; diff --git a/packages/typechain-target-fuels/example/types/Token.d.ts b/packages/typechain-target-fuels/example/types/Token.d.ts index 92015810325..35824d28be3 100644 --- a/packages/typechain-target-fuels/example/types/Token.d.ts +++ b/packages/typechain-target-fuels/example/types/Token.d.ts @@ -2,11 +2,15 @@ /* tslint:disable */ /* eslint-disable */ -import { Interface, FunctionFragment, DecodedValue } from "@fuel-ts/abi-coder"; -import { Contract, Overrides } from "@fuel-ts/contract"; -import { Provider } from "@fuel-ts/providers"; -import { BigNumberish } from "@ethersproject/bignumber"; -import { BytesLike } from "@ethersproject/bytes"; +import type { + Interface, + FunctionFragment, + DecodedValue, + Contract, + Overrides, + BigNumberish, + BytesLike, +} from "fuels"; export type ArgsStruct = { reciever: string; amount: BigNumberish }; diff --git a/packages/typechain-target-fuels/example/types/factories/Demo__factory.ts b/packages/typechain-target-fuels/example/types/factories/Demo__factory.ts index ac1bae37014..0b431235c0e 100644 --- a/packages/typechain-target-fuels/example/types/factories/Demo__factory.ts +++ b/packages/typechain-target-fuels/example/types/factories/Demo__factory.ts @@ -2,10 +2,8 @@ /* tslint:disable */ /* eslint-disable */ -import { Interface } from "@fuel-ts/abi-coder"; -import type { Provider } from "@fuel-ts/providers"; -import type { Wallet } from "@fuel-ts/wallet"; -import { Contract } from "@fuel-ts/contract"; +import type { Provider, Wallet } from "fuels"; +import { Interface, Contract } from "fuels"; import type { Demo, DemoInterface } from "../Demo"; const _abi = [ { diff --git a/packages/typechain-target-fuels/example/types/factories/Token__factory.ts b/packages/typechain-target-fuels/example/types/factories/Token__factory.ts index c4c9cf8a48a..7076abd8350 100644 --- a/packages/typechain-target-fuels/example/types/factories/Token__factory.ts +++ b/packages/typechain-target-fuels/example/types/factories/Token__factory.ts @@ -2,10 +2,8 @@ /* tslint:disable */ /* eslint-disable */ -import { Interface } from "@fuel-ts/abi-coder"; -import type { Provider } from "@fuel-ts/providers"; -import type { Wallet } from "@fuel-ts/wallet"; -import { Contract } from "@fuel-ts/contract"; +import type { Provider, Wallet } from "fuels"; +import { Interface, Contract } from "fuels"; import type { Token, TokenInterface } from "../Token"; const _abi = [ { diff --git a/packages/typechain-target-fuels/src/codegen/index.ts b/packages/typechain-target-fuels/src/codegen/index.ts index 8b3f4fe5de8..42b5ce591ac 100644 --- a/packages/typechain-target-fuels/src/codegen/index.ts +++ b/packages/typechain-target-fuels/src/codegen/index.ts @@ -18,11 +18,7 @@ import generateStruct from './structs'; */ export function codegenContractTypings(contract: Contract, codegenConfig: CodegenConfig): string { const template = ` - import { Interface, FunctionFragment, DecodedValue } from '@fuel-ts/abi-coder'; - import { Contract, Overrides } from '@fuel-ts/contract'; - import { Provider } from '@fuel-ts/providers'; - import { BigNumberish } from '@ethersproject/bignumber'; - import { BytesLike } from '@ethersproject/bytes'; + import type { Interface, FunctionFragment, DecodedValue, Contract, Overrides, BigNumberish, BytesLike } from 'fuels'; ${Object.values(contract.structs) .map((v) => generateStruct(v[0])) @@ -89,10 +85,8 @@ function codegenCommonContractFactory( abi: RawAbiDefinition[] ): { header: string; body: string } { const header = ` - import { Interface } from "@fuel-ts/abi-coder"; - import type { Provider } from "@fuel-ts/providers"; - import type { Wallet } from "@fuel-ts/wallet"; - import { Contract } from "@fuel-ts/contract"; + import type { Provider, Wallet } from "fuels"; + import { Interface, Contract } from "fuels"; import type { ${contract.name}, ${contract.name}Interface } from "../${contract.name}"; const _abi = ${JSON.stringify(abi, null, 2)}; `.trim();