From c6895b68ea6dd9677339abc249ccf096b43e7c35 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Thu, 2 Jan 2025 12:17:34 +0000 Subject: [PATCH 1/4] chore: bumped `@fuels/*` deps to `0.36.1` (#3511) * chore: bumped @fuels/connectors + @fuels/react versions * chore: changeset * chore: release * chore: removed await from provider instantiation * chore: remove release flag * chore: fixed transaction url * chore: removed hardcoded network --- .changeset/clever-bikes-itch.md | 5 + apps/create-fuels-counter-guide/package.json | 4 +- apps/create-fuels-counter-guide/src/lib.tsx | 3 +- apps/create-fuels-counter-guide/src/main.tsx | 10 +- apps/demo-wallet-sdk-react/package.json | 4 +- pnpm-lock.yaml | 349 +++++++++---------- templates/nextjs/package.json | 4 +- templates/nextjs/src/app/layout.tsx | 13 +- templates/nextjs/src/lib.tsx | 2 +- templates/vite/package.json | 4 +- templates/vite/src/lib.tsx | 2 +- templates/vite/src/main.tsx | 12 +- 12 files changed, 202 insertions(+), 210 deletions(-) create mode 100644 .changeset/clever-bikes-itch.md diff --git a/.changeset/clever-bikes-itch.md b/.changeset/clever-bikes-itch.md new file mode 100644 index 00000000000..928b49a6c27 --- /dev/null +++ b/.changeset/clever-bikes-itch.md @@ -0,0 +1,5 @@ +--- +"create-fuels": patch +--- + +chore: bumped `@fuels/*` deps to `0.36.1` diff --git a/apps/create-fuels-counter-guide/package.json b/apps/create-fuels-counter-guide/package.json index deba01e8324..5d7b658ef34 100644 --- a/apps/create-fuels-counter-guide/package.json +++ b/apps/create-fuels-counter-guide/package.json @@ -14,8 +14,8 @@ "postbuild": "run-s fuels:build original:build" }, "dependencies": { - "@fuels/connectors": "^0.27.1", - "@fuels/react": "^0.27.1", + "@fuels/connectors": "^0.36.1", + "@fuels/react": "^0.36.1", "@tanstack/react-query": "^5.55.4", "clsx": "2.1.1", "@wagmi/connectors": "^5.1.14", diff --git a/apps/create-fuels-counter-guide/src/lib.tsx b/apps/create-fuels-counter-guide/src/lib.tsx index cd4fbd76e68..f01d5ca33e1 100644 --- a/apps/create-fuels-counter-guide/src/lib.tsx +++ b/apps/create-fuels-counter-guide/src/lib.tsx @@ -11,6 +11,7 @@ export const isTestnet = environment === environments.TESTNET; export const localProviderUrl = `http://127.0.0.1:${process.env.VITE_FUEL_NODE_PORT || 4000}/v1/graphql`; export const testnetProviderUrl = 'https://testnet.fuel.network/v1/graphql'; export const providerUrl = isLocal ? localProviderUrl : testnetProviderUrl; +export const chainId = 0; // Local and testnet are both on chain 0 export const playgroundUrl = providerUrl.replace('v1/graphql', 'v1/playground'); // #region deploying-dapp-to-testnet-frontend-contract-id @@ -28,7 +29,7 @@ export const renderTransactionId = (transactionId: string) => { return ( - + diff --git a/apps/demo-wallet-sdk-react/package.json b/apps/demo-wallet-sdk-react/package.json index 80f73573e3d..5484a2e69cb 100644 --- a/apps/demo-wallet-sdk-react/package.json +++ b/apps/demo-wallet-sdk-react/package.json @@ -9,8 +9,8 @@ "lint": "next lint" }, "dependencies": { - "@fuels/connectors": "^0.27.1", - "@fuels/react": "^0.27.1", + "@fuels/connectors": "^0.36.1", + "@fuels/react": "^0.36.1", "@tanstack/react-query": "^5.55.4", "fuels": "workspace:*", "next": "14.2.15", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 84d3d93dfba..9da1024d276 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -183,11 +183,11 @@ importers: apps/create-fuels-counter-guide: dependencies: '@fuels/connectors': - specifier: ^0.27.1 - version: 0.27.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.8)(@babel/preset-env@7.22.5(@babel/core@7.25.8))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8) + specifier: ^0.36.1 + version: 0.36.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.8)(@babel/preset-env@7.22.5(@babel/core@7.25.8))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8) '@fuels/react': - specifier: ^0.27.1 - version: 0.27.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^0.36.1 + version: 0.36.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(@types/react@18.3.11)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@tanstack/react-query': specifier: ^5.55.4 version: 5.56.2(react@18.3.1) @@ -440,11 +440,11 @@ importers: apps/demo-wallet-sdk-react: dependencies: '@fuels/connectors': - specifier: ^0.27.1 - version: 0.27.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.8)(@babel/preset-env@7.22.5(@babel/core@7.25.8))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8) + specifier: ^0.36.1 + version: 0.36.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.8)(@babel/preset-env@7.22.5(@babel/core@7.25.8))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8) '@fuels/react': - specifier: ^0.27.1 - version: 0.27.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^0.36.1 + version: 0.36.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(@types/react@18.3.11)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@tanstack/react-query': specifier: ^5.55.4 version: 5.56.2(react@18.3.1) @@ -1241,11 +1241,11 @@ importers: templates/nextjs: dependencies: '@fuels/connectors': - specifier: ^0.27.1 - version: 0.27.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.8)(@babel/preset-env@7.22.5(@babel/core@7.25.8))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8) + specifier: ^0.36.1 + version: 0.36.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.8)(@babel/preset-env@7.22.5(@babel/core@7.25.8))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8) '@fuels/react': - specifier: ^0.27.1 - version: 0.27.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^0.36.1 + version: 0.36.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(@types/react@18.3.11)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@tanstack/react-query': specifier: ^5.55.4 version: 5.56.2(react@18.3.1) @@ -1317,11 +1317,11 @@ importers: templates/vite: dependencies: '@fuels/connectors': - specifier: ^0.27.1 - version: 0.27.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.2)(@babel/preset-env@7.22.5(@babel/core@7.25.2))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8) + specifier: ^0.36.1 + version: 0.36.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.2)(@babel/preset-env@7.22.5(@babel/core@7.25.2))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8) '@fuels/react': - specifier: ^0.27.1 - version: 0.27.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^0.36.1 + version: 0.36.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(@types/react@18.3.11)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@tanstack/react-query': specifier: ^5.55.4 version: 5.56.2(react@18.3.1) @@ -3533,17 +3533,17 @@ packages: resolution: {integrity: sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==} engines: {node: '>=14'} - '@fuels/connectors@0.27.1': - resolution: {integrity: sha512-gn5OyniNyFMjq611PfUm2asZ07oUr/wLo9Mx/Kr5vMmc33KAxA2B6uxRhBaBY8ysHwGuab6ZeONjVGnJ7iO8Vw==} + '@fuels/connectors@0.36.1': + resolution: {integrity: sha512-BFoN80F7G7MotNMzFscfFNjvBUBURoxrVjs3Sa7OneR/9eK8zvE87zIF8Ymsh/Cxue4bwwc6/1663PX3RM2OTw==} peerDependencies: - fuels: '>=0.94.0' + fuels: '>=0.96.1' - '@fuels/react@0.27.1': - resolution: {integrity: sha512-qVlgjvIiP8+SGvNIrKAdTWvVTKSoYhjzabL/S6KhJ8Rp3DxWulpyZ0zYuLv5ElOmHMyOKYu5clHZbkhYsvVLYA==} + '@fuels/react@0.36.1': + resolution: {integrity: sha512-vI57X6zRjoe8yWHru/EeHGsqDiAYizvt3P2B38TmnkKKaFlCZkVrDPVLMUAD/oUecE4Y35JcEOF0Su9EXPNXtQ==} peerDependencies: '@tanstack/react-query': '>=5.0.0' - fuels: '>=0.94.0' - react: ^18.2.0 + fuels: '>=0.96.1' + react: '>=18.0.0' '@fuels/vm-asm@0.58.2': resolution: {integrity: sha512-1/5azTzKJP508BXbZvM6Y0V5bCCX5JgEnd/8mXdBFmFvNLOhiYbwb25yk26auqOokfBXvthSkdkrvipEFft6jQ==} @@ -4588,164 +4588,164 @@ packages: engines: {node: '>=18'} hasBin: true - '@radix-ui/primitive@1.0.1': - resolution: {integrity: sha512-yQ8oGX2GVsEYMWGxcovu1uGWPCxV5BFfeeYxqPmuAzUyLT9qmaMXSAhXpb0WrspIeqYzdJpkh2vHModJPgRIaw==} + '@radix-ui/primitive@1.1.0': + resolution: {integrity: sha512-4Z8dn6Upk0qk4P74xBhZ6Hd/w0mPEzOOLxy4xiPXOXqjF7jZS0VAKk7/x/H6FyY2zCkYJqePf1G5KmkmNJ4RBA==} - '@radix-ui/react-compose-refs@1.0.1': - resolution: {integrity: sha512-fDSBgd44FKHa1FRMU59qBMPFcl2PZE+2nmqunj+BWFyYYjnhIDWL2ItDs3rrbJDQOtzt5nIebLCQc4QRfz6LJw==} + '@radix-ui/react-compose-refs@1.1.0': + resolution: {integrity: sha512-b4inOtiaOnYf9KWyO3jAeeCG6FeyfY6ldiEPanbUjWd+xIk5wZeHa8yVwmrJ2vderhu/BQvzCrJI0lHd+wIiqw==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true - '@radix-ui/react-context@1.0.1': - resolution: {integrity: sha512-ebbrdFoYTcuZ0v4wG5tedGnp9tzcV8awzsxYph7gXUyvnNLuTIcCk1q17JEbnVhXAKG9oX3KtchwiMIAYp9NLg==} + '@radix-ui/react-context@1.1.0': + resolution: {integrity: sha512-OKrckBy+sMEgYM/sMmqmErVn0kZqrHPJze+Ql3DzYsDDp0hl0L62nx/2122/Bvps1qz645jlcu2tD9lrRSdf8A==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true - '@radix-ui/react-dialog@1.0.5': - resolution: {integrity: sha512-GjWJX/AUpB703eEBanuBnIWdIXg6NvJFCXcNlSZk4xdszCdhrJgBoUd1cGk67vFO+WdA2pfI/plOpqz/5GUP6Q==} + '@radix-ui/react-dialog@1.1.1': + resolution: {integrity: sha512-zysS+iU4YP3STKNS6USvFVqI4qqx8EpiwmT5TuCApVEBca+eRCbONi4EgzfNSuVnOXvC5UPHHMjs8RXO6DH9Bg==} peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: ^16.8 || ^17.0 || ^18.0 - react-dom: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true '@types/react-dom': optional: true - '@radix-ui/react-dismissable-layer@1.0.5': - resolution: {integrity: sha512-aJeDjQhywg9LBu2t/At58hCvr7pEm0o2Ke1x33B+MhjNmmZ17sy4KImo0KPLgsnc/zN7GPdce8Cnn0SWvwZO7g==} + '@radix-ui/react-dismissable-layer@1.1.0': + resolution: {integrity: sha512-/UovfmmXGptwGcBQawLzvn2jOfM0t4z3/uKffoBlj724+n3FvBbZ7M0aaBOmkp6pqFYpO4yx8tSVJjx3Fl2jig==} peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: ^16.8 || ^17.0 || ^18.0 - react-dom: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true '@types/react-dom': optional: true - '@radix-ui/react-focus-guards@1.0.1': - resolution: {integrity: sha512-Rect2dWbQ8waGzhMavsIbmSVCgYxkXLxxR3ZvCX79JOglzdEy4JXMb98lq4hPxUbLr77nP0UOGf4rcMU+s1pUA==} + '@radix-ui/react-focus-guards@1.1.0': + resolution: {integrity: sha512-w6XZNUPVv6xCpZUqb/yN9DL6auvpGX3C/ee6Hdi16v2UUy25HV2Q5bcflsiDyT/g5RwbPQ/GIT1vLkeRb+ITBw==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true - '@radix-ui/react-focus-scope@1.0.4': - resolution: {integrity: sha512-sL04Mgvf+FmyvZeYfNu1EPAaaxD+aw7cYeIB9L9Fvq8+urhltTRaEo5ysKOpHuKPclsZcSUMKlN05x4u+CINpA==} + '@radix-ui/react-focus-scope@1.1.0': + resolution: {integrity: sha512-200UD8zylvEyL8Bx+z76RJnASR2gRMuxlgFCPAe/Q/679a/r0eK3MBVYMb7vZODZcffZBdob1EGnky78xmVvcA==} peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: ^16.8 || ^17.0 || ^18.0 - react-dom: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true '@types/react-dom': optional: true - '@radix-ui/react-id@1.0.1': - resolution: {integrity: sha512-tI7sT/kqYp8p96yGWY1OAnLHrqDgzHefRBKQ2YAkBS5ja7QLcZ9Z/uY7bEjPUatf8RomoXM8/1sMj1IJaE5UzQ==} + '@radix-ui/react-id@1.1.0': + resolution: {integrity: sha512-EJUrI8yYh7WOjNOqpoJaf1jlFIH2LvtgAl+YcFqNCa+4hj64ZXmPkAKOFs/ukjz3byN6bdb/AVUqHkI8/uWWMA==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true - '@radix-ui/react-portal@1.0.4': - resolution: {integrity: sha512-Qki+C/EuGUVCQTOTD5vzJzJuMUlewbzuKyUy+/iHM2uwGiru9gZeBJtHAPKAEkB5KWGi9mP/CHKcY0wt1aW45Q==} + '@radix-ui/react-portal@1.1.1': + resolution: {integrity: sha512-A3UtLk85UtqhzFqtoC8Q0KvR2GbXF3mtPgACSazajqq6A41mEQgo53iPzY4i6BwDxlIFqWIhiQ2G729n+2aw/g==} peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: ^16.8 || ^17.0 || ^18.0 - react-dom: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true '@types/react-dom': optional: true - '@radix-ui/react-presence@1.0.1': - resolution: {integrity: sha512-UXLW4UAbIY5ZjcvzjfRFo5gxva8QirC9hF7wRE4U5gz+TP0DbRk+//qyuAQ1McDxBt1xNMBTaciFGvEmJvAZCg==} + '@radix-ui/react-presence@1.1.0': + resolution: {integrity: sha512-Gq6wuRN/asf9H/E/VzdKoUtT8GC9PQc9z40/vEr0VCJ4u5XvvhWIrSsCB6vD2/cH7ugTdSfYq9fLJCcM00acrQ==} peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: ^16.8 || ^17.0 || ^18.0 - react-dom: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true '@types/react-dom': optional: true - '@radix-ui/react-primitive@1.0.3': - resolution: {integrity: sha512-yi58uVyoAcK/Nq1inRY56ZSjKypBNKTa/1mcL8qdl6oJeEaDbOldlzrGn7P6Q3Id5d+SYNGc5AJgc4vGhjs5+g==} + '@radix-ui/react-primitive@2.0.0': + resolution: {integrity: sha512-ZSpFm0/uHa8zTvKBDjLFWLo8dkr4MBsiDLz0g3gMUwqgLHz9rTaRRGYDgvZPtBJgYCBKXkS9fzmoySgr8CO6Cw==} peerDependencies: '@types/react': '*' '@types/react-dom': '*' - react: ^16.8 || ^17.0 || ^18.0 - react-dom: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc + react-dom: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true '@types/react-dom': optional: true - '@radix-ui/react-slot@1.0.2': - resolution: {integrity: sha512-YeTpuq4deV+6DusvVUW4ivBgnkHwECUu0BiN43L5UCDFgdhsRUWAghhTF5MbvNTPzmiFOx90asDSUjWuCNapwg==} + '@radix-ui/react-slot@1.1.0': + resolution: {integrity: sha512-FUCf5XMfmW4dtYl69pdS4DbxKy8nj4M7SafBgPllysxmdachynNflAdp/gCsnYWNDnge6tI9onzMp5ARYc1KNw==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true - '@radix-ui/react-use-callback-ref@1.0.1': - resolution: {integrity: sha512-D94LjX4Sp0xJFVaoQOd3OO9k7tpBYNOXdVhkltUbGv2Qb9OXdrg/CpsjlZv7ia14Sylv398LswWBVVu5nqKzAQ==} + '@radix-ui/react-use-callback-ref@1.1.0': + resolution: {integrity: sha512-CasTfvsy+frcFkbXtSJ2Zu9JHpN8TYKxkgJGWbjiZhFivxaeW7rMeZt7QELGVLaYVfFMsKHjb7Ak0nMEe+2Vfw==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true - '@radix-ui/react-use-controllable-state@1.0.1': - resolution: {integrity: sha512-Svl5GY5FQeN758fWKrjM6Qb7asvXeiZltlT4U2gVfl8Gx5UAv2sMR0LWo8yhsIZh2oQ0eFdZ59aoOOMV7b47VA==} + '@radix-ui/react-use-controllable-state@1.1.0': + resolution: {integrity: sha512-MtfMVJiSr2NjzS0Aa90NPTnvTSg6C/JLCV7ma0W6+OMV78vd8OyRpID+Ng9LxzsPbLeuBnWBA1Nq30AtBIDChw==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true - '@radix-ui/react-use-escape-keydown@1.0.3': - resolution: {integrity: sha512-vyL82j40hcFicA+M4Ex7hVkB9vHgSse1ZWomAqV2Je3RleKGO5iM8KMOEtfoSB0PnIelMd2lATjTGMYqN5ylTg==} + '@radix-ui/react-use-escape-keydown@1.1.0': + resolution: {integrity: sha512-L7vwWlR1kTTQ3oh7g1O0CBF3YCyyTj8NmhLR+phShpyA50HCfBFKVJTpshm9PzLiKmehsrQzTYTpX9HvmC9rhw==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true - '@radix-ui/react-use-layout-effect@1.0.1': - resolution: {integrity: sha512-v/5RegiJWYdoCvMnITBkNNx6bCj20fiaJnWtRkU18yITptraXjffz5Qbn05uOiQnOvi+dbkznkoaMltz1GnszQ==} + '@radix-ui/react-use-layout-effect@1.1.0': + resolution: {integrity: sha512-+FPE0rOdziWSrH9athwI1R0HDVbWlEhd+FR+aSDk4uWGmSJ9Z54sdZVDQPZAinJhJXwfT+qnj969mCsT2gfm5w==} peerDependencies: '@types/react': '*' - react: ^16.8 || ^17.0 || ^18.0 + react: ^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc peerDependenciesMeta: '@types/react': optional: true @@ -5623,9 +5623,6 @@ packages: '@types/react-dom@18.3.0': resolution: {integrity: sha512-EhwApuTmMBmXuFOikhQLIBUn6uFg81SwLMOAUgodJF14SOBOCMdU04gDoYi0WOJJHD144TL32z4yDqCW3dnkQg==} - '@types/react@18.3.1': - resolution: {integrity: sha512-V0kuGBX3+prX+DQ/7r2qsv1NsdfnCLnTgnRJ1pYnxykBhGMz+qj+box5lq7XsO5mtZsBqpjwwTu/7wszPfMBcw==} - '@types/react@18.3.11': resolution: {integrity: sha512-r6QZ069rFTjrEYgFdOck1gK7FLVsgJE7tTz0pQBczlBNUhBNk0MQH4UbnFSwjpQLMkLzgqvBBa+qGpLje16eTQ==} @@ -6400,7 +6397,6 @@ packages: '@web3modal/wagmi@5.0.0': resolution: {integrity: sha512-AegPzmmArOpELk9N44/BzNHKE50Fp19nfDJ/eVq8fM/yqDSlq7Gj2D1sEeZuEeXQGxgoAKNOWOlKP6IoQ/+s6g==} - deprecated: Web3Modal is now Reown AppKit. Please follow the upgrade guide at https://docs.reown.com/appkit/upgrade/from-w3m-to-reown peerDependencies: '@wagmi/connectors': '>=4' '@wagmi/core': '>=2.0.0' @@ -13116,8 +13112,8 @@ packages: '@types/react': optional: true - react-remove-scroll@2.5.5: - resolution: {integrity: sha512-ImKhrzJJsyXJfBZ4bzu8Bwpka14c/fQt0k+cyFp/PBhTfyDnU5hjOtM4AG/0AMyy8oKzOTR0lDgJIM7pYXI0kw==} + react-remove-scroll@2.5.7: + resolution: {integrity: sha512-FnrTWO4L7/Bhhf3CYBNArEG/yROV0tKmTv7/3h9QCFvH6sndeFf1wPqOcbFVu5VAulS5dV1wGT3GZZ/1GawqiA==} engines: {node: '>=10'} peerDependencies: '@types/react': ^16.8.0 || ^17.0.0 || ^18.0.0 @@ -19210,7 +19206,7 @@ snapshots: '@fastify/busboy@2.1.1': {} - '@fuels/connectors@0.27.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.2)(@babel/preset-env@7.22.5(@babel/core@7.25.2))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8)': + '@fuels/connectors@0.36.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.2)(@babel/preset-env@7.22.5(@babel/core@7.25.2))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8)': dependencies: '@ethereumjs/util': 9.0.3 '@ethersproject/bytes': 5.7.0 @@ -19253,7 +19249,7 @@ snapshots: - vue - zod - '@fuels/connectors@0.27.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.8)(@babel/preset-env@7.22.5(@babel/core@7.25.8))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8)': + '@fuels/connectors@0.36.1(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(@wagmi/connectors@5.1.14(@types/react@18.3.11)(@wagmi/core@2.13.9(@tanstack/query-core@5.56.2)(@types/react@18.3.11)(immer@9.0.21)(react@18.3.1)(typescript@5.6.3)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8)))(bufferutil@4.0.8)(react-dom@18.3.1(react@18.3.1))(react-native@0.74.1(@babel/core@7.25.8)(@babel/preset-env@7.22.5(@babel/core@7.25.8))(@types/react@18.3.11)(bufferutil@4.0.8)(react@18.3.1)(utf-8-validate@5.0.10))(react@18.3.1)(rollup@4.24.0)(typescript@5.6.3)(utf-8-validate@5.0.10)(viem@2.20.1(bufferutil@4.0.8)(typescript@5.6.3)(utf-8-validate@5.0.10)(zod@3.23.8))(zod@3.23.8))(bufferutil@4.0.8)(fuels@packages+fuels)(immer@9.0.21)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(typescript@5.6.3)(utf-8-validate@5.0.10)(vue@3.5.12(typescript@5.6.3))(zod@3.23.8)': dependencies: '@ethereumjs/util': 9.0.3 '@ethersproject/bytes': 5.7.0 @@ -19296,15 +19292,15 @@ snapshots: - vue - zod - '@fuels/react@0.27.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@fuels/react@0.36.1(@tanstack/react-query@5.56.2(react@18.3.1))(@types/react-dom@18.3.0)(@types/react@18.3.11)(fuels@packages+fuels)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@radix-ui/react-dialog': 1.0.5(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-dialog': 1.1.1(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@tanstack/react-query': 5.56.2(react@18.3.1) - '@types/react': 18.3.1 events: 3.3.0 fuels: link:packages/fuels react: 18.3.1 transitivePeerDependencies: + - '@types/react' - '@types/react-dom' - react-dom @@ -20855,156 +20851,140 @@ snapshots: - supports-color optional: true - '@radix-ui/primitive@1.0.1': - dependencies: - '@babel/runtime': 7.25.4 + '@radix-ui/primitive@1.1.0': {} - '@radix-ui/react-compose-refs@1.0.1(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-compose-refs@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - '@radix-ui/react-context@1.0.1(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-context@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - '@radix-ui/react-dialog@1.0.5(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': - dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/primitive': 1.0.1 - '@radix-ui/react-compose-refs': 1.0.1(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-context': 1.0.1(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-dismissable-layer': 1.0.5(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@radix-ui/react-focus-guards': 1.0.1(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-focus-scope': 1.0.4(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@radix-ui/react-id': 1.0.1(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-portal': 1.0.4(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@radix-ui/react-presence': 1.0.1(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@radix-ui/react-primitive': 1.0.3(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@radix-ui/react-slot': 1.0.2(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-use-controllable-state': 1.0.1(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/react-dialog@1.1.1(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + dependencies: + '@radix-ui/primitive': 1.1.0 + '@radix-ui/react-compose-refs': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-context': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-dismissable-layer': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-focus-guards': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-focus-scope': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-id': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-portal': 1.1.1(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-presence': 1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-slot': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-use-controllable-state': 1.1.0(@types/react@18.3.11)(react@18.3.1) aria-hidden: 1.2.3 react: 18.3.1 react-dom: 18.3.1(react@18.3.1) - react-remove-scroll: 2.5.5(@types/react@18.3.1)(react@18.3.1) + react-remove-scroll: 2.5.7(@types/react@18.3.11)(react@18.3.1) optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 '@types/react-dom': 18.3.0 - '@radix-ui/react-dismissable-layer@1.0.5(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@radix-ui/react-dismissable-layer@1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/primitive': 1.0.1 - '@radix-ui/react-compose-refs': 1.0.1(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-primitive': 1.0.3(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@radix-ui/react-use-callback-ref': 1.0.1(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-use-escape-keydown': 1.0.3(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/primitive': 1.1.0 + '@radix-ui/react-compose-refs': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-use-callback-ref': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-use-escape-keydown': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 react-dom: 18.3.1(react@18.3.1) optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 '@types/react-dom': 18.3.0 - '@radix-ui/react-focus-guards@1.0.1(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-focus-guards@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - '@radix-ui/react-focus-scope@1.0.4(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@radix-ui/react-focus-scope@1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/react-compose-refs': 1.0.1(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-primitive': 1.0.3(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) - '@radix-ui/react-use-callback-ref': 1.0.1(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/react-compose-refs': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-use-callback-ref': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 react-dom: 18.3.1(react@18.3.1) optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 '@types/react-dom': 18.3.0 - '@radix-ui/react-id@1.0.1(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-id@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/react-use-layout-effect': 1.0.1(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/react-use-layout-effect': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - '@radix-ui/react-portal@1.0.4(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@radix-ui/react-portal@1.1.1(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/react-primitive': 1.0.3(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-primitive': 2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + '@radix-ui/react-use-layout-effect': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 react-dom: 18.3.1(react@18.3.1) optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 '@types/react-dom': 18.3.0 - '@radix-ui/react-presence@1.0.1(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@radix-ui/react-presence@1.1.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/react-compose-refs': 1.0.1(@types/react@18.3.1)(react@18.3.1) - '@radix-ui/react-use-layout-effect': 1.0.1(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/react-compose-refs': 1.1.0(@types/react@18.3.11)(react@18.3.1) + '@radix-ui/react-use-layout-effect': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 react-dom: 18.3.1(react@18.3.1) optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 '@types/react-dom': 18.3.0 - '@radix-ui/react-primitive@1.0.3(@types/react-dom@18.3.0)(@types/react@18.3.1)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@radix-ui/react-primitive@2.0.0(@types/react-dom@18.3.0)(@types/react@18.3.11)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/react-slot': 1.0.2(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/react-slot': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 react-dom: 18.3.1(react@18.3.1) optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 '@types/react-dom': 18.3.0 - '@radix-ui/react-slot@1.0.2(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-slot@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/react-compose-refs': 1.0.1(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/react-compose-refs': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - '@radix-ui/react-use-callback-ref@1.0.1(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-use-callback-ref@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - '@radix-ui/react-use-controllable-state@1.0.1(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-use-controllable-state@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/react-use-callback-ref': 1.0.1(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/react-use-callback-ref': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - '@radix-ui/react-use-escape-keydown@1.0.3(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-use-escape-keydown@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 - '@radix-ui/react-use-callback-ref': 1.0.1(@types/react@18.3.1)(react@18.3.1) + '@radix-ui/react-use-callback-ref': 1.1.0(@types/react@18.3.11)(react@18.3.1) react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - '@radix-ui/react-use-layout-effect@1.0.1(@types/react@18.3.1)(react@18.3.1)': + '@radix-ui/react-use-layout-effect@1.1.0(@types/react@18.3.11)(react@18.3.1)': dependencies: - '@babel/runtime': 7.25.4 react: 18.3.1 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 '@react-native-community/cli-clean@13.6.6': dependencies: @@ -21696,7 +21676,7 @@ snapshots: '@solana/web3.js@1.93.1(bufferutil@4.0.8)(utf-8-validate@5.0.10)': dependencies: - '@babel/runtime': 7.25.4 + '@babel/runtime': 7.25.7 '@noble/curves': 1.6.0 '@noble/hashes': 1.5.0 '@solana/buffer-layout': 4.0.1 @@ -22300,11 +22280,6 @@ snapshots: dependencies: '@types/react': 18.3.11 - '@types/react@18.3.1': - dependencies: - '@types/prop-types': 15.7.5 - csstype: 3.1.3 - '@types/react@18.3.11': dependencies: '@types/prop-types': 15.7.5 @@ -32817,24 +32792,24 @@ snapshots: react-refresh@0.14.2: {} - react-remove-scroll-bar@2.3.5(@types/react@18.3.1)(react@18.3.1): + react-remove-scroll-bar@2.3.5(@types/react@18.3.11)(react@18.3.1): dependencies: react: 18.3.1 - react-style-singleton: 2.2.1(@types/react@18.3.1)(react@18.3.1) + react-style-singleton: 2.2.1(@types/react@18.3.11)(react@18.3.1) tslib: 2.8.0 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - react-remove-scroll@2.5.5(@types/react@18.3.1)(react@18.3.1): + react-remove-scroll@2.5.7(@types/react@18.3.11)(react@18.3.1): dependencies: react: 18.3.1 - react-remove-scroll-bar: 2.3.5(@types/react@18.3.1)(react@18.3.1) - react-style-singleton: 2.2.1(@types/react@18.3.1)(react@18.3.1) + react-remove-scroll-bar: 2.3.5(@types/react@18.3.11)(react@18.3.1) + react-style-singleton: 2.2.1(@types/react@18.3.11)(react@18.3.1) tslib: 2.8.0 - use-callback-ref: 1.3.1(@types/react@18.3.1)(react@18.3.1) - use-sidecar: 1.1.2(@types/react@18.3.1)(react@18.3.1) + use-callback-ref: 1.3.1(@types/react@18.3.11)(react@18.3.1) + use-sidecar: 1.1.2(@types/react@18.3.11)(react@18.3.1) optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 react-scripts@5.0.1(@babel/plugin-syntax-flow@7.25.7(@babel/core@7.22.5))(@babel/plugin-transform-react-jsx@7.25.7(@babel/core@7.22.5))(@swc/core@1.7.14(@swc/helpers@0.5.12))(@types/babel__core@7.20.5)(bufferutil@4.0.8)(esbuild@0.17.19)(eslint@9.9.1(jiti@2.3.3))(react@18.3.1)(ts-node@10.9.1(@swc/core@1.7.14(@swc/helpers@0.5.12))(@types/node@22.5.5)(typescript@5.6.3))(type-fest@3.1.0)(typescript@5.6.3)(utf-8-validate@5.0.10): dependencies: @@ -32928,14 +32903,14 @@ snapshots: react: 18.3.1 react-is: 18.3.1 - react-style-singleton@2.2.1(@types/react@18.3.1)(react@18.3.1): + react-style-singleton@2.2.1(@types/react@18.3.11)(react@18.3.1): dependencies: get-nonce: 1.0.1 invariant: 2.2.4 react: 18.3.1 tslib: 2.8.0 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 react-toastify@10.0.6(react-dom@18.3.1(react@18.3.1))(react@18.3.1): dependencies: @@ -33071,7 +33046,7 @@ snapshots: regenerator-transform@0.15.1: dependencies: - '@babel/runtime': 7.25.4 + '@babel/runtime': 7.25.7 regex-parser@2.2.11: {} @@ -35096,20 +35071,20 @@ snapshots: urlpattern-polyfill@10.0.0: {} - use-callback-ref@1.3.1(@types/react@18.3.1)(react@18.3.1): + use-callback-ref@1.3.1(@types/react@18.3.11)(react@18.3.1): dependencies: react: 18.3.1 tslib: 2.8.0 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 - use-sidecar@1.1.2(@types/react@18.3.1)(react@18.3.1): + use-sidecar@1.1.2(@types/react@18.3.11)(react@18.3.1): dependencies: detect-node-es: 1.1.0 react: 18.3.1 tslib: 2.8.0 optionalDependencies: - '@types/react': 18.3.1 + '@types/react': 18.3.11 use-sync-external-store@1.2.0(react@18.3.1): dependencies: diff --git a/templates/nextjs/package.json b/templates/nextjs/package.json index 3404109f462..510fb409ec9 100644 --- a/templates/nextjs/package.json +++ b/templates/nextjs/package.json @@ -13,8 +13,8 @@ "test:ui": "sh ./test/ui/test-ui.sh" }, "dependencies": { - "@fuels/connectors": "^0.27.1", - "@fuels/react": "^0.27.1", + "@fuels/connectors": "^0.36.1", + "@fuels/react": "^0.36.1", "@tanstack/react-query": "^5.55.4", "clsx": "2.1.1", "@wagmi/connectors": "^5.1.14", diff --git a/templates/nextjs/src/app/layout.tsx b/templates/nextjs/src/app/layout.tsx index 235c91c3047..6f9e49f67de 100644 --- a/templates/nextjs/src/app/layout.tsx +++ b/templates/nextjs/src/app/layout.tsx @@ -4,7 +4,7 @@ import { FuelProvider } from "@fuels/react"; import React, { ReactNode, useEffect, useState } from "react"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import { ToastContainer } from "react-toastify"; -import { Provider } from "fuels"; +import { FuelConnector, Provider } from "fuels"; import { defaultConnectors } from "@fuels/connectors"; import { providerUrl } from "../lib"; @@ -14,9 +14,9 @@ import "@/styles/globals.css"; const queryClient = new QueryClient(); -const connectors = defaultConnectors({ +const connectors: FuelConnector[] = defaultConnectors({ devMode: true, - burnerWalletConfig: { fuelProvider: Provider.create(providerUrl) }, + fuelProvider: Provider.create(providerUrl), }); interface RootLayoutProps { @@ -42,7 +42,12 @@ export default function RootLayout({ children }: RootLayoutProps) { - + + {" "} <>{children} diff --git a/templates/nextjs/src/lib.tsx b/templates/nextjs/src/lib.tsx index a5bd27ffa5c..5229827f2d2 100644 --- a/templates/nextjs/src/lib.tsx +++ b/templates/nextjs/src/lib.tsx @@ -25,7 +25,7 @@ export const renderTransactionId = (transactionId: string) => { return ( { return ( - + From 4ccc6286132c98c23a290dca805d326a415e40c7 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Thu, 2 Jan 2025 12:44:44 +0000 Subject: [PATCH 2/4] chore!: remove Bech32 address (#3493) * chore: removed bech32 * chore: update recipes * chore: fix test * chore: update changeset * Update apps/docs/src/guide/types/address.md Co-authored-by: Daniel Bate --------- Co-authored-by: Anderson Arboleya Co-authored-by: Daniel Bate --- .changeset/small-plums-talk.md | 8 ++ CONTRIBUTING.md | 7 +- apps/docs/.vitepress/config.ts | 4 - apps/docs/spell-check-custom-words.txt | 1 - .../contracts/managing-deployed-contracts.md | 7 +- apps/docs/src/guide/types/address.md | 19 +-- apps/docs/src/guide/types/bech32.md | 22 ---- .../snippets/address/creating-an-address.ts | 6 +- .../snippets/address/utilities-function-1.ts | 2 - apps/docs/src/guide/types/snippets/b256.ts | 6 + apps/docs/src/guide/types/snippets/bech32.ts | 16 --- .../src/guide/utilities/address-conversion.md | 27 +--- .../b256-to-bech32-utilities.ts | 12 -- .../address-conversion/b256-to-bech32.ts | 16 --- .../bech32-to-b256-utilities.ts | 14 -- .../address-conversion/bech32-to-b256.ts | 16 --- .../snippets/address-conversion/contract.ts | 12 +- .../snippets/address-conversion/wallet.ts | 12 +- .../guide/wallets/instantiating-wallets.md | 2 +- ...bech32-address.ts => from-b256-address.ts} | 4 +- .../instantiating/unlock-from-private-key.ts | 2 +- .../wallets/snippets/signing/sign-message.ts | 2 +- packages/account/src/signer/signer.test.ts | 2 +- .../src/wallet/keystore-wallet.test.ts | 2 +- .../src/wallet/wallet-unlocked.test.ts | 2 +- packages/address/README.md | 5 +- packages/address/package.json | 3 +- packages/address/src/address.test.ts | 123 +++--------------- packages/address/src/address.ts | 116 +++++++---------- packages/address/src/utils.ts | 104 ++------------- packages/errors/src/error-codes.ts | 6 - packages/fuel-gauge/src/doc-examples.test.ts | 19 +-- packages/fuel-gauge/src/e2e-script.test.ts | 4 +- packages/interfaces/src/index.ts | 9 +- packages/logger/src/index.ts | 6 - packages/logger/test/index.test.ts | 20 --- packages/recipes/src/types/Src14OwnedProxy.ts | 2 +- .../src/types/Src14OwnedProxyFactory.ts | 2 +- packages/recipes/src/types/common.d.ts | 2 +- packages/recipes/src/types/index.ts | 2 +- pnpm-lock.yaml | 8 -- 41 files changed, 135 insertions(+), 519 deletions(-) create mode 100644 .changeset/small-plums-talk.md delete mode 100644 apps/docs/src/guide/types/bech32.md create mode 100644 apps/docs/src/guide/types/snippets/b256.ts delete mode 100644 apps/docs/src/guide/types/snippets/bech32.ts delete mode 100644 apps/docs/src/guide/utilities/snippets/address-conversion/b256-to-bech32-utilities.ts delete mode 100644 apps/docs/src/guide/utilities/snippets/address-conversion/b256-to-bech32.ts delete mode 100644 apps/docs/src/guide/utilities/snippets/address-conversion/bech32-to-b256-utilities.ts delete mode 100644 apps/docs/src/guide/utilities/snippets/address-conversion/bech32-to-b256.ts rename apps/docs/src/guide/wallets/snippets/instantiating/{from-bech32-address.ts => from-b256-address.ts} (58%) diff --git a/.changeset/small-plums-talk.md b/.changeset/small-plums-talk.md new file mode 100644 index 00000000000..83f4952100f --- /dev/null +++ b/.changeset/small-plums-talk.md @@ -0,0 +1,8 @@ +--- +"@fuel-ts/address": minor +"@fuel-ts/errors": patch +"@fuel-ts/recipes": patch +"@fuel-ts/logger": minor +--- + +chore!: remove Bech32 address diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 88a07d3af77..0c2b4b5f108 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -244,10 +244,7 @@ During the CI process an automated end-to-end (e2e) test is executed. This test The e2e test can be found at: `packages/fuel-gauge/src/e2e-script.test.ts` -The Bech32 address of this wallet is `fuel1x33ajpj0jy5p2wcqqu45e32r75zrwfeh6hwqfv5un670rv4p0mns58enjg`. This address can be funded via the [faucet](https://faucet-testnet.fuel.network/). - -> [!NOTE] Note -> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) +The B256 address of this wallet is `0x3463d9064f9128153b00072b4cc543f504372737d5dc04b29c9ebcf1b2a17ee7`. This address can be funded via the [faucet](https://faucet-testnet.fuel.network/). If you want to run an e2e test locally, you can provide your own wallet address and private key. For obvious security reasons, the private key should not be shared. @@ -270,8 +267,6 @@ This will enable you to run the e2e test locally against the live network: pnpm test:filter e2e-script ``` - - # Commit Convention Before you create a Pull Request, please check whether your commits comply with diff --git a/apps/docs/.vitepress/config.ts b/apps/docs/.vitepress/config.ts index 17fbc9b5931..05ea76b776e 100644 --- a/apps/docs/.vitepress/config.ts +++ b/apps/docs/.vitepress/config.ts @@ -487,10 +487,6 @@ export default defineConfig({ text: 'Asset Id', link: '/guide/types/asset-id', }, - { - text: 'Bech32', - link: '/guide/types/bech32', - }, { text: 'Bits256', link: '/guide/types/bits256', diff --git a/apps/docs/spell-check-custom-words.txt b/apps/docs/spell-check-custom-words.txt index aa3ebc175d7..bd79fd9cf81 100644 --- a/apps/docs/spell-check-custom-words.txt +++ b/apps/docs/spell-check-custom-words.txt @@ -21,7 +21,6 @@ backends backoff backtrace backtraces -Bech BigNumber Bitfield bitmask diff --git a/apps/docs/src/guide/contracts/managing-deployed-contracts.md b/apps/docs/src/guide/contracts/managing-deployed-contracts.md index b24d3752125..361a9e37599 100644 --- a/apps/docs/src/guide/contracts/managing-deployed-contracts.md +++ b/apps/docs/src/guide/contracts/managing-deployed-contracts.md @@ -6,16 +6,13 @@ To interact with a deployed contract using the SDK without redeploying it, you o The `contractId` property from the [`Contract`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_program.Contract.html) class is of type [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html), an abstract class that is exclusively extended by the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class. -The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class wraps all methods from the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class and adds a single property: `bech32Address`. This property is a string encoded in [`Bech32`](../types/bech32.md) format, recognizable by the human-readable prefix `fuel` followed by the separator `1`. - -> [!NOTE] Note -> `Bech32` addresses like `fuel1..` are now deprecated; please switch to B256 format, for more details see [here](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256). +The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class wraps all methods from the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class and adds a single property: `b256Address`. This property is a string encoded in [`B256`](../types/bits256.md) format. When you log the `contractId` property of an instantiated Contract using `console.log`, the output appears as follows: ```console Address { - bech32Address: 'fuel1e5tdjlzufcvwut5dvs5yglweepmrevpnvuvt2djj6pyl3mygkwaq8m7f20' + b256Address: '0xcd16d97c5c4e18ee2e8d6428447dd9c8763cb0336718b53652d049f8ec88b3ba' } ``` diff --git a/apps/docs/src/guide/types/address.md b/apps/docs/src/guide/types/address.md index a87f80b38af..73e4a971ea9 100644 --- a/apps/docs/src/guide/types/address.md +++ b/apps/docs/src/guide/types/address.md @@ -10,7 +10,7 @@ The SDK defines the [AbstractAddress](https://fuels-ts-docs-api.vercel.app/class ## Address Class -Besides conforming to the interface of the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html), the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also defines one property; `bech32Address`, which is of the [`Bech32`](./bech32.md) type. +Besides conforming to the interface of the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html), the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also defines one property; `b256Address`, which is of the [`B256`](./bits256.md) type. <<< @/../../../packages/address/src/address.ts#address-2{ts:line-numbers} @@ -18,14 +18,11 @@ Besides conforming to the interface of the [`AbstractAddress`](https://fuels-ts- Thanks to the utility functions provided by the [`AbstractAddress`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_interfaces.AbstractAddress.html) class, there are several ways to create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) instance: -### From a `Bech32` Address +### From a b256 address -To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a `Bech32` address, use the following code snippet: - -<<< @./snippets/address/creating-an-address.ts#full{ts:line-numbers} +To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a 256-bit address, use the following code snippet: -> [!NOTE] Note -> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) +<<< @./snippets/address/from-a-b256.ts#full{ts:line-numbers} ### From a Public Key @@ -33,17 +30,11 @@ To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_a <<< @./snippets/address/from-a-public-key.ts#full{ts:line-numbers} -### From a 256-bit Address - -To create an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from a 256-bit address, use the following code snippet: - -<<< @./snippets/address/from-a-b256.ts#full{ts:line-numbers} - ## Utility Functions The [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class also provides some practical utility functions: -1. `fromString`: Create a new [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from an ambiguous source that may be a `Bech32` or `B256` address: +1. `fromString`: Create a new [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) from an ambiguous source that may be a `B256` address: <<< @./snippets/address/utilities-function-1.ts#full{ts:line-numbers} diff --git a/apps/docs/src/guide/types/bech32.md b/apps/docs/src/guide/types/bech32.md deleted file mode 100644 index 58e0d72e4a6..00000000000 --- a/apps/docs/src/guide/types/bech32.md +++ /dev/null @@ -1,22 +0,0 @@ -# `Bech32` - -> [!NOTE] Note -> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) - -The SDK uses the `Bech32` type as the core property of the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class, specifically through the `bech32Address` property. - -Originally designed for Bitcoin, the `Bech32` format offers numerous advantages such as enhanced error detection, simplified integrations, and improved compatibility with future upgrades. Given these benefits, the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class is constructed around the `Bech32` type. - -You can read more about the `Bech32` type [here](https://thebitcoinmanual.com/articles/btc-bech32-address/). - -## Default Human-Readable Part (HRP) - -A `Bech32` address consists of an HRP (Human-Readable Part) followed by the number `1`, which acts as a separator: - -<<< @/../../../packages/interfaces/src/index.ts#bech32-1{ts:line-numbers} - -A complete `Bech32` address will resemble the following: - -<<< @./snippets/bech32.ts#bech32-2{5 ts:line-numbers} - -The HRP in the example above is `fuel`. This human-readable prefix is included to provide better readability and prevent users from accidentally using addresses on the wrong network. diff --git a/apps/docs/src/guide/types/snippets/address/creating-an-address.ts b/apps/docs/src/guide/types/snippets/address/creating-an-address.ts index bdc0642e38d..377e02066d2 100644 --- a/apps/docs/src/guide/types/snippets/address/creating-an-address.ts +++ b/apps/docs/src/guide/types/snippets/address/creating-an-address.ts @@ -1,10 +1,10 @@ // #region full import { Address } from 'fuels'; -const ADDRESS_BECH32 = - 'fuel1elnmzsav56dqnp95sx4e2pckq36cvae9ser44m5zlvgtwxw49fmqd7e42e'; +const ADDRESS_B256 = + '0xcfe7b143aca69a0984b481ab950716047586772586475aee82fb10b719d52a76'; -const address = new Address(ADDRESS_BECH32); +const address = new Address(ADDRESS_B256); // #endregion full console.log('address', address); diff --git a/apps/docs/src/guide/types/snippets/address/utilities-function-1.ts b/apps/docs/src/guide/types/snippets/address/utilities-function-1.ts index b1acbcd343a..0823a6f9400 100644 --- a/apps/docs/src/guide/types/snippets/address/utilities-function-1.ts +++ b/apps/docs/src/guide/types/snippets/address/utilities-function-1.ts @@ -3,9 +3,7 @@ import { Address } from 'fuels'; const address = Address.fromRandom(); -const addressCloneFromBech = Address.fromString(address.toString()); const addressCloneFromB256 = Address.fromString(address.toB256()); // #endregion full -console.log('addressCloneFromBech', addressCloneFromBech); console.log('addressCloneFromB256', addressCloneFromB256); diff --git a/apps/docs/src/guide/types/snippets/b256.ts b/apps/docs/src/guide/types/snippets/b256.ts new file mode 100644 index 00000000000..595b44ff156 --- /dev/null +++ b/apps/docs/src/guide/types/snippets/b256.ts @@ -0,0 +1,6 @@ +// #region addresses-1 +const b256 = + '0x9ae5b658754e096e4d681c548daf46354495a437cc61492599e33fc64dcdc30c'; +// #endregion addresses-1 + +console.log('b256', b256); diff --git a/apps/docs/src/guide/types/snippets/bech32.ts b/apps/docs/src/guide/types/snippets/bech32.ts deleted file mode 100644 index 5e3c399ec44..00000000000 --- a/apps/docs/src/guide/types/snippets/bech32.ts +++ /dev/null @@ -1,16 +0,0 @@ -// #region bech32-2 -import { Address } from 'fuels'; - -const address = Address.fromRandom(); - -console.log('Bech32', address.bech32Address); - -// fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs -// #endregion bech32-2 - -// #region addresses-1 -const bech32 = - 'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs'; -// #endregion addresses-1 - -console.log('bech32', bech32); diff --git a/apps/docs/src/guide/utilities/address-conversion.md b/apps/docs/src/guide/utilities/address-conversion.md index 2bb1eaf8c82..ba42aeca586 100644 --- a/apps/docs/src/guide/utilities/address-conversion.md +++ b/apps/docs/src/guide/utilities/address-conversion.md @@ -2,12 +2,9 @@ Addresses and varying address formats are commonplace when interacting with decentralized applications. Furthermore, different networks may enforce different address formats. -The Fuel Network uses the [`Bech32`](../types/bech32.md) address format for its interactions, an example of which can be seen below: +The Fuel Network uses the [`Bits256`](../types/bits256.md) address format for its interactions, an example of which can be seen below: -<<< @/../../docs/src/guide/types/snippets/bech32.ts#addresses-1{ts:line-numbers} - -> [!NOTE] Note -> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) +<<< @/../../docs/src/guide/types/snippets/b256.ts#addresses-1{ts:line-numbers} However, a hexlified [Bits256](../types/bits256.md) (hex) is another common address format; an example can be seen below: @@ -26,26 +23,6 @@ The following [conversion guide](./address-conversion.md#address-conversion) wil This guide demonstrates how to convert between address formats and Sway Standard Types using helper functions. Native types are wrappers for bytes, and you can perform conversions between them by leveraging these functions and classes. -## From `Bech32` to `b256` - -By instantiating an [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html), we can validate a `Bech32` address and easily convert it to a `b256`: - -<<< @./snippets/address-conversion/bech32-to-b256.ts#conversion-5{ts:line-numbers} - -Or, if you'd prefer to use utility functions directly for validation and conversion, you can use `isBech32` and `toB256`: - -<<< @./snippets/address-conversion/bech32-to-b256-utilities.ts#conversion-6{ts:line-numbers} - -## From `b256` to `Bech32` - -In a similar fashion, we have both class functions on the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) and utilities available for `b256` validation and conversion: - -<<< @./snippets/address-conversion/b256-to-bech32.ts#conversion-7{ts:line-numbers} - -And by using the `isB256` and `toBech32` utilities: - -<<< @./snippets/address-conversion/b256-to-bech32-utilities.ts#conversion-8{ts:line-numbers} - ## Converting a Contract ID The Contract `id` property has the [`AbstractAddress`](../types/address.md#abstractaddress-class) type. Therefore, it can be converted using the [`Address`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_address.Address.html) class functions such as `toAddress` and `toB256`: diff --git a/apps/docs/src/guide/utilities/snippets/address-conversion/b256-to-bech32-utilities.ts b/apps/docs/src/guide/utilities/snippets/address-conversion/b256-to-bech32-utilities.ts deleted file mode 100644 index f06ca69b731..00000000000 --- a/apps/docs/src/guide/utilities/snippets/address-conversion/b256-to-bech32-utilities.ts +++ /dev/null @@ -1,12 +0,0 @@ -// #region conversion-8 -import { isB256, toBech32 } from 'fuels'; - -const b256 = - '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f'; -const bech32 = isB256(b256) ? toBech32(b256) : null; -// fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs -// #endregion conversion-8 - -const expectedBech32 = - 'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs'; -console.log('Bech32 should be equal to example', bech32 === expectedBech32); diff --git a/apps/docs/src/guide/utilities/snippets/address-conversion/b256-to-bech32.ts b/apps/docs/src/guide/utilities/snippets/address-conversion/b256-to-bech32.ts deleted file mode 100644 index 24dc999e4aa..00000000000 --- a/apps/docs/src/guide/utilities/snippets/address-conversion/b256-to-bech32.ts +++ /dev/null @@ -1,16 +0,0 @@ -// #region conversion-7 -import type { B256Address, Bech32Address } from 'fuels'; -import { Address } from 'fuels'; - -const b256: B256Address = - '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f'; - -const address: Address = Address.fromDynamicInput(b256); - -const bech32: Bech32Address = address.bech32Address; -// fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs -// #endregion conversion-7 - -const expectedBech32 = - 'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs'; -console.log('Bech32 should be equal to example', bech32 === expectedBech32); diff --git a/apps/docs/src/guide/utilities/snippets/address-conversion/bech32-to-b256-utilities.ts b/apps/docs/src/guide/utilities/snippets/address-conversion/bech32-to-b256-utilities.ts deleted file mode 100644 index 037e6e7e7a3..00000000000 --- a/apps/docs/src/guide/utilities/snippets/address-conversion/bech32-to-b256-utilities.ts +++ /dev/null @@ -1,14 +0,0 @@ -// #region conversion-6 -import type { B256Address, Bech32Address } from 'fuels'; -import { isBech32, toB256 } from 'fuels'; - -const bech32: Bech32Address = - 'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs'; - -const b256: B256Address | null = isBech32(bech32) ? toB256(bech32) : null; -// 0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f -// #endregion conversion-6 - -const expectedB256 = - '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f'; -console.log('B256 should be equal to example', b256 === expectedB256); diff --git a/apps/docs/src/guide/utilities/snippets/address-conversion/bech32-to-b256.ts b/apps/docs/src/guide/utilities/snippets/address-conversion/bech32-to-b256.ts deleted file mode 100644 index 82af1183028..00000000000 --- a/apps/docs/src/guide/utilities/snippets/address-conversion/bech32-to-b256.ts +++ /dev/null @@ -1,16 +0,0 @@ -// #region conversion-5 -import type { B256Address, Bech32Address } from 'fuels'; -import { Address } from 'fuels'; - -const bech32: Bech32Address = - 'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs'; - -const address: Address = Address.fromDynamicInput(bech32); - -const b256: B256Address = address.toB256(); -// 0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f -// #endregion conversion-5 - -const expectedB256 = - '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f'; -console.log('B256 should be equal to example', b256 === expectedB256); diff --git a/apps/docs/src/guide/utilities/snippets/address-conversion/contract.ts b/apps/docs/src/guide/utilities/snippets/address-conversion/contract.ts index be3dac1d8ac..c18a8e5607e 100644 --- a/apps/docs/src/guide/utilities/snippets/address-conversion/contract.ts +++ b/apps/docs/src/guide/utilities/snippets/address-conversion/contract.ts @@ -1,5 +1,5 @@ // #region conversion-2 -import type { Bech32Address } from 'fuels'; +import type { B256Address } from 'fuels'; import { Address, Provider, Contract } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; @@ -14,10 +14,10 @@ const contractAddress = Address.fromB256( const contract = new Contract(contractAddress, contractAbi, provider); -const bech32: Bech32Address = contract.id.toAddress(); -// fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs +const b256: B256Address = contract.id.toAddress(); +// 0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f // #endregion conversion-2 -const expectedBech32 = - 'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs'; -console.log('Bech32 address should equal expected', bech32 === expectedBech32); +const expectedB256 = + '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f'; +console.log('B256 address should equal expected', b256 === expectedB256); diff --git a/apps/docs/src/guide/utilities/snippets/address-conversion/wallet.ts b/apps/docs/src/guide/utilities/snippets/address-conversion/wallet.ts index 9301faa9957..a5522f62979 100644 --- a/apps/docs/src/guide/utilities/snippets/address-conversion/wallet.ts +++ b/apps/docs/src/guide/utilities/snippets/address-conversion/wallet.ts @@ -1,5 +1,5 @@ // #region conversion-3 -import type { Bech32Address, WalletLocked } from 'fuels'; +import type { B256Address, WalletLocked } from 'fuels'; import { Address, Provider, Wallet } from 'fuels'; import { LOCAL_NETWORK_URL } from '../../../../env'; @@ -12,10 +12,10 @@ const address = Address.fromB256( const wallet: WalletLocked = Wallet.fromAddress(address, provider); -const bech32: Bech32Address = wallet.address.toAddress(); -// fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs +const b256: B256Address = wallet.address.toAddress(); +// 0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f // #endregion conversion-3 -const expectedBech32 = - 'fuel1d5cfwekq78r0zq73g7eg0747etkaxxltrqx5tncm7lvg89awe3hswhqjhs'; -console.log('Bech32 address should equal expected', bech32 === expectedBech32); +const expectedB256 = + '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f'; +console.log('b256 address should equal expected', b256 === expectedB256); diff --git a/apps/docs/src/guide/wallets/instantiating-wallets.md b/apps/docs/src/guide/wallets/instantiating-wallets.md index 8c15954f6b5..b7a501ee524 100644 --- a/apps/docs/src/guide/wallets/instantiating-wallets.md +++ b/apps/docs/src/guide/wallets/instantiating-wallets.md @@ -40,7 +40,7 @@ It's possible to instantiate a `WalletUnlocked` from a `WalletLocked`: You can also instantiate [`WalletLocked`](https://fuels-ts-docs-api.vercel.app/classes/_fuel_ts_account.WalletLocked.html) instances using just the wallet address: -<<< @./snippets/instantiating/from-bech32-address.ts#instantiating-wallets-8{ts:line-numbers} +<<< @./snippets/instantiating/from-b256-address.ts#instantiating-wallets-8{ts:line-numbers} ## Connecting to a Provider diff --git a/apps/docs/src/guide/wallets/snippets/instantiating/from-bech32-address.ts b/apps/docs/src/guide/wallets/snippets/instantiating/from-b256-address.ts similarity index 58% rename from apps/docs/src/guide/wallets/snippets/instantiating/from-bech32-address.ts rename to apps/docs/src/guide/wallets/snippets/instantiating/from-b256-address.ts index 1ef57e2f503..795333a26ae 100644 --- a/apps/docs/src/guide/wallets/snippets/instantiating/from-bech32-address.ts +++ b/apps/docs/src/guide/wallets/snippets/instantiating/from-b256-address.ts @@ -1,8 +1,8 @@ // #region instantiating-wallets-8 -import type { WalletLocked } from 'fuels'; +import type { B256Address, WalletLocked } from 'fuels'; import { Wallet } from 'fuels'; -const address = `fuel14kjrdcdcp7z4l9xk0pm3cwz9qnjxxd04wx4zgnc3kknslclxzezqyeux5d`; +const address: B256Address = `0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f`; const wallet: WalletLocked = Wallet.fromAddress(address); // #endregion instantiating-wallets-8 diff --git a/apps/docs/src/guide/wallets/snippets/instantiating/unlock-from-private-key.ts b/apps/docs/src/guide/wallets/snippets/instantiating/unlock-from-private-key.ts index 2e27e7cfd66..1785aa15f89 100644 --- a/apps/docs/src/guide/wallets/snippets/instantiating/unlock-from-private-key.ts +++ b/apps/docs/src/guide/wallets/snippets/instantiating/unlock-from-private-key.ts @@ -3,7 +3,7 @@ import type { WalletLocked, WalletUnlocked } from 'fuels'; import { Wallet } from 'fuels'; const address = - 'fuel1fjett54ahnydhklerngqhclzmmkmp6s0xnykns8dwsdpjfg3r2rsfazpw5'; + '0x4cb2b5d2bdbcc8dbdbf91cd00be3e2deedb0ea0f34c969c0ed741a1925111a87'; const privateKey = '0x9deba03f08676716e3a4247797672d8008a5198d183048be65415ef89447b890'; diff --git a/apps/docs/src/guide/wallets/snippets/signing/sign-message.ts b/apps/docs/src/guide/wallets/snippets/signing/sign-message.ts index 094919d72b7..1088a24edab 100644 --- a/apps/docs/src/guide/wallets/snippets/signing/sign-message.ts +++ b/apps/docs/src/guide/wallets/snippets/signing/sign-message.ts @@ -16,7 +16,7 @@ const hashedMessage = hashMessage(message); const recoveredAddress = Signer.recoverAddress(hashedMessage, signedMessage); // Example output: Address { -// bech32Address: 'fuel1za0wl90u09c6v88faqkvczu9r927kewvvr0asejv5xmdwtm98w0st7m2s3' +// b256Address: '0x6d309766c0f1c6f103d147b287fabecaedd31beb180d45cf1bf7d88397aecc6f' // } // #endregion signing-1 diff --git a/packages/account/src/signer/signer.test.ts b/packages/account/src/signer/signer.test.ts index a6edf44d149..a24c9ef0593 100644 --- a/packages/account/src/signer/signer.test.ts +++ b/packages/account/src/signer/signer.test.ts @@ -11,7 +11,7 @@ describe('Signer', () => { const expectedPrivateKey = '0x5f70feeff1f229e4a95e1056e8b4d80d0b24b565674860cc213bdb07127ce1b1'; const expectedPublicKey = '0x2f34bc0df4db0ec391792cedb05768832b49b1aa3a2dd8c30054d1af00f67d00b74b7acbbf3087c8e0b1a4c343db50aa471d21f278ff5ce09f07795d541fb47e'; - const expectedAddress = 'fuel1785jcs4epy625cmjuv9u269rymmwv6s6q2y9jhnw877nj2j08ehqce3rxf'; + const expectedAddress = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e'; const expectedMessage = 'my message'; const expectedB256Address = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e'; const expectedSignedMessage = diff --git a/packages/account/src/wallet/keystore-wallet.test.ts b/packages/account/src/wallet/keystore-wallet.test.ts index c68d6331ac8..036f395f27b 100644 --- a/packages/account/src/wallet/keystore-wallet.test.ts +++ b/packages/account/src/wallet/keystore-wallet.test.ts @@ -14,7 +14,7 @@ describe('Keystore Wallet', () => { const privateKey = '0xeac85e732b683119e62fb52ce3b04c0d2f60539cd55af34c731fcdcf802e5ef4'; const address = Address.fromAddressOrString( - 'fuel1v77yj3g6xcatrhkcz72m2njx4cxxzgj8yepywz7ylf4fhkpptawqkh3dft' + '0x67bc49451a363ab1ded81795b54e46ae0c6122472642470bc4fa6a9bd8215f5c' ); const password = '123456'; diff --git a/packages/account/src/wallet/wallet-unlocked.test.ts b/packages/account/src/wallet/wallet-unlocked.test.ts index b21576af0da..b9e7b1dc7ed 100644 --- a/packages/account/src/wallet/wallet-unlocked.test.ts +++ b/packages/account/src/wallet/wallet-unlocked.test.ts @@ -23,7 +23,7 @@ describe('WalletUnlocked', () => { const expectedPrivateKey = '0x5f70feeff1f229e4a95e1056e8b4d80d0b24b565674860cc213bdb07127ce1b1'; const expectedPublicKey = '0x2f34bc0df4db0ec391792cedb05768832b49b1aa3a2dd8c30054d1af00f67d00b74b7acbbf3087c8e0b1a4c343db50aa471d21f278ff5ce09f07795d541fb47e'; - const expectedAddress = 'fuel1785jcs4epy625cmjuv9u269rymmwv6s6q2y9jhnw877nj2j08ehqce3rxf'; + const expectedAddress = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e'; const expectedMessage = 'my message'; const expectedSignedMessage = '0x8eeb238db1adea4152644f1cd827b552dfa9ab3f4939718bb45ca476d167c6512a656f4d4c7356bfb9561b14448c230c6e7e4bd781df5ee9e5999faa6495163d'; diff --git a/packages/address/README.md b/packages/address/README.md index 73b0cb482f7..26620e2a7f7 100644 --- a/packages/address/README.md +++ b/packages/address/README.md @@ -2,10 +2,7 @@ **@fuel-ts/address** is a sub-module for interacting with **Fuel**. -This module contains the utilities for encoding and decoding address and contract ids between Bech32 and other address formats. - -> [!NOTE] Note -> `Bech32` addresses like `fuel1..` are now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) +This module contains the utilities for encoding and decoding address and contract ids between B256 and other address formats. # Table of contents diff --git a/packages/address/package.json b/packages/address/package.json index f82a413a602..717aea35601 100644 --- a/packages/address/package.json +++ b/packages/address/package.json @@ -41,7 +41,6 @@ "@fuel-ts/errors": "workspace:*", "@fuel-ts/interfaces": "workspace:*", "@fuel-ts/utils": "workspace:^", - "@noble/hashes": "^1.5.0", - "bech32": "^2.0.0" + "@noble/hashes": "^1.5.0" } } diff --git a/packages/address/src/address.test.ts b/packages/address/src/address.test.ts index 12e62237ba1..a168d1e9104 100644 --- a/packages/address/src/address.test.ts +++ b/packages/address/src/address.test.ts @@ -1,6 +1,6 @@ import { FuelError } from '@fuel-ts/errors'; import { expectToThrowFuelError } from '@fuel-ts/errors/test-utils'; -import type { AssetId, B256AddressEvm, Bech32Address, EvmAddress } from '@fuel-ts/interfaces'; +import type { AssetId, B256Address, B256AddressEvm, EvmAddress } from '@fuel-ts/interfaces'; import Address from './address'; import * as utils from './utils'; @@ -11,19 +11,12 @@ const ADDRESS_B256 = '0xef86afa9696cf0dc6385e2c407a6e159a1103cefb7e2ae0636fb33d3 const ADDRESS_B256_EVM_PADDED: B256AddressEvm = '0x00000000000000000000000007a6e159a1103cefb7e2ae0636fb33d3cb2a9e4a'; const ADDRESS_EVM = '0x07a6e159a1103cefb7e2ae0636fb33d3cb2a9e4a'; -const ADDRESS_BECH32: Bech32Address = - 'fuel1a7r2l2tfdncdccu9utzq0fhptxs3q080kl32up3klvea8je2ne9qrqnt6n'; const ADDRESS_CHECKSUM = '0xEf86Afa9696cF0Dc6385E2c407a6E159A1103CEfb7e2Ae0636fb33D3cb2A9e4a'; -const ADDRESS_WORDS = [ - 29, 30, 3, 10, 31, 10, 11, 9, 13, 19, 24, 13, 24, 24, 28, 5, 28, 11, 2, 0, 15, 9, 23, 1, 11, 6, - 16, 17, 0, 15, 7, 15, 22, 31, 17, 10, 28, 1, 17, 22, 31, 12, 25, 29, 7, 18, 25, 10, 19, 25, 5, 0, -]; const ADDRESS_BYTES = [ 239, 134, 175, 169, 105, 108, 240, 220, 99, 133, 226, 196, 7, 166, 225, 89, 161, 16, 60, 239, 183, 226, 174, 6, 54, 251, 51, 211, 203, 42, 158, 74, ]; -const expectedAddress = 'fuel1785jcs4epy625cmjuv9u269rymmwv6s6q2y9jhnw877nj2j08ehqce3rxf'; const expectedB256Address = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e'; /** @@ -31,51 +24,12 @@ const expectedB256Address = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6 * @group browser */ describe('Address utils', () => { - test('fromBech32 (bech32 to decoded bech32)', () => { - const result = utils.fromBech32(ADDRESS_BECH32); - - expect(result).toEqual({ - prefix: utils.FUEL_BECH32_HRP_PREFIX, - words: ADDRESS_WORDS, - }); - }); - - test('normalizeBech32 (bech32 to lowercase bech32)', () => { - const result = utils.normalizeBech32(ADDRESS_BECH32.toUpperCase() as Bech32Address); - - expect(result).toEqual(ADDRESS_BECH32); - }); - - test('isBech32 (bech32)', () => { - const result = utils.isBech32(ADDRESS_BECH32); - - expect(result).toBeTruthy(); - }); - - test('isBech32 (b256)', () => { - const result = utils.isBech32(ADDRESS_B256); - - expect(result).toBeFalsy(); - }); - - test('isBech32 (bytes)', () => { - const result = utils.isBech32(new Uint8Array(ADDRESS_BYTES)); - - expect(result).toBeFalsy(); - }); - test('isB256 (b256)', () => { const result = utils.isB256(ADDRESS_B256); expect(result).toBeTruthy(); }); - test('isB256 (bech32)', () => { - const result = utils.isB256(ADDRESS_BECH32); - - expect(result).toBeFalsy(); - }); - test('isB256 (invalid chars)', () => { const result = utils.isB256(`${ADDRESS_B256}/?`); @@ -100,12 +54,6 @@ describe('Address utils', () => { expect(result).toBeFalsy(); }); - test('isB256 (using toB256)', () => { - const result = utils.isB256(utils.toB256(ADDRESS_BECH32)); - - expect(result).toBeTruthy(); - }); - test('isPublicKey (publicKey)', () => { const result = utils.isPublicKey(PUBLIC_KEY); @@ -166,43 +114,8 @@ describe('Address utils', () => { expect(result).toBeFalsy(); }); - test('getBytesFromBech32 (bech32 to Uint8Array)', () => { - const result = utils.getBytesFromBech32(ADDRESS_BECH32); - - expect(result).toEqual(new Uint8Array(ADDRESS_BYTES)); - }); - - test('toBech32 (b256 to bech32)', () => { - const result = utils.toBech32(ADDRESS_B256); - - expect(result).toEqual(ADDRESS_BECH32); - }); - - test('toB256 (bech32 to b256)', () => { - const result = utils.toB256(ADDRESS_BECH32); - - expect(result).toEqual(ADDRESS_B256); - }); - - test('toB256 (b256 to b256)', async () => { - const address = ADDRESS_B256 as Bech32Address; - const expectedError = new FuelError( - FuelError.CODES.INVALID_BECH32_ADDRESS, - `Invalid Bech32 Address: ${address}.` - ); - await expectToThrowFuelError(() => utils.toB256(address), expectedError); - }); - - test('toBech32=>toB256', () => { - const ADDRESS = '0x000000000000000000000000000000000000000000000000000000000000002a'; - const result = utils.toBech32(ADDRESS); - const finalResult = utils.toB256(result); - - expect(finalResult).toEqual(ADDRESS); - }); - test('clearFirst12BytesFromB256 (b256 to evm b256)', () => { - const result = utils.clearFirst12BytesFromB256(ADDRESS_B256); + const result = utils.toB256AddressEvm(ADDRESS_B256); expect(result).toEqual(ADDRESS_B256_EVM_PADDED); }); @@ -213,7 +126,7 @@ describe('Address utils', () => { FuelError.CODES.PARSE_FAILED, `Cannot generate EVM Address B256 from: ${invalidB256}.` ); - await expectToThrowFuelError(() => utils.clearFirst12BytesFromB256(invalidB256), expectedError); + await expectToThrowFuelError(() => utils.toB256AddressEvm(invalidB256), expectedError); }); test('padFirst12BytesOfEvmAddress (evm Address to b256)', () => { @@ -237,9 +150,9 @@ describe('Address utils', () => { describe('Address class', () => { test('instantiate an Address class', () => { - const result = new Address(ADDRESS_BECH32.toUpperCase() as Bech32Address); + const result = new Address(ADDRESS_B256.toUpperCase() as B256Address); - expect(result.toAddress()).toEqual(ADDRESS_BECH32); + expect(result.toAddress()).toEqual(ADDRESS_B256); expect(result.toString()).toEqual(ADDRESS_CHECKSUM); expect(`cast as string${result}`).toEqual(`cast as string${ADDRESS_CHECKSUM}`); expect(result.toB256()).toEqual(ADDRESS_B256); @@ -247,8 +160,8 @@ describe('Address class', () => { }); test('instance equality', () => { - const resultA = new Address(ADDRESS_BECH32); - const resultB = new Address(ADDRESS_BECH32.toUpperCase() as Bech32Address); + const resultA = new Address(ADDRESS_B256); + const resultB = new Address(ADDRESS_B256.toUpperCase() as B256Address); expect(resultA).toEqual(resultB); expect(resultA.equals(resultB)).toBeTruthy(); @@ -258,7 +171,7 @@ describe('Address class', () => { test('create an Address class using public key', () => { const address = Address.fromPublicKey(PUBLIC_KEY); - expect(address.toAddress()).toEqual(expectedAddress); + expect(address.toAddress()).toEqual(expectedB256Address); expect(address.toB256()).toEqual(expectedB256Address); }); @@ -275,7 +188,7 @@ describe('Address class', () => { test('create an Address class using b256Address', () => { const address = Address.fromB256(ADDRESS_B256); - expect(address.toAddress()).toEqual(ADDRESS_BECH32); + expect(address.toAddress()).toEqual(ADDRESS_B256); expect(address.toB256()).toEqual(ADDRESS_B256); }); @@ -289,13 +202,13 @@ describe('Address class', () => { await expectToThrowFuelError(() => Address.fromB256(address), expectedError); }); - test('when parsing to JSON it should show the bech32 address', () => { + test('when parsing to JSON it should show the b256 address', () => { const result = Address.fromB256(expectedB256Address); - expect(JSON.stringify(result)).toEqual(`"${expectedAddress}"`); + expect(JSON.stringify(result)).toEqual(`"${expectedB256Address}"`); }); test('valueOf matches toString', () => { - const address = new Address(ADDRESS_BECH32); + const address = new Address(ADDRESS_B256); expect(address.toString()).toEqual(address.valueOf()); }); @@ -303,18 +216,18 @@ describe('Address class', () => { test('create an Address class fromDynamicInput [public key]', () => { const address = Address.fromDynamicInput(PUBLIC_KEY); - expect(address.toAddress()).toEqual(expectedAddress); + expect(address.toAddress()).toEqual(expectedB256Address); expect(address.toB256()).toEqual(expectedB256Address); }); test('create an Address class fromDynamicInput [b256Address]', () => { const address = Address.fromDynamicInput(expectedB256Address); - expect(address.toAddress()).toEqual(expectedAddress); + expect(address.toAddress()).toEqual(expectedB256Address); }); - test('create an Address class fromDynamicInput [bech32Address]', () => { - const address = Address.fromDynamicInput(expectedAddress); + test('create an Address class fromDynamicInput [b256Address]', () => { + const address = Address.fromDynamicInput(expectedB256Address); expect(address.toB256()).toEqual(expectedB256Address); }); @@ -328,7 +241,7 @@ describe('Address class', () => { test('create an Address class fromDynamicInput [bad input]', async () => { const expectedError = new FuelError( FuelError.CODES.PARSE_FAILED, - `Unknown address format: only 'Bech32', 'B256', or 'Public Key (512)' are supported.` + `Unknown address format: only 'B256', or 'Public Key (512)' are supported.` ); await expectToThrowFuelError(() => Address.fromDynamicInput('badinput'), expectedError); }); @@ -390,7 +303,7 @@ describe('Address class', () => { test('validate checksum address for invalid types', () => { const address = Address.fromRandom(); - expect(Address.isChecksumValid(address.toB256())).toBeFalsy(); + expect(Address.isChecksumValid(address.toB256().toLowerCase())).toBeFalsy(); expect( Address.isChecksumValid('0x9cfB2CAd509D417ec40b70ebE1DD72a3624D46fdD1Ea5420dBD755CE7f4dc897') ).toBeFalsy(); diff --git a/packages/address/src/address.ts b/packages/address/src/address.ts index 6f99a248fe5..c6ac5de0744 100644 --- a/packages/address/src/address.ts +++ b/packages/address/src/address.ts @@ -1,27 +1,17 @@ import { FuelError } from '@fuel-ts/errors'; import { AbstractAddress } from '@fuel-ts/interfaces'; -import type { - Bech32Address, - B256Address, - EvmAddress, - AssetId, - ChecksumAddress, -} from '@fuel-ts/interfaces'; +import type { B256Address, EvmAddress, AssetId, ChecksumAddress } from '@fuel-ts/interfaces'; import { arrayify, hexlify } from '@fuel-ts/utils'; import { sha256 } from '@noble/hashes/sha256'; import { - normalizeBech32, - isBech32, - toB256, - getBytesFromBech32, - toBech32, getRandomB256, isPublicKey, isB256, - clearFirst12BytesFromB256, isEvmAddress, padFirst12BytesOfEvmAddress, + toB256AddressEvm, + normalizeB256, } from './utils'; /** @@ -30,31 +20,23 @@ import { */ export default class Address extends AbstractAddress { // #region address-2 - /** - * @deprecated - * Type `Bech32Address` is now deprecated, as is this property. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) - */ - readonly bech32Address: Bech32Address; + readonly b256Address: B256Address; // #endregion address-2 /** - * @param address - A Bech32 address or B256 address + * @param address - A B256 address */ - constructor(address: Bech32Address | B256Address) { + constructor(address: B256Address) { super(); - if (isB256(address)) { - this.bech32Address = toBech32(address); - } else { - this.bech32Address = normalizeBech32(address as Bech32Address); - - if (!isBech32(this.bech32Address)) { - throw new FuelError( - FuelError.CODES.INVALID_BECH32_ADDRESS, - `Invalid Bech32 Address: ${this.bech32Address}.` - ); - } + if (!isB256(address)) { + throw new FuelError( + FuelError.CODES.INVALID_B256_ADDRESS, + `Invalid B256 Address: ${address}.` + ); } + + this.b256Address = normalizeB256(address); } /** @@ -64,38 +46,38 @@ export default class Address extends AbstractAddress { * @returns A new `ChecksumAddress` instance */ toChecksum(): ChecksumAddress { - return Address.toChecksum(this.toB256()); + return Address.toChecksum(this.b256Address); } /** - * Returns the `bech32Address` property - * @deprecated - * Type `Bech32Address` is now deprecated, as is this method. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) - * @returns The `bech32Address` property + * Returns the `b256Address` property */ - toAddress(): Bech32Address { - return this.bech32Address; + toAddress(): B256Address { + return this.b256Address; } /** - * Converts and returns the `bech32Address` property to a 256 bit hash string - * @returns The `bech32Address` property as a 256 bit hash string + * Returns the B256 hash address as a string + * + * @returns The B256 address */ toB256(): B256Address { - return toB256(this.bech32Address); + return this.b256Address; } /** - * Converts and returns the `bech32Address` property to a byte array - * @returns The `bech32Address` property as a byte array + * Returns the B256 hash address as a Uint8Array + * + * @returns The B256 address as a Uint8Array */ toBytes(): Uint8Array { - return getBytesFromBech32(this.bech32Address); + return arrayify(this.b256Address); } /** - * Converts the `bech32Address` property to a 256 bit hash string - * @returns The `bech32Address` property as a 256 bit hash string + * Returns the B256 hash address as a string + * + * @returns The B256 address */ toHexString(): B256Address { return this.toB256(); @@ -104,29 +86,28 @@ export default class Address extends AbstractAddress { /** * returns the address `checksum` as a string * - * @returns The `bech32Address` property as a string + * @returns The `b256Address` property as a string */ toString(): string { return this.toChecksum(); } /** - * Converts and returns the `bech32Address` property as a string - * @returns The `bech32Address` property as a JSON string + * Converts and returns the `b256Address` property as a string + * @returns The `b256Address` property as a JSON string */ toJSON(): string { - return this.bech32Address; + return this.b256Address; } /** - * Clears the first 12 bytes of the `bech32Address` property and returns it as a `EvmAddress` - * @returns The `bech32Address` property as an {@link EvmAddress | `EvmAddress`} + * Converts to an EVM address + * + * @returns an {@link EvmAddress | `EvmAddress`} representation of the address */ toEvmAddress(): EvmAddress { - const b256Address = toB256(this.bech32Address); - return { - bits: clearFirst12BytesFromB256(b256Address), + bits: toB256AddressEvm(this.b256Address), } as EvmAddress; } @@ -136,7 +117,7 @@ export default class Address extends AbstractAddress { */ toAssetId(): AssetId { return { - bits: this.toB256(), + bits: this.b256Address, } as AssetId; } @@ -149,12 +130,12 @@ export default class Address extends AbstractAddress { } /** - * Compares this the `bech32Address` property to another for direct equality + * Compares this the `b256Address` property to another for direct equality * @param other - Another address to compare against * @returns The equality of the comparison */ equals(other: Address): boolean { - return this.bech32Address === other.bech32Address; + return this.toChecksum() === other.toChecksum(); } /** @@ -169,7 +150,7 @@ export default class Address extends AbstractAddress { } const b256Address = hexlify(sha256(arrayify(publicKey))); - return new Address(toBech32(b256Address)); + return new Address(b256Address); } /** @@ -186,11 +167,11 @@ export default class Address extends AbstractAddress { ); } - return new Address(toBech32(b256Address)); + return new Address(b256Address); } /** - * Creates an `Address` with a randomized `bech32Address` property + * Creates an `Address` with a randomized `b256Address` property * * @returns A new `Address` instance */ @@ -205,7 +186,7 @@ export default class Address extends AbstractAddress { * @returns A new `Address` instance */ static fromString(address: string): Address { - return isBech32(address) ? new Address(address as Bech32Address) : this.fromB256(address); + return this.fromB256(address); } /** @@ -220,7 +201,7 @@ export default class Address extends AbstractAddress { /** * Takes a dynamic string or `AbstractAddress` and creates an `Address` * - * @param addressId - A string containing Bech32, B256, or Public Key + * @param addressId - A string containing B256, or Public Key * @throws Error - Unknown address if the format is not recognised * @returns A new `Address` instance */ @@ -235,10 +216,6 @@ export default class Address extends AbstractAddress { return Address.fromPublicKey(address); } - if (isBech32(address)) { - return new Address(address as Bech32Address); - } - if (isB256(address)) { return Address.fromB256(address); } @@ -249,7 +226,7 @@ export default class Address extends AbstractAddress { throw new FuelError( FuelError.CODES.PARSE_FAILED, - `Unknown address format: only 'Bech32', 'B256', or 'Public Key (512)' are supported.` + `Unknown address format: only 'B256', or 'Public Key (512)' are supported.` ); } @@ -267,8 +244,7 @@ export default class Address extends AbstractAddress { } const paddedAddress = padFirst12BytesOfEvmAddress(evmAddress); - - return new Address(toBech32(paddedAddress)); + return new Address(paddedAddress); } /** diff --git a/packages/address/src/utils.ts b/packages/address/src/utils.ts index 8123b22c8f9..9f4b7be00e0 100644 --- a/packages/address/src/utils.ts +++ b/packages/address/src/utils.ts @@ -2,61 +2,13 @@ import { randomBytes } from '@fuel-ts/crypto'; import { FuelError } from '@fuel-ts/errors'; import { AbstractContract, AbstractAccount } from '@fuel-ts/interfaces'; import type { - Bech32Address, B256Address, AddressLike, ContractIdLike, AbstractAddress, B256AddressEvm, - BytesLike, } from '@fuel-ts/interfaces'; -import { arrayify, hexlify } from '@fuel-ts/utils'; -import type { Decoded } from 'bech32'; -import { bech32m } from 'bech32'; - -/** - * Fuel Network HRP (human-readable part) for bech32 encoding - * - * @hidden - */ -export const FUEL_BECH32_HRP_PREFIX = 'fuel'; - -/** - * Decodes a Bech32 address string into Decoded - * @deprecated - * Type `Bech32Address` is now deprecated, as is this function. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) - * @hidden - */ -export function fromBech32(address: Bech32Address): Decoded { - return bech32m.decode(address); -} - -/** - * Converts a B256 address string into Bech32 - * @deprecated - * Type `Bech32Address` is now deprecated, as is this function. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) - * @hidden - */ -export function toBech32(address: B256Address): Bech32Address { - return bech32m.encode( - FUEL_BECH32_HRP_PREFIX, - bech32m.toWords(arrayify(hexlify(address))) - ) as Bech32Address; -} - -/** - * Determines if a given string is Bech32 format - * @deprecated - * Type `Bech32Address` is now deprecated, as is this function. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) - * @hidden - */ -export function isBech32(address: BytesLike): boolean { - return ( - typeof address === 'string' && - address.indexOf(FUEL_BECH32_HRP_PREFIX + 1) === 0 && - fromBech32(address as Bech32Address).prefix === FUEL_BECH32_HRP_PREFIX - ); -} +import { arrayify, concat, hexlify } from '@fuel-ts/utils'; /** * Determines if a given string is B256 format @@ -85,42 +37,8 @@ export function isEvmAddress(address: string): boolean { return address.length === 42 && /(0x)[0-9a-f]{40}$/i.test(address); } -/** - * Takes a Bech32 address and returns the byte data - * @deprecated - * The `bech32Address` is now deprecated. Please migrate to B256 format (see https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256 for more details) as this will be the standard going forward. - * @hidden - */ -export function getBytesFromBech32(address: Bech32Address): Uint8Array { - return new Uint8Array(bech32m.fromWords(fromBech32(address).words)); -} - -/** - * Converts a Bech32 address string into B256 - * @hidden - */ -export function toB256(address: Bech32Address): B256Address { - if (!isBech32(address)) { - throw new FuelError( - FuelError.CODES.INVALID_BECH32_ADDRESS, - `Invalid Bech32 Address: ${address}.` - ); - } - - return hexlify(getBytesFromBech32(address)); -} - -/** - * Takes a Bech32 address and returns a normalized (i.e. lower case) representation of it. - * - * The input is validated along the way, which makes this significantly safer than - * using `address.toLowerCase()`. - * - * @hidden - */ -export function normalizeBech32(address: Bech32Address): Bech32Address { - const { words } = fromBech32(address); - return bech32m.encode(FUEL_BECH32_HRP_PREFIX, words) as Bech32Address; +export function normalizeB256(address: B256Address): B256Address { + return address.toLowerCase(); } /** @@ -153,27 +71,21 @@ export const getRandomB256 = () => hexlify(randomBytes(32)); * * @hidden */ -export const clearFirst12BytesFromB256 = (b256: B256Address): B256AddressEvm => { - let bytes; - +export const toB256AddressEvm = (b256: B256Address): B256AddressEvm => { try { if (!isB256(b256)) { - throw new FuelError( - FuelError.CODES.INVALID_BECH32_ADDRESS, - `Invalid Bech32 Address: ${b256}.` - ); + throw new FuelError(FuelError.CODES.INVALID_B256_ADDRESS, `Invalid B256 Address: ${b256}.`); } - bytes = getBytesFromBech32(toBech32(b256)); - bytes = hexlify(bytes.fill(0, 0, 12)) as B256AddressEvm; + const evmBytes = arrayify(b256).slice(12); + const paddedBytes = new Uint8Array(12).fill(0); + return hexlify(concat([paddedBytes, evmBytes])) as B256AddressEvm; } catch (error) { throw new FuelError( FuelError.CODES.PARSE_FAILED, `Cannot generate EVM Address B256 from: ${b256}.` ); } - - return bytes; }; /** diff --git a/packages/errors/src/error-codes.ts b/packages/errors/src/error-codes.ts index 2959d4e6212..6728db60612 100644 --- a/packages/errors/src/error-codes.ts +++ b/packages/errors/src/error-codes.ts @@ -25,12 +25,6 @@ export enum ErrorCode { WORKSPACE_NOT_DETECTED = 'workspace-not-detected', // address - /** - * @deprecated - * Type `Bech32Address` is now deprecated, as is this constant. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) - */ - INVALID_BECH32_ADDRESS = 'invalid-bech32-address', - INVALID_EVM_ADDRESS = 'invalid-evm-address', INVALID_B256_ADDRESS = 'invalid-b256-address', diff --git a/packages/fuel-gauge/src/doc-examples.test.ts b/packages/fuel-gauge/src/doc-examples.test.ts index 535e6378ae7..3e31b52d923 100644 --- a/packages/fuel-gauge/src/doc-examples.test.ts +++ b/packages/fuel-gauge/src/doc-examples.test.ts @@ -1,4 +1,4 @@ -import type { Bech32Address, BigNumberish, Bytes, WalletLocked } from 'fuels'; +import type { BigNumberish, Bytes, WalletLocked } from 'fuels'; import { bn, hashMessage, @@ -26,9 +26,6 @@ const PUBLIC_KEY = const ADDRESS_B256 = '0xf1e92c42b90934aa6372e30bc568a326f6e66a1a0288595e6e3fbd392a4f3e6e'; -const ADDRESS_BECH32: Bech32Address = - 'fuel1785jcs4epy625cmjuv9u269rymmwv6s6q2y9jhnw877nj2j08ehqce3rxf'; - const ADDRESS_BYTES = new Uint8Array([ 241, 233, 44, 66, 185, 9, 52, 170, 99, 114, 227, 11, 197, 104, 163, 38, 246, 230, 106, 26, 2, 136, 89, 94, 110, 63, 189, 57, 42, 79, 62, 110, @@ -39,8 +36,8 @@ const ADDRESS_BYTES = new Uint8Array([ * @group browser */ describe('Doc Examples', () => { - test('it has an Address class using bech32Address', () => { - const address = new Address(ADDRESS_BECH32); + test('it has an Address class using b256Address', () => { + const address = new Address(ADDRESS_B256); expect(address.toB256()).toEqual(ADDRESS_B256); expect(address.toBytes()).toEqual(ADDRESS_BYTES); @@ -50,14 +47,14 @@ describe('Doc Examples', () => { test('it has an Address class using public key', () => { const address = Address.fromPublicKey(PUBLIC_KEY); - expect(address.toAddress()).toEqual(ADDRESS_BECH32); + expect(address.toAddress()).toEqual(ADDRESS_B256); expect(address.toB256()).toEqual(ADDRESS_B256); }); test('it has an Address class using b256Address', () => { const address = Address.fromB256(ADDRESS_B256); - expect(address.toAddress()).toEqual(ADDRESS_BECH32); + expect(address.toAddress()).toEqual(ADDRESS_B256); expect(address.toB256()).toEqual(ADDRESS_B256); }); @@ -65,8 +62,7 @@ describe('Doc Examples', () => { // you can make a random address - useful for testing const address = Address.fromRandom(); - // you can it has a new Address from an ambiguous source that may be a Bech32 or B256 address - const addressCloneFromBech = Address.fromString(address.toString()); + // you can it has a new Address from an ambiguous source that may be a B256 address const addressCloneFromB256 = Address.fromString(address.toB256()); // if you aren't sure where the address comes from, use fromDynamicInput @@ -76,8 +72,7 @@ describe('Doc Examples', () => { const someAddress = Address.fromDynamicInput(dataFromInput); // you can verify equality using the helper functions - expect(address.equals(addressCloneFromBech)).toBeTruthy(); - expect(addressCloneFromBech.toString()).toEqual(addressCloneFromB256.toString()); + expect(address.equals(addressCloneFromB256)).toBeTruthy(); expect(someAddress).toBeTruthy(); }); diff --git a/packages/fuel-gauge/src/e2e-script.test.ts b/packages/fuel-gauge/src/e2e-script.test.ts index 674fed133c8..b1c692017cf 100644 --- a/packages/fuel-gauge/src/e2e-script.test.ts +++ b/packages/fuel-gauge/src/e2e-script.test.ts @@ -84,13 +84,13 @@ describe.each(selectedNetworks)('Live Script Test', (selectedNetwork) => { output = value; } catch (e) { - const address = wallet.address.toAddress(); + const address = wallet.address.toB256(); console.error((e as Error).message); console.warn(` not enough coins to fit the target? - add assets: ${configuredNetworks[selectedNetwork].faucetUrl} - - bech32 address: ${address} + - B256 address: ${address} `); } diff --git a/packages/interfaces/src/index.ts b/packages/interfaces/src/index.ts index 12e07905429..f5d558f64c5 100644 --- a/packages/interfaces/src/index.ts +++ b/packages/interfaces/src/index.ts @@ -7,13 +7,6 @@ * TODO: Consider re-distritubing interfaces near their original packages */ -// #region bech32-1 -/** - * @deprecated - * Type `Bech32Address` is now deprecated. Use `B256` addresses instead. ([help](https://docs.fuel.network/docs/specs/abi/argument-encoding/#b256)) - */ -export type Bech32Address = `fuel${string}`; -// #endregion bech32-1 export type B256Address = string; export type ChecksumAddress = string; @@ -55,7 +48,7 @@ export abstract class AbstractScriptRequest { export abstract class AbstractAddress { abstract toJSON(): string; abstract toString(): string; - abstract toAddress(): Bech32Address; + abstract toAddress(): B256Address; abstract toB256(): B256Address; abstract toHexString(): string; abstract toBytes(): Uint8Array; diff --git a/packages/logger/src/index.ts b/packages/logger/src/index.ts index a93a53989c5..dea385796b0 100644 --- a/packages/logger/src/index.ts +++ b/packages/logger/src/index.ts @@ -20,7 +20,6 @@ * * log('with this walletAddress: %w', address) * log('and this B256: %b', address) - * log('and this bech32 address : %n', address) * ``` * * ```console @@ -31,7 +30,6 @@ * ``` */ -import { toBech32 } from '@fuel-ts/address'; import type { Address } from '@fuel-ts/address'; import type { AbstractAddress } from '@fuel-ts/interfaces'; import type { BN } from '@fuel-ts/math'; @@ -108,10 +106,6 @@ debug.formatters.a = (v?: BN): string => { // Add a formatter for converting to a b256 string debug.formatters.b = (v?: AbstractAddress): string => (v == null ? 'undefined' : v.toB256()); -// Add a formatter for outputting a bech32 address -debug.formatters.c = (v?: AbstractAddress): string => - v == null ? 'undefined' : toBech32(v.toString()); - // Add a formatter for outputting a BN hex string debug.formatters.h = (v?: BN): string => (v == null ? 'undefined' : v.toHex()); diff --git a/packages/logger/test/index.test.ts b/packages/logger/test/index.test.ts index 655af61e57d..f3933fce4bf 100644 --- a/packages/logger/test/index.test.ts +++ b/packages/logger/test/index.test.ts @@ -1,4 +1,3 @@ -import type { AbstractAddress } from '@fuel-ts/interfaces'; import { BN } from '@fuel-ts/math'; import debug from 'debug'; import type { MockInstance } from 'vitest'; @@ -99,25 +98,6 @@ describe('Logger Tests', () => { expect(formatted).toBe('undefined'); }); - it('should format AbstractAddress to bech32 string using formatter c', () => { - const mockAddress: AbstractAddress = { - toJSON: () => '', - toString: () => '0x000000000000000000000000000000000000000000000000000000000000002a', - toAddress: () => 'fuel1xyzabc123', - toB256: () => '', - toHexString: () => '', - toBytes: () => new Uint8Array(), - equals: () => false, - }; - const formatted = debug.formatters.c(mockAddress); - expect(formatted).toBe('fuel1qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq4qvpkv30'); - }); - - it('should return undefined for null input using formatter c', () => { - const formatted = debug.formatters.c(null); - expect(formatted).toBe('undefined'); - }); - it('should format BN to hex string using formatter h', () => { const bnValue = new BN('255'); const formatted = debug.formatters.h(bnValue); diff --git a/packages/recipes/src/types/Src14OwnedProxy.ts b/packages/recipes/src/types/Src14OwnedProxy.ts index dcfab7009a8..aab3c9532ae 100644 --- a/packages/recipes/src/types/Src14OwnedProxy.ts +++ b/packages/recipes/src/types/Src14OwnedProxy.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.97.0 + Fuels version: 0.97.2 */ import { Contract, type InvokeFunction } from '@fuel-ts/program'; diff --git a/packages/recipes/src/types/Src14OwnedProxyFactory.ts b/packages/recipes/src/types/Src14OwnedProxyFactory.ts index b0789cb3f5a..30762b7a0e9 100644 --- a/packages/recipes/src/types/Src14OwnedProxyFactory.ts +++ b/packages/recipes/src/types/Src14OwnedProxyFactory.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.97.0 + Fuels version: 0.97.2 */ import { ContractFactory, type DeployContractOptions } from '@fuel-ts/contract'; diff --git a/packages/recipes/src/types/common.d.ts b/packages/recipes/src/types/common.d.ts index d7ca20eaa69..ef3dec5e95c 100644 --- a/packages/recipes/src/types/common.d.ts +++ b/packages/recipes/src/types/common.d.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.97.0 + Fuels version: 0.97.2 */ /** diff --git a/packages/recipes/src/types/index.ts b/packages/recipes/src/types/index.ts index 22dd3591167..15dc6b12ae3 100644 --- a/packages/recipes/src/types/index.ts +++ b/packages/recipes/src/types/index.ts @@ -5,7 +5,7 @@ /* eslint-disable @typescript-eslint/consistent-type-imports */ /* - Fuels version: 0.97.0 + Fuels version: 0.97.2 */ export { Src14OwnedProxy } from './Src14OwnedProxy'; diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9da1024d276..dcc7a2cfdf6 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -786,9 +786,6 @@ importers: '@noble/hashes': specifier: ^1.5.0 version: 1.5.0 - bech32: - specifier: ^2.0.0 - version: 2.0.0 packages/contract: dependencies: @@ -7024,9 +7021,6 @@ packages: bcrypt-pbkdf@1.0.2: resolution: {integrity: sha512-qeFIXtP4MSoi6NLqO12WfqARWWuCKi2Rn/9hJLEmtB5yTNr9DqFWkJRCf2qShWzPeAMRnOgCrq0sg/KLv5ES9w==} - bech32@2.0.0: - resolution: {integrity: sha512-LcknSilhIGatDAsY1ak2I8VtGaHNhgMSYVxFrGLXv+xLHytaKZKcaUJJUE7qmBr7h33o5YQwP55pMI0xmkpJwg==} - before-after-hook@2.2.3: resolution: {integrity: sha512-NzUnlZexiaH/46WDhANlyR2bXRopNg4F/zuSA3OpZnllCUgRaOF2znDioDWrmbNVsuZk6l9pMquQB38cfBZwkQ==} @@ -25029,8 +25023,6 @@ snapshots: dependencies: tweetnacl: 0.14.5 - bech32@2.0.0: {} - before-after-hook@2.2.3: {} better-path-resolve@1.0.0: From d5a696c9ac95ba969e6243d10fd96be166442d12 Mon Sep 17 00:00:00 2001 From: Ivan Oberemok Date: Thu, 2 Jan 2025 15:08:31 +0200 Subject: [PATCH 3/4] feat: added method to duplicate predicate (#3432) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: added static method to duplicate predicate * chore: refactored toNewInstance method * chore: fixed some lint errors * chore: added changeset * Update packages/fuel-gauge/src/predicate/predicate-duplication.test.ts Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> * Update packages/fuel-gauge/src/predicate/predicate-duplication.test.ts Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> * Update packages/fuel-gauge/src/predicate/predicate-duplication.test.ts Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> * Update packages/fuel-gauge/src/predicate/predicate-duplication.test.ts Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> * Update packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> * Update packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> * chore: removed helpers * chore: typing in fund function * chore: refactored fundPredicate function to fundAccount * feat: added method to duplicate predicate --------- Co-authored-by: Dhaiwat Co-authored-by: Sérgio Torres <30977845+Torres-ssf@users.noreply.github.com> Co-authored-by: Anderson Arboleya --- .changeset/gentle-toes-play.md | 5 + packages/account/src/predicate/predicate.ts | 22 +- .../src/predicate/predicate-arguments.test.ts | 20 +- .../predicate/predicate-configurables.test.ts | 14 +- .../predicate/predicate-duplication.test.ts | 352 ++++++++++++++++++ .../predicate/predicate-estimations.test.ts | 16 +- .../predicate/predicate-evaluations.test.ts | 6 +- .../predicate/predicate-input-data.test.ts | 4 +- .../predicate/predicate-invalidations.test.ts | 6 +- .../predicate-populate-witness.test.ts | 20 +- .../predicate/predicate-with-contract.test.ts | 6 +- .../predicate/predicate-with-script.test.ts | 4 +- .../predicate/utils/predicate/fundAccount.ts | 26 ++ .../utils/predicate/fundPredicate.ts | 30 -- .../src/predicate/utils/predicate/index.ts | 2 +- templates/nextjs/src/components/Predicate.tsx | 2 +- templates/vite/src/components/Predicate.tsx | 2 +- 17 files changed, 455 insertions(+), 82 deletions(-) create mode 100644 .changeset/gentle-toes-play.md create mode 100644 packages/fuel-gauge/src/predicate/predicate-duplication.test.ts create mode 100644 packages/fuel-gauge/src/predicate/utils/predicate/fundAccount.ts delete mode 100644 packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts diff --git a/.changeset/gentle-toes-play.md b/.changeset/gentle-toes-play.md new file mode 100644 index 00000000000..98b9a4d469b --- /dev/null +++ b/.changeset/gentle-toes-play.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": patch +--- + +feat: added method to duplicate predicate diff --git a/packages/account/src/predicate/predicate.ts b/packages/account/src/predicate/predicate.ts index 1bc90f4a05e..2e9dacdb4c0 100644 --- a/packages/account/src/predicate/predicate.ts +++ b/packages/account/src/predicate/predicate.ts @@ -48,7 +48,8 @@ export class Predicate< bytes: Uint8Array; predicateData: TData = [] as unknown as TData; interface: Interface; - + initialBytecode: Uint8Array; + configurableConstants: TConfigurables | undefined; /** * Creates an instance of the Predicate class. * @@ -73,8 +74,10 @@ export class Predicate< const address = Address.fromB256(getPredicateRoot(predicateBytes)); super(address, provider); + this.initialBytecode = arrayify(bytecode); this.bytes = predicateBytes; this.interface = predicateInterface; + this.configurableConstants = configurableConstants; if (data !== undefined && data.length > 0) { this.predicateData = data; } @@ -147,6 +150,23 @@ export class Predicate< return mainFn?.encodeArguments(this.predicateData) || new Uint8Array(); } + /** + * Creates a new Predicate instance from an existing Predicate instance. + * @param overrides - The data and configurable constants to override. + * @returns A new Predicate instance with the same bytecode, ABI and provider but with the ability to set the data and configurable constants. + */ + toNewInstance( + overrides: Pick, 'data' | 'configurableConstants'> = {} + ) { + return new Predicate({ + bytecode: this.initialBytecode, + abi: this.interface.jsonAbi, + provider: this.provider, + data: overrides.data ?? this.predicateData, + configurableConstants: overrides.configurableConstants ?? this.configurableConstants, + }); + } + /** * Processes the predicate data and returns the altered bytecode and interface. * diff --git a/packages/fuel-gauge/src/predicate/predicate-arguments.test.ts b/packages/fuel-gauge/src/predicate/predicate-arguments.test.ts index d9c6d2f8ee9..84e0ddd80c9 100644 --- a/packages/fuel-gauge/src/predicate/predicate-arguments.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-arguments.test.ts @@ -9,7 +9,7 @@ import { PredicateU32, } from '../../test/typegen'; -import { fundPredicate, assertBalances } from './utils/predicate'; +import { fundAccount, assertBalances } from './utils/predicate'; /** * @group node @@ -34,7 +34,7 @@ describe('Predicate', () => { }); // transfer funds to predicate - await fundPredicate(fundingWallet, predicate, amountToPredicate, 3); + await fundAccount(fundingWallet, predicate, amountToPredicate, 3); const receiver = Wallet.generate({ provider }); const initialReceiverBalance = await receiver.getBalance(); @@ -67,7 +67,7 @@ describe('Predicate', () => { }); // fund predicate - await fundPredicate(fundingWallet, predicate, amountToPredicate); + await fundAccount(fundingWallet, predicate, amountToPredicate); const receiver = Wallet.generate({ provider }); @@ -91,7 +91,7 @@ describe('Predicate', () => { const initialReceiverBalance = await receiver.getBalance(); // fund predicate - await fundPredicate(fundingWallet, predicate, amountToPredicate); + await fundAccount(fundingWallet, predicate, amountToPredicate); const tx = await predicate.transfer( receiver.address, @@ -118,7 +118,7 @@ describe('Predicate', () => { const predicate = new PredicateU32({ provider, data: [100] }); // fund predicate - await fundPredicate(fundingWallet, predicate, 90_000_00, 3); + await fundAccount(fundingWallet, predicate, 90_000_00, 3); const receiver = Wallet.generate({ provider }); const initialReceiverBalance = await receiver.getBalance(); @@ -191,7 +191,7 @@ describe('Predicate', () => { const receiver = Wallet.generate({ provider }); // fund predicate - await fundPredicate(fundingWallet, predicate, amountToPredicate); + await fundAccount(fundingWallet, predicate, amountToPredicate); await expect( predicate.transfer(receiver.address, 50, provider.getBaseAssetId(), { gasLimit: 1000 }) @@ -212,7 +212,7 @@ describe('Predicate', () => { const initialReceiverBalance = await receiver.getBalance(); // fund predicate - await fundPredicate(fundingWallet, predicate, amountToPredicate); + await fundAccount(fundingWallet, predicate, amountToPredicate); const tx = await predicate.transfer( receiver.address, @@ -242,7 +242,7 @@ describe('Predicate', () => { const predicate = new PredicateMultiArgs({ provider, data: [20, 30] }); // fund the predicate - await fundPredicate(fundingWallet, predicate, amountToPredicate); + await fundAccount(fundingWallet, predicate, amountToPredicate); const tx = await predicate.transfer( receiver.address, @@ -272,7 +272,7 @@ describe('Predicate', () => { const predicate = new PredicateMultiArgs({ provider, data: [20, 30] }); // fund predicate - await fundPredicate(fundingWallet, predicate, amountToPredicate); + await fundAccount(fundingWallet, predicate, amountToPredicate); const tx = await predicate.transfer( receiver.address, @@ -299,7 +299,7 @@ describe('Predicate', () => { const predicate = new PredicateMultiArgs({ provider, data: [20, 20] }); // fund predicate - await fundPredicate(fundingWallet, predicate, amountToPredicate); + await fundAccount(fundingWallet, predicate, amountToPredicate); const receiver = Wallet.generate({ provider }); diff --git a/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts b/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts index 582f757e1a2..2a409c3d651 100644 --- a/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-configurables.test.ts @@ -3,7 +3,7 @@ import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils'; import { PredicateTrue, PredicateWithConfigurable } from '../../test/typegen'; -import { fundPredicate, assertBalance } from './utils/predicate'; +import { fundAccount, assertBalance } from './utils/predicate'; /** * @group node @@ -33,7 +33,7 @@ describe('Predicate', () => { const amountToTransfer = 200; - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); // create destination wallet const destination = WalletUnlocked.generate({ @@ -82,7 +82,7 @@ describe('Predicate', () => { await assertBalance(destination, 0, provider.getBaseAssetId()); // transfer funds to predicate - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); // executing predicate transfer const tx = await predicate.transfer( @@ -125,7 +125,7 @@ describe('Predicate', () => { await assertBalance(destination, 0, provider.getBaseAssetId()); // transfer funds to predicate - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); // executing predicate transfer const tx = await predicate.transfer( @@ -171,7 +171,7 @@ describe('Predicate', () => { await assertBalance(destination, 0, provider.getBaseAssetId()); - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); const tx = await predicate.transfer( destination.address, @@ -213,7 +213,7 @@ describe('Predicate', () => { await assertBalance(destination, 0, provider.getBaseAssetId()); - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); const tx = await predicate.transfer( destination.address, @@ -245,7 +245,7 @@ describe('Predicate', () => { provider: wallet.provider, }); - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); await expect( predicate.transfer(destination.address, 300, provider.getBaseAssetId(), { gasLimit: 1000 }) diff --git a/packages/fuel-gauge/src/predicate/predicate-duplication.test.ts b/packages/fuel-gauge/src/predicate/predicate-duplication.test.ts new file mode 100644 index 00000000000..54cec443091 --- /dev/null +++ b/packages/fuel-gauge/src/predicate/predicate-duplication.test.ts @@ -0,0 +1,352 @@ +import { WalletUnlocked } from '@fuel-ts/account'; +import { launchTestNode } from 'fuels/test-utils'; + +import { PredicateWithConfigurable } from '../../test/typegen'; +import type { + PredicateWithConfigurableConfigurables, + PredicateWithConfigurableInputs, +} from '../../test/typegen/predicates/PredicateWithConfigurable'; + +import { fundAccount, assertBalance } from './utils/predicate'; + +/** + * @group node + * @group browser + */ +describe('Predicate.fromInstance', () => { + const amountToPredicate = 300_000; + + const defaultValues = { + FEE: 10, + ADDRESS: '0x38966262edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96', + }; + + it('creates new predicate instance from existing one with default values', async () => { + using launched = await launchTestNode(); + + const provider = launched.provider; + const basePredicate = new PredicateWithConfigurable({ + provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const newPredicate: PredicateWithConfigurable = basePredicate.toNewInstance(); + + expect(newPredicate.predicateData).toEqual(basePredicate.predicateData); + expect(newPredicate.interface).toEqual(basePredicate.interface); + expect(newPredicate.provider).toEqual(basePredicate.provider); + expect(newPredicate.bytes).toEqual(basePredicate.bytes); + }); + + it('creates new predicate instance with custom data', async () => { + using launched = await launchTestNode(); + + const provider = launched.provider; + const basePredicate = new PredicateWithConfigurable({ + provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const data: PredicateWithConfigurableInputs = [ + 13, + '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96', + ]; + const newPredicate: PredicateWithConfigurable = basePredicate.toNewInstance({ data }); + + expect(newPredicate.predicateData).toEqual(data); + expect(newPredicate.interface).toEqual(basePredicate.interface); + expect(newPredicate.provider).toEqual(basePredicate.provider); + expect(newPredicate.bytes).toEqual(basePredicate.bytes); + expect(newPredicate.predicateData).not.toEqual(basePredicate.predicateData); + }); + + it('creates new predicate instance with configurable constants', async () => { + using launched = await launchTestNode(); + + const provider = launched.provider; + const basePredicate = new PredicateWithConfigurable({ + provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const configurableConstants: PredicateWithConfigurableConfigurables = { + FEE: 13, + ADDRESS: '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96', + }; + const newPredicate: PredicateWithConfigurable = basePredicate.toNewInstance({ + configurableConstants, + }); + + expect(newPredicate.predicateData).toEqual(basePredicate.predicateData); + expect(newPredicate.interface).toEqual(basePredicate.interface); + expect(newPredicate.provider).toEqual(basePredicate.provider); + expect(newPredicate.bytes).toEqual( + new PredicateWithConfigurable({ + provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants, + }).bytes + ); + }); + + it('supports chaining withData and withConfigurableConstants', async () => { + using launched = await launchTestNode(); + + const provider = launched.provider; + const basePredicate = new PredicateWithConfigurable({ + provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const data: PredicateWithConfigurableInputs = [ + 13, + '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96', + ]; + const configurableConstants: PredicateWithConfigurableConfigurables = { + FEE: 13, + ADDRESS: '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96', + }; + const newPredicate: PredicateWithConfigurable = basePredicate.toNewInstance({ + data, + configurableConstants, + }); + + expect(newPredicate.predicateData).toEqual(data); + expect(newPredicate.interface).toEqual(basePredicate.interface); + expect(newPredicate.provider).toEqual(basePredicate.provider); + expect(newPredicate.bytes).toEqual( + new PredicateWithConfigurable({ + provider, + data, + configurableConstants, + }).bytes + ); + }); + + it('can create multiple different instances from same source, same bytecode', async () => { + using launched = await launchTestNode(); + + const provider = launched.provider; + const basePredicate = new PredicateWithConfigurable({ + provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const newPredicate1 = basePredicate.toNewInstance(); + const newPredicate2 = basePredicate.toNewInstance(); + + expect(newPredicate1.bytes).toEqual(newPredicate2.bytes); + }); + + it('can create multiple different instances from same source, different bytecode', async () => { + using launched = await launchTestNode(); + + const provider = launched.provider; + const basePredicate = new PredicateWithConfigurable({ + provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const configurableConstants: PredicateWithConfigurableConfigurables = { + FEE: 13, + ADDRESS: '0x38966262edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96', + }; + const newPredicate1 = basePredicate.toNewInstance(); + const newPredicate2 = basePredicate.toNewInstance({ configurableConstants }); + + expect(newPredicate1.bytes).not.toEqual(newPredicate2.bytes); + }); + + it('does not modify original instance', async () => { + using launched = await launchTestNode(); + + const provider = launched.provider; + const basePredicate = new PredicateWithConfigurable({ + provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const bytes = basePredicate.bytes; + const newPredicate = basePredicate.toNewInstance(); + + expect(newPredicate.bytes).toEqual(bytes); + }); + + it('can transfer funds using duplicated predicate with same data and configurable constants', async () => { + using launched = await launchTestNode(); + + const { + provider, + wallets: [wallet], + } = launched; + + const basePredicate = new PredicateWithConfigurable({ + provider: wallet.provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const predicate = basePredicate.toNewInstance(); + + const amountToTransfer = 200; + + await fundAccount(wallet, predicate, amountToPredicate); + + const destination = WalletUnlocked.generate({ + provider: wallet.provider, + }); + + await assertBalance(destination, 0, provider.getBaseAssetId()); + + const tx = await predicate.transfer( + destination.address, + amountToTransfer, + provider.getBaseAssetId(), + { + gasLimit: 1000, + } + ); + + await tx.waitForResult(); + + await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + }); + + it('can transfer funds using duplicated predicate with different data and same configurable constants', async () => { + using launched = await launchTestNode(); + + const { + provider, + wallets: [wallet], + } = launched; + + const basePredicate = new PredicateWithConfigurable({ + provider: wallet.provider, + data: [13, '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96'], + configurableConstants: defaultValues, + }); + + const predicate = basePredicate.toNewInstance({ + data: [defaultValues.FEE, defaultValues.ADDRESS], + }); + + const amountToTransfer = 200; + + await fundAccount(wallet, predicate, amountToPredicate); + + const destination = WalletUnlocked.generate({ + provider: wallet.provider, + }); + + await assertBalance(destination, 0, provider.getBaseAssetId()); + + const tx = await predicate.transfer( + destination.address, + amountToTransfer, + provider.getBaseAssetId(), + { + gasLimit: 1000, + } + ); + + await tx.waitForResult(); + + await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + }); + + it('can transfer funds using duplicated predicate with same data and different configurable constants', async () => { + using launched = await launchTestNode(); + + const { + provider, + wallets: [wallet], + } = launched; + + const basePredicate = new PredicateWithConfigurable({ + provider: wallet.provider, + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: { + FEE: 13, + ADDRESS: '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96', + }, + }); + + const predicate = basePredicate.toNewInstance({ configurableConstants: defaultValues }); + + const amountToTransfer = 200; + + await fundAccount(wallet, predicate, amountToPredicate); + + const destination = WalletUnlocked.generate({ + provider: wallet.provider, + }); + + await assertBalance(destination, 0, provider.getBaseAssetId()); + + const tx = await predicate.transfer( + destination.address, + amountToTransfer, + provider.getBaseAssetId(), + { + gasLimit: 1000, + } + ); + + await tx.waitForResult(); + + await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + }); + + it('can transfer funds using duplicated predicate with different data and configurable constants', async () => { + using launched = await launchTestNode(); + + const { + provider, + wallets: [wallet], + } = launched; + + const basePredicate = new PredicateWithConfigurable({ + provider: wallet.provider, + data: [13, '0x48966232edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96'], + configurableConstants: { + FEE: 15, + ADDRESS: '0x38966262edb5997574be45f94c665aedb41a1663f5b0528e765f355086eebf96', + }, + }); + + const predicate = basePredicate.toNewInstance({ + data: [defaultValues.FEE, defaultValues.ADDRESS], + configurableConstants: defaultValues, + }); + + const amountToTransfer = 200; + + await fundAccount(wallet, predicate, amountToPredicate); + + const destination = WalletUnlocked.generate({ + provider: wallet.provider, + }); + + await assertBalance(destination, 0, provider.getBaseAssetId()); + + const tx = await predicate.transfer( + destination.address, + amountToTransfer, + provider.getBaseAssetId(), + { + gasLimit: 1000, + } + ); + + await tx.waitForResult(); + + await assertBalance(destination, amountToTransfer, provider.getBaseAssetId()); + }); +}); diff --git a/packages/fuel-gauge/src/predicate/predicate-estimations.test.ts b/packages/fuel-gauge/src/predicate/predicate-estimations.test.ts index f37a0d06943..3919c0c9b9f 100644 --- a/packages/fuel-gauge/src/predicate/predicate-estimations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-estimations.test.ts @@ -22,7 +22,7 @@ import { } from '../../test/typegen'; import type { Validation } from '../types/predicate'; -import { fundPredicate } from './utils/predicate'; +import { fundAccount } from './utils/predicate'; /** * @group node @@ -48,7 +48,7 @@ describe('Predicate', () => { provider, }); - await fundPredicate(wallet, predicateStruct, fundingAmount); + await fundAccount(wallet, predicateStruct, fundingAmount); const tx = new ScriptTransactionRequest(); @@ -138,7 +138,7 @@ describe('Predicate', () => { const predicateTrue = new PredicateTrue({ provider }); - await fundPredicate(wallet, predicateTrue, fundingAmount); + await fundAccount(wallet, predicateTrue, fundingAmount); const resources = await predicateTrue.getResourcesToSpend([[1, provider.getBaseAssetId()]]); tx.addResources(resources); @@ -167,8 +167,8 @@ describe('Predicate', () => { provider, }); - await fundPredicate(wallet, predicateTrue, fundingAmount); - await fundPredicate(wallet, predicateStruct, fundingAmount); + await fundAccount(wallet, predicateTrue, fundingAmount); + await fundAccount(wallet, predicateStruct, fundingAmount); const tx = new ScriptTransactionRequest(); const trueResources = await predicateTrue.getResourcesToSpend([ @@ -210,7 +210,7 @@ describe('Predicate', () => { data: [bn(amountToPredicate)], }); - await fundPredicate(wallet, predicateValidateTransfer, amountToPredicate); + await fundAccount(wallet, predicateValidateTransfer, amountToPredicate); const receiverWallet = WalletUnlocked.generate({ provider, @@ -252,7 +252,7 @@ describe('Predicate', () => { provider, }); - await fundPredicate(wallet, predicateStruct, fundingAmount); + await fundAccount(wallet, predicateStruct, fundingAmount); const transactionRequest = new ScriptTransactionRequest(); @@ -286,7 +286,7 @@ describe('Predicate', () => { provider, }); - await fundPredicate(wallet, predicateStruct, fundingAmount); + await fundAccount(wallet, predicateStruct, fundingAmount); const transactionRequest = new ScriptTransactionRequest(); diff --git a/packages/fuel-gauge/src/predicate/predicate-evaluations.test.ts b/packages/fuel-gauge/src/predicate/predicate-evaluations.test.ts index eab569adbc2..14bbbc60997 100644 --- a/packages/fuel-gauge/src/predicate/predicate-evaluations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-evaluations.test.ts @@ -3,7 +3,7 @@ import { launchTestNode } from 'fuels/test-utils'; import { PredicateTrue, PredicateFalse } from '../../test/typegen/predicates'; -import { assertBalances, fundPredicate } from './utils/predicate'; +import { assertBalances, fundAccount } from './utils/predicate'; /** * @group node @@ -24,7 +24,7 @@ describe('Predicate', () => { const predicate = new PredicateTrue({ provider }); - await fundPredicate(wallet, predicate, 200_000); + await fundAccount(wallet, predicate, 200_000); const amountToReceiver = 50; @@ -55,7 +55,7 @@ describe('Predicate', () => { const predicate = new PredicateFalse({ provider }); - await fundPredicate(wallet, predicate, 200_000); + await fundAccount(wallet, predicate, 200_000); await expect( predicate.transfer(receiver.address, 50, provider.getBaseAssetId(), { diff --git a/packages/fuel-gauge/src/predicate/predicate-input-data.test.ts b/packages/fuel-gauge/src/predicate/predicate-input-data.test.ts index 6e80bc22a35..a804b0af70c 100644 --- a/packages/fuel-gauge/src/predicate/predicate-input-data.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-input-data.test.ts @@ -3,7 +3,7 @@ import { launchTestNode } from 'fuels/test-utils'; import { PredicateInputData } from '../../test/typegen'; -import { fundPredicate } from './utils/predicate'; +import { fundAccount } from './utils/predicate'; /** * @group node @@ -24,7 +24,7 @@ describe('Predicate', () => { const predicate = new PredicateInputData({ provider }); - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); const receiver = Wallet.generate({ provider }); diff --git a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts index a1fb59388e0..ca812be9fee 100644 --- a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts @@ -4,7 +4,7 @@ import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils'; import { PredicateMainArgsStruct } from '../../test/typegen'; import type { Validation } from '../types/predicate'; -import { fundPredicate } from './utils/predicate'; +import { fundAccount } from './utils/predicate'; /** * @group node @@ -25,7 +25,7 @@ describe('Predicate', () => { provider, }); - await fundPredicate(wallet, predicate, 1000); + await fundAccount(wallet, predicate, 1000); const receiver = Wallet.generate({ provider }); @@ -59,7 +59,7 @@ describe('Predicate', () => { provider, }); - await fundPredicate(wallet, predicate, 1000); + await fundAccount(wallet, predicate, 1000); const receiver = Wallet.generate({ provider }); diff --git a/packages/fuel-gauge/src/predicate/predicate-populate-witness.test.ts b/packages/fuel-gauge/src/predicate/predicate-populate-witness.test.ts index 827ab20aa8d..162d5c4f67d 100644 --- a/packages/fuel-gauge/src/predicate/predicate-populate-witness.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-populate-witness.test.ts @@ -4,7 +4,7 @@ import { launchTestNode } from 'fuels/test-utils'; import { PredicateAssertNumber, PredicateAssertValue } from '../../test/typegen'; -import { fundPredicate } from './utils/predicate'; +import { fundAccount } from './utils/predicate'; /** * @group node @@ -46,7 +46,7 @@ describe('Predicate', () => { data: [11], }); - await fundPredicate(wallet, predicateAssertNumber, 500_000); + await fundAccount(wallet, predicateAssertNumber, 500_000); let transactionRequest = new ScriptTransactionRequest(); const receiver = Wallet.generate({ provider }); @@ -101,7 +101,7 @@ describe('Predicate', () => { data: [11], }); - await fundPredicate(fundingWallet, predicateAssertNumber, 500_000); + await fundAccount(fundingWallet, predicateAssertNumber, 500_000); const resources1 = await wallet1.getResourcesToSpend(quantity); const predicateAssertNumberWrongResources = await provider.getResourcesToSpend( @@ -156,7 +156,7 @@ describe('Predicate', () => { data: [11], }); - await fundPredicate(fundingWallet, predicateAssertNumber, 500_000, UTXOS_AMOUNT); + await fundAccount(fundingWallet, predicateAssertNumber, 500_000, UTXOS_AMOUNT); const receiver = Wallet.generate({ provider }); @@ -234,7 +234,7 @@ describe('Predicate', () => { data: [11], }); - await fundPredicate(fundingWallet, predicateAssertNumber, 500_000, UTXOS_AMOUNT); + await fundAccount(fundingWallet, predicateAssertNumber, 500_000, UTXOS_AMOUNT); const predicateAssertValue = new Predicate<[boolean]>({ abi: PredicateAssertValue.abi, @@ -243,7 +243,7 @@ describe('Predicate', () => { data: [true], }); - await fundPredicate(fundingWallet, predicateAssertValue, 500_000, UTXOS_AMOUNT); + await fundAccount(fundingWallet, predicateAssertValue, 500_000, UTXOS_AMOUNT); // predicate resources fetched as non predicate resources const predicateAssertNumberWrongResources = await provider.getResourcesToSpend( @@ -325,7 +325,7 @@ describe('Predicate', () => { data: [11], }); - await fundPredicate(fundingWallet, predicateAssertNumber, 500_000, UTXOS_AMOUNT); + await fundAccount(fundingWallet, predicateAssertNumber, 500_000, UTXOS_AMOUNT); const predicateAssertValue = new Predicate<[boolean]>({ abi: PredicateAssertValue.abi, @@ -334,7 +334,7 @@ describe('Predicate', () => { data: [true], }); - await fundPredicate(fundingWallet, predicateAssertValue, 500_000, UTXOS_AMOUNT); + await fundAccount(fundingWallet, predicateAssertValue, 500_000, UTXOS_AMOUNT); const resources1 = await wallet1.getResourcesToSpend(quantity); const resources2 = await wallet2.getResourcesToSpend(quantity); @@ -411,7 +411,7 @@ describe('Predicate', () => { data: [11], }); - await fundPredicate(fundingWallet, predicateAssertNumber, 500_000, UTXOS_AMOUNT); + await fundAccount(fundingWallet, predicateAssertNumber, 500_000, UTXOS_AMOUNT); const predicateAssertNumberWrongResources = await provider.getResourcesToSpend( predicateAssertNumber.address, @@ -429,7 +429,7 @@ describe('Predicate', () => { data: [true], }); - await fundPredicate(fundingWallet, predicateAssertValue, 500_000, UTXOS_AMOUNT); + await fundAccount(fundingWallet, predicateAssertValue, 500_000, UTXOS_AMOUNT); const predicateAssertValueWrongResources = await provider.getResourcesToSpend( predicateAssertValue.address, diff --git a/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts b/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts index 89cc08ed1d9..ff9976d3477 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts @@ -4,7 +4,7 @@ import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils'; import { CallTestContractFactory, TokenContractFactory } from '../../test/typegen/contracts'; import { PredicateMainArgsStruct, PredicateTrue } from '../../test/typegen/predicates'; -import { fundPredicate } from './utils/predicate'; +import { fundAccount } from './utils/predicate'; /** * @group node @@ -28,7 +28,7 @@ describe('Predicate', () => { // Create a instance of the contract with the predicate as the caller Account const contractPredicate = new Contract(contract.id, contract.interface, predicate); - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); const { waitForResult } = await contractPredicate.functions .return_context_amount() @@ -81,7 +81,7 @@ describe('Predicate', () => { ], }); - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); // executing predicate to transfer resources to receiver const tx = await predicate.transfer( diff --git a/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts b/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts index 10b9e5d72a1..cd002879999 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts @@ -5,7 +5,7 @@ import { expectToThrowFuelError, launchTestNode } from 'fuels/test-utils'; import { PredicateMainArgsStruct, ScriptMainArgs } from '../../test/typegen'; import type { Validation } from '../types/predicate'; -import { fundPredicate } from './utils/predicate'; +import { fundAccount } from './utils/predicate'; /** * @group node @@ -56,7 +56,7 @@ describe('Predicate', () => { ], }); - await fundPredicate(wallet, predicate, amountToPredicate); + await fundAccount(wallet, predicate, amountToPredicate); // executing predicate to transfer resources to receiver const tx = await predicate.transfer( diff --git a/packages/fuel-gauge/src/predicate/utils/predicate/fundAccount.ts b/packages/fuel-gauge/src/predicate/utils/predicate/fundAccount.ts new file mode 100644 index 00000000000..26587ab0de7 --- /dev/null +++ b/packages/fuel-gauge/src/predicate/utils/predicate/fundAccount.ts @@ -0,0 +1,26 @@ +import type { BigNumberish, Account } from 'fuels'; +import { ScriptTransactionRequest, BN } from 'fuels'; + +export const fundAccount = async ( + fundedAccount: Account, + accountToBeFunded: Account, + amount: BigNumberish, + utxosAmount: number = 1 +): Promise => { + const baseAssetId = fundedAccount.provider.getBaseAssetId(); + const request = new ScriptTransactionRequest(); + + for (let i = 0; i < utxosAmount; i++) { + request.addCoinOutput(accountToBeFunded.address, new BN(amount).div(utxosAmount), baseAssetId); + } + + const txCost = await fundedAccount.getTransactionCost(request); + request.gasLimit = txCost.gasUsed; + request.maxFee = txCost.maxFee; + await fundedAccount.fund(request, txCost); + + const submit = await fundedAccount.sendTransaction(request); + await submit.waitForResult(); + + return accountToBeFunded.getBalance(); +}; diff --git a/packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts b/packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts deleted file mode 100644 index 8d092e444a0..00000000000 --- a/packages/fuel-gauge/src/predicate/utils/predicate/fundPredicate.ts +++ /dev/null @@ -1,30 +0,0 @@ -import type { InputValue, BigNumberish, WalletUnlocked, Predicate } from 'fuels'; -import { ScriptTransactionRequest, BN } from 'fuels'; - -export const fundPredicate = async ( - wallet: WalletUnlocked, - predicate: Predicate, - amountToPredicate: BigNumberish, - utxosAmount: number = 1 -): Promise => { - const baseAssetId = wallet.provider.getBaseAssetId(); - const request = new ScriptTransactionRequest(); - - for (let i = 0; i < utxosAmount; i++) { - request.addCoinOutput( - predicate.address, - new BN(amountToPredicate).div(utxosAmount), - baseAssetId - ); - } - - const txCost = await wallet.getTransactionCost(request); - request.gasLimit = txCost.gasUsed; - request.maxFee = txCost.maxFee; - await wallet.fund(request, txCost); - - const submit = await wallet.sendTransaction(request); - await submit.waitForResult(); - - return predicate.getBalance(); -}; diff --git a/packages/fuel-gauge/src/predicate/utils/predicate/index.ts b/packages/fuel-gauge/src/predicate/utils/predicate/index.ts index c538f8abb17..0c6b6db67e3 100644 --- a/packages/fuel-gauge/src/predicate/utils/predicate/index.ts +++ b/packages/fuel-gauge/src/predicate/utils/predicate/index.ts @@ -1,3 +1,3 @@ export * from './assertBalance'; export * from './assertBalances'; -export * from './fundPredicate'; +export * from './fundAccount'; diff --git a/templates/nextjs/src/components/Predicate.tsx b/templates/nextjs/src/components/Predicate.tsx index bbc5ca23435..4fa1223b7cd 100644 --- a/templates/nextjs/src/components/Predicate.tsx +++ b/templates/nextjs/src/components/Predicate.tsx @@ -16,7 +16,7 @@ export default function Predicate() { successNotification, } = useNotification(); useNotification(); - const [predicate, setPredicate] = useState>(); + const [predicate, setPredicate] = useState(); const [predicatePin, setPredicatePin] = useState(); const [isLoading, setIsLoading] = useState(false); diff --git a/templates/vite/src/components/Predicate.tsx b/templates/vite/src/components/Predicate.tsx index 0bc92492dad..a4f74f770e2 100644 --- a/templates/vite/src/components/Predicate.tsx +++ b/templates/vite/src/components/Predicate.tsx @@ -15,7 +15,7 @@ export default function Predicate() { transactionSuccessNotification, successNotification, } = useNotification(); - const [predicate, setPredicate] = useState>(); + const [predicate, setPredicate] = useState(); const [predicatePin, setPredicatePin] = useState(); const [isLoading, setIsLoading] = useState(false); From e8a8c7168a459f7572a9c70ed0e50086a6e4ca28 Mon Sep 17 00:00:00 2001 From: dhai Date: Thu, 2 Jan 2025 19:03:49 +0530 Subject: [PATCH 4/4] feat: auto-detect package manager in `create fuels` (#3503) * feat: auto-detect package manager in `create fuels` * fix tests and docs * add changeset * fix tests * disable pr release --- .changeset/lazy-ears-tap.md | 5 ++ .../src/guide/creating-a-fuel-dapp/index.md | 6 +-- .../src/guide/creating-a-fuel-dapp/options.md | 18 ++----- packages/create-fuels/src/cli.ts | 2 +- .../src/lib/getPackageManager.test.ts | 49 +++++++++---------- .../create-fuels/src/lib/getPackageManager.ts | 46 ++++++++++------- .../create-fuels/src/lib/setupProgram.test.ts | 14 +----- packages/create-fuels/src/lib/setupProgram.ts | 6 --- packages/create-fuels/test/cli.test.ts | 5 +- .../create-fuels/test/utils/generateArgs.ts | 1 - 10 files changed, 70 insertions(+), 82 deletions(-) create mode 100644 .changeset/lazy-ears-tap.md diff --git a/.changeset/lazy-ears-tap.md b/.changeset/lazy-ears-tap.md new file mode 100644 index 00000000000..a25355967f5 --- /dev/null +++ b/.changeset/lazy-ears-tap.md @@ -0,0 +1,5 @@ +--- +"create-fuels": patch +--- + +feat: auto-detect package manager in `create fuels` diff --git a/apps/docs/src/guide/creating-a-fuel-dapp/index.md b/apps/docs/src/guide/creating-a-fuel-dapp/index.md index ac9b3eb234f..1f5e6954ee6 100644 --- a/apps/docs/src/guide/creating-a-fuel-dapp/index.md +++ b/apps/docs/src/guide/creating-a-fuel-dapp/index.md @@ -20,15 +20,15 @@ The first step is to run the command: ::: code-group ```sh-vue [npm] -npm create fuels@{{fuels}} -- --npm +npm create fuels@{{fuels}} ``` ```sh-vue [pnpm] -pnpm create fuels@{{fuels}} --pnpm +pnpm create fuels@{{fuels}} ``` ```sh-vue [bun] -bunx --bun create-fuels@{{fuels}} --bun +bun create fuels@{{fuels}} ``` ::: diff --git a/apps/docs/src/guide/creating-a-fuel-dapp/options.md b/apps/docs/src/guide/creating-a-fuel-dapp/options.md index 8719900be02..0e016e8b6ac 100644 --- a/apps/docs/src/guide/creating-a-fuel-dapp/options.md +++ b/apps/docs/src/guide/creating-a-fuel-dapp/options.md @@ -10,15 +10,15 @@ The `npm create fuels` command has several command-line options that you can use ::: code-group ```sh-vue [pnpm] -pnpm create fuels@{{fuels}} --pnpm [project-name] [options] +pnpm create fuels@{{fuels}} [project-name] [options] ``` ```sh-vue [npm] -npm create fuels@{{fuels}} -- --npm [project-name] [options] +npm create fuels@{{fuels}} -- [project-name] [options] ``` ```sh-vue [bun] -bunx --bun create-fuels@{{fuels}} --bun [project-name] [options] +bun create fuels@{{fuels}} [project-name] [options] ``` ::: @@ -27,18 +27,6 @@ bunx --bun create-fuels@{{fuels}} --bun [project-name] [options] Specifies the template to use for your project. The available templates are: `vite` and `nextjs`. The default template is `vite`. -## `--pnpm` - -Notifies the tool to use pnpm as the package manager to install the necessary dependencies. - -## `--npm` - -Notifies the tool to use npm as the package manager to install the necessary dependencies. - -## `--bun` - -Notifies the tool to use bun as the package manager to install the necessary dependencies. - ## `--verbose` Enables verbose logging. Useful when debugging issues with the tool. diff --git a/packages/create-fuels/src/cli.ts b/packages/create-fuels/src/cli.ts index 6b33723e20a..2b9078f83c6 100644 --- a/packages/create-fuels/src/cli.ts +++ b/packages/create-fuels/src/cli.ts @@ -63,7 +63,7 @@ export const runScaffoldCli = async ({ let projectPath = program.args[0] ?? (await promptForProjectPath()); const verboseEnabled = opts.verbose ?? false; - const packageManager = getPackageManager(opts); + const packageManager = getPackageManager(); if (!process.env.VITEST) { await tryInstallFuelUp(verboseEnabled); diff --git a/packages/create-fuels/src/lib/getPackageManager.test.ts b/packages/create-fuels/src/lib/getPackageManager.test.ts index 9fb4b0fb780..5eab1e42f71 100644 --- a/packages/create-fuels/src/lib/getPackageManager.test.ts +++ b/packages/create-fuels/src/lib/getPackageManager.test.ts @@ -3,14 +3,6 @@ import { mockLogger } from '../../test/utils/mockLogger'; import type { PackageManager } from './getPackageManager'; import { availablePackageManagers, getPackageManager, packageMangers } from './getPackageManager'; -const mockAllDeps = () => { - const { warn } = mockLogger(); - - return { - warn, - }; -}; - const installScenarios: [PackageManager, string][] = [ ['pnpm', 'pnpm install'], ['npm', 'npm install'], @@ -24,17 +16,30 @@ const runScenarios: [PackageManager, string][] = [ ['bun', 'bun run fuels:dev'], ]; +const mockAllDeps = () => { + const { warn } = mockLogger(); + + return { + warn, + }; +}; + /** * @group node */ describe('getPackageManager', () => { + beforeEach(() => { + delete process.env.npm_config_user_agent; + }); + it.each(availablePackageManagers)( `should get the correct package manager for %s`, (packageManager: PackageManager) => { const expectedPackageManager = packageMangers[packageManager]; - const opts = { [packageManager]: true }; - const result = getPackageManager(opts); + process.env.npm_config_user_agent = packageManager; + + const result = getPackageManager(); expect(result).toEqual(expectedPackageManager); } @@ -43,7 +48,9 @@ describe('getPackageManager', () => { it.each(installScenarios)( 'should have the correct install commands', (packageManager, expectedInstallCommand) => { - const command = getPackageManager({ [packageManager]: true }); + process.env.npm_config_user_agent = packageManager; + + const command = getPackageManager(); const install = command.install; @@ -54,7 +61,9 @@ describe('getPackageManager', () => { it.each(runScenarios)( 'should have the correct run commands', (packageManager, expectedRunCommand) => { - const command = getPackageManager({ [packageManager]: true }); + process.env.npm_config_user_agent = packageManager; + + const command = getPackageManager(); const run = command.run(runCommand); @@ -62,24 +71,14 @@ describe('getPackageManager', () => { } ); - it('should warn the user if more than one package manager selected', () => { - const { warn } = mockAllDeps(); - const opts = { pnpm: true, npm: true }; - - getPackageManager(opts); - - expect(warn).toBeCalledWith('More than one package manager was selected.'); - }); - - it('should default to npm if no package manager is selected', () => { + it('should default to npm', () => { const packageManager = 'npm'; const expectedPackageManager = packageMangers[packageManager]; const { warn } = mockAllDeps(); - const opts = {}; - const result = getPackageManager(opts); + const result = getPackageManager(); - expect(warn).not.toBeCalled(); expect(result).toEqual(expectedPackageManager); + expect(warn).toHaveBeenCalledWith(`This package manager is not supported. Using npm instead.`); }); }); diff --git a/packages/create-fuels/src/lib/getPackageManager.ts b/packages/create-fuels/src/lib/getPackageManager.ts index f1982f13b84..fcbc60fc84d 100644 --- a/packages/create-fuels/src/lib/getPackageManager.ts +++ b/packages/create-fuels/src/lib/getPackageManager.ts @@ -1,7 +1,5 @@ import { warn } from '../utils/logger'; -import type { ProgramOptions } from './setupProgram'; - export const availablePackageManagers = ['pnpm', 'npm', 'bun'] as const; export type PackageManager = (typeof availablePackageManagers)[number]; @@ -10,39 +8,53 @@ const runnableApplicator = (command: string = '') => `${commandPrefix} ${command}`; -export const packageMangers = { +export const packageMangers: Record< + PackageManager, + { + install: string; + run: (command: string) => string; + name: PackageManager; + } +> = { pnpm: { install: 'pnpm install', run: runnableApplicator('pnpm'), + name: 'pnpm', }, npm: { install: 'npm install', run: runnableApplicator('npm run'), + name: 'npm', }, bun: { install: 'bun install', run: runnableApplicator('bun run'), + name: 'bun', }, } as const; -export const getPackageManager = (opts: ProgramOptions) => { - const packageMangerOpts = { - pnpm: opts.pnpm, - npm: opts.npm, - bun: opts.bun, - }; +export function getUserPkgManager(): PackageManager { + const userAgent = process.env.npm_config_user_agent || ''; - const cliChosenPackageManagerSelected = Object.entries(packageMangerOpts) - .filter(([, v]) => v) - .map(([k]) => k) as PackageManager[]; + if (userAgent.startsWith(packageMangers.pnpm.name)) { + return packageMangers.pnpm.name; + } - let packageManager: PackageManager | undefined = cliChosenPackageManagerSelected[0]; - if (cliChosenPackageManagerSelected.length > 1) { - warn('More than one package manager was selected.'); + if (userAgent.startsWith(packageMangers.bun.name)) { + return packageMangers.bun.name; } - if (!packageManager) { - packageManager = 'npm'; // default to npm if the user has not specified a package manager (eg. --pnpm, --bun) + if (userAgent.startsWith(packageMangers.npm.name)) { + return packageMangers.npm.name; } + + warn(`This package manager is not supported. Using npm instead.`); + + return packageMangers.npm.name; +} + +export const getPackageManager = () => { + const packageManager = getUserPkgManager(); + return packageMangers[packageManager]; }; diff --git a/packages/create-fuels/src/lib/setupProgram.test.ts b/packages/create-fuels/src/lib/setupProgram.test.ts index 642afdce40c..f63913dc072 100644 --- a/packages/create-fuels/src/lib/setupProgram.test.ts +++ b/packages/create-fuels/src/lib/setupProgram.test.ts @@ -6,20 +6,8 @@ import { setupProgram } from './setupProgram'; describe('setupProgram', () => { test('setupProgram takes in args properly', () => { const program = setupProgram(); - program.parse([ - '', - '', - 'test-project-name', - '--template', - 'nextjs', - '--pnpm', - '--npm', - '--bun', - ]); + program.parse(['', '', 'test-project-name', '--template', 'nextjs']); expect(program.args[0]).toBe('test-project-name'); - expect(program.opts().pnpm).toBe(true); - expect(program.opts().npm).toBe(true); - expect(program.opts().bun).toBe(true); expect(program.opts().install).toBe(true); expect(program.opts().template).toBe('nextjs'); }); diff --git a/packages/create-fuels/src/lib/setupProgram.ts b/packages/create-fuels/src/lib/setupProgram.ts index 7576240c803..009ba4ce257 100644 --- a/packages/create-fuels/src/lib/setupProgram.ts +++ b/packages/create-fuels/src/lib/setupProgram.ts @@ -10,9 +10,6 @@ export interface ProgramOptions { contract?: boolean; predicate?: boolean; script?: boolean; - pnpm?: boolean; - npm?: boolean; - bun?: boolean; verbose?: boolean; install?: boolean; template?: Template; @@ -22,9 +19,6 @@ export const setupProgram = () => { const program = new Command(packageJson.name) .version(packageJson.version) .arguments('[projectDirectory]') - .option('--pnpm', 'Use pnpm to install dependencies') - .option('--npm', 'Use npm to install dependencies') - .option('--bun', 'Use bun to install dependencies') .option('--verbose', 'Enable verbose logging') .option('--no-install', 'Do not install dependencies') .option('--template