@glowlabs-org/utils 0.0.9 → 0.1.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.
Files changed (130) hide show
  1. package/.github/workflows/publish.yml +14 -4
  2. package/dist/cjs/constants/regex.d.ts +1 -0
  3. package/dist/cjs/constants/urls.d.ts +2 -0
  4. package/dist/cjs/constants/weights.d.ts +12 -0
  5. package/dist/cjs/index.d.ts +1 -1
  6. package/dist/cjs/index.js +18988 -89
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/lib/create-weekly-report/index.d.ts +73 -0
  9. package/dist/cjs/lib/create-weekly-report/types/Audit.d.ts +40 -0
  10. package/dist/cjs/lib/create-weekly-report/types/index.d.ts +7 -0
  11. package/dist/cjs/lib/create-weekly-report/types/merkle.d.ts +10 -0
  12. package/dist/cjs/lib/create-weekly-report/utils/accumulate-leaf-weights.d.ts +2 -0
  13. package/dist/cjs/lib/create-weekly-report/utils/custom-to-fixed.d.ts +1 -0
  14. package/dist/cjs/lib/create-weekly-report/utils/fetch-farms-for-week.d.ts +12 -0
  15. package/dist/cjs/lib/create-weekly-report/utils/from-bigint.d.ts +7 -0
  16. package/dist/cjs/lib/create-weekly-report/utils/greater-than-max-deviation.d.ts +1 -0
  17. package/dist/cjs/lib/create-weekly-report/utils/hashLeaf.d.ts +7 -0
  18. package/dist/cjs/lib/create-weekly-report/utils/multiply-bigInt-by-decimal-percentage.d.ts +1 -0
  19. package/dist/cjs/lib/create-weekly-report/utils/to-bigint.d.ts +7 -0
  20. package/dist/cjs/utils/custom-to-fixed.d.ts +1 -0
  21. package/dist/cjs/utils/greater-than-max-deviation.d.ts +1 -0
  22. package/dist/cjs/utils/hash-leaf.d.ts +7 -0
  23. package/dist/esm/constants/regex.d.ts +1 -0
  24. package/dist/esm/constants/urls.d.ts +2 -0
  25. package/dist/esm/constants/weights.d.ts +12 -0
  26. package/dist/esm/index.d.ts +1 -1
  27. package/dist/esm/index.js +18988 -89
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/lib/create-weekly-report/index.d.ts +73 -0
  30. package/dist/esm/lib/create-weekly-report/types/Audit.d.ts +40 -0
  31. package/dist/esm/lib/create-weekly-report/types/RewardSplit copy.d.ts +5 -0
  32. package/dist/esm/lib/create-weekly-report/types/RewardSplit.d.ts +5 -0
  33. package/dist/esm/lib/create-weekly-report/types/RewardSplits copy.d.ts +2 -0
  34. package/dist/esm/lib/create-weekly-report/types/RewardSplits.d.ts +2 -0
  35. package/dist/esm/lib/create-weekly-report/types/index.d.ts +7 -0
  36. package/dist/esm/lib/create-weekly-report/types/merkle.d.ts +10 -0
  37. package/dist/esm/lib/create-weekly-report/utils/accumulate-leaf-weights.d.ts +2 -0
  38. package/dist/esm/lib/create-weekly-report/utils/custom-to-fixed.d.ts +1 -0
  39. package/dist/esm/lib/create-weekly-report/utils/fetch-farms-for-week.d.ts +12 -0
  40. package/dist/esm/lib/create-weekly-report/utils/from-bigint.d.ts +7 -0
  41. package/dist/esm/lib/create-weekly-report/utils/greater-than-max-deviation.d.ts +1 -0
  42. package/dist/esm/lib/create-weekly-report/utils/hashLeaf.d.ts +7 -0
  43. package/dist/esm/lib/create-weekly-report/utils/multiply-bigInt-by-decimal-percentage.d.ts +1 -0
  44. package/dist/esm/lib/create-weekly-report/utils/to-bigint.d.ts +7 -0
  45. package/dist/esm/utils/custom-to-fixed.d.ts +1 -0
  46. package/dist/esm/utils/greater-than-max-deviation.d.ts +1 -0
  47. package/dist/esm/utils/hash-leaf.d.ts +7 -0
  48. package/package.json +13 -9
  49. package/rollup.config.js +2 -0
  50. package/src/constants/regex.ts +2 -0
  51. package/src/constants/urls.ts +3 -0
  52. package/src/constants/weights.ts +15 -0
  53. package/src/index.ts +1 -1
  54. package/src/lib/create-weekly-report/index.ts +691 -0
  55. package/src/lib/create-weekly-report/types/Audit.ts +41 -0
  56. package/src/{types → lib/create-weekly-report/types}/AuditCompleted.ts +3 -1
  57. package/src/lib/create-weekly-report/types/AuditInherited.ts +8 -0
  58. package/src/lib/create-weekly-report/types/Device.ts +7 -0
  59. package/src/lib/create-weekly-report/types/DuplicatedButPastAuditCompleted.ts +10 -0
  60. package/src/lib/create-weekly-report/types/Farm.ts +22 -0
  61. package/src/{types → lib/create-weekly-report/types}/FarmStatus.ts +6 -6
  62. package/src/{types → lib/create-weekly-report/types}/GCAServerResponse.ts +5 -1
  63. package/src/lib/create-weekly-report/types/GetEquipmentDataHandlerParams.ts +7 -0
  64. package/src/lib/create-weekly-report/types/PayoutWalletAndSplit.ts +25 -0
  65. package/src/lib/create-weekly-report/types/PayoutWalletAndSplitWithRewardSplits.ts +23 -0
  66. package/src/lib/create-weekly-report/types/RewardSplit copy.ts +7 -0
  67. package/src/lib/create-weekly-report/types/RewardSplit.ts +7 -0
  68. package/src/{types/RewardSplit.ts → lib/create-weekly-report/types/RewardSplits copy.ts } +2 -1
  69. package/src/{types → lib/create-weekly-report/types}/RewardSplits.ts +1 -1
  70. package/src/{types → lib/create-weekly-report/types}/SlotRange.ts +4 -1
  71. package/src/{types → lib/create-weekly-report/types}/WeekAndSlotRange.ts +4 -1
  72. package/src/lib/create-weekly-report/types/index.ts +7 -0
  73. package/src/lib/create-weekly-report/types/merkle.ts +11 -0
  74. package/src/lib/create-weekly-report/types/stashed-Farm.ts +22 -0
  75. package/src/lib/create-weekly-report/utils/accumulate-leaf-weights.ts +17 -0
  76. package/src/lib/create-weekly-report/utils/custom-to-fixed.ts +9 -0
  77. package/src/lib/create-weekly-report/utils/fetch-farms-for-week.ts +30 -0
  78. package/src/lib/create-weekly-report/utils/from-bigint.ts +12 -0
  79. package/src/lib/create-weekly-report/utils/greater-than-max-deviation.ts +9 -0
  80. package/src/lib/create-weekly-report/utils/hashLeaf.ts +20 -0
  81. package/src/lib/create-weekly-report/utils/multiply-bigInt-by-decimal-percentage.ts +15 -0
  82. package/src/lib/create-weekly-report/utils/to-bigint.ts +16 -0
  83. package/src/utils/custom-to-fixed.ts +9 -0
  84. package/src/utils/greater-than-max-deviation.ts +9 -0
  85. package/src/utils/hash-leaf.ts +22 -0
  86. package/tsconfig.json +2 -2
  87. package/dist/cjs/types/GCAAndServerUrl.d.ts +0 -5
  88. package/dist/cjs/types/index.d.ts +0 -14
  89. package/dist/esm/types/GCAAndServerUrl.d.ts +0 -5
  90. package/dist/esm/types/index.d.ts +0 -14
  91. package/src/types/AuditInherited.ts +0 -3
  92. package/src/types/Device.ts +0 -3
  93. package/src/types/DuplicatedButPastAuditCompleted.ts +0 -4
  94. package/src/types/Farm.ts +0 -22
  95. package/src/types/GCAAndServerUrl.ts +0 -5
  96. package/src/types/GetEquipmentDataHandlerParams.ts +0 -3
  97. package/src/types/PayoutWalletAndSplit.ts +0 -5
  98. package/src/types/PayoutWalletAndSplitWithRewardSplits.ts +0 -6
  99. package/src/types/index.ts +0 -14
  100. package/src/types/stashed-Farm.ts +0 -22
  101. /package/dist/cjs/{types → lib/create-weekly-report/types}/AuditCompleted.d.ts +0 -0
  102. /package/dist/cjs/{types → lib/create-weekly-report/types}/AuditInherited.d.ts +0 -0
  103. /package/dist/cjs/{types → lib/create-weekly-report/types}/Device.d.ts +0 -0
  104. /package/dist/cjs/{types → lib/create-weekly-report/types}/DuplicatedButPastAuditCompleted.d.ts +0 -0
  105. /package/dist/cjs/{types → lib/create-weekly-report/types}/Farm.d.ts +0 -0
  106. /package/dist/cjs/{types → lib/create-weekly-report/types}/FarmStatus.d.ts +0 -0
  107. /package/dist/cjs/{types → lib/create-weekly-report/types}/GCAServerResponse.d.ts +0 -0
  108. /package/dist/cjs/{types → lib/create-weekly-report/types}/GetEquipmentDataHandlerParams.d.ts +0 -0
  109. /package/dist/cjs/{types → lib/create-weekly-report/types}/PayoutWalletAndSplit.d.ts +0 -0
  110. /package/dist/cjs/{types → lib/create-weekly-report/types}/PayoutWalletAndSplitWithRewardSplits.d.ts +0 -0
  111. /package/dist/cjs/{types/RewardSplit.d.ts → lib/create-weekly-report/types/RewardSplit copy.d.ts} +0 -0
  112. /package/dist/{esm → cjs/lib/create-weekly-report}/types/RewardSplit.d.ts +0 -0
  113. /package/dist/cjs/{types/RewardSplits.d.ts → lib/create-weekly-report/types/RewardSplits copy.d.ts} +0 -0
  114. /package/dist/{esm → cjs/lib/create-weekly-report}/types/RewardSplits.d.ts +0 -0
  115. /package/dist/cjs/{types → lib/create-weekly-report/types}/SlotRange.d.ts +0 -0
  116. /package/dist/cjs/{types → lib/create-weekly-report/types}/WeekAndSlotRange.d.ts +0 -0
  117. /package/dist/cjs/{types → lib/create-weekly-report/types}/stashed-Farm.d.ts +0 -0
  118. /package/dist/esm/{types → lib/create-weekly-report/types}/AuditCompleted.d.ts +0 -0
  119. /package/dist/esm/{types → lib/create-weekly-report/types}/AuditInherited.d.ts +0 -0
  120. /package/dist/esm/{types → lib/create-weekly-report/types}/Device.d.ts +0 -0
  121. /package/dist/esm/{types → lib/create-weekly-report/types}/DuplicatedButPastAuditCompleted.d.ts +0 -0
  122. /package/dist/esm/{types → lib/create-weekly-report/types}/Farm.d.ts +0 -0
  123. /package/dist/esm/{types → lib/create-weekly-report/types}/FarmStatus.d.ts +0 -0
  124. /package/dist/esm/{types → lib/create-weekly-report/types}/GCAServerResponse.d.ts +0 -0
  125. /package/dist/esm/{types → lib/create-weekly-report/types}/GetEquipmentDataHandlerParams.d.ts +0 -0
  126. /package/dist/esm/{types → lib/create-weekly-report/types}/PayoutWalletAndSplit.d.ts +0 -0
  127. /package/dist/esm/{types → lib/create-weekly-report/types}/PayoutWalletAndSplitWithRewardSplits.d.ts +0 -0
  128. /package/dist/esm/{types → lib/create-weekly-report/types}/SlotRange.d.ts +0 -0
  129. /package/dist/esm/{types → lib/create-weekly-report/types}/WeekAndSlotRange.d.ts +0 -0
  130. /package/dist/esm/{types → lib/create-weekly-report/types}/stashed-Farm.d.ts +0 -0
@@ -0,0 +1,41 @@
1
+ export interface AuditSummary {
2
+ address: {
3
+ location: string;
4
+ coordinates: string;
5
+ };
6
+ solarPanels: {
7
+ quantity: number;
8
+ brandAndModel: string;
9
+ warranty: string;
10
+ };
11
+ installationAndOperations: {
12
+ installationDate: string;
13
+ ptoDate: string;
14
+ electricityPrice: string;
15
+ };
16
+ carbonFootprintAndProduction: {
17
+ averageSunlightPerDay: string;
18
+ adjustedWeeklyCarbonCredit: string;
19
+ weeklyTotalCarbonDebt: string;
20
+ netCarbonCreditEarningWeekly: string;
21
+ protocolFees: string;
22
+ systemWattageOutput: string;
23
+ };
24
+ }
25
+
26
+ export interface Audit {
27
+ orderIndex: number;
28
+ id: string;
29
+ farmName: string;
30
+ image: string;
31
+ auditDate: string;
32
+ auditorName: string;
33
+ auditorDesc: string;
34
+ auditorImage: string;
35
+ previousShortIds: number[];
36
+ activeShortIds: number[];
37
+ auditDocuments: unknown[];
38
+ preInstallPictures: unknown[];
39
+ afterInstallPictures: unknown[];
40
+ summary: AuditSummary;
41
+ }
@@ -1,3 +1,5 @@
1
1
  // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
2
 
3
- export interface AuditCompleted { week: number, }
3
+ export interface AuditCompleted {
4
+ week: number;
5
+ }
@@ -0,0 +1,8 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+
3
+ export interface AuditInherited {
4
+ originalAuditCompleteWeek: number;
5
+ oldFarmId: bigint;
6
+ weekAuditWasInherited: number;
7
+ slotRangeActiveInWeekInherited: [number, number];
8
+ }
@@ -0,0 +1,7 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+
3
+ export interface Device {
4
+ PublicKey: Array<number>;
5
+ powerOutputs: Array<number>;
6
+ impactRates: Array<number>;
7
+ }
@@ -0,0 +1,10 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { AuditInherited } from "./AuditInherited";
3
+
4
+ export interface DuplicatedButPastAuditCompleted {
5
+ weekDuplicated: number;
6
+ slotRangeActiveInWeekDuplicated: [number, number];
7
+ originalWeekAuditCompletedOrInherited: number;
8
+ newFarmId: bigint;
9
+ ifWasAlsoAuditInheritedInOnboardingWeek: AuditInherited | null;
10
+ }
@@ -0,0 +1,22 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { FarmStatus } from "./FarmStatus";
3
+ import type { RewardSplits } from "./RewardSplits";
4
+ import type { SlotRange } from "./SlotRange";
5
+
6
+ export interface Farm {
7
+ hexlifiedPublicKey: string;
8
+ carbonCreditsProduced: number;
9
+ powerOutputs: Array<number>;
10
+ impactRates: Array<number>;
11
+ weeklyPayment: number;
12
+ rollingImpactPoints: number;
13
+ powerOutput: number;
14
+ shortId: bigint;
15
+ protocolFee: number;
16
+ rewardSplits: RewardSplits | null;
17
+ status: FarmStatus;
18
+ protocolFeePaymentHash: string | null;
19
+ weeksAndSlotRangesToInvertPowerMap: Record<number, Array<SlotRange>> | null;
20
+ weeksAndSlotsToInvalidatePowerMap: Record<number, Array<SlotRange>> | null;
21
+ timestampAuditedComplete: bigint | null;
22
+ }
@@ -4,9 +4,9 @@ import type { AuditInherited } from "./AuditInherited";
4
4
  import type { DuplicatedButPastAuditCompleted } from "./DuplicatedButPastAuditCompleted";
