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

Reproduce Jesse's original subgraph #1

Closed
wants to merge 5 commits into from

Conversation

arthurgousset
Copy link

@arthurgousset arthurgousset commented Apr 1, 2024

Description

This is step 1 of 2:

  1. Reproduce Jesse's original subgraph in the celo-org/v3-subgraph fork
  2. Update the subgraph with new tokens as requested in this issue: Updating Uniwap Celo Subgraph  uniswap-v3-info#1

I'll open a separate PR to add new tokens to the whitelist.

Changes

I'm applying all changes made in this PR:

to this repo.

Other changes

None

Testing

I haven't tested the subgraph configured in this PR yet. I'll do that and document how I tested it before this PR gets merged.

Docs

None

Source: Jesse-Sawa#1

I'm applying all changes made in this PR "v3-subgraph for celo changes
#1" (Jesse-Sawa#1).
Source: Jesse-Sawa#1

I'm applying all changes made in this PR "v3-subgraph for celo changes
Uniswap#1" (Jesse-Sawa#1).
arthurgousset added a commit that referenced this pull request Apr 1, 2024
Source: Jesse-Sawa#1

I'm applying all changes made in this PR "v3-subgraph for celo changes
#1".
Source: Jesse-Sawa#1

I'm applying all changes made in this PR "v3-subgraph for celo changes
Uniswap#1" (Jesse-Sawa#1).
Source: Jesse-Sawa#1

I'm applying all changes made in this PR "v3-subgraph for celo changes
Uniswap#1" (Jesse-Sawa#1).

In this commit, I had to modify the original diff from Jesse a little, because the source code has changed slightly since he made the change.
Source: Jesse-Sawa#1

I'm applying all changes made in this PR "v3-subgraph for celo changes
@arthurgousset arthurgousset force-pushed the arthurgousset/configure-celo-subgraph branch from f46ba64 to f298136 Compare April 1, 2024 14:23
@arthurgousset arthurgousset marked this pull request as ready for review April 1, 2024 18:05
@arthurgousset arthurgousset marked this pull request as draft April 1, 2024 18:09
@arthurgousset
Copy link
Author

I'd like to test this subgraph in a local deployment before it gets merged.

@arthurgousset arthurgousset requested a review from jcortejoso April 1, 2024 18:10
@arthurgousset arthurgousset self-assigned this Apr 1, 2024
@arthurgousset arthurgousset marked this pull request as ready for review April 1, 2024 18:13
@arthurgousset
Copy link
Author

arthurgousset commented Apr 1, 2024

Asked if @Data-Nexus could give this PR a quick look since he worked on various Uniswap v3 related PRs in the upstream repo.

For example:

That PR changes code that is touched upon in this PR like position-manager.ts.

@arthurgousset
Copy link
Author

To test the subgraph, I'll use these commands:

Install dependencies:

$ yarn install

Generate types for GraphQL schema:

$ yarn run codegen

Build the subgraph:

$ yarn run build

Set the access token secret:

$ ACCESS_KEY='<paste-here>'

Deploy the subgraph:

$ yarn run deploy-celo

I'm waiting for @jcortejoso to look into key and account setup to deploy a test subgraph.

@arthurgousset
Copy link
Author

arthurgousset commented Apr 3, 2024

I'm following these instructions to generate an ACCESS_TOKEN to test the subgraph: Deploying a Subgraph to the Hosted Service

@arthurgousset
Copy link
Author

arthurgousset commented Apr 3, 2024

Installing graph CLI:

$ yarn global add @graphprotocol/graph-cli

Authenticating:

$ graph auth --product hosted-service <ACCESS_TOKEN>

This will store the access token on your computer. You only need to do this once, or if you ever regenerate the access token.

@arthurgousset
Copy link
Author

arthurgousset commented Apr 3, 2024

@jcortejoso Looks like it should be possible to create the subgraph we'll use in production as celo-org/uniswap, because the account can be a GitHub organization:

