@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.
- package/dist/esm/bytecodes/index.js +1 -0
- package/dist/esm/bytecodes/index.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/batchCampaigns.js +1 -1
- package/dist/esm/bytecodes/votemarket/batchCampaigns.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/batchCampaignsRestrictedVotes.js +33 -0
- package/dist/esm/bytecodes/votemarket/batchCampaignsRestrictedVotes.js.map +1 -0
- package/dist/esm/bytecodes/votemarket/batchClaimableData.js +1 -1
- package/dist/esm/bytecodes/votemarket/batchClaimableData.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/getNeededCampaignUpdate.js +17 -0
- package/dist/esm/bytecodes/votemarket/getNeededCampaignUpdate.js.map +1 -0
- package/dist/esm/endpoints.js +1 -0
- package/dist/esm/endpoints.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/strategies/curve/fetch/curveApiData/getGaugesWeights.js +2 -2
- package/dist/esm/strategies/curve/fetch/curveApiData/getGaugesWeights.js.map +1 -1
- package/dist/esm/strategies/pancakeswap/fetch/getPancakeV3Vaults.js +1 -1
- package/dist/esm/strategies/pancakeswap/fetch/getPancakeV3Vaults.js.map +1 -1
- package/dist/esm/strategies/pancakeswap/fetch/pancakePositions.js +2 -2
- package/dist/esm/strategies/pancakeswap/fetch/pancakePositions.js.map +1 -1
- package/dist/esm/strategies/pancakeswap/fetch/pancakeswapMath.js +1 -1
- package/dist/esm/strategies/pancakeswap/fetch/pancakeswapMath.js.map +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/utils.js +13 -0
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/votemarket/curve/fetchCurveGauges.js +4 -1
- package/dist/esm/votemarket/curve/fetchCurveGauges.js.map +1 -1
- package/dist/esm/votemarket/curve/fetchSnapshotUserData.js +34 -1
- package/dist/esm/votemarket/curve/fetchSnapshotUserData.js.map +1 -1
- package/dist/esm/votemarket/curve/fetchUserVlCvxClaimable.js +37 -5
- package/dist/esm/votemarket/curve/fetchUserVlCvxClaimable.js.map +1 -1
- package/dist/esm/votemarket/fetchCampaigns.js +75 -14
- package/dist/esm/votemarket/fetchCampaigns.js.map +1 -1
- package/dist/esm/votemarket/fetchNeededCampaignUpdate.js +17 -0
- package/dist/esm/votemarket/fetchNeededCampaignUpdate.js.map +1 -0
- package/dist/esm/votemarket/fetchPendingRemoteCampaigns.js +102 -0
- package/dist/esm/votemarket/fetchPendingRemoteCampaigns.js.map +1 -0
- package/dist/types/bytecodes/index.d.ts +1 -0
- package/dist/types/bytecodes/index.d.ts.map +1 -1
- package/dist/types/bytecodes/votemarket/batchCampaignsRestrictedVotes.d.ts +4 -0
- package/dist/types/bytecodes/votemarket/batchCampaignsRestrictedVotes.d.ts.map +1 -0
- package/dist/types/bytecodes/votemarket/getNeededCampaignUpdate.d.ts +4 -0
- package/dist/types/bytecodes/votemarket/getNeededCampaignUpdate.d.ts.map +1 -0
- package/dist/types/endpoints.d.ts +1 -0
- package/dist/types/endpoints.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/strategies/pancakeswap/fetch/pancakeswapMath.d.ts.map +1 -1
- package/dist/types/utils.d.ts +1 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/votemarket/curve/fetchCurveGauges.d.ts.map +1 -1
- package/dist/types/votemarket/curve/fetchSnapshotUserData.d.ts +6 -0
- package/dist/types/votemarket/curve/fetchSnapshotUserData.d.ts.map +1 -1
- package/dist/types/votemarket/curve/fetchUserVlCvxClaimable.d.ts.map +1 -1
- package/dist/types/votemarket/fetchCampaigns.d.ts +6 -1
- package/dist/types/votemarket/fetchCampaigns.d.ts.map +1 -1
- package/dist/types/votemarket/fetchNeededCampaignUpdate.d.ts +2 -0
- package/dist/types/votemarket/fetchNeededCampaignUpdate.d.ts.map +1 -0
- package/dist/types/votemarket/fetchPendingRemoteCampaigns.d.ts +46 -0
- package/dist/types/votemarket/fetchPendingRemoteCampaigns.d.ts.map +1 -0
- package/dist/types/votemarket/types.d.ts +1 -0
- package/dist/types/votemarket/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/bytecodes/index.ts +1 -0
- package/src/bytecodes/votemarket/batchCampaigns.ts +1 -1
- package/src/bytecodes/votemarket/batchCampaignsRestrictedVotes.ts +35 -0
- package/src/bytecodes/votemarket/batchClaimableData.ts +1 -1
- package/src/bytecodes/votemarket/getNeededCampaignUpdate.ts +19 -0
- package/src/endpoints.ts +2 -0
- package/src/index.ts +3 -1
- package/src/strategies/curve/fetch/curveApiData/getGaugesWeights.ts +2 -2
- package/src/strategies/pancakeswap/fetch/getPancakeV3Vaults.ts +1 -1
- package/src/strategies/pancakeswap/fetch/pancakePositions.ts +2 -2
- package/src/strategies/pancakeswap/fetch/pancakeswapMath.ts +1 -1
- package/src/utils.ts +19 -0
- package/src/votemarket/curve/fetchCurveGauges.ts +5 -1
- package/src/votemarket/curve/fetchSnapshotUserData.ts +43 -3
- package/src/votemarket/curve/fetchUserVlCvxClaimable.ts +51 -6
- package/src/votemarket/fetchCampaigns.ts +113 -16
- package/src/votemarket/fetchNeededCampaignUpdate.ts +28 -0
- package/src/votemarket/fetchPendingRemoteCampaigns.ts +141 -0
- 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
|
+
}
|