Skip to content

Commit

Permalink
Merge branch 'master' into st/chore/[email protected]
Browse files Browse the repository at this point in the history
  • Loading branch information
Torres-ssf authored Jan 23, 2025
2 parents 48d1a1d + e5251e2 commit ede84bc
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 103 deletions.
6 changes: 6 additions & 0 deletions .changeset/clever-mirrors-jam.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@fuel-ts/account": patch
"@fuel-ts/program": patch
---

feat: allow passing `gasPrice` to `getTransactionCost`
2 changes: 1 addition & 1 deletion .github/workflows/linear-pr-integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ jobs:
with:
pull_number: ${{ github.event.pull_request.number }}
linear_api_key: ${{ secrets.LINEAR_TOKEN }}
github_token: ${{ secrets.REPO_TOKEN }}
github_token: ${{ secrets.GITHUB_TOKEN }}
7 changes: 2 additions & 5 deletions .github/workflows/pr-validate-changesets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jobs:
with:
fetch-depth: 0
ref: ${{ github.event.client_payload.ref }}
# workaround to ensure changeset file is pushed with REPO_TOKEN owner's account
# see https://github.com/changesets/action/issues/70
persist-credentials: false

- name: Get PR's changeset file
run: |
Expand Down Expand Up @@ -51,7 +48,7 @@ jobs:
run: |
echo "machine github.com" > $HOME/.netrc
echo "login github-actions[bot]" >> $HOME/.netrc
echo "password ${{ secrets.REPO_TOKEN }}" >> $HOME/.netrc
echo "password ${{ secrets.GITHUB_TOKEN }}" >> $HOME/.netrc
chmod 600 $HOME/.netrc
- name: Commit Changeset
Expand All @@ -63,7 +60,7 @@ jobs:
git commit -m "build: update dependency changeset"
git push origin HEAD:${{ github.event.pull_request.head.ref }}
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

validate-changeset:
name: Validate PR Changeset
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ jobs:
with:
fetch-depth: 0
ref: ${{ github.event.pull_request.head.ref }}
# workaround to ensure force pushes to changeset branch use REPO_TOKEN owner's account
# see https://github.com/changesets/action/issues/70
persist-credentials: false

- name: CI Setup
uses: ./.github/actions/ci-setup
Expand Down Expand Up @@ -76,13 +73,13 @@ jobs:
githubReleaseName: ${{ env.RELEASE_VERSION }}
githubTagName: ${{ env.RELEASE_VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

- name: Prettify changelog
run: pnpm changeset:update-changelog
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: ${{ env.RELEASE_VERSION }}
PUBLISHED: ${{ steps.changesets.outputs.published }}
REF_NAME: ${{ github.ref_name }}
Expand Down Expand Up @@ -129,7 +126,7 @@ jobs:
workflow: update-nightly.yml
ref: master
repo: FuelLabs/docs-hub
token: ${{ secrets.REPO_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}

- name: Create PR to apply latest release to master
if: steps.changesets.outputs.published == 'true' && startsWith(github.ref_name, 'release/') && env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'true'
Expand All @@ -145,7 +142,7 @@ jobs:
gh pr create -B master -H $GITHUB_REF_NAME --title "$PR_TITLE" --body "$PR_BODY"
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_VERSION: ${{ env.RELEASE_VERSION }}
LATEST_VERSION: ${{ env.LATEST_VERSION }}

Expand All @@ -155,7 +152,7 @@ jobs:
if: steps.changesets.outputs.published == 'true' && startsWith(github.ref_name, 'release/') && env.RELEASE_VERSION_HIGHER_THAN_LATEST == 'false'
run: git push origin --delete ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.REPO_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# Upload assets to S3
- uses: unfor19/[email protected]
Expand Down
3 changes: 2 additions & 1 deletion packages/account/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ export class Account extends AbstractAccount implements WithAddress {
*/
async getTransactionCost(
transactionRequestLike: TransactionRequestLike,
{ signatureCallback, quantities = [] }: TransactionCostParams = {}
{ signatureCallback, quantities = [], gasPrice }: TransactionCostParams = {}
): Promise<TransactionCost> {
const txRequestClone = clone(transactionRequestify(transactionRequestLike));
const baseAssetId = await this.provider.getBaseAssetId();
Expand Down Expand Up @@ -603,6 +603,7 @@ export class Account extends AbstractAccount implements WithAddress {

const txCost = await this.provider.getTransactionCost(txRequestClone, {
signatureCallback,
gasPrice,
});

return {
Expand Down
54 changes: 43 additions & 11 deletions packages/account/src/providers/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,30 @@ export type TransactionCostParams = EstimateTransactionParams & {
* @returns A promise that resolves to the signed transaction request.
*/
signatureCallback?: (request: ScriptTransactionRequest) => Promise<ScriptTransactionRequest>;

/**
* The gas price to use for the transaction.
*/
gasPrice?: BN;
};

export type EstimateTxDependenciesParams = {
/**
* The gas price to use for the transaction.
*/
gasPrice?: BN;
};

export type EstimateTxGasAndFeeParams = {
/**
* The transaction request to estimate the gas and fee for.
*/
transactionRequest: TransactionRequest;

/**
* The gas price to use for the transaction.
*/
gasPrice?: BN;
};

/**
Expand Down Expand Up @@ -1019,10 +1043,12 @@ export default class Provider {
* `addVariableOutputs` is called on the transaction.
*
* @param transactionRequest - The transaction request object.
* @param gasPrice - The gas price to use for the transaction, if not provided it will be fetched.
* @returns A promise that resolves to the estimate transaction dependencies.
*/
async estimateTxDependencies(
transactionRequest: TransactionRequest
transactionRequest: TransactionRequest,
{ gasPrice: gasPriceParam }: EstimateTxDependenciesParams = {}
): Promise<EstimateTxDependenciesReturns> {
if (isTransactionTypeCreate(transactionRequest)) {
return {
Expand All @@ -1039,13 +1065,15 @@ export default class Provider {

await this.validateTransaction(transactionRequest);

const gasPrice = gasPriceParam ?? (await this.estimateGasPrice(10));

for (let attempt = 0; attempt < MAX_RETRIES; attempt++) {
const {
dryRun: [{ receipts: rawReceipts, status }],
} = await this.operations.dryRun({
encodedTransactions: [hexlify(transactionRequest.toTransactionBytes())],
utxoValidation: false,
gasPrice: '0',
gasPrice: gasPrice.toString(),
});

receipts = rawReceipts.map(processGqlReceipt);
Expand All @@ -1067,7 +1095,7 @@ export default class Provider {

const { maxFee } = await this.estimateTxGasAndFee({
transactionRequest,
gasPrice: bn(0),
gasPrice,
});

// eslint-disable-next-line no-param-reassign
Expand Down Expand Up @@ -1234,12 +1262,12 @@ export default class Provider {

/**
* Estimates the transaction gas and fee based on the provided transaction request.
* @param transactionRequest - The transaction request object.
* @param params - The parameters for estimating the transaction gas and fee.
* @returns An object containing the estimated minimum gas, minimum fee, maximum gas, and maximum fee.
*/
async estimateTxGasAndFee(params: { transactionRequest: TransactionRequest; gasPrice?: BN }) {
const { transactionRequest } = params;
let { gasPrice } = params;
async estimateTxGasAndFee(params: EstimateTxGasAndFeeParams) {
const { transactionRequest, gasPrice: gasPriceParam } = params;
let gasPrice = gasPriceParam;

await this.autoRefetchConfigs();

Expand Down Expand Up @@ -1355,7 +1383,7 @@ export default class Provider {
*/
async getTransactionCost(
transactionRequestLike: TransactionRequestLike,
{ signatureCallback }: TransactionCostParams = {}
{ signatureCallback, gasPrice: gasPriceParam }: TransactionCostParams = {}
): Promise<Omit<TransactionCost, 'requiredQuantities'>> {
const txRequestClone = clone(transactionRequestify(transactionRequestLike));
const updateMaxFee = txRequestClone.maxFee.eq(0);
Expand All @@ -1377,12 +1405,16 @@ export default class Provider {
await this.estimatePredicates(signedRequest);
txRequestClone.updatePredicateGasUsed(signedRequest.inputs);

const gasPrice = gasPriceParam ?? (await this.estimateGasPrice(10));

/**
* Calculate minGas and maxGas based on the real transaction
*/
// eslint-disable-next-line prefer-const
let { maxFee, maxGas, minFee, minGas, gasPrice, gasLimit } = await this.estimateTxGasAndFee({
let { maxFee, maxGas, minFee, minGas, gasLimit } = await this.estimateTxGasAndFee({
// Fetches and returns a gas price
transactionRequest: signedRequest,
gasPrice,
});

let receipts: TransactionResultReceipt[] = [];
Expand All @@ -1399,7 +1431,7 @@ export default class Provider {
}

({ receipts, missingContractIds, outputVariables, dryRunStatus } =
await this.estimateTxDependencies(txRequestClone));
await this.estimateTxDependencies(txRequestClone, { gasPrice }));

if (dryRunStatus && 'reason' in dryRunStatus) {
throw this.extractDryRunError(txRequestClone, receipts, dryRunStatus);
Expand All @@ -1411,7 +1443,7 @@ export default class Provider {
gasUsed = bn(pristineGasUsed.muln(GAS_USED_MODIFIER)).max(maxGasPerTx.sub(minGas));
txRequestClone.gasLimit = gasUsed;

({ maxFee, maxGas, minFee, minGas, gasPrice } = await this.estimateTxGasAndFee({
({ maxFee, maxGas, minFee, minGas } = await this.estimateTxGasAndFee({
transactionRequest: txRequestClone,
gasPrice,
}));
Expand Down
Loading

0 comments on commit ede84bc

Please sign in to comment.