@stake-dao/reader 0.3.20 → 0.4.1

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.
@@ -17,7 +17,7 @@ export declare const GAUGES_CHUNK_SIZE: {
17
17
  42161: number;
18
18
  };
19
19
  export declare const TOKENS_CHUNK_SIZE = 100;
20
- export declare const GAUGES_WEIGHTS_CHUNK_SIZE = 50;
20
+ export declare const GAUGES_WEIGHTS_CHUNK_SIZE = 80;
21
21
  export declare const GAUGES_REGISTRY_CHUNK_SIZE = 30;
22
22
  export declare const BROKEN_VAULTS: {
23
23
  1: string[];
@@ -8,5 +8,5 @@ export type GaugesWeightsData = {
8
8
  gaugesCount: number;
9
9
  gauges: GaugeWeight[];
10
10
  };
11
- export declare const getGaugesWeights: (rpc: string) => Promise<GaugesWeightsData>;
11
+ export declare const getGaugesWeights: (provider: any, rpc: string) => Promise<GaugesWeightsData>;
12
12
  //# sourceMappingURL=getGaugesWeights.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getGaugesWeights.d.ts","sourceRoot":"","sources":["../../../../../../src/strategies/curve/fetch/curveApiData/getGaugesWeights.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CAAA;AAE9E,eAAO,MAAM,gBAAgB,QAAe,MAAM,KAAG,OAAO,CAAC,iBAAiB,CAoC7E,CAAA"}
1
+ {"version":3,"file":"getGaugesWeights.d.ts","sourceRoot":"","sources":["../../../../../../src/strategies/curve/fetch/curveApiData/getGaugesWeights.ts"],"names":[],"mappings":"AASA,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,MAAM,CAAA;IACb,aAAa,EAAE,MAAM,CAAA;IACrB,cAAc,EAAE,MAAM,CAAA;IACtB,oBAAoB,EAAE,MAAM,CAAA;CAC7B,CAAA;AAED,MAAM,MAAM,iBAAiB,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,WAAW,EAAE,CAAA;CAAE,CAAA;AAE9E,eAAO,MAAM,gBAAgB,aAAoB,GAAG,OAAO,MAAM,KAAG,OAAO,CAAC,iBAAiB,CAwF5F,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stake-dao/reader",
3
3
  "description": "",
4
- "version": "0.3.20",
4
+ "version": "0.4.1",
5
5
  "license": "AGPL-3.0-only",
6
6
  "repository": {
7
7
  "type": "git",
@@ -35,7 +35,7 @@
35
35
  "graphql-request": "^6.0.0",
36
36
  "lodash-es": "^4.17.21",
37
37
  "viem": "^2.9.31",
38
- "@stake-dao/constants": "0.3.10"
38
+ "@stake-dao/constants": "0.4.1"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/lodash-es": "^4.17.12"
@@ -126,7 +126,7 @@ export const buildCurveStrategies = async (
126
126
  let curveLendingGauges: any[] = []
127
127
  let curveLendingGaugesIndex = 0
128
128
 
129
- if (chainId === 1) {
129
+ if ([1, 42161].includes(chainId)) {
130
130
  curveLendingGauges = await provider.multicall({
131
131
  contracts: strats
132
132
  .map((s) =>
@@ -36,7 +36,7 @@ export const lendingStartIndex = {
36
36
  export const CHUNK_SIZE = 30
37
37
  export const GAUGES_CHUNK_SIZE = { 1: 60, 42161: 30 }
38
38
  export const TOKENS_CHUNK_SIZE = 100
39
- export const GAUGES_WEIGHTS_CHUNK_SIZE = 50
39
+ export const GAUGES_WEIGHTS_CHUNK_SIZE = 80
40
40
  export const GAUGES_REGISTRY_CHUNK_SIZE = 30
41
41
 
42
42
  export const BROKEN_VAULTS = {
@@ -1,10 +1,10 @@
1
- import { contracts } from '@stake-dao/constants'
2
- import { range } from 'lodash-es'
3
- import { decodeAbiParameters, encodeAbiParameters, formatUnits, parseAbiParameters } from 'viem'
4
- import { batchJsonRpc, rpcCall } from '../../../../utils.js'
5
- import { concatBytecode } from '../../../utils/index.js'
6
- import { getCurveDataGaugesWeightsOutputTypeAbi } from './abi.js'
7
- import { gaugesWeightBytecode } from './bytecode.js'
1
+ import { ONE_WEEK, contracts } from '@stake-dao/constants'
2
+ import { chunk, range } from 'lodash-es'
3
+ import { decodeAbiParameters, formatUnits, parseAbi } from 'viem'
4
+ import { multicall, rpcCall } from '../../../../utils.js'
5
+ // import { concatBytecode } from '../../../utils/index.js'
6
+ // import { getCurveDataGaugesWeightsOutputTypeAbi } from './abi.js'
7
+ // import { gaugesWeightBytecode } from './bytecode.js'
8
8
  import { GAUGES_WEIGHTS_CHUNK_SIZE } from './config.js'
9
9
 
10
10
  export type GaugeWeight = {
@@ -16,40 +16,92 @@ export type GaugeWeight = {
16
16
 
17
17
  export type GaugesWeightsData = { gaugesCount: number; gauges: GaugeWeight[] }
18
18
 
19
- export const getGaugesWeights = async (rpc: string): Promise<GaugesWeightsData> => {
19
+ export const getGaugesWeights = async (provider: any, rpc: string): Promise<GaugesWeightsData> => {
20
+ const now = Math.floor(Date.now() / 1000)
20
21
  const nGaugesRequest = await rpcCall(rpc, [{ to: contracts.curveGaugeController![1]!, data: '0xe93841d0' }])
21
-
22
22
  const nGauges = Number(decodeAbiParameters([{ type: 'uint256', name: 'n_gauges' }], nGaugesRequest[0].result))
23
23
 
24
- const gaugesWeightsCalls = range(0, nGauges, GAUGES_WEIGHTS_CHUNK_SIZE).map((skip) => {
25
- const inputParams = [
26
- nGauges,
27
- skip,
28
- skip + GAUGES_WEIGHTS_CHUNK_SIZE > nGauges ? nGauges : skip + GAUGES_WEIGHTS_CHUNK_SIZE,
29
- ]
24
+ // const gaugesWeightsCalls = range(0, nGauges, GAUGES_WEIGHTS_CHUNK_SIZE).map((skip) => {
25
+ // const inputParams = [
26
+ // nGauges,
27
+ // skip,
28
+ // skip + GAUGES_WEIGHTS_CHUNK_SIZE > nGauges ? nGauges : skip + GAUGES_WEIGHTS_CHUNK_SIZE,
29
+ // ]
30
+
31
+ // const inputData = encodeAbiParameters(
32
+ // parseAbiParameters(['uint256 maxLength, uint256 skip, uint256 limit']) as any,
33
+ // inputParams,
34
+ // )
35
+ // return concatBytecode(gaugesWeightBytecode, inputData)
36
+ // })
37
+
38
+ // const gaugesWeights = await batchJsonRpc({
39
+ // rpc,
40
+ // calls: gaugesWeightsCalls,
41
+ // outputTypeAbi: getCurveDataGaugesWeightsOutputTypeAbi,
42
+ // parse: false,
43
+ // callsKey: `strategies/curve/fetch/curveApiData/getGaugesWeights.ts: gaugesWeights - chainId ${1} - rpc ${rpc}`,
44
+ // })
45
+
46
+ const gaugesCalls = range(0, nGauges).map((i) => ({
47
+ address: contracts.curveGaugeController![1]!,
48
+ name: 'gauges',
49
+ params: [i],
50
+ }))
51
+
52
+ const gauges = (
53
+ await multicall(provider, gaugesCalls, parseAbi(['function gauges(uint256 index) external view returns (address)']))
54
+ ).map((g) => g.result)
30
55
 
31
- const inputData = encodeAbiParameters(
32
- parseAbiParameters(['uint256 maxLength, uint256 skip, uint256 limit']) as any,
33
- inputParams,
56
+ const gaugesWeightsCalls = range(0, nGauges).flatMap((i) => [
57
+ { address: gauges[i], name: 'inflation_params' },
58
+ { address: gauges[i], name: 'inflation_rate' },
59
+ {
60
+ address: contracts.curveGaugeController![1]!,
61
+ name: 'gauge_relative_weight_write',
62
+ params: [gauges[i]],
63
+ },
64
+ {
65
+ address: contracts.curveGaugeController![1]!,
66
+ name: 'gauge_relative_weight_write',
67
+ params: [gauges[i], now + ONE_WEEK],
68
+ },
69
+ ])
70
+
71
+ const chunkedGaugesWeightsCalls = chunk(gaugesWeightsCalls, GAUGES_WEIGHTS_CHUNK_SIZE)
72
+ const rawGaugesWeights: any = []
73
+
74
+ for (const chunk of chunkedGaugesWeightsCalls) {
75
+ rawGaugesWeights.push(
76
+ await multicall(
77
+ provider,
78
+ chunk,
79
+ parseAbi([
80
+ 'function inflation_rate() external view returns (uint256)',
81
+ 'function inflation_params() external view returns (uint256,uint256)',
82
+ 'function gauge_relative_weight_write(address gauge) external view returns (uint256)',
83
+ 'function gauge_relative_weight_write(address gauge, uint256 time) external view returns (uint256)',
84
+ ]),
85
+ ),
34
86
  )
35
- return concatBytecode(gaugesWeightBytecode, inputData)
36
- })
87
+ }
37
88
 
38
- const gaugesWeights = await batchJsonRpc({
39
- rpc,
40
- calls: gaugesWeightsCalls,
41
- outputTypeAbi: getCurveDataGaugesWeightsOutputTypeAbi,
42
- parse: false,
43
- callsKey: `strategies/curve/fetch/curveApiData/getGaugesWeights.ts: gaugesWeights - chainId ${1} - rpc ${rpc}`,
44
- })
89
+ const gaugesWeights = chunk(rawGaugesWeights.flat(), 4)
45
90
 
46
91
  return {
47
92
  gaugesCount: nGauges,
48
- gauges: gaugesWeights.map((gw) => ({
49
- gauge: gw.gauge,
50
- inflationRate: formatUnits(gw.inflationRate, 0),
51
- relativeWeight: formatUnits(gw.relativeWeight, 0),
52
- futureRelativeWeight: formatUnits(gw.futureRelativeWeight, 0),
53
- })),
93
+ gauges: gauges.map((gauge, index) => {
94
+ const gaugeWeight: { result: any; error: any; status: 'success' | 'failure' }[] = gaugesWeights[index] as any
95
+ const inflationRate = gaugeWeight[0]!.result ? gaugeWeight[0]!.result[0] : gaugeWeight[1]!.result
96
+
97
+ if (typeof inflationRate === 'undefined') console.debug('undefined inflationRate for gauge:', gauge)
98
+
99
+ return {
100
+ gauge,
101
+ inflationRate: formatUnits(inflationRate || 0, 0),
102
+ relativeWeight: formatUnits(gaugeWeight[2]!.result, 0),
103
+ futureRelativeWeight: formatUnits(gaugeWeight[3]!.result, 0),
104
+ }
105
+ }),
54
106
  }
55
107
  }