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

Self route flashloan #70

Open
wants to merge 36 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1338e6f
update transfer fee
KaymasJain May 6, 2022
0f4be40
added event
KaymasJain May 6, 2022
e0996b5
Implementations created
shriyatyagii May 9, 2022
e88ad6a
flashloan func added in implementations
shriyatyagii May 10, 2022
0c5c158
changed file names
shriyatyagii May 10, 2022
c7d3a69
minor update
shriyatyagii May 10, 2022
2ba7c66
added common helper and interface
shriyatyagii May 13, 2022
c549c3a
Added Implementation proxy - Arbitrum
shriyatyagii May 14, 2022
4c64449
Added implementation proxy - Avalanche
shriyatyagii May 14, 2022
2ab8019
Added implementation proxy - Optimism
shriyatyagii May 15, 2022
907b1ec
Added implementation proxy - Polygon
shriyatyagii May 15, 2022
cd8a484
code refactored
shriyatyagii May 15, 2022
7c7e650
arbitrum updates + testcases
shriyatyagii May 19, 2022
4c232b1
added sortTokens for uniswap key sorting
shriyatyagii May 20, 2022
57b3aca
minor updates + optimism testcases
shriyatyagii May 20, 2022
8ddef00
bubbleSort added in new implementations
shriyatyagii May 20, 2022
6cd9969
minor updates on all chains
shriyatyagii May 20, 2022
76ab257
polygon testcase + polygon updates
shriyatyagii May 20, 2022
cc7ca71
Avalanche testcases + new updates
shriyatyagii May 20, 2022
3d93a57
minor updates
shriyatyagii May 20, 2022
1277d61
Uni v3 flashloan added
shriyatyagii May 25, 2022
f6b80f4
testcases added
shriyatyagii May 25, 2022
baccd8c
self-route set up
shriyatyagii May 27, 2022
78327ea
testcases added
shriyatyagii May 27, 2022
2afdaa0
added route 9 - polygon
shriyatyagii May 29, 2022
a92298f
testcases added - polygon
shriyatyagii May 29, 2022
4d72798
minor updates
shriyatyagii May 30, 2022
e110eb3
route 9 added- Arbitrum
shriyatyagii May 30, 2022
8e8ec28
testcases added - arbitrum
shriyatyagii May 30, 2022
3d13e8a
route 9 added - Avalanche
shriyatyagii May 30, 2022
e506911
testcases added - Avalanche
shriyatyagii May 30, 2022
66a2a5d
route 9 added - optimism
shriyatyagii May 30, 2022
153a7b0
testcases added - optimism
shriyatyagii May 30, 2022
f0e5ac1
updated changes - mainnet
shriyatyagii May 31, 2022
fba997d
updated testcases -mainnet
shriyatyagii May 31, 2022
bf09018
minor updates
shriyatyagii May 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
flashloan func added in implementations
  • Loading branch information
shriyatyagii committed May 10, 2022
commit e88ad6a22068295bec01a06a2be72b669b8f2ba0
19 changes: 19 additions & 0 deletions contracts/ProxyAave/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,25 @@ import "../aggregator/mainnet/flashloan/helpers.sol";

contract AaveImplementation is Helper {

/**
* @dev Main function for flashloan for all routes. Calls the middle functions according to routes.
* @notice Main function for flashloan for all routes. Calls the middle functions according to routes.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _route route for flashloan.
* @param _data extra data passed.
*/
function flashLoan(
address[] memory _tokens,
uint256[] memory _amounts,
uint256 _route,
bytes calldata _data,
bytes calldata // kept for future use by instadapp. Currently not used anywhere.
) external reentrancy {
require(_route == 1, "invalid AAVE flashloan route");
routeAave(_tokens, _amounts, _data);
}

/**
* @dev Callback function for aave flashloan.
* @notice Callback function for aave flashloan.
Expand Down
26 changes: 26 additions & 0 deletions contracts/ProxyBalancer/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ import "../aggregator/mainnet/flashloan/helpers.sol";

contract BalancerImplementation is Helper {

/**
* @dev Main function for flashloan for all routes. Calls the middle functions according to routes.
* @notice Main function for flashloan for all routes. Calls the middle functions according to routes.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _route route for flashloan.
* @param _data extra data passed.
*/
function flashLoan(
address[] memory _tokens,
uint256[] memory _amounts,
uint256 _route,
bytes calldata _data,
bytes calldata // kept for future use by instadapp. Currently not used anywhere.
) external reentrancy {
require(_route == 5 || _route == 6 || _route == 7, "invalid BALANCER flashloan route");

if (_route == 5) {
routeBalancer(_tokens, _amounts, _data);
} else if (_route == 6) {
routeBalancerCompound(_tokens, _amounts, _data);
} else if (_route == 7) {
routeBalancerAave(_tokens, _amounts, _data);
}
}

/**
* @dev Fallback function for balancer flashloan.
* @notice Fallback function for balancer flashloan.
Expand Down
26 changes: 26 additions & 0 deletions contracts/ProxyMaker/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,32 @@ import "../aggregator/mainnet/flashloan/helpers.sol";

contract MakerImplementation is Helper {

/**
* @dev Main function for flashloan for all routes. Calls the middle functions according to routes.
* @notice Main function for flashloan for all routes. Calls the middle functions according to routes.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _route route for flashloan.
* @param _data extra data passed.
*/
function flashLoan(
address[] memory _tokens,
uint256[] memory _amounts,
uint256 _route,
bytes calldata _data,
bytes calldata // kept for future use by instadapp. Currently not used anywhere.
) external reentrancy {
require((_route == 2 || _route == 3 || _route == 4), "invalid MAKER flashloan route");

if (_route == 2) {
routeMaker(_tokens[0], _amounts[0], _data);
} else if (_route == 3) {
routeMakerCompound(_tokens, _amounts, _data);
} else if (_route == 4) {
routeMakerAave(_tokens, _amounts, _data);
}
}

/**
* @dev Fallback function for makerdao flashloan.
* @notice Fallback function for makerdao flashloan.
Expand Down
135 changes: 11 additions & 124 deletions contracts/aggregator/mainnet/flashloan/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ pragma solidity ^0.8.0;
*/

import "./helpers.sol";
import "hardhat/console.sol";
import "@openzeppelin/contracts/utils/Address.sol";

contract AdminModule is Helper {
Expand Down Expand Up @@ -105,7 +104,7 @@ contract FlashAggregator is Setups {
address _initiator,
bytes memory _data
) external returns (bool) {
bytes memory response = spell(AAVE_PROXY, msg.data);
bytes memory response = spell(AAVE_IMP, msg.data);
return (abi.decode(response, (bool)));
}

Expand All @@ -124,7 +123,7 @@ contract FlashAggregator is Setups {
uint256 _fee,
bytes calldata _data
) external returns (bytes32) {
bytes memory response = spell(MAKER_PROXY, msg.data);
bytes memory response = spell(MAKER_IMP, msg.data);
return (abi.decode(response, (bytes32)));
}

Expand All @@ -141,112 +140,7 @@ contract FlashAggregator is Setups {
uint256[] memory _fees,
bytes memory _data
) external {
spell(BALANCER_PROXY, msg.data);
}

/**
* @dev Middle function for route 1.
* @notice Middle function for route 1.
* @param _tokens list of token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets or amount of ether to borrow as collateral for flashloan.
* @param _data extra data passed.
*/
function routeAave(
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal {
spell(AAVE_PROXY, msg.data);
}

/**
* @dev Middle function for route 2.
* @notice Middle function for route 2.
* @param _token token address for flashloan(DAI).
* @param _amount DAI amount for flashloan.
* @param _data extra data passed.
*/
function routeMaker(
address _token,
uint256 _amount,
bytes memory _data
) internal {
spell(MAKER_PROXY, msg.data);
}

/**
* @dev Middle function for route 3.
* @notice Middle function for route 3.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _data extra data passed.
*/
function routeMakerCompound(
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal {
spell(MAKER_PROXY, msg.data);
}

/**
* @dev Middle function for route 4.
* @notice Middle function for route 4.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _data extra data passed.
*/
function routeMakerAave(
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal {
spell(MAKER_PROXY, msg.data);
}

/**
* @dev Middle function for route 5.
* @notice Middle function for route 5.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _data extra data passed.
*/
function routeBalancer(
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal {
spell(BALANCER_PROXY, msg.data);
}

/**
* @dev Middle function for route 6.
* @notice Middle function for route 6.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _data extra data passed.
*/
function routeBalancerCompound(
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal {
spell(BALANCER_PROXY, msg.data);
}

/**
* @dev Middle function for route 7.
* @notice Middle function for route 7.
* @param _tokens token addresses for flashloan.
* @param _amounts list of amounts for the corresponding assets.
* @param _data extra data passed.
*/
function routeBalancerAave(
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal {
spell(BALANCER_PROXY, msg.data);
spell(BALANCER_IMP, msg.data);
}

/**
Expand All @@ -263,26 +157,26 @@ contract FlashAggregator is Setups {
uint256 _route,
bytes calldata _data,
bytes calldata // kept for future use by instadapp. Currently not used anywhere.
) external reentrancy {
) external {
require(_tokens.length == _amounts.length, "array-lengths-not-same");

(_tokens, _amounts) = bubbleSort(_tokens, _amounts);
validateTokens(_tokens);

if (_route == 1) {
routeAave(_tokens, _amounts, _data);
spell(AAVE_IMP, msg.data);
} else if (_route == 2) {
routeMaker(_tokens[0], _amounts[0], _data);
spell(MAKER_IMP, msg.data);
} else if (_route == 3) {
routeMakerCompound(_tokens, _amounts, _data);
spell(MAKER_IMP, msg.data);
} else if (_route == 4) {
routeMakerAave(_tokens, _amounts, _data);
spell(MAKER_IMP, msg.data);
} else if (_route == 5) {
routeBalancer(_tokens, _amounts, _data);
spell(BALANCER_IMP, msg.data);
} else if (_route == 6) {
routeBalancerCompound(_tokens, _amounts, _data);
spell(BALANCER_IMP, msg.data);
} else if (_route == 7) {
routeBalancerAave(_tokens, _amounts, _data);
spell(BALANCER_IMP, msg.data);
} else {
revert("route-does-not-exist");
}
Expand Down Expand Up @@ -333,13 +227,6 @@ contract FlashAggregator is Setups {
contract InstaFlashAggregator is FlashAggregator {
using SafeERC20 for IERC20;

function initialize(address aave, address maker, address balancer) public {
AAVE_PROXY = aave;
MAKER_PROXY = maker;
BALANCER_PROXY = balancer;
console.log("initialize call successful! AAVE_PROXY = ", AAVE_PROXY);
}

/*
Deprecated
*/
Expand Down
10 changes: 4 additions & 6 deletions contracts/aggregator/mainnet/flashloan/variables.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,6 @@ contract ConstantVariables {
ListInterface internal constant instaList =
ListInterface(0x4c8a1BEb8a87765788946D6B19C6C6355194AbEb);
uint256 public constant InstaFeeBPS = 5; // in BPS; 1 BPS = 0.01%
// address internal constant AAVE_PROXY;
// address internal constant MAKER_PROXY;
// address internal constant BALANCER_PROXY;
address internal AAVE_PROXY;
address internal MAKER_PROXY;
address internal BALANCER_PROXY;
}

contract Variables is ConstantVariables {
Expand All @@ -62,4 +56,8 @@ contract Variables is ConstantVariables {
uint256 internal ownerStatus;

mapping(address => bool) public isWhitelisted;

address internal AAVE_IMP;
address internal MAKER_IMP;
address internal BALANCER_IMP;
}
Loading