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

Ampleforth subgraph key init #248

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions frontend/.env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ESLINT_NO_DEV_ERRORS=true
SKIP_PREFLIGHT_CHECK=true
GRAPH_API_KEY=xyz123
4 changes: 3 additions & 1 deletion frontend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
44 changes: 27 additions & 17 deletions frontend/src/utils/ampleforth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<entities.XCRebaseData[]>(
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<entities.XCRebaseData[]>(
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<entities.RebaseData[]>(
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<entities.RebaseData[]>(
async () => (await getRebases(policy, chainId)).map((r) => r.rawData),
`${policy.address}|rebases|${policy.epoch.toString()}`,
DAY_IN_MS,
)

export const computeAMPLRewardShares = async (
rewardSchedules: RewardSchedule[],
Expand All @@ -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) =>
Expand All @@ -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) =>
Expand Down
8 changes: 4 additions & 4 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down