ethers/lib/utils#isHexString TypeScript Examples

The following examples show how to use ethers/lib/utils#isHexString. 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: proposing.ts    From safe-tasks with GNU Lesser General Public License v3.0 6 votes vote down vote up
task("propose", "Create a Safe tx proposal json file")
    .addPositionalParam("address", "Address or ENS name of the Safe to check", undefined, types.string)
    .addParam("to", "Address of the target", undefined, types.string)
    .addParam("value", "Value in ETH", "0", types.string, true)
    .addParam("data", "Data as hex string", "0x", types.string, true)
    .addFlag("delegatecall", "Indicator if tx should be executed as a delegatecall")
    .addFlag("onChainHash", "Get hash from chain (required for pre-1.3.0 version)")
    .setAction(async (taskArgs, hre) => {
        console.log(`Running on ${hre.network.name}`)
        const safe = await safeSingleton(hre, taskArgs.address)
        const safeAddress = await safe.resolvedAddress
        console.log(`Using Safe at ${safeAddress}`)
        const nonce = await safe.nonce()
        if (!isHexString(taskArgs.data)) throw Error(`Invalid hex string provided for data: ${taskArgs.data}`)
        const tx = buildSafeTransaction({ to: taskArgs.to, value: parseEther(taskArgs.value).toString(), data: taskArgs.data, nonce: nonce.toString(), operation: taskArgs.delegatecall ? 1 : 0 })
        const chainId = (await safe.provider.getNetwork()).chainId
        const safeTxHash = await calcSafeTxHash(safe, tx, chainId, taskArgs.onChainHash)
        const proposal: SafeTxProposal = {
            safe: safeAddress,
            chainId,
            safeTxHash,
            tx
        }
        await writeToCliCache(proposalFile(safeTxHash), proposal)
        console.log(`Safe transaction hash: ${safeTxHash}`)
    });
Example #2
Source File: signing.ts    From safe-tasks with GNU Lesser General Public License v3.0 6 votes vote down vote up
task("sign-tx", "Signs a Safe transaction")
    .addPositionalParam("address", "Address or ENS name of the Safe to check", undefined, types.string)
    .addParam("to", "Address of the target", undefined, types.string)
    .addParam("value", "Value in ETH", "0", types.string, true)
    .addParam("data", "Data as hex string", "0x", types.string, true)
    .addParam("signerIndex", "Index of the signer to use", 0, types.int, true)
    .addFlag("delegatecall", "Indicator if tx should be executed as a delegatecall")
    .setAction(async (taskArgs, hre) => {
        console.log(`Running on ${hre.network.name}`)
        const signers = await hre.ethers.getSigners()
        const signer = signers[taskArgs.signerIndex]
        const safe = await safeSingleton(hre, taskArgs.address)
        const safeAddress = await safe.resolvedAddress
        console.log(`Using Safe at ${safeAddress} with ${signer.address}`)
        const nonce = await safe.nonce()
        if (!isHexString(taskArgs.data)) throw Error(`Invalid hex string provided for data: ${taskArgs.data}`)
        const tx = buildSafeTransaction({ to: taskArgs.to, value: parseEther(taskArgs.value), data: taskArgs.data, nonce, operation: taskArgs.delegatecall ? 1 : 0 })
        const signature = await safeSignMessage(signer, safe, tx)
        console.log(`Signature: ${signature.data}`)
    });
