Merge pull request #258 from Instadapp/compound-v3-1

Compound V3 | 2
This commit is contained in:
Thrilok kumar 2022-09-03 01:42:06 +05:30 committed by GitHub
commit 27454a75d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 27 deletions

View File

@ -97,12 +97,13 @@ contract Events {
uint256 setId
);
event LogPayback(address indexed market, uint256 tokenAmt, uint256 setId);
event LogPayback(address indexed market, uint256 tokenAmt, uint256 getId, uint256 setId);
event LogPaybackOnBehalf(
address indexed market,
address to,
uint256 tokenAmt,
uint256 getId,
uint256 setId
);
@ -111,6 +112,7 @@ contract Events {
address from,
address to,
uint256 tokenAmt,
uint256 getId,
uint256 setId
);
@ -127,14 +129,13 @@ contract Events {
event LogTransferAsset(
address indexed market,
address token,
address indexed from,
address indexed dest,
uint256 amount,
uint256 getId,
uint256 setId
);
event LogTransferAssetFromUsingManager(
event LogTransferAssetOnBehalf(
address indexed market,
address token,
address indexed from,

View File

@ -74,7 +74,7 @@ abstract contract Helpers is DSMath, Basic {
params.from = params.from == address(0) ? address(this) : params.from;
require(
TokenInterface(params.market).balanceOf(params.from) == 0,
CometInterface(params.market).balanceOf(params.from) == 0,
"borrow-disabled-when-supplied-base"
);
@ -253,6 +253,10 @@ abstract contract Helpers is DSMath, Basic {
)
);
uint256 initialCollBal_ = CometInterface(params.market)
.userCollateral(address(this), params.buyAsset)
.balance;
approve(TokenInterface(params.sellToken), params.market, sellAmt_);
CometInterface(params.market).buyCollateral(
params.buyAsset,
@ -260,11 +264,11 @@ abstract contract Helpers is DSMath, Basic {
sellAmt_,
address(this)
);
uint256 finalCollBal_ = CometInterface(params.market)
.userCollateral(address(this), params.buyAsset)
.balance;
uint256 buyAmt_ = CometInterface(params.market).quoteCollateral(
params.buyAsset,
sellAmt_
);
uint256 buyAmt_ = sub(finalCollBal_, initialCollBal_);
require(slippageAmt_ <= buyAmt_, "too-much-slippage");
convertWethToEth(isEth, TokenInterface(params.buyAsset), buyAmt_);

View File

@ -224,14 +224,11 @@ abstract contract CompoundV3Resolver is Events, Helpers {
);
if (token_ == getBaseToken(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;
} else {
require(
amt_ <= initialBal,
"withdraw-amt-greater-than-supplies"
);
//if there are supplies, ensure withdrawn amount is not greater than supplied i.e can't borrow using withdraw.
require(amt_ <= initialBal, "withdraw-amt-greater-than-supplies");
}
//if borrow balance > 0, there are no supplies so no withdraw, borrow instead.
@ -598,11 +595,11 @@ abstract contract CompoundV3Resolver is Events, Helpers {
} else {
require(
amt_ <= borrowedBalance_,
"withdraw-amt-greater-than-supplies"
"payback-amt-greater-than-borrows"
);
}
//if supply balance > 0, there are no borrowing so no repay, withdraw instead.
//if supply balance > 0, there are no borrowing so no repay, supply instead.
require(
CometInterface(market).balanceOf(address(this)) == 0,
"cannot-repay-when-supplied"
@ -615,8 +612,8 @@ abstract contract CompoundV3Resolver is Events, Helpers {
setUint(setId, amt_);
eventName_ = "LogPayback(address,address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, token_, amt_, getId, setId);
eventName_ = "LogPayback(address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, amt_, getId, setId);
}
/**
@ -656,15 +653,15 @@ abstract contract CompoundV3Resolver is Events, Helpers {
uint256 borrowedBalance_ = CometInterface(market).borrowBalanceOf(to);
if (amt_ == uint256(-1)) {
amt_ = initialBal;
amt_ = borrowedBalance_;
} else {
require(
amt_ <= borrowedBalance_,
"withdraw-amt-greater-than-supplies"
"payback-amt-greater-than-borrows"
);
}
//if supply balance > 0, there are no borrowing so no repay, withdraw instead.
//if supply balance > 0, there are no borrowing so no repay, supply instead.
require(
CometInterface(market).balanceOf(to) == 0,
"cannot-repay-when-supplied"
@ -677,8 +674,8 @@ abstract contract CompoundV3Resolver is Events, Helpers {
setUint(setId, amt_);
eventName_ = "LogPaybackOnBehalf(address,address,address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, token_, to, amt_, getId, setId);
eventName_ = "LogPaybackOnBehalf(address,address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, to, amt_, getId, setId);
}
/**
@ -733,15 +730,29 @@ abstract contract CompoundV3Resolver is Events, Helpers {
);
}
uint256 supplyBalance_ = CometInterface(market).balanceOf(to);
require(supplyBalance_ == 0, "cannot-repay-when-supplied");
uint256 borrowedBalance_ = CometInterface(market).borrowBalanceOf(to);
if (amt_ == uint256(-1)) {
amt_ = borrowedBalance_;
} else {
require(
amt_ <= borrowedBalance_,
"payback-amt-greater-than-borrows"
);
}
//if supply balance > 0, there are no borrowing so no repay, withdraw instead.
require(
CometInterface(market).balanceOf(to) == 0,
"cannot-repay-when-supplied"
);
CometInterface(market).supplyFrom(from, to, token_, amt_);
setUint(setId, amt_);
eventName_ = "LogPaybackFromUsingManager(address,address,address,address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, token_, from, to, amt_, getId, setId);
eventName_ = "LogPaybackFromUsingManager(address,address,address,uint256,uint256,uint256)";
eventParam_ = abi.encode(market, from, to, amt_, getId, setId);
}
/**
@ -920,8 +931,8 @@ abstract contract CompoundV3Resolver is Events, Helpers {
owner,
manager,
isAllowed,
nonce,
expiry,
nonce,
v,
r,
s