简体   繁体   English

Web3:如何获取 python 中令牌的 maxTransactionAmount?

[英]Web3: How to get the maxTransactionAmount for a token in python?

Im currently working on code where i want to be able to buy what is max allowed to buy for the specific token.我目前正在编写代码,我希望能够购买特定令牌的最大允许购买量。

In the smart contract, they sometimes implements a max transaction, ie: 1% Max buy.在智能合约中,他们有时会执行最大交易,即:1% Max Buy。 How can my code detect it in a smart contract and use it as a buy parameter in the function contract.functions.swapExactETHForTokens( )?我的代码如何在智能合约中检测到它并将其用作 function contract.functions.swapExactETHForTokens( ) 中的购买参数? i imagine it would be something like,我想它会是这样的,

maxTokens = token_contract.functions.maxAllowedTransactions maxTokens = token_contract.functions.maxAllowedTransactions

then, i can use maxTokens as a parameter in the swapExactETH.. function.然后,我可以使用 maxTokens 作为 swapExactETH 中的参数。function。 I have tried googling around but i havent encountered anything similar.我试过用谷歌搜索,但我没有遇到类似的事情。

Thanks!谢谢!

I assume you are talking about uniswap v3/v2.我假设您在谈论 uniswap v3/v2。 There is no "max amount".没有“最大数量”。 The percentage you are referring to is the slippage amount which is represented as the variable amountOutMin in the swapExactETHForTokens function.您所指的百分比是滑点量,它表示为amountOutMin中的变量swapExactETHForTokens This parameter is the minimum amount that you are willing to receive for x amount of ETH.此参数是您愿意为 x 数量的 ETH 获得的最低金额。

If you don't care about slippage then you can set amountOutMin to be equal to 0. You will likely get frontrun by MEV bots if you do this though.如果您不关心滑点,则可以将amountOutMin设置为 0。如果您这样做,您可能会被 MEV 机器人抢先。

The true maximum amount of a token that you can buy is the total amount of the tokens in the pool that you are swapping in. If a pool has 50 Buttcoins and 30 Dog coins, then you can buy a maximum of 30 dog coins for an infinite amount of Buttcoins.您可以购买的代币的真正最大数量是您要换入的池中代币的总数量。如果池中有 50 个 Buttcoins 和 30 个 Dog 币,那么您最多可以购买 30 个 Dog 币一个无限数量的比特币。 Based on the swap formula of:基于掉期公式:

buttcoin amount = 50 Butt / (30 Dog - 30 Dog) = infinity

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM