@stake-dao/reader 0.1.0
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/batches/curveStrats.js +163 -0
- package/dist/esm/batches/curveStrats.js.map +1 -0
- package/dist/esm/batches/index.js +4 -0
- package/dist/esm/batches/index.js.map +1 -0
- package/dist/esm/batches/sdtGaugeRewards.js +22 -0
- package/dist/esm/batches/sdtGaugeRewards.js.map +1 -0
- package/dist/esm/batches/tokenData.js +22 -0
- package/dist/esm/batches/tokenData.js.map +1 -0
- package/dist/esm/batches/types.js +2 -0
- package/dist/esm/batches/types.js.map +1 -0
- package/dist/esm/endpoints.js +3 -0
- package/dist/esm/endpoints.js.map +1 -0
- package/dist/esm/index.js +8 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/number.js +45 -0
- package/dist/esm/number.js.map +1 -0
- package/dist/esm/prices.js +70 -0
- package/dist/esm/prices.js.map +1 -0
- package/dist/esm/sdt/sdt.js +92 -0
- package/dist/esm/sdt/sdt.js.map +1 -0
- package/dist/esm/sdt/veSdtAlternativeYields.js +19 -0
- package/dist/esm/sdt/veSdtAlternativeYields.js.map +1 -0
- package/dist/esm/strategies/curve/build.js +123 -0
- package/dist/esm/strategies/curve/build.js.map +1 -0
- package/dist/esm/strategies/curve/endpoints.js +6 -0
- package/dist/esm/strategies/curve/endpoints.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/abi.js +80 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/abi.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/bytecode.js +24 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/bytecode.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/config.js +47 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/config.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getCurveApiData.js +172 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getCurveApiData.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getGaugesFromRegistry.js +33 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getGaugesFromRegistry.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getGaugesWeights.js +36 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getGaugesWeights.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getPoolsFromRegistries.ts.js +26 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getPoolsFromRegistries.ts.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getRegistries.js +20 -0
- package/dist/esm/strategies/curve/fetch/curveApiData/getRegistries.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/getAprBreakdown.js +73 -0
- package/dist/esm/strategies/curve/fetch/getAprBreakdown.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/getCvxApr.js +33 -0
- package/dist/esm/strategies/curve/fetch/getCvxApr.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/getOnlyboostData.js +63 -0
- package/dist/esm/strategies/curve/fetch/getOnlyboostData.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/getStratsWithApr.js +88 -0
- package/dist/esm/strategies/curve/fetch/getStratsWithApr.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/index.js +209 -0
- package/dist/esm/strategies/curve/fetch/index.js.map +1 -0
- package/dist/esm/strategies/curve/fetch/types.js +2 -0
- package/dist/esm/strategies/curve/fetch/types.js.map +1 -0
- package/dist/esm/strategies/curve/httpCalls.js +80 -0
- package/dist/esm/strategies/curve/httpCalls.js.map +1 -0
- package/dist/esm/strategies/curve/onChainCalls.js +28 -0
- package/dist/esm/strategies/curve/onChainCalls.js.map +1 -0
- package/dist/esm/strategies/types.js +2 -0
- package/dist/esm/strategies/types.js.map +1 -0
- package/dist/esm/strategies/utils/boost.js +30 -0
- package/dist/esm/strategies/utils/boost.js.map +1 -0
- package/dist/esm/strategies/utils/decodeEtherscanFactoryEvent.js +40 -0
- package/dist/esm/strategies/utils/decodeEtherscanFactoryEvent.js.map +1 -0
- package/dist/esm/strategies/utils/index.js +7 -0
- package/dist/esm/strategies/utils/index.js.map +1 -0
- package/dist/esm/strategies/utils/promise.js +10 -0
- package/dist/esm/strategies/utils/promise.js.map +1 -0
- package/dist/esm/strategies/utils/sdt.js +112 -0
- package/dist/esm/strategies/utils/sdt.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -0
- package/dist/esm/utils.js +113 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/batches/curveStrats.d.ts +4 -0
- package/dist/types/batches/curveStrats.d.ts.map +1 -0
- package/dist/types/batches/index.d.ts +4 -0
- package/dist/types/batches/index.d.ts.map +1 -0
- package/dist/types/batches/sdtGaugeRewards.d.ts +4 -0
- package/dist/types/batches/sdtGaugeRewards.d.ts.map +1 -0
- package/dist/types/batches/tokenData.d.ts +4 -0
- package/dist/types/batches/tokenData.d.ts.map +1 -0
- package/dist/types/batches/types.d.ts +15 -0
- package/dist/types/batches/types.d.ts.map +1 -0
- package/dist/types/endpoints.d.ts +3 -0
- package/dist/types/endpoints.d.ts.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/number.d.ts +6 -0
- package/dist/types/number.d.ts.map +1 -0
- package/dist/types/prices.d.ts +10 -0
- package/dist/types/prices.d.ts.map +1 -0
- package/dist/types/sdt/sdt.d.ts +31 -0
- package/dist/types/sdt/sdt.d.ts.map +1 -0
- package/dist/types/sdt/veSdtAlternativeYields.d.ts +19 -0
- package/dist/types/sdt/veSdtAlternativeYields.d.ts.map +1 -0
- package/dist/types/strategies/curve/build.d.ts +37 -0
- package/dist/types/strategies/curve/build.d.ts.map +1 -0
- package/dist/types/strategies/curve/endpoints.d.ts +6 -0
- package/dist/types/strategies/curve/endpoints.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/curveApiData/abi.d.ts +49 -0
- package/dist/types/strategies/curve/fetch/curveApiData/abi.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/curveApiData/bytecode.d.ts +8 -0
- package/dist/types/strategies/curve/fetch/curveApiData/bytecode.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/curveApiData/config.d.ts +34 -0
- package/dist/types/strategies/curve/fetch/curveApiData/config.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getCurveApiData.d.ts +3 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getCurveApiData.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getGaugesFromRegistry.d.ts +2 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getGaugesFromRegistry.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getGaugesWeights.d.ts +11 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getGaugesWeights.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getPoolsFromRegistries.ts.d.ts +2 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getPoolsFromRegistries.ts.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getRegistries.d.ts +5 -0
- package/dist/types/strategies/curve/fetch/curveApiData/getRegistries.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/getAprBreakdown.d.ts +17 -0
- package/dist/types/strategies/curve/fetch/getAprBreakdown.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/getCvxApr.d.ts +3 -0
- package/dist/types/strategies/curve/fetch/getCvxApr.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/getOnlyboostData.d.ts +4 -0
- package/dist/types/strategies/curve/fetch/getOnlyboostData.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/getStratsWithApr.d.ts +9 -0
- package/dist/types/strategies/curve/fetch/getStratsWithApr.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/index.d.ts +10 -0
- package/dist/types/strategies/curve/fetch/index.d.ts.map +1 -0
- package/dist/types/strategies/curve/fetch/types.d.ts +11 -0
- package/dist/types/strategies/curve/fetch/types.d.ts.map +1 -0
- package/dist/types/strategies/curve/httpCalls.d.ts +18 -0
- package/dist/types/strategies/curve/httpCalls.d.ts.map +1 -0
- package/dist/types/strategies/curve/onChainCalls.d.ts +2 -0
- package/dist/types/strategies/curve/onChainCalls.d.ts.map +1 -0
- package/dist/types/strategies/types.d.ts +130 -0
- package/dist/types/strategies/types.d.ts.map +1 -0
- package/dist/types/strategies/utils/boost.d.ts +2 -0
- package/dist/types/strategies/utils/boost.d.ts.map +1 -0
- package/dist/types/strategies/utils/decodeEtherscanFactoryEvent.d.ts +4 -0
- package/dist/types/strategies/utils/decodeEtherscanFactoryEvent.d.ts.map +1 -0
- package/dist/types/strategies/utils/index.d.ts +6 -0
- package/dist/types/strategies/utils/index.d.ts.map +1 -0
- package/dist/types/strategies/utils/promise.d.ts +2 -0
- package/dist/types/strategies/utils/promise.d.ts.map +1 -0
- package/dist/types/strategies/utils/sdt.d.ts +16 -0
- package/dist/types/strategies/utils/sdt.d.ts.map +1 -0
- package/dist/types/utils.d.ts +33 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +54 -0
- package/src/batches/curveStrats.ts +166 -0
- package/src/batches/index.ts +3 -0
- package/src/batches/sdtGaugeRewards.ts +26 -0
- package/src/batches/tokenData.ts +26 -0
- package/src/batches/types.ts +14 -0
- package/src/endpoints.ts +2 -0
- package/src/index.ts +7 -0
- package/src/number.ts +51 -0
- package/src/prices.ts +86 -0
- package/src/sdt/sdt.ts +110 -0
- package/src/sdt/veSdtAlternativeYields.ts +19 -0
- package/src/strategies/curve/build.ts +187 -0
- package/src/strategies/curve/endpoints.ts +21 -0
- package/src/strategies/curve/fetch/curveApiData/abi.ts +81 -0
- package/src/strategies/curve/fetch/curveApiData/bytecode.ts +43 -0
- package/src/strategies/curve/fetch/curveApiData/config.ts +56 -0
- package/src/strategies/curve/fetch/curveApiData/getCurveApiData.ts +207 -0
- package/src/strategies/curve/fetch/curveApiData/getGaugesFromRegistry.ts +41 -0
- package/src/strategies/curve/fetch/curveApiData/getGaugesWeights.ts +52 -0
- package/src/strategies/curve/fetch/curveApiData/getPoolsFromRegistries.ts.ts +36 -0
- package/src/strategies/curve/fetch/curveApiData/getRegistries.ts +25 -0
- package/src/strategies/curve/fetch/getAprBreakdown.ts +98 -0
- package/src/strategies/curve/fetch/getCvxApr.ts +49 -0
- package/src/strategies/curve/fetch/getOnlyboostData.ts +100 -0
- package/src/strategies/curve/fetch/getStratsWithApr.ts +118 -0
- package/src/strategies/curve/fetch/index.ts +276 -0
- package/src/strategies/curve/fetch/types.ts +11 -0
- package/src/strategies/curve/httpCalls.ts +117 -0
- package/src/strategies/curve/onChainCalls.ts +36 -0
- package/src/strategies/types.ts +137 -0
- package/src/strategies/utils/boost.ts +41 -0
- package/src/strategies/utils/decodeEtherscanFactoryEvent.ts +42 -0
- package/src/strategies/utils/index.ts +8 -0
- package/src/strategies/utils/promise.ts +10 -0
- package/src/strategies/utils/sdt.ts +206 -0
- package/src/utils.ts +171 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { range } from 'lodash-es'
|
|
2
|
+
import { encodeAbiParameters, parseAbiParameters } from 'viem'
|
|
3
|
+
import { batchJsonRpc } from '../../../../utils.js'
|
|
4
|
+
import { getCurveDataPoolsOutputTypeAbi } from './abi.js'
|
|
5
|
+
import { curveApiDataBytecodes } from './bytecode.js'
|
|
6
|
+
import { CHUNK_SIZE } from './config.js'
|
|
7
|
+
|
|
8
|
+
export const getPoolsFromRegistries = async (rpc: string, lendingCallsStartIndex: number, poolCounts: any) => {
|
|
9
|
+
const registriesCalls = poolCounts.flatMap((registry) =>
|
|
10
|
+
range(0, registry.poolCount, CHUNK_SIZE).map((skip) => {
|
|
11
|
+
const inputParams = [
|
|
12
|
+
registry.address,
|
|
13
|
+
skip,
|
|
14
|
+
skip + CHUNK_SIZE > registry.poolCount ? registry.poolCount : skip + CHUNK_SIZE,
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
const inputData = encodeAbiParameters(
|
|
18
|
+
parseAbiParameters(['address _registry, uint256 skip, uint256 limit']) as any,
|
|
19
|
+
inputParams,
|
|
20
|
+
)
|
|
21
|
+
return curveApiDataBytecodes[registry.bytecodeIndex]?.concat(inputData.slice(2))
|
|
22
|
+
}),
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
const pools = await batchJsonRpc({
|
|
26
|
+
rpc,
|
|
27
|
+
calls: registriesCalls,
|
|
28
|
+
outputTypeAbi: Array.from({ length: registriesCalls.length }, (_el, index) =>
|
|
29
|
+
getCurveDataPoolsOutputTypeAbi(index >= lendingCallsStartIndex),
|
|
30
|
+
),
|
|
31
|
+
parse: false,
|
|
32
|
+
callsKey: 'Fetch Curve Apis Data',
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return pools
|
|
36
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { decodeAbiParameters } from 'viem'
|
|
2
|
+
import { rpcCall } from '../../../../utils.js'
|
|
3
|
+
import { CHUNK_SIZE, lendingStartIndex, registries } from './config.js'
|
|
4
|
+
|
|
5
|
+
export const getRegistries = async (rpc: string, chainId: number) => {
|
|
6
|
+
const poolCountsRequest = await rpcCall(
|
|
7
|
+
rpc,
|
|
8
|
+
registries[chainId]!.map((registry) => ({
|
|
9
|
+
to: registry.address,
|
|
10
|
+
data: registry.isLending ? '0xfd775c78' : '0x956aae3a',
|
|
11
|
+
})),
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
let totalPoolCount = 0
|
|
15
|
+
let lendingCallsStartIndex = 0
|
|
16
|
+
|
|
17
|
+
const poolCounts = poolCountsRequest.map((res, index) => {
|
|
18
|
+
const poolCount = Number(decodeAbiParameters([{ type: 'uint256', name: 'poolCount' }], res.result))
|
|
19
|
+
if (lendingStartIndex[chainId] > index) lendingCallsStartIndex += Math.ceil(poolCount / CHUNK_SIZE)
|
|
20
|
+
totalPoolCount += poolCount
|
|
21
|
+
return { ...registries[chainId]![index], poolCount, sumCount: totalPoolCount }
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
return { lendingCallsStartIndex, poolCounts }
|
|
25
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { getBreakdownLabel, isProtocolToken } from '../../../utils.js'
|
|
2
|
+
import type { RewardsData } from '../../types.js'
|
|
3
|
+
|
|
4
|
+
type Breakdown = {
|
|
5
|
+
label: string
|
|
6
|
+
value: number[]
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const getAprBreakdown = (strat: any, rewardsData: RewardsData[], boost: number, cvxApr: number, sdtApr: any) => {
|
|
10
|
+
// Base Rewards
|
|
11
|
+
// Trading Fees for LP
|
|
12
|
+
// Supply APY for lending
|
|
13
|
+
const baseReward: Breakdown = {
|
|
14
|
+
label: `${strat.isLending ? 'Lending' : 'Trading Fees'} (APY)`,
|
|
15
|
+
value: [strat?.tradingApy || 0],
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Current streaming APRs from the Stake DAO gauge
|
|
19
|
+
const currentAprBreakdown: Breakdown[] = rewardsData.map((r) => {
|
|
20
|
+
const value = r.token.symbol === 'SDT' ? [sdtApr.sdtMinApr, sdtApr.sdtMaxApr] : [r.apr * 100]
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
label: getBreakdownLabel(strat, r, false, boost, sdtApr),
|
|
24
|
+
value,
|
|
25
|
+
}
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
// Projected CRV APR
|
|
29
|
+
const projectedCrvApr = strat ? boost * strat.minApr : 0
|
|
30
|
+
|
|
31
|
+
// Projected CVX APR
|
|
32
|
+
const projectedCvxApr = { label: 'CVX APR', value: [cvxApr] }
|
|
33
|
+
|
|
34
|
+
// Format SDT and CRV rewards APR for breakdown
|
|
35
|
+
const projectedAprBreakdown: Breakdown[] = rewardsData
|
|
36
|
+
.map((r) => {
|
|
37
|
+
const value =
|
|
38
|
+
r.token.symbol === 'SDT'
|
|
39
|
+
? [sdtApr.sdtFuturMinApr, sdtApr.sdtFuturMaxApr]
|
|
40
|
+
: isProtocolToken(strat.protocol, r.token.symbol)
|
|
41
|
+
? [projectedCrvApr]
|
|
42
|
+
: [0]
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
label: getBreakdownLabel(strat, r, true, boost, sdtApr),
|
|
46
|
+
value,
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
.filter((r) => r.value[0] > 0)
|
|
50
|
+
|
|
51
|
+
// Get extra rewards APR from current streaming APR breakdown
|
|
52
|
+
let extraTokensAprBreakdown: Breakdown[] = currentAprBreakdown.filter(
|
|
53
|
+
(x) =>
|
|
54
|
+
![...projectedAprBreakdown, projectedCvxApr].find((y) => y.label.startsWith(x.label)) &&
|
|
55
|
+
!x.label.startsWith('SDT'),
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
// Remove extra rewards already present in gaugesProjectedApr
|
|
59
|
+
if (strat?.gaugesProjectedApr) {
|
|
60
|
+
extraTokensAprBreakdown = extraTokensAprBreakdown.filter(
|
|
61
|
+
(x) => !strat.gaugesProjectedApr.find((z: any) => x.label === `${z.symbol} APR`),
|
|
62
|
+
)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Compute total current APR
|
|
66
|
+
const currentTotal =
|
|
67
|
+
baseReward.value[0]! + currentAprBreakdown.reduce((total: number, curr) => total + curr.value[0]!, 0)
|
|
68
|
+
|
|
69
|
+
// Compute total projected APR
|
|
70
|
+
const projectedTotal =
|
|
71
|
+
baseReward.value[0]! +
|
|
72
|
+
projectedAprBreakdown.reduce((total: number, curr) => total + curr.value[0]!, 0) +
|
|
73
|
+
cvxApr +
|
|
74
|
+
(strat.gaugesProjectedApr ? strat.gaugesProjectedApr.reduce((total: number, y: any) => total + y.apr, 0) : 0) +
|
|
75
|
+
extraTokensAprBreakdown.reduce((total: number, y: any) => total + y.value[0], 0)
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
current: {
|
|
79
|
+
total: currentTotal,
|
|
80
|
+
details: [baseReward, ...currentAprBreakdown].filter((r) => r.value[0] || -1 > 0),
|
|
81
|
+
},
|
|
82
|
+
projected: {
|
|
83
|
+
total: projectedTotal,
|
|
84
|
+
details: [
|
|
85
|
+
baseReward,
|
|
86
|
+
...projectedAprBreakdown,
|
|
87
|
+
...(strat?.gaugesProjectedApr
|
|
88
|
+
? strat.gaugesProjectedApr.map((r: any) => ({
|
|
89
|
+
label: `${r.symbol} APR`,
|
|
90
|
+
value: [r.apr],
|
|
91
|
+
}))
|
|
92
|
+
: []),
|
|
93
|
+
...extraTokensAprBreakdown,
|
|
94
|
+
projectedCvxApr,
|
|
95
|
+
].filter((r) => r.value[0] > 0),
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { formatUnits, parseUnits } from 'viem'
|
|
2
|
+
import { Zero } from '../../utils/index.js'
|
|
3
|
+
|
|
4
|
+
const CVX_CLIFF_SIZE = parseUnits('100000', 18) // new cliff every 100,000 tokens
|
|
5
|
+
const CVX_CLIFF_COUNT = BigInt(1000) // 1,000 cliffs
|
|
6
|
+
const CVX_MAX_SUPPLY = parseUnits('100000000', 18) // 100 mil max supply
|
|
7
|
+
|
|
8
|
+
export const getCvxMintAmount = (crvEarned: bigint, _cvxTotalSupply: string) => {
|
|
9
|
+
// First get total supply
|
|
10
|
+
const cvxTotalSupply = parseUnits(_cvxTotalSupply, 0)
|
|
11
|
+
|
|
12
|
+
// Get current cliff
|
|
13
|
+
const currentCliff = cvxTotalSupply / CVX_CLIFF_SIZE
|
|
14
|
+
|
|
15
|
+
// If current cliff is under the max
|
|
16
|
+
if (currentCliff < CVX_CLIFF_COUNT) {
|
|
17
|
+
// Get remaining cliffs
|
|
18
|
+
const remaining = CVX_CLIFF_COUNT - currentCliff
|
|
19
|
+
|
|
20
|
+
// Multiply ratio of remaining cliffs to total cliffs against amount CRV received
|
|
21
|
+
let cvxEarned = (crvEarned * remaining) / CVX_CLIFF_COUNT
|
|
22
|
+
|
|
23
|
+
// Double check we have not gone over the max supply
|
|
24
|
+
const amountTillMax = CVX_MAX_SUPPLY - cvxTotalSupply
|
|
25
|
+
if (cvxEarned > amountTillMax) {
|
|
26
|
+
cvxEarned = amountTillMax
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return cvxEarned
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return Zero
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const getCvxApr = (
|
|
36
|
+
convexTvlInUsd: number,
|
|
37
|
+
tvlInUsd: number,
|
|
38
|
+
crvApr: number,
|
|
39
|
+
cvxTotalSupply: string,
|
|
40
|
+
cvxPrice: number,
|
|
41
|
+
) => {
|
|
42
|
+
const weeklyCrvEarn = (convexTvlInUsd * (crvApr / 100)) / 52
|
|
43
|
+
const weeklyCrvEarnBI = parseUnits(weeklyCrvEarn.toString(), 18)
|
|
44
|
+
|
|
45
|
+
const weeklyCvxMint = getCvxMintAmount(weeklyCrvEarnBI, cvxTotalSupply)
|
|
46
|
+
const yearlyCvxMint = Number(formatUnits(weeklyCvxMint, 18)) * 52
|
|
47
|
+
|
|
48
|
+
return ((yearlyCvxMint * cvxPrice) / tvlInUsd) * 100
|
|
49
|
+
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { formatUnits } from 'viem'
|
|
2
|
+
import { projectWorkingBalance } from '../../../utils.js'
|
|
3
|
+
import type { OnlyBoostData } from '../../types.js'
|
|
4
|
+
import { getBoost } from '../../utils/boost.js'
|
|
5
|
+
|
|
6
|
+
const getOnlyboostData = (
|
|
7
|
+
data: any,
|
|
8
|
+
stakeDaoVeBoost: string,
|
|
9
|
+
convexVeBoost: string,
|
|
10
|
+
veCrvTotalSupply: string,
|
|
11
|
+
curveGaugeTotalSupply: bigint,
|
|
12
|
+
strategyHoldings: bigint,
|
|
13
|
+
workingBalance: bigint,
|
|
14
|
+
baseTotalSupply: bigint,
|
|
15
|
+
lpPriceInUsd: number,
|
|
16
|
+
): OnlyBoostData => {
|
|
17
|
+
const active = data.active
|
|
18
|
+
const convexImpl = data.convexImpl
|
|
19
|
+
|
|
20
|
+
const totalSupply = formatUnits(active ? data.totalSupply : baseTotalSupply, 0)
|
|
21
|
+
|
|
22
|
+
// Current
|
|
23
|
+
const stakeDaoSupply = formatUnits(data.stakeDaoSupply, 0)
|
|
24
|
+
const convexSupply = formatUnits(data.convexSupply, 0)
|
|
25
|
+
|
|
26
|
+
const stakeDaoTvl = Number(formatUnits(data.stakeDaoSupply, 18)) * lpPriceInUsd
|
|
27
|
+
const convexTvl = Number(formatUnits(data.convexSupply, 18)) * lpPriceInUsd
|
|
28
|
+
|
|
29
|
+
const stakeDaoShare = Number(stakeDaoSupply) / Number(totalSupply)
|
|
30
|
+
const convexShare = Number(convexSupply) / Number(totalSupply)
|
|
31
|
+
|
|
32
|
+
const stakeDaoBoost = getBoost('curve', strategyHoldings, workingBalance)
|
|
33
|
+
const convexBoost = getBoost('curve', data.convexStrategyHoldings, data.convexWorkingBalance)
|
|
34
|
+
|
|
35
|
+
// Optimal
|
|
36
|
+
const stakeDaoOptSupply = formatUnits(data.stakeDaoOptSupply, 0)
|
|
37
|
+
const convexOptSupply = formatUnits(data.convexOptSupply, 0)
|
|
38
|
+
|
|
39
|
+
const stakeDaoOptShare = Number(stakeDaoOptSupply) / Number(totalSupply)
|
|
40
|
+
const convexOptShare = Number(convexOptSupply) / Number(totalSupply)
|
|
41
|
+
|
|
42
|
+
const stakeDaoOptStrategyHoldings = strategyHoldings - data.stakeDaoSupply + data.stakeDaoOptSupply
|
|
43
|
+
const convexOptStrategyHoldings = data.convexStrategyHoldings - data.convexSupply + data.convexOptSupply
|
|
44
|
+
|
|
45
|
+
const stakeDaoOptWorkingBalance = projectWorkingBalance(
|
|
46
|
+
BigInt(stakeDaoVeBoost),
|
|
47
|
+
BigInt(veCrvTotalSupply),
|
|
48
|
+
stakeDaoOptStrategyHoldings,
|
|
49
|
+
curveGaugeTotalSupply,
|
|
50
|
+
)
|
|
51
|
+
const convexOptWorkingBalance = projectWorkingBalance(
|
|
52
|
+
BigInt(convexVeBoost),
|
|
53
|
+
BigInt(veCrvTotalSupply),
|
|
54
|
+
convexOptStrategyHoldings,
|
|
55
|
+
curveGaugeTotalSupply,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
const stakeDaoOptBoost = getBoost('curve', stakeDaoOptStrategyHoldings, stakeDaoOptWorkingBalance)
|
|
59
|
+
const convexOptBoost = getBoost('curve', convexOptStrategyHoldings, convexOptWorkingBalance)
|
|
60
|
+
|
|
61
|
+
const boost = Number(totalSupply) > 0 ? stakeDaoBoost * stakeDaoShare + convexBoost * convexShare : 2.5
|
|
62
|
+
const optimalBoost =
|
|
63
|
+
Number(totalSupply) > 0 ? stakeDaoOptBoost * stakeDaoOptShare + convexOptBoost * convexOptShare : 2.5
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
active,
|
|
67
|
+
implementations: [{ key: 'convex', address: convexImpl }],
|
|
68
|
+
|
|
69
|
+
totalSupply,
|
|
70
|
+
boost,
|
|
71
|
+
optimalBoost,
|
|
72
|
+
|
|
73
|
+
stakeDao: {
|
|
74
|
+
tvl: stakeDaoTvl,
|
|
75
|
+
supply: stakeDaoSupply,
|
|
76
|
+
boost: stakeDaoBoost,
|
|
77
|
+
optimal: {
|
|
78
|
+
supply: stakeDaoOptSupply,
|
|
79
|
+
boost: stakeDaoOptBoost,
|
|
80
|
+
share: stakeDaoOptShare,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
convex: {
|
|
84
|
+
tvl: convexTvl,
|
|
85
|
+
supply: convexSupply,
|
|
86
|
+
boost: convexBoost,
|
|
87
|
+
optimal: {
|
|
88
|
+
supply: convexOptSupply,
|
|
89
|
+
boost: convexOptBoost,
|
|
90
|
+
share: convexOptShare,
|
|
91
|
+
},
|
|
92
|
+
claimable: data.claimableData.map((c: any) => ({
|
|
93
|
+
token: c.token,
|
|
94
|
+
claimable: formatUnits(c.claimable, 0),
|
|
95
|
+
})),
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export default getOnlyboostData
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { formatUnits, parseAbi } from 'viem'
|
|
2
|
+
|
|
3
|
+
import { ONE_YEAR, STRAT_FEES, contract, tokenWithId } from '@stake-dao/constants'
|
|
4
|
+
import { equalTlc, multicall } from '../../../utils.js'
|
|
5
|
+
|
|
6
|
+
export const getCurveStratsWithApr = (chainId: number, curveStrats: any[], apisData: any) => {
|
|
7
|
+
const curveStratsDataCalls: any[] = []
|
|
8
|
+
|
|
9
|
+
const strats = curveStrats.filter((s) => s.key && s.chainId === chainId && !s.isLending)
|
|
10
|
+
|
|
11
|
+
const curveStratsWithApr = strats.map((s) => {
|
|
12
|
+
const curveApiData = apisData.curveApiData.find((el) => equalTlc(el.lp, s.lpToken.address))
|
|
13
|
+
|
|
14
|
+
const subgraphData = apisData.curveSubgraphData.find((el: any) => curveApiData && el.address === curveApiData.pool)
|
|
15
|
+
const gaugesProjectedApr = curveApiData?.gauge
|
|
16
|
+
? curveApiData.gauge.extraRewards.map((extra) => ({
|
|
17
|
+
symbol: extra.token.symbol,
|
|
18
|
+
apr: extra.apr,
|
|
19
|
+
}))
|
|
20
|
+
: []
|
|
21
|
+
const convexPool =
|
|
22
|
+
s.chainId === 1
|
|
23
|
+
? apisData.convexPools.find(
|
|
24
|
+
(pool: any) => pool.lpTokenAddress.toLowerCase() === s.lpToken.address.toLowerCase(),
|
|
25
|
+
)
|
|
26
|
+
: undefined
|
|
27
|
+
|
|
28
|
+
curveStratsDataCalls.push({
|
|
29
|
+
vault: s.vault,
|
|
30
|
+
token: s.lpToken.address,
|
|
31
|
+
liquidityGauge: s.gaugeAddress,
|
|
32
|
+
sdtLiquidityGauge: s.sdGauge,
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
...s,
|
|
37
|
+
name: (s.isMetapool ? s.underlyingCoins : s.coins)
|
|
38
|
+
.reduce((res: string, current: any) => `${res}/${current.symbol}`, '')
|
|
39
|
+
.slice(1),
|
|
40
|
+
tradingApy: subgraphData?.latestWeeklyApy || 0,
|
|
41
|
+
gaugesProjectedApr,
|
|
42
|
+
minApr: curveApiData?.crvApr ? curveApiData.crvApr[0] * ((100 - STRAT_FEES) / 100) : 0,
|
|
43
|
+
maxApr: curveApiData?.crvApr ? curveApiData.crvApr[1] * ((100 - STRAT_FEES) / 100) : 0,
|
|
44
|
+
lpPriceInUsd: curveApiData.lpPriceInUsd,
|
|
45
|
+
convexPool: convexPool ? convexPool.convexPoolData : undefined,
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
return { curveStratsWithApr, curveStratsDataCalls }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export const getCurveLendingWithApr = async (provider: any, chainId: number, curveStrats: any[], apisData: any) => {
|
|
53
|
+
const curveLendingDataCalls: any[] = []
|
|
54
|
+
|
|
55
|
+
const strats = curveStrats.filter((s) => s.key && s.chainId === chainId && s.isLending)
|
|
56
|
+
|
|
57
|
+
const gaugesData = await multicall(
|
|
58
|
+
provider,
|
|
59
|
+
strats.flatMap((s) => [
|
|
60
|
+
{ address: s.gaugeAddress, name: 'inflation_rate' },
|
|
61
|
+
{ address: s.gaugeAddress, name: 'working_supply' },
|
|
62
|
+
{ address: contract('curveGaugeController', chainId), name: 'gauge_relative_weight', params: [s.gaugeAddress] },
|
|
63
|
+
]),
|
|
64
|
+
parseAbi([
|
|
65
|
+
'function inflation_rate() external view returns (uint256)',
|
|
66
|
+
'function working_supply() external view returns (uint256)',
|
|
67
|
+
'function gauge_relative_weight(address gauge) external view returns (uint256)',
|
|
68
|
+
]),
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
const triCrvPool = apisData.curveApiData.find((el) => equalTlc(el.lp, '0x4eBdF703948ddCEA3B11f675B4D1Fba9d2414A14'))
|
|
72
|
+
const triCrvPoolCrvData = triCrvPool.coins.find((c) => equalTlc(c.coinAddress, tokenWithId('crv')?.address as string))
|
|
73
|
+
const crvPriceInUsd = triCrvPoolCrvData.usdBalance / Number(triCrvPoolCrvData.balance)
|
|
74
|
+
|
|
75
|
+
const curveLendingWithApr = strats.map((s) => {
|
|
76
|
+
const curveApiData = apisData.curveApiData.find((el) => equalTlc(el.lp, s.lpToken.address))
|
|
77
|
+
|
|
78
|
+
const convexPool =
|
|
79
|
+
s.chainId === 1
|
|
80
|
+
? apisData.convexLendingVaults.find(
|
|
81
|
+
(pool: any) => pool.address.toLowerCase() === s.lpToken.address.toLowerCase(),
|
|
82
|
+
)
|
|
83
|
+
: undefined
|
|
84
|
+
const lpPriceInUsd = curveApiData?.lpPriceInUsd || 0
|
|
85
|
+
|
|
86
|
+
curveLendingDataCalls.push({
|
|
87
|
+
vault: s.vault,
|
|
88
|
+
token: s.lpToken.address,
|
|
89
|
+
liquidityGauge: s.gaugeAddress,
|
|
90
|
+
sdtLiquidityGauge: s.sdGauge,
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const inflationRate = Number(formatUnits(gaugesData.shift().result as any as bigint, 18))
|
|
94
|
+
const workingSupply = Number(formatUnits(gaugesData.shift().result as any as bigint, 18))
|
|
95
|
+
const gaugeRelativeWeight = Number(formatUnits(gaugesData.shift().result as any as bigint, 18))
|
|
96
|
+
|
|
97
|
+
const crvBaseApr =
|
|
98
|
+
((((inflationRate * gaugeRelativeWeight * ONE_YEAR) / workingSupply) * 0.4 * crvPriceInUsd) / lpPriceInUsd) * 100
|
|
99
|
+
|
|
100
|
+
const gaugesProjectedApr = undefined
|
|
101
|
+
const minApr = crvBaseApr * ((100 - STRAT_FEES) / 100)
|
|
102
|
+
const maxApr = crvBaseApr * 2.5 * ((100 - STRAT_FEES) / 100)
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
...s,
|
|
106
|
+
name: s.coins[0].symbol,
|
|
107
|
+
// subname: curveApiData?.assets ? `${curveApiData.assets.collateral.symbol} collateral` : '',
|
|
108
|
+
// tradingApy: curveApiData?.rates ? curveApiData.rates.lendApyPcent : 0,
|
|
109
|
+
gaugesProjectedApr,
|
|
110
|
+
minApr,
|
|
111
|
+
maxApr,
|
|
112
|
+
lpPriceInUsd,
|
|
113
|
+
convexPool: convexPool ? convexPool.convexPoolData : undefined,
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
return { curveLendingWithApr, curveLendingDataCalls }
|
|
118
|
+
}
|