mirror of
https://github.com/Instadapp/dsa-connectors-2.0.git
synced 2024-07-29 21:57:39 +00:00
feat: add fluid staking contract
This commit is contained in:
parent
aa599f1ff3
commit
1cbdbe64ee
28
contracts/mainnet/connectors/fluid-staking/events.sol
Normal file
28
contracts/mainnet/connectors/fluid-staking/events.sol
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
//SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.2;
|
||||||
|
|
||||||
|
contract Events {
|
||||||
|
|
||||||
|
event LogDeposit(
|
||||||
|
address indexed stakingPool,
|
||||||
|
uint256 amount,
|
||||||
|
uint getId,
|
||||||
|
uint setId
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogWithdrawAndClaimedReward(
|
||||||
|
address indexed stakingPool,
|
||||||
|
uint256 amount,
|
||||||
|
uint256 rewardAmt,
|
||||||
|
uint getId,
|
||||||
|
uint setIdAmount,
|
||||||
|
uint setIdReward
|
||||||
|
);
|
||||||
|
|
||||||
|
event LogClaimedReward(
|
||||||
|
address indexed stakingPool,
|
||||||
|
address indexed rewardToken,
|
||||||
|
uint256 rewardAmt,
|
||||||
|
uint setId
|
||||||
|
);
|
||||||
|
}
|
13
contracts/mainnet/connectors/fluid-staking/helpers.sol
Normal file
13
contracts/mainnet/connectors/fluid-staking/helpers.sol
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
//SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.2;
|
||||||
|
|
||||||
|
|
||||||
|
import { DSMath } from "../../common/math.sol";
|
||||||
|
import { Basic } from "../../common/basic.sol";
|
||||||
|
import { TokenInterface } from "../../common/interfaces.sol";
|
||||||
|
import { IStakingRewards } from "./interface.sol";
|
||||||
|
|
||||||
|
abstract contract Helpers is DSMath, Basic {
|
||||||
|
TokenInterface constant internal REWARD_TOKEN =
|
||||||
|
TokenInterface(0x6f40d4A6237C257fff2dB00FA0510DeEECd303eb); // TODO: Update
|
||||||
|
}
|
9
contracts/mainnet/connectors/fluid-staking/interface.sol
Normal file
9
contracts/mainnet/connectors/fluid-staking/interface.sol
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
//SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.2;
|
||||||
|
|
||||||
|
interface IStakingRewards {
|
||||||
|
function stake(uint256 amount) external;
|
||||||
|
function withdraw(uint256 amount) external;
|
||||||
|
function getReward() external;
|
||||||
|
function balanceOf(address account) external view returns(uint256);
|
||||||
|
}
|
117
contracts/mainnet/connectors/fluid-staking/main.sol
Normal file
117
contracts/mainnet/connectors/fluid-staking/main.sol
Normal file
|
@ -0,0 +1,117 @@
|
||||||
|
//SPDX-License-Identifier: MIT
|
||||||
|
pragma solidity ^0.8.2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @title Fluid Staking.
|
||||||
|
* @dev Stake Fluid for earning rewards.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { TokenInterface } from "../../common/interfaces.sol";
|
||||||
|
import { Stores } from "../../common/stores.sol";
|
||||||
|
import { Helpers } from "./helpers.sol";
|
||||||
|
import { Events } from "./events.sol";
|
||||||
|
import { IStakingRewards } from "./interface.sol";
|
||||||
|
|
||||||
|
contract Main is Helpers, Events {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Deposit ERC20.
|
||||||
|
* @notice Deposit Tokens to staking pool.
|
||||||
|
* @param stakingPool staking pool address.
|
||||||
|
* @param stakingToken staking token address.
|
||||||
|
* @param amt staking token amount.
|
||||||
|
* @param getId ID to retrieve amount.
|
||||||
|
* @param setId ID stores the amount of staked tokens.
|
||||||
|
*/
|
||||||
|
function deposit(
|
||||||
|
address stakingPool,
|
||||||
|
address stakingToken,
|
||||||
|
uint amt,
|
||||||
|
uint getId,
|
||||||
|
uint setId
|
||||||
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
uint _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
||||||
|
TokenInterface stakingTokenContract = TokenInterface(stakingToken);
|
||||||
|
|
||||||
|
_amt = _amt == type(uint256).max
|
||||||
|
? stakingTokenContract.balanceOf(address(this))
|
||||||
|
: _amt;
|
||||||
|
|
||||||
|
approve(stakingTokenContract, address(stakingContract), _amt);
|
||||||
|
stakingContract.stake(_amt);
|
||||||
|
|
||||||
|
setUint(setId, _amt);
|
||||||
|
_eventName = "LogDeposit(address,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(stakingPool, _amt, getId, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Withdraw ERC20.
|
||||||
|
* @notice Withdraw Tokens from the staking pool.
|
||||||
|
* @param stakingPool staking pool address.
|
||||||
|
* @param stakingToken staking token address.
|
||||||
|
* @param amt staking token amount.
|
||||||
|
* @param getId ID to retrieve amount.
|
||||||
|
* @param setIdAmount ID stores the amount of stake tokens withdrawn.
|
||||||
|
* @param setIdReward ID stores the amount of reward tokens claimed.
|
||||||
|
*/
|
||||||
|
function withdraw(
|
||||||
|
address stakingPool,
|
||||||
|
address stakingToken, // TODO: Remove?
|
||||||
|
uint amt,
|
||||||
|
uint getId,
|
||||||
|
uint setIdAmount,
|
||||||
|
uint setIdReward
|
||||||
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
uint _amt = getUint(getId, amt);
|
||||||
|
|
||||||
|
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
||||||
|
|
||||||
|
_amt = _amt == type(uint256).max
|
||||||
|
? stakingContract.balanceOf(address(this))
|
||||||
|
: _amt;
|
||||||
|
|
||||||
|
uint intialBal = REWARD_TOKEN.balanceOf(address(this));
|
||||||
|
stakingContract.withdraw(_amt);
|
||||||
|
stakingContract.getReward();
|
||||||
|
|
||||||
|
uint rewardAmt = REWARD_TOKEN.balanceOf(address(this)) - intialBal;
|
||||||
|
|
||||||
|
setUint(setIdAmount, _amt);
|
||||||
|
setUint(setIdReward, rewardAmt);
|
||||||
|
{
|
||||||
|
_eventName = "LogWithdrawAndClaimedReward(address,uint256,uint256,uint256,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(stakingPool, _amt, rewardAmt, getId, setIdAmount, setIdReward);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dev Claim Reward.
|
||||||
|
* @notice Claim Pending Rewards of tokens staked.
|
||||||
|
* @param stakingPool staking pool address.
|
||||||
|
* @param setId ID stores the amount of reward tokens claimed.
|
||||||
|
*/
|
||||||
|
function claimReward(
|
||||||
|
address stakingPool,
|
||||||
|
uint setId
|
||||||
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
|
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
||||||
|
|
||||||
|
uint intialBal = REWARD_TOKEN.balanceOf(address(this));
|
||||||
|
stakingContract.getReward();
|
||||||
|
uint finalBal = REWARD_TOKEN.balanceOf(address(this));
|
||||||
|
|
||||||
|
uint rewardAmt = finalBal - intialBal;
|
||||||
|
|
||||||
|
setUint(setId, rewardAmt);
|
||||||
|
_eventName = "LogClaimedReward(address,address,uint256,uint256)";
|
||||||
|
_eventParam = abi.encode(address(stakingPool), address(REWARD_TOKEN), rewardAmt, setId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
contract connectV2StakeFluid is Main {
|
||||||
|
string public constant name = "Stake-Fluid-v1.0";
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user