From b06b37ada10904fe725db14275a6d7a8fc4975e6 Mon Sep 17 00:00:00 2001 From: Alex Kroeger Date: Tue, 14 Jul 2020 14:12:57 -0400 Subject: [PATCH 01/19] Added a unique identifier to the quote within the timestamp metadata field --- src/utils/number_utils.ts | 19 +++++++++++++++++++ src/utils/service_utils.ts | 19 +++++++++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 src/utils/number_utils.ts diff --git a/src/utils/number_utils.ts b/src/utils/number_utils.ts new file mode 100644 index 000000000..1f17311ff --- /dev/null +++ b/src/utils/number_utils.ts @@ -0,0 +1,19 @@ +export const numberUtils = { + // from MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random + randomNumberInclusive: (minimumSpecified: number, maximumSpecified: number): number => { + const min = Math.ceil(minimumSpecified); + const max = Math.floor(maximumSpecified); + return Math.floor(Math.random() * (max - min + 1)) + min; // The maximum is inclusive and the minimum is inclusive + }, + // creates a random hex number of desired length by stringing together + // random integers from 1-15, guaranteeing the + // result is a hex number of the given length + randomHexNumberOfLength: (numberLength: number): string => { + let res = ''; + for (let i = 0; i < numberLength; i++) { + // tslint:disable-next-line:custom-no-magic-numbers + res = `${res}${numberUtils.randomNumberInclusive(1, 15).toString(16)}`; + } + return res; + }, +}; diff --git a/src/utils/service_utils.ts b/src/utils/service_utils.ts index db4fac0ab..dbcb36515 100644 --- a/src/utils/service_utils.ts +++ b/src/utils/service_utils.ts @@ -29,6 +29,8 @@ import { GasTokenRefundInfo, GetSwapQuoteResponseLiquiditySource } from '../type import { orderUtils } from '../utils/order_utils'; import { findTokenDecimalsIfExists } from '../utils/token_metadata_utils'; +import { numberUtils } from './number_utils'; + export const serviceUtils = { attributeSwapQuoteOrders( swapQuote: MarketSellSwapQuote | MarketBuySwapQuote, @@ -69,8 +71,21 @@ export const serviceUtils = { stateMutability: 'view', type: 'function', }); - const timestamp = new BigNumber(Date.now() / ONE_SECOND_MS).integerValue(); - const encodedAffiliateData = affiliateCallDataEncoder.encode([affiliateAddressOrDefault, timestamp]); + + // Generate unique identiifer + const HEX_DIGITS = 16; + const timestampInSeconds = new BigNumber(Date.now() / ONE_SECOND_MS).integerValue(); + const hexTimestamp = timestampInSeconds.toString(HEX_DIGITS); + const randomNumber = numberUtils.randomHexNumberOfLength(10); + + // Concatenate the hex identifier with the hex timestamp + // In the final encoded call data, this will leave us with a 5-byte ID followed by + // a 4-byte timestamp, and won't break parsers of the timestamp made prior to the + // addition of the ID + const uniqueIdentifier = new BigNumber(`${randomNumber}${hexTimestamp}`, HEX_DIGITS); + + // Encode additional call data and return + const encodedAffiliateData = affiliateCallDataEncoder.encode([affiliateAddressOrDefault, uniqueIdentifier]); const affiliatedData = `${data}${encodedAffiliateData.slice(2)}`; return affiliatedData; }, From ddd8e9a22d371b02f28d323165e24c244cfd74e1 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 27 Jul 2020 13:38:19 -0700 Subject: [PATCH 02/19] upgrade yarn version --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f83bf7723..d573ddb8d 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ }, "dependencies": { "@0x/assert": "^3.0.4", - "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-ae2a6fb68", + "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.7.0-aae1a6179", "@0x/connect": "^6.0.4", "@0x/contract-addresses": "^4.11.0", "@0x/contract-wrappers": "^13.7.0", diff --git a/yarn.lock b/yarn.lock index 1a6b4db36..95c9a370f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -32,9 +32,9 @@ lodash "^4.17.11" valid-url "^1.0.9" -"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-ae2a6fb68": - version "4.6.0" - resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/209c8324412173f5aa1c4b65fbe5494ea648205e" +"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.7.0-aae1a6179": + version "4.7.0" + resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/1a71959e0b167a198fc17ca4dca2e3dc9379a20a" dependencies: "@0x/assert" "^3.0.9" "@0x/contract-addresses" "^4.11.0" From 8150715c2438fb3e28d803bbad770d29a226d4af Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 27 Jul 2020 13:38:57 -0700 Subject: [PATCH 03/19] return and log quote report --- src/handlers/swap_handlers.ts | 5 ++++- src/services/swap_service.ts | 3 ++- src/types.ts | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index 72498ef24..b8b2af0f2 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -2,6 +2,7 @@ import { SwapQuoterError } from '@0x/asset-swapper'; import { BigNumber, NULL_ADDRESS } from '@0x/utils'; import * as express from 'express'; import * as HttpStatus from 'http-status-codes'; +import _ = require('lodash'); import { CHAIN_ID } from '../config'; import { @@ -59,10 +60,12 @@ export class SwapHandlers { buyAmount: params.buyAmount, sellAmount: params.sellAmount, makers: quote.orders.map(order => order.makerAddress), + quoteReport: quote.quoteReport, }, }); } - res.status(HttpStatus.OK).send(quote); + const cleanedQuote = _.omit(quote, 'quoteReport'); + res.status(HttpStatus.OK).send(cleanedQuote); } // tslint:disable-next-line:prefer-function-over-method public async getSwapTokensAsync(_req: express.Request, res: express.Response): Promise { diff --git a/src/services/swap_service.ts b/src/services/swap_service.ts index 2b65fbafe..af9678320 100644 --- a/src/services/swap_service.ts +++ b/src/services/swap_service.ts @@ -118,7 +118,7 @@ export class SwapService { protocolFeeInWeiAmount: bestCaseProtocolFee, } = attributedSwapQuote.bestCaseQuoteInfo; const { protocolFeeInWeiAmount: protocolFee, gas: worstCaseGas } = attributedSwapQuote.worstCaseQuoteInfo; - const { orders, gasPrice, sourceBreakdown } = attributedSwapQuote; + const { orders, gasPrice, sourceBreakdown, quoteReport } = attributedSwapQuote; const { to, value, data } = await this._getSwapQuotePartialTransactionAsync( swapQuote, @@ -208,6 +208,7 @@ export class SwapService { sources: serviceUtils.convertSourceBreakdownToArray(sourceBreakdown), orders: serviceUtils.cleanSignedOrderFields(orders), allowanceTarget, + quoteReport, }; return apiSwapQuote; } diff --git a/src/types.ts b/src/types.ts index cd99fcadc..5343fdb45 100644 --- a/src/types.ts +++ b/src/types.ts @@ -2,6 +2,7 @@ import { ERC20BridgeSource, MarketBuySwapQuote, MarketSellSwapQuote, + QuoteReport, RfqtRequestOpts, SupportedProvider, } from '@0x/asset-swapper'; @@ -411,6 +412,7 @@ export interface GetSwapQuoteResponse extends SwapQuoteResponsePartialTransactio estimatedGas: BigNumber; estimatedGasTokenRefund: BigNumber; allowanceTarget?: string; + quoteReport?: QuoteReport; } export interface Price { From ea8c690b73e1af266629a58869380ff466bf265c Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 27 Jul 2020 16:44:29 -0700 Subject: [PATCH 04/19] Revert "upgrade yarn version" This reverts commit ddd8e9a22d371b02f28d323165e24c244cfd74e1. --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d573ddb8d..f83bf7723 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ }, "dependencies": { "@0x/assert": "^3.0.4", - "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.7.0-aae1a6179", + "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-ae2a6fb68", "@0x/connect": "^6.0.4", "@0x/contract-addresses": "^4.11.0", "@0x/contract-wrappers": "^13.7.0", diff --git a/yarn.lock b/yarn.lock index 95c9a370f..1a6b4db36 100644 --- a/yarn.lock +++ b/yarn.lock @@ -32,9 +32,9 @@ lodash "^4.17.11" valid-url "^1.0.9" -"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.7.0-aae1a6179": - version "4.7.0" - resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/1a71959e0b167a198fc17ca4dca2e3dc9379a20a" +"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-ae2a6fb68": + version "4.6.0" + resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/209c8324412173f5aa1c4b65fbe5494ea648205e" dependencies: "@0x/assert" "^3.0.9" "@0x/contract-addresses" "^4.11.0" From 7a926579f3e9decb4ac90e92c22f7c3cead817bb Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 27 Jul 2020 17:46:31 -0700 Subject: [PATCH 05/19] experiment: chunk responses --- src/handlers/swap_handlers.ts | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index 22c78624c..fa9051f22 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -1,4 +1,4 @@ -import { RfqtRequestOpts, SwapQuoterError } from '@0x/asset-swapper'; +import { QuoteReport, RfqtRequestOpts, SwapQuoterError } from '@0x/asset-swapper'; import { BigNumber, NULL_ADDRESS } from '@0x/utils'; import * as express from 'express'; import * as HttpStatus from 'http-status-codes'; @@ -60,9 +60,11 @@ export class SwapHandlers { buyAmount: params.buyAmount, sellAmount: params.sellAmount, makers: quote.orders.map(order => order.makerAddress), - quoteReport: quote.quoteReport, }, }); + if (quote.quoteReport) { + logQuoteReport(quote.quoteReport); + } } const cleanedQuote = _.omit(quote, 'quoteReport'); res.status(HttpStatus.OK).send(cleanedQuote); @@ -276,6 +278,27 @@ export class SwapHandlers { } } +const logQuoteReport = (qr: QuoteReport) => { + const sourcesConsideredChunks = _.chunk(qr.sourcesConsidered, 12); + const sourcesDeliveredChunks = _.chunk(qr.sourcesDelivered, 12); + sourcesConsideredChunks.forEach((chunk, i) => { + logger.info({ + firmQuoteReport: 'true', + sourcesConsideredChunkIndex: i, + sourcesConsideredChunkLength: sourcesConsideredChunks.length, + sourcesConsidered: chunk, + }); + }); + sourcesDeliveredChunks.forEach((chunk, i) => { + logger.info({ + firmQuoteReport: 'true', + sourcesDeliveredChunkIndex: i, + sourcesDeliveredChunkLength: sourcesDeliveredChunks.length, + sourcesDelivered: chunk, + }); + }); +}; + const parseGetSwapQuoteRequestParams = ( req: express.Request, endpoint: 'price' | 'quote', From ec4b9d8a8549326eacb451e1f287d0c87541f6b3 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 27 Jul 2020 17:50:52 -0700 Subject: [PATCH 06/19] linting --- src/handlers/swap_handlers.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index fa9051f22..7fd077adb 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -279,7 +279,9 @@ export class SwapHandlers { } const logQuoteReport = (qr: QuoteReport) => { + // tslint:disable-next-line:custom-no-magic-numbers const sourcesConsideredChunks = _.chunk(qr.sourcesConsidered, 12); + // tslint:disable-next-line:custom-no-magic-numbers const sourcesDeliveredChunks = _.chunk(qr.sourcesDelivered, 12); sourcesConsideredChunks.forEach((chunk, i) => { logger.info({ From 653b7f3e414729882654c7076ad7072babc4c23c Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 27 Jul 2020 17:51:50 -0700 Subject: [PATCH 07/19] boolean --- src/handlers/swap_handlers.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index 7fd077adb..cad5f83c1 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -285,7 +285,7 @@ const logQuoteReport = (qr: QuoteReport) => { const sourcesDeliveredChunks = _.chunk(qr.sourcesDelivered, 12); sourcesConsideredChunks.forEach((chunk, i) => { logger.info({ - firmQuoteReport: 'true', + firmQuoteReport: true, sourcesConsideredChunkIndex: i, sourcesConsideredChunkLength: sourcesConsideredChunks.length, sourcesConsidered: chunk, @@ -293,7 +293,7 @@ const logQuoteReport = (qr: QuoteReport) => { }); sourcesDeliveredChunks.forEach((chunk, i) => { logger.info({ - firmQuoteReport: 'true', + firmQuoteReport: true, sourcesDeliveredChunkIndex: i, sourcesDeliveredChunkLength: sourcesDeliveredChunks.length, sourcesDelivered: chunk, From 4ab3e5ab8a89319a6004a8dbddd1b05e0f37ce2c Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 28 Jul 2020 13:46:31 -0700 Subject: [PATCH 08/19] update to fixed asset-swapper --- package.json | 2 +- yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f83bf7723..b8d9e53c1 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ }, "dependencies": { "@0x/assert": "^3.0.4", - "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-ae2a6fb68", + "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-766888ec4", "@0x/connect": "^6.0.4", "@0x/contract-addresses": "^4.11.0", "@0x/contract-wrappers": "^13.7.0", diff --git a/yarn.lock b/yarn.lock index 1a6b4db36..fe4817ad4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -32,9 +32,9 @@ lodash "^4.17.11" valid-url "^1.0.9" -"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-ae2a6fb68": +"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-766888ec4": version "4.6.0" - resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/209c8324412173f5aa1c4b65fbe5494ea648205e" + resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/c89fa41b593c3c28f024a588865ec9ffb25068ca" dependencies: "@0x/assert" "^3.0.9" "@0x/contract-addresses" "^4.11.0" From d29520cffa32ca1e29db9c4fd00ea709b9ad8b02 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 28 Jul 2020 14:35:46 -0700 Subject: [PATCH 09/19] update to neweset master --- package.json | 2 +- yarn.lock | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index b8d9e53c1..3ed659f92 100644 --- a/package.json +++ b/package.json @@ -128,7 +128,7 @@ }, "dependencies": { "@0x/assert": "^3.0.4", - "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-766888ec4", + "@0x/asset-swapper": "0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-498a50b22", "@0x/connect": "^6.0.4", "@0x/contract-addresses": "^4.11.0", "@0x/contract-wrappers": "^13.7.0", diff --git a/yarn.lock b/yarn.lock index fe4817ad4..1d18fa411 100644 --- a/yarn.lock +++ b/yarn.lock @@ -32,9 +32,9 @@ lodash "^4.17.11" valid-url "^1.0.9" -"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-766888ec4": +"@0x/asset-swapper@0xProject/gitpkg-registry#0x-asset-swapper-v4.6.0-498a50b22": version "4.6.0" - resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/c89fa41b593c3c28f024a588865ec9ffb25068ca" + resolved "https://codeload.github.com/0xProject/gitpkg-registry/tar.gz/739bc287b0fc24d67d54d29346b46eb608c3054f" dependencies: "@0x/assert" "^3.0.9" "@0x/contract-addresses" "^4.11.0" From a3cad308ba67a0c16c7ad421897452a4298e844b Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 28 Jul 2020 14:38:22 -0700 Subject: [PATCH 10/19] use constant for chunks --- src/constants.ts | 3 +++ src/handlers/swap_handlers.ts | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index efc98f7db..b970f03b9 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -93,3 +93,6 @@ export const GST2_WALLET_ADDRESSES = { export const MARKET_DEPTH_MAX_SAMPLES = 50; export const MARKET_DEPTH_DEFAULT_DISTRIBUTION = 1.05; export const MARKET_DEPTH_END_PRICE_SLIPPAGE_PERC = 20; + +// Logging +export const NUMBER_SOURCES_PER_LOG_LINE = 12; diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index cad5f83c1..339d2d017 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -9,6 +9,7 @@ import { DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE, MARKET_DEPTH_DEFAULT_DISTRIBUTION, MARKET_DEPTH_MAX_SAMPLES, + NUMBER_SOURCES_PER_LOG_LINE, SWAP_DOCS_URL, } from '../constants'; import { @@ -279,10 +280,7 @@ export class SwapHandlers { } const logQuoteReport = (qr: QuoteReport) => { - // tslint:disable-next-line:custom-no-magic-numbers - const sourcesConsideredChunks = _.chunk(qr.sourcesConsidered, 12); - // tslint:disable-next-line:custom-no-magic-numbers - const sourcesDeliveredChunks = _.chunk(qr.sourcesDelivered, 12); + const sourcesConsideredChunks = _.chunk(qr.sourcesConsidered, NUMBER_SOURCES_PER_LOG_LINE); sourcesConsideredChunks.forEach((chunk, i) => { logger.info({ firmQuoteReport: true, @@ -291,6 +289,8 @@ const logQuoteReport = (qr: QuoteReport) => { sourcesConsidered: chunk, }); }); + + const sourcesDeliveredChunks = _.chunk(qr.sourcesDelivered, NUMBER_SOURCES_PER_LOG_LINE); sourcesDeliveredChunks.forEach((chunk, i) => { logger.info({ firmQuoteReport: true, From 28f900be9b9e1eba2c44a7f57a23dfd8c66ff97e Mon Sep 17 00:00:00 2001 From: Alex Kroeger Date: Thu, 30 Jul 2020 17:08:24 -0400 Subject: [PATCH 11/19] Added unit test for affiliate data generation, other nits --- src/constants.ts | 1 + src/utils/service_utils.ts | 6 +++--- test/constants.ts | 1 + test/service_utils_test.ts | 24 +++++++++++++++++++++++- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/constants.ts b/src/constants.ts index ec77a4dee..eb514e149 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -18,6 +18,7 @@ export const ONE_SECOND_MS = 1000; export const ONE_MINUTE_MS = ONE_SECOND_MS * 60; export const TEN_MINUTES_MS = ONE_MINUTE_MS * 10; export const DEFAULT_VALIDATION_GAS_LIMIT = 10e6; +export const HEX_BASE = 16; // The number of orders to post to Mesh at one time export const MESH_ORDERS_BATCH_SIZE = 200; diff --git a/src/utils/service_utils.ts b/src/utils/service_utils.ts index dbcb36515..c4e58420d 100644 --- a/src/utils/service_utils.ts +++ b/src/utils/service_utils.ts @@ -18,6 +18,7 @@ import { GAS_BURN_REFUND, GST_DIVISOR, GST_INTERACTION_COST, + HEX_BASE, ONE_SECOND_MS, PERCENTAGE_SIG_DIGITS, SSTORE_COST, @@ -73,16 +74,15 @@ export const serviceUtils = { }); // Generate unique identiifer - const HEX_DIGITS = 16; const timestampInSeconds = new BigNumber(Date.now() / ONE_SECOND_MS).integerValue(); - const hexTimestamp = timestampInSeconds.toString(HEX_DIGITS); + const hexTimestamp = timestampInSeconds.toString(HEX_BASE); const randomNumber = numberUtils.randomHexNumberOfLength(10); // Concatenate the hex identifier with the hex timestamp // In the final encoded call data, this will leave us with a 5-byte ID followed by // a 4-byte timestamp, and won't break parsers of the timestamp made prior to the // addition of the ID - const uniqueIdentifier = new BigNumber(`${randomNumber}${hexTimestamp}`, HEX_DIGITS); + const uniqueIdentifier = new BigNumber(`${randomNumber}${hexTimestamp}`, HEX_BASE); // Encode additional call data and return const encodedAffiliateData = affiliateCallDataEncoder.encode([affiliateAddressOrDefault, uniqueIdentifier]); diff --git a/test/constants.ts b/test/constants.ts index 3a08ce367..f71caa057 100644 --- a/test/constants.ts +++ b/test/constants.ts @@ -18,3 +18,4 @@ export const SYMBOL_TO_ADDRESS: ObjectMap = { ZRX: ZRX_TOKEN_ADDRESS, WETH: WETH_TOKEN_ADDRESS, }; +export const AFFILIATE_DATA_SELECTOR = '869584cd'; diff --git a/test/service_utils_test.ts b/test/service_utils_test.ts index 174006fd4..7b5f168a3 100644 --- a/test/service_utils_test.ts +++ b/test/service_utils_test.ts @@ -6,7 +6,7 @@ import 'mocha'; import { ZERO } from '../src/constants'; import { serviceUtils } from '../src/utils/service_utils'; -import { MAX_INT } from './constants'; +import { AFFILIATE_DATA_SELECTOR, MAX_INT } from './constants'; const SUITE_NAME = 'serviceUtils test'; @@ -68,4 +68,26 @@ describe(SUITE_NAME, () => { expect(gasTokenGasCost.toNumber()).to.be.eq(0); }); }); + describe('attributeCallData', () => { + it('it returns a reasonable ID and timestamp', () => { + const fakeCallData = '0x0000000000000'; + const fakeAffiliate = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; + const attributedCallData = serviceUtils.attributeCallData(fakeCallData, fakeAffiliate); + const currentTime = new Date(); + + // parse out items from call data to ensure they are reasonable values + const selectorPos = attributedCallData.indexOf(AFFILIATE_DATA_SELECTOR); + const affiliateAddress = '0x'.concat(attributedCallData.substring(selectorPos + 32, selectorPos + 72)); + const randomId = attributedCallData.substring(selectorPos + 118, selectorPos + 128); + const timestampFromCallDataHex = attributedCallData.substring(selectorPos + 128, selectorPos + 136); + const timestampFromCallData = parseInt(timestampFromCallDataHex, 16); + + expect(affiliateAddress).to.be.eq(fakeAffiliate); + // call data timestamp is within 3 seconds of timestamp created during test + expect(timestampFromCallData).to.be.greaterThan((currentTime.getTime() / 1000) - 3); + expect(timestampFromCallData).to.be.lessThan((currentTime.getTime() / 1000) + 3); + // ID is a 10-digit hex number + expect(randomId).to.match(/[0-9A-Fa-f]{10}/); + }); + }); }); From 521ff29938eaa5625b54754d2919ae9c548d5b1a Mon Sep 17 00:00:00 2001 From: Alex Kroeger Date: Thu, 30 Jul 2020 17:18:38 -0400 Subject: [PATCH 12/19] prettier :facepalm: --- test/service_utils_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/service_utils_test.ts b/test/service_utils_test.ts index 7b5f168a3..c590947b5 100644 --- a/test/service_utils_test.ts +++ b/test/service_utils_test.ts @@ -84,8 +84,8 @@ describe(SUITE_NAME, () => { expect(affiliateAddress).to.be.eq(fakeAffiliate); // call data timestamp is within 3 seconds of timestamp created during test - expect(timestampFromCallData).to.be.greaterThan((currentTime.getTime() / 1000) - 3); - expect(timestampFromCallData).to.be.lessThan((currentTime.getTime() / 1000) + 3); + expect(timestampFromCallData).to.be.greaterThan(currentTime.getTime() / 1000 - 3); + expect(timestampFromCallData).to.be.lessThan(currentTime.getTime() / 1000 + 3); // ID is a 10-digit hex number expect(randomId).to.match(/[0-9A-Fa-f]{10}/); }); From 3af429d04e261541da09622e92c9fd435a9b43c2 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 30 Jul 2020 21:41:21 -0700 Subject: [PATCH 13/19] log unique id in logs --- src/handlers/swap_handlers.ts | 7 ++++--- src/services/swap_service.ts | 6 ++++-- src/types.ts | 2 ++ src/utils/service_utils.ts | 10 ++++++++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index 339d2d017..714176454 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -64,10 +64,10 @@ export class SwapHandlers { }, }); if (quote.quoteReport) { - logQuoteReport(quote.quoteReport); + logQuoteReport(quote.quoteReport, quote.uniqueIdString); } } - const cleanedQuote = _.omit(quote, 'quoteReport'); + const cleanedQuote = _.omit(quote, 'quoteReport', 'uniqueIdString'); res.status(HttpStatus.OK).send(cleanedQuote); } // tslint:disable-next-line:prefer-function-over-method @@ -279,7 +279,7 @@ export class SwapHandlers { } } -const logQuoteReport = (qr: QuoteReport) => { +const logQuoteReport = (qr: QuoteReport, uniqueIdString: string) => { const sourcesConsideredChunks = _.chunk(qr.sourcesConsidered, NUMBER_SOURCES_PER_LOG_LINE); sourcesConsideredChunks.forEach((chunk, i) => { logger.info({ @@ -294,6 +294,7 @@ const logQuoteReport = (qr: QuoteReport) => { sourcesDeliveredChunks.forEach((chunk, i) => { logger.info({ firmQuoteReport: true, + firmQuoteUniqueIdString: uniqueIdString, sourcesDeliveredChunkIndex: i, sourcesDeliveredChunkLength: sourcesDeliveredChunks.length, sourcesDelivered: chunk, diff --git a/src/services/swap_service.ts b/src/services/swap_service.ts index af9678320..d80d6375c 100644 --- a/src/services/swap_service.ts +++ b/src/services/swap_service.ts @@ -120,7 +120,7 @@ export class SwapService { const { protocolFeeInWeiAmount: protocolFee, gas: worstCaseGas } = attributedSwapQuote.worstCaseQuoteInfo; const { orders, gasPrice, sourceBreakdown, quoteReport } = attributedSwapQuote; - const { to, value, data } = await this._getSwapQuotePartialTransactionAsync( + const { to, value, data, uniqueIdString } = await this._getSwapQuotePartialTransactionAsync( swapQuote, isETHSell, isETHBuy, @@ -208,6 +208,7 @@ export class SwapService { sources: serviceUtils.convertSourceBreakdownToArray(sourceBreakdown), orders: serviceUtils.cleanSignedOrderFields(orders), allowanceTarget, + uniqueIdString, quoteReport, }; return apiSwapQuote; @@ -521,11 +522,12 @@ export class SwapService { toAddress: to, } = await this._swapQuoteConsumer.getCalldataOrThrowAsync(swapQuote, opts); - const affiliatedData = serviceUtils.attributeCallData(data, affiliateAddress); + const { affiliatedData, uniqueIdString } = serviceUtils.attributeCallData(data, affiliateAddress); return { to, value, data: affiliatedData, + uniqueIdString, }; } diff --git a/src/types.ts b/src/types.ts index 9c6bb05bc..2bf45b183 100644 --- a/src/types.ts +++ b/src/types.ts @@ -390,6 +390,7 @@ export interface SwapQuoteResponsePartialTransaction { to: string; data: string; value: BigNumber; + uniqueIdString: string; } export interface SwapQuoteResponsePrice { @@ -411,6 +412,7 @@ export interface GetSwapQuoteResponse extends SwapQuoteResponsePartialTransactio gas: BigNumber; estimatedGas: BigNumber; estimatedGasTokenRefund: BigNumber; + uniqueIdString: string; allowanceTarget?: string; quoteReport?: QuoteReport; } diff --git a/src/utils/service_utils.ts b/src/utils/service_utils.ts index 10ea25f8f..53509bb0e 100644 --- a/src/utils/service_utils.ts +++ b/src/utils/service_utils.ts @@ -58,7 +58,13 @@ export const serviceUtils = { return attributedSwapQuote; }, - attributeCallData(data: string, affiliateAddress?: string): string { + attributeCallData( + data: string, + affiliateAddress?: string, + ): { + affiliatedData: string; + uniqueIdString: string; + } { const affiliateAddressOrDefault = affiliateAddress ? affiliateAddress : FEE_RECIPIENT_ADDRESS; const affiliateCallDataEncoder = new AbiEncoder.Method({ constant: true, @@ -87,7 +93,7 @@ export const serviceUtils = { // Encode additional call data and return const encodedAffiliateData = affiliateCallDataEncoder.encode([affiliateAddressOrDefault, uniqueIdentifier]); const affiliatedData = `${data}${encodedAffiliateData.slice(2)}`; - return affiliatedData; + return { affiliatedData, uniqueIdString: `${randomNumber}-${timestampInSeconds}` }; }, // tslint:disable-next-line:prefer-function-over-method From f543b70d6ef1c99f77d9e2c6c3916170facbf805 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 3 Aug 2020 16:18:13 -0700 Subject: [PATCH 14/19] abstract out reporting and associate with meta txns --- src/handlers/swap_handlers.ts | 34 ++++----------- src/services/meta_transaction_service.ts | 23 ++++++++-- src/services/swap_service.ts | 5 ++- src/types.ts | 1 + src/utils/quote_report_utils.ts | 53 ++++++++++++++++++++++++ test/service_utils_test.ts | 2 +- 6 files changed, 85 insertions(+), 33 deletions(-) create mode 100644 src/utils/quote_report_utils.ts diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index 714176454..0b93b532a 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -1,4 +1,4 @@ -import { QuoteReport, RfqtRequestOpts, SwapQuoterError } from '@0x/asset-swapper'; +import { RfqtRequestOpts, SwapQuoterError } from '@0x/asset-swapper'; import { BigNumber, NULL_ADDRESS } from '@0x/utils'; import * as express from 'express'; import * as HttpStatus from 'http-status-codes'; @@ -9,7 +9,6 @@ import { DEFAULT_QUOTE_SLIPPAGE_PERCENTAGE, MARKET_DEPTH_DEFAULT_DISTRIBUTION, MARKET_DEPTH_MAX_SAMPLES, - NUMBER_SOURCES_PER_LOG_LINE, SWAP_DOCS_URL, } from '../constants'; import { @@ -34,6 +33,8 @@ import { isWETHSymbolOrAddress, } from '../utils/token_metadata_utils'; +import { quoteReportUtils } from './../utils/quote_report_utils'; + export class SwapHandlers { private readonly _swapService: SwapService; public static rootAsync(_req: express.Request, res: express.Response): void { @@ -64,7 +65,11 @@ export class SwapHandlers { }, }); if (quote.quoteReport) { - logQuoteReport(quote.quoteReport, quote.uniqueIdString); + quoteReportUtils.logQuoteReport({ + quoteReport: quote.quoteReport, + submissionBy: 'taker', + uniqueIdString: quote.uniqueIdString, + }); } } const cleanedQuote = _.omit(quote, 'quoteReport', 'uniqueIdString'); @@ -279,29 +284,6 @@ export class SwapHandlers { } } -const logQuoteReport = (qr: QuoteReport, uniqueIdString: string) => { - const sourcesConsideredChunks = _.chunk(qr.sourcesConsidered, NUMBER_SOURCES_PER_LOG_LINE); - sourcesConsideredChunks.forEach((chunk, i) => { - logger.info({ - firmQuoteReport: true, - sourcesConsideredChunkIndex: i, - sourcesConsideredChunkLength: sourcesConsideredChunks.length, - sourcesConsidered: chunk, - }); - }); - - const sourcesDeliveredChunks = _.chunk(qr.sourcesDelivered, NUMBER_SOURCES_PER_LOG_LINE); - sourcesDeliveredChunks.forEach((chunk, i) => { - logger.info({ - firmQuoteReport: true, - firmQuoteUniqueIdString: uniqueIdString, - sourcesDeliveredChunkIndex: i, - sourcesDeliveredChunkLength: sourcesDeliveredChunks.length, - sourcesDelivered: chunk, - }); - }); -}; - const parseGetSwapQuoteRequestParams = ( req: express.Request, endpoint: 'price' | 'quote', diff --git a/src/services/meta_transaction_service.ts b/src/services/meta_transaction_service.ts index 58005c914..7d5d3e113 100644 --- a/src/services/meta_transaction_service.ts +++ b/src/services/meta_transaction_service.ts @@ -1,4 +1,11 @@ -import { Orderbook, SwapQuoter, SwapQuoteRequestOpts, SwapQuoterOpts } from '@0x/asset-swapper'; +import { + MarketBuySwapQuote, + MarketSellSwapQuote, + Orderbook, + SwapQuoter, + SwapQuoteRequestOpts, + SwapQuoterOpts, +} from '@0x/asset-swapper'; import { ContractAddresses, getContractAddressesForChainOrThrow } from '@0x/contract-addresses'; import { ContractWrappers } from '@0x/contract-wrappers'; import { DevUtilsContract } from '@0x/contracts-dev-utils'; @@ -41,6 +48,7 @@ import { ZeroExTransactionWithoutDomain, } from '../types'; import { ethGasStationUtils } from '../utils/gas_station_utils'; +import { quoteReportUtils } from '../utils/quote_report_utils'; import { serviceUtils } from '../utils/service_utils'; import { utils } from '../utils/utils'; @@ -111,7 +119,7 @@ export class MetaTransactionService { rfqt: _rfqt, }; - let swapQuote; + let swapQuote: MarketSellSwapQuote | MarketBuySwapQuote | undefined; if (sellAmount !== undefined) { swapQuote = await this._swapQuoter.getMarketSellSwapQuoteAsync( buyTokenAddress, @@ -129,7 +137,7 @@ export class MetaTransactionService { } else { throw new Error('sellAmount or buyAmount required'); } - const { gasPrice } = swapQuote; + const { gasPrice, quoteReport } = swapQuote; const { gas, protocolFeeInWeiAmount: protocolFee } = swapQuote.worstCaseQuoteInfo; const makerAssetAmount = swapQuote.bestCaseQuoteInfo.makerAssetAmount; const totalTakerAssetAmount = swapQuote.bestCaseQuoteInfo.totalTakerAssetAmount; @@ -162,6 +170,7 @@ export class MetaTransactionService { protocolFee, minimumProtocolFee: protocolFee, allowanceTarget, + quoteReport, }; return response; } @@ -177,6 +186,7 @@ export class MetaTransactionService { estimatedGas, protocolFee, minimumProtocolFee, + quoteReport, } = await this.calculateMetaTransactionPriceAsync(params, 'quote'); const floatGasPrice = swapQuote.gasPrice; @@ -206,6 +216,11 @@ export class MetaTransactionService { ) .callAsync(); + // log quote report and associate with txn hash + if (quoteReport) { + quoteReportUtils.logQuoteReport({ submissionBy: 'metaTxn', quoteReport, zeroExTransactionHash }); + } + const makerAssetAmount = swapQuote.bestCaseQuoteInfo.makerAssetAmount; const totalTakerAssetAmount = swapQuote.bestCaseQuoteInfo.totalTakerAssetAmount; const allowanceTarget = this._contractAddresses.erc20Proxy; @@ -339,7 +354,7 @@ export class MetaTransactionService { status: TransactionStates.Unsubmitted, takerAddress: zeroExTransaction.signerAddress, to: this._contractWrappers.exchange.address, - data, + data: data.affiliatedData, value: protocolFee, apiKey, gasPrice: zeroExTransaction.gasPrice, diff --git a/src/services/swap_service.ts b/src/services/swap_service.ts index d80d6375c..6e9bdec70 100644 --- a/src/services/swap_service.ts +++ b/src/services/swap_service.ts @@ -349,7 +349,7 @@ export class SwapService { : this._wethContract.deposit() ).getABIEncodedTransactionData(); const value = isUnwrap ? ZERO : amount; - const affiliatedData = serviceUtils.attributeCallData(data, affiliateAddress); + const attributedCalldata = serviceUtils.attributeCallData(data, affiliateAddress); // TODO: consider not using protocol fee utils due to lack of need for an aggresive gas price for wrapping/unwrapping const gasPrice = providedGasPrice || (await this._swapQuoter.getGasPriceEstimationOrThrowAsync()); const gasEstimate = isUnwrap ? UNWRAP_QUOTE_GAS : WRAP_QUOTE_GAS; @@ -357,7 +357,8 @@ export class SwapService { price: ONE, guaranteedPrice: ONE, to: this._wethContract.address, - data: affiliatedData, + data: attributedCalldata.affiliatedData, + uniqueIdString: attributedCalldata.uniqueIdString, value, gas: gasEstimate, estimatedGas: gasEstimate, diff --git a/src/types.ts b/src/types.ts index 2bf45b183..38066041a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -474,6 +474,7 @@ export interface CalculateMetaTransactionPriceResponse { protocolFee: BigNumber; minimumProtocolFee: BigNumber; estimatedGas: BigNumber; + quoteReport?: QuoteReport; allowanceTarget?: string; } diff --git a/src/utils/quote_report_utils.ts b/src/utils/quote_report_utils.ts new file mode 100644 index 000000000..22b1adae8 --- /dev/null +++ b/src/utils/quote_report_utils.ts @@ -0,0 +1,53 @@ +import { QuoteReport } from '@0x/asset-swapper'; +import _ = require('lodash'); + +import { NUMBER_SOURCES_PER_LOG_LINE } from '../constants'; +import { logger } from '../logger'; + +interface QuoteReportSubmissionByTaker { + quoteReport: QuoteReport; + submissionBy: 'taker'; + uniqueIdString: string; +} +interface QuoteReportSubmissionByMetaTxn { + quoteReport: QuoteReport; + submissionBy: 'metaTxn'; + zeroExTransactionHash: string; +} +type LogQuoteReportOptions = QuoteReportSubmissionByTaker | QuoteReportSubmissionByMetaTxn; + +export const quoteReportUtils = { + logQuoteReport(logOpts: LogQuoteReportOptions): void { + const qr = logOpts.quoteReport; + + let logBase: { [key: string]: string | boolean } = { + firmQuoteReport: true, + submissionBy: logOpts.submissionBy, + }; + if (logOpts.submissionBy === 'metaTxn') { + logBase = { ...logBase, zeroExTransactionHash: logOpts.zeroExTransactionHash }; + } else if (logOpts.submissionBy === 'taker') { + logBase = { ...logBase, uniqueIdString: logOpts.uniqueIdString }; + } + + // Deliver in chunks since Kibana can't handle logs large requests + const sourcesConsideredChunks = _.chunk(qr.sourcesConsidered, NUMBER_SOURCES_PER_LOG_LINE); + sourcesConsideredChunks.forEach((chunk, i) => { + logger.info({ + ...logBase, + sourcesConsidered: chunk, + sourcesConsideredChunkIndex: i, + sourcesConsideredChunkLength: sourcesConsideredChunks.length, + }); + }); + const sourcesDeliveredChunks = _.chunk(qr.sourcesDelivered, NUMBER_SOURCES_PER_LOG_LINE); + sourcesDeliveredChunks.forEach((chunk, i) => { + logger.info({ + ...logBase, + sourcesDelivered: chunk, + sourcesDeliveredChunkIndex: i, + sourcesDeliveredChunkLength: sourcesDeliveredChunks.length, + }); + }); + }, +}; diff --git a/test/service_utils_test.ts b/test/service_utils_test.ts index f71a0d1c3..39d1f382a 100644 --- a/test/service_utils_test.ts +++ b/test/service_utils_test.ts @@ -72,7 +72,7 @@ describe(SUITE_NAME, () => { it('it returns a reasonable ID and timestamp', () => { const fakeCallData = '0x0000000000000'; const fakeAffiliate = '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'; - const attributedCallData = serviceUtils.attributeCallData(fakeCallData, fakeAffiliate); + const attributedCallData = serviceUtils.attributeCallData(fakeCallData, fakeAffiliate).affiliatedData; const currentTime = new Date(); // parse out items from call data to ensure they are reasonable values From edd0830385e380c6273b63e7d0ba073c21ca4f3f Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Mon, 3 Aug 2020 16:48:08 -0700 Subject: [PATCH 15/19] only log quote report when its an rfqt firm quote --- src/handlers/swap_handlers.ts | 2 +- src/services/meta_transaction_service.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index 0b93b532a..8a8d88ea1 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -64,7 +64,7 @@ export class SwapHandlers { makers: quote.orders.map(order => order.makerAddress), }, }); - if (quote.quoteReport) { + if (quote.quoteReport && params.rfqt && params.rfqt.intentOnFilling) { quoteReportUtils.logQuoteReport({ quoteReport: quote.quoteReport, submissionBy: 'taker', diff --git a/src/services/meta_transaction_service.ts b/src/services/meta_transaction_service.ts index 7d5d3e113..2fa23f811 100644 --- a/src/services/meta_transaction_service.ts +++ b/src/services/meta_transaction_service.ts @@ -216,8 +216,8 @@ export class MetaTransactionService { ) .callAsync(); - // log quote report and associate with txn hash - if (quoteReport) { + // log quote report and associate with txn hash if this is an RFQT firm quote + if (quoteReport && params.apiKey !== undefined) { quoteReportUtils.logQuoteReport({ submissionBy: 'metaTxn', quoteReport, zeroExTransactionHash }); } From ba495a78e305113478396539e74577f84e2f3fba Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Tue, 4 Aug 2020 13:19:19 -0700 Subject: [PATCH 16/19] remove apiKey restriction from logging for meta txn --- src/services/meta_transaction_service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/meta_transaction_service.ts b/src/services/meta_transaction_service.ts index 2fa23f811..15ad9e2f1 100644 --- a/src/services/meta_transaction_service.ts +++ b/src/services/meta_transaction_service.ts @@ -217,7 +217,7 @@ export class MetaTransactionService { .callAsync(); // log quote report and associate with txn hash if this is an RFQT firm quote - if (quoteReport && params.apiKey !== undefined) { + if (quoteReport) { quoteReportUtils.logQuoteReport({ submissionBy: 'metaTxn', quoteReport, zeroExTransactionHash }); } From 939135fd72e13cf980bfe8ee753deff7666cc99f Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 6 Aug 2020 14:36:37 -0700 Subject: [PATCH 17/19] remove unneeded param --- src/types.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/types.ts b/src/types.ts index 38066041a..b5442bff0 100644 --- a/src/types.ts +++ b/src/types.ts @@ -412,7 +412,6 @@ export interface GetSwapQuoteResponse extends SwapQuoteResponsePartialTransactio gas: BigNumber; estimatedGas: BigNumber; estimatedGasTokenRefund: BigNumber; - uniqueIdString: string; allowanceTarget?: string; quoteReport?: QuoteReport; } From 3dae495ac6f8d375b9fef3a54660fbcd1b26abb4 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 6 Aug 2020 14:43:23 -0700 Subject: [PATCH 18/19] update names to be more clear --- src/utils/quote_report_utils.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/quote_report_utils.ts b/src/utils/quote_report_utils.ts index 22b1adae8..ba6f6ae3b 100644 --- a/src/utils/quote_report_utils.ts +++ b/src/utils/quote_report_utils.ts @@ -4,20 +4,20 @@ import _ = require('lodash'); import { NUMBER_SOURCES_PER_LOG_LINE } from '../constants'; import { logger } from '../logger'; -interface QuoteReportSubmissionByTaker { +interface QuoteReportForTakerTxn { quoteReport: QuoteReport; submissionBy: 'taker'; uniqueIdString: string; } -interface QuoteReportSubmissionByMetaTxn { +interface QuoteReportForMetaTxn { quoteReport: QuoteReport; submissionBy: 'metaTxn'; zeroExTransactionHash: string; } -type LogQuoteReportOptions = QuoteReportSubmissionByTaker | QuoteReportSubmissionByMetaTxn; +type QuoteReportLogOptions = QuoteReportForTakerTxn | QuoteReportForMetaTxn; export const quoteReportUtils = { - logQuoteReport(logOpts: LogQuoteReportOptions): void { + logQuoteReport(logOpts: QuoteReportLogOptions): void { const qr = logOpts.quoteReport; let logBase: { [key: string]: string | boolean } = { From c5593dbfc0c7153166acee9dc9248114d8cae4b9 Mon Sep 17 00:00:00 2001 From: Steve Klebanoff Date: Thu, 6 Aug 2020 15:01:02 -0700 Subject: [PATCH 19/19] uniqueIdString -> decodedUniqueId --- src/handlers/swap_handlers.ts | 4 ++-- src/services/swap_service.ts | 10 +++++----- src/types.ts | 2 +- src/utils/quote_report_utils.ts | 4 ++-- src/utils/service_utils.ts | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/handlers/swap_handlers.ts b/src/handlers/swap_handlers.ts index 8a8d88ea1..d80327b8a 100644 --- a/src/handlers/swap_handlers.ts +++ b/src/handlers/swap_handlers.ts @@ -68,11 +68,11 @@ export class SwapHandlers { quoteReportUtils.logQuoteReport({ quoteReport: quote.quoteReport, submissionBy: 'taker', - uniqueIdString: quote.uniqueIdString, + decodedUniqueId: quote.decodedUniqueId, }); } } - const cleanedQuote = _.omit(quote, 'quoteReport', 'uniqueIdString'); + const cleanedQuote = _.omit(quote, 'quoteReport', 'decodedUniqueId'); res.status(HttpStatus.OK).send(cleanedQuote); } // tslint:disable-next-line:prefer-function-over-method diff --git a/src/services/swap_service.ts b/src/services/swap_service.ts index 6e9bdec70..a68bc7cf3 100644 --- a/src/services/swap_service.ts +++ b/src/services/swap_service.ts @@ -120,7 +120,7 @@ export class SwapService { const { protocolFeeInWeiAmount: protocolFee, gas: worstCaseGas } = attributedSwapQuote.worstCaseQuoteInfo; const { orders, gasPrice, sourceBreakdown, quoteReport } = attributedSwapQuote; - const { to, value, data, uniqueIdString } = await this._getSwapQuotePartialTransactionAsync( + const { to, value, data, decodedUniqueId } = await this._getSwapQuotePartialTransactionAsync( swapQuote, isETHSell, isETHBuy, @@ -208,7 +208,7 @@ export class SwapService { sources: serviceUtils.convertSourceBreakdownToArray(sourceBreakdown), orders: serviceUtils.cleanSignedOrderFields(orders), allowanceTarget, - uniqueIdString, + decodedUniqueId, quoteReport, }; return apiSwapQuote; @@ -358,7 +358,7 @@ export class SwapService { guaranteedPrice: ONE, to: this._wethContract.address, data: attributedCalldata.affiliatedData, - uniqueIdString: attributedCalldata.uniqueIdString, + decodedUniqueId: attributedCalldata.decodedUniqueId, value, gas: gasEstimate, estimatedGas: gasEstimate, @@ -523,12 +523,12 @@ export class SwapService { toAddress: to, } = await this._swapQuoteConsumer.getCalldataOrThrowAsync(swapQuote, opts); - const { affiliatedData, uniqueIdString } = serviceUtils.attributeCallData(data, affiliateAddress); + const { affiliatedData, decodedUniqueId } = serviceUtils.attributeCallData(data, affiliateAddress); return { to, value, data: affiliatedData, - uniqueIdString, + decodedUniqueId, }; } diff --git a/src/types.ts b/src/types.ts index b5442bff0..208096028 100644 --- a/src/types.ts +++ b/src/types.ts @@ -390,7 +390,7 @@ export interface SwapQuoteResponsePartialTransaction { to: string; data: string; value: BigNumber; - uniqueIdString: string; + decodedUniqueId: string; } export interface SwapQuoteResponsePrice { diff --git a/src/utils/quote_report_utils.ts b/src/utils/quote_report_utils.ts index ba6f6ae3b..f82266954 100644 --- a/src/utils/quote_report_utils.ts +++ b/src/utils/quote_report_utils.ts @@ -7,7 +7,7 @@ import { logger } from '../logger'; interface QuoteReportForTakerTxn { quoteReport: QuoteReport; submissionBy: 'taker'; - uniqueIdString: string; + decodedUniqueId: string; } interface QuoteReportForMetaTxn { quoteReport: QuoteReport; @@ -27,7 +27,7 @@ export const quoteReportUtils = { if (logOpts.submissionBy === 'metaTxn') { logBase = { ...logBase, zeroExTransactionHash: logOpts.zeroExTransactionHash }; } else if (logOpts.submissionBy === 'taker') { - logBase = { ...logBase, uniqueIdString: logOpts.uniqueIdString }; + logBase = { ...logBase, decodedUniqueId: logOpts.decodedUniqueId }; } // Deliver in chunks since Kibana can't handle logs large requests diff --git a/src/utils/service_utils.ts b/src/utils/service_utils.ts index 53509bb0e..70659702e 100644 --- a/src/utils/service_utils.ts +++ b/src/utils/service_utils.ts @@ -63,7 +63,7 @@ export const serviceUtils = { affiliateAddress?: string, ): { affiliatedData: string; - uniqueIdString: string; + decodedUniqueId: string; } { const affiliateAddressOrDefault = affiliateAddress ? affiliateAddress : FEE_RECIPIENT_ADDRESS; const affiliateCallDataEncoder = new AbiEncoder.Method({ @@ -93,7 +93,7 @@ export const serviceUtils = { // Encode additional call data and return const encodedAffiliateData = affiliateCallDataEncoder.encode([affiliateAddressOrDefault, uniqueIdentifier]); const affiliatedData = `${data}${encodedAffiliateData.slice(2)}`; - return { affiliatedData, uniqueIdString: `${randomNumber}-${timestampInSeconds}` }; + return { affiliatedData, decodedUniqueId: `${randomNumber}-${timestampInSeconds}` }; }, // tslint:disable-next-line:prefer-function-over-method