From 765e07caf99d28d6bc66f4e5e224f5b265a6bfcb Mon Sep 17 00:00:00 2001 From: Daniel Bate Date: Wed, 6 Dec 2023 14:54:22 -0300 Subject: [PATCH 1/4] Revert "feat: add `Predicate.getTransferTxId` helper (#1467)" This reverts commit 70233c1e579e607bdc2714b9b8039ea0eaac40a9. --- ...nd-and-spend-funds-from-predicates.test.ts | 21 ++----------- .../send-and-spend-funds-from-predicates.md | 6 ---- packages/predicate/package.json | 1 - packages/predicate/src/predicate.ts | 30 +------------------ packages/wallet/src/account.ts | 30 ++++--------------- pnpm-lock.yaml | 7 +++-- 6 files changed, 12 insertions(+), 83 deletions(-) diff --git a/apps/docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts b/apps/docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts index 6fcddf6adde..0f7ce1ae338 100644 --- a/apps/docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts +++ b/apps/docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts @@ -9,10 +9,7 @@ import { BaseAssetId, } from 'fuels'; -import { - DocSnippetProjectsEnum, - getDocsSnippetsForcProject, -} from '../../../test/fixtures/forc-projects'; +import { DocSnippetProjectsEnum, getDocsSnippetsForcProject } from '../../../test/fixtures/forc-projects'; import { getTestWallet } from '../../utils'; describe(__filename, () => { @@ -53,22 +50,11 @@ describe(__filename, () => { predicate.setData(inputAddress); // #endregion send-and-spend-funds-from-predicates-4 + // #region send-and-spend-funds-from-predicates-5 const receiverWallet = WalletUnlocked.generate({ provider, }); - // #region send-and-spend-funds-from-predicates-8 - const txId = await predicate.getTransferTxId( - receiverWallet.address, - amountToPredicate - 150_000, - BaseAssetId, - { - gasPrice, - } - ); - // #endregion send-and-spend-funds-from-predicates-8 - - // #region send-and-spend-funds-from-predicates-5 const tx2 = await predicate.transfer( receiverWallet.address, amountToPredicate - 150_000, @@ -80,9 +66,6 @@ describe(__filename, () => { await tx2.waitForResult(); // #endregion send-and-spend-funds-from-predicates-5 - const txIdFromExecutedTx = tx2.id; - - expect(txId).toEqual(txIdFromExecutedTx); }); it('should fail when trying to spend predicates entire amount', async () => { diff --git a/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md b/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md index 68c8695edd3..337b0d79d8c 100644 --- a/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md +++ b/apps/docs/src/guide/predicates/send-and-spend-funds-from-predicates.md @@ -38,12 +38,6 @@ Note the method transfer has two parameters: the recipient's address and the int Once the predicate resolves with a return value `true` based on its predefined condition, our predicate successfully spends its funds by means of a transfer to a desired wallet. ---- - -You can also use the `getTransferTxId` helper to obtain the transaction ID of the transfer beforehand, without actually executing it. - -<<< @/../../docs-snippets/src/guide/predicates/send-and-spend-funds-from-predicates.test.ts#send-and-spend-funds-from-predicates-8{ts:line-numbers} - ## Spending Entire Predicate Held Amount Trying to forward the entire amount held by the predicate results in an error because no funds are left to cover the transaction fees. Attempting this will result in an error message like: diff --git a/packages/predicate/package.json b/packages/predicate/package.json index 15e7bf94815..a45badd0f87 100644 --- a/packages/predicate/package.json +++ b/packages/predicate/package.json @@ -28,7 +28,6 @@ "@fuel-ts/abi-coder": "workspace:*", "@fuel-ts/address": "workspace:*", "@fuel-ts/interfaces": "workspace:*", - "@fuel-ts/math": "workspace:*", "@fuel-ts/merkle": "workspace:*", "@fuel-ts/providers": "workspace:*", "@fuel-ts/transactions": "workspace:*", diff --git a/packages/predicate/src/predicate.ts b/packages/predicate/src/predicate.ts index 673337bc402..7449097e079 100644 --- a/packages/predicate/src/predicate.ts +++ b/packages/predicate/src/predicate.ts @@ -7,11 +7,8 @@ import { calculateVmTxMemory, } from '@fuel-ts/abi-coder'; import { Address } from '@fuel-ts/address'; -import { BaseAssetId } from '@fuel-ts/address/configs'; import { ErrorCode, FuelError } from '@fuel-ts/errors'; -import { hashTransaction } from '@fuel-ts/hasher'; -import type { AbstractAddress, AbstractPredicate } from '@fuel-ts/interfaces'; -import type { BigNumberish } from '@fuel-ts/math'; +import type { AbstractPredicate } from '@fuel-ts/interfaces'; import type { CallResult, Provider, @@ -20,7 +17,6 @@ import type { } from '@fuel-ts/providers'; import { transactionRequestify } from '@fuel-ts/providers'; import { ByteArrayCoder, InputType } from '@fuel-ts/transactions'; -import type { TxParamsType } from '@fuel-ts/wallet'; import { Account } from '@fuel-ts/wallet'; import type { BytesLike } from 'ethers'; import { getBytesCopy, hexlify } from 'ethers'; @@ -96,30 +92,6 @@ export class Predicate extends Account implements Abs return super.sendTransaction(transactionRequest); } - /** - * Returns the transaction ID for a transfer transaction, without sending it. - * - * @param destination - The address of the destination. - * @param amount - The amount of coins to transfer. - * @param assetId - The asset ID of the coins to transfer. - * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity). - * @returns A promise that resolves to the transaction ID. - */ - async getTransferTxId( - /** Address of the destination */ - destination: AbstractAddress, - /** Amount of coins */ - amount: BigNumberish, - /** Asset ID of coins */ - assetId: BytesLike = BaseAssetId, - /** Tx Params */ - txParams: TxParamsType = {} - ): Promise { - const request = await super.prepareTransferTxRequest(destination, amount, assetId, txParams); - const populatedRequest = this.populateTransactionPredicateData(request); - return hashTransaction(populatedRequest, this.provider.getChainId()); - } - /** * Simulates a transaction with the populated predicate data. * diff --git a/packages/wallet/src/account.ts b/packages/wallet/src/account.ts index 18bbedbc512..12695799a6b 100644 --- a/packages/wallet/src/account.ts +++ b/packages/wallet/src/account.ts @@ -32,7 +32,7 @@ import { formatScriptDataForTransferringToContract, } from './utils'; -export type TxParamsType = Pick; +type TxParamsType = Pick; /** * `Account` provides an abstraction for interacting with accounts or wallets on the network. @@ -239,36 +239,16 @@ export class Account extends AbstractAccount { /** Tx Params */ txParams: TxParamsType = {} ): Promise { - const request = await this.prepareTransferTxRequest(destination, amount, assetId, txParams); - return this.sendTransaction(request); - } - - /** - * A helper that prepares a transaction request for calculating the transaction ID. - * - * @param destination - The address of the destination. - * @param amount - The amount of coins to transfer. - * @param assetId - The asset ID of the coins to transfer. - * @param txParams - The transaction parameters (gasLimit, gasPrice, maturity). - * @returns A promise that resolves to the prepared transaction request. - */ - protected async prepareTransferTxRequest( - /** Address of the destination */ - destination: AbstractAddress, - /** Amount of coins */ - amount: BigNumberish, - /** Asset ID of coins */ - assetId: BytesLike = BaseAssetId, - /** Tx Params */ - txParams: TxParamsType = {} - ): Promise { const { maxGasPerTx } = this.provider.getGasConfig(); const params: TxParamsType = { gasLimit: maxGasPerTx, ...txParams }; const request = new ScriptTransactionRequest(params); request.addCoinOutput(destination, amount, assetId); + const { maxFee, requiredQuantities } = await this.provider.getTransactionCost(request); + await this.fund(request, requiredQuantities, maxFee); - return request; + + return this.sendTransaction(request); } /** diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 088ad532f3f..39b72e6804e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -870,9 +870,6 @@ importers: '@fuel-ts/interfaces': specifier: workspace:* version: link:../interfaces - '@fuel-ts/math': - specifier: workspace:* - version: link:../math '@fuel-ts/merkle': specifier: workspace:* version: link:../merkle @@ -894,6 +891,10 @@ importers: ethers: specifier: ^6.7.1 version: 6.7.1 + devDependencies: + '@fuel-ts/math': + specifier: workspace:* + version: link:../math packages/program: dependencies: From ca337a16d8dbfbbd76aeae1c3b84cd4a78955ff6 Mon Sep 17 00:00:00 2001 From: Daniel Bate Date: Fri, 8 Dec 2023 10:35:21 -0300 Subject: [PATCH 2/4] feat: alter workflow stage name --- .github/workflows/release-unpublish.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-unpublish.yaml b/.github/workflows/release-unpublish.yaml index 6d1ed0ca2cc..d3545d56543 100644 --- a/.github/workflows/release-unpublish.yaml +++ b/.github/workflows/release-unpublish.yaml @@ -14,7 +14,7 @@ concurrency: jobs: clean-npm-versions: - name: Unpublish versions next, preview, master... + name: Unpublish versions next and pr runs-on: buildjet-4vcpu-ubuntu-2204 steps: - uses: actions/checkout@v3 From 098397e98ff021bf3f31a2ac2dacbefdee3a9bf6 Mon Sep 17 00:00:00 2001 From: Daniel Bate Date: Fri, 8 Dec 2023 10:35:38 -0300 Subject: [PATCH 3/4] feat: move unpublish script to js --- scripts/{release-unpublish.ts => release-unpublish.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename scripts/{release-unpublish.ts => release-unpublish.js} (100%) diff --git a/scripts/release-unpublish.ts b/scripts/release-unpublish.js similarity index 100% rename from scripts/release-unpublish.ts rename to scripts/release-unpublish.js From c42b6cc37d4237d634d4a79a59d5afe2b9467ca8 Mon Sep 17 00:00:00 2001 From: Daniel Bate Date: Fri, 8 Dec 2023 10:41:47 -0300 Subject: [PATCH 4/4] feat: rewrite imports --- scripts/release-unpublish.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/scripts/release-unpublish.js b/scripts/release-unpublish.js index 3317646127e..e61e73bd6a9 100644 --- a/scripts/release-unpublish.js +++ b/scripts/release-unpublish.js @@ -1,8 +1,9 @@ -import { versions } from '@fuel-ts/versions'; -import { exec } from 'child_process'; -import { compare } from 'compare-versions'; -import { readFileSync, readdirSync } from 'fs'; -import { join } from 'path'; +/* eslint-disable @typescript-eslint/no-var-requires */ +const { versions } = require('@fuel-ts/versions'); +const exec = require('child_process'); +const { compare } = require('compare-versions'); +const { readFileSync, readdirSync } = require('fs'); +const { join } = require('path'); const DELETE_TAGS = /next|pr/; const { FUELS: CURRENT_VERSION } = versions;