From 28bf7430cc3c140d948a5061800a601c3c9fee1e Mon Sep 17 00:00:00 2001 From: Brendan Chou Date: Fri, 12 Oct 2018 13:43:54 -0700 Subject: [PATCH] fix for more comments --- .../IMatchingMarketV1.sol} | 4 +- .../ISimpleMarketV1.sol} | 2 +- ...sol => OasisV1MatchingExchangeWrapper.sol} | 44 ++++++++++--------- ...r.sol => OasisV1SimpleExchangeWrapper.sol} | 24 +++++----- migrations/2_deploy.js | 8 ++-- .../TestMatchingMarketExchangeWrapper.js | 6 +-- .../TestSimpleMarketExchangeWrapper.js | 6 +-- 7 files changed, 48 insertions(+), 46 deletions(-) rename contracts/external/Maker/{IMatchingMarket.sol => OasisV1/IMatchingMarketV1.sol} (97%) rename contracts/external/Maker/{ISimpleMarket.sol => OasisV1/ISimpleMarketV1.sol} (98%) rename contracts/margin/external/exchangewrappers/{MatchingMarketExchangeWrapper.sol => OasisV1MatchingExchangeWrapper.sol} (80%) rename contracts/margin/external/exchangewrappers/{SimpleMarketExchangeWrapper.sol => OasisV1SimpleExchangeWrapper.sol} (88%) diff --git a/contracts/external/Maker/IMatchingMarket.sol b/contracts/external/Maker/OasisV1/IMatchingMarketV1.sol similarity index 97% rename from contracts/external/Maker/IMatchingMarket.sol rename to contracts/external/Maker/OasisV1/IMatchingMarketV1.sol index 5810c0ac..a923173e 100644 --- a/contracts/external/Maker/IMatchingMarket.sol +++ b/contracts/external/Maker/OasisV1/IMatchingMarketV1.sol @@ -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 ================ diff --git a/contracts/external/Maker/ISimpleMarket.sol b/contracts/external/Maker/OasisV1/ISimpleMarketV1.sol similarity index 98% rename from contracts/external/Maker/ISimpleMarket.sol rename to contracts/external/Maker/OasisV1/ISimpleMarketV1.sol index 851b184b..9225c9c5 100644 --- a/contracts/external/Maker/ISimpleMarket.sol +++ b/contracts/external/Maker/OasisV1/ISimpleMarketV1.sol @@ -2,7 +2,7 @@ pragma solidity 0.4.24; pragma experimental "v0.5.0"; -contract ISimpleMarket { +contract ISimpleMarketV1 { // ============ Structs ================ diff --git a/contracts/margin/external/exchangewrappers/MatchingMarketExchangeWrapper.sol b/contracts/margin/external/exchangewrappers/OasisV1MatchingExchangeWrapper.sol similarity index 80% rename from contracts/margin/external/exchangewrappers/MatchingMarketExchangeWrapper.sol rename to contracts/margin/external/exchangewrappers/OasisV1MatchingExchangeWrapper.sol index d1d1a940..e62933d7 100644 --- a/contracts/margin/external/exchangewrappers/MatchingMarketExchangeWrapper.sol +++ b/contracts/margin/external/exchangewrappers/OasisV1MatchingExchangeWrapper.sol @@ -20,7 +20,7 @@ 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"; @@ -28,12 +28,12 @@ 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 { @@ -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); @@ -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 @@ -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; @@ -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 @@ -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); } } diff --git a/contracts/margin/external/exchangewrappers/SimpleMarketExchangeWrapper.sol b/contracts/margin/external/exchangewrappers/OasisV1SimpleExchangeWrapper.sol similarity index 88% rename from contracts/margin/external/exchangewrappers/SimpleMarketExchangeWrapper.sol rename to contracts/margin/external/exchangewrappers/OasisV1SimpleExchangeWrapper.sol index 2881586a..c4067276 100644 --- a/contracts/margin/external/exchangewrappers/SimpleMarketExchangeWrapper.sol +++ b/contracts/margin/external/exchangewrappers/OasisV1SimpleExchangeWrapper.sol @@ -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"; @@ -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 { @@ -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); @@ -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 @@ -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 @@ -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); @@ -182,7 +182,7 @@ contract SimpleMarketExchangeWrapper is } function getOffer( - ISimpleMarket market, + ISimpleMarketV1 market, uint256 offerId ) private @@ -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" ); } @@ -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; diff --git a/migrations/2_deploy.js b/migrations/2_deploy.js index 823501eb..1a10c543 100644 --- a/migrations/2_deploy.js +++ b/migrations/2_deploy.js @@ -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"); @@ -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( diff --git a/test/tests/margin/external/exchangewrappers/TestMatchingMarketExchangeWrapper.js b/test/tests/margin/external/exchangewrappers/TestMatchingMarketExchangeWrapper.js index 9ca906eb..75c6fc58 100644 --- a/test/tests/margin/external/exchangewrappers/TestMatchingMarketExchangeWrapper.js +++ b/test/tests/margin/external/exchangewrappers/TestMatchingMarketExchangeWrapper.js @@ -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'); @@ -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"); @@ -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]; diff --git a/test/tests/margin/external/exchangewrappers/TestSimpleMarketExchangeWrapper.js b/test/tests/margin/external/exchangewrappers/TestSimpleMarketExchangeWrapper.js index 159b981f..8f71de82 100644 --- a/test/tests/margin/external/exchangewrappers/TestSimpleMarketExchangeWrapper.js +++ b/test/tests/margin/external/exchangewrappers/TestSimpleMarketExchangeWrapper.js @@ -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"); @@ -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"); @@ -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];