mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-01-13 08:37:53 -05:00
19 lines
546 B
TypeScript
19 lines
546 B
TypeScript
import { BigNumberish, ethers } from 'ethers';
|
|
|
|
export const isPow2 = (int: number): boolean =>
|
|
int > 0 && (int & (int - 1)) === 0;
|
|
|
|
export const weiToEth = (amount?: BigNumberish) => {
|
|
if (amount === undefined) {
|
|
throw new Error('`amount` is `undefined` in `weiToEth`.');
|
|
}
|
|
return Number(ethers.formatEther(amount || 0));
|
|
};
|
|
|
|
export const ethToWei = (amount?: BigNumberish) => {
|
|
if (amount === undefined) {
|
|
throw new Error('`amount` is `undefined` in `ethToWei`.');
|
|
}
|
|
return ethers.parseEther((amount || 0).toString());
|
|
};
|