@stake-dao/reader 0.4.32 → 0.4.34

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 (82) hide show
  1. package/dist/esm/bytecodes/index.js +1 -0
  2. package/dist/esm/bytecodes/index.js.map +1 -1
  3. package/dist/esm/bytecodes/votemarket/batchCampaigns.js +1 -1
  4. package/dist/esm/bytecodes/votemarket/batchCampaigns.js.map +1 -1
  5. package/dist/esm/bytecodes/votemarket/batchCampaignsRestrictedVotes.js +33 -0
  6. package/dist/esm/bytecodes/votemarket/batchCampaignsRestrictedVotes.js.map +1 -0
  7. package/dist/esm/bytecodes/votemarket/batchClaimableData.js +1 -1
  8. package/dist/esm/bytecodes/votemarket/batchClaimableData.js.map +1 -1
  9. package/dist/esm/bytecodes/votemarket/getNeededCampaignUpdate.js +17 -0
  10. package/dist/esm/bytecodes/votemarket/getNeededCampaignUpdate.js.map +1 -0
  11. package/dist/esm/endpoints.js +1 -0
  12. package/dist/esm/endpoints.js.map +1 -1
  13. package/dist/esm/index.js +3 -1
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/esm/strategies/curve/fetch/curveApiData/getGaugesWeights.js +2 -2
  16. package/dist/esm/strategies/curve/fetch/curveApiData/getGaugesWeights.js.map +1 -1
  17. package/dist/esm/strategies/pancakeswap/fetch/getPancakeV3Vaults.js +1 -1
  18. package/dist/esm/strategies/pancakeswap/fetch/getPancakeV3Vaults.js.map +1 -1
  19. package/dist/esm/strategies/pancakeswap/fetch/pancakePositions.js +2 -2
  20. package/dist/esm/strategies/pancakeswap/fetch/pancakePositions.js.map +1 -1
  21. package/dist/esm/strategies/pancakeswap/fetch/pancakeswapMath.js +1 -1
  22. package/dist/esm/strategies/pancakeswap/fetch/pancakeswapMath.js.map +1 -1
  23. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  24. package/dist/esm/utils.js +13 -0
  25. package/dist/esm/utils.js.map +1 -1
  26. package/dist/esm/votemarket/curve/fetchCurveGauges.js +4 -1
  27. package/dist/esm/votemarket/curve/fetchCurveGauges.js.map +1 -1
  28. package/dist/esm/votemarket/curve/fetchSnapshotUserData.js +34 -1
  29. package/dist/esm/votemarket/curve/fetchSnapshotUserData.js.map +1 -1
  30. package/dist/esm/votemarket/curve/fetchUserVlCvxClaimable.js +37 -5
  31. package/dist/esm/votemarket/curve/fetchUserVlCvxClaimable.js.map +1 -1
  32. package/dist/esm/votemarket/fetchCampaigns.js +75 -14
  33. package/dist/esm/votemarket/fetchCampaigns.js.map +1 -1
  34. package/dist/esm/votemarket/fetchNeededCampaignUpdate.js +17 -0
  35. package/dist/esm/votemarket/fetchNeededCampaignUpdate.js.map +1 -0
  36. package/dist/esm/votemarket/fetchPendingRemoteCampaigns.js +102 -0
  37. package/dist/esm/votemarket/fetchPendingRemoteCampaigns.js.map +1 -0
  38. package/dist/types/bytecodes/index.d.ts +1 -0
  39. package/dist/types/bytecodes/index.d.ts.map +1 -1
  40. package/dist/types/bytecodes/votemarket/batchCampaignsRestrictedVotes.d.ts +4 -0
  41. package/dist/types/bytecodes/votemarket/batchCampaignsRestrictedVotes.d.ts.map +1 -0
  42. package/dist/types/bytecodes/votemarket/getNeededCampaignUpdate.d.ts +4 -0
  43. package/dist/types/bytecodes/votemarket/getNeededCampaignUpdate.d.ts.map +1 -0
  44. package/dist/types/endpoints.d.ts +1 -0
  45. package/dist/types/endpoints.d.ts.map +1 -1
  46. package/dist/types/index.d.ts +3 -1
  47. package/dist/types/index.d.ts.map +1 -1
  48. package/dist/types/strategies/pancakeswap/fetch/pancakeswapMath.d.ts.map +1 -1
  49. package/dist/types/utils.d.ts +1 -0
  50. package/dist/types/utils.d.ts.map +1 -1
  51. package/dist/types/votemarket/curve/fetchCurveGauges.d.ts.map +1 -1
  52. package/dist/types/votemarket/curve/fetchSnapshotUserData.d.ts +6 -0
  53. package/dist/types/votemarket/curve/fetchSnapshotUserData.d.ts.map +1 -1
  54. package/dist/types/votemarket/curve/fetchUserVlCvxClaimable.d.ts.map +1 -1
  55. package/dist/types/votemarket/fetchCampaigns.d.ts +6 -1
  56. package/dist/types/votemarket/fetchCampaigns.d.ts.map +1 -1
  57. package/dist/types/votemarket/fetchNeededCampaignUpdate.d.ts +2 -0
  58. package/dist/types/votemarket/fetchNeededCampaignUpdate.d.ts.map +1 -0
  59. package/dist/types/votemarket/fetchPendingRemoteCampaigns.d.ts +46 -0
  60. package/dist/types/votemarket/fetchPendingRemoteCampaigns.d.ts.map +1 -0
  61. package/dist/types/votemarket/types.d.ts +1 -0
  62. package/dist/types/votemarket/types.d.ts.map +1 -1
  63. package/package.json +2 -2
  64. package/src/bytecodes/index.ts +1 -0
  65. package/src/bytecodes/votemarket/batchCampaigns.ts +1 -1
  66. package/src/bytecodes/votemarket/batchCampaignsRestrictedVotes.ts +35 -0
  67. package/src/bytecodes/votemarket/batchClaimableData.ts +1 -1
  68. package/src/bytecodes/votemarket/getNeededCampaignUpdate.ts +19 -0
  69. package/src/endpoints.ts +2 -0
  70. package/src/index.ts +3 -1
  71. package/src/strategies/curve/fetch/curveApiData/getGaugesWeights.ts +2 -2
  72. package/src/strategies/pancakeswap/fetch/getPancakeV3Vaults.ts +1 -1
  73. package/src/strategies/pancakeswap/fetch/pancakePositions.ts +2 -2
  74. package/src/strategies/pancakeswap/fetch/pancakeswapMath.ts +1 -1
  75. package/src/utils.ts +19 -0
  76. package/src/votemarket/curve/fetchCurveGauges.ts +5 -1
  77. package/src/votemarket/curve/fetchSnapshotUserData.ts +43 -3
  78. package/src/votemarket/curve/fetchUserVlCvxClaimable.ts +51 -6
  79. package/src/votemarket/fetchCampaigns.ts +113 -16
  80. package/src/votemarket/fetchNeededCampaignUpdate.ts +28 -0
  81. package/src/votemarket/fetchPendingRemoteCampaigns.ts +141 -0
  82. package/src/votemarket/types.ts +1 -0
