-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP add part complete fund manager for the OVM #8
- Loading branch information
1 parent
fe02c41
commit 5aba3cf
Showing
6 changed files
with
109 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "./interfaces/IDCAManager.sol"; | ||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; | ||
|
||
/* | ||
* @dev this contract is responsible for dollar cost averaging a users position from DAI to ETH at a specific time (weekly) and percentage(10%) on the OVM | ||
*/ | ||
contract DCAManager is IDCAManager { | ||
|
||
uint public percentage; //= 0.1 ether; // since both DAI and WETH are decimals 18 | ||
uint public timeInterval; //= 604800; // 1 week in seconds | ||
uint public lastTimeStamp; | ||
string public fundPosition; // e.g. DAI to WETH 10% Weekly | ||
address public baseToken; | ||
address public destinationToken; | ||
|
||
constructor( | ||
address _baseToken, | ||
address _destinationToken, | ||
uint _timeInterval, | ||
uint _percentage, | ||
string _fundPosition | ||
) public { | ||
lastTimeStamp = block.timestamp; | ||
baseToken = _baseToken; | ||
destinationToken = _destinationToken; | ||
timeInterval = _timeInterval; | ||
percentage = _percentage; | ||
fundPosition = _fundPosition; | ||
} | ||
|
||
mapping(address => mapping(address => uint)) balances; // user => token => balance | ||
|
||
modifier isATokenPair(address token) { | ||
require(token == baseToken || token == destinationToken); | ||
_; | ||
} | ||
|
||
// you should only deposit the base token i.e. DAI | ||
function deposit(uint amount) public returns(bool) { | ||
require(ERC20(baseToken).transferFrom(msg.sender, address(this), amount)); | ||
baseTokenBalances[msg.sender] += amount; | ||
|
||
return true; | ||
} | ||
|
||
function getContractBalances() public view returns(address, uint, address, uint) { | ||
uint baseTokenBalance = ERC20(baseToken).balanceOf(address(this)); | ||
uint destinationTokenBalance = ERC20(destinationToken).balanceOf(address(this)); | ||
// base & destination token | ||
return (baseToken, baseTokenBalance, destinationToken, destinationTokenBalance); | ||
} | ||
|
||
// you should be able to withdraw either the base token or the destination token | ||
function withdraw(uint amount, address token) public isATokenPair(token) returns(bool) { | ||
require(balances[msg.sender][token] >= amount); | ||
require(ERC20(token).transferFrom(address(this), msg.sender, amount)); | ||
balances[msg.sender][token] -= amount; | ||
|
||
return true; | ||
} | ||
|
||
function performSwap() public returns(bool) { | ||
require(lastTimeStamp + timeInterval <= block.timestamp); | ||
(address dai, uint daiBalance, address weth, uint wethBalance) = getContractBalances(); | ||
uint amountOfDaiToSwap = daiBalance * percentage; | ||
//TODO do uniswap swap here with default values | ||
lastTimeStamp = block.timestamp; | ||
|
||
return true; | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
interface IDCAManager { | ||
/* | ||
* @dev allow the user to deposit the base pair into the contract for DCA | ||
* @param amount - the amount of the token they wish to deposit | ||
*/ | ||
function deposit(uint amount) external returns(bool); | ||
/* | ||
* @dev allow the user to withdraw the either token from the pool | ||
* @param amount - the amount of the token they wish to deposit | ||
* @param token - the address of the token contract | ||
* @returns boolean - true if successful else revert | ||
*/ | ||
function withdraw(uint amount, address token) external returns(bool); | ||
/* | ||
* @dev perform the swap of the base token into the destination token | ||
* @returns boolean - true if successful else revert | ||
*/ | ||
function performSwap() external returns(bool); | ||
/* | ||
* @dev get the balances of both the base and destination token that the contract holds | ||
* @returns address base token, uint balance, address destination token, uint balance | ||
*/ | ||
function getContractBalances() external returns(address, uint, address, uint); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters