ethers#constants JavaScript Examples

The following examples show how to use ethers#constants. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResolveName.js    From Tai-Shang-NFT-Wallet with MIT License 6 votes vote down vote up
useResolveName = (provider, ensName) => {
  const [address, setAddress] = useState(constants.AddressZero);

  useEffect(() => {
    if (provider) {
      provider.resolveName(ensName).then(resolvedAddress => setAddress(resolvedAddress));
    }
  }, [provider, ensName]);

  return address;
}
Example #2
Source File: TaskReceipt.js    From gelato-network with MIT License 6 votes vote down vote up
constructor({
    id,
    userProxy,
    provider,
    index,
    tasks,
    expiryDate,
    cycleId,
    submissionsLeft,
  }) {
    if (userProxy === undefined) throw new Error("TaskReceipt: no userProxy");
    if (!provider) throw new Error("TaskReceipt: no provider\n");
    if (!tasks || !Array.isArray(tasks))
      throw new Error("\nTask: tasks must be Array\n");
    if (!tasks.length) throw new Error("\nTask: tasks be non-empty Array\n");
    for (const task of tasks) checkTaskMembers(task);

    this.id = id !== undefined ? utils.bigNumberify(id) : constants.Zero;
    this.userProxy = userProxy;
    this.provider = provider;
    this.index =
      index === undefined ? constants.Zero : utils.bigNumberify(index);
    this.tasks = tasks ? tasks : [];
    this.expiryDate = expiryDate !== undefined ? expiryDate : constants.Zero;
    this.cycleId = cycleId !== undefined ? cycleId : constants.Zero;
    this.submissionsLeft = submissionsLeft === undefined ? 1 : submissionsLeft;
  }
Example #3
Source File: Ether.js    From lido-dao with GNU General Public License v3.0 6 votes vote down vote up
Ether = ({ ether }) => {
  if (typeof ether === 'undefined') {
    return <LoadingRing />
  }

  try {
    ether = formatEth(ether)
  } catch (error) {
    console.warn(error)
    return <span>N/A</span>
  }

  return (
    <span>
      {constants.EtherSymbol}
      {ether}
    </span>
  )
}
Example #4
Source File: RestorationRate.js    From lido-dao with GNU General Public License v3.0 6 votes vote down vote up
RestorationRate = ({ maxLimit, blocks }) => {
  if (typeof maxLimit === 'undefined' || typeof blocks === 'undefined') {
    return <LoadingRing />
  }

  maxLimit = Number(maxLimit)
  blocks = Number(blocks)
  const rate = maxLimit / blocks

  if (Number.isNaN(maxLimit) || Number.isNaN(blocks) || Number.isNaN(rate)) {
    return <span>N/A</span>
  }

  return (
    <span>
      {constants.EtherSymbol}
      {formatEth(String(rate))} per block
    </span>
  )
}
Example #5
Source File: App.js    From lido-dao with GNU General Public License v3.0 6 votes vote down vote up
function renderLastCompletedReportDelta(lastCompletedReportDelta) {
  if (!lastCompletedReportDelta) return null

  return (
    <>
      <LabelValue
        label="Pre-total:"
        value={`${constants.EtherSymbol}${Number(
          ethers.utils.formatEther(lastCompletedReportDelta.preTotalPooledEther)
        ).toFixed(4)}`}
      />
      <LabelValue
        label="Post-total:"
        value={`${constants.EtherSymbol}${Number(
          ethers.utils.formatEther(
            lastCompletedReportDelta.postTotalPooledEther
          )
        ).toFixed(4)}`}
      />
      <LabelValue
        label="Time elapsed:"
        value={`${lastCompletedReportDelta.timeElapsed}s`}
      />
    </>
  )
}
Example #6
Source File: Action.js    From gelato-network with MIT License 5 votes vote down vote up
constructor({ addr, data, operation, dataFlow, value, termsOkCheck }) {
    if (!addr) throw new Error("\nAction: no addr passed to constructor\n");
    if (operation === undefined)
      throw new Error("\nAction: no operation passed to constructor\n");

    if (operation !== Operation.Call && operation !== Operation.Delegatecall) {
      throw new Error(
        "\nAction: pass 'Operation.Call' or 'Operation.Delegatecall', you passed:",
        operation,
        "\n CASE SENSITIVE => .call or .delegatecall do not work!",
        "\n"
      );
    }
    if (
      operation == Operation.Delegatecall &&
      value &&
      value.toString() !== "0"
    ) {
      throw new Error(
        "\n Action: Delegatecalls must have 0 in the value field"
      );
    }
    if (dataFlow && Object.values(DataFlow).indexOf(dataFlow) === -1)
      throw new Error("\n Action: Invalid DataFlow value \n");
    const trueOrFalse = [true, false];
    if (termsOkCheck !== undefined && !trueOrFalse.includes(termsOkCheck)) {
      throw new Error(
        "\nAction.termsOkCheck: pass true or false, you passed:",
        termsOkCheck,
        "\n"
      );
    }

    this.addr = addr;
    this.data = data ? data : constants.HashZero;
    this.operation = operation;
    this.dataFlow = dataFlow !== undefined ? dataFlow : DataFlow.None;
    this.value = value ? value : constants.Zero;
    this.termsOkCheck = termsOkCheck === true ? termsOkCheck : false;
  }
Example #7
Source File: Condition.js    From gelato-network with MIT License 5 votes vote down vote up
constructor({ inst, data }) {
    this.inst = inst ? inst : constants.AddressZero;
    this.data = data ? data : constants.HashZero;
  }
Example #8
Source File: GelatoSysAdmin.initialState.js    From gelato-network with MIT License 5 votes vote down vote up
GELATO_GAS_PRICE_ORACLE = constants.AddressZero
Example #9
Source File: PrizeSplitControlCard.jsx    From pooltogether-community-ui with MIT License 5 votes vote down vote up
convertFormToPrizeSplitsConfig = async (
  { count, provider, poolToast },
  prizeSplit1Target,
  prizeSplit1Percentage,
  prizeSplit1Token,
  prizeSplit2Target,
  prizeSplit2Percentage,
  prizeSplit2Token
) => {
  const prizeSplitMerged = []

  if (isValidAddress(prizeSplit1Target) && prizeSplit1Target != constants.AddressZero) {
    prizeSplitMerged.push({
      target: prizeSplit1Target,
      percentage: convertPercentageToSingleDecimalPrecision(prizeSplit1Percentage),
      token: prizeSplit1Token
    })
  } else if (prizeSplit1Target && prizeSplit1Target != constants.AddressZero) {
    const ensResolved = await provider.resolveName(prizeSplit1Target)
    if (isValidAddress(ensResolved)) {
      prizeSplitMerged.push({
        target: ensResolved,
        percentage: convertPercentageToSingleDecimalPrecision(prizeSplit1Percentage),
        token: prizeSplit1Token
      })
    } else {
      poolToast.error(`First Prize Split: Unable to resolve ENS address`)
      return
    }
  }

  if (
    count == 2 &&
    isValidAddress(prizeSplit2Target) &&
    prizeSplit2Target != constants.AddressZero
  ) {
    prizeSplitMerged.push({
      target: prizeSplit2Target,
      percentage: convertPercentageToSingleDecimalPrecision(prizeSplit2Percentage),
      token: prizeSplit2Token
    })
  } else if (count == 2 && prizeSplit2Target && prizeSplit2Target != constants.AddressZero) {
    const ensResolved = await provider.resolveName(prizeSplit2Target)
    if (isValidAddress(ensResolved)) {
      prizeSplitMerged.push({
        target: ensResolved,
        percentage: convertPercentageToSingleDecimalPrecision(prizeSplit2Percentage),
        token: prizeSplit2Token
      })
    } else {
      poolToast.error(`First Prize Split: Unable to resolve ENS address`)
      return
    }
  }

  return prizeSplitMerged
}
Example #10
Source File: PrizeSplitControlCard.jsx    From pooltogether-community-ui with MIT License 4 votes vote down vote up
PrizeSplitForm = (props) => {
  const [tx, setTx] = useState({})
  const counter = useCounter(1, { min: 0, max: 2 })
  const usersAddress = useUsersAddress()
  const sendTx = useSendTransaction()
  const { provider } = useOnboard()

  const { prizePoolContracts, prizeSplitsValues, refetchprizeSplitsValues } = props

  const txName = 'Set PrizeStrategy prize split'

  useEffect(() => {
    if (idx(prizeSplitsValues, (_) => _.prizeSplits)) {
      counter.set(prizeSplitsValues.prizeSplits.length)
    }
  }, [prizeSplitsValues])

  // Form Value State
  const [prizeSplit1Target, setPrizeSplit1Target] = useState(
    idx(prizeSplitsValues, (_) => _.prizeSplits[0].target || constants.AddressZero)
  )
  const [prizeSplit1Percentage, setPrizeSplit1Percentage] = useState(
    idx(prizeSplitsValues, (_) => _.prizeSplits[0].percentage / 10 || 0)
  )

  const [prizeSplit1TokenType, setPrizeSplit1TokenType] = useState(
    `${idx(prizeSplitsValues, (_) => _.prizeSplits[0].token)}`
  )

  const [prizeSplit2Target, setPrizeSplit2Target] = useState(
    idx(prizeSplitsValues, (_) => _.prizeSplits[1].target || constants.AddressZero)
  )
  const [prizeSplit2Percentage, setPrizeSplit2Percentage] = useState(
    idx(prizeSplitsValues, (_) => _.prizeSplits[1].percentage / 10 || '1')
  )

  const [prizeSplit2TokenType, setPrizeSplit2TokenType] = useState(
    `${idx(prizeSplitsValues, (_) => _.prizeSplits[1].token)}`
  )

  const [isPrizeSplitTouched, setIsPrizeSplitTouched] = useState(false)
  useEffect(() => {
    if (idx(prizeSplitsValues, (_) => _.prizeSplits)) {
      const prizeSplitsChain = [
        {
          target: idx(prizeSplitsValues, (_) => _.prizeSplits[0].target),
          percentage: idx(prizeSplitsValues, (_) => _.prizeSplits[0].percentage),
          token: `${idx(prizeSplitsValues, (_) => _.prizeSplits[0].token)}`
        },
        {
          target: idx(prizeSplitsValues, (_) => _.prizeSplits[1].target),
          percentage: idx(prizeSplitsValues, (_) => _.prizeSplits[1].percentage),
          token: `${idx(prizeSplitsValues, (_) => _.prizeSplits[1].token)}`
        }
      ]

      const prizeSplitsConfig = [
        {
          target: prizeSplit1Target,
          percentage: convertPercentageToSingleDecimalPrecision(prizeSplit1Percentage),
          token: prizeSplit1TokenType
        },
        {
          target: prizeSplit2Target,
          percentage: convertPercentageToSingleDecimalPrecision(prizeSplit2Percentage),
          token: prizeSplit2TokenType
        }
      ]
      const prizeSplitTouched = isEqual(prizeSplitsChain, prizeSplitsConfig)
      setIsPrizeSplitTouched(prizeSplitTouched)
    }
  }, [
    prizeSplitsValues,
    prizeSplit1Target,
    prizeSplit1Percentage,
    prizeSplit1TokenType,
    prizeSplit2Target,
    prizeSplit2Percentage,
    prizeSplit2TokenType
  ])

  const handleSubmit = async (e) => {
    const prizeSplits = await convertFormToPrizeSplitsConfig(
      { provider, poolToast, count: counter.value },
      prizeSplit1Target,
      prizeSplit1Percentage,
      prizeSplit1TokenType,
      prizeSplit2Target,
      prizeSplit2Percentage,
      prizeSplit2TokenType
    )
    e.preventDefault()
    handleSetPrizeSplits(
      sendTx,
      txName,
      setTx,
      prizePoolContracts.prizeStrategy.address,
      prizeSplits
    )
  }

  const handleSetPrizeSplit = async (prizeSplit, prizeSplitIndex) => {
    const prizeSplitConfig = await convertFormToPrizeSplitConfig(prizeSplit, {
      provider,
      poolToast
    })

    if (prizeSplitConfig) {
      setPrizeSplit(
        sendTx,
        txName,
        setTx,
        prizePoolContracts.prizeStrategy.address,
        prizeSplitConfig,
        prizeSplitIndex
      )
    }
  }

  const handleRemovePrizeSplit = (index) => {
    if (index == 1) {
      setPrizeSplit1Target(constants.AddressZero)
      setPrizeSplit1Percentage(undefined)
      setPrizeSplit1TokenType(undefined)
    } else {
      setPrizeSplit2Target(constants.AddressZero)
      setPrizeSplit2Percentage(undefined)
      setPrizeSplit2TokenType(undefined)
    }
    counter.decr(1)
  }

  useOnTransactionCompleted(tx, refetchprizeSplitsValues)

  const resetState = (e) => {
    e.preventDefault()
    setTx({})
  }

  if (!usersAddress) {
    return <ConnectWalletButton className='w-full mt-4' />
  }

  if (tx.inWallet || tx.sent || tx.completed) {
    return <TxMessage txType={txName} tx={tx} handleReset={resetState} />
  }

  return (
    <form onSubmit={handleSubmit}>
      {(counter.value == 1 || counter.value == 2) && (
        <PrizeSplitPosition
          prizeSplitsLength={prizeSplitsValues.prizeSplits.length}
          index={0}
          position={1}
          target={prizeSplit1Target}
          percentage={prizeSplit1Percentage}
          setTarget={setPrizeSplit1Target}
          setPercentage={setPrizeSplit1Percentage}
          tokenType={prizeSplit1TokenType}
          setTokenType={setPrizeSplit1TokenType}
          handleSetPrizeSplit={handleSetPrizeSplit}
          provider={provider}
          prizeSplitsValues={prizeSplitsValues}
        />
      )}
      {counter.value == 2 && (
        <PrizeSplitPosition
          prizeSplitsLength={prizeSplitsValues.prizeSplits.length}
          index={1}
          position={2}
          target={prizeSplit2Target}
          percentage={prizeSplit2Percentage}
          setTarget={setPrizeSplit2Target}
          setPercentage={setPrizeSplit2Percentage}
          tokenType={prizeSplit2TokenType}
          setTokenType={setPrizeSplit2TokenType}
          handleSetPrizeSplit={handleSetPrizeSplit}
          provider={provider}
          prizeSplitsValues={prizeSplitsValues}
        />
      )}

      <div className='grid grid-cols-1 lg:grid-cols-2 lg:gap-x-10 gap-y-3 lg:gap-y-0 justify-between mt-5 lg:mt-10'>
        <Button
          fullWidth
          disabled={counter.value == 2}
          type='button'
          color='secondary'
          onClick={() => counter.incr(1)}
        >
          Add Additional PrizeSplit
        </Button>
        <Button
          fullWidth
          disabled={counter.value == 0}
          type='button'
          color='danger'
          onClick={() => handleRemovePrizeSplit(counter.value)}
        >
          Remove PrizeSplit
        </Button>
      </div>

      <Button
        fullWidth
        color='primary'
        size='lg'
        className='mt-8 w-full'
        disabled={isPrizeSplitTouched}
      >
        Update All Prize Splits
      </Button>
    </form>
  )
}
Example #11
Source File: PrizeSplitCard.jsx    From pooltogether-pool-builder-ui with MIT License 4 votes vote down vote up
PrizeSplitCard = (props) => {
  const {
    prizePool1Target,
    prizePool1Percentage,
    prizePool2Target,
    prizePool2Percentage,
    setPrizePool1Target,
    setPrizePool1TokenType,
    setPrizePool1Percentage,
    setPrizePool2Target,
    setPrizePool2Percentage,
    setPrizePool2TokenType
  } = props
  const counter = useCounter(1, {
    min: 0,
    max: 2
  })

  const handleRemovePrizeSplit = (index) => {
    if (index == 1) {
      setPrizePool1Target(constants.AddressZero)
      setPrizePool1Percentage(undefined)
      setPrizePool1TokenType(undefined)
    } else {
      setPrizePool2Target(constants.AddressZero)
      setPrizePool2Percentage(undefined)
      setPrizePool2TokenType(undefined)
    }
    counter.decr(1)
  }

  return (
    <Card>
      <InputLabel
        primary='Prize Split'
        description='Distribute a percentage of prize (before awarding winners) on every draw to static address.'
      >
        {(counter.value == 1 || counter.value == 2) && (
          <PrizeSplitPosition
            index={1}
            target={prizePool1Target}
            percentage={prizePool1Percentage}
            setTarget={setPrizePool1Target}
            setPercentage={setPrizePool1Percentage}
            setTokenType={setPrizePool1TokenType}
          />
        )}
        {counter.value == 2 && (
          <PrizeSplitPosition
            index={2}
            target={prizePool2Target}
            percentage={prizePool2Percentage}
            setTarget={setPrizePool2Target}
            setPercentage={setPrizePool2Percentage}
            setTokenType={setPrizePool2TokenType}
          />
        )}
      </InputLabel>

      <div className='flex items-center mt-4'>
        <Button
          disabled={counter.value == 2}
          color='primary'
          size='sm'
          paddingClasses='p-2'
          onClick={() => counter.incr(1)}
        >
          Add prize split
        </Button>
        <Button
          disabled={counter.value == 0}
          color='warning'
          size='sm'
          className='ml-2'
          paddingClasses='p-2'
          onClick={() => handleRemovePrizeSplit(counter.value)}
        >
          Remove prize split
        </Button>
      </div>
    </Card>
  )
}