mirror of
https://github.com/Instadapp/dsa-polygon-migration.git
synced 2024-07-29 22:27:58 +00:00
Add flashloan connector
This commit is contained in:
parent
b6551a2838
commit
bfe3579afd
10
contracts/receivers/flashloan-connector/events.sol
Normal file
10
contracts/receivers/flashloan-connector/events.sol
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
pragma solidity >=0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
contract Events {
|
||||||
|
event LogFlashBorrow(address token, uint256 tokenAmt);
|
||||||
|
event LogFlashPayback(address token, uint256 tokenAmt);
|
||||||
|
|
||||||
|
event LogFlashMultiBorrow(address[] token, uint256[] tokenAmts);
|
||||||
|
event LogFlashMultiPayback(address[] token, uint256[] tokenAmts);
|
||||||
|
}
|
6
contracts/receivers/flashloan-connector/interfaces.sol
Normal file
6
contracts/receivers/flashloan-connector/interfaces.sol
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
pragma solidity >=0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
interface InstaFlashV2Interface {
|
||||||
|
function initiateFlashLoan(address[] calldata tokens, uint256[] calldata amts, uint route, bytes calldata data) external;
|
||||||
|
}
|
118
contracts/receivers/flashloan-connector/main.sol
Normal file
118
contracts/receivers/flashloan-connector/main.sol
Normal file
|
@ -0,0 +1,118 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||||
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
import { TokenInterface } from "../../common/interfaces.sol";
|
||||||
|
import { DSMath } from "../../common/math.sol";
|
||||||
|
import { Stores } from "../../common/stores-polygon.sol";
|
||||||
|
import { Variables } from "./variables.sol";
|
||||||
|
import { Events } from "./events.sol";
|
||||||
|
|
||||||
|
contract LiquidityResolver is DSMath, Stores, Variables, Events {
|
||||||
|
using SafeERC20 for IERC20;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Borrow Flashloan and Cast spells.
|
||||||
|
* @param token Token Address.
|
||||||
|
* @param amt Token Amount.
|
||||||
|
* @param data targets & data for cast.
|
||||||
|
*/
|
||||||
|
function flashBorrowAndCast(
|
||||||
|
address token,
|
||||||
|
uint amt,
|
||||||
|
uint route,
|
||||||
|
bytes memory data
|
||||||
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
address[] memory tokens = new address[](1);
|
||||||
|
uint[] memory amts = new uint[](1);
|
||||||
|
tokens[0] = token;
|
||||||
|
amts[0] = amt;
|
||||||
|
|
||||||
|
instaPool.initiateFlashLoan(tokens, amts, route, data);
|
||||||
|
|
||||||
|
_eventName = "LogFlashBorrow(address,uint256)";
|
||||||
|
_eventParam = abi.encode(token, amt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Return token to InstaPool.
|
||||||
|
* @param token Token Address.
|
||||||
|
* @param amt Token Amount.
|
||||||
|
* @param getId Get token amount at this ID from `InstaMemory` Contract.
|
||||||
|
* @param setId Set token amount at this ID in `InstaMemory` Contract.
|
||||||
|
*/
|
||||||
|
function flashPayback(
|
||||||
|
address token,
|
||||||
|
uint amt,
|
||||||
|
uint getId,
|
||||||
|
uint setId
|
||||||
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
uint _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
IERC20 tokenContract = IERC20(token);
|
||||||
|
|
||||||
|
tokenContract.safeTransfer(address(instaPool), _amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogFlashPayback(address,uint256)";
|
||||||
|
_eventParam = abi.encode(token, _amt);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Borrow Flashloan and Cast spells.
|
||||||
|
* @param tokens Array of token Addresses.
|
||||||
|
* @param amts Array of token Amounts.
|
||||||
|
* @param route Route to borrow.
|
||||||
|
* @param data targets & data for cast.
|
||||||
|
*/
|
||||||
|
function flashMultiBorrowAndCast(
|
||||||
|
address[] calldata tokens,
|
||||||
|
uint[] calldata amts,
|
||||||
|
uint route,
|
||||||
|
bytes calldata data
|
||||||
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
instaPool.initiateFlashLoan(tokens, amts, route, data);
|
||||||
|
|
||||||
|
_eventName = "LogFlashMultiBorrow(address[],uint256[])";
|
||||||
|
_eventParam = abi.encode(tokens, amts);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Return Multiple token liquidity to InstaPool.
|
||||||
|
* @param tokens Array of token addresses.
|
||||||
|
* @param amts Array of token amounts.
|
||||||
|
* @param getId get token amounts at this IDs from `InstaMemory` Contract.
|
||||||
|
* @param setId set token amounts at this IDs in `InstaMemory` Contract.
|
||||||
|
*/
|
||||||
|
function flashMultiPayback(
|
||||||
|
address[] calldata tokens,
|
||||||
|
uint[] calldata amts,
|
||||||
|
uint[] calldata getId,
|
||||||
|
uint[] calldata setId
|
||||||
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
uint _length = tokens.length;
|
||||||
|
|
||||||
|
uint[] memory _amts = new uint[](_length);
|
||||||
|
|
||||||
|
for (uint i = 0; i < _length; i++) {
|
||||||
|
uint _amt = getUint(getId[i], amts[i]);
|
||||||
|
|
||||||
|
_amts[i] = _amt;
|
||||||
|
|
||||||
|
IERC20 tokenContract = IERC20(tokens[i]);
|
||||||
|
|
||||||
|
tokenContract.safeTransfer(address(instaPool), _amt);
|
||||||
|
|
||||||
|
setUint(setId[i], _amt);
|
||||||
|
}
|
||||||
|
|
||||||
|
_eventName = "LogFlashMultiPayback(address[],uint256[])";
|
||||||
|
_eventParam = abi.encode(tokens, _amts);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
contract ConnectInstaPool is LiquidityResolver {
|
||||||
|
string public name = "Instapool-v1";
|
||||||
|
}
|
12
contracts/receivers/flashloan-connector/variables.sol
Normal file
12
contracts/receivers/flashloan-connector/variables.sol
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
pragma solidity ^0.7.0;
|
||||||
|
pragma experimental ABIEncoderV2;
|
||||||
|
|
||||||
|
import { InstaFlashV2Interface } from "./interfaces.sol";
|
||||||
|
|
||||||
|
contract Variables {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Instapool / Receiver contract proxy
|
||||||
|
*/
|
||||||
|
InstaFlashV2Interface public constant instaPool = InstaFlashV2Interface(0x4A090897f47993C2504144419751D6A91D79AbF4);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user