Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
Renames (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
brandoniles authored Jun 21, 2018
1 parent e868b14 commit f742ce0
Show file tree
Hide file tree
Showing 11 changed files with 1,991 additions and 1,995 deletions.
27 changes: 0 additions & 27 deletions contracts/ExchangeRateFactory.sol

This file was deleted.

42 changes: 20 additions & 22 deletions contracts/ExchangeRateAggregator.sol → contracts/MarketOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,37 @@ pragma solidity 0.4.24;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

import "./ExchangeRateSource.sol";
import "./MarketSource.sol";


/**
* @title Exchange rate aggregator contract
* @title Market Oracle
* @notice https://www.fragments.org/protocol/
*
* @dev The aggregator contract maintains a public whitelist of valid exchange rate sources
* Only the contract owner can add/remove sources from this whitelist.
* The aggregated exchange rate is computed as the volume weighted average of valid
* exchange rates from whitelisted sources.
* @dev This oracle provides price and volume data onchain via a whitelist of sources. The exchange
rate is computed as a volume weighted average of valid exchange rates.
*/
contract ExchangeRateAggregator is Ownable {
contract MarketOracle is Ownable {
using SafeMath for uint256;

// The maximum number of sources which can be added
// Maximum number of whitelisted sources
uint8 public constant MAX_SOURCES = 255;

// It signifies the number of decimal places in the aggregated exchange rate returned by this aggregator
// Number of decimal places in the exchange rate provided by this oracle.
uint8 public constant DECIMALS = 18;

// Whitelist of sources
ExchangeRateSource[] public whitelist;
MarketSource[] public whitelist;

event SourceAdded(ExchangeRateSource source);
event SourceRemoved(ExchangeRateSource source);
event SourceExpired(ExchangeRateSource source);
event SourceAdded(MarketSource source);
event SourceRemoved(MarketSource source);
event SourceExpired(MarketSource source);

/**
* @dev Adds source to whitelist
* @param source Reference to the ExchangeRateSource contract which is to be added.
* @dev Adds a source to the whitelist
* @param source Reference to the MarketSource contract which is to be added.
*/
function addSource(ExchangeRateSource source) public onlyOwner {
function addSource(MarketSource source) public onlyOwner {
require(whitelist.length < MAX_SOURCES);
require(source.DECIMALS() == DECIMALS);
whitelist.push(source);
Expand All @@ -44,9 +42,9 @@ contract ExchangeRateAggregator is Ownable {

/**
* @dev Performs a linear scan and removes the provided source from whitelist
* @param source Reference to the ExchangeRateSource contract which is to be removed.
* @param source Reference to the MarketSource contract which is to be removed.
*/
function removeSource(ExchangeRateSource source) public onlyOwner {
function removeSource(MarketSource source) public onlyOwner {
for (uint8 i = 0; i < whitelist.length; i++) {
if (whitelist[i] == source) {
removeSource(i);
Expand All @@ -55,10 +53,10 @@ contract ExchangeRateAggregator is Ownable {
}

/**
* @dev Computes the volume weighted average of valid exchange rates from whitelisted sources and
* the total trade volume.
* @return The volume weighted average of valid exchange rates from whitelisted sources and
* the total trade volume.
*/
function aggregate() public view returns (uint256, uint256) {
function getPriceAndVolume() public view returns (uint256, uint256) {
uint256 volumeWeightedSum = 0;
uint256 volume = 0;
for (uint8 i = 0; i < whitelist.length; i++) {
Expand All @@ -76,7 +74,7 @@ contract ExchangeRateAggregator is Ownable {
}

/**
* @dev Performs a linear scan on the whitelisted sources and removes dead sources
* @dev Performs a linear scan on the whitelisted sources and removes any dead sources
*/
function removeDeadSources() public {
for (uint8 i = 0; i < whitelist.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import "openzeppelin-solidity/contracts/math/SafeMath.sol";


/**
* @title Exchange rate source contract
* @title Market Source
* @notice https://www.fragments.org/protocol/
*
* @dev This contract interacts with off chain exchange rate providers and records
* the latest fragments to USD exchange rates onto the blockchain.
* @dev This contract provides the USD-UFragments exchange rate and volume from a single offchain
* market source.
*/
contract ExchangeRateSource is Destructible {
contract MarketSource is Destructible {
using SafeMath for uint256;

// It signifies the number of decimal places in the reported exchange rate
Expand Down
27 changes: 27 additions & 0 deletions contracts/MarketSourceFactory.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pragma solidity 0.4.24;

import "./MarketSource.sol";


/**
* @title Market Source Factory
* @notice https://www.fragments.org/protocol/
*
* @dev A factory which spawns MarketSource contracts.
*/
contract MarketSourceFactory {
event SourceCreated(address owner, string name, MarketSource source);

/**
* @dev Any user may call this function to create a MarketSource,
* which can be used to report market data.
* @param name a human readable identifier for the source.
* @return The address of the created MarketSource contract.
*/
function createSource(string name) public returns (MarketSource) {
MarketSource source = new MarketSource(name);
emit SourceCreated(msg.sender, name, source);
source.transferOwnership(msg.sender);
return source;
}
}
16 changes: 8 additions & 8 deletions migrations/2_deploy_contracts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const ExchangeRateFactory = artifacts.require('ExchangeRateFactory.sol');
const ExchangeRateAggregator = artifacts.require('ExchangeRateAggregator.sol');
const MarketSourceFactory = artifacts.require('MarketSourceFactory.sol');
const MarketOracle = artifacts.require('MarketOracle.sol');

const APP_ROOT_PATH = require('app-root-path');
const _require = APP_ROOT_PATH.require;
Expand All @@ -15,8 +15,8 @@ module.exports = function (deployer, network, accounts) {

async function deployFragmentsContracts (deployer) {
deployer.logger.log('Deploying core contracts');
await deployer.deploy(ExchangeRateFactory, deploymentConfig);
await deployer.deploy(ExchangeRateAggregator, deploymentConfig);
await deployer.deploy(MarketSourceFactory, deploymentConfig);
await deployer.deploy(MarketOracle, deploymentConfig);
}

async function saveDeploymentData () {
Expand All @@ -26,10 +26,10 @@ module.exports = function (deployer, network, accounts) {
rpcHttpClient: `http://${config.host}:${config.port}`,
rpcWsClient: `ws://${config.host}:${config.wsPort}`,
deployer: deployerAccount,
exchangeRateAggregator: ExchangeRateAggregator.address,
exchangeRateAggregatorTx: ExchangeRateAggregator.transactionHash,
exchangeRateFactory: ExchangeRateFactory.address,
exchangeRateFactoryTx: ExchangeRateFactory.transactionHash
MarketOracle: MarketOracle.address,
MarketOracleTx: MarketOracle.transactionHash,
MarketSourceFactory: MarketSourceFactory.address,
MarketSourceFactoryTx: MarketSourceFactory.transactionHash
}, `${APP_ROOT_PATH}/migrations/deployments/${config.ref}.yaml`);
}

Expand Down
Loading

0 comments on commit f742ce0

Please sign in to comment.