From bd1dcf5ddc091c497aa7115e030587f2d09c6f13 Mon Sep 17 00:00:00 2001 From: Richa-iitr Date: Sat, 3 Sep 2022 02:06:46 +0530 Subject: [PATCH] fixes --- .../connectors/compound/v3/helpers.sol | 47 +++++++------------ .../mainnet/connectors/compound/v3/main.sol | 12 ++--- test/mainnet/compound/compound.iii.test.ts | 20 -------- 3 files changed, 22 insertions(+), 57 deletions(-) diff --git a/contracts/mainnet/connectors/compound/v3/helpers.sol b/contracts/mainnet/connectors/compound/v3/helpers.sol index 6ab86013..3c1a3268 100644 --- a/contracts/mainnet/connectors/compound/v3/helpers.sol +++ b/contracts/mainnet/connectors/compound/v3/helpers.sol @@ -39,21 +39,6 @@ abstract contract Helpers is DSMath, Basic { baseToken = CometInterface(market).baseToken(); } - /** - *@dev helper function for following withdraw or borrow cases: - *withdrawFrom - for `withdrawFromUsingManager` withdraws from src to dest using DSA as manager - *withdrawTo - for `withdrawTo` withdraws from DSA to dest address. - */ - function _withdrawHelper( - address market, - address token, - address from, - address to, - uint256 amt - ) internal { - CometInterface(market).withdrawFrom(from, to, token, amt); - } - function _borrow(BorrowWithdrawParams memory params) internal returns (uint256 amt, uint256 setId) @@ -82,7 +67,12 @@ abstract contract Helpers is DSMath, Basic { params.from ); - CometInterface(params.market).withdrawFrom(params.from, params.to, token_, amt_); + CometInterface(params.market).withdrawFrom( + params.from, + params.to, + token_, + amt_ + ); uint256 finalBal = CometInterface(params.market).borrowBalanceOf( params.from @@ -123,7 +113,7 @@ abstract contract Helpers is DSMath, Basic { token_ ); - if (token_ == getBaseToken(market)) { + if (token_ == getBaseToken(params.market)) { //if there are supplies, ensure withdrawn amount is not greater than supplied i.e can't borrow using withdraw. if (amt_ == uint256(-1)) { amt_ = initialBal; @@ -136,14 +126,19 @@ abstract contract Helpers is DSMath, Basic { //if borrow balance > 0, there are no supplies so no withdraw, borrow instead. require( - CometInterface(market).borrowBalanceOf(params.from) == 0, + CometInterface(params.market).borrowBalanceOf(params.from) == 0, "withdraw-disabled-for-zero-supplies" ); } else { amt_ = amt_ == uint256(-1) ? initialBal : amt_; } - CometInterface(params.market).withdrawFrom(params.from, params.to, token_, amt_); + CometInterface(params.market).withdrawFrom( + params.from, + params.to, + token_, + amt_ + ); uint256 finalBal = _getAccountSupplyBalanceOfAsset( params.from, @@ -161,16 +156,6 @@ abstract contract Helpers is DSMath, Basic { setId = params.setId; } - function _transfer( - address market, - address token, - address from, - address to, - uint256 amt - ) internal { - CometInterface(market).transferAssetFrom(from, to, token, amt); - } - function _getAccountSupplyBalanceOfAsset( address account, address market, @@ -204,8 +189,8 @@ abstract contract Helpers is DSMath, Basic { } else if (action == Action.DEPOSIT) { if (isEth) bal_ = src.balance; else bal_ = TokenInterface(token).balanceOf(src); - } - + } + amt = bal_ < allowance_ ? bal_ : allowance_; } if (src == address(this)) diff --git a/contracts/mainnet/connectors/compound/v3/main.sol b/contracts/mainnet/connectors/compound/v3/main.sol index 9cdfe2b6..0de0d544 100644 --- a/contracts/mainnet/connectors/compound/v3/main.sol +++ b/contracts/mainnet/connectors/compound/v3/main.sol @@ -157,7 +157,7 @@ abstract contract CompoundV3Resolver is Events, Helpers { market != address(0) && token != address(0) && to != address(0), "invalid market/token/to address" ); - require(from != address(this), "from-cannot-be-address(this)-use-paybackOnBehalf"); + require(from != address(this), "from-cannot-be-address(this)-use-depositOnBehalf"); address token_ = token == ethAddr ? wethAddr : token; @@ -173,7 +173,7 @@ abstract contract CompoundV3Resolver is Events, Helpers { token_, from, amt_, - isEth, + token == ethAddr, Action.DEPOSIT ); @@ -717,7 +717,7 @@ abstract contract CompoundV3Resolver is Events, Helpers { token_, from, amt_, - isEth, + token == ethAddr, Action.REPAY ); } else { @@ -809,9 +809,9 @@ abstract contract CompoundV3Resolver is Events, Helpers { address token_ = token == ethAddr ? wethAddr : token; - amt_ = amt_ == uint256(-1) ? _getAccountSupplyBalanceOfAsset(address(this)) : amt_; + amt_ = amt_ == uint256(-1) ? _getAccountSupplyBalanceOfAsset(address(this), market, token) : amt_; - CometInterface(market).transferAssetFrom(address(this), dest, token_, amt); + CometInterface(market).transferAssetFrom(address(this), dest, token_, amt_); setUint(setId, amt_); @@ -851,7 +851,7 @@ abstract contract CompoundV3Resolver is Events, Helpers { address token_ = token == ethAddr ? wethAddr : token; - amt_ = amt_ == uint256(-1) ? _getAccountSupplyBalanceOfAsset(src) : amt_; + amt_ = amt_ == uint256(-1) ? _getAccountSupplyBalanceOfAsset(src, market, token) : amt_; CometInterface(market).transferAssetFrom(src, dest, token_, amt_); diff --git a/test/mainnet/compound/compound.iii.test.ts b/test/mainnet/compound/compound.iii.test.ts index f36b66cf..3d60c914 100644 --- a/test/mainnet/compound/compound.iii.test.ts +++ b/test/mainnet/compound/compound.iii.test.ts @@ -557,26 +557,6 @@ describe("Compound III", function () { expect(await wethContract.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte(initialBal.sub(amount)); }); - it("should deposit eth using manager same as 'from'", async function () { - const amount = ethers.utils.parseEther("1"); - await wethContract.connect(dsa0Signer).approve(market, amount); - let initialBal = await ethers.provider.getBalance(dsaWallet0.address); - - const spells = [ - { - connector: connectorName, - method: "depositFromUsingManager", - args: [market, tokens.eth.address, dsaWallet0.address, dsaWallet1.address, amount, 0, 0] - } - ]; - - const tx = await dsaWallet0.connect(wallet0).cast(...encodeSpells(spells), wallet1.address); - const receipt = await tx.wait(); - expect((await comet.connect(signer).userCollateral(dsaWallet1.address, tokens.weth.address)).balance).to.be.gte( - ethers.utils.parseEther("2") - ); - expect(await ethers.provider.getBalance(dsaWallet0.address)).to.be.lte(initialBal.sub(amount)); - }); it("should allow manager for dsaWallet0's collateral", async function () { const spells = [ {