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
route 9 added- Arbitrum
  • Loading branch information
shriyatyagii committed May 30, 2022
commit e110eb3e29f3c57ca3143f7de75a3721958002c2
2 changes: 2 additions & 0 deletions contracts/aggregator/arbitrum/flashloan/helpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ contract Helper is HelpersCommon, Variables {
.getFlashLoanFeePercentage()
) *
100;
} else if (_route == 9) {
BPS_ = InstaFeeBPS;
} else {
revert("Invalid source");
}
Expand Down
53 changes: 52 additions & 1 deletion contracts/aggregator/arbitrum/flashloan/main.sol
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,52 @@ contract FlashAggregatorArbitrum is Helper {
spell(UNISWAP_IMPL, msg.data);
}

function routeFLA(
address _receiverAddress,
address[] memory _tokens,
uint256[] memory _amounts,
bytes memory _data
) internal reentrancy returns (bool) {//TODO: doubt

FlashloanVariables memory instaLoanVariables_;
instaLoanVariables_._tokens = _tokens;
instaLoanVariables_._amounts = _amounts;
instaLoanVariables_._instaFees = calculateFees(
_amounts,
calculateFeeBPS(9)
);
instaLoanVariables_._iniBals = calculateBalances(
_tokens,
address(this)
);
safeTransfer(instaLoanVariables_, _receiverAddress);

if (checkIfDsa(_receiverAddress)) {
Address.functionCall(
_receiverAddress,
_data,
"DSA-flashloan-fallback-failed"
);
} else {
require(InstaFlashReceiverInterface(_receiverAddress).executeOperation(
_tokens,
_amounts,
instaLoanVariables_._instaFees,
_receiverAddress,
_data
), "invalid flashloan execution");
}

instaLoanVariables_._finBals = calculateBalances(
_tokens,
address(this)
);
validateFlashloan(instaLoanVariables_);

status = 1;
return true;
}

/**
* @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.
Expand All @@ -69,6 +115,10 @@ contract FlashAggregatorArbitrum is Helper {
spell(BALANCER_IMPL, msg.data);
} else if (_route == 8) {
spell(UNISWAP_IMPL, msg.data);
} else if (_route == 9) {
(_tokens, _amounts) = bubbleSort(_tokens, _amounts);
validateTokens(_tokens);
routeFLA(msg.sender, _tokens, _amounts, _data);
} else {
revert("route-does-not-exist");
}
Expand All @@ -81,9 +131,10 @@ contract FlashAggregatorArbitrum is Helper {
* @notice Function to get the list of available routes.
*/
function getRoutes() public pure returns (uint16[] memory routes_) {
routes_ = new uint16[](2);
routes_ = new uint16[](3);
routes_[0] = 5;
routes_[1] = 8;
routes_[2] = 9;
}

/**
Expand Down