@stake-dao/reader 0.4.58 → 0.4.59

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 (43) hide show
  1. package/dist/esm/bytecodes/votemarket/batchUserVotes.js +39 -0
  2. package/dist/esm/bytecodes/votemarket/batchUserVotes.js.map +1 -0
  3. package/dist/esm/index.js +4 -0
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  6. package/dist/esm/votemarket/balancer/fetchBalancerUserVotes.js +42 -0
  7. package/dist/esm/votemarket/balancer/fetchBalancerUserVotes.js.map +1 -0
  8. package/dist/esm/votemarket/curve/fetchCurveUserVotes.js +8 -3
  9. package/dist/esm/votemarket/curve/fetchCurveUserVotes.js.map +1 -1
  10. package/dist/esm/votemarket/fetchCampaigns/index.js +1 -0
  11. package/dist/esm/votemarket/fetchCampaigns/index.js.map +1 -1
  12. package/dist/esm/votemarket/fetchCampaigns/pendingRemote.js +5 -1
  13. package/dist/esm/votemarket/fetchCampaigns/pendingRemote.js.map +1 -1
  14. package/dist/esm/votemarket/fetchCampaigns/processRawCampaigns.js +2 -2
  15. package/dist/esm/votemarket/fetchCampaigns/processRawCampaigns.js.map +1 -1
  16. package/dist/esm/votemarket/fxn/fetchFxnUserVotes.js +42 -0
  17. package/dist/esm/votemarket/fxn/fetchFxnUserVotes.js.map +1 -0
  18. package/dist/types/bytecodes/votemarket/batchUserVotes.d.ts +4 -0
  19. package/dist/types/bytecodes/votemarket/batchUserVotes.d.ts.map +1 -0
  20. package/dist/types/index.d.ts +2 -0
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/votemarket/balancer/fetchBalancerUserVotes.d.ts +16 -0
  23. package/dist/types/votemarket/balancer/fetchBalancerUserVotes.d.ts.map +1 -0
  24. package/dist/types/votemarket/curve/fetchCurveUserVotes.d.ts.map +1 -1
  25. package/dist/types/votemarket/fetchCampaigns/index.d.ts.map +1 -1
  26. package/dist/types/votemarket/fetchCampaigns/pendingRemote.d.ts +2 -1
  27. package/dist/types/votemarket/fetchCampaigns/pendingRemote.d.ts.map +1 -1
  28. package/dist/types/votemarket/fxn/fetchFxnUserVotes.d.ts +16 -0
  29. package/dist/types/votemarket/fxn/fetchFxnUserVotes.d.ts.map +1 -0
  30. package/package.json +2 -2
  31. package/src/bytecodes/votemarket/batchUserVotes.ts +41 -0
  32. package/src/index.ts +6 -0
  33. package/src/votemarket/balancer/fetchBalancerUserVotes.ts +61 -0
  34. package/src/votemarket/curve/fetchCurveUserVotes.ts +9 -4
  35. package/src/votemarket/fetchCampaigns/index.ts +1 -0
  36. package/src/votemarket/fetchCampaigns/pendingRemote.ts +6 -0
  37. package/src/votemarket/fetchCampaigns/processRawCampaigns.ts +2 -2
  38. package/src/votemarket/fxn/fetchFxnUserVotes.ts +61 -0
  39. package/dist/esm/bytecodes/votemarket/curve/batchCurveUserVotes.js +0 -39
  40. package/dist/esm/bytecodes/votemarket/curve/batchCurveUserVotes.js.map +0 -1
  41. package/dist/types/bytecodes/votemarket/curve/batchCurveUserVotes.d.ts +0 -4
  42. package/dist/types/bytecodes/votemarket/curve/batchCurveUserVotes.d.ts.map +0 -1
  43. package/src/bytecodes/votemarket/curve/batchCurveUserVotes.ts +0 -41
@@ -1,4 +1,4 @@
1
- import { ONE_WEEK, Zero, contracts, tokenWithAddress, tokens } from '@stake-dao/constants'
1
+ import { ONE_WEEK, Zero, tokenWithAddress, tokens } from '@stake-dao/constants'
2
2
  import { chunk, filter, remove, uniq } from 'lodash-es'
