Skip to content

Commit

Permalink
Removed unused contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo Silva committed Feb 2, 2018
1 parent dec0eef commit 8b200dc
Show file tree
Hide file tree
Showing 15 changed files with 84 additions and 152 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build
node_modules
package-lock.json
.vscode
66 changes: 0 additions & 66 deletions contracts/CloseFundToken.sol

This file was deleted.

50 changes: 0 additions & 50 deletions contracts/EIP20Interface.sol

This file was deleted.

35 changes: 22 additions & 13 deletions contracts/Fund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@ pragma solidity ^0.4.18;
import "../node_modules/zeppelin-solidity/contracts/math/SafeMath.sol";
import "../node_modules/zeppelin-solidity/contracts/ownership/Ownable.sol";
import "./OpenFundToken.sol";
import "./OpenFund.sol";

contract Fund is Ownable {
contract Fund is OpenFund, Ownable {
using SafeMath for uint256;

string public name;
string public tokenSymbol;
OpenFundToken public token;
uint256 public purchaseFeePP;
uint256 public sellFeePP;
uint256 public feeDenominator;

mapping(address => uint256) pendingPurchases;
mapping(address => uint256) pendingSells;
address investmentWallet;

function Fund(address _investmentWallet, string _name, string _tokenSymbol) public {
function Fund(address _investmentWallet, string _name, string _tokenSymbol, uint256 _purchaseFeePP, uint256 _sellFeePP, uint _feeDenominator) public {
investmentWallet = _investmentWallet;
name = _name;
tokenSymbol = _tokenSymbol;
purchaseFeePP = _purchaseFeePP;
sellFeePP = _sellFeePP;
feeDenominator = _feeDenominator;
token = createTokenContract();
}

Expand All @@ -31,13 +36,14 @@ contract Fund is Ownable {
}

function purchase() public payable {
//todo what happens if amount is less than NAV?
uint256 weiAmount = msg.value;
address buyer = msg.sender;

pendingPurchases[buyer] = pendingPurchases[buyer].add(weiAmount); // add amount to the pending requests to be processed
owner.transfer(weiAmount); // add amount to the wallet

TokenPurchaseRequest(buyer, weiAmount);

}

function sell(uint256 tokenAmount) public {
Expand All @@ -58,25 +64,27 @@ contract Fund is Ownable {

function processPurchase(uint256 nav, address buyer) public onlyOwner payable { // nav: net asset value. is the price per share of the fund
uint256 weiAmount = pendingPurchases[buyer];

uint256 tokens = getTokenAmount(weiAmount, nav);

token.mint(buyer, tokens);
uint256 fee = weiAmount.mul(purchaseFeePP).div(feeDenominator);
uint256 tokens = getTokenAmount(weiAmount - fee, nav);

investmentWallet.transfer(weiAmount);
token.mint(buyer, tokens);

delete pendingPurchases[buyer];

TokenPurchased(buyer, tokens, nav, fee);
}

function processSell(uint256 nav, address buyer) public onlyOwner payable {
uint256 tokenAmount = pendingSells[buyer];

uint256 weiAmount = getWeiAmount(tokenAmount, nav);
uint256 fee = weiAmount.mul(sellFeePP).div(feeDenominator);

token.burn(buyer, tokenAmount);
buyer.transfer(weiAmount);
buyer.transfer(weiAmount - fee);

delete pendingSells[buyer];

TokenSold(buyer, tokenAmount, nav, fee);
}

function getTokenAmount(uint256 weiAmount, uint256 nav) internal pure returns(uint256) {
Expand All @@ -88,6 +96,7 @@ contract Fund is Ownable {
}

event TokenPurchaseRequest(address indexed purchaser, uint256 amount);
event TokenPurchased(address indexed purchaser, uint256 tokenAmount, uint256 nav, uint256 fee);
event TokenSellRequest(address indexed purchaser, uint256 amount);
event Log(uint256 amount);
event TokenSold(address indexed purchaser, uint256 tokenAmount, uint256 nav, uint256 fee);
}
11 changes: 11 additions & 0 deletions contracts/OpenFund.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pragma solidity ^0.4.18;

import "./OpenFundToken.sol";

contract OpenFund {
string public name;
OpenFundToken public token;

function purchase() public payable;
function sell(uint256 tokenAmount) public;
}
11 changes: 11 additions & 0 deletions deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

set -e

truffle deploy --reset
redis-cli flushall
cp build/contracts/* ../cf-core/blockchain/contracts
cp build/contracts/* ../cf-web/src/contracts
cd ../cf-core
pm2 restart ./ecosystem.config.js
cd ../cf
9 changes: 9 additions & 0 deletions experiment-buy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var Fund = artifacts.require("./Fund.sol");

module.exports = function(callback) {
var fund = Fund.deployed();
fund.then(async function(instance) {
instance.purchase({from: web3.eth.accounts[1], value: web3.toWei(1, 'ether')});
});
}

12 changes: 12 additions & 0 deletions experiment-sell.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var Fund = artifacts.require("./Fund.sol");
var OpenFundToken = artifacts.require("./OpenFundToken.sol");

module.exports = function (callback) {
var fund = Fund.deployed();
fund.then(async function (instance) {
let token = await OpenFundToken.at(await instance.token());
let tokenAmount = await token.balanceOf(web3.eth.accounts[1]);
instance.sell(tokenAmount, { from: web3.eth.accounts[1] });
});
}

6 changes: 6 additions & 0 deletions experiment-transfer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
var Fund = artifacts.require("./Fund.sol");

module.exports = function (callback) {
web3.eth.sendTransaction({ from: web3.eth.accounts[2], to: "0xED7f4Bb6f52033535f555923E906AE64B155D9Ef", value: web3.toWei(20, 'ether') })
}

13 changes: 0 additions & 13 deletions experiment.js

This file was deleted.

8 changes: 8 additions & 0 deletions migrations/2_deploy_funds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
var Fund = artifacts.require('./Fund.sol')

module.exports = async (deployer, network, accounts) => {
let investmentAccount = accounts[1];
let purchaseFeePP = 1;
let sellFeePP = 3;
deployer.deploy(Fund, investmentAccount, "Fund Market 1", "FUNDX1", purchaseFeePP, sellFeePP, 100);
};
5 changes: 0 additions & 5 deletions migrations/2_deploy_tokens.js

This file was deleted.

5 changes: 0 additions & 5 deletions migrations/3_deploy_funds.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"package.json": "^2.0.1",
"zeppelin-solidity": "^1.5.0"
}
}
3 changes: 3 additions & 0 deletions test/Fund.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ contract('Fund', function([ownerWallet, investmentWallet, wallet, purchaser]) {
await fund.processPurchase(nav, purchaser, {value: requestedAmount});

let balance = await token.balanceOf(purchaser);
let totalSupply = await token.totalSupply();

assert.equal(balance.toNumber(), tokenValue);
assert.equal(totalSupply.toNumber(), tokenValue);
});

it("should sell tokens", async function() {
Expand Down

0 comments on commit 8b200dc

Please sign in to comment.