This commit is contained in:
Richa-iitr 2022-09-03 02:06:46 +05:30
parent a4bf92bdbb
commit bd1dcf5ddc
3 changed files with 22 additions and 57 deletions

View File

@ -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))

View File

@ -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_);

View File

@ -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 = [
{