5
5
 
6
6
  export type FarmStatus =
7
- | { AuditCompleted: AuditCompleted }
8
- | { AuditInherited: AuditInherited }
9
- | { Banned: number }
10
- | { Duplicate: number }
11
- | { DuplicateWithPastAuditCompleted: DuplicatedButPastAuditCompleted }
12
- | "Unassigned";
7
+ | { AuditCompleted: AuditCompleted }
8
+ | { AuditInherited: AuditInherited }
9
+ | { Banned: number }
10
+ | { Duplicate: number }
11
+ | { DuplicateWithPastAuditCompleted: DuplicatedButPastAuditCompleted }
12
+ | "Unassigned";
@@ -1,4 +1,8 @@
1
1
  // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
2
  import type { Device } from "./Device";
3
3
 
4
- export interface GCAServerResponse { Devices: Array<Device>, TimeslotOffset: bigint, signature: Array<number>, }
4
+ export interface GCAServerResponse {
5
+ Devices: Array<Device>;
6
+ TimeslotOffset: bigint;
7
+ signature: Array<number>;
8
+ }
@@ -0,0 +1,7 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+
3
+ export interface GetEquipmentDataHandlerParams {
4
+ url: string;
5
+ weekNumber: number;
6
+ withFullData: boolean | null;
7
+ }
@@ -0,0 +1,25 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { FarmStatus } from "./FarmStatus";
3
+ import type { SlotRange } from "./SlotRange";
4
+
5
+ export interface PayoutWalletAndSplit {
6
+ short_id: bigint;
7
+ payout_wallet: string;
8
+ auditor: string;
9
+ auditor_percenage_glow_weight: number;
10
+ auditor_percentage_usdc_weight: number;
11
+ glow_weight: number;
12
+ comments: Array<string> | null;
13
+ payment_tx_hash: string | null;
14
+ protocol_fee_paid_week: number;
15
+ status: FarmStatus | null;
16
+ weeks_and_slot_ranges_to_invert_power_map: Record<
17
+ number,
18
+ Array<SlotRange>
19
+ > | null;
20
+ weeks_and_slots_to_invalidate_power_map: Record<
21
+ number,
22
+ Array<SlotRange>
23
+ > | null;
24
+ timestamp_audited_completed: bigint | null;
25
+ }
@@ -0,0 +1,23 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { FarmStatus } from "./FarmStatus";
3
+ import type { RewardSplits } from "./RewardSplits";
4
+ import type { SlotRange } from "./SlotRange";
5
+
6
+ export interface PayoutWalletAndSplitWithRewardSplits {
7
+ short_id: bigint;
8
+ reward_splits: RewardSplits | null;
9
+ glow_weight: number;
10
+ comments: Array<string> | null;
11
+ payment_tx_hash: string | null;
12
+ protocol_fee_paid_week: number;
13
+ status: FarmStatus | null;
14
+ weeks_and_slot_ranges_to_invert_power_map: Record<
15
+ number,
16
+ Array<SlotRange>
17
+ > | null;
18
+ weeks_and_slots_to_invalidate_power_map: Record<
19
+ number,
20
+ Array<SlotRange>
21
+ > | null;
22
+ timestamp_audited_completed: bigint | null;
23
+ }
@@ -0,0 +1,7 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+
3
+ export interface RewardSplit {
4
+ walletAddress: string;
5
+ glowSplitPercent: number;
6
+ usdgSplitPercent: number;
7
+ }
@@ -0,0 +1,7 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+
3
+ export interface RewardSplit {
4
+ walletAddress: string;
5
+ glowSplitPercent: number;
6
+ usdgSplitPercent: number;
7
+ }
@@ -1,3 +1,4 @@
1
1
  // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { RewardSplit } from "./RewardSplit";
2
3
 
3
- export interface RewardSplit { walletAddress: string, glowSplitPercent: number, usdgSplitPercent: number, }
4
+ export type RewardSplits = Array<RewardSplit>;
@@ -1,4 +1,4 @@
1
1
  // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
2
  import type { RewardSplit } from "./RewardSplit";
3
3
 
4
- export type RewardSplits = Array<RewardSplit>;
4
+ export type RewardSplits = Array<RewardSplit>;
@@ -1,3 +1,6 @@
1
1
  // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
2
 
3
- export interface SlotRange { start_slot: number, end_slot: number, }
3
+ export interface SlotRange {
4
+ start_slot: number;
5
+ end_slot: number;
6
+ }
@@ -1,4 +1,7 @@
1
1
  // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
2
  import type { SlotRange } from "./SlotRange";
3
3
 
4
- export interface WeekAndSlotRange { week: number, slot_ranges: Array<SlotRange>, }
4
+ export interface WeekAndSlotRange {
5
+ week: number;
6
+ slot_ranges: Array<SlotRange>;
7
+ }
@@ -0,0 +1,7 @@
1
+ export * from "./Audit";
2
+ export * from "./Farm";
3
+ export * from "./GCAServerResponse";
4
+ export * from "./merkle";
5
+ export * from "./RewardSplits";
6
+ export * from "./SlotRange";
7
+ export * from "./FarmStatus";
@@ -0,0 +1,11 @@
1
+ export interface MerkleLeaf {
2
+ wallet: string;
3
+ glowWeight: bigint;
4
+ usdgWeight: bigint;
5
+ }
6
+
7
+ export interface FinalizedLeaf {
8
+ wallet: string;
9
+ glowWeight: string;
10
+ usdgWeight: string;
11
+ }
@@ -0,0 +1,22 @@
1
+ // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
+ import type { FarmStatus } from "./FarmStatus";
3
+ import type { RewardSplits } from "./RewardSplits";
4
+ import type { SlotRange } from "./SlotRange";
5
+
6
+ export interface Farm {
7
+ hexlifiedPublicKey: string;
8
+ carbonCreditsProduced: number;
9
+ powerOutputs: Array<number>;
10
+ impactRates: Array<number>;
11
+ weeklyPayment: number;
12
+ rollingImpactPoints: number;
13
+ powerOutput: number;
14
+ shortId: bigint;
15
+ protocolFee: number;
16
+ rewardSplits: RewardSplits | null;
17
+ status: FarmStatus;
18
+ protocolFeePaymentHash: string | null;
19
+ weeksAndSlotRangesToInvertPowerMap: Record<number, Array<SlotRange>> | null;
20
+ weeksAndSlotsToInvalidatePowerMap: Record<number, Array<SlotRange>> | null;
21
+ timestampAuditedComplete: bigint | null;
22
+ }
@@ -0,0 +1,17 @@
1
+ import { MerkleLeaf } from "../types/merkle";
2
+
3
+ export function accumulateLeafWeights(
4
+ key: string,
5
+ value: MerkleLeaf,
6
+ map: Map<string, MerkleLeaf>
7
+ ) {
8
+ if (map.has(key)) {
9
+ //+= everything
10
+ const existingValue = map.get(key)!;
11
+ existingValue.glowWeight += value.glowWeight;
12
+ existingValue.usdgWeight += value.usdgWeight;
13
+ map.set(key, existingValue);
14
+ } else {
15
+ map.set(key, value);
16
+ }
17
+ }
@@ -0,0 +1,9 @@
1
+ import Decimal from "decimal.js";
2
+
3
+ export function customToFixed(num: number, precision: number): string {
4
+ const decimal = new Decimal(num);
5
+ const fixed = decimal.toFixed(precision, Decimal.ROUND_DOWN);
6
+ if (fixed.includes("e"))
7
+ throw new Error("Number can't include scientific notation big");
8
+ return fixed;
9
+ }
@@ -0,0 +1,30 @@
1
+ import axios from "axios";
2
+ import { GCAServerResponse } from "../types/GCAServerResponse";
3
+ import { Farm } from "../types/Farm";
4
+
5
+ export interface ApiResponse {
6
+ filteredFarms: Farm[];
7
+ rawData: GCAServerResponse;
8
+ multiplier: number;
9
+ }
10
+
11
+ /**
12
+ * Fetches farm data for a given protocol week from the GCA API.
13
+ * @param weekNumber - The protocol week number
14
+ */
15
+ export async function fetchFarmsForWeek(
16
+ weekNumber: number,
17
+ gcaUrls: string[],
18
+ apiUrl: string
19
+ ): Promise<ApiResponse> {
20
+ const url = apiUrl;
21
+ const body = {
22
+ urls: gcaUrls,
23
+ week_number: weekNumber,
24
+ with_full_data: true,
25
+ include_unassigned_farms: false,
26
+ with_raw_data: true,
27
+ };
28
+ const res = await axios.post<ApiResponse>(url, body);
29
+ return res.data;
30
+ }
@@ -0,0 +1,12 @@
1
+ import Decimal from "decimal.js";
2
+
3
+ /**
4
+ * Converts a bigint with the specified decimal precision back to a Decimal.
5
+ * @param value - The bigint value
6
+ * @param decimals - Number of decimal places (default: 8)
7
+ */
8
+ export function fromBigInt(value: bigint, decimals = 8): Decimal {
9
+ if (decimals < 0 || decimals > 20)
10
+ throw new Error("decimals out of safe range (0-20)");
11
+ return new Decimal(value.toString()).div(10 ** decimals);
12
+ }
@@ -0,0 +1,9 @@
1
+ export function greaterThanMaxDeviation(
2
+ valA: number,
3
+ valB: number,
4
+ maxDeviationPercent: number,
5
+ ): boolean {
6
+ if (valA === valB) return false;
7
+ const maxDeviation = Math.abs(valA * maxDeviationPercent);
8
+ return Math.abs(valA - valB) >= maxDeviation;
9
+ }
@@ -0,0 +1,20 @@
1
+ import { ethers } from "ethers";
2
+ const leafTypes = ["address", "uint256", "uint256"];
3
+
4
+ type HashLeafArgs = {
5
+ address: string;
6
+ glowWeight: string;
7
+ usdcWeight: string;
8
+ };
9
+ export function hashLeaf({
10
+ address,
11
+ glowWeight,
12
+ usdcWeight,
13
+ }: HashLeafArgs): string {
14
+ const hash = ethers.utils.solidityKeccak256(leafTypes, [
15
+ address,
16
+ glowWeight,
17
+ usdcWeight,
18
+ ]);
19
+ return hash;
20
+ }
@@ -0,0 +1,15 @@
1
+ import { parseUnits } from "viem";
2
+ import { customToFixed } from "./custom-to-fixed";
3
+
4
+ export function multiplyBigIntByDecimalPercentage(
5
+ bigInt: bigint,
6
+ numberOfDecimals: number,
7
+ percentage: number
8
+ ): bigint {
9
+ const DENOMINATOR: bigint = BigInt(10 ** numberOfDecimals);
10
+ const percentageAsBigNum = BigInt(
11
+ parseUnits(customToFixed(percentage, numberOfDecimals), numberOfDecimals)
12
+ );
13
+ const value: bigint = (bigInt * percentageAsBigNum) / DENOMINATOR;
14
+ return value;
15
+ }
@@ -0,0 +1,16 @@
1
+ import Decimal from "decimal.js";
2
+
3
+ /**
4
+ * Converts a Decimal-like value to bigint with the specified decimal precision, rounding down.
5
+ * @param value - The value to convert (string, number, or Decimal)
6
+ * @param decimals - Number of decimal places (default: 8)
7
+ */
8
+ export function toBigInt(
9
+ value: string | number | Decimal,
10
+ decimals = 8
11
+ ): bigint {
12
+ if (decimals < 0 || decimals > 20)
13
+ throw new Error("decimals out of safe range (0-20)");
14
+ // ROUND_DOWN = 1
15
+ return BigInt(new Decimal(value).mul(10 ** decimals).toFixed(0, 1));
16
+ }
@@ -0,0 +1,9 @@
1
+ import Decimal from "decimal.js";
2
+
3
+ export function customToFixed(num: number, precision: number): string {
4
+ const decimal = new Decimal(num);
5
+ const fixed = decimal.toFixed(precision, Decimal.ROUND_DOWN);
6
+ if (fixed.includes("e"))
7
+ throw new Error("Number can't include scientific notation big");
8
+ return fixed;
9
+ }
@@ -0,0 +1,9 @@
1
+ export function greaterThanMaxDeviation(
2
+ valA: number,
3
+ valB: number,
4
+ maxDeviationPercent: number
5
+ ): boolean {
6
+ if (valA === valB) return false;
7
+ const maxDeviation = Math.abs(valA * maxDeviationPercent);
8
+ return Math.abs(valA - valB) >= maxDeviation;
9
+ }
@@ -0,0 +1,22 @@
1
+ import { ethers } from "ethers";
2
+ const leafTypes = ["address", "uint256", "uint256"];
3
+
4
+ type HashLeafArgs = {
5
+ address: string;
6
+ glowWeight: string;
7
+ usdcWeight: string;
8
+ };
9
+ export function hashLeaf({
10
+ address,
11
+ glowWeight,
12
+ usdcWeight,
13
+ }: HashLeafArgs): string {
14
+ const hash = ethers.utils.solidityKeccak256(leafTypes, [
15
+ address,
16
+ glowWeight,
17
+ usdcWeight,
18
+ ]);
19
+ return hash;
20
+ }
21
+
22
+ //
package/tsconfig.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "isolatedModules": true,
12
12
  "jsx": "preserve",
13
13
  "lib": ["es2020", "esnext", "dom"],
14
- "module": "esnext",
14
+ "module": "ESNext",
15
15
  "moduleResolution": "node",
16
16
  "noErrorTruncation": true,
17
17
  "noFallthroughCasesInSwitch": true,
@@ -22,7 +22,7 @@
22
22
  "skipLibCheck": true,
23
23
  "sourceMap": true,
24
24
  "strict": true,
25
- "target": "esnext",
25
+ "target": "ES2020",
26
26
  "typeRoots": ["node_modules/@types", "src/types"],
27
27
  "types": ["node"]
28
28
  },
@@ -1,5 +0,0 @@
1
- export type GCAAndServerUrl = {
2
- gca: `0x${string}`;
3
- urls: string[];
4
- notes?: string[];
5
- };
@@ -1,14 +0,0 @@
1
- export * from "./AuditCompleted";
2
- export * from "./AuditInherited";
3
- export * from "./Device";
4
- export * from "./DuplicatedButPastAuditCompleted";
5
- export * from "./Farm";
6
- export * from "./FarmStatus";
7
- export * from "./GCAServerResponse";
8
- export * from "./GetEquipmentDataHandlerParams";
9
- export * from "./PayoutWalletAndSplit";
10
- export * from "./PayoutWalletAndSplitWithRewardSplits";
11
- export * from "./RewardSplit";
12
- export * from "./RewardSplits";
13
- export * from "./SlotRange";
14
- export * from "./WeekAndSlotRange";
@@ -1,5 +0,0 @@
1
- export type GCAAndServerUrl = {
2
- gca: `0x${string}`;
3
- urls: string[];
4
- notes?: string[];
5
- };
@@ -1,14 +0,0 @@
1
- export * from "./AuditCompleted";
2
- export * from "./AuditInherited";
3
- export * from "./Device";
4
- export * from "./DuplicatedButPastAuditCompleted";
5
- export * from "./Farm";
6
- export * from "./FarmStatus";
7
- export * from "./GCAServerResponse";
8
- export * from "./GetEquipmentDataHandlerParams";
9
- export * from "./PayoutWalletAndSplit";
10
- export * from "./PayoutWalletAndSplitWithRewardSplits";
11
- export * from "./RewardSplit";
12
- export * from "./RewardSplits";
13
- export * from "./SlotRange";
14
- export * from "./WeekAndSlotRange";
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export interface AuditInherited { originalAuditCompleteWeek: number, oldFarmId: bigint, weekAuditWasInherited: number, slotRangeActiveInWeekInherited: [number, number], }
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export interface Device { PublicKey: Array<number>, powerOutputs: Array<number>, impactRates: Array<number>, }
@@ -1,4 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { AuditInherited } from "./AuditInherited";
3
-
4
- export interface DuplicatedButPastAuditCompleted { weekDuplicated: number, slotRangeActiveInWeekDuplicated: [number, number], originalWeekAuditCompletedOrInherited: number, newFarmId: bigint, ifWasAlsoAuditInheritedInOnboardingWeek: AuditInherited | null, }
package/src/types/Farm.ts DELETED
@@ -1,22 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { FarmStatus } from "./FarmStatus";
3
- import type { RewardSplits } from "./RewardSplits";
4
- import type { SlotRange } from "./SlotRange";
5
-
6
- export interface Farm {
7
- hexlifiedPublicKey: string;
8
- carbonCreditsProduced: number;
9
- powerOutputs: Array<number>;
10
- impactRates: Array<number>;
11
- weeklyPayment: number;
12
- rollingImpactPoints: number;
13
- powerOutput: number;
14
- shortId: bigint;
15
- protocolFee: number;
16
- rewardSplits: RewardSplits | null;
17
- status: FarmStatus;
18
- protocolFeePaymentHash: string | null;
19
- weeksAndSlotRangesToInvertPowerMap: Record<number, Array<SlotRange>> | null;
20
- weeksAndSlotsToInvalidatePowerMap: Record<number, Array<SlotRange>> | null;
21
- timestampAuditedComplete: bigint | null;
22
- }
@@ -1,5 +0,0 @@
1
- export type GCAAndServerUrl = {
2
- gca: `0x${string}`;
3
- urls: string[];
4
- notes?: string[];
5
- };
@@ -1,3 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
-
3
- export interface GetEquipmentDataHandlerParams { url: string, weekNumber: number, withFullData: boolean | null, }
@@ -1,5 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { FarmStatus } from "./FarmStatus";
3
- import type { SlotRange } from "./SlotRange";
4
-
5
- export interface PayoutWalletAndSplit { short_id: bigint, payout_wallet: string, auditor: string, auditor_percenage_glow_weight: number, auditor_percentage_usdc_weight: number, glow_weight: number, comments: Array<string> | null, payment_tx_hash: string | null, protocol_fee_paid_week: number, status: FarmStatus | null, weeks_and_slot_ranges_to_invert_power_map: Record<number, Array<SlotRange>> | null, weeks_and_slots_to_invalidate_power_map: Record<number, Array<SlotRange>> | null, timestamp_audited_completed: bigint | null, }
@@ -1,6 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { FarmStatus } from "./FarmStatus";
3
- import type { RewardSplits } from "./RewardSplits";
4
- import type { SlotRange } from "./SlotRange";
5
-
6
- export interface PayoutWalletAndSplitWithRewardSplits { short_id: bigint, reward_splits: RewardSplits | null, glow_weight: number, comments: Array<string> | null, payment_tx_hash: string | null, protocol_fee_paid_week: number, status: FarmStatus | null, weeks_and_slot_ranges_to_invert_power_map: Record<number, Array<SlotRange>> | null, weeks_and_slots_to_invalidate_power_map: Record<number, Array<SlotRange>> | null, timestamp_audited_completed: bigint | null, }
@@ -1,14 +0,0 @@
1
- export * from "./AuditCompleted";
2
- export * from "./AuditInherited";
3
- export * from "./Device";
4
- export * from "./DuplicatedButPastAuditCompleted";
5
- export * from "./Farm";
6
- export * from "./FarmStatus";
7
- export * from "./GCAServerResponse";
8
- export * from "./GetEquipmentDataHandlerParams";
9
- export * from "./PayoutWalletAndSplit";
10
- export * from "./PayoutWalletAndSplitWithRewardSplits";
11
- export * from "./RewardSplit";
12
- export * from "./RewardSplits";
13
- export * from "./SlotRange";
14
- export * from "./WeekAndSlotRange";
@@ -1,22 +0,0 @@
1
- // This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2
- import type { FarmStatus } from "./FarmStatus";
3
- import type { RewardSplits } from "./RewardSplits";
4
- import type { SlotRange } from "./SlotRange";
5
-
6
- export interface Farm {
7
- hexlifiedPublicKey: string;
8
- carbonCreditsProduced: number;
9
- powerOutputs: Array<number>;
10
- impactRates: Array<number>;
11
- weeklyPayment: number;
12
- rollingImpactPoints: number;
13
- powerOutput: number;
14
- shortId: bigint;
15
- protocolFee: number;
16
- rewardSplits: RewardSplits | null;
17
- status: FarmStatus;
18
- protocolFeePaymentHash: string | null;
19
- weeksAndSlotRangesToInvertPowerMap: Record<number, Array<SlotRange>> | null;
20
- weeksAndSlotsToInvalidatePowerMap: Record<number, Array<SlotRange>> | null;
21
- timestampAuditedComplete: bigint | null;
22
- }