dsa-connectors/contracts/mainnet/connectors/instaLite_import/main.sol

82 lines
2.2 KiB
Solidity
Raw Normal View History

2022-10-01 21:11:44 +00:00
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
/**
* @title InstaLite Connector
* @dev Import Position
*/
import { TokenInterface } from "../../common/interfaces.sol";
import { Basic } from "../../common/basic.sol";
import { Events } from "./events.sol";
import { IInstaLite } from "./interface.sol";
abstract contract InstaLiteConnector is Events, Basic {
TokenInterface internal constant astethToken =
TokenInterface(0x1982b2F5814301d4e9a8b0201555376e62F82428);
TokenInterface internal constant stethToken =
TokenInterface(0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84);
2022-10-01 22:20:17 +00:00
IInstaLite internal constant iEth =
IInstaLite(0xc383a3833A87009fD9597F8184979AF5eDFad019);
2022-10-01 21:11:44 +00:00
/**
* @dev Supply ETH/ERC20
* @notice Supply a token into Instalite.
* @param flashTkn_ Address of flash token.
* @param flashAmt_ Flash loan amount.
* @param route_ Flash loan route.
* @param stEthAmt_ Amount of astEthToken to be imported.
2022-10-01 22:20:17 +00:00
* @param wethAmt_ Amount of weth borrows to be imported.
2022-10-01 21:11:44 +00:00
* @param getIds IDs to retrieve amt.
2022-10-02 04:43:11 +00:00
* @param setId ID to store balanceOf of iEth.
2022-10-01 21:11:44 +00:00
*/
function importPosition(
address flashTkn_,
uint256 flashAmt_,
uint256 route_,
uint256 stEthAmt_,
uint256 wethAmt_,
uint256[] memory getIds,
2022-10-02 04:43:11 +00:00
uint256 setId
2022-10-01 21:11:44 +00:00
) external returns (string memory eventName_, bytes memory eventParam_) {
uint256 stEthAmt_ = getUint(getIds[0], stEthAmt_);
uint256 wethAmt_ = getUint(getIds[1], wethAmt_);
stEthAmt_ = stEthAmt_ == type(uint256).max
? astethToken.balanceOf(msg.sender)
: stEthAmt_;
2022-10-01 22:20:17 +00:00
astethToken.approve(address(iEth), stEthAmt_);
2022-10-02 14:55:58 +00:00
uint256 initialBal = iEth.balanceOf(address(this));
2022-10-01 21:11:44 +00:00
2022-10-01 22:20:17 +00:00
iEth.importPosition(
2022-10-01 21:11:44 +00:00
flashTkn_,
flashAmt_,
route_,
address(this),
stEthAmt_,
wethAmt_
);
2022-10-02 14:55:58 +00:00
uint256 finalBalance = iEth.balanceOf(address(this));
uint256 iEthAmt_ = finalBalance - initialBal;
setUint(setId, iEthAmt_);
2022-10-01 21:11:44 +00:00
2022-10-02 14:59:01 +00:00
eventName_ = "LogImport(address,uint256,uint256,uint256,uint256,uint256,uint256[],uint256)";
2022-10-01 22:20:17 +00:00
eventParam_ = abi.encode(
flashTkn_,
flashAmt_,
route_,
stEthAmt_,
wethAmt_,
2022-10-02 14:55:58 +00:00
iEthAmt_,
2022-10-01 22:20:17 +00:00
getIds,
2022-10-02 04:43:11 +00:00
setId
2022-10-01 22:20:17 +00:00
);
2022-10-01 21:11:44 +00:00
}
}
2022-10-01 21:57:58 +00:00
contract ConnectV2InstaLiteImport is InstaLiteConnector {
string public constant name = "InstaLite-Import-v1.0";
2022-10-01 21:11:44 +00:00
}