Account - The account that the subgraph is created under. This can be the account of an individual or organization. Subgraphs cannot be moved between accounts later.

Subgraph Name - Together with the account name that the subgraph is created under, this will also define the account-name/subgraph-name-style name used for deployments and GraphQL endpoints. This field cannot be changed later.

Source: https://thegraph.com/docs/en/deploying/deploying-a-subgraph-to-hosted/#create-a-subgraph-on-the-hosted-service

@arthurgousset
Copy link
Author

arthurgousset commented Apr 3, 2024

@jcortejoso has been testing automatic subgraph deployment to the hosted service from GitHub Actions: https://github.com/celo-org/v3-subgraph/actions/runs/8537277015/job/23387505490

🥳

@arthurgousset
Copy link
Author

Registered a test subgraph to which I'll deploy from this branch: https://thegraph.com/hosted-service/subgraph/arthurgousset/uniswap

@arthurgousset
Copy link
Author

arthurgousset commented Apr 3, 2024

Test deployment to https://thegraph.com/hosted-service/subgraph/arthurgousset/uniswap worked ✅

$ cd v3-subgraph
$ yarn
$ yarn run codegen
$ yarn run build
$ graph auth --product hosted-service <ACCESS_TOKEN> # replace with your token
$ graph deploy --product hosted-service arthurgousset/uniswap

# ...
Build completed: QmXKPZVYLCZ24HP5cXS1KuPECCJP9jmddtk1g174bJCGZU

Deployed to https://thegraph.com/explorer/subgraph/arthurgousset/uniswap

Subgraph endpoints:
Queries (HTTP):     https://api.thegraph.com/subgraphs/name/arthurgousset/uniswap

@arthurgousset
Copy link
Author

Now thinking about how we can test our subgraphs work with local builds of Uniswap.

@arthurgousset
Copy link
Author

Re updating subgraphs while testing:

When making changes to your subgraph definition, for example, to fix a problem in the entity mappings, run the yarn deploy command above again to deploy the updated version of your subgraph. Any update of a subgraph requires that Graph Node reindexes your entire subgraph, again starting with the genesis block.

If your previously deployed subgraph is still in status Syncing, it will be immediately replaced with the newly deployed version. If the previously deployed subgraph is already fully synced, Graph Node will mark the newly deployed version as the Pending Version, sync it in the background, and only replace the currently deployed version with the new one once syncing the new version has finished. This ensures that you have a subgraph to work with while the new version is syncing.

Source: ⁠Redeploying a Subgraph

@arthurgousset
Copy link
Author

Looks like we can test smart order routing with:

Celo Mainnet

./bin/cli quote --tokenIn CELO --tokenOut 0x765DE816845861e75A25fCA122bb6898B8B1282a --amount 5 --exactIn --minSplits 1 --protocols v3 --router alpha --chainId 42220

Source: Uniswap/smart-order-router

@arthurgousset
Copy link
Author

arthurgousset commented Apr 3, 2024

Original bug

Trying to test the interface works with the new subgraph. For that I'm trying to build and serve the interface from celo-org/uniswap-interface.

I'm running into an error when installing dependencies:

## I'm in the root directory of the repo
$ pwd
/Users/arthur/Documents/celo-org/uniswap-interface
$ yarn 
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 0s 362ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed in 0s 712ms
➤ YN0000: ┌ Link step
➤ YN0007: │ universe@workspace:. must be built because it never has been before or the last one failed
➤ YN0007: │ postinstall-postinstall@npm:2.1.0 must be built because it never has been before or the last one failed
➤ YN0009: │ universe@workspace:. couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/9r/vpr7vg4j72s81zzgxxdwtszc0000gp/T/xfs-5c2adfc7/build.log)
➤ YN0009: │ postinstall-postinstall@npm:2.1.0 couldn't be built successfully (exit code 1, logs can be found here: /private/var/folders/9r/vpr7vg4j72s81zzgxxdwtszc0000gp/T/xfs-9676c2ef/build.log)
➤ YN0000: └ Completed in 16s 898ms
➤ YN0000: Failed with errors in 18s 105ms

