-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: include new markdown on bridged transfers (#884)
* docs: add documentation to fn * chore: cleaned up return type * chore: defined function instead of variable * feat: fn to resolve decimals from a token symbol * feat: include new markdown * improve: set specific chain id Co-authored-by: Paul <108695806+pxrl@users.noreply.github.com> --------- Co-authored-by: Paul <108695806+pxrl@users.noreply.github.com>
- Loading branch information
1 parent
6f95f59
commit f83e9ee
Showing
3 changed files
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,27 @@ | ||
import { constants, utils } from "@across-protocol/sdk-v2"; | ||
import { CONTRACT_ADDRESSES } from "../common"; | ||
import { BigNumberish, utils as ethersUtils } from "ethers"; | ||
const { TOKEN_SYMBOLS_MAP, CHAIN_IDs, ZERO_ADDRESS } = constants; | ||
|
||
export const { fetchTokenInfo } = utils; | ||
|
||
export const getL2TokenAddresses = (l1TokenAddress: string): { [chainId: number]: string } => { | ||
export function getL2TokenAddresses(l1TokenAddress: string): { [chainId: number]: string } { | ||
return Object.values(TOKEN_SYMBOLS_MAP).find((details) => { | ||
return details.addresses[CHAIN_IDs.MAINNET] === l1TokenAddress; | ||
})?.addresses; | ||
}; | ||
} | ||
|
||
export const getEthAddressForChain = (chainId: number): string => { | ||
export function getEthAddressForChain(chainId: number): string { | ||
return CONTRACT_ADDRESSES[chainId]?.eth?.address ?? ZERO_ADDRESS; | ||
}; | ||
} | ||
|
||
/** | ||
* Format the given amount of tokens to the correct number of decimals for the given token symbol. | ||
* @param symbol The token symbol to format the amount for. | ||
* @param amount The amount to format. | ||
* @returns The formatted amount as a decimal-inclusive string. | ||
*/ | ||
export function formatUnitsForToken(symbol: string, amount: BigNumberish): string { | ||
const decimals = (TOKEN_SYMBOLS_MAP[symbol]?.decimals as number) ?? 18; | ||
return ethersUtils.formatUnits(amount, decimals); | ||
} |