@0xtorch/core 0.0.33 → 0.0.35
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/.DS_Store +0 -0
- package/_cjs/actions/index.js +5 -1
- package/_cjs/actions/index.js.map +1 -1
- package/_cjs/actions/utils/checkIfAccountActionsIsValid.js +60 -0
- package/_cjs/actions/utils/checkIfAccountActionsIsValid.js.map +1 -0
- package/_cjs/actions/utils/createEvidenceNoneAccountActions.js +6 -119
- package/_cjs/actions/utils/createEvidenceNoneAccountActions.js.map +1 -1
- package/_cjs/actions/utils/mergeSameAssetTransfers.js +121 -0
- package/_cjs/actions/utils/mergeSameAssetTransfers.js.map +1 -0
- package/_cjs/index.js +5 -3
- package/_cjs/index.js.map +1 -1
- package/_esm/actions/index.js +2 -0
- package/_esm/actions/index.js.map +1 -1
- package/_esm/actions/utils/checkIfAccountActionsIsValid.js +66 -0
- package/_esm/actions/utils/checkIfAccountActionsIsValid.js.map +1 -0
- package/_esm/actions/utils/createEvidenceNoneAccountActions.js +8 -128
- package/_esm/actions/utils/createEvidenceNoneAccountActions.js.map +1 -1
- package/_esm/actions/utils/mergeSameAssetTransfers.js +124 -0
- package/_esm/actions/utils/mergeSameAssetTransfers.js.map +1 -0
- package/_esm/index.js +1 -1
- package/_esm/index.js.map +1 -1
- package/_types/actions/index.d.ts +2 -0
- package/_types/actions/index.d.ts.map +1 -1
- package/_types/actions/utils/checkIfAccountActionsIsValid.d.ts +9 -0
- package/_types/actions/utils/checkIfAccountActionsIsValid.d.ts.map +1 -0
- package/_types/actions/utils/createEvidenceNoneAccountActions.d.ts.map +1 -1
- package/_types/actions/utils/mergeSameAssetTransfers.d.ts +3 -0
- package/_types/actions/utils/mergeSameAssetTransfers.d.ts.map +1 -0
- package/_types/index.d.ts +1 -1
- package/_types/index.d.ts.map +1 -1
- package/actions/.DS_Store +0 -0
- package/actions/index.ts +2 -0
- package/actions/utils/checkIfAccountActionsIsValid.ts +129 -0
- package/actions/utils/createEvidenceNoneAccountActions.ts +17 -170
- package/actions/utils/mergeSameAssetTransfers.ts +162 -0
- package/assets/.DS_Store +0 -0
- package/index.ts +2 -0
- package/package.json +1 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { absoluteValue, minus, plus } from '@0xtorch/big-decimal'
|
|
2
1
|
import type {
|
|
3
2
|
AccountAction,
|
|
4
3
|
AccountActionBuyCrypto,
|
|
@@ -8,7 +7,6 @@ import type {
|
|
|
8
7
|
AccountActionSwapNft,
|
|
9
8
|
AccountActionTrade,
|
|
10
9
|
NormalActionTransfer,
|
|
11
|
-
Transfer,
|
|
12
10
|
TransferCryptoCurrencyIn,
|
|
13
11
|
TransferCryptoCurrencyOut,
|
|
14
12
|
TransferFiatCurrencyIn,
|
|
@@ -18,6 +16,7 @@ import type {
|
|
|
18
16
|
TransferNftOut,
|
|
19
17
|
TransferOut,
|
|
20
18
|
} from '../types'
|
|
19
|
+
import { mergeSameAssetTransfers } from './mergeSameAssetTransfers'
|
|
21
20
|
|
|
22
21
|
type CreateEvidenceNoneAccountActionsParameters = {
|
|
23
22
|
readonly source: string
|
|
@@ -33,7 +32,10 @@ export const createEvidenceNoneAccountActions = ({
|
|
|
33
32
|
accountIdSet,
|
|
34
33
|
}: CreateEvidenceNoneAccountActionsParameters): readonly AccountAction[] => {
|
|
35
34
|
// transfer を asset , account id 毎に merge
|
|
36
|
-
const transferList =
|
|
35
|
+
const transferList = mergeSameAssetTransfers(
|
|
36
|
+
actionList.flatMap((action) => action.transfers),
|
|
37
|
+
accountIdSet,
|
|
38
|
+
)
|
|
37
39
|
|
|
38
40
|
// direction = none の transfer を move action に個別変換
|
|
39
41
|
const moveActionList = transferList
|
|
@@ -136,11 +138,15 @@ export const createEvidenceNoneAccountActions = ({
|
|
|
136
138
|
order,
|
|
137
139
|
}))
|
|
138
140
|
}
|
|
139
|
-
// in transfer asset 全て NFT
|
|
141
|
+
// in transfer asset 全て NFT , out transfer asset に NFT 含まない場合、 buy-nft action に変換
|
|
140
142
|
else if (
|
|
141
143
|
inOutTransferList
|
|
142
144
|
.filter((transfer) => transfer.direction === 'in')
|
|
143
|
-
.every((transfer) => transfer.asset.type === 'Nft')
|
|
145
|
+
.every((transfer) => transfer.asset.type === 'Nft') &&
|
|
146
|
+
inOutTransferList.filter(
|
|
147
|
+
(transfer) =>
|
|
148
|
+
transfer.direction === 'out' && transfer.asset.type === 'Nft',
|
|
149
|
+
).length === 0
|
|
144
150
|
) {
|
|
145
151
|
return [
|
|
146
152
|
...moveActionList,
|
|
@@ -172,11 +178,15 @@ export const createEvidenceNoneAccountActions = ({
|
|
|
172
178
|
order,
|
|
173
179
|
}))
|
|
174
180
|
}
|
|
175
|
-
// out transfer 全て NFT
|
|
181
|
+
// out transfer 全て NFT, in transfer に NFT を含まない場合、 sell-nft action に変換
|
|
176
182
|
else if (
|
|
177
183
|
inOutTransferList
|
|
178
184
|
.filter((transfer) => transfer.direction === 'out')
|
|
179
|
-
.every((transfer) => transfer.asset.type === 'Nft')
|
|
185
|
+
.every((transfer) => transfer.asset.type === 'Nft') &&
|
|
186
|
+
inOutTransferList.filter(
|
|
187
|
+
(transfer) =>
|
|
188
|
+
transfer.direction === 'in' && transfer.asset.type === 'Nft',
|
|
189
|
+
).length === 0
|
|
180
190
|
) {
|
|
181
191
|
return [
|
|
182
192
|
...moveActionList,
|
|
@@ -307,166 +317,3 @@ export const createEvidenceNoneAccountActions = ({
|
|
|
307
317
|
}))
|
|
308
318
|
}
|
|
309
319
|
}
|
|
310
|
-
|
|
311
|
-
const createTransferList = ({
|
|
312
|
-
actionList,
|
|
313
|
-
accountIdSet,
|
|
314
|
-
}: Pick<
|
|
315
|
-
CreateEvidenceNoneAccountActionsParameters,
|
|
316
|
-
'accountIdSet' | 'actionList'
|
|
317
|
-
>): readonly Transfer[] => {
|
|
318
|
-
const mut_transfers: (Transfer & { readonly key: string })[] = []
|
|
319
|
-
|
|
320
|
-
for (const transfer of actionList.flatMap((action) => action.transfers)) {
|
|
321
|
-
if (
|
|
322
|
-
(transfer.from === undefined || !accountIdSet.has(transfer.from)) &&
|
|
323
|
-
(transfer.to === undefined || !accountIdSet.has(transfer.to))
|
|
324
|
-
) {
|
|
325
|
-
continue
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
const transferKey = createTransferKey(transfer, accountIdSet)
|
|
329
|
-
const transferIndex = mut_transfers.findIndex(
|
|
330
|
-
({ key }) => key === transferKey,
|
|
331
|
-
)
|
|
332
|
-
|
|
333
|
-
if (transferIndex === -1) {
|
|
334
|
-
mut_transfers.push({
|
|
335
|
-
...transfer,
|
|
336
|
-
direction: createTransferDirection(transfer, accountIdSet),
|
|
337
|
-
key: transferKey,
|
|
338
|
-
})
|
|
339
|
-
} else {
|
|
340
|
-
const baseTransfer = mut_transfers[transferIndex]
|
|
341
|
-
// from=new-from/to=new-to の場合は加算
|
|
342
|
-
if (
|
|
343
|
-
baseTransfer.from === transfer.from &&
|
|
344
|
-
baseTransfer.to === transfer.to
|
|
345
|
-
) {
|
|
346
|
-
mut_transfers[transferIndex] = {
|
|
347
|
-
...baseTransfer,
|
|
348
|
-
amount: plus(baseTransfer.amount, transfer.amount),
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
// from=new-to/to=new-from の場合は減算
|
|
352
|
-
else if (
|
|
353
|
-
baseTransfer.from === transfer.to &&
|
|
354
|
-
baseTransfer.to === transfer.from
|
|
355
|
-
) {
|
|
356
|
-
mut_transfers[transferIndex] = {
|
|
357
|
-
...baseTransfer,
|
|
358
|
-
amount: minus(baseTransfer.amount, transfer.amount),
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
// from=new-from/to!=new-to の場合は to を undefined にして加算
|
|
362
|
-
else if (
|
|
363
|
-
baseTransfer.from === transfer.from &&
|
|
364
|
-
baseTransfer.to !== transfer.to
|
|
365
|
-
) {
|
|
366
|
-
mut_transfers[transferIndex] = {
|
|
367
|
-
...baseTransfer,
|
|
368
|
-
to: undefined,
|
|
369
|
-
amount: plus(baseTransfer.amount, transfer.amount),
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
// from!=new-from/to=new-to の場合は from を undefined にして加算
|
|
373
|
-
else if (
|
|
374
|
-
baseTransfer.from !== transfer.from &&
|
|
375
|
-
baseTransfer.to === transfer.to
|
|
376
|
-
) {
|
|
377
|
-
mut_transfers[transferIndex] = {
|
|
378
|
-
...baseTransfer,
|
|
379
|
-
from: undefined,
|
|
380
|
-
amount: plus(baseTransfer.amount, transfer.amount),
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
// from=new-to/to!=new-from の場合は to を undefined にして減算
|
|
384
|
-
else if (
|
|
385
|
-
baseTransfer.from === transfer.to &&
|
|
386
|
-
baseTransfer.to !== transfer.from
|
|
387
|
-
) {
|
|
388
|
-
mut_transfers[transferIndex] = {
|
|
389
|
-
...baseTransfer,
|
|
390
|
-
to: undefined,
|
|
391
|
-
amount: minus(baseTransfer.amount, transfer.amount),
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
// from!=new-to/to=new-from の場合は from を undefined にして減算
|
|
395
|
-
else if (
|
|
396
|
-
baseTransfer.from !== transfer.to &&
|
|
397
|
-
baseTransfer.to === transfer.from
|
|
398
|
-
) {
|
|
399
|
-
mut_transfers[transferIndex] = {
|
|
400
|
-
...baseTransfer,
|
|
401
|
-
from: undefined,
|
|
402
|
-
amount: minus(baseTransfer.amount, transfer.amount),
|
|
403
|
-
}
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
// amount がマイナスの場合は from/to , direction を逆にして amount をプラスにする
|
|
409
|
-
return mut_transfers
|
|
410
|
-
.filter((transfer) => transfer.amount.value !== 0n)
|
|
411
|
-
.map((transfer) =>
|
|
412
|
-
transfer.amount.value < 0
|
|
413
|
-
? {
|
|
414
|
-
...transfer,
|
|
415
|
-
from: transfer.to,
|
|
416
|
-
to: transfer.from,
|
|
417
|
-
direction: reverseTransferDirection(transfer.direction),
|
|
418
|
-
amount: absoluteValue(transfer.amount),
|
|
419
|
-
}
|
|
420
|
-
: transfer,
|
|
421
|
-
)
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
const createTransferDirection = (
|
|
425
|
-
transfer: Transfer,
|
|
426
|
-
accountIdSet: Set<string>,
|
|
427
|
-
) => {
|
|
428
|
-
if (
|
|
429
|
-
transfer.from !== undefined &&
|
|
430
|
-
accountIdSet.has(transfer.from) &&
|
|
431
|
-
transfer.to !== undefined &&
|
|
432
|
-
accountIdSet.has(transfer.to)
|
|
433
|
-
) {
|
|
434
|
-
return 'none'
|
|
435
|
-
} else if (transfer.from !== undefined && accountIdSet.has(transfer.from)) {
|
|
436
|
-
return 'out'
|
|
437
|
-
} else if (transfer.to !== undefined && accountIdSet.has(transfer.to)) {
|
|
438
|
-
return 'in'
|
|
439
|
-
} else {
|
|
440
|
-
return 'none'
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
const reverseTransferDirection = (
|
|
445
|
-
direction: Transfer['direction'],
|
|
446
|
-
): Transfer['direction'] => {
|
|
447
|
-
switch (direction) {
|
|
448
|
-
case 'in': {
|
|
449
|
-
return 'out'
|
|
450
|
-
}
|
|
451
|
-
case 'none': {
|
|
452
|
-
return 'none'
|
|
453
|
-
}
|
|
454
|
-
case 'out': {
|
|
455
|
-
return 'in'
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
const createTransferKey = (
|
|
461
|
-
transfer: Transfer,
|
|
462
|
-
accountIdSet: Set<string>,
|
|
463
|
-
): string => {
|
|
464
|
-
const addressKey = [transfer.from, transfer.to]
|
|
465
|
-
.filter(
|
|
466
|
-
(address): address is string =>
|
|
467
|
-
address !== undefined && accountIdSet.has(address),
|
|
468
|
-
)
|
|
469
|
-
.sort()
|
|
470
|
-
.join('/')
|
|
471
|
-
return `${transfer.asset.type}/${transfer.asset.id}/${addressKey}`
|
|
472
|
-
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { absoluteValue, minus, plus } from '@0xtorch/big-decimal'
|
|
2
|
+
import type { Transfer } from '../types'
|
|
3
|
+
|
|
4
|
+
export const mergeSameAssetTransfers = (
|
|
5
|
+
transfers: readonly Transfer[],
|
|
6
|
+
accountIds: Set<string>,
|
|
7
|
+
): readonly Transfer[] => {
|
|
8
|
+
const mut_transfers: (Transfer & { readonly key: string })[] = []
|
|
9
|
+
|
|
10
|
+
for (const transfer of transfers) {
|
|
11
|
+
if (
|
|
12
|
+
(transfer.from === undefined || !accountIds.has(transfer.from)) &&
|
|
13
|
+
(transfer.to === undefined || !accountIds.has(transfer.to))
|
|
14
|
+
) {
|
|
15
|
+
continue
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const transferKey = createTransferKey(transfer, accountIds)
|
|
19
|
+
const transferIndex = mut_transfers.findIndex(
|
|
20
|
+
({ key }) => key === transferKey,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
if (transferIndex === -1) {
|
|
24
|
+
mut_transfers.push({
|
|
25
|
+
...transfer,
|
|
26
|
+
direction: createTransferDirection(transfer, accountIds),
|
|
27
|
+
key: transferKey,
|
|
28
|
+
})
|
|
29
|
+
} else {
|
|
30
|
+
const baseTransfer = mut_transfers[transferIndex]
|
|
31
|
+
// from=new-from/to=new-to の場合は加算
|
|
32
|
+
if (
|
|
33
|
+
baseTransfer.from === transfer.from &&
|
|
34
|
+
baseTransfer.to === transfer.to
|
|
35
|
+
) {
|
|
36
|
+
mut_transfers[transferIndex] = {
|
|
37
|
+
...baseTransfer,
|
|
38
|
+
amount: plus(baseTransfer.amount, transfer.amount),
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// from=new-to/to=new-from の場合は減算
|
|
42
|
+
else if (
|
|
43
|
+
baseTransfer.from === transfer.to &&
|
|
44
|
+
baseTransfer.to === transfer.from
|
|
45
|
+
) {
|
|
46
|
+
mut_transfers[transferIndex] = {
|
|
47
|
+
...baseTransfer,
|
|
48
|
+
amount: minus(baseTransfer.amount, transfer.amount),
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
// from=new-from/to!=new-to の場合は to を undefined にして加算
|
|
52
|
+
else if (
|
|
53
|
+
baseTransfer.from === transfer.from &&
|
|
54
|
+
baseTransfer.to !== transfer.to
|
|
55
|
+
) {
|
|
56
|
+
mut_transfers[transferIndex] = {
|
|
57
|
+
...baseTransfer,
|
|
58
|
+
to: undefined,
|
|
59
|
+
amount: plus(baseTransfer.amount, transfer.amount),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// from!=new-from/to=new-to の場合は from を undefined にして加算
|
|
63
|
+
else if (
|
|
64
|
+
baseTransfer.from !== transfer.from &&
|
|
65
|
+
baseTransfer.to === transfer.to
|
|
66
|
+
) {
|
|
67
|
+
mut_transfers[transferIndex] = {
|
|
68
|
+
...baseTransfer,
|
|
69
|
+
from: undefined,
|
|
70
|
+
amount: plus(baseTransfer.amount, transfer.amount),
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
// from=new-to/to!=new-from の場合は to を undefined にして減算
|
|
74
|
+
else if (
|
|
75
|
+
baseTransfer.from === transfer.to &&
|
|
76
|
+
baseTransfer.to !== transfer.from
|
|
77
|
+
) {
|
|
78
|
+
mut_transfers[transferIndex] = {
|
|
79
|
+
...baseTransfer,
|
|
80
|
+
to: undefined,
|
|
81
|
+
amount: minus(baseTransfer.amount, transfer.amount),
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// from!=new-to/to=new-from の場合は from を undefined にして減算
|
|
85
|
+
else if (
|
|
86
|
+
baseTransfer.from !== transfer.to &&
|
|
87
|
+
baseTransfer.to === transfer.from
|
|
88
|
+
) {
|
|
89
|
+
mut_transfers[transferIndex] = {
|
|
90
|
+
...baseTransfer,
|
|
91
|
+
from: undefined,
|
|
92
|
+
amount: minus(baseTransfer.amount, transfer.amount),
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// amount がマイナスの場合は from/to , direction を逆にして amount をプラスにする
|
|
99
|
+
return mut_transfers
|
|
100
|
+
.filter((transfer) => transfer.amount.value !== 0n)
|
|
101
|
+
.map((transfer) =>
|
|
102
|
+
transfer.amount.value < 0
|
|
103
|
+
? {
|
|
104
|
+
...transfer,
|
|
105
|
+
from: transfer.to,
|
|
106
|
+
to: transfer.from,
|
|
107
|
+
direction: reverseTransferDirection(transfer.direction),
|
|
108
|
+
amount: absoluteValue(transfer.amount),
|
|
109
|
+
}
|
|
110
|
+
: transfer,
|
|
111
|
+
)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const createTransferKey = (
|
|
115
|
+
transfer: Transfer,
|
|
116
|
+
accountIds: Set<string>,
|
|
117
|
+
): string => {
|
|
118
|
+
const addressKey = [transfer.from, transfer.to]
|
|
119
|
+
.filter(
|
|
120
|
+
(address): address is string =>
|
|
121
|
+
address !== undefined && accountIds.has(address),
|
|
122
|
+
)
|
|
123
|
+
.sort()
|
|
124
|
+
.join('/')
|
|
125
|
+
return `${transfer.asset.type}/${transfer.asset.id}/${addressKey}`
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const createTransferDirection = (
|
|
129
|
+
transfer: Transfer,
|
|
130
|
+
accountIds: Set<string>,
|
|
131
|
+
) => {
|
|
132
|
+
if (
|
|
133
|
+
transfer.from !== undefined &&
|
|
134
|
+
accountIds.has(transfer.from) &&
|
|
135
|
+
transfer.to !== undefined &&
|
|
136
|
+
accountIds.has(transfer.to)
|
|
137
|
+
) {
|
|
138
|
+
return 'none'
|
|
139
|
+
} else if (transfer.from !== undefined && accountIds.has(transfer.from)) {
|
|
140
|
+
return 'out'
|
|
141
|
+
} else if (transfer.to !== undefined && accountIds.has(transfer.to)) {
|
|
142
|
+
return 'in'
|
|
143
|
+
} else {
|
|
144
|
+
return 'none'
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const reverseTransferDirection = (
|
|
149
|
+
direction: Transfer['direction'],
|
|
150
|
+
): Transfer['direction'] => {
|
|
151
|
+
switch (direction) {
|
|
152
|
+
case 'in': {
|
|
153
|
+
return 'out'
|
|
154
|
+
}
|
|
155
|
+
case 'none': {
|
|
156
|
+
return 'none'
|
|
157
|
+
}
|
|
158
|
+
case 'out': {
|
|
159
|
+
return 'in'
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
package/assets/.DS_Store
ADDED
|
Binary file
|
package/index.ts
CHANGED
|
@@ -46,6 +46,7 @@ export {
|
|
|
46
46
|
accountActionWithdrawSchema,
|
|
47
47
|
accountActionWithdrawWithBondSchema,
|
|
48
48
|
accountActionWrapSchema,
|
|
49
|
+
checkIfAccountActionsIsValid,
|
|
49
50
|
createEvidenceNoneAccountActions,
|
|
50
51
|
crossActionBundleSchema,
|
|
51
52
|
crossTypeSchema,
|
|
@@ -58,6 +59,7 @@ export {
|
|
|
58
59
|
isTransferNftIn,
|
|
59
60
|
isTransferNftNone,
|
|
60
61
|
isTransferNftOut,
|
|
62
|
+
mergeSameAssetTransfers,
|
|
61
63
|
normalActionActionSchema,
|
|
62
64
|
normalActionAddLiquiditySchema,
|
|
63
65
|
normalActionApproveSchema,
|