utils#ZERO_ADDRESS TypeScript Examples

The following examples show how to use utils#ZERO_ADDRESS. 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: Preview.tsx    From dxvote with GNU Affero General Public License v3.0 5 votes vote down vote up
Preview = ({ descriptionText, schemeToUse }) => {
  const {
    context: { daoStore, configStore },
  } = useContext();
  const networkTokens = configStore.getTokensOfNetwork();
  const networkContracts = configStore.getNetworkContracts();
  const { assetLimits: transferLimits } = daoStore.getSchemeRecommendedCalls(
    schemeToUse.address
  );
  const networkAssetSymbol =
    NETWORK_ASSET_SYMBOL[configStore.getActiveChainName()];
  return (
    <>
      <MDEditor.Markdown
        source={descriptionText}
        style={{
          backgroundColor: 'white',
          borderRadius: '5px',
          border: '1px solid gray',
          padding: '20px 10px',
        }}
        linkTarget="_blank"
        skipHtml
        escapeHtml
      />
      {schemeToUse.type === 'ContributionReward' ||
      schemeToUse.type === 'GenericMulticall' ||
      schemeToUse.type === 'SchemeRegistrar' ||
      (isWalletScheme(schemeToUse) &&
        schemeToUse.controllerAddress === networkContracts.controller) ? (
        <h2>
          Calls executed from the avatar <Question question="9" />
        </h2>
      ) : (
        <h2>
          Calls executed from the scheme <Question question="9" />
        </h2>
      )}
      {Object.keys(transferLimits).map(assetAddress => {
        if (assetAddress === ZERO_ADDRESS)
          return (
            <h3>
              Transfer limit of{' '}
              {normalizeBalance(transferLimits[assetAddress]).toString()}{' '}
              {networkAssetSymbol}
            </h3>
          );
        else {
          const token = networkTokens.find(
            networkToken => networkToken.address === assetAddress
          );
          if (token)
            return (
              <h3>
                Transfer limit of{' '}
                {normalizeBalance(
                  transferLimits[assetAddress],
                  token.decimals
                ).toString()}{' '}
                {token.symbol}
              </h3>
            );
          else
            return (
              <h3>
                Transfer limit {transferLimits[assetAddress].toString()} of
                asset {assetAddress}
              </h3>
            );
        }
      })}
    </>
  );
}
Example #2
Source File: CreateProposal.tsx    From dxvote with GNU Affero General Public License v3.0 5 votes vote down vote up
EMPTY_CALL: Call = {
  data: ZERO_HASH,
  from: ZERO_ADDRESS,
  to: ZERO_ADDRESS,
  value: BigNumber.from(0),
}
Example #3
Source File: useABIService.ts    From dxvote with GNU Affero General Public License v3.0 4 votes vote down vote up
useABIService = (): UseABIServiceReturns => {
  const [ABI, setABI] = useState<DecodedABI>();
  const {
    context: { abiService, providerStore, configStore },
  } = useContext();

  const decodeABI = (params: DecodeABI) => {
    let contract: ContractType | undefined;
    const { data, contractType, contractABI } = params;
    if (contractType) {
      contract = contractType;
    }
    try {
      const abi = abiService.decodeCall(data, contract, contractABI);
      setABI(abi);
      return abi;
    } catch (error) {
      console.error(error);
      return {};
    }
  };

  const decodedCallData = (
    from: string,
    to: string,
    data: string,
    value: BigNumber,
    contractABI: string
  ) => {
    const { library } = providerStore.getActiveWeb3React();
    const recommendedCalls = configStore.getRecommendedCalls();
    let functionSignature = data.substring(0, 10);

    const controllerCallDecoded = abiService.decodeCall(
      data,
      ContractType.Controller
    );
    const decodedAbi = decodeABI({ data, contractABI });

    if (
      controllerCallDecoded &&
      controllerCallDecoded.function.name === 'genericCall'
    ) {
      to = controllerCallDecoded.args[0];
      data = '0x' + controllerCallDecoded.args[1].substring(10);
      value = bnum(controllerCallDecoded.args[3]);
      functionSignature = controllerCallDecoded.args[1].substring(0, 10);
    } else {
      data = '0x' + data.substring(10);
    }

    let asset = ZERO_ADDRESS;
    if (
      functionSignature === ERC20_TRANSFER_SIGNATURE ||
      functionSignature === ERC20_APPROVE_SIGNATURE
    ) {
      asset = to;
    }
    const recommendedCallUsed = recommendedCalls.find(recommendedCall => {
      return (
        asset === recommendedCall.asset &&
        (ANY_ADDRESS === recommendedCall.from ||
          from === recommendedCall.from) &&
        to === recommendedCall.to &&
        functionSignature ===
          library.eth.abi.encodeFunctionSignature(recommendedCall.functionName)
      );
    });

    if (recommendedCallUsed) {
      const callParameters = library.eth.abi.decodeParameters(
        recommendedCallUsed.params.map(param => param.type),
        data
      );

      if (callParameters.__length__) delete callParameters.__length__;

      let encodeFunctionName = library.eth.abi.encodeFunctionSignature(
        recommendedCallUsed.functionName
      );

      return {
        from: from,
        to: to,
        recommendedCallUsed: recommendedCallUsed,
        encodedFunctionName: encodeFunctionName,
        callParameters: callParameters,
        data: data,
        value: value,
        contractABI: decodedAbi,
      };
    }

    return {
      from: from,
      to: to,
      data: data,
      value: value,
      functionSignature: functionSignature,
      contractABI: decodedAbi,
    };
  };

  return {
    ABI,
    decodedCallData,
  };
}
Example #4
Source File: useFilterCriteria.ts    From dxvote with GNU Affero General Public License v3.0 4 votes vote down vote up
useFilterCriteria = (): useFilterCriteriaReturns => {
  const {
    context: { daoStore },
  } = useContext();

  const { getRep } = useRep(ZERO_ADDRESS);

  const [filteredProposals, setFilteredProposals] = useState<
    ProposalsExtended[]
  >([]);

  const [loading, setLoading] = useState(true);
  const timeNow = bnum(moment().unix());

  useEffect(() => {
    const allProposals = daoStore.getAllProposals();

    // Queded && positiveVotes >= 10% (Ordered from time to finish, from lower to higher)
    const stateEarliestAbove10 = allProposals
      .filter(proposal => {
        const queuedVotePeriodLimit = daoStore.getVotingMachineOfProposal(
          proposal.id
        ).params.queuedVotePeriodLimit;

        const repAtCreation = getRep(
          proposal.creationEvent.blockNumber
        ).totalSupply;

        return (
          proposal.stateInVotingMachine === VotingMachineProposalState.Queued &&
          timeNow.lt(proposal.submittedTime.plus(queuedVotePeriodLimit)) &&
          proposal.positiveVotes
            .div(repAtCreation)
            .times(100)
            .decimalPlaces(2)
            .gte(QUEUED_PRIORITY_THRESHOLD)
        );
      })
      .sort(orderByNewestTimeToFinish);

    // Proposals Boosted. (Ordered from time to finish, from lower to higher)
    const stateBoosted = allProposals
      .filter(
        (proposal): Boolean =>
          proposal.stateInVotingMachine === VotingMachineProposalState.Boosted
      )
      .sort(orderByNewestTimeToFinish);

    const stateQuiteEndingProposals = allProposals
      .filter(proposal => {
        return (
          proposal.stateInVotingMachine ===
          VotingMachineProposalState.QuietEndingPeriod
        );
      })
      .sort(orderByNewestTimeToFinish);

    const statePreBoosted = allProposals
      .filter(
        (proposal): Boolean =>
          proposal.stateInVotingMachine ===
          VotingMachineProposalState.PreBoosted
      )
      .sort(orderByNewestTimeToFinish);

    // Queded && positiveVotes < 10% (Ordered from time to finish, from lower to higher)
    const stateEarliestUnder10 = allProposals
      .filter((proposal): Boolean => {
        const queuedVotePeriodLimit = daoStore.getVotingMachineOfProposal(
          proposal.id
        ).params.queuedVotePeriodLimit;

        const repAtCreation = getRep(
          proposal.creationEvent.blockNumber
        ).totalSupply;

        return (
          proposal.stateInVotingMachine === VotingMachineProposalState.Queued &&
          timeNow.lt(proposal.submittedTime.plus(queuedVotePeriodLimit)) &&
          proposal.positiveVotes
            .div(repAtCreation)
            .times(100)
            .decimalPlaces(2)
            .lt(QUEUED_PRIORITY_THRESHOLD)
        );
      })
      .sort(orderByNewestTimeToFinish);

    //Proposals in Executed status. (Ordered in time passed since finish, from higher to lower)
    const stateExecuted = allProposals
      .filter(
        (proposal): Boolean =>
          proposal.stateInVotingMachine === VotingMachineProposalState.Executed
      )
      .sort(orderByOldestTimeToFinish);

    //Proposals finished status. (Expired in queue, rejected or passed)
    const stateFinished = allProposals
      .filter((proposal): Boolean => {
        const queuedVotePeriodLimit = daoStore.getVotingMachineOfProposal(
          proposal.id
        ).params.queuedVotePeriodLimit;
        return (
          (proposal.stateInVotingMachine ===
            VotingMachineProposalState.Queued &&
            timeNow.gt(proposal.submittedTime.plus(queuedVotePeriodLimit))) ||
          proposal.stateInVotingMachine ===
            VotingMachineProposalState.ExpiredInQueue ||
          proposal.stateInVotingMachine ===
            VotingMachineProposalState.Rejected ||
          proposal.stateInVotingMachine === VotingMachineProposalState.Passed
        );
      })
      .sort(orderByOldestTimeToFinish);

    setFilteredProposals([
      ...stateBoosted,
      ...statePreBoosted,
      ...stateQuiteEndingProposals,
      ...stateEarliestAbove10,
      ...stateEarliestUnder10,
      ...stateExecuted,
      ...stateFinished,
    ]);

    setLoading(false);
  }, []);

  return {
    proposals: filteredProposals,
    loading,
  };
}