From c71d15038c12ee7f67e25b4873181ba4eeab6088 Mon Sep 17 00:00:00 2001 From: CodeNinja04 Date: Mon, 7 Mar 2022 08:35:49 +0530 Subject: [PATCH] new supply and withdraw functions added --- .../polygon/connectors/fluidity/events.sol | 8 ++ .../polygon/connectors/fluidity/helper.sol | 1 - .../polygon/connectors/fluidity/interface.sol | 5 + .../polygon/connectors/fluidity/main.sol | 124 +++++++++++++----- 4 files changed, 107 insertions(+), 31 deletions(-) diff --git a/contracts/polygon/connectors/fluidity/events.sol b/contracts/polygon/connectors/fluidity/events.sol index c49b21ad..657e8950 100644 --- a/contracts/polygon/connectors/fluidity/events.sol +++ b/contracts/polygon/connectors/fluidity/events.sol @@ -10,6 +10,14 @@ contract Events { uint256 setId ); + event LogSupplyItoken( + address indexed token_, + uint256 amount_, + uint256 itokenAmount_, + uint256 getId, + uint256 setId + ); + event LogWithdraw( address indexed token_, uint256 amt_, diff --git a/contracts/polygon/connectors/fluidity/helper.sol b/contracts/polygon/connectors/fluidity/helper.sol index 75acde00..380415be 100644 --- a/contracts/polygon/connectors/fluidity/helper.sol +++ b/contracts/polygon/connectors/fluidity/helper.sol @@ -1,6 +1,5 @@ // 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"; diff --git a/contracts/polygon/connectors/fluidity/interface.sol b/contracts/polygon/connectors/fluidity/interface.sol index ff532521..ee7a3d80 100644 --- a/contracts/polygon/connectors/fluidity/interface.sol +++ b/contracts/polygon/connectors/fluidity/interface.sol @@ -17,4 +17,9 @@ interface IProtocolModule { function claim(address user_, address token_) external returns (uint256[] memory updatedRewards_); + + function tokenToItoken(address token_) + external + view + returns (address itoken_); } diff --git a/contracts/polygon/connectors/fluidity/main.sol b/contracts/polygon/connectors/fluidity/main.sol index 961c3ce8..f336d47d 100644 --- a/contracts/polygon/connectors/fluidity/main.sol +++ b/contracts/polygon/connectors/fluidity/main.sol @@ -1,6 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity ^0.8.6; -pragma experimental ABIEncoderV2; /** * @title Fluidity. @@ -33,7 +32,7 @@ abstract contract FluidityResolver is Events, Helpers { ? tokenContract.balanceOf(address(this)) : amt_; - Helpers.approve(tokenContract, address(this), amt_); + approve(tokenContract, address(protocolModule), amt_); uint256 itokenAmount_ = protocolModule.supply(token_, amt_); setUint(setId, amt_); @@ -56,15 +55,26 @@ abstract contract FluidityResolver is Events, Helpers { * @param getId ID to retrieve amt * @param setId ID stores the amount of tokens withdrawn */ - function withdraw( + function withdrawRaw( address token_, uint256 amount_, uint256 getId, uint256 setId ) public returns (string memory _eventName, bytes memory _eventParam) { uint256 amt_ = getUint(getId, amount_); + uint256 itokenAmount_; - uint256 itokenAmount_ = protocolModule.withdraw(token_, amt_); + if (amt_ == type(uint256).max) { + address itoken_ = protocolModule.tokenToItoken(token_); + + TokenInterface tokenContract = TokenInterface(itoken_); + + amt_ = tokenContract.balanceOf(address(this)); + + itokenAmount_ = protocolModule.withdrawItoken(itoken_, amt_); + } else { + itokenAmount_ = protocolModule.withdraw(token_, amt_); + } setUint(setId, amt_); @@ -78,31 +88,6 @@ abstract contract FluidityResolver 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 returns (string memory _eventName, bytes memory _eventParam) { - uint256 amt_ = getUint(getId, itokenAmount_); - - uint256 amount_ = protocolModule.withdrawItoken(token_, amt_); - - setUint(setId, amt_); - - _eventName = "LogWithdrawItoken(address,uint256,uint256,uint256,uint256)"; - _eventParam = abi.encode(address(token_), amt_, amount_, getId, setId); - } - /** * @dev * @notice @@ -129,8 +114,87 @@ abstract contract FluidityResolver is Events, Helpers { setId ); } + + /** + * @dev + * @notice + * @param token_ Token Address. + * @param amt Token Amount. + * @param getId ID to retrieve amt + * @param setId ID stores the amount of itokens + */ + + function supplyItoken( + address token_, + uint256 amt, + uint256 getId, + uint256 setId + ) public returns (string memory _eventName, bytes memory _eventParam) { + uint256 amt_ = getUint(getId, amt); + + TokenInterface tokenContract = TokenInterface(token_); + amt_ = amt_ == type(uint256).max + ? tokenContract.balanceOf(address(this)) + : amt_; + + approve(tokenContract, address(protocolModule), amt_); + uint256 itokenAmount_ = protocolModule.supply(token_, amt_); + + setUint(setId, itokenAmount_); + + _eventName = "LogSupplyItoken(address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode( + address(token_), + amt_, + itokenAmount_, + getId, + setId + ); + } + + /** + * @dev + * @notice + * @param token_ Token Address. + * @param amtount Token Amount. + * @param getId ID to retrieve amt + * @param setId ID stores the amount of itokens + */ + + function withdrawItokenRaw( + address token_, + uint256 amount_, + uint256 getId, + uint256 setId + ) public returns (string memory _eventName, bytes memory _eventParam) { + uint256 amt_ = getUint(getId, amount_); + uint256 itokenAmount_; + + if (amt_ == type(uint256).max) { + address itoken_ = protocolModule.tokenToItoken(token_); + + TokenInterface tokenContract = TokenInterface(itoken_); + + amt_ = tokenContract.balanceOf(address(this)); + + itokenAmount_ = protocolModule.withdrawItoken(itoken_, amt_); + } else { + itokenAmount_ = protocolModule.withdraw(token_, amt_); + } + + setUint(setId, itokenAmount_); + + _eventName = "LogWithdrawItoken(address,uint256,uint256,uint256,uint256)"; + _eventParam = abi.encode( + address(itoken_), + amt_, + itokenAmount_, + getId, + setId + ); + } } contract ConnectV2FluidityP1 is FluidityResolver { - string public constant name = "FluidityP1M2"; + string public constant name = "FluidityP1"; }