How to use the ethers.utils.bigNumberify function in ethers

To help you get started, we’ve selected a few ethers 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 hubiinetwork / nahmii-contracts / test / scenarios / DriipSettlementChallengeState.js View on Github external
before(() => {
                proposal = {
                    wallet: mocks.address1,
                    nonce: 1,
                    referenceBlockNumber: 123,
                    definitionBlockNumber: 456,
                    expirationTime: 12345678,
                    status: mocks.settlementStatuses.indexOf('Qualified'),
                    amounts: {
                        cumulativeTransfer: utils.bigNumberify(10),
                        stage: utils.bigNumberify(20),
                        targetBalance: utils.bigNumberify(30)
                    },
                    currency: {
                        ct: mocks.address0,
                        id: 0
                    },
                    challenged: {
                        kind: 'payment',
                        hash: mocks.hash1
                    },
                    walletInitiated: true,
                    terminated: false,
                    disqualification: {
                        challenger: mocks.address2,
                        nonce: 2,
                        blockNumber: 789,
                        candidate: {
github hubiinetwork / nahmii-contracts / test / scenarios / DriipSettlementChallengeState.js View on Github external
before(() => {
                proposal = {
                    wallet: mocks.address1,
                    nonce: 1,
                    referenceBlockNumber: 123,
                    definitionBlockNumber: 456,
                    expirationTime: 12345678,
                    status: mocks.settlementStatuses.indexOf('Qualified'),
                    amounts: {
                        cumulativeTransfer: utils.bigNumberify(10),
                        stage: utils.bigNumberify(20),
                        targetBalance: utils.bigNumberify(30)
                    },
                    currency: {
                        ct: mocks.address0,
                        id: 0
                    },
                    challenged: {
                        kind: 'payment',
                        hash: mocks.hash1
                    },
                    walletInitiated: true,
                    terminated: false,
                    disqualification: {
                        challenger: mocks.address2,
                        nonce: 2,
github hubiinetwork / nahmii-contracts / test / mocks.js View on Github external
{
                        originId: utils.bigNumberify(0),
                        figure: {
                            amount: utils.parseUnits('0.2', 18),
                            currency: {
                                ct: exports.address1,
                                id: utils.bigNumberify(0)
                            }
                        }
                    }
                ]
            }
        },
        seller: {
            wallet: Wallet.createRandom().address,
            nonce: utils.bigNumberify(1),
            rollingVolume: utils.bigNumberify(0),
            liquidityRole: exports.liquidityRoles.indexOf('Taker'),
            order: {
                amount: utils.parseUnits('1000', 18),
                hashes: {
                    wallet: cryptography.hash(Wallet.createRandom().address),
                    operator: cryptography.hash(Wallet.createRandom().address)
                },
                residuals: {
                    current: utils.parseUnits('600', 18),
                    previous: utils.parseUnits('700', 18)
                }
            },
            balances: {
                intended: {
                    current: utils.parseUnits('19500', 18),
github sablierhq / sablier / packages / burner-wallet / src / plugins / WithdrawFromStream / WithdrawFromStream.jsx View on Github external
}

      const withdrawn = stream.deposit.sub(stream.remainingBalance);
      const balance = await sablier.methods.balanceOf(streamId, stream.recipient).call();
      if (isUndefined(balance)) {
        throw new Error("Error reading the balance of the stream");
      }

      const streamed = balance.add(withdrawn);
      let intervalId = null;

      /**
       * Update the balance in real-time only if the stream is active. That is, the
       * current time has to be higher than the start time and lower then the stop time.
       */
      const now = utils.bigNumberify(Math.round(new Date().getTime() / 1000));
      if (now.gte(stream.startTime) && now.lte(stream.stopTime)) {
        intervalId = setInterval(this.updateBalance, 1000);
      }
      this.setState({
        balance,
        intervalId,
        stream,
        streamed,
        withdrawn,
      });
    } catch (err) {
      console.error(err);
    } finally {
      this.setState({ loading: false });
    }
  }
github hubiinetwork / nahmii-contracts / scripts / truffle / upgrade-state.js View on Github external
));

        const walletCurrencyBlockNumberSettledAmount = await parseJSONFromFile(`${stateImportDir}/DriipSettlementState/walletCurrencyBlockNumberSettledAmount.json`);
        console.log(`> Upgrading ${Object.getOwnPropertyNames(walletCurrencyBlockNumberSettledAmount).length} settled amounts by wallet and currency entries`);
        for (let wallet in walletCurrencyBlockNumberSettledAmount)
            for (let currencyCt in walletCurrencyBlockNumberSettledAmount[wallet])
                for (let currencyId in walletCurrencyBlockNumberSettledAmount[wallet][currencyCt])
                    for (let blockNumber in walletCurrencyBlockNumberSettledAmount[wallet][currencyCt][currencyId])
                        await confirm(await ethersDriipSettlementState.upgradeSettledAmount(
                            wallet,
                            utils.bigNumberify(walletCurrencyBlockNumberSettledAmount[wallet][currencyCt][currencyId][blockNumber]),
                            {
                                ct: currencyCt,
                                id: utils.bigNumberify(currencyId)
                            },
                            utils.bigNumberify(blockNumber),
                            {gasPrice, gasLimit: 5e6}
                        ));

        const walletCurrencySettledBlockNumbers = await parseJSONFromFile(`${stateImportDir}/DriipSettlementState/walletCurrencySettledBlockNumbers.json`);
        console.log(`> Upgrading ${Object.getOwnPropertyNames(walletCurrencySettledBlockNumbers).length} settled block numbers by wallet and currency entries`);
        for (let wallet in walletCurrencySettledBlockNumbers)
            for (let currencyCt in walletCurrencySettledBlockNumbers[wallet])
                for (let currencyId in walletCurrencySettledBlockNumbers[wallet][currencyCt]) {
                    const settledBlockNumbers = walletCurrencySettledBlockNumbers[wallet][currencyCt][currencyId];
                    await confirm(await ethersDriipSettlementState.upgradeSettledAmount(
                        wallet,
                        constants.Zero,
                        {
                            ct: currencyCt,
                            id: utils.bigNumberify(currencyId)
                        },
github pillarwallet / pillarwallet / src / utils / common.js View on Github external
export const parseTokenBigNumberAmount = (amount: number | string, decimals: number): utils.BigNumber => {
  const formatted = amount.toString();
  return decimals > 0
    ? utils.parseUnits(formatted, decimals)
    : utils.bigNumberify(formatted);
};
github ProofSuite / amp-client / src / utils / helpers.js View on Github external
export const computeChange = ( open: string, close: string ) => {
  let bigOpen = utils.bigNumberify(open)
  let bigClose = utils.bigNumberify(close)
  let percentMultiplier = utils.bigNumberify(100)

  if (bigOpen.eq(bigClose)) return 0

  let change = ((bigClose.sub(bigOpen)).mul(percentMultiplier)).div(bigOpen)
  let percentChange = Number(change.toString()) / 100
  return percentChange
}
github ProofSuite / amp-client / src / utils / helpers.js View on Github external
export const minOrderAmount = (makeFee: string, takeFee: string) => {
  let bigMakeFee = utils.bigNumberify(makeFee)
  let bigTakeFee = utils.bigNumberify(takeFee)
  let minAmount = (bigMakeFee.mul(2)).add(bigTakeFee.mul(2))
  
  return minAmount
}
github ProofSuite / amp-client / src / data.js View on Github external
import { utils } from 'ethers';

export const receipt = {
  status: '0x1',
  blockHash: '0x98887e6a4d3981430f5cd7ce5394e6a5bca15d0ff33cccd2b63cdcc1df297d70',
  blockNumber: '4132335',
  gasLimit: utils.bigNumberify(1000000),
  hash: '0x7379944c48520639ed73f8cbad1a922cbf15fb44db7f109ba1fca40d6c483d9e',
};

export const failedTxReceipt = {
  status: '0x0',
  blockHash: '0x98887e6a4d3981430f5cd7ce5394e6a5bca15d0ff33cccd2b63cdcc1df297d70',
  blockNumber: '4132335',
  gasLimit: utils.bigNumberify(1000000),
  hash: '0x7379944c48520639ed73f8cbad1a922cbf15fb44db7f109ba1fca40d6c483d9e',
};

export const tx = {
  amount: 10e18,
  receiver: '0x14d281013d8ee8ccfa0eca87524e5b3cfa6152ba',
  gasPrice: 2e9,
  gas: 100000,
};

export const tokens = [
  { symbol: 'ETH', address: '0x0' },
  { symbol: 'EOS', address: '0x8d0a722b76c0dcb91bf62334afd11f925c0adb95' },
  { symbol: 'WETH', address: '0x2eb24432177e82907de24b7c5a6e0a5c03226135' },
  { symbol: 'ZRX', address: '0xc73eec564e96e6653943d6d0e32121d455917653' },
].map((m, index) => ({ ...m, rank: index + 1 }));