dsa-connectors/contracts/mainnet/connectors/euler/helpers.sol

76 lines
1.7 KiB
Solidity
Raw Normal View History

2022-06-30 23:43:20 +00:00
//SPDX-License-Identifier: MIT
pragma solidity ^0.7.0;
2022-07-07 18:51:06 +00:00
import "./interface.sol";
2022-07-06 01:07:56 +00:00
import "./events.sol";
2022-06-30 23:43:20 +00:00
import { Basic } from "../../common/basic.sol";
2022-07-07 18:51:06 +00:00
contract Helpers is Basic, Events {
address internal constant EULER_MAINNET =
0x27182842E098f60e3D576794A5bFFb0777E025d3;
IEulerMarkets internal constant markets =
IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3);
IEulerSwap internal constant swapExec =
IEulerSwap(0x7123C8cBBD76c5C7fCC9f7150f23179bec0bA341);
struct swapHelper {
address _sellAddr;
address _buyAddr;
uint256 _buyDec;
uint256 _sellDec;
uint256 _sellAmt18;
uint256 _slippageAmt;
}
struct swapParams {
uint256 subAccountFrom;
uint256 subAccountTo;
address buyAddr;
address sellAddr;
uint256 sellAmt;
uint256 unitAmt;
bytes callData;
}
2022-07-06 13:40:38 +00:00
/**
2022-07-06 13:52:01 +00:00
* @dev Get Enetered markets for a user
2022-06-30 23:43:20 +00:00
*/
function getEnteredMarkets()
internal
view
returns (address[] memory enteredMarkets)
{
enteredMarkets = markets.getEnteredMarkets(address(this));
}
2022-07-06 13:52:01 +00:00
/**
* @dev Get sub account address
* @param primary address of user
* @param subAccountId subAccount ID
*/
2022-07-06 13:40:38 +00:00
function getSubAccount(address primary, uint256 subAccountId)
public
pure
returns (address)
{
require(subAccountId < 256, "sub-account-id-too-big");
return address(uint160(primary) ^ uint160(subAccountId));
}
2022-07-06 01:07:56 +00:00
2022-07-06 13:52:01 +00:00
/**
* @dev Check if the market is entered
* @param token token address
*/
2022-07-06 13:40:38 +00:00
function checkIfEnteredMarket(address token) public view returns (bool) {
2022-07-06 01:07:56 +00:00
address[] memory enteredMarkets = getEnteredMarkets();
uint256 length = enteredMarkets.length;
2022-07-06 13:40:38 +00:00
for (uint256 i = 0; i < length; i++) {
if (enteredMarkets[i] == token) {
2022-07-06 01:07:56 +00:00
return true;
}
}
return false;
}
2022-06-30 23:43:20 +00:00
}