Skip to content

Commit

Permalink
WIP add part complete fund manager for the OVM #8
Browse files Browse the repository at this point in the history
  • Loading branch information
bitcoinwarrior1 committed May 2, 2021
1 parent fe02c41 commit f9b967a
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 24 deletions.
73 changes: 73 additions & 0 deletions contracts/DAIToWETHW10FundManager.sol
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;
}

}
23 changes: 0 additions & 23 deletions contracts/Greeter.sol

This file was deleted.

26 changes: 26 additions & 0 deletions contracts/IDCAManager.sol
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);
}
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ task("accounts", "Prints the list of accounts", async () => {
* @type import('hardhat/config').HardhatUserConfig
*/
module.exports = {
solidity: "0.7.3",
solidity: "0.8.0",
defaultNetwork: "hardhat",
networks: {
hardhat: {
Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"ethereum-waffle": "^3.3.0",
"ethers": "^5.1.4",
"hardhat": "^2.2.1"
},
"dependencies": {
"@openzeppelin/contracts": "^4.1.0"
}
}

0 comments on commit f9b967a

Please sign in to comment.