From 1d5a16720b3ac9f59bce6e91988939b56edf4319 Mon Sep 17 00:00:00 2001 From: nms-7 Date: Sun, 17 Jul 2022 13:34:08 -0400 Subject: [PATCH 1/3] updates ampleforthorg/sdk --- frontend/package.json | 2 +- frontend/yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/frontend/package.json b/frontend/package.json index a23d9c88..1fab6104 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -3,7 +3,7 @@ "version": "0.1.0", "private": true, "dependencies": { - "@ampleforthorg/sdk": "1.0.18", + "@ampleforthorg/sdk": "1.0.27", "@apollo/client": "^3.3.16", "@craco/craco": "^6.1.2", "@headlessui/react": "^1.4.1", diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 3109bf9d..0a208822 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -2,10 +2,10 @@ # yarn lockfile v1 -"@ampleforthorg/sdk@1.0.18": - version "1.0.18" - resolved "https://registry.yarnpkg.com/@ampleforthorg/sdk/-/sdk-1.0.18.tgz#49d936c4db52d7249a4e293215ee995db1f3b35f" - integrity sha512-UavhESOzRKrxWMmGZmiXtobudPGL3jMd1j/MLT4/MCYJqBvDHIBdGn3M5JYqacDv+tqFc1xpm/4mSkLMZzaavQ== +"@ampleforthorg/sdk@1.0.27": + version "1.0.27" + resolved "https://registry.yarnpkg.com/@ampleforthorg/sdk/-/sdk-1.0.27.tgz#cff9c069c17eca7050bf697f6dfae04c92e0664f" + integrity sha512-9XLebQ6moTRa3Uxx2PqTx124noPXx6evbT8Zwxmv3ITNG3Fa4+sNVWqdJakfbcKNXfEARHoIoMPoOIuk+zD3tQ== dependencies: "@types/bignumber.js" "^5.0.0" "@typescript-eslint/eslint-plugin" "^4.29.0" From 696ef22890944d2f72624372f541a5cab97adfba Mon Sep 17 00:00:00 2001 From: nms-7 Date: Sun, 17 Jul 2022 13:34:47 -0400 Subject: [PATCH 2/3] updates ampleforth sdk utils to initialize subgraph api key --- frontend/src/utils/ampleforth.ts | 44 ++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/frontend/src/utils/ampleforth.ts b/frontend/src/utils/ampleforth.ts index 4e16c577..e46704a8 100644 --- a/frontend/src/utils/ampleforth.ts +++ b/frontend/src/utils/ampleforth.ts @@ -3,25 +3,33 @@ import { getRebases, getXCAmpleController, getXCRebases, - entities -} from '@ampleforthorg/sdk'; + entities, + queries, +} from '@ampleforthorg/sdk' import { formatUnits } from 'ethers/lib/utils' import { Signer, providers } from 'ethers' import { RewardSchedule, SignerOrProvider } from '../types' import * as ls from './cache' -import {DAY_IN_MS} from '../constants' +import { DAY_IN_MS } from '../constants' -const loadXCRebasesFromCache = async (controller:entities.XCController, chainId:number) => ls.computeAndCache( - async () => (await getXCRebases(controller, chainId)).map(r => r.rawData), - `${controller.address}|xc_rebases|${controller.epoch.toString()}`, - DAY_IN_MS, -) +const loadGraphApiKey = () => { + const key = process.env.GRAPH_API_KEY + queries.initializeApiKey(key) +} + +const loadXCRebasesFromCache = async (controller: entities.XCController, chainId: number) => + ls.computeAndCache( + async () => (await getXCRebases(controller, chainId)).map((r) => r.rawData), + `${controller.address}|xc_rebases|${controller.epoch.toString()}`, + DAY_IN_MS, + ) -const loadRebasesFromCache = async (policy:entities.Policy, chainId:number) => ls.computeAndCache( - async () => (await getRebases(policy, chainId)).map(r => r.rawData), - `${policy.address}|rebases|${policy.epoch.toString()}`, - DAY_IN_MS, -) +const loadRebasesFromCache = async (policy: entities.Policy, chainId: number) => + ls.computeAndCache( + async () => (await getRebases(policy, chainId)).map((r) => r.rawData), + `${policy.address}|rebases|${policy.epoch.toString()}`, + DAY_IN_MS, + ) export const computeAMPLRewardShares = async ( rewardSchedules: RewardSchedule[], @@ -33,12 +41,14 @@ export const computeAMPLRewardShares = async ( signerOrProvider: SignerOrProvider, ) => { const provider = (signerOrProvider as Signer).provider || (signerOrProvider as providers.Provider) - const {chainId} = await provider.getNetwork() + const { chainId } = await provider.getNetwork() + + loadGraphApiKey() - if(isCrossChain){ + if (isCrossChain) { const controller = await getXCAmpleController(chainId) const rebases = await loadXCRebasesFromCache(controller, chainId) - controller.loadHistoricalRebases(rebases.map(r => new entities.XCRebase(r))) + controller.loadHistoricalRebases(rebases.map((r) => new entities.XCRebase(r))) // const rebases = await getXCRebases(controller, chainId) // controller.loadHistoricalRebases(rebases) const getShares = (schedule: RewardSchedule) => @@ -48,7 +58,7 @@ export const computeAMPLRewardShares = async ( const policy = await getAmpleforthPolicy(chainId) const rebases = await loadRebasesFromCache(policy, chainId) - policy.loadHistoricalRebases(rebases.map(r => new entities.Rebase(r))) + policy.loadHistoricalRebases(rebases.map((r) => new entities.Rebase(r))) // const rebases = await getRebases(policy, chainId) // policy.loadHistoricalRebases(rebases) const getShares = (schedule: RewardSchedule) => From a1d29f7b55fc5e4e3dd03c51e759f09b71bfe797 Mon Sep 17 00:00:00 2001 From: nms-7 Date: Sun, 17 Jul 2022 13:35:08 -0400 Subject: [PATCH 3/3] updates docs to note GRAPH_API_KEY env variable --- frontend/.env.sample | 1 + frontend/README.md | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/frontend/.env.sample b/frontend/.env.sample index 4cb60f03..6e044038 100644 --- a/frontend/.env.sample +++ b/frontend/.env.sample @@ -1,2 +1,3 @@ ESLINT_NO_DEV_ERRORS=true SKIP_PREFLIGHT_CHECK=true +GRAPH_API_KEY=xyz123 diff --git a/frontend/README.md b/frontend/README.md index 57a6854d..a9c49a0a 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -20,7 +20,7 @@ Jump to The following are the main elements that need to be configured prior to deploying 1. [GraphQL Endpoint for subgraph](#graphql-endpoint) -2. [Environment variable `NODE_ENV`](#process-environment) +2. [Environment variables `NODE_ENV`, `GRAPH_API_KEY`](#process-environment) 3. [Geysers configuration](#geyser-specific-configuration) 4. [List of additional tokens for vault management](#list-of-additional-tokens) 5. [Infura Project ID](#ethereum-provider) @@ -37,6 +37,8 @@ The initialization of the GraphQL client can be found under `src/queries/client. Make sure that the environment variable `NODE_ENV` is set to something other than `development` when deploying to production. +Make sure that `GRAPH_API_KEY` is set to a funded API Key that is unrestricted from using the Ampleforth DAO Subgraph (see https://thegraph.com/docs/en/querying/managing-api-keys/) for using the Graph. + ## Geyser Specific Configuration