@ocap/tx-protocols 1.13.63 → 1.13.64

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.
@@ -11,7 +11,7 @@ const debug = require('debug')(`${require('../../../package.json').name}:deposit
11
11
 
12
12
  const VerifySigners = require('../rollup/pipes/verify-signers');
13
13
  const VerifyPaused = require('../rollup/pipes/verify-paused');
14
- const { applyTokenUpdates, getTxFee, getRewardLocker } = require('../../util');
14
+ const { applyTokenUpdates, getTxFee, getBNSum, getRewardLocker } = require('../../util');
15
15
 
16
16
  const schema = Joi.object({
17
17
  token: Joi.tokenInputSchema.required(),
@@ -138,15 +138,15 @@ runner.use((context, next) => {
138
138
  const { itx, rollupState, tokenState } = context;
139
139
  const { depositFeeRate, maxDepositFee, minDepositFee } = rollupState;
140
140
 
141
- context.txFee = getTxFee({
141
+ const { reward } = getTxFee({
142
142
  amount: itx.token.value,
143
143
  feeRate: depositFeeRate,
144
144
  maxFee: maxDepositFee,
145
145
  minFee: minDepositFee,
146
146
  });
147
147
 
148
- if (new BN(itx.actualFee).lt(new BN(context.txFee.reward))) {
149
- const expected = fromUnitToToken(context.txFee.reward, tokenState.decimal);
148
+ if (new BN(itx.actualFee).lt(new BN(reward))) {
149
+ const expected = fromUnitToToken(reward, tokenState.decimal);
150
150
  const actual = fromUnitToToken(itx.actualFee, tokenState.decimal);
151
151
  return next(new Error('INVALID_TX', `itx.actualFee too low, expect at least ${expected}, got ${actual}`));
152
152
  }
@@ -162,12 +162,16 @@ runner.use(pipes.VerifyAccountMigration({ signerKey: 'signerStates', senderKey:
162
162
  // 8. update state: the token minting is done when deposit finalized in rollup-block
163
163
  runner.use(
164
164
  async (context, next) => {
165
- const { tx, itx, txFee, statedb, senderState, stakeState, stakeAddress, lockerState, lockerAddress } = context;
165
+ const { tx, itx, statedb, senderState, stakeState, stakeAddress, lockerState, lockerAddress } = context;
166
166
 
167
- const stakeUpdates = applyTokenUpdates([{ address: itx.token.address, value: txFee.total }], stakeState, 'sub');
168
- const senderUpdates = applyTokenUpdates([{ address: itx.token.address, value: txFee.user }], senderState, 'add');
167
+ const user = itx.token.value;
168
+ const fee = itx.actualFee;
169
+ const total = getBNSum(user, fee);
170
+
171
+ const stakeUpdates = applyTokenUpdates([{ address: itx.token.address, value: total }], stakeState, 'sub');
172
+ const senderUpdates = applyTokenUpdates([{ address: itx.token.address, value: user }], senderState, 'add');
169
173
  const lockerUpdates = applyTokenUpdates(
170
- [{ address: itx.token.address, value: txFee.reward }],
174
+ [{ address: itx.token.address, value: fee }],
171
175
  lockerState || { tokens: {} },
172
176
  'add'
173
177
  );
@@ -218,11 +222,11 @@ runner.use(
218
222
 
219
223
  context.updatedAccounts = [
220
224
  // stake for tx proposer is decreased
221
- { address: stakeAddress, token: itx.token.address, delta: `-${txFee.total}`, action: 'unlock' },
225
+ { address: stakeAddress, token: itx.token.address, delta: `-${total}`, action: 'unlock' },
222
226
  // mint to depositor from stake
223
- { address: senderState.address, token: itx.token.address, delta: txFee.user, action: 'unlock' },
224
- // block reward is locked for later claiming
225
- { address: lockerAddress, token: itx.token.address, delta: txFee.reward, action: 'pending' },
227
+ { address: senderState.address, token: itx.token.address, delta: user, action: 'unlock' },
228
+ // tx fee is locked for later claiming
229
+ { address: lockerAddress, token: itx.token.address, delta: fee, action: 'pending' },
226
230
  ];
227
231
 
228
232
  debug('deposit-token-v2', itx);
@@ -99,15 +99,15 @@ runner.use((context, next) => {
99
99
 
100
100
  const isFixedFee = new BN(itx.maxFee).isZero();
101
101
  if (isFixedFee) {
102
- context.txFee = getTxFee({
102
+ const { reward } = getTxFee({
103
103
  amount: itx.token.value,
104
104
  feeRate: withdrawFeeRate,
105
105
  maxFee: maxWithdrawFee,
106
106
  minFee: minWithdrawFee,
107
107
  });
108
108
 
109
- if (new BN(itx.actualFee).lt(new BN(context.txFee.reward))) {
110
- const expected = fromUnitToToken(context.txFee.reward, tokenState.decimal);
109
+ if (new BN(itx.actualFee).lt(new BN(reward))) {
110
+ const expected = fromUnitToToken(reward, tokenState.decimal);
111
111
  const actual = fromUnitToToken(itx.actualFee, tokenState.decimal);
112
112
  return next(new Error('INVALID_TX', `itx.actualFee too low, expect at least ${expected}, got ${actual}`));
113
113
  }
package/lib/util.js CHANGED
@@ -165,7 +165,7 @@ const splitTxFee = ({ total, shares = {}, stringify = true }) => {
165
165
 
166
166
  const getRewardLocker = (rollupAddress) => toStakeAddress(rollupAddress, rollupAddress);
167
167
  const getBNSum = (...args) => flattenDeep(args).reduce((sum, x) => sum.add(new BN(x)), new BN(0)).toString(10); // prettier-ignore
168
- const isFixedFee = (x) => new BN(x.tx.itxJson.maxFee).isZero();
168
+ const isFixedFee = (x) => !x.tx.itxJson.maxFee || new BN(x.tx.itxJson.maxFee).isZero();
169
169
 
170
170
  const ensureBlockReward = (rollupState, minReward, txStates) => {
171
171
  const { address, withdrawFeeRate, minWithdrawFee, maxWithdrawFee, tokenAddress } = rollupState;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.13.63",
6
+ "version": "1.13.64",
7
7
  "description": "Predefined tx pipeline sets to execute certain type of transactions",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -19,16 +19,16 @@
19
19
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",
20
20
  "license": "MIT",
21
21
  "dependencies": {
22
- "@arcblock/did": "1.13.63",
23
- "@arcblock/did-util": "1.13.63",
24
- "@ocap/asset": "1.13.63",
25
- "@ocap/mcrypto": "1.13.63",
26
- "@ocap/merkle-tree": "1.13.63",
27
- "@ocap/message": "1.13.63",
28
- "@ocap/state": "1.13.63",
29
- "@ocap/tx-pipeline": "1.13.63",
30
- "@ocap/util": "1.13.63",
31
- "@ocap/wallet": "1.13.63",
22
+ "@arcblock/did": "1.13.64",
23
+ "@arcblock/did-util": "1.13.64",
24
+ "@ocap/asset": "1.13.64",
25
+ "@ocap/mcrypto": "1.13.64",
26
+ "@ocap/merkle-tree": "1.13.64",
27
+ "@ocap/message": "1.13.64",
28
+ "@ocap/state": "1.13.64",
29
+ "@ocap/tx-pipeline": "1.13.64",
30
+ "@ocap/util": "1.13.64",
31
+ "@ocap/wallet": "1.13.64",
32
32
  "debug": "^4.3.2",
33
33
  "empty-value": "^1.0.1",
34
34
  "lodash": "^4.17.21",
@@ -41,5 +41,5 @@
41
41
  "devDependencies": {
42
42
  "jest": "^27.3.1"
43
43
  },
44
- "gitHead": "7e40f22f90f4f5ac08fde3d4d3b7194aa792c95d"
44
+ "gitHead": "49c94d9fd5f12ec63c34ad609d041a92f68322a8"
45
45
  }