The build.log file referenced above shows:

@uniswap/interface:prepare: [ajv] npm WARN ignoring workspace config at /Users/arthur/Documents/celo-org/uniswap-interface/apps/web/.npmrc 
@uniswap/interface:prepare: [i18n] npm WARN ignoring workspace config at /Users/arthur/Documents/celo-org/uniswap-interface/apps/web/.npmrc 
@uniswap/interface:prepare: [ajv] 
@uniswap/interface:prepare: [ajv] > @uniswap/[email protected] ajv
@uniswap/interface:prepare: [ajv] > node scripts/compile-ajv-validators.js
@uniswap/interface:prepare: [ajv] 
@uniswap/interface:prepare: [i18n] 
@uniswap/interface:prepare: [i18n] > @uniswap/[email protected] i18n
@uniswap/interface:prepare: [i18n] > yarn i18n:extract --clean && yarn i18n:compile
@uniswap/interface:prepare: [i18n] 
@uniswap/interface:prepare: [ajv] node:internal/fs/utils:347
@uniswap/interface:prepare: [ajv]     throw err;
@uniswap/interface:prepare: [ajv]     ^
@uniswap/interface:prepare: [ajv] 
@uniswap/interface:prepare: [ajv] Error: ENOENT: no such file or directory, open '/Users/arthur/Documents/celo-org/uniswap-interface/apps/web/src/utils/__generated__/validateTokenList.js'
@uniswap/interface:prepare: [ajv]     at Object.openSync (node:fs:601:3)
@uniswap/interface:prepare: [ajv]     at Object.writeFileSync (node:fs:2249:35)
@uniswap/interface:prepare: [ajv]     at Object.<anonymous> (/Users/arthur/Documents/celo-org/uniswap-interface/apps/web/scripts/compile-ajv-validators.js:14:4)
@uniswap/interface:prepare: [ajv]     at Module._compile (node:internal/modules/cjs/loader:1254:14)
@uniswap/interface:prepare: [ajv]     at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
@uniswap/interface:prepare: [ajv]     at Module.load (node:internal/modules/cjs/loader:1117:32)
@uniswap/interface:prepare: [ajv]     at Module._load (node:internal/modules/cjs/loader:958:12)
@uniswap/interface:prepare: [ajv]     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
@uniswap/interface:prepare: [ajv]     at node:internal/main/run_main_module:23:47 {
@uniswap/interface:prepare: [ajv]   errno: -2,
@uniswap/interface:prepare: [ajv]   syscall: 'open',
@uniswap/interface:prepare: [ajv]   code: 'ENOENT',
@uniswap/interface:prepare: [ajv]   path: '/Users/arthur/Documents/celo-org/uniswap-interface/apps/web/src/utils/__generated__/validateTokenList.js'
@uniswap/interface:prepare: [ajv] }
@uniswap/interface:prepare: [ajv] 
@uniswap/interface:prepare: [ajv] Node.js v18.16.0
@uniswap/interface:prepare: [ajv] npm ERR! Lifecycle script `ajv` failed with error: 
@uniswap/interface:prepare: [ajv] npm ERR! Error: command failed 
@uniswap/interface:prepare: [ajv] npm ERR!   in workspace: @uniswap/[email protected] 
@uniswap/interface:prepare: [ajv] npm ERR!   at location: /Users/arthur/Documents/celo-org/uniswap-interface/apps/web 

Looks like somehow a file is missing:

Error: ENOENT: no such file or directory, open '/Users/arthur/Documents/celo-org/uniswap-interface/apps/web/src/utils/__generated__/validateTokenList.js'

