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
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogPayback(address indexed market, uint256 tokenAmt, uint256 setId);
|
event LogPayback(address indexed market, uint256 tokenAmt, uint256 getId, uint256 setId);
|
||||||
|
|
||||||
event LogPaybackOnBehalf(
|
event LogPaybackOnBehalf(
|
||||||
address indexed market,
|
address indexed market,
|
||||||
address to,
|
address to,
|
||||||
uint256 tokenAmt,
|
uint256 tokenAmt,
|
||||||
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -111,6 +112,7 @@ contract Events {
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 tokenAmt,
|
uint256 tokenAmt,
|
||||||
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -127,14 +129,13 @@ contract Events {
|
||||||
event LogTransferAsset(
|
event LogTransferAsset(
|
||||||
address indexed market,
|
address indexed market,
|
||||||
address token,
|
address token,
|
||||||
address indexed from,
|
|
||||||
address indexed dest,
|
address indexed dest,
|
||||||
uint256 amount,
|
uint256 amount,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogTransferAssetFromUsingManager(
|
event LogTransferAssetOnBehalf(
|
||||||
address indexed market,
|
address indexed market,
|
||||||
address token,
|
address token,
|
||||||
address indexed from,
|
address indexed from,
|
||||||
|
|
|
@ -82,7 +82,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
);
|
);
|
||||||
|
|
||||||
require(
|
require(
|
||||||
TokenInterface(params.market).balanceOf(params.from) == 0,
|
CometInterface(params.market).balanceOf(params.from) == 0,
|
||||||
"borrow-disabled-when-supplied-base"
|
"borrow-disabled-when-supplied-base"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -127,22 +127,16 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
token_
|
token_
|
||||||
);
|
);
|
||||||
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
||||||
|
|
||||||
if (token_ == getBaseToken(params.market)) {
|
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 there are supplies, ensure withdrawn amount is not greater than supplied i.e can't borrow using withdraw.
|
||||||
if (balance > 0) {
|
require(amt_ <= initialBal, "withdraw-amt-greater-than-supplies");
|
||||||
require(amt_ <= balance, "withdraw-amt-greater-than-supplies");
|
|
||||||
}
|
|
||||||
//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(params.market).borrowBalanceOf(params.from) == 0,
|
CometInterface(params.market).borrowBalanceOf(params.from) == 0,
|
||||||
"withdraw-disabled-for-zero-supplies"
|
"withdraw-disabled-for-zero-supplies"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
||||||
|
|
||||||
uint256 finalBal = _getAccountSupplyBalanceOfAsset(
|
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_);
|
approve(TokenInterface(params.sellToken), params.market, sellAmt_);
|
||||||
CometInterface(params.market).buyCollateral(
|
CometInterface(params.market).buyCollateral(
|
||||||
params.buyAsset,
|
params.buyAsset,
|
||||||
|
@ -268,11 +266,11 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
sellAmt_,
|
sellAmt_,
|
||||||
address(this)
|
address(this)
|
||||||
);
|
);
|
||||||
|
uint256 finalCollBal_ = CometInterface(params.market)
|
||||||
|
.userCollateral(address(this), params.buyAsset)
|
||||||
|
.balance;
|
||||||
|
|
||||||
uint256 buyAmt_ = CometInterface(params.market).quoteCollateral(
|
uint256 buyAmt_ = sub(finalCollBal_, initialCollBal_);
|
||||||
params.buyAsset,
|
|
||||||
sellAmt_
|
|
||||||
);
|
|
||||||
require(slippageAmt_ <= buyAmt_, "too-much-slippage");
|
require(slippageAmt_ <= buyAmt_, "too-much-slippage");
|
||||||
|
|
||||||
convertWethToEth(isEth, TokenInterface(params.buyAsset), buyAmt_);
|
convertWethToEth(isEth, TokenInterface(params.buyAsset), buyAmt_);
|
||||||
|
|
|
@ -223,24 +223,17 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
token_
|
token_
|
||||||
);
|
);
|
||||||
|
|
||||||
|
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
||||||
if (token_ == getBaseToken(market)) {
|
if (token_ == getBaseToken(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)) {
|
|
||||||
amt_ = initialBal;
|
require(amt_ <= initialBal, "withdraw-amt-greater-than-supplies");
|
||||||
} else {
|
|
||||||
require(
|
|
||||||
amt_ <= initialBal,
|
|
||||||
"withdraw-amt-greater-than-supplies"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
//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(address(this)) == 0,
|
CometInterface(market).borrowBalanceOf(address(this)) == 0,
|
||||||
"withdraw-disabled-for-zero-supplies"
|
"withdraw-disabled-for-zero-supplies"
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
amt_ = amt_ == uint256(-1) ? initialBal : amt_;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CometInterface(market).withdraw(token_, amt_);
|
CometInterface(market).withdraw(token_, amt_);
|
||||||
|
@ -596,15 +589,15 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (amt_ == uint256(-1)) {
|
if (amt_ == uint256(-1)) {
|
||||||
amt_ = initialBal;
|
amt_ = borrowedBalance_;
|
||||||
} else {
|
} else {
|
||||||
require(
|
require(
|
||||||
amt_ <= borrowedBalance_,
|
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(
|
require(
|
||||||
CometInterface(market).balanceOf(address(this)) == 0,
|
CometInterface(market).balanceOf(address(this)) == 0,
|
||||||
"cannot-repay-when-supplied"
|
"cannot-repay-when-supplied"
|
||||||
|
@ -617,8 +610,8 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
|
|
||||||
setUint(setId, amt_);
|
setUint(setId, amt_);
|
||||||
|
|
||||||
eventName_ = "LogPayback(address,address,uint256,uint256,uint256)";
|
eventName_ = "LogPayback(address,uint256,uint256,uint256)";
|
||||||
eventParam_ = abi.encode(market, token_, amt_, getId, setId);
|
eventParam_ = abi.encode(market, amt_, getId, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -658,15 +651,15 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
uint256 borrowedBalance_ = CometInterface(market).borrowBalanceOf(to);
|
uint256 borrowedBalance_ = CometInterface(market).borrowBalanceOf(to);
|
||||||
|
|
||||||
if (amt_ == uint256(-1)) {
|
if (amt_ == uint256(-1)) {
|
||||||
amt_ = initialBal;
|
amt_ = borrowedBalance_;
|
||||||
} else {
|
} else {
|
||||||
require(
|
require(
|
||||||
amt_ <= borrowedBalance_,
|
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(
|
require(
|
||||||
CometInterface(market).balanceOf(to) == 0,
|
CometInterface(market).balanceOf(to) == 0,
|
||||||
"cannot-repay-when-supplied"
|
"cannot-repay-when-supplied"
|
||||||
|
@ -679,8 +672,8 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
|
|
||||||
setUint(setId, amt_);
|
setUint(setId, amt_);
|
||||||
|
|
||||||
eventName_ = "LogPaybackOnBehalf(address,address,address,uint256,uint256,uint256)";
|
eventName_ = "LogPaybackOnBehalf(address,address,uint256,uint256,uint256)";
|
||||||
eventParam_ = abi.encode(market, token_, to, amt_, getId, setId);
|
eventParam_ = abi.encode(market, to, amt_, getId, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -728,15 +721,29 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
Action.REPAY
|
Action.REPAY
|
||||||
);
|
);
|
||||||
|
|
||||||
uint256 supplyBalance_ = CometInterface(market).balanceOf(to);
|
uint256 borrowedBalance_ = CometInterface(market).borrowBalanceOf(to);
|
||||||
require(supplyBalance_ == 0, "cannot-repay-when-supplied");
|
|
||||||
|
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_);
|
CometInterface(market).supplyFrom(from, to, token_, amt_);
|
||||||
|
|
||||||
setUint(setId, amt_);
|
setUint(setId, amt_);
|
||||||
|
|
||||||
eventName_ = "LogPaybackFromUsingManager(address,address,address,address,uint256,uint256,uint256)";
|
eventName_ = "LogPaybackFromUsingManager(address,address,address,uint256,uint256,uint256)";
|
||||||
eventParam_ = abi.encode(market, token_, from, to, amt_, getId, setId);
|
eventParam_ = abi.encode(market, from, to, amt_, getId, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -936,8 +943,8 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
owner,
|
owner,
|
||||||
manager,
|
manager,
|
||||||
isAllowed,
|
isAllowed,
|
||||||
nonce,
|
|
||||||
expiry,
|
expiry,
|
||||||
|
nonce,
|
||||||
v,
|
v,
|
||||||
r,
|
r,
|
||||||
s
|
s
|
||||||
|
|
Loading…
Reference in New Issue
Block a user