1
- import { getAmpleforthPolicy , getRebases , getXCAmpleController , getXCRebases , entities } from '@ampleforthorg/sdk'
1
+ import { getAmpleforthPolicy , getRebases , getXCAmpleController , getXCRebases , queries , entities } from '@ampleforthorg/sdk'
2
2
import { formatUnits } from 'ethers/lib/utils'
3
3
import { Signer , providers } from 'ethers'
4
4
import { RewardSchedule , SignerOrProvider } from '../types'
5
5
import * as ls from './cache'
6
6
import { DAY_IN_MS } from '../constants'
7
7
8
+ const AMPLEFORTH_CORE_GRAPHQL_ENDPOINT = "https://web-api.ampleforth.org/graph-cache/ampleforth-core"
9
+ const getClient = ( chainId ) => {
10
+ const endpoint = ( chainId === 1 ) ? AMPLEFORTH_CORE_GRAPHQL_ENDPOINT : queries . graphHostedURL ( chainId ) ;
11
+ return queries . initializeClient ( endpoint )
12
+ }
13
+
8
14
const loadXCRebasesFromCache = async ( controller : entities . XCController , chainId : number ) =>
9
15
ls . computeAndCache < entities . XCRebaseData [ ] > (
10
- async ( ) => ( await getXCRebases ( controller , chainId ) ) . map ( ( r ) => r . rawData ) ,
16
+ async ( ) => ( await getXCRebases ( controller , chainId , getClient ( chainId ) ) ) . map ( ( r ) => r . rawData ) ,
11
17
`${ controller . address } |xc_rebases|${ controller . epoch . toString ( ) } ` ,
12
18
DAY_IN_MS ,
13
19
)
14
20
15
21
const loadRebasesFromCache = async ( policy : entities . Policy , chainId : number ) =>
16
22
ls . computeAndCache < entities . RebaseData [ ] > (
17
- async ( ) => ( await getRebases ( policy , chainId ) ) . map ( ( r ) => r . rawData ) ,
23
+ async ( ) => ( await getRebases ( policy , chainId , getClient ( chainId ) ) ) . map ( ( r ) => r . rawData ) ,
18
24
`${ policy . address } |rebases|${ policy . epoch . toString ( ) } ` ,
19
25
DAY_IN_MS ,
20
26
)
@@ -32,20 +38,20 @@ export const computeAMPLRewardShares = async (
32
38
const { chainId } = await provider . getNetwork ( )
33
39
34
40
if ( isCrossChain ) {
35
- const controller = await getXCAmpleController ( chainId )
36
- const rebases = await loadXCRebasesFromCache ( controller , chainId )
41
+ const controller = await getXCAmpleController ( chainId , getClient ( chainId ) )
42
+ const rebases = await loadXCRebasesFromCache ( controller , chainId , getClient ( chainId ) )
37
43
controller . loadHistoricalRebases ( rebases . map ( ( r ) => new entities . XCRebase ( r ) ) )
38
- // const rebases = await getXCRebases(controller, chainId)
44
+ // const rebases = await getXCRebases(controller, chainId, getClient(chainId) )
39
45
// controller.loadHistoricalRebases(rebases)
40
46
const getShares = ( schedule : RewardSchedule ) =>
41
47
parseFloat ( formatUnits ( schedule . rewardAmount , decimals ) ) / controller . getSupplyOn ( schedule . start ) . toNumber ( )
42
48
return rewardSchedules . reduce ( ( acc , schedule ) => acc + getShares ( schedule ) , 0 )
43
49
}
44
50
45
- const policy = await getAmpleforthPolicy ( chainId )
46
- const rebases = await loadRebasesFromCache ( policy , chainId )
51
+ const policy = await getAmpleforthPolicy ( chainId , getClient ( chainId ) )
52
+ const rebases = await loadRebasesFromCache ( policy , chainId , getClient ( chainId ) )
47
53
policy . loadHistoricalRebases ( rebases . map ( ( r ) => new entities . Rebase ( r ) ) )
48
- // const rebases = await getRebases(policy, chainId)
54
+ // const rebases = await getRebases(policy, chainId, getClient(chainId) )
49
55
// policy.loadHistoricalRebases(rebases)
50
56
const getShares = ( schedule : RewardSchedule ) =>
51
57
parseFloat ( formatUnits ( schedule . rewardAmount , decimals ) ) / policy . getSupplyOn ( schedule . start ) . toNumber ( )
0 commit comments