Skip to content
This repository has been archived by the owner on Feb 25, 2023. It is now read-only.

Commit

Permalink
[DataFeed] added interface for importing | fix test constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
carlolm committed Dec 8, 2017
1 parent c1298cd commit 3f1c1b4
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions contracts/DataFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import "./jsmnsol/JsmnSolLib.sol";
* @dev Generic Oraclize data feed contract for data feeds returning an unsigned integer.
*/

contract IDataFeed {
uint public value; // Total portfolio value in USD
uint public usdEth; // USD/ETH exchange rate
}

contract DataFeed is usingOraclize, DestructibleModified {
using SafeMath for uint;
using JsmnSolLib for string;
Expand Down
6 changes: 3 additions & 3 deletions contracts/Fund.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ contract Fund is DestructiblePausable {
// Modules: where possible, fund logic is delegated to the module contracts below, so that they can be patched and upgraded after contract deployment
NavCalculator public navCalculator; // calculating net asset value
InvestorActions public investorActions; // performing investor actions such as subscriptions, redemptions, and withdrawals
DataFeed public dataFeed; // fetching external data like total portfolio value and exchange rates
IDataFeed public dataFeed; // fetching external data like total portfolio value and exchange rates

// This struct tracks fund-related balances for a specific investor address
struct Investor {
Expand Down Expand Up @@ -135,7 +135,7 @@ contract Fund is DestructiblePausable {
exchange = _exchange;
navCalculator = NavCalculator(_navCalculator);
investorActions = InvestorActions(_investorActions);
dataFeed = DataFeed(_dataFeed);
dataFeed = IDataFeed(_dataFeed);

// Set the initial net asset value calculation variables
lastCalcDate = now;
Expand Down Expand Up @@ -560,7 +560,7 @@ contract Fund is DestructiblePausable {
{
require(_addr != address(0));
address old = dataFeed;
dataFeed = DataFeed(_addr);
dataFeed = IDataFeed(_addr);
LogDataFeedModuleChanged(old, _addr);
return true;
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/InvestorActions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ contract InvestorActions is DestructibleModified {
address public fundAddress;

// Modules
DataFeed public dataFeed;
IDataFeed public dataFeed;
Fund fund;

// This modifier is applied to all external methods in this contract since only
Expand All @@ -36,7 +36,7 @@ contract InvestorActions is DestructibleModified {
address _dataFeed
)
{
dataFeed = DataFeed(_dataFeed);
dataFeed = IDataFeed(_dataFeed);
}

// Modifies the max investment limit allowed for an investor and overwrites the past limit
Expand Down Expand Up @@ -253,7 +253,7 @@ contract InvestorActions is DestructibleModified {
onlyOwner
returns (bool success)
{
dataFeed = DataFeed(_address);
dataFeed = IDataFeed(_address);
return true;
}
}
6 changes: 3 additions & 3 deletions contracts/NavCalculator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ contract NavCalculator is DestructibleModified {
address public fundAddress;

// Modules
DataFeed public dataFeed;
IDataFeed public dataFeed;
Fund fund;

// This modifier is applied to all external methods in this contract since only
Expand All @@ -35,7 +35,7 @@ contract NavCalculator is DestructibleModified {

function NavCalculator(address _dataFeed)
{
dataFeed = DataFeed(_dataFeed);
dataFeed = IDataFeed(_dataFeed);
}

event LogNavCalculation(
Expand Down Expand Up @@ -131,7 +131,7 @@ contract NavCalculator is DestructibleModified {
function setDataFeed(address _address)
onlyOwner
{
dataFeed = DataFeed(_address);
dataFeed = IDataFeed(_address);
}

// ********* HELPERS *********
Expand Down
13 changes: 10 additions & 3 deletions test/3_initialize_fund.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ contract('Initialize Fund', (accounts) => {
const EXCHANGE = accounts[1];
const INITIAL_NAV = web3.toWei(1, 'ether');

const USD_ETH = 300;
const GAS_AMT = 500000;
const USD_ETH_EXCHANGE_RATE = 450;
const USD_BTC_EXCHANGE_RATE = 10000;
const USD_LTC_EXCHANGE_RATE = 100;
const SECONDS_BETWEEN_QUERIES = 300;

const MIN_INITIAL_SUBSCRIPTION = 20;
const INVESTOR_ALLOCATION = 21;
const MIN_SUBSCRIPTION = 5;
Expand All @@ -42,8 +47,10 @@ contract('Initialize Fund', (accounts) => {
before(() => DataFeed.new(
false, // _useOraclize
'[NOT USED]', // _queryUrl
300, // _secondsBetweenQueries
USD_ETH * 100, // _initialExchangeRate
SECONDS_BETWEEN_QUERIES, // _secondsBetweenQueries
USD_ETH_EXCHANGE_RATE * 100, // _initialUsdEthRate
USD_BTC_EXCHANGE_RATE * 100, // _initialUsdBtcRate
USD_LTC_EXCHANGE_RATE * 100, // _initialUsdLtcRate
EXCHANGE, // _exchange
{ from: OWNER, value: 0 }
)
Expand Down
12 changes: 9 additions & 3 deletions test/4_fund_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ contract('Fund Actions', (accounts) => {

// test parameters
const GAS_AMT = 500000;
const USD_ETH = 300;
const USD_ETH_EXCHANGE_RATE = 450;
const USD_BTC_EXCHANGE_RATE = 10000;
const USD_LTC_EXCHANGE_RATE = 100;
const SECONDS_BETWEEN_QUERIES = 300;

const MIN_INITIAL_SUBSCRIPTION = 20;
const INVESTOR_ALLOCATION = 21;
const MIN_SUBSCRIPTION = 5;
Expand Down Expand Up @@ -61,8 +65,10 @@ contract('Fund Actions', (accounts) => {
before(() => DataFeed.new(
false, // _useOraclize
'[NOT USED]', // _queryUrl
USD_ETH * 100, // _secondsBetweenQueries
30000, // _initialExchangeRate
SECONDS_BETWEEN_QUERIES, // _secondsBetweenQueries
USD_ETH_EXCHANGE_RATE * 100, // _initialUsdEthRate
USD_BTC_EXCHANGE_RATE * 100, // _initialUsdBtcRate
USD_LTC_EXCHANGE_RATE * 100, // _initialUsdLtcRate
EXCHANGE, // _exchange
{ from: OWNER, value: 0 }
)
Expand Down

0 comments on commit 3f1c1b4

Please sign in to comment.