@stake-dao/reader 0.4.95 → 0.4.97
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/bytecodes/votemarket/batchCampaignsRestrictedVotes.js +1 -1
- package/dist/esm/bytecodes/votemarket/batchCampaignsRestrictedVotes.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/batchClaimableData.js +1 -1
- package/dist/esm/bytecodes/votemarket/batchClaimableData.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/batchGaugesWeight.js +1 -1
- package/dist/esm/bytecodes/votemarket/batchGaugesWeight.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/batchPendleUserVotes.js +39 -0
- package/dist/esm/bytecodes/votemarket/batchPendleUserVotes.js.map +1 -0
- package/dist/esm/bytecodes/votemarket/batchPendleVotes.js +13 -0
- package/dist/esm/bytecodes/votemarket/batchPendleVotes.js.map +1 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/strategies/curve/fetch/index.js +9 -20
- package/dist/esm/strategies/curve/fetch/index.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/utils/snapshot.js +5 -0
- package/dist/esm/utils/snapshot.js.map +1 -1
- package/dist/esm/votemarket/curve/fetchSnapshotUserData.js +1 -1
- package/dist/esm/votemarket/curve/fetchSnapshotUserData.js.map +1 -1
- package/dist/esm/votemarket/fetchClaimableData.js +33 -4
- package/dist/esm/votemarket/fetchClaimableData.js.map +1 -1
- package/dist/esm/votemarket/fetchEpochVotes.js +9 -4
- package/dist/esm/votemarket/fetchEpochVotes.js.map +1 -1
- package/dist/esm/votemarket/pendle/fetchPendleUserVotes.js +37 -0
- package/dist/esm/votemarket/pendle/fetchPendleUserVotes.js.map +1 -0
- package/dist/types/bytecodes/votemarket/batchPendleUserVotes.d.ts +4 -0
- package/dist/types/bytecodes/votemarket/batchPendleUserVotes.d.ts.map +1 -0
- package/dist/types/bytecodes/votemarket/batchPendleVotes.d.ts +4 -0
- package/dist/types/bytecodes/votemarket/batchPendleVotes.d.ts.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/strategies/curve/fetch/index.d.ts.map +1 -1
- package/dist/types/utils/snapshot.d.ts.map +1 -1
- package/dist/types/votemarket/curve/fetchSnapshotUserData.d.ts.map +1 -1
- package/dist/types/votemarket/fetchClaimableData.d.ts.map +1 -1
- package/dist/types/votemarket/fetchEpochVotes.d.ts.map +1 -1
- package/dist/types/votemarket/pendle/fetchPendleUserVotes.d.ts +3 -0
- package/dist/types/votemarket/pendle/fetchPendleUserVotes.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/bytecodes/votemarket/batchCampaignsRestrictedVotes.ts +1 -1
- package/src/bytecodes/votemarket/batchClaimableData.ts +1 -1
- package/src/bytecodes/votemarket/batchGaugesWeight.ts +1 -1
- package/src/bytecodes/votemarket/batchPendleUserVotes.ts +41 -0
- package/src/bytecodes/votemarket/batchPendleVotes.ts +15 -0
- package/src/index.ts +3 -0
- package/src/strategies/curve/fetch/index.ts +9 -28
- package/src/utils/snapshot.ts +5 -0
- package/src/votemarket/curve/fetchSnapshotUserData.ts +1 -2
- package/src/votemarket/fetchClaimableData.ts +46 -4
- package/src/votemarket/fetchEpochVotes.ts +12 -4
- package/src/votemarket/pendle/fetchPendleUserVotes.ts +46 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatUnits } from 'viem'
|
|
2
2
|
|
|
3
|
-
import { ONE_YEAR, OneEther,
|
|
3
|
+
import { ONE_YEAR, OneEther, curveStrats, mainnet } from '@stake-dao/constants'
|
|
4
4
|
import type { Price } from '../../../prices.js'
|
|
5
5
|
import { type SdtEmissionData, getSdtApr } from '../../../sdt.js'
|
|
6
6
|
import { equalTlc } from '../../../utils.js'
|
|
@@ -78,7 +78,6 @@ export const fetchCurve = async ({
|
|
|
78
78
|
// TODO stratsData type
|
|
79
79
|
let stratsData: any[] = []
|
|
80
80
|
|
|
81
|
-
const crv = tokenWithId('crv', chainId)
|
|
82
81
|
decodedPromise.forEach((d: any, index: number) => {
|
|
83
82
|
if (index === 0) {
|
|
84
83
|
if (chainId === mainnet.id) {
|
|
@@ -162,12 +161,13 @@ export const fetchCurve = async ({
|
|
|
162
161
|
periodFinish,
|
|
163
162
|
rate: formatUnits(r.rate, 0),
|
|
164
163
|
lastUpdate: formatUnits(r.last_update, 0),
|
|
165
|
-
claimablePendingRewards:
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
claimablePendingRewards: '0',
|
|
165
|
+
// claimablePendingRewards: equalTlc(v.rewardsTokens[rewardIndex], crv?.address!)
|
|
166
|
+
// ? formatUnits(v.claimablePendingRewards, 0)
|
|
167
|
+
// : formatUnits(
|
|
168
|
+
// v.claimableData.find((c: any) => c.token === v.rewardsTokens[rewardIndex])?.claimable || Zero,
|
|
169
|
+
// 0,
|
|
170
|
+
// ),
|
|
171
171
|
}
|
|
172
172
|
})
|
|
173
173
|
|
|
@@ -259,29 +259,10 @@ export const fetchCurve = async ({
|
|
|
259
259
|
stratsData = stratsData.concat(parsedData)
|
|
260
260
|
})
|
|
261
261
|
|
|
262
|
-
const deployedStratsGauges = stratsData.map((s) => s.gaugeAddress)
|
|
263
|
-
const notDeployedStrats = apisData.curveApiData
|
|
264
|
-
.filter(
|
|
265
|
-
(curvePool) =>
|
|
266
|
-
curvePool.gauge &&
|
|
267
|
-
!deployedStratsGauges.includes(curvePool.gauge.address) &&
|
|
268
|
-
((curvePool.crvApr && curvePool.crvApr.length > 1 && curvePool.crvApr[1] !== null && curvePool.crvApr[1] > 0) ||
|
|
269
|
-
(curvePool.gauge.extraRewards && curvePool.gauge.extraRewards.length > 0)),
|
|
270
|
-
)
|
|
271
|
-
.map((s) => ({
|
|
272
|
-
...s,
|
|
273
|
-
protocol: 'curve',
|
|
274
|
-
chainId,
|
|
275
|
-
convexPool:
|
|
276
|
-
chainId === 1
|
|
277
|
-
? apisData.convexPools.find((pool: any) => equalTlc(pool.lpTokenAddress, s.lp))?.convexPoolData || undefined
|
|
278
|
-
: undefined,
|
|
279
|
-
}))
|
|
280
|
-
|
|
281
262
|
return {
|
|
282
263
|
global,
|
|
283
264
|
deployed: stratsData,
|
|
284
|
-
notDeployed:
|
|
265
|
+
notDeployed: [],
|
|
285
266
|
fetched: true,
|
|
286
267
|
}
|
|
287
268
|
}
|
package/src/utils/snapshot.ts
CHANGED
|
@@ -134,8 +134,7 @@ export const fetchSnapshotUserData = async (
|
|
|
134
134
|
const userVotes = {}
|
|
135
135
|
if (isAddress(userAddress)) {
|
|
136
136
|
const proposalVp = await getSnapshotProposalVp(space, proposal.id, userAddress)
|
|
137
|
-
|
|
138
|
-
vp = proposalVp.vp.vp
|
|
137
|
+
vp = proposalVp.votes.length ? proposalVp.votes[0].vp : proposalVp.vp.vp
|
|
139
138
|
|
|
140
139
|
const rawUserVotes = await graphql(SNAPSHOT_HUB, SNAPSHOT_USER_VOTE_QUERY(space, proposal.id, userAddress))
|
|
141
140
|
|
|
@@ -1,11 +1,51 @@
|
|
|
1
|
-
import { chunk } from 'lodash-es'
|
|
2
1
|
import { encodeAbiParameters, formatUnits, parseAbiParameters } from 'viem'
|
|
3
2
|
import { arbitrum } from 'viem/chains'
|
|
4
3
|
import batchClaimableData from '../bytecodes/votemarket/batchClaimableData.js'
|
|
5
4
|
import { concatBytecode } from '../index.js'
|
|
6
5
|
import { batchJsonRpc } from '../utils.js'
|
|
7
6
|
|
|
8
|
-
const
|
|
7
|
+
const MAX_VOTES_PER_CHUNK = 50
|
|
8
|
+
const MAX_CAMPAIGNS_PER_CHUNKS = 5
|
|
9
|
+
|
|
10
|
+
const chunkCampaignsWithVoteLimit = (campaigns: number[], userVotes: any[]) => {
|
|
11
|
+
const campaignChunks: number[][] = []
|
|
12
|
+
const voteChunks: any[][][] = []
|
|
13
|
+
|
|
14
|
+
let currentCampaignChunk: number[] = []
|
|
15
|
+
let currentVoteChunk: any[][] = []
|
|
16
|
+
let currentVoteCount = 0
|
|
17
|
+
|
|
18
|
+
for (let i = 0; i < campaigns.length; i++) {
|
|
19
|
+
const votes = userVotes[i]
|
|
20
|
+
const voteCount = votes.length
|
|
21
|
+
|
|
22
|
+
if (
|
|
23
|
+
(currentVoteCount + voteCount > MAX_VOTES_PER_CHUNK && currentCampaignChunk.length > 0) ||
|
|
24
|
+
currentCampaignChunk.length >= MAX_CAMPAIGNS_PER_CHUNKS
|
|
25
|
+
) {
|
|
26
|
+
// Push current chunks and resets
|
|
27
|
+
campaignChunks.push(currentCampaignChunk)
|
|
28
|
+
voteChunks.push(currentVoteChunk)
|
|
29
|
+
|
|
30
|
+
currentCampaignChunk = []
|
|
31
|
+
currentVoteChunk = []
|
|
32
|
+
currentVoteCount = 0
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
//Add to chunk
|
|
36
|
+
currentCampaignChunk.push(campaigns[i] as number)
|
|
37
|
+
currentVoteChunk.push(votes)
|
|
38
|
+
currentVoteCount += voteCount
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Push remaining
|
|
42
|
+
if (currentCampaignChunk.length > 0) {
|
|
43
|
+
campaignChunks.push(currentCampaignChunk)
|
|
44
|
+
voteChunks.push(currentVoteChunk)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return { campaignChunks, voteChunks }
|
|
48
|
+
}
|
|
9
49
|
|
|
10
50
|
export const fetchClaimableData = async (
|
|
11
51
|
chainId: number,
|
|
@@ -15,8 +55,10 @@ export const fetchClaimableData = async (
|
|
|
15
55
|
campaigns: number[],
|
|
16
56
|
userVotes: any[][],
|
|
17
57
|
) => {
|
|
18
|
-
const inputCampaignsChunks =
|
|
19
|
-
|
|
58
|
+
const { campaignChunks: inputCampaignsChunks, voteChunks: inputVotesChunks } = chunkCampaignsWithVoteLimit(
|
|
59
|
+
campaigns,
|
|
60
|
+
userVotes,
|
|
61
|
+
)
|
|
20
62
|
|
|
21
63
|
const claimableCalls = inputCampaignsChunks.map((campaignsArgs, index) => {
|
|
22
64
|
const inputData = encodeAbiParameters(
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { contracts } from '@stake-dao/constants'
|
|
1
2
|
import { chunk } from 'lodash-es'
|
|
2
3
|
import { encodeAbiParameters, parseAbiParameters } from 'viem'
|
|
3
4
|
import { mainnet } from 'viem/chains'
|
|
5
|
+
import batchPendleVotes from '../bytecodes/votemarket/batchPendleVotes.js'
|
|
4
6
|
import batchVotes from '../bytecodes/votemarket/batchVotes.js'
|
|
5
7
|
import { STAKE_DAO_API } from '../endpoints.js'
|
|
6
8
|
import { concatBytecode } from '../index.js'
|
|
7
|
-
import { batchJsonRpcWithBlocks } from '../utils.js'
|
|
9
|
+
import { batchJsonRpcWithBlocks, equalTlc } from '../utils.js'
|
|
8
10
|
|
|
9
11
|
type Rpcs = {
|
|
10
12
|
[chainId: number]: string
|
|
@@ -35,20 +37,26 @@ export const fetchEpochsVotes = async (rpc: Rpcs, gaugeController: string, user:
|
|
|
35
37
|
// Merge blocks
|
|
36
38
|
const blocksForEpoch = [...cachedBlocks, ...missingBlocks]
|
|
37
39
|
|
|
38
|
-
const
|
|
40
|
+
const batchVotesProtocol = equalTlc(gaugeController, contracts.pendleGaugeController?.[1] || '')
|
|
41
|
+
? batchPendleVotes
|
|
42
|
+
: batchVotes
|
|
43
|
+
|
|
44
|
+
const inputData = encodeAbiParameters(parseAbiParameters(batchVotesProtocol.inputType[mainnet.id]!) as any, [
|
|
39
45
|
gaugeController,
|
|
40
46
|
user,
|
|
41
47
|
])
|
|
42
|
-
|
|
48
|
+
|
|
49
|
+
const call = concatBytecode(batchVotesProtocol.bytecode[mainnet.id]!, inputData)
|
|
43
50
|
|
|
44
51
|
const blocksChunks = chunk(blocksForEpoch, 10)
|
|
52
|
+
|
|
45
53
|
const votes = (
|
|
46
54
|
await Promise.all(
|
|
47
55
|
blocksChunks.map((b) =>
|
|
48
56
|
batchJsonRpcWithBlocks({
|
|
49
57
|
rpc: rpc[1]!,
|
|
50
58
|
call,
|
|
51
|
-
outputTypeAbi:
|
|
59
|
+
outputTypeAbi: batchVotesProtocol.outputTypeHr[mainnet.id],
|
|
52
60
|
callsKey: `Batch block votes data - chainId ${mainnet.id} - rpc ${rpc[mainnet.id]}`,
|
|
53
61
|
blocks: b,
|
|
54
62
|
}),
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { encodeAbiParameters, formatUnits, parseAbiParameters, zeroAddress } from 'viem'
|
|
2
|
+
import { mainnet } from 'viem/chains'
|
|
3
|
+
import batchPendleUserVotes from '../../bytecodes/votemarket/batchPendleUserVotes.js'
|
|
4
|
+
import { concatBytecode } from '../../index.js'
|
|
5
|
+
import { batchJsonRpc, equalTlc } from '../../utils.js'
|
|
6
|
+
import type { GaugesUserData } from '../curve/fetchCurveUserVotes.js'
|
|
7
|
+
|
|
8
|
+
export const fetchPendleUserVotes = async (rpc: string, user: string): Promise<GaugesUserData> => {
|
|
9
|
+
const calls = [
|
|
10
|
+
concatBytecode(
|
|
11
|
+
batchPendleUserVotes.bytecode[mainnet.id]!,
|
|
12
|
+
encodeAbiParameters(parseAbiParameters(batchPendleUserVotes.inputType[mainnet.id]!) as any, [user]),
|
|
13
|
+
),
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
const rawVotes = await batchJsonRpc({
|
|
17
|
+
rpc,
|
|
18
|
+
calls,
|
|
19
|
+
outputTypeAbi: batchPendleUserVotes.outputType![mainnet.id],
|
|
20
|
+
parse: false,
|
|
21
|
+
callsKey: `votemarket/pendle/fetchPendleUserVotes.ts: rawGauges - chainId ${mainnet.id} - rpc ${rpc}`,
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
const veBalance = rawVotes[0].veBalance
|
|
25
|
+
|
|
26
|
+
const votes = rawVotes[0].votes
|
|
27
|
+
.filter((rv) => !equalTlc(rv.gauge, zeroAddress))
|
|
28
|
+
.map((v) => ({
|
|
29
|
+
gauge: v.gauge,
|
|
30
|
+
slope: formatUnits(v.slope, 0),
|
|
31
|
+
relativeWeight: Number.parseFloat(formatUnits(v.power, 16)),
|
|
32
|
+
weight: formatUnits((veBalance * BigInt(v.power)) / BigInt(10 ** 16) / BigInt(100), 18),
|
|
33
|
+
start: Number(v.start),
|
|
34
|
+
end: Number(v.end),
|
|
35
|
+
}))
|
|
36
|
+
|
|
37
|
+
const unusedRelativeWeight = 10 ** 18 - votes.reduce((total, x) => total + x.relativeWeight * 100, 0)
|
|
38
|
+
const unusedVeBalance = (veBalance * BigInt(unusedRelativeWeight)) / BigInt(10 ** 18)
|
|
39
|
+
|
|
40
|
+
return {
|
|
41
|
+
veBalance: formatUnits(veBalance, 18),
|
|
42
|
+
unusedVeBalance: formatUnits(unusedVeBalance, 18),
|
|
43
|
+
unusedRelativeWeight: unusedRelativeWeight / 100,
|
|
44
|
+
votes,
|
|
45
|
+
}
|
|
46
|
+
}
|