@stake-dao/reader 0.4.27 → 0.4.29
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/batchCampaigns.js +6 -3
- package/dist/esm/bytecodes/votemarket/batchCampaigns.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/batchClaimableData.js +21 -0
- package/dist/esm/bytecodes/votemarket/batchClaimableData.js.map +1 -0
- package/dist/esm/bytecodes/votemarket/batchGaugesWeight.js +13 -0
- package/dist/esm/bytecodes/votemarket/batchGaugesWeight.js.map +1 -0
- package/dist/esm/bytecodes/votemarket/batchVotes.js +13 -0
- package/dist/esm/bytecodes/votemarket/batchVotes.js.map +1 -0
- package/dist/esm/bytecodes/votemarket/curve/batchCurveGaugesMetadata.js +5 -3
- package/dist/esm/bytecodes/votemarket/curve/batchCurveGaugesMetadata.js.map +1 -1
- package/dist/esm/bytecodes/votemarket/curve/batchCurveOldLps.js +3 -2
- package/dist/esm/bytecodes/votemarket/curve/batchCurveOldLps.js.map +1 -1
- package/dist/esm/endpoints.js +0 -1
- package/dist/esm/endpoints.js.map +1 -1
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lockers/fetch/index.js +10 -0
- package/dist/esm/lockers/fetch/index.js.map +1 -1
- package/dist/esm/lockers/utils/getHttpCalls.js +8 -0
- package/dist/esm/lockers/utils/getHttpCalls.js.map +1 -1
- package/dist/esm/sdt/fetch.js +20 -26
- package/dist/esm/sdt/fetch.js.map +1 -1
- package/dist/esm/strategies/pancakeswap/endpoints.js +1 -1
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/utils.js +43 -19
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/votemarket/curve/config.js +4 -1
- package/dist/esm/votemarket/curve/config.js.map +1 -1
- package/dist/esm/votemarket/curve/fetchCurveGauges.js +6 -1
- package/dist/esm/votemarket/curve/fetchCurveGauges.js.map +1 -1
- package/dist/esm/votemarket/curve/fetchSnapshotUserData.js +14 -9
- package/dist/esm/votemarket/curve/fetchSnapshotUserData.js.map +1 -1
- package/dist/esm/votemarket/fetchCampaigns.js +115 -14
- package/dist/esm/votemarket/fetchCampaigns.js.map +1 -1
- package/dist/esm/votemarket/fetchClaimableData.js +36 -0
- package/dist/esm/votemarket/fetchClaimableData.js.map +1 -0
- package/dist/esm/votemarket/fetchEpochVotes.js +30 -0
- package/dist/esm/votemarket/fetchEpochVotes.js.map +1 -0
- package/dist/esm/votemarket/generateProofs/config.js +53 -0
- package/dist/esm/votemarket/generateProofs/config.js.map +1 -0
- package/dist/esm/votemarket/generateProofs/getBlockProof.js +33 -0
- package/dist/esm/votemarket/generateProofs/getBlockProof.js.map +1 -0
- package/dist/esm/votemarket/generateProofs/getGaugeProof.js +50 -0
- package/dist/esm/votemarket/generateProofs/getGaugeProof.js.map +1 -0
- package/dist/esm/votemarket/generateProofs/getUserProof.js +49 -0
- package/dist/esm/votemarket/generateProofs/getUserProof.js.map +1 -0
- package/dist/types/bytecodes/votemarket/batchCampaigns.d.ts.map +1 -1
- package/dist/types/bytecodes/votemarket/batchClaimableData.d.ts +4 -0
- package/dist/types/bytecodes/votemarket/batchClaimableData.d.ts.map +1 -0
- package/dist/types/bytecodes/votemarket/batchGaugesWeight.d.ts +4 -0
- package/dist/types/bytecodes/votemarket/batchGaugesWeight.d.ts.map +1 -0
- package/dist/types/bytecodes/votemarket/batchVotes.d.ts +4 -0
- package/dist/types/bytecodes/votemarket/batchVotes.d.ts.map +1 -0
- package/dist/types/bytecodes/votemarket/curve/batchCurveGaugesMetadata.d.ts.map +1 -1
- package/dist/types/bytecodes/votemarket/curve/batchCurveOldLps.d.ts.map +1 -1
- package/dist/types/endpoints.d.ts +0 -1
- package/dist/types/endpoints.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lockers/fetch/index.d.ts.map +1 -1
- package/dist/types/lockers/utils/getHttpCalls.d.ts +3 -0
- package/dist/types/lockers/utils/getHttpCalls.d.ts.map +1 -1
- package/dist/types/sdt/fetch.d.ts +2 -2
- package/dist/types/sdt/fetch.d.ts.map +1 -1
- package/dist/types/utils.d.ts +13 -1
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/votemarket/curve/config.d.ts +8 -1
- package/dist/types/votemarket/curve/config.d.ts.map +1 -1
- package/dist/types/votemarket/curve/fetchCurveGauges.d.ts.map +1 -1
- package/dist/types/votemarket/curve/fetchSnapshotUserData.d.ts +1 -0
- package/dist/types/votemarket/curve/fetchSnapshotUserData.d.ts.map +1 -1
- package/dist/types/votemarket/fetchCampaigns.d.ts.map +1 -1
- package/dist/types/votemarket/fetchClaimableData.d.ts +6 -0
- package/dist/types/votemarket/fetchClaimableData.d.ts.map +1 -0
- package/dist/types/votemarket/fetchEpochVotes.d.ts +9 -0
- package/dist/types/votemarket/fetchEpochVotes.d.ts.map +1 -0
- package/dist/types/votemarket/generateProofs/config.d.ts +32 -0
- package/dist/types/votemarket/generateProofs/config.d.ts.map +1 -0
- package/dist/types/votemarket/generateProofs/getBlockProof.d.ts +6 -0
- package/dist/types/votemarket/generateProofs/getBlockProof.d.ts.map +1 -0
- package/dist/types/votemarket/generateProofs/getGaugeProof.d.ts +6 -0
- package/dist/types/votemarket/generateProofs/getGaugeProof.d.ts.map +1 -0
- package/dist/types/votemarket/generateProofs/getUserProof.d.ts +6 -0
- package/dist/types/votemarket/generateProofs/getUserProof.d.ts.map +1 -0
- package/dist/types/votemarket/types.d.ts +31 -8
- package/dist/types/votemarket/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/bytecodes/votemarket/batchCampaigns.ts +6 -3
- package/src/bytecodes/votemarket/batchClaimableData.ts +24 -0
- package/src/bytecodes/votemarket/batchGaugesWeight.ts +15 -0
- package/src/bytecodes/votemarket/batchVotes.ts +15 -0
- package/src/bytecodes/votemarket/curve/batchCurveGaugesMetadata.ts +5 -3
- package/src/bytecodes/votemarket/curve/batchCurveOldLps.ts +3 -2
- package/src/endpoints.ts +0 -1
- package/src/index.ts +10 -0
- package/src/lockers/fetch/index.ts +13 -0
- package/src/lockers/utils/getHttpCalls.ts +8 -0
- package/src/sdt/fetch.ts +29 -27
- package/src/strategies/pancakeswap/endpoints.ts +1 -1
- package/src/utils.ts +66 -19
- package/src/votemarket/curve/config.ts +5 -1
- package/src/votemarket/curve/fetchCurveGauges.ts +15 -2
- package/src/votemarket/curve/fetchSnapshotUserData.ts +16 -9
- package/src/votemarket/fetchCampaigns.ts +148 -15
- package/src/votemarket/fetchClaimableData.ts +50 -0
- package/src/votemarket/fetchEpochVotes.ts +48 -0
- package/src/votemarket/generateProofs/config.ts +53 -0
- package/src/votemarket/generateProofs/getBlockProof.ts +48 -0
- package/src/votemarket/generateProofs/getGaugeProof.ts +75 -0
- package/src/votemarket/generateProofs/getUserProof.ts +74 -0
- package/src/votemarket/types.ts +36 -8
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { http, createPublicClient, encodeAbiParameters, fromRlp, keccak256, toHex, toRlp } from 'viem'
|
|
2
|
+
import { mainnet } from 'viem/chains'
|
|
3
|
+
import { GaugeControllerConstants } from './config.js'
|
|
4
|
+
|
|
5
|
+
type Rpcs = {
|
|
6
|
+
[chainId: number]: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Helper function to encode gauge time
|
|
10
|
+
function _encodeGaugeTime(gauge: `0x${string}`, time: bigint, baseSlot: number): `0x${string}` {
|
|
11
|
+
const gaugeEncoded = keccak256(
|
|
12
|
+
encodeAbiParameters([{ type: 'uint256' }, { type: 'address' }], [BigInt(baseSlot), gauge]),
|
|
13
|
+
)
|
|
14
|
+
return keccak256(encodeAbiParameters([{ type: 'bytes32' }, { type: 'uint256' }], [gaugeEncoded, time]))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Function to get storage slot for non-Curve protocols
|
|
18
|
+
function getGaugeTimeStorageSlot(gauge: `0x${string}`, time: bigint, baseSlot: number): bigint {
|
|
19
|
+
const finalSlot = _encodeGaugeTime(gauge, time, baseSlot)
|
|
20
|
+
return BigInt(finalSlot)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Function to get storage slot for Curve protocol (pre-Vyper 0.3)
|
|
24
|
+
function getGaugeTimeStorageSlotPreVyper03(gauge: `0x${string}`, time: bigint, baseSlot: number): bigint {
|
|
25
|
+
const intermediateHash = _encodeGaugeTime(gauge, time, baseSlot)
|
|
26
|
+
const finalSlot = keccak256(encodeAbiParameters([{ type: 'bytes32' }], [intermediateHash]))
|
|
27
|
+
return BigInt(finalSlot)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Main function to generate gauge proof
|
|
31
|
+
export async function generateGaugeProof(
|
|
32
|
+
rpc: Rpcs,
|
|
33
|
+
protocol: string,
|
|
34
|
+
gaugeAddress: `0x${string}`,
|
|
35
|
+
currentPeriod: bigint,
|
|
36
|
+
blockNumber: bigint,
|
|
37
|
+
): Promise<[string, string]> {
|
|
38
|
+
const publicClient = createPublicClient({
|
|
39
|
+
chain: mainnet,
|
|
40
|
+
transport: http(rpc[mainnet.id]),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const pointWeightsBaseSlot = GaugeControllerConstants.GAUGES_SLOTS[protocol].pointWeights
|
|
44
|
+
|
|
45
|
+
const positionFunctions: Record<string, any> = {
|
|
46
|
+
curve: getGaugeTimeStorageSlotPreVyper03,
|
|
47
|
+
default: getGaugeTimeStorageSlot,
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const getPosition = positionFunctions[protocol] || positionFunctions.default
|
|
51
|
+
const pointWeightsPosition = getPosition!(gaugeAddress, currentPeriod, pointWeightsBaseSlot)
|
|
52
|
+
|
|
53
|
+
const slots = [toHex(pointWeightsPosition)]
|
|
54
|
+
|
|
55
|
+
const proof = await publicClient.getProof({
|
|
56
|
+
address: GaugeControllerConstants.GAUGE_CONTROLLER[protocol] as `0x${string}`,
|
|
57
|
+
storageKeys: slots,
|
|
58
|
+
blockNumber,
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
const decodedAccountProof = proof.accountProof.map((p) => fromRlp(p))
|
|
62
|
+
const accountProof = toRlp(decodedAccountProof)
|
|
63
|
+
|
|
64
|
+
const decodedStorageProof = proof.storageProof[0]!.proof.map((p) => fromRlp(p))
|
|
65
|
+
let storageProof = toRlp(decodedStorageProof)
|
|
66
|
+
|
|
67
|
+
// Add length prefix to match Python output for storage proof
|
|
68
|
+
const storageProofLength = (storageProof.length - 2) / 2 // subtract 2 for '0x' prefix
|
|
69
|
+
const storageProofLengthHex = storageProofLength.toString(16).padStart(4, '0')
|
|
70
|
+
|
|
71
|
+
// 0xf9 is the RLP prefix for a list longer than 55 bytes, followed by the length of the length (2 bytes), and then the length itself
|
|
72
|
+
storageProof = `0xf9${storageProofLengthHex}${storageProof.slice(2)}`
|
|
73
|
+
|
|
74
|
+
return [accountProof, storageProof]
|
|
75
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { http, createPublicClient, encodeAbiParameters, fromRlp, keccak256, toHex, toRlp } from 'viem'
|
|
2
|
+
import { mainnet } from 'viem/chains'
|
|
3
|
+
import { GaugeControllerConstants } from './config.js'
|
|
4
|
+
|
|
5
|
+
type Rpcs = {
|
|
6
|
+
[chainId: number]: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// Helper function to encode user gauge data
|
|
10
|
+
function _encodeUserGaugeData(user: `0x${string}`, gauge: `0x${string}`, baseSlot: number): `0x${string}` {
|
|
11
|
+
const userEncoded = keccak256(
|
|
12
|
+
encodeAbiParameters([{ type: 'uint256' }, { type: 'address' }], [BigInt(baseSlot), user]),
|
|
13
|
+
)
|
|
14
|
+
return keccak256(encodeAbiParameters([{ type: 'bytes32' }, { type: 'address' }], [userEncoded, gauge]))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Function to get storage slot for non-Curve protocols
|
|
18
|
+
function getUserGaugeStorageSlot(user: `0x${string}`, gauge: `0x${string}`, baseSlot: number): bigint {
|
|
19
|
+
const finalSlot = _encodeUserGaugeData(user, gauge, baseSlot)
|
|
20
|
+
return BigInt(finalSlot)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// Function to get storage slot for Curve protocol (pre-Vyper 0.3)
|
|
24
|
+
function getUserGaugeStorageSlotPreVyper03(user: `0x${string}`, gauge: `0x${string}`, baseSlot: number): bigint {
|
|
25
|
+
const intermediateHash = _encodeUserGaugeData(user, gauge, baseSlot)
|
|
26
|
+
const finalSlot = keccak256(encodeAbiParameters([{ type: 'bytes32' }], [intermediateHash]))
|
|
27
|
+
return BigInt(finalSlot)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Main function to generate user proof
|
|
31
|
+
export async function generateUserProof(
|
|
32
|
+
rpc: Rpcs,
|
|
33
|
+
protocol: string,
|
|
34
|
+
gaugeAddress: `0x${string}`,
|
|
35
|
+
user: `0x${string}`,
|
|
36
|
+
blockNumber: bigint,
|
|
37
|
+
): Promise<[string, string]> {
|
|
38
|
+
const publicClient = createPublicClient({
|
|
39
|
+
chain: mainnet,
|
|
40
|
+
transport: http(rpc[mainnet.id]),
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const lastUserVoteBaseSlot = GaugeControllerConstants.GAUGES_SLOTS[protocol].lastUserVote
|
|
44
|
+
const voteUserSlopeBaseSlot = GaugeControllerConstants.GAUGES_SLOTS[protocol].voteUserSlope
|
|
45
|
+
|
|
46
|
+
const lastUserVoteSlot = getUserGaugeStorageSlot(user, gaugeAddress, lastUserVoteBaseSlot)
|
|
47
|
+
|
|
48
|
+
const positionFunctions: Record<string, any> = {
|
|
49
|
+
curve: getUserGaugeStorageSlotPreVyper03,
|
|
50
|
+
default: getUserGaugeStorageSlot,
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const getPosition = positionFunctions[protocol] || positionFunctions.default
|
|
54
|
+
const voteUserSlopeSlot = getPosition(user, gaugeAddress, voteUserSlopeBaseSlot)
|
|
55
|
+
|
|
56
|
+
const voteUserSlopeSlope = voteUserSlopeSlot
|
|
57
|
+
const voteUserSlopeEnd = voteUserSlopeSlot + 2n
|
|
58
|
+
|
|
59
|
+
const slots = [toHex(lastUserVoteSlot), toHex(voteUserSlopeSlope), toHex(voteUserSlopeEnd)]
|
|
60
|
+
|
|
61
|
+
const proof = await publicClient.getProof({
|
|
62
|
+
address: GaugeControllerConstants.GAUGE_CONTROLLER[protocol] as `0x${string}`,
|
|
63
|
+
storageKeys: slots,
|
|
64
|
+
blockNumber,
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const decodedAccountProof = proof.accountProof.map((p) => fromRlp(p))
|
|
68
|
+
const accountProof = toRlp(decodedAccountProof)
|
|
69
|
+
|
|
70
|
+
const decodedStorageProof = proof.storageProof.map((sp) => sp.proof.map((p) => fromRlp(p)))
|
|
71
|
+
const storageProof = toRlp(decodedStorageProof)
|
|
72
|
+
|
|
73
|
+
return [accountProof, storageProof]
|
|
74
|
+
}
|
package/src/votemarket/types.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
|
+
export type Period = {
|
|
2
|
+
rewardPerPeriod: string
|
|
3
|
+
rewardPerVote: string
|
|
4
|
+
leftover: string
|
|
5
|
+
updated: boolean
|
|
6
|
+
}
|
|
7
|
+
|
|
1
8
|
export type Campaign = {
|
|
2
9
|
id: number
|
|
3
10
|
chainId: number
|
|
4
11
|
gauge: string
|
|
12
|
+
gaugeChainId: number
|
|
5
13
|
manager: string
|
|
6
14
|
rewardToken: {
|
|
7
15
|
name: string
|
|
@@ -10,6 +18,7 @@ export type Campaign = {
|
|
|
10
18
|
decimals: number
|
|
11
19
|
chainId: number
|
|
12
20
|
}
|
|
21
|
+
rewardTokenPrice: number
|
|
13
22
|
numberOfPeriods: number
|
|
14
23
|
maxRewardPerVote: string
|
|
15
24
|
totalRewardAmount: string
|
|
@@ -17,17 +26,12 @@ export type Campaign = {
|
|
|
17
26
|
startTimestamp: number
|
|
18
27
|
endTimestamp: number
|
|
19
28
|
hook: string
|
|
20
|
-
|
|
29
|
+
isClosed: boolean
|
|
21
30
|
addresses: string[]
|
|
22
31
|
isWhitelist: boolean
|
|
23
32
|
isBlacklist: boolean
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
rewardPerVote: string
|
|
27
|
-
leftover: string
|
|
28
|
-
updated: boolean
|
|
29
|
-
}
|
|
30
|
-
totalPeriods: number
|
|
33
|
+
previousPeriod: Period
|
|
34
|
+
currentPeriod: Period
|
|
31
35
|
periodLeft: number
|
|
32
36
|
status: {
|
|
33
37
|
voteOpen: boolean
|
|
@@ -36,4 +40,28 @@ export type Campaign = {
|
|
|
36
40
|
claimClosed: boolean
|
|
37
41
|
expired: boolean
|
|
38
42
|
}
|
|
43
|
+
claimableAmount?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// RAW
|
|
47
|
+
|
|
48
|
+
export type RawPeriod = {
|
|
49
|
+
rewardPerPeriod: bigint
|
|
50
|
+
rewardPerVote: bigint
|
|
51
|
+
leftover: bigint
|
|
52
|
+
updated: boolean
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export type RawCampaign = {
|
|
56
|
+
chainId: bigint
|
|
57
|
+
endTimestamp: bigint
|
|
58
|
+
gauge: string
|
|
59
|
+
hook: string
|
|
60
|
+
manager: string
|
|
61
|
+
maxRewardPerVote: bigint
|
|
62
|
+
numberOfPeriods: number
|
|
63
|
+
rewardToken: bigint
|
|
64
|
+
startTimestamp: bigint
|
|
65
|
+
totalDistributed: bigint
|
|
66
|
+
totalRewardAmount: bigint
|
|
39
67
|
}
|