3
3
  import { encodeAbiParameters, formatEther, formatUnits, parseAbiParameters } from 'viem'
4
4
  import { mainnet } from 'viem/chains'
@@ -68,7 +68,7 @@ export const processRawCampaigns = async ({
68
68
  concatBytecode(
69
69
  batchGaugesWeight.bytecode[mainnet.id]!,
70
70
  encodeAbiParameters(parseAbiParameters(batchGaugesWeight.inputType[mainnet.id]!) as any, [
71
- contracts.curveGaugeController![1]!,
71
+ gaugeController,
72
72
  campaignsGauges,
73
73
  ]),
74
74
  ),
@@ -0,0 +1,61 @@
1
+ import { contracts } from '@stake-dao/constants'
2
+ import { encodeAbiParameters, formatUnits, parseAbiParameters, zeroAddress } from 'viem'
3
+ import { mainnet } from 'viem/chains'
4
+ import batchUserVotes from '../../bytecodes/votemarket/batchUserVotes.js'
5
+ import { concatBytecode } from '../../index.js'
6
+ import { batchJsonRpc, equalTlc } from '../../utils.js'
7
+
8
+ export type Vote = {
9
+ gauge: string
10
+ slope: string
11
+ relativeWeight: number
12
+ weight: number
13
+ start: number
14
+ end: number
15
+ }
16
+
17
+ export type GaugesUserData = { veBalance: string; unusedVeBalance: string; unusedRelativeWeight: number; votes: Vote[] }
18
+
19
+ export const fetchFxnUserVotes = async (rpc: string, user: string): Promise<GaugesUserData> => {
20
+ const calls = [
21
+ concatBytecode(
22
+ batchUserVotes.bytecode[mainnet.id]!,
23
+ encodeAbiParameters(parseAbiParameters(batchUserVotes.inputType[mainnet.id]!) as any, [
24
+ user,
25
+ contracts.fxnGaugeController![1]!,
26
+ contracts.veFxn![1]!,
27
+ ]),
28
+ ),
29
+ ]
30
+
31
+ const rawVotes = await batchJsonRpc({
32
+ rpc,
33
+ calls,
34
+ outputTypeAbi: batchUserVotes.outputType![mainnet.id],
35
+ parse: false,
36
+ callsKey: `votemarket/fxn/fetchFxnUserVotes.ts: rawGauges - chainId ${mainnet.id} - rpc ${rpc}`,
37
+ })
38
+
39
+ const veBalance = rawVotes[0].veBalance
40
+
41
+ const votes = rawVotes[0].votes
42
+ .filter((rv) => !equalTlc(rv.gauge, zeroAddress))
43
+ .map((v) => ({
44
+ gauge: v.gauge,
45
+ slope: formatUnits(v.slope, 0),
46
+ relativeWeight: Number(v.power) / 100,
47
+ weight: formatUnits((veBalance * BigInt(v.power)) / BigInt(10000), 18),
48
+ start: Number(v.start),
49
+ end: Number(v.end),
50
+ }))
51
+
52
+ const unusedRelativeWeight = 10000 - votes.reduce((total, x) => total + x.relativeWeight * 100, 0)
53
+ const unusedVeBalance = (veBalance * BigInt(unusedRelativeWeight)) / BigInt(10000)
54
+
55
+ return {
56
+ veBalance: formatUnits(veBalance, 18),
57
+ unusedVeBalance: formatUnits(unusedVeBalance, 18),
58
+ unusedRelativeWeight: unusedRelativeWeight / 100,
59
+ votes,
60
+ }
61
+ }
@@ -1,39 +0,0 @@
1
- const batchCurveUserVotes = {
2
- bytecode: {
3
- 1: '0x608060405234801561000f575f80fd5b5060405161099538038061099583398181016040528101906100319190610604565b5f732f50d538606fa9edd2b11e2446beb18c9d5846bb90505f8173ffffffffffffffffffffffffffffffffffffffff1663e93841d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610093573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100b79190610662565b90506100c161054d565b735f3b5dfeb7b28cdbd7faba78963ee202a494e2a273ffffffffffffffffffffffffffffffffffffffff166370a08231856040518263ffffffff1660e01b815260040161010e919061069c565b602060405180830381865afa158015610129573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061014d9190610662565b815f0181815250505f805b838110156103dd575f8573ffffffffffffffffffffffffffffffffffffffff1663b0539187836040518263ffffffff1660e01b815260040161019a91906106c4565b602060405180830381865afa1580156101b5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101d99190610604565b90506101e3610566565b8673ffffffffffffffffffffffffffffffffffffffff16630f467f9889846040518363ffffffff1660e01b815260040161021e9291906106dd565b606060405180830381865afa158015610239573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061025d9190610704565b8360200184604001856080018381525083815250838152505050505f816040015111156103ce5781815f019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508673ffffffffffffffffffffffffffffffffffffffff16637e418fa089846040518363ffffffff1660e01b81526004016102f69291906106dd565b602060405180830381865afa158015610311573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103359190610662565b816060018181525050805f808681526020019081526020015f205f820151815f015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550602082015181600101556040820151816002015560608201518160030155608082015181600401559050506001846103cb9190610781565b93505b50508080600101915050610158565b506103ed8161042360201b60201c565b82602001819052505f82604051602001610407919061091a565b6040516020818303038152906040529050602081018059038082f35b60608167ffffffffffffffff81111561043f5761043e61093a565b5b60405190808252806020026020018201604052801561047857816020015b610465610566565b81526020019060019003908161045d5790505b5090505f5b82811015610547575f808281526020019081526020015f206040518060a00160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200160018201548152602001600282015481526020016003820154815260200160048201548152505082828151811061052f5761052e610967565b5b6020026020010181905250808060010191505061047d565b50919050565b60405180604001604052805f8152602001606081525090565b6040518060a001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81526020015f81526020015f81526020015f81525090565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6105d3826105aa565b9050919050565b6105e3816105c9565b81146105ed575f80fd5b50565b5f815190506105fe816105da565b92915050565b5f60208284031215610619576106186105a6565b5b5f610626848285016105f0565b91505092915050565b5f819050919050565b6106418161062f565b811461064b575f80fd5b50565b5f8151905061065c81610638565b92915050565b5f60208284031215610677576106766105a6565b5b5f6106848482850161064e565b91505092915050565b610696816105c9565b82525050565b5f6020820190506106af5f83018461068d565b92915050565b6106be8161062f565b82525050565b5f6020820190506106d75f8301846106b5565b92915050565b5f6040820190506106f05f83018561068d565b6106fd602083018461068d565b9392505050565b5f805f6060848603121561071b5761071a6105a6565b5b5f6107288682870161064e565b93505060206107398682870161064e565b925050604061074a8682870161064e565b9150509250925092565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61078b8261062f565b91506107968361062f565b92508282019050808211156107ae576107ad610754565b5b92915050565b6107bd8161062f565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6107f5816105c9565b82525050565b60a082015f82015161080f5f8501826107ec565b50602082015161082260208501826107b4565b50604082015161083560408501826107b4565b50606082015161084860608501826107b4565b50608082015161085b60808501826107b4565b50505050565b5f61086c83836107fb565b60a08301905092915050565b5f602082019050919050565b5f61088e826107c3565b61089881856107cd565b93506108a3836107dd565b805f5b838110156108d35781516108ba8882610861565b97506108c583610878565b9250506001810190506108a6565b5085935050505092915050565b5f604083015f8301516108f55f8601826107b4565b506020830151848203602086015261090d8282610884565b9150508091505092915050565b5f6020820190508181035f83015261093281846108e0565b905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfe',
4
- },
5
- inputType: {
6
- 1: ['address user'],
7
- },
8
- outputTypeHr: {
9
- 1: [
10
- 'ReturnData memory returnData',
11
- 'struct ReturnData { uint256 veBalance; Vote[] votes; }',
12
- 'struct Vote { address gauge; uint256 slope; uint256 power; uint256 start; uint256 end; }',
13
- ],
14
- },
15
- outputType: {
16
- 1: [
17
- {
18
- type: 'tuple',
19
- name: 'returnData',
20
- components: [
21
- { type: 'uint256', name: 'veBalance' },
22
- {
23
- type: 'tuple[]',
24
- name: 'votes',
25
- components: [
26
- { type: 'address', name: 'gauge' },
27
- { type: 'uint256', name: 'slope' },
28
- { type: 'uint256', name: 'power' },
29
- { type: 'uint256', name: 'start' },
30
- { type: 'uint256', name: 'end' },
31
- ],
32
- },
33
- ],
34
- },
35
- ],
36
- },
37
- };
38
- export default batchCurveUserVotes;
39
- //# sourceMappingURL=batchCurveUserVotes.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"batchCurveUserVotes.js","sourceRoot":"","sources":["../../../../../src/bytecodes/votemarket/curve/batchCurveUserVotes.ts"],"names":[],"mappings":"AAEA,MAAM,mBAAmB,GAAkB;IACzC,QAAQ,EAAE;QACR,CAAC,EAAE,8yJAA8yJ;KAClzJ;IACD,SAAS,EAAE;QACT,CAAC,EAAE,CAAC,cAAc,CAAC;KACpB;IACD,YAAY,EAAE;QACZ,CAAC,EAAE;YACD,8BAA8B;YAC9B,wDAAwD;YACxD,0FAA0F;SAC3F;KACF;IACD,UAAU,EAAE;QACV,CAAC,EAAE;YACD;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,YAAY;gBAClB,UAAU,EAAE;oBACV,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE;oBACtC;wBACE,IAAI,EAAE,SAAS;wBACf,IAAI,EAAE,OAAO;wBACb,UAAU,EAAE;4BACV,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE;4BAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE;4BAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE;4BAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE;4BAClC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE;yBACjC;qBACF;iBACF;aACF;SACF;KACF;CACF,CAAA;AAED,eAAe,mBAAmB,CAAA"}
@@ -1,4 +0,0 @@
1
- import type { BatchMetaData } from '../../types.js';
2
- declare const batchCurveUserVotes: BatchMetaData;
3
- export default batchCurveUserVotes;
4
- //# sourceMappingURL=batchCurveUserVotes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"batchCurveUserVotes.d.ts","sourceRoot":"","sources":["../../../../../src/bytecodes/votemarket/curve/batchCurveUserVotes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAEnD,QAAA,MAAM,mBAAmB,EAAE,aAoC1B,CAAA;AAED,eAAe,mBAAmB,CAAA"}
@@ -1,41 +0,0 @@
1
- import type { BatchMetaData } from '../../types.js'
2
-
3
- const batchCurveUserVotes: BatchMetaData = {
4
- bytecode: {
5
- 1: '0x608060405234801561000f575f80fd5b5060405161099538038061099583398181016040528101906100319190610604565b5f732f50d538606fa9edd2b11e2446beb18c9d5846bb90505f8173ffffffffffffffffffffffffffffffffffffffff1663e93841d06040518163ffffffff1660e01b8152600401602060405180830381865afa158015610093573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906100b79190610662565b90506100c161054d565b735f3b5dfeb7b28cdbd7faba78963ee202a494e2a273ffffffffffffffffffffffffffffffffffffffff166370a08231856040518263ffffffff1660e01b815260040161010e919061069c565b602060405180830381865afa158015610129573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061014d9190610662565b815f0181815250505f805b838110156103dd575f8573ffffffffffffffffffffffffffffffffffffffff1663b0539187836040518263ffffffff1660e01b815260040161019a91906106c4565b602060405180830381865afa1580156101b5573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906101d99190610604565b90506101e3610566565b8673ffffffffffffffffffffffffffffffffffffffff16630f467f9889846040518363ffffffff1660e01b815260040161021e9291906106dd565b606060405180830381865afa158015610239573d5f803e3d5ffd5b505050506040513d601f19601f8201168201806040525081019061025d9190610704565b8360200184604001856080018381525083815250838152505050505f816040015111156103ce5781815f019073ffffffffffffffffffffffffffffffffffffffff16908173ffffffffffffffffffffffffffffffffffffffff16815250508673ffffffffffffffffffffffffffffffffffffffff16637e418fa089846040518363ffffffff1660e01b81526004016102f69291906106dd565b602060405180830381865afa158015610311573d5f803e3d5ffd5b505050506040513d601f19601f820116820180604052508101906103359190610662565b816060018181525050805f808681526020019081526020015f205f820151815f015f6101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550602082015181600101556040820151816002015560608201518160030155608082015181600401559050506001846103cb9190610781565b93505b50508080600101915050610158565b506103ed8161042360201b60201c565b82602001819052505f82604051602001610407919061091a565b6040516020818303038152906040529050602081018059038082f35b60608167ffffffffffffffff81111561043f5761043e61093a565b5b60405190808252806020026020018201604052801561047857816020015b610465610566565b81526020019060019003908161045d5790505b5090505f5b82811015610547575f808281526020019081526020015f206040518060a00160405290815f82015f9054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200160018201548152602001600282015481526020016003820154815260200160048201548152505082828151811061052f5761052e610967565b5b6020026020010181905250808060010191505061047d565b50919050565b60405180604001604052805f8152602001606081525090565b6040518060a001604052805f73ffffffffffffffffffffffffffffffffffffffff1681526020015f81526020015f81526020015f81526020015f81525090565b5f80fd5b5f73ffffffffffffffffffffffffffffffffffffffff82169050919050565b5f6105d3826105aa565b9050919050565b6105e3816105c9565b81146105ed575f80fd5b50565b5f815190506105fe816105da565b92915050565b5f60208284031215610619576106186105a6565b5b5f610626848285016105f0565b91505092915050565b5f819050919050565b6106418161062f565b811461064b575f80fd5b50565b5f8151905061065c81610638565b92915050565b5f60208284031215610677576106766105a6565b5b5f6106848482850161064e565b91505092915050565b610696816105c9565b82525050565b5f6020820190506106af5f83018461068d565b92915050565b6106be8161062f565b82525050565b5f6020820190506106d75f8301846106b5565b92915050565b5f6040820190506106f05f83018561068d565b6106fd602083018461068d565b9392505050565b5f805f6060848603121561071b5761071a6105a6565b5b5f6107288682870161064e565b93505060206107398682870161064e565b925050604061074a8682870161064e565b9150509250925092565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52601160045260245ffd5b5f61078b8261062f565b91506107968361062f565b92508282019050808211156107ae576107ad610754565b5b92915050565b6107bd8161062f565b82525050565b5f81519050919050565b5f82825260208201905092915050565b5f819050602082019050919050565b6107f5816105c9565b82525050565b60a082015f82015161080f5f8501826107ec565b50602082015161082260208501826107b4565b50604082015161083560408501826107b4565b50606082015161084860608501826107b4565b50608082015161085b60808501826107b4565b50505050565b5f61086c83836107fb565b60a08301905092915050565b5f602082019050919050565b5f61088e826107c3565b61089881856107cd565b93506108a3836107dd565b805f5b838110156108d35781516108ba8882610861565b97506108c583610878565b9250506001810190506108a6565b5085935050505092915050565b5f604083015f8301516108f55f8601826107b4565b506020830151848203602086015261090d8282610884565b9150508091505092915050565b5f6020820190508181035f83015261093281846108e0565b905092915050565b7f4e487b71000000000000000000000000000000000000000000000000000000005f52604160045260245ffd5b7f4e487b71000000000000000000000000000000000000000000000000000000005f52603260045260245ffdfe',
6
- },
7
- inputType: {
8
- 1: ['address user'],
9
- },
10
- outputTypeHr: {
11
- 1: [
12
- 'ReturnData memory returnData',
13
- 'struct ReturnData { uint256 veBalance; Vote[] votes; }',
14
- 'struct Vote { address gauge; uint256 slope; uint256 power; uint256 start; uint256 end; }',
15
- ],
16
- },
17
- outputType: {
18
- 1: [
19
- {
20
- type: 'tuple',
21
- name: 'returnData',
22
- components: [
23
- { type: 'uint256', name: 'veBalance' },
24
- {
25
- type: 'tuple[]',
26
- name: 'votes',
27
- components: [
28
- { type: 'address', name: 'gauge' },
29
- { type: 'uint256', name: 'slope' },
30
- { type: 'uint256', name: 'power' },
31
- { type: 'uint256', name: 'start' },
32
- { type: 'uint256', name: 'end' },
33
- ],
34
- },
35
- ],
36
- },
37
- ],
38
- },
39
- }
40
-
41
- export default batchCurveUserVotes