mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
minor changes
This commit is contained in:
parent
69eb33d64a
commit
9b3e5b6c0b
|
@ -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,
|
||||
|
|
|
@ -82,7 +82,7 @@ abstract contract Helpers is DSMath, Basic {
|
|||
);
|
||||
|
||||
require(
|
||||
TokenInterface(params.market).balanceOf(params.from) == 0,
|
||||
CometInterface(params.market).balanceOf(params.from) == 0,
|
||||
"borrow-disabled-when-supplied-base"
|
||||
);
|
||||
|
||||
|
@ -127,22 +127,16 @@ abstract contract Helpers is DSMath, Basic {
|
|||
token_
|
||||
);
|
||||
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
||||
|
||||
if (token_ == getBaseToken(params.market)) {
|
||||
uint256 balance = CometInterface(params.market).balanceOf(
|
||||
params.from
|
||||
);
|
||||
//if there are supplies, ensure withdrawn amount is not greater than supplied i.e can't borrow using withdraw.
|
||||
if (balance > 0) {
|
||||
require(amt_ <= balance, "withdraw-amt-greater-than-supplies");
|
||||
}
|
||||
require(amt_ <= initialBal, "withdraw-amt-greater-than-supplies");
|
||||
|
||||
//if borrow balance > 0, there are no supplies so no withdraw, borrow instead.
|
||||
require(
|
||||
CometInterface(params.market).borrowBalanceOf(params.from) == 0,
|
||||
"withdraw-disabled-for-zero-supplies"
|
||||
);
|
||||
}
|
||||
|
||||
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
||||
|
||||
uint256 finalBal = _getAccountSupplyBalanceOfAsset(
|
||||
|
@ -261,6 +255,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,
|
||||
|
@ -268,11 +266,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_);
|
||||
|
|
|
@ -223,24 +223,17 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
|||
token_
|
||||
);
|
||||
|
||||
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
||||
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"
|
||||
);
|
||||
}
|
||||
|
||||
require(amt_ <= initialBal, "withdraw-amt-greater-than-supplies");
|
||||
|
||||
//if borrow balance > 0, there are no supplies so no withdraw, borrow instead.
|
||||
require(
|
||||
CometInterface(market).borrowBalanceOf(address(this)) == 0,
|
||||
"withdraw-disabled-for-zero-supplies"
|
||||
);
|
||||
} else {
|
||||
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
||||
}
|
||||
|
||||
CometInterface(market).withdraw(token_, amt_);
|
||||
|
@ -596,15 +589,15 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
|||
);
|
||||
|
||||
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(address(this)) == 0,
|
||||
"cannot-repay-when-supplied"
|
||||
|
@ -617,8 +610,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -658,15 +651,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"
|
||||
|
@ -679,8 +672,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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -728,15 +721,29 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
|||
Action.REPAY
|
||||
);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -936,8 +943,8 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
|||
owner,
|
||||
manager,
|
||||
isAllowed,
|
||||
nonce,
|
||||
expiry,
|
||||
nonce,
|
||||
v,
|
||||
r,
|
||||
s
|
||||
|
|
Loading…
Reference in New Issue
Block a user