Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added a unique identifier to the quote within the timestamp metadata … #281

Merged
merged 3 commits into from
Jul 31, 2020

Conversation

alexkroeger
Copy link
Contributor

@alexkroeger alexkroeger commented Jul 14, 2020

…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

  • Update documentation as needed. Website Documentation PR:
  • Prefix PR title with [WIP] if necessary.
  • Add tests to cover changes as needed.

@alexkroeger alexkroeger changed the title Added a unique identifier to the quote within the timestamp metadata … feat: added a unique identifier to the quote within the timestamp metadata … Jul 14, 2020
Copy link
Contributor

@steveklebanoff steveklebanoff left a 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 => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice function!

const encodedAffiliateData = affiliateCallDataEncoder.encode([affiliateAddressOrDefault, timestamp]);

// Generate unique identiifer
const HEX_DIGITS = 16;
Copy link
Contributor

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?

// 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);
Copy link
Contributor

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

Copy link
Member

@dekz dekz left a 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

Copy link
Contributor

@steveklebanoff steveklebanoff left a 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

@alexkroeger alexkroeger merged commit d992563 into master Jul 31, 2020
@alexkroeger alexkroeger deleted the feat/unique-id branch July 31, 2020 16:20
github-actions bot pushed a commit that referenced this pull request Aug 3, 2020
# [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))
@github-actions
Copy link

github-actions bot commented Aug 3, 2020

🎉 This PR is included in version 1.13.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants