Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add byte length override for transfer fee estimates #1763

Merged
merged 1 commit into from
Nov 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions packages/transactions/src/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@
* Estimate the total transaction fee in microstacks for a token transfer
*
* ⚠ Only sensible for token transfer transactions!
* @param opts.transaction - The token transfer transaction to estimate fees for
* @param opts.transaction - The token transfer transaction to estimate fees for (or its estimated length in bytes)
* @param opts.api - Optional API info (`.url` & `.fetch`) used for fetch call
* @return A promise that resolves to number of microstacks per byte
*/
Expand All @@ -138,10 +138,10 @@
network: _network,
client: _client,
}: {
/** The token transfer transaction to estimate fees for */
transaction: StacksTransactionWire;
/** The token transfer transaction to estimate fees for (or its estimated length in bytes) */
transaction: StacksTransactionWire | number;
} & NetworkClientParam): Promise<bigint> {
const network = _network ?? deriveNetworkFromTx(txOpt);
const network = typeof txOpt === 'number' ? 'mainnet' : _network ?? deriveNetworkFromTx(txOpt);
const client = Object.assign({}, clientFromNetwork(networkFrom(network)), _client);

const url = `${client.baseUrl}${TRANSFER_FEE_ESTIMATE_PATH}`;
Expand All @@ -157,7 +157,10 @@
}

const feeRateResult = await response.text();
const txBytes = BigInt(Math.ceil(txOpt.serializeBytes().byteLength));
const txBytes =
typeof txOpt === 'number'
? BigInt(txOpt)

Check warning on line 162 in packages/transactions/src/fetch.ts

View check run for this annotation

Codecov / codecov/patch

packages/transactions/src/fetch.ts#L162

Added line #L162 was not covered by tests
: BigInt(Math.ceil(txOpt.serializeBytes().byteLength));
const feeRate = BigInt(feeRateResult);
return feeRate * txBytes;
}
Expand Down
Loading