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 |
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 startArbitrage( | |
address token0, | |
address token1, | |
uint amount0, | |
uint amount1 | |
) external { | |
address pairAddress = IUniswapV2Factory(pancakeFactory).getPair(token0, token1); | |
require(pairAddress != address(0), 'This pool does not exist'); | |
IUniswapV2Pair(pairAddress).swap( |
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
pragma solidity ^0.5.0; | |
import "./base/FlashLoanReceiverBase.sol"; | |
import "./interfaces/ILendingPoolAddressesProvider.sol"; | |
import "./interfaces/ILendingPool.sol"; | |
contract Flashloan is FlashLoanReceiverBase { | |
address public receiver = address(this); | |
address public constant BNB_ADDRESS = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; |
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
// See https://multiplierfinance.medium.com/multi-chain-lend-protocol-is-live-on-bsc-5003735e3c18 | |
// The official address should not change once deployed | |
ILendingPoolAddressesProvider public addressesProvider = | |
ILendingPoolAddressesProvider(address(0xcc0479a98cc66e85806d0cd7970d6e07f77fd633)); |
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
>> JPYC.deploy({'from': accounts[0]}) | |
Transaction sent: 0xcb24ddc2d7e7387549ddd1706c86bf0ec7de7cc627976dd5e0c1b17a8ed2eb3d | |
Gas price: 1.0 gwei Gas limit: 1428853 Nonce: 52 | |
JPYC.constructor confirmed - Block: 8152507 Gas used: 1298958 (90.91%) | |
JPYC deployed at: 0xbD9c419003A36F187DAf1273FCe184e1341362C0 |
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
$ export WEB3_INFURA_PROJECT_ID=<Rinkeby INFURA PROJECT ID> | |
$ brownie console --network rinkeby | |
Brownie v1.12.4 - Python development framework for Ethereum | |
JpycRinkebyProject is the active project. | |
Brownie environment is ready. | |
>>> accounts.add('<your private key>') | |
>>> con = PriceConsumerV3.deploy({'from': accounts[-1]}) | |
Transaction sent: 0x46b76bd13ceeb137066c01709a9e60201b4d4c0e49bbbd942b5bdb4953e54277 | |
Gas price: 1.0 gwei Gas limit: 244127 Nonce: 51 |
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
import pytest | |
import click | |
configurations = { | |
'dai': {'token': '0x6b175474e89094c44da98b954eedeac495271d0f', 'whale': '0x70178102AA04C5f0E54315aA958601eC9B7a4E08'}, | |
'usdt': {'token': '0xdac17f958d2ee523a2206206994597c13d831ec7', 'whale': '0x1062a747393198f70f71ec65a582423dba7e5ab3'}, | |
'usdc': {'token': '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', 'whale': '0xa191e578a6736167326d05c119ce0c90849e84b7'}, | |
} | |
# isolation fixture for each function, takes a snapshot of the chain |
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
import pytest | |
import click | |
# isolation fixture for each function, takes a snapshot of the chain | |
@pytest.fixture(scope='function', autouse=True) | |
def isolation(fn_isolation): | |
pass | |
def test_flashloan_aave1(accounts, interface, chain, Flashloan): | |
# prepare accounts |
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
// This is the function that will be called postLoan | |
// i.e. Encode the logic to handle your flashloaned funds here | |
function callFunction( | |
address sender, | |
Account.Info memory account, | |
bytes memory data | |
) public { | |
DexArbitrage memory dex = abi.decode(data, (DexArbitrage)); | |
address[] memory path1 = new address[](2); | |
address[] memory path2 = new address[](3); |
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
// 1. Sell A for B at Uniswap | |
const uAtoB = await uFetcher.fetchPairData( | |
tokenFetchers[i][1], | |
tokenFetchers[i][0] | |
); | |
const route1 = await new uRoute([uAtoB], tokenFetchers[i][0]); | |
const trade1 = await new uTrade( | |
route1, | |
new uTokenAmount(tokenFetchers[i][0], amount0), | |
uTradeType.EXACT_INPUT |