Skip to content

Commit

Permalink
using internal subgraph endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
aalavandhan committed Jun 27, 2024
1 parent 067838d commit 1257645
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 45 deletions.
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.32",
"@apollo/client": "^3.3.16",
"@craco/craco": "^6.1.2",
"@headlessui/react": "^1.4.1",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/config/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const networkConfig: NetworkConfig = {
ref: 'mainnet',
name: 'Ethereum',
rpcUrl: `https://eth-mainnet.alchemyapi.io/v2/${ALCHEMY_PROJECT_ID}`,
graphUrl: 'https://api.thegraph.com/subgraphs/name/aalavandhan/amplgeyserv2beta',
graphUrl: `https://web-api.ampleforth.org/graph-cache/ampleforth-token-geyser`,
explorerUrl: 'https://etherscan.io/tx',
nativeCurrency: {
name: 'Ethereum',
Expand Down Expand Up @@ -220,7 +220,7 @@ const additionalTokens: AppAdditionalTokensList = {
],
}

export const activeNetworks: Network[] = [Network.Mainnet, Network.Avalanche]
export const activeNetworks: Network[] = [Network.Mainnet]

export function getConnectionConfig(networkId: number | null): ConnectionConfig {
return networkConfig[networkId as Network] || networkConfig[Network.Mainnet]
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/queries/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ export const makeClient = (networkId: number | null) => {
uri: graphUrl,
cache: new InMemoryCache(),
})
}
}
24 changes: 15 additions & 9 deletions frontend/src/utils/ampleforth.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { getAmpleforthPolicy, getRebases, getXCAmpleController, getXCRebases, entities } from '@ampleforthorg/sdk'
import { getAmpleforthPolicy, getRebases, getXCAmpleController, getXCRebases, queries, entities } 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'

const AMPLEFORTH_CORE_GRAPHQL_ENDPOINT = "https://web-api.ampleforth.org/graph-cache/ampleforth-core"
const getClient = (chainId) => {
const endpoint = (chainId === 1) ? AMPLEFORTH_CORE_GRAPHQL_ENDPOINT : queries.graphHostedURL(chainId);
return queries.initializeClient(endpoint)
}

