Skip to content

Commit

Permalink
Merge 8077f4a into 804c54b
Browse files Browse the repository at this point in the history
  • Loading branch information
Phil Elsasser committed Sep 26, 2018
2 parents 804c54b + 8077f4a commit 1d959db
Show file tree
Hide file tree
Showing 18 changed files with 273 additions and 368 deletions.
200 changes: 125 additions & 75 deletions contracts/MarketCollateralPool.sol

Large diffs are not rendered by default.

31 changes: 6 additions & 25 deletions contracts/MarketContract.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ contract MarketContract is Creatable {
}

// constants
address public COLLATERAL_POOL_FACTORY_ADDRESS;
address public MKT_TOKEN_ADDRESS;
MarketToken MKT_TOKEN;

Expand All @@ -62,11 +61,10 @@ contract MarketContract is Creatable {
uint public lastPrice;
uint public settlementPrice;
bool public isSettled = false;
bool public isCollateralPoolContractLinked = false;

// accounting
address public MARKET_COLLATERAL_POOL_ADDRESS;
MarketCollateralPool marketCollateralPool;
MarketCollateralPool MARKET_COLLATERAL_POOL;
OrderLib.OrderMappings orderMappings;

// events
Expand Down Expand Up @@ -101,7 +99,7 @@ contract MarketContract is Creatable {
/// creatorAddress address of the person creating the contract
/// marketTokenAddress address of our member token
/// collateralTokenAddress address of the ERC20 token that will be used for collateral and pricing
/// collateralPoolFactoryAddress address of the factory creating the collateral pools
/// collateralPoolAddress address of the collateral pool
/// @param contractSpecs array of unsigned integers including:
/// floorPrice minimum tradeable price of this contract, contract enters settlement if breached
/// capPrice maximum tradeable price of this contract, contract enters settlement if breached
Expand All @@ -115,7 +113,8 @@ contract MarketContract is Creatable {
uint[5] contractSpecs
) public
{
COLLATERAL_POOL_FACTORY_ADDRESS = baseAddresses[3];
MARKET_COLLATERAL_POOL_ADDRESS = baseAddresses[3];
MARKET_COLLATERAL_POOL = MarketCollateralPool(MARKET_COLLATERAL_POOL_ADDRESS);
MKT_TOKEN_ADDRESS = baseAddresses[1];
MKT_TOKEN = MarketToken(MKT_TOKEN_ADDRESS);
require(MKT_TOKEN.isBalanceSufficientForContractCreation(msg.sender)); // creator must be MKT holder
Expand Down Expand Up @@ -155,7 +154,7 @@ contract MarketContract is Creatable {
bytes32 s
) external returns (int filledQty)
{
require(isCollateralPoolContractLinked && !isSettled); // no trading past settlement
require(!isSettled); // no trading past settlement
require(orderQty != 0 && qtyToFill != 0 && orderQty.isSameSign(qtyToFill)); // no zero trades, sings match
require(MKT_TOKEN.isUserEnabledForContract(this, msg.sender));
OrderLib.Order memory order = address(this).createOrder(orderAddresses, unsignedOrderValues, orderQty);
Expand Down Expand Up @@ -186,7 +185,7 @@ contract MarketContract is Creatable {
}

filledQty = MathLib.absMin(remainingQty, qtyToFill);
marketCollateralPool.updatePositions(
MARKET_COLLATERAL_POOL.updatePositions(
order.maker,
msg.sender,
filledQty,
Expand Down Expand Up @@ -274,18 +273,6 @@ contract MarketContract is Creatable {
return qtyCancelled;
}

/// @notice allows the factory to link a collateral pool contract to this trading contract.
/// can only be called once if successful. Trading cannot commence until this is completed.
/// @param poolAddress deployed address of the unique collateral pool for this contract.
function setCollateralPoolContractAddress(address poolAddress) external onlyFactory {
require(!isCollateralPoolContractLinked); // address has not been set previously
require(poolAddress != address(0)); // not trying to set it to null addr.
marketCollateralPool = MarketCollateralPool(poolAddress);
require(marketCollateralPool.linkedAddress() == address(this)); // ensure pool set up correctly.
MARKET_COLLATERAL_POOL_ADDRESS = poolAddress;
isCollateralPoolContractLinked = true;
}

/* Currently no pre-funding is required.
/// @notice after contract settlement the contract creator can reclaim any
/// unused ethereum balance from this contract that was provided for oracle query costs / gas.
Expand Down Expand Up @@ -339,10 +326,4 @@ contract MarketContract is Creatable {
settlementPrice = finalSettlementPrice;
emit ContractSettled(finalSettlementPrice);
}

///@dev Throws if called by any account other than the factory.
modifier onlyFactory() {
require(msg.sender == COLLATERAL_POOL_FACTORY_ADDRESS);
_;
}
}
4 changes: 2 additions & 2 deletions contracts/chainlink/MarketContractChainLink.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract MarketContractChainLink is MarketContract {
/// creatorAddress address of the person creating the contract
/// marketTokenAddress address of our member token
/// collateralTokenAddress address of the ERC20 token that will be used for collateral and pricing
/// collateralPoolFactoryAddress address of the factory creating the collateral pools
/// collateralPoolAddress address of the the collateral pool
/// @param contractSpecs array of unsigned integers including:
/// floorPrice minimum tradeable price of this contract, contract enters settlement if breached
/// capPrice maximum tradeable price of this contract, contract enters settlement if breached
Expand Down Expand Up @@ -75,4 +75,4 @@ contract MarketContractChainLink is MarketContract {
require(msg.sender == ORACLE_HUB_ADDRESS);
_;
}
}
}
9 changes: 4 additions & 5 deletions contracts/chainlink/MarketContractFactoryChainLink.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,13 @@ pragma solidity ^0.4.24;

import "./MarketContractChainLink.sol";
import "./OracleHubChainLink.sol";
import "../factories/MarketCollateralPoolFactoryInterface.sol";
import "../MarketContractRegistryInterface.sol";


contract MarketContractFactoryChainLink is Ownable {

address public marketContractRegistry;
address public collateralPoolFactoryAddress;
address public collateralPool;
address public oracleHubAddress;

address public MKT_TOKEN_ADDRESS;
Expand All @@ -35,11 +34,11 @@ contract MarketContractFactoryChainLink is Ownable {
constructor(
address registryAddress,
address mktTokenAddress,
address marketCollateralPoolFactoryAddress
address marketCollateralPool
) public {
marketContractRegistry = registryAddress;
MKT_TOKEN_ADDRESS = mktTokenAddress;
collateralPoolFactoryAddress = marketCollateralPoolFactoryAddress;
collateralPool = marketCollateralPool;
}

/// @param contractName viewable name of this contract (BTC/ETH, LTC/ETH, etc)
Expand Down Expand Up @@ -71,7 +70,7 @@ contract MarketContractFactoryChainLink is Ownable {
msg.sender,
MKT_TOKEN_ADDRESS,
collateralTokenAddress,
collateralPoolFactoryAddress
collateralPool
],
oracleHubAddress,
contractSpecs,
Expand Down
50 changes: 0 additions & 50 deletions contracts/factories/MarketCollateralPoolFactory.sol

This file was deleted.

22 changes: 0 additions & 22 deletions contracts/factories/MarketCollateralPoolFactoryInterface.sol

This file was deleted.

20 changes: 5 additions & 15 deletions contracts/oraclize/MarketContractFactoryOraclize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pragma solidity ^0.4.24;

import "./MarketContractOraclize.sol";
import "../MarketContractRegistryInterface.sol";
import "../factories/MarketCollateralPoolFactoryInterface.sol";

import "openzeppelin-solidity/contracts/ownership/Ownable.sol";

Expand All @@ -28,19 +27,19 @@ import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract MarketContractFactoryOraclize is Ownable {

address public marketContractRegistry;
address public collateralPoolFactoryAddress;
address public collateralPool;
address public MKT_TOKEN_ADDRESS;

event MarketContractCreated(address indexed creator, address indexed contractAddress);

/// @dev deploys our factory and ties it the a supply registry address
/// @param registryAddress - address of our MARKET registry
/// @param mktTokenAddress - MARKET Token address
/// @param marketCollateralPoolFactoryAddress - address of collateral pool factory.
constructor(address registryAddress, address mktTokenAddress, address marketCollateralPoolFactoryAddress) public {
/// @param marketCollateralPool - address of collateral pool.
constructor(address registryAddress, address mktTokenAddress, address marketCollateralPool) public {
marketContractRegistry = registryAddress;
MKT_TOKEN_ADDRESS = mktTokenAddress;
collateralPoolFactoryAddress = marketCollateralPoolFactoryAddress;
collateralPool = marketCollateralPool;
}

/// @dev Deploys a new instance of a market contract and adds it to the whitelist.
Expand Down Expand Up @@ -70,7 +69,7 @@ contract MarketContractFactoryOraclize is Ownable {
msg.sender,
MKT_TOKEN_ADDRESS,
collateralTokenAddress,
collateralPoolFactoryAddress
collateralPool
],
contractSpecs,
oracleDataSource,
Expand All @@ -86,13 +85,4 @@ contract MarketContractFactoryOraclize is Ownable {
require(registryAddress != address(0));
marketContractRegistry = registryAddress;
}

/*
currently adding this function pushes us over the edge for gas, for the time being we can leave it out.
/// @dev allows for the owner to set switch out factories
/// @param marketCollateralPoolFactoryAddress desired factory address.
function setCollateralPoolFactoryAddress(address marketCollateralPoolFactoryAddress) external onlyOwner {
collateralPoolFactoryAddress = marketCollateralPoolFactoryAddress;
}
*/
}
4 changes: 2 additions & 2 deletions contracts/oraclize/MarketContractOraclize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ contract MarketContractOraclize is MarketContract, usingOraclize {
/// creatorAddress address of the person creating the contract
/// marketTokenAddress address of our member token
/// collateralTokenAddress address of the ERC20 token that will be used for collateral and pricing
/// collateralPoolFactoryAddress address of the factory creating the collateral pools
/// collateralPoolAddress address of the collateral pool
/// @param contractSpecs array of unsigned integers including:
/// floorPrice minimum tradeable price of this contract, contract enters settlement if breached
/// capPrice maximum tradeable price of this contract, contract enters settlement if breached
Expand Down Expand Up @@ -135,4 +135,4 @@ contract MarketContractOraclize is MarketContract, usingOraclize {
require(queryId != 0);
validQueryIDs[queryId] = true;
}
}
}
19 changes: 5 additions & 14 deletions contracts/oraclize/TestableMarketContractFactoryOraclize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
contract TestableMarketContractFactoryOraclize is Ownable {

address public marketContractRegistry;
address public collateralPoolFactoryAddress;
address public collateralPoolAddress;
address public MKT_TOKEN_ADDRESS;

event MarketContractCreated(address indexed creator, address indexed contractAddress);

/// @dev deploys our factory and ties it the a supply registry address
/// @param registryAddress - address of our MARKET registry
/// @param mktTokenAddress - MARKET Token address
/// @param marketCollateralPoolFactoryAddress - address of collateral pool factory.
constructor(address registryAddress, address mktTokenAddress, address marketCollateralPoolFactoryAddress) public {
/// @param marketCollateralPool - address of collateral pool
constructor(address registryAddress, address mktTokenAddress, address marketCollateralPool) public {
marketContractRegistry = registryAddress;
MKT_TOKEN_ADDRESS = mktTokenAddress;
collateralPoolFactoryAddress = marketCollateralPoolFactoryAddress;
collateralPoolAddress = marketCollateralPool;
}

/// @dev Deploys a new instance of a market contract and adds it to the whitelist.
Expand Down Expand Up @@ -69,7 +69,7 @@ contract TestableMarketContractFactoryOraclize is Ownable {
msg.sender,
MKT_TOKEN_ADDRESS,
collateralTokenAddress,
collateralPoolFactoryAddress
collateralPoolAddress
],
contractSpecs,
oracleDataSource,
Expand All @@ -85,13 +85,4 @@ contract TestableMarketContractFactoryOraclize is Ownable {
require(registryAddress != address(0));
marketContractRegistry = registryAddress;
}

/*
currently adding this function pushes us over the edge for gas, for the time being we can leave it out.
/// @dev allows for the owner to set switch out factories
/// @param marketCollateralPoolFactoryAddress desired factory address.
function setCollateralPoolFactoryAddress(address marketCollateralPoolFactoryAddress) external onlyOwner {
collateralPoolFactoryAddress = marketCollateralPoolFactoryAddress;
}
*/
}
4 changes: 2 additions & 2 deletions contracts/oraclize/TestableMarketContractOraclize.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ contract TestableMarketContractOraclize is MarketContractOraclize {
/// creatorAddress address of the person creating the contract
/// marketTokenAddress address of our member token
/// collateralTokenAddress address of the ERC20 token that will be used for collateral and pricing
/// collateralPoolFactoryAddress address of the factory creating the collateral pools
/// collateralPoolAddress address of the collateral pool
/// @param contractSpecs array of unsigned integers including:
/// floorPrice minimum tradeable price of this contract, contract enters settlement if breached
/// capPrice maximum tradeable price of this contract, contract enters settlement if breached
Expand Down Expand Up @@ -62,4 +62,4 @@ contract TestableMarketContractOraclize is MarketContractOraclize {
lastPrice = price;
checkSettlement();
}
}
}
1 change: 1 addition & 0 deletions contracts/tokens/MarketToken.sol
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ contract MarketToken is UpgradeableToken {
uint256 balanceAfterUnLock = contractAddressToUserAddressToQtyLocked[marketContractAddress][msg.sender].sub(
qtyToUnlock
); // no need to check balance, sub() will ensure sufficient balance to unlock!
// TODO: only allow unlock if user has no open position!
// update balance before external call!
contractAddressToUserAddressToQtyLocked[marketContractAddress][msg.sender] = balanceAfterUnLock;
transferLockedTokensBackToUser(qtyToUnlock);
Expand Down
8 changes: 3 additions & 5 deletions migrations/2_market_contracts.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ const OrderLib = artifacts.require('./libraries/OrderLib.sol');
const OrderLibMock = artifacts.require('./mocks/OrderLibMock.sol');
const CollateralToken = artifacts.require('./tokens/CollateralToken.sol');
const MarketContractOraclize = artifacts.require('./oraclize/TestableMarketContractOraclize.sol');
const MarketCollateralPoolFactory = artifacts.require(
'./factories/MarketCollateralPoolFactory.sol'
);
const MarketCollateralPool = artifacts.require('./MarketCollateralPool.sol');
const MarketContractRegistry = artifacts.require('./MarketContractRegistry.sol');
const MarketToken = artifacts.require('./tokens/MarketToken.sol');
const MarketContractFactory = artifacts.require(
Expand All @@ -17,11 +15,11 @@ module.exports = function(deployer, network) {
deployer.deploy([MathLib, OrderLib, MarketContractRegistry]).then(function(){

deployer.link(MathLib,
[ MarketContractOraclize, MarketContractFactory, MarketCollateralPoolFactory, OrderLibMock ]
[ MarketContractOraclize, MarketContractFactory, MarketCollateralPool, OrderLibMock ]
);
deployer.link(OrderLib, [MarketContractOraclize, MarketContractFactory, OrderLibMock]);

deployer.deploy([OrderLibMock, [MarketCollateralPoolFactory, MarketContractRegistry.address]]);
deployer.deploy([OrderLibMock, [MarketCollateralPool, MarketContractRegistry.address]]);

const marketTokenToLockForTrading = 0; // for testing purposes, require no loc
const marketTokenAmountForContractCreation = 0; //for testing purposes require no balance
Expand Down

0 comments on commit 1d959db

Please sign in to comment.