Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Strawman for flashloans for flashbots
pragma solidity ^0.7.0;
// Each mining pool that intends to provide flash loans deploys a Loaner contract and transfers ETH to it
// When testing each bundle, the diff in balance in this contract is taking into account for calculating effective gas price
// The contract loans funds only on blocks mined by the miner and on zero-gasprice txs
contract Loaner {
address immutable owner;
constructor(address _owner) {
owner = _owner;
}
function loan(address payable to, uint256 amount) public returns (uint256) {
require(tx.gasprice == 0 && block.coinbase == owner);
to.transfer(amount);
return amount;
}
function withdraw(address payable to) public {
require(msg.sender == owner);
to.transfer(address(this).balance);
}
}
// Users interact with the router, which redirects to the corresponding loaner based on the miner that picked up the bundle
contract Router {
mapping(address => Loaner) registry;
function getBalance() public view returns(uint256) {
Loaner loaner = registry[block.coinbase];
if (address(loaner) == address(0)) return 0;
return address(loaner).balance;
}
function loan(address payable to, uint256 amount) public returns(uint256) {
Loaner loaner = registry[block.coinbase];
if (address(loaner) == address(0)) return 0;
return loaner.loan(to, amount);
}
function register(Loaner loaner) public {
registry[msg.sender] = loaner;
}
}
@spalladino

This comment has been minimized.

Copy link
Owner Author

@spalladino spalladino commented Apr 8, 2021

Broken by onewayfunction here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment