Skip to main content
Share Your Experience: Take the 2024 Developer Survey
19 votes

Understand price impact and liquidity in pancakeswap

Disclaimer: I don't think this is the correct method to calculate the price impact but it's almost 100% accurate for price impacts of less than 1%. This calculation method assumes that multi-hop is ...
vlj614's user avatar
  • 396
8 votes
Accepted

Fail with error 'TransferHelper: TRANSFER_FROM_FAILED' even approved in contract

The issue is that you need to approve the pair and not the router. Looking at the transaction you linked you can see that it revert on the transfer from 0xa89C6f52Ce3Ce1BFF6CAac1E1c98b4f9b3AA5f63 (...
Richard's user avatar
  • 4,994
7 votes
Accepted

Finding a Pair Contract on PancakeSwap

you're looking at the different PancakeSwap contracts versions. Example: PancakeRouter V1 - 0x05ff2b0db69458a0750badebc4f9e13add608c7f PancakeFactory V1 - 0xbcfccbde45ce874adcb698cc183debcf17952812 ...
Miroslav Nedelchev's user avatar
6 votes
Accepted

understanding the Swap function in pancakeSwap Pair contract

balance0 and balance1 are local variables of functions mint, burn and swap while reserve0 and reserve1 are globally declared variables. why there is a need for computing balance and reserve? As ...
hack3r-0m's user avatar
  • 1,919
5 votes
Accepted

Token Price from pancakeswap

You do not need to go through this hassle, you can use getAmountsOut on the PancakeSwap router contract to make this a lot simpler. You provide a path&amount of the first token in the path to use, ...
bru53001's user avatar
  • 721
5 votes

Call swapExactETHForTokens from contract and pay with contract balance

You should be able to achieve that if you send the ether along the function call. In solc v0.8 you achieve that using the function call options {value: amount}. The resulting function should look like ...
Ismael's user avatar
  • 30.5k
5 votes
Accepted

How to create a liquidity pool by code?

Since the you (the contract) are adding ETH/Token as liquidity, your function needs to be marked as internal/private. Additionally, you need to give the PancakeRouter02an allowance to spend at least ...
Smye's user avatar
  • 491
5 votes
Accepted

Testing Token with Uniswap liquidity provisioning using hardhat

It sounds like you're facing one of two problems - either you're using a local dev chain and haven't deployed Uniswap to it, or you're using a testing fork of a chain, and haven't told your test suite ...
Linum Labs's user avatar
  • 1,448
4 votes
Accepted

where can i find the addresses of the pancakeswap coin pairs smart contracts

The factory contract - PancakeFactory - is here: https://bscscan.com/address/0xcA143Ce32Fe78f1f7019d7d551a6402fC5350c73 If you read the contract, you'll see that allPairsLength gives you 14,690 pairs. ...
Richard Horrocks's user avatar
4 votes

understanding the Swap function in pancakeSwap Pair contract

Here is the TL;DR version. Q1 balance0 and balance1 vs reserve0 and reserve1 reserve0 and reserve1 are the balances of each tokens in the pair contract just before the swap transaction is processed. ...
Undead8's user avatar
  • 3,610
3 votes
Accepted

An unlocked wallet is holding 100% of <PAIR> LP

It means the owner can rug pull(remove liquidity, steal everyone's investment, and make the token valueless) any time. That is why that prompt exists. Locks are commonly done on DxSale and Poocoin ...
bru53001's user avatar
  • 721
3 votes

What are the Pancakeswap "*SupportingFeeOnTransfer" methods for?

For anything like this, it's always best to refer to the original documentation... which exists on Uniswap site. PancakeSwap didn't seem bothered about copying the actual documentation, unlike ...
Richard Horrocks's user avatar
3 votes

How to conduct a flash loan on PancakeSwap?

PancakeSwap is a fork of Uniswap V2, which allows flashswaps. An example of flashswap using Uniswap V2 can be found here: https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/examples/...
Alexander Barry's user avatar
3 votes
Accepted

How To Read LP Tokens Held By Address After Being Staked On Pancakeswap

After spending some time looking into other projects that show this information I discovered the way to find it is by executing a function called userInfo on the main PancakeSwap Staking contract: ...
simoes's user avatar
  • 141
3 votes
Accepted

Solidity function can't sell with slippage on Pancakeswap

That's because for these tokens you need to call swapExactTokensForETHSupportingFeeOnTransferTokens or swapExactETHForTokensSupportingFeeOnTransferTokens. You can always use these method instead of ...
Kof's user avatar
  • 2,954
2 votes

Unable to understand master-chef contract in pancake-swap

Dev Address - Some percentage of cake minted is sent to the dev address. For every 100 cake, 10 is sent to dev address. The dev address will then burn it. Update pool fn - Straight forward, it is ...
Mohamed Sohail's user avatar
2 votes

Understanding front running. Why did my transaction fail? (PancakeSwap V2)

There's no predefined order for transactions in a block. The only requirement is for transactions from the same address to be sorted by the transaction's nonce but transactions from different ...
Ismael's user avatar
  • 30.5k
2 votes

Failing to add liquidity to pancakeswap on bsc testnet

Yes, I believe this problem is due to the deadline parameter of the addLiquidity method. In your tx you have submitted a deadline of 7741799 which corresponds (https://www.epochconverter.com/) to ...
lobis's user avatar
  • 145
2 votes

An unlocked wallet is holding 100% of <PAIR> LP

If it says: An unlocked wallet is holding 100% of the lp. This means that the owner of the token can at any time get his liquidity and devalue the token. Therefore, you need to block liquidity, for ...
Artem's user avatar
  • 41
2 votes
Accepted

swapExactTokensForTokens ignore amountOutMin parameter

The AMM is only checking that it is sending you the amountOutMin, not that you are receiving it. In other words, it calls a transfer for that token for an amount greater than or equal amountOutMin. ...
Undead8's user avatar
  • 3,610
2 votes
Accepted

How to understand the constant product formula?

The product k would actually be constant, if the swap fee was 0%. Since AMMs usually have a fee, the product of the reserves is not really a constant in practice. The name ‘constant product market’ ...
pwagner's user avatar
  • 910
2 votes

What's the relationship between LP reserves and Swap rate?

amount_in=14067900000000 amount_out=393017164305296368 reserve0=95594454080845 reserve1=3070347989941780637 amount_in_with_fee=amount_in*998-14067900000000*0.5 numerator=amount_in_with_fee*reserve1 ...
Gajus's user avatar
  • 713
2 votes

What does a Swap event describe when amount0In and amount0Out are non-0, but amount1In and amount1Out are zero?

After analyzing the contract interactions and the account history it isn't a regular trade. It appears to be a bot farming rewards then interacting with other pools. It initially get 0.1046 WBNB as ...
Ismael's user avatar
  • 30.5k
2 votes

Getting the balance of a token in wallet - decimal issue

ethers.utils.formatEther uses decimals as 18. Though most of popular ERC20 tokens out there use 18 decimals, there are some ERC20s that can use a different decimal value, like in your case it appears ...
Soham Zemse's user avatar
  • 2,041
2 votes
Accepted

Is this smart contract code malicious?

TL;DR Yes, it's a scam. The functions used are hidden in the Manager object imported with this line import "ipfs://Qmf5Ua79ZT8ERFa9q32fQtGuWkqk1eZXxnzRdeTi6wvzUy". I cannot see that code, ...
Undead8's user avatar
  • 3,610
2 votes

Is there a way to convert Binance pegged tokens into Ethereum based tokens?

I think the main "problem" here is that BSC is derived from Ethereum - they use the same EVM code (Ethereum Virtual Machine) in the background. Therefore they also have the same underlying ...
Lauri Peltonen's user avatar
2 votes

Check valid slippage before sending transaction using web3

Currently, ERC-20 tokens do not expose interface expose transaction fees. Only thing you can find these out is by checking them by hand. Also, taking fee on transfer() does not fit to ERC-20 token ...
Mikko Ohtamaa's user avatar
2 votes
Accepted

Retrieving APY from PancakeSwap CAKE auto-compounding pool

https://github.com/gaijinjoe/cake-liquidity/blob/7ae59f159d09dc3560b294ce8d19955a56f401e5/borrow-limit-status.js#L233 Here you go. Call it like this: const autoAPY = compoundInterest(1, ...
Joe's user avatar
  • 36
2 votes

How can we fetch the current market price to our DEX?

You can get price of BNB/BUSD using getAmountsOut method //one WBNB in Wei const oneWBNB = '1000000000000000000'; const WBNB = '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'; const BUSD = '...
M M's user avatar
  • 57
2 votes

What happens when disconnect my wallet from Pancakeswap

Just by connecting your wallet, most websites will just see your wallet address and require your permission before signing a transaction. Unless you connect to a shady site which asks for transaction ...
bru53001's user avatar
  • 721

Only top scored, non community-wiki answers of a minimum length are eligible