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;
contract Events {
event LogEulerImport (
address user,
uint sourceId,
uint targetId,
address[] supplyTokens,
uint256[] supplyAmounts,
address[] borrowTokens,
uint256[] borrowAmounts,
bool[] enterMarket
);
event LogEulerImport(
address user,
uint256 sourceId,
uint256 targetId,
address[] supplyTokens,
uint256[] supplyAmounts,
address[] borrowTokens,
uint256[] borrowAmounts,
bool[] enterMarket
);
}

View File

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

View File

@ -3,7 +3,6 @@ pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2;
interface EulerTokenInterface {
function balanceOf(address _user) external view returns (uint256);
function transferFrom(
@ -37,19 +36,21 @@ interface IEulerMarkets {
}
interface IEulerExecute {
struct EulerBatchItem {
bool allowError;
address proxyAddr;
bytes data;
}
struct EulerBatchItemResponse {
bool success;
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;
}

View File

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