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

docs: Improve code documentation with detailed JSDoc comments #1183

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
8 changes: 5 additions & 3 deletions src/hooks/useBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ const getBalanceBySymbol = async (params: {
};

/**
* @param token - The token to fetch the balance of.
* @param chainId - The chain Id of the chain to execute the query on. If not specified, defaults to the chainId the user is connected to or undefined.
* Retrieves the balance of a specific token for a given account and chain.
*
* @param tokenSymbol - The symbol of the token to retrieve the balance for. If not provided, it will return the Ether (ETH) balance.
* @param chainId - The ID of the chain to execute the query on. If not specified, defaults to the chainId the user is connected to or undefined.
* @param account - The account to query the balance of.
* @remarks Passing the zero address as token will return the ETH balance. Passing no account will return the balance of the connected account.
* @returns The balance of the account and the UseQueryResult object
* @returns An object containing the balance of the account (as a `BigNumber`) and the `UseQueryResult` object.
*/
export function useBalanceBySymbol(
tokenSymbol?: string,
Expand Down
1 change: 1 addition & 0 deletions src/hooks/useBridgeFees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { AxiosError } from "axios";
* @param toChainId The chain Id of the receiving chain, its timestamp will be used to calculate the fees.
* @param inputTokenSymbol - The input token symbol to check bridge fees for.
* @param outputTokenSymbol - The output token symbol to check bridge fees for.
* @param recipientAddress - The recipient address for the bridged tokens.
* @returns The bridge fees for the given amount and token symbol and the UseQueryResult object.
*/
export function useBridgeFees(
Expand Down
35 changes: 26 additions & 9 deletions src/utils/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,26 @@ export type GetBridgeFeesResult = BridgeFees & {
};

/**
* Retrieves the bridge fees for a given token bridging operation.
*
* @param amount - amount to bridge
* @param inputTokenSymbol - symbol of the input token to bridge
* @param outputTokenSymbol - symbol of the output token to bridge
* @param fromChain The origin chain of this bridge action
* @param toChain The destination chain of this bridge action
* @returns Returns the `relayerFee` and `lpFee` fees for bridging the given amount of tokens, along with an `isAmountTooLow` flag indicating whether the amount is too low to bridge and an `isLiquidityInsufficient` flag indicating whether the liquidity is insufficient.
* @param amount - The amount of tokens to be bridged.
* @param inputTokenSymbol - The symbol of the input token to be bridged.
* @param outputTokenSymbol - The symbol of the output token to be received after bridging.
* @param fromChainId - The ID of the origin chain for the bridge operation.
* @param toChainId - The ID of the destination chain for the bridge operation.
* @param recipientAddress - The address of the recipient who will receive the bridged tokens.
* @returns An object containing the following properties:
* - `totalRelayFee`: The total relay fee for the bridge operation.
* - `relayerGasFee`: The gas fee paid to the relayer.
* - `relayerCapitalFee`: The capital fee paid to the relayer.
* - `lpFee`: The fee paid to the liquidity provider.
* - `isAmountTooLow`: A boolean indicating whether the provided amount is too low to bridge.
* - `quoteTimestamp`: The timestamp of the bridge fee quote.
* - `quoteTimestampInMs`: The quote timestamp in milliseconds.
* - `quoteBlock`: The block number of the bridge fee quote.
* - `quoteLatency`: The latency of the bridge fee quote request in milliseconds.
* - `limits`: An object containing the minimum and maximum bridge limits.
* - `estimatedFillTimeSec`: The estimated time in seconds for the bridge operation to be filled.
*/
export async function getBridgeFees({
amount,
Expand Down Expand Up @@ -154,10 +167,14 @@ type NetworkMismatchHandler = (
) => void;

/**
* Makes a deposit on Across using the `SpokePoolVerifiers` contract's `deposit` function if possible.
* @param signer A valid signer, must be connected to a provider.
* Makes a deposit on the Across protocol using the `SpokePoolVerifiers` contract's `deposit` function, if possible.
*
* @param signer - A valid Ethereum signer, which must be connected to a provider.
* @param spokePool - The `SpokePool` contract instance used for the deposit operation.
* @param spokePoolVerifier - The `SpokePoolVerifier` contract instance used for the deposit operation.
* @param onNetworkMismatch - An optional callback function that will be called if the signer's network does not match the from/to chain IDs.
* @param depositArgs - An object containing the {@link AcrossDepositArgs arguments} to pass to the deposit function of the bridge contract.
* @returns The transaction response obtained after sending the transaction.
* @returns The transaction response obtained after sending the deposit transaction.
*/
export async function sendSpokePoolVerifierDepositTx(
signer: ethers.Signer,
Expand Down
4 changes: 3 additions & 1 deletion src/utils/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,9 @@ export function formatWeiPct(wei?: ethers.BigNumberish, precision: number = 3) {

/**
* Formats a number into a human readable format
* @param num The number to format
*
* @param num - The number to be formatted.
* @param decimals - The number of decimal places to display. Default is 0.
* @returns A human readable format. I.e. 1000 -> 1K, 1001 -> 1K+
*/
export function humanReadableNumber(num: number, decimals = 0): string {
Expand Down
6 changes: 5 additions & 1 deletion src/utils/notify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ export const notificationEmitter = async (

/**
* Calls and waits on the Notify API to resolve the status of a TX if the chain is supported by Onboard
*
* @param requiredChainId The ID of the chain that the transaction was executed on.
* @param tx The transaction to wait for
* @param notify The BNC Notify API that is used to handle the UI visualization
* @param timingBuffer An optional waiting time in milliseconds to wait to resolve this promise on a successful tx confirmation in Notify (Default: 5000ms)
* @param ignoreErrors An optional parameter to ignore tx failure and return successful
**/
*
* @throws {Error} If the transaction fails and `ignoreErrors` is set to `false`.
*/
export const waitOnTransaction = async (
requiredChainId: number,
tx: ContractTransaction,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/staking-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export type PoolQueryData = {
* Calls on-chain data & the Vercel API to resolve information about the AcceleratingDistributor Contract
* @param tokenAddress The address of the ERC-20 token on the current chain
* @param account A user address to query against the on-chain data
* @param acxPriceInUSD The current price of the ACX token in US dollars
* @returns The staking pool information, or `undefined` if the required data is not available.
*/
export async function fetchStakingPool(
tokenAddress?: string,
Expand Down
3 changes: 2 additions & 1 deletion src/utils/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { parseUnits } from "./format";

/**
* This function takes a raw transaction and a signer and returns the result of signing the transaction.
* @param tx The raw transaction to sign.
* @param rawTx The raw transaction to sign.
* @param signer A signer used to sign the transaction
* @returns The raw transaction signed by the given `signer`.
*/
Expand Down Expand Up @@ -55,6 +55,7 @@ export async function getPaddedGasEstimation(
* Pads the gas estimation by a fixed amount dictated in the `REACT_SEND_TXN_GAS_ESTIMATION_MULTIPLIER` env var
* @param contract The contract that this transaction will originate from
* @param method The specific call method
* @param chainId The chain ID to use for the gas estimation.
* @returns A completed or failed transaction
*/
export function sendWithPaddedGas(
Expand Down
2 changes: 1 addition & 1 deletion src/utils/weiMath.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function toWeiSafe(
numberToConvertToWei: string,
desiredPrecision = DEFAULT_PRECISION
) {
// Try converting just the raw string first to avoid unneccessary stripping of precision.
// Try converting just the raw string first to avoid unnecessary stripping of precision.
try {
return toWei(numberToConvertToWei, desiredPrecision);
} catch (err) {
Expand Down