From 5c37283e8cf87a88a65050fda74b53e489413f6b Mon Sep 17 00:00:00 2001 From: dankelleher Date: Fri, 28 Jun 2024 09:25:08 +0200 Subject: [PATCH 1/5] chore: replace Subgraph urls with new ones sourced from docs Taken from: https://docs.toucan.earth/developers/sdk/subgraph. Also, removed obsolete mumbai subgraph. --- src/types/index.ts | 2 +- src/utils/addresses.ts | 9 --------- src/utils/graphAPIs.ts | 15 ++++++++++----- src/utils/graphClients.ts | 5 +---- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/types/index.ts b/src/types/index.ts index 69a9707..10155db 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -16,7 +16,7 @@ along with this program. If not, see . */ -export type Network = "polygon" | "mumbai" | "celo" | "alfajores"; +export type Network = "polygon" | "celo" | "alfajores"; export type PoolSymbol = "BCT" | "NCT"; diff --git a/src/utils/addresses.ts b/src/utils/addresses.ts index 538bdb7..f0485ca 100644 --- a/src/utils/addresses.ts +++ b/src/utils/addresses.ts @@ -11,7 +11,6 @@ export interface INetworkAddresses { celo: INetworkTokenAddresses; alfajores: INetworkTokenAddresses; polygon: INetworkTokenAddresses; - mumbai: INetworkTokenAddresses; } const addresses: INetworkAddresses = { @@ -39,14 +38,6 @@ const addresses: INetworkAddresses = { weth: "0x7ceb23fd6bc0add59e62ac25578270cff1b9f619", toucanContractRegistry: "0x263fa1c180889b3a3f46330f32a4a23287e99fc9", }, - mumbai: { - bct: "0xf2438a14f668b1bba53408346288f3d7c71c10a1", - nct: "0x7becba11618ca63ead5605de235f6dd3b25c530e", - offsetHelper: "0x66B1B59F9D59413dDC1539122D7d5F6b70869717", - swapper: "0x68DF99A11BD292cB91d3Fb07272062eF339d6dc1", - weth: "0xa6fa4fb5f76172d178d61b04b0ecd319c5d1c0aa", - toucanContractRegistry: "0x6739d490670b2710dc7e79bb12e455de33ee1cb6", - }, }; export default addresses; diff --git a/src/utils/graphAPIs.ts b/src/utils/graphAPIs.ts index a62f8a6..a404036 100644 --- a/src/utils/graphAPIs.ts +++ b/src/utils/graphAPIs.ts @@ -1,12 +1,17 @@ +// Description: This file contains the API URLs for the subgraphs used in the project. +// Links are sourced from https://docs.toucan.earth/developers/sdk/subgraph + export const CELO_TOUCAN_GRAPH_API_URL = - "https://api.thegraph.com/subgraphs/name/toucanprotocol/celo"; + "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/BWmN569zDopYXp3nzDukJsGDHqRstYAFULFPH8rxyVBk"; export const ALFAJORES_TOUCAN_GRAPH_API_URL = - "https://api.thegraph.com/subgraphs/name/toucanprotocol/alfajores"; + "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/4uY2L3vQW8XKYPrFFk4i6ZuJkgbpJ8SbJayc8wzMBRYw"; export const POLYGON_TOUCAN_GRAPH_API_URL = - "https://api.thegraph.com/subgraphs/name/toucanprotocol/matic"; -export const MUMBAI_TOUCAN_GRAPH_API_URL = - "https://api.thegraph.com/subgraphs/name/toucanprotocol/mumbai"; + "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/FU5APMSSCqcRy9jy56aXJiGV3PQmFQHg2tzukvSJBgwW"; export const POLYGON_SUSHI_GRAPH_API_URL = "https://api.thegraph.com/subgraphs/name/sushiswap/matic-exchange"; export const CELO_UBESWAP_GRAPH_API_URL = "https://api.thegraph.com/subgraphs/name/ubeswap/ubeswap"; +export const BASE_TOUCAN_GRAPH_API_URL = + "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/AEJ5PEDye6Z198HRQBioG6mZ6ZacHenBg2HTopZPsUCi"; +export const BASE_SEPOLIA_GRAPH_API_URL = + "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/2oKCq3rDwdYPSao4UbDZKSNbawEdhBVf3BxmqJzFe1uj"; diff --git a/src/utils/graphClients.ts b/src/utils/graphClients.ts index 4431948..33b039d 100644 --- a/src/utils/graphClients.ts +++ b/src/utils/graphClients.ts @@ -5,7 +5,6 @@ import { ALFAJORES_TOUCAN_GRAPH_API_URL, CELO_TOUCAN_GRAPH_API_URL, CELO_UBESWAP_GRAPH_API_URL, - MUMBAI_TOUCAN_GRAPH_API_URL, POLYGON_SUSHI_GRAPH_API_URL, POLYGON_TOUCAN_GRAPH_API_URL, } from "./graphAPIs"; @@ -15,8 +14,6 @@ export const getToucanGraphClient = (network: Network) => url: network === "polygon" ? POLYGON_TOUCAN_GRAPH_API_URL - : network === "mumbai" - ? MUMBAI_TOUCAN_GRAPH_API_URL : network === "celo" ? CELO_TOUCAN_GRAPH_API_URL : ALFAJORES_TOUCAN_GRAPH_API_URL, @@ -28,7 +25,7 @@ export const getToucanGraphClient = (network: Network) => export const getDexGraphClient = (network: Network) => createClient({ url: - network === "polygon" || network === "mumbai" + network === "polygon" ? POLYGON_SUSHI_GRAPH_API_URL : CELO_UBESWAP_GRAPH_API_URL, exchanges: [cacheExchange, fetchExchange], From 3ba32b603890bffa585e63845a8aef52b742542e Mon Sep 17 00:00:00 2001 From: pheuberger Date: Fri, 5 Jul 2024 14:07:29 +0300 Subject: [PATCH 2/5] feat: make Subgraph API key read from env var We want everybody to use their own API keys for Subgraph queries. However, we need an API key to run our Subgraph regression tests against live endpoints on pull requests. That's why a tightly scoped key is added to our CI workflow config. IMPORTANT: That means if you extend the regression tests to also query other networks than Alfajores, you need to make sure the API key has permissions for those networks. --- .env.example | 1 + .github/workflows/ci.yml | 3 +++ README.md | 8 ++++++-- src/utils/graphAPIs.ts | 17 +++++++---------- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 2a8f1f9..7ae4e6d 100644 --- a/.env.example +++ b/.env.example @@ -4,3 +4,4 @@ NODE_PROVIDER_MUMBAI_RPC_URL=https://rpc.ankr.com/polygon_mumbai NODE_PROVIDER_CELO_RPC_URL=https://rpc.ankr.com/celo NODE_PROVIDER_ALFAJORES_RPC_URL=https://alfajores-forno.celo-testnet.org TEST_TIMEOUT=500000 +GRAPH_API_KEY=... diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1576168..844eb2d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,6 +6,9 @@ on: pull_request: branches: [main] +env: + GRAPH_API_KEY: 0e7dd738749485cb3dceaeaa33ce3eb8 + jobs: build: runs-on: ubuntu-latest diff --git a/README.md b/README.md index eb081e6..66c62aa 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ For the full documentation, check our [docs](https://docs.toucan.earth/toucan/de ⚠️ This SDK is heavily under development. USE AT YOUR OWN RISK. ⚠️ -## Install +## Install and setup ``` npm i toucan-sdk @@ -22,6 +22,10 @@ or yarn add toucan-sdk ``` +Now, copy `.env.example` to `.env`. + +Before you can make Subgraph queries, you need to set `GRAPH_API_KEY` in your `.env` file. You can create an API key in [The Graph Studio](https://thegraph.com/studio/apikeys/) after connecting your wallet. + # Quickstart Instantiate the ToucanClient and set a `signer` & `provider` to interact with our infrastructure. @@ -161,7 +165,7 @@ The result will look like this: Now you have quite some info on the project, including its address. -## All queries: +## All queries Toucan SDK offers a lot of pre-defined queries. Try them out! diff --git a/src/utils/graphAPIs.ts b/src/utils/graphAPIs.ts index a404036..1f51445 100644 --- a/src/utils/graphAPIs.ts +++ b/src/utils/graphAPIs.ts @@ -1,17 +1,14 @@ // Description: This file contains the API URLs for the subgraphs used in the project. // Links are sourced from https://docs.toucan.earth/developers/sdk/subgraph -export const CELO_TOUCAN_GRAPH_API_URL = - "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/BWmN569zDopYXp3nzDukJsGDHqRstYAFULFPH8rxyVBk"; -export const ALFAJORES_TOUCAN_GRAPH_API_URL = - "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/4uY2L3vQW8XKYPrFFk4i6ZuJkgbpJ8SbJayc8wzMBRYw"; -export const POLYGON_TOUCAN_GRAPH_API_URL = - "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/FU5APMSSCqcRy9jy56aXJiGV3PQmFQHg2tzukvSJBgwW"; +const { GRAPH_API_KEY } = process.env; + +export const CELO_TOUCAN_GRAPH_API_URL = `https://gateway-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/BWmN569zDopYXp3nzDukJsGDHqRstYAFULFPH8rxyVBk`; +export const ALFAJORES_TOUCAN_GRAPH_API_URL = `https://gateway-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/4uY2L3vQW8XKYPrFFk4i6ZuJkgbpJ8SbJayc8wzMBRYw`; +export const POLYGON_TOUCAN_GRAPH_API_URL = `https://gateway-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/FU5APMSSCqcRy9jy56aXJiGV3PQmFQHg2tzukvSJBgwW`; export const POLYGON_SUSHI_GRAPH_API_URL = "https://api.thegraph.com/subgraphs/name/sushiswap/matic-exchange"; export const CELO_UBESWAP_GRAPH_API_URL = "https://api.thegraph.com/subgraphs/name/ubeswap/ubeswap"; -export const BASE_TOUCAN_GRAPH_API_URL = - "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/AEJ5PEDye6Z198HRQBioG6mZ6ZacHenBg2HTopZPsUCi"; -export const BASE_SEPOLIA_GRAPH_API_URL = - "https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/2oKCq3rDwdYPSao4UbDZKSNbawEdhBVf3BxmqJzFe1uj"; +export const BASE_TOUCAN_GRAPH_API_URL = `https://gateway-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/AEJ5PEDye6Z198HRQBioG6mZ6ZacHenBg2HTopZPsUCi`; +export const BASE_SEPOLIA_GRAPH_API_URL = `https://gateway-arbitrum.network.thegraph.com/api/${GRAPH_API_KEY}/subgraphs/id/2oKCq3rDwdYPSao4UbDZKSNbawEdhBVf3BxmqJzFe1uj`; From 674efaafa28094f81dce7a43acb7d9528badf60f Mon Sep 17 00:00:00 2001 From: pheuberger Date: Fri, 5 Jul 2024 18:36:01 +0300 Subject: [PATCH 3/5] chore: disable token price getter tests Sushiswap and Ubeswap migrated to the decentralized network and also their API changed. This needs to be a slightly bigger rework that will be tracked in LILA-7487. This is a problem because the CI is breaking because of it. --- README.md | 3 +++ src/index.ts | 3 +++ test/subgraph.test.ts | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 66c62aa..c019cae 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,9 @@ If you don't have a signer nor a provider set, you can only interact with the su ## Fetch pool prices from a Dex +IMPORTANT: +_Fetching pool prices is currently not working. We are working on a fix for this._ + You can find pools for Toucan pool tokens on [Celo Network](https://celo.org) at [Uniswap](https://uniswap.org/) and for [Polygon Network](https://polygon.technology) on [SushiSwap](sushi.com). Something that may come in handy in your applications is fetching the USD price of our pool tokens. diff --git a/src/index.ts b/src/index.ts index b9cdd30..b9eed73 100644 --- a/src/index.ts +++ b/src/index.ts @@ -830,6 +830,9 @@ export default class ToucanClient { // -------------------------------------------------------------------------------- // -------------------------------------------------------------------------------- + // FIXME: The SushiSwap and Ubeswap Subgraph APIs that are used to get token + // market prices have changed slightly. This function breaks currently. Work + // on it is tracked in LILA-7487. fetchTokenPriceOnDex = async ( pool: PoolSymbol ): Promise<{ diff --git a/test/subgraph.test.ts b/test/subgraph.test.ts index ba422bd..682391a 100644 --- a/test/subgraph.test.ts +++ b/test/subgraph.test.ts @@ -67,11 +67,11 @@ describe("Testing Toucan-SDK subgraph interactions", function () { expect(await toucan.fetchAggregations()).to.not.throw; }); - it("Should fetch price of BCT", async function () { + xit("Should fetch price of BCT", async function () { expect(await toucan.fetchTokenPriceOnDex("BCT")).to.not.throw; }); - it("Should fetch price of NCT", async function () { + xit("Should fetch price of NCT", async function () { expect(await toucan.fetchTokenPriceOnDex("NCT")).to.not.throw; }); }); From 3963b5ee7a7ce3ba636c0297db97a71775eef3f8 Mon Sep 17 00:00:00 2001 From: pheuberger Date: Mon, 8 Jul 2024 14:11:24 +0300 Subject: [PATCH 4/5] chore(docs): update subgraph playground url Without this patch the matic playground URL was still pointing to the discontinued Hosted Service. I used the opportunity to also add links to all other playgrounds. --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c019cae..d244d58 100644 --- a/README.md +++ b/README.md @@ -213,7 +213,14 @@ await toucan.fetchAggregations(); Now that you have an overview of our pre-build queries, let's have a look at the `fetchCustomQuery` method. -This allows you to fetch with your own queries and can be very powerful if you know graphQL. You can also check out a lot of example queries in our subgraph [playgrounds](https://thegraph.com/hosted-service/subgraph/toucanprotocol/matic). +This allows you to fetch with your own queries and can be very powerful if you know graphQL. You can also check out a lot of example queries in our Subgraph playgrounds: + +- [Matic](https://thegraph.com/explorer/subgraphs/FU5APMSSCqcRy9jy56aXJiGV3PQmFQHg2tzukvSJBgwW) +- [Celo](https://thegraph.com/explorer/subgraphs/BWmN569zDopYXp3nzDukJsGDHqRstYAFULFPH8rxyVBk) +- [Base](https://thegraph.com/explorer/subgraphs/AEJ5PEDye6Z198HRQBioG6mZ6ZacHenBg2HTopZPsUCi) +- [Alfajores](https://thegraph.com/explorer/subgraphs/4uY2L3vQW8XKYPrFFk4i6ZuJkgbpJ8SbJayc8wzMBRYw) +- [Base Sepolia](https://thegraph.com/explorer/subgraphs/2oKCq3rDwdYPSao4UbDZKSNbawEdhBVf3BxmqJzFe1uj) +- [Amoy](https://thegraph.com/explorer/subgraphs/FKzFZuYHxyHiiDmdW9Qvwtet1Ad1ERsvjWMhhqd9V8pk) - Getting all infos on a carbon project (`region` stands for the country) From 316a4543c852d5a12d7f86ebd00889663cf7e50f Mon Sep 17 00:00:00 2001 From: pheuberger Date: Mon, 8 Jul 2024 15:59:54 +0300 Subject: [PATCH 5/5] chore: bumped version to 1.0.6-beta --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ac3d8f0..4b7d76c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "toucan-sdk", - "version": "1.0.5-beta", + "version": "1.0.6-beta", "description": "A JavaScript SDK for Toucan Protocol. Works in the web browser and Node.js.", "main": "./dist/index.js", "scripts": {