-
Notifications
You must be signed in to change notification settings - Fork 238
feat: added a unique identifier to the quote within the timestamp metadata … #281
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice function!
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @steveklebanoff requested changes, then LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 0xProject/0x-event-pipeline#26).
Testing Instructions
Checklist
[WIP]
if necessary.