Man I am pulling my hair out one at a time! Can someone save me from days of googling and ending up with no further answer? All I want to know is how to trigger Uniswap or any AMM to call this function 'swapExactTokensForTokensSupportingFeeOnTransferTokens' when user wants to sell my token via the Uniswap/Pancakeswap/Sushiswap UI. How does uniswap know that my token takes fees and then call that fee function instead of the regular one? Where do I tell it to do that in my code?? Why is this so complicated 😤😤🤬🤬
Jan 21, 2022, 11:29 PM
I shared your mood friend
Jan 22, 2022, 4:14 AM
Pancakeswap SDK repo contains router.ts. The file contains swapCallParameters function that is called by the frontend (src/hooks/useSwapCallback.ts). Depending on there is fee or not
Jan 22, 2022, 4:45 AM
Guys, does anyone have a unit test on adding liquidity to a fork (bsc/eth)? I'm trying to do it and I get a TRANSFER_FROM error.
> The pair is created with no problem, I get wbnb from the mainnet to have balance on the main account, I approve the router but still get that error.
> The pair is created with no problem, I get wbnb from the mainnet to have balance on the main account, I approve the router but still get that error.
Jan 22, 2022, 4:46 AM
Yes this hook I've looked at through Uniswap github. After digging more into the frontend of uniswap it seems the trade.type needs to equal "EXACT_INPUT". I think the reason for that is that the input will be exact on input but after recalculating the reserves/balances after fees are take the output will be different. Either way this is the other function that sets the trade type and ultimately the correct feesontransfer function:
/**
* Constructs an exact in trade with the given amount in and route
* @param route route of the exact in trade
* @param amountIn the amount being passed in
*/
public static exactIn(route: Route, amountIn: CurrencyAmount, chainId: ChainId): Trade {
return new Trade(route, amountIn, TradeType.EXACT_INPUT, chainId)
}
/**
* Constructs an exact in trade with the given amount in and route
* @param route route of the exact in trade
* @param amountIn the amount being passed in
*/
public static exactIn(route: Route, amountIn: CurrencyAmount, chainId: ChainId): Trade {
return new Trade(route, amountIn, TradeType.EXACT_INPUT, chainId)
}
And just to be clear I am no where closer to figuring out how UniswapV2 triggers the correct function call for tokens that require fees taken on them 😤
This is definitely an approval issue as I used to get the same error code many times and it was always something going wrong with my approve statement
Jan 22, 2022, 5:03 AM
I tried to approve everything and it returns the same error 😅
Jan 22, 2022, 5:05 AM
a clear walkthrough on uniswap v2 is helpful
https://ethereum.org/en/developers/tutorials/uniswap-v2-annotated-code/
Jan 22, 2022, 5:07 AM
my approvals
Jan 22, 2022, 5:07 AM
hmm not sure mate. Google addliquidity transferhelper: transfer_from_failed. It's quite common and lots of troubleshoots to sift through for you
Jan 22, 2022, 5:12 AM
Thanks Sam, before coming to ask the group I have checked from A to Z google, I don't ask for help at first
Jan 22, 2022, 5:13 AM
Thanks. I need to start at the bottom again and work my way up the mountain using a different path
I hear you. Sadly I am not really working with web3 yet. Mainly just testing solidity contracts and learning using remix so can't help you but good luck mate
Jan 22, 2022, 5:14 AM
No...the blog just explained each part of code..clearly...there won't be a different path mate
Jan 22, 2022, 5:14 AM
Yeah but I have been making assumptions on how uniswap works just from being a user but now I am reading that blog and it is telling me the control flow which I did not know before so for sure I can see maybe a different path here to approach the problem than what I was banging my head with these last few days. Hope that makes sense friend
Jan 22, 2022, 5:16 AM
Yeah👍
Jan 22, 2022, 5:16 AM
Thanks Sam dont worry ^^!
Jan 22, 2022, 5:17 AM
Do you find solution ?
Jan 22, 2022, 8:24 AM
do you have wbnb?
or just Bnb?
Jan 22, 2022, 9:06 AM
Below the button auto compile...switch on optimization
Jan 22, 2022, 11:01 AM
I impersonate the wbnb address to send to me 500 wbnb so my account have wbnb
Jan 22, 2022, 2:21 PM
What are you using is it ganache or hardhat?
Nope that's not possible as it is not a static function of those variables it is generated by abis and as they are based on abis tabnine/copilot cannot get them
The best way is to use them a few times till tabnine generates some variables based on your previous usages
That's how I do it 😂
Jan 22, 2022, 3:03 PM
Hardhat with bsc mainnet fork
Jan 22, 2022, 3:42 PM
change your wallet bal swap bnb for wbnb and then try ig Or why not try adding liq with bnb?
Jan 22, 2022, 3:43 PM
you refer to addLiquidityEth?
Jan 22, 2022, 4:27 PM
Yes
Jan 22, 2022, 4:29 PM
I've tried, I've tried some things too but the error is persistent.
Jan 22, 2022, 5:57 PM
How are you modifying your bnb bal?
I've tried alot of times and it works always
Jan 22, 2022, 5:58 PM
Im using the ETH bal as BNB im wrong?
I tried to have wbnb balance too
@Voidcoder maybe if because im using a fork? Im not running the uni/pancake router/factory through internal deploy
Jan 22, 2022, 6:03 PM
I can't under why you are doing so
which is your aim
Jan 22, 2022, 6:08 PM
Im trying to createPair, addLiquidity and test swaps on (Tests)
Jan 22, 2022, 6:09 PM
you could fork mainnet and test with pancake router no?
Jan 22, 2022, 6:44 PM
Yep i can interact with the router/factory without any problem
as you can see i impersonate the wbnb and use it without any problem, the problem is creating the pair and adding liquidity
here es some of the prints that i share here
I tried to send tokens to the liquidity new pair address and i get pancakeswap error input amount
Jan 22, 2022, 11:11 PM
At the first, You swap token to wbnb ?
Jan 22, 2022, 11:12 PM
No im not swapping at the moment, i createPair then i approve and later i tried to addLiquidity
Jan 22, 2022, 11:13 PM
Do you have X token and WBnB on acc?
Jan 22, 2022, 11:14 PM
yep
Jan 22, 2022, 11:15 PM
Or you have token in contract address ? And wbnb on your account?
You deploy token, mint to your account then create pair
Right?
Right?
Jan 22, 2022, 11:16 PM
I have token in my account and wbnb in my account
I am creating the pair in Js, not through the token contract.
Jan 22, 2022, 11:18 PM
😯
Jan 22, 2022, 11:19 PM