Example #3
Source File: submitting.ts    From safe-tasks with GNU Lesser General Public License v3.0 6 votes vote down vote up
parseSignature = (safeTxHash: string, signature: string): SafeSignature => {
    if (!isHexString(signature, 65)) throw Error(`Unsupported signature: ${signature}`)
    const type = parseInt(signature.slice(signature.length - 2), 16)
    switch (type) {
        case 1: return parsePreApprovedConfirmation(signature)
        case 27:
        case 28:
            return parseTypeDataConfirmation(safeTxHash, signature)
        case 31:
        case 32:
            return parseEthSignConfirmation(safeTxHash, signature)
        case 0:
        default:
            throw Error(`Unsupported type ${type} in ${signature}`)
    }
}
Example #4
Source File: submitting.ts    From safe-tasks with GNU Lesser General Public License v3.0 6 votes vote down vote up
task("submit-tx", "Executes a Safe transaction")
    .addPositionalParam("address", "Address or ENS name of the Safe to check", undefined, types.string)
    .addParam("to", "Address of the target", undefined, types.string)
    .addParam("value", "Value in ETH", "0", types.string, true)
    .addParam("data", "Data as hex string", "0x", types.string, true)
    .addParam("signatures", "Comma seperated list of signatures", undefined, types.string, true)
    .addParam("gasPrice", "Gas price to be used", undefined, types.int, true)
    .addParam("gasLimit", "Gas limit to be used", undefined, types.int, true)
    .addFlag("delegatecall", "Indicator if tx should be executed as a delegatecall")
    .setAction(async (taskArgs, hre) => {
        console.log(`Running on ${hre.network.name}`)
        const [signer] = await hre.ethers.getSigners()
        const safe = await safeSingleton(hre, taskArgs.address)
        const safeAddress = await safe.resolvedAddress
        console.log(`Using Safe at ${safeAddress} with ${signer.address}`)
        const nonce = await safe.nonce()
        if (!isHexString(taskArgs.data)) throw Error(`Invalid hex string provided for data: ${taskArgs.data}`)
        const tx = buildSafeTransaction({ 
            to: taskArgs.to, 
            value: parseEther(taskArgs.value), 
            data: taskArgs.data, 
            nonce, 
            operation: taskArgs.delegatecall ? 1 : 0 
        })
        const signatures = await prepareSignatures(safe, tx, taskArgs.signatures, signer)
        const populatedTx: PopulatedTransaction = await populateExecuteTx(safe, tx, signatures, { gasLimit: taskArgs.gasLimit, gasPrice: taskArgs.gasPrice })
        const receipt = await signer.sendTransaction(populatedTx).then(tx => tx.wait())
        console.log(receipt.transactionHash)
    });
Example #5
Source File: proposing.ts    From safe-tasks with GNU Lesser General Public License v3.0 5 votes vote down vote up
buildMetaTx = (description: TxDescription): MetaTransaction => {
    const to = getAddress(description.to)
    const value = parseEther(description.value).toString()
    const operation = description.operation
    const data = isHexString(description.data) ? description.data!! : (description.method ? buildData(description.method, description.params) : "0x")
    return { to, value, data, operation }
}
Example #6
Source File: useErc20Deposit.ts    From crust-apps with Apache License 2.0 5 votes vote down vote up
useErc20Deposit = (
  sender?: string
): DepositSubmitFn | undefined => {
  const { contract } = useBridgeContract();
  const { systemChain: substrateName } = useApi();
  const { options: config } = useEthereumNetworkOptions();
  const { data: network } = useEthersNetworkQuery();
  const { provider } = useEthers();

  const bridge = useMemo(() => {
    return contract !== undefined && provider !== undefined
      ? contract.connect(provider.getSigner(sender))
      : undefined;
  }, [contract, provider, sender]);

  return useMemo(() => {
    if (
      bridge === undefined ||
      config === undefined ||
      network === undefined ||
      sender === undefined ||
      substrateName === undefined
    ) {
      return undefined;
    }

    const destChainId = config.peerChainIds[substrateName] as
      | number
      | undefined;

    return async (amount, recipient) => {
      if (destChainId === undefined) {
        throw new Error(
          `Unsupported Ethereum network: ${network.name} (${network.chainId})`
        );
      }

      if (typeof bridge.functions.deposit !== 'function') {
        throw new Error(
          'Assertion failed: deposit should be available on the bridge contract'
        );
      }

      if (!isHexString(recipient)) {
        throw new Error('Validation failed: recipient should be hex string');
      }

      const amountPayload = ethers.utils
        .hexZeroPad(amount.toHexString(), 32)
        .substr(2);
      const recipientPayload = recipient.substr(2);
      const recipientSize = ethers.utils
        .hexZeroPad(ethers.utils.hexlify(recipientPayload.length / 2), 32)
        .substr(2);

      const payload = `0x${amountPayload}${recipientSize}${recipientPayload}`;

      return await (bridge.functions.deposit(
        destChainId,
        config.erc20ResourceId,
        payload
      ) as Promise<ethers.providers.TransactionResponse>);
    };
  }, [bridge, config, network, sender, substrateName]);
}
Example #7
Source File: pancakeswap-pair-contract.factory.public.spec.ts    From simple-pancakeswap-sdk with MIT License 5 votes vote down vote up
describe('PancakeswapPairContractFactoryPublic', () => {
  const pancakeswapPairContractFactoryPublic = new PancakeswapPairContractFactoryPublic();

  it('allPairs', async () => {
    const result = await pancakeswapPairContractFactoryPublic.allPairs('0x01');
    expect(result).toEqual('0x0eD7e52944161450477ee417DE9Cd3a859b14fD0');
  });

  it('allPairsLength', async () => {
    const result = await pancakeswapPairContractFactoryPublic.allPairsLength();
    expect(isHexString(result)).toEqual(true);
  });

  it('createPair', () => {
    const result = pancakeswapPairContractFactoryPublic.createPair(
      MOCKBAT().contractAddress,
      BNB.token().contractAddress
    );
    expect(result).toEqual(
      '0xc9c65396000000000000000000000000101d82428437127bf1608f699cd651e6abf9766e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'
    );
  });

  it('feeTo', async () => {
    const result = await pancakeswapPairContractFactoryPublic.feeTo();
    expect(isHexString(result)).toEqual(true);
  });

  it('feeToSetter', async () => {
    const result = await pancakeswapPairContractFactoryPublic.feeToSetter();
    expect(isHexString(result)).toEqual(true);
  });

  it('getPair', async () => {
    const result = await pancakeswapPairContractFactoryPublic.getPair(
      BNB.token().contractAddress,
      MOCKBAT().contractAddress
    );
    expect(result).toEqual('0xD72AE03Be5ce45bB6FdFE0AA0D81d7eef709dCC3');
  });

  it('setFeeTo', async () => {
    const result = await pancakeswapPairContractFactoryPublic.setFeeTo(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xf46901ed00000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });

  it('setFeeToSetter', async () => {
    const result = await pancakeswapPairContractFactoryPublic.setFeeToSetter(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xa2e74af600000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });
});
Example #8
Source File: pancakeswap-pair-contract.factory.spec.ts    From simple-pancakeswap-sdk with MIT License 5 votes vote down vote up
describe('PancakeswapPairContractFactory', () => {
  const ethersProvider = new EthersProvider();

  const pancakeswapPairContractFactory = new PancakeswapPairContractFactory(
    ethersProvider
  );

  it('allPairs', async () => {
    const result = await pancakeswapPairContractFactory.allPairs('0x01');
    expect(result).toEqual('0x0eD7e52944161450477ee417DE9Cd3a859b14fD0');
  });

  it('allPairsLength', async () => {
    const result = await pancakeswapPairContractFactory.allPairsLength();
    expect(isHexString(result)).toEqual(true);
  });

  it('createPair', () => {
    const result = pancakeswapPairContractFactory.createPair(
      MOCKBAT().contractAddress,
      BNB.token().contractAddress
    );
    expect(result).toEqual(
      '0xc9c65396000000000000000000000000101d82428437127bf1608f699cd651e6abf9766e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'
    );
  });

  it('feeTo', async () => {
    const result = await pancakeswapPairContractFactory.feeTo();
    expect(isHexString(result)).toEqual(true);
  });

  it('feeToSetter', async () => {
    const result = await pancakeswapPairContractFactory.feeToSetter();
    expect(isHexString(result)).toEqual(true);
  });

  it('getPair', async () => {
    const result = await pancakeswapPairContractFactory.getPair(
      BNB.token().contractAddress,
      MOCKBAT().contractAddress
    );
    expect(result).toEqual('0xD72AE03Be5ce45bB6FdFE0AA0D81d7eef709dCC3');
  });

  it('setFeeTo', async () => {
    const result = await pancakeswapPairContractFactory.setFeeTo(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xf46901ed00000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });

  it('setFeeToSetter', async () => {
    const result = await pancakeswapPairContractFactory.setFeeToSetter(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xa2e74af600000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });
});
Example #9
Source File: pancakeswap-contract.factory.public.spec.ts    From simple-pancakeswap-sdk with MIT License 5 votes vote down vote up
describe('PancakeswapContractFactoryPublic', () => {
  const pancakeswapContractFactoryPublic = new PancakeswapContractFactoryPublic();

  it('allPairs', async () => {
    const result = await pancakeswapContractFactoryPublic.allPairs('0x01');
    expect(result).toEqual('0x0eD7e52944161450477ee417DE9Cd3a859b14fD0');
  });

  it('allPairsLength', async () => {
    const result = await pancakeswapContractFactoryPublic.allPairsLength();
    expect(isHexString(result)).toEqual(true);
  });

  it('createPair', () => {
    const result = pancakeswapContractFactoryPublic.createPair(
      MOCKBAT().contractAddress,
      BNB.token().contractAddress
    );
    expect(result).toEqual(
      '0xc9c65396000000000000000000000000101d82428437127bf1608f699cd651e6abf9766e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'
    );
  });

  it('feeTo', async () => {
    const result = await pancakeswapContractFactoryPublic.feeTo();
    expect(isHexString(result)).toEqual(true);
  });

  it('feeToSetter', async () => {
    const result = await pancakeswapContractFactoryPublic.feeToSetter();
    expect(isHexString(result)).toEqual(true);
  });

  it('getPair', async () => {
    const result = await pancakeswapContractFactoryPublic.getPair(
      BNB.token().contractAddress,
      MOCKBAT().contractAddress
    );
    expect(result).toEqual('0xD72AE03Be5ce45bB6FdFE0AA0D81d7eef709dCC3');
  });

  it('setFeeTo', async () => {
    const result = await pancakeswapContractFactoryPublic.setFeeTo(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xf46901ed00000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });

  it('setFeeToSetter', async () => {
    const result = await pancakeswapContractFactoryPublic.setFeeToSetter(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xa2e74af600000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });
});
Example #10
Source File: pancakeswap-contract.factory.spec.ts    From simple-pancakeswap-sdk with MIT License 5 votes vote down vote up
describe('PancakeswapContractFactory', () => {
  const ethersProvider = new EthersProvider();

  const pancakeswapContractFactory = new PancakeswapContractFactory(
    ethersProvider
  );

  it('allPairs', async () => {
    const result = await pancakeswapContractFactory.allPairs('0x01');
    expect(result).toEqual('0x0eD7e52944161450477ee417DE9Cd3a859b14fD0');
  });

  it('allPairsLength', async () => {
    const result = await pancakeswapContractFactory.allPairsLength();
    expect(isHexString(result)).toEqual(true);
  });

  it('createPair', () => {
    const result = pancakeswapContractFactory.createPair(
      MOCKBAT().contractAddress,
      BNB.token().contractAddress
    );
    expect(result).toEqual(
      '0xc9c65396000000000000000000000000101d82428437127bf1608f699cd651e6abf9766e000000000000000000000000bb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'
    );
  });

  it('feeTo', async () => {
    const result = await pancakeswapContractFactory.feeTo();
    expect(isHexString(result)).toEqual(true);
  });

  it('feeToSetter', async () => {
    const result = await pancakeswapContractFactory.feeToSetter();
    expect(isHexString(result)).toEqual(true);
  });

  it('getPair', async () => {
    const result = await pancakeswapContractFactory.getPair(
      BNB.token().contractAddress,
      MOCKBAT().contractAddress
    );
    expect(result).toEqual('0xD72AE03Be5ce45bB6FdFE0AA0D81d7eef709dCC3');
  });

  it('setFeeTo', async () => {
    const result = await pancakeswapContractFactory.setFeeTo(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xf46901ed00000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });

  it('setFeeToSetter', async () => {
    const result = await pancakeswapContractFactory.setFeeToSetter(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xa2e74af600000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });
});
Example #11
Source File: uniswap-pair-contract.factory.public.v2.spec.ts    From simple-uniswap-sdk with MIT License 5 votes vote down vote up
describe('UniswapPairContractFactoryPublicV2', () => {
  const uniswapPairContractFactoryPublic =
    new UniswapPairContractFactoryPublicV2({ chainId: ChainId.MAINNET });

  it('allPairs', async () => {
    const result = await uniswapPairContractFactoryPublic.allPairs('0x01');
    expect(result).toEqual('0x3139Ffc91B99aa94DA8A2dc13f1fC36F9BDc98eE');
  });

  it('allPairsLength', async () => {
    const result = await uniswapPairContractFactoryPublic.allPairsLength();
    expect(isHexString(result)).toEqual(true);
  });

  it('createPair', () => {
    const result = uniswapPairContractFactoryPublic.createPair(
      MOCKFUN().contractAddress,
      WETHContract.MAINNET().contractAddress
    );
    expect(result).toEqual(
      '0xc9c65396000000000000000000000000419d0d8bdd9af5e606ae2232ed285aff190e711b000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
    );
  });

  it('feeTo', async () => {
    const result = await uniswapPairContractFactoryPublic.feeTo();
    expect(isHexString(result)).toEqual(true);
  });

  it('feeToSetter', async () => {
    const result = await uniswapPairContractFactoryPublic.feeToSetter();
    expect(isHexString(result)).toEqual(true);
  });

  it('getPair', async () => {
    const result = await uniswapPairContractFactoryPublic.getPair(
      WETHContract.MAINNET().contractAddress,
      MOCKFUN().contractAddress
    );
    expect(result).toEqual('0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142');
  });

  it('setFeeTo', async () => {
    const result = await uniswapPairContractFactoryPublic.setFeeTo(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xf46901ed00000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });

  it('setFeeToSetter', async () => {
    const result = await uniswapPairContractFactoryPublic.setFeeToSetter(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xa2e74af600000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });
});
Example #12
Source File: uniswap-pair-contract.factory.v2.spec.ts    From simple-uniswap-sdk with MIT License 5 votes vote down vote up
describe('UniswapPairContractFactoryV2', () => {
  const ethersProvider = new EthersProvider({ chainId: ChainId.MAINNET });

  const uniswapPairContractFactory = new UniswapPairContractFactoryV2(
    ethersProvider
  );

  it('allPairs', async () => {
    const result = await uniswapPairContractFactory.allPairs('0x01');
    expect(result).toEqual('0x3139Ffc91B99aa94DA8A2dc13f1fC36F9BDc98eE');
  });

  it('allPairsLength', async () => {
    const result = await uniswapPairContractFactory.allPairsLength();
    expect(isHexString(result)).toEqual(true);
  });

  it('createPair', () => {
    const result = uniswapPairContractFactory.createPair(
      MOCKFUN().contractAddress,
      WETHContract.MAINNET().contractAddress
    );
    expect(result).toEqual(
      '0xc9c65396000000000000000000000000419d0d8bdd9af5e606ae2232ed285aff190e711b000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
    );
  });

  it('feeTo', async () => {
    const result = await uniswapPairContractFactory.feeTo();
    expect(isHexString(result)).toEqual(true);
  });

  it('feeToSetter', async () => {
    const result = await uniswapPairContractFactory.feeToSetter();
    expect(isHexString(result)).toEqual(true);
  });

  it('getPair', async () => {
    const result = await uniswapPairContractFactory.getPair(
      WETHContract.MAINNET().contractAddress,
      MOCKFUN().contractAddress
    );
    expect(result).toEqual('0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142');
  });

  it('setFeeTo', async () => {
    const result = await uniswapPairContractFactory.setFeeTo(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xf46901ed00000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });

  it('setFeeToSetter', async () => {
    const result = await uniswapPairContractFactory.setFeeToSetter(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xa2e74af600000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });
});
Example #13
Source File: uniswap-contract.factory.public.v2.spec.ts    From simple-uniswap-sdk with MIT License 5 votes vote down vote up
describe('UniswapContractFactoryV2Public', () => {
  const uniswapContractFactoryPublic = new UniswapContractFactoryV2Public({
    chainId: ChainId.MAINNET,
  });

  it('allPairs', async () => {
    const result = await uniswapContractFactoryPublic.allPairs('0x01');
    expect(result).toEqual('0x3139Ffc91B99aa94DA8A2dc13f1fC36F9BDc98eE');
  });

  it('allPairsLength', async () => {
    const result = await uniswapContractFactoryPublic.allPairsLength();
    expect(isHexString(result)).toEqual(true);
  });

  it('createPair', () => {
    const result = uniswapContractFactoryPublic.createPair(
      MOCKFUN().contractAddress,
      WETHContract.MAINNET().contractAddress
    );
    expect(result).toEqual(
      '0xc9c65396000000000000000000000000419d0d8bdd9af5e606ae2232ed285aff190e711b000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
    );
  });

  it('feeTo', async () => {
    const result = await uniswapContractFactoryPublic.feeTo();
    expect(isHexString(result)).toEqual(true);
  });

  it('feeToSetter', async () => {
    const result = await uniswapContractFactoryPublic.feeToSetter();
    expect(isHexString(result)).toEqual(true);
  });

  it('getPair', async () => {
    const result = await uniswapContractFactoryPublic.getPair(
      WETHContract.MAINNET().contractAddress,
      MOCKFUN().contractAddress
    );
    expect(result).toEqual('0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142');
  });

  it('setFeeTo', async () => {
    const result = await uniswapContractFactoryPublic.setFeeTo(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xf46901ed00000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });

  it('setFeeToSetter', async () => {
    const result = await uniswapContractFactoryPublic.setFeeToSetter(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xa2e74af600000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });
});
Example #14
Source File: uniswap-contract.factory.v2.spec.ts    From simple-uniswap-sdk with MIT License 5 votes vote down vote up
describe('UniswapContractFactoryV2', () => {
  const ethersProvider = new EthersProvider({ chainId: ChainId.MAINNET });

  const uniswapContractFactory = new UniswapContractFactoryV2(ethersProvider);

  it('allPairs', async () => {
    const result = await uniswapContractFactory.allPairs('0x01');
    expect(result).toEqual('0x3139Ffc91B99aa94DA8A2dc13f1fC36F9BDc98eE');
  });

  it('allPairsLength', async () => {
    const result = await uniswapContractFactory.allPairsLength();
    expect(isHexString(result)).toEqual(true);
  });

  it('createPair', () => {
    const result = uniswapContractFactory.createPair(
      MOCKFUN().contractAddress,
      WETHContract.MAINNET().contractAddress
    );
    expect(result).toEqual(
      '0xc9c65396000000000000000000000000419d0d8bdd9af5e606ae2232ed285aff190e711b000000000000000000000000c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'
    );
  });

  it('feeTo', async () => {
    const result = await uniswapContractFactory.feeTo();
    expect(isHexString(result)).toEqual(true);
  });

  it('feeToSetter', async () => {
    const result = await uniswapContractFactory.feeToSetter();
    expect(isHexString(result)).toEqual(true);
  });

  it('getPair', async () => {
    const result = await uniswapContractFactory.getPair(
      WETHContract.MAINNET().contractAddress,
      MOCKFUN().contractAddress
    );
    expect(result).toEqual('0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142');
  });

  it('setFeeTo', async () => {
    const result = await uniswapContractFactory.setFeeTo(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xf46901ed00000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });

  it('setFeeToSetter', async () => {
    const result = await uniswapContractFactory.setFeeToSetter(
      '0x05B0c1D8839eF3a989B33B6b63D3aA96cB7Ec142'
    );
    expect(result).toEqual(
      '0xa2e74af600000000000000000000000005b0c1d8839ef3a989b33b6b63d3aa96cb7ec142'
    );
  });
});