How to use the @0x/utils.BigNumber function in @0x/utils

To help you get started, we’ve selected a few @0x/utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / website / ts / pages / governance / vote_index.tsx View on Github external
}

            const responseData = await response.json();
            let { no, yes } = responseData;
            yes = new BigNumber(yes);
            no = new BigNumber(no);
            const tally = {
                ...responseData,
                yes: new BigNumber(yes),
                no: new BigNumber(no),
            };
            return tally;
        } catch (e) {
            // Empty block
            return {
                yes: new BigNumber(0),
                no: new BigNumber(0),
            };
        }
    }
github 0xProject / 0x-monorepo / contracts / exchange-libs / src / reference_functions.ts View on Github external
export function isRoundingErrorFloor(numerator: BigNumber, denominator: BigNumber, target: BigNumber): boolean {
    if (denominator.eq(0)) {
        throw new LibMathRevertErrors.DivisionByZeroError();
    }
    if (numerator.eq(0) || target.eq(0)) {
        return false;
    }
    const remainder = numerator.times(target).mod(denominator);
    // Need to do this separately because solidity evaluates RHS of the comparison expression first.
    const rhs = safeMul(numerator, target);
    const lhs = safeMul(remainder, new BigNumber(1000));
    return lhs.gte(rhs);
}
github 0xProject / 0x-monorepo / packages / asset-buyer / src / constants.ts View on Github external
};

const DEFAULT_FORWARDER_SWAP_QUOTE_EXECUTE_OPTS: ForwarderSwapQuoteExecutionOpts = DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS;

const DEFAULT_SWAP_QUOTE_REQUEST_OPTS: SwapQuoteRequestOpts = {
    shouldForceOrderRefresh: false,
    slippagePercentage: 0.2, // 20% slippage protection,
};

const EMPTY_ORDERS_AND_FILLABLE_AMOUNTS: OrdersAndFillableAmounts = {
    orders: [] as SignedOrder[],
    remainingFillableMakerAssetAmounts: [] as BigNumber[],
};

export const constants = {
    ZERO_AMOUNT: new BigNumber(0),
    NULL_ADDRESS,
    MAINNET_NETWORK_ID,
    ETHER_TOKEN_DECIMALS: 18,
    ONE_AMOUNT: new BigNumber(1),
    ONE_SECOND_MS,
    DEFAULT_SWAP_QUOTER_OPTS,
    DEFAULT_FORWARDER_SWAP_QUOTE_GET_OPTS,
    DEFAULT_FORWARDER_SWAP_QUOTE_EXECUTE_OPTS,
    DEFAULT_SWAP_QUOTE_REQUEST_OPTS,
    EMPTY_ORDERS_AND_FILLABLE_AMOUNTS,
};
github 0xProject / 0x-monorepo / packages / migrations / src / utils / constants.ts View on Github external
import { BigNumber } from '@0x/utils';

// tslint:disable custom-no-magic-numbers
export const constants = {
    NULL_ADDRESS: '0x0000000000000000000000000000000000000000',
    MAINNET_CHAIN_ID: 1,
    ZERO_AMOUNT: new BigNumber(0),
    TWO_WEEKS_IN_SEC: new BigNumber(14)
        .times(24)
        .times(60)
        .times(60),
    TEN_DAYS_IN_SEC: new BigNumber(10)
        .times(24)
        .times(60)
        .times(60),
    TWENTY_DAYS_IN_SEC: new BigNumber(20)
        .times(24)
        .times(60)
        .times(60),
};
github veilco / veil-js / src / Veil.ts View on Github external
export function fromWei(amount: BigNumber | string) {
  return new BigNumber(amount.toString()).div(TEN_18);
}
github veilco / veil-js / src / Veil.ts View on Github external
export function fromShares(
  amount: BigNumber | string,
  numTicks: string | number
) {
  return new BigNumber(amount.toString())
    .times(new BigNumber(numTicks))
    .div(TEN_18);
}
github 0xProject / 0x-monorepo / contracts / asset-proxy / src / erc20_wrapper.ts View on Github external
_.forEach(balances, (balance, balanceIndex) => {
            const tokenAddress = balanceInfo[balanceIndex].tokenAddress;
            const tokenOwnerAddress = balanceInfo[balanceIndex].tokenOwnerAddress;
            if (balancesByOwner[tokenOwnerAddress] === undefined) {
                balancesByOwner[tokenOwnerAddress] = {};
            }
            const wrappedBalance = new BigNumber(balance);
            balancesByOwner[tokenOwnerAddress][tokenAddress] = wrappedBalance;
        });
        return balancesByOwner;
