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 refactor #3085

Draft
wants to merge 53 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
c041f20
chore: added @fuel-ts/abi package
petertonysmith94 Sep 3, 2024
cb48d9c
chore: added basic folder structure
petertonysmith94 Sep 3, 2024
74a6f50
chore: added ignore to changeset
petertonysmith94 Sep 3, 2024
0736344
chore: changeset
petertonysmith94 Sep 3, 2024
584d354
chore: changeset
petertonysmith94 Sep 3, 2024
f63a171
chore: added missing index file
petertonysmith94 Sep 3, 2024
a618c89
scaffold cleanup
nedsalk Sep 3, 2024
d74786a
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into np…
petertonysmith94 Sep 4, 2024
8e58b23
chore: added basic test infrastructure (#3090)
petertonysmith94 Sep 4, 2024
a5eeaef
Merge branch 'master' into np/feat/abi-refactor
petertonysmith94 Sep 10, 2024
ed8e598
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Sep 12, 2024
882a0a2
feat: sway type matchers (#3137)
nedsalk Sep 12, 2024
c3a9b6f
chore: added start of line to ABI regex matchers (#3163)
petertonysmith94 Sep 13, 2024
09cddf0
Merge branch 'master' of https://github.com/FuelLabs/fuels-ts into np…
petertonysmith94 Sep 16, 2024
8eb9316
chore: consolidate all ABI Sway programs (#3171)
petertonysmith94 Sep 16, 2024
8235b4e
chore: separate minor and major versions (#3170)
petertonysmith94 Sep 16, 2024
5e55da8
chore: inform users if their `fuels` version is outdated (#3108)
Dhaiwat10 Sep 16, 2024
7096791
fix: some assets got assetId, contractId and decimals incorrect (#3167)
LuizAsFight Sep 16, 2024
dc0db20
build(deps): bump the deps-patch group (#3173)
dependabot[bot] Sep 16, 2024
e6b6af9
fix: add missing receipts properties (#3156)
Torres-ssf Sep 16, 2024
7e3b66c
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Sep 17, 2024
bd79318
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Sep 25, 2024
540d4e2
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Sep 28, 2024
3659e50
update proxy contract
nedsalk Oct 3, 2024
976c1bd
feat: add missing matcher (#3247)
nedsalk Oct 6, 2024
3605a1c
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Oct 11, 2024
052e7d7
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Oct 15, 2024
43e6c6e
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Oct 23, 2024
0e5e9cb
Merge branch 'master' into np/feat/abi-refactor
nedsalk Oct 24, 2024
691f3c0
Merge branch 'master' into np/feat/abi-refactor
petertonysmith94 Nov 18, 2024
bd647b3
Merge branch 'master' of github.com:FuelLabs/fuels-ts into np/feat/ab…
petertonysmith94 Nov 25, 2024
7611c55
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Nov 27, 2024
97c03f4
chore: added errors for matchers
petertonysmith94 Nov 27, 2024
ee79c21
chore: added matcher to spell check
petertonysmith94 Nov 27, 2024
c5bfa0a
chore: added errors dep
petertonysmith94 Nov 27, 2024
fb5e04d
Merge branch 'master' of github.com:FuelLabs/fuels-ts into np/feat/ab…
petertonysmith94 Nov 29, 2024
0d33661
Merge branch 'master' of github.com:FuelLabs/fuels-ts into np/feat/ab…
petertonysmith94 Dec 2, 2024
8ce4810
Merge branch 'master' of github.com:FuelLabs/fuels-ts into np/feat/ab…
petertonysmith94 Dec 3, 2024
57014d5
Merge branch 'master' of github.com:FuelLabs/fuels-ts into np/feat/ab…
petertonysmith94 Dec 9, 2024
7ca0689
Merge branch 'master' of github.com:FuelLabs/fuels-ts into np/feat/ab…
petertonysmith94 Dec 11, 2024
ed95764
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Dec 12, 2024
bff8061
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Dec 12, 2024
1390116
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Dec 16, 2024
74ad20c
Merge branch 'master' into np/feat/abi-refactor
nedsalk Dec 31, 2024
31ddb12
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Jan 2, 2025
508991b
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Jan 8, 2025
5bd8378
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Jan 8, 2025
86b7109
Merge remote-tracking branch 'origin/master' into np/feat/abi-refactor
nedsalk Jan 13, 2025
9a86b31
remove unused dependency
nedsalk Jan 13, 2025
21ac698
fix lock file
nedsalk Jan 14, 2025
6962abb
Merge branch 'master' of github.com:FuelLabs/fuels-ts into np/feat/ab…
petertonysmith94 Jan 22, 2025
44f6590
feat: ABI parser (#3089)
nedsalk Jan 22, 2025
9ec45f9
feat!: ABI Gen (#3249)
petertonysmith94 Jan 22, 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
4 changes: 4 additions & 0 deletions .changeset/flat-roses-lie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

feat: ABI refactor
Copy link
Contributor Author

@petertonysmith94 petertonysmith94 Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

This is not to be merged until we've concluded development

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
7 changes: 7 additions & 0 deletions .changeset/tender-tigers-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fuel-ts/abi": patch
"fuels": patch
"@fuel-ts/errors": patch
---

feat: ABI parser
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
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ jobs:
PUBLISHED_NPM_TAG: next

e2e:
if: false
runs-on: ubuntu-latest
timeout-minutes: 25
needs: [environments]
Expand Down
2 changes: 1 addition & 1 deletion .knip.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"fuels",
"bun",
"@types/rimraf",
"@fuel-ts/abi-typegen",
"@fuel-ts/abi",
"@internal/fuel-core",
"get-graphql-schema",
"events",
Expand Down
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
3 changes: 3 additions & 0 deletions apps/docs-api/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

# Modules

<!-- TODO: uncomment once deployed -->
<!-- - [abi](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_abi.html) -->

- [abi-coder](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_abi_coder.html)
- [abi-typegen](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_abi_typegen.html)
- [account](https://fuels-ts-docs-api.vercel.app/modules/_fuel_ts_account.html)
Expand Down
1 change: 1 addition & 0 deletions apps/docs-api/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"$schema": "https://typedoc.org/schema.json",
"entryPointStrategy": "packages",
"entryPoints": [
"../../packages/abi",
"../../packages/abi-coder",
"../../packages/abi-typegen",
"../../packages/address",
Expand Down
4 changes: 4 additions & 0 deletions apps/docs/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ export default defineConfig({
text: 'Optimized React Example',
link: '/guide/cookbook/optimized-react-example',
},
{
text: 'Working with the ABI',
link: '/guide/cookbook/working-with-the-abi',
},
],
},
{
Expand Down
3 changes: 2 additions & 1 deletion apps/docs/spell-check-custom-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,5 @@ Workspaces
WSL
XOR
XORs
YAML
YAML
matcher
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 = new Provider(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
9 changes: 9 additions & 0 deletions apps/docs/src/guide/cookbook/snippets/parsing-the-abi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// #region full
import { AbiParser } from 'fuels';
import type { Abi, AbiSpecificationV1 } from 'fuels';

import { Counter } from '../../../typegend';

const parsedAbi: Abi = AbiParser.parse(Counter.abi as AbiSpecificationV1);
// #endregion full
console.log('Parsed ABI:', parsedAbi);
11 changes: 11 additions & 0 deletions apps/docs/src/guide/cookbook/working-with-the-abi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Working with the ABI

Building a Sway program with `forc build` outputs multiple files, one of which is a JSON representation of the program's ABI. Because ABI specifications can change from one `forc` version to another, working directly with the ABI is cumbersome due to having to manage all ABI specification versions in order to ensure proper functionality.

<!-- TODO: fix links once it's live -->
<!-- AbiParser: https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_abi.AbiParser.html-->
<!-- ABI: https://fuels-ts-docs-api.vercel.app/interfaces/_fuel_ts_abi.Abi.html -->

To mitigate this, The SDK provides [`AbiParser`](#working-with-the-abi) which can parse all ABI specification versions and output an object that conforms to the [`Abi`](#working-with-the-abi) interface. The SDK also internally uses this `Abi` interface for implementing its encoding/decoding and TS type generation.

<<< @./snippets/parsing-the-abi.ts#full{ts:line-numbers}
12 changes: 12 additions & 0 deletions apps/docs/src/guide/errors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ When the arguments supplied to the function do not match the minimum required in

Check that the arguments supplied to the function match the required type.

### `ABI_SPECIFICATION_INVALID`

When the ABI specification provided is invalid.

Check that the ABI specification is valid.

### `ACCOUNT_REQUIRED`

When an [`Account`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_account.Account.html) is required for an operation. This will usually be in the form of a [`Wallet`](../wallets/index.md).
Expand Down Expand Up @@ -324,6 +330,12 @@ In cases where the error hasn't been mapped yet, this code will be used.

If you believe you found a bug, please report the [issue](https://github.com/FuelLabs/fuels-ts/issues/new/choose) to the team.

### `MATCHER_NOT_FOUND`

When a matcher is not found for a given Sway type.

Check that the Sway type is correct and exists in the ABI.

### `MAX_INPUTS_EXCEEDED`

When the number of transaction inputs exceeds the maximum limit allowed by the blockchain.
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 @@ -79,7 +79,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 @@ -167,9 +167,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 = new Provider(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 = new Provider(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 = new Provider(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
6 changes: 6 additions & 0 deletions internal/check-imports/src/references.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,16 @@ import {
arrayify,
hexlify,
createConfig,
AbiParser,
} from 'fuels';

const { log } = console;

/**
* abi
*/
log(AbiParser);

/**
* abi-coder
*/
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.98.0",
"description": "Generates Typescript definitions from Sway ABI Json files",
"author": "Fuel Labs <[email protected]> (https://fuel.network/)",
"bin": {
"fuels-typegen": "typegen.js"
},
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
Expand Down
Loading
Loading