Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Are testnets supported?#151

WhoisAV started this conversation inGeneral
Aug 10, 2021· 1 comments· 8 replies
Discussion options

Thanks for such a helpful module! It works like a charm on the mainnet but I am trying to run some testing on either of the testnets and get the same error over and over:

---------------------------------------------------------------------------ContractLogicError                        Traceback (most recent call last)<ipython-input-14-0f06b5397729> in <module>     10 dai =  Web3.toChecksumAddress("0xc715abcd34c8ed9ebbf95990e0c43401fbbc122d")     11 ---> 12 print(uniswap.get_price_input(bat, dai, 10**18), route=[eth, dai])     13 print(uniswap.get_price_output(bat, dai, 10**18), route=[eth, dai])~/anaconda3/lib/python3.8/site-packages/uniswap/uniswap.py in get_price_input(self, token0, token1, qty, fee, route)    174             return self._get_token_eth_input_price(token0, qty, fee)    175         else:--> 176             return self._get_token_token_input_price(token0, token1, qty, fee, route)    177     178     def get_price_output(~/anaconda3/lib/python3.8/site-packages/uniswap/uniswap.py in _get_token_token_input_price(self, token0, token1, qty, fee, route)    262             # FIXME: How to calculate this properly? See https://docs.uniswap.org/reference/libraries/SqrtPriceMath    263             sqrtPriceLimitX96 = 0--> 264             price = self.quoter.functions.quoteExactInputSingle(    265                 token0, token1, fee, qty, sqrtPriceLimitX96    266             ).call()~/anaconda3/lib/python3.8/site-packages/web3/contract.py in call(self, transaction, block_identifier, state_override)    955         block_id = parse_block_identifier(self.web3, block_identifier)    956 --> 957         return call_contract_function(    958             self.web3,    959             self.address,~/anaconda3/lib/python3.8/site-packages/web3/contract.py in call_contract_function(web3, address, normalizers, function_identifier, transaction, block_id, contract_abi, fn_abi, state_override, *args, **kwargs)   1499     )   1500 -> 1501     return_data = web3.eth.call(   1502         call_transaction,   1503         block_identifier=block_id,~/anaconda3/lib/python3.8/site-packages/web3/module.py in caller(*args, **kwargs)     55             return LogFilter(eth_module=module, filter_id=err.filter_id)     56         result_formatters, error_formatters, null_result_formatters = response_formatters---> 57         result = w3.manager.request_blocking(method_str,     58                                              params,     59                                              error_formatters,~/anaconda3/lib/python3.8/site-packages/web3/manager.py in request_blocking(self, method, params, error_formatters, null_result_formatters)    185         """    186         response = self._make_request(method, params)--> 187         return self.formatted_response(response,    188                                        params,    189                                        error_formatters,~/anaconda3/lib/python3.8/site-packages/web3/manager.py in formatted_response(self, response, params, error_formatters, null_result_formatters)    165     ) -> Any:    166         if "error" in response:--> 167             apply_error_formatters(error_formatters, response)    168             raise ValueError(response["error"])    169         elif response['result'] in NULL_RESPONSES:~/anaconda3/lib/python3.8/site-packages/web3/manager.py in apply_error_formatters(error_formatters, response)     65 ) -> RPCResponse:     66     if error_formatters:---> 67         formatted_resp = pipe(response, error_formatters)     68         return formatted_resp     69     else:~/anaconda3/lib/python3.8/site-packages/cytoolz/functoolz.pyx in cytoolz.functoolz.pipe()~/anaconda3/lib/python3.8/site-packages/cytoolz/functoolz.pyx in cytoolz.functoolz.c_pipe()~/anaconda3/lib/python3.8/site-packages/web3/_utils/method_formatters.py in raise_solidity_error_on_revert(response)    555     # Geth Revert without error message case:    556     if 'execution reverted' in response['error'].get('message'):--> 557         raise ContractLogicError('execution reverted')    558     559     return responseContractLogicError: execution reverted`

The code that generates it is this one:

# Ropstenaddress = None         # or None if you're not going to make transactionsprivate_key = None     # or None if you're not going to make transactionsversion = 3                   # specify which version of Uniswap to useprovider = "https://ropsten.infura.io/v3/xxxxxxxxxxxxxxxxx"    # can also be set through the environment variable `PROVIDER`uniswap = Uniswap(address=address, private_key=private_key, version=version, provider=provider)eth =  Web3.toChecksumAddress("0xac7fa82f7b2937b0714a61c84fa9902224ad5a65")bat =  Web3.toChecksumAddress("0xe43a8b1bfd19721e918b6068c158bf8fab41abee")dai =  Web3.toChecksumAddress("0xc715abcd34c8ed9ebbf95990e0c43401fbbc122d")print(uniswap.get_price_input(bat, dai, 10**18), route=[eth, dai])print(uniswap.get_price_output(bat, dai, 10**18), route=[eth, dai])

Is this due to the module not being implemented for the testnets?

Thank you!

You must be logged in to vote

Replies: 1 comment 8 replies

Comment options

The common testnets should work fine, but the token contracts you're looking up might not exist there.

You must be logged in to vote
8 replies
@WhoisAV
Comment options

Hey@ErikBjare, could you provide a simple example of the code running on a testnet?

Basically, we got the code running fine on mainnet but not at all on any of the testnets. Here is a sample code that runs fine on mainnet:

# Mainnetaddress = None         # or None if you're not going to make transactionsprivate_key = None     # or None if you're not going to make transactionsversion = 3                   # specify which version of Uniswap to useprovider = "https://mainnet.infura.io/v3/09f0fcddd344415081c2d2db1e953eb0"    # can also be set through the environment variable `PROVIDER`uniswap = Uniswap(address=address, private_key=private_key, version=version, provider=provider)eth = "0x0000000000000000000000000000000000000000"bat = "0x0D8775F648430679A709E98d2b0Cb6250d2887EF"dai = "0x6B175474E89094C44Da98b954EedeAC495271d0F"print(uniswap.get_price_input(eth, dai, int(10**18), route=[eth, dai]))print(uniswap.get_price_output(eth, dai, int(10**18), route=[eth, dai]))

Same code, on Rinkeby crashes:

# Rinkebyaddress = None         # or None if you're not going to make transactionsprivate_key = None     # or None if you're not going to make transactionsversion = 3                 # specify which version of Uniswap to useprovider = "https://rinkeby.infura.io/v3/09f0fcddd344415081c2d2db1e953eb0"    # can also be set through the environment variable `PROVIDER`uniswap = Uniswap(address=address, private_key=private_key, version=version, provider=provider)eth =  Web3.toChecksumAddress("0x55a7154f49b046693a7c90e7bcf99ca8268fa0bf")bat =  Web3.toChecksumAddress("0xe43a8b1bfd19721e918b6068c158bf8fab41abee")dai =  Web3.toChecksumAddress("0x569aaff8f90a5e48b27c154249ee5a08ed0c44e2")print(uniswap.get_price_input(bat, dai, int(10**18)), route=[bat, dai])print(uniswap.get_price_output(bat, dai, int(10**18)), route=[bat, dai])

The addresses exist on the testnet as follows:
https://rinkeby.etherscan.io/token/0x55a7154f49b046693a7c90e7bcf99ca8268fa0bf
https://rinkeby.etherscan.io/token/0xe43a8b1bfd19721e918b6068c158bf8fab41abee
https://rinkeby.etherscan.io/token/0x569aaff8f90a5e48b27c154249ee5a08ed0c44e2

So the issue is how the testnets are handled.

Also, for the mainnet, you can pass the address as either a string or a checksum address and it resolves it properly while for testnets it requires you to enter a checksum address only. This makes me think that there are 2 separate implementations for mainnet vs testnet.

Finally, for theget_price_output() function the example says that it returns the amount of ETH you need to pay (in wei) to get 1000 DAI and the parameters should be as follows:uniswap.get_price_output(eth, dai, 1_000 * 10**18) but the example is not running unless you swap the order of eth and dai. This seems to be a bug ar at least a documentation mismatch.

Like I mentioned in the beginning, a sample testnet implementation would be really useful!

@liquid-8
Comment options

Talking about v3: beside token contracts you need pool's contract to get prices. Here is V3Factory@rinkeby

https://rinkeby.etherscan.io/address/0x1f98431c8ad98523631ae4a59f267346ea31f984

Its txns are pools that are active at this testnet. You might use them for your test or you can create your own if you need. To see which tokens are pooled and fee value just click "decode input data" inside txn. As far as I can see there is nor V3 eth-dai pool@ropsten neither V3 bat-dai pool@rinkeby at this moment. It's about all the same for v2 btw.

@ErikBjare
Comment options

@liquid-8 The contract addresses should be the same as the mainnet addresses for Uniswap V3 contracts (so no overriding necessary), see:https://github.com/Uniswap/uniswap-v3-periphery/blob/main/deploys.md

But yeah, it's likely that the pools@WhoisAV is trying to use simply don't exist on the testnet (or don't have liquidity, etc).

@WhoisAV If you want to run tests/experiment, I recommend you do as we do in our tests and run off a fork of mainnet with ganache. That way, you won't have to deal with some of the differences between testnet and mainnet.

@WhoisAV
Comment options

Ok, it all makes sense now! I haven't used Ganache before, do you guys have any documentation to point to to get started and connect it with your module? I'd assume it would somehow be through the provider url?

@liquid-8
Comment options

https://www.trufflesuite.com/docs/ganache/quickstart

I'd assume it would somehow be through the provider url?

Yeah, just specify RPC server as provider url.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
General
Labels
None yet
4 participants
@WhoisAV@ErikBjare@liquid-8@sweeta20793

[8]ページ先頭

©2009-2025 Movatter.jp