Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
FixedNumber.from = function (value, format) {
if (typeof (value) === "string") {
return FixedNumber.fromString(value, format);
}
if (bytes_1.isBytes(value)) {
return FixedNumber.fromBytes(value, format);
}
try {
return FixedNumber.fromValue(value, 0, format);
}
catch (error) {
// Allow NUMERIC_FAULT to bubble up
if (error.code !== logger_1.Logger.errors.INVALID_ARGUMENT) {
throw error;
}
}
return logger.throwArgumentError("invalid FixedNumber value", "value", value);
};
FixedNumber.isFixedNumber = function (value) {
function ContractFactory(contractInterface, bytecode, signer) {
var _newTarget = this.constructor;
var bytecodeHex = null;
if (typeof (bytecode) === "string") {
bytecodeHex = bytecode;
}
else if (bytes_1.isBytes(bytecode)) {
bytecodeHex = bytes_1.hexlify(bytecode);
}
else if (bytecode && typeof (bytecode.object) === "string") {
// Allow the bytecode object from the Solidity compiler
bytecodeHex = bytecode.object;
}
else {
// Crash in the next verification step
bytecodeHex = "!";
}
// Make sure it is 0x prefixed
if (bytecodeHex.substring(0, 2) !== "0x") {
bytecodeHex = "0x" + bytecodeHex;
}
// Make sure the final result is valid bytecode
if (!bytes_1.isHexString(bytecodeHex) || (bytecodeHex.length % 2)) {
static from(value, format) {
if (typeof (value) === "string") {
return FixedNumber.fromString(value, format);
}
if (isBytes(value)) {
return FixedNumber.fromBytes(value, format);
}
try {
return FixedNumber.fromValue(value, 0, format);
}
catch (error) {
// Allow NUMERIC_FAULT to bubble up
if (error.code !== Logger.errors.INVALID_ARGUMENT) {
throw error;
}
}
return logger.throwArgumentError("invalid FixedNumber value", "value", value);
}
static isFixedNumber(value) {
constructor(contractInterface, bytecode, signer) {
let bytecodeHex = null;
if (typeof (bytecode) === "string") {
bytecodeHex = bytecode;
}
else if (isBytes(bytecode)) {
bytecodeHex = hexlify(bytecode);
}
else if (bytecode && typeof (bytecode.object) === "string") {
// Allow the bytecode object from the Solidity compiler
bytecodeHex = bytecode.object;
}
else {
// Crash in the next verification step
bytecodeHex = "!";
}
// Make sure it is 0x prefixed
if (bytecodeHex.substring(0, 2) !== "0x") {
bytecodeHex = "0x" + bytecodeHex;
}
// Make sure the final result is valid bytecode
if (!isHexString(bytecodeHex) || (bytecodeHex.length % 2)) {
static from(value: any, format?: FixedFormat | string) {
if (typeof(value) === "string") {
return FixedNumber.fromString(value, format);
}
if (isBytes(value)) {
return FixedNumber.fromBytes(value, format);
}
try {
return FixedNumber.fromValue(value, 0, format);
} catch (error) {
// Allow NUMERIC_FAULT to bubble up
if (error.code !== Logger.errors.INVALID_ARGUMENT) {
throw error;
}
}
return logger.throwArgumentError("invalid FixedNumber value", "value", value);
}
}
return logger.throwArgumentError("invalid BigNumber string", "value", value);
}
if (typeof (value) === "number") {
if (value % 1) {
throwFault("underflow", "BigNumber.from", value);
}
if (value >= MAX_SAFE || value <= -MAX_SAFE) {
throwFault("overflow", "BigNumber.from", value);
}
return BigNumber.from(String(value));
}
if (typeof (value) === "bigint") {
return BigNumber.from(value.toString());
}
if (isBytes(value)) {
return BigNumber.from(hexlify(value));
}
if (value._hex && isHexString(value._hex)) {
return BigNumber.from(value._hex);
}
if (value.toHexString) {
value = value.toHexString();
if (typeof (value) === "string") {
return BigNumber.from(value);
}
}
return logger.throwArgumentError("invalid BigNumber value", "value", value);
}
static isBigNumber(value) {
function isBigNumberish(value) {
return (value != null) && (BigNumber.isBigNumber(value) ||
(typeof (value) === "number" && (value % 1) === 0) ||
(typeof (value) === "string" && !!value.match(/^-?[0-9]+$/)) ||
bytes_1.isHexString(value) ||
(typeof (value) === "bigint") ||
bytes_1.isBytes(value));
}
exports.isBigNumberish = isBigNumberish;
}
return logger.throwArgumentError("invalid BigNumber string", "value", value);
}
if (typeof (value) === "number") {
if (value % 1) {
throwFault("underflow", "BigNumber.from", value);
}
if (value >= MAX_SAFE || value <= -MAX_SAFE) {
throwFault("overflow", "BigNumber.from", value);
}
return BigNumber.from(String(value));
}
if (typeof (value) === "bigint") {
return BigNumber.from(value.toString());
}
if (bytes_1.isBytes(value)) {
return BigNumber.from(bytes_1.hexlify(value));
}
if (value._hex && bytes_1.isHexString(value._hex)) {
return BigNumber.from(value._hex);
}
if (value.toHexString) {
value = value.toHexString();
if (typeof (value) === "string") {
return BigNumber.from(value);
}
}
return logger.throwArgumentError("invalid BigNumber value", "value", value);
};
BigNumber.isBigNumber = function (value) {
export function isBigNumberish(value) {
return (value != null) && (BigNumber.isBigNumber(value) ||
(typeof (value) === "number" && (value % 1) === 0) ||
(typeof (value) === "string" && !!value.match(/^-?[0-9]+$/)) ||
isHexString(value) ||
(typeof (value) === "bigint") ||
isBytes(value));
}
export class BigNumber {