const loadXCRebasesFromCache = async (controller: entities.XCController, chainId: number) =>
ls.computeAndCache<entities.XCRebaseData[]>(
async () => (await getXCRebases(controller, chainId)).map((r) => r.rawData),
async () => (await getXCRebases(controller, chainId, getClient(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),
async () => (await getRebases(policy, chainId, getClient(chainId))).map((r) => r.rawData),
`${policy.address}|rebases|${policy.epoch.toString()}`,
DAY_IN_MS,
)
Expand All @@ -32,20 +38,20 @@ export const computeAMPLRewardShares = async (
const { chainId } = await provider.getNetwork()

if (isCrossChain) {
const controller = await getXCAmpleController(chainId)
const rebases = await loadXCRebasesFromCache(controller, chainId)
const controller = await getXCAmpleController(chainId, getClient(chainId))
const rebases = await loadXCRebasesFromCache(controller, chainId, getClient(chainId))
controller.loadHistoricalRebases(rebases.map((r) => new entities.XCRebase(r)))
// const rebases = await getXCRebases(controller, chainId)
// const rebases = await getXCRebases(controller, chainId, getClient(chainId))
// controller.loadHistoricalRebases(rebases)
const getShares = (schedule: RewardSchedule) =>
parseFloat(formatUnits(schedule.rewardAmount, decimals)) / controller.getSupplyOn(schedule.start).toNumber()
return rewardSchedules.reduce((acc, schedule) => acc + getShares(schedule), 0)
}

const policy = await getAmpleforthPolicy(chainId)
const rebases = await loadRebasesFromCache(policy, chainId)
const policy = await getAmpleforthPolicy(chainId, getClient(chainId))
const rebases = await loadRebasesFromCache(policy, chainId, getClient(chainId))
policy.loadHistoricalRebases(rebases.map((r) => new entities.Rebase(r)))
// const rebases = await getRebases(policy, chainId)
// const rebases = await getRebases(policy, chainId, getClient(chainId))
// policy.loadHistoricalRebases(rebases)
const getShares = (schedule: RewardSchedule) =>
parseFloat(formatUnits(schedule.rewardAmount, decimals)) / policy.getSupplyOn(schedule.start).toNumber()
Expand Down
58 changes: 26 additions & 32 deletions frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@
# yarn lockfile v1


"@ampleforthorg/[email protected]":
version "1.0.18"
resolved "https://registry.yarnpkg.com/@ampleforthorg/sdk/-/sdk-1.0.18.tgz#49d936c4db52d7249a4e293215ee995db1f3b35f"
integrity sha512-UavhESOzRKrxWMmGZmiXtobudPGL3jMd1j/MLT4/MCYJqBvDHIBdGn3M5JYqacDv+tqFc1xpm/4mSkLMZzaavQ==
"@0no-co/graphql.web@^1.0.5":
version "1.0.7"
resolved "https://registry.yarnpkg.com/@0no-co/graphql.web/-/graphql.web-1.0.7.tgz#c7a762c887b3482a79ffa68f63de5e96059a62e4"
integrity sha512-E3Qku4mTzdrlwVWGPxklDnME5ANrEGetvYw4i2GCRlppWXXE4QD66j7pwb8HelZwS6LnqEChhrSOGCXpbiu6MQ==

"@ampleforthorg/[email protected]":
version "1.0.32"
resolved "https://registry.yarnpkg.com/@ampleforthorg/sdk/-/sdk-1.0.32.tgz#04df04c69a388b0e18531222c29baa59ed288963"
integrity sha512-q05O05sc8cd/pW+nuh7WsqCKT4rcw/ff+FI9JUtcl4q4R0VL2VGhIn8+RIUQMkRfeDI4huFduRL1RrdWkaEBRg==
dependencies:
"@types/bignumber.js" "^5.0.0"
"@typescript-eslint/eslint-plugin" "^4.29.0"
Expand All @@ -19,7 +24,7 @@
prettier "^2.3.2"
tiny-invariant "^1.1.0"
typescript "^4.3.5"
urql "^2.0.4"
urql "^4.0.0"

"@ampproject/remapping@^2.0.0":
version "2.0.3"
Expand Down Expand Up @@ -2313,11 +2318,6 @@
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.0.tgz#0eee6373e11418bfe0b5638f654df7a4ca6a3950"
integrity sha512-wYn6r8zVZyQJ6rQaALBEln5B1pzxb9shV5Ef97kTvn6yVGrqyXVnDqnU24MXnFubR+rZjBY9NWuxX3FB2sTsjg==

"@graphql-typed-document-node/core@^3.1.1":
version "3.1.1"
resolved "https://registry.yarnpkg.com/@graphql-typed-document-node/core/-/core-3.1.1.tgz#076d78ce99822258cf813ecc1e7fa460fa74d052"
integrity sha512-NQ17ii0rK1b34VZonlmT2QMJFI70m0TRwbknO/ihlbatXyaktDhN/98vBiUU6kNBPljqGqyIrl2T4nY2RpFANg==

"@hapi/[email protected]":
version "2.1.4"
resolved "https://registry.yarnpkg.com/@hapi/address/-/address-2.1.4.tgz#5d67ed43f3fd41a69d4b9ff7b56e7c0d1d0a81e5"
Expand Down Expand Up @@ -3802,13 +3802,13 @@
"@typescript-eslint/types" "4.33.0"
eslint-visitor-keys "^2.0.0"

"@urql/core@^2.4.1":
version "2.4.1"
resolved "https://registry.yarnpkg.com/@urql/core/-/core-2.4.1.tgz#bae449dafe98fb4944f3be61eb8e70ba33f8a46d"
integrity sha512-HnS54oNwO4pAACKl/2/tNLbRrxAxKawVJuG9UPiixqeEVekiecUQQnCjb9SpOW4Qr54HYzCMDbr3c5px3hfEEg==
"@urql/core@^5.0.0":
version "5.0.4"
resolved "https://registry.yarnpkg.com/@urql/core/-/core-5.0.4.tgz#e5d0e185d0833ebf277be58bd6603fd53e48e07f"
integrity sha512-gl86J6B6gWXvvkx5omZ+CaGiPQ0chCUGM0jBsm0zTtkDQPRqufv0NSUN6sp2JhGGtTOB0NR6Pd+w7XAVGGyUOA==
dependencies:
"@graphql-typed-document-node/core" "^3.1.1"
wonka "^4.0.14"
"@0no-co/graphql.web" "^1.0.5"
wonka "^6.3.2"

"@walletconnect/browser-utils@^1.4.1":
version "1.4.1"
Expand Down Expand Up @@ -16467,19 +16467,13 @@ url@^0.11.0:
punycode "1.3.2"
querystring "0.2.0"

urql@^2.0.4:
version "2.1.3"
resolved "https://registry.yarnpkg.com/urql/-/urql-2.1.3.tgz#4bfe631db03dc059738ff774b46244bf1a755c6d"
integrity sha512-S6GaKM7NJLed25L2qdZxaWFjWggXQHrneEVEe47+ZTQWxmfyV05STMl6DhtnZqb6n1wdT/KUljHkggz0kiE3NA==
urql@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/urql/-/urql-4.1.0.tgz#a75efe572d7b2e69103649a8457d3a63fce31ee8"
integrity sha512-NfbfTvxy1sM89EQAJWm89qJZihUWk7BSMfrWgfljFXLOf+e7RK7DtV/Tbg2+82HnCG2x3LcEOJenxiFSYEC+bw==
dependencies:
"@urql/core" "^2.4.1"
use-sync-external-store "1.0.0-rc.0 || ^1.0.0"
wonka "^4.0.14"

"[email protected] || ^1.0.0":
version "1.0.0-rc.0"
resolved "https://registry.yarnpkg.com/use-sync-external-store/-/use-sync-external-store-1.0.0-rc.0.tgz#0d8fb7cbc31ddfb3ee01225f6b0a700cf59c449b"
integrity sha512-0U9Xlc2QDFzSGMB0DvcJQL0+DIdxDPJC7mnZlYFbl7wrSrPMcs89X5TVkNB6Dzg618m8lZop+U+J6ow3vq9RAQ==
"@urql/core" "^5.0.0"
wonka "^6.3.2"

use@^3.1.0:
version "3.1.1"
Expand Down Expand Up @@ -17307,10 +17301,10 @@ [email protected]:
dependencies:
window-getters "^1.0.0"

wonka@^4.0.14:
version "4.0.15"
resolved "https://registry.yarnpkg.com/wonka/-/wonka-4.0.15.tgz#9aa42046efa424565ab8f8f451fcca955bf80b89"
integrity sha512-U0IUQHKXXn6PFo9nqsHphVCE5m3IntqZNB9Jjn7EB1lrR7YTDY3YWgFvEvwniTzXSvOH/XMzAZaIfJF/LvHYXg==
wonka@^6.3.2:
version "6.3.4"
resolved "https://registry.yarnpkg.com/wonka/-/wonka-6.3.4.tgz#76eb9316e3d67d7febf4945202b5bdb2db534594"
integrity sha512-CjpbqNtBGNAeyNS/9W6q3kSkKE52+FjIj7AkFlLr11s/VWGUu6a2CdYSdGxocIhIVjaW/zchesBQUKPVU69Cqg==

word-wrap@^1.2.3, word-wrap@~1.2.3:
version "1.2.3"
Expand Down

0 comments on commit 1257645

Please sign in to comment.