@glowlabs-org/utils 0.2.156 → 0.2.158
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/dist/cjs/browser.d.ts +1 -0
- package/dist/cjs/browser.js +41 -39
- package/dist/cjs/browser.js.map +1 -1
- package/dist/cjs/{farms-router-DekpTBQj.js → calculate-farm-efficiency-CLa5037R.js} +58 -1
- package/dist/cjs/calculate-farm-efficiency-CLa5037R.js.map +1 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +46 -45
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/control-api/farms-router.d.ts +527 -13
- package/dist/cjs/lib/types/index.d.ts +16 -0
- package/dist/cjs/utils/calculate-farm-efficiency.d.ts +27 -0
- package/dist/esm/browser.d.ts +1 -0
- package/dist/esm/browser.js +3 -2
- package/dist/esm/browser.js.map +1 -1
- package/dist/esm/{farms-router-L56VPDNz.js → calculate-farm-efficiency-Ceoa2xwl.js} +58 -2
- package/dist/esm/calculate-farm-efficiency-Ceoa2xwl.js.map +1 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +2 -2
- package/dist/esm/lib/control-api/farms-router.d.ts +527 -13
- package/dist/esm/lib/types/index.d.ts +16 -0
- package/dist/esm/utils/calculate-farm-efficiency.d.ts +27 -0
- package/package.json +1 -1
- package/src/browser.ts +1 -0
- package/src/index.ts +1 -0
- package/src/lib/control-api/farms-router.ts +550 -12
- package/src/lib/types/index.ts +20 -0
- package/src/utils/calculate-farm-efficiency.ts +48 -0
- package/dist/cjs/farms-router-DekpTBQj.js.map +0 -1
- package/dist/esm/farms-router-L56VPDNz.js.map +0 -1
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var ethers = require('ethers');
|
|
4
4
|
var viem = require('viem');
|
|
5
|
+
var Decimal = require('decimal.js');
|
|
5
6
|
|
|
6
7
|
const HUB_URL = "https://glow.org";
|
|
7
8
|
const GCA_URLS = ["http://95.217.194.59:35015"];
|
|
@@ -4998,6 +4999,19 @@ function FarmsRouter(baseUrl) {
|
|
|
4998
4999
|
throw new Error(parseApiError(error));
|
|
4999
5000
|
}
|
|
5000
5001
|
};
|
|
5002
|
+
const fetchEfficiencyScores = async (farmId) => {
|
|
5003
|
+
try {
|
|
5004
|
+
const query = farmId ? `?farmId=${encodeURIComponent(farmId)}` : "";
|
|
5005
|
+
const data = await request(`/farms/efficiency-scores${query}`);
|
|
5006
|
+
if ("error" in data) {
|
|
5007
|
+
throw new Error(data.error);
|
|
5008
|
+
}
|
|
5009
|
+
return data;
|
|
5010
|
+
}
|
|
5011
|
+
catch (error) {
|
|
5012
|
+
throw new Error(parseApiError(error));
|
|
5013
|
+
}
|
|
5014
|
+
};
|
|
5001
5015
|
return {
|
|
5002
5016
|
fetchFarmRewardSplits,
|
|
5003
5017
|
fetchSponsoredFarms,
|
|
@@ -5006,9 +5020,51 @@ function FarmsRouter(baseUrl) {
|
|
|
5006
5020
|
estimateRewardScore,
|
|
5007
5021
|
estimateRewardScoresBatch,
|
|
5008
5022
|
calculateMiningScoresBatch,
|
|
5023
|
+
fetchEfficiencyScores,
|
|
5009
5024
|
};
|
|
5010
5025
|
}
|
|
5011
5026
|
|
|
5027
|
+
/**
|
|
5028
|
+
* Calculates the efficiency score for a farm
|
|
5029
|
+
*
|
|
5030
|
+
* Formula: efficiencyScore = (CC / PD) / 100,000
|
|
5031
|
+
*
|
|
5032
|
+
* Where:
|
|
5033
|
+
* - CC = weekly carbon credits in WAD format (18 decimals)
|
|
5034
|
+
* - PD = protocol deposit in USD (6 decimals)
|
|
5035
|
+
*
|
|
5036
|
+
* Due to the decimal difference (CC has 18 decimals, PD has 6 decimals),
|
|
5037
|
+
* the actual calculation maintains a 10^12 factor, resulting in:
|
|
5038
|
+
* efficiencyScore = (CC_actual / PD_actual) × 10^8
|
|
5039
|
+
*
|
|
5040
|
+
* The efficiency score represents carbon credits produced per $100,000 of
|
|
5041
|
+
* protocol deposit per week. Higher scores indicate more efficient farms.
|
|
5042
|
+
*
|
|
5043
|
+
* @param protocolDepositUsd6 - Protocol deposit in USD (6 decimals)
|
|
5044
|
+
* @param weeklyImpactAssetsWad - Weekly carbon credits in WAD format (18 decimals)
|
|
5045
|
+
* @returns The efficiency score as a number
|
|
5046
|
+
*
|
|
5047
|
+
* @example
|
|
5048
|
+
* ```typescript
|
|
5049
|
+
* const score = calculateFarmEfficiency(5000000000n, 1500000000000000000n);
|
|
5050
|
+
* // Returns the efficiency score
|
|
5051
|
+
* ```
|
|
5052
|
+
*/
|
|
5053
|
+
function calculateFarmEfficiency(protocolDepositUsd6, weeklyImpactAssetsWad) {
|
|
5054
|
+
// Handle zero carbon credits case
|
|
5055
|
+
if (weeklyImpactAssetsWad === 0n) {
|
|
5056
|
+
return 0;
|
|
5057
|
+
}
|
|
5058
|
+
// Convert to Decimal for precise calculation
|
|
5059
|
+
const pdDecimal = new Decimal(protocolDepositUsd6.toString());
|
|
5060
|
+
const ccDecimal = new Decimal(weeklyImpactAssetsWad.toString());
|
|
5061
|
+
// Formula: efficiencyScore = (CC / PD) / 100,000
|
|
5062
|
+
// CC is in 18 decimals, PD is in 6 decimals
|
|
5063
|
+
// Direct division: (CC / PD) / 100,000
|
|
5064
|
+
const efficiencyDecimal = ccDecimal.div(pdDecimal).div(100000);
|
|
5065
|
+
return efficiencyDecimal.toNumber();
|
|
5066
|
+
}
|
|
5067
|
+
|
|
5012
5068
|
exports.ControlRouter = ControlRouter;
|
|
5013
5069
|
exports.DECIMALS_BY_TOKEN = DECIMALS_BY_TOKEN;
|
|
5014
5070
|
exports.FORWARDER_ABI = FORWARDER_ABI;
|
|
@@ -5027,6 +5083,7 @@ exports.TRANSFER_TYPES = TRANSFER_TYPES;
|
|
|
5027
5083
|
exports.USDG_WEIGHT_DECIMAL_PRECISION = USDG_WEIGHT_DECIMAL_PRECISION;
|
|
5028
5084
|
exports.WalletsRouter = WalletsRouter;
|
|
5029
5085
|
exports.allRegions = allRegions;
|
|
5086
|
+
exports.calculateFarmEfficiency = calculateFarmEfficiency;
|
|
5030
5087
|
exports.configureSentry = configureSentry;
|
|
5031
5088
|
exports.countries = countries;
|
|
5032
5089
|
exports.getAddresses = getAddresses;
|
|
@@ -5039,4 +5096,4 @@ exports.useOffchainFractions = useOffchainFractions;
|
|
|
5039
5096
|
exports.useRewardsKernel = useRewardsKernel;
|
|
5040
5097
|
exports.waitForEthersTransactionWithRetry = waitForEthersTransactionWithRetry;
|
|
5041
5098
|
exports.waitForViemTransactionWithRetry = waitForViemTransactionWithRetry;
|
|
5042
|
-
//# sourceMappingURL=
|
|
5099
|
+
//# sourceMappingURL=calculate-farm-efficiency-CLa5037R.js.map
|