lint added

This commit is contained in:
Shriya Tyagi 2022-07-06 17:40:38 +04:00
parent 37103d99ef
commit a110574642
5 changed files with 335 additions and 247 deletions

View File

@ -2,100 +2,93 @@
pragma solidity ^0.7.0; pragma solidity ^0.7.0;
contract Events { contract Events {
event LogDeposit(
uint256 subaccount,
address token,
uint256 amount,
bool enableCollateral,
uint256 getId,
uint256 setId
);
event LogDeposit( event LogWithdraw(
uint256 subaccount, uint256 subaccount,
address token, address token,
uint256 amount, uint256 amount,
bool enableCollateral, uint256 getId,
uint256 getId, uint256 setId
uint256 setId );
);
event LogWithdraw( event LogBorrow(
uint256 subaccount, uint256 subAccount,
address token, address token,
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
); );
event LogBorrow( event LogRepay(
uint256 subAccount, uint256 subAccount,
address token, address token,
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
); );
event LogRepay( event LogMint(
uint256 subAccount, uint256 subAccount,
address token, address token,
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
); );
event LogMint( event LogBurn(
uint256 subAccount, uint256 subAccount,
address token, address token,
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
); );
event LogBurn( event LogETransfer(
uint256 subAccount, uint256 subAccount1,
address token, uint256 subAccount2,
uint256 amount, address token,
uint256 getId, uint256 amount,
uint256 setId uint256 getId,
); uint256 setId
);
event LogETransfer( event LogDTransfer(
uint256 subAccount1, uint256 subAccount1,
uint256 subAccount2, uint256 subAccount2,
address token, address token,
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
); );
event LogDTransfer( event LogApproveDebt(
uint256 subAccount1, uint256 subAccountId,
uint256 subAccount2,
address token,
uint256 amount,
uint256 getId,
uint256 setId
);
event LogApproveDebt(
uint256 subAccountId,
address debtReceiver, address debtReceiver,
address token, address token,
uint256 amount, uint256 amount,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
); );
event LogSwap( event LogSwap(
uint256 subAccountFrom, uint256 subAccountFrom,
uint subAccountTo, uint256 subAccountTo,
address buyAddr, address buyAddr,
address sellAddr, address sellAddr,
uint sellAmt, uint256 sellAmt,
uint unitAmt, uint256 unitAmt,
bytes callData bytes callData
); );
event LogEnterMarket( event LogEnterMarket(uint256 subAccountId, address[] newMarkets);
uint subAccountId,
address[] newMarkets
);
event LogExitMarket( event LogExitMarket(uint256 subAccountId, address oldMarket);
uint subAccountId,
address oldMarket
);
} }

View File

@ -5,8 +5,7 @@ import "./events.sol";
import { Basic } from "../../common/basic.sol"; import { Basic } from "../../common/basic.sol";
contract Helpers is Basic, Variables, Events { contract Helpers is Basic, Variables, Events {
/**
/**
* @dev Get total collateral balance for an asset * @dev Get total collateral balance for an asset
*/ */
function getEnteredMarkets() function getEnteredMarkets()
@ -17,21 +16,24 @@ contract Helpers is Basic, Variables, Events {
enteredMarkets = markets.getEnteredMarkets(address(this)); enteredMarkets = markets.getEnteredMarkets(address(this));
} }
function getSubAccount(address primary, uint subAccountId) public pure returns (address) { function getSubAccount(address primary, uint256 subAccountId)
require(subAccountId < 256, "sub-account-id-too-big"); public
return address(uint160(primary) ^ uint160(subAccountId)); pure
} returns (address)
{
require(subAccountId < 256, "sub-account-id-too-big");
return address(uint160(primary) ^ uint160(subAccountId));
}
function checkIfEnteredMarket(address token) public view returns(bool) { function checkIfEnteredMarket(address token) public view returns (bool) {
address[] memory enteredMarkets = getEnteredMarkets(); address[] memory enteredMarkets = getEnteredMarkets();
uint256 length = enteredMarkets.length; uint256 length = enteredMarkets.length;
for(uint i = 0; i < length; i++) { for (uint256 i = 0; i < length; i++) {
if(enteredMarkets[i] == token) { if (enteredMarkets[i] == token) {
return true; return true;
} }
} }
return false; return false;
} }
} }

View File

@ -3,44 +3,77 @@ pragma solidity ^0.7.0;
pragma experimental ABIEncoderV2; pragma experimental ABIEncoderV2;
interface IEulerMarkets { interface IEulerMarkets {
function enterMarket(uint subAccountId, address newMarket) external; function enterMarket(uint256 subAccountId, address newMarket) external;
function getEnteredMarkets(address account) external view returns (address[] memory);
function exitMarket(uint subAccountId, address oldMarket) external; function getEnteredMarkets(address account)
function underlyingToEToken(address underlying) external view returns (address); external
function underlyingToDToken(address underlying) external view returns (address); view
returns (address[] memory);
function exitMarket(uint256 subAccountId, address oldMarket) external;
function underlyingToEToken(address underlying)
external
view
returns (address);
function underlyingToDToken(address underlying)
external
view
returns (address);
} }
interface IEulerEToken { interface IEulerEToken {
function deposit(uint subAccountId, uint amount) external; function deposit(uint256 subAccountId, uint256 amount) external;
function withdraw(uint subAccountId, uint amount) external;
function decimals() external view returns (uint8); function withdraw(uint256 subAccountId, uint256 amount) external;
function mint(uint subAccountId, uint amount) external;
function burn(uint subAccountId, uint amount) external; function decimals() external view returns (uint8);
function balanceOf(address account) external view returns (uint);
function transfer(address to, uint amount) external returns (bool); function mint(uint256 subAccountId, uint256 amount) external;
function approve(address spender, uint amount) external returns (bool);
function burn(uint256 subAccountId, uint256 amount) external;
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
} }
interface IEulerDToken { interface IEulerDToken {
function underlyingToDToken(address underlying) external view returns (address); function underlyingToDToken(address underlying)
function decimals() external view returns (uint8); external
function borrow(uint subAccountId, uint amount) external; view
function repay(uint subAccountId, uint amount) external; returns (address);
function balanceOf(address account) external view returns (uint);
function transfer(address to, uint amount) external returns (bool); function decimals() external view returns (uint8);
function approveDebt(uint subAccountId, address spender, uint amount) external returns (bool);
function borrow(uint256 subAccountId, uint256 amount) external;
function repay(uint256 subAccountId, uint256 amount) external;
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function approveDebt(
uint256 subAccountId,
address spender,
uint256 amount
) external returns (bool);
} }
interface IEulerSwap { interface IEulerSwap {
struct Swap1InchParams { struct Swap1InchParams {
uint subAccountIdIn; uint256 subAccountIdIn;
uint subAccountIdOut; uint256 subAccountIdOut;
address underlyingIn; address underlyingIn;
address underlyingOut; address underlyingOut;
uint amount; uint256 amount;
uint amountOutMinimum; uint256 amountOutMinimum;
bytes payload; bytes payload;
} }
function swap1Inch(Swap1InchParams memory) external; function swap1Inch(Swap1InchParams memory) external;
} }

View File

@ -9,21 +9,21 @@ import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
abstract contract Euler is Helpers { abstract contract Euler is Helpers {
using SafeERC20 for IERC20; using SafeERC20 for IERC20;
/** /**
* @dev Deposit ETH/ERC20_Token. * @dev Deposit ETH/ERC20_Token.
* @notice Deposit a token to Euler for lending / collaterization. * @notice Deposit a token to Euler for lending / collaterization.
* @param subAccount Subaccount number * @param subAccount Subaccount number
* @param token The address of the token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to deposit.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to deposit. (For max: `uint256(-1)`) * @param amt The amount of the token to deposit. (For max: `uint256(-1)`)
* @param enableCollateral True for entering the market * @param enableCollateral True for entering the market
* @param getId ID to retrieve amt. * @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens deposited. * @param setId ID stores the amount of tokens deposited.
*/ */
function deposit( function deposit(
uint256 subAccount, uint256 subAccount,
address token, address token,
uint256 amt, uint256 amt,
bool enableCollateral, bool enableCollateral,
uint256 getId, uint256 getId,
uint256 setId uint256 setId
) )
@ -50,28 +50,35 @@ abstract contract Euler is Helpers {
approve(tokenContract, EULER_MAINNET, _amt); approve(tokenContract, EULER_MAINNET, _amt);
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
eToken.deposit(subAccount, _amt);//0 for primary eToken.deposit(subAccount, _amt); //0 for primary
if (enableCollateral) { if (enableCollateral) {
markets.enterMarket(subAccount, _token); markets.enterMarket(subAccount, _token);
} }
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogDeposit(uint256,address,uint256,bool,uint256,uint256)"; _eventName = "LogDeposit(uint256,address,uint256,bool,uint256,uint256)";
_eventParam = abi.encode(subAccount, token, _amt, enableCollateral, getId, setId); _eventParam = abi.encode(
subAccount,
token,
_amt,
enableCollateral,
getId,
setId
);
} }
/** /**
* @dev Withdraw ETH/ERC20_Token. * @dev Withdraw ETH/ERC20_Token.
* @notice Withdraw deposited token Euler * @notice Withdraw deposited token Euler
* @param subAccount Subaccount number * @param subAccount Subaccount number
* @param token The address of the token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to withdraw.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`) * @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
* @param getId ID to retrieve amt. * @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens withdrawn. * @param setId ID stores the amount of tokens withdrawn.
*/ */
function withdraw( function withdraw(
uint256 subAccount, uint256 subAccount,
address token, address token,
uint256 amt, uint256 amt,
uint256 getId, uint256 getId,
@ -88,7 +95,7 @@ abstract contract Euler is Helpers {
TokenInterface tokenContract = TokenInterface(_token); TokenInterface tokenContract = TokenInterface(_token);
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
uint256 initialBal = tokenContract.balanceOf(address(this)); uint256 initialBal = tokenContract.balanceOf(address(this));
eToken.withdraw(subAccount, _amt); eToken.withdraw(subAccount, _amt);
@ -107,14 +114,14 @@ abstract contract Euler is Helpers {
/** /**
* @dev Borrow ETH/ERC20_Token. * @dev Borrow ETH/ERC20_Token.
* @notice Borrow a token from Euler * @notice Borrow a token from Euler
* @param subAccount Subaccount number * @param subAccount Subaccount number
* @param token The address of the token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to borrow.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to borrow. (For max: `uint256(-1)`) * @param amt The amount of the token to borrow. (For max: `uint256(-1)`)
* @param getId ID to retrieve amt. * @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens deposited. * @param setId ID stores the amount of tokens deposited.
*/ */
function borrow( function borrow(
uint256 subAccount, uint256 subAccount,
address token, address token,
uint256 amt, uint256 amt,
uint256 getId, uint256 getId,
@ -124,33 +131,35 @@ abstract contract Euler is Helpers {
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
uint256 _amt = getUint(getId, amt);//max value? uint256 _amt = getUint(getId, amt);
bool isEth = token == ethAddr ? true : false; bool isEth = token == ethAddr ? true : false;
address _token = isEth ? wethAddr : token; address _token = isEth ? wethAddr : token;
IEulerDToken borrowedDToken = IEulerDToken(markets.underlyingToDToken(_token)); IEulerDToken borrowedDToken = IEulerDToken(
borrowedDToken.borrow(subAccount, amt); markets.underlyingToDToken(_token)
);
borrowedDToken.borrow(subAccount, amt);
convertWethToEth(isEth, TokenInterface(_token), _amt); convertWethToEth(isEth, TokenInterface(_token), _amt);
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogBorrow(uint256,address,uint256,uint256,uint256)"; _eventName = "LogBorrow(uint256,address,uint256,uint256,uint256)";
_eventParam = abi.encode(subAccount, token, _amt, getId, setId); _eventParam = abi.encode(subAccount, token, _amt, getId, setId);
} }
/** /**
* @dev Repay ETH/ERC20_Token. * @dev Repay ETH/ERC20_Token.
* @notice Repay a token from Euler * @notice Repay a token from Euler
* @param subAccount Subaccount number * @param subAccount Subaccount number
* @param token The address of the token to repay.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to repay.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to repay. (For max: `uint256(-1)`) * @param amt The amount of the token to repay. (For max: `uint256(-1)`)
* @param getId ID to retrieve amt. * @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens deposited. * @param setId ID stores the amount of tokens deposited.
*/ */
function repay( function repay(
uint256 subAccount, uint256 subAccount,
address token, address token,
uint256 amt, uint256 amt,
uint256 getId, uint256 getId,
@ -160,37 +169,41 @@ abstract contract Euler is Helpers {
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
uint256 _amt = getUint(getId, amt); uint256 _amt = getUint(getId, amt);
bool isEth = token == ethAddr ? true : false; bool isEth = token == ethAddr ? true : false;
address _token = isEth ? wethAddr : token; address _token = isEth ? wethAddr : token;
IEulerDToken borrowedDToken = IEulerDToken(markets.underlyingToDToken(_token)); IEulerDToken borrowedDToken = IEulerDToken(
markets.underlyingToDToken(_token)
);
if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
_amt = _amt == type(uint).max ? borrowedDToken.balanceOf(address(this)) : _amt; _amt = _amt == type(uint256).max
? borrowedDToken.balanceOf(address(this))
: _amt;
TokenInterface(_token).approve(EULER_MAINNET, _amt); TokenInterface(_token).approve(EULER_MAINNET, _amt);
borrowedDToken.repay(subAccount, amt); borrowedDToken.repay(subAccount, amt);
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogRepay(uint256,address,uint256,uint256,uint256)"; _eventName = "LogRepay(uint256,address,uint256,uint256,uint256)";
_eventParam = abi.encode(subAccount, token, _amt, getId, setId); _eventParam = abi.encode(subAccount, token, _amt, getId, setId);
} }
/** /**
* @dev Mint ETH/ERC20_Token. * @dev Mint ETH/ERC20_Token.
* @notice Mint a token from Euler. Maint creates equal amount of deposits and debts. * @notice Mint a token from Euler. Maint creates equal amount of deposits and debts.
* @param subAccount Subaccount number * @param subAccount Subaccount number
* @param token The address of the token to mint.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to mint.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to mint. * @param amt The amount of the token to mint.
* @param getId ID to retrieve amt. * @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens deposited. * @param setId ID stores the amount of tokens deposited.
*/ */
function mint( function mint(
uint256 subAccount, uint256 subAccount,
address token, address token,
uint256 amt, uint256 amt,
uint256 getId, uint256 getId,
@ -200,66 +213,68 @@ abstract contract Euler is Helpers {
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
uint256 _amt = getUint(getId, amt); uint256 _amt = getUint(getId, amt);
bool isEth = token == ethAddr ? true : false; bool isEth = token == ethAddr ? true : false;
address _token = isEth ? wethAddr : token; address _token = isEth ? wethAddr : token;
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
eToken.mint(subAccount, amt); eToken.mint(subAccount, amt);
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogMint(uint256,address,uint256,uint256,uint256)"; _eventName = "LogMint(uint256,address,uint256,uint256,uint256)";
_eventParam = abi.encode(subAccount, token, _amt, getId, setId); _eventParam = abi.encode(subAccount, token, _amt, getId, setId);
} }
/** /**
* @dev Burn ETH/ERC20_Token. * @dev Burn ETH/ERC20_Token.
* @notice Burn a token from Euler. Burn removes equal amount of deposits and debts. * @notice Burn a token from Euler. Burn removes equal amount of deposits and debts.
* @param subAccount Subaccount number * @param subAccount Subaccount number
* @param token The address of the token to burn.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to burn.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to burn. (For max: `uint256(-1)`) * @param amt The amount of the token to burn. (For max: `uint256(-1)`)
* @param getId ID to retrieve amt. * @param getId ID to retrieve amt.
* @param setId ID stores the amount of tokens deposited. * @param setId ID stores the amount of tokens deposited.
*/ */
function burn( function burn(
uint256 subAccount, uint256 subAccount,
address token,//eth address token,
uint256 amt,//max uint256 amt,
uint256 getId,//1 uint256 getId,
uint256 setId uint256 setId
) )
external external
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
uint256 _amt = getUint(getId, amt); uint256 _amt = getUint(getId, amt);
bool isEth = token == ethAddr ? true : false; bool isEth = token == ethAddr ? true : false;
address _token = isEth ? wethAddr : token; address _token = isEth ? wethAddr : token;
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token)); IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
_amt = _amt == type(uint).max ? dToken.balanceOf(address(this)) : _amt; _amt = _amt == type(uint256).max
? dToken.balanceOf(address(this))
: _amt;
if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
eToken.burn(subAccount, amt); eToken.burn(subAccount, amt);
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogBurn(uint256,address,uint256,uint256,uint256)"; _eventName = "LogBurn(uint256,address,uint256,uint256,uint256)";
_eventParam = abi.encode(subAccount, token, _amt, getId, setId); _eventParam = abi.encode(subAccount, token, _amt, getId, setId);
} }
/** /**
* @dev ETransfer ETH/ERC20_Token. * @dev ETransfer ETH/ERC20_Token.
* @notice ETransfer deposits from account to another. * @notice ETransfer deposits from account to another.
* @param subAccountFrom subAccount from which deposit is transferred * @param subAccountFrom subAccount from which deposit is transferred
* @param subAccountTo subAccount to which deposit is transferred * @param subAccountTo subAccount to which deposit is transferred
* @param token The address of the token to etransfer.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to etransfer.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to etransfer. (For max: `uint256(-1)`) * @param amt The amount of the token to etransfer. (For max: `uint256(-1)`)
@ -267,42 +282,51 @@ abstract contract Euler is Helpers {
* @param setId ID stores the amount of tokens deposited. * @param setId ID stores the amount of tokens deposited.
*/ */
function eTransfer( function eTransfer(
uint256 subAccountFrom, uint256 subAccountFrom,
uint256 subAccountTo, uint256 subAccountTo,
address token,//eth address token,
uint256 amt,//max uint256 amt,
uint256 getId,//1 uint256 getId,
uint256 setId uint256 setId
) )
external external
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
uint256 _amt = getUint(getId, amt); uint256 _amt = getUint(getId, amt);
bool isEth = token == ethAddr ? true : false; bool isEth = token == ethAddr ? true : false;
address _token = isEth ? wethAddr : token; address _token = isEth ? wethAddr : token;
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
_amt = _amt == type(uint).max ? eToken.balanceOf(address(this)) : _amt; _amt = _amt == type(uint256).max
? eToken.balanceOf(address(this))
: _amt;
if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
address _subAccountToAddr = getSubAccount(address(this), subAccountTo); address _subAccountToAddr = getSubAccount(address(this), subAccountTo);
eToken.transfer(_subAccountToAddr, amt); eToken.transfer(_subAccountToAddr, amt);
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogETransfer(uint256,uint256,address,uint256,uint256,uint256)"; _eventName = "LogETransfer(uint256,uint256,address,uint256,uint256,uint256)";
_eventParam = abi.encode(subAccountFrom, subAccountTo, token, _amt, getId, setId); _eventParam = abi.encode(
} subAccountFrom,
subAccountTo,
token,
_amt,
getId,
setId
);
}
/** /**
* @dev DTransfer ETH/ERC20_Token. * @dev DTransfer ETH/ERC20_Token.
* @notice DTransfer deposits from account to another. * @notice DTransfer deposits from account to another.
* @param subAccountFrom subAccount from which debt is transferred * @param subAccountFrom subAccount from which debt is transferred
* @param subAccountTo subAccount to which debt is transferred * @param subAccountTo subAccount to which debt is transferred
* @param token The address of the token to dtransfer.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE) * @param token The address of the token to dtransfer.(For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
* @param amt The amount of the token to dtransfer. (For max: `uint256(-1)`) * @param amt The amount of the token to dtransfer. (For max: `uint256(-1)`)
@ -310,36 +334,45 @@ abstract contract Euler is Helpers {
* @param setId ID stores the amount of tokens deposited. * @param setId ID stores the amount of tokens deposited.
*/ */
function dTransfer( function dTransfer(
uint256 subAccountFrom, uint256 subAccountFrom,
uint256 subAccountTo, uint256 subAccountTo,
address token,//eth address token,
uint256 amt,//max uint256 amt,
uint256 getId,//1 uint256 getId,
uint256 setId uint256 setId
) )
external external
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
uint256 _amt = getUint(getId, amt); uint256 _amt = getUint(getId, amt);
bool isEth = token == ethAddr ? true : false; bool isEth = token == ethAddr ? true : false;
address _token = isEth ? wethAddr : token; address _token = isEth ? wethAddr : token;
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token)); IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
_amt = _amt == type(uint).max ? dToken.balanceOf(address(this)) : _amt; _amt = _amt == type(uint256).max
? dToken.balanceOf(address(this))
: _amt;
if(isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt); if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);
address _subAccountToAddr = getSubAccount(address(this), subAccountTo); address _subAccountToAddr = getSubAccount(address(this), subAccountTo);
dToken.transfer(_subAccountToAddr, amt); dToken.transfer(_subAccountToAddr, amt);
setUint(setId, _amt); setUint(setId, _amt);
_eventName = "LogDTransfer(uint256,uint256,address,uint256,uint256,uint256)"; _eventName = "LogDTransfer(uint256,uint256,address,uint256,uint256,uint256)";
_eventParam = abi.encode(subAccountFrom, subAccountTo, token, _amt, getId, setId); _eventParam = abi.encode(
} subAccountFrom,
subAccountTo,
token,
_amt,
getId,
setId
);
}
function approveDebt( function approveDebt(
uint256 subAccountId, uint256 subAccountId,
@ -359,7 +392,9 @@ abstract contract Euler is Helpers {
address _token = isEth ? wethAddr : token; address _token = isEth ? wethAddr : token;
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token)); IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
_amt = _amt == type(uint).max ? dToken.balanceOf(address(this)) : _amt; _amt = _amt == type(uint256).max
? dToken.balanceOf(address(this))
: _amt;
dToken.approveDebt(subAccountId, debtReceiver, _amt); dToken.approveDebt(subAccountId, debtReceiver, _amt);
@ -372,64 +407,84 @@ abstract contract Euler is Helpers {
struct swapHelper { struct swapHelper {
address _sellAddr; address _sellAddr;
address _buyAddr; address _buyAddr;
uint _buyDec; uint256 _buyDec;
uint _sellDec; uint256 _sellDec;
uint _sellAmt18; uint256 _sellAmt18;
uint _slippageAmt; uint256 _slippageAmt;
} }
struct swapParams { struct swapParams {
uint256 subAccountFrom; uint256 subAccountFrom;
uint subAccountTo; uint256 subAccountTo;
address buyAddr; address buyAddr;
address sellAddr; address sellAddr;
uint sellAmt; uint256 sellAmt;
uint unitAmt; uint256 unitAmt;
bytes callData; bytes callData;
} }
function swap( function swap(swapParams memory params)
swapParams memory params
)
external external
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
{ {
swapHelper memory helperParams; swapHelper memory helperParams;
helperParams._sellAddr = params.sellAddr == ethAddr ? wethAddr : params.sellAddr; helperParams._sellAddr = params.sellAddr == ethAddr
helperParams._buyAddr = params.sellAddr == ethAddr ? wethAddr : params.buyAddr; ? wethAddr
: params.sellAddr;
helperParams._buyAddr = params.sellAddr == ethAddr
? wethAddr
: params.buyAddr;
TokenInterface sellToken = TokenInterface(helperParams._sellAddr); TokenInterface sellToken = TokenInterface(helperParams._sellAddr);
TokenInterface buyToken = TokenInterface(helperParams._buyAddr); TokenInterface buyToken = TokenInterface(helperParams._buyAddr);
approve(sellToken, address(swapExec), params.sellAmt); approve(sellToken, address(swapExec), params.sellAmt);
(helperParams._buyDec, helperParams._sellDec) = getTokensDec(buyToken, sellToken); (helperParams._buyDec, helperParams._sellDec) = getTokensDec(
helperParams._sellAmt18 = convertTo18(helperParams._sellDec, params.sellAmt); buyToken,
helperParams._slippageAmt = convert18ToDec(helperParams._buyDec, wmul(params.unitAmt, helperParams._sellAmt18)); sellToken
);
helperParams._sellAmt18 = convertTo18(
helperParams._sellDec,
params.sellAmt
);
helperParams._slippageAmt = convert18ToDec(
helperParams._buyDec,
wmul(params.unitAmt, helperParams._sellAmt18)
);
IEulerSwap.Swap1InchParams memory oneInchParams = IEulerSwap.Swap1InchParams({ IEulerSwap.Swap1InchParams memory oneInchParams = IEulerSwap
subAccountIdIn: params.subAccountFrom, .Swap1InchParams({
subAccountIdOut: params.subAccountTo, subAccountIdIn: params.subAccountFrom,
underlyingIn: helperParams._sellAddr, subAccountIdOut: params.subAccountTo,
underlyingOut: helperParams._buyAddr, underlyingIn: helperParams._sellAddr,
amount: params.sellAmt, underlyingOut: helperParams._buyAddr,
amountOutMinimum: helperParams._slippageAmt, amount: params.sellAmt,
payload: params.callData amountOutMinimum: helperParams._slippageAmt,
}); payload: params.callData
});
swapExec.swap1Inch(oneInchParams); swapExec.swap1Inch(oneInchParams);
if(!checkIfEnteredMarket(helperParams._buyAddr)) { if (!checkIfEnteredMarket(helperParams._buyAddr)) {
markets.enterMarket(params.subAccountTo, helperParams._buyAddr); markets.enterMarket(params.subAccountTo, helperParams._buyAddr);
} }
_eventName = "LogSwap(uint256,uint256,address,address,uint256,uint256,bytes)"; _eventName = "LogSwap(uint256,uint256,address,address,uint256,uint256,bytes)";
_eventParam = abi.encode(params.subAccountFrom, params.subAccountTo, params.buyAddr, params.sellAddr, params.sellAmt, params.unitAmt, params.callData); _eventParam = abi.encode(
} params.subAccountFrom,
params.subAccountTo,
params.buyAddr,
params.sellAddr,
params.sellAmt,
params.unitAmt,
params.callData
);
}
function enterMarket(uint subAccountId, address[] memory newMarkets) function enterMarket(uint256 subAccountId, address[] memory newMarkets)
external external
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)
@ -441,7 +496,9 @@ abstract contract Euler is Helpers {
bool isEth = newMarkets[i] == ethAddr; bool isEth = newMarkets[i] == ethAddr;
address _token = isEth ? wethAddr : newMarkets[i]; address _token = isEth ? wethAddr : newMarkets[i];
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token)); IEulerEToken eToken = IEulerEToken(
markets.underlyingToEToken(_token)
);
markets.enterMarket(subAccountId, _token); markets.enterMarket(subAccountId, _token);
} }
@ -449,7 +506,7 @@ abstract contract Euler is Helpers {
_eventParam = abi.encode(subAccountId, newMarkets); _eventParam = abi.encode(subAccountId, newMarkets);
} }
function exitMarket(uint subAccountId, address oldMarket) function exitMarket(uint256 subAccountId, address oldMarket)
external external
payable payable
returns (string memory _eventName, bytes memory _eventParam) returns (string memory _eventName, bytes memory _eventParam)

View File

@ -3,7 +3,10 @@ pragma solidity ^0.7.0;
import "./interface.sol"; import "./interface.sol";
contract Variables { contract Variables {
address internal constant EULER_MAINNET = 0x27182842E098f60e3D576794A5bFFb0777E025d3; address internal constant EULER_MAINNET =
IEulerMarkets internal constant markets = IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3); 0x27182842E098f60e3D576794A5bFFb0777E025d3;
IEulerSwap internal constant swapExec = IEulerSwap(0x7123C8cBBD76c5C7fCC9f7150f23179bec0bA341); IEulerMarkets internal constant markets =
IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3);
IEulerSwap internal constant swapExec =
IEulerSwap(0x7123C8cBBD76c5C7fCC9f7150f23179bec0bA341);
} }