@ethersphere/bee-js 9.1.1 → 9.2.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.
- package/README.md +2 -0
- package/dist/cjs/bee.js +2 -2
- package/dist/cjs/utils/size.js +6 -0
- package/dist/cjs/utils/stamps.js +34 -34
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +2 -2
- package/dist/mjs/utils/size.js +6 -0
- package/dist/mjs/utils/stamps.js +17 -23
- package/dist/types/utils/size.d.ts +2 -0
- package/package.json +1 -1
package/dist/mjs/bee.js
CHANGED
|
@@ -1136,7 +1136,7 @@ export class Bee {
|
|
|
1136
1136
|
throw new BeeArgumentError(`Depth has to be between ${STAMPS_DEPTH_MIN}..${STAMPS_DEPTH_MAX}`, depth);
|
|
1137
1137
|
}
|
|
1138
1138
|
const chainState = await this.getChainState();
|
|
1139
|
-
const minimumAmount = BigInt(chainState.currentPrice) * 17280n;
|
|
1139
|
+
const minimumAmount = BigInt(chainState.currentPrice) * 17280n + 1n;
|
|
1140
1140
|
if (BigInt(amountString) < minimumAmount) {
|
|
1141
1141
|
throw new BeeArgumentError(`Amount has to be at least ${minimumAmount} (1 day at current price ${chainState.currentPrice})`, amountString);
|
|
1142
1142
|
}
|
|
@@ -1168,7 +1168,7 @@ export class Bee {
|
|
|
1168
1168
|
if (delta <= 0) {
|
|
1169
1169
|
throw new BeeArgumentError('New depth has to be greater than the original depth', depth);
|
|
1170
1170
|
}
|
|
1171
|
-
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1), options);
|
|
1171
|
+
await this.topUpBatch(batch.batchID, BigInt(batch.amount) * 2n ** BigInt(delta - 1) + 1n, options);
|
|
1172
1172
|
return this.diluteBatch(batch.batchID, depth, options);
|
|
1173
1173
|
}
|
|
1174
1174
|
async extendStorageDuration(postageBatchId, duration, options) {
|
package/dist/mjs/utils/size.js
CHANGED
|
@@ -16,6 +16,12 @@ export class Size {
|
|
|
16
16
|
static fromBytes(bytes) {
|
|
17
17
|
return new Size(bytes);
|
|
18
18
|
}
|
|
19
|
+
static fromKilobytes(kilobytes) {
|
|
20
|
+
return new Size(kilobytes * 1000);
|
|
21
|
+
}
|
|
22
|
+
static fromMegabytes(megabytes) {
|
|
23
|
+
return new Size(megabytes * 1000 * 1000);
|
|
24
|
+
}
|
|
19
25
|
static fromGigabytes(gigabytes) {
|
|
20
26
|
return new Size(gigabytes * 1000 * 1000 * 1000);
|
|
21
27
|
}
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -3,6 +3,7 @@ import { Bytes } from "./bytes.js";
|
|
|
3
3
|
import { Duration } from "./duration.js";
|
|
4
4
|
import { BZZ } from "./tokens.js";
|
|
5
5
|
import { asNumberString } from "./type.js";
|
|
6
|
+
const MAX_UTILIZATION = 0.9;
|
|
6
7
|
/**
|
|
7
8
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
8
9
|
*
|
|
@@ -25,23 +26,9 @@ export function getStampTheoreticalBytes(depth) {
|
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
27
28
|
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
29
|
+
* Optimised for encrypted, medium erasure coding
|
|
28
30
|
*/
|
|
29
|
-
const
|
|
30
|
-
22: 0.2867,
|
|
31
|
-
23: 0.4956,
|
|
32
|
-
24: 0.6433,
|
|
33
|
-
25: 0.7478,
|
|
34
|
-
26: 0.8217,
|
|
35
|
-
27: 0.8739,
|
|
36
|
-
28: 0.9108,
|
|
37
|
-
29: 0.9369,
|
|
38
|
-
30: 0.9554,
|
|
39
|
-
31: 0.9685,
|
|
40
|
-
32: 0.9777,
|
|
41
|
-
33: 0.9842,
|
|
42
|
-
34: 0.9889
|
|
43
|
-
};
|
|
44
|
-
const effectiveSizeBreakpoints = [[22, 4.93], [23, 17.03], [24, 44.21], [25, 102.78], [26, 225.87], [27, 480.44], [28, 1001.44], [29, 2060.27], [30, 4201.9], [31, 8519.02], [32, 17199.89], [33, 34628.46]];
|
|
31
|
+
const effectiveSizeBreakpoints = [[17, 0.00004089], [18, 0.00609], [19, 0.10249], [20, 0.62891], [21, 2.38], [22, 7.07], [23, 18.24], [24, 43.04], [25, 96.5], [26, 208.52], [27, 435.98], [28, 908.81], [29, 1870], [30, 3810], [31, 7730], [32, 15610], [33, 31430], [34, 63150]];
|
|
45
32
|
/**
|
|
46
33
|
* Utility function that calculates the effective size of a postage batch based on its depth.
|
|
47
34
|
*
|
|
@@ -51,15 +38,22 @@ const effectiveSizeBreakpoints = [[22, 4.93], [23, 17.03], [24, 44.21], [25, 102
|
|
|
51
38
|
* @returns {number} The effective size of the postage batch in bytes.
|
|
52
39
|
*/
|
|
53
40
|
export function getStampEffectiveBytes(depth) {
|
|
54
|
-
if (depth <
|
|
41
|
+
if (depth < 17) {
|
|
55
42
|
return 0;
|
|
56
43
|
}
|
|
57
|
-
const
|
|
58
|
-
|
|
44
|
+
const breakpoint = effectiveSizeBreakpoints.find(([d, size]) => {
|
|
45
|
+
if (depth === d) {
|
|
46
|
+
return size;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
if (breakpoint) {
|
|
50
|
+
return breakpoint[1] * 1000 * 1000 * 1000;
|
|
51
|
+
}
|
|
52
|
+
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
59
53
|
}
|
|
60
54
|
export function getStampEffectiveBytesBreakpoints() {
|
|
61
55
|
const map = new Map();
|
|
62
|
-
for (let i =
|
|
56
|
+
for (let i = 17; i < 35; i++) {
|
|
63
57
|
map.set(i, getStampEffectiveBytes(i));
|
|
64
58
|
}
|
|
65
59
|
return map;
|
|
@@ -89,7 +83,7 @@ export function getStampDuration(amount, pricePerBlock, blockTime) {
|
|
|
89
83
|
* @param blockTime The block time in seconds.
|
|
90
84
|
*/
|
|
91
85
|
export function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
92
|
-
return BigInt(duration.toSeconds()) / BigInt(blockTime) * BigInt(pricePerBlock);
|
|
86
|
+
return BigInt(duration.toSeconds()) / BigInt(blockTime) * BigInt(pricePerBlock) + 1n;
|
|
93
87
|
}
|
|
94
88
|
/**
|
|
95
89
|
* Utility function that calculates the depth required for a postage batch to achieve the specified effective size
|
|
@@ -99,11 +93,11 @@ export function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
|
99
93
|
*/
|
|
100
94
|
export function getDepthForSize(size) {
|
|
101
95
|
for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
|
|
102
|
-
if (size.
|
|
96
|
+
if (size.toBytes() <= sizeBreakpoint * 1000 * 1000 * 1000) {
|
|
103
97
|
return depth;
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
|
-
return
|
|
100
|
+
return 35;
|
|
107
101
|
}
|
|
108
102
|
export function convertEnvelopeToMarshaledStamp(envelope) {
|
|
109
103
|
return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
|
|
@@ -9,6 +9,8 @@ export declare class Size {
|
|
|
9
9
|
private bytes;
|
|
10
10
|
private constructor();
|
|
11
11
|
static fromBytes(bytes: number): Size;
|
|
12
|
+
static fromKilobytes(kilobytes: number): Size;
|
|
13
|
+
static fromMegabytes(megabytes: number): Size;
|
|
12
14
|
static fromGigabytes(gigabytes: number): Size;
|
|
13
15
|
toBytes(): number;
|
|
14
16
|
toGigabytes(): number;
|