From 24a2a105873859b2152b7c875f5432bdfb1a651c Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 12:26:48 -0300 Subject: [PATCH 01/79] using fuel core 0.41.0 --- internal/fuel-core/VERSION | 2 +- packages/versions/src/lib/getBuiltinVersions.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/fuel-core/VERSION b/internal/fuel-core/VERSION index 385bb682d05..72a8a6313bb 100644 --- a/internal/fuel-core/VERSION +++ b/internal/fuel-core/VERSION @@ -1 +1 @@ -0.40.2 +0.41.0 diff --git a/packages/versions/src/lib/getBuiltinVersions.ts b/packages/versions/src/lib/getBuiltinVersions.ts index ad9bc0b08f2..57c15794c3b 100644 --- a/packages/versions/src/lib/getBuiltinVersions.ts +++ b/packages/versions/src/lib/getBuiltinVersions.ts @@ -3,7 +3,7 @@ import type { Versions } from './types'; export function getBuiltinVersions(): Versions { return { FORC: '0.66.5', - FUEL_CORE: '0.40.2', + FUEL_CORE: '0.41.0', FUELS: '0.98.0', }; } From a2baaf8789c7d77c227a404e57e21a589e9b8812 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 12:42:09 -0300 Subject: [PATCH 02/79] update fuel-core schema --- .../src/providers/fuel-core-schema.graphql | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/packages/account/src/providers/fuel-core-schema.graphql b/packages/account/src/providers/fuel-core-schema.graphql index 8a4f2db83cd..ba249d7bf47 100644 --- a/packages/account/src/providers/fuel-core-schema.graphql +++ b/packages/account/src/providers/fuel-core-schema.graphql @@ -18,9 +18,16 @@ scalar Address scalar AssetId +type AssetInfoDetails { + contractId: ContractId! + subId: SubId! + totalSupply: U128! +} + type Balance { owner: Address! amount: U64! + amountU128: U128! assetId: AssetId! } @@ -314,6 +321,10 @@ enum ContractParametersVersion { V1 } +type DaCompressedBlock { + bytes: HexString! +} + union DependentCost = LightOperation | HeavyOperation type DryRunFailureStatus { @@ -468,6 +479,7 @@ type GasCosts { wqmm: U64! xor: U64! xori: U64! + ecop: U64 alocDependentCost: DependentCost! bldd: DependentCost bsiz: DependentCost @@ -492,6 +504,7 @@ type GasCosts { smo: DependentCost! srwq: DependentCost! swwq: DependentCost! + epar: DependentCost contractRoot: DependentCost! stateRoot: DependentCost! vmInitialization: DependentCost! @@ -809,8 +822,11 @@ type NodeInfo { utxoValidation: Boolean! vmBacktrace: Boolean! maxTx: U64! + maxGas: U64! + maxSize: U64! maxDepth: U64! nodeVersion: String! + txPoolStats: TxPoolStats! peers: [PeerInfo!]! } @@ -921,6 +937,13 @@ type ProgramState { } type Query { + assetDetails( + """ + ID of the Asset + """ + id: AssetId! + ): AssetInfoDetails! + """ Read register value by index. """ @@ -1039,7 +1062,8 @@ type Query { """ The list of requested assets` coins with asset ids, `target` amount the user wants to reach, and the `max` number of coins in the selection. Several - entries with the same asset id are not allowed. + entries with the same asset id are not allowed. The result can't contain + more coins than `max_inputs`. """ queryPerAsset: [SpendQueryElementInput!]! @@ -1048,6 +1072,12 @@ type Query { """ excludedIds: ExcludeInput ): [[CoinType!]!]! + daCompressedBlock( + """ + Height of the block + """ + height: U32! + ): DaCompressedBlock contract( """ ID of the Contract @@ -1091,7 +1121,7 @@ type Query { nonce: Nonce! commitBlockId: BlockId commitBlockHeight: U32 - ): MessageProof + ): MessageProof! messageStatus(nonce: Nonce!): MessageStatus! relayedTransactionStatus( """ @@ -1232,6 +1262,8 @@ type StateTransitionPurpose { root: Bytes32! } +scalar SubId + type SubmittedStatus { time: Tai64Timestamp! } @@ -1383,6 +1415,25 @@ enum TxParametersVersion { scalar TxPointer +type TxPoolStats { + """ + The number of transactions in the pool + """ + txCount: U64! + + """ + The total size of the transactions in the pool + """ + totalSize: U64! + + """ + The total gas of the transactions in the pool + """ + totalGas: U64! +} + +scalar U128 + scalar U16 scalar U32 From a2c85887d9fed608a012e3956951b7ec65322234 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 12:42:13 -0300 Subject: [PATCH 03/79] add new scalars --- packages/account/codegen.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/account/codegen.json b/packages/account/codegen.json index 03f32961274..85478abf54b 100644 --- a/packages/account/codegen.json +++ b/packages/account/codegen.json @@ -27,7 +27,9 @@ "U16": "string", "U32": "string", "U64": "string", - "UtxoId": "string" + "U128": "string", + "UtxoId": "string", + "SubId": "string" }, "useTypeImports": true, "dedupeOperationSuffix": true, From 1514020ce3c383811bd3acd034247adfb8a7fa2e Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 13:14:15 -0300 Subject: [PATCH 04/79] made getBalances support pagination --- .../account/src/providers/provider.test.ts | 49 ++++++++++++++++++- packages/account/src/providers/provider.ts | 20 +++++--- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 5072e7226c2..2323cded6ca 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -20,13 +20,14 @@ import { MOCK_TX_UNKNOWN_RAW_PAYLOAD, MOCK_TX_SCRIPT_RAW_PAYLOAD, } from '../../test/fixtures/transaction-summary'; -import { setupTestProviderAndWallets, launchNode, TestMessage } from '../test-utils'; +import { setupTestProviderAndWallets, launchNode, TestMessage, TestAssetId } from '../test-utils'; import type { Coin } from './coin'; import { coinQuantityfy } from './coin-quantity'; import type { Message } from './message'; import type { ChainInfo, CursorPaginationArgs, NodeInfo } from './provider'; import Provider, { + BALANCES_PAGE_SIZE_LIMIT, BLOCKS_PAGE_SIZE_LIMIT, DEFAULT_RESOURCE_CACHE_TTL, GAS_USED_MODIFIER, @@ -2131,6 +2132,47 @@ Supported fuel-core version: ${mock.supportedVersion}.` expect(pageInfo.endCursor).toBeDefined(); }); + it('can get balances', async () => { + using launched = await setupTestProviderAndWallets({ + walletsConfig: { + assets: 110, + }, + }); + const { + provider, + wallets: [wallet], + } = launched; + + let { balances, pageInfo } = await provider.getBalances(wallet.address, { first: 10 }); + + expect(balances.length).toBe(10); + expect(pageInfo.hasNextPage).toBeTruthy(); + expect(pageInfo.hasPreviousPage).toBeFalsy(); + expect(pageInfo.startCursor).toBeDefined(); + expect(pageInfo.endCursor).toBeDefined(); + + ({ balances, pageInfo } = await provider.getBalances(wallet.address, { + after: pageInfo.endCursor, + })); + + expect(balances.length).toBe(100); + expect(pageInfo.hasNextPage).toBeFalsy(); + expect(pageInfo.hasPreviousPage).toBeTruthy(); + expect(pageInfo.startCursor).toBeDefined(); + expect(pageInfo.endCursor).toBeDefined(); + + ({ balances, pageInfo } = await provider.getBalances(wallet.address, { + before: pageInfo.startCursor, + last: 10, + })); + + expect(balances.length).toBe(10); + expect(pageInfo.hasNextPage).toBeFalsy(); + expect(pageInfo.hasPreviousPage).toBeTruthy(); + expect(pageInfo.startCursor).toBeDefined(); + expect(pageInfo.endCursor).toBeDefined(); + }); + describe('pagination arguments', async () => { using launched = await setupTestProviderAndWallets({ walletsConfig: { @@ -2160,6 +2202,11 @@ Supported fuel-core version: ${mock.supportedVersion}.` invocation: () => provider.getBlocks(args), limit: BLOCKS_PAGE_SIZE_LIMIT, }, + { + name: 'getBalances', + invocation: () => provider.getBalances(address, args), + limit: BALANCES_PAGE_SIZE_LIMIT, + }, ]; } diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index b894d9b6b89..56ead98e267 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -69,6 +69,7 @@ const MAX_RETRIES = 10; export const RESOURCES_PAGE_SIZE_LIMIT = 512; export const TRANSACTIONS_PAGE_SIZE_LIMIT = 60; +export const BALANCES_PAGE_SIZE_LIMIT = 100; export const BLOCKS_PAGE_SIZE_LIMIT = 5; export const DEFAULT_RESOURCE_CACHE_TTL = 20_000; // 20 seconds export const GAS_USED_MODIFIER = 1.2; @@ -122,6 +123,7 @@ export type GetMessagesResponse = { export type GetBalancesResponse = { balances: CoinQuantity[]; + pageInfo: PageInfo; }; export type GetTransactionsResponse = { @@ -1769,15 +1771,17 @@ Supported fuel-core version: ${supportedVersion}.` * @param paginationArgs - Pagination arguments (optional). * @returns A promise that resolves to the balances. */ - async getBalances(owner: string | Address): Promise { + async getBalances( + owner: string | Address, + paginationArgs?: CursorPaginationArgs + ): Promise { const { - balances: { edges }, + balances: { edges, pageInfo }, } = await this.operations.getBalances({ - /** - * The query parameters for this method were designed to support pagination, - * but the current Fuel-Core implementation does not support pagination yet. - */ - first: 10000, + ...validatePaginationArgs({ + paginationLimit: BALANCES_PAGE_SIZE_LIMIT, + inputArgs: paginationArgs, + }), filter: { owner: Address.fromAddressOrString(owner).toB256() }, }); @@ -1786,7 +1790,7 @@ Supported fuel-core version: ${supportedVersion}.` amount: bn(node.amount), })); - return { balances }; + return { balances, pageInfo }; } /** From c9fe8b4a132577fc48ab940ccd9dde54de8e11e9 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 13:22:19 -0300 Subject: [PATCH 05/79] made balance related queries use amount128 instead of amount --- packages/account/src/providers/operations.graphql | 4 ++-- packages/account/src/providers/provider.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index 8d40845b9bf..25101550d11 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -663,7 +663,7 @@ query getContractBalance($contract: ContractId!, $asset: AssetId!) { query getBalance($owner: Address!, $assetId: AssetId!) { balance(owner: $owner, assetId: $assetId) { - amount + amountU128 } } @@ -699,7 +699,7 @@ query getBalances( edges { node { assetId - amount + amountU128 } } } diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 56ead98e267..65d54616a9c 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -1761,7 +1761,7 @@ Supported fuel-core version: ${supportedVersion}.` owner: Address.fromAddressOrString(owner).toB256(), assetId: hexlify(assetId), }); - return bn(balance.amount, 10); + return bn(balance.amountU128, 10); } /** @@ -1787,7 +1787,7 @@ Supported fuel-core version: ${supportedVersion}.` const balances = edges.map(({ node }) => ({ assetId: node.assetId, - amount: bn(node.amount), + amount: bn(node.amountU128), })); return { balances, pageInfo }; From 3ead231c4c7bf2f94946f3975823a27beb295d5b Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 13:23:21 -0300 Subject: [PATCH 06/79] add todo test --- packages/account/src/providers/provider.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 2323cded6ca..0ce1248dbfd 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -2173,6 +2173,8 @@ Supported fuel-core version: ${mock.supportedVersion}.` expect(pageInfo.endCursor).toBeDefined(); }); + it.todo('can get balances amount greater than u64', () => {}); + describe('pagination arguments', async () => { using launched = await setupTestProviderAndWallets({ walletsConfig: { From 76752787bc61b060f421525c036a4c6fed63c2c8 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 13:26:23 -0300 Subject: [PATCH 07/79] update return type of getMessageProof --- packages/account/src/providers/provider.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 65d54616a9c..2810b38db4d 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -1850,7 +1850,7 @@ Supported fuel-core version: ${supportedVersion}.` nonce: string, commitBlockId?: string, commitBlockHeight?: BN - ): Promise { + ): Promise { let inputObject: { /** The transaction to get message from */ transactionId: string; @@ -1888,10 +1888,6 @@ Supported fuel-core version: ${supportedVersion}.` const result = await this.operations.getMessageProof(inputObject); - if (!result.messageProof) { - return null; - } - const { messageProof, messageBlockHeader, From 0e8a7be57607430ae47e77f14aed96487c18e85e Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 13:36:22 -0300 Subject: [PATCH 08/79] add maxGas and txPoolStats to nodeInfoFragment --- packages/account/src/providers/operations.graphql | 6 ++++++ packages/account/test/fixtures/nodeInfo.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index 25101550d11..1a89f7f6089 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -448,8 +448,14 @@ query getVersion { fragment nodeInfoFragment on NodeInfo { utxoValidation vmBacktrace + maxGas maxTx maxDepth + txPoolStats { + txCount + totalGas + totalSize + } nodeVersion } diff --git a/packages/account/test/fixtures/nodeInfo.ts b/packages/account/test/fixtures/nodeInfo.ts index 4b8b3b5f919..3e4772f3e74 100644 --- a/packages/account/test/fixtures/nodeInfo.ts +++ b/packages/account/test/fixtures/nodeInfo.ts @@ -4,6 +4,12 @@ export const MOCK_NODE_INFO: GqlNodeInfoFragment = { utxoValidation: true, vmBacktrace: true, maxTx: '4064', + maxGas: '1000000000', + txPoolStats: { + totalGas: '100000000000', + totalSize: '10000000000000', + txCount: '100', + }, maxDepth: '10', nodeVersion: '0.22.0', }; From 90a0fdd8de0af1b0b527c432a9eb6b394a16f0a7 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 13:37:31 -0300 Subject: [PATCH 09/79] add TODO --- packages/account/src/providers/provider.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 2810b38db4d..f9a341dc1da 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -755,6 +755,7 @@ Supported fuel-core version: ${supportedVersion}.` nodeVersion: nodeInfo.nodeVersion, utxoValidation: nodeInfo.utxoValidation, vmBacktrace: nodeInfo.vmBacktrace, + // TODO: should we add `maxGas` and `txPoolStats` to the NodeInfo type? }; Provider.nodeInfoCache[this.urlWithoutAuth] = processedNodeInfo; From fcc5b5da03cbe5e75d49198be66d030c5ae61490 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 14:13:15 -0300 Subject: [PATCH 10/79] implement query for getAssetDetails --- packages/account/src/providers/operations.graphql | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index 1a89f7f6089..80d1aa3ae46 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -766,6 +766,14 @@ query getRelayedTransactionStatus( } } +query getAssetDetails($assetId: AssetId!) { + assetDetails(id: $assetId) { + subId + contractId + totalSupply + } +} + mutation dryRun( $encodedTransactions: [HexString!]! $utxoValidation: Boolean From ceb8d25b694fb388b0751231cb8583964791736a Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 14:13:46 -0300 Subject: [PATCH 11/79] implement getAssetDetails method --- packages/account/src/providers/provider.ts | 25 ++++++++++++++ packages/errors/src/error-codes.ts | 3 ++ packages/fuel-gauge/src/contract.test.ts | 39 ++++++++++++++++++++++ 3 files changed, 67 insertions(+) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index f9a341dc1da..3e9caeca60f 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -131,6 +131,12 @@ export type GetTransactionsResponse = { pageInfo: PageInfo; }; +export type GetAssetDetailsResponse = { + subId: string; + contractId: string; + totalSupply: BN; +}; + export type GetBlocksResponse = { blocks: Block[]; pageInfo: PageInfo; @@ -803,6 +809,25 @@ Supported fuel-core version: ${supportedVersion}.` return baseAssetId; } + async getAssetDetails(assetId: string): Promise { + try { + const { assetDetails } = await this.operations.getAssetDetails({ assetId }); + + const { contractId, subId, totalSupply } = assetDetails; + + return { + subId, + contractId, + totalSupply: bn(totalSupply), + }; + } catch (e) { + throw new FuelError( + ErrorCode.ASSET_NOT_FOUND, + `Asset not found for given asset id: ${assetId}` + ); + } + } + /** * @hidden */ diff --git a/packages/errors/src/error-codes.ts b/packages/errors/src/error-codes.ts index fdbec36d7cc..292acdf299b 100644 --- a/packages/errors/src/error-codes.ts +++ b/packages/errors/src/error-codes.ts @@ -103,6 +103,9 @@ export enum ErrorCode { ACCOUNT_REQUIRED = 'account-required', UNLOCKED_WALLET_REQUIRED = 'unlocked-wallet-required', + // asset + ASSET_NOT_FOUND = 'asset-not-found', + // chain ERROR_BUILDING_BLOCK_EXPLORER_URL = 'error-building-block-explorer-url', diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index 1f7d38cc9a0..efd1b04d770 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -35,6 +35,7 @@ import { SmoContractFactory, StorageTestContract, StorageTestContractFactory, + TokenContractFactory, VoidFactory, } from '../test/typegen/contracts'; import { PredicateTrue } from '../test/typegen/predicates/PredicateTrue'; @@ -1271,6 +1272,44 @@ describe('Contract', () => { expect(bn(maxFeePolicy?.data).toNumber()).toBe(maxFee); }); + it('can get asset details just fine', async () => { + using launched = await launchTestNode({ + contractsConfigs: [ + { + factory: TokenContractFactory, + }, + ], + }); + const { + contracts: [tokenContract], + provider, + } = launched; + + const totalSupply = 100_000_000; + const { waitForResult } = await tokenContract.functions.mint_coins(totalSupply).call(); + + const { + transactionResult: { mintedAssets }, + } = await waitForResult(); + + const { subId, contractId } = mintedAssets[0]; + + const assetDetails = await provider.getAssetDetails(mintedAssets[0].assetId); + + expect(assetDetails.contractId).toBe(contractId); + expect(assetDetails.subId).toBe(subId); + expect(assetDetails.totalSupply.toNumber()).toBe(totalSupply); + }); + + it('should throw an error if asset details are not found', async () => { + using launched = await launchTestNode(); + const { provider } = launched; + + await expectToThrowFuelError(() => provider.getAssetDetails(getRandomB256()), { + code: ErrorCode.ASSET_NOT_FOUND, + }); + }); + it('should ensure "maxFee" and "gasLimit" can be set on a multicall', async () => { using contract = await setupTestContract(); From 4563216b09a4a3018bb55f5656610f80a74cd891 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 14:51:55 -0300 Subject: [PATCH 12/79] implement daCompressedBlock method --- packages/account/src/providers/operations.graphql | 6 ++++++ packages/account/src/providers/provider.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index 80d1aa3ae46..21002a6d306 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -774,6 +774,12 @@ query getAssetDetails($assetId: AssetId!) { } } +query daCompressedBlock($height: U32!) { + daCompressedBlock(height: $height) { + bytes + } +} + mutation dryRun( $encodedTransactions: [HexString!]! $utxoValidation: Boolean diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 3e9caeca60f..6d8fbbd67b0 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -1702,6 +1702,18 @@ Supported fuel-core version: ${supportedVersion}.` } } + async daCompressedBlock(height: string) { + const { daCompressedBlock } = await this.operations.daCompressedBlock({ + height, + }); + + if (!daCompressedBlock) { + return null; + } + + return daCompressedBlock; + } + /** * Retrieves transactions based on the provided pagination arguments. * @param paginationArgs - The pagination arguments for retrieving transactions. From cd7daa609bdea0c09ac89c3400f92ffc86bd1618 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 15:23:07 -0300 Subject: [PATCH 13/79] add new expiration policy --- packages/transactions/src/coders/policy.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/transactions/src/coders/policy.ts b/packages/transactions/src/coders/policy.ts index aeb7c03fb8e..5967b122cf7 100644 --- a/packages/transactions/src/coders/policy.ts +++ b/packages/transactions/src/coders/policy.ts @@ -9,9 +9,15 @@ export enum PolicyType { WitnessLimit = 2, Maturity = 4, MaxFee = 8, + Expiration = 16, } -export type Policy = PolicyTip | PolicyWitnessLimit | PolicyMaturity | PolicyMaxFee; +export type Policy = + | PolicyTip + | PolicyWitnessLimit + | PolicyMaturity + | PolicyMaxFee + | PolicyExpiration; export type PolicyTip = { type: PolicyType.Tip; @@ -28,6 +34,11 @@ export type PolicyMaturity = { data: number; }; +export type PolicyExpiration = { + type: PolicyType.Expiration; + data: number; +}; + export type PolicyMaxFee = { type: PolicyType.MaxFee; data: BN; @@ -70,6 +81,7 @@ export class PoliciesCoder extends Coder { break; case PolicyType.Maturity: + case PolicyType.Expiration: parts.push(new NumberCoder('u32', { padToWordSize: true }).encode(data)); break; @@ -113,6 +125,12 @@ export class PoliciesCoder extends Coder { policies.push({ type: PolicyType.MaxFee, data: maxFee }); } + if (policyTypes & PolicyType.Expiration) { + const [maxFee, nextOffset] = new NumberCoder('u32', { padToWordSize: true }).decode(data, o); + o = nextOffset; + policies.push({ type: PolicyType.Expiration, data: maxFee }); + } + return [policies, o]; } } From 4b4c49b654cbb9e47d0cf5fe82bcdce4b4ebe02a Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 15:30:49 -0300 Subject: [PATCH 14/79] fix var name --- packages/transactions/src/coders/policy.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/transactions/src/coders/policy.ts b/packages/transactions/src/coders/policy.ts index 5967b122cf7..1dcac8c7cf8 100644 --- a/packages/transactions/src/coders/policy.ts +++ b/packages/transactions/src/coders/policy.ts @@ -126,9 +126,12 @@ export class PoliciesCoder extends Coder { } if (policyTypes & PolicyType.Expiration) { - const [maxFee, nextOffset] = new NumberCoder('u32', { padToWordSize: true }).decode(data, o); + const [expiration, nextOffset] = new NumberCoder('u32', { padToWordSize: true }).decode( + data, + o + ); o = nextOffset; - policies.push({ type: PolicyType.Expiration, data: maxFee }); + policies.push({ type: PolicyType.Expiration, data: expiration }); } return [policies, o]; From 85ffa1acca810c61f59167dcfb58e890bfb1d709 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 15:37:59 -0300 Subject: [PATCH 15/79] fix test description --- packages/transactions/src/coders/policy.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/transactions/src/coders/policy.test.ts b/packages/transactions/src/coders/policy.test.ts index 3eda915b208..0f18e3c5668 100644 --- a/packages/transactions/src/coders/policy.test.ts +++ b/packages/transactions/src/coders/policy.test.ts @@ -200,7 +200,7 @@ describe('PoliciesCoder', () => { }); }); - it('should decode garPrice and witnessLimit', () => { + it('should decode tip and witnessLimit', () => { const tipByteArr = [0, 0, 0, 0, 0, 0, 0, 100]; const witLimitByteArr = [0, 0, 0, 0, 0, 0, 11, 184]; From f2f3ca9a13248b6b77da0671a3f48e3986cec801 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 15:39:13 -0300 Subject: [PATCH 16/79] add tests for new expiration policy --- .../transactions/src/coders/policy.test.ts | 99 ++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/packages/transactions/src/coders/policy.test.ts b/packages/transactions/src/coders/policy.test.ts index 0f18e3c5668..3af84ed6a6d 100644 --- a/packages/transactions/src/coders/policy.test.ts +++ b/packages/transactions/src/coders/policy.test.ts @@ -39,6 +39,13 @@ describe('PoliciesCoder', () => { expect(encoded).toStrictEqual(Uint8Array.from([0, 0, 0, 0, 0, 0, 0, 76])); }); + it('should encode policy correctly (Expiration)', () => { + const policies: Policy[] = [{ type: PolicyType.Expiration, data: 12000 }]; + const encoded = new PoliciesCoder().encode(policies); + + expect(encoded).toStrictEqual(Uint8Array.from([0, 0, 0, 0, 0, 0, 46, 224])); + }); + it('should encode policy correctly (Tip + MaxFee)', () => { const policies: Policy[] = [ { type: PolicyType.Tip, data: bn(19) }, @@ -63,6 +70,18 @@ describe('PoliciesCoder', () => { ); }); + it('should encode policy correctly (WitnessLimit + Expiration)', () => { + const policies: Policy[] = [ + { type: PolicyType.WitnessLimit, data: bn(87) }, + { type: PolicyType.Expiration, data: 3000000 }, + ]; + const encoded = new PoliciesCoder().encode(policies); + + expect(encoded).toStrictEqual( + Uint8Array.from([0, 0, 0, 0, 0, 0, 0, 87, 0, 0, 0, 0, 0, 45, 198, 192]) + ); + }); + it('should encode policy correctly (WitnessLimit + Maturity + MaxFee)', () => { const policies: Policy[] = [ { type: PolicyType.WitnessLimit, data: bn(87) }, @@ -95,6 +114,24 @@ describe('PoliciesCoder', () => { ); }); + it('should encode policy correctly (Tip + WitnessLimit + Maturity + MaxFee + Expiration)', () => { + const policies: Policy[] = [ + { type: PolicyType.Tip, data: bn(28) }, + { type: PolicyType.WitnessLimit, data: bn(87) }, + { type: PolicyType.Maturity, data: 26 }, + { type: PolicyType.MaxFee, data: bn(199) }, + { type: PolicyType.Expiration, data: 2000000 }, + ]; + const encoded = new PoliciesCoder().encode(policies); + + expect(encoded).toStrictEqual( + Uint8Array.from([ + 0, 0, 0, 0, 0, 0, 0, 28, 0, 0, 0, 0, 0, 0, 0, 87, 0, 0, 0, 0, 0, 0, 0, 26, 0, 0, 0, 0, 0, + 0, 0, 199, 0, 0, 0, 0, 0, 30, 132, 128, + ]) + ); + }); + it('should ensure unsorted policies array will not reflect in error when encoding', () => { const policies: Policy[] = [ { type: PolicyType.MaxFee, data: bn(199) }, @@ -200,6 +237,23 @@ describe('PoliciesCoder', () => { }); }); + it('should decode expiration', () => { + // maxFee is 3000000 + const byteArr = [0, 0, 0, 0, 0, 45, 198, 192]; + const data = Uint8Array.from(byteArr); + + // bitfield is 8 representing maxFee + const policyTypes = PolicyType.Expiration; + + const [policies] = new PoliciesCoder().decode(data, 0, policyTypes); + + expect(policies).toHaveLength(1); + expect(policies[0]).toStrictEqual({ + type: PolicyType.Expiration, + data: bn(byteArr).toNumber(), + }); + }); + it('should decode tip and witnessLimit', () => { const tipByteArr = [0, 0, 0, 0, 0, 0, 0, 100]; const witLimitByteArr = [0, 0, 0, 0, 0, 0, 11, 184]; @@ -269,27 +323,62 @@ describe('PoliciesCoder', () => { }); }); + it('should decode tip, maxFee, and expiration', () => { + const witLimitByteArr = [0, 0, 0, 0, 0, 0, 11, 184]; + const maxFeeByteArr = [0, 0, 0, 0, 0, 0, 1, 244]; + const expirationByteArr = [0, 0, 0, 0, 0, 0, 90, 244]; + + const data = Uint8Array.from([...witLimitByteArr, ...maxFeeByteArr, ...expirationByteArr]); + + // bitfield is 10 representing witnessLimit + maxFee + const policyTypes = PolicyType.WitnessLimit + PolicyType.MaxFee + PolicyType.Expiration; + expect(policyTypes).toBe(26); + + const [policies] = new PoliciesCoder().decode(data, 0, policyTypes); + + expect(policies).toHaveLength(3); + expect(policies[0]).toStrictEqual({ + type: PolicyType.WitnessLimit, + data: bn(witLimitByteArr), + }); + expect(policies[1]).toStrictEqual({ + type: PolicyType.MaxFee, + data: bn(maxFeeByteArr), + }); + expect(policies[2]).toStrictEqual({ + type: PolicyType.Expiration, + data: bn(expirationByteArr).toNumber(), + }); + }); + it('should decode when all policy types are present', () => { const tipByteArr = [0, 0, 0, 0, 0, 0, 0, 100]; const witLimitByteArr = [0, 0, 0, 0, 0, 0, 11, 184]; const maturityByteArr = [0, 0, 0, 0, 0, 0, 0, 25]; const maxFeeByteArr = [0, 0, 0, 0, 0, 0, 1, 244]; + const expirationByteArr = [0, 0, 0, 0, 0, 0, 100, 244]; const data = Uint8Array.from([ ...tipByteArr, ...witLimitByteArr, ...maturityByteArr, ...maxFeeByteArr, + ...expirationByteArr, ]); // bitfield is 15 representing witnessLimit + maxFee const policyTypes = - PolicyType.Tip + PolicyType.WitnessLimit + PolicyType.Maturity + PolicyType.MaxFee; - expect(policyTypes).toBe(15); + PolicyType.Tip + + PolicyType.WitnessLimit + + PolicyType.Maturity + + PolicyType.MaxFee + + PolicyType.Expiration; + + expect(policyTypes).toBe(31); const [policies] = new PoliciesCoder().decode(data, 0, policyTypes); - expect(policies).toHaveLength(4); + expect(policies).toHaveLength(5); expect(policies).toStrictEqual([ { type: PolicyType.Tip, @@ -307,6 +396,10 @@ describe('PoliciesCoder', () => { type: PolicyType.MaxFee, data: bn(maxFeeByteArr), }, + { + type: PolicyType.Expiration, + data: bn(expirationByteArr).toNumber(), + }, ]); }); }); From 73f4361ef00f0e5ee3a455e38d5be5a2dff666b7 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 15:41:17 -0300 Subject: [PATCH 17/79] add expiration policy to TransactionRequest --- packages/account/src/account.ts | 2 +- .../transaction-request/transaction-request.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 8ab6ecf20e6..ea69b56a9cb 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -51,7 +51,7 @@ import { assembleTransferToContractScript } from './utils/formatTransferToContra export type TxParamsType = Pick< ScriptTransactionRequestLike, - 'gasLimit' | 'tip' | 'maturity' | 'maxFee' | 'witnessLimit' + 'gasLimit' | 'tip' | 'maturity' | 'maxFee' | 'witnessLimit' | 'expiration' >; export type TransferParams = { diff --git a/packages/account/src/providers/transaction-request/transaction-request.ts b/packages/account/src/providers/transaction-request/transaction-request.ts index d38eaed6a94..b942e4b0b0c 100644 --- a/packages/account/src/providers/transaction-request/transaction-request.ts +++ b/packages/account/src/providers/transaction-request/transaction-request.ts @@ -75,6 +75,8 @@ export interface BaseTransactionRequestLike { tip?: BigNumberish; /** Block until which tx cannot be included */ maturity?: number; + /** TODO: describe me please */ + expiration?: number; /** The maximum fee payable by this transaction using BASE_ASSET. */ maxFee?: BigNumberish; /** The maximum amount of witness data allowed for the transaction */ @@ -109,6 +111,8 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi tip?: BN; /** Block until which tx cannot be included */ maturity?: number; + /** TODO: describe me please */ + expiration?: number; /** The maximum fee payable by this transaction using BASE_ASSET. */ maxFee: BN; /** The maximum amount of witness data allowed for the transaction */ @@ -128,6 +132,7 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi constructor({ tip, maturity, + expiration, maxFee, witnessLimit, inputs, @@ -136,6 +141,7 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi }: BaseTransactionRequestLike = {}) { this.tip = tip ? bn(tip) : undefined; this.maturity = maturity && maturity > 0 ? maturity : undefined; + this.expiration = expiration && expiration > 0 ? expiration : undefined; this.witnessLimit = isDefined(witnessLimit) ? bn(witnessLimit) : undefined; this.maxFee = bn(maxFee); this.inputs = inputs ?? []; @@ -147,7 +153,7 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi let policyTypes = 0; const policies: Policy[] = []; - const { tip, witnessLimit, maturity } = req; + const { tip, witnessLimit, maturity, expiration } = req; if (bn(tip).gt(0)) { policyTypes += PolicyType.Tip; @@ -162,6 +168,11 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi policies.push({ data: maturity, type: PolicyType.Maturity }); } + if (expiration && expiration > 0) { + policyTypes += PolicyType.Expiration; + policies.push({ data: expiration, type: PolicyType.Expiration }); + } + policyTypes += PolicyType.MaxFee; policies.push({ data: req.maxFee, type: PolicyType.MaxFee }); From e5374ae46be916d6a416c4719835e5c20d2350ea Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 15:41:36 -0300 Subject: [PATCH 18/79] support expiration policy on BaseInvocationScope --- packages/program/src/functions/base-invocation-scope.ts | 1 + packages/program/src/types.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/program/src/functions/base-invocation-scope.ts b/packages/program/src/functions/base-invocation-scope.ts index 118ad9944b2..63950611222 100644 --- a/packages/program/src/functions/base-invocation-scope.ts +++ b/packages/program/src/functions/base-invocation-scope.ts @@ -283,6 +283,7 @@ export class BaseInvocationScope { request.maxFee = txParams.maxFee ? bn(txParams.maxFee) : request.maxFee; request.witnessLimit = txParams.witnessLimit ? bn(txParams.witnessLimit) : request.witnessLimit; request.maturity = txParams.maturity || request.maturity; + request.expiration = txParams.expiration || request.expiration; request.addVariableOutputs(this.txParameters?.variableOutputs || 0); diff --git a/packages/program/src/types.ts b/packages/program/src/types.ts index fc373f52f30..6d5c19e9d75 100644 --- a/packages/program/src/types.ts +++ b/packages/program/src/types.ts @@ -57,6 +57,7 @@ export type TxParams = Partial<{ tip: BigNumberish; gasLimit: BigNumberish; maturity?: number; + expiration?: number; maxFee?: BigNumberish; witnessLimit?: BigNumberish; variableOutputs: number; From 468f54bb2c956aa5a87e52230047f5017560dbf3 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 16:00:08 -0300 Subject: [PATCH 19/79] adjust policies order --- .../providers/transaction-request/transaction-request.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/account/src/providers/transaction-request/transaction-request.ts b/packages/account/src/providers/transaction-request/transaction-request.ts index b942e4b0b0c..3f2de193a68 100644 --- a/packages/account/src/providers/transaction-request/transaction-request.ts +++ b/packages/account/src/providers/transaction-request/transaction-request.ts @@ -168,14 +168,14 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi policies.push({ data: maturity, type: PolicyType.Maturity }); } + policyTypes += PolicyType.MaxFee; + policies.push({ data: req.maxFee, type: PolicyType.MaxFee }); + if (expiration && expiration > 0) { policyTypes += PolicyType.Expiration; policies.push({ data: expiration, type: PolicyType.Expiration }); } - policyTypes += PolicyType.MaxFee; - policies.push({ data: req.maxFee, type: PolicyType.MaxFee }); - return { policyTypes, policies, From c30108cb25aa22164d13a904695ee738afcc1072 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 15 Jan 2025 16:04:57 -0300 Subject: [PATCH 20/79] add e2e test for new expiration policy --- packages/fuel-gauge/src/policies.test.ts | 45 ++++++++++++++++++++---- 1 file changed, 39 insertions(+), 6 deletions(-) diff --git a/packages/fuel-gauge/src/policies.test.ts b/packages/fuel-gauge/src/policies.test.ts index 3ab86e37480..b5064805cbc 100644 --- a/packages/fuel-gauge/src/policies.test.ts +++ b/packages/fuel-gauge/src/policies.test.ts @@ -23,6 +23,7 @@ describe('Policies', () => { tip?: BigNumberish; maxFee?: BigNumberish; witnessLimit?: BigNumberish; + expiration?: number; }; const randomNumber = (minNumber: number, maxNumber: number) => { @@ -43,6 +44,8 @@ describe('Policies', () => { expect(bn(transaction.policies?.[1].data).eq(bn(params.witnessLimit))).toBeTruthy(); expect(transaction.policies?.[2].type).toBe(PolicyType.MaxFee); expect(bn(transaction.policies?.[2]?.data).lte(bn(params.maxFee))).toBeTruthy(); + expect(transaction.policies?.[3].type).toBe(PolicyType.Expiration); + expect(transaction.policies?.[3]?.data).toBe(params.expiration); }; it('should ensure optional TX policies are not set when not informed', () => { @@ -119,6 +122,7 @@ describe('Policies', () => { const txParams: CustomTxParams = { tip: 10, + expiration: 10000, witnessLimit: randomNumber(800, 900), maxFee: 1000, }; @@ -133,8 +137,8 @@ describe('Policies', () => { const { transaction } = await tx.waitForResult(); - expect(transaction.policyTypes).toBe(11); - expect(transaction.policies?.length).toBe(3); + expect(transaction.policyTypes).toBe(27); + expect(transaction.policies?.length).toBe(4); validatePolicies({ transaction, @@ -152,6 +156,7 @@ describe('Policies', () => { const txParams: CustomTxParams = { tip: 11, witnessLimit: 2000, + expiration: 10000, maxFee: 70_000, }; @@ -194,7 +199,7 @@ describe('Policies', () => { const callScope = contract.functions.payable().txParams({ tip: 5, - + expiration: 10000, witnessLimit: randomNumber(800, 900), maxFee: 70_000, }); @@ -228,7 +233,7 @@ describe('Policies', () => { const callScope = scriptInstance.functions.main(33).txParams({ tip: 2, - + expiration: 10000, witnessLimit: randomNumber(800, 900), maxFee: 70_000, }); @@ -259,7 +264,7 @@ describe('Policies', () => { const txParams: CustomTxParams = { tip: 4, - + expiration: 5000, witnessLimit: randomNumber(800, 900), maxFee: 70_000, }; @@ -296,7 +301,7 @@ describe('Policies', () => { const txParams: CustomTxParams = { tip: 1, - + expiration: 5000, witnessLimit: randomNumber(800, 900), maxFee: 70_000, }; @@ -342,6 +347,34 @@ describe('Policies', () => { }).rejects.toThrow(/TransactionWitnessLimitExceeded/); }); + it('should ensure TX expiration policy limits tx execution as expected', async () => { + using launched = await launchTestNode(); + + const { + provider, + wallets: [wallet], + } = launched; + + const receiver = Wallet.generate({ provider }); + + const txParams: CustomTxParams = { + expiration: 1, + }; + + await expect(async () => { + const tx1 = await wallet.transfer(receiver.address, 500, await provider.getBaseAssetId()); + await tx1.waitForResult(); + + const tx2 = await wallet.transfer( + receiver.address, + 500, + await provider.getBaseAssetId(), + txParams + ); + await tx2.waitForResult(); + }).rejects.toThrow(/TransactionExpiration/); + }); + describe('should ensure TX maxFee policy limits TX execution as expected', () => { it('on account transfer', async () => { using launched = await launchTestNode({ From 99e6a1b02bfa1e7a4ea645d802f8575737831c1c Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 07:57:12 -0300 Subject: [PATCH 21/79] unify 2 errors to conform with fuel core changes --- .../providers/utils/handle-gql-error-message.ts | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/account/src/providers/utils/handle-gql-error-message.ts b/packages/account/src/providers/utils/handle-gql-error-message.ts index 3a2d3d82fb2..d5d5a23f6d3 100644 --- a/packages/account/src/providers/utils/handle-gql-error-message.ts +++ b/packages/account/src/providers/utils/handle-gql-error-message.ts @@ -2,23 +2,15 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors'; import type { GraphQLError } from 'graphql'; export enum GqlErrorMessage { - NOT_ENOUGH_COINS = 'not enough coins to fit the target', - MAX_COINS_REACHED = 'max number of coins is reached while trying to fit the target', + NOT_ENOUGH_COINS_MAX_COINS = 'the target cannot be met due to no coins available or exceeding the 255 coin limit.', } export const handleGqlErrorMessage = (errorMessage: string, rawError: GraphQLError) => { switch (errorMessage) { - case GqlErrorMessage.NOT_ENOUGH_COINS: + case GqlErrorMessage.NOT_ENOUGH_COINS_MAX_COINS: throw new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.`, - {}, - rawError - ); - case GqlErrorMessage.MAX_COINS_REACHED: - throw new FuelError( - ErrorCode.MAX_COINS_REACHED, - 'The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.', + `Insufficient funds or too many small value coins. Consider combining UTXOs.`, {}, rawError ); From bca1a27b1a0da5a953b8534cb9679f853cc39a6d Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 07:59:01 -0300 Subject: [PATCH 22/79] adjust tests --- apps/demo-bun-fuels/src/bun.test.ts | 2 +- apps/demo-fuels/src/index.test.ts | 2 +- apps/demo-typegen/src/demo.test.ts | 2 +- packages/account/src/account.test.ts | 7 +++---- packages/fuel-gauge/src/contract.test.ts | 2 +- packages/fuel-gauge/src/mapped-error-messages.test.ts | 7 +++---- .../src/predicate/predicate-invalidations.test.ts | 2 +- .../src/predicate/predicate-with-contract.test.ts | 2 +- .../fuel-gauge/src/predicate/predicate-with-script.test.ts | 2 +- 9 files changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/demo-bun-fuels/src/bun.test.ts b/apps/demo-bun-fuels/src/bun.test.ts index 15585de28a4..b0be12c33c2 100644 --- a/apps/demo-bun-fuels/src/bun.test.ts +++ b/apps/demo-bun-fuels/src/bun.test.ts @@ -82,7 +82,7 @@ describe('ExampleContract', () => { () => contractInstance.functions.return_input(1337).simulate(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.` + `Insufficient funds or too many low value coins. Consider combining UTXOs.` ) ); }); diff --git a/apps/demo-fuels/src/index.test.ts b/apps/demo-fuels/src/index.test.ts index 49e1e841f2c..6035911a377 100644 --- a/apps/demo-fuels/src/index.test.ts +++ b/apps/demo-fuels/src/index.test.ts @@ -75,7 +75,7 @@ describe('ExampleContract', () => { () => contractInstance.functions.return_input(1337).simulate(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.` + `Insufficient funds or too many low value coins. Consider combining UTXOs.` ) ); }); diff --git a/apps/demo-typegen/src/demo.test.ts b/apps/demo-typegen/src/demo.test.ts index d52c7bf2383..8ed1c9bd0d3 100644 --- a/apps/demo-typegen/src/demo.test.ts +++ b/apps/demo-typegen/src/demo.test.ts @@ -109,7 +109,7 @@ it('should throw when simulating via contract factory with wallet with no resour () => contractInstance.functions.return_input(1337).simulate(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.` + `Insufficient funds or too many low value coins. Consider combining UTXOs.` ) ); }); diff --git a/packages/account/src/account.test.ts b/packages/account/src/account.test.ts index 5a15b43d9b9..7265a8367f1 100644 --- a/packages/account/src/account.test.ts +++ b/packages/account/src/account.test.ts @@ -590,7 +590,7 @@ describe('Account', () => { () => user.getResourcesToSpend([[1, ASSET_A, 500_000]], { utxos: [assetAUTXO.id] }), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.` + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); }); @@ -969,9 +969,8 @@ describe('Account', () => { request.addCoinOutput(wallet.address, 30_000, await provider.getBaseAssetId()); await expectToThrowFuelError(() => request.estimateAndFund(wallet), { - code: ErrorCode.MAX_COINS_REACHED, - message: - 'The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.', + code: ErrorCode.NOT_ENOUGH_FUNDS, + message: 'Insufficient funds or too many small value coins. Consider combining UTXOs.', }); }); diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index efd1b04d770..7a1290efe21 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -1111,7 +1111,7 @@ describe('Contract', () => { .simulate(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.` + `Insufficient funds or too many low value coins. Consider combining UTXOs.` ) ); }); diff --git a/packages/fuel-gauge/src/mapped-error-messages.test.ts b/packages/fuel-gauge/src/mapped-error-messages.test.ts index 10590ccf4a8..b8fee6ce088 100644 --- a/packages/fuel-gauge/src/mapped-error-messages.test.ts +++ b/packages/fuel-gauge/src/mapped-error-messages.test.ts @@ -19,7 +19,7 @@ describe('mapped error messages', () => { await expectToThrowFuelError(() => emptyWalletContract.functions.return_void().call(), { code: ErrorCode.NOT_ENOUGH_FUNDS, - message: `The account(s) sending the transaction don't have enough funds to cover the transaction.`, + message: `Insufficient funds or too many low value coins. Consider combining UTXOs.`, }); }); @@ -42,9 +42,8 @@ describe('mapped error messages', () => { request.maxFee = txCost.maxFee; await expectToThrowFuelError(() => wallet.fund(request, txCost), { - code: ErrorCode.MAX_COINS_REACHED, - message: - 'The account retrieving coins has exceeded the maximum number of coins per asset. Please consider combining your coins into a single UTXO.', + code: ErrorCode.NOT_ENOUGH_FUNDS, + message: 'Insufficient funds or too many low value coins. Consider combining UTXOs.', }); }); }); diff --git a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts index 8987b2c76df..ded8d8a14b5 100644 --- a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts @@ -41,7 +41,7 @@ describe('Predicate', () => { ), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.` + `Insufficient funds or too many low value coins. Consider combining UTXOs.` ) ); }); 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 c43510f4527..3e9f6c5cfa2 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts @@ -64,7 +64,7 @@ describe('Predicate', () => { () => contract.functions.mint_coins(200).call(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.` + `Insufficient funds or too many low value coins. Consider combining UTXOs.` ) ); 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 e66ff21b6d6..124082f2160 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts @@ -37,7 +37,7 @@ describe('Predicate', () => { () => scriptInstance.functions.main(scriptInput).call(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.` + `Insufficient funds or too many low value coins. Consider combining UTXOs.` ) ); From 757a692d85a5fded04a3fc08555e885ae746fc4b Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 08:16:49 -0300 Subject: [PATCH 23/79] fix test --- packages/fuel-gauge/src/doc-examples.test.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/fuel-gauge/src/doc-examples.test.ts b/packages/fuel-gauge/src/doc-examples.test.ts index a8c75fb8a79..510a0801a6c 100644 --- a/packages/fuel-gauge/src/doc-examples.test.ts +++ b/packages/fuel-gauge/src/doc-examples.test.ts @@ -209,14 +209,12 @@ describe('Doc Examples', () => { const { balances: walletCBalances } = await walletC.getBalances(); // validate balances - expect(walletABalances).toEqual([ - { assetId: await provider.getBaseAssetId(), amount: bn(100) }, - ]); - expect(walletBBalances).toEqual([ - { assetId: TestAssetId.A.value, amount: bn(100) }, - { assetId: TestAssetId.B.value, amount: bn(100) }, - { assetId: await provider.getBaseAssetId(), amount: bn(100) }, - ]); + expect(walletABalances).toEqual([{ assetId: baseAssetId, amount: bn(100) }]); + + expect(walletBBalances.find((bal) => bal.assetId === TestAssetId.A.value)).toBeTruthy(); + expect(walletBBalances.find((bal) => bal.assetId === TestAssetId.A.value)).toBeTruthy(); + expect(walletBBalances.find((bal) => bal.assetId === baseAssetId)).toBeTruthy(); + expect(walletCBalances).toEqual([]); }); From 2a6990d5c3da6bb1d8e73d15d6fcc8e7666bdfa3 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 12:13:30 -0300 Subject: [PATCH 24/79] fix error message --- apps/demo-bun-fuels/src/bun.test.ts | 2 +- apps/demo-fuels/src/index.test.ts | 2 +- apps/demo-typegen/src/demo.test.ts | 2 +- .../predicates/snippets/cookbook/failure-not-enough-funds.ts | 2 +- packages/fuel-gauge/src/mapped-error-messages.test.ts | 4 ++-- .../fuel-gauge/src/predicate/predicate-invalidations.test.ts | 2 +- .../fuel-gauge/src/predicate/predicate-with-contract.test.ts | 2 +- .../fuel-gauge/src/predicate/predicate-with-script.test.ts | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/apps/demo-bun-fuels/src/bun.test.ts b/apps/demo-bun-fuels/src/bun.test.ts index b0be12c33c2..a96a375396d 100644 --- a/apps/demo-bun-fuels/src/bun.test.ts +++ b/apps/demo-bun-fuels/src/bun.test.ts @@ -82,7 +82,7 @@ describe('ExampleContract', () => { () => contractInstance.functions.return_input(1337).simulate(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `Insufficient funds or too many low value coins. Consider combining UTXOs.` + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); }); diff --git a/apps/demo-fuels/src/index.test.ts b/apps/demo-fuels/src/index.test.ts index 6035911a377..67ffce86321 100644 --- a/apps/demo-fuels/src/index.test.ts +++ b/apps/demo-fuels/src/index.test.ts @@ -75,7 +75,7 @@ describe('ExampleContract', () => { () => contractInstance.functions.return_input(1337).simulate(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `Insufficient funds or too many low value coins. Consider combining UTXOs.` + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); }); diff --git a/apps/demo-typegen/src/demo.test.ts b/apps/demo-typegen/src/demo.test.ts index 8ed1c9bd0d3..117fc7d03e6 100644 --- a/apps/demo-typegen/src/demo.test.ts +++ b/apps/demo-typegen/src/demo.test.ts @@ -109,7 +109,7 @@ it('should throw when simulating via contract factory with wallet with no resour () => contractInstance.functions.return_input(1337).simulate(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `Insufficient funds or too many low value coins. Consider combining UTXOs.` + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); }); diff --git a/apps/docs/src/guide/predicates/snippets/cookbook/failure-not-enough-funds.ts b/apps/docs/src/guide/predicates/snippets/cookbook/failure-not-enough-funds.ts index 72ad1bb2308..37c79c14f87 100644 --- a/apps/docs/src/guide/predicates/snippets/cookbook/failure-not-enough-funds.ts +++ b/apps/docs/src/guide/predicates/snippets/cookbook/failure-not-enough-funds.ts @@ -25,7 +25,7 @@ const { error } = await safeExec(async () => ); // #region send-and-spend-funds-from-predicates-6 -const errorMessage = `The account(s) sending the transaction don't have enough funds to cover the transaction.`; +const errorMessage = `Insufficient funds or too many small value coins. Consider combining UTXOs.`; // #endregion send-and-spend-funds-from-predicates-6 const actualErrorMessage = (error).message; diff --git a/packages/fuel-gauge/src/mapped-error-messages.test.ts b/packages/fuel-gauge/src/mapped-error-messages.test.ts index b8fee6ce088..67730f92687 100644 --- a/packages/fuel-gauge/src/mapped-error-messages.test.ts +++ b/packages/fuel-gauge/src/mapped-error-messages.test.ts @@ -19,7 +19,7 @@ describe('mapped error messages', () => { await expectToThrowFuelError(() => emptyWalletContract.functions.return_void().call(), { code: ErrorCode.NOT_ENOUGH_FUNDS, - message: `Insufficient funds or too many low value coins. Consider combining UTXOs.`, + message: `Insufficient funds or too many small value coins. Consider combining UTXOs.`, }); }); @@ -43,7 +43,7 @@ describe('mapped error messages', () => { await expectToThrowFuelError(() => wallet.fund(request, txCost), { code: ErrorCode.NOT_ENOUGH_FUNDS, - message: 'Insufficient funds or too many low value coins. Consider combining UTXOs.', + message: 'Insufficient funds or too many small value coins. Consider combining UTXOs.', }); }); }); diff --git a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts index ded8d8a14b5..75c619ba25d 100644 --- a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts @@ -41,7 +41,7 @@ describe('Predicate', () => { ), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `Insufficient funds or too many low value coins. Consider combining UTXOs.` + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); }); 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 3e9f6c5cfa2..6d1f886a33a 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts @@ -64,7 +64,7 @@ describe('Predicate', () => { () => contract.functions.mint_coins(200).call(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `Insufficient funds or too many low value coins. Consider combining UTXOs.` + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); 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 124082f2160..dd8348f83b9 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts @@ -37,7 +37,7 @@ describe('Predicate', () => { () => scriptInstance.functions.main(scriptInput).call(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `Insufficient funds or too many low value coins. Consider combining UTXOs.` + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); From 985bfc3548a673a47118a758cbf63e822dc06612 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 12:13:38 -0300 Subject: [PATCH 25/79] fix test --- packages/fuel-gauge/src/contract.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index 7a1290efe21..b5b6c25ba8b 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -714,7 +714,7 @@ describe('Contract', () => { const initialBalance = new BN( await contract.getBalance(await provider.getBaseAssetId()) ).toNumber(); - const amountToContract = bn(2).pow(62); // Very big number + const amountToContract = bn(2).pow(61); // Very big number const tx = await wallet.transferToContract( contract.id, @@ -1111,7 +1111,7 @@ describe('Contract', () => { .simulate(), new FuelError( ErrorCode.NOT_ENOUGH_FUNDS, - `Insufficient funds or too many low value coins. Consider combining UTXOs.` + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); }); From 5872e8ddd42d7be98b86b7bd2b8f36b79f877b1b Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 12:22:31 -0300 Subject: [PATCH 26/79] adjusting test --- packages/account/src/providers/provider.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 0ce1248dbfd..0660325908d 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -1368,7 +1368,7 @@ Supported fuel-core version: ${mock.supportedVersion}.` const { minFee, maxFee, gasPrice } = await wallet.getTransactionCost(request); - expect(gasPrice.eq(0)).toBeTruthy(); + expect(gasPrice.eq(0)).not.toBeTruthy(); expect(maxFee.eq(0)).not.toBeTruthy(); expect(minFee.eq(0)).not.toBeTruthy(); }); From af5b9a8094c97c71ea95871ad4d77f786a415cdb Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 12:33:51 -0300 Subject: [PATCH 27/79] fix test case --- packages/account/src/providers/provider.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 0660325908d..41b02bc38cc 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -700,6 +700,11 @@ describe('Provider', () => { request.addCoinOutput(receiver.address, transferAmount, baseAssetId); request.addResources(resources); + // Forcing TX submission to fail at submission state + vi.spyOn(wallet.provider, 'sendTransaction').mockImplementationOnce(() => + Promise.reject(new FuelError(ErrorCode.INVALID_REQUEST, 'Tx failed')) + ); + await expectToThrowFuelError( () => wallet.sendTransaction(request, { estimateTxDependencies: false }), { code: ErrorCode.INVALID_REQUEST } @@ -709,6 +714,8 @@ describe('Provider', () => { [...utxos, ...messages].forEach((key) => { expect(provider.cache?.isCached(key)).toBeFalsy(); }); + + vi.restoreAllMocks(); }); it('should unset cached resources when TX execution fails', async () => { From 4158f848e9bd2ca885d22063caf50754bf4ef4e9 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 13:35:21 -0300 Subject: [PATCH 28/79] adjust test --- .../account/src/providers/provider.test.ts | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 41b02bc38cc..3ebd9cff002 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -866,7 +866,7 @@ describe('Provider', () => { }, }, walletsConfig: { - amountPerCoin: 500_000, + coinsPerAsset: 5, }, }); @@ -880,21 +880,12 @@ describe('Provider', () => { maxFee: 1000, }); - const quantities = [ - coinQuantityfy([1000, ASSET_A]), - coinQuantityfy([500, ASSET_B]), - coinQuantityfy([5000, await provider.getBaseAssetId()]), - ]; + const { coins } = await sender.getCoins(await provider.getBaseAssetId(), { + first: 4, + }); - const resources = await sender.getResourcesToSpend(quantities); request.addCoinOutput(receiver.address, 500, await provider.getBaseAssetId()); - request.addResources(resources); - - // We need to add more resources manually here as a single `getResourcesToSpend` call - // will always truncate to `maxInputs`. So we need to add more resources manually - // to test our validation logic. - const moreResources = await sender.getResourcesToSpend(quantities); - request.addResources(moreResources); + request.addResources(coins); await expectToThrowFuelError( () => sender.sendTransaction(request), From d550e44f50f5c98c0b476ea8d573143df2613d28 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 13:35:54 -0300 Subject: [PATCH 29/79] fix test --- packages/fuel-gauge/src/funding-transaction.test.ts | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/packages/fuel-gauge/src/funding-transaction.test.ts b/packages/fuel-gauge/src/funding-transaction.test.ts index fa5b415b31d..eded8025ae8 100644 --- a/packages/fuel-gauge/src/funding-transaction.test.ts +++ b/packages/fuel-gauge/src/funding-transaction.test.ts @@ -265,18 +265,7 @@ describe('Funding Transactions', () => { () => sender.fund(request, txCost), new FuelError( FuelError.CODES.NOT_ENOUGH_FUNDS, - `The account(s) sending the transaction don't have enough funds to cover the transaction.`, - {}, - { - locations: [ - { - column: 3, - line: 2, - }, - ], - message: 'not enough coins to fit the target', - path: ['coinsToSpend'], - } + `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); From 821ebdcf849cd0f5869a1f46b1aba06a683b1711 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 13:56:24 -0300 Subject: [PATCH 30/79] unset cached resources as soon as the TX is processed --- .../src/providers/transaction-response/transaction-response.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/account/src/providers/transaction-response/transaction-response.ts b/packages/account/src/providers/transaction-response/transaction-response.ts index 64c106c672b..bf3ef333b57 100644 --- a/packages/account/src/providers/transaction-response/transaction-response.ts +++ b/packages/account/src/providers/transaction-response/transaction-response.ts @@ -392,7 +392,6 @@ export class TransactionResponse { const status = this.status ?? this.gqlTransaction?.status; if (status?.type === 'FailureStatus') { - this.unsetResourceCache(); const { reason } = status; throw extractTxError({ receipts, @@ -413,6 +412,7 @@ export class TransactionResponse { contractsAbiMap?: AbiMap ): Promise> { await this.waitForStatusChange(); + this.unsetResourceCache(); return this.assembleResult(contractsAbiMap); } From 7701bad57d5095889a154dc48da8c165b20031da Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 16 Jan 2025 17:30:42 -0300 Subject: [PATCH 31/79] document new expiration policy --- .../src/guide/transactions/adding-parameters.md | 12 +++++++++--- .../src/guide/transactions/adding-policies.md | 4 ++++ .../snippets/transaction-parameters.ts | 15 +++++++++------ .../policies-from-response.ts | 1 + .../transaction-policies/setting-policies.ts | 1 + 5 files changed, 24 insertions(+), 9 deletions(-) diff --git a/apps/docs/src/guide/transactions/adding-parameters.md b/apps/docs/src/guide/transactions/adding-parameters.md index a968075ff5c..754e6705171 100644 --- a/apps/docs/src/guide/transactions/adding-parameters.md +++ b/apps/docs/src/guide/transactions/adding-parameters.md @@ -4,7 +4,7 @@ Transaction parameters allow you to configure various aspects of your blockchain All available parameters are shown below: -<<< @./snippets/transaction-parameters.ts#transaction-parameters-6{ts:line-numbers} +<<< @./snippets/transaction-parameters.ts#transaction-parameters-7{ts:line-numbers} ## Gas Limit @@ -38,6 +38,12 @@ The maximum byte length allowed for the transaction witnesses array. For instanc <<< @./snippets/transaction-parameters.ts#transaction-parameters-5{ts:line-numbers} +## Expiration + +The block number after which the transaction can no longer be included in the blockchain. For example, if you set the expiration block for your transaction to 200, and the transaction remains in the queue waiting to be processed when block 200 is created, the transaction will be rejected. + +<<< @./snippets/transaction-parameters.ts#transaction-parameters-6{ts:line-numbers} + ## Variable Outputs The number of variable outputs that should be added to the transaction request. You can read more about it on this [guide](../contracts/variable-outputs.md) @@ -48,11 +54,11 @@ The number of variable outputs that should be added to the transaction request. To set the transaction parameters, you have access to the `txParams` method on a transaction request. -<<< @./snippets/transaction-parameters.ts#transaction-parameters-7{ts:line-numbers} +<<< @./snippets/transaction-parameters.ts#transaction-parameters-8{ts:line-numbers} The same method is also accessible within a function invocation scope, so it can also be used when calling contract functions. -<<< @./snippets/transaction-parameters.ts#transaction-parameters-8{ts:line-numbers} +<<< @./snippets/transaction-parameters.ts#transaction-parameters-9{ts:line-numbers} > **Note:** When performing an action that results in a transaction (e.g. contract deployment, contract call with `.call()`, asset transfer), the SDK will automatically estimate the fee based on the gas limit and the transaction's byte size. This estimation is used when building the transaction. As a side effect, your wallet must own at least one coin of the base asset, regardless of the amount. diff --git a/apps/docs/src/guide/transactions/adding-policies.md b/apps/docs/src/guide/transactions/adding-policies.md index 90ceae3fb2b..0f273bb1e20 100644 --- a/apps/docs/src/guide/transactions/adding-policies.md +++ b/apps/docs/src/guide/transactions/adding-policies.md @@ -18,6 +18,10 @@ The number of blocks that must pass before the transaction can be included in a The maximum amount you're willing to pay for the transaction using the base asset. +### Expiration + +Block number after which the transaction can no longer be included in the blockchain. + ## Setting Transaction Policies The following snippet shows which transaction parameters correspond to which policies: diff --git a/apps/docs/src/guide/transactions/snippets/transaction-parameters.ts b/apps/docs/src/guide/transactions/snippets/transaction-parameters.ts index 49ad4907aff..343b882a12e 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-parameters.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-parameters.ts @@ -13,7 +13,7 @@ const deploy = await CounterFactory.deploy(wallet); const { contract } = await deploy.waitForResult(); -// #region transaction-parameters-6 +// #region transaction-parameters-7 const txParams: TxParams = { // #region transaction-parameters-1 gasLimit: bn(70935), @@ -30,17 +30,20 @@ const txParams: TxParams = { // #region transaction-parameters-5 witnessLimit: bn(5000), // #endregion transaction-parameters-5 + // #region transaction-parameters-6 + expiration: 200, + // #endregion transaction-parameters-6 }; -// #endregion transaction-parameters-6 +// #endregion transaction-parameters-7 -// #region transaction-parameters-7 +// #region transaction-parameters-8 const transactionRequest = new ScriptTransactionRequest({ script: ScriptSum.bytecode, gasLimit: 100, }); -// #endregion transaction-parameters-7 +// #endregion transaction-parameters-8 -// #region transaction-parameters-8 +// #region transaction-parameters-9 const { waitForResult } = await contract.functions .increment_count(15) // .txParams(txParams) @@ -55,5 +58,5 @@ console.log('Transaction request', transactionRequest); console.log('Transaction status', isStatusSuccess); console.log('Transaction value', value); -// #endregion transaction-parameters-8 +// #endregion transaction-parameters-9 // #endregion full diff --git a/apps/docs/src/guide/transactions/snippets/transaction-policies/policies-from-response.ts b/apps/docs/src/guide/transactions/snippets/transaction-policies/policies-from-response.ts index 0862206e0af..edeeec2997a 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-policies/policies-from-response.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-policies/policies-from-response.ts @@ -18,6 +18,7 @@ const transactionRequest = new ScriptTransactionRequest({ tip: bn(10), witnessLimit: 900, maxFee: bn(2000), + expiration: 200, }); // Set the script main function arguments diff --git a/apps/docs/src/guide/transactions/snippets/transaction-policies/setting-policies.ts b/apps/docs/src/guide/transactions/snippets/transaction-policies/setting-policies.ts index 65611d36a66..a4b40507019 100644 --- a/apps/docs/src/guide/transactions/snippets/transaction-policies/setting-policies.ts +++ b/apps/docs/src/guide/transactions/snippets/transaction-policies/setting-policies.ts @@ -6,6 +6,7 @@ const transactionRequest = new ScriptTransactionRequest({ witnessLimit: bn(1), // Sets the witness limit policy maturity: 1, // Sets the maturity policy maxFee: bn(1), // Sets the max fee policy + expiration: 200, // Sets the block after which the transaction cannot be included. }); // #endregion transaction-policies-1 From 85a87bf6f44faabd37edc43896ea91cc7f1d671b Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Fri, 17 Jan 2025 11:14:43 -0300 Subject: [PATCH 32/79] reverting breaking changes --- .../account/src/providers/operations.graphql | 10 +-- .../account/src/providers/provider.test.ts | 90 +++++++++---------- packages/account/src/providers/provider.ts | 23 +++-- packages/account/test/fixtures/nodeInfo.ts | 6 -- 4 files changed, 57 insertions(+), 72 deletions(-) diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index 21002a6d306..f12be04d546 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -448,14 +448,8 @@ query getVersion { fragment nodeInfoFragment on NodeInfo { utxoValidation vmBacktrace - maxGas maxTx maxDepth - txPoolStats { - txCount - totalGas - totalSize - } nodeVersion } @@ -669,7 +663,7 @@ query getContractBalance($contract: ContractId!, $asset: AssetId!) { query getBalance($owner: Address!, $assetId: AssetId!) { balance(owner: $owner, assetId: $assetId) { - amountU128 + amount } } @@ -705,7 +699,7 @@ query getBalances( edges { node { assetId - amountU128 + amount } } } diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 3ebd9cff002..ba2cf1a9405 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -2130,46 +2130,46 @@ Supported fuel-core version: ${mock.supportedVersion}.` expect(pageInfo.endCursor).toBeDefined(); }); - it('can get balances', async () => { - using launched = await setupTestProviderAndWallets({ - walletsConfig: { - assets: 110, - }, - }); - const { - provider, - wallets: [wallet], - } = launched; - - let { balances, pageInfo } = await provider.getBalances(wallet.address, { first: 10 }); - - expect(balances.length).toBe(10); - expect(pageInfo.hasNextPage).toBeTruthy(); - expect(pageInfo.hasPreviousPage).toBeFalsy(); - expect(pageInfo.startCursor).toBeDefined(); - expect(pageInfo.endCursor).toBeDefined(); - - ({ balances, pageInfo } = await provider.getBalances(wallet.address, { - after: pageInfo.endCursor, - })); - - expect(balances.length).toBe(100); - expect(pageInfo.hasNextPage).toBeFalsy(); - expect(pageInfo.hasPreviousPage).toBeTruthy(); - expect(pageInfo.startCursor).toBeDefined(); - expect(pageInfo.endCursor).toBeDefined(); - - ({ balances, pageInfo } = await provider.getBalances(wallet.address, { - before: pageInfo.startCursor, - last: 10, - })); - - expect(balances.length).toBe(10); - expect(pageInfo.hasNextPage).toBeFalsy(); - expect(pageInfo.hasPreviousPage).toBeTruthy(); - expect(pageInfo.startCursor).toBeDefined(); - expect(pageInfo.endCursor).toBeDefined(); - }); + // it('can get balances', async () => { + // using launched = await setupTestProviderAndWallets({ + // walletsConfig: { + // assets: 110, + // }, + // }); + // const { + // provider, + // wallets: [wallet], + // } = launched; + + // let { balances, pageInfo } = await provider.getBalances(wallet.address, { first: 10 }); + + // expect(balances.length).toBe(10); + // expect(pageInfo.hasNextPage).toBeTruthy(); + // expect(pageInfo.hasPreviousPage).toBeFalsy(); + // expect(pageInfo.startCursor).toBeDefined(); + // expect(pageInfo.endCursor).toBeDefined(); + + // ({ balances, pageInfo } = await provider.getBalances(wallet.address, { + // after: pageInfo.endCursor, + // })); + + // expect(balances.length).toBe(100); + // expect(pageInfo.hasNextPage).toBeFalsy(); + // expect(pageInfo.hasPreviousPage).toBeTruthy(); + // expect(pageInfo.startCursor).toBeDefined(); + // expect(pageInfo.endCursor).toBeDefined(); + + // ({ balances, pageInfo } = await provider.getBalances(wallet.address, { + // before: pageInfo.startCursor, + // last: 10, + // })); + + // expect(balances.length).toBe(10); + // expect(pageInfo.hasNextPage).toBeFalsy(); + // expect(pageInfo.hasPreviousPage).toBeTruthy(); + // expect(pageInfo.startCursor).toBeDefined(); + // expect(pageInfo.endCursor).toBeDefined(); + // }); it.todo('can get balances amount greater than u64', () => {}); @@ -2202,11 +2202,11 @@ Supported fuel-core version: ${mock.supportedVersion}.` invocation: () => provider.getBlocks(args), limit: BLOCKS_PAGE_SIZE_LIMIT, }, - { - name: 'getBalances', - invocation: () => provider.getBalances(address, args), - limit: BALANCES_PAGE_SIZE_LIMIT, - }, + // { + // name: 'getBalances', + // invocation: () => provider.getBalances(address, args), + // limit: BALANCES_PAGE_SIZE_LIMIT, + // }, ]; } diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 6d8fbbd67b0..d69f4a459d3 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -123,7 +123,6 @@ export type GetMessagesResponse = { export type GetBalancesResponse = { balances: CoinQuantity[]; - pageInfo: PageInfo; }; export type GetTransactionsResponse = { @@ -1799,7 +1798,7 @@ Supported fuel-core version: ${supportedVersion}.` owner: Address.fromAddressOrString(owner).toB256(), assetId: hexlify(assetId), }); - return bn(balance.amountU128, 10); + return bn(balance.amount, 10); } /** @@ -1809,26 +1808,24 @@ Supported fuel-core version: ${supportedVersion}.` * @param paginationArgs - Pagination arguments (optional). * @returns A promise that resolves to the balances. */ - async getBalances( - owner: string | Address, - paginationArgs?: CursorPaginationArgs - ): Promise { + async getBalances(owner: string | Address): Promise { const { - balances: { edges, pageInfo }, + balances: { edges }, } = await this.operations.getBalances({ - ...validatePaginationArgs({ - paginationLimit: BALANCES_PAGE_SIZE_LIMIT, - inputArgs: paginationArgs, - }), + /** + * The query parameters for this method were designed to support pagination, + * but the current Fuel-Core implementation does not support pagination yet. + */ + first: 10000, filter: { owner: Address.fromAddressOrString(owner).toB256() }, }); const balances = edges.map(({ node }) => ({ assetId: node.assetId, - amount: bn(node.amountU128), + amount: bn(node.amount), })); - return { balances, pageInfo }; + return { balances }; } /** diff --git a/packages/account/test/fixtures/nodeInfo.ts b/packages/account/test/fixtures/nodeInfo.ts index 3e4772f3e74..4b8b3b5f919 100644 --- a/packages/account/test/fixtures/nodeInfo.ts +++ b/packages/account/test/fixtures/nodeInfo.ts @@ -4,12 +4,6 @@ export const MOCK_NODE_INFO: GqlNodeInfoFragment = { utxoValidation: true, vmBacktrace: true, maxTx: '4064', - maxGas: '1000000000', - txPoolStats: { - totalGas: '100000000000', - totalSize: '10000000000000', - txCount: '100', - }, maxDepth: '10', nodeVersion: '0.22.0', }; From 04c02f5bb3ced3aff7c849a4d0c16809d98e8144 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Fri, 17 Jan 2025 11:47:42 -0300 Subject: [PATCH 33/79] remove unused imports --- packages/account/src/providers/provider.test.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index ba2cf1a9405..f80fab8e5b0 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -20,14 +20,12 @@ import { MOCK_TX_UNKNOWN_RAW_PAYLOAD, MOCK_TX_SCRIPT_RAW_PAYLOAD, } from '../../test/fixtures/transaction-summary'; -import { setupTestProviderAndWallets, launchNode, TestMessage, TestAssetId } from '../test-utils'; +import { setupTestProviderAndWallets, launchNode, TestMessage } from '../test-utils'; import type { Coin } from './coin'; -import { coinQuantityfy } from './coin-quantity'; import type { Message } from './message'; import type { ChainInfo, CursorPaginationArgs, NodeInfo } from './provider'; import Provider, { - BALANCES_PAGE_SIZE_LIMIT, BLOCKS_PAGE_SIZE_LIMIT, DEFAULT_RESOURCE_CACHE_TTL, GAS_USED_MODIFIER, From 33902b84320e531298923eebce32b855762e8106 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Fri, 17 Jan 2025 11:50:35 -0300 Subject: [PATCH 34/79] add changeset --- .changeset/real-schools-poke.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .changeset/real-schools-poke.md diff --git a/.changeset/real-schools-poke.md b/.changeset/real-schools-poke.md new file mode 100644 index 00000000000..2ea490426d9 --- /dev/null +++ b/.changeset/real-schools-poke.md @@ -0,0 +1,11 @@ +--- +"@fuel-ts/transactions": patch +"@internal/fuel-core": patch +"@fuel-ts/versions": patch +"@fuel-ts/account": patch +"@fuel-ts/program": patch +"@fuel-ts/recipes": patch +"@fuel-ts/errors": patch +--- + +chore: upgrade `fuel-core` to `0.41.0` From 5590af0fc5662d96a37a65b627d6915492020157 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Fri, 17 Jan 2025 12:44:39 -0300 Subject: [PATCH 35/79] adjusting errors messages from master --- packages/account/src/providers/provider.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 4cb8e79c10a..dc81fd24cd4 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -1164,7 +1164,7 @@ describe('Provider', () => { await expectToThrowFuelError(() => sender.transfer(receiver.address, 1), { code: ErrorCode.NOT_ENOUGH_FUNDS, message: [ - `The account(s) sending the transaction don't have enough funds to cover the transaction.`, + `Insufficient funds or too many small value coins. Consider combining UTXOs.`, ``, `The Fuel Node that you are trying to connect to is using fuel-core version ${current.FUEL_CORE}.`, `The TS SDK currently supports fuel-core version ${supported.FUEL_CORE}.`, @@ -1191,7 +1191,7 @@ describe('Provider', () => { await expectToThrowFuelError(() => sender.transfer(receiver.address, 1), { code: ErrorCode.NOT_ENOUGH_FUNDS, message: [ - `The account(s) sending the transaction don't have enough funds to cover the transaction.`, + `Insufficient funds or too many small value coins. Consider combining UTXOs.`, ``, `The Fuel Node that you are trying to connect to is using fuel-core version ${current.FUEL_CORE}.`, `The TS SDK currently supports fuel-core version ${supported.FUEL_CORE}.`, From a8885bf5470a9ba5ef726249ef8015d928ea7803 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 09:05:47 -0300 Subject: [PATCH 36/79] implement gte helper for semver --- packages/versions/src/lib/semver.test.ts | 11 ++++++++++- packages/versions/src/lib/semver.ts | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/versions/src/lib/semver.test.ts b/packages/versions/src/lib/semver.test.ts index e1ea836b54f..aeff9b1dca5 100644 --- a/packages/versions/src/lib/semver.test.ts +++ b/packages/versions/src/lib/semver.test.ts @@ -1,4 +1,4 @@ -import { eq, gt, majorEq, minorEq, patchEq } from './semver'; +import { eq, gt, gte, majorEq, minorEq, patchEq } from './semver'; /** * @group node @@ -40,4 +40,13 @@ describe('semver', () => { expect(eq('1.2.3', '1.2.2')).toBe(false); expect(eq('1.2.3', '1.2.4')).toBe(false); }); + test('gte', () => { + expect(gte('1.2.3', '1.2.3')).toBe(true); + expect(gte('1.2.3', '0.2.3')).toBe(true); + expect(gte('1.2.3', '2.2.3')).toBe(false); + expect(gte('1.2.3', '1.1.3')).toBe(true); + expect(gte('1.2.3', '1.3.3')).toBe(false); + expect(gte('1.2.3', '1.2.2')).toBe(true); + expect(gte('1.2.3', '1.2.4')).toBe(false); + }); }); diff --git a/packages/versions/src/lib/semver.ts b/packages/versions/src/lib/semver.ts index a479e2670e4..7fb1e0da9e5 100644 --- a/packages/versions/src/lib/semver.ts +++ b/packages/versions/src/lib/semver.ts @@ -30,6 +30,11 @@ export function eq(version1: string, version2: string): boolean { return fullVersionDiff === 0; } +export function gte(version1: string, version2: string): boolean { + const { fullVersionDiff } = versionDiffs(version1, version2); + return fullVersionDiff >= 0; +} + export function majorEq(version1: string, version2: string): boolean { const { major } = versionDiffs(version1, version2); return major === 0; From ee65f508af75583d064bb6435fdcb6153d671510 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 09:07:41 -0300 Subject: [PATCH 37/79] add features property to Provider class --- packages/account/src/providers/provider.ts | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 7a08175e780..4a7c90f5d2c 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -5,7 +5,7 @@ import type { Transaction } from '@fuel-ts/transactions'; import { InputType, InputMessageCoder, TransactionCoder } from '@fuel-ts/transactions'; import type { BytesLike } from '@fuel-ts/utils'; import { arrayify, hexlify, DateTime, isDefined } from '@fuel-ts/utils'; -import { checkFuelCoreVersionCompatibility, versions } from '@fuel-ts/versions'; +import { checkFuelCoreVersionCompatibility, gte, versions } from '@fuel-ts/versions'; import { equalBytes } from '@noble/curves/abstract/utils'; import type { DocumentNode } from 'graphql'; import { GraphQLClient } from 'graphql-request'; @@ -74,6 +74,11 @@ export const BLOCKS_PAGE_SIZE_LIMIT = 5; export const DEFAULT_RESOURCE_CACHE_TTL = 20_000; // 20 seconds export const GAS_USED_MODIFIER = 1.2; +export type Features = { + balancePagination: boolean; + amount128: boolean; +}; + export type DryRunFailureStatusFragment = GqlDryRunFailureStatusFragment; export type DryRunSuccessStatusFragment = GqlDryRunSuccessStatusFragment; @@ -417,6 +422,12 @@ export default class Provider { public url: string; /** @hidden */ private urlWithoutAuth: string; + /** @hidden */ + private features: Features = { + balancePagination: false, + amount128: false, + }; + /** @hidden */ private static chainInfoCache: ChainInfoCache = {}; /** @hidden */ @@ -526,7 +537,8 @@ export default class Provider { * Initialize Provider async stuff */ async init(): Promise { - await this.fetchChainAndNodeInfo(); + const { nodeInfo } = await this.fetchChainAndNodeInfo(); + this.setupFeatures(nodeInfo.nodeVersion); return this; } @@ -720,6 +732,16 @@ export default class Provider { return { ...getOperationsSdk(executeQuery), ...customOperations(executeQuery) }; } + /** + * @hidden + */ + private setupFeatures(nodeVersion: string) { + if (gte(nodeVersion, '0.41.0')) { + this.features.balancePagination = true; + this.features.amount128 = true; + } + } + /** * Returns the version of the connected node. * From 325669019bb04c65b0967e177c6fc650b2b39d48 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 09:08:25 -0300 Subject: [PATCH 38/79] implement query getBalancesV2 --- .../account/src/providers/operations.graphql | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index f12be04d546..c63318ef6a3 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -705,6 +705,32 @@ query getBalances( } } +query getBalancesV2( + $filter: BalanceFilterInput! + $after: String + $before: String + $first: Int + $last: Int +) { + balances( + filter: $filter + after: $after + before: $before + first: $first + last: $last + ) { + pageInfo { + ...pageInfoFragment + } + edges { + node { + assetId + amountU128 + } + } + } +} + query getMessages( $owner: Address! $after: String From 42135f55000de8be38ada319b1401495bde28015 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 09:09:17 -0300 Subject: [PATCH 39/79] add support for balance pagination --- packages/account/src/providers/provider.ts | 45 +++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 4a7c90f5d2c..5944eadee65 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -128,6 +128,7 @@ export type GetMessagesResponse = { export type GetBalancesResponse = { balances: CoinQuantity[]; + pageInfo?: PageInfo; }; export type GetTransactionsResponse = { @@ -1830,7 +1831,24 @@ export default class Provider { * @param paginationArgs - Pagination arguments (optional). * @returns A promise that resolves to the balances. */ - async getBalances(owner: string | Address): Promise { + async getBalances( + owner: string | Address, + paginationArgs?: CursorPaginationArgs + ): Promise { + if (!this.features.balancePagination) { + return this.getBalancesV1(owner, paginationArgs); + } + + return this.getBalancesV2(owner, paginationArgs); + } + + /** + * @hidden + */ + private async getBalancesV1( + owner: string | Address, + _paginationArgs?: CursorPaginationArgs + ): Promise { const { balances: { edges }, } = await this.operations.getBalances({ @@ -1850,6 +1868,31 @@ export default class Provider { return { balances }; } + /** + * @hidden + */ + private async getBalancesV2( + owner: string | Address, + paginationArgs?: CursorPaginationArgs + ): Promise { + const { + balances: { edges, pageInfo }, + } = await this.operations.getBalancesV2({ + ...validatePaginationArgs({ + inputArgs: paginationArgs, + paginationLimit: BALANCES_PAGE_SIZE_LIMIT, + }), + filter: { owner: Address.fromAddressOrString(owner).toB256() }, + }); + + const balances = edges.map(({ node }) => ({ + assetId: node.assetId, + amount: bn(node.amountU128), + })); + + return { balances, pageInfo }; + } + /** * Returns message for the given address. * From e8e0f8e9d52f0e4894917133f4a853511c1721df Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 09:09:34 -0300 Subject: [PATCH 40/79] implement query getBalanceV2 --- packages/account/src/providers/operations.graphql | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/account/src/providers/operations.graphql b/packages/account/src/providers/operations.graphql index c63318ef6a3..a67f4412494 100644 --- a/packages/account/src/providers/operations.graphql +++ b/packages/account/src/providers/operations.graphql @@ -667,6 +667,12 @@ query getBalance($owner: Address!, $assetId: AssetId!) { } } +query getBalanceV2($owner: Address!, $assetId: AssetId!) { + balance(owner: $owner, assetId: $assetId) { + amountU128 + } +} + query getLatestGasPrice { latestGasPrice { gasPrice From 34ae0cb3b91c533bb892923de108b1e1a64ec666 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 09:10:06 -0300 Subject: [PATCH 41/79] made getBalance return amount128 when supported by the node --- packages/account/src/providers/provider.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 5944eadee65..84a4f5c444a 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -1817,11 +1817,22 @@ export default class Provider { /** The asset ID of coins to get */ assetId: BytesLike ): Promise { - const { balance } = await this.operations.getBalance({ - owner: Address.fromAddressOrString(owner).toB256(), - assetId: hexlify(assetId), + const ownerStr = Address.fromAddressOrString(owner).toB256(); + const assetIdStr = hexlify(assetId); + + if (!this.features.amount128) { + const { balance } = await this.operations.getBalance({ + owner: ownerStr, + assetId: assetIdStr, + }); + return bn(balance.amount, 10); + } + + const { balance } = await this.operations.getBalanceV2({ + owner: ownerStr, + assetId: assetIdStr, }); - return bn(balance.amount, 10); + return bn(balance.amountU128, 10); } /** From 64282609604d8ae6d52aa46ee944e991dee84278 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 09:10:44 -0300 Subject: [PATCH 42/79] uncomment tests related to balance pagination --- .../account/src/providers/provider.test.ts | 98 ++++++++++--------- 1 file changed, 51 insertions(+), 47 deletions(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index dc81fd24cd4..ba023f7d69a 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -2187,48 +2187,52 @@ describe('Provider', () => { expect(pageInfo.endCursor).toBeDefined(); }); - // it('can get balances', async () => { - // using launched = await setupTestProviderAndWallets({ - // walletsConfig: { - // assets: 110, - // }, - // }); - // const { - // provider, - // wallets: [wallet], - // } = launched; - - // let { balances, pageInfo } = await provider.getBalances(wallet.address, { first: 10 }); - - // expect(balances.length).toBe(10); - // expect(pageInfo.hasNextPage).toBeTruthy(); - // expect(pageInfo.hasPreviousPage).toBeFalsy(); - // expect(pageInfo.startCursor).toBeDefined(); - // expect(pageInfo.endCursor).toBeDefined(); - - // ({ balances, pageInfo } = await provider.getBalances(wallet.address, { - // after: pageInfo.endCursor, - // })); - - // expect(balances.length).toBe(100); - // expect(pageInfo.hasNextPage).toBeFalsy(); - // expect(pageInfo.hasPreviousPage).toBeTruthy(); - // expect(pageInfo.startCursor).toBeDefined(); - // expect(pageInfo.endCursor).toBeDefined(); - - // ({ balances, pageInfo } = await provider.getBalances(wallet.address, { - // before: pageInfo.startCursor, - // last: 10, - // })); - - // expect(balances.length).toBe(10); - // expect(pageInfo.hasNextPage).toBeFalsy(); - // expect(pageInfo.hasPreviousPage).toBeTruthy(); - // expect(pageInfo.startCursor).toBeDefined(); - // expect(pageInfo.endCursor).toBeDefined(); - // }); - - it.todo('can get balances amount greater than u64', () => {}); + it('can get balances', async () => { + using launched = await setupTestProviderAndWallets({ + walletsConfig: { + assets: 110, + }, + }); + const { + provider, + wallets: [wallet], + } = launched; + + let { balances, pageInfo } = await provider.getBalances(wallet.address, { first: 10 }); + + pageInfo = pageInfo as GqlPageInfo; + + expect(balances.length).toBe(10); + expect(pageInfo.hasNextPage).toBeTruthy(); + expect(pageInfo.hasPreviousPage).toBeFalsy(); + expect(pageInfo.startCursor).toBeDefined(); + expect(pageInfo.endCursor).toBeDefined(); + + ({ balances, pageInfo } = await provider.getBalances(wallet.address, { + after: pageInfo.endCursor, + })); + + pageInfo = pageInfo as GqlPageInfo; + + expect(balances.length).toBe(100); + expect(pageInfo.hasNextPage).toBeFalsy(); + expect(pageInfo.hasPreviousPage).toBeTruthy(); + expect(pageInfo.startCursor).toBeDefined(); + expect(pageInfo.endCursor).toBeDefined(); + + ({ balances, pageInfo } = await provider.getBalances(wallet.address, { + before: pageInfo.startCursor, + last: 10, + })); + + pageInfo = pageInfo as GqlPageInfo; + + expect(balances.length).toBe(10); + expect(pageInfo.hasNextPage).toBeFalsy(); + expect(pageInfo.hasPreviousPage).toBeTruthy(); + expect(pageInfo.startCursor).toBeDefined(); + expect(pageInfo.endCursor).toBeDefined(); + }); describe('pagination arguments', async () => { using launched = await setupTestProviderAndWallets({ @@ -2259,11 +2263,11 @@ describe('Provider', () => { invocation: () => provider.getBlocks(args), limit: BLOCKS_PAGE_SIZE_LIMIT, }, - // { - // name: 'getBalances', - // invocation: () => provider.getBalances(address, args), - // limit: BALANCES_PAGE_SIZE_LIMIT, - // }, + { + name: 'getBalances', + invocation: () => provider.getBalances(address, args), + limit: BALANCES_PAGE_SIZE_LIMIT, + }, ]; } From de1679c965d37869424e037ebb3cc1629c3c2244 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 09:11:01 -0300 Subject: [PATCH 43/79] fix test --- packages/account/src/providers/provider.test.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index ba023f7d69a..8ac220f1b37 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -23,10 +23,12 @@ import { import { mockIncompatibleVersions } from '../../test/utils/mockIncompabileVersions'; import { setupTestProviderAndWallets, launchNode, TestMessage } from '../test-utils'; +import type { GqlPageInfo } from './__generated__/operations'; import type { Coin } from './coin'; import type { Message } from './message'; import type { ChainInfo, CursorPaginationArgs, NodeInfo } from './provider'; import Provider, { + BALANCES_PAGE_SIZE_LIMIT, BLOCKS_PAGE_SIZE_LIMIT, DEFAULT_RESOURCE_CACHE_TTL, GAS_USED_MODIFIER, @@ -495,7 +497,7 @@ describe('Provider', () => { .spyOn(Provider.prototype, 'fetchChainAndNodeInfo') .mockResolvedValue({ chain: {} as ChainInfo, - nodeInfo: {} as NodeInfo, + nodeInfo: { nodeVersion: '0.41.0' } as NodeInfo, }); const provider = new Provider(providerUrl, { From 01344d32106d3a4fab3b74902a67219ed265ed61 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 10:26:25 -0300 Subject: [PATCH 44/79] add more values to Features type --- packages/account/src/providers/provider.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 84a4f5c444a..05b9ae7ccec 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -77,6 +77,8 @@ export const GAS_USED_MODIFIER = 1.2; export type Features = { balancePagination: boolean; amount128: boolean; + daCompressedBlock: boolean; + getAssetDetails: boolean; }; export type DryRunFailureStatusFragment = GqlDryRunFailureStatusFragment; @@ -427,6 +429,8 @@ export default class Provider { private features: Features = { balancePagination: false, amount128: false, + daCompressedBlock: false, + getAssetDetails: false, }; /** @hidden */ @@ -740,6 +744,8 @@ export default class Provider { if (gte(nodeVersion, '0.41.0')) { this.features.balancePagination = true; this.features.amount128 = true; + this.features.daCompressedBlock = true; + this.features.getAssetDetails = true; } } From 23d82c49577ab8d6f651eb512160d98f962e5256 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 10:26:52 -0300 Subject: [PATCH 45/79] ensure node supports getAssetDetails query --- packages/account/src/providers/provider.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 05b9ae7ccec..0436e951b66 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -838,6 +838,14 @@ export default class Provider { } async getAssetDetails(assetId: string): Promise { + if (!this.features.getAssetDetails) { + const { nodeVersion } = await this.getNode(); + throw new FuelError( + ErrorCode.NOT_SUPPORTED, + `The query "getAssetDetails" is not supported by node version: ${nodeVersion}` + ); + } + try { const { assetDetails } = await this.operations.getAssetDetails({ assetId }); From f0649fd44a5ead81fa39e160972319d2d6a50729 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 10:27:08 -0300 Subject: [PATCH 46/79] ensure node supports daCompressedBlock query --- packages/account/src/providers/provider.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 0436e951b66..c8d42d8660f 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -1739,6 +1739,14 @@ export default class Provider { } async daCompressedBlock(height: string) { + if (!this.features.daCompressedBlock) { + const { nodeVersion } = await this.getNode(); + throw new FuelError( + ErrorCode.NOT_SUPPORTED, + `The query "daCompressedBlock" is not supported by node version: ${nodeVersion}` + ); + } + const { daCompressedBlock } = await this.operations.daCompressedBlock({ height, }); From 890a2477eb061e55a3d780e063a6b2f9fdba15a9 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 10:27:17 -0300 Subject: [PATCH 47/79] add more tests --- .../account/src/providers/provider.test.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 8ac220f1b37..45b202e35c3 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -1986,6 +1986,58 @@ describe('Provider', () => { expect(block?.transactions?.[0]).toStrictEqual(expectedData); }); + it('ensures "daCompressedBlock" is supported by the node', async () => { + const nodeVersion = '0.40.0'; + + vi.spyOn(Provider.prototype, 'fetchChainAndNodeInfo').mockResolvedValue({ + chain: {} as ChainInfo, + nodeInfo: { nodeVersion } as NodeInfo, + }); + + vi.spyOn(Provider.prototype, 'getNode').mockResolvedValue({ + nodeVersion, + } as NodeInfo); + + using launched = await setupTestProviderAndWallets(); + const { provider } = launched; + + await expectToThrowFuelError( + () => provider.daCompressedBlock('100'), + new FuelError( + ErrorCode.NOT_SUPPORTED, + `The query "daCompressedBlock" is not supported by node version: ${nodeVersion}` + ) + ); + + vi.restoreAllMocks(); + }); + + it('ensures "getAssetDetails" is supported by the node', async () => { + const nodeVersion = '0.40.0'; + + vi.spyOn(Provider.prototype, 'fetchChainAndNodeInfo').mockResolvedValue({ + chain: {} as ChainInfo, + nodeInfo: { nodeVersion } as NodeInfo, + }); + + vi.spyOn(Provider.prototype, 'getNode').mockResolvedValue({ + nodeVersion, + } as NodeInfo); + + using launched = await setupTestProviderAndWallets(); + const { provider } = launched; + + await expectToThrowFuelError( + () => provider.getAssetDetails(getRandomB256()), + new FuelError( + ErrorCode.NOT_SUPPORTED, + `The query "getAssetDetails" is not supported by node version: ${nodeVersion}` + ) + ); + + vi.restoreAllMocks(); + }); + describe('paginated methods', () => { test('can properly use getCoins', async () => { const totalCoins = RESOURCES_PAGE_SIZE_LIMIT + 1; From b370707c07a65a6219cf6b02d75802cae5e89b1c Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 11:57:50 -0300 Subject: [PATCH 48/79] upgrade @fuels/vm-asm dep --- apps/demo-nextjs/package.json | 2 +- apps/demo-react-cra/package.json | 2 +- apps/demo-react-vite/package.json | 2 +- packages/account/package.json | 2 +- packages/contract/package.json | 2 +- packages/program/package.json | 2 +- pnpm-lock.yaml | 94 ++++++------------------------- 7 files changed, 24 insertions(+), 82 deletions(-) diff --git a/apps/demo-nextjs/package.json b/apps/demo-nextjs/package.json index 190266ee4e5..5c4cb965e74 100644 --- a/apps/demo-nextjs/package.json +++ b/apps/demo-nextjs/package.json @@ -10,7 +10,7 @@ "pretest": "pnpm original:build" }, "dependencies": { - "@fuels/vm-asm": "0.58.2", + "@fuels/vm-asm": "0.59.1", "@types/node": "22.5.5", "@types/react-dom": "18.3", "@types/react": "18.3.11", diff --git a/apps/demo-react-cra/package.json b/apps/demo-react-cra/package.json index b94328b81b9..a4aafeac02f 100644 --- a/apps/demo-react-cra/package.json +++ b/apps/demo-react-cra/package.json @@ -3,7 +3,7 @@ "version": "0.1.29", "private": true, "dependencies": { - "@fuels/vm-asm": "0.58.2", + "@fuels/vm-asm": "0.59.1", "@testing-library/react": "16.0.1", "@types/node": "22.5.5", "@types/react": "18.3.11", diff --git a/apps/demo-react-vite/package.json b/apps/demo-react-vite/package.json index b73ae721422..4eb3cf86be3 100644 --- a/apps/demo-react-vite/package.json +++ b/apps/demo-react-vite/package.json @@ -11,7 +11,7 @@ "pretest": "pnpm original:build" }, "dependencies": { - "@fuels/vm-asm": "0.58.2", + "@fuels/vm-asm": "0.59.1", "fuels": "workspace:*", "react-dom": "18.3.1", "react": "18.3.1" diff --git a/packages/account/package.json b/packages/account/package.json index 56cfe8b42ab..5fe51554aa3 100644 --- a/packages/account/package.json +++ b/packages/account/package.json @@ -58,7 +58,7 @@ "@fuel-ts/transactions": "workspace:*", "@fuel-ts/utils": "workspace:*", "@fuel-ts/versions": "workspace:*", - "@fuels/vm-asm": "0.58.2", + "@fuels/vm-asm": "0.59.1", "@noble/curves": "1.6.0", "events": "3.3.0", "graphql": "16.9.0", diff --git a/packages/contract/package.json b/packages/contract/package.json index 950ab5d0471..786ed9b9827 100644 --- a/packages/contract/package.json +++ b/packages/contract/package.json @@ -49,7 +49,7 @@ "@fuel-ts/program": "workspace:*", "@fuel-ts/transactions": "workspace:*", "@fuel-ts/utils": "workspace:*", - "@fuels/vm-asm": "0.58.2", + "@fuels/vm-asm": "0.59.1", "ramda": "0.30.1" }, "devDependencies": { diff --git a/packages/program/package.json b/packages/program/package.json index bac64bd1b55..35f4ca61fe4 100644 --- a/packages/program/package.json +++ b/packages/program/package.json @@ -33,7 +33,7 @@ "@fuel-ts/math": "workspace:*", "@fuel-ts/transactions": "workspace:*", "@fuel-ts/utils": "workspace:*", - "@fuels/vm-asm": "0.58.2" + "@fuels/vm-asm": "0.59.1" }, "devDependencies": { "@types/ramda": "0.30.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 8e9fee65ce7..e5a919d2581 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -68,7 +68,7 @@ importers: version: 2.0.5(bufferutil@4.0.8)(playwright@1.49.1)(typescript@5.6.3)(utf-8-validate@6.0.4)(vitest@2.0.5)(webdriverio@9.0.9(bufferutil@4.0.8)(utf-8-validate@6.0.4)) '@vitest/coverage-istanbul': specifier: 2.0.5 - version: 2.0.5(vitest@2.0.5(@types/node@22.5.5)(@vitest/browser@2.0.5)(jsdom@16.7.0(bufferutil@4.0.8)(utf-8-validate@6.0.4))(terser@5.36.0)) + version: 2.0.5(vitest@2.0.5) compare-versions: specifier: 6.1.1 version: 6.1.1 @@ -276,8 +276,8 @@ importers: apps/demo-nextjs: dependencies: '@fuels/vm-asm': - specifier: 0.58.2 - version: 0.58.2 + specifier: 0.59.1 + version: 0.59.1 '@types/node': specifier: 22.5.5 version: 22.5.5 @@ -312,8 +312,8 @@ importers: apps/demo-react-cra: dependencies: '@fuels/vm-asm': - specifier: 0.58.2 - version: 0.58.2 + specifier: 0.59.1 + version: 0.59.1 '@testing-library/react': specifier: 16.0.1 version: 16.0.1(@testing-library/dom@10.4.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) @@ -355,8 +355,8 @@ importers: apps/demo-react-vite: dependencies: '@fuels/vm-asm': - specifier: 0.58.2 - version: 0.58.2 + specifier: 0.59.1 + version: 0.59.1 fuels: specifier: workspace:* version: link:../../packages/fuels @@ -673,8 +673,8 @@ importers: specifier: workspace:* version: link:../versions '@fuels/vm-asm': - specifier: 0.58.2 - version: 0.58.2 + specifier: 0.59.1 + version: 0.59.1 '@noble/curves': specifier: 1.6.0 version: 1.6.0 @@ -767,8 +767,8 @@ importers: specifier: workspace:* version: link:../utils '@fuels/vm-asm': - specifier: 0.58.2 - version: 0.58.2 + specifier: 0.59.1 + version: 0.59.1 ramda: specifier: 0.30.1 version: 0.30.1 @@ -1021,8 +1021,8 @@ importers: specifier: workspace:* version: link:../utils '@fuels/vm-asm': - specifier: 0.58.2 - version: 0.58.2 + specifier: 0.59.1 + version: 0.59.1 ramda: specifier: 0.30.1 version: 0.30.1 @@ -3263,8 +3263,8 @@ packages: fuels: '>=0.96.1' react: '>=18.0.0' - '@fuels/vm-asm@0.58.2': - resolution: {integrity: sha512-1/5azTzKJP508BXbZvM6Y0V5bCCX5JgEnd/8mXdBFmFvNLOhiYbwb25yk26auqOokfBXvthSkdkrvipEFft6jQ==} + '@fuels/vm-asm@0.59.1': + resolution: {integrity: sha512-2KWwrjvZdj1DHlfkyGZPDOULBlUSj/2oZgn4RO+JO7uDPw7pNiHjsgKjmhDHWN5RPEGLhyUre14ObtLd3MA+Ag==} '@graphql-codegen/add@5.0.3': resolution: {integrity: sha512-SxXPmramkth8XtBlAHu4H4jYcYXM/o3p01+psU+0NADQowA8jtYkK6MW5rV6T+CxkEaNZItfSmZRPgIuypcqnA==} @@ -16340,7 +16340,7 @@ snapshots: - '@types/react-dom' - react-dom - '@fuels/vm-asm@0.58.2': {} + '@fuels/vm-asm@0.59.1': {} '@graphql-codegen/add@5.0.3(graphql@16.9.0)': dependencies: @@ -19584,7 +19584,7 @@ snapshots: - typescript - utf-8-validate - '@vitest/coverage-istanbul@2.0.5(vitest@2.0.5(@types/node@22.5.5)(@vitest/browser@2.0.5)(jsdom@16.7.0(bufferutil@4.0.8)(utf-8-validate@6.0.4))(terser@5.36.0))': + '@vitest/coverage-istanbul@2.0.5(vitest@2.0.5)': dependencies: '@istanbuljs/schema': 0.1.3 debug: 4.3.7(supports-color@5.5.0) @@ -23384,24 +23384,6 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0): - dependencies: - debug: 4.3.7(supports-color@5.5.0) - enhanced-resolve: 5.17.1 - eslint: 8.57.0 - eslint-module-utils: 2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0))(eslint@8.57.0) - eslint-plugin-import: 2.30.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) - fast-glob: 3.3.2 - get-tsconfig: 4.7.6 - is-core-module: 2.15.1 - is-glob: 4.0.3 - transitivePeerDependencies: - - '@typescript-eslint/parser' - - eslint-import-resolver-node - - eslint-import-resolver-webpack - - supports-color - optional: true - eslint-module-utils@2.11.0(@typescript-eslint/parser@5.59.0(eslint@9.9.1(jiti@2.4.2))(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint@9.9.1(jiti@2.4.2)): dependencies: debug: 3.2.7 @@ -23423,17 +23405,6 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0))(eslint@8.57.0): - dependencies: - debug: 3.2.7 - optionalDependencies: - '@typescript-eslint/parser': 6.21.0(eslint@8.57.0)(typescript@5.6.3) - eslint: 8.57.0 - eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0) - transitivePeerDependencies: - - supports-color - eslint-plugin-eslint-comments@3.2.0(eslint@8.57.0): dependencies: escape-string-regexp: 1.0.5 @@ -23485,7 +23456,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0))(eslint@8.57.0) + eslint-module-utils: 2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) hasown: 2.0.2 is-core-module: 2.15.1 is-glob: 4.0.3 @@ -23530,35 +23501,6 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-plugin-import@2.30.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0): - dependencies: - '@rtsao/scc': 1.1.0 - array-includes: 3.1.8 - array.prototype.findlastindex: 1.2.5 - array.prototype.flat: 1.3.2 - array.prototype.flatmap: 1.3.2 - debug: 3.2.7 - doctrine: 2.1.0 - eslint: 8.57.0 - eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.11.0(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@6.21.0(eslint@8.57.0)(typescript@5.6.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.30.0)(eslint@8.57.0))(eslint@8.57.0) - hasown: 2.0.2 - is-core-module: 2.15.1 - is-glob: 4.0.3 - minimatch: 3.1.2 - object.fromentries: 2.0.8 - object.groupby: 1.0.3 - object.values: 1.2.0 - semver: 6.3.1 - tsconfig-paths: 3.15.0 - optionalDependencies: - '@typescript-eslint/parser': 6.21.0(eslint@8.57.0)(typescript@5.6.3) - transitivePeerDependencies: - - eslint-import-resolver-typescript - - eslint-import-resolver-webpack - - supports-color - optional: true - eslint-plugin-jest@25.7.0(@typescript-eslint/eslint-plugin@5.59.0(@typescript-eslint/parser@5.59.0(eslint@9.9.1(jiti@2.4.2))(typescript@5.6.3))(eslint@9.9.1(jiti@2.4.2))(typescript@5.6.3))(eslint@9.9.1(jiti@2.4.2))(jest@27.5.1(bufferutil@4.0.8)(ts-node@10.9.1(@swc/core@1.7.14(@swc/helpers@0.5.12))(@types/node@22.5.5)(typescript@5.6.3))(utf-8-validate@5.0.10))(typescript@5.6.3): dependencies: '@typescript-eslint/experimental-utils': 5.60.1(eslint@9.9.1(jiti@2.4.2))(typescript@5.6.3) From 3d8e44e7af7329186c7eb0ce4caf944efd911536 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Mon, 20 Jan 2025 11:58:12 -0300 Subject: [PATCH 49/79] update PANIC_REASONS const --- packages/transactions/src/configs.ts | 90 +++++++++++++++------------- 1 file changed, 47 insertions(+), 43 deletions(-) diff --git a/packages/transactions/src/configs.ts b/packages/transactions/src/configs.ts index ea38645e3a6..8f8e9f296fe 100644 --- a/packages/transactions/src/configs.ts +++ b/packages/transactions/src/configs.ts @@ -43,63 +43,67 @@ export const FAILED_ASSERT_NE_SIGNAL = '0xffffffffffff0005'; export const FAILED_UNKNOWN_SIGNAL = '0x0'; export const PANIC_REASONS = [ - 'UnknownPanicReason', - 'Revert', - 'OutOfGas', - 'TransactionValidity', - 'MemoryOverflow', + 'ArithmeticError', 'ArithmeticOverflow', + 'AssetIdNotFound', + 'BalanceOverflow', + 'BlobIdAlreadyUploaded', + 'BlobNotFound', + 'BytecodeAlreadyUploaded', + 'ContractIdAlreadyDeployed', + 'ContractInstructionNotAllowed', + 'ContractMaxSize', + 'ContractMismatch', 'ContractNotFound', - 'MemoryOwnership', - 'NotEnoughBalance', + 'ContractNotInInputs', + 'EcalError', + 'ExpectedCoinInput', 'ExpectedInternalContext', - 'AssetIdNotFound', + 'ExpectedNestedCaller', + 'ExpectedOutputVariable', + 'ExpectedParentInternalContext', + 'ExpectedUnallocatedStack', + 'GasCostNotDefined', + 'InputContractDoesNotExist', 'InputNotFound', - 'OutputNotFound', - 'WitnessNotFound', - 'TransactionMaturity', - 'InvalidMetadataIdentifier', - 'MalformedCallStructure', - 'ReservedRegisterNotWritable', + 'InternalBalanceOverflow', + 'InvalidBlockHeight', + 'InvalidEllipticCurvePoint', 'InvalidFlags', 'InvalidImmediateValue', - 'ExpectedCoinInput', - 'EcalError', - 'MemoryWriteOverlap', - 'ContractNotInInputs', - 'InternalBalanceOverflow', - 'ContractMaxSize', - 'ExpectedUnallocatedStack', - 'MaxStaticContractsReached', - 'TransferAmountCannotBeZero', - 'ExpectedOutputVariable', - 'ExpectedParentInternalContext', - 'PredicateReturnedNonOne', - 'ContractIdAlreadyDeployed', - 'ContractMismatch', - 'MessageDataTooLong', - 'ArithmeticError', - 'ContractInstructionNotAllowed', - 'TransferZeroCoins', 'InvalidInstruction', + 'InvalidMetadataIdentifier', + 'MalformedCallStructure', + 'MaxStaticContractsReached', + 'MemoryGrowthOverlap', 'MemoryNotExecutable', + 'MemoryOverflow', + 'MemoryOwnership', + 'MemoryWriteOverlap', + 'MessageDataTooLong', + 'NotEnoughBalance', + 'OutOfGas', + 'OutputNotFound', + 'OverridingConsensusParameters', + 'OverridingStateTransactionBytecode', 'PolicyIsNotSet', 'PolicyNotFound', + 'PredicateReturnedNonOne', + 'ReservedRegisterNotWritable', + 'Revert', + 'ThePartIsNotSequentiallyConnected', 'TooManyReceipts', - 'BalanceOverflow', - 'InvalidBlockHeight', 'TooManySlots', - 'ExpectedNestedCaller', - 'MemoryGrowthOverlap', + 'TransactionMaturity', + 'TransactionValidity', + 'TransferAmountCannotBeZero', + 'TransferZeroCoins', 'UninitalizedMemoryAccess', - 'OverridingConsensusParameters', + 'UnknownPanicReason', 'UnknownStateTransactionBytecodeRoot', - 'OverridingStateTransactionBytecode', - 'BytecodeAlreadyUploaded', - 'ThePartIsNotSequentiallyConnected', - 'BlobIdAlreadyUploaded', - 'BlobNotFound', - 'GasCostNotDefined', + 'UnsupportedCurveId', + 'UnsupportedOperationType', + 'WitnessNotFound', ]; export const PANIC_DOC_URL = 'https://docs.rs/fuel-asm/latest/fuel_asm/enum.PanicReason.html'; From 3baa29769b857c70386e2bdb6c4d13d8e2571c01 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Tue, 21 Jan 2025 14:22:22 -0300 Subject: [PATCH 50/79] add TS DOCS --- packages/account/src/providers/provider.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index c8d42d8660f..15374c027d2 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -837,6 +837,12 @@ export default class Provider { return baseAssetId; } + /** + * Retrieves the details of an asset given its ID. + * + * @param assetId - The unique identifier of the asset. + * @returns A promise that resolves to an object containing the asset details. + */ async getAssetDetails(assetId: string): Promise { if (!this.features.getAssetDetails) { const { nodeVersion } = await this.getNode(); @@ -1738,6 +1744,12 @@ export default class Provider { } } + /** + * Fetches a compressed block at the specified height. + * + * @param height - The height of the block to fetch. + * @returns The compressed block if available, otherwise `null`. + */ async daCompressedBlock(height: string) { if (!this.features.daCompressedBlock) { const { nodeVersion } = await this.getNode(); From 8a8c773fdf4f253aa04562e5e20e0f043b8ebe99 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Tue, 21 Jan 2025 14:22:33 -0300 Subject: [PATCH 51/79] add comments --- .../src/providers/transaction-request/transaction-request.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/account/src/providers/transaction-request/transaction-request.ts b/packages/account/src/providers/transaction-request/transaction-request.ts index 3f2de193a68..facdbf6fe3f 100644 --- a/packages/account/src/providers/transaction-request/transaction-request.ts +++ b/packages/account/src/providers/transaction-request/transaction-request.ts @@ -75,7 +75,7 @@ export interface BaseTransactionRequestLike { tip?: BigNumberish; /** Block until which tx cannot be included */ maturity?: number; - /** TODO: describe me please */ + /** The block number after which the transaction is no longer valid. */ expiration?: number; /** The maximum fee payable by this transaction using BASE_ASSET. */ maxFee?: BigNumberish; @@ -111,7 +111,7 @@ export abstract class BaseTransactionRequest implements BaseTransactionRequestLi tip?: BN; /** Block until which tx cannot be included */ maturity?: number; - /** TODO: describe me please */ + /** The block number after which the transaction is no longer valid. */ expiration?: number; /** The maximum fee payable by this transaction using BASE_ASSET. */ maxFee: BN; From a08e7fe26688f1a831f233f0dc591d9e7269336a Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 10:51:29 -0300 Subject: [PATCH 52/79] comparing messages using regex instead of switch --- .../utils/handle-gql-error-message.ts | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/account/src/providers/utils/handle-gql-error-message.ts b/packages/account/src/providers/utils/handle-gql-error-message.ts index cb015fe30df..12ba9955056 100644 --- a/packages/account/src/providers/utils/handle-gql-error-message.ts +++ b/packages/account/src/providers/utils/handle-gql-error-message.ts @@ -8,17 +8,15 @@ export enum GqlErrorMessage { type GqlError = { message: string } | GraphQLError; const mapGqlErrorMessage = (error: GqlError): FuelError => { - switch (error.message) { - case GqlErrorMessage.NOT_ENOUGH_COINS_MAX_COINS: - return new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, - `Insufficient funds or too many small value coins. Consider combining UTXOs.`, - {}, - error - ); - default: - return new FuelError(ErrorCode.INVALID_REQUEST, error.message, {}, error); + if (new RegExp(GqlErrorMessage.NOT_ENOUGH_COINS_MAX_COINS).test(error.message)) { + return new FuelError( + ErrorCode.NOT_ENOUGH_FUNDS, + `Insufficient funds or too many small value coins. Consider combining UTXOs.`, + {}, + error + ); } + return new FuelError(ErrorCode.INVALID_REQUEST, error.message, {}, error); }; const mapGqlErrorWithIncompatibleNodeVersion = ( From 1321c222bbff4f22a43051e4c8928cc1c8ca4872 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 10:55:24 -0300 Subject: [PATCH 53/79] update gql error message to match with any value --- .../account/src/providers/utils/handle-gql-error-message.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/account/src/providers/utils/handle-gql-error-message.ts b/packages/account/src/providers/utils/handle-gql-error-message.ts index 12ba9955056..1333bb2ca9c 100644 --- a/packages/account/src/providers/utils/handle-gql-error-message.ts +++ b/packages/account/src/providers/utils/handle-gql-error-message.ts @@ -1,8 +1,8 @@ import { ErrorCode, FuelError } from '@fuel-ts/errors'; import type { GraphQLError } from 'graphql'; -export enum GqlErrorMessage { - NOT_ENOUGH_COINS_MAX_COINS = 'the target cannot be met due to no coins available or exceeding the 255 coin limit.', +enum GqlErrorMessage { + NOT_ENOUGH_COINS_MAX_COINS = 'the target cannot be met due to no coins available or exceeding the \\d+ coin limit.', } type GqlError = { message: string } | GraphQLError; From 4dd1f36fa7e94e142a523f772b1e1a288807c21b Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 11:25:50 -0300 Subject: [PATCH 54/79] throwing error in proper place --- packages/account/src/providers/provider.ts | 21 +++++++------------ .../utils/handle-gql-error-message.ts | 11 ++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 15374c027d2..fdaaaaecb2b 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -852,22 +852,15 @@ export default class Provider { ); } - try { - const { assetDetails } = await this.operations.getAssetDetails({ assetId }); + const { assetDetails } = await this.operations.getAssetDetails({ assetId }); - const { contractId, subId, totalSupply } = assetDetails; + const { contractId, subId, totalSupply } = assetDetails; - return { - subId, - contractId, - totalSupply: bn(totalSupply), - }; - } catch (e) { - throw new FuelError( - ErrorCode.ASSET_NOT_FOUND, - `Asset not found for given asset id: ${assetId}` - ); - } + return { + subId, + contractId, + totalSupply: bn(totalSupply), + }; } /** diff --git a/packages/account/src/providers/utils/handle-gql-error-message.ts b/packages/account/src/providers/utils/handle-gql-error-message.ts index 1333bb2ca9c..a91ac1e8e70 100644 --- a/packages/account/src/providers/utils/handle-gql-error-message.ts +++ b/packages/account/src/providers/utils/handle-gql-error-message.ts @@ -3,6 +3,7 @@ import type { GraphQLError } from 'graphql'; enum GqlErrorMessage { NOT_ENOUGH_COINS_MAX_COINS = 'the target cannot be met due to no coins available or exceeding the \\d+ coin limit.', + ASSET_NOT_FOUND = 'resource was not found in table', } type GqlError = { message: string } | GraphQLError; @@ -16,6 +17,16 @@ const mapGqlErrorMessage = (error: GqlError): FuelError => { error ); } + + if (new RegExp(GqlErrorMessage.ASSET_NOT_FOUND).test(error.message)) { + return new FuelError( + ErrorCode.ASSET_NOT_FOUND, + `Asset not found for given asset id.`, + {}, + error + ); + } + return new FuelError(ErrorCode.INVALID_REQUEST, error.message, {}, error); }; From feba962116d2e1e167717fed3eab35994cd4acbb Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 12:36:04 -0300 Subject: [PATCH 55/79] release PR --- .github/workflows/pr-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index 6eeca1f3f04..593d7fce145 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: "Release PR to npm" runs-on: ubuntu-latest # comment out if:false to enable release PR to npm - if: false + # if: false permissions: write-all steps: - name: Checkout From aa2d70f52c37da46f40faf7b0fe3d40a7e91f3b9 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 15:05:26 -0300 Subject: [PATCH 56/79] remove backwards compatibility for new features --- .../account/src/providers/provider.test.ts | 52 ------------------- packages/account/src/providers/provider.ts | 22 -------- 2 files changed, 74 deletions(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 45b202e35c3..8ac220f1b37 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -1986,58 +1986,6 @@ describe('Provider', () => { expect(block?.transactions?.[0]).toStrictEqual(expectedData); }); - it('ensures "daCompressedBlock" is supported by the node', async () => { - const nodeVersion = '0.40.0'; - - vi.spyOn(Provider.prototype, 'fetchChainAndNodeInfo').mockResolvedValue({ - chain: {} as ChainInfo, - nodeInfo: { nodeVersion } as NodeInfo, - }); - - vi.spyOn(Provider.prototype, 'getNode').mockResolvedValue({ - nodeVersion, - } as NodeInfo); - - using launched = await setupTestProviderAndWallets(); - const { provider } = launched; - - await expectToThrowFuelError( - () => provider.daCompressedBlock('100'), - new FuelError( - ErrorCode.NOT_SUPPORTED, - `The query "daCompressedBlock" is not supported by node version: ${nodeVersion}` - ) - ); - - vi.restoreAllMocks(); - }); - - it('ensures "getAssetDetails" is supported by the node', async () => { - const nodeVersion = '0.40.0'; - - vi.spyOn(Provider.prototype, 'fetchChainAndNodeInfo').mockResolvedValue({ - chain: {} as ChainInfo, - nodeInfo: { nodeVersion } as NodeInfo, - }); - - vi.spyOn(Provider.prototype, 'getNode').mockResolvedValue({ - nodeVersion, - } as NodeInfo); - - using launched = await setupTestProviderAndWallets(); - const { provider } = launched; - - await expectToThrowFuelError( - () => provider.getAssetDetails(getRandomB256()), - new FuelError( - ErrorCode.NOT_SUPPORTED, - `The query "getAssetDetails" is not supported by node version: ${nodeVersion}` - ) - ); - - vi.restoreAllMocks(); - }); - describe('paginated methods', () => { test('can properly use getCoins', async () => { const totalCoins = RESOURCES_PAGE_SIZE_LIMIT + 1; diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index fdaaaaecb2b..1822baaf8a8 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -77,8 +77,6 @@ export const GAS_USED_MODIFIER = 1.2; export type Features = { balancePagination: boolean; amount128: boolean; - daCompressedBlock: boolean; - getAssetDetails: boolean; }; export type DryRunFailureStatusFragment = GqlDryRunFailureStatusFragment; @@ -429,8 +427,6 @@ export default class Provider { private features: Features = { balancePagination: false, amount128: false, - daCompressedBlock: false, - getAssetDetails: false, }; /** @hidden */ @@ -744,8 +740,6 @@ export default class Provider { if (gte(nodeVersion, '0.41.0')) { this.features.balancePagination = true; this.features.amount128 = true; - this.features.daCompressedBlock = true; - this.features.getAssetDetails = true; } } @@ -844,14 +838,6 @@ export default class Provider { * @returns A promise that resolves to an object containing the asset details. */ async getAssetDetails(assetId: string): Promise { - if (!this.features.getAssetDetails) { - const { nodeVersion } = await this.getNode(); - throw new FuelError( - ErrorCode.NOT_SUPPORTED, - `The query "getAssetDetails" is not supported by node version: ${nodeVersion}` - ); - } - const { assetDetails } = await this.operations.getAssetDetails({ assetId }); const { contractId, subId, totalSupply } = assetDetails; @@ -1744,14 +1730,6 @@ export default class Provider { * @returns The compressed block if available, otherwise `null`. */ async daCompressedBlock(height: string) { - if (!this.features.daCompressedBlock) { - const { nodeVersion } = await this.getNode(); - throw new FuelError( - ErrorCode.NOT_SUPPORTED, - `The query "daCompressedBlock" is not supported by node version: ${nodeVersion}` - ); - } - const { daCompressedBlock } = await this.operations.daCompressedBlock({ height, }); From 34cb7e62dc443f6ec78e11a8d9f0ff24b9e07005 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 15:13:54 -0300 Subject: [PATCH 57/79] remove TODO --- packages/account/src/providers/provider.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 1822baaf8a8..d8a9b30b3ad 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -783,7 +783,6 @@ export default class Provider { nodeVersion: nodeInfo.nodeVersion, utxoValidation: nodeInfo.utxoValidation, vmBacktrace: nodeInfo.vmBacktrace, - // TODO: should we add `maxGas` and `txPoolStats` to the NodeInfo type? }; Provider.nodeInfoCache[this.urlWithoutAuth] = processedNodeInfo; From d2c55affbbf3a459c01a832366fe5591428cc809 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 15:53:57 -0300 Subject: [PATCH 58/79] add test for u128 balances --- .../account/src/providers/provider.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 8ac220f1b37..df716f1634b 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -10,6 +10,7 @@ import { DateTime, arrayify, sleep } from '@fuel-ts/utils'; import { ASSET_A, ASSET_B } from '@fuel-ts/utils/test-utils'; import { versions } from '@fuel-ts/versions'; +import type { CoinQuantity } from '..'; import { Wallet } from '..'; import { messageStatusResponse, @@ -2357,6 +2358,40 @@ describe('Provider', () => { }); }); + test('should ensure getBalance and getBalances can return u128 amounts ', async () => { + const fundingAmount = 2 ** 63; + const maxU64 = bn('0xFFFFFFFFFFFFFFFF'); + + using launched = await setupTestProviderAndWallets({ + walletsConfig: { + amountPerCoin: fundingAmount, + count: 3, + }, + }); + const { + provider, + wallets: [wallet1, wallet2, recipient], + } = launched; + + const baseAssetId = await provider.getBaseAssetId(); + + const tx1 = await wallet1.transfer(recipient.address, bn(String(fundingAmount)).sub(1000)); + await tx1.waitForResult(); + + const tx2 = await wallet2.transfer(recipient.address, bn(String(fundingAmount)).sub(1000)); + await tx2.waitForResult(); + + const balance = await recipient.getBalance(); + + expect(balance.gt(maxU64)).toBeTruthy(); + + const { balances } = await recipient.getBalances(); + const baseAssetBalance = balances.find((b) => b.assetId === baseAssetId) as CoinQuantity; + + expect(baseAssetBalance).toBeDefined(); + expect(baseAssetBalance.amount.gt(maxU64)).toBeTruthy(); + }); + test('should not refetch consensus params in less than 1min', async () => { using launched = await setupTestProviderAndWallets(); From fa363cb6eebfd330cd154d0bc95854da193c7c13 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 16:24:26 -0300 Subject: [PATCH 59/79] add test to validate getBalancesV1 --- .../account/src/providers/provider.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index df716f1634b..63281c763e4 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -2237,6 +2237,34 @@ describe('Provider', () => { expect(pageInfo.endCursor).toBeDefined(); }); + it('can get balances [V1]', async () => { + vi.spyOn(Provider.prototype, 'fetchChainAndNodeInfo').mockImplementationOnce(async () => + Promise.resolve({ + nodeInfo: { nodeVersion: '0.40.0' } as NodeInfo, + chain: {} as ChainInfo, + }) + ); + + using launched = await setupTestProviderAndWallets(); + const { + provider, + wallets: [wallet], + } = launched; + + const spy = vi.spyOn(provider.operations, 'getBalances'); + + const { pageInfo } = await wallet.getBalances(); + + expect(spy).toHaveBeenCalledWith({ + first: 10000, + filter: { owner: wallet.address.toB256() }, + }); + + expect(pageInfo).not.toBeDefined(); + + vi.restoreAllMocks(); + }); + describe('pagination arguments', async () => { using launched = await setupTestProviderAndWallets({ walletsConfig: { From 0b29a6024e7d4b688a483b0d5998c3b2dfe0c8eb Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 16:29:36 -0300 Subject: [PATCH 60/79] stop releasing PR --- .github/workflows/pr-release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-release.yaml b/.github/workflows/pr-release.yaml index 593d7fce145..6eeca1f3f04 100644 --- a/.github/workflows/pr-release.yaml +++ b/.github/workflows/pr-release.yaml @@ -8,7 +8,7 @@ jobs: name: "Release PR to npm" runs-on: ubuntu-latest # comment out if:false to enable release PR to npm - # if: false + if: false permissions: write-all steps: - name: Checkout From 438fa988c96dd59ed6d62068c0e7196f0669081a Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 16:48:52 -0300 Subject: [PATCH 61/79] add test for daCompressedBlock --- .../account/src/providers/provider.test.ts | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 63281c763e4..9092dfc5236 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -6,7 +6,7 @@ import { expectToThrowFuelError, safeExec } from '@fuel-ts/errors/test-utils'; import { BN, bn } from '@fuel-ts/math'; import type { Receipt } from '@fuel-ts/transactions'; import { InputType, OutputType, ReceiptType } from '@fuel-ts/transactions'; -import { DateTime, arrayify, sleep } from '@fuel-ts/utils'; +import { DateTime, arrayify, hexlify, sleep } from '@fuel-ts/utils'; import { ASSET_A, ASSET_B } from '@fuel-ts/utils/test-utils'; import { versions } from '@fuel-ts/versions'; @@ -2576,4 +2576,29 @@ describe('Provider', () => { code: ErrorCode.SCRIPT_REVERTED, }); }); + + it('can get compressed block bytes', async () => { + const bytes = hexlify(randomBytes(32)); + + using launched = await setupTestProviderAndWallets(); + const { provider } = launched; + + // Should return null when block is not found + let compressed = await provider.daCompressedBlock('1'); + + expect(compressed).toBeNull(); + + vi.spyOn(provider, 'daCompressedBlock').mockImplementationOnce(async () => + Promise.resolve({ + bytes, + }) + ); + + const block = await provider.getBlock('latest'); + compressed = await provider.daCompressedBlock(String(block?.height)); + + expect(compressed).toStrictEqual({ bytes }); + + vi.restoreAllMocks(); + }); }); From dc94c51b151ee2a23417722515be931564962268 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 17:04:42 -0300 Subject: [PATCH 62/79] add new props to GasCosts --- packages/utils/src/utils/defaultSnapshots/chainConfig.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/utils/src/utils/defaultSnapshots/chainConfig.json b/packages/utils/src/utils/defaultSnapshots/chainConfig.json index 243b9249015..73c2fac49fe 100644 --- a/packages/utils/src/utils/defaultSnapshots/chainConfig.json +++ b/packages/utils/src/utils/defaultSnapshots/chainConfig.json @@ -126,6 +126,7 @@ "wqmm": 6, "xor": 2, "xori": 2, + "ecop": 2, "aloc": { "LightOperation": { "base": 2, @@ -270,6 +271,12 @@ "gas_per_unit": 5776 } }, + "epar": { + "HeavyOperation": { + "base": 5661, + "gas_per_unit": 5776 + } + }, "contract_root": { "LightOperation": { "base": 24, From 29801971fd61ba000d8d609e06bc730e96f81585 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 17:17:02 -0300 Subject: [PATCH 63/79] fix changeset --- .changeset/real-schools-poke.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/.changeset/real-schools-poke.md b/.changeset/real-schools-poke.md index 2ea490426d9..8628de98732 100644 --- a/.changeset/real-schools-poke.md +++ b/.changeset/real-schools-poke.md @@ -1,11 +1,13 @@ --- -"@fuel-ts/transactions": patch -"@internal/fuel-core": patch -"@fuel-ts/versions": patch -"@fuel-ts/account": patch -"@fuel-ts/program": patch -"@fuel-ts/recipes": patch -"@fuel-ts/errors": patch +"@fuel-ts/transactions": minor +"@internal/fuel-core": minor +"@fuel-ts/contract": minor +"@fuel-ts/versions": minor +"@fuel-ts/account": minor +"@fuel-ts/program": minor +"@fuel-ts/recipes": minor +"@fuel-ts/errors": minor +"@fuel-ts/utils": minor --- chore: upgrade `fuel-core` to `0.41.0` From 3ecdae9921c49af43464562636da5358a3147337 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 21:38:32 -0300 Subject: [PATCH 64/79] rename NOT_ENOUGH_FUNDS error and removed MAX_COINS_REACHED --- apps/demo-bun-fuels/src/bun.test.ts | 2 +- apps/demo-fuels/src/index.test.ts | 2 +- apps/demo-typegen/src/demo.test.ts | 2 +- packages/account/src/account.test.ts | 4 ++-- packages/account/src/account.ts | 2 +- packages/account/src/providers/provider.test.ts | 4 ++-- .../account/src/providers/utils/handle-gql-error-message.ts | 2 +- packages/errors/src/error-codes.ts | 3 +-- packages/fuel-gauge/src/contract.test.ts | 2 +- packages/fuel-gauge/src/funding-transaction.test.ts | 2 +- packages/fuel-gauge/src/mapped-error-messages.test.ts | 4 ++-- .../fuel-gauge/src/predicate/predicate-invalidations.test.ts | 2 +- .../fuel-gauge/src/predicate/predicate-with-contract.test.ts | 2 +- .../fuel-gauge/src/predicate/predicate-with-script.test.ts | 2 +- 14 files changed, 17 insertions(+), 18 deletions(-) diff --git a/apps/demo-bun-fuels/src/bun.test.ts b/apps/demo-bun-fuels/src/bun.test.ts index a96a375396d..a14426c5dae 100644 --- a/apps/demo-bun-fuels/src/bun.test.ts +++ b/apps/demo-bun-fuels/src/bun.test.ts @@ -81,7 +81,7 @@ describe('ExampleContract', () => { await expectToThrowFuelError( () => contractInstance.functions.return_input(1337).simulate(), new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); diff --git a/apps/demo-fuels/src/index.test.ts b/apps/demo-fuels/src/index.test.ts index 67ffce86321..7fd17d78908 100644 --- a/apps/demo-fuels/src/index.test.ts +++ b/apps/demo-fuels/src/index.test.ts @@ -74,7 +74,7 @@ describe('ExampleContract', () => { await expectToThrowFuelError( () => contractInstance.functions.return_input(1337).simulate(), new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); diff --git a/apps/demo-typegen/src/demo.test.ts b/apps/demo-typegen/src/demo.test.ts index 117fc7d03e6..030ae91e8a4 100644 --- a/apps/demo-typegen/src/demo.test.ts +++ b/apps/demo-typegen/src/demo.test.ts @@ -108,7 +108,7 @@ it('should throw when simulating via contract factory with wallet with no resour await expectToThrowFuelError( () => contractInstance.functions.return_input(1337).simulate(), new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); diff --git a/packages/account/src/account.test.ts b/packages/account/src/account.test.ts index 7265a8367f1..76791e7936b 100644 --- a/packages/account/src/account.test.ts +++ b/packages/account/src/account.test.ts @@ -589,7 +589,7 @@ describe('Account', () => { await expectToThrowFuelError( () => user.getResourcesToSpend([[1, ASSET_A, 500_000]], { utxos: [assetAUTXO.id] }), new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); @@ -969,7 +969,7 @@ describe('Account', () => { request.addCoinOutput(wallet.address, 30_000, await provider.getBaseAssetId()); await expectToThrowFuelError(() => request.estimateAndFund(wallet), { - code: ErrorCode.NOT_ENOUGH_FUNDS, + code: ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, message: 'Insufficient funds or too many small value coins. Consider combining UTXOs.', }); }); diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index ea69b56a9cb..57b47d67747 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -306,7 +306,7 @@ export class Account extends AbstractAccount implements WithAddress { // If the transaction still needs to be funded after the maximum number of attempts if (needsToBeFunded) { throw new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `The account ${this.address} does not have enough base asset funds to cover the transaction execution.` ); } diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index 9092dfc5236..adfd8b2b288 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -1165,7 +1165,7 @@ describe('Provider', () => { const receiver = Wallet.generate({ provider }); await expectToThrowFuelError(() => sender.transfer(receiver.address, 1), { - code: ErrorCode.NOT_ENOUGH_FUNDS, + code: ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, message: [ `Insufficient funds or too many small value coins. Consider combining UTXOs.`, ``, @@ -1192,7 +1192,7 @@ describe('Provider', () => { const receiver = Wallet.generate({ provider }); await expectToThrowFuelError(() => sender.transfer(receiver.address, 1), { - code: ErrorCode.NOT_ENOUGH_FUNDS, + code: ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, message: [ `Insufficient funds or too many small value coins. Consider combining UTXOs.`, ``, diff --git a/packages/account/src/providers/utils/handle-gql-error-message.ts b/packages/account/src/providers/utils/handle-gql-error-message.ts index a91ac1e8e70..3b5f69ec04c 100644 --- a/packages/account/src/providers/utils/handle-gql-error-message.ts +++ b/packages/account/src/providers/utils/handle-gql-error-message.ts @@ -11,7 +11,7 @@ type GqlError = { message: string } | GraphQLError; const mapGqlErrorMessage = (error: GqlError): FuelError => { if (new RegExp(GqlErrorMessage.NOT_ENOUGH_COINS_MAX_COINS).test(error.message)) { return new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.`, {}, error diff --git a/packages/errors/src/error-codes.ts b/packages/errors/src/error-codes.ts index 292acdf299b..d088aa6aad1 100644 --- a/packages/errors/src/error-codes.ts +++ b/packages/errors/src/error-codes.ts @@ -57,7 +57,7 @@ export enum ErrorCode { MISSING_REQUIRED_PARAMETER = 'missing-required-parameter', INVALID_REQUEST = 'invalid-request', INVALID_TRANSFER_AMOUNT = 'invalid-transfer-amount', - NOT_ENOUGH_FUNDS = 'not-enough-funds', + INSUFFICIENT_FUNDS_OR_MAX_COINS = 'not-enough-funds-or-max-coins-reached', // crypto INVALID_CREDENTIALS = 'invalid-credentials', @@ -85,7 +85,6 @@ export enum ErrorCode { MAX_INPUTS_EXCEEDED = 'max-inputs-exceeded', FUNDS_TOO_LOW = 'funds-too-low', MAX_OUTPUTS_EXCEEDED = 'max-outputs-exceeded', - MAX_COINS_REACHED = 'max-coins-reached', ASSET_BURN_DETECTED = 'asset-burn-detected', // receipt diff --git a/packages/fuel-gauge/src/contract.test.ts b/packages/fuel-gauge/src/contract.test.ts index b5b6c25ba8b..821166d505c 100644 --- a/packages/fuel-gauge/src/contract.test.ts +++ b/packages/fuel-gauge/src/contract.test.ts @@ -1110,7 +1110,7 @@ describe('Contract', () => { }) .simulate(), new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); diff --git a/packages/fuel-gauge/src/funding-transaction.test.ts b/packages/fuel-gauge/src/funding-transaction.test.ts index eded8025ae8..d1b58a389c8 100644 --- a/packages/fuel-gauge/src/funding-transaction.test.ts +++ b/packages/fuel-gauge/src/funding-transaction.test.ts @@ -264,7 +264,7 @@ describe('Funding Transactions', () => { await expectToThrowFuelError( () => sender.fund(request, txCost), new FuelError( - FuelError.CODES.NOT_ENOUGH_FUNDS, + FuelError.CODES.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); diff --git a/packages/fuel-gauge/src/mapped-error-messages.test.ts b/packages/fuel-gauge/src/mapped-error-messages.test.ts index 975c61704c6..7be7b9673a0 100644 --- a/packages/fuel-gauge/src/mapped-error-messages.test.ts +++ b/packages/fuel-gauge/src/mapped-error-messages.test.ts @@ -18,7 +18,7 @@ describe('mapped error messages', () => { const emptyWalletContract = new Contract(contract.id, contract.interface.jsonAbi, emptyWallet); await expectToThrowFuelError(() => emptyWalletContract.functions.return_void().call(), { - code: ErrorCode.NOT_ENOUGH_FUNDS, + code: ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, message: `Insufficient funds or too many small value coins. Consider combining UTXOs.`, }); }); @@ -42,7 +42,7 @@ describe('mapped error messages', () => { request.maxFee = txCost.maxFee; await expectToThrowFuelError(() => wallet.fund(request, txCost), { - code: ErrorCode.NOT_ENOUGH_FUNDS, + code: ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, message: 'Insufficient funds or too many small value coins. Consider combining UTXOs.', }); }); diff --git a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts index 75c619ba25d..c423d0c0f71 100644 --- a/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-invalidations.test.ts @@ -40,7 +40,7 @@ describe('Predicate', () => { } ), new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); 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 6d1f886a33a..5ad5bd57958 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-contract.test.ts @@ -63,7 +63,7 @@ describe('Predicate', () => { await expectToThrowFuelError( () => contract.functions.mint_coins(200).call(), new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); 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 dd8348f83b9..2a78545bd63 100644 --- a/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts +++ b/packages/fuel-gauge/src/predicate/predicate-with-script.test.ts @@ -36,7 +36,7 @@ describe('Predicate', () => { await expectToThrowFuelError( () => scriptInstance.functions.main(scriptInput).call(), new FuelError( - ErrorCode.NOT_ENOUGH_FUNDS, + ErrorCode.INSUFFICIENT_FUNDS_OR_MAX_COINS, `Insufficient funds or too many small value coins. Consider combining UTXOs.` ) ); From c3945eeab87f023fe9c3e3aa572ac37624cad14d Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 21:38:42 -0300 Subject: [PATCH 65/79] improving docs --- .../src/guide/cookbook/combining-utxos.md | 2 +- apps/docs/src/guide/errors/index.md | 22 +++++++++++-------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/apps/docs/src/guide/cookbook/combining-utxos.md b/apps/docs/src/guide/cookbook/combining-utxos.md index a08677e1936..e9ddc9090ff 100644 --- a/apps/docs/src/guide/cookbook/combining-utxos.md +++ b/apps/docs/src/guide/cookbook/combining-utxos.md @@ -1,6 +1,6 @@ # Combining UTXOs -When performing a funding operation or calling `getResourcesToSpend`, you may encounter the `MAX_COINS_REACHED` error if the number of coins fetched per asset exceeds the maximum limit allowed by the chain. +When performing a funding operation or calling `getResourcesToSpend`, you may encounter the `INSUFFICIENT_FUNDS_OR_MAX_COINS` error if the number of coins fetched per asset exceeds the maximum limit allowed by the chain. You may also want to do this if you want to reduce the number of inputs in your transaction, which can be useful if you are trying to reduce the size of your transaction or you are receiving the `MAX_INPUTS_EXCEEDED` error. diff --git a/apps/docs/src/guide/errors/index.md b/apps/docs/src/guide/errors/index.md index f28a91ef8b4..9fc637b3c3e 100644 --- a/apps/docs/src/guide/errors/index.md +++ b/apps/docs/src/guide/errors/index.md @@ -276,11 +276,21 @@ When the Fuel Node info cache is empty; This is usually caused by not being conn Ensure that the provider has connected to a Fuel Node successfully. -### `NOT_ENOUGH_FUNDS` +### `INSUFFICIENT_FUNDS_OR_MAX_COINS` -When the account sending the transaction does not have enough funds to cover the fee. +This error can occur during a funding operation or when calling the `getResourcesToSpend` method. It indicates one of the following issues: -Ensure that the account creating the transaction has been funded appropriately. +`Insufficient Balance`: The specified account does not have enough balance to cover the required amount. + +`UTXO Limit Exceeded`: Although the account has enough total funds, the funds are spread across too many UTXOs (coins). The blockchain limits how many UTXOs can be used in a single transaction, and exceeding this limit prevents the transaction from being processed. + +To solve this you need first to determine the cause of the issue. You can check the balance of the relevant `assetId` to confirm if the issue is due to insufficient funds or too many UTXOs. + +First to be sure what is the real reason, you can fetch the [balance](../wallets/checking-balances) of the `assetId` in order to make sure that the account have enough funds to cover the amount. After knowing the reason, to solve you can: + +`For Insufficient Balance`: Acquire additional funds in the required asset to meet the amount needed. + +`For UTXO Limit Exceeded`: Combine UTXOs to reduce their number and meet the network's requirements. You can follow [this guide](../cookbook/combining-utxos.md) to learn how to combine UTXOs effectively. ### `TIMEOUT_EXCEEDED` @@ -331,9 +341,3 @@ When the number of transaction inputs exceeds the maximum limit allowed by the b ### `MAX_OUTPUTS_EXCEEDED` When the number of transaction outputs exceeds the maximum limit allowed by the blockchain. - -### `MAX_COINS_REACHED` - -When performing a funding operation, or calling `getResourcesToSpend`, this error can be thrown if the number of coins fetched per asset exceeds the maximum limit allowed by the blockchain. - -This can be avoided by paginating the results of the `getCoins` method to fund your transaction, or by reducing the number of UTXOs for your account. This can be done by performing a transfer that amalgamates your UTXOs, as demonstrated in [this cookbook](../cookbook/combining-utxos.md). From 0f75513995ed3e25ddc2014a917a6ee375a6991d Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 21:41:26 -0300 Subject: [PATCH 66/79] fix changeset --- .changeset/real-schools-poke.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/real-schools-poke.md b/.changeset/real-schools-poke.md index 8628de98732..0a55413f135 100644 --- a/.changeset/real-schools-poke.md +++ b/.changeset/real-schools-poke.md @@ -10,4 +10,4 @@ "@fuel-ts/utils": minor --- -chore: upgrade `fuel-core` to `0.41.0` +chore!: upgrade `fuel-core` to `0.41.0` From 092aa06a04433e748ae4e9f9cc2546ee8ad39687 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Wed, 22 Jan 2025 21:54:52 -0300 Subject: [PATCH 67/79] fix link --- apps/docs/src/guide/errors/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/docs/src/guide/errors/index.md b/apps/docs/src/guide/errors/index.md index 9fc637b3c3e..175e92af256 100644 --- a/apps/docs/src/guide/errors/index.md +++ b/apps/docs/src/guide/errors/index.md @@ -286,7 +286,7 @@ This error can occur during a funding operation or when calling the `getResource To solve this you need first to determine the cause of the issue. You can check the balance of the relevant `assetId` to confirm if the issue is due to insufficient funds or too many UTXOs. -First to be sure what is the real reason, you can fetch the [balance](../wallets/checking-balances) of the `assetId` in order to make sure that the account have enough funds to cover the amount. After knowing the reason, to solve you can: +First to be sure what is the real reason, you can fetch the [balance](../wallets/checking-balances.md) of the `assetId` in order to make sure that the account have enough funds to cover the amount. After knowing the reason, to solve you can: `For Insufficient Balance`: Acquire additional funds in the required asset to meet the amount needed. From cedd2ee22e27260d7afb34dee81cbeaa9022b8b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 23 Jan 2025 08:34:51 -0300 Subject: [PATCH 68/79] Update apps/docs/src/guide/errors/index.md Co-authored-by: Anderson Arboleya --- apps/docs/src/guide/errors/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/docs/src/guide/errors/index.md b/apps/docs/src/guide/errors/index.md index 175e92af256..b0adb5ef309 100644 --- a/apps/docs/src/guide/errors/index.md +++ b/apps/docs/src/guide/errors/index.md @@ -284,7 +284,7 @@ This error can occur during a funding operation or when calling the `getResource `UTXO Limit Exceeded`: Although the account has enough total funds, the funds are spread across too many UTXOs (coins). The blockchain limits how many UTXOs can be used in a single transaction, and exceeding this limit prevents the transaction from being processed. -To solve this you need first to determine the cause of the issue. You can check the balance of the relevant `assetId` to confirm if the issue is due to insufficient funds or too many UTXOs. +To solve this, you first need to determine the cause of the issue. You can check the balance of the relevant `assetId` to confirm whether the problem is due to insufficient funds or too many UTXOs. First to be sure what is the real reason, you can fetch the [balance](../wallets/checking-balances.md) of the `assetId` in order to make sure that the account have enough funds to cover the amount. After knowing the reason, to solve you can: From 24e2cb3b243830c76b4f3daaa0f2425177687cc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Torres?= <30977845+Torres-ssf@users.noreply.github.com> Date: Thu, 23 Jan 2025 08:35:54 -0300 Subject: [PATCH 69/79] Update apps/docs/src/guide/errors/index.md Co-authored-by: Anderson Arboleya --- apps/docs/src/guide/errors/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/docs/src/guide/errors/index.md b/apps/docs/src/guide/errors/index.md index b0adb5ef309..1a1d430f551 100644 --- a/apps/docs/src/guide/errors/index.md +++ b/apps/docs/src/guide/errors/index.md @@ -286,7 +286,7 @@ This error can occur during a funding operation or when calling the `getResource To solve this, you first need to determine the cause of the issue. You can check the balance of the relevant `assetId` to confirm whether the problem is due to insufficient funds or too many UTXOs. -First to be sure what is the real reason, you can fetch the [balance](../wallets/checking-balances.md) of the `assetId` in order to make sure that the account have enough funds to cover the amount. After knowing the reason, to solve you can: +First, to be sure what the real reason is, you can fetch the [balance](../wallets/checking-balances.md) of the `assetId` to ensure that the account has enough funds to cover the amount. After knowing the reason, to solve you can: `For Insufficient Balance`: Acquire additional funds in the required asset to meet the amount needed. From 48d1a1dca9b79a6485855f8e2e61c36818f0db56 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 23 Jan 2025 08:37:06 -0300 Subject: [PATCH 70/79] remove duplicated doc paragraph --- apps/docs/src/guide/errors/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/docs/src/guide/errors/index.md b/apps/docs/src/guide/errors/index.md index 1a1d430f551..2849af2645c 100644 --- a/apps/docs/src/guide/errors/index.md +++ b/apps/docs/src/guide/errors/index.md @@ -284,8 +284,6 @@ This error can occur during a funding operation or when calling the `getResource `UTXO Limit Exceeded`: Although the account has enough total funds, the funds are spread across too many UTXOs (coins). The blockchain limits how many UTXOs can be used in a single transaction, and exceeding this limit prevents the transaction from being processed. -To solve this, you first need to determine the cause of the issue. You can check the balance of the relevant `assetId` to confirm whether the problem is due to insufficient funds or too many UTXOs. - First, to be sure what the real reason is, you can fetch the [balance](../wallets/checking-balances.md) of the `assetId` to ensure that the account has enough funds to cover the amount. After knowing the reason, to solve you can: `For Insufficient Balance`: Acquire additional funds in the required asset to meet the amount needed. From de249efcab489362cd57c54cb9f39239b171c073 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Fri, 24 Jan 2025 13:46:42 -0300 Subject: [PATCH 71/79] fix BN variable --- packages/account/src/providers/provider.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/account/src/providers/provider.test.ts b/packages/account/src/providers/provider.test.ts index adfd8b2b288..61f096ee7d0 100644 --- a/packages/account/src/providers/provider.test.ts +++ b/packages/account/src/providers/provider.test.ts @@ -2387,7 +2387,7 @@ describe('Provider', () => { }); test('should ensure getBalance and getBalances can return u128 amounts ', async () => { - const fundingAmount = 2 ** 63; + const fundingAmount = bn(2).pow(63); const maxU64 = bn('0xFFFFFFFFFFFFFFFF'); using launched = await setupTestProviderAndWallets({ From 5861d8811ab5f3b5d58a1339417cbc99f60c3804 Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Tue, 28 Jan 2025 16:21:46 +0000 Subject: [PATCH 72/79] chore: upgrade `fuel core` to `0.41.4` (#3628) * chore: bump to `0.41.1` * chore: bump `fuel-core` to `0.41.2` * chore: bump `fuel-core` to `0.41.3` * chore: bump `fuel-core` to `0.41.4` * chore: changeset --- .changeset/honest-plums-wink.md | 7 +++++++ apps/create-fuels-counter-guide/fuel-toolchain.toml | 2 +- internal/fuel-core/VERSION | 2 +- packages/create-fuels/test/cli.test.ts | 2 +- packages/versions/src/lib/getBuiltinVersions.ts | 2 +- templates/nextjs/fuel-toolchain.toml | 2 +- templates/vite/fuel-toolchain.toml | 2 +- 7 files changed, 13 insertions(+), 6 deletions(-) create mode 100644 .changeset/honest-plums-wink.md diff --git a/.changeset/honest-plums-wink.md b/.changeset/honest-plums-wink.md new file mode 100644 index 00000000000..d1534fe38ad --- /dev/null +++ b/.changeset/honest-plums-wink.md @@ -0,0 +1,7 @@ +--- +"create-fuels": patch +"@internal/fuel-core": patch +"@fuel-ts/versions": patch +--- + +chore: upgrade `fuel core` to `0.41.4` diff --git a/apps/create-fuels-counter-guide/fuel-toolchain.toml b/apps/create-fuels-counter-guide/fuel-toolchain.toml index 5f5831c5755..d70e2ad0eb2 100644 --- a/apps/create-fuels-counter-guide/fuel-toolchain.toml +++ b/apps/create-fuels-counter-guide/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.40.2" +fuel-core = "0.41.4" diff --git a/internal/fuel-core/VERSION b/internal/fuel-core/VERSION index 72a8a6313bb..2659f4c4638 100644 --- a/internal/fuel-core/VERSION +++ b/internal/fuel-core/VERSION @@ -1 +1 @@ -0.41.0 +0.41.4 diff --git a/packages/create-fuels/test/cli.test.ts b/packages/create-fuels/test/cli.test.ts index 32cae04b9e2..da4bbe0739e 100644 --- a/packages/create-fuels/test/cli.test.ts +++ b/packages/create-fuels/test/cli.test.ts @@ -87,7 +87,7 @@ describe('CLI', { timeout: 15_000 }, () => { expect(toolchain).toEqual({ channel: 'testnet' }); expect(components).toEqual({ forc: '0.66.6', - 'fuel-core': '0.40.2', + 'fuel-core': '0.41.4', }); }); diff --git a/packages/versions/src/lib/getBuiltinVersions.ts b/packages/versions/src/lib/getBuiltinVersions.ts index 95aadb2eebf..566893e622c 100644 --- a/packages/versions/src/lib/getBuiltinVersions.ts +++ b/packages/versions/src/lib/getBuiltinVersions.ts @@ -2,7 +2,7 @@ import type { Versions } from './types'; export function getBuiltinVersions(): Versions { return { - FUEL_CORE: '0.41.0', + FUEL_CORE: '0.41.4', FORC: '0.66.6', FUELS: '0.98.0', }; diff --git a/templates/nextjs/fuel-toolchain.toml b/templates/nextjs/fuel-toolchain.toml index 5f5831c5755..d70e2ad0eb2 100644 --- a/templates/nextjs/fuel-toolchain.toml +++ b/templates/nextjs/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.40.2" +fuel-core = "0.41.4" diff --git a/templates/vite/fuel-toolchain.toml b/templates/vite/fuel-toolchain.toml index 5f5831c5755..d70e2ad0eb2 100644 --- a/templates/vite/fuel-toolchain.toml +++ b/templates/vite/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.40.2" +fuel-core = "0.41.4" From d93a0187f68897814b9683fb943a6682282aee27 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 30 Jan 2025 14:41:45 -0300 Subject: [PATCH 73/79] fix changeset --- .changeset/real-schools-poke.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/real-schools-poke.md b/.changeset/real-schools-poke.md index 0a55413f135..3e347c34e44 100644 --- a/.changeset/real-schools-poke.md +++ b/.changeset/real-schools-poke.md @@ -10,4 +10,4 @@ "@fuel-ts/utils": minor --- -chore!: upgrade `fuel-core` to `0.41.0` +chore!: upgrade `fuel-core` to `0.41.4` From 8f34540ab7770f7fd282f92c89ab1c4217375d8e Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 30 Jan 2025 14:42:08 -0300 Subject: [PATCH 74/79] remove duplicated changeset --- .changeset/honest-plums-wink.md | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .changeset/honest-plums-wink.md diff --git a/.changeset/honest-plums-wink.md b/.changeset/honest-plums-wink.md deleted file mode 100644 index d1534fe38ad..00000000000 --- a/.changeset/honest-plums-wink.md +++ /dev/null @@ -1,7 +0,0 @@ ---- -"create-fuels": patch -"@internal/fuel-core": patch -"@fuel-ts/versions": patch ---- - -chore: upgrade `fuel core` to `0.41.4` From 68cc74ebae2d864cf37bcc1b7cf0c13722aace01 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Tue, 4 Feb 2025 08:01:53 -0300 Subject: [PATCH 75/79] upgrade fuel-core to 0.41.5 --- apps/create-fuels-counter-guide/fuel-toolchain.toml | 2 +- internal/fuel-core/VERSION | 2 +- packages/create-fuels/test/cli.test.ts | 5 +++-- packages/versions/src/lib/getBuiltinVersions.ts | 2 +- templates/nextjs/fuel-toolchain.toml | 2 +- templates/vite/fuel-toolchain.toml | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/apps/create-fuels-counter-guide/fuel-toolchain.toml b/apps/create-fuels-counter-guide/fuel-toolchain.toml index d70e2ad0eb2..3010e5d70d9 100644 --- a/apps/create-fuels-counter-guide/fuel-toolchain.toml +++ b/apps/create-fuels-counter-guide/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.41.4" +fuel-core = "0.41.5" diff --git a/internal/fuel-core/VERSION b/internal/fuel-core/VERSION index 2659f4c4638..fc4d6cab90f 100644 --- a/internal/fuel-core/VERSION +++ b/internal/fuel-core/VERSION @@ -1 +1 @@ -0.41.4 +0.41.5 diff --git a/packages/create-fuels/test/cli.test.ts b/packages/create-fuels/test/cli.test.ts index da4bbe0739e..7f8236af7e7 100644 --- a/packages/create-fuels/test/cli.test.ts +++ b/packages/create-fuels/test/cli.test.ts @@ -1,3 +1,4 @@ +import { versions } from '@fuel-ts/versions'; import toml from '@iarna/toml'; import { mkdirSync, readFileSync } from 'fs'; import { join } from 'path'; @@ -86,8 +87,8 @@ describe('CLI', { timeout: 15_000 }, () => { expect(toolchain).toEqual({ channel: 'testnet' }); expect(components).toEqual({ - forc: '0.66.6', - 'fuel-core': '0.41.4', + forc: versions.FORC, + 'fuel-core': versions.FUEL_CORE, }); }); diff --git a/packages/versions/src/lib/getBuiltinVersions.ts b/packages/versions/src/lib/getBuiltinVersions.ts index 566893e622c..fedf53385c6 100644 --- a/packages/versions/src/lib/getBuiltinVersions.ts +++ b/packages/versions/src/lib/getBuiltinVersions.ts @@ -2,7 +2,7 @@ import type { Versions } from './types'; export function getBuiltinVersions(): Versions { return { - FUEL_CORE: '0.41.4', + FUEL_CORE: '0.41.5', FORC: '0.66.6', FUELS: '0.98.0', }; diff --git a/templates/nextjs/fuel-toolchain.toml b/templates/nextjs/fuel-toolchain.toml index d70e2ad0eb2..3010e5d70d9 100644 --- a/templates/nextjs/fuel-toolchain.toml +++ b/templates/nextjs/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.41.4" +fuel-core = "0.41.5" diff --git a/templates/vite/fuel-toolchain.toml b/templates/vite/fuel-toolchain.toml index d70e2ad0eb2..3010e5d70d9 100644 --- a/templates/vite/fuel-toolchain.toml +++ b/templates/vite/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.41.4" +fuel-core = "0.41.5" From 92bccaf074b3de316dd28abaf4824f058b932e11 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Tue, 4 Feb 2025 08:04:15 -0300 Subject: [PATCH 76/79] fix changeset --- .changeset/real-schools-poke.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/real-schools-poke.md b/.changeset/real-schools-poke.md index 3e347c34e44..484cb1e3a2e 100644 --- a/.changeset/real-schools-poke.md +++ b/.changeset/real-schools-poke.md @@ -10,4 +10,4 @@ "@fuel-ts/utils": minor --- -chore!: upgrade `fuel-core` to `0.41.4` +chore!: upgrade `fuel-core` to `0.41.5` From fa866c751164342d9066b77b19974dcc352dea2a Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Tue, 4 Feb 2025 08:08:09 -0300 Subject: [PATCH 77/79] update fuel core graphql schema --- .../src/providers/fuel-core-schema.graphql | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/packages/account/src/providers/fuel-core-schema.graphql b/packages/account/src/providers/fuel-core-schema.graphql index ba249d7bf47..ec4d7ddd727 100644 --- a/packages/account/src/providers/fuel-core-schema.graphql +++ b/packages/account/src/providers/fuel-core-schema.graphql @@ -626,6 +626,23 @@ type HeavyOperation { scalar HexString +type IndexationFlags { + """ + Is balances indexation enabled + """ + balances: Boolean! + + """ + Is coins to spend indexation enabled + """ + coinsToSpend: Boolean! + + """ + Is asset metadata indexation enabled + """ + assetMetadata: Boolean! +} + union Input = InputCoin | InputContract | InputMessage type InputCoin { @@ -826,6 +843,7 @@ type NodeInfo { maxSize: U64! maxDepth: U64! nodeVersion: String! + indexation: IndexationFlags! txPoolStats: TxPoolStats! peers: [PeerInfo!]! } From 15c7b4250998ecd163c4b3888451df9da683edb1 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 6 Feb 2025 08:38:52 -0300 Subject: [PATCH 78/79] upgrade fuel-core to 0.41.6 --- apps/create-fuels-counter-guide/fuel-toolchain.toml | 2 +- internal/fuel-core/VERSION | 2 +- packages/versions/src/lib/getBuiltinVersions.ts | 2 +- templates/nextjs/fuel-toolchain.toml | 2 +- templates/vite/fuel-toolchain.toml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/create-fuels-counter-guide/fuel-toolchain.toml b/apps/create-fuels-counter-guide/fuel-toolchain.toml index 3010e5d70d9..d0f4ab7c8aa 100644 --- a/apps/create-fuels-counter-guide/fuel-toolchain.toml +++ b/apps/create-fuels-counter-guide/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.41.5" +fuel-core = "0.41.6" diff --git a/internal/fuel-core/VERSION b/internal/fuel-core/VERSION index fc4d6cab90f..63f3da2664e 100644 --- a/internal/fuel-core/VERSION +++ b/internal/fuel-core/VERSION @@ -1 +1 @@ -0.41.5 +0.41.6 diff --git a/packages/versions/src/lib/getBuiltinVersions.ts b/packages/versions/src/lib/getBuiltinVersions.ts index 08d04aad68c..bbefbad0559 100644 --- a/packages/versions/src/lib/getBuiltinVersions.ts +++ b/packages/versions/src/lib/getBuiltinVersions.ts @@ -2,7 +2,7 @@ import type { Versions } from './types'; export function getBuiltinVersions(): Versions { return { - FUEL_CORE: '0.41.5', + FUEL_CORE: '0.41.6', FORC: '0.66.6', FUELS: '0.99.0', }; diff --git a/templates/nextjs/fuel-toolchain.toml b/templates/nextjs/fuel-toolchain.toml index 3010e5d70d9..d0f4ab7c8aa 100644 --- a/templates/nextjs/fuel-toolchain.toml +++ b/templates/nextjs/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.41.5" +fuel-core = "0.41.6" diff --git a/templates/vite/fuel-toolchain.toml b/templates/vite/fuel-toolchain.toml index 3010e5d70d9..d0f4ab7c8aa 100644 --- a/templates/vite/fuel-toolchain.toml +++ b/templates/vite/fuel-toolchain.toml @@ -3,4 +3,4 @@ channel = "testnet" [components] forc = "0.66.6" -fuel-core = "0.41.5" +fuel-core = "0.41.6" From 58655735a98bc0836996be9ed095a13b75e18e82 Mon Sep 17 00:00:00 2001 From: Torres-ssf Date: Thu, 6 Feb 2025 08:39:02 -0300 Subject: [PATCH 79/79] fix changeset --- .changeset/real-schools-poke.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/real-schools-poke.md b/.changeset/real-schools-poke.md index 484cb1e3a2e..8b194ba89ca 100644 --- a/.changeset/real-schools-poke.md +++ b/.changeset/real-schools-poke.md @@ -10,4 +10,4 @@ "@fuel-ts/utils": minor --- -chore!: upgrade `fuel-core` to `0.41.5` +chore!: upgrade `fuel-core` to `0.41.6`