mirror of
https://github.com/Instadapp/dsa-connectors.git
synced 2024-07-29 22:37:00 +00:00
claim and supply function updated
This commit is contained in:
parent
ef2c024e67
commit
e73f720551
|
|
@ -1,15 +1,16 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.6;
|
||||
|
||||
|
||||
contract Events {
|
||||
|
||||
event LogSupply(address indexed token_, uint amount_,uint itokenAmount_,uint getId,uint setId);
|
||||
event LogSupply(address indexed token_, uint256 amount_,uint256 itokenAmount_,uint256 getId,uint256 setId);
|
||||
|
||||
event LogWithdraw(address indexed token_, uint amt_,uint itokenAmount_,uint getId,uint setId);
|
||||
event LogWithdraw(address indexed token_, uint256 amt_,uint256 itokenAmount_,uint256 getId,uint256 setId);
|
||||
|
||||
event LogWithdrawItoken(address indexed token_, uint amt_,uint amount_,uint getId,uint setId);
|
||||
event LogWithdrawItoken(address indexed token_, uint256 amt_,uint256 amount_,uint256 getId,uint256 setId);
|
||||
|
||||
event LogClaimReward(address indexed user_ , address indexed token_ , uint[] updatedRewards_)
|
||||
event LogClaimReward(address indexed user_ , address indexed token_ , uint256[] updatedRewards_,uint256[] setId);
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,13 +1,26 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import { DSMath } from "../../common/math.sol";
|
||||
import { Basic } from "../../common/basic.sol";
|
||||
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "./interface.sol";
|
||||
|
||||
abstract contract Helpers is DSMath, Basic {
|
||||
P1M2 internal constant p1m2 =
|
||||
P1M2("0xf40c01Adc86CF5d534Ff5CaFaA451694FdD2b08C");
|
||||
IProtocolModule internal constant protocolModule =
|
||||
IProtocolModule("0xf40c01Adc86CF5d534Ff5CaFaA451694FdD2b08C");
|
||||
|
||||
function approve(
|
||||
TokenInterface token_,
|
||||
address spender_,
|
||||
uint256 amount_
|
||||
) internal {
|
||||
try token_.approve(spender_, amount_) {} catch {
|
||||
IERC20 tokenContract_ = IERC20(address(token_));
|
||||
tokenContract_.safeApprove(spender_, 0);
|
||||
tokenContract_.safeApprove(spender_, amount_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.6;
|
||||
|
||||
interface P1M2 {
|
||||
interface IProtocolModule {
|
||||
function supply(address token_, uint256 amount_)
|
||||
external
|
||||
returns (uint256 itokenAmount_);
|
||||
|
|
@ -16,4 +17,6 @@ interface P1M2 {
|
|||
function claim(address user_, address token_)
|
||||
external
|
||||
returns (uint256[] memory updatedRewards_);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,21 +1,32 @@
|
|||
// SPDX-License-Identifier: GPL-3.0
|
||||
pragma solidity ^0.8.6;
|
||||
pragma experimental ABIEncoderV2;
|
||||
|
||||
import {Events} from "./events.sol";
|
||||
import {Helpers} "./helpers.sol";
|
||||
/**
|
||||
* @title Fluidity.
|
||||
* @dev
|
||||
*/
|
||||
|
||||
import { Events } from "./events.sol";
|
||||
import { Helpers } from "./helper.sol";
|
||||
import { TokenInterface } from "../../common/interfaces.sol";
|
||||
|
||||
abstract contract FluidityP1M2 is Events, Helpers {
|
||||
abstract contract FluidityResolver is Events, Helpers {
|
||||
|
||||
/**
|
||||
* @dev
|
||||
* @notice
|
||||
* @param token_ Token Address.
|
||||
* @param amt Token Amount.
|
||||
* @param getId ID to retrieve amt
|
||||
* @param setId ID stores the amount of tokens supplied
|
||||
*/
|
||||
function supply(
|
||||
address token_,
|
||||
uint256 amt,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint256 amt_ = getUint(getId, amt);
|
||||
|
||||
TokenInterface tokenContract = TokenInterface(token_);
|
||||
|
|
@ -23,11 +34,12 @@ abstract contract FluidityP1M2 is Events, Helpers {
|
|||
? tokenContract.balanceOf(address(this))
|
||||
: amt_;
|
||||
|
||||
uint256 itokenAmount_ = p1m2.supply(token_, amt_);
|
||||
Helpers.approve(tokenContract, address(this), amt_);
|
||||
uint256 itokenAmount_ = protocolModule.supply(token_, amt_);
|
||||
|
||||
setUint(setId, amt_);
|
||||
|
||||
_eventName = "LogSupply(address,uint,uint,uint,uint)";
|
||||
_eventName = "LogSupply(address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
address(token_),
|
||||
amt_,
|
||||
|
|
@ -37,27 +49,27 @@ abstract contract FluidityP1M2 is Events, Helpers {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev
|
||||
* @notice
|
||||
* @param token_ Token Address.
|
||||
* @param amtount Token Amount.
|
||||
* @param getId ID to retrieve amt
|
||||
* @param setId ID stores the amount of tokens withdrawn
|
||||
*/
|
||||
function withdraw(
|
||||
address token_,
|
||||
uint256 amount_,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint256 amt_ = getUint(getId, amount_);
|
||||
TokenInterface tokenContract = TokenInterface(token_);
|
||||
amt_ = amt_ == type(uint256).max
|
||||
? tokenContract.balanceOf(address(this))
|
||||
: amt_;
|
||||
|
||||
uint256 itokenAmount_ = p1m2.withdraw(token_, amt_);
|
||||
uint256 itokenAmount_ = protocolModule.withdraw(token_, amt_);
|
||||
|
||||
setUint(setId, amt_);
|
||||
|
||||
_eventName = "LogWithdraw(address,uint,uint,uint,uint)";
|
||||
_eventName = "LogWithdraw(address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(
|
||||
address(token_),
|
||||
amt_,
|
||||
|
|
@ -67,38 +79,50 @@ abstract contract FluidityP1M2 is Events, Helpers {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev
|
||||
* @notice
|
||||
* @param token_ Token Address.
|
||||
* @param itokenAmtount iToken Amount.
|
||||
* @param getId ID to retrieve amt
|
||||
* @param setId ID stores the amount of itokens withdrawn
|
||||
*/
|
||||
|
||||
function withdrawItoken(
|
||||
address token_,
|
||||
uint256 itokenAmount_,
|
||||
uint256 getId,
|
||||
uint256 setId
|
||||
)
|
||||
public
|
||||
payable
|
||||
returns (string memory _eventName, bytes memory _eventParam)
|
||||
{
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint256 amt_ = getUint(getId, itokenAmount_);
|
||||
TokenInterface tokenContract = TokenInterface(token_);
|
||||
amt_ = amt_ == type(uint256).max
|
||||
? tokenContract.balanceOf(address(this))
|
||||
: amt_;
|
||||
|
||||
uint256 amount_ = p1m2.withdrawItoken(token_, amt_);
|
||||
uint256 amount_ = protocolModule.withdrawItoken(token_, amt_);
|
||||
|
||||
setUint(setId, amt_);
|
||||
|
||||
_eventName = "LogWithdrawItoken(address,uint,uint,uint,uint)";
|
||||
_eventName = "LogWithdrawItoken(address,uint256,uint256,uint256,uint256)";
|
||||
_eventParam = abi.encode(address(token_), amt_, amount_, getId, setId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dev
|
||||
* @notice
|
||||
* @param user_ User Address.
|
||||
* @param token_ Token Address.
|
||||
* @param setId Array of setId stores the amount of claimed Rewards
|
||||
*/
|
||||
function claim(
|
||||
address user_,
|
||||
address token_,
|
||||
|
||||
uint256[] memory setId
|
||||
) public returns (string memory _eventName, bytes memory _eventParam) {
|
||||
uint256[] memory updatedRewards_ = p1m2.claim(user_, token_);
|
||||
uint256[] memory updatedRewards_ = protocolModule.claim(user_, token_);
|
||||
|
||||
_eventName = "LogClaimReward(address,address,uint[])";
|
||||
for (uint256 i = 0; i < updatedRewards_.length; i++) {
|
||||
setUint(setId[i], updatedRewards_[i]);
|
||||
}
|
||||
|
||||
_eventName = "LogClaimReward(address,address,uint256[])";
|
||||
_eventParam = abi.encode(
|
||||
address(user_),
|
||||
address(token_),
|
||||
|
|
@ -106,3 +130,7 @@ abstract contract FluidityP1M2 is Events, Helpers {
|
|||
);
|
||||
}
|
||||
}
|
||||
|
||||
contract ConnectV2FluidityP1 is FluidityResolver {
|
||||
string public constant name = "FluidityP1M2";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user