Skip to content

Fail with error 'Pancake: K' on FeeOnTransfer token #130

Closed

Description

@LucaZanatta

Here is my code

`from uniswap import Uniswap
from web3 import Web3
from decimal import *

wallet_address = "xxx"
private_key = "yyy"
address = Web3.toChecksumAddress(wallet_address)
version = 2

bsc = "https://bsc-dataseed.binance.org/"
web3 = Web3(Web3.HTTPProvider(bsc))
print(web3.isConnected())
uniswap = Uniswap(address=address, private_key=private_key, version=version, web3=web3, default_slippage=.5)

wbnb = "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c"
token = "0xa872960bc3393b2a19aa1e784ab7f385d543ce37"

wbnb_w = Web3.toChecksumAddress(wbnb)
token_w = Web3.toChecksumAddress(token)

qty = int(.01 * 10**18)
decimals_wbnb = uniswap.get_token(wbnb_w).decimals
decimals_token = uniswap.get_token(token_w).decimals

uniswap.make_trade(wbnb_w, token_w, qty) # THIS WORKS

qty_token = uniswap.get_token_balance(token_w)
print(qty_token)

uniswap.make_trade(token_w, wbnb_w, qty_token) # DOESN'T WORK
`

In this link, it's written that the problem can be slippage.
https://www.followchain.org/pancake-k-pancakeswap/

Here there is the transaction
https://bscscan.com/tx/0x472895b975f80c38c9bc87f29902ab35add7f312b64ead6c2b20fffbf8a04c61

I already saw that slippage is not tested. My question is: there are some problems in my code, or it can be a problem of slippage?

I apologize if the problem is trivial, but I'm just beginning :D

Activity

  1. liquid-8 commented on Jul 3, 2021

    @liquid-8
    Member

    First, it would be nice if you close issue that has been solved already.

    Regarding your problem, it is BSC. This network has technical issues, sad but true. Pancakeswap is uniswapV2's clone so the library itself works totally fine. Your problem isn't about slippage implementation in this project, it is about BSC network organization. I'd consider picking suitable slippage value. I have to note that default_slippage=.5 means 50% slippage and I doubt it's OK. Also you can try to swap just some part of the token's balance not the exactly whole one.

  2. LucaZanatta commented on Jul 3, 2021

    @LucaZanatta
    Author

    Okay, I apologize. I have now closed the other issue.

    Ok, thanks for your explanation.
    Actually, I had tried 1%, 5%, 12%, 20% and 50% but it always gave me back the same error.
    I also tried to swap less token balance, but it works only if I swap "1 digit" of the token (1 to 9 tokens), from 10 tokens the error occurs.

  3. liquid-8 commented on Jul 4, 2021

    @liquid-8
    Member

    I got it. Token you're going to swap has fees on transfer. It requires swapExactTokensForETHSupportingFeeOnTransferTokens() or swapExactTokensForTokensSupportingFeeOnTransferTokens() to be implemented. When you're trying to swap extra small amounts there are just no fees. So swapExactTokensForETH() works fine and fails otherwise. Usual tokens should swap correctly. Can't promise but I'm going to add that in few days OR you can add it yourself. In before "how do I determine if contract has these fees": this "swap: K" error might be caused by inappropriate contract calls too.

  4. LucaZanatta commented on Jul 5, 2021

    @LucaZanatta
    Author

    Sorry, but I don't know python well enough, so if you were to do this, you'd be doing me a huge favour. Should I close the issue?

  5. liquid-8 commented on Jul 5, 2021

    @liquid-8
    Member

    Still not, I'd pushed PR for this issue. I'll let you know what to do after merge.

  6. ErikBjare commented on Jul 7, 2021

    @ErikBjare
    Member

    Implemented in #132. Will be in the next release.

  7. changed the title [-]Fail with error 'Pancake: K'[/-] [+]Fail with error 'Pancake: K' on FeeOnTransfer token[/+] on Jul 7, 2021
  8. liquid-8 commented on Jul 8, 2021

    @liquid-8
    Member

    @LucaZanatta

    qty_token = uniswap.get_token_balance(token_w)
    print(qty_token)

    uniswap.make_trade(token_w, wbnb_w, qty_token) # DOESN'T WORK

    So, just update uniswap-python and then this part of code should be

    qty_token = uniswap.get_token_balance(token_w)
    print(qty_token)
     
    uniswap.make_trade(token_w, wbnb_w, qty_token, fee_on_transfer = True) #HAVE TO WORK
    

    Feel free to ask questions if something go wrong.

  9. LucaZanatta commented on Jul 8, 2021

    @LucaZanatta
    Author

    It works fine! Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions