From b5f3f30291cf1ba549c2449343774303f030fde6 Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Mon, 16 Dec 2024 18:11:24 -0300 Subject: [PATCH 1/8] chore: include beforesign workaround --- packages/account/src/account.ts | 4 ++-- packages/account/src/connectors/fuel-connector.ts | 5 +++-- packages/account/src/connectors/types/data-type.ts | 5 +++++ packages/account/src/providers/provider.ts | 4 +++- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 60484577999..bfd75ad895f 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -646,11 +646,11 @@ export class Account extends AbstractAccount { */ async sendTransaction( transactionRequestLike: TransactionRequestLike, - { estimateTxDependencies = true }: ProviderSendTxParams = {} + { estimateTxDependencies = true, onBeforeSend }: ProviderSendTxParams = {} ): Promise { if (this._connector) { return this.provider.getTransactionResponse( - await this._connector.sendTransaction(this.address.toString(), transactionRequestLike) + await this._connector.sendTransaction(this.address.toString(), transactionRequestLike, { onBeforeSend }) ); } const transactionRequest = transactionRequestify(transactionRequestLike); diff --git a/packages/account/src/connectors/fuel-connector.ts b/packages/account/src/connectors/fuel-connector.ts index 92d4346e932..d26f4582f56 100644 --- a/packages/account/src/connectors/fuel-connector.ts +++ b/packages/account/src/connectors/fuel-connector.ts @@ -14,6 +14,7 @@ import type { FuelEventArg, Version, SelectNetworkArguments, + SendTransactionParams, } from './types'; interface Connector { @@ -42,7 +43,7 @@ interface Connector { signTransaction(address: string, transaction: TransactionRequestLike): Promise; // #endregion fuel-connector-method-signTransaction // #region fuel-connector-method-sendTransaction - sendTransaction(address: string, transaction: TransactionRequestLike): Promise; + sendTransaction(address: string, transaction: TransactionRequestLike, params?: SendTransactionParams): Promise; // #endregion fuel-connector-method-sendTransaction // #region fuel-connector-method-currentAccount currentAccount(): Promise; @@ -196,7 +197,7 @@ export abstract class FuelConnector extends EventEmitter implements Connector { * * @returns The transaction id */ - async sendTransaction(_address: string, _transaction: TransactionRequestLike): Promise { + async sendTransaction(_address: string, _transaction: TransactionRequestLike, params?: SendTransactionParams): Promise { throw new FuelError(FuelError.CODES.NOT_IMPLEMENTED, 'Method not implemented.'); } diff --git a/packages/account/src/connectors/types/data-type.ts b/packages/account/src/connectors/types/data-type.ts index 04a63ad028d..df69cf07d98 100644 --- a/packages/account/src/connectors/types/data-type.ts +++ b/packages/account/src/connectors/types/data-type.ts @@ -1,5 +1,6 @@ import type { JsonAbi } from '@fuel-ts/abi-coder'; import type { RequireAtLeastOne } from 'type-fest'; +import type { TransactionRequest } from '../../providers'; /** * @name Version @@ -42,3 +43,7 @@ export type SelectNetworkArguments = RequireAtLeastOne TransactionRequest; +} \ No newline at end of file diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 5f9ffe88f42..37186294aef 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -363,7 +363,9 @@ export type ProviderCallParams = UTXOValidationParams & EstimateTransactionParam /** * Provider Send transaction params */ -export type ProviderSendTxParams = EstimateTransactionParams; +export type ProviderSendTxParams = EstimateTransactionParams & { + onBeforeSend?: (txRequest: TransactionRequest) => TransactionRequest; +}; /** * URL - Consensus Params mapping. From 2dbae8e6b07c0a7aa11629780f25762d64ddfce3 Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Mon, 16 Dec 2024 18:13:48 -0300 Subject: [PATCH 2/8] chore --- .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 7269d45005b728107c6ddf557e368ad4997d2a2c Mon Sep 17 00:00:00 2001 From: Peter Smith Date: Mon, 16 Dec 2024 21:17:44 +0000 Subject: [PATCH 3/8] chore: changeset --- .changeset/sharp-islands-collect.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/sharp-islands-collect.md diff --git a/.changeset/sharp-islands-collect.md b/.changeset/sharp-islands-collect.md new file mode 100644 index 00000000000..17c594e15b3 --- /dev/null +++ b/.changeset/sharp-islands-collect.md @@ -0,0 +1,5 @@ +--- +"@fuel-ts/account": patch +--- + +feat: added `onBeforeSend` hook to the connector interface From 2a5ff27e7fff0a8bc81280fe60d08bd2f11d3743 Mon Sep 17 00:00:00 2001 From: chad Date: Mon, 16 Dec 2024 16:29:57 -0500 Subject: [PATCH 4/8] lint: minor linting fixes --- packages/account/src/account.ts | 4 +++- packages/account/src/connectors/fuel-connector.ts | 14 +++++++++++--- packages/account/src/connectors/types/data-type.ts | 3 ++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index bfd75ad895f..48458893291 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -650,7 +650,9 @@ export class Account extends AbstractAccount { ): Promise { if (this._connector) { return this.provider.getTransactionResponse( - await this._connector.sendTransaction(this.address.toString(), transactionRequestLike, { onBeforeSend }) + await this._connector.sendTransaction(this.address.toString(), transactionRequestLike, { + onBeforeSend, + }) ); } const transactionRequest = transactionRequestify(transactionRequestLike); diff --git a/packages/account/src/connectors/fuel-connector.ts b/packages/account/src/connectors/fuel-connector.ts index d26f4582f56..9e004f0f0d2 100644 --- a/packages/account/src/connectors/fuel-connector.ts +++ b/packages/account/src/connectors/fuel-connector.ts @@ -43,7 +43,11 @@ interface Connector { signTransaction(address: string, transaction: TransactionRequestLike): Promise; // #endregion fuel-connector-method-signTransaction // #region fuel-connector-method-sendTransaction - sendTransaction(address: string, transaction: TransactionRequestLike, params?: SendTransactionParams): Promise; + sendTransaction( + address: string, + transaction: TransactionRequestLike, + params?: SendTransactionParams + ): Promise; // #endregion fuel-connector-method-sendTransaction // #region fuel-connector-method-currentAccount currentAccount(): Promise; @@ -194,10 +198,14 @@ export abstract class FuelConnector extends EventEmitter implements Connector { * * @param address - The address to sign the transaction * @param transaction - The transaction to send - * + * @param params - Optional parameters to send the transaction * @returns The transaction id */ - async sendTransaction(_address: string, _transaction: TransactionRequestLike, params?: SendTransactionParams): Promise { + async sendTransaction( + _address: string, + _transaction: TransactionRequestLike, + _params?: SendTransactionParams + ): Promise { throw new FuelError(FuelError.CODES.NOT_IMPLEMENTED, 'Method not implemented.'); } diff --git a/packages/account/src/connectors/types/data-type.ts b/packages/account/src/connectors/types/data-type.ts index df69cf07d98..4037538a68b 100644 --- a/packages/account/src/connectors/types/data-type.ts +++ b/packages/account/src/connectors/types/data-type.ts @@ -1,5 +1,6 @@ import type { JsonAbi } from '@fuel-ts/abi-coder'; import type { RequireAtLeastOne } from 'type-fest'; + import type { TransactionRequest } from '../../providers'; /** @@ -46,4 +47,4 @@ export type FuelABI = JsonAbi; export type SendTransactionParams = { onBeforeSend?: (txRequest: TransactionRequest) => TransactionRequest; -} \ No newline at end of file +}; From e7787ecc6254abd98b03811779f1c89b2ffaa1e4 Mon Sep 17 00:00:00 2001 From: LuizAsFight Date: Mon, 16 Dec 2024 19:51:30 -0300 Subject: [PATCH 5/8] chore: accept promise as callback --- packages/account/src/connectors/types/data-type.ts | 4 ++-- packages/account/src/providers/provider.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/account/src/connectors/types/data-type.ts b/packages/account/src/connectors/types/data-type.ts index df69cf07d98..384e607042d 100644 --- a/packages/account/src/connectors/types/data-type.ts +++ b/packages/account/src/connectors/types/data-type.ts @@ -45,5 +45,5 @@ export type SelectNetworkArguments = RequireAtLeastOne TransactionRequest; -} \ No newline at end of file + onBeforeSend?: (txRequest: TransactionRequest) => Promise; +} diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index 37186294aef..af13935795d 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -364,7 +364,7 @@ export type ProviderCallParams = UTXOValidationParams & EstimateTransactionParam * Provider Send transaction params */ export type ProviderSendTxParams = EstimateTransactionParams & { - onBeforeSend?: (txRequest: TransactionRequest) => TransactionRequest; + onBeforeSend?: (txRequest: TransactionRequest) => Promise; }; /** From f550fa003bb53a6212bfcfd5abf26b9dd91ca038 Mon Sep 17 00:00:00 2001 From: Nelito Junior Date: Fri, 20 Dec 2024 15:57:34 -0300 Subject: [PATCH 6/8] feat: skip custom fee --- packages/account/src/account.ts | 7 ++++++- packages/account/src/connectors/types/data-type.ts | 3 ++- packages/account/src/providers/provider.ts | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/account/src/account.ts b/packages/account/src/account.ts index 48458893291..3c22d3cd8f9 100644 --- a/packages/account/src/account.ts +++ b/packages/account/src/account.ts @@ -646,12 +646,17 @@ export class Account extends AbstractAccount { */ async sendTransaction( transactionRequestLike: TransactionRequestLike, - { estimateTxDependencies = true, onBeforeSend }: ProviderSendTxParams = {} + { + estimateTxDependencies = true, + onBeforeSend, + skipCustomFee = false + }: ProviderSendTxParams = {} ): Promise { if (this._connector) { return this.provider.getTransactionResponse( await this._connector.sendTransaction(this.address.toString(), transactionRequestLike, { onBeforeSend, + skipCustomFee, }) ); } diff --git a/packages/account/src/connectors/types/data-type.ts b/packages/account/src/connectors/types/data-type.ts index f214b6c28fd..77c6458b29f 100644 --- a/packages/account/src/connectors/types/data-type.ts +++ b/packages/account/src/connectors/types/data-type.ts @@ -46,5 +46,6 @@ export type SelectNetworkArguments = RequireAtLeastOne Promise; -} +}; diff --git a/packages/account/src/providers/provider.ts b/packages/account/src/providers/provider.ts index af13935795d..70c07e79506 100644 --- a/packages/account/src/providers/provider.ts +++ b/packages/account/src/providers/provider.ts @@ -365,6 +365,7 @@ export type ProviderCallParams = UTXOValidationParams & EstimateTransactionParam */ export type ProviderSendTxParams = EstimateTransactionParams & { onBeforeSend?: (txRequest: TransactionRequest) => Promise; + skipCustomFee?: boolean; }; /** From 760bf3b786bd07042eec9e5b01d4d2efc70b21fe Mon Sep 17 00:00:00 2001 From: Nelito Junior Date: Sat, 21 Dec 2024 00:06:39 -0300 Subject: [PATCH 7/8] feat: sip custom fee on contract call --- packages/program/src/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/program/src/types.ts b/packages/program/src/types.ts index 258f98c277f..a3c080b1891 100644 --- a/packages/program/src/types.ts +++ b/packages/program/src/types.ts @@ -43,6 +43,7 @@ export type TxParams = Partial<{ maxFee?: BigNumberish; witnessLimit?: BigNumberish; variableOutputs: number; + skipCustomFee: boolean; }>; /** From 6f17863331125ae7d6f6ffca8a29556c3eaace37 Mon Sep 17 00:00:00 2001 From: Nelito Junior Date: Sat, 21 Dec 2024 00:10:13 -0300 Subject: [PATCH 8/8] Revert "feat: sip custom fee on contract call" This reverts commit 760bf3b786bd07042eec9e5b01d4d2efc70b21fe. --- packages/program/src/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/program/src/types.ts b/packages/program/src/types.ts index a3c080b1891..258f98c277f 100644 --- a/packages/program/src/types.ts +++ b/packages/program/src/types.ts @@ -43,7 +43,6 @@ export type TxParams = Partial<{ maxFee?: BigNumberish; witnessLimit?: BigNumberish; variableOutputs: number; - skipCustomFee: boolean; }>; /**