@ocap/state 1.22.3 → 1.23.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.
Files changed (2) hide show
  1. package/lib/states/tx.js +34 -26
  2. package/package.json +9 -9
package/lib/states/tx.js CHANGED
@@ -341,25 +341,24 @@ const getCreateTokenReceipts = (tx) => {
341
341
  };
342
342
 
343
343
  const getMintTokenReceipts = (tx, ctx) => {
344
- const { reserveAddress, tokenAddress, owner } = ctx.tokenFactoryState;
345
- const hasFee = ctx.reserveFee && new BN(ctx.reserveFee).gt(ZERO);
344
+ const { inputChanges, tokenFactoryState } = ctx;
345
+ const { reserveAddress, tokenAddress, owner } = tokenFactoryState;
346
+ const hasFee = new BN(ctx.reserveFee || '0').gt(ZERO);
346
347
 
347
- return [
348
- {
349
- address: tx.from,
348
+ const inputReceipts = inputChanges.map((input) => {
349
+ return {
350
+ address: input.address,
350
351
  changes: [
351
352
  {
352
353
  target: reserveAddress,
353
354
  action: 'swap',
354
- value: `-${ctx.reserveAmount}`,
355
+ value: input.delta,
355
356
  },
356
- hasFee && {
357
- target: reserveAddress,
358
- action: 'fee',
359
- value: `-${ctx.reserveFee}`,
360
- },
361
- ].filter(Boolean),
362
- },
357
+ ],
358
+ };
359
+ });
360
+
361
+ return inputReceipts.concat([
363
362
  {
364
363
  address: tx.itxJson.receiver,
365
364
  changes: [
@@ -374,30 +373,39 @@ const getMintTokenReceipts = (tx, ctx) => {
374
373
  address: owner,
375
374
  changes: hasFee ? [{ target: reserveAddress, action: 'fee', value: `${ctx.reserveFee}` }] : [],
376
375
  },
377
- ];
376
+ ]);
378
377
  };
379
378
 
380
379
  const getBurnTokenReceipts = (tx, ctx) => {
381
- const { reserveAddress, tokenAddress, owner } = ctx.tokenFactoryState;
382
- const hasFee = ctx.reserveFee && new BN(ctx.reserveFee).gt(ZERO);
380
+ const { inputChanges, tokenFactoryState } = ctx;
381
+ const { reserveAddress, tokenAddress, owner } = tokenFactoryState;
383
382
 
384
- return [
385
- {
386
- address: tx.from,
383
+ const fee = new BN(ctx.reserveFee || '0');
384
+ const receiveAmount = new BN(ctx.reserveAmount).sub(fee).toString();
385
+
386
+ const inputReceipts = inputChanges.map((input) => {
387
+ return {
388
+ address: input.address,
387
389
  changes: [
388
- { target: tokenAddress, action: 'burn', value: `-${tx.itxJson.amount}` },
389
- hasFee && { target: reserveAddress, action: 'fee', value: `-${ctx.reserveFee}` },
390
- ].filter(Boolean),
391
- },
390
+ {
391
+ target: tokenAddress,
392
+ action: 'burn',
393
+ value: input.delta,
394
+ },
395
+ ],
396
+ };
397
+ });
398
+
399
+ return inputReceipts.concat([
392
400
  {
393
401
  address: tx.itxJson.receiver,
394
- changes: [{ target: reserveAddress, action: 'swap', value: `${ctx.reserveAmount}` }],
402
+ changes: [{ target: reserveAddress, action: 'swap', value: receiveAmount }],
395
403
  },
396
404
  {
397
405
  address: owner,
398
- changes: hasFee ? [{ target: reserveAddress, action: 'fee', value: `${ctx.reserveFee}` }] : [],
406
+ changes: fee.gt(ZERO) ? [{ target: reserveAddress, action: 'fee', value: `${ctx.reserveFee}` }] : [],
399
407
  },
400
- ];
408
+ ]);
401
409
  };
402
410
 
403
411
  // Following only exist for legacy support purpose
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.22.3",
6
+ "version": "1.23.0",
7
7
  "description": "",
8
8
  "main": "lib/index.js",
9
9
  "files": [
@@ -12,18 +12,18 @@
12
12
  "dependencies": {
13
13
  "bloom-filters": "^1.3.9",
14
14
  "lodash": "^4.17.21",
15
- "@arcblock/did": "1.22.3",
16
- "@arcblock/validator": "1.22.3",
17
- "@ocap/contract": "1.22.3",
18
- "@ocap/mcrypto": "1.22.3",
19
- "@ocap/message": "1.22.3",
20
- "@ocap/util": "1.22.3",
21
- "@ocap/wallet": "1.22.3"
15
+ "@arcblock/did": "1.23.0",
16
+ "@arcblock/validator": "1.23.0",
17
+ "@ocap/contract": "1.23.0",
18
+ "@ocap/mcrypto": "1.23.0",
19
+ "@ocap/util": "1.23.0",
20
+ "@ocap/wallet": "1.23.0",
21
+ "@ocap/message": "1.23.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "jest": "^29.7.0",
25
25
  "start-server-and-test": "^1.14.0",
26
- "@ocap/e2e-test": "1.22.3"
26
+ "@ocap/e2e-test": "1.23.0"
27
27
  },
28
28
  "keywords": [],
29
29
  "author": "wangshijun <wangshijun2010@gmail.com> (http://github.com/wangshijun)",