@ethersphere/bee-js
Advanced tools
Comparing version 6.6.0 to 6.7.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampCostInPlur = exports.getStampCostInBzz = exports.getDepthForCapacity = exports.getAmountForTtl = exports.makeMaxTarget = exports.keccak256Hash = exports.readableWebToNode = exports.readableNodeToWeb = exports.normalizeToReadableStream = exports.isReadableStream = exports.isReadable = exports.isNodeReadable = exports.toLittleEndian = exports.makeHexEthAddress = exports.makeEthereumWalletSigner = exports.makeEthAddress = exports.isHexEthAddress = exports.fromLittleEndian = exports.ethToSwarmAddress = exports.makeHexString = exports.isHexString = exports.intToHex = exports.hexToBytes = exports.bytesToHex = exports.assertPrefixedHexString = exports.assertHexString = exports.isFlexBytes = exports.isBytes = exports.flexBytesAtOffset = exports.bytesEqual = exports.bytesAtOffset = exports.assertFlexBytes = exports.assertBytes = exports.getFolderSize = exports.getCollectionSize = void 0; | ||
exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampEffectiveBytes = exports.getStampMaximumCapacityBytes = exports.getStampCostInPlur = exports.getStampCostInBzz = exports.getDepthForCapacity = exports.getAmountForTtl = exports.makeMaxTarget = exports.keccak256Hash = exports.readableWebToNode = exports.readableNodeToWeb = exports.normalizeToReadableStream = exports.isReadableStream = exports.isReadable = exports.isNodeReadable = exports.toLittleEndian = exports.makeHexEthAddress = exports.makeEthereumWalletSigner = exports.makeEthAddress = exports.isHexEthAddress = exports.fromLittleEndian = exports.ethToSwarmAddress = exports.makeHexString = exports.isHexString = exports.intToHex = exports.hexToBytes = exports.bytesToHex = exports.assertPrefixedHexString = exports.assertHexString = exports.isFlexBytes = exports.isBytes = exports.flexBytesAtOffset = exports.bytesEqual = exports.bytesAtOffset = exports.assertFlexBytes = exports.assertBytes = exports.getFolderSize = exports.getCollectionSize = void 0; | ||
var collection_1 = require("./collection"); | ||
@@ -49,3 +49,4 @@ Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } }); | ||
Object.defineProperty(exports, "getStampMaximumCapacityBytes", { enumerable: true, get: function () { return stamps_1.getStampMaximumCapacityBytes; } }); | ||
Object.defineProperty(exports, "getStampEffectiveBytes", { enumerable: true, get: function () { return stamps_1.getStampEffectiveBytes; } }); | ||
Object.defineProperty(exports, "getStampTtlSeconds", { enumerable: true, get: function () { return stamps_1.getStampTtlSeconds; } }); | ||
Object.defineProperty(exports, "getStampUsage", { enumerable: true, get: function () { return stamps_1.getStampUsage; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.getStampCostInBzz = exports.getStampCostInPlur = exports.getStampMaximumCapacityBytes = exports.getStampUsage = void 0; | ||
exports.getDepthForCapacity = exports.getAmountForTtl = exports.getStampTtlSeconds = exports.getStampCostInBzz = exports.getStampCostInPlur = exports.getStampEffectiveBytes = exports.getStampMaximumCapacityBytes = exports.getStampUsage = void 0; | ||
/** | ||
@@ -27,2 +27,36 @@ * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth. | ||
/** | ||
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table | ||
*/ | ||
const utilisationRateMap = { | ||
22: 0.2867, | ||
23: 0.4956, | ||
24: 0.6433, | ||
25: 0.7478, | ||
26: 0.8217, | ||
27: 0.8739, | ||
28: 0.9108, | ||
29: 0.9369, | ||
30: 0.9554, | ||
31: 0.9685, | ||
32: 0.9777, | ||
33: 0.9842, | ||
34: 0.9889, | ||
}; | ||
/** | ||
* Utility function that calculates the effective volume of a postage batch based on its depth. | ||
* | ||
* Below 22 depth the effective volume is 0 | ||
* Above 34 it's always > 99% | ||
* | ||
* @returns {number} The effective volume of the postage batch in bytes. | ||
*/ | ||
function getStampEffectiveBytes(depth) { | ||
if (depth < 22) { | ||
return 0; | ||
} | ||
const utilRate = utilisationRateMap[depth] ?? 0.99; | ||
return getStampMaximumCapacityBytes(depth) * utilRate; | ||
} | ||
exports.getStampEffectiveBytes = getStampEffectiveBytes; | ||
/** | ||
* Utility function that calculates the cost of a postage batch based on its depth and amount. | ||
@@ -29,0 +63,0 @@ * |
@@ -9,2 +9,2 @@ export { getCollectionSize } from "./collection.js"; | ||
export { makeMaxTarget } from "./pss.js"; | ||
export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js"; | ||
export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampEffectiveBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js"; |
@@ -22,2 +22,35 @@ /** | ||
/** | ||
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table | ||
*/ | ||
const utilisationRateMap = { | ||
22: 0.2867, | ||
23: 0.4956, | ||
24: 0.6433, | ||
25: 0.7478, | ||
26: 0.8217, | ||
27: 0.8739, | ||
28: 0.9108, | ||
29: 0.9369, | ||
30: 0.9554, | ||
31: 0.9685, | ||
32: 0.9777, | ||
33: 0.9842, | ||
34: 0.9889 | ||
}; | ||
/** | ||
* Utility function that calculates the effective volume of a postage batch based on its depth. | ||
* | ||
* Below 22 depth the effective volume is 0 | ||
* Above 34 it's always > 99% | ||
* | ||
* @returns {number} The effective volume of the postage batch in bytes. | ||
*/ | ||
export function getStampEffectiveBytes(depth) { | ||
if (depth < 22) { | ||
return 0; | ||
} | ||
const utilRate = utilisationRateMap[depth] ?? 0.99; | ||
return getStampMaximumCapacityBytes(depth) * utilRate; | ||
} | ||
/** | ||
* Utility function that calculates the cost of a postage batch based on its depth and amount. | ||
@@ -24,0 +57,0 @@ * |
@@ -9,2 +9,2 @@ export { getCollectionSize } from './collection'; | ||
export { makeMaxTarget } from './pss'; | ||
export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage, } from './stamps'; | ||
export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampEffectiveBytes, getStampTtlSeconds, getStampUsage, } from './stamps'; |
@@ -19,2 +19,11 @@ import { NumberString } from '../types'; | ||
/** | ||
* Utility function that calculates the effective volume of a postage batch based on its depth. | ||
* | ||
* Below 22 depth the effective volume is 0 | ||
* Above 34 it's always > 99% | ||
* | ||
* @returns {number} The effective volume of the postage batch in bytes. | ||
*/ | ||
export declare function getStampEffectiveBytes(depth: number): number; | ||
/** | ||
* Utility function that calculates the cost of a postage batch based on its depth and amount. | ||
@@ -21,0 +30,0 @@ * |
{ | ||
"name": "@ethersphere/bee-js", | ||
"version": "6.6.0", | ||
"version": "6.7.0", | ||
"description": "Javascript client for Bee", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
2027683
14374