@upcoming/bee-js 9.9.0 → 9.9.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/dist/cjs/bee.js CHANGED
@@ -1231,26 +1231,28 @@ class Bee {
1231
1231
  const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
1232
1232
  const chainState = await this.getChainState(options);
1233
1233
  const depthDelta = depth - batch.depth;
1234
- const multiplier = depthDelta === 0 ? 1n : 2n ** BigInt(depthDelta);
1235
- const additionalAmount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1236
- const targetAmount = duration.isZero()
1237
- ? BigInt(batch.amount) * multiplier
1238
- : (BigInt(batch.amount) + additionalAmount) * multiplier;
1239
- const amountDelta = targetAmount - BigInt(batch.amount);
1234
+ const multiplier = depthDelta <= 0 ? 1n : 2n ** BigInt(depthDelta);
1235
+ const blockTime = this.network === 'gnosis' ? 5 : 15;
1236
+ const additionalAmount = (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, blockTime);
1237
+ const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, blockTime);
1238
+ const targetAmount = duration.isZero() ? currentAmount * multiplier : currentAmount + additionalAmount * multiplier;
1239
+ const amountDelta = targetAmount - currentAmount;
1240
1240
  const transactionId = await this.topUpBatch(batch.batchID, amountDelta, options);
1241
- if (depthDelta) {
1241
+ if (depthDelta > 0) {
1242
1242
  return this.diluteBatch(batch.batchID, depth, options);
1243
1243
  }
1244
1244
  return transactionId;
1245
1245
  }
1246
1246
  async extendStorageSize(postageBatchId, size, options, encryption, erasureCodeLevel) {
1247
+ const chainState = await this.getChainState(options);
1247
1248
  const batch = await this.getPostageBatch(postageBatchId, options);
1248
1249
  const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
1249
1250
  const delta = depth - batch.depth;
1250
1251
  if (delta <= 0) {
1251
1252
  throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
1252
1253
  }
1253
- await this.topUpBatch(batch.batchID, BigInt(batch.amount) * (2n ** BigInt(delta) - 1n) + 1n, options);
1254
+ const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1255
+ await this.topUpBatch(batch.batchID, currentAmount * (2n ** BigInt(delta) - 1n) + 1n, options);
1254
1256
  return this.diluteBatch(batch.batchID, depth, options);
1255
1257
  }
1256
1258
  async extendStorageDuration(postageBatchId, duration, options) {
@@ -1262,23 +1264,25 @@ class Bee {
1262
1264
  async getExtensionCost(postageBatchId, size, duration, options, encryption, erasureCodeLevel) {
1263
1265
  const batch = await this.getPostageBatch(postageBatchId, options);
1264
1266
  const chainState = await this.getChainState(options);
1265
- const amount = duration.isZero()
1266
- ? 0n
1267
- : (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1267
+ const blockTime = this.network === 'gnosis' ? 5 : 15;
1268
+ const amount = duration.isZero() ? 0n : (0, stamps_1.getAmountForDuration)(duration, chainState.currentPrice, blockTime);
1268
1269
  const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
1269
- const currentCost = (0, stamps_1.getStampCost)(batch.depth, batch.amount);
1270
- const newCost = (0, stamps_1.getStampCost)(depth, BigInt(batch.amount) + amount);
1270
+ const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, blockTime);
1271
+ const currentCost = (0, stamps_1.getStampCost)(batch.depth, currentAmount);
1272
+ const newCost = (0, stamps_1.getStampCost)(depth, currentAmount + amount);
1271
1273
  return newCost.minus(currentCost);
1272
1274
  }
1273
1275
  async getSizeExtensionCost(postageBatchId, size, options, encryption, erasureCodeLevel) {
1274
1276
  const batch = await this.getPostageBatch(postageBatchId, options);
1277
+ const chainState = await this.getChainState(options);
1275
1278
  const depth = (0, stamps_1.getDepthForSize)(size, encryption, erasureCodeLevel);
1276
1279
  const delta = depth - batch.depth;
1277
1280
  if (delta <= 0) {
1278
1281
  throw new error_1.BeeArgumentError('New depth has to be greater than the original depth', depth);
1279
1282
  }
1280
- const currentCost = (0, stamps_1.getStampCost)(batch.depth, batch.amount);
1281
- const newCost = (0, stamps_1.getStampCost)(depth, batch.amount);
1283
+ const currentAmount = (0, stamps_1.getAmountForDuration)(batch.duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15);
1284
+ const currentCost = (0, stamps_1.getStampCost)(batch.depth, currentAmount);
1285
+ const newCost = (0, stamps_1.getStampCost)(depth, currentAmount);
1282
1286
  return newCost.minus(currentCost);
1283
1287
  }
1284
1288
  async getDurationExtensionCost(postageBatchId, duration, options) {