@ocap/tx-protocols 1.13.74 → 1.13.78

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.
@@ -101,7 +101,7 @@ runner.use((context, next) => {
101
101
  return next(new Error('INVALID_STAKE_STATE', `Staking not locked for deposit: ${stakeState.address}`));
102
102
  }
103
103
 
104
- const depositAmount = new BN(itx.token.value);
104
+ const depositAmount = new BN(itx.token.value).add(new BN(itx.actualFee));
105
105
  const minDepositAmount = new BN(rollupState.minDepositAmount);
106
106
  const maxDepositAmount = new BN(rollupState.maxDepositAmount);
107
107
  if (depositAmount.lt(minDepositAmount)) {
package/lib/util.js CHANGED
@@ -197,20 +197,22 @@ const ensureBlockReward = (rollupState, minReward, txStates) => {
197
197
  const totalMissingFee = minRequiredReward.sub(totalFixedFee);
198
198
 
199
199
  // 2. calculate actual reward for each dynamic reward tx, mark tx to be updated
200
+ const minTxFee = minRequiredReward.div(new BN(txStates.length));
200
201
  const changes = { stake: [], account: [] };
201
202
  dynamicFeeTxs.forEach((x) => {
202
203
  const maxFee = new BN(x.tx.itxJson.maxFee);
204
+ const defaults = getTxFee({
205
+ amount: x.tx.itxJson.token.value,
206
+ feeRate: withdrawFeeRate,
207
+ maxFee: maxWithdrawFee,
208
+ minFee: minWithdrawFee,
209
+ stringify: false,
210
+ });
211
+
203
212
  let actualFee = new BN(0);
204
213
  // If totalMissingFee is less than 0, then the tx will be charged for fixedFee
205
214
  if (totalMissingFee.lt(ZERO)) {
206
- const fee = getTxFee({
207
- amount: x.tx.itxJson.token.value,
208
- feeRate: withdrawFeeRate,
209
- maxFee: maxWithdrawFee,
210
- minFee: minWithdrawFee,
211
- stringify: false,
212
- });
213
- actualFee = fee.reward;
215
+ actualFee = defaults.reward;
214
216
  } else {
215
217
  // Else the tx is charged for a portion of totalMissingFee
216
218
  actualFee = totalMissingFee.mul(maxFee).div(totalDynamicFee);
@@ -220,6 +222,16 @@ const ensureBlockReward = (rollupState, minReward, txStates) => {
220
222
  throw new Error('NEGATIVE_ACTUAL_FEE', 'Got negative actualFee for tx, abort!');
221
223
  }
222
224
 
225
+ // If the actualFee is less than default fee, user will be charged the default fee
226
+ if (actualFee.lt(defaults.reward)) {
227
+ actualFee = defaults.reward;
228
+ }
229
+
230
+ // If the actualFee is less than minTxFee, user will be charged the minTxFee
231
+ if (actualFee.lt(minTxFee)) {
232
+ actualFee = minTxFee;
233
+ }
234
+
223
235
  // If the actualFee is less than the maxFee, user will have a refund
224
236
  if (actualFee.lt(maxFee)) {
225
237
  const refundFee = maxFee.sub(actualFee).toString(10);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.13.74",
6
+ "version": "1.13.78",
7
7
  "description": "Predefined tx pipeline sets to execute certain type of transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,17 +19,17 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@arcblock/did": "1.13.74",
23
- "@arcblock/did-util": "1.13.74",
24
- "@ocap/asset": "1.13.74",
25
- "@ocap/mcrypto": "1.13.74",
26
- "@ocap/merkle-tree": "1.13.74",
27
- "@ocap/message": "1.13.74",
28
- "@ocap/state": "1.13.74",
29
- "@ocap/tx-pipeline": "1.13.74",
30
- "@ocap/util": "1.13.74",
31
- "@ocap/validator": "1.13.74",
32
- "@ocap/wallet": "1.13.74",
22
+ "@arcblock/did": "1.13.78",
23
+ "@arcblock/did-util": "1.13.78",
24
+ "@ocap/asset": "1.13.78",
25
+ "@ocap/mcrypto": "1.13.78",
26
+ "@ocap/merkle-tree": "1.13.78",
27
+ "@ocap/message": "1.13.78",
28
+ "@ocap/state": "1.13.78",
29
+ "@ocap/tx-pipeline": "1.13.78",
30
+ "@ocap/util": "1.13.78",
31
+ "@ocap/validator": "1.13.78",
32
+ "@ocap/wallet": "1.13.78",
33
33
  "debug": "^4.3.2",
34
34
  "empty-value": "^1.0.1",
35
35
  "lodash": "^4.17.21",
@@ -42,5 +42,5 @@
42
42
  "devDependencies": {
43
43
  "jest": "^27.3.1"
44
44
  },
45
- "gitHead": "24531e4142d2dc888d6f6091d82d2f7e5abe22ae"
45
+ "gitHead": "427091e2d69b996a69c39ed7d55a999638728f02"
46
46
  }