Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: ABI Gen #3249

Open
wants to merge 164 commits into
base: ns/feat/abi-parser
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
72fc6d6
parser scaffolding
nedsalk Sep 3, 2024
451b1db
lint fix
nedsalk Sep 4, 2024
6c1eed5
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Sep 4, 2024
cfb3499
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Sep 4, 2024
36c9866
Merge branch 'np/feat/abi-refactor' of github.com:FuelLabs/fuels-ts i…
petertonysmith94 Sep 10, 2024
4c9743a
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Sep 12, 2024
e7c55d5
chore: ABI parser - API alterations (#3164)
petertonysmith94 Sep 13, 2024
96785b3
Merge remote-tracking branch 'origin/np/feat/abi-refactor' into ns/fe…
nedsalk Sep 25, 2024
b304bf6
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Sep 28, 2024
51f7857
Add `AbiTypeMetadata` and fix bug
nedsalk Oct 3, 2024
582f609
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Oct 3, 2024
23aec29
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Oct 11, 2024
54b5dd2
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Oct 11, 2024
3318c80
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Oct 15, 2024
916bb90
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Oct 23, 2024
3e88a37
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Oct 24, 2024
9ee2e74
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
petertonysmith94 Nov 18, 2024
0215397
Merge branch 'np/feat/abi-refactor' of github.com:FuelLabs/fuels-ts i…
petertonysmith94 Nov 25, 2024
8fc8e08
chore: adjust attributes to match spec
petertonysmith94 Nov 25, 2024
e73a7ab
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Nov 27, 2024
8e5781e
chore: added `FuelError`
petertonysmith94 Nov 27, 2024
f67b4a8
chore: fixed test for matchers
petertonysmith94 Nov 27, 2024
beeebea
Merge branch 'np/feat/abi-refactor' of github.com:FuelLabs/fuels-ts i…
petertonysmith94 Nov 27, 2024
c35de21
Merge branch 'np/feat/abi-refactor' of github.com:FuelLabs/fuels-ts i…
petertonysmith94 Nov 27, 2024
b0a4f02
fix generic type resolution edge case
nedsalk Nov 27, 2024
d1d0929
changeset
nedsalk Nov 28, 2024
65d4ed9
refactoring, commenting
nedsalk Nov 28, 2024
e160e74
Merge branch 'np/feat/abi-refactor' of github.com:FuelLabs/fuels-ts i…
petertonysmith94 Nov 29, 2024
be228d8
chore: favour `concreteTypeId`
petertonysmith94 Dec 2, 2024
ed43cd6
chore: fix up errors for the parser specification
petertonysmith94 Dec 2, 2024
52e22b3
docs: added error code
petertonysmith94 Dec 2, 2024
ef1484e
chore: nit
petertonysmith94 Dec 2, 2024
9b38b48
chore: attribute arguments always defined
petertonysmith94 Dec 2, 2024
bee8f28
chore: fix incorrect inline attribute arguments
petertonysmith94 Dec 2, 2024
06e70c1
Merge branch 'np/feat/abi-refactor' of github.com:FuelLabs/fuels-ts i…
petertonysmith94 Dec 2, 2024
b2d6bdc
chore: re-adjusted `mapAttribute`
petertonysmith94 Dec 3, 2024
2235308
chore: added helper functions for finding concreteTypes and metadataT…
petertonysmith94 Dec 3, 2024
f25c90b
chore: removed static methods + further `findConcreteType` + `findMet…
petertonysmith94 Dec 3, 2024
af93e03
Merge branch 'np/feat/abi-refactor' of github.com:FuelLabs/fuels-ts i…
petertonysmith94 Dec 3, 2024
fe56f53
chore: more verbose variable names
petertonysmith94 Dec 3, 2024
c3806b4
chore: constructor as first public method
petertonysmith94 Dec 5, 2024
400a93a
chore: rename `type` for `swayType`
petertonysmith94 Dec 5, 2024
a07a3b5
chore: removed `specVersion`
petertonysmith94 Dec 5, 2024
583fcc3
add comments
nedsalk Dec 6, 2024
da6384b
chore: added name to typeArguments
petertonysmith94 Dec 6, 2024
37d5567
Merge branch 'ns/feat/abi-parser' of github.com:FuelLabs/fuels-ts int…
nedsalk Dec 6, 2024
4c64f49
comments
nedsalk Dec 6, 2024
ca57c86
fix?
nedsalk Dec 6, 2024
a2118e2
fix?
nedsalk Dec 6, 2024
4d7a528
Merge branch 'master' of github.com:FuelLabs/fuels-ts into ns/feat/ab…
petertonysmith94 Dec 8, 2024
c2af71e
Merge branch 'master' of github.com:FuelLabs/fuels-ts into ns/feat/ab…
petertonysmith94 Dec 10, 2024
3fbb2d6
Merge branch 'np/feat/abi-refactor' of github.com:FuelLabs/fuels-ts i…
petertonysmith94 Dec 11, 2024
16c340e
chore: rollback to working state
petertonysmith94 Dec 11, 2024
2904381
refactoring
nedsalk Dec 12, 2024
c6a4a38
add test group
nedsalk Dec 12, 2024
a2fae3a
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Dec 12, 2024
cacbacf
revert changes
nedsalk Dec 12, 2024
799dce8
format projects
nedsalk Dec 12, 2024
d1ec960
export parser from fuels
nedsalk Dec 12, 2024
43ca2d0
cleanup
nedsalk Dec 12, 2024
55a88c7
renamings
nedsalk Dec 12, 2024
e4dfa53
renamings
nedsalk Dec 12, 2024
167e43d
add comments to `Abi`
nedsalk Dec 12, 2024
3a2cc1c
add docs
nedsalk Dec 12, 2024
c2bb0c6
update docs
nedsalk Dec 12, 2024
88b2224
rename test
nedsalk Dec 12, 2024
0dc80e4
rename to
nedsalk Dec 12, 2024
d658f80
formatting
nedsalk Dec 12, 2024
a8886b9
more explanations
nedsalk Dec 12, 2024
244f02c
cleaner
nedsalk Dec 12, 2024
238b4ad
formatting
nedsalk Dec 12, 2024
64ccd8d
comments
nedsalk Dec 12, 2024
9e33353
add double generic case
nedsalk Dec 12, 2024
4fddeca
fix test
nedsalk Dec 12, 2024
0434ecd
update changeset
nedsalk Dec 12, 2024
18e659f
revert
nedsalk Dec 12, 2024
dbf83c6
fix changeset
nedsalk Dec 12, 2024
e973ec7
Merge branch 'np/feat/abi-refactor' into ns/feat/abi-parser
nedsalk Dec 12, 2024
eff1232
not breaking
nedsalk Dec 12, 2024
7b6da13
fix test
nedsalk Dec 12, 2024
5ad1fdb
add import check
nedsalk Dec 12, 2024
733b559
fix linting
nedsalk Dec 12, 2024
7756375
fix lint
nedsalk Dec 12, 2024
2390cca
add comments to abi interface
nedsalk Dec 12, 2024
6287f87
Update .changeset/tender-tigers-fry.md
nedsalk Dec 12, 2024
dcd468a
fix changeset
nedsalk Dec 12, 2024
c9ffae1
add implicit generic edge case
nedsalk Dec 12, 2024
1d84672
feat: ABI Gen
nedsalk Dec 12, 2024
378e67e
fix storage slots and imports in tests
nedsalk Dec 13, 2024
b904bdf
fix linting
nedsalk Dec 13, 2024
0b01607
fix linting
nedsalk Dec 13, 2024
2feadf1
Update .changeset/poor-years-hang.md
nedsalk Dec 13, 2024
b446299
improve type arguments representation
nedsalk Dec 13, 2024
dea838d
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 13, 2024
e330aba
fix type arguments
nedsalk Dec 13, 2024
f526b04
explanatory comment
nedsalk Dec 13, 2024
1068197
move types to separate file
nedsalk Dec 13, 2024
972721b
move fixtures into folders
nedsalk Dec 13, 2024
b4a9fd5
move `mapComponents` and add explanations
nedsalk Dec 13, 2024
9aac5cb
move logic to shared folder
nedsalk Dec 13, 2024
55b481b
add type docs explaining functions
nedsalk Dec 13, 2024
09a9e97
add doc blocks for `AbiGen` and related types
nedsalk Dec 13, 2024
1703d8f
remove unnecessary flags
nedsalk Dec 13, 2024
30aaa43
remove todo
nedsalk Dec 13, 2024
e6ea6fa
input/output
nedsalk Dec 13, 2024
3671f0d
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 13, 2024
ab04c07
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 15, 2024
0225502
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 15, 2024
1445925
remove rawUntypedPtr
nedsalk Dec 15, 2024
23b1f03
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 16, 2024
9e7a266
made `abi` and `storage-slots` ts files
nedsalk Dec 16, 2024
cf65fbf
move from linting to cast
nedsalk Dec 16, 2024
7a0ae00
remove usage of `fuels-typegen`
nedsalk Dec 16, 2024
6b25941
change to `FuelError`
nedsalk Dec 16, 2024
3f06b38
simplify inputs/output types for script and predicate
nedsalk Dec 16, 2024
032b736
improve index file rendering
nedsalk Dec 16, 2024
ae86e26
export types from base program file (and thus index)
nedsalk Dec 16, 2024
6f79a26
cleanup type rendering
nedsalk Dec 16, 2024
67c5e38
simplified program rendering
nedsalk Dec 16, 2024
d4a7bf3
fix recipes
nedsalk Dec 16, 2024
c0f01f7
reorder deps
nedsalk Dec 16, 2024
3bf2df2
refactor render-index-files
nedsalk Dec 16, 2024
988c7ec
remove file
nedsalk Dec 16, 2024
e18240a
update changeset
nedsalk Dec 16, 2024
0b03ce5
fix changeset
nedsalk Dec 16, 2024
e03ae55
fix recipes build
nedsalk Dec 16, 2024
ab83ccc
fix test
nedsalk Dec 16, 2024
69dfcb7
cleanup
nedsalk Dec 16, 2024
ad36793
fix knip
nedsalk Dec 16, 2024
c280227
fix lint
nedsalk Dec 16, 2024
05a613a
export inputs, outputs and configurables
nedsalk Dec 16, 2024
e354ddc
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 17, 2024
1c7f6a1
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 17, 2024
92bae57
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 17, 2024
569e356
remove already included --silent flag
nedsalk Dec 23, 2024
e23571c
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Dec 23, 2024
5446c30
added non-happy paths testing
nedsalk Dec 24, 2024
fe159f6
mvoed cli into abi package
nedsalk Dec 26, 2024
403e2ca
cleanup
nedsalk Dec 26, 2024
143f356
export types from contract/predicate/script
nedsalk Dec 26, 2024
aa6b0af
improve upon index exports now that types are also re-exported
nedsalk Dec 26, 2024
ff6cbac
fix pnpm-lock.yaml
nedsalk Dec 26, 2024
632a46c
rename
nedsalk Dec 26, 2024
57902f3
fix recipes
nedsalk Dec 26, 2024
4feb731
log instead of throwing
nedsalk Dec 27, 2024
62323df
fix lint
nedsalk Dec 27, 2024
6a00878
add `forc` and `fuel-core` to path
nedsalk Dec 27, 2024
ab574c3
try again
nedsalk Dec 27, 2024
cddae24
try again
nedsalk Dec 27, 2024
a3a969d
fix lint
nedsalk Dec 27, 2024
ff22e94
Increase timeout
nedsalk Dec 27, 2024
c3a2b9a
cleanup
nedsalk Dec 30, 2024
a96bfa0
revert timeout
nedsalk Dec 30, 2024
9f3986d
Merge remote-tracking branch 'origin/ns/feat/abi-parser' into ns/feat…
nedsalk Dec 31, 2024
d4ccfe8
chore: use playwright in browser tests
nedsalk Jan 1, 2025
be77143
revert isolate flag for safety
nedsalk Jan 1, 2025
c1fefe4
Merge branch 'ns/chore/browser-tests-playwright' into ns/feat/abi-typ…
nedsalk Jan 1, 2025
f5768e9
Merge branch 'ns/feat/abi-parser' into ns/feat/abi-typegen
nedsalk Jan 2, 2025
423834c
revert some changes
nedsalk Jan 2, 2025
7643979
update docs
nedsalk Jan 2, 2025
1e51d6b
update imports
nedsalk Jan 2, 2025
81d61b9
revert file
nedsalk Jan 2, 2025
f8d45b7
revert input
nedsalk Jan 2, 2025
32e18a5
fix import
nedsalk Jan 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/poor-years-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/abi": minor
"fuels": minor
---

feat!: ABI Gen
6 changes: 6 additions & 0 deletions .github/actions/test-setup/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ runs:
with:
bun-version: ${{ inputs.bun-version }}

- name: Set forc and fuel-core paths
shell: bash
run: |
echo "$GITHUB_WORKSPACE/internal/forc/forc-binaries" >> $GITHUB_PATH
echo "$GITHUB_WORKSPACE/internal/fuel-core/fuel-core-binaries" >> $GITHUB_PATH

- name: Build
run: pnpm build
shell: bash
4 changes: 2 additions & 2 deletions apps/demo-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"forc:predicate": "pnpm fuels-forc build -p demo-predicate --release",
"build:types": "run-p types:*",
"types:contract": "pnpm fuels typegen -i demo-contract/out/release/demo-contract-abi.json -o src/contract-types",
"types:script": "pnpm fuels typegen -i demo-script/out/release/demo-script-abi.json -o src/script-types --script",
"types:predicate": "pnpm fuels typegen -i demo-predicate/out/release/demo-predicate-abi.json -o src/predicate-types --predicate"
"types:script": "pnpm fuels typegen -i demo-script/out/release/demo-script-abi.json -o src/script-types",
"types:predicate": "pnpm fuels typegen -i demo-predicate/out/release/demo-predicate-abi.json -o src/predicate-types"
},
"license": "Apache-2.0",
"dependencies": {
Expand Down
6 changes: 2 additions & 4 deletions apps/demo-typegen/src/demo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
import { toHex, Address, Wallet, FuelError, ErrorCode } from 'fuels';
import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils';

import storageSlots from '../demo-contract/out/release/demo-contract-storage_slots.json';

import { DemoContract, DemoContractFactory } from './contract-types';
import { DemoPredicate } from './predicate-types';
import type { DemoPredicateInputs } from './predicate-types/DemoPredicate';
import type { DemoPredicateInputs } from './predicate-types/predicates/DemoPredicate';
import { DemoScript } from './script-types';

/**
Expand All @@ -25,7 +23,7 @@ describe('ExampleContract', () => {
// #context import { DemoContractFactory } from './sway-programs-api';

const { waitForResult } = await DemoContractFactory.deploy(wallet, {
storageSlots,
storageSlots: DemoContractFactory.storageSlots,
});

const { contract } = await waitForResult();
Expand Down
9 changes: 2 additions & 7 deletions apps/docs/src/guide/contracts/snippets/proxy-contracts.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
// #region proxy-2
import {
Provider,
Wallet,
Src14OwnedProxy,
Src14OwnedProxyFactory,
} from 'fuels';
import { Provider, Wallet, Src14OwnedProxyFactory } from 'fuels';

import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../env';
import {
Expand All @@ -28,7 +23,7 @@ const { contract: counterContract } = await deploy.waitForResult();
* initialize the storage slots.
*/
const storageSlots = counterContractFactory.storageSlots.concat(
Src14OwnedProxy.storageSlots
Src14OwnedProxyFactory.storageSlots
);
/**
* These configurables are specific to our recommended SRC14 compliant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
import { Provider, Wallet } from 'fuels';

import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env';
import {
StorageTestContract,
StorageTestContractFactory,
} from '../../../../typegend';
import { StorageTestContractFactory } from '../../../../typegend';

const provider = await Provider.create(LOCAL_NETWORK_URL);
const deployer = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);

const deploymentTx = await StorageTestContractFactory.deploy(deployer, {
storageSlots: StorageTestContract.storageSlots,
storageSlots: StorageTestContractFactory.storageSlots,
});

await deploymentTx.waitForResult();
Expand Down
5 changes: 1 addition & 4 deletions apps/docs/src/guide/fuels-cli/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ npx fuels@{{fuels}} build
```

1. Build all Sway programs under your `workspace` using `forc` <sup>[1](https://docs.fuel.network/docs/forc/commands/forc_build/)</sup>
1. Generate types for them using `fuels-typegen` <sup>[2](#fuels-typegen)</sup>
1. Generate types for them using `fuels typegen` <sup>[2](#fuels-typegen)</sup>

```console-vue
npx fuels@{{fuels}} build --deploy
Expand Down Expand Up @@ -157,9 +157,6 @@ npx fuels@{{fuels}} help typegen
Options:
-i, --inputs <path|glob...> Input paths/globals to your Abi JSON files
-o, --output <dir> Directory path for generated files
-c, --contract Generate types for Contracts [default]
-s, --script Generate types for Scripts
-p, --predicate Generate types for Predicates
-S, --silent Omit output messages
```

Expand Down
32 changes: 7 additions & 25 deletions apps/docs/src/guide/fuels-cli/generating-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,15 @@ Generate Typescript from Sway ABI JSON files
Options:
-i, --inputs <path|glob...> Input paths/globals to your ABI JSON files
-o, --output <dir> Directory path for generated files
-c, --contract Generate types for Contracts [default]
-s, --script Generate types for Scripts
-p, --predicate Generate types for Predicates
-S, --silent Omit output messages
-h, --help Display help
```

## Generating Types for Contracts
## Generating Types

You can generate types for a Sway contract using the command below:
You can generate types for a Sway program using the command below:

<!-- This section should have the command to generate types for a Sway contract -->
<!-- This section should have the command to generate types for a Sway program -->
<!-- gen_types:example:start -->

```console
Expand All @@ -50,30 +47,15 @@ pnpm fuels typegen -i ./abis/*-abi.json -o ./types
<!-- This section should explain the flags used in the typegen command -->
<!-- flags:example:start -->

The path after the input flag `-i` should point to the file ending in `-abi.json` produced when the contract was built.
The path after the input flag `-i` should point to the file ending in `-abi.json` produced when the Sway program was built.

The path after the output flag `-o` will be the output directory for the generated types.
- For scripts and predicates, you'll need the bytecode of the program to be in the same folder for the command to work.
- For contracts, the command will work without the bytecode but the corresponding `ContractFactory` file won't be generated as factories need the bytecode to operate.

You can omit the `--contract` option here since it's the default.
The path after the output flag `-o` will be the output directory for the generated types.

<!-- flags:example:end -->

## Generating Types for Scripts

To generate types for a Sway script, use the `--script` flag:

```console
pnpm fuels typegen -i ./abis/*-abi.json -o ./types --script
```

## Generating Types for Predicates

To generate types for a Sway predicate, use the `--predicate` flag:

```console
pnpm fuels typegen -i ./abis/*-abi.json -o ./types --predicate
```

---

See also:
Expand Down
4 changes: 2 additions & 2 deletions apps/docs/src/guide/fuels-cli/using-generated-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Typegen tries to resolve, auto-load, and embed the [Storage Slots](../contracts/
After generating types via:

```console
pnpm fuels typegen -i ./abis/*-abi.json -o ./types --script
pnpm fuels typegen -i ./abis/*-abi.json -o ./types
```

We can use these files like so:
Expand All @@ -41,7 +41,7 @@ We can use these files like so:
After generating types via:

```console
pnpm fuels typegen -i ./abis/*-abi.json -o ./types --predicate
pnpm fuels typegen -i ./abis/*-abi.json -o ./types
```

We can use these files like so:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Provider, Wallet } from 'fuels';

import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env';
import { EchoEnumFactory } from '../../../../typegend';
import { UserErrorInput } from '../../../../typegend/contracts/EchoEnum';
import { UserError } from '../../../../typegend/contracts/EchoEnum';

const provider = await Provider.create(LOCAL_NETWORK_URL);
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);
const deploy = await EchoEnumFactory.deploy(wallet);
const { contract } = await deploy.waitForResult();

// #region snippet-1
const enumParam = { UserError: UserErrorInput.InsufficientPermissions };
const enumParam = { UserError: UserError.InsufficientPermissions };

const { value } = await contract.functions.echo_error_enum(enumParam).get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { Provider, Wallet } from 'fuels';

import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env';
import { EchoEnumFactory } from '../../../../typegend';
import { StateErrorInput } from '../../../../typegend/contracts/EchoEnum';
import { StateError } from '../../../../typegend/contracts/EchoEnum';

const provider = await Provider.create(LOCAL_NETWORK_URL);
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);
const deploy = await EchoEnumFactory.deploy(wallet);
const { contract } = await deploy.waitForResult();

// #region snippet-1
const enumParam = { StateError: StateErrorInput.Completed };
const enumParam = { StateError: StateError.Completed };

const { value } = await contract.functions.echo_error_enum(enumParam).get();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import { Provider, Wallet } from 'fuels';

import { LOCAL_NETWORK_URL, WALLET_PVT_KEY } from '../../../../env';
import { EchoEnumFactory } from '../../../../typegend';
import { StateErrorInput } from '../../../../typegend/contracts/EchoEnum';
import { StateError } from '../../../../typegend/contracts/EchoEnum';

const provider = await Provider.create(LOCAL_NETWORK_URL);
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);
const deploy = await EchoEnumFactory.deploy(wallet);
const { contract } = await deploy.waitForResult();

const enumParam = StateErrorInput.Completed;
const enumParam = StateError.Completed;

const { value } = await contract.functions
.echo_state_error_enum(enumParam)
Expand Down
3 changes: 0 additions & 3 deletions packages/abi-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
"version": "0.97.2",
"description": "Generates Typescript definitions from Sway ABI Json files",
"author": "Fuel Labs <contact@fuel.sh> (https://fuel.network/)",
"bin": {
"fuels-typegen": "typegen.js"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
21 changes: 20 additions & 1 deletion packages/abi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,26 @@
"engines": {
"node": "^18.20.3 || ^20.0.0 || ^22.0.0"
},
"bin": {
"fuels-typegen": "typegen.js"
},
"exports": {
".": {
"require": "./dist/index.js",
"import": "./dist/index.mjs",
"types": "./dist/index.d.ts"
},
"./cli": {
"types": "./dist/cli.d.ts",
"require": "./dist/cli.js",
"import": "./dist/cli.mjs"
}
},
"typesVersions": {
"*": {
"cli": [
"./dist/cli.d.ts"
]
}
},
"files": [
Expand All @@ -27,7 +42,11 @@
},
"dependencies": {
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/utils": "workspace:*"
"@fuel-ts/utils": "workspace:*",
"@fuel-ts/versions": "workspace:*",
"handlebars": "^4.7.8",
"commander": "12.1.0",
"glob": "^10.4.5"
},
"devDependencies": {}
}
15 changes: 15 additions & 0 deletions packages/abi/src/bin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getBinaryVersions } from '@fuel-ts/versions/cli';
import { Command } from 'commander';

import { configureTypegenCliOptions } from './cli';

const program = new Command();

program.name('fuels-typegen');
program.version(getBinaryVersions().FUELS);
program.usage(`-i ../out/*-abi.json -o ./generated/`);
program.option('-S, --silent', 'Omit output messages', false);

configureTypegenCliOptions(program);

program.parse(process.argv);
1 change: 1 addition & 0 deletions packages/abi/src/cli.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './gen/cli';
56 changes: 55 additions & 1 deletion packages/abi/src/gen/abi-gen-types.ts
Original file line number Diff line number Diff line change
@@ -1 +1,55 @@
// Placeholder
import type { BinaryVersions } from '@fuel-ts/versions';

import type { Abi } from '../parser';

export interface AbiGenInput {
/**
* The details of the program to generate the files for.
*/
programDetails: ProgramDetails[];
/**
* The versions of the binaries used to generate the files.
*/
versions: BinaryVersions;
/**
* The mode to generate the files in.
* Defaults to 'ts' which generates typescript files.
*/
mode?: 'ts';
}

export interface AbiGenResult {
/**
* The filename of the generated file.
*/
filename: string;
/**
* The content of the generated file.
*/
content: string;
}

export interface ProgramDetails {
/**
* The name of the program to generate files for.
* This will be used to name the generated files,
* as well as throughout the generated code.
*/
name: string;
/**
* The compressed bytecode of the program in base64 format.
*/
binCompressed?: string;
/**
* The abi of the program in the format returned via `AbiParser`.
*/
abi: Abi;
/**
* The original abi contents in string format.
*/
abiContents: string;
/**
* The storage slots, if working with a contract.
*/
storageSlots?: string;
}
20 changes: 19 additions & 1 deletion packages/abi/src/gen/abi-gen.ts
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
export class AbiGen {}
import type { AbiGenInput, AbiGenResult } from './abi-gen-types';
import { getRenderer } from './renderers/getRenderer';

/**
* The main class to generate files for given sway programs.
* These contents of these generated files make it easier to interact
* with the sway programs, because type definitions are added,
* as well as some automatic loading is done for the user.
*/
export class AbiGen {
/**
* @returns an array of generated files for the given program details.
* They can be saved to disk as-is or further processed.
*/
public static generate({ programDetails, mode, versions }: AbiGenInput): AbiGenResult[] {
const render = getRenderer(mode);
return render(programDetails, versions);
}
}
1 change: 1 addition & 0 deletions packages/abi/src/gen/cli/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { configureTypegenCliOptions, runTypegen } from './run';
Loading
Loading