feat: added a unique identifier to the quote within the timestamp metadata …#281
feat: added a unique identifier to the quote within the timestamp metadata …#281alexkroeger merged 3 commits intomasterfrom
Conversation
steveklebanoff
left a comment
There was a problem hiding this comment.
A few nits but overall LGTM as-is. Thank you for doing this!
Sanity test:
const ONE_SECOND_MS = 1000;
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);
const uniqueIdentifier = new BigNumber(`${randomNumber}${hexTimestamp}`, HEX_DIGITS);
console.log('random number', randomNumber);
console.log('timestamp', timestampInSeconds);
console.log('uniqueIdentifier', uniqueIdentifier);
const hexRep = uniqueIdentifier.toString(16);
const decodedHexFirst = hexRep.substr(0, 10);
const decodedHexSecond = hexRep.substr(10, 100);
console.log('decoded', parseInt(decodedHexFirst, 16), ',', parseInt(decodedHexSecond, 16));
Output:
random number 59f8a19c92
timestamp 1595285925
uniqueIdentifier 1659675995505281081765
decoded 386423430290 , 1595285925
| // 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 => { |
src/utils/service_utils.ts
Outdated
| const encodedAffiliateData = affiliateCallDataEncoder.encode([affiliateAddressOrDefault, timestamp]); | ||
|
|
||
| // Generate unique identiifer | ||
| const HEX_DIGITS = 16; |
There was a problem hiding this comment.
nit but can we move this to constants.ts?
src/utils/service_utils.ts
Outdated
| // 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); |
There was a problem hiding this comment.
might be nice to move the unique identification generation to a separate function, and add a unit test to ensure that the timestamp you can parse out of it is "sane"
you could do this with freezing time in tests (but I think this would add a new dependency), or at least ensure that the returned timestamp is within ~10 seconds of the current timestamp
dekz
left a comment
There was a problem hiding this comment.
Agree with @steveklebanoff requested changes, then LGTM
steveklebanoff
left a comment
There was a problem hiding this comment.
LGTM but would still prefer the timestamp generated to be in its own function. that being said -- I could do that move in my own PR
# [1.13.0](v1.12.0...v1.13.0) (2020-08-03) ### Bug Fixes * Kovan deploy UniswapV2 ([#304](#304)) ([f4fb99b](f4fb99b)) * Kovan ERC20BridgeSampler ([#299](#299)) ([56f7a90](56f7a90)) ### Features * added a unique identifier to the quote within the timestamp metadata … ([#281](#281)) ([d992563](d992563)) * Rfqt included ([#293](#293)) ([965dedb](965dedb))
|
🎉 This PR is included in version 1.13.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
…field
Description
This PR supercedes #267.
This PR adds a unique identifier to 0x API quotes within the metadata timestamp field. An existing field was utilized in order to not increase the gas expenditure associated with publishing this data on-chain.
The identifier is a 10-digit hex number placed before the second timestamp (an 8-digit hex number). Placing the identifier in this position will not break the metadata parsing in Dune Analytics (see https://github.com/duneanalytics/abstractions/blob/master/schema/zeroex/view_affiliate_data.sql)the event-pipeline (see https://github.com/0xProject/0x-event-pipeline/pull/26).
Testing Instructions
Checklist
[WIP]if necessary.