@marinade.finance/scoring 1.0.0 → 1.0.2

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 (108) hide show
  1. package/dist/computing/cluster.d.ts +10 -0
  2. package/dist/computing/cluster.js +95 -0
  3. package/dist/computing/cluster.js.map +1 -0
  4. package/dist/computing/eligibility.d.ts +19 -0
  5. package/dist/computing/eligibility.js +163 -0
  6. package/dist/computing/eligibility.js.map +1 -0
  7. package/dist/computing/score.d.ts +20 -0
  8. package/dist/computing/score.js +174 -0
  9. package/dist/computing/score.js.map +1 -0
  10. package/dist/computing/stake.d.ts +26 -0
  11. package/dist/computing/stake.js +197 -0
  12. package/dist/computing/stake.js.map +1 -0
  13. package/dist/computing/validators.d.ts +16 -0
  14. package/dist/computing/validators.js +123 -0
  15. package/dist/computing/validators.js.map +1 -0
  16. package/dist/constants/marinade.json +38 -0
  17. package/dist/dto/bonds.dto.d.ts +12 -0
  18. package/dist/dto/bonds.dto.js +3 -0
  19. package/dist/dto/bonds.dto.js.map +1 -0
  20. package/dist/dto/cluster.dto.d.ts +12 -0
  21. package/dist/dto/cluster.dto.js +3 -0
  22. package/dist/dto/cluster.dto.js.map +1 -0
  23. package/{src/dto/eligibility.dto.ts → dist/dto/eligibility.dto.d.ts} +15 -20
  24. package/dist/dto/eligibility.dto.js +3 -0
  25. package/dist/dto/eligibility.dto.js.map +1 -0
  26. package/dist/dto/jito.dto.d.ts +9 -0
  27. package/dist/dto/jito.dto.js +10 -0
  28. package/dist/dto/jito.dto.js.map +1 -0
  29. package/dist/dto/marinade.dto.d.ts +18 -0
  30. package/dist/dto/marinade.dto.js +3 -0
  31. package/dist/dto/marinade.dto.js.map +1 -0
  32. package/dist/dto/rewards.dto.d.ts +17 -0
  33. package/dist/dto/rewards.dto.js +18 -0
  34. package/dist/dto/rewards.dto.js.map +1 -0
  35. package/dist/dto/scoring.dto.d.ts +101 -0
  36. package/dist/dto/scoring.dto.js +3 -0
  37. package/dist/dto/scoring.dto.js.map +1 -0
  38. package/dist/dto/snapshots.dto.d.ts +15 -0
  39. package/dist/dto/snapshots.dto.js +13 -0
  40. package/dist/dto/snapshots.dto.js.map +1 -0
  41. package/dist/dto/stakes.dto.d.ts +30 -0
  42. package/dist/dto/stakes.dto.js +3 -0
  43. package/dist/dto/stakes.dto.js.map +1 -0
  44. package/dist/dto/validators.dto.d.ts +110 -0
  45. package/dist/dto/validators.dto.js +19 -0
  46. package/dist/dto/validators.dto.js.map +1 -0
  47. package/dist/errors/fetching.d.ts +22 -0
  48. package/dist/errors/fetching.js +30 -0
  49. package/dist/errors/fetching.js.map +1 -0
  50. package/dist/index.d.ts +24 -0
  51. package/dist/index.js +41 -0
  52. package/dist/index.js.map +1 -0
  53. package/dist/interfaces/data-provider.interface.d.ts +16 -0
  54. package/dist/interfaces/data-provider.interface.js +3 -0
  55. package/dist/interfaces/data-provider.interface.js.map +1 -0
  56. package/dist/logging/logger.d.ts +3 -0
  57. package/dist/logging/logger.js +72 -0
  58. package/dist/logging/logger.js.map +1 -0
  59. package/dist/providers/api-data.provider.d.ts +30 -0
  60. package/dist/providers/api-data.provider.js +227 -0
  61. package/dist/providers/api-data.provider.js.map +1 -0
  62. package/dist/providers/file-data.provider.d.ts +29 -0
  63. package/dist/providers/file-data.provider.js +96 -0
  64. package/dist/providers/file-data.provider.js.map +1 -0
  65. package/dist/tsconfig.tsbuildinfo +1 -0
  66. package/dist/utils/csv.d.ts +2 -0
  67. package/dist/utils/csv.js +53 -0
  68. package/dist/utils/csv.js.map +1 -0
  69. package/dist/utils/maths.d.ts +8 -0
  70. package/dist/utils/maths.js +56 -0
  71. package/dist/utils/maths.js.map +1 -0
  72. package/dist/utils/solana.d.ts +1 -0
  73. package/dist/utils/solana.js +9 -0
  74. package/dist/utils/solana.js.map +1 -0
  75. package/dist/utils/zip.d.ts +2 -0
  76. package/dist/utils/zip.js +15 -0
  77. package/dist/utils/zip.js.map +1 -0
  78. package/package.json +14 -16
  79. package/src/cluster/cluster.module.ts +0 -8
  80. package/src/cluster/cluster.service.ts +0 -108
  81. package/src/config/config.module.ts +0 -8
  82. package/src/config/config.service.ts +0 -136
  83. package/src/constants/marinade.json +0 -38
  84. package/src/dto/bonds.dto.ts +0 -14
  85. package/src/dto/cluster.dto.ts +0 -13
  86. package/src/dto/jito.dto.ts +0 -10
  87. package/src/dto/marinade.dto.ts +0 -18
  88. package/src/dto/rewards.dto.ts +0 -21
  89. package/src/dto/scoring.dto.ts +0 -109
  90. package/src/dto/snapshots.dto.ts +0 -19
  91. package/src/dto/stakes.dto.ts +0 -35
  92. package/src/dto/validators.dto.ts +0 -146
  93. package/src/eligibility/eligibility.module.ts +0 -11
  94. package/src/eligibility/eligibility.service.ts +0 -183
  95. package/src/errors/fetching.ts +0 -25
  96. package/src/interfaces/data-provider.interface.ts +0 -17
  97. package/src/providers/api-data.provider.ts +0 -261
  98. package/src/providers/file-data.provider.ts +0 -125
  99. package/src/scoring/scoring.module.ts +0 -11
  100. package/src/scoring/scoring.service.ts +0 -184
  101. package/src/stake/stake.module.ts +0 -10
  102. package/src/stake/stake.service.ts +0 -242
  103. package/src/utils/csv.ts +0 -30
  104. package/src/utils/maths.ts +0 -75
  105. package/src/utils/solana.ts +0 -9
  106. package/src/utils/zip.ts +0 -12
  107. package/src/validators/validators.module.ts +0 -48
  108. package/src/validators/validators.service.ts +0 -177
