@stake-dao/reader 0.4.95 → 0.4.96

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.
Files changed (51) hide show
  1. package/dist/esm/bytecodes/votemarket/batchCampaignsRestrictedVotes.js +1 -1
  2. package/dist/esm/bytecodes/votemarket/batchCampaignsRestrictedVotes.js.map +1 -1
  3. package/dist/esm/bytecodes/votemarket/batchClaimableData.js +1 -1
  4. package/dist/esm/bytecodes/votemarket/batchClaimableData.js.map +1 -1
  5. package/dist/esm/bytecodes/votemarket/batchGaugesWeight.js +1 -1
  6. package/dist/esm/bytecodes/votemarket/batchGaugesWeight.js.map +1 -1
  7. package/dist/esm/bytecodes/votemarket/batchPendleUserVotes.js +39 -0
  8. package/dist/esm/bytecodes/votemarket/batchPendleUserVotes.js.map +1 -0
  9. package/dist/esm/bytecodes/votemarket/batchPendleVotes.js +13 -0
  10. package/dist/esm/bytecodes/votemarket/batchPendleVotes.js.map +1 -0
  11. package/dist/esm/index.js +2 -0
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/esm/strategies/curve/fetch/index.js +1 -15
  14. package/dist/esm/strategies/curve/fetch/index.js.map +1 -1
  15. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  16. package/dist/esm/utils/snapshot.js +5 -0
  17. package/dist/esm/utils/snapshot.js.map +1 -1
  18. package/dist/esm/votemarket/curve/fetchSnapshotUserData.js +1 -1
  19. package/dist/esm/votemarket/curve/fetchSnapshotUserData.js.map +1 -1
  20. package/dist/esm/votemarket/fetchClaimableData.js +33 -4
  21. package/dist/esm/votemarket/fetchClaimableData.js.map +1 -1
  22. package/dist/esm/votemarket/fetchEpochVotes.js +9 -4
  23. package/dist/esm/votemarket/fetchEpochVotes.js.map +1 -1
  24. package/dist/esm/votemarket/pendle/fetchPendleUserVotes.js +37 -0
  25. package/dist/esm/votemarket/pendle/fetchPendleUserVotes.js.map +1 -0
  26. package/dist/types/bytecodes/votemarket/batchPendleUserVotes.d.ts +4 -0
  27. package/dist/types/bytecodes/votemarket/batchPendleUserVotes.d.ts.map +1 -0
  28. package/dist/types/bytecodes/votemarket/batchPendleVotes.d.ts +4 -0
  29. package/dist/types/bytecodes/votemarket/batchPendleVotes.d.ts.map +1 -0
  30. package/dist/types/index.d.ts +1 -0
  31. package/dist/types/index.d.ts.map +1 -1
  32. package/dist/types/strategies/curve/fetch/index.d.ts.map +1 -1
  33. package/dist/types/utils/snapshot.d.ts.map +1 -1
  34. package/dist/types/votemarket/curve/fetchSnapshotUserData.d.ts.map +1 -1
  35. package/dist/types/votemarket/fetchClaimableData.d.ts.map +1 -1
  36. package/dist/types/votemarket/fetchEpochVotes.d.ts.map +1 -1
  37. package/dist/types/votemarket/pendle/fetchPendleUserVotes.d.ts +3 -0
  38. package/dist/types/votemarket/pendle/fetchPendleUserVotes.d.ts.map +1 -0
  39. package/package.json +2 -2
  40. package/src/bytecodes/votemarket/batchCampaignsRestrictedVotes.ts +1 -1
  41. package/src/bytecodes/votemarket/batchClaimableData.ts +1 -1
  42. package/src/bytecodes/votemarket/batchGaugesWeight.ts +1 -1
  43. package/src/bytecodes/votemarket/batchPendleUserVotes.ts +41 -0
  44. package/src/bytecodes/votemarket/batchPendleVotes.ts +15 -0
  45. package/src/index.ts +3 -0
  46. package/src/strategies/curve/fetch/index.ts +1 -20
  47. package/src/utils/snapshot.ts +5 -0
  48. package/src/votemarket/curve/fetchSnapshotUserData.ts +1 -2
  49. package/src/votemarket/fetchClaimableData.ts +46 -4
  50. package/src/votemarket/fetchEpochVotes.ts +12 -4
  51. package/src/votemarket/pendle/fetchPendleUserVotes.ts +46 -0
@@ -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: notDeployedStrats,
265
+ notDeployed: [],
285
266
  fetched: true,
286
267
  }
287
268
  }
@@ -71,6 +71,11 @@ export const getSnapshotProposalVp = async (space: string, proposalId: string, u
71
71
  ) {
72
72
  vp
73
73
  }
74
+ votes(where: { voter: "${userAddress}", space: "${space}", proposal: "${proposalId}" }) {
75
+ vp
76
+ vp_by_strategy
77
+ vp_state
78
+ }
74
79
  }
75
80
  `,
76
81
  )
@@ -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 CLAIMABLE_CHUNK_SIZE = 5
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 = chunk(campaigns, CLAIMABLE_CHUNK_SIZE)
19
- const inputVotesChunks = chunk(userVotes, CLAIMABLE_CHUNK_SIZE)
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 inputData = encodeAbiParameters(parseAbiParameters(batchVotes.inputType[mainnet.id]!) as any, [
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
- const call = concatBytecode(batchVotes.bytecode[mainnet.id]!, inputData)
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: batchVotes.outputTypeHr[mainnet.id],
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
+ }