diff --git a/contracts/tec/README.md b/contracts/tec/README.md index dc99db0dfb..df91b529ee 100644 --- a/contracts/tec/README.md +++ b/contracts/tec/README.md @@ -1,13 +1,13 @@ -## Trade Execution Coordinator (TEC) +## Trade Execution Coordinator (Coordinator) -This package contains a contract that allows users to call arbitrary functions on the Exchange contract with permission from one or more TECs (Trade Execution Coordinators). Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. +This package contains a contract that allows users to call arbitrary functions on the Exchange contract with permission from one or more Coordinators (Trade Execution Coordinators). Addresses of the deployed contracts can be found in the 0x [wiki](https://0xproject.com/wiki#Deployed-Addresses) or the [DEPLOYS](./DEPLOYS.json) file within this package. ## Installation **Install** ```bash -npm install @0x/contracts-tec --save +npm install @0x/contracts-coordinator --save ``` ## Bug bounty @@ -41,13 +41,13 @@ yarn install To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: ```bash -PKG=@0x/contracts-tec yarn build +PKG=@0x/contracts-coordinator yarn build ``` Or continuously rebuild on change: ```bash -PKG=@0x/contracts-tec yarn watch +PKG=@0x/contracts-coordinator yarn watch ``` ### Clean diff --git a/contracts/tec/compiler.json b/contracts/tec/compiler.json index 68d864c189..c3325ff17c 100644 --- a/contracts/tec/compiler.json +++ b/contracts/tec/compiler.json @@ -16,5 +16,5 @@ } } }, - "contracts": ["src/TEC.sol", "test/TestLibs.sol", "test/TestMixins.sol"] + "contracts": ["src/Coordinator.sol", "test/TestLibs.sol", "test/TestMixins.sol"] } diff --git a/contracts/tec/contracts/src/TEC.sol b/contracts/tec/contracts/src/Coordinator.sol similarity index 83% rename from contracts/tec/contracts/src/TEC.sol rename to contracts/tec/contracts/src/Coordinator.sol index 075ed5d690..6ad7fb73d7 100644 --- a/contracts/tec/contracts/src/TEC.sol +++ b/contracts/tec/contracts/src/Coordinator.sol @@ -21,16 +21,16 @@ pragma experimental "ABIEncoderV2"; import "./libs/LibConstants.sol"; import "./MixinSignatureValidator.sol"; -import "./MixinTECApprovalVerifier.sol"; -import "./MixinTECCore.sol"; +import "./MixinCoordinatorApprovalVerifier.sol"; +import "./MixinCoordinatorCore.sol"; // solhint-disable no-empty-blocks -contract TEC is +contract Coordinator is LibConstants, MixinSignatureValidator, - MixinTECApprovalVerifier, - MixinTECCore + MixinCoordinatorApprovalVerifier, + MixinCoordinatorCore { constructor (address _exchange) public diff --git a/contracts/tec/contracts/src/MixinTECApprovalVerifier.sol b/contracts/tec/contracts/src/MixinCoordinatorApprovalVerifier.sol similarity index 95% rename from contracts/tec/contracts/src/MixinTECApprovalVerifier.sol rename to contracts/tec/contracts/src/MixinCoordinatorApprovalVerifier.sol index 14efa753ff..162d74567f 100644 --- a/contracts/tec/contracts/src/MixinTECApprovalVerifier.sol +++ b/contracts/tec/contracts/src/MixinCoordinatorApprovalVerifier.sol @@ -23,19 +23,19 @@ import "@0x/contracts-exchange-libs/contracts/src/LibExchangeSelectors.sol"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "@0x/contracts-utils/contracts/src/LibBytes.sol"; import "@0x/contracts-utils/contracts/src/LibAddressArray.sol"; -import "./libs/LibTECApproval.sol"; +import "./libs/LibCoordinatorApproval.sol"; import "./libs/LibZeroExTransaction.sol"; import "./mixins/MSignatureValidator.sol"; -import "./mixins/MTECApprovalVerifier.sol"; +import "./mixins/MCoordinatorApprovalVerifier.sol"; // solhint-disable avoid-tx-origin -contract MixinTECApprovalVerifier is +contract MixinCoordinatorApprovalVerifier is LibExchangeSelectors, - LibTECApproval, + LibCoordinatorApproval, LibZeroExTransaction, MSignatureValidator, - MTECApprovalVerifier + MCoordinatorApprovalVerifier { using LibBytes for bytes; using LibAddressArray for address[]; @@ -46,7 +46,7 @@ contract MixinTECApprovalVerifier is /// @param transactionSignature Proof that the transaction has been signed by the signer. /// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires. /// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order in the transaction's Exchange calldata. - function assertValidTECApprovals( + function assertValidCoordinatorApprovals( LibZeroExTransaction.ZeroExTransaction memory transaction, bytes memory transactionSignature, uint256[] memory approvalExpirationTimeSeconds, @@ -97,7 +97,7 @@ contract MixinTECApprovalVerifier is for (uint256 i = 0; i < signaturesLength; i++) { // Create approval message uint256 currentApprovalExpirationTimeSeconds = approvalExpirationTimeSeconds[i]; - TECApproval memory approval = TECApproval({ + CoordinatorApproval memory approval = CoordinatorApproval({ transactionHash: transactionHash, transactionSignature: transactionSignature, approvalExpirationTimeSeconds: currentApprovalExpirationTimeSeconds @@ -111,7 +111,7 @@ contract MixinTECApprovalVerifier is ); // Hash approval message and recover signer address - bytes32 approvalHash = getTECApprovalHash(approval); + bytes32 approvalHash = getCoordinatorApprovalHash(approval); address approvalSignerAddress = getSignerAddress(approvalHash, approvalSignatures[i]); // Add approval signer to list of signers diff --git a/contracts/tec/contracts/src/MixinTECCore.sol b/contracts/tec/contracts/src/MixinCoordinatorCore.sol similarity index 90% rename from contracts/tec/contracts/src/MixinTECCore.sol rename to contracts/tec/contracts/src/MixinCoordinatorCore.sol index 3fd4d9f343..8de0879405 100644 --- a/contracts/tec/contracts/src/MixinTECCore.sol +++ b/contracts/tec/contracts/src/MixinCoordinatorCore.sol @@ -21,14 +21,14 @@ pragma experimental "ABIEncoderV2"; import "./libs/LibZeroExTransaction.sol"; import "./libs/LibConstants.sol"; -import "./mixins/MTECApprovalVerifier.sol"; -import "./interfaces/ITECCore.sol"; +import "./mixins/MCoordinatorApprovalVerifier.sol"; +import "./interfaces/ICoordinatorCore.sol"; -contract MixinTECCore is +contract MixinCoordinatorCore is LibConstants, - MTECApprovalVerifier, - ITECCore + MCoordinatorApprovalVerifier, + ICoordinatorCore { /// @dev Executes a 0x transaction that has been signed by the feeRecipients that correspond to each order in the transaction's Exchange calldata. /// @param transaction 0x transaction containing salt, signerAddress, and data. @@ -44,7 +44,7 @@ contract MixinTECCore is public { // Validate that the 0x transaction has been approves by each feeRecipient - assertValidTECApprovals( + assertValidCoordinatorApprovals( transaction, transactionSignature, approvalExpirationTimeSeconds, diff --git a/contracts/tec/contracts/src/interfaces/ITECApprovalVerifier.sol b/contracts/tec/contracts/src/interfaces/ICoordinatorApprovalVerifier.sol similarity index 96% rename from contracts/tec/contracts/src/interfaces/ITECApprovalVerifier.sol rename to contracts/tec/contracts/src/interfaces/ICoordinatorApprovalVerifier.sol index c1c8d9f8bc..aa8ec8bad5 100644 --- a/contracts/tec/contracts/src/interfaces/ITECApprovalVerifier.sol +++ b/contracts/tec/contracts/src/interfaces/ICoordinatorApprovalVerifier.sol @@ -23,7 +23,7 @@ import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; import "../libs/LibZeroExTransaction.sol"; -contract ITECApprovalVerifier { +contract ICoordinatorApprovalVerifier { /// @dev Validates that the 0x transaction has been approved by all of the feeRecipients /// that correspond to each order in the transaction's Exchange calldata. @@ -31,7 +31,7 @@ contract ITECApprovalVerifier { /// @param transactionSignature Proof that the transaction has been signed by the signer. /// @param approvalExpirationTimeSeconds Array of expiration times in seconds for which each corresponding approval signature expires. /// @param approvalSignatures Array of signatures that correspond to the feeRecipients of each order in the transaction's Exchange calldata. - function assertValidTECApprovals( + function assertValidCoordinatorApprovals( LibZeroExTransaction.ZeroExTransaction memory transaction, bytes memory transactionSignature, uint256[] memory approvalExpirationTimeSeconds, diff --git a/contracts/tec/contracts/src/interfaces/ITECCore.sol b/contracts/tec/contracts/src/interfaces/ICoordinatorCore.sol similarity index 98% rename from contracts/tec/contracts/src/interfaces/ITECCore.sol rename to contracts/tec/contracts/src/interfaces/ICoordinatorCore.sol index 90e48f1427..4da0fa7a4d 100644 --- a/contracts/tec/contracts/src/interfaces/ITECCore.sol +++ b/contracts/tec/contracts/src/interfaces/ICoordinatorCore.sol @@ -22,7 +22,7 @@ pragma experimental "ABIEncoderV2"; import "../libs/LibZeroExTransaction.sol"; -contract ITECCore { +contract ICoordinatorCore { /// @dev Executes a 0x transaction that has been signed by the feeRecipients that correspond to each order in the transaction's Exchange calldata. /// @param transaction 0x transaction containing salt, signerAddress, and data. diff --git a/contracts/tec/contracts/src/libs/LibTECApproval.sol b/contracts/tec/contracts/src/libs/LibCoordinatorApproval.sol similarity index 64% rename from contracts/tec/contracts/src/libs/LibTECApproval.sol rename to contracts/tec/contracts/src/libs/LibCoordinatorApproval.sol index cfb1ee0ece..11e15629a7 100644 --- a/contracts/tec/contracts/src/libs/LibTECApproval.sol +++ b/contracts/tec/contracts/src/libs/LibCoordinatorApproval.sol @@ -21,45 +21,45 @@ pragma solidity ^0.5.3; import "./LibEIP712Domain.sol"; -contract LibTECApproval is +contract LibCoordinatorApproval is LibEIP712Domain { - // Hash for the EIP712 TEC approval message - bytes32 constant internal EIP712_TEC_APPROVAL_SCHEMA_HASH = keccak256(abi.encodePacked( - "TECApproval(", + // Hash for the EIP712 Coordinator approval message + bytes32 constant internal EIP712_Coordinator_APPROVAL_SCHEMA_HASH = keccak256(abi.encodePacked( + "CoordinatorApproval(", "bytes32 transactionHash,", "bytes transactionSignature,", "uint256 approvalExpirationTimeSeconds", ")" )); - struct TECApproval { + struct CoordinatorApproval { bytes32 transactionHash; // EIP712 hash of the transaction, using the domain separator of this contract. bytes transactionSignature; // Signature of the 0x transaction. uint256 approvalExpirationTimeSeconds; // Timestamp in seconds for which the signature expires. } - /// @dev Calculated the EIP712 hash of the TEC approval mesasage using the domain separator of this contract. - /// @param approval TEC approval message containing the transaction hash, transaction signature, and expiration of the approval. - /// @return EIP712 hash of the TEC approval message with the domain separator of this contract. - function getTECApprovalHash(TECApproval memory approval) + /// @dev Calculated the EIP712 hash of the Coordinator approval mesasage using the domain separator of this contract. + /// @param approval Coordinator approval message containing the transaction hash, transaction signature, and expiration of the approval. + /// @return EIP712 hash of the Coordinator approval message with the domain separator of this contract. + function getCoordinatorApprovalHash(CoordinatorApproval memory approval) internal view returns (bytes32 approvalHash) { - approvalHash = hashEIP712Message(hashTECApproval(approval)); + approvalHash = hashEIP712Message(hashCoordinatorApproval(approval)); return approvalHash; } - /// @dev Calculated the EIP712 hash of the TEC approval mesasage with no domain separator. - /// @param approval TEC approval message containing the transaction hash, transaction signature, and expiration of the approval. - /// @return EIP712 hash of the TEC approval message with no domain separator. - function hashTECApproval(TECApproval memory approval) + /// @dev Calculated the EIP712 hash of the Coordinator approval mesasage with no domain separator. + /// @param approval Coordinator approval message containing the transaction hash, transaction signature, and expiration of the approval. + /// @return EIP712 hash of the Coordinator approval message with no domain separator. + function hashCoordinatorApproval(CoordinatorApproval memory approval) internal pure returns (bytes32 result) { - bytes32 schemaHash = EIP712_TEC_APPROVAL_SCHEMA_HASH; + bytes32 schemaHash = EIP712_Coordinator_APPROVAL_SCHEMA_HASH; bytes32 transactionSignatureHash = keccak256(approval.transactionSignature); // TODO(abandeali1): optimize by loading from memory in assembly bytes32 transactionHash = approval.transactionHash; @@ -67,7 +67,7 @@ contract LibTECApproval is // Assembly for more efficiently computing: // keccak256(abi.encodePacked( - // EIP712_TEC_APPROVAL_SCHEMA_HASH, + // EIP712_Coordinator_APPROVAL_SCHEMA_HASH, // approval.transactionHash, // keccak256(approval.transactionSignature) // approval.expiration, diff --git a/contracts/tec/contracts/src/mixins/MTECApprovalVerifier.sol b/contracts/tec/contracts/src/mixins/MCoordinatorApprovalVerifier.sol similarity index 88% rename from contracts/tec/contracts/src/mixins/MTECApprovalVerifier.sol rename to contracts/tec/contracts/src/mixins/MCoordinatorApprovalVerifier.sol index 6ecc2883b0..85063c8d9c 100644 --- a/contracts/tec/contracts/src/mixins/MTECApprovalVerifier.sol +++ b/contracts/tec/contracts/src/mixins/MCoordinatorApprovalVerifier.sol @@ -20,11 +20,11 @@ pragma solidity ^0.5.3; pragma experimental "ABIEncoderV2"; import "@0x/contracts-exchange-libs/contracts/src/LibOrder.sol"; -import "../interfaces/ITECApprovalVerifier.sol"; +import "../interfaces/ICoordinatorApprovalVerifier.sol"; -contract MTECApprovalVerifier is - ITECApprovalVerifier +contract MCoordinatorApprovalVerifier is + ICoordinatorApprovalVerifier { /// @dev Decodes the orders from Exchange calldata representing any fill method. /// @param data Exchange calldata representing a fill method. diff --git a/contracts/tec/contracts/test/TestLibs.sol b/contracts/tec/contracts/test/TestLibs.sol index faa24b0279..f789ccf3c3 100644 --- a/contracts/tec/contracts/test/TestLibs.sol +++ b/contracts/tec/contracts/test/TestLibs.sol @@ -19,23 +19,23 @@ pragma solidity ^0.5.3; pragma experimental "ABIEncoderV2"; -import "../src/libs/LibTECApproval.sol"; +import "../src/libs/LibCoordinatorApproval.sol"; import "../src/libs/LibZeroExTransaction.sol"; contract TestLibs is - LibTECApproval, + LibCoordinatorApproval, LibZeroExTransaction { - /// @dev Calculated the EIP712 hash of the TEC approval mesasage using the domain separator of this contract. - /// @param approval TEC approval message containing the transaction hash, transaction signature, and expiration of the approval. - /// @return EIP712 hash of the TEC approval message with the domain separator of this contract. - function publicGetTECApprovalHash(TECApproval memory approval) + /// @dev Calculated the EIP712 hash of the Coordinator approval mesasage using the domain separator of this contract. + /// @param approval Coordinator approval message containing the transaction hash, transaction signature, and expiration of the approval. + /// @return EIP712 hash of the Coordinator approval message with the domain separator of this contract. + function publicGetCoordinatorApprovalHash(CoordinatorApproval memory approval) public view returns (bytes32 approvalHash) { - approvalHash = getTECApprovalHash(approval); + approvalHash = getCoordinatorApprovalHash(approval); return approvalHash; } diff --git a/contracts/tec/contracts/test/TestMixins.sol b/contracts/tec/contracts/test/TestMixins.sol index 8fb4e31622..693b732f4e 100644 --- a/contracts/tec/contracts/test/TestMixins.sol +++ b/contracts/tec/contracts/test/TestMixins.sol @@ -20,11 +20,11 @@ pragma solidity 0.5.3; pragma experimental "ABIEncoderV2"; import "../src/MixinSignatureValidator.sol"; -import "../src/MixinTECApprovalVerifier.sol"; +import "../src/MixinCoordinatorApprovalVerifier.sol"; // solhint-disable no-empty-blocks contract TestMixins is MixinSignatureValidator, - MixinTECApprovalVerifier + MixinCoordinatorApprovalVerifier {} diff --git a/contracts/tec/package.json b/contracts/tec/package.json index aa866922e8..345189433c 100644 --- a/contracts/tec/package.json +++ b/contracts/tec/package.json @@ -33,7 +33,7 @@ "lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol" }, "config": { - "abis": "./generated-artifacts/@(IExchange|TEC|TestLibs|TestMixins).json", + "abis": "./generated-artifacts/@(Coordinator|TestLibs|TestMixins).json", "abis:comment": "This list is auto-generated by contracts-gen. Don't edit manually." }, "repository": { diff --git a/contracts/tec/src/artifacts.ts b/contracts/tec/src/artifacts.ts index d37eb0fff3..2e4450f27f 100644 --- a/contracts/tec/src/artifacts.ts +++ b/contracts/tec/src/artifacts.ts @@ -5,11 +5,11 @@ */ import { ContractArtifact } from 'ethereum-types'; -import * as TEC from '../generated-artifacts/TEC.json'; +import * as Coordinator from '../generated-artifacts/Coordinator.json'; import * as TestLibs from '../generated-artifacts/TestLibs.json'; import * as TestMixins from '../generated-artifacts/TestMixins.json'; export const artifacts = { - TEC: TEC as ContractArtifact, + Coordinator: Coordinator as ContractArtifact, TestLibs: TestLibs as ContractArtifact, TestMixins: TestMixins as ContractArtifact, }; diff --git a/contracts/tec/src/wrappers.ts b/contracts/tec/src/wrappers.ts index 69ad17bdfa..e6d6dc8753 100644 --- a/contracts/tec/src/wrappers.ts +++ b/contracts/tec/src/wrappers.ts @@ -3,6 +3,6 @@ * Warning: This file is auto-generated by contracts-gen. Don't edit manually. * ----------------------------------------------------------------------------- */ -export * from '../generated-wrappers/tec'; +export * from '../generated-wrappers/coordinator'; export * from '../generated-wrappers/test_libs'; export * from '../generated-wrappers/test_mixins'; diff --git a/contracts/tec/test/tec.ts b/contracts/tec/test/coordinator.ts similarity index 91% rename from contracts/tec/test/tec.ts rename to contracts/tec/test/coordinator.ts index 6b3fec9f96..386bef791f 100644 --- a/contracts/tec/test/tec.ts +++ b/contracts/tec/test/coordinator.ts @@ -24,14 +24,14 @@ import { BigNumber } from '@0x/utils'; import * as chai from 'chai'; import { LogWithDecodedArgs } from 'ethereum-types'; -import { ApprovalFactory, artifacts, constants, exchangeDataEncoder, TECContract } from '../src'; +import { ApprovalFactory, artifacts, constants, exchangeDataEncoder, CoordinatorContract } from '../src'; chaiSetup.configure(); const expect = chai.expect; const blockchainLifecycle = new BlockchainLifecycle(web3Wrapper); web3Wrapper.abiDecoder.addABI(exchangeArtifacts.Exchange.compilerOutput.abi); // tslint:disable:no-unnecessary-type-assertion -describe('TEC tests', () => { +describe('Coordinator tests', () => { let makerAddress: string; let owner: string; let takerAddress: string; @@ -41,7 +41,7 @@ describe('TEC tests', () => { let erc20TokenA: DummyERC20TokenContract; let erc20TokenB: DummyERC20TokenContract; let zrxToken: DummyERC20TokenContract; - let tecContract: TECContract; + let coordinatorContract: CoordinatorContract; let exchange: ExchangeContract; let erc20Wrapper: ERC20Wrapper; @@ -86,8 +86,8 @@ describe('TEC tests', () => { devConstants.AWAIT_TRANSACTION_MINED_MS, ); - tecContract = await TECContract.deployFrom0xArtifactAsync( - artifacts.TEC, + coordinatorContract = await CoordinatorContract.deployFrom0xArtifactAsync( + artifacts.Coordinator, provider, txDefaults, exchange.address, @@ -97,7 +97,7 @@ describe('TEC tests', () => { const defaultOrderParams = { ...devConstants.STATIC_ORDER_PARAMS, exchangeAddress: exchange.address, - senderAddress: tecContract.address, + senderAddress: coordinatorContract.address, makerAddress, feeRecipientAddress, makerAssetData: assetDataUtils.encodeERC20AssetData(erc20TokenA.address), @@ -109,7 +109,7 @@ describe('TEC tests', () => { orderFactory = new OrderFactory(makerPrivateKey, defaultOrderParams); makerTransactionFactory = new TransactionFactory(makerPrivateKey, exchange.address); takerTransactionFactory = new TransactionFactory(takerPrivateKey, exchange.address); - approvalFactory = new ApprovalFactory(feeRecipientPrivateKey, tecContract.address); + approvalFactory = new ApprovalFactory(feeRecipientPrivateKey, coordinatorContract.address); }); beforeEach(async () => { await blockchainLifecycle.startAsync(); @@ -128,7 +128,7 @@ describe('TEC tests', () => { const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory.newSignedApproval(transaction, approvalExpirationTimeSeconds); const transactionReceipt = await web3Wrapper.awaitTransactionSuccessAsync( - await tecContract.executeTransaction.sendTransactionAsync( + await coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -144,7 +144,7 @@ describe('TEC tests', () => { const fillLogArgs = (fillLogs[0] as LogWithDecodedArgs).args; expect(fillLogArgs.makerAddress).to.eq(makerAddress); expect(fillLogArgs.takerAddress).to.eq(takerAddress); - expect(fillLogArgs.senderAddress).to.eq(tecContract.address); + expect(fillLogArgs.senderAddress).to.eq(coordinatorContract.address); expect(fillLogArgs.feeRecipientAddress).to.eq(feeRecipientAddress); expect(fillLogArgs.makerAssetData).to.eq(orders[0].makerAssetData); expect(fillLogArgs.takerAssetData).to.eq(orders[0].takerAssetData); @@ -159,7 +159,7 @@ describe('TEC tests', () => { const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = takerTransactionFactory.newSignedTransaction(data); const transactionReceipt = await web3Wrapper.awaitTransactionSuccessAsync( - await tecContract.executeTransaction.sendTransactionAsync( + await coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [], @@ -175,7 +175,7 @@ describe('TEC tests', () => { const fillLogArgs = (fillLogs[0] as LogWithDecodedArgs).args; expect(fillLogArgs.makerAddress).to.eq(makerAddress); expect(fillLogArgs.takerAddress).to.eq(takerAddress); - expect(fillLogArgs.senderAddress).to.eq(tecContract.address); + expect(fillLogArgs.senderAddress).to.eq(coordinatorContract.address); expect(fillLogArgs.feeRecipientAddress).to.eq(feeRecipientAddress); expect(fillLogArgs.makerAssetData).to.eq(orders[0].makerAssetData); expect(fillLogArgs.takerAssetData).to.eq(orders[0].takerAssetData); @@ -190,7 +190,7 @@ describe('TEC tests', () => { const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = takerTransactionFactory.newSignedTransaction(data); await expectTransactionFailedAsync( - tecContract.executeTransaction.sendTransactionAsync(transaction, transaction.signature, [], [], { + coordinatorContract.executeTransaction.sendTransactionAsync(transaction, transaction.signature, [], [], { from: takerAddress, gas: devConstants.MAX_EXECUTE_TRANSACTION_GAS, }), @@ -206,7 +206,7 @@ describe('TEC tests', () => { const approval = approvalFactory.newSignedApproval(transaction, approvalExpirationTimeSeconds); const signature = `${approval.signature.slice(0, 4)}FFFFFFFF${approval.signature.slice(12)}`; await expectTransactionFailedAsync( - tecContract.executeTransaction.sendTransactionAsync( + coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -224,7 +224,7 @@ describe('TEC tests', () => { const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).minus(constants.TIME_BUFFER); const approval = approvalFactory.newSignedApproval(transaction, approvalExpirationTimeSeconds); await expectTransactionFailedAsync( - tecContract.executeTransaction.sendTransactionAsync( + coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -242,7 +242,7 @@ describe('TEC tests', () => { const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory.newSignedApproval(transaction, approvalExpirationTimeSeconds); await expectTransactionFailedAsync( - tecContract.executeTransaction.sendTransactionAsync( + coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -264,7 +264,7 @@ describe('TEC tests', () => { const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory.newSignedApproval(transaction, approvalExpirationTimeSeconds); const transactionReceipt = await web3Wrapper.awaitTransactionSuccessAsync( - await tecContract.executeTransaction.sendTransactionAsync( + await coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -281,7 +281,7 @@ describe('TEC tests', () => { const fillLogArgs = (fillLogs[index] as LogWithDecodedArgs).args; expect(fillLogArgs.makerAddress).to.eq(makerAddress); expect(fillLogArgs.takerAddress).to.eq(takerAddress); - expect(fillLogArgs.senderAddress).to.eq(tecContract.address); + expect(fillLogArgs.senderAddress).to.eq(coordinatorContract.address); expect(fillLogArgs.feeRecipientAddress).to.eq(feeRecipientAddress); expect(fillLogArgs.makerAssetData).to.eq(order.makerAssetData); expect(fillLogArgs.takerAssetData).to.eq(order.takerAssetData); @@ -297,7 +297,7 @@ describe('TEC tests', () => { const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); const transaction = takerTransactionFactory.newSignedTransaction(data); const transactionReceipt = await web3Wrapper.awaitTransactionSuccessAsync( - await tecContract.executeTransaction.sendTransactionAsync( + await coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [], @@ -314,7 +314,7 @@ describe('TEC tests', () => { const fillLogArgs = (fillLogs[index] as LogWithDecodedArgs).args; expect(fillLogArgs.makerAddress).to.eq(makerAddress); expect(fillLogArgs.takerAddress).to.eq(takerAddress); - expect(fillLogArgs.senderAddress).to.eq(tecContract.address); + expect(fillLogArgs.senderAddress).to.eq(coordinatorContract.address); expect(fillLogArgs.feeRecipientAddress).to.eq(feeRecipientAddress); expect(fillLogArgs.makerAssetData).to.eq(order.makerAssetData); expect(fillLogArgs.takerAssetData).to.eq(order.takerAssetData); @@ -334,7 +334,7 @@ describe('TEC tests', () => { const approval = approvalFactory.newSignedApproval(transaction, approvalExpirationTimeSeconds); const signature = `${approval.signature.slice(0, 4)}FFFFFFFF${approval.signature.slice(12)}`; await expectTransactionFailedAsync( - tecContract.executeTransaction.sendTransactionAsync( + coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -352,7 +352,7 @@ describe('TEC tests', () => { const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).minus(constants.TIME_BUFFER); const approval = approvalFactory.newSignedApproval(transaction, approvalExpirationTimeSeconds); await expectTransactionFailedAsync( - tecContract.executeTransaction.sendTransactionAsync( + coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -370,7 +370,7 @@ describe('TEC tests', () => { const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory.newSignedApproval(transaction, approvalExpirationTimeSeconds); await expectTransactionFailedAsync( - tecContract.executeTransaction.sendTransactionAsync( + coordinatorContract.executeTransaction.sendTransactionAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -388,7 +388,7 @@ describe('TEC tests', () => { const data = exchangeDataEncoder.encodeOrdersToExchangeData(constants.CANCEL_ORDERS, orders); const transaction = makerTransactionFactory.newSignedTransaction(data); const transactionReceipt = await web3Wrapper.awaitTransactionSuccessAsync( - await tecContract.executeTransaction.sendTransactionAsync(transaction, transaction.signature, [], [], { + await coordinatorContract.executeTransaction.sendTransactionAsync(transaction, transaction.signature, [], [], { from: makerAddress, }), ); @@ -398,7 +398,7 @@ describe('TEC tests', () => { expect(cancelLogs.length).to.eq(1); const cancelLogArgs = (cancelLogs[0] as LogWithDecodedArgs).args; expect(cancelLogArgs.makerAddress).to.eq(makerAddress); - expect(cancelLogArgs.senderAddress).to.eq(tecContract.address); + expect(cancelLogArgs.senderAddress).to.eq(coordinatorContract.address); expect(cancelLogArgs.feeRecipientAddress).to.eq(feeRecipientAddress); expect(cancelLogArgs.makerAssetData).to.eq(orders[0].makerAssetData); expect(cancelLogArgs.takerAssetData).to.eq(orders[0].takerAssetData); @@ -409,7 +409,7 @@ describe('TEC tests', () => { const data = exchangeDataEncoder.encodeOrdersToExchangeData(constants.BATCH_CANCEL_ORDERS, orders); const transaction = makerTransactionFactory.newSignedTransaction(data); const transactionReceipt = await web3Wrapper.awaitTransactionSuccessAsync( - await tecContract.executeTransaction.sendTransactionAsync(transaction, transaction.signature, [], [], { + await coordinatorContract.executeTransaction.sendTransactionAsync(transaction, transaction.signature, [], [], { from: makerAddress, }), ); @@ -420,7 +420,7 @@ describe('TEC tests', () => { orders.forEach((order, index) => { const cancelLogArgs = (cancelLogs[index] as LogWithDecodedArgs).args; expect(cancelLogArgs.makerAddress).to.eq(makerAddress); - expect(cancelLogArgs.senderAddress).to.eq(tecContract.address); + expect(cancelLogArgs.senderAddress).to.eq(coordinatorContract.address); expect(cancelLogArgs.feeRecipientAddress).to.eq(feeRecipientAddress); expect(cancelLogArgs.makerAssetData).to.eq(order.makerAssetData); expect(cancelLogArgs.takerAssetData).to.eq(order.takerAssetData); @@ -432,7 +432,7 @@ describe('TEC tests', () => { const data = exchangeDataEncoder.encodeOrdersToExchangeData(constants.CANCEL_ORDERS_UP_TO, orders); const transaction = makerTransactionFactory.newSignedTransaction(data); const transactionReceipt = await web3Wrapper.awaitTransactionSuccessAsync( - await tecContract.executeTransaction.sendTransactionAsync(transaction, transaction.signature, [], [], { + await coordinatorContract.executeTransaction.sendTransactionAsync(transaction, transaction.signature, [], [], { from: makerAddress, }), ); @@ -442,7 +442,7 @@ describe('TEC tests', () => { expect(cancelLogs.length).to.eq(1); const cancelLogArgs = (cancelLogs[0] as LogWithDecodedArgs).args; expect(cancelLogArgs.makerAddress).to.eq(makerAddress); - expect(cancelLogArgs.senderAddress).to.eq(tecContract.address); + expect(cancelLogArgs.senderAddress).to.eq(coordinatorContract.address); expect(cancelLogArgs.orderEpoch).to.bignumber.eq(new BigNumber(1)); }); }); diff --git a/contracts/tec/test/libs.ts b/contracts/tec/test/libs.ts index 3331603b95..9573ba15c2 100644 --- a/contracts/tec/test/libs.ts +++ b/contracts/tec/test/libs.ts @@ -58,7 +58,7 @@ describe('Libs tests', () => { approvalExpirationTimeSeconds, }; const expectedApprovalHash = hashUtils.getApprovalHashHex(signedTx, approvalExpirationTimeSeconds); - const approvalHash = await testLibs.publicGetTECApprovalHash.callAsync(approval); + const approvalHash = await testLibs.publicGetCoordinatorApprovalHash.callAsync(approval); expect(expectedApprovalHash).to.eq(approvalHash); }); }); diff --git a/contracts/tec/test/mixins.ts b/contracts/tec/test/mixins.ts index 5454716817..42592cc739 100644 --- a/contracts/tec/test/mixins.ts +++ b/contracts/tec/test/mixins.ts @@ -19,8 +19,8 @@ import { constants, exchangeDataEncoder, hashUtils, - TECSignatureType, - TECTransactionFactory, + CoordinatorSignatureType, + CoordinatorTransactionFactory, TestMixinsContract, } from '../src'; @@ -33,7 +33,7 @@ describe('Mixins tests', () => { let approvalSignerAddress1: string; let approvalSignerAddress2: string; let mixins: TestMixinsContract; - let transactionFactory: TECTransactionFactory; + let transactionFactory: CoordinatorTransactionFactory; let approvalFactory1: ApprovalFactory; let approvalFactory2: ApprovalFactory; let defaultOrder: SignedOrder; @@ -67,7 +67,7 @@ describe('Mixins tests', () => { devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(transactionSignerAddress)]; const approvalSignerPrivateKey1 = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(approvalSignerAddress1)]; const approvalSignerPrivateKey2 = devConstants.TESTRPC_PRIVATE_KEYS[accounts.indexOf(approvalSignerAddress2)]; - transactionFactory = new TECTransactionFactory(transactionSignerPrivateKey, mixins.address); + transactionFactory = new CoordinatorTransactionFactory(transactionSignerPrivateKey, mixins.address); approvalFactory1 = new ApprovalFactory(approvalSignerPrivateKey1, mixins.address); approvalFactory2 = new ApprovalFactory(approvalSignerPrivateKey2, mixins.address); }); @@ -81,22 +81,22 @@ describe('Mixins tests', () => { describe('getSignerAddress', () => { it('should return the correct address using the EthSign signature type', async () => { const data = devConstants.NULL_BYTES; - const transaction = transactionFactory.newSignedTECTransaction(data, TECSignatureType.EthSign); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data, CoordinatorSignatureType.EthSign); const transactionHash = hashUtils.getTransactionHashHex(transaction); const signerAddress = await mixins.getSignerAddress.callAsync(transactionHash, transaction.signature); expect(transaction.signerAddress).to.eq(signerAddress); }); it('should return the correct address using the EIP712 signature type', async () => { const data = devConstants.NULL_BYTES; - const transaction = transactionFactory.newSignedTECTransaction(data, TECSignatureType.EIP712); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data, CoordinatorSignatureType.EIP712); const transactionHash = hashUtils.getTransactionHashHex(transaction); const signerAddress = await mixins.getSignerAddress.callAsync(transactionHash, transaction.signature); expect(transaction.signerAddress).to.eq(signerAddress); }); it('should revert with with the Illegal signature type', async () => { const data = devConstants.NULL_BYTES; - const transaction = transactionFactory.newSignedTECTransaction(data); - const illegalSignatureByte = ethUtil.toBuffer(TECSignatureType.Illegal).toString('hex'); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); + const illegalSignatureByte = ethUtil.toBuffer(CoordinatorSignatureType.Illegal).toString('hex'); transaction.signature = `${transaction.signature.slice( 0, transaction.signature.length - 2, @@ -109,7 +109,7 @@ describe('Mixins tests', () => { }); it("should revert with with a signature type that doesn't exist", async () => { const data = devConstants.NULL_BYTES; - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const invalidSignatureByte = '03'; transaction.signature = `${transaction.signature.slice( 0, @@ -128,7 +128,7 @@ describe('Mixins tests', () => { it(`Should be successful: function=${fnName}, caller=tx_signer, senderAddress=[verifier], approval_sig=[approver1], expiration=[valid]`, async () => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -140,7 +140,7 @@ describe('Mixins tests', () => { [approval.signature], { from: transactionSignerAddress }, ); - await mixins.assertValidTECApprovals.callAsync( + await mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -155,7 +155,7 @@ describe('Mixins tests', () => { }; const orders = [order]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -167,7 +167,7 @@ describe('Mixins tests', () => { [approval.signature], { from: transactionSignerAddress }, ); - await mixins.assertValidTECApprovals.callAsync( + await mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -178,7 +178,7 @@ describe('Mixins tests', () => { it(`Should be successful: function=${fnName}, caller=approver1, senderAddress=[verifier], approval_sig=[], expiration=[]`, async () => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); await mixins.assertValidTransactionOrdersApproval.callAsync( transaction, orders, @@ -187,14 +187,14 @@ describe('Mixins tests', () => { [], { from: approvalSignerAddress1 }, ); - await mixins.assertValidTECApprovals.callAsync(transaction, transaction.signature, [], [], { + await mixins.assertValidCoordinatorApprovals.callAsync(transaction, transaction.signature, [], [], { from: approvalSignerAddress1, }); }); it(`Should be successful: function=${fnName}, caller=approver1, senderAddress=[verifier], approval_sig=[approver1], expiration=[invalid]`, async () => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -206,7 +206,7 @@ describe('Mixins tests', () => { [approval.signature], { from: approvalSignerAddress1 }, ); - await mixins.assertValidTECApprovals.callAsync( + await mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -217,7 +217,7 @@ describe('Mixins tests', () => { it(`Should be successful: function=${fnName}, caller=approver1, senderAddress=[verifier], approval_sig=[], expiration=[]`, async () => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); await mixins.assertValidTransactionOrdersApproval.callAsync( transaction, orders, @@ -226,14 +226,14 @@ describe('Mixins tests', () => { [], { from: approvalSignerAddress1 }, ); - await mixins.assertValidTECApprovals.callAsync(transaction, transaction.signature, [], [], { + await mixins.assertValidCoordinatorApprovals.callAsync(transaction, transaction.signature, [], [], { from: approvalSignerAddress1, }); }); it(`Should revert: function=${fnName}, caller=tx_signer, senderAddress=[verifier], approval_sig=[invalid], expiration=[valid]`, async () => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -250,7 +250,7 @@ describe('Mixins tests', () => { RevertReason.InvalidApprovalSignature, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -263,7 +263,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName}, caller=tx_signer, senderAddress=[verifier], approval_sig=[approver1], expiration=[invalid]`, async () => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).minus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -279,7 +279,7 @@ describe('Mixins tests', () => { RevertReason.ApprovalExpired, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -292,7 +292,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName}, caller=approver2, senderAddress=[verifier], approval_sig=[approver1], expiration=[valid]`, async () => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -308,7 +308,7 @@ describe('Mixins tests', () => { RevertReason.InvalidSender, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -329,7 +329,7 @@ describe('Mixins tests', () => { it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[verifier,verifier], feeRecipient=[approver1,approver1], approval_sig=[approver1], expiration=[valid]`, async () => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -341,7 +341,7 @@ describe('Mixins tests', () => { [approval.signature], { from: transactionSignerAddress }, ); - await mixins.assertValidTECApprovals.callAsync( + await mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -355,7 +355,7 @@ describe('Mixins tests', () => { senderAddress: devConstants.NULL_ADDRESS, })); const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -367,7 +367,7 @@ describe('Mixins tests', () => { [approval.signature], { from: transactionSignerAddress }, ); - await mixins.assertValidTECApprovals.callAsync( + await mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -381,7 +381,7 @@ describe('Mixins tests', () => { senderAddress: devConstants.NULL_ADDRESS, })); const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); await mixins.assertValidTransactionOrdersApproval.callAsync( transaction, orders, @@ -390,14 +390,14 @@ describe('Mixins tests', () => { [], { from: transactionSignerAddress }, ); - await mixins.assertValidTECApprovals.callAsync(transaction, transaction.signature, [], [], { + await mixins.assertValidCoordinatorApprovals.callAsync(transaction, transaction.signature, [], [], { from: transactionSignerAddress, }); }); it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[verifier,null], feeRecipient=[approver1,approver1], approval_sig=[approver1], expiration=[valid]`, async () => { const orders = [defaultOrder, { ...defaultOrder, senderAddress: devConstants.NULL_ADDRESS }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -409,7 +409,7 @@ describe('Mixins tests', () => { [approval.signature], { from: transactionSignerAddress }, ); - await mixins.assertValidTECApprovals.callAsync( + await mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -420,7 +420,7 @@ describe('Mixins tests', () => { it(`Should be successful: function=${fnName} caller=tx_signer, senderAddress=[verifier,verifier], feeRecipient=[approver1,approver2], approval_sig=[approver1,approver2], expiration=[valid,valid]`, async () => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval1 = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -433,7 +433,7 @@ describe('Mixins tests', () => { [approval1.signature, approval2.signature], { from: transactionSignerAddress }, ); - await mixins.assertValidTECApprovals.callAsync( + await mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds, approvalExpirationTimeSeconds], @@ -444,7 +444,7 @@ describe('Mixins tests', () => { it(`Should be successful: function=${fnName} caller=approver1, senderAddress=[verifier,verifier], feeRecipient=[approver1,approver1], approval_sig=[], expiration=[]`, async () => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); await mixins.assertValidTransactionOrdersApproval.callAsync( transaction, orders, @@ -453,14 +453,14 @@ describe('Mixins tests', () => { [], { from: approvalSignerAddress1 }, ); - await mixins.assertValidTECApprovals.callAsync(transaction, transaction.signature, [], [], { + await mixins.assertValidCoordinatorApprovals.callAsync(transaction, transaction.signature, [], [], { from: approvalSignerAddress1, }); }); it(`Should be successful: function=${fnName} caller=approver1, senderAddress=[verifier,verifier], feeRecipient=[approver1,approver2], approval_sig=[approver2], expiration=[valid]`, async () => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval2 = approvalFactory2.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -472,7 +472,7 @@ describe('Mixins tests', () => { [approval2.signature], { from: approvalSignerAddress1 }, ); - await mixins.assertValidTECApprovals.callAsync( + await mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -483,7 +483,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName} caller=tx_signer, senderAddress=[verifier,verifier], feeRecipient=[approver1, approver1], approval_sig=[], expiration=[]`, async () => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); expectContractCallFailedAsync( mixins.assertValidTransactionOrdersApproval.callAsync( transaction, @@ -496,7 +496,7 @@ describe('Mixins tests', () => { RevertReason.InvalidApprovalSignature, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync(transaction, transaction.signature, [], [], { + mixins.assertValidCoordinatorApprovals.callAsync(transaction, transaction.signature, [], [], { from: transactionSignerAddress, }), RevertReason.InvalidApprovalSignature, @@ -505,7 +505,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName} caller=tx_signer, senderAddress=[verifier,verifier], feeRecipient=[approver1, approver1], approval_sig=[invalid], expiration=[valid]`, async () => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -522,7 +522,7 @@ describe('Mixins tests', () => { RevertReason.InvalidApprovalSignature, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -535,7 +535,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName} caller=tx_signer, senderAddress=[verifier,verifier], feeRecipient=[approver1, approver2], approval_sig=[valid,invalid], expiration=[valid,valid]`, async () => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval1 = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -553,7 +553,7 @@ describe('Mixins tests', () => { RevertReason.InvalidApprovalSignature, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds, approvalExpirationTimeSeconds], @@ -566,7 +566,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName} caller=approver1, senderAddress=[verifier,verifier], feeRecipient=[approver1, approver2], approval_sig=[invalid], expiration=[valid]`, async () => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval2 = approvalFactory2.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -583,7 +583,7 @@ describe('Mixins tests', () => { RevertReason.InvalidApprovalSignature, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -596,7 +596,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName} caller=tx_signer, senderAddress=[verifier,verifier], feeRecipient=[approver1, approver2], approval_sig=[valid,valid], expiration=[valid,invalid]`, async () => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds1 = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approvalExpirationTimeSeconds2 = new BigNumber(currentTimestamp).minus(constants.TIME_BUFFER); @@ -614,7 +614,7 @@ describe('Mixins tests', () => { RevertReason.ApprovalExpired, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds1, approvalExpirationTimeSeconds2], @@ -627,7 +627,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName} caller=approver1, senderAddress=[verifier,verifier], feeRecipient=[approver1, approver2], approval_sig=[valid], expiration=[invalid]`, async () => { const orders = [defaultOrder, { ...defaultOrder, feeRecipientAddress: approvalSignerAddress2 }]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).minus(constants.TIME_BUFFER); const approval2 = approvalFactory2.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -643,7 +643,7 @@ describe('Mixins tests', () => { RevertReason.ApprovalExpired, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -656,7 +656,7 @@ describe('Mixins tests', () => { it(`Should revert: function=${fnName} caller=approver2, senderAddress=[verifier,verifier], feeRecipient=[approver1, approver1], approval_sig=[valid], expiration=[valid]`, async () => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(fnName, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); const currentTimestamp = await getLatestBlockTimestampAsync(); const approvalExpirationTimeSeconds = new BigNumber(currentTimestamp).plus(constants.TIME_BUFFER); const approval1 = approvalFactory1.newSignedApproval(transaction, approvalExpirationTimeSeconds); @@ -672,7 +672,7 @@ describe('Mixins tests', () => { RevertReason.InvalidSender, ); expectContractCallFailedAsync( - mixins.assertValidTECApprovals.callAsync( + mixins.assertValidCoordinatorApprovals.callAsync( transaction, transaction.signature, [approvalExpirationTimeSeconds], @@ -688,24 +688,24 @@ describe('Mixins tests', () => { it('should allow the tx signer to call `cancelOrders` without approval', async () => { const orders = [defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(constants.CANCEL_ORDERS, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); - await mixins.assertValidTECApprovals.callAsync(transaction, transaction.signature, [], [], { + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); + await mixins.assertValidCoordinatorApprovals.callAsync(transaction, transaction.signature, [], [], { from: transactionSignerAddress, }); }); it('should allow the tx signer to call `batchCancelOrders` without approval', async () => { const orders = [defaultOrder, defaultOrder]; const data = exchangeDataEncoder.encodeOrdersToExchangeData(constants.BATCH_CANCEL_ORDERS, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); - await mixins.assertValidTECApprovals.callAsync(transaction, transaction.signature, [], [], { + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); + await mixins.assertValidCoordinatorApprovals.callAsync(transaction, transaction.signature, [], [], { from: transactionSignerAddress, }); }); it('should allow the tx signer to call `cancelOrdersUpTo` without approval', async () => { const orders: SignedOrder[] = []; const data = exchangeDataEncoder.encodeOrdersToExchangeData(constants.CANCEL_ORDERS_UP_TO, orders); - const transaction = transactionFactory.newSignedTECTransaction(data); - await mixins.assertValidTECApprovals.callAsync(transaction, transaction.signature, [], [], { + const transaction = transactionFactory.newSignedCoordinatorTransaction(data); + await mixins.assertValidCoordinatorApprovals.callAsync(transaction, transaction.signature, [], [], { from: transactionSignerAddress, }); }); diff --git a/contracts/tec/test/utils/approval_factory.ts b/contracts/tec/test/utils/approval_factory.ts index 55e3468318..abb6e74b47 100644 --- a/contracts/tec/test/utils/approval_factory.ts +++ b/contracts/tec/test/utils/approval_factory.ts @@ -2,7 +2,7 @@ import { SignedZeroExTransaction } from '@0x/types'; import { BigNumber } from '@0x/utils'; import * as ethUtil from 'ethereumjs-util'; -import { hashUtils, SignedTECApproval, signingUtils, TECSignatureType } from './index'; +import { hashUtils, SignedCoordinatorApproval, signingUtils, CoordinatorSignatureType } from './index'; export class ApprovalFactory { private readonly _privateKey: Buffer; @@ -14,16 +14,16 @@ export class ApprovalFactory { public newSignedApproval( transaction: SignedZeroExTransaction, approvalExpirationTimeSeconds: BigNumber, - signatureType: TECSignatureType = TECSignatureType.EthSign, - ): SignedTECApproval { - const tecTransaction = { + signatureType: CoordinatorSignatureType = CoordinatorSignatureType.EthSign, + ): SignedCoordinatorApproval { + const coordinatorTransaction = { ...transaction, verifyingContractAddress: this._verifyingContractAddress, }; - const approvalHashBuff = hashUtils.getApprovalHashBuffer(tecTransaction, approvalExpirationTimeSeconds); + const approvalHashBuff = hashUtils.getApprovalHashBuffer(coordinatorTransaction, approvalExpirationTimeSeconds); const signatureBuff = signingUtils.signMessage(approvalHashBuff, this._privateKey, signatureType); const signedApproval = { - transaction: tecTransaction, + transaction: coordinatorTransaction, approvalExpirationTimeSeconds, signature: ethUtil.addHexPrefix(signatureBuff.toString('hex')), }; diff --git a/contracts/tec/test/utils/constants.ts b/contracts/tec/test/utils/constants.ts index 00973df5ac..ff348b3258 100644 --- a/contracts/tec/test/utils/constants.ts +++ b/contracts/tec/test/utils/constants.ts @@ -1,10 +1,10 @@ import { BigNumber } from '@0x/utils'; export const constants = { - TEC_DOMAIN_NAME: '0x Protocol Trade Execution Coordinator', - TEC_DOMAIN_VERSION: '1.0.0', - TEC_APPROVAL_SCHEMA: { - name: 'TECApproval', + Coordinator_DOMAIN_NAME: '0x Protocol Trade Execution Coordinator', + Coordinator_DOMAIN_VERSION: '1.0.0', + Coordinator_APPROVAL_SCHEMA: { + name: 'CoordinatorApproval', parameters: [ { name: 'transactionHash', type: 'bytes32' }, { name: 'transactionSignature', type: 'bytes' }, diff --git a/contracts/tec/test/utils/tec_transaction_factory.ts b/contracts/tec/test/utils/coordinator_transaction_factory.ts similarity index 83% rename from contracts/tec/test/utils/tec_transaction_factory.ts rename to contracts/tec/test/utils/coordinator_transaction_factory.ts index 8d2191717a..f2535c7191 100644 --- a/contracts/tec/test/utils/tec_transaction_factory.ts +++ b/contracts/tec/test/utils/coordinator_transaction_factory.ts @@ -2,9 +2,9 @@ import { generatePseudoRandomSalt } from '@0x/order-utils'; import { SignedZeroExTransaction } from '@0x/types'; import * as ethUtil from 'ethereumjs-util'; -import { hashUtils, signingUtils, TECSignatureType } from './index'; +import { hashUtils, signingUtils, CoordinatorSignatureType } from './index'; -export class TECTransactionFactory { +export class CoordinatorTransactionFactory { private readonly _signerBuff: Buffer; private readonly _verifyingContractAddress: string; private readonly _privateKey: Buffer; @@ -13,9 +13,9 @@ export class TECTransactionFactory { this._verifyingContractAddress = verifyingContractAddress; this._signerBuff = ethUtil.privateToAddress(this._privateKey); } - public newSignedTECTransaction( + public newSignedCoordinatorTransaction( data: string, - signatureType: TECSignatureType = TECSignatureType.EthSign, + signatureType: CoordinatorSignatureType = CoordinatorSignatureType.EthSign, ): SignedZeroExTransaction { const transaction = { verifyingContractAddress: this._verifyingContractAddress, diff --git a/contracts/tec/test/utils/hash_utils.ts b/contracts/tec/test/utils/hash_utils.ts index f7ea74eef1..b03c62c3bc 100644 --- a/contracts/tec/test/utils/hash_utils.ts +++ b/contracts/tec/test/utils/hash_utils.ts @@ -9,8 +9,8 @@ import { constants } from './index'; export const hashUtils = { getApprovalHashBuffer(transaction: SignedZeroExTransaction, approvalExpirationTimeSeconds: BigNumber): Buffer { const domain = { - name: constants.TEC_DOMAIN_NAME, - version: constants.TEC_DOMAIN_VERSION, + name: constants.Coordinator_DOMAIN_NAME, + version: constants.Coordinator_DOMAIN_VERSION, verifyingContractAddress: transaction.verifyingContractAddress, }; const transactionHash = hashUtils.getTransactionHashHex(transaction); @@ -20,9 +20,9 @@ export const hashUtils = { approvalExpirationTimeSeconds: approvalExpirationTimeSeconds.toString(), }; const typedData = eip712Utils.createTypedData( - constants.TEC_APPROVAL_SCHEMA.name, + constants.Coordinator_APPROVAL_SCHEMA.name, { - TECApproval: constants.TEC_APPROVAL_SCHEMA.parameters, + CoordinatorApproval: constants.Coordinator_APPROVAL_SCHEMA.parameters, }, approval, domain, @@ -38,8 +38,8 @@ export const hashUtils = { }, getTransactionHashBuffer(transaction: ZeroExTransaction | SignedZeroExTransaction): Buffer { const domain = { - name: constants.TEC_DOMAIN_NAME, - version: constants.TEC_DOMAIN_VERSION, + name: constants.Coordinator_DOMAIN_NAME, + version: constants.Coordinator_DOMAIN_VERSION, verifyingContractAddress: transaction.verifyingContractAddress, }; const normalizedTransaction = _.mapValues(transaction, value => { diff --git a/contracts/tec/test/utils/index.ts b/contracts/tec/test/utils/index.ts index ad03b8ee87..9ffc956f90 100644 --- a/contracts/tec/test/utils/index.ts +++ b/contracts/tec/test/utils/index.ts @@ -1,6 +1,6 @@ export { hashUtils } from './hash_utils'; export { signingUtils } from './signing_utils'; -export { TECTransactionFactory } from './tec_transaction_factory'; +export { CoordinatorTransactionFactory } from './coordinator_transaction_factory'; export { ApprovalFactory } from './approval_factory'; export { constants } from './constants'; export { exchangeDataEncoder } from './exchange_data_encoder'; diff --git a/contracts/tec/test/utils/signing_utils.ts b/contracts/tec/test/utils/signing_utils.ts index 12ed71175b..8515a0b385 100644 --- a/contracts/tec/test/utils/signing_utils.ts +++ b/contracts/tec/test/utils/signing_utils.ts @@ -1,10 +1,10 @@ import * as ethUtil from 'ethereumjs-util'; -import { TECSignatureType } from './types'; +import { CoordinatorSignatureType } from './types'; export const signingUtils = { - signMessage(message: Buffer, privateKey: Buffer, signatureType: TECSignatureType): Buffer { - if (signatureType === TECSignatureType.EthSign) { + signMessage(message: Buffer, privateKey: Buffer, signatureType: CoordinatorSignatureType): Buffer { + if (signatureType === CoordinatorSignatureType.EthSign) { const prefixedMessage = ethUtil.hashPersonalMessage(message); const ecSignature = ethUtil.ecsign(prefixedMessage, privateKey); const signature = Buffer.concat([ @@ -14,7 +14,7 @@ export const signingUtils = { ethUtil.toBuffer(signatureType), ]); return signature; - } else if (signatureType === TECSignatureType.EIP712) { + } else if (signatureType === CoordinatorSignatureType.EIP712) { const ecSignature = ethUtil.ecsign(message, privateKey); const signature = Buffer.concat([ ethUtil.toBuffer(ecSignature.v), diff --git a/contracts/tec/test/utils/types.ts b/contracts/tec/test/utils/types.ts index d88da93c1a..822d2795cc 100644 --- a/contracts/tec/test/utils/types.ts +++ b/contracts/tec/test/utils/types.ts @@ -1,16 +1,16 @@ import { SignedZeroExTransaction } from '@0x/types'; import { BigNumber } from '@0x/utils'; -export interface TECApproval { +export interface CoordinatorApproval { transaction: SignedZeroExTransaction; approvalExpirationTimeSeconds: BigNumber; } -export interface SignedTECApproval extends TECApproval { +export interface SignedCoordinatorApproval extends CoordinatorApproval { signature: string; } -export enum TECSignatureType { +export enum CoordinatorSignatureType { Illegal, EIP712, EthSign, diff --git a/contracts/tec/tsconfig.json b/contracts/tec/tsconfig.json index fc2b9eac21..adbd5d2853 100644 --- a/contracts/tec/tsconfig.json +++ b/contracts/tec/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "outDir": "lib", "rootDir": ".", "resolveJsonModule": true }, "include": ["./src/**/*", "./test/**/*", "./generated-wrappers/**/*"], "files": [ - "generated-artifacts/TEC.json", + "generated-artifacts/Coordinator.json", "generated-artifacts/TestLibs.json", "generated-artifacts/TestMixins.json" ],