@@ -1,9 +0,0 @@
1
- /**
2
- * Converts a lamport value (as a string) to its equivalent in SOL, adding a decimal point before the last 9 digits.
3
- * @param {string} lamports - The lamport value to convert, represented as a string.
4
- * @return {string} The equivalent value in SOL, as a string.
5
- */
6
- export function lamportsToSol (lamports: string): string {
7
- const paddedLamports = lamports.padStart(10, '0');
8
- return paddedLamports.replace(/(.{9})$/, '.$1');
9
- }
package/src/utils/zip.ts DELETED
@@ -1,12 +0,0 @@
1
- export function zip<T1, T2, T3> (...iterables: [Iterable<T1>, Iterable<T2>, Iterable<T3>]): Generator<[T1, T2, T3]>
2
- export function zip<T1, T2> (...iterables: [Iterable<T1>, Iterable<T2>]): Generator<[T1, T2]>
3
- export function* zip<T1, T2> (...iterables: Iterable<T1 | T2>[]): Generator<(T1 | T2)[]> {
4
- const iterators = iterables.map((iterable) => iterable[Symbol.iterator]());
5
- while (true) {
6
- const results = iterators.map((iter) => iter.next());
7
- if (results.some((result) => result.done)) {
8
- return;
9
- }
10
- yield results.map((result) => result.value);
11
- }
12
- }
@@ -1,48 +0,0 @@
1
- import { Module } from '@nestjs/common';
2
- import { ValidatorsService } from './validators.service';
3
- import { ConfigService } from '../config/config.service';
4
- import { ApiDataProvider } from '../providers/api-data.provider';
5
- import { FileDataProvider } from '../providers/file-data.provider';
6
- import { ConfigModule } from '../config/config.module';
7
-
8
- @Module({
9
- imports: [ConfigModule],
10
- providers: [ValidatorsService, {
11
- provide: 'IDataProvider',
12
- useFactory: (configService: ConfigService) => {
13
- const dataSourceType = configService.getDataProviderMode();
14
- if (dataSourceType === 'api') {
15
- return new ApiDataProvider(
16
- {
17
- validatorsURL: configService.getValidatorsURL(),
18
- blacklistURL: configService.getBlacklistURL(),
19
- vemndeVotesURL: configService.getVemndeVotesURL(),
20
- msolVotesURL: configService.getMsolVotesURL(),
21
- rewardsURL: configService.getRewardsURL(),
22
- jitoMevURL: configService.getJitoMevURL(),
23
- bondsURL: configService.getBondsURL(),
24
- marinadeTvlURL: configService.getMarinadeTvlURL(),
25
- }
26
- );
27
- } else if (dataSourceType === 'file') {
28
- return new FileDataProvider(
29
- {
30
- validatorsPath: configService.getValidatorsPath(),
31
- blacklistPath: configService.getBlacklistPath(),
32
- vemndeVotesPath: configService.getVemndeVotesPath(),
33
- msolVotesPath: configService.getMsolVotesPath(),
34
- rewardsPath: configService.getRewardsPath(),
35
- jitoMevPath: configService.getJitoMevPath(),
36
- bondsPath: configService.getBondsPath(),
37
- marinadeTvlPath: configService.getMarinadeTvlPath(),
38
- }
39
- );
40
- } else {
41
- throw new Error('Invalid data provider type');
42
- }
43
- },
44
- inject: [ConfigService],
45
- }],
46
- exports: [ValidatorsService],
47
- })
48
- export class ValidatorsModule {}
@@ -1,177 +0,0 @@
1
- import { AggregatedValidator, AggregatedValidators, ValidatorDto } from '../dto/validators.dto';
2
- import { IDataProvider } from '../interfaces/data-provider.interface';
3
- import { JitoValidatorDto } from '../dto/jito.dto';
4
- import { Inject } from '@nestjs/common';
5
- import { mean, sum } from '../utils/maths';
6
- import { ClusterInfo } from '../dto/cluster.dto';
7
- import { Votes } from '../dto/snapshots.dto';
8
- import { Bonds } from '../dto/bonds.dto';
9
- import { Rewards } from '../dto/rewards.dto';
10
- import { TvlStats } from '../dto/marinade.dto';
11
-
12
- export class ValidatorsService {
13
- constructor (@Inject('IDataProvider') private dataProvider: IDataProvider) { }
14
-
15
- aggregateValidatorData (
16
- validator: ValidatorDto,
17
- mevRecord: JitoValidatorDto,
18
- blacklist: Set<string>,
19
- firstEpoch: number,
20
- lastEpoch: number
21
- ): AggregatedValidator {
22
- const currentMarinadeStake = Number(validator.epochStats[lastEpoch]?.marinade_native_stake || 0) / 1e9 + Number(validator.epochStats[lastEpoch]?.marinade_stake || 0) / 1e9;
23
- const voteAccount = validator.vote_account;
24
- const name = validator.info_name || 'Unknown';
25
- const epochs: number[] = [];
26
- const commission: number[] = [];
27
- const stake: number[] = [];
28
- const externalStake: number[] = [];
29
- const credits: number[] = [];
30
- const blocksProduced: number[] = [];
31
- const leaderSlots: number[] = [];
32
- const dataAvailable: boolean[] = [];
33
-
34
- const currentStake = Number(validator.epochStats[lastEpoch]?.activated_stake || 0) / 1e9;
35
-
36
- const blacklisted = blacklist.has(voteAccount);
37
-
38
- for (let epoch = lastEpoch; epoch >= firstEpoch; epoch--) {
39
- const epochStat = validator.epochStats?.[epoch];
40
-
41
- epochs.push(epoch);
42
- commission.push(epochStat?.commission_max_observed || epochStat?.commission_advertised || 0);
43
- stake.push(Number(epochStat?.activated_stake || 0) / 1e9);
44
- externalStake.push(Number(epochStat?.activated_stake || 0) / 1e9 - Number(epochStat?.marinade_stake || 0) / 1e9 - Number(epochStat?.marinade_native_stake || 0) / 1e9);
45
- credits.push(epochStat?.credits || 0);
46
- blocksProduced.push(epochStat?.blocks_produced || 0);
47
- leaderSlots.push(epochStat?.leader_slots || 0);
48
- dataAvailable.push(!!epochStat);
49
- }
50
-
51
- const mevCommission = mevRecord?.running_jito ? mevRecord.mev_commission_bps / 100 : 100;
52
- return {
53
- voteAccount,
54
- name,
55
- epochs,
56
- currentMarinadeStake,
57
- currentStake,
58
- commission,
59
- stake,
60
- externalStake,
61
- credits,
62
- blocksProduced,
63
- leaderSlots,
64
- dataAvailable,
65
- mevCommission,
66
- country: validator.dc_country || 'Unknown',
67
- city: validator.dc_full_city || 'Unknown',
68
- aso: validator.dc_aso || 'Unknown',
69
- blacklisted,
70
- version: validator.version
71
- };
72
- }
73
-
74
- async fetchTvlStats (withSnapshot: boolean): Promise<TvlStats> {
75
- return await this.dataProvider.fetchTvl(withSnapshot);
76
- }
77
-
78
- async fetchValidators (epochsToFetch: number, withSnapshot: boolean): Promise<ValidatorDto[]> {
79
- return this.dataProvider.fetchValidators(epochsToFetch, withSnapshot);
80
- }
81
-
82
- async fetchMsolVotes (withSnapshot: boolean): Promise<Votes> {
83
- return await this.dataProvider.fetchMSolVotes(withSnapshot);
84
- }
85
-
86
- async fetchRewards (epochs:number, withSnapshot: boolean): Promise<Rewards> {
87
- return await this.dataProvider.fetchRewards(epochs, withSnapshot);
88
- }
89
-
90
- async fetchVeMndeVotes (withSnapshot: boolean): Promise<Votes> {
91
- return await this.dataProvider.fetchVeMndeVotes(withSnapshot);
92
- }
93
-
94
- async fetchBonds (withSnapshot: boolean): Promise<Bonds> {
95
- return this.dataProvider.fetchBonds(withSnapshot);
96
- }
97
-
98
- async aggregateValidatorsData (
99
- validators: ValidatorDto[],
100
- basicEligibilityEpochs: number,
101
- bonusEligibilityExtraEpochs: number
102
- ): Promise<AggregatedValidators> {
103
- const lastEpoch = this.getMaxEpoch(validators);
104
- const firstEpoch = lastEpoch - basicEligibilityEpochs - bonusEligibilityExtraEpochs;
105
-
106
- const jitoMevRecords: Record<string, JitoValidatorDto> = await this.dataProvider.fetchValidatorsJitoMEV(true);
107
- const blacklist: Set<string> = await this.dataProvider.fetchBlacklist(true);
108
-
109
- const result: { [voteAccount: string]: AggregatedValidator } = {};
110
-
111
- for (const validator of validators) {
112
- const mevRecord = jitoMevRecords[validator.vote_account] ?? {
113
- vote_account: validator.vote_account,
114
- mev_commission_bps: 100,
115
- running_jito: false,
116
- active_stake: Number(validator.activated_stake)
117
- } as JitoValidatorDto;
118
-
119
- if (mevRecord) {
120
- const aggregatedData = this.aggregateValidatorData(validator, mevRecord, blacklist, firstEpoch, lastEpoch);
121
- result[validator.vote_account] = aggregatedData;
122
- }
123
- }
124
-
125
- return result;
126
- }
127
-
128
- getMaxEpoch (validators: ValidatorDto[]): number {
129
- return validators.reduce((maxEpoch, validator) => {
130
- const validatorMaxEpoch = validator.epoch_stats.reduce((max, { epoch }) => {
131
- return Math.max(epoch, max);
132
- }, 0);
133
- return Math.max(maxEpoch, validatorMaxEpoch);
134
- }, 0);
135
- }
136
-
137
- selectExternalStakeMin (validator: AggregatedValidator, fullEpochs: number): number {
138
- if (validator.externalStake.length === 0) {
139
- throw new Error('Validator has no external stake data.');
140
- }
141
- return Math.min(...validator.externalStake.slice(0, fullEpochs + 1));
142
- }
143
-
144
- selectCreditsPctMean (validator: AggregatedValidator, clusterInfo: ClusterInfo, fullEpochs: number): number {
145
- return mean(validator.epochs.slice(1, fullEpochs + 1).map((epoch, fullEpochIndex) =>
146
- (validator.credits[fullEpochIndex + 1] ?? 0) / (clusterInfo.targetCreditsByEpoch.get(epoch) ?? 1)));
147
- }
148
-
149
- selectBlockProductionMean (validator: AggregatedValidator, fullEpochs: number): number {
150
- const leaderSlots = sum(validator.leaderSlots.slice(1, fullEpochs + 1));
151
- return leaderSlots === 0 ? 1 : sum(validator.blocksProduced.slice(1, fullEpochs + 1)) / leaderSlots;
152
- }
153
-
154
- selectCommissonInflationMax (validator: AggregatedValidator, epochs: number): number {
155
- return Math.max(...validator.commission.slice(0, epochs));
156
- }
157
-
158
- selectCommissonMEV (validator: AggregatedValidator): number {
159
- return validator.mevCommission;
160
- }
161
-
162
- selectCountryStakeConcentration (validator: AggregatedValidator, clusterInfo: ClusterInfo): number {
163
- return clusterInfo.country.get(validator.country ?? '???') ?? 0;
164
- }
165
-
166
- selectCityStakeConcentration (validator: AggregatedValidator, clusterInfo: ClusterInfo): number {
167
- return clusterInfo.city.get(validator.city ?? '???') ?? 0;
168
- }
169
-
170
- selectASOStakeConcentration (validator: AggregatedValidator, clusterInfo: ClusterInfo): number {
171
- return clusterInfo.aso.get(validator.aso ?? '???') ?? 0;
172
- }
173
-
174
- selectNodeStake (validator: AggregatedValidator): number {
175
- return validator.stake[0] ?? 0;
176
- }
177
- }