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

Commit

Permalink
fix for more comments
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanChou committed Oct 12, 2018
1 parent a27731a commit 28bf743
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 46 deletions.
@@ -1,10 +1,10 @@
pragma solidity 0.4.24;
pragma experimental "v0.5.0";

import { ISimpleMarket } from "./ISimpleMarket.sol";
import { ISimpleMarketV1 } from "./ISimpleMarketV1.sol";


contract IMatchingMarket is ISimpleMarket {
contract IMatchingMarketV1 is ISimpleMarketV1 {

// ============ Structs ================

Expand Down
Expand Up @@ -2,7 +2,7 @@ pragma solidity 0.4.24;
pragma experimental "v0.5.0";


contract ISimpleMarket {
contract ISimpleMarketV1 {

// ============ Structs ================

Expand Down
Expand Up @@ -20,20 +20,20 @@ pragma solidity 0.4.24;
pragma experimental "v0.5.0";

import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";
import { IMatchingMarket } from "../../../external/Maker/IMatchingMarket.sol";
import { IMatchingMarketV1 } from "../../../external/Maker/OasisV1/IMatchingMarketV1.sol";
import { AdvancedTokenInteract } from "../../../lib/AdvancedTokenInteract.sol";
import { TokenInteract } from "../../../lib/TokenInteract.sol";
import { ExchangeReader } from "../../interfaces/ExchangeReader.sol";
import { ExchangeWrapper } from "../../interfaces/ExchangeWrapper.sol";


/**
* @title MatchingMarketExchangeWrapper
* @title OasisV1MatchingExchangeWrapper
* @author dYdX
*
* dYdX ExchangeWrapper to interface with Maker's MatchingMarket contract (Oasis exchange)
*/
contract MatchingMarketExchangeWrapper is
contract OasisV1MatchingExchangeWrapper is
ExchangeWrapper,
ExchangeReader
{
Expand Down Expand Up @@ -77,7 +77,7 @@ contract MatchingMarketExchangeWrapper is
external
returns (uint256)
{
IMatchingMarket market = IMatchingMarket(MATCHING_MARKET);
IMatchingMarketV1 market = IMatchingMarketV1(MATCHING_MARKET);

// make sure that the exchange can take the tokens from this contract
takerToken.ensureAllowance(address(market), requestedFillAmount);
Expand Down Expand Up @@ -109,7 +109,9 @@ contract MatchingMarketExchangeWrapper is
view
returns (uint256)
{
uint256 costInTakerToken = IMatchingMarket(MATCHING_MARKET).getPayAmount(
IMatchingMarketV1 market = IMatchingMarketV1(MATCHING_MARKET);

uint256 costInTakerToken = market.getPayAmount(
takerToken,
makerToken,
desiredMakerToken
Expand All @@ -132,10 +134,10 @@ contract MatchingMarketExchangeWrapper is
(uint256 takerAmountRatio, uint256 makerAmountRatio) = getMaximumPrice(orderData);
require(
makerAmountRatio > 0,
"MatchingMarketExchangeWrapper#getMaxMakerAmount: No maximum price given"
"OasisV1MatchingExchangeWrapper#getMaxMakerAmount: No maximum price given"
);

IMatchingMarket market = IMatchingMarket(MATCHING_MARKET);
IMatchingMarketV1 market = IMatchingMarketV1(MATCHING_MARKET);
uint256 offerId = market.getBestOffer(makerToken, takerToken);
uint256 totalMakerAmount = 0;

Expand Down Expand Up @@ -173,13 +175,13 @@ contract MatchingMarketExchangeWrapper is
// all amounts have previously been required to fit within 128 bits each
require(
takerAmount.mul(makerAmountRatio) <= makerAmount.mul(takerAmountRatio),
"MatchingMarketExchangeWrapper:#requireBelowMaximumPrice: price is too high"
"OasisV1MatchingExchangeWrapper:#requireBelowMaximumPrice: price is too high"
);
}
}

function getOffer(
IMatchingMarket market,
IMatchingMarketV1 market,
uint256 offerId
)
private
Expand Down Expand Up @@ -210,38 +212,38 @@ contract MatchingMarketExchangeWrapper is
pure
returns (uint256, uint256)
{
uint256 takerAmount = 0;
uint256 makerAmount = 0;
uint256 takerAmountRatio = 0;
uint256 makerAmountRatio = 0;

if (orderData.length > 0) {
require(
orderData.length == 64,
"MatchingMarketExchangeWrapper:#getMaximumPrice: orderData is not the right length"
"OasisV1MatchingExchangeWrapper:#getMaximumPrice: orderData is not the right length"
);

/* solium-disable-next-line security/no-inline-assembly */
assembly {
takerAmount := mload(add(orderData, 32))
makerAmount := mload(add(orderData, 64))
takerAmountRatio := mload(add(orderData, 32))
makerAmountRatio := mload(add(orderData, 64))
}

// require numbers to fit within 128 bits to prevent overflow when checking bounds
require(
uint128(takerAmount) == takerAmount,
"MatchingMarketExchangeWrapper:#getMaximumPrice: takerAmount larger than 128 bits"
uint128(takerAmountRatio) == takerAmountRatio,
"OasisV1MatchingExchangeWrapper:#getMaximumPrice: takerAmountRatio > 128 bits"
);
require(
uint128(makerAmount) == makerAmount,
"MatchingMarketExchangeWrapper:#getMaximumPrice: makerAmount larger than 128 bits"
uint128(makerAmountRatio) == makerAmountRatio,
"OasisV1MatchingExchangeWrapper:#getMaximumPrice: makerAmountRatio > 128 bits"
);

// since this is a price ratio, the denominator cannot be zero
require(
makerAmount > 0,
"MatchingMarketExchangeWrapper:#getMaximumPrice: makerAmount cannot be zero"
makerAmountRatio > 0,
"OasisV1MatchingExchangeWrapper:#getMaximumPrice: makerAmountRatio cannot be zero"
);
}

return (takerAmount, makerAmount);
return (takerAmountRatio, makerAmountRatio);
}
}
Expand Up @@ -20,7 +20,7 @@ pragma solidity 0.4.24;
pragma experimental "v0.5.0";

import { SafeMath } from "openzeppelin-solidity/contracts/math/SafeMath.sol";
import { ISimpleMarket } from "../../../external/Maker/ISimpleMarket.sol";
import { ISimpleMarketV1 } from "../../../external/Maker/OasisV1/ISimpleMarketV1.sol";
import { AdvancedTokenInteract } from "../../../lib/AdvancedTokenInteract.sol";
import { MathHelpers } from "../../../lib/MathHelpers.sol";
import { TokenInteract } from "../../../lib/TokenInteract.sol";
Expand All @@ -29,14 +29,14 @@ import { ExchangeWrapper } from "../../interfaces/ExchangeWrapper.sol";


/**
* @title SimpleMarketExchangeWrapper
* @title OasisV1SimpleExchangeWrapper
* @author dYdX
*
* dYdX ExchangeWrapper to interface with Maker's (Oasis exchange) SimpleMarket or MatchingMarket
* contracts to trade using a specific offer. Since any MatchingMarket is also a SimpleMarket, this
* ExchangeWrapper can also be used for any MatchingMarket.
*/
contract SimpleMarketExchangeWrapper is
contract OasisV1SimpleExchangeWrapper is
ExchangeWrapper,
ExchangeReader
{
Expand Down Expand Up @@ -80,7 +80,7 @@ contract SimpleMarketExchangeWrapper is
external
returns (uint256)
{
ISimpleMarket market = ISimpleMarket(SIMPLE_MARKET);
ISimpleMarketV1 market = ISimpleMarketV1(SIMPLE_MARKET);
uint256 offerId = bytesToOfferId(orderData);

Offer memory offer = getOffer(market, offerId);
Expand All @@ -99,7 +99,7 @@ contract SimpleMarketExchangeWrapper is
// do the exchange
require(
market.buy(offerId, makerAmount),
"SimpleMarketExchangeWrapper#exchange: Buy failed"
"OasisV1SimpleExchangeWrapper#exchange: Buy failed"
);

// set allowance for the receiver
Expand All @@ -118,13 +118,13 @@ contract SimpleMarketExchangeWrapper is
view
returns (uint256)
{
ISimpleMarket market = ISimpleMarket(SIMPLE_MARKET);
ISimpleMarketV1 market = ISimpleMarketV1(SIMPLE_MARKET);
Offer memory offer = getOffer(market, bytesToOfferId(orderData));
verifyOffer(offer, makerToken, takerToken);

require(
desiredMakerToken <= offer.makerAmount,
"SimpleMarketExchangeWrapper#getExchangeCost: Offer is not large enough"
"OasisV1SimpleExchangeWrapper#getExchangeCost: Offer is not large enough"
);

// return takerToken cost of desiredMakerToken
Expand All @@ -144,7 +144,7 @@ contract SimpleMarketExchangeWrapper is
view
returns (uint256)
{
ISimpleMarket market = ISimpleMarket(SIMPLE_MARKET);
ISimpleMarketV1 market = ISimpleMarketV1(SIMPLE_MARKET);
Offer memory offer = getOffer(market, bytesToOfferId(orderData));
verifyOffer(offer, makerToken, takerToken);

Expand Down Expand Up @@ -182,7 +182,7 @@ contract SimpleMarketExchangeWrapper is
}

function getOffer(
ISimpleMarket market,
ISimpleMarketV1 market,
uint256 offerId
)
private
Expand Down Expand Up @@ -214,11 +214,11 @@ contract SimpleMarketExchangeWrapper is
{
require(
makerToken == offer.makerToken,
"SimpleMarketExchangeWrapper#verifyOffer: offer makerToken does not match"
"OasisV1SimpleExchangeWrapper#verifyOffer: offer makerToken does not match"
);
require(
takerToken == offer.takerToken,
"SimpleMarketExchangeWrapper#verifyOffer: offer takerToken does not match"
"OasisV1SimpleExchangeWrapper#verifyOffer: offer takerToken does not match"
);
}

Expand All @@ -231,7 +231,7 @@ contract SimpleMarketExchangeWrapper is
{
require(
orderData.length == 32,
"SimpleMarketExchangeWrapper:#bytesToOfferId: orderData is not the right length"
"OasisV1SimpleExchangeWrapper:#bytesToOfferId: orderData is not the right length"
);

uint256 offerId;
Expand Down
8 changes: 4 additions & 4 deletions migrations/2_deploy.js
Expand Up @@ -19,8 +19,8 @@
const { isDevNetwork, isMainNet, isKovan, MULTISIG } = require('./helpers');

const OpenDirectlyExchangeWrapper = artifacts.require("OpenDirectlyExchangeWrapper");
const SimpleMarketExchangeWrapper = artifacts.require("SimpleMarketExchangeWrapper");
const MatchingMarketExchangeWrapper = artifacts.require("MatchingMarketExchangeWrapper");
const OasisV1SimpleExchangeWrapper = artifacts.require("OasisV1SimpleExchangeWrapper");
const OasisV1MatchingExchangeWrapper = artifacts.require("OasisV1MatchingExchangeWrapper");
const ZeroExV1ExchangeWrapper = artifacts.require("ZeroExV1ExchangeWrapper");
const ZeroExV2ExchangeWrapper = artifacts.require("ZeroExV2ExchangeWrapper");
const Vault = artifacts.require("Vault");
Expand Down Expand Up @@ -329,11 +329,11 @@ async function deploySecondLayer(deployer, network) {

await Promise.all([
deployer.deploy(
SimpleMarketExchangeWrapper,
OasisV1SimpleExchangeWrapper,
getOasisDexAddress(network)
),
deployer.deploy(
MatchingMarketExchangeWrapper,
OasisV1MatchingExchangeWrapper,
getOasisDexAddress(network)
),
deployer.deploy(
Expand Down
Expand Up @@ -5,7 +5,7 @@ const expect = chai.expect;
chai.use(require('chai-bignumber')());
const BigNumber = require('bignumber.js');

const MatchingMarketExchangeWrapper = artifacts.require("MatchingMarketExchangeWrapper");
const OasisV1MatchingExchangeWrapper = artifacts.require("OasisV1MatchingExchangeWrapper");
const TokenA = artifacts.require("TokenA");
const TokenB = artifacts.require("TokenB");
const { MatchingMarket } = require('../../../../contracts/OasisDex');
Expand All @@ -22,7 +22,7 @@ function priceToBytes(num, den) {
);
}

contract('MatchingMarketExchangeWrapper', accounts => {
contract('OasisV1MatchingExchangeWrapper', accounts => {
let DAI, WETH, OasisDEX, MMEW;
const DAI_PER_WETH = 400;
const MAKER_WETH_AMOUNT = new BigNumber("1e24");
Expand All @@ -39,7 +39,7 @@ contract('MatchingMarketExchangeWrapper', accounts => {
TokenB.new(),
MatchingMarket.new(OASIS_DEX_CLOSE_TIME)
]);
MMEW = await MatchingMarketExchangeWrapper.new(OasisDEX.address);
MMEW = await OasisV1MatchingExchangeWrapper.new(OasisDEX.address);

// set up makers
const maker = accounts[9];
Expand Down
Expand Up @@ -5,7 +5,7 @@ const expect = chai.expect;
chai.use(require('chai-bignumber')());
const BigNumber = require('bignumber.js');

const SimpleMarketExchangeWrapper = artifacts.require("SimpleMarketExchangeWrapper");
const OasisV1SimpleExchangeWrapper = artifacts.require("OasisV1SimpleExchangeWrapper");
const TokenA = artifacts.require("TokenA");
const TokenB = artifacts.require("TokenB");
const TokenC = artifacts.require("TokenC");
Expand All @@ -20,7 +20,7 @@ function orderIdToBytes(orderId) {
return web3Instance.utils.bytesToHex([].concat(toBytes32(orderId)));
}

contract('SimpleMarketExchangeWrapper', accounts => {
contract('OasisV1SimpleExchangeWrapper', accounts => {
let DAI, WETH, TEST, OasisDEX, SMEW;
const DAI_PER_WETH = 400;
const MAKER_WETH_AMOUNT = new BigNumber("1e24");
Expand All @@ -40,7 +40,7 @@ contract('SimpleMarketExchangeWrapper', accounts => {
TokenC.new(),
MatchingMarket.new(OASIS_DEX_CLOSE_TIME)
]);
SMEW = await SimpleMarketExchangeWrapper.new(OasisDEX.address);
SMEW = await OasisV1SimpleExchangeWrapper.new(OasisDEX.address);

// set up makers
const maker = accounts[9];
Expand Down

0 comments on commit 28bf743

Please sign in to comment.