Skip to content

Commit

Permalink
Merge branch 'db/docs/tx-speed' into aa/docs/tx-speed-touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
arboleya authored Jan 10, 2025
2 parents a5bb499 + 5d68edc commit 06c3a87
Show file tree
Hide file tree
Showing 51 changed files with 1,419 additions and 3,587 deletions.
7 changes: 7 additions & 0 deletions .changeset/khaki-candles-beg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@fuel-ts/account": minor
"@fuel-ts/program": minor
"@fuel-ts/script": patch
---

docs!: optimizing frontend apps
5 changes: 5 additions & 0 deletions .changeset/sharp-islands-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fuel-ts/account": patch
---

feat: added `onBeforeSend` hook to the connector interface
5 changes: 5 additions & 0 deletions .changeset/spicy-oranges-worry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"fuels": patch
---

fix: usage of `providerUrl` in `fuels dev` command
4 changes: 4 additions & 0 deletions .changeset/stupid-jokes-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
---

chore: add script for network testing
6 changes: 6 additions & 0 deletions .changeset/wild-avocados-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": minor
"@fuel-ts/errors": patch
---

feat!: prevent implicit asset burn
9 changes: 9 additions & 0 deletions .changeset/witty-mice-lick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"@fuel-ts/contract": patch
"@fuel-ts/crypto": patch
"fuels": patch
"create-fuels": patch
"@fuel-ts/script": patch
---

