mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
refactor code
This commit is contained in:
parent
278019753d
commit
2030617e74
|
@ -133,19 +133,11 @@ contract Events {
|
||||||
address indexed market,
|
address indexed market,
|
||||||
address indexed owner,
|
address indexed owner,
|
||||||
address indexed manager,
|
address indexed manager,
|
||||||
|
bool allow,
|
||||||
uint256 expiry,
|
uint256 expiry,
|
||||||
uint256 nonce,
|
uint256 nonce,
|
||||||
uint256 v,
|
uint8 v,
|
||||||
uint256 r,
|
bytes32 r,
|
||||||
uint256 s,
|
bytes32 s,
|
||||||
bool allow
|
|
||||||
);
|
|
||||||
|
|
||||||
event LogApproveMarket(
|
|
||||||
address indexed market,
|
|
||||||
address indexed token,
|
|
||||||
uint256 indexed amount,
|
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,12 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
baseToken = CometInterface(market).baseToken();
|
baseToken = CometInterface(market).baseToken();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*@dev helper function for three withdraw or borrow cases:
|
||||||
|
*withdraw - for `withdraw` withdraws the collateral or base from DSA's position to account.
|
||||||
|
*withdrawFrom - for `withdrawFromUsingManager` withdraws from src to dest using DSA as manager
|
||||||
|
*withdrawTo - for `withdrawTo` withdraws from DSA to dest address.
|
||||||
|
*/
|
||||||
function _withdrawHelper(
|
function _withdrawHelper(
|
||||||
address market,
|
address market,
|
||||||
address token,
|
address token,
|
||||||
|
@ -81,7 +87,9 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
|
|
||||||
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
_withdrawHelper(params.market, token_, params.from, params.to, amt_);
|
||||||
|
|
||||||
uint256 finalBal = CometInterface(params.market).borrowBalanceOf(params.from);
|
uint256 finalBal = CometInterface(params.market).borrowBalanceOf(
|
||||||
|
params.from
|
||||||
|
);
|
||||||
amt_ = sub(finalBal, initialBal);
|
amt_ = sub(finalBal, initialBal);
|
||||||
|
|
||||||
convertWethToEth(isEth, tokenContract, amt_);
|
convertWethToEth(isEth, tokenContract, amt_);
|
||||||
|
|
|
@ -786,7 +786,7 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
r,
|
r,
|
||||||
s
|
s
|
||||||
);
|
);
|
||||||
eventName_ = "LogAllowWithPermit(address,address,address,uint256,uint256,uint256,uint256,uint256,bool)";
|
eventName_ = "LogAllowWithPermit(address,address,address,bool,uint256,uint256,uint8,bytes32,bytes32)";
|
||||||
eventParam_ = abi.encode(
|
eventParam_ = abi.encode(
|
||||||
market,
|
market,
|
||||||
owner,
|
owner,
|
||||||
|
@ -799,40 +799,6 @@ abstract contract CompoundV3Resolver is Events, Helpers {
|
||||||
s
|
s
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function approveMarket(
|
|
||||||
address market,
|
|
||||||
address token,
|
|
||||||
uint256 amt,
|
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
|
||||||
)
|
|
||||||
external
|
|
||||||
payable
|
|
||||||
returns (string memory eventName_, bytes memory eventParam_)
|
|
||||||
{
|
|
||||||
uint256 amt_ = getUint(getId, amt);
|
|
||||||
require(
|
|
||||||
market != address(0) && token != address(0),
|
|
||||||
"invalid market/token address"
|
|
||||||
);
|
|
||||||
require(amt > 0, "amount-cannot-be-zero");
|
|
||||||
|
|
||||||
bool isEth = token == ethAddr;
|
|
||||||
address token_ = isEth ? wethAddr : token;
|
|
||||||
TokenInterface tokenContract = TokenInterface(token_);
|
|
||||||
|
|
||||||
amt_ = amt_ == uint256(-1)
|
|
||||||
? TokenInterface(market).balanceOf(address(this))
|
|
||||||
: amt_;
|
|
||||||
|
|
||||||
approve(tokenContract, market, amt_);
|
|
||||||
|
|
||||||
setUint(setId, amt_);
|
|
||||||
|
|
||||||
eventName_ = "LogApproveMarket(address,address,uint256,uint256,uint256)";
|
|
||||||
eventParam_ = abi.encode(market, token_, amt_, getId, setId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV2CompoundV3 is CompoundV3Resolver {
|
contract ConnectV2CompoundV3 is CompoundV3Resolver {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user