2021-07-13 19:06:36 +02:00
|
|
|
import { BigNumber, utils, BigNumberish } from 'ethers';
|
|
|
|
|
|
|
|
import { numbers } from '@/constants';
|
|
|
|
|
2021-07-21 12:37:08 +02:00
|
|
|
export function isAddress(value: string): boolean {
|
|
|
|
return utils.isAddress(value);
|
2021-07-13 19:06:36 +02:00
|
|
|
}
|
|
|
|
|
2021-07-21 12:37:08 +02:00
|
|
|
export function toChecksumAddress(value: string): string {
|
|
|
|
return utils.getAddress(value);
|
2021-07-13 19:06:36 +02:00
|
|
|
}
|
|
|
|
|
2021-09-27 11:10:19 +02:00
|
|
|
export function toWei(value: string, uintName = 'ether') {
|
2021-12-01 15:49:33 +01:00
|
|
|
return utils.parseUnits(String(value), uintName);
|
2021-07-13 19:06:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function hexToNumber(hex: string) {
|
|
|
|
return BigNumber.from(hex).toNumber();
|
|
|
|
}
|
|
|
|
|
|
|
|
export function numberToHex(value: number) {
|
|
|
|
return utils.hexlify(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function fromWei(balance: BigNumberish) {
|
|
|
|
return utils.formatUnits(balance, numbers.ETH_DECIMALS);
|
|
|
|
}
|
2021-09-27 11:10:19 +02:00
|
|
|
|
2021-12-01 15:49:33 +01:00
|
|
|
export function getToIntegerMultiplier(): BigNumber {
|
|
|
|
return toWei('1', 'ether');
|
2021-09-27 11:10:19 +02:00
|
|
|
}
|