Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add a flashloan and make contract callable by anyone #14

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

bertmiller
Copy link
Member

This PR does the following:

  • Adds a flashloan from Aave to "BundleExecutor.sol," as well as importing all the necessary libraries
  • Moved the previous bundle executor to "BundleExecutorNoFlashloan.sol"
  • Ups the minimum volume and profits in arbitrage.ts to make more sense with flashloans
  • Packs variables in ABI encoded params for passing in to our bundle executor post-Flashloan

Some remaining tasks I could use help on:

  • Does it make sense to use tx.origin to send profits to the caller of the contract? I think msg.sender will be Aave calling back our contract after sending the flashloan
  • Testing to ensure this works. It's very similar to the previous version, but we should probably test it.

address private immutable owner;
address private immutable executor;
IWETH private constant WETH = IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
address public WETH_address = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constant as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made WETH_address constant as well, was that your intention?

{
uint aaveDebt = amounts[0].add(premiums[0]);
uniswapWethFLParams(amounts[0], params, aaveDebt);
WETH.approve(address(LENDING_POOL), aaveDebt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you just approve uint(-1) in constructor and avoid this in the hot path?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup.

@bertmiller
Copy link
Member Author

@epheph a gentle ping on this, I addressed your comments above!

if (msg.value > 0) {
WETH.deposit{value: msg.value}();
}
WETH.approve(address(LENDING_POOL), uint(-1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting! you don't move them back yourself, aave takes them back from you?

override
returns (bool)
{
uint aaveDebt = amounts[0].add(premiums[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess since there's no assets held in the contract, you don't need to limit msg.sender to aave?

);
}

function uniswapWethFLParams(uint256 _amountToFirstMarket, bytes memory _params, uint256 aaveDebt) internal {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just like the first one, anyone can perform arbitrary calls, so the "owner" here isn't really that empowered. more a convenience than anything

address private immutable owner;
address private immutable executor;
IWETH private constant WETH = IWETH(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
address public constant WETH_address = address(0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove executor?

Copy link
Contributor

@epheph epheph left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice. I look forward to people not moving weth into a contract.

@@ -2,6 +2,10 @@ simple-arbitrage
================
This repository contains a simple, mechanical system for discovering, evaluating, rating, and submitting arbitrage opportunities to the Flashbots bundle endpoint. This script is very unlikely to be profitable, as many users have access to it, and it is targeting well-known Ethereum opportunities.

simple-arbitrage uses Flashloans to source liquidity to execute on arbitrage opportunities it finds. It attempts to capture them and sends any profits made, net of fees, back to the message sender. We have deployed a contract that anyone can submit trades to here:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please update the link to this execution contract or send us its address.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants