diff --git a/contracts/asset-proxy/contracts/src/bridges/DydxBridge.sol b/contracts/asset-proxy/contracts/src/bridges/DydxBridge.sol index 8176c2507c..60bcd57ead 100644 --- a/contracts/asset-proxy/contracts/src/bridges/DydxBridge.sol +++ b/contracts/asset-proxy/contracts/src/bridges/DydxBridge.sol @@ -229,7 +229,7 @@ contract DydxBridge is withdrawAction = IDydx.ActionArgs({ actionType: IDydx.ActionType.Withdraw, // withdraw tokens. amount: amountToWithdraw, // amount to withdraw. - accountIdx: bridgeAction.accountIdx, // index in the `accounts` when calling `operate`. + accountIdx: bridgeAction.accountIdx, // index in the `accounts` when calling `operate`. primaryMarketId: bridgeAction.marketId, // indicates which token to withdraw. otherAddress: withdrawTo, // withdraw tokens to this address. // unused parameters diff --git a/contracts/asset-proxy/contracts/src/interfaces/IDydx.sol b/contracts/asset-proxy/contracts/src/interfaces/IDydx.sol index b1aaac75b7..1ec67a2dfe 100644 --- a/contracts/asset-proxy/contracts/src/interfaces/IDydx.sol +++ b/contracts/asset-proxy/contracts/src/interfaces/IDydx.sol @@ -189,13 +189,4 @@ interface IDydx { external view returns (Value memory supplyValue, Value memory borrowValue); - - // @dev Approves/disapproves any number of operators. An operator is an external address that has the - // same permissions to manipulate an account as the owner of the account. Operators are simply - // addresses and therefore may either be externally-owned Ethereum accounts OR smart contracts. - // Operators are also able to act as AutoTrader contracts on behalf of the account owner if the - // operator is a smart contract and implements the IAutoTrader interface. - // @param args A list of OperatorArgs which have an address and a boolean. The boolean value - // denotes whether to approve (true) or revoke approval (false) for that address. - function setOperators(OperatorArg[] calldata args) external; } diff --git a/contracts/asset-proxy/contracts/test/TestDydxBridge.sol b/contracts/asset-proxy/contracts/test/TestDydxBridge.sol index 275d4f1dfb..d23425b865 100644 --- a/contracts/asset-proxy/contracts/test/TestDydxBridge.sol +++ b/contracts/asset-proxy/contracts/test/TestDydxBridge.sol @@ -226,9 +226,6 @@ contract TestDydxBridge is returns (Value memory supplyValue, Value memory borrowValue) {} - /// @dev Unused. - function setOperators(OperatorArg[] calldata args) external {} - /// @dev overrides `_getDydxAddress()` from `DeploymentConstants` to return this address. function _getDydxAddress() internal diff --git a/contracts/dev-utils/CHANGELOG.json b/contracts/dev-utils/CHANGELOG.json index d0495169a2..ac298b5591 100644 --- a/contracts/dev-utils/CHANGELOG.json +++ b/contracts/dev-utils/CHANGELOG.json @@ -46,14 +46,6 @@ { "note": "Remove `LibTransactionDecoder` export", "pr": 2464 - }, - { - "note": "Add `DydxBridge` order validation", - "pr": 2466 - }, - { - "note": "Add `D18` library for working with base-10, 18-precision decimals", - "pr": 2466 } ], "timestamp": 1581204851 diff --git a/contracts/dev-utils/contracts/src/D18.sol b/contracts/dev-utils/contracts/src/D18.sol deleted file mode 100644 index f491976186..0000000000 --- a/contracts/dev-utils/contracts/src/D18.sol +++ /dev/null @@ -1,239 +0,0 @@ -/* - - Copyright 2019 ZeroEx Intl. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - -*/ - -pragma solidity ^0.5.16; - - -/// @dev A library for working with 18 digit, base 10 decimals. -library D18 { - - /// @dev Decimal places for dydx value quantities. - uint256 private constant PRECISION = 18; - /// @dev 1.0 in base-18 decimal. - int256 private constant DECIMAL_ONE = int256(10 ** PRECISION); - /// @dev Minimum signed integer value. - int256 private constant MIN_INT256_VALUE = int256(0x8000000000000000000000000000000000000000000000000000000000000000); - - /// @dev Return `1.0` - function one() - internal - pure - returns (int256 r) - { - r = DECIMAL_ONE; - } - - /// @dev Add two decimals. - function add(int256 a, int256 b) - internal - pure - returns (int256 r) - { - r = _add(a, b); - } - - /// @dev Add two decimals. - function add(uint256 a, int256 b) - internal - pure - returns (int256 r) - { - require(int256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _add(int256(a), b); - } - - /// @dev Add two decimals. - function add(uint256 a, uint256 b) - internal - pure - returns (int256 r) - { - require(int256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - require(int256(b) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _add(int256(a), int256(b)); - } - - /// @dev Subract two decimals. - function sub(int256 a, int256 b) - internal - pure - returns (int256 r) - { - r = _add(a, -b); - } - - /// @dev Subract two decimals. - function sub(uint256 a, int256 b) - internal - pure - returns (int256 r) - { - require(int256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _add(int256(a), -b); - } - - /// @dev Subract two decimals. - function sub(uint256 a, uint256 b) - internal - pure - returns (int256 r) - { - require(int256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - require(int256(b) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _add(int256(a), -int256(b)); - } - - /// @dev Multiply two decimals. - function mul(int256 a, int256 b) - internal - pure - returns (int256 r) - { - r = _div(_mul(a, b), DECIMAL_ONE); - } - - /// @dev Multiply two decimals. - function mul(uint256 a, int256 b) - internal - pure - returns (int256 r) - { - require(int256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _div(_mul(int256(a), b), DECIMAL_ONE); - } - - /// @dev Multiply two decimals. - function mul(int256 a, uint256 b) - internal - pure - returns (int256 r) - { - require(int256(b) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _div(_mul(a, int256(b)), DECIMAL_ONE); - } - - /// @dev Multiply two decimals. - function mul(uint256 a, uint256 b) - internal - pure - returns (int256 r) - { - require(int256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - require(int256(b) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _div(_mul(int256(a), int256(b)), DECIMAL_ONE); - } - - /// @dev Divide two decimals. - function div(int256 a, int256 b) - internal - pure - returns (int256 r) - { - require(a != MIN_INT256_VALUE || b != -1, "D18/DECIMAL_MUL_OVERFLOW"); - r = _div(_mul(a, DECIMAL_ONE), b); - } - - /// @dev Divide two decimals. - function div(uint256 a, int256 b) - internal - pure - returns (int256 r) - { - require(int256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _div(_mul(int256(a), DECIMAL_ONE), b); - } - - /// @dev Divide two decimals. - function div(int256 a, uint256 b) - internal - pure - returns (int256 r) - { - require(int256(b) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _div(_mul(a, DECIMAL_ONE), int256(b)); - } - - /// @dev Divide two decimals. - function div(uint256 a, uint256 b) - internal - pure - returns (int256 r) - { - require(uint256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - require(uint256(b) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = _div(_mul(int256(a), DECIMAL_ONE), int256(b)); - } - - /// @dev Safely convert an unsigned integer into a signed integer. - function toSigned(uint256 a) - internal - pure - returns (int256 r) - { - require(uint256(a) >= 0, "D18/DECIMAL_VALUE_TOO_BIG"); - r = int256(a); - } - - /// @dev Clip a signed value to be positive. - function clip(int256 a) - internal - pure - returns (int256 r) - { - r = a < 0 ? 0 : a; - } - - /// @dev Safely multiply two signed integers. - function _mul(int256 a, int256 b) - private - pure - returns (int256 r) - { - if (a == 0 || b == 0) { - return 0; - } - r = a * b; - require(r / a == b && r / b == a, "D18/DECIMAL_MUL_OVERFLOW"); - return r; - } - - /// @dev Safely divide two signed integers. - function _div(int256 a, int256 b) - private - pure - returns (int256 r) - { - require(b != 0, "D18/DECIMAL_DIVISION_BY_ZERO"); - require(a != MIN_INT256_VALUE || b != -1, "D18/DECIMAL_MUL_OVERFLOW"); - r = a / b; - } - - /// @dev Safely add two signed integers. - function _add(int256 a, int256 b) - private - pure - returns (int256 r) - { - r = a + b; - require( - !((a < 0 && b < 0 && r > a) || (a > 0 && b > 0 && r < a)), - "D18/DECIMAL_MUL_OVERFLOW" - ); - } - -} diff --git a/contracts/dev-utils/package.json b/contracts/dev-utils/package.json index 8788816691..c54868e86d 100644 --- a/contracts/dev-utils/package.json +++ b/contracts/dev-utils/package.json @@ -28,7 +28,7 @@ }, "config": { "publicInterfaceContracts": "DevUtils,LibAssetData,LibDydxBalance,LibOrderTransferSimulation,LibTransactionDecoder", - "abis": "./test/generated-artifacts/@(Addresses|AssetBalance|D18|DevUtils|EthBalanceChecker|ExternalFunctions|LibAssetData|LibDydxBalance|LibOrderTransferSimulation|LibTransactionDecoder|OrderTransferSimulationUtils|OrderValidationUtils|TestDydx|TestLibDydxBalance).json", + "abis": "./test/generated-artifacts/@(Addresses|AssetBalance|DevUtils|EthBalanceChecker|ExternalFunctions|LibAssetData|LibDydxBalance|LibOrderTransferSimulation|LibTransactionDecoder|OrderTransferSimulationUtils|OrderValidationUtils|TestDydx|TestLibDydxBalance).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/dev-utils/test/artifacts.ts b/contracts/dev-utils/test/artifacts.ts index a4ff20758e..e4c1802bc0 100644 --- a/contracts/dev-utils/test/artifacts.ts +++ b/contracts/dev-utils/test/artifacts.ts @@ -7,7 +7,6 @@ import { ContractArtifact } from 'ethereum-types'; import * as Addresses from '../test/generated-artifacts/Addresses.json'; import * as AssetBalance from '../test/generated-artifacts/AssetBalance.json'; -import * as D18 from '../test/generated-artifacts/D18.json'; import * as DevUtils from '../test/generated-artifacts/DevUtils.json'; import * as EthBalanceChecker from '../test/generated-artifacts/EthBalanceChecker.json'; import * as ExternalFunctions from '../test/generated-artifacts/ExternalFunctions.json'; @@ -22,7 +21,6 @@ import * as TestLibDydxBalance from '../test/generated-artifacts/TestLibDydxBala export const artifacts = { Addresses: Addresses as ContractArtifact, AssetBalance: AssetBalance as ContractArtifact, - D18: D18 as ContractArtifact, DevUtils: DevUtils as ContractArtifact, EthBalanceChecker: EthBalanceChecker as ContractArtifact, ExternalFunctions: ExternalFunctions as ContractArtifact, diff --git a/contracts/dev-utils/test/wrappers.ts b/contracts/dev-utils/test/wrappers.ts index 587e4c6281..01f291fa09 100644 --- a/contracts/dev-utils/test/wrappers.ts +++ b/contracts/dev-utils/test/wrappers.ts @@ -5,7 +5,6 @@ */ export * from '../test/generated-wrappers/addresses'; export * from '../test/generated-wrappers/asset_balance'; -export * from '../test/generated-wrappers/d18'; export * from '../test/generated-wrappers/dev_utils'; export * from '../test/generated-wrappers/eth_balance_checker'; export * from '../test/generated-wrappers/external_functions'; diff --git a/contracts/dev-utils/tsconfig.json b/contracts/dev-utils/tsconfig.json index b2b229e0c7..eccc9bf633 100644 --- a/contracts/dev-utils/tsconfig.json +++ b/contracts/dev-utils/tsconfig.json @@ -10,7 +10,6 @@ "generated-artifacts/LibTransactionDecoder.json", "test/generated-artifacts/Addresses.json", "test/generated-artifacts/AssetBalance.json", - "test/generated-artifacts/D18.json", "test/generated-artifacts/DevUtils.json", "test/generated-artifacts/EthBalanceChecker.json", "test/generated-artifacts/ExternalFunctions.json", diff --git a/contracts/integrations/CHANGELOG.json b/contracts/integrations/CHANGELOG.json index 73793aaf84..5538ad897a 100644 --- a/contracts/integrations/CHANGELOG.json +++ b/contracts/integrations/CHANGELOG.json @@ -1,4 +1,13 @@ [ + { + "version": "2.5.0", + "changes": [ + { + "note": "Add `ChaiBridge` and `DydxBridge` gas benchmark tests.", + "pr": 2478 + } + ] + }, { "timestamp": 1582677073, "version": "2.4.2", @@ -57,10 +66,6 @@ { "note": "Add DevUtils DydxBridge validation mainnet tests", "pr": 2466 - }, - { - "note": "Add `ChaiBridge` and `DydxBridge` gas benchmark tests.", - "pr": 2478 } ], "timestamp": 1581204851 diff --git a/contracts/integrations/test/benchmarks/chai_bridge_test.ts b/contracts/integrations/test/benchmarks/chai_bridge_test.ts index 01e15bcc7e..5c9ea2440b 100644 --- a/contracts/integrations/test/benchmarks/chai_bridge_test.ts +++ b/contracts/integrations/test/benchmarks/chai_bridge_test.ts @@ -9,9 +9,9 @@ import { DecodedLogEntry } from 'ethereum-types'; import { contractAddresses } from '../mainnet_fork_utils'; -const CHONKY_DAI_WALLET = '0x3a9F7C8cA36C42d7035E87C3304eE5cBd353a532'; +const CHONKY_DAI_WALLET = '0xe235AAa27428E32cA14089b03F532c571C7ab3c8'; const CHONKY_CHAI_WALLET = '0xfc64382c9ce89ba1c21692a68000366a35ff0336'; -const CHONKY_WETH_WALLET = '0x07320deb2713370a3d7b49189fc2f99906e1ae8e'; +const CHONKY_WETH_WALLET = '0x4abB24590606f5bf4645185e20C4E7B97596cA3B'; blockchainTests.configure({ fork: { unlockedAccounts: [CHONKY_CHAI_WALLET, CHONKY_WETH_WALLET, CHONKY_DAI_WALLET], @@ -91,6 +91,7 @@ blockchainTests.fork.skip('ChaiBridge fill benchmarks', env => { return order; } + // Last run: 282194 it('filling one chai maker asset', async () => { const order = await prepareOrderAsync(); const receipt = await exchange @@ -108,6 +109,7 @@ blockchainTests.fork.skip('ChaiBridge fill benchmarks', env => { logUtils.log(`gas used: ${receipt.gasUsed}`); }); + // Last run: 292707 it('filling one chai taker asset', async () => { const order = await prepareOrderAsync({ makerAddress: CHONKY_WETH_WALLET, @@ -151,6 +153,7 @@ blockchainTests.fork.skip('ChaiBridge fill benchmarks', env => { return order; } + // Last run: 124665 it('filling one dai maker asset', async () => { const order = await prepareOrderAsync({ makerAddress: CHONKY_DAI_WALLET, @@ -171,6 +174,7 @@ blockchainTests.fork.skip('ChaiBridge fill benchmarks', env => { logUtils.log(`gas used: ${receipt.gasUsed}`); }); + // Last run: 124665 it('filling one dai taker asset', async () => { const order = await prepareOrderAsync({ makerAddress: CHONKY_WETH_WALLET, diff --git a/contracts/integrations/test/benchmarks/dydx_bridge_test.ts b/contracts/integrations/test/benchmarks/dydx_bridge_test.ts index 98ed559fc8..474b1de0ad 100644 --- a/contracts/integrations/test/benchmarks/dydx_bridge_test.ts +++ b/contracts/integrations/test/benchmarks/dydx_bridge_test.ts @@ -24,7 +24,7 @@ import { DecodedLogEntry } from 'ethereum-types'; import { contractAddresses } from '../mainnet_fork_utils'; // A chonky dai wallet. -const MAKER_ADDRESS = '0x3a9F7C8cA36C42d7035E87C3304eE5cBd353a532'; +const MAKER_ADDRESS = '0xe235AAa27428E32cA14089b03F532c571C7ab3c8'; // Also a chonky dai wallet. const TAKER_ADDRESS = '0x66c57bf505a85a74609d2c83e94aabb26d691e1f'; blockchainTests.configure({ @@ -42,6 +42,7 @@ blockchainTests.fork.skip('DydxBridge fill benchmarks', env => { dydx = new IDydxContract(DYDX_ADDRESS, env.provider, env.txDefaults); // Initialize a dydx account with some Dai collateral and USDC borrowed. await approveSpenderAsync(MAKER_ADDRESS, BRIDGE_ADDRESS, DAI_ADDRESS); + await approveSpenderAsync(MAKER_ADDRESS, DYDX_ADDRESS, DAI_ADDRESS); await dydx .setOperators([{ operator: BRIDGE_ADDRESS, trusted: true }]) .awaitTransactionSuccessAsync({ from: MAKER_ADDRESS }, { shouldValidate: false }); @@ -225,6 +226,7 @@ blockchainTests.fork.skip('DydxBridge fill benchmarks', env => { return order; } + // Last run: 375066 it('filling a DAI->USDC dydx order with a deposit action', async () => { const order = await prepareOrderAsync(); const receipt = await exchange @@ -242,6 +244,7 @@ blockchainTests.fork.skip('DydxBridge fill benchmarks', env => { logUtils.log(`gas used: ${receipt.gasUsed}`); }); + // Last run: 315896 it('filling a DAI->USDC dydx order with no deposit action', async () => { const order = await prepareOrderAsync({ makerAssetData: encodeDydxBridgeAssetData(DAI_ADDRESS, USDC_ADDRESS, 0),