Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Created April 3, 2021 01:05
Show Gist options
  • Save yuyasugano/6801fe9835cddf448d9a38cbfb3aeba6 to your computer and use it in GitHub Desktop.
Save yuyasugano/6801fe9835cddf448d9a38cbfb3aeba6 to your computer and use it in GitHub Desktop.
Flash Swaps callback
function pancakeCall(address sender, uint amount0, uint amount1, bytes calldata data) {
address token0 = IUniswapV2Pair(msg.sender).token0(); // fetch the address of token0
address token1 = IUniswapV2Pair(msg.sender).token1(); // fetch the address of token1
assert(msg.sender == IUniswapV2Factory(factoryV2).getPair(token0, token1)); // ensure that msg.sender is a V2 pair
// rest of the function goes here!
...
// transfer tokens to reimburse the required amount for swap
IERC20(token1).transfer(msg.sender, amountRequired);
// transfer tokens to an address who receives an arbitrage profit
IERC20(token1).transfer(owner, amountReceived.sub(amountRequired));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment