Added max check in burn + minor edits

This commit is contained in:
Shriya Tyagi 2022-08-14 18:34:45 +08:00
parent 34a4ad41bd
commit a599b46dee
3 changed files with 35 additions and 45 deletions

View File

@ -11,40 +11,10 @@ contract Helpers is Basic, Events {
IEulerMarkets internal constant markets =
IEulerMarkets(0x3520d5a913427E6F0D6A83E07ccD4A4da316e4d3);
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;
}
/**
* @dev Get Enetered markets for a user
*/
function getEnteredMarkets()
internal
view
returns (address[] memory enteredMarkets)
{
enteredMarkets = markets.getEnteredMarkets(address(this));
}
/**
* @dev Get sub account address
* @param primary address of user
* @param subAccountId subAccount ID
* @param subAccountId sub-account id
*/
function getSubAccount(address primary, uint256 subAccountId)
public
@ -55,12 +25,26 @@ contract Helpers is Basic, Events {
return address(uint160(primary) ^ uint160(subAccountId));
}
/**
* @dev Get Enetered markets for a user
* @param subAccountId sub-account id
*/
function getEnteredMarkets(uint256 subAccountId)
internal
view
returns (address[] memory enteredMarkets)
{
address _subAccountAddress = getSubAccount(address(this), subAccountId);
enteredMarkets = markets.getEnteredMarkets(_subAccountAddress);
}
/**
* @dev Check if the market is entered
* @param subAccountId sub-account id
* @param token token address
*/
function checkIfEnteredMarket(address token) public view returns (bool) {
address[] memory enteredMarkets = getEnteredMarkets();
function checkIfEnteredMarket(uint256 subAccountId, address token) public view returns (bool) {
address[] memory enteredMarkets = getEnteredMarkets(subAccountId);
uint256 length = enteredMarkets.length;
for (uint256 i = 0; i < length; i++) {

View File

@ -98,11 +98,11 @@ abstract contract Euler is Helpers {
address _subAccount = getSubAccount(address(this), subAccount);
_amt = _amt == uint256(-1) ? eToken.balanceOfUnderlying(_subAccount) : _amt;
uint256 initialBal = tokenContract.balanceOf(address(this));
uint256 initialBal = tokenContract.balanceOf(_subAccount);
eToken.withdraw(subAccount, _amt);
uint256 finalBal = tokenContract.balanceOf(address(this));
uint256 finalBal = tokenContract.balanceOf(_subAccount);
_amt = finalBal - initialBal;
convertWethToEth(isEth, tokenContract, _amt);
@ -259,9 +259,15 @@ abstract contract Euler is Helpers {
IEulerDToken dToken = IEulerDToken(markets.underlyingToDToken(_token));
IEulerEToken eToken = IEulerEToken(markets.underlyingToEToken(_token));
_amt = _amt == type(uint256).max
? dToken.balanceOf(address(this))
: _amt;
address _subAccount = getSubAccount(address(this), subAccount);
if(_amt == uint256(-1)) {
uint256 _eTokenBalance = eToken.balanceOfUnderlying(_subAccount);
uint256 _dTokenBalance = dToken.balanceOf(_subAccount);
_amt = _eTokenBalance <= _dTokenBalance ? _eTokenBalance : _dTokenBalance;
}
if (isEth) convertEthToWeth(isEth, TokenInterface(_token), _amt);

View File

@ -172,7 +172,7 @@ describe("Euler", function () {
{
connector: connectorName,
method: "deposit",
args: ["0", tokens.usdc.address, "10000000", "true", "0", "0"],
args: ["0", tokens.usdc.address, "10000000", "true", "0", "0"], // 10 USDC
},
];
@ -188,7 +188,7 @@ describe("Euler", function () {
{
connector: connectorName,
method: "deposit",
args: ["1", tokens.usdc.address, "10000000", "true", "0", "0"],
args: ["1", tokens.usdc.address, "10000000", "true", "0", "0"], // 10 USDC
},
];
@ -206,7 +206,7 @@ describe("Euler", function () {
{
connector: connectorName,
method: "borrow",
args: ["0", tokens.dai.address, "1000000000000000000", "0", "0"],
args: ["0", tokens.dai.address, "1000000000000000000", "0", "0"], // 1 DAI
},
];
@ -224,7 +224,7 @@ describe("Euler", function () {
{
connector: connectorName,
method: "repay",
args: ["0", tokens.dai.address, "500000000000000000", "0", "0"],
args: ["0", tokens.dai.address, "500000000000000000", "0", "0"], // 0.5 DAI
},
];
@ -243,7 +243,7 @@ describe("Euler", function () {
{
connector: connectorName,
method: "withdraw",
args: ["0", tokens.usdc.address, "2000000", "0", "0"],
args: ["0", tokens.usdc.address, "2000000", "0", "0"], // 2 USDC
},
];
@ -462,7 +462,7 @@ describe("Euler", function () {
{
connector: connectorName,
method: "deposit",
args: ["3", tokens.weth.address, "1000000000000000000", "true", "0", "0"],
args: ["3", tokens.dai.address, "1000000000000000000", "true", "0", "0"],
},
];
@ -492,7 +492,7 @@ describe("Euler", function () {
{
connector: connectorName,
method: "burn",
args: ["3", tokens.weth.address, "10000000", "0", "0"],
args: ["3", tokens.weth.address, "115792089237316195423570985008687907853269984665640564039457584007913129639935", "0", "0"],
},
];