@0x/utils

  • Version 7.0.0
  • Published
  • 536 kB
  • 14 dependencies
  • Apache-2.0 license

Install

npm i @0x/utils
yarn add @0x/utils
pnpm add @0x/utils

Overview

0x TS utils

Index

Variables

variable AbiEncoderConstants

const AbiEncoderConstants: {
EVM_WORD_WIDTH_IN_BYTES: number;
EVM_WORD_WIDTH_IN_BITS: number;
HEX_BASE: number;
DEC_BASE: number;
BIN_BASE: number;
HEX_SELECTOR_LENGTH_IN_CHARS: number;
HEX_SELECTOR_LENGTH_IN_BYTES: number;
HEX_SELECTOR_BYTE_OFFSET_IN_CALLDATA: number;
DEFAULT_DECODING_RULES: DecodingRules;
DEFAULT_ENCODING_RULES: EncodingRules;
EMPTY_EVM_WORD_STRING: string;
EMPTY_EVM_WORD_BUFFER: Buffer;
NUMBER_OF_BYTES_IN_UINT8: number;
NUMBER_OF_BYTES_IN_INT8: number;
};

    variable abiUtils

    const abiUtils: {
    parseEthersParams: typeof parseEthersParams;
    isAbiDataEqual: typeof isAbiDataEqual;
    splitTupleTypes: typeof splitTupleTypes;
    parseFunctionParam(param: DataItem): string;
    getFunctionSignature(methodAbi: MethodAbi): string;
    renameOverloadedMethods(inputContractAbi: ContractAbi): ContractAbi;
    };

      variable addressUtils

      const addressUtils: {
      isChecksumAddress(address: string): boolean;
      isAddress(address: string): boolean;
      padZeros(address: string): string;
      generatePseudoRandomAddress(): string;
      };

        variable classUtils

        const classUtils: { bindAll(self: any, exclude?: string[], thisArg?: any): void };

          variable errorUtils

          const errorUtils: { spawnSwitchErr(name: string, value: any): Error };

            variable hexUtils

            const hexUtils: {
            concat: typeof concat;
            random: typeof random;
            leftPad: typeof leftPad;
            rightPad: typeof rightPad;
            invert: typeof invert;
            slice: typeof slice;
            hash: typeof hash;
            size: typeof size;
            toHex: typeof toHex;
            isHex: typeof isHex;
            };

              variable intervalUtils

              const intervalUtils: {
              setAsyncExcludingInterval(
              fn: () => Promise<void>,
              intervalMs: number,
              onError: (err: Error) => void
              ): NodeJS.Timer;
              clearAsyncExcludingInterval(intervalId: NodeJS.Timer): void;
              setInterval(
              fn: () => void,
              intervalMs: number,
              onError: (err: Error) => void
              ): NodeJS.Timer;
              clearInterval(intervalId: NodeJS.Timer): void;
              };

                variable logUtils

                const logUtils: {
                log(...args: any[]): void;
                header(text: string, padStr?: string): void;
                warn(...args: any[]): void;
                table(columnarData: { [rowName: string]: any }): void;
                logWithTime(arg: string): void;
                };

                  variable NULL_ADDRESS

                  const NULL_ADDRESS: string;

                    variable NULL_BYTES

                    const NULL_BYTES: string;

                      variable providerUtils

                      const providerUtils: {
                      startProviderEngine(providerEngine: any): void;
                      standardizeOrThrow(supportedProvider: SupportedProvider): ZeroExProvider;
                      getChainIdAsync(supportedProvider: SupportedProvider): Promise<number>;
                      };

                        variable signTypedDataUtils

                        const signTypedDataUtils: {
                        generateTypedDataHash(typedData: EIP712TypedData): Buffer;
                        generateTypedDataHashWithoutDomain(typedData: EIP712TypedData): Buffer;
                        generateDomainHash(domain: EIP712Object): Buffer;
                        _findDependencies(
                        primaryType: string,
                        types: EIP712Types,
                        found?: string[]
                        ): string[];
                        _encodeType(primaryType: string, types: EIP712Types): string;
                        _encodeData(primaryType: string, data: EIP712Object, types: EIP712Types): string;
                        _normalizeValue(type: string, value: any): EIP712ObjectValue;
                        _typeHash(primaryType: string, types: EIP712Types): Buffer;
                        _structHash(primaryType: string, data: EIP712Object, types: EIP712Types): Buffer;
                        };

                          variable ZeroExRevertErrors

                          const ZeroExRevertErrors: {
                          Common: any;
                          Proxy: any;
                          SimpleFunctionRegistry: any;
                          Ownable: any;
                          Spender: any;
                          TransformERC20: any;
                          Wallet: any;
                          MetaTransactions: any;
                          SignatureValidator: any;
                          LiquidityProvider: any;
                          };

                            Functions

                            function coerceThrownErrorAsRevertError

                            coerceThrownErrorAsRevertError: (error: Error) => RevertError;
                            • Coerce a thrown error into a RevertError. Always succeeds.

                              Parameter error

                              Any thrown error. A RevertError object.

                            function decodeBytesAsRevertError

                            decodeBytesAsRevertError: (
                            bytes: string | Buffer,
                            coerce?: boolean
                            ) => RevertError;
                            • Decode an ABI encoded revert error. Throws if the data cannot be decoded as a known RevertError type.

                              Parameter bytes

                              The ABI encoded revert error. Either a hex string or a Buffer.

                              Parameter coerce

                              Coerce unknown selectors into a RawRevertError type. A RevertError object.

                            function decodeThrownErrorAsRevertError

                            decodeThrownErrorAsRevertError: (error: Error, coerce?: boolean) => RevertError;
                            • Decode a thrown error. Throws if the data cannot be decoded as a known RevertError type.

                              Parameter error

                              Any thrown error.

                              Parameter coerce

                              Coerce unknown selectors into a RawRevertError type. A RevertError object.

                            function deleteNestedProperty

                            deleteNestedProperty: (obj: any, propPath: string) => void;

                              function fetchAsync

                              fetchAsync: (
                              endpoint: string,
                              options?: RequestInit,
                              timeoutMs?: number
                              ) => Promise<Response>;

                                function fromTokenUnitAmount

                                fromTokenUnitAmount: (units: Numberish, decimals?: number) => BigNumber;
                                • Convert a token unit amount to weis. E.g., 10.1 ETH -> 10100000000000000000.

                                function generatePseudoRandom256BitNumber

                                generatePseudoRandom256BitNumber: () => BigNumber;
                                • Generates a pseudo-random 256-bit number. A pseudo-random 256-bit number.

                                function registerRevertErrorType

                                registerRevertErrorType: (revertClass: RevertErrorType, force?: boolean) => void;
                                • Register a RevertError type so that it can be decoded by decodeRevertError.

                                  Parameter revertClass

                                  A class that inherits from RevertError.

                                  Parameter force

                                  Allow overwriting registered types.

                                function toTokenUnitAmount

                                toTokenUnitAmount: (weis: Numberish, decimals?: number) => BigNumber;
                                • Convert a wei amount to token units. E.g., 10100000000000000000 -> 10.1 ETH.

                                Classes

                                class AbiDecoder

                                class AbiDecoder {}
                                • AbiDecoder allows you to decode event logs given a set of supplied contract ABI's. It takes the contract's event signature from the ABI and attempts to decode the logs using it.

                                constructor

                                constructor(abiArrays: AbiDefinition[][]);
                                • Instantiate an AbiDecoder

                                  Parameter abiArrays

                                  An array of contract ABI's AbiDecoder instance

                                method addABI

                                addABI: (abiArray: AbiDefinition[], contractName?: string) => void;
                                • Adds a set of ABI definitions, after which calldata and logs targeting these ABI's can be decoded. Additional properties can be included to disambiguate similar ABI's. For example, if two functions have the same signature but different parameter names, then their ABI definitions can be disambiguated by specifying a contract name.

                                  Parameter abiDefinitions

                                  ABI definitions for a given contract.

                                  Parameter contractName

                                  Name of contract that encapsulates the ABI definitions (optional). This can be used when decoding calldata to disambiguate methods with the same signature but different parameter names.

                                method decodeCalldataOrThrow

                                decodeCalldataOrThrow: (
                                calldata: string,
                                contractName?: string
                                ) => DecodedCalldata;
                                • Decodes calldata for a known ABI.

                                  Parameter calldata

                                  hex-encoded calldata.

                                  Parameter contractName

                                  used to disambiguate similar ABI's (optional). Decoded calldata. Includes: function name and signature, along with the decoded arguments.

                                method tryToDecodeLogOrNoop

                                tryToDecodeLogOrNoop: <ArgsType extends DecodedLogArgs>(
                                log: LogEntry
                                ) => LogWithDecodedArgs<ArgsType> | RawLog;
                                • Attempt to decode a log given the ABI's the AbiDecoder knows about.

                                  Parameter log

                                  The log to attempt to decode The decoded log if the requisite ABI was available. Otherwise the log unaltered.

                                class AnyRevertError

                                class AnyRevertError extends RevertError {}
                                • Special RevertError type that matches with any other RevertError instance.

                                constructor

                                constructor();

                                  class RawRevertError

                                  class RawRevertError extends RevertError {}
                                  • Special RevertError type that is not decoded.

                                  constructor

                                  constructor(encoded: any);

                                    class RevertError

                                    abstract class RevertError extends Error {}
                                    • Base type for revert errors.

                                    constructor

                                    protected constructor(
                                    name: string,
                                    declaration?: string,
                                    values?: ObjectMap<any>,
                                    raw?: string
                                    );
                                    • Create a RevertError instance with optional parameter values. Parameters that are left undefined will not be tested in equality checks.

                                      Parameter declaration

                                      Function-style declaration of the revert (e.g., Error(string message))

                                      Parameter values

                                      Optional mapping of parameters to values.

                                      Parameter raw

                                      Optional encoded form of the revert error. If supplied, this instance will be treated as a RawRevertError, meaning it can only match other RawRevertError types with the same encoded payload.

                                    property [Symbol.toStringTag]

                                    readonly [Symbol.toStringTag]: string;

                                      property abi

                                      readonly abi?: RevertErrorAbi;

                                        property arguments

                                        readonly arguments: DataItem[];
                                        • Get the ABI arguments for this revert.

                                        property name

                                        readonly name: string;
                                        • Get the ABI name for this revert.

                                        property selector

                                        readonly selector: string;
                                        • Get the hex selector for this revert (without leading '0x').

                                        property signature

                                        readonly signature: string;
                                        • Get the signature for this revert: e.g., 'Error(string)'.

                                        property typeName

                                        readonly typeName: string;
                                        • Get the class name of this type.

                                        property values

                                        readonly values: ObjectMap<any>;

                                          method decode

                                          static decode: (
                                          bytes: string | Buffer | RevertError,
                                          coerce?: boolean
                                          ) => RevertError;
                                          • Decode an ABI encoded revert error. Throws if the data cannot be decoded as a known RevertError type.

                                            Parameter bytes

                                            The ABI encoded revert error. Either a hex string or a Buffer.

                                            Parameter coerce

                                            Whether to coerce unknown selectors into a RawRevertError type. A RevertError object.

                                          method encode

                                          encode: () => string;

                                            method equals

                                            equals: (other: RevertError | Buffer | string) => boolean;
                                            • Compares this instance with another. Fails if instances are not of the same type. Only fields/values defined in both instances are compared.

                                              Parameter other

                                              Either another RevertError instance, hex-encoded bytes, or a Buffer of the ABI encoded revert. True if both instances match.

                                            method registerType

                                            static registerType: (revertClass: RevertErrorType, force?: boolean) => void;
                                            • Register a RevertError type so that it can be decoded by RevertError.decode.

                                              Parameter revertClass

                                              A class that inherits from RevertError.

                                              Parameter force

                                              Allow overwriting existing registrations.

                                            method toString

                                            toString: () => string;

                                              class StringRevertError

                                              class StringRevertError extends RevertError {}
                                              • RevertError type for standard string reverts.

                                              constructor

                                              constructor(message?: string);

                                                Interfaces

                                                interface DecodedCalldata

                                                interface DecodedCalldata {}

                                                  property functionArguments

                                                  functionArguments: any;

                                                    property functionName

                                                    functionName: string;

                                                      property functionSignature

                                                      functionSignature: string;

                                                        interface DecodingRules

                                                        interface DecodingRules {}

                                                          property isStrictMode

                                                          isStrictMode: boolean;

                                                            property shouldConvertStructsToObjects

                                                            shouldConvertStructsToObjects: boolean;

                                                              interface EncodingRules

                                                              interface EncodingRules {}

                                                                property shouldAnnotate

                                                                shouldAnnotate?: boolean;

                                                                  property shouldOptimize

                                                                  shouldOptimize?: boolean;

                                                                    interface FunctionInfo

                                                                    interface FunctionInfo {}

                                                                      property abiEncoder

                                                                      abiEncoder?: AbiEncoder.Method;

                                                                        property chainId

                                                                        chainId?: number;

                                                                          property contractAddress

                                                                          contractAddress?: string;

                                                                            property contractName

                                                                            contractName?: string;

                                                                              property functionSignature

                                                                              functionSignature: string;

                                                                                interface SelectorToFunctionInfo

                                                                                interface SelectorToFunctionInfo {}

                                                                                  index signature

                                                                                  [index: string]: FunctionInfo[];

                                                                                    Type Aliases

                                                                                    type Numberish

                                                                                    type Numberish = BigNumber | string | number;

                                                                                      Package Files (20)

                                                                                      Dependencies (14)

                                                                                      Dev Dependencies (13)

                                                                                      Peer Dependencies (0)

                                                                                      No peer dependencies.

                                                                                      Badge

                                                                                      To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                      You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/@0x/utils.

                                                                                      • Markdown
                                                                                        [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/@0x/utils)
                                                                                      • HTML
                                                                                        <a href="https://www.jsdocs.io/package/@0x/utils"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>