mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
fixes
This commit is contained in:
parent
a4bf92bdbb
commit
bd1dcf5ddc
|
@ -39,21 +39,6 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
baseToken = CometInterface(market).baseToken();
|
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)
|
function _borrow(BorrowWithdrawParams memory params)
|
||||||
internal
|
internal
|
||||||
returns (uint256 amt, uint256 setId)
|
returns (uint256 amt, uint256 setId)
|
||||||
|
@ -82,7 +67,12 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
params.from
|
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(
|
uint256 finalBal = CometInterface(params.market).borrowBalanceOf(
|
||||||
params.from
|
params.from
|
||||||
|
@ -123,7 +113,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
token_
|
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 there are supplies, ensure withdrawn amount is not greater than supplied i.e can't borrow using withdraw.
|
||||||
if (amt_ == uint256(-1)) {
|
if (amt_ == uint256(-1)) {
|
||||||
amt_ = initialBal;
|
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.
|
//if borrow balance > 0, there are no supplies so no withdraw, borrow instead.
|
||||||
require(
|
require(
|
||||||
CometInterface(market).borrowBalanceOf(params.from) == 0,
|
CometInterface(params.market).borrowBalanceOf(params.from) == 0,
|
||||||
"withdraw-disabled-for-zero-supplies"
|
"withdraw-disabled-for-zero-supplies"
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
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(
|
uint256 finalBal = _getAccountSupplyBalanceOfAsset(
|
||||||
params.from,
|
params.from,
|
||||||
|
@ -161,16 +156,6 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
setId = params.setId;
|
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(
|
function _getAccountSupplyBalanceOfAsset(
|
||||||
address account,
|
address account,
|
||||||
address market,
|
address market,
|
||||||
|
@ -204,8 +189,8 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
} else if (action == Action.DEPOSIT) {
|
} else if (action == Action.DEPOSIT) {
|
||||||
if (isEth) bal_ = src.balance;
|
if (isEth) bal_ = src.balance;
|
||||||
else bal_ = TokenInterface(token).balanceOf(src);
|
else bal_ = TokenInterface(token).balanceOf(src);
|
||||||
}
|
}
|
||||||
|
|
||||||
amt = bal_ < allowance_ ? bal_ : allowance_;
|
amt = bal_ < allowance_ ? bal_ : allowance_;
|
||||||
}
|
}
|
||||||
if (src == address(this))
|
if (src == address(this))
|
||||||
|
|
|
@ -157,7 +157,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
market != address(0) && token != address(0) && to != address(0),
|
market != address(0) && token != address(0) && to != address(0),
|
||||||
"invalid market/token/to address"
|
"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;
|
address token_ = token == ethAddr ? wethAddr : token;
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
token_,
|
token_,
|
||||||
from,
|
from,
|
||||||
amt_,
|
amt_,
|
||||||
isEth,
|
token == ethAddr,
|
||||||
Action.DEPOSIT
|
Action.DEPOSIT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -717,7 +717,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
token_,
|
token_,
|
||||||
from,
|
from,
|
||||||
amt_,
|
amt_,
|
||||||
isEth,
|
token == ethAddr,
|
||||||
Action.REPAY
|
Action.REPAY
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
@ -809,9 +809,9 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
|
|
||||||
address token_ = token == ethAddr ? wethAddr : token;
|
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_);
|
setUint(setId, amt_);
|
||||||
|
|
||||||
|
@ -851,7 +851,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
|
|
||||||
address token_ = token == ethAddr ? wethAddr : token;
|
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_);
|
CometInterface(market).transferAssetFrom(src, dest, token_, amt_);
|
||||||
|
|
||||||
|
|
|
@ -557,26 +557,6 @@ describe("Compound III", function () {
|
||||||
expect(await wethContract.connect(wallet0).balanceOf(dsaWallet0.address)).to.be.lte(initialBal.sub(amount));
|
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 () {
|
it("should allow manager for dsaWallet0's collateral", async function () {
|
||||||
const spells = [
|
const spells = [
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue
Block a user