mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
rewards, claim functions
This commit is contained in:
parent
a9ed4a2fcb
commit
40d3b6e67a
|
@ -80,18 +80,12 @@ contract Events {
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogPayback(
|
event LogPayback(address indexed market, uint256 tokenAmt, uint256 setId);
|
||||||
address indexed market,
|
|
||||||
uint256 tokenAmt,
|
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
|
||||||
);
|
|
||||||
|
|
||||||
event LogPaybackOnBehalfOf(
|
event LogPaybackOnBehalfOf(
|
||||||
address indexed market,
|
address indexed market,
|
||||||
address to,
|
address to,
|
||||||
uint256 tokenAmt,
|
uint256 tokenAmt,
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -100,17 +94,24 @@ contract Events {
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 tokenAmt,
|
uint256 tokenAmt,
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogRewardsClaimed(
|
event LogRewardsClaimed(
|
||||||
address indexed token,
|
address indexed market,
|
||||||
address cToken,
|
address indexed account,
|
||||||
uint256 tokenAmt,
|
uint256 indexed totalClaimedInWei,
|
||||||
uint256 cTokenAmt,
|
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
bool accrued
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogRewardsClaimedTo(
|
||||||
|
address indexed market,
|
||||||
|
address indexed account,
|
||||||
|
address to,
|
||||||
|
uint256 indexed totalClaimedInWei,
|
||||||
|
uint256 getId,
|
||||||
|
bool accrued
|
||||||
);
|
);
|
||||||
|
|
||||||
event LogLiquidate(
|
event LogLiquidate(
|
||||||
|
@ -121,4 +122,23 @@ contract Events {
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
);
|
);
|
||||||
|
|
||||||
|
event LogBuyCollateral(
|
||||||
|
address indexed market,
|
||||||
|
address indexed asset,
|
||||||
|
uint256 indexed baseAmount,
|
||||||
|
uint256 minCollateralAmt,
|
||||||
|
uint256 collateralAmount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogApproveManager(
|
||||||
|
address indexed market,
|
||||||
|
address indexed account,
|
||||||
|
address indexed asset,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
//SPDX-License-Identifier: MIT
|
//SPDX-License-Identifier: MIT
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
pragma abicoder v2;
|
||||||
|
|
||||||
import { DSMath } from "../../common/math.sol";
|
import { DSMath } from "../../common/math.sol";
|
||||||
import { Basic } from "../../common/basic.sol";
|
import { Basic } from "../../common/basic.sol";
|
||||||
import { CometInterface } from "./interface.sol";
|
import { CometInterface, CometRewards } from "./interface.sol";
|
||||||
|
|
||||||
abstract contract Helpers is DSMath, Basic {
|
abstract contract Helpers is DSMath, Basic {
|
||||||
|
|
||||||
|
CometRewards internal constant cometRewards = CometRewards(0x1B0e765F6224C21223AeA2af16c1C46E38885a40);
|
||||||
|
|
||||||
function getBaseToken(address market)
|
function getBaseToken(address market)
|
||||||
internal
|
internal
|
||||||
view
|
view
|
||||||
|
@ -20,7 +24,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 amt
|
uint256 amt
|
||||||
) internal payable returns (bool success) {
|
) public payable returns (bool success) {
|
||||||
bytes memory data;
|
bytes memory data;
|
||||||
|
|
||||||
if (from == address(0) && to == address(0)) {
|
if (from == address(0) && to == address(0)) {
|
||||||
|
@ -46,7 +50,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
(success, ) = market.delegateCall(data);
|
(success, ) = market.delegatecall(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _withdraw(
|
function _withdraw(
|
||||||
|
@ -55,7 +59,7 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 amt
|
uint256 amt
|
||||||
) internal payable returns (bool success) {
|
) internal returns (bool success) {
|
||||||
bytes memory data;
|
bytes memory data;
|
||||||
|
|
||||||
if (from == address(0) && to == address(0)) {
|
if (from == address(0) && to == address(0)) {
|
||||||
|
@ -80,14 +84,14 @@ abstract contract Helpers is DSMath, Basic {
|
||||||
amt
|
amt
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
(success, ) = market.delegateCall(data);
|
(success, ) = market.delegatecall(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAccountSupplyBalanceOfAsset(
|
function getAccountSupplyBalanceOfAsset(
|
||||||
address account,
|
address account,
|
||||||
address market,
|
address market,
|
||||||
address asset
|
address asset
|
||||||
) internal view returns (uint256 balance) {
|
) internal returns (uint256 balance) {
|
||||||
if (asset == getBaseToken(market)) {
|
if (asset == getBaseToken(market)) {
|
||||||
//balance in base
|
//balance in base
|
||||||
balance = CometInterface(market).balanceOf(account);
|
balance = CometInterface(market).balanceOf(account);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
//SPDX-License-Identifier: MIT
|
//SPDX-License-Identifier: MIT
|
||||||
pragma solidity ^0.7.0;
|
pragma solidity ^0.7.0;
|
||||||
|
pragma abicoder v2;
|
||||||
|
|
||||||
struct UserCollateral {
|
struct UserCollateral {
|
||||||
uint128 balance;
|
uint128 balance;
|
||||||
|
@ -81,9 +82,8 @@ interface CometInterface {
|
||||||
) external virtual;
|
) external virtual;
|
||||||
|
|
||||||
function quoteCollateral(address asset, uint256 baseAmount)
|
function quoteCollateral(address asset, uint256 baseAmount)
|
||||||
public
|
external
|
||||||
view
|
view
|
||||||
virtual
|
|
||||||
returns (uint256);
|
returns (uint256);
|
||||||
|
|
||||||
function userCollateral(address, address)
|
function userCollateral(address, address)
|
||||||
|
@ -93,4 +93,26 @@ interface CometInterface {
|
||||||
function baseToken() external view returns (address);
|
function baseToken() external view returns (address);
|
||||||
|
|
||||||
function balanceOf(address account) external view returns (uint256);
|
function balanceOf(address account) external view returns (uint256);
|
||||||
|
|
||||||
|
function borrowBalanceOf(address account) external view returns (uint256);
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CometRewards {
|
||||||
|
function claim(
|
||||||
|
address comet,
|
||||||
|
address src,
|
||||||
|
bool shouldAccrue
|
||||||
|
) external;
|
||||||
|
|
||||||
|
function claimTo(
|
||||||
|
address comet,
|
||||||
|
address src,
|
||||||
|
address to,
|
||||||
|
bool shouldAccrue
|
||||||
|
) external;
|
||||||
|
|
||||||
|
function rewardsClaimed(address cometProxy, address account)
|
||||||
|
external
|
||||||
|
view
|
||||||
|
returns (uint256);
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
|
|
||||||
approve(tokenContract, market, _amt);
|
approve(tokenContract, market, _amt);
|
||||||
|
|
||||||
bool success = _supply(market, _token, 0x00, 0x00, _amt);
|
bool success = _supply(market, _token, address(0), address(0), _amt);
|
||||||
require(success, "supply-failed");
|
require(success, "supply-failed");
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
@ -65,7 +65,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
* @notice Deposit a token to Compound for lending / collaterization on behalf of 'to'.
|
* @notice Deposit a token to Compound for lending / collaterization on behalf of 'to'.
|
||||||
* @param market The address of the market where to supply.
|
* @param market The address of the market where to supply.
|
||||||
* @param token The address of the token to be supplied. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE).
|
* @param token The address of the token to be supplied. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE).
|
||||||
* @param to The address on behalf of which the supply is made.
|
* @param to The address on behalf of which the supply is made.
|
||||||
* @param amt The amount of the token to deposit. (For max: `uint256(-1)`)
|
* @param amt The amount of the token to deposit. (For max: `uint256(-1)`)
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens deposited.
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
@ -99,7 +99,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
|
|
||||||
approve(tokenContract, market, _amt);
|
approve(tokenContract, market, _amt);
|
||||||
|
|
||||||
bool success = _supply(market, _token, 0x00, to, _amt);
|
bool success = _supply(market, _token, address(0), to, _amt);
|
||||||
require(success, "supply-failed");
|
require(success, "supply-failed");
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
@ -113,8 +113,8 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
* @notice Deposit a token to Compound for lending / collaterization from a address and update the position of 'to'.
|
* @notice Deposit a token to Compound for lending / collaterization from a address and update the position of 'to'.
|
||||||
* @param market The address of the market from where to supply.
|
* @param market The address of the market from where to supply.
|
||||||
* @param token The address of the token to be supplied. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param token The address of the token to be supplied. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param from The address from where amount is to be supplied.
|
* @param from The address from where amount is to be supplied.
|
||||||
* @param to The address on account of which the supply is made or whose positions are updated.
|
* @param to The address on account of which the supply is made or whose positions are updated.
|
||||||
* @param amt The amount of the token to deposit. (For max: `uint256(-1)`)
|
* @param amt The amount of the token to deposit. (For max: `uint256(-1)`)
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens deposited.
|
* @param setId ID stores the amount of tokens deposited.
|
||||||
|
@ -123,7 +123,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
address market,
|
address market,
|
||||||
address token,
|
address token,
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -195,7 +195,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
market,
|
market,
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
bool success = _withdraw(market, token, 0x00, 0x00, _amt);
|
bool success = _withdraw(market, token, address(0), address(0), _amt);
|
||||||
require(success, "withdraw-failed");
|
require(success, "withdraw-failed");
|
||||||
|
|
||||||
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
||||||
|
@ -219,7 +219,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
* @notice Withdraw base token or deposited token from Compound on behalf of an address and transfer to 'to'.
|
* @notice Withdraw base token or deposited token from Compound on behalf of an address and transfer to 'to'.
|
||||||
* @param market The address of the market from where to withdraw.
|
* @param market The address of the market from where to withdraw.
|
||||||
* @param token The address of the token to be withdrawn. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param token The address of the token to be withdrawn. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param to The address to which the borrowed assets are to be transferred.
|
* @param to The address to which the borrowed assets are to be transferred.
|
||||||
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens withdrawn.
|
* @param setId ID stores the amount of tokens withdrawn.
|
||||||
|
@ -227,7 +227,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
function withdrawOnbehalf(
|
function withdrawOnbehalf(
|
||||||
address market,
|
address market,
|
||||||
address token,
|
address token,
|
||||||
address to,
|
address to,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -253,7 +253,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
market,
|
market,
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
bool success = _withdraw(market, token, 0x00, to, _amt);
|
bool success = _withdraw(market, token, address(0), to, _amt);
|
||||||
require(success, "withdraw-failed");
|
require(success, "withdraw-failed");
|
||||||
|
|
||||||
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
||||||
|
@ -277,8 +277,8 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
* @notice Withdraw base token or deposited token from Compound from an address and transfer to 'to'.
|
* @notice Withdraw base token or deposited token from Compound from an address and transfer to 'to'.
|
||||||
* @param market The address of the market from where to withdraw.
|
* @param market The address of the market from where to withdraw.
|
||||||
* @param token The address of the token to be withdrawn. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
* @param token The address of the token to be withdrawn. (For ETH: 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE)
|
||||||
* @param from The address from where asset is to be withdrawed.
|
* @param from The address from where asset is to be withdrawed.
|
||||||
* @param to The address to which the borrowed assets are to be transferred.
|
* @param to The address to which the borrowed assets are to be transferred.
|
||||||
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens withdrawn.
|
* @param setId ID stores the amount of tokens withdrawn.
|
||||||
|
@ -286,8 +286,8 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
function withdrawFrom(
|
function withdrawFrom(
|
||||||
address market,
|
address market,
|
||||||
address token,
|
address token,
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -354,7 +354,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
|
|
||||||
require(market != address(0), "invalid market address");
|
require(market != address(0), "invalid market address");
|
||||||
|
|
||||||
bool token = getBaseToken(market);
|
address token = getBaseToken(market);
|
||||||
bool isEth = token == ethAddr;
|
bool isEth = token == ethAddr;
|
||||||
address _token = isEth ? wethAddr : token;
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
@ -365,7 +365,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
market,
|
market,
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
bool success = _withdraw(market, token, 0x00, 0x00, _amt);;
|
bool success = _withdraw(market, token, address(0), address(0), _amt);
|
||||||
require(success, "borrow-failed");
|
require(success, "borrow-failed");
|
||||||
|
|
||||||
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
||||||
|
@ -388,14 +388,14 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
* @dev Borrow base asset and transfer to 'to' account.
|
* @dev Borrow base asset and transfer to 'to' account.
|
||||||
* @notice Withdraw base token from Compound on behalf of an address.
|
* @notice Withdraw base token from Compound on behalf of an address.
|
||||||
* @param market The address of the market from where to withdraw.
|
* @param market The address of the market from where to withdraw.
|
||||||
* @param to The address to which the borrowed asset is transferred.
|
* @param to The address to which the borrowed asset is transferred.
|
||||||
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens withdrawn.
|
* @param setId ID stores the amount of tokens withdrawn.
|
||||||
*/
|
*/
|
||||||
function borrowOnBehalf(
|
function borrowOnBehalf(
|
||||||
address market,
|
address market,
|
||||||
address to,
|
address to,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -408,7 +408,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
|
|
||||||
require(market != address(0), "invalid market address");
|
require(market != address(0), "invalid market address");
|
||||||
|
|
||||||
bool token = getBaseToken(market);
|
address token = getBaseToken(market);
|
||||||
bool isEth = token == ethAddr;
|
bool isEth = token == ethAddr;
|
||||||
address _token = isEth ? wethAddr : token;
|
address _token = isEth ? wethAddr : token;
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
market,
|
market,
|
||||||
token
|
token
|
||||||
);
|
);
|
||||||
bool success = _withdraw(market, token, 0x00, to, _amt);
|
bool success = _withdraw(market, token, address(0), to, _amt);
|
||||||
require(success, "borrow-failed");
|
require(success, "borrow-failed");
|
||||||
|
|
||||||
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
||||||
|
@ -443,15 +443,15 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
* @notice Withdraw base token or deposited token from Compound.
|
* @notice Withdraw base token or deposited token from Compound.
|
||||||
* @param market The address of the market from where to withdraw.
|
* @param market The address of the market from where to withdraw.
|
||||||
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
||||||
* @param from The address from where asset is to be withdrawed.
|
* @param from The address from where asset is to be withdrawed.
|
||||||
* @param to The address to which the borrowed assets are to be transferred.
|
* @param to The address to which the borrowed assets are to be transferred.
|
||||||
* @param getId ID to retrieve amt.
|
* @param getId ID to retrieve amt.
|
||||||
* @param setId ID stores the amount of tokens withdrawn.
|
* @param setId ID stores the amount of tokens withdrawn.
|
||||||
*/
|
*/
|
||||||
function borrowFrom(
|
function borrowFrom(
|
||||||
address market,
|
address market,
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 amt,
|
uint256 amt,
|
||||||
uint256 getId,
|
uint256 getId,
|
||||||
uint256 setId
|
uint256 setId
|
||||||
|
@ -463,25 +463,23 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
uint256 _amt = getUint(getId, amt);
|
uint256 _amt = getUint(getId, amt);
|
||||||
|
|
||||||
require(market != address(0), "invalid market address");
|
require(market != address(0), "invalid market address");
|
||||||
|
bool isEth = (getBaseToken(market) == ethAddr);
|
||||||
bool token = getBaseToken(market);
|
address _token = isEth ? wethAddr : getBaseToken(market);
|
||||||
bool isEth = token == ethAddr;
|
|
||||||
address _token = isEth ? wethAddr : token;
|
|
||||||
|
|
||||||
TokenInterface tokenContract = TokenInterface(_token);
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
|
|
||||||
uint256 initialBal = getAccountSupplyBalanceOfAsset(
|
uint256 initialBal = getAccountSupplyBalanceOfAsset(
|
||||||
address(this),
|
address(this),
|
||||||
market,
|
market,
|
||||||
token
|
getBaseToken(market)
|
||||||
);
|
);
|
||||||
bool success = _withdraw(market, token, from, to, _amt);
|
bool success = _withdraw(market, _token, from, to, _amt);
|
||||||
require(success, "borrow-failed");
|
require(success, "borrow-failed");
|
||||||
|
|
||||||
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
uint256 finalBal = getAccountSupplyBalanceOfAsset(
|
||||||
address(this),
|
address(this),
|
||||||
market,
|
market,
|
||||||
token
|
getBaseToken(market)
|
||||||
);
|
);
|
||||||
|
|
||||||
_amt = sub(finalBal, initialBal);
|
_amt = sub(finalBal, initialBal);
|
||||||
|
@ -494,19 +492,13 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
_eventParam = abi.encode(market, from, to, _amt, getId, setId);
|
_eventParam = abi.encode(market, from, to, _amt, getId, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Repays entire borrow of the base asset.
|
* @dev Repays entire borrow of the base asset.
|
||||||
* @notice Repays an entire borrow of the base asset.
|
* @notice Repays an entire borrow of the base asset.
|
||||||
* @param market The address of the market from where to withdraw.
|
* @param market The address of the market from where to withdraw.
|
||||||
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
|
||||||
* @param getId ID to retrieve amt.
|
|
||||||
* @param setId ID stores the amount of tokens withdrawn.
|
* @param setId ID stores the amount of tokens withdrawn.
|
||||||
*/
|
*/
|
||||||
function payBack(
|
function payBack(address market, uint256 setId)
|
||||||
address market,
|
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
|
||||||
)
|
|
||||||
external
|
external
|
||||||
payable
|
payable
|
||||||
returns (string memory _eventName, bytes memory _eventParam)
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
@ -518,34 +510,28 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
address _token = isEth ? wethAddr : token;
|
address _token = isEth ? wethAddr : token;
|
||||||
TokenInterface tokenContract = TokenInterface(_token);
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
|
|
||||||
if (isEth) {
|
approve(tokenContract, market, uint256(-1));
|
||||||
convertEthToWeth(isEth, tokenContract, _amt);
|
uint256 _amt = CometInterface(market).borrowBalanceOf(address(this));
|
||||||
}
|
|
||||||
|
|
||||||
approve(tokenContract, market, _amt);
|
bool success = _supply(market, _token, address(0), address(0), uint256(-1));
|
||||||
|
require(success, "payback-failed");
|
||||||
bool success = _supply(market, _token, 0x00, 0x00, _amt);
|
|
||||||
require(success, "supply-failed");
|
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogPayback(address,address,uint256,uint256,uint256)";
|
_eventName = "LogPayback(address,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(market, token, _amt, getId, setId);
|
_eventParam = abi.encode(market, token, _amt, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Repays entire borrow of the base asset on behalf of 'to'.
|
* @dev Repays entire borrow of the base asset on behalf of 'to'.
|
||||||
* @notice Repays an entire borrow of the base asset on behalf of 'to'.
|
* @notice Repays an entire borrow of the base asset on behalf of 'to'.
|
||||||
* @param market The address of the market from where to withdraw.
|
* @param market The address of the market from where to withdraw.
|
||||||
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
* @param to The address on behalf of which the borrow is to be repaid.
|
||||||
* @param to The address on behalf of which the borrow is to be repaid.
|
|
||||||
* @param getId ID to retrieve amt.
|
|
||||||
* @param setId ID stores the amount of tokens withdrawn.
|
* @param setId ID stores the amount of tokens withdrawn.
|
||||||
*/
|
*/
|
||||||
function payBackOnBehalf(
|
function payBackOnBehalf(
|
||||||
address market,
|
address market,
|
||||||
address to,
|
address to,
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
uint256 setId
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
|
@ -559,36 +545,30 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
address _token = isEth ? wethAddr : token;
|
address _token = isEth ? wethAddr : token;
|
||||||
TokenInterface tokenContract = TokenInterface(_token);
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
|
|
||||||
if (isEth) {
|
approve(tokenContract, market, uint256(-1));
|
||||||
convertEthToWeth(isEth, tokenContract, _amt);
|
uint256 _amt = CometInterface(market).borrowBalanceOf(to);
|
||||||
}
|
|
||||||
|
|
||||||
approve(tokenContract, market, _amt);
|
bool success = _supply(market, _token, address(0), to, uint256(-1));
|
||||||
|
require(success, "paybackOnBehalf-failed");
|
||||||
bool success = _supply(market, _token, 0x00, to, _amt);
|
|
||||||
require(success, "supply-failed");
|
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogPaybackOnBehalf(address,address,address,uint256,uint256,uint256)";
|
_eventName = "LogPaybackOnBehalf(address,address,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(market, token, to, _amt, getId, setId);
|
_eventParam = abi.encode(market, token, to, _amt, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Repays entire borrow of the base asset form 'from' on behalf of 'to'.
|
* @dev Repays entire borrow of the base asset form 'from' on behalf of 'to'.
|
||||||
* @notice Repays an entire borrow of the base asset on behalf of 'to'.
|
* @notice Repays an entire borrow of the base asset on behalf of 'to'.
|
||||||
* @param market The address of the market from where to withdraw.
|
* @param market The address of the market from where to withdraw.
|
||||||
* @param amt The amount of the token to withdraw. (For max: `uint256(-1)`)
|
* @param from The address from which the borrow has to be repaid on behalf of 'to'.
|
||||||
* @param from The address from which the borrow has to be repaid on behalf of 'to'.
|
* @param to The address on behalf of which the borrow is to be repaid.
|
||||||
* @param to The address on behalf of which the borrow is to be repaid.
|
|
||||||
* @param getId ID to retrieve amt.
|
|
||||||
* @param setId ID stores the amount of tokens withdrawn.
|
* @param setId ID stores the amount of tokens withdrawn.
|
||||||
*/
|
*/
|
||||||
function payFrom(
|
function payFrom(
|
||||||
address market,
|
address market,
|
||||||
address from,
|
address from,
|
||||||
address to,
|
address to,
|
||||||
uint256 getId,
|
|
||||||
uint256 setId
|
uint256 setId
|
||||||
)
|
)
|
||||||
external
|
external
|
||||||
|
@ -602,23 +582,134 @@ abstract contract CompoundIIIResolver is Events, Helpers {
|
||||||
address _token = isEth ? wethAddr : token;
|
address _token = isEth ? wethAddr : token;
|
||||||
TokenInterface tokenContract = TokenInterface(_token);
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
|
|
||||||
|
approve(tokenContract, market, uint256(-1));
|
||||||
|
uint256 _amt = CometInterface(market).borrowBalanceOf(to);
|
||||||
|
|
||||||
|
bool success = _supply(market, _token, from, to, uint256(-1));
|
||||||
|
require(success, "paybackFrom-failed");
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogPaybackFrom(address,address,address,address,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(market, token, from, to, _amt, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
function buyCollateral(
|
||||||
|
address market,
|
||||||
|
address asset,
|
||||||
|
address dest,
|
||||||
|
uint256 minCollateralAmt,
|
||||||
|
uint256 baseAmt,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
)
|
||||||
|
external
|
||||||
|
payable
|
||||||
|
returns (string memory _eventName, bytes memory _eventParam)
|
||||||
|
{
|
||||||
|
uint256 _amt = getUint(getId, baseAmt);
|
||||||
|
|
||||||
|
bool isEth = asset == ethAddr;
|
||||||
|
address _token = isEth ? wethAddr : asset;
|
||||||
|
TokenInterface tokenContract = TokenInterface(_token);
|
||||||
|
|
||||||
if (isEth) {
|
if (isEth) {
|
||||||
convertEthToWeth(isEth, tokenContract, _amt);
|
convertEthToWeth(isEth, tokenContract, _amt);
|
||||||
}
|
}
|
||||||
|
|
||||||
approve(tokenContract, market, _amt);
|
CometInterface(market).buyCollateral(
|
||||||
|
asset,
|
||||||
|
minCollateralAmt,
|
||||||
|
_amt,
|
||||||
|
dest
|
||||||
|
);
|
||||||
|
|
||||||
bool success = _supply(market, _token, from, to, _amt);
|
uint256 collAmt = CometInterface(market).quoteCollateral(asset, _amt);
|
||||||
require(success, "supply-failed");
|
setUint(setId, _amt);
|
||||||
|
|
||||||
|
_eventName = "LogBuyCollateral(address,address,uint256,uint256,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
market,
|
||||||
|
asset,
|
||||||
|
baseAmt,
|
||||||
|
minCollateralAmt,
|
||||||
|
collAmt,
|
||||||
|
getId,
|
||||||
|
setId
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function approveManager(
|
||||||
|
address market,
|
||||||
|
address manager,
|
||||||
|
address asset,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 getId,
|
||||||
|
uint256 setId
|
||||||
|
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
uint256 _amt = getUint(getId, amount);
|
||||||
|
|
||||||
|
CometInterface(market).approveThis(manager, asset, amount);
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
||||||
_eventName = "LogPaybackFrom(address,address,address,address,uint256,uint256,uint256)";
|
_eventName = "LogApproveManager(address,address,address,uint256,uint256,uint256)";
|
||||||
_eventParam = abi.encode(market, token, from, to, _amt, getId, setId);
|
_eventParam = abi.encode(market, manager, asset, _amt, getId, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function claimRewards(
|
||||||
|
address market,
|
||||||
|
address account,
|
||||||
|
bool accrue,
|
||||||
|
uint256 setId
|
||||||
|
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
cometRewards.claim(market, account, accrue);
|
||||||
|
|
||||||
|
//in reward token decimals
|
||||||
|
uint256 totalRewardsClaimed = cometRewards.rewardsClaimed(
|
||||||
|
market,
|
||||||
|
account
|
||||||
|
);
|
||||||
|
setUint(setId, totalRewardsClaimed);
|
||||||
|
|
||||||
|
_eventName = "LogRewardsClaimed(address,address,uint256,uint256,bool)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
market,
|
||||||
|
account,
|
||||||
|
totalRewardsClaimed,
|
||||||
|
setId,
|
||||||
|
accrue
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function claimRewardsTo(
|
||||||
|
address market,
|
||||||
|
address account,
|
||||||
|
address dest,
|
||||||
|
bool accrue,
|
||||||
|
uint256 setId
|
||||||
|
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
cometRewards.claimTo(market, account, dest, accrue);
|
||||||
|
|
||||||
|
//in reward token decimals
|
||||||
|
uint256 totalRewardsClaimed = cometRewards.rewardsClaimed(
|
||||||
|
market,
|
||||||
|
account
|
||||||
|
);
|
||||||
|
setUint(setId, totalRewardsClaimed);
|
||||||
|
|
||||||
|
_eventName = "LogRewardsClaimedTo(address,address,address,uint256,uint256,bool)";
|
||||||
|
_eventParam = abi.encode(
|
||||||
|
market,
|
||||||
|
account,
|
||||||
|
dest,
|
||||||
|
totalRewardsClaimed,
|
||||||
|
setId,
|
||||||
|
accrue
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contract ConnectV3Compound is CompoundResolver {
|
contract ConnectV3Compound is CompoundIIIResolver {
|
||||||
string public name = "Compound-v1.0";
|
string public name = "Compound-v1.0";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user