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: Track historical tft prices #169

Merged
merged 6 commits into from
May 21, 2024

Conversation

sameh-farouk
Copy link
Member

@sameh-farouk sameh-farouk commented May 13, 2024

What's Changed:

  • Indexing TFT price and average TFT price, by processing two tfchain events TFTPriceModule.AveragePriceStored and TFTPriceModule.PriceStored. data included is a timestamp, block height, and 1 TFT price in USD.

Decisions Made:

  • Since our squid indexed the price from tfchain emitted events there are different versions of price data with different scales (the number of digits to the right of the decimal point in a number). Some have too few like 2 and some have too many. I chose not to attempt to unify these and leave the values as they are. clients could round these as needed.
  • Prices are stored in Postgresql as decimal/numeric type

Related issues:

example of querying the last 3 average prices for TFT stored on tfchain.

query MyQuery {
  averagePriceStoreds(limit: 3, orderBy: block_DESC) {
    block
    id
    newAveragePrice
    timestamp
  }
}

Result:

{
  "data": {
    "averagePriceStoreds": [
      {
        "block": 11160373,
        "id": "0011160373-000003-a6bf7",
        "newAveragePrice": "0.02",
        "timestamp": "1716289794"
      },
      {
        "block": 11160363,
        "id": "0011160363-000008-81af9",
        "newAveragePrice": "0.02",
        "timestamp": "1716289734"
      },
      {
        "block": 11160353,
        "id": "0011160353-000003-91221",
        "newAveragePrice": "0.02",
        "timestamp": "1716289674"
      }
    ]
  }
}

example of querying the last 3 prices for TFT stored on tfchain.

query MyQuery {
  priceStoreds(limit: 3, orderBy: block_DESC) {
    block
    id
    newPrice
    timestamp
  }
}

Result:

{
  "data": {
    "priceStoreds": [
      {
        "block": 11160586,
        "id": "0011160586-000002-273c9",
        "newPrice": "0.02",
        "timestamp": "1716291072"
      },
      {
        "block": 11160576,
        "id": "0011160576-000017-82e41",
        "newPrice": "0.02",
        "timestamp": "1716291012"
      },
      {
        "block": 11160566,
        "id": "0011160566-000028-4cb5a",
        "newPrice": "0.02",
        "timestamp": "1716290952"
      }
    ]
  }
}

@sameh-farouk sameh-farouk requested a review from renauter as a code owner May 13, 2024 16:34
@sameh-farouk sameh-farouk changed the title Track historical tft prices feat: Track historical tft prices May 13, 2024
@sameh-farouk sameh-farouk marked this pull request as draft May 13, 2024 17:50
@sameh-farouk sameh-farouk marked this pull request as ready for review May 20, 2024 15:23
@sameh-farouk sameh-farouk marked this pull request as draft May 20, 2024 15:23
@sameh-farouk sameh-farouk marked this pull request as ready for review May 20, 2024 17:28
Copy link

@LeeSmet LeeSmet left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@renauter renauter left a comment

Choose a reason for hiding this comment

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

I chose not to attempt to unify these and leave the values as they are

I agree with this choice

Nice work
LGTM !!

@sameh-farouk sameh-farouk merged commit aed4bd3 into master May 21, 2024
1 check passed
@sameh-farouk sameh-farouk deleted the master-track-historical-tft-prices branch May 21, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants