@stake-dao/reader 0.4.51 → 0.4.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/abis/passiveVaultsMulticall.js +56 -0
- package/dist/esm/abis/passiveVaultsMulticall.js.map +1 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/prices.js +9 -5
- package/dist/esm/prices.js.map +1 -1
- package/dist/esm/strategies/passive/fetch.js +73 -0
- package/dist/esm/strategies/passive/fetch.js.map +1 -0
- package/dist/esm/strategies/passive/httpCalls.js +35 -0
- package/dist/esm/strategies/passive/httpCalls.js.map +1 -0
- package/dist/esm/strategies/stakeDao/fetch.js +107 -0
- package/dist/esm/strategies/stakeDao/fetch.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/votemarket/curve/fetchUserVlCvxClaimable.js +10 -9
- package/dist/esm/votemarket/curve/fetchUserVlCvxClaimable.js.map +1 -1
- package/dist/types/abis/passiveVaultsMulticall.d.ts +33 -0
- package/dist/types/abis/passiveVaultsMulticall.d.ts.map +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/prices.d.ts.map +1 -1
- package/dist/types/strategies/passive/fetch.d.ts +161 -0
- package/dist/types/strategies/passive/fetch.d.ts.map +1 -0
- package/dist/types/strategies/passive/httpCalls.d.ts +8 -0
- package/dist/types/strategies/passive/httpCalls.d.ts.map +1 -0
- package/dist/types/strategies/stakeDao/fetch.d.ts +78 -0
- package/dist/types/strategies/stakeDao/fetch.d.ts.map +1 -0
- package/dist/types/votemarket/curve/fetchUserVlCvxClaimable.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/abis/passiveVaultsMulticall.ts +56 -0
- package/src/index.ts +6 -0
- package/src/prices.ts +10 -5
- package/src/strategies/passive/fetch.ts +97 -0
- package/src/strategies/passive/httpCalls.ts +42 -0
- package/src/strategies/stakeDao/fetch.ts +128 -0
- package/src/votemarket/curve/fetchUserVlCvxClaimable.ts +15 -10
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { CURVE_API_URL } from '../curve/endpoints.js'
|
|
2
|
+
|
|
3
|
+
export const getPassiveHttpCalls = async (chainId: number) => {
|
|
4
|
+
switch (chainId) {
|
|
5
|
+
case 1: {
|
|
6
|
+
const ethHttpCalls = [
|
|
7
|
+
// Curve Apis
|
|
8
|
+
(await fetch(`${CURVE_API_URL}/getPools/ethereum/main`)).json(),
|
|
9
|
+
(await fetch(`${CURVE_API_URL}/getSubgraphData/ethereum`)).json(),
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
const ethHttpResponses = await Promise.all(ethHttpCalls)
|
|
13
|
+
|
|
14
|
+
const ethCurveMain = ethHttpResponses[0].data.poolData
|
|
15
|
+
const ethCurveSubgraph = ethHttpResponses[1].data.poolList
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
curveSubgraphData: ethCurveSubgraph,
|
|
19
|
+
curveApiData: [{ type: 'main', value: ethCurveMain }],
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
case 137: {
|
|
23
|
+
const polygonHttpCalls = [
|
|
24
|
+
// Curve Apis
|
|
25
|
+
(await fetch(`${CURVE_API_URL}/getPools/polygon/main`)).json(),
|
|
26
|
+
(await fetch(`${CURVE_API_URL}/getSubgraphData/polygon`)).json(),
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
const polygonHttpResponses = await Promise.all(polygonHttpCalls)
|
|
30
|
+
|
|
31
|
+
const polygonCurveMain = polygonHttpResponses[0].data.poolData
|
|
32
|
+
const polygonCurveSubgraph = polygonHttpResponses[1].data.poolList
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
curveSubgraphData: polygonCurveSubgraph,
|
|
36
|
+
curveApiData: [{ type: 'main', value: polygonCurveMain }],
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return { curveSubgraphData: undefined, curveApiData: [] }
|
|
42
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { contract, stakeDaoStrats } from '@stake-dao/constants'
|
|
2
|
+
import { formatUnits, parseAbi, zeroAddress } from 'viem'
|
|
3
|
+
import type { Price } from '../../prices.js'
|
|
4
|
+
import { multicall } from '../../utils.js'
|
|
5
|
+
import getAverageYearlyRewards from '../../utils/getAverageYearlyRewards.js'
|
|
6
|
+
|
|
7
|
+
const baseQueryParams = {
|
|
8
|
+
module: 'logs',
|
|
9
|
+
action: 'getLogs',
|
|
10
|
+
fromBlock: `${20061000}`,
|
|
11
|
+
address: '0xCe00aD8DF94D8C365dc415B84963aA37A06bE923',
|
|
12
|
+
topic0: '0x4882c2b96bd65ac9234537053e19a51399df7ee5f67f5f20256bfff49f7389a5',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
interface TFetchStakeDao {
|
|
16
|
+
provider: any
|
|
17
|
+
chainId: number
|
|
18
|
+
lockers: any[]
|
|
19
|
+
prices: Price[]
|
|
20
|
+
explorerApiKey: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const fetchStakeDao = async ({ provider, chainId, lockers, prices, explorerApiKey }: TFetchStakeDao) => {
|
|
24
|
+
let amountPerYear = 0
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const queryParams = { ...baseQueryParams, chainid: `${chainId}`, apikey: explorerApiKey }
|
|
28
|
+
const url = `https://api.etherscan.io/v2/api?${new URLSearchParams(queryParams)}`
|
|
29
|
+
|
|
30
|
+
const rawEventsData = await (await fetch(url)).json()
|
|
31
|
+
amountPerYear = await getAverageYearlyRewards(rawEventsData, 5)
|
|
32
|
+
} catch {
|
|
33
|
+
amountPerYear = 0
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const rawData: any = await multicall(
|
|
37
|
+
provider,
|
|
38
|
+
[
|
|
39
|
+
{
|
|
40
|
+
address: contract('veSdtBoostDelegation'),
|
|
41
|
+
name: 'received_balance',
|
|
42
|
+
params: [contract('voteBoosterStrategy')],
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
parseAbi(['function received_balance(address user) external view returns (uint256)']),
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
const parsedData = stakeDaoStrats.strats.map((s, index) => {
|
|
49
|
+
const locker = lockers.find((l) => l.id === s.lockerId)
|
|
50
|
+
const boost = locker.voteBooster?.boost || 0
|
|
51
|
+
const lpPriceInUsd = prices.find((p) => p.symbol === 'SDT')?.usdPrice || 0
|
|
52
|
+
|
|
53
|
+
const totalSupply = rawData[index].result
|
|
54
|
+
const tvl = lpPriceInUsd * Number(formatUnits(totalSupply, 18))
|
|
55
|
+
|
|
56
|
+
const currentApr = ((amountPerYear * lpPriceInUsd) / tvl) * 100
|
|
57
|
+
const projectedApr = locker?.rewards ? locker.rewards.reduce((total, r) => (total += r.apr), 0) : 0
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
key: s.key,
|
|
61
|
+
name: s.name,
|
|
62
|
+
subname: s.subname,
|
|
63
|
+
type: s.type,
|
|
64
|
+
protocol: s.protocol,
|
|
65
|
+
chainId: s.chainId,
|
|
66
|
+
vault: s.vault,
|
|
67
|
+
lpToken: s.lpToken,
|
|
68
|
+
coins: s.coins,
|
|
69
|
+
underlyingCoins: s.underlyingCoins,
|
|
70
|
+
vSdToken: s.vSdToken,
|
|
71
|
+
lpPriceInUsd,
|
|
72
|
+
streaming: amountPerYear > 0,
|
|
73
|
+
tvl,
|
|
74
|
+
apr: {
|
|
75
|
+
boost,
|
|
76
|
+
current: {
|
|
77
|
+
total: currentApr,
|
|
78
|
+
details: [
|
|
79
|
+
{
|
|
80
|
+
label: 'SDT',
|
|
81
|
+
value: [currentApr],
|
|
82
|
+
},
|
|
83
|
+
],
|
|
84
|
+
},
|
|
85
|
+
projected: {
|
|
86
|
+
total: projectedApr,
|
|
87
|
+
details: [
|
|
88
|
+
{
|
|
89
|
+
label: 'SDT',
|
|
90
|
+
value: [projectedApr],
|
|
91
|
+
},
|
|
92
|
+
],
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
rewards: s.rewards.map((r) => {
|
|
96
|
+
return {
|
|
97
|
+
token: {
|
|
98
|
+
name: r!.name,
|
|
99
|
+
decimals: r!.decimals,
|
|
100
|
+
symbol: r!.symbol,
|
|
101
|
+
address: r!.address,
|
|
102
|
+
},
|
|
103
|
+
distributor: zeroAddress,
|
|
104
|
+
periodFinish: '0',
|
|
105
|
+
rate: '0',
|
|
106
|
+
lastUpdate: '0',
|
|
107
|
+
integral: '0',
|
|
108
|
+
claimablePendingRewards: '0',
|
|
109
|
+
}
|
|
110
|
+
}),
|
|
111
|
+
// Base APR data
|
|
112
|
+
tradingApy: 0,
|
|
113
|
+
minApr: projectedApr,
|
|
114
|
+
maxApr: projectedApr,
|
|
115
|
+
// Raw data
|
|
116
|
+
totalSupply: formatUnits(totalSupply, 0),
|
|
117
|
+
}
|
|
118
|
+
})
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
global: {
|
|
122
|
+
fees: { accumulator: 0, perf: 0, veSdt: 0, claimer: 0 },
|
|
123
|
+
},
|
|
124
|
+
deployed: parsedData,
|
|
125
|
+
notDeployed: [],
|
|
126
|
+
fetched: true,
|
|
127
|
+
}
|
|
128
|
+
}
|
|
@@ -19,15 +19,20 @@ type UnknownToken = {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
const getMerkleData = async (epoch: number) => {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const [delegators, nonDelegators] = await Promise.all([
|
|
23
|
+
fetch(
|
|
24
|
+
`${GH_STAKE_DAO_BOUNTIES_REPORT}/refs/heads/main/bounties-reports/${epoch}/vlCVX/merkle_data_delegators.json`,
|
|
25
|
+
).then((res) => res.json()),
|
|
26
|
+
fetch(
|
|
27
|
+
`${GH_STAKE_DAO_BOUNTIES_REPORT}/refs/heads/main/bounties-reports/${epoch}/vlCVX/merkle_data_non_delegators.json`,
|
|
28
|
+
).then((res) => res.json()),
|
|
29
|
+
])
|
|
30
|
+
|
|
31
|
+
return { delegators, nonDelegators }
|
|
27
32
|
}
|
|
28
33
|
|
|
29
34
|
const isRootMatch = (contractRoot: string, fileRoot: string) =>
|
|
30
|
-
(contractRoot === ZERO_ROOT && fileRoot === ZERO_ROOT) || contractRoot
|
|
35
|
+
(contractRoot === ZERO_ROOT && fileRoot === ZERO_ROOT) || equalTlc(contractRoot, fileRoot)
|
|
31
36
|
|
|
32
37
|
const validateMerkleRoots = (delegatorRoot: string, nonDelegatorRoot: string, merkleData: any) => {
|
|
33
38
|
const delegatorMatches = isRootMatch(delegatorRoot, merkleData.delegators.merkleRoot)
|
|
@@ -107,8 +112,8 @@ const getParsedData = (
|
|
|
107
112
|
const ZERO_ROOT = '0x0000000000000000000000000000000000000000000000000000000000000000'
|
|
108
113
|
|
|
109
114
|
export const fetchUserVlCvxClaimable = async (provider: any, rpc: Rpcs, user: string) => {
|
|
110
|
-
const nowEpoch = Math.floor(Date.now() /
|
|
111
|
-
const prevEpoch = nowEpoch -
|
|
115
|
+
const nowEpoch = Math.floor(Date.now() / 1000 / ONE_WEEK) * ONE_WEEK
|
|
116
|
+
const prevEpoch = nowEpoch - ONE_WEEK
|
|
112
117
|
|
|
113
118
|
const { delegatorRoot, nonDelegatorRoot } = await getMerkleRoots(provider)
|
|
114
119
|
|
|
@@ -140,8 +145,8 @@ export const fetchUserVlCvxClaimable = async (provider: any, rpc: Rpcs, user: st
|
|
|
140
145
|
if (!tokens.length) return []
|
|
141
146
|
|
|
142
147
|
const [delegatedClaimed, notDelegatedClaimed] = await Promise.all([
|
|
143
|
-
getClaimedData(provider, tokensDelegated, user, contract('vlCvxDelegatorMerkle'
|
|
144
|
-
getClaimedData(provider, tokensNotDelegated, user, contract('vlCvxNotDelegatorMerkle'
|
|
148
|
+
getClaimedData(provider, tokensDelegated, user, contract('vlCvxDelegatorMerkle')),
|
|
149
|
+
getClaimedData(provider, tokensNotDelegated, user, contract('vlCvxNotDelegatorMerkle')),
|
|
145
150
|
])
|
|
146
151
|
|
|
147
152
|
const unknownTokens = tokens.filter((t) => !tokenWithAddress(t))
|