Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
yuyasugano / callback.sol
Created April 3, 2021 01:05
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
@yuyasugano
yuyasugano / flashswaps.sol
Created April 3, 2021 00:39
Flash Swaps arbitrage
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(
@yuyasugano
yuyasugano / Flashloan.sol
Created March 29, 2021 14:06
MCL Flashloan.sol overview
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;
@yuyasugano
yuyasugano / Flashloan1.sol
Created March 29, 2021 13:50
MCL ILendingPoolAddressesProvider set
// 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));
@yuyasugano
yuyasugano / brownie.sh
Created February 28, 2021 13:07
JPYC.sol deploy in Rinkeby
>> 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
@yuyasugano
yuyasugano / PriceConsumerV3.sh
Created February 28, 2021 09:17
PriceConsumerV3.sol deploument in brownie
$ 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
@yuyasugano
yuyasugano / test_aave2.py
Created February 23, 2021 09:57
Aave V2 flashloan test
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
@yuyasugano
yuyasugano / test_aave1.py
Created February 23, 2021 09:47
Aave V1 flashloan test
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
@yuyasugano
yuyasugano / uni_sushi_arbitrage.sol
Created January 24, 2021 08:24
callFunction for Uniswap & Sushiswap arbitrage
// 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);
@yuyasugano
yuyasugano / swap.js
Created January 22, 2021 12:09
Token swap Sell A for B at Uniswap
// 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