mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
minor updates + lint
This commit is contained in:
parent
da5716c0f3
commit
cc526d5899
|
@ -9,7 +9,9 @@ contract Events {
|
||||||
uint sourceId,
|
uint sourceId,
|
||||||
uint targetId,
|
uint targetId,
|
||||||
address[] supplyTokens,
|
address[] supplyTokens,
|
||||||
|
uint256[] supplyAmounts,
|
||||||
address[] borrowTokens,
|
address[] borrowTokens,
|
||||||
|
uint256[] borrowAmounts,
|
||||||
bool[] enterMarket
|
bool[] enterMarket
|
||||||
);
|
);
|
||||||
}
|
}
|
|
@ -34,44 +34,52 @@ contract EulerHelpers is Basic {
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ImportHelper {
|
||||||
|
uint256 supplylength;
|
||||||
|
uint256 borrowlength;
|
||||||
|
uint256 totalExecutions;
|
||||||
|
address sourceAccount;
|
||||||
|
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[](inputData._supplyTokens.length);
|
||||||
|
|
||||||
for (uint256 i = 0; i < inputData.supplyTokens.length; i++) {
|
for (uint256 i = 0; i < inputData._supplyTokens.length; i++) {
|
||||||
for (uint256 j = i; j < inputData.supplyTokens.length; j++) {
|
for (uint256 j = i; j < inputData._supplyTokens.length; j++) {
|
||||||
if (j != i) {
|
if (j != i) {
|
||||||
require(
|
require(
|
||||||
inputData.supplyTokens[i] != inputData.supplyTokens[j],
|
inputData._supplyTokens[i] != inputData._supplyTokens[j],
|
||||||
"token-repeated"
|
"token-repeated"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (uint256 i = 0; i < inputData.supplyTokens.length; i++) {
|
for (uint256 i = 0; i < inputData._supplyTokens.length; i++) {
|
||||||
address _token = inputData.supplyTokens[i] == ethAddr
|
address _token = inputData._supplyTokens[i] == ethAddr
|
||||||
? 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(markets.underlyingToEToken(_token));
|
||||||
data.supplyAmts[i] = data.eTokens[i].balanceOf(userAccount);//All 18 dec
|
data.supplyAmts[i] = data.eTokens[i].balanceOf(userAccount);//All 18 dec
|
||||||
}
|
}
|
||||||
|
@ -84,18 +92,18 @@ contract EulerHelpers is Basic {
|
||||||
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;
|
uint _borrowTokensLength = inputData._borrowTokens.length;
|
||||||
|
|
||||||
if (_borrowTokensLength > 0) {
|
if (_borrowTokensLength > 0) {
|
||||||
data._borrowTokens = new address[](_borrowTokensLength);
|
data.borrowTokens = new address[](_borrowTokensLength);
|
||||||
data.dTokens = new EulerTokenInterface[](_borrowTokensLength);
|
data.dTokens = new EulerTokenInterface[](_borrowTokensLength);
|
||||||
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; j < _borrowTokensLength; j++) {
|
for (uint256 j = i; j < _borrowTokensLength; j++) {
|
||||||
if (j != i) {
|
if (j != i) {
|
||||||
require(
|
require(
|
||||||
inputData.borrowTokens[i] !=
|
inputData._borrowTokens[i] !=
|
||||||
inputData.borrowTokens[j],
|
inputData._borrowTokens[j],
|
||||||
"token-repeated"
|
"token-repeated"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -103,11 +111,11 @@ contract EulerHelpers is Basic {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint256 i = 0; i < _borrowTokensLength; i++) {
|
for (uint256 i = 0; i < _borrowTokensLength; i++) {
|
||||||
address _token = inputData.borrowTokens[i] == ethAddr
|
address _token = inputData._borrowTokens[i] == ethAddr
|
||||||
? wethAddr
|
? wethAddr
|
||||||
: 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(markets.underlyingToDToken(_token));
|
||||||
data.borrowAmts[i] = data.dTokens[i].balanceOf(userAccount);
|
data.borrowAmts[i] = data.dTokens[i].balanceOf(userAccount);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,12 @@ import "./interface.sol";
|
||||||
import "./events.sol";
|
import "./events.sol";
|
||||||
|
|
||||||
contract EulerImport is EulerHelpers {
|
contract EulerImport is EulerHelpers {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Import Euler position .
|
* @dev Import Euler position .
|
||||||
* @notice Import EOA's Euler position to DSA's Euler position
|
* @notice Import EOA's Euler position to DSA's Euler position
|
||||||
* @param userAccount The address of the EOA from which position will be imported
|
* @param userAccount EOA address
|
||||||
* @param sourceId sub-account id of EOA from which the funds will be transferred
|
* @param sourceId Sub-account id of "EOA" from which the funds will be transferred
|
||||||
* @param targetId sub-account id of DSA to which the funds will be transferred
|
* @param targetId Sub-account id of "DSA" to which the funds will be transferred
|
||||||
* @param inputData The struct containing all the neccessary input data
|
* @param inputData The struct containing all the neccessary input data
|
||||||
*/
|
*/
|
||||||
function importEuler(
|
function importEuler(
|
||||||
|
@ -25,22 +24,20 @@ contract EulerImport is EulerHelpers {
|
||||||
payable
|
payable
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
(_eventName, _eventParam) = _importEuler(userAccount, sourceId, targetId, inputData);
|
(_eventName, _eventParam) = _importEuler(
|
||||||
}
|
userAccount,
|
||||||
|
sourceId,
|
||||||
struct importHelper {
|
targetId,
|
||||||
uint enterMarketLength;
|
inputData
|
||||||
uint supplylength;
|
);
|
||||||
uint borrowlength;
|
|
||||||
uint totalLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Import Euler position .
|
* @dev Import Euler position .
|
||||||
* @notice Import EOA's Euler position to DSA's Euler position
|
* @notice Import EOA's Euler position to DSA's Euler position
|
||||||
* @param userAccount The address of the EOA from which position will be imported
|
* @param userAccount EOA address
|
||||||
* @param sourceId sub-account id of EOA from which the funds will be transferred
|
* @param sourceId Sub-account id of "EOA" from which the funds will be transferred
|
||||||
* @param targetId sub-account id of DSA to which the funds will be transferred
|
* @param targetId Sub-account id of "DSA" to which the funds will be transferred
|
||||||
* @param inputData The struct containing all the neccessary input data
|
* @param inputData The struct containing all the neccessary input data
|
||||||
*/
|
*/
|
||||||
function _importEuler(
|
function _importEuler(
|
||||||
|
@ -53,83 +50,91 @@ contract EulerImport is EulerHelpers {
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
{
|
{
|
||||||
|
|
||||||
importHelper memory helper;
|
require(inputData._supplyTokens.length > 0, "0-length-not-allowed");
|
||||||
|
|
||||||
require(
|
require(
|
||||||
AccountInterface(address(this)).isAuth(userAccount),
|
AccountInterface(address(this)).isAuth(userAccount),
|
||||||
"user-account-not-auth"
|
"user-account-not-auth"
|
||||||
);
|
);
|
||||||
require(inputData.supplyTokens.length > 0, "0-length-not-allowed");
|
require(
|
||||||
|
inputData._enterMarket.length == inputData._supplyTokens.length,
|
||||||
|
"lengths-not-same"
|
||||||
|
);
|
||||||
|
|
||||||
ImportData memory data;
|
ImportData memory data;
|
||||||
|
ImportHelper memory helper;
|
||||||
|
|
||||||
helper.enterMarketLength = inputData.enterMarket.length;
|
helper.sourceAccount = getSubAccountAddress(userAccount, sourceId);
|
||||||
|
helper.targetAccount = getSubAccountAddress(address(this), targetId);
|
||||||
|
|
||||||
require(helper.enterMarketLength == inputData.supplyTokens.length, "lengths-not-same");
|
// BorrowAmts will be in underlying token decimals
|
||||||
|
data = getBorrowAmounts(helper.sourceAccount, inputData, data);
|
||||||
|
|
||||||
address _sourceAccount = getSubAccountAddress(userAccount, sourceId);
|
// SupplyAmts will be in 18 decimals
|
||||||
address _targetAccount = getSubAccountAddress(address(this), targetId);
|
data = getSupplyAmounts(helper.sourceAccount, inputData, data);
|
||||||
|
|
||||||
data = getBorrowAmounts(_sourceAccount, inputData, data);
|
helper.supplylength = data.supplyTokens.length;
|
||||||
|
helper.borrowlength = data.borrowTokens.length;
|
||||||
|
uint16 enterMarkets = 0;
|
||||||
|
|
||||||
// In 18 dec
|
for (uint16 i = 0; i < inputData._enterMarket.length; i++) {
|
||||||
data = getSupplyAmounts(_sourceAccount, inputData, data);
|
if (inputData._enterMarket[i]) {
|
||||||
|
++enterMarkets;
|
||||||
helper.supplylength = data._supplyTokens.length;
|
}
|
||||||
helper.borrowlength = data._borrowTokens.length;
|
|
||||||
uint count = 0;
|
|
||||||
|
|
||||||
for(uint i = 0; i < helper.enterMarketLength; i++) {
|
|
||||||
count = inputData.enterMarket[i] ? count++ : count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.totalLength = count + helper.supplylength + helper.borrowlength;
|
helper.totalExecutions = helper.supplylength + enterMarkets + helper.borrowlength;
|
||||||
|
|
||||||
IEulerExecute.EulerBatchItem[] memory items = new IEulerExecute.EulerBatchItem[](helper.totalLength);
|
IEulerExecute.EulerBatchItem[]
|
||||||
|
memory items = new IEulerExecute.EulerBatchItem[](
|
||||||
|
helper.totalExecutions
|
||||||
|
);
|
||||||
|
|
||||||
uint k = 0;
|
uint16 k = 0;
|
||||||
|
|
||||||
for(uint i = 0; i < helper.supplylength; i++) {
|
|
||||||
|
|
||||||
|
for (uint16 i = 0; i < helper.supplylength; i++) {
|
||||||
items[k] = IEulerExecute.EulerBatchItem({
|
items[k] = IEulerExecute.EulerBatchItem({
|
||||||
allowError: false,
|
allowError: false,
|
||||||
proxyAddr: address(data.eTokens[i]),
|
proxyAddr: address(data.eTokens[i]),
|
||||||
data: abi.encodeWithSignature(
|
data: abi.encodeWithSignature(
|
||||||
"transferFrom(address,address,uint256)",
|
"transferFrom(address,address,uint256)",
|
||||||
_sourceAccount, _targetAccount, data.supplyAmts[i]
|
helper.sourceAccount,
|
||||||
|
helper.targetAccount,
|
||||||
|
data.supplyAmts[i]
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
k++;
|
k++;
|
||||||
|
|
||||||
if (inputData.enterMarket[i]) {
|
if (inputData._enterMarket[i]) {
|
||||||
|
|
||||||
items[k] = IEulerExecute.EulerBatchItem({
|
items[k] = IEulerExecute.EulerBatchItem({
|
||||||
allowError: false,
|
allowError: false,
|
||||||
proxyAddr: address(markets),
|
proxyAddr: address(markets),
|
||||||
data: abi.encodeWithSignature(
|
data: abi.encodeWithSignature(
|
||||||
"enterMarket(uint256,address)",
|
"enterMarket(uint256,address)",
|
||||||
targetId, data._supplyTokens[i]
|
targetId,
|
||||||
|
data.supplyTokens[i]
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(uint j = 0; j < helper.borrowlength; j++) {
|
for (uint16 j = 0; j < helper.borrowlength; j++) {
|
||||||
items[k] = IEulerExecute.EulerBatchItem({
|
items[k] = IEulerExecute.EulerBatchItem({
|
||||||
allowError: false,
|
allowError: false,
|
||||||
proxyAddr: address(data.dTokens[j]),
|
proxyAddr: address(data.dTokens[j]),
|
||||||
data: abi.encodeWithSignature(
|
data: abi.encodeWithSignature(
|
||||||
"transferFrom(address,address,uint256)",
|
"transferFrom(address,address,uint256)",
|
||||||
_sourceAccount, _targetAccount, data.borrowAmts[j]
|
helper.sourceAccount,
|
||||||
|
helper.targetAccount,
|
||||||
|
data.borrowAmts[j]
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
|
|
||||||
address[] memory deferLiquidityChecks = new address[](2);
|
address[] memory deferLiquidityChecks = new address[](2);
|
||||||
deferLiquidityChecks[0] = _sourceAccount;
|
deferLiquidityChecks[0] = helper.sourceAccount;
|
||||||
deferLiquidityChecks[1] = _targetAccount;
|
deferLiquidityChecks[1] = helper.targetAccount;
|
||||||
|
|
||||||
eulerExec.batchDispatch(items, deferLiquidityChecks);
|
eulerExec.batchDispatch(items, deferLiquidityChecks);
|
||||||
|
|
||||||
|
@ -138,9 +143,11 @@ contract EulerImport is EulerHelpers {
|
||||||
userAccount,
|
userAccount,
|
||||||
sourceId,
|
sourceId,
|
||||||
targetId,
|
targetId,
|
||||||
inputData.supplyTokens,
|
inputData._supplyTokens,
|
||||||
inputData.borrowTokens,
|
data.supplyAmts,
|
||||||
inputData.enterMarket
|
inputData._borrowTokens,
|
||||||
|
data.borrowAmts,
|
||||||
|
inputData._enterMarket
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user