Reproducing the bug:

$ yarn web ajv
node:internal/fs/utils:347
    throw err;
    ^

Error: ENOENT: no such file or directory, open '/Users/arthur/Documents/celo-org/uniswap-interface/apps/web/src/utils/__generated__/validateTokenList.js'
    at Object.openSync (node:fs:601:3)
    at Object.writeFileSync (node:fs:2249:35)
    at Object.<anonymous> (/Users/arthur/Documents/celo-org/uniswap-interface/apps/web/scripts/compile-ajv-validators.js:14:4)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1310:10)
    at Module.load (node:internal/modules/cjs/loader:1119:32)
    at Module._load (node:internal/modules/cjs/loader:960:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:23:47 {
  errno: -2,
  syscall: 'open',
  code: 'ENOENT',
  path: '/Users/arthur/Documents/celo-org/uniswap-interface/apps/web/src/utils/__generated__/validateTokenList.js'
}

Node.js v18.16.1

Edit: Fixed bug ✅

This is a known issue:

Workaround:

  1. create an empty directory __generated__ at apps/web/src/utils
$ mkdir apps/web/src/utils/__generated__ 
  1. run yarn as usual (should work now)

A fix in the upstream repo is proposed in this PR:

Context for fix:

Hi. There seems to be a problem in line 14 in apps/web/scripts/compile-ajv-validators.js file. fs.writeFileSync(path.join(__dirname, '../src/utils/__generated__/validateTokenList.js'), tokenListModuleCode) script tries to write tokenListModuleCode to validateTokenList.js in __generated__ folder but that folder doesn't exists. As a matter of fact it's .gitignored hence the error. I'd like to work on that if possible. As a workaround just create empty __generated__ folder in apps/web/src/utils and run yarn install again

Source: Uniswap/interface#7631 (comment)

@arthurgousset
Copy link
Author

Asked for help (on Slack) from the Uniswap team to test the subgraph.

@arthurgousset
Copy link
Author

arthurgousset commented Apr 4, 2024

@nicolasbrugneaux confirmed he has the same build issue when trying to serve the uniswap interface locally in this PR:

@arthurgousset
Copy link
Author

Putting this on hold until I get an owner on the Uniswap side that can help me test this.

@arthurgousset arthurgousset linked an issue Apr 24, 2024 that may be closed by this pull request
@arthurgousset
Copy link
Author

arthurgousset commented Apr 26, 2024

Managed to build and serve the interface locally with a workaround

# Workaround: create this empty directory
$ cd apps/web/src/utils
$ mkdir __generated__

# Get on the right Node version
$ nvm use

# Workaround: Build interface manually
$ yarn web g:build

# Serve interface as suggested
$ yarn web start
image

@arthurgousset
Copy link
Author

arthurgousset commented Apr 29, 2024

Looks like part of the changes reproduced here are covered by this draft PR by @mzywang:

@arthurgousset
Copy link
Author

TLDR:

  1. Uniswap Labs will host the Celo subgraph used in production, and
  2. Uniswap Labs will own and maintain the v3-subgraph repo that generates the subgraph.

On that basis, community members can request new tokens to be whitelisted by opening a PR in the v3-subgraph repo.

@mzywang expects the new Celo subgraph will be live and used in production in the order of "weeks" (not days or months).

For future reference:

  • The subgraph affects optimal order routing, Uniswap uses the subgraph for pool discoverability and ranks pools based on TVL.
  • If the subgraph is down (as is the case right now for the one on the hosted service), a static list of tokens is used to determine routes defined in the uniswap interface.

Source: celo-org/uniswap-v3-info#1 (comment)

On that basis, I'll close this PRs, since all work streams here are and will be owned by Uniswap.

@arthurgousset arthurgousset deleted the arthurgousset/configure-celo-subgraph branch May 22, 2024 12:09
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.

Updating Uniwap Celo Subgraph
2 participants