0

Apparently it's possible to take a flash loan on PancakeSwap, being that it's a fork of Uniswap. However, I haven't found any examples anywhere of a flash loan on PancakeSwap, nor do the docs mention it anywhere.

What's the simplest example of a contract taking a flash loan from PancakeSwap?

The flash loan would:

  1. Borrow a certain amount of some token (say CAKE) from PancakeSwap
  2. Pay back the required amount of the token
0

PancakeSwap is a fork of UniswapV2, which allows flashloans. An example of flashloans using Uniswap V2 can be found here: https://github.com/Uniswap/uniswap-v2-periphery/blob/master/contracts/examples/ExampleFlashSwap.sol

it is invoked by calling the swap function of the Uniswap V2 pair you wish to take the loan from. It originates from this line in the UniswapV2Pair.sol contract(source: https://github.com/Uniswap/uniswap-v2-core/blob/master/contracts/UniswapV2Pair.sol):

if (data.length > 0) IUniswapV2Callee(to).uniswapV2Call(msg.sender, amount0Out, amount1Out, data);

In pancake everything is the same, except instead of a call to function named UniswapV2Call, the pancake contract will call a contract named pancakeCall

if (data.length > 0) IPancakeCallee(to).pancakeCall(msg.sender, amount0Out, amount1Out, data);

All you need to do is change the the function header in your FlashLoan Receiver method from this:

function uniswapV2Call(address sender, uint amount0, uint amount1, bytes calldata data) external override { ... }

to this

function pancakeCall(address sender, uint amount0, uint amount1, bytes calldata data) external override { ... }

Edit: link to the pancakeswap pool contract here: https://github.com/pancakeswap/pancake-swap-core/blob/master/contracts/PancakePair.sol

you will need to specify the address of the pool you wish to take the loan from

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.