diff --git a/contracts/mainnet/connectors/compound-rewards/events.sol b/contracts/mainnet/connectors/compound-rewards/events.sol new file mode 100644 index 00000000..08d936d9 --- /dev/null +++ b/contracts/mainnet/connectors/compound-rewards/events.sol @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.7.6; +pragma experimental ABIEncoderV2; + +contract Events { + event LogRewardsClaimed( + address indexed market, + address indexed account, + uint256 indexed totalClaimedInWei, + uint256 getId, + bool accrued + ); + + event LogRewardsClaimedTo( + address indexed market, + address indexed account, + address to, + uint256 indexed totalClaimedInWei, + uint256 getId, + bool accrued + ); +} diff --git a/contracts/mainnet/connectors/compound-rewards/helpers.sol b/contracts/mainnet/connectors/compound-rewards/helpers.sol new file mode 100644 index 00000000..748d5bcf --- /dev/null +++ b/contracts/mainnet/connectors/compound-rewards/helpers.sol @@ -0,0 +1,13 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma abicoder v2; + +import { TokenInterface } from "../../common/interfaces.sol"; +import { DSMath } from "../../common/math.sol"; +import { Basic } from "../../common/basic.sol"; +import { CometRewards } from "./interface.sol"; + +abstract contract Helpers is DSMath, Basic { + CometRewards internal constant cometRewards = + CometRewards(0x1B0e765F6224C21223AeA2af16c1C46E38885a40); +} diff --git a/contracts/mainnet/connectors/compound-rewards/interface.sol b/contracts/mainnet/connectors/compound-rewards/interface.sol new file mode 100644 index 00000000..b2157255 --- /dev/null +++ b/contracts/mainnet/connectors/compound-rewards/interface.sol @@ -0,0 +1,37 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma abicoder v2; + +struct UserCollateral { + uint128 balance; + uint128 _reserved; +} + +struct RewardOwed { + address token; + uint256 owed; +} + +interface CometRewards { + function claim( + address comet, + address src, + bool shouldAccrue + ) external; + + function claimTo( + address comet, + address src, + address to, + bool shouldAccrue + ) external; + + function getRewardOwed(address comet, address account) + external + returns (RewardOwed memory); + + function rewardsClaimed(address cometProxy, address account) + external + view + returns (uint256); +} diff --git a/contracts/mainnet/connectors/compound-rewards/main.sol b/contracts/mainnet/connectors/compound-rewards/main.sol new file mode 100644 index 00000000..527c631d --- /dev/null +++ b/contracts/mainnet/connectors/compound-rewards/main.sol @@ -0,0 +1,75 @@ +//SPDX-License-Identifier: MIT +pragma solidity ^0.7.0; +pragma experimental ABIEncoderV2; + +/** + * @title Compound. + * @dev Rewards. + */ + +import { TokenInterface } from "../../common/interfaces.sol"; +import { Stores } from "../../common/stores.sol"; +import { Helpers } from "./helpers.sol"; +import { Events } from "./events.sol"; + +abstract contract CompoundV3RewardsResolver is Events, Helpers { + /** + * @dev Claim rewards and interests accrued in supplied/borrowed base asset. + * @notice Claim rewards and interests accrued. + * @param market The address of the market. + * @param account The account of which the rewards are to be claimed. + * @param accrue Should accrue the rewards and interest before claiming. + * @param setId ID stores the amount of rewards claimed. + */ + function claimRewards( + address market, + address account, + bool accrue, + uint256 setId + ) public returns (string memory eventName_, bytes memory eventParam_) { + uint256 rewardsOwed = cometRewards.getRewardOwed(market, account).owed; + cometRewards.claim(market, account, accrue); + + setUint(setId, rewardsOwed); + + eventName_ = "LogRewardsClaimed(address,address,uint256,uint256,bool)"; + eventParam_ = abi.encode(market, account, rewardsOwed, setId, accrue); + } + + /** + * @dev Claim rewards and interests accrued in supplied/borrowed base asset. + * @notice Claim rewards and interests accrued and transfer to dest address. + * @param market The address of the market. + * @param account The account of which the rewards are to be claimed. + * @param dest The account where to transfer the claimed rewards. + * @param accrue Should accrue the rewards and interest before claiming. + * @param setId ID stores the amount of rewards claimed. + */ + function claimRewardsTo( + address market, + address account, + address dest, + bool accrue, + uint256 setId + ) public returns (string memory eventName_, bytes memory eventParam_) { + //in reward token decimals + uint256 rewardsOwed = cometRewards.getRewardOwed(market, account).owed; + cometRewards.claimTo(market, account, dest, accrue); + + setUint(setId, rewardsOwed); + + eventName_ = "LogRewardsClaimedTo(address,address,address,uint256,uint256,bool)"; + eventParam_ = abi.encode( + market, + account, + dest, + rewardsOwed, + setId, + accrue + ); + } +} + +contract ConnectV2CompoundV3Rewards is CompoundV3RewardsResolver { + string public name = "CompoundV3Rewards-v1.0"; +}