Created
April 3, 2021 01:05
-
-
Save yuyasugano/6801fe9835cddf448d9a38cbfb3aeba6 to your computer and use it in GitHub Desktop.
Flash Swaps callback
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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