@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.
- package/.github/workflows/publish.yml +14 -4
- package/dist/cjs/constants/regex.d.ts +1 -0
- package/dist/cjs/constants/urls.d.ts +2 -0
- package/dist/cjs/constants/weights.d.ts +12 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +18988 -89
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/create-weekly-report/index.d.ts +73 -0
- package/dist/cjs/lib/create-weekly-report/types/Audit.d.ts +40 -0
- package/dist/cjs/lib/create-weekly-report/types/index.d.ts +7 -0
- package/dist/cjs/lib/create-weekly-report/types/merkle.d.ts +10 -0
- package/dist/cjs/lib/create-weekly-report/utils/accumulate-leaf-weights.d.ts +2 -0
- package/dist/cjs/lib/create-weekly-report/utils/custom-to-fixed.d.ts +1 -0
- package/dist/cjs/lib/create-weekly-report/utils/fetch-farms-for-week.d.ts +12 -0
- package/dist/cjs/lib/create-weekly-report/utils/from-bigint.d.ts +7 -0
- package/dist/cjs/lib/create-weekly-report/utils/greater-than-max-deviation.d.ts +1 -0
- package/dist/cjs/lib/create-weekly-report/utils/hashLeaf.d.ts +7 -0
- package/dist/cjs/lib/create-weekly-report/utils/multiply-bigInt-by-decimal-percentage.d.ts +1 -0
- package/dist/cjs/lib/create-weekly-report/utils/to-bigint.d.ts +7 -0
- package/dist/cjs/utils/custom-to-fixed.d.ts +1 -0
- package/dist/cjs/utils/greater-than-max-deviation.d.ts +1 -0
- package/dist/cjs/utils/hash-leaf.d.ts +7 -0
- package/dist/esm/constants/regex.d.ts +1 -0
- package/dist/esm/constants/urls.d.ts +2 -0
- package/dist/esm/constants/weights.d.ts +12 -0
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +18988 -89
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/create-weekly-report/index.d.ts +73 -0
- package/dist/esm/lib/create-weekly-report/types/Audit.d.ts +40 -0
- package/dist/esm/lib/create-weekly-report/types/RewardSplit copy.d.ts +5 -0
- package/dist/esm/lib/create-weekly-report/types/RewardSplit.d.ts +5 -0
- package/dist/esm/lib/create-weekly-report/types/RewardSplits copy.d.ts +2 -0
- package/dist/esm/lib/create-weekly-report/types/RewardSplits.d.ts +2 -0
- package/dist/esm/lib/create-weekly-report/types/index.d.ts +7 -0
- package/dist/esm/lib/create-weekly-report/types/merkle.d.ts +10 -0
- package/dist/esm/lib/create-weekly-report/utils/accumulate-leaf-weights.d.ts +2 -0
- package/dist/esm/lib/create-weekly-report/utils/custom-to-fixed.d.ts +1 -0
- package/dist/esm/lib/create-weekly-report/utils/fetch-farms-for-week.d.ts +12 -0
- package/dist/esm/lib/create-weekly-report/utils/from-bigint.d.ts +7 -0
- package/dist/esm/lib/create-weekly-report/utils/greater-than-max-deviation.d.ts +1 -0
- package/dist/esm/lib/create-weekly-report/utils/hashLeaf.d.ts +7 -0
- package/dist/esm/lib/create-weekly-report/utils/multiply-bigInt-by-decimal-percentage.d.ts +1 -0
- package/dist/esm/lib/create-weekly-report/utils/to-bigint.d.ts +7 -0
- package/dist/esm/utils/custom-to-fixed.d.ts +1 -0
- package/dist/esm/utils/greater-than-max-deviation.d.ts +1 -0
- package/dist/esm/utils/hash-leaf.d.ts +7 -0
- package/package.json +13 -9
- package/rollup.config.js +2 -0
- package/src/constants/regex.ts +2 -0
- package/src/constants/urls.ts +3 -0
- package/src/constants/weights.ts +15 -0
- package/src/index.ts +1 -1
- package/src/lib/create-weekly-report/index.ts +691 -0
- package/src/lib/create-weekly-report/types/Audit.ts +41 -0
- package/src/{types → lib/create-weekly-report/types}/AuditCompleted.ts +3 -1
- package/src/lib/create-weekly-report/types/AuditInherited.ts +8 -0
- package/src/lib/create-weekly-report/types/Device.ts +7 -0
- package/src/lib/create-weekly-report/types/DuplicatedButPastAuditCompleted.ts +10 -0
- package/src/lib/create-weekly-report/types/Farm.ts +22 -0
- package/src/{types → lib/create-weekly-report/types}/FarmStatus.ts +6 -6
- package/src/{types → lib/create-weekly-report/types}/GCAServerResponse.ts +5 -1
- package/src/lib/create-weekly-report/types/GetEquipmentDataHandlerParams.ts +7 -0
- package/src/lib/create-weekly-report/types/PayoutWalletAndSplit.ts +25 -0
- package/src/lib/create-weekly-report/types/PayoutWalletAndSplitWithRewardSplits.ts +23 -0
- package/src/lib/create-weekly-report/types/RewardSplit copy.ts +7 -0
- package/src/lib/create-weekly-report/types/RewardSplit.ts +7 -0
- package/src/{types/RewardSplit.ts → lib/create-weekly-report/types/RewardSplits copy.ts } +2 -1
- package/src/{types → lib/create-weekly-report/types}/RewardSplits.ts +1 -1
- package/src/{types → lib/create-weekly-report/types}/SlotRange.ts +4 -1
- package/src/{types → lib/create-weekly-report/types}/WeekAndSlotRange.ts +4 -1
- package/src/lib/create-weekly-report/types/index.ts +7 -0
- package/src/lib/create-weekly-report/types/merkle.ts +11 -0
- package/src/lib/create-weekly-report/types/stashed-Farm.ts +22 -0
- package/src/lib/create-weekly-report/utils/accumulate-leaf-weights.ts +17 -0
- package/src/lib/create-weekly-report/utils/custom-to-fixed.ts +9 -0
- package/src/lib/create-weekly-report/utils/fetch-farms-for-week.ts +30 -0
- package/src/lib/create-weekly-report/utils/from-bigint.ts +12 -0
- package/src/lib/create-weekly-report/utils/greater-than-max-deviation.ts +9 -0
- package/src/lib/create-weekly-report/utils/hashLeaf.ts +20 -0
- package/src/lib/create-weekly-report/utils/multiply-bigInt-by-decimal-percentage.ts +15 -0
- package/src/lib/create-weekly-report/utils/to-bigint.ts +16 -0
- package/src/utils/custom-to-fixed.ts +9 -0
- package/src/utils/greater-than-max-deviation.ts +9 -0
- package/src/utils/hash-leaf.ts +22 -0
- package/tsconfig.json +2 -2
- package/dist/cjs/types/GCAAndServerUrl.d.ts +0 -5
- package/dist/cjs/types/index.d.ts +0 -14
- package/dist/esm/types/GCAAndServerUrl.d.ts +0 -5
- package/dist/esm/types/index.d.ts +0 -14
- package/src/types/AuditInherited.ts +0 -3
- package/src/types/Device.ts +0 -3
- package/src/types/DuplicatedButPastAuditCompleted.ts +0 -4
- package/src/types/Farm.ts +0 -22
- package/src/types/GCAAndServerUrl.ts +0 -5
- package/src/types/GetEquipmentDataHandlerParams.ts +0 -3
- package/src/types/PayoutWalletAndSplit.ts +0 -5
- package/src/types/PayoutWalletAndSplitWithRewardSplits.ts +0 -6
- package/src/types/index.ts +0 -14
- package/src/types/stashed-Farm.ts +0 -22
- /package/dist/cjs/{types → lib/create-weekly-report/types}/AuditCompleted.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/AuditInherited.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/Device.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/DuplicatedButPastAuditCompleted.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/Farm.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/FarmStatus.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/GCAServerResponse.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/GetEquipmentDataHandlerParams.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/PayoutWalletAndSplit.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/PayoutWalletAndSplitWithRewardSplits.d.ts +0 -0
- /package/dist/cjs/{types/RewardSplit.d.ts → lib/create-weekly-report/types/RewardSplit copy.d.ts} +0 -0
- /package/dist/{esm → cjs/lib/create-weekly-report}/types/RewardSplit.d.ts +0 -0
- /package/dist/cjs/{types/RewardSplits.d.ts → lib/create-weekly-report/types/RewardSplits copy.d.ts} +0 -0
- /package/dist/{esm → cjs/lib/create-weekly-report}/types/RewardSplits.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/SlotRange.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/WeekAndSlotRange.d.ts +0 -0
- /package/dist/cjs/{types → lib/create-weekly-report/types}/stashed-Farm.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/AuditCompleted.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/AuditInherited.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/Device.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/DuplicatedButPastAuditCompleted.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/Farm.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/FarmStatus.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/GCAServerResponse.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/GetEquipmentDataHandlerParams.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/PayoutWalletAndSplit.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/PayoutWalletAndSplitWithRewardSplits.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/SlotRange.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/WeekAndSlotRange.d.ts +0 -0
- /package/dist/esm/{types → lib/create-weekly-report/types}/stashed-Farm.d.ts +0 -0
@@ -0,0 +1,73 @@
|
|
1
|
+
import { FinalizedLeaf } from "./types/merkle";
|
2
|
+
export type MerkleLeafIntermediary = {
|
3
|
+
wallet: string;
|
4
|
+
glowWeight: bigint;
|
5
|
+
usdgWeight: bigint;
|
6
|
+
};
|
7
|
+
export type FinalLeaf = {
|
8
|
+
wallet: string;
|
9
|
+
glowWeight: string;
|
10
|
+
usdgWeight: string;
|
11
|
+
};
|
12
|
+
export type CreateWeeklyReportArgs = {
|
13
|
+
week: number;
|
14
|
+
gcaUrls: string[];
|
15
|
+
apiUrl: string;
|
16
|
+
};
|
17
|
+
export declare function createWeeklyReport({ week, gcaUrls, apiUrl, }: CreateWeeklyReportArgs): Promise<{
|
18
|
+
headlineStats: {
|
19
|
+
weekNumber: number;
|
20
|
+
totalCreditsProduced: string;
|
21
|
+
totalCreditsProducedBN: string;
|
22
|
+
totalGlowWeightInFinalized: string;
|
23
|
+
totalGlowWeightHuman: string;
|
24
|
+
totalUSDGWeightInFinalized: string;
|
25
|
+
totalUSDGWeightHuman: string;
|
26
|
+
root: string;
|
27
|
+
glowWeightDecimals: number;
|
28
|
+
usdgWeightDecimals: number;
|
29
|
+
};
|
30
|
+
finalLeaves: FinalLeaf[];
|
31
|
+
farmsWithMerkleProofs: {
|
32
|
+
proof: string[];
|
33
|
+
wallet: string;
|
34
|
+
glowWeight: string;
|
35
|
+
usdgWeight: string;
|
36
|
+
}[];
|
37
|
+
farms: import("./types").Farm[];
|
38
|
+
rawData: import("./types").GCAServerResponse;
|
39
|
+
} | {
|
40
|
+
headlineStats: {
|
41
|
+
weekNumber: number;
|
42
|
+
totalCreditsProduced: string;
|
43
|
+
totalCreditsProducedBN: string;
|
44
|
+
totalGlowWeightInFinalized: string;
|
45
|
+
totalGlowWeightHuman: string;
|
46
|
+
totalUSDGWeightInFinalized: string;
|
47
|
+
totalUSDGWeightHuman: string;
|
48
|
+
root: string;
|
49
|
+
glowWeightDecimals: number;
|
50
|
+
usdgWeightDecimals: number;
|
51
|
+
};
|
52
|
+
finalizedLeaves: FinalizedLeaf[];
|
53
|
+
leavesWithProofs: {
|
54
|
+
proof: string[];
|
55
|
+
wallet: string;
|
56
|
+
glowWeight: string;
|
57
|
+
usdgWeight: string;
|
58
|
+
}[];
|
59
|
+
farms: import("./types").Farm[];
|
60
|
+
rawData: import("./types").GCAServerResponse;
|
61
|
+
shortIdAdjustedList: {
|
62
|
+
shortId: string;
|
63
|
+
adjustedCredit: string;
|
64
|
+
}[];
|
65
|
+
creditsDeviationList: {
|
66
|
+
shortId: string;
|
67
|
+
carbonCreditsProduced: number;
|
68
|
+
adjustedWeeklyCarbonCredit: number;
|
69
|
+
deviation: number;
|
70
|
+
absDeviation: number;
|
71
|
+
deviationPercent: number;
|
72
|
+
}[];
|
73
|
+
}>;
|
@@ -0,0 +1,40 @@
|
|
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
|
+
export interface Audit {
|
26
|
+
orderIndex: number;
|
27
|
+
id: string;
|
28
|
+
farmName: string;
|
29
|
+
image: string;
|
30
|
+
auditDate: string;
|
31
|
+
auditorName: string;
|
32
|
+
auditorDesc: string;
|
33
|
+
auditorImage: string;
|
34
|
+
previousShortIds: number[];
|
35
|
+
activeShortIds: number[];
|
36
|
+
auditDocuments: unknown[];
|
37
|
+
preInstallPictures: unknown[];
|
38
|
+
afterInstallPictures: unknown[];
|
39
|
+
summary: AuditSummary;
|
40
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function customToFixed(num: number, precision: number): string;
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import { GCAServerResponse } from "../types/GCAServerResponse";
|
2
|
+
import { Farm } from "../types/Farm";
|
3
|
+
export interface ApiResponse {
|
4
|
+
filteredFarms: Farm[];
|
5
|
+
rawData: GCAServerResponse;
|
6
|
+
multiplier: number;
|
7
|
+
}
|
8
|
+
/**
|
9
|
+
* Fetches farm data for a given protocol week from the GCA API.
|
10
|
+
* @param weekNumber - The protocol week number
|
11
|
+
*/
|
12
|
+
export declare function fetchFarmsForWeek(weekNumber: number, gcaUrls: string[], apiUrl: string): Promise<ApiResponse>;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import Decimal from "decimal.js";
|
2
|
+
/**
|
3
|
+
* Converts a bigint with the specified decimal precision back to a Decimal.
|
4
|
+
* @param value - The bigint value
|
5
|
+
* @param decimals - Number of decimal places (default: 8)
|
6
|
+
*/
|
7
|
+
export declare function fromBigInt(value: bigint, decimals?: number): Decimal;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function greaterThanMaxDeviation(valA: number, valB: number, maxDeviationPercent: number): boolean;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function multiplyBigIntByDecimalPercentage(bigInt: bigint, numberOfDecimals: number, percentage: number): bigint;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
import Decimal from "decimal.js";
|
2
|
+
/**
|
3
|
+
* Converts a Decimal-like value to bigint with the specified decimal precision, rounding down.
|
4
|
+
* @param value - The value to convert (string, number, or Decimal)
|
5
|
+
* @param decimals - Number of decimal places (default: 8)
|
6
|
+
*/
|
7
|
+
export declare function toBigInt(value: string | number | Decimal, decimals?: number): bigint;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function customToFixed(num: number, precision: number): string;
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function greaterThanMaxDeviation(valA: number, valB: number, maxDeviationPercent: number): boolean;
|
package/package.json
CHANGED
@@ -1,11 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@glowlabs-org/utils",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.1.1",
|
4
4
|
"description": "A library containing all typechain types and addresses relating to the glow guarded launch",
|
5
|
-
"scripts": {
|
6
|
-
"test": "echo \"Error: no test specified\" && exit 1",
|
7
|
-
"build": "rollup -c"
|
8
|
-
},
|
9
5
|
"keywords": [],
|
10
6
|
"author": "",
|
11
7
|
"license": "ISC",
|
@@ -26,18 +22,26 @@
|
|
26
22
|
"peerDependencies": {
|
27
23
|
"ethers": "5.x.x",
|
28
24
|
"merkletreejs": "^0.3.11",
|
29
|
-
"viem": "^2.19.7"
|
25
|
+
"viem": "^2.19.7",
|
26
|
+
"decimal.js": "^10.4.3"
|
30
27
|
},
|
31
28
|
"devDependencies": {
|
32
29
|
"@rollup/plugin-commonjs": "^26.0.1",
|
30
|
+
"@rollup/plugin-json": "^6.1.0",
|
33
31
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
34
32
|
"@types/node": "^20.10.5",
|
33
|
+
"axios": "^1.9.0",
|
34
|
+
"decimal.js": "^10.4.3",
|
35
35
|
"esbuild": "^0.23.1",
|
36
|
-
"ethers": "
|
36
|
+
"ethers": "5.7.2",
|
37
37
|
"rollup": "^4.21.0",
|
38
38
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
39
39
|
"rollup-plugin-typescript2": "^0.36.0",
|
40
40
|
"typescript": "^5.5.4",
|
41
|
-
"viem": "^2.
|
41
|
+
"viem": "^2.7.16"
|
42
|
+
},
|
43
|
+
"scripts": {
|
44
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
45
|
+
"build": "rollup -c"
|
42
46
|
}
|
43
|
-
}
|
47
|
+
}
|
package/rollup.config.js
CHANGED
@@ -2,6 +2,7 @@ import commonjs from "@rollup/plugin-commonjs";
|
|
2
2
|
import resolve from "@rollup/plugin-node-resolve";
|
3
3
|
import typescript from "rollup-plugin-typescript2";
|
4
4
|
import peerDepsExternal from "rollup-plugin-peer-deps-external";
|
5
|
+
import json from "@rollup/plugin-json";
|
5
6
|
|
6
7
|
export default {
|
7
8
|
input: "src/index.ts", // Adjust to your entry point
|
@@ -21,6 +22,7 @@ export default {
|
|
21
22
|
peerDepsExternal(), // Automatically externalize peer dependencies
|
22
23
|
resolve(), // Resolves node modules
|
23
24
|
commonjs(), // Converts CommonJS modules to ES6
|
25
|
+
json(),
|
24
26
|
typescript({ tsconfig: "./tsconfig.json" }), // Handles TypeScript
|
25
27
|
],
|
26
28
|
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
/**
|
2
|
+
* @dev This is actually not as intuitive as it seems.
|
3
|
+
* Glow actually has 18 decimals, but glow weight is based on the amount of protocol fees (USDC) that the farm paid
|
4
|
+
* Therefore, the weight is based on the amount of USDC that was paid, which has 8 decimals
|
5
|
+
*/
|
6
|
+
export const GLOW_WEIGHT_DECIMAL_PRECISION = 8;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* @dev This is actually not as intuitive as it seems.
|
10
|
+
* USDG weight is based on the amount of carbon credits produced, but the max value of a weight is ((2*64)-1) / 5 so we need to choose sensible precision to make sure that number never overflows
|
11
|
+
*/
|
12
|
+
export const USDG_WEIGHT_DECIMAL_PRECISION = 8;
|
13
|
+
|
14
|
+
export const MAX_WEIGHT: bigint =
|
15
|
+
(BigInt(2) ** BigInt(64) - BigInt(1)) / BigInt(5);
|
package/src/index.ts
CHANGED