mirror of
https://github.com/Instadapp/dsa-connectors-2.0.git
synced 2024-07-29 21:57:39 +00:00
feat: add spark incentives contract
This commit is contained in:
parent
d8aa7ee6b6
commit
ce443792e6
13
contracts/mainnet/connectors/spark-rewards/events.sol
Normal file
13
contracts/mainnet/connectors/spark-rewards/events.sol
Normal file
|
@ -0,0 +1,13 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.2;
|
||||
|
||||
contract Events {
|
||||
event LogClaimed(
|
||||
address[] assets,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
);
|
||||
|
||||
event LogAllClaimed(address[] assets, address[] rewards, uint256[] amts);
|
||||
}
|
14
contracts/mainnet/connectors/spark-rewards/helpers.sol
Normal file
14
contracts/mainnet/connectors/spark-rewards/helpers.sol
Normal file
|
@ -0,0 +1,14 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.2;
|
||||
|
||||
import {DSMath} from "../../common/math.sol";
|
||||
import {Basic} from "../../common/basic.sol";
|
||||
import {SparkIncentivesInterface} from "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
/**
|
||||
* @dev Spark Incentives
|
||||
*/
|
||||
SparkIncentivesInterface internal constant SPARK_INCENTIVES =
|
||||
SparkIncentivesInterface(0x8164Cc65827dcFe994AB23944CBC90e0aa80bFcb);
|
||||
}
|
18
contracts/mainnet/connectors/spark-rewards/interface.sol
Normal file
18
contracts/mainnet/connectors/spark-rewards/interface.sol
Normal file
|
@ -0,0 +1,18 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.2;
|
||||
|
||||
interface SparkIncentivesInterface {
|
||||
function claimRewards(
|
||||
address[] calldata assets,
|
||||
uint256 amount,
|
||||
address to,
|
||||
address reward
|
||||
) external returns (uint256);
|
||||
|
||||
function claimAllRewards(
|
||||
address[] calldata assets,
|
||||
address to
|
||||
)
|
||||
external
|
||||
returns (address[] memory rewardsList, uint256[] memory claimedAmounts);
|
||||
}
|
94
contracts/mainnet/connectors/spark-rewards/main.sol
Normal file
94
contracts/mainnet/connectors/spark-rewards/main.sol
Normal file
|
@ -0,0 +1,94 @@
|
|||
//SPDX-License-Identifier: MIT
|
||||
pragma solidity ^0.8.2;
|
||||
|
||||
/**
|
||||
* @title Spark Rewards.
|
||||
* @dev Claim spark 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 IncentivesConnector is Helpers, Events {
|
||||
/**
|
||||
* @dev Claim Pending Rewards.
|
||||
* @notice Claim Pending Rewards from Spark incentives contract.
|
||||
* @param assets The list of assets supplied and borrowed.
|
||||
* @param amt The amount of reward to claim. (uint(-1) for max)
|
||||
* @param reward The address of reward token to claim.
|
||||
* @param getId ID to retrieve amt.
|
||||
* @param setId ID stores the amount of rewards claimed.
|
||||
*/
|
||||
function claim(
|
||||
address[] calldata assets,
|
||||
uint256 amt,
|
||||
address reward,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
uint256 _amt = getUint(getId, amt);
|
||||
|
||||
require(assets.length > 0, "invalid-assets");
|
||||
|
||||
TokenInterface weth = TokenInterface(wethAddr);
|
||||
uint256 wethAmountBefore = weth.balanceOf(address(this));
|
||||
|
||||
_amt = SPARK_INCENTIVES.claimRewards(
|
||||
assets,
|
||||
_amt,
|
||||
address(this),
|
||||
reward
|
||||
);
|
||||
|
||||
uint256 wethAmountDiff = weth.balanceOf(address(this)) -
|
||||
wethAmountBefore;
|
||||
convertWethToEth(wethAmountDiff > 0, weth, wethAmountDiff);
|
||||
|
||||
setUint(setId, _amt);
|
||||
|
||||
_eventName = "LogClaimed(address[],uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(assets, _amt, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev Claim All Pending Rewards.
|
||||
* @notice Claim All Pending Rewards from Spark incentives contract.
|
||||
* @param assets The list of assets supplied and borrowed.
|
||||
*/
|
||||
function claimAll(
|
||||
address[] calldata assets
|
||||
)
|
||||
external
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
require(assets.length > 0, "invalid-assets");
|
||||
uint256[] memory _amts = new uint256[](assets.length);
|
||||
address[] memory _rewards = new address[](assets.length);
|
||||
|
||||
TokenInterface weth = TokenInterface(wethAddr);
|
||||
uint256 wethAmountBefore = weth.balanceOf(address(this));
|
||||
|
||||
(_rewards, _amts) = SPARK_INCENTIVES.claimAllRewards(
|
||||
assets,
|
||||
address(this)
|
||||
);
|
||||
|
||||
uint256 wethAmountDiff = weth.balanceOf(address(this)) -
|
||||
wethAmountBefore;
|
||||
convertWethToEth(wethAmountDiff > 0, weth, wethAmountDiff);
|
||||
|
||||
_eventName = "LogAllClaimed(address[],address[],uint256[])";
|
||||
_eventParam = abi.encode(assets, _rewards, _amts);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2SparkIncentives is IncentivesConnector {
|
||||
string public constant name = "Spark-Incentives-v1";
|
||||
}
|
Loading…
Reference in New Issue
Block a user