-
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 f9b967a
Showing
6 changed files
with
108 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,73 @@ | ||
pragma solidity ^0.8.0; | ||
|
||
import "./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 | ||
* TODO: | ||
- Handle deposits and balances for users | ||
- Move a certain percentage of the funds per cycle | ||
- Move the funds on a specified interval e.g. weekly | ||
- Handle withdrawals on a pro rata basis | ||
- make the contract erc20? That way users can transfer to other people but tax implications are worse as you can converting a token | ||
*/ | ||
contract DAIToWETHW10DCAManager is IDCAManager { | ||
|
||
uint percentage = 0.1 ether; // since both DAI and ETH are decimals 18 | ||
uint timeInterval = 604800; // 1 week in seconds | ||
uint lastTimeStamp; | ||
address daiOptimism = address(0); //TODO | ||
address wethOptimism = address(0); | ||
|
||
constructor() public { | ||
lastTimeStamp = block.timestamp; | ||
} | ||
|
||
mapping(address => uint) daiBalances; | ||
mapping(address => uint) wethBalances; | ||
|
||
modifier isATokenPair(address token) { | ||
require(token == daiOptimism || token == wethOptimism); | ||
_; | ||
} | ||
|
||
// you should only deposit the base token i.e. DAI | ||
function deposit(uint amount) public returns(bool) { | ||
require(ERC20(daiOptimism).transferFrom(msg.sender, address(this), amount)); | ||
daiBalances[msg.sender] += amount; | ||
|
||
return true; | ||
} | ||
|
||
function getContractBalances() public view returns(address, uint, address, uint) { | ||
uint daiBalance = ERC20(daiOptimism).balanceOf(address(this)); | ||
uint wethBalance = ERC20(wethOptimism).balanceOf(address(this)); | ||
// base & destination token | ||
return (daiOptimism, daiBalance, wethOptimism, wethBalance); | ||
} | ||
|
||
// 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(daiBalances[msg.sender] >= amount); | ||
require(ERC20(token).transferFrom(address(this), msg.sender, amount)); | ||
//TODO this is hideous | ||
if(token == daiOptimism) { | ||
daiBalances[msg.sender] -= amount; | ||
} else { | ||
wethBalances[msg.sender] -= 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 | ||
|
||
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