Remove generate-exchange-selectors script

This commit is contained in:
Amir Bandeali 2019-08-13 16:51:52 -07:00
parent 070147db52
commit c5d4559300
3 changed files with 1 additions and 350 deletions

View File

@ -1,186 +0,0 @@
/*
Copyright 2018 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.9;
contract LibExchangeSelectors {
// solhint-disable max-line-length
// function allowedValidators(address,address)
bytes4 constant internal ALLOWED_VALIDATORS_SELECTOR = 0x7b8e3514;
// function assetProxies(bytes4)
bytes4 constant internal ASSET_PROXIES_SELECTOR = 0x3fd3c997;
// function batchCancelOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[])
bytes4 constant internal BATCH_CANCEL_ORDERS_SELECTOR = 0xdedfc1f1;
// function batchExecuteTransactions((uint256,uint256,address,bytes)[],bytes[])
bytes4 constant internal BATCH_EXECUTE_TRANSACTIONS_SELECTOR = 0x3f80f0ee;
// function batchFillOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])
bytes4 constant internal BATCH_FILL_ORDERS_SELECTOR = 0x9694a402;
// function batchFillOrdersNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])
bytes4 constant internal BATCH_FILL_ORDERS_NO_THROW_SELECTOR = 0x8ea8dfe4;
// function batchFillOrKillOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256[],bytes[])
bytes4 constant internal BATCH_FILL_OR_KILL_ORDERS_SELECTOR = 0xbeee2e14;
// function batchMatchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],bytes[])
bytes4 constant internal BATCH_MATCH_ORDERS_SELECTOR = 0x6fcf3e9e;
// function batchMatchOrdersWithMaximalFill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],bytes[],bytes[])
bytes4 constant internal BATCH_MATCH_ORDERS_WITH_MAXIMAL_FILL_SELECTOR = 0x6a1a80fd;
// function calculateMatchedFillResults((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,uint256,bool)
bytes4 constant internal CALCULATE_MATCHED_FILL_RESULTS_SELECTOR = 0x38f9eb3b;
// function cancelled(bytes32)
bytes4 constant internal CANCELLED_SELECTOR = 0x2ac12622;
// function cancelOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))
bytes4 constant internal CANCEL_ORDER_SELECTOR = 0x2da62987;
// function cancelOrdersUpTo(uint256)
bytes4 constant internal CANCEL_ORDERS_UP_TO_SELECTOR = 0x4f9559b1;
// function currentContextAddress()
bytes4 constant internal CURRENT_CONTEXT_ADDRESS_SELECTOR = 0xeea086ba;
// function doesSignatureRequireRegularValidation(bytes32,address,bytes)
bytes4 constant internal DOES_SIGNATURE_REQUIRE_REGULAR_VALIDATION_SELECTOR = 0xc17f8ccc;
// function EIP1271_MAGIC_VALUE()
bytes4 constant internal EIP_1271_MAGIC_VALUE_SELECTOR = 0xdd885e2d;
// function EIP712_EXCHANGE_DOMAIN_HASH()
bytes4 constant internal EIP_712_EXCHANGE_DOMAIN_HASH_SELECTOR = 0xc26cfecd;
// function EIP712_EXCHANGE_DOMAIN_NAME()
bytes4 constant internal EIP_712_EXCHANGE_DOMAIN_NAME_SELECTOR = 0x63c4e8cc;
// function EIP712_EXCHANGE_DOMAIN_VERSION()
bytes4 constant internal EIP_712_EXCHANGE_DOMAIN_VERSION_SELECTOR = 0x0f01323b;
// function EIP712_ORDER_SCHEMA_HASH()
bytes4 constant internal EIP_712_ORDER_SCHEMA_HASH_SELECTOR = 0xe4588b64;
// function EIP712_ZEROEX_TRANSACTION_SCHEMA_HASH()
bytes4 constant internal EIP_712_ZEROEX_TRANSACTION_SCHEMA_HASH_SELECTOR = 0xc148c58a;
// function executeTransaction((uint256,uint256,address,bytes),bytes)
bytes4 constant internal EXECUTE_TRANSACTION_SELECTOR = 0xcba0648a;
// function filled(bytes32)
bytes4 constant internal FILLED_SELECTOR = 0x288cdc91;
// function fillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)
bytes4 constant internal FILL_ORDER_SELECTOR = 0x9b44d556;
// function fillOrderNoThrow((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)
bytes4 constant internal FILL_ORDER_NO_THROW_SELECTOR = 0x01da61ae;
// function fillOrKillOrder((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),uint256,bytes)
bytes4 constant internal FILL_OR_KILL_ORDER_SELECTOR = 0xe14b58c4;
// function getAssetProxy(bytes4)
bytes4 constant internal GET_ASSET_PROXY_SELECTOR = 0x60704108;
// function getOrderHash((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))
bytes4 constant internal GET_ORDER_HASH_SELECTOR = 0xad3449bd;
// function getOrderInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes))
bytes4 constant internal GET_ORDER_INFO_SELECTOR = 0x9d3fa4b9;
// function getOrdersInfo((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[])
bytes4 constant internal GET_ORDERS_INFO_SELECTOR = 0x9dfac06d;
// function getTransactionHash((uint256,uint256,address,bytes))
bytes4 constant internal GET_TRANSACTION_HASH_SELECTOR = 0xe0456690;
// function isValidHashSignature(bytes32,address,bytes)
bytes4 constant internal IS_VALID_HASH_SIGNATURE_SELECTOR = 0x8171c407;
// function isValidOrderSignature((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),address,bytes)
bytes4 constant internal IS_VALID_ORDER_SIGNATURE_SELECTOR = 0xf813e384;
// function isValidTransactionSignature((uint256,uint256,address,bytes),address,bytes)
bytes4 constant internal IS_VALID_TRANSACTION_SIGNATURE_SELECTOR = 0xfaa8b882;
// function marketBuyOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])
bytes4 constant internal MARKET_BUY_ORDERS_SELECTOR = 0xdb702a9c;
// function marketSellOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes)[],uint256,bytes[])
bytes4 constant internal MARKET_SELL_ORDERS_SELECTOR = 0x52b3ca9e;
// function matchOrders((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)
bytes4 constant internal MATCH_ORDERS_SELECTOR = 0x88ec79fb;
// function matchOrdersWithMaximalFill((address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),(address,address,address,address,uint256,uint256,uint256,uint256,uint256,uint256,bytes,bytes,bytes,bytes),bytes,bytes)
bytes4 constant internal MATCH_ORDERS_WITH_MAXIMAL_FILL_SELECTOR = 0xb718e292;
// function orderEpoch(address,address)
bytes4 constant internal ORDER_EPOCH_SELECTOR = 0xd9bfa73e;
// function owner()
bytes4 constant internal OWNER_SELECTOR = 0x8da5cb5b;
// function preSign(bytes32)
bytes4 constant internal PRE_SIGN_SELECTOR = 0x46c02d7a;
// function preSigned(bytes32,address)
bytes4 constant internal PRE_SIGNED_SELECTOR = 0x82c174d0;
// function registerAssetProxy(address)
bytes4 constant internal REGISTER_ASSET_PROXY_SELECTOR = 0xc585bb93;
// function setSignatureValidatorApproval(address,bool)
bytes4 constant internal SET_SIGNATURE_VALIDATOR_APPROVAL_SELECTOR = 0x77fcce68;
// function simulateDispatchTransferFromCalls(bytes[],address[],address[],uint256[])
bytes4 constant internal SIMULATE_DISPATCH_TRANSFER_FROM_CALLS_SELECTOR = 0xb04fbddd;
// function transactionsExecuted(bytes32)
bytes4 constant internal TRANSACTIONS_EXECUTED_SELECTOR = 0x0228e168;
// function transferOwnership(address)
bytes4 constant internal TRANSFER_OWNERSHIP_SELECTOR = 0xf2fde38b;
// function VERSION()
bytes4 constant internal VERSION_SELECTOR = 0xffa1ad74;
// event AssetProxyRegistered(bytes4,address)
bytes32 constant internal EVENT_ASSET_PROXY_REGISTERED_SELECTOR = 0xd2c6b762299c609bdb96520b58a49bfb80186934d4f71a86a367571a15c03194;
// event Cancel(address,address,address,bytes32,bytes,bytes)
bytes32 constant internal EVENT_CANCEL_SELECTOR = 0xdc47b3613d9fe400085f6dbdc99453462279057e6207385042827ed6b1a62cf7;
// event CancelUpTo(address,address,uint256)
bytes32 constant internal EVENT_CANCEL_UP_TO_SELECTOR = 0x82af639571738f4ebd4268fb0363d8957ebe1bbb9e78dba5ebd69eed39b154f0;
// event Fill(address,address,bytes,bytes,bytes,bytes,uint256,uint256,uint256,uint256,address,address,bytes32)
bytes32 constant internal EVENT_FILL_SELECTOR = 0xa5a8f3e79ee70e3be6330220296f9075863b936f4098d942ab107367d193a197;
// event SignatureValidatorApproval(address,address,bool)
bytes32 constant internal EVENT_SIGNATURE_VALIDATOR_APPROVAL_SELECTOR = 0xa8656e308026eeabce8f0bc18048433252318ab80ac79da0b3d3d8697dfba891;
// event TransactionExecution(bytes32)
bytes32 constant internal EVENT_TRANSACTION_EXECUTION_SELECTOR = 0xa4a7329f1dd821363067e07d359e347b4af9b1efe4b6cccf13240228af3c800d;
}

View File

@ -31,8 +31,7 @@
"coverage:report:lcov": "istanbul report lcov",
"test:circleci": "yarn test",
"contracts:gen": "contracts-gen",
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol",
"generate-exchange-selectors": "node lib/scripts/generate-exchange-selectors.js ../../../exchange/generated-artifacts/Exchange.json ./contracts/src/LibExchangeSelectors.sol"
"lint-contracts": "solhint -c ../.solhint.json contracts/**/**/**/**/*.sol"
},
"config": {
"abis": "./generated-artifacts/@(LibEIP712ExchangeDomain|LibExchangeRichErrors|LibExchangeSelectors|LibFillResults|LibMath|LibMathRichErrors|LibOrder|LibZeroExTransaction|TestLibEIP712ExchangeDomain|TestLibFillResults|TestLibMath|TestLibOrder|TestLibZeroExTransaction).json",

View File

@ -1,162 +0,0 @@
import { AbiDefinition, ContractAbi, DataItem, EventAbi, MethodAbi } from 'ethereum-types';
import * as ethUtil from 'ethereumjs-util';
import * as fs from 'fs';
import * as _ from 'lodash';
import * as path from 'path';
import * as process from 'process';
const keccak256 = ethUtil.sha3;
const ARGS = process.argv.slice(2);
const INDENT = ' ';
const LINEBREAK = '\n';
const VISIBILITY = 'internal';
interface ParsedContract {
methods: {
[functionName: string]: Array<{
selector: string;
signature: string;
}>;
};
events: {
[eventName: string]: {
selector: string;
signature: string;
};
};
}
// tslint:disable: no-console
(() => {
const [exchangeArtifactsFile, outputFile] = ARGS;
const exchangeArtifacts = require(exchangeArtifactsFile);
const contractName = path.basename(outputFile, '.sol');
const parsedContract = parseContract(exchangeArtifacts.compilerOutput.abi);
const contractDefinition = defineContract(contractName, parsedContract);
const preamble = extractOutputFilePreamble(outputFile);
const outputFileContents = `${preamble}${contractDefinition}${LINEBREAK}`;
fs.writeFileSync(outputFile, outputFileContents);
console.log(`Wrote exchange selectors to "${path.resolve(outputFile)}."`);
})();
function parseContract(abi: ContractAbi): ParsedContract {
const parsedContract: ParsedContract = {
methods: {},
events: {},
};
for (const abiItem of abi) {
if (isMethodAbi(abiItem)) {
const name = abiItem.name;
const signature = `${name}(${encodeMethodInputs(abiItem.inputs)})`;
const selector = `0x${keccak256(signature)
.slice(0, 4)
.toString('hex')}`;
if (parsedContract.methods[name] === undefined) {
parsedContract.methods[name] = [];
}
parsedContract.methods[name].push({
selector,
signature,
});
} else if (isEventAbi(abiItem)) {
const name = abiItem.name;
const signature = `${name}(${encodeMethodInputs(abiItem.inputs)})`;
const selector = `0x${keccak256(signature).toString('hex')}`;
parsedContract.events[name] = {
selector,
signature,
};
}
}
return parsedContract;
}
function isMethodAbi(abiItem: AbiDefinition): abiItem is MethodAbi {
return abiItem.type === 'function';
}
function isEventAbi(abiItem: AbiDefinition): abiItem is EventAbi {
return abiItem.type === 'event';
}
function defineContract(contractName: string, parsedContract: ParsedContract): string {
const constantDefinitions = [];
// Define function selectors.
const sortedMethodNames = _.sortBy(_.keys(parsedContract.methods), name => name.toLowerCase());
for (const name of sortedMethodNames) {
const methods = parsedContract.methods[name];
for (let idx = 0; idx < methods.length; idx++) {
const constantLines = generateFunctionSelectorConstantDefinition(
name,
methods[idx].signature,
methods[idx].selector,
idx,
methods.length,
);
constantDefinitions.push(constantLines);
}
}
// Define event selectors.
const sortedEventNames = _.sortBy(_.keys(parsedContract.events), name => name.toLowerCase());
for (const name of sortedEventNames) {
const event = parsedContract.events[name];
const constantLines = generateEventSelectorConstantDefinition(name, event.signature, event.selector);
constantDefinitions.push(constantLines);
}
return [
`contract ${contractName} {`,
`${INDENT}// solhint-disable max-line-length`,
'',
constantDefinitions
.map(lines => lines.map(line => `${INDENT}${line}`))
.map(lines => lines.join(LINEBREAK))
.join(`${LINEBREAK}${LINEBREAK}`),
`}`,
].join(LINEBREAK);
}
function extractOutputFilePreamble(outputFile: string): string {
const preambleLines = [];
const outputFileLines = fs.readFileSync(outputFile, 'utf-8').split(/\r?\n/);
for (const line of outputFileLines) {
if (/^\s*contract\s+[a-zA-Z][a-zA-Z0-9_]+/.test(line)) {
preambleLines.push('');
break;
}
preambleLines.push(line);
}
return preambleLines.join(LINEBREAK);
}
function generateFunctionSelectorConstantDefinition(
name: string,
signature: string,
selector: string,
idx: number,
total: number,
): string[] {
const varName = _.snakeCase(total === 1 ? name : `${name}_${idx + 1}`).toUpperCase();
return [`// function ${signature}`, `bytes4 constant ${VISIBILITY} ${varName}_SELECTOR = ${selector};`];
}
function generateEventSelectorConstantDefinition(name: string, signature: string, selector: string): string[] {
const varName = _.snakeCase(name).toUpperCase();
return [`// event ${signature}`, `bytes32 constant ${VISIBILITY} EVENT_${varName}_SELECTOR = ${selector};`];
}
function encodeMethodInputs(inputs?: DataItem[]): string {
if (inputs === undefined) {
throw new Error('encodeMethodInputs: inputs are undefined');
}
const types = [];
for (const input of inputs) {
if (input.type === 'tuple') {
types.push(`(${encodeMethodInputs(input.components)})`);
} else if (input.type === 'tuple[]') {
types.push(`(${encodeMethodInputs(input.components)})[]`);
} else {
types.push(input.type);
}
}
return types.join(',');
}