@@ -0,0 +1,141 @@
1
+ import { LA_POSTE_MESSAGE_SENT_EVENT, ONE_WEEK, One, Zero, contract } from '@stake-dao/constants'
2
+ import { range } from 'lodash-es'
3
+ import { decodeAbiParameters, decodeEventLog, parseAbiParameters, zeroAddress } from 'viem'
4
+ import { mainnet } from 'viem/chains'
5
+
6
+ export const CAMPAIGNS_CHUNK_SIZE = 10
7
+ export const CLAIM_WINDOW_LENGTH = 24 // weeks
8
+ export const CLOSE_WINDOW_LENGTH = 4 // weeks
9
+
10
+ interface FetchPendingRemoteCampaignsProps {
11
+ mainnetVmRemote: string
12
+ chainId: number
13
+ fromBlock: number
14
+ etherscanApiKey: string
15
+ nextIndex: number
16
+ }
17
+
18
+ export const fetchPendingRemoteCampaigns = async ({
19
+ mainnetVmRemote,
20
+ chainId,
21
+ fromBlock,
22
+ etherscanApiKey,
23
+ nextIndex,
24
+ }: FetchPendingRemoteCampaignsProps) => {
25
+ const queryParams = {
26
+ chainid: `${mainnet.id}`,
27
+ module: 'logs',
28
+ action: 'getLogs',
29
+ address: contract('laPoste', chainId),
30
+ topic0: LA_POSTE_MESSAGE_SENT_EVENT.topic,
31
+ topic0_3_opr: 'and',
32
+ topic3: mainnetVmRemote.replace('0x', '0x000000000000000000000000'),
33
+ apikey: etherscanApiKey,
34
+ fromBlock: `${fromBlock}`,
35
+ }
36
+
37
+ const rawEvents = await fetch(`https://api.etherscan.io/v2/api?${new URLSearchParams(queryParams)}`).then((res) =>
38
+ res.json(),
39
+ )
40
+
41
+ const campaignsParams: any[] = []
42
+ const manageParams: any[] = []
43
+
44
+ if (rawEvents.message === 'OK') {
45
+ for (const e of rawEvents.result) {
46
+ const decodedEvent: any = decodeEventLog({
47
+ abi: LA_POSTE_MESSAGE_SENT_EVENT.abi,
48
+ data: e.data,
49
+ topics: e.topics,
50
+ })
51
+
52
+ try {
53
+ if (Number(decodedEvent.args.chainId) === chainId) {
54
+ const payload = decodeAbiParameters(
55
+ parseAbiParameters([
56
+ 'Payload payload',
57
+ 'struct Payload { uint256 actionType; address sender; bytes parameters }',
58
+ ]),
59
+ decodedEvent.args.message.payload,
60
+ )
61
+
62
+ // Create Campaign (actionType === 0)
63
+ if (payload[0].actionType === Zero) {
64
+ const decodedParams = decodeAbiParameters(
65
+ parseAbiParameters([
66
+ 'CampaignCreationParams params',
67
+ 'struct CampaignCreationParams { uint256 chainId; address gauge; address manager; address rewardToken; uint8 numberOfPeriods; uint256 maxRewardPerVote; uint256 totalRewardAmount; address[] addresses; address hook; bool isWhitelist; }',
68
+ ]),
69
+ (payload[0] as any).parameters,
70
+ )
71
+
72
+ campaignsParams.push({ decoded: decodedParams[0], eventTimestamp: Number(e.timeStamp) })
73
+ }
74
+
75
+ // Manage Campaign (actionType === 1)
76
+ if (payload[0].actionType === One) {
77
+ const decodedParams = decodeAbiParameters(
78
+ parseAbiParameters([
79
+ 'CampaignManagementParams params',
80
+ 'struct CampaignManagementParams { uint256 campaignId; address rewardToken; uint8 numberOfPeriods; uint256 totalRewardAmount; uint256 maxRewardPerVote; }',
81
+ ]),
82
+ (payload[0] as any).parameters,
83
+ )
84
+
85
+ manageParams.push({ decoded: decodedParams[0], eventTimestamp: Number(e.timeStamp) })
86
+ }
87
+ }
88
+ } catch (err) {
89
+ console.error(err)
90
+ }
91
+ }
92
+ }
93
+
94
+ const remoteCampaigns = campaignsParams.map((element) => {
95
+ const campaignParams = element.decoded
96
+
97
+ const totalRewardAmount = campaignParams.totalRewardAmount
98
+ const maxRewardPerVote = campaignParams.maxRewardPerVote
99
+ const numberOfPeriods = BigInt(campaignParams.numberOfPeriods)
100
+
101
+ const startTimestamp = BigInt(Math.floor(element.eventTimestamp / ONE_WEEK) * ONE_WEEK + ONE_WEEK)
102
+ const endTimestamp = startTimestamp + numberOfPeriods * BigInt(ONE_WEEK)
103
+
104
+ const campaign = {
105
+ isPendingRemote: true,
106
+ id: BigInt(nextIndex),
107
+ addresses: campaignParams.addresses,
108
+ campaign: {
109
+ chainId: campaignParams.chainId,
110
+ startTimestamp,
111
+ endTimestamp,
112
+ gauge: campaignParams.gauge,
113
+ hook: campaignParams.hook,
114
+ manager: campaignParams.manager,
115
+ maxRewardPerVote,
116
+ numberOfPeriods: Number(numberOfPeriods),
117
+ rewardToken: zeroAddress, // Unknown
118
+ totalDistributed: Zero,
119
+ totalRewardAmount,
120
+ },
121
+ isKilled: false,
122
+ isWhitelistOnly: campaignParams.isWhitelist,
123
+ periodLeft: campaignParams.numberOfPeriods,
124
+ periods: range(0, Number(numberOfPeriods)).map((index) => ({
125
+ timestampStart: startTimestamp + BigInt(index) * BigInt(ONE_WEEK),
126
+ timestampEnd: startTimestamp + BigInt(ONE_WEEK) + BigInt(index) * BigInt(ONE_WEEK),
127
+ rewardPerPeriod: totalRewardAmount / numberOfPeriods,
128
+ rewardPerVote: maxRewardPerVote,
129
+ leftover: Zero,
130
+ updated: false,
131
+ })),
132
+ rewardAddress: campaignParams.rewardToken,
133
+ rewardChainId: BigInt(mainnet.id),
134
+ }
135
+
136
+ nextIndex++
137
+ return campaign
138
+ })
139
+
140
+ return { remoteCampaigns, remoteCampaignsUpdate: manageParams }
141
+ }
@@ -11,6 +11,7 @@ export type Campaign = {
11
11
  gauge: string
12
12
  gaugeChainId: number
13
13
  manager: string
14
+ restrictedVotes: string
14
15
  rewardChainId: number
15
16
  receiptRewardToken: {
16
17
  name: string