mirror of
https://github.com/Instadapp/dsa-connectors-2.0.git
synced 2024-07-29 21:57:39 +00:00
feat: update mainnet connector
This commit is contained in:
parent
1cbdbe64ee
commit
afb457e4c2
|
|
@ -1,13 +0,0 @@
|
||||||
//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
|
|
||||||
}
|
|
||||||
|
|
@ -1,9 +1,13 @@
|
||||||
//SPDX-License-Identifier: MIT
|
//SPDX-License-Identifier: MIT
|
||||||
pragma solidity ^0.8.2;
|
pragma solidity ^0.8.2;
|
||||||
|
|
||||||
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
|
||||||
interface IStakingRewards {
|
interface IStakingRewards {
|
||||||
function stake(uint256 amount) external;
|
function stake(uint256 amount) external;
|
||||||
function withdraw(uint256 amount) external;
|
function withdraw(uint256 amount) external;
|
||||||
function getReward() external;
|
function getReward() external;
|
||||||
function balanceOf(address account) external view returns(uint256);
|
function balanceOf(address account) external view returns(uint256);
|
||||||
|
function rewardsToken() external view returns (IERC20);
|
||||||
|
function stakingToken() external view returns (IERC20);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,24 +8,23 @@ pragma solidity ^0.8.2;
|
||||||
|
|
||||||
import { TokenInterface } from "../../common/interfaces.sol";
|
import { TokenInterface } from "../../common/interfaces.sol";
|
||||||
import { Stores } from "../../common/stores.sol";
|
import { Stores } from "../../common/stores.sol";
|
||||||
import { Helpers } from "./helpers.sol";
|
import { Basic } from "../../common/basic.sol";
|
||||||
import { Events } from "./events.sol";
|
import { Events } from "./events.sol";
|
||||||
import { IStakingRewards } from "./interface.sol";
|
import { IStakingRewards } from "./interface.sol";
|
||||||
|
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||||
|
|
||||||
contract Main is Helpers, Events {
|
contract Main is Basic, Events {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @dev Deposit ERC20.
|
* @dev Deposit ERC20.
|
||||||
* @notice Deposit Tokens to staking pool.
|
* @notice Deposit Tokens to staking pool.
|
||||||
* @param stakingPool staking pool address.
|
* @param stakingPool staking pool address.
|
||||||
* @param stakingToken staking token address.
|
|
||||||
* @param amt staking token amount.
|
* @param amt staking token amount.
|
||||||
* @param getId ID to retrieve amount.
|
* @param getId ID to retrieve amount.
|
||||||
* @param setId ID stores the amount of staked tokens.
|
* @param setId ID stores the amount of staked tokens.
|
||||||
*/
|
*/
|
||||||
function deposit(
|
function deposit(
|
||||||
address stakingPool,
|
address stakingPool,
|
||||||
address stakingToken,
|
|
||||||
uint amt,
|
uint amt,
|
||||||
uint getId,
|
uint getId,
|
||||||
uint setId
|
uint setId
|
||||||
|
|
@ -33,13 +32,13 @@ contract Main is Helpers, Events {
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
|
|
||||||
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
||||||
TokenInterface stakingTokenContract = TokenInterface(stakingToken);
|
IERC20 stakingTokenContract = stakingContract.stakingToken();
|
||||||
|
|
||||||
_amt = _amt == type(uint256).max
|
_amt = _amt == type(uint256).max
|
||||||
? stakingTokenContract.balanceOf(address(this))
|
? stakingTokenContract.balanceOf(address(this))
|
||||||
: _amt;
|
: _amt;
|
||||||
|
|
||||||
approve(stakingTokenContract, address(stakingContract), _amt);
|
approve(TokenInterface(address(stakingTokenContract)), address(stakingContract), _amt);
|
||||||
stakingContract.stake(_amt);
|
stakingContract.stake(_amt);
|
||||||
|
|
||||||
setUint(setId, _amt);
|
setUint(setId, _amt);
|
||||||
|
|
@ -51,7 +50,6 @@ contract Main is Helpers, Events {
|
||||||
* @dev Withdraw ERC20.
|
* @dev Withdraw ERC20.
|
||||||
* @notice Withdraw Tokens from the staking pool.
|
* @notice Withdraw Tokens from the staking pool.
|
||||||
* @param stakingPool staking pool address.
|
* @param stakingPool staking pool address.
|
||||||
* @param stakingToken staking token address.
|
|
||||||
* @param amt staking token amount.
|
* @param amt staking token amount.
|
||||||
* @param getId ID to retrieve amount.
|
* @param getId ID to retrieve amount.
|
||||||
* @param setIdAmount ID stores the amount of stake tokens withdrawn.
|
* @param setIdAmount ID stores the amount of stake tokens withdrawn.
|
||||||
|
|
@ -59,7 +57,6 @@ contract Main is Helpers, Events {
|
||||||
*/
|
*/
|
||||||
function withdraw(
|
function withdraw(
|
||||||
address stakingPool,
|
address stakingPool,
|
||||||
address stakingToken, // TODO: Remove?
|
|
||||||
uint amt,
|
uint amt,
|
||||||
uint getId,
|
uint getId,
|
||||||
uint setIdAmount,
|
uint setIdAmount,
|
||||||
|
|
@ -68,16 +65,17 @@ contract Main is Helpers, Events {
|
||||||
uint _amt = getUint(getId, amt);
|
uint _amt = getUint(getId, amt);
|
||||||
|
|
||||||
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
||||||
|
IERC20 rewardsToken = stakingContract.rewardsToken();
|
||||||
|
|
||||||
_amt = _amt == type(uint256).max
|
_amt = _amt == type(uint256).max
|
||||||
? stakingContract.balanceOf(address(this))
|
? stakingContract.balanceOf(address(this))
|
||||||
: _amt;
|
: _amt;
|
||||||
|
|
||||||
uint intialBal = REWARD_TOKEN.balanceOf(address(this));
|
uint intialBal = rewardsToken.balanceOf(address(this));
|
||||||
stakingContract.withdraw(_amt);
|
stakingContract.withdraw(_amt);
|
||||||
stakingContract.getReward();
|
stakingContract.getReward();
|
||||||
|
|
||||||
uint rewardAmt = REWARD_TOKEN.balanceOf(address(this)) - intialBal;
|
uint rewardAmt = rewardsToken.balanceOf(address(this)) - intialBal;
|
||||||
|
|
||||||
setUint(setIdAmount, _amt);
|
setUint(setIdAmount, _amt);
|
||||||
setUint(setIdReward, rewardAmt);
|
setUint(setIdReward, rewardAmt);
|
||||||
|
|
@ -98,20 +96,21 @@ contract Main is Helpers, Events {
|
||||||
uint setId
|
uint setId
|
||||||
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
) external payable returns (string memory _eventName, bytes memory _eventParam) {
|
||||||
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
IStakingRewards stakingContract = IStakingRewards(stakingPool);
|
||||||
|
IERC20 rewardsToken = stakingContract.rewardsToken();
|
||||||
|
|
||||||
uint intialBal = REWARD_TOKEN.balanceOf(address(this));
|
uint intialBal = rewardsToken.balanceOf(address(this));
|
||||||
stakingContract.getReward();
|
stakingContract.getReward();
|
||||||
uint finalBal = REWARD_TOKEN.balanceOf(address(this));
|
uint finalBal = rewardsToken.balanceOf(address(this));
|
||||||
|
|
||||||
uint rewardAmt = finalBal - intialBal;
|
uint rewardAmt = finalBal - intialBal;
|
||||||
|
|
||||||
setUint(setId, rewardAmt);
|
setUint(setId, rewardAmt);
|
||||||
_eventName = "LogClaimedReward(address,address,uint256,uint256)";
|
_eventName = "LogClaimedReward(address,address,uint256,uint256)";
|
||||||
_eventParam = abi.encode(address(stakingPool), address(REWARD_TOKEN), rewardAmt, setId);
|
_eventParam = abi.encode(stakingPool, address(rewardsToken), rewardAmt, setId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
contract connectV2StakeFluid is Main {
|
contract ConnectV2StakeFluid is Main {
|
||||||
string public constant name = "Stake-Fluid-v1.0";
|
string public constant name = "Stake-Fluid-v1.0";
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user