minor edits + lint

This commit is contained in:
Shriya Tyagi 2022-08-26 15:36:30 +05:30
parent bd03d6e709
commit ecb57503ee
4 changed files with 68 additions and 61 deletions

View File

@ -3,15 +3,14 @@ pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
contract Events { contract Events {
event LogEulerImport(
event LogEulerImport ( address user,
address user, uint256 sourceId,
uint sourceId, uint256 targetId,
uint targetId, address[] supplyTokens,
address[] supplyTokens, uint256[] supplyAmounts,
uint256[] supplyAmounts, address[] borrowTokens,
address[] borrowTokens, uint256[] borrowAmounts,
uint256[] borrowAmounts, bool[] enterMarket
bool[] enterMarket );
);
} }

View File

@ -6,23 +6,23 @@ import { Basic } from "../../../common/basic.sol";
import "./interface.sol"; import "./interface.sol";
contract EulerHelpers is Basic { contract EulerHelpers is Basic {
/** /**
* @dev Euler's Market Module * @dev Euler's Market Module
*/ */
IEulerMarkets internal constant markets = IEulerMarkets internal constant markets =
IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3); IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3);
/** /**
* @dev Euler's Execution Module * @dev Euler's Execution Module
*/ */
IEulerExecute internal constant eulerExec = IEulerExecute(0x59828FdF7ee634AaaD3f58B19fDBa3b03E2D9d80); IEulerExecute internal constant eulerExec =
IEulerExecute(0x59828FdF7ee634AaaD3f58B19fDBa3b03E2D9d80);
/** /**
* @dev Compute sub account address. * @dev Compute sub account address.
* @notice Compute sub account address from sub-account id * @notice Compute sub account address from sub-account id
* @param primary primary address * @param primary primary address
* @param subAccountId sub-account id whose address needs to be computed * @param subAccountId sub-account id whose address needs to be computed
*/ */
function getSubAccountAddress(address primary, uint256 subAccountId) function getSubAccountAddress(address primary, uint256 subAccountId)
public public
@ -33,17 +33,17 @@ contract EulerHelpers is Basic {
return address(uint160(primary) ^ uint160(subAccountId)); return address(uint160(primary) ^ uint160(subAccountId));
} }
struct ImportInputData { struct ImportInputData {
address[] _supplyTokens; address[] _supplyTokens;
address[] _borrowTokens; address[] _borrowTokens;
bool[] _enterMarket; bool[] _enterMarket;
} }
struct ImportData { struct ImportData {
address[] supplyTokens; address[] supplyTokens;
address[] borrowTokens; address[] borrowTokens;
EulerTokenInterface[] eTokens; EulerTokenInterface[] eTokens;
EulerTokenInterface[] dTokens; EulerTokenInterface[] dTokens;
uint256[] supplyAmts; uint256[] supplyAmts;
uint256[] borrowAmts; uint256[] borrowAmts;
} }
@ -56,21 +56,23 @@ contract EulerHelpers is Basic {
address targetAccount; address targetAccount;
} }
function getSupplyAmounts( function getSupplyAmounts(
address userAccount,// user's EOA sub-account address address userAccount, // user's EOA sub-account address
ImportInputData memory inputData, ImportInputData memory inputData,
ImportData memory data ImportData memory data
) internal view returns (ImportData memory) { ) internal view returns (ImportData memory) {
data.supplyAmts = new uint256[](inputData._supplyTokens.length); data.supplyAmts = new uint256[](inputData._supplyTokens.length);
data.supplyTokens = new address[](inputData._supplyTokens.length); data.supplyTokens = new address[](inputData._supplyTokens.length);
data.eTokens = new EulerTokenInterface[](inputData._supplyTokens.length); data.eTokens = new EulerTokenInterface[](
uint256 length_ = inputData._supplyTokens.length; inputData._supplyTokens.length
);
uint256 length_ = inputData._supplyTokens.length;
for (uint256 i = 0; i < length_; i++) { for (uint256 i = 0; i < length_; i++) {
for (uint256 j = i + 1; j < length_; j++) { for (uint256 j = i + 1; j < length_; j++) {
require( require(
inputData._supplyTokens[i] != inputData._supplyTokens[j], inputData._supplyTokens[i] != inputData._supplyTokens[j],
"token-repeated" "token-repeated"
); );
} }
} }
for (uint256 i = 0; i < length_; i++) { for (uint256 i = 0; i < length_; i++) {
@ -78,19 +80,21 @@ contract EulerHelpers is Basic {
? wethAddr ? wethAddr
: inputData._supplyTokens[i]; : inputData._supplyTokens[i];
data.supplyTokens[i] = _token; data.supplyTokens[i] = _token;
data.eTokens[i] = EulerTokenInterface(markets.underlyingToEToken(_token)); data.eTokens[i] = EulerTokenInterface(
data.supplyAmts[i] = data.eTokens[i].balanceOf(userAccount);//All 18 dec markets.underlyingToEToken(_token)
);
data.supplyAmts[i] = data.eTokens[i].balanceOf(userAccount); //All 18 dec
} }
return data; return data;
} }
function getBorrowAmounts( function getBorrowAmounts(
address userAccount,// user's EOA sub-account address address userAccount, // user's EOA sub-account address
ImportInputData memory inputData, ImportInputData memory inputData,
ImportData memory data ImportData memory data
) internal view returns (ImportData memory) { ) internal view returns (ImportData memory) {
uint _borrowTokensLength = inputData._borrowTokens.length; uint256 _borrowTokensLength = inputData._borrowTokens.length;
if (_borrowTokensLength > 0) { if (_borrowTokensLength > 0) {
data.borrowTokens = new address[](_borrowTokensLength); data.borrowTokens = new address[](_borrowTokensLength);
@ -98,11 +102,11 @@ contract EulerHelpers is Basic {
data.borrowAmts = new uint256[](_borrowTokensLength); data.borrowAmts = new uint256[](_borrowTokensLength);
for (uint256 i = 0; i < _borrowTokensLength; i++) { for (uint256 i = 0; i < _borrowTokensLength; i++) {
for (uint256 j = i + 1; j < _borrowTokensLength; j++) { for (uint256 j = i + 1; j < _borrowTokensLength; j++) {
require( require(
inputData._borrowTokens[i] != inputData._borrowTokens[i] !=
inputData._borrowTokens[j], inputData._borrowTokens[j],
"token-repeated" "token-repeated"
); );
} }
} }
@ -112,8 +116,10 @@ contract EulerHelpers is Basic {
: inputData._borrowTokens[i]; : inputData._borrowTokens[i];
data.borrowTokens[i] = _token; data.borrowTokens[i] = _token;
data.dTokens[i] = EulerTokenInterface(markets.underlyingToDToken(_token)); data.dTokens[i] = EulerTokenInterface(
data.borrowAmts[i] = data.dTokens[i].balanceOf(userAccount); markets.underlyingToDToken(_token)
);
data.borrowAmts[i] = data.dTokens[i].balanceOf(userAccount);
} }
} }
return data; return data;

View File

@ -3,7 +3,6 @@ pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
interface EulerTokenInterface { interface EulerTokenInterface {
function balanceOf(address _user) external view returns (uint256); function balanceOf(address _user) external view returns (uint256);
function transferFrom( function transferFrom(
@ -37,19 +36,21 @@ interface IEulerMarkets {
} }
interface IEulerExecute { interface IEulerExecute {
struct EulerBatchItem { struct EulerBatchItem {
bool allowError; bool allowError;
address proxyAddr; address proxyAddr;
bytes data; bytes data;
} }
struct EulerBatchItemResponse { struct EulerBatchItemResponse {
bool success; bool success;
bytes result; bytes result;
} }
function batchDispatch(EulerBatchItem[] calldata items, address[] calldata deferLiquidityChecks) external; function batchDispatch(
EulerBatchItem[] calldata items,
address[] calldata deferLiquidityChecks
) external;
function deferLiquidityCheck(address account, bytes memory data) external; function deferLiquidityCheck(address account, bytes memory data) external;
} }

View File

@ -24,6 +24,8 @@ contract EulerImport is EulerHelpers {
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
require(sourceId < 256 && targetId < 256, "Id should be less than 256");
(_eventName, _eventParam) = _importEuler( (_eventName, _eventParam) = _importEuler(
userAccount, userAccount,
sourceId, sourceId,
@ -45,28 +47,24 @@ contract EulerImport is EulerHelpers {
uint256 sourceId, uint256 sourceId,
uint256 targetId, uint256 targetId,
ImportInputData memory inputData ImportInputData memory inputData
) ) internal returns (string memory _eventName, bytes memory _eventParam) {
internal require(inputData._supplyTokens.length > 0, "0-length-not-allowed");
returns (string memory _eventName, bytes memory _eventParam) require(
{ AccountInterface(address(this)).isAuth(userAccount),
"user-account-not-auth"
);
require(
inputData._enterMarket.length == inputData._supplyTokens.length,
"lengths-not-same"
);
require(inputData._supplyTokens.length > 0, "0-length-not-allowed"); ImportData memory data;
require( ImportHelper memory helper;
AccountInterface(address(this)).isAuth(userAccount),
"user-account-not-auth"
);
require(
inputData._enterMarket.length == inputData._supplyTokens.length,
"lengths-not-same"
);
ImportData memory data;
ImportHelper memory helper;
helper.sourceAccount = getSubAccountAddress(userAccount, sourceId); helper.sourceAccount = getSubAccountAddress(userAccount, sourceId);
helper.targetAccount = getSubAccountAddress(address(this), targetId); helper.targetAccount = getSubAccountAddress(address(this), targetId);
// BorrowAmts will be in underlying token decimals // BorrowAmts will be in underlying token decimals
data = getBorrowAmounts(helper.sourceAccount, inputData, data); data = getBorrowAmounts(helper.sourceAccount, inputData, data);
// SupplyAmts will be in 18 decimals // SupplyAmts will be in 18 decimals
@ -78,11 +76,14 @@ contract EulerImport is EulerHelpers {
for (uint16 i = 0; i < inputData._enterMarket.length; i++) { for (uint16 i = 0; i < inputData._enterMarket.length; i++) {
if (inputData._enterMarket[i]) { if (inputData._enterMarket[i]) {
++enterMarkets; ++enterMarketsLength;
} }
} }
helper.totalExecutions = helper.supplylength + enterMarkets + helper.borrowlength; helper.totalExecutions =
helper.supplylength +
enterMarketsLength +
helper.borrowlength;
IEulerExecute.EulerBatchItem[] IEulerExecute.EulerBatchItem[]
memory items = new IEulerExecute.EulerBatchItem[]( memory items = new IEulerExecute.EulerBatchItem[](