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

ERC-20 token prices #691

Merged
merged 16 commits into from
Aug 29, 2024
Merged

ERC-20 token prices #691

merged 16 commits into from
Aug 29, 2024

Conversation

pro-wh
Copy link
Collaborator

@pro-wh pro-wh commented May 11, 2024

this adds a "relative" token price estimate and total value estimate to the tokens API.

this data comes from on-chain swap contracts. for contracts that follow the Uniswap v2 interface, we index the swap contracts in a new chain.evm_swap_pairs table. the pair contracts emit a "Sync" event, which reports a contract's reserves, and the contract trades its two tokens in proportion to its reserves of the two tokens.

we add a new configuration that specifies a collection of swap contracts identified by their "factory" contract plus a "reference" token. the relative token price estimate for a token is available when there is a swap pair contract for that token and the reference token or if the token is the reference token itself.

in this PR, we select illumineX swap and Wrapped ROSE (0x8Bc2B030b299964eEfb5e1e0b36991352E56D2D3) for Sapphire mainnet.

@pro-wh pro-wh added the analysis-layer Analysis layer-related issues. label May 11, 2024
@pro-wh
Copy link
Collaborator Author

pro-wh commented May 11, 2024

this adds gpl'd code to our repo

@pro-wh pro-wh force-pushed the pro-wh/feature/swapprice branch from dc98a8f to 4e52598 Compare May 13, 2024 23:34
@pro-wh pro-wh force-pushed the pro-wh/feature/blockmeta branch from 4c1db1c to aab2e4d Compare May 13, 2024 23:34
@pro-wh pro-wh force-pushed the pro-wh/feature/swapprice branch from 287fbc3 to 9c6302a Compare May 15, 2024 23:00
@jberci jberci force-pushed the pro-wh/feature/blockmeta branch 2 times, most recently from 0cbe365 to 668490f Compare June 21, 2024 22:40
@pro-wh pro-wh force-pushed the pro-wh/feature/swapprice branch from 9c6302a to 1b19994 Compare July 25, 2024 00:11
@pro-wh pro-wh changed the base branch from pro-wh/feature/blockmeta to main July 25, 2024 00:11
@pro-wh pro-wh force-pushed the pro-wh/feature/swapprice branch from 1b19994 to a7a1a83 Compare July 26, 2024 23:53
@pro-wh pro-wh marked this pull request as ready for review July 27, 2024 00:03
@pro-wh pro-wh requested review from Andrew7234 and ptrus as code owners July 27, 2024 00:03
Copy link
Collaborator

@Andrew7234 Andrew7234 left a comment

Choose a reason for hiding this comment

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

Thanks for putting this all together! Looks good so far

analyzer/queries/queries.go Outdated Show resolved Hide resolved
storage/client/queries/queries.go Outdated Show resolved Hide resolved
api/spec/v1.yaml Outdated Show resolved Hide resolved
api/spec/v1.yaml Show resolved Hide resolved
api/spec/v1.yaml Outdated Show resolved Hide resolved
api/spec/v1.yaml Outdated Show resolved Hide resolved
config/reference_swaps.go Show resolved Hide resolved
@pro-wh pro-wh force-pushed the pro-wh/feature/swapprice branch 3 times, most recently from 78b89d3 to 22b47b3 Compare August 14, 2024 22:35
analyzer/runtime/extract.go Show resolved Hide resolved
api/spec/v1.yaml Show resolved Hide resolved
config/reference_swaps.go Show resolved Hide resolved
@pro-wh pro-wh force-pushed the pro-wh/feature/swapprice branch 2 times, most recently from c9175a3 to f227a8f Compare August 21, 2024 23:07
@pro-wh pro-wh requested a review from Andrew7234 August 21, 2024 23:11
Copy link
Collaborator

@Andrew7234 Andrew7234 left a comment

Choose a reason for hiding this comment

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

Thanks! The api descriptions are looking good; left a couple minor questions but I think it's getting very close.

},
{
Name: "reserve1",
EvmType: "uint112",
Copy link
Collaborator

Choose a reason for hiding this comment

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

TIL there's a uint112

Comment on lines +1077 to +1078
Token0: token0Addr,
Token1: token1Addr,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does uniswap enforce some ordering on token0/token1? Like is it possible to create a usdt/wrose pair and then create a wrose/usdt pair that's distinct from it? (and if uniswap combines the pairs, would nexus do the same?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

my reading of the actual contract is they have to have the lower token address in token0

api/spec/v1.yaml Show resolved Hide resolved
config/reference_swaps.go Show resolved Hide resolved
Copy link
Collaborator

@Andrew7234 Andrew7234 left a comment

Choose a reason for hiding this comment

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

Thank you! Looks good, left a minor comment

api/spec/v1.yaml Outdated Show resolved Hide resolved
api/spec/v1.yaml Show resolved Hide resolved
@pro-wh pro-wh force-pushed the pro-wh/feature/swapprice branch from 02677db to 3d2712f Compare August 27, 2024 23:18
@pro-wh pro-wh force-pushed the pro-wh/feature/swapprice branch from a992f5f to 6d55d50 Compare August 29, 2024 19:03
@pro-wh
Copy link
Collaborator Author

pro-wh commented Aug 29, 2024

had to disable the gocyclo on visit evm event

@pro-wh pro-wh merged commit 651eef7 into main Aug 29, 2024
16 checks passed
@pro-wh pro-wh deleted the pro-wh/feature/swapprice branch August 29, 2024 19:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analysis-layer Analysis layer-related issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants