Uniswap

如何在 Uniswap-Python 函式 uniswap.get_price_input() 中設置費用?

  • November 23, 2021

我成功地使用 uniswap.get_price_input(eth, dai, 10**18) 來獲取 ETH/DAI 對的價格。此外,我在終端中收到消息“未設置費用,假設為 0.3%”。

我想刪除該消息並將費用設置為 0.3%,但會收到各種錯誤,具體取決於我的嘗試。

嘗試 1

>>>uniswap.get_price_input(eth, dai, 10**18, .3)

>>>Could not identify the intended function with name `quoteExactInputSingle`, positional argument(s) of type `(<class 'str'>, <class 'str'>, <class 'float'>, <class 'int'>, <class 'int'>)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `quoteExactInputSingle`: ['quoteExactInputSingle(address,address,uint24,uint256,uint160)']
Function invocation failed due to no matching argument types.

嘗試 2

>>>uniswap.get_price_input(eth, dai, 10**18, int(.3))


>>>raise ContractLogicError('execution reverted')
>>>web3.exceptions.ContractLogicError: execution reverted

嘗試 3

>>>uniswap.get_price_input(eth, dai, 10**18, fee=.3)

>>>Could not identify the intended function with name `quoteExactInputSingle`, positional argument(s) of type `(<class 'str'>, <class 'str'>, <class 'float'>, <class 'int'>, <class 'int'>)` and keyword argument(s) of type `{}`.
Found 1 function(s) with the name `quoteExactInputSingle`: ['quoteExactInputSingle(address,address,uint24,uint256,uint160)']
Function invocation failed due to no matching argument types.

供參考:get_price_input(token0: Union

$$ Address, ChecksumAddress $$, token1: 聯合$$ Address, ChecksumAddress $$,數量:int,費用:可選$$ int $$= 無,路線:可選$$ List[Union[Address, ChecksumAddress $$]] = 無) → int 你如何設置費用?

將 0.3 轉換為 int 將返回 0。

如果您檢查函式原型,0.3% 的預設費用被傳遞為 3000,因此這是您應該使用的值。

引用自:https://ethereum.stackexchange.com/questions/114153