github 0xProject / 0x-monorepo / packages / website / ts / components / onboarding / portal_onboarding_flow.tsx View on Github external
shouldHideNextButton: true,
                shouldCenterTitle: true,
                shouldRemoveExtraSpacing: true,
            },
            {
                position: nextToWalletPosition,
                title: '0x Ecosystem Account Setup',
                content: ,
                shouldHideBackButton: true,
                continueButtonDisplay: 'enabled',
            },
            {
                position: nextToWalletPosition,
                title: 'Step 1: Add ETH',
                content: (
                    
                ),
                continueButtonDisplay: this._userHasVisibleEth() ? 'enabled' : 'disabled',
            },
            {
                position: nextToWalletPosition,
                title: 'Step 2: Wrap ETH',
                content: ,
                continueButtonDisplay: 'enabled',
            },
            {
                position: nextToWalletPosition,
                title: 'Step 2: Wrap ETH',
                content: ,
                continueButtonDisplay: this._userHasVisibleWeth() ? 'enabled' : 'disabled',
            },
            {
github 0xProject / 0x-monorepo / packages / website / ts / components / token_balances.tsx View on Github external
lastForceTokenStateRefetch: number;
    isFullWidth?: boolean;
}

interface TokenBalancesState {
    errorType: BalanceErrs;
    trackedTokenStateByAddress: TokenStateByAddress;
    isBalanceSpinnerVisible: boolean;
    isZRXSpinnerVisible: boolean;
    isTokenPickerOpen: boolean;
    isAddingToken: boolean;
}

export class TokenBalances extends React.Component {
    public static defaultProps: Partial = {
        userEtherBalanceInWei: new BigNumber(0),
        isFullWidth: false,
    };
    private _isUnmounted: boolean;
    public constructor(props: TokenBalancesProps) {
        super(props);
        this._isUnmounted = false;
        const initialTrackedTokenStateByAddress = this._getInitialTrackedTokenStateByAddress(props.trackedTokens);
        this.state = {
            errorType: undefined,
            isBalanceSpinnerVisible: false,
            isZRXSpinnerVisible: false,
            isTokenPickerOpen: false,
            isAddingToken: false,
            trackedTokenStateByAddress: initialTrackedTokenStateByAddress,
        };
    }
github 0xProject / 0x-monorepo / packages / order-utils / src / order_state_utils.ts View on Github external
);
        const traderFeeProxyAllowance = await this._balanceAndProxyAllowanceFetcher.getProxyAllowanceAsync(
            zrxAssetData,
            traderAddress,
        );

        const transferrableTraderAssetAmount = BigNumber.min(traderProxyAllowance, traderBalance);
        const transferrableFeeAssetAmount = BigNumber.min(traderFeeProxyAllowance, traderFeeBalance);

        const orderHash = orderHashUtils.getOrderHashHex(signedOrder);
        const filledTakerAssetAmount = await this._orderFilledCancelledFetcher.getFilledTakerAmountAsync(orderHash);
        const totalMakerAssetAmount = signedOrder.makerAssetAmount;
        const totalTakerAssetAmount = signedOrder.takerAssetAmount;
        const isOrderCancelled = await this._orderFilledCancelledFetcher.isOrderCancelledAsync(signedOrder);
        const remainingTakerAssetAmount = isOrderCancelled
            ? new BigNumber(0)
            : totalTakerAssetAmount.minus(filledTakerAssetAmount);
        const remainingMakerAssetAmount = remainingTakerAssetAmount.eq(0)
            ? new BigNumber(0)
            : remainingTakerAssetAmount.times(totalMakerAssetAmount).dividedToIntegerBy(totalTakerAssetAmount);
        const remainingAssetAmount = isMakerSide ? remainingMakerAssetAmount : remainingTakerAssetAmount;

        const remainingFillableCalculator = new RemainingFillableCalculator(
            feeAmount,
            assetAmount,
            isAssetZRX,
            transferrableTraderAssetAmount,
            transferrableFeeAssetAmount,
            remainingAssetAmount,
        );
        const remainingFillableAssetAmount = remainingFillableCalculator.computeRemainingFillable();