@ethersphere/bee-js 6.6.0 → 6.7.0

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.
@@ -6,4 +6,4 @@ export { ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeEthAddress, m
6
6
  export { isNodeReadable, isReadable, isReadableStream, normalizeToReadableStream, readableNodeToWeb, readableWebToNode } from "./stream.js";
7
7
  export { keccak256Hash } from "./hash.js";
8
8
  export { makeMaxTarget } from "./pss.js";
9
- export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js";
9
+ export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampEffectiveBytes, getStampTtlSeconds, getStampUsage } from "./stamps.js";
@@ -18,6 +18,39 @@ export function getStampUsage(utilization, depth, bucketDepth) {
18
18
  export function getStampMaximumCapacityBytes(depth) {
19
19
  return 2 ** depth * 4096;
20
20
  }
21
+ /**
22
+ * Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
23
+ */
24
+ const utilisationRateMap = {
25
+ 22: 0.2867,
26
+ 23: 0.4956,
27
+ 24: 0.6433,
28
+ 25: 0.7478,
29
+ 26: 0.8217,
30
+ 27: 0.8739,
31
+ 28: 0.9108,
32
+ 29: 0.9369,
33
+ 30: 0.9554,
34
+ 31: 0.9685,
35
+ 32: 0.9777,
36
+ 33: 0.9842,
37
+ 34: 0.9889
38
+ };
39
+ /**
40
+ * Utility function that calculates the effective volume of a postage batch based on its depth.
41
+ *
42
+ * Below 22 depth the effective volume is 0
43
+ * Above 34 it's always > 99%
44
+ *
45
+ * @returns {number} The effective volume of the postage batch in bytes.
46
+ */
47
+ export function getStampEffectiveBytes(depth) {
48
+ if (depth < 22) {
49
+ return 0;
50
+ }
51
+ const utilRate = utilisationRateMap[depth] ?? 0.99;
52
+ return getStampMaximumCapacityBytes(depth) * utilRate;
53
+ }
21
54
  /**
22
55
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
23
56
  *
@@ -6,4 +6,4 @@ export { EthAddress, ethToSwarmAddress, fromLittleEndian, isHexEthAddress, makeE
6
6
  export { isNodeReadable, isReadable, isReadableStream, normalizeToReadableStream, readableNodeToWeb, readableWebToNode, } from './stream';
7
7
  export { keccak256Hash } from './hash';
8
8
  export { makeMaxTarget } from './pss';
9
- export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampTtlSeconds, getStampUsage, } from './stamps';
9
+ export { getAmountForTtl, getDepthForCapacity, getStampCostInBzz, getStampCostInPlur, getStampMaximumCapacityBytes, getStampEffectiveBytes, getStampTtlSeconds, getStampUsage, } from './stamps';
@@ -15,6 +15,15 @@ export declare function getStampUsage(utilization: number, depth: number, bucket
15
15
  * @returns {number} The maximum capacity of the postage batch in bytes.
16
16
  */
17
17
  export declare function getStampMaximumCapacityBytes(depth: number): number;
18
+ /**
19
+ * Utility function that calculates the effective volume of a postage batch based on its depth.
20
+ *
21
+ * Below 22 depth the effective volume is 0
22
+ * Above 34 it's always > 99%
23
+ *
24
+ * @returns {number} The effective volume of the postage batch in bytes.
25
+ */
26
+ export declare function getStampEffectiveBytes(depth: number): number;
18
27
  /**
19
28
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
20
29
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "6.6.0",
3
+ "version": "6.7.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",