chore: remove unused deps + update knip config
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DEVNET_WALLET_PVT_KEY=
TESTNET_WALLET_PVT_KEY=
PUBLISHED_NPM_TAG=
PUBLISHED_NPM_TAG=
NETWORK_TEST_URL=
NETWORK_TEST_PVT_KEY=
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @digorithm @arboleya @Torres-ssf @danielbate @nedsalk @petertonysmith94 @maschad
* @digorithm @arboleya @Torres-ssf @danielbate @nedsalk @petertonysmith94
33 changes: 9 additions & 24 deletions .knip.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
{
"ignore": [
".github/**",
"**/*/fuels.config.*",
"**/*/.vitepress/*",
"/apps/docs/*",
"/packages/abi-typegen/test/**",
"templates/**",
"/apps/docs/**/*.test.ts",
"apps/create-fuels-counter-guide/**",
"apps/docs-api/**"
"entry": [
"apps/docs/src/versions.data.ts",
"apps/docs/src/guide/types/snippets/numbers/for-u8-u16-and-u32-2.ts"
],
"ignore": [".github/**"],
"ignoreDependencies": [
"autocannon",
"fuels",
"bun",
"@/sway-api/*",
"@fuel-ts/*",
"@fuels/connectors",
"@internal/fuel-core",
"@internal/forc",
"@types/jest",
"@types/rimraf",
"@graphql-codegen*",
"graphql-tag",
"@fuel-ts/abi-typegen",
"@internal/fuel-core",
"get-graphql-schema",
"events",
"eslint-plugin-jsdoc",
Expand All @@ -30,14 +18,11 @@
"eslint-plugin-react",
"eslint-plugin-react-hooks",
"dotenv",
"ethers",
"kill",
"lsof",
"memfs",
"open",
"markdown-link-check",
"ts-generator",
"webdriverio",
"syncpack"
"vitepress-plugin-search",
"vue"
]
}
42 changes: 34 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,6 @@ pnpm bench:node
pnpm bench:node packages/my-desired-package
```

# Profiling

We currently use [`clinic`](https://clinicjs.org/) to profile and debug our tooling. For instance you can run clinic's flame command to create a flamegraph for a specific package:

```sh
# creates a flamegraph for a specific package
npm_config_package_name=account pnpm clinic:flame // runs flame against the account package
```

### CI Test

Expand Down Expand Up @@ -369,6 +361,40 @@ We'd follow the same approach as explained in the [Patching old releases](#patch
- have the versions of packages on `master` match the `latest` released package versions,
- have the released functionality on `master` as well

# Network Testing

The network test suite is designed to run locally against a specified network for validation purposes.

You can find the test suite at: `packages/fuel-gauge/src/network.test.ts`.

### Setup Instructions

Before running the tests, you need to configure the `.env` file:

1. Copy the `.env.example` file:

```sh
cp .env.example .env
```

2. Set the values for the following environment variables in the `.env` file:

```env
NETWORK_TEST_URL=https://testnet.fuel.network/v1/graphql
NETWORK_TEST_PVT_KEY=0x...
```

- `NETWORK_TEST_URL`: The URL of which network the test should run (e.g., Fuel Testnet endpoint).
- `NETWORK_TEST_PVT_KEY`: Your private key for the network.

### Running the Test Suite

Once the environment is set up, run the network tests using the following command:

```sh
pnpm test:network
```

# FAQ

### Why is the prefix `fuels` and not `fuel`?
Expand Down
4 changes: 1 addition & 3 deletions apps/create-fuels-counter-guide/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"test:ui": "sh ./test/ui/test-ui.sh",
"original:dev": "vite",
"original:build": "tsc -b && vite build",
"original:start": "next start",
"original:start": "vite start",
"original:lint": "eslint .",
"fuels:build": "fuels build",
"fuels:dev": "fuels dev",
Expand All @@ -18,8 +18,6 @@
"@fuels/react": "0.36.1",
"@tanstack/react-query": "5.55.4",
"clsx": "2.1.1",
"@wagmi/connectors": "5.1.14",
"@wagmi/core": "2.13.9",
"dotenv": "16.4.5",
"fuels": "workspace:*",
"react": "18.3.1",
Expand Down
2 changes: 0 additions & 2 deletions apps/demo-bun-fuels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
},
"license": "Apache-2.0",
"dependencies": {
"@fuel-ts/account": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"fuels": "workspace:*"
},
"devDependencies": {
Expand Down
2 changes: 0 additions & 2 deletions apps/demo-fuels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
},
"license": "Apache-2.0",
"dependencies": {
"@fuel-ts/errors": "workspace:*",
"@fuel-ts/account": "workspace:*",
"fuels": "workspace:*"
}
}
2 changes: 0 additions & 2 deletions apps/demo-typegen/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
"fuels": "workspace:*"
},
"devDependencies": {
"@fuel-ts/account": "workspace:*",
"@fuel-ts/errors": "workspace:*",
"@internal/forc": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion apps/docs/.vitepress/plugins/codeInContextPlugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
CodeSnippetToken,
} from './codeInContextPlugin';
import MarkdownIt from 'markdown-it';
import Token from 'markdown-it/lib/token';
import { Token } from 'markdown-it';

/**
* @group node
Expand Down
1 change: 1 addition & 0 deletions apps/docs/fuels.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export default createConfig({
forcBuildFlags: ['--release'],
forcPath: 'fuels-forc',
fuelCorePath: 'fuels-core',
fuelCorePort: 0,
});
6 changes: 1 addition & 5 deletions apps/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
"dev": "nodemon --config nodemon.config.json -x 'run-s build:snippets dev:docs'",
"build": "run-s build:snippets build:docs",
"preview": "run-s build:snippets preview:docs",
"pretest": "./scripts/pretest.sh",
"test": "cd ../.. && pnpm run test:filter apps/docs",
"build:snippets": "run-s wrap:snippets build:forc",
"build:docs": "vitepress build",
"preview:docs": "vitepress preview",
"dev:docs": "vitepress dev",
"wrap:snippets": "tsx ./scripts/wrap-snippets.ts",
"build:forc": "pnpm fuels build",
"build:forc": "pnpm fuels build --deploy",
"type:check": "pnpm tsc --noEmit --project tsconfig.emit.json"
},
"keywords": [],
Expand All @@ -29,12 +28,9 @@
},
"devDependencies": {
"@types/markdown-it": "14.1.2",
"@vue/devtools-api": "6.6.3",
"flexsearch": "0.7.43",
"glob": "10.4.5",
"markdown-it": "14.1.0",
"nodemon": "3.1.7",
"replace": "1.2.2",
"vitepress-plugin-search": "1.0.4-alpha.22",
"vitepress": "1.3.4",
"vue": "3.5.12"
Expand Down
16 changes: 0 additions & 16 deletions apps/docs/scripts/pretest.sh

This file was deleted.

6 changes: 6 additions & 0 deletions apps/docs/src/guide/errors/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ When an [`Account`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_accoun

It could be caused during the deployments of contracts when an account is required to sign the transaction. This can be resolved by following the deployment guide [here](../contracts/deploying-contracts.md).

### `ASSET_BURN_DETECTED`

When you are trying to send a transaction that will result in an asset burn.

Add relevant coin change outputs to the transaction, or enable asset burn in the transaction request.

### `CONFIG_FILE_NOT_FOUND`

When a configuration file is not found. This could either be a `fuels.config.[ts,js,mjs,cjs]` file or a TOML file.
Expand Down
30 changes: 16 additions & 14 deletions apps/docs/src/guide/getting-started/react-example.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,22 @@ function App() {

const NETWORK_URL = "https://mainnet.fuel.network/v1/graphql";
const provider = new Provider(NETWORK_URL);
const wallet = Wallet.generate({ provider });
const wallet = Wallet.fromAddress("0x...", provider);

const prePrepareTransaction = async () => {
const recipient = Wallet.generate({ provider });
const newRequest = new ScriptTransactionRequest();
newRequest.addCoinOutput(
recipient.address,
1_000,
await provider.getBaseAssetId(),
);
await newRequest.estimateAndFund(wallet);
setRequest(newRequest);
};

useEffect(() => {
const onPageLoad = async () => {
const recipient = Wallet.generate({ provider });
const newRequest = new ScriptTransactionRequest();
newRequest.addCoinOutput(
recipient.address,
1_000,
await provider.getBaseAssetId(),
);
await newRequest.estimateAndFund(wallet);
setRequest(newRequest);
};

onPageLoad();
prePrepareTransaction();
}, []);

const handleSubmit = async () => {
Expand All @@ -74,6 +74,8 @@ function App() {

const result = await response.waitForResult();
setStatus(`Settled - ${result.id}`);

prePrepareTransaction();
};

return (
Expand Down
9 changes: 8 additions & 1 deletion apps/docs/src/guide/transactions/modifying-the-request.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ The other more manual approach is as so:

<<< @./snippets/transaction-request/get-transaction-cost.ts#transaction-request-4{ts:line-numbers}

// For a more manual implementation....

This approach provides the same behaviour as the `estimateAndFund` helper, but gives more granular control over the transaction request. The `getTransactionCost` method also returns various information about the simulated request that you may want to use to further modify the transaction request, more on that can be found in the [API reference](https://fuels-ts-docs-api.vercel.app/types/_fuel_ts_account.TransactionCost.html).

Expand Down Expand Up @@ -99,3 +98,11 @@ The transaction ID is a SHA-256 hash of the entire transaction request. This can
<<< @./snippets/transaction-request/add-witness.ts#transaction-request-11{ts:line-numbers}

> **Note**: Any changes made to a transaction request will alter the transaction ID. Therefore, you should only get the transaction ID after all modifications have been made.
### Burning assets

Assets can be burnt as part of a transaction that has inputs without associated output change. The SDK validates against this behavior, so we need to explicitly enable this by sending the transaction with the `enableAssetBurn` option set to `true`.

<<< @./snippets/transaction-request/asset-burn.ts#asset-burn{ts:line-numbers}

> **Note**: Burning assets is permanent and all assets burnt will be lost. Therefore, be mindful of the usage of this functionality.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { InputType, Provider, ScriptTransactionRequest, Wallet } from 'fuels';
import { ASSET_A } from 'fuels/test-utils';

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

const provider = new Provider(LOCAL_NETWORK_URL);
const sender = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);

// #region asset-burn
const transactionRequest = new ScriptTransactionRequest();

const {
coins: [coin],
} = await sender.getCoins(ASSET_A);

// Add the coin as an input, without a change output
transactionRequest.inputs.push({
id: coin.id,
type: InputType.Coin,
owner: coin.owner.toB256(),
amount: coin.amount,
assetId: coin.assetId,
txPointer: '0x00000000000000000000000000000000',
witnessIndex:
transactionRequest.getCoinInputWitnessIndexByOwner(coin.owner) ??
transactionRequest.addEmptyWitness(),
});

// Fund the transaction
await transactionRequest.estimateAndFund(sender);

// Send the transaction with asset burn enabled
const tx = await sender.sendTransaction(transactionRequest, {
enableAssetBurn: true,
});
// #endregion asset-burn

const { isStatusSuccess } = await tx.waitForResult();
console.log('Transaction should have been successful', isStatusSuccess);
Loading

0 comments on commit 06c3a87

Please sign in to comment.