tbc-tx-parser 0.1.6 → 0.1.8
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/README.md +65 -8
- package/dist/decode-tx-raw.d.ts.map +1 -1
- package/dist/decode-tx-raw.js +28 -5
- package/dist/decode-tx-raw.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/protocols/ft/index.d.ts +12 -0
- package/dist/protocols/ft/index.d.ts.map +1 -1
- package/dist/protocols/ft/index.js +141 -18
- package/dist/protocols/ft/index.js.map +1 -1
- package/dist/protocols/order-book/facts.d.ts +1 -1
- package/dist/protocols/order-book/facts.d.ts.map +1 -1
- package/dist/protocols/order-book/facts.js +8 -6
- package/dist/protocols/order-book/facts.js.map +1 -1
- package/dist/protocols/order-book/settlement.js +2 -2
- package/dist/protocols/order-book/settlement.js.map +1 -1
- package/dist/render-transaction-description.d.ts +8 -0
- package/dist/render-transaction-description.d.ts.map +1 -0
- package/dist/render-transaction-description.js +32 -0
- package/dist/render-transaction-description.js.map +1 -0
- package/dist/result/classification-description.d.ts +11 -0
- package/dist/result/classification-description.d.ts.map +1 -0
- package/dist/result/classification-description.js +570 -0
- package/dist/result/classification-description.js.map +1 -0
- package/dist/result/classification.d.ts +20 -0
- package/dist/result/classification.d.ts.map +1 -0
- package/dist/result/classification.js +495 -0
- package/dist/result/classification.js.map +1 -0
- package/dist/result/index.d.ts +2 -1
- package/dist/result/index.d.ts.map +1 -1
- package/dist/result/index.js +23 -1
- package/dist/result/index.js.map +1 -1
- package/dist/result/semantic.d.ts.map +1 -1
- package/dist/result/semantic.js +17 -7
- package/dist/result/semantic.js.map +1 -1
- package/dist/types/result.d.ts +44 -0
- package/dist/types/result.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import { buildStandardClassificationDescription } from './classification-description.js';
|
|
2
|
+
const definitions = {
|
|
3
|
+
'TBC coinbase': {
|
|
4
|
+
type: 'tbc.coinbase',
|
|
5
|
+
protocol: 'tbc',
|
|
6
|
+
action: 'coinbase',
|
|
7
|
+
standardDescription: 'Creates native TBC as block rewards.',
|
|
8
|
+
subject: 'a native TBC coinbase transaction',
|
|
9
|
+
},
|
|
10
|
+
'TBC transfer': {
|
|
11
|
+
type: 'tbc.transfer',
|
|
12
|
+
protocol: 'tbc',
|
|
13
|
+
action: 'transfer',
|
|
14
|
+
standardDescription: 'Sends native TBC.',
|
|
15
|
+
subject: 'a native TBC transfer',
|
|
16
|
+
},
|
|
17
|
+
'TBC multisig': {
|
|
18
|
+
type: 'tbc.multisig',
|
|
19
|
+
protocol: 'tbc',
|
|
20
|
+
action: 'multisig',
|
|
21
|
+
standardDescription: 'Moves native TBC using a multisignature wallet.',
|
|
22
|
+
subject: 'a native TBC MultiSig transaction',
|
|
23
|
+
},
|
|
24
|
+
'FT mint': {
|
|
25
|
+
type: 'ft.mint',
|
|
26
|
+
protocol: 'ft',
|
|
27
|
+
action: 'mint',
|
|
28
|
+
standardDescription: 'Mints FT tokens.',
|
|
29
|
+
subject: 'an FT mint',
|
|
30
|
+
},
|
|
31
|
+
'FT transfer': {
|
|
32
|
+
type: 'ft.transfer',
|
|
33
|
+
protocol: 'ft',
|
|
34
|
+
action: 'transfer',
|
|
35
|
+
standardDescription: 'Sends FT tokens.',
|
|
36
|
+
subject: 'an FT transfer',
|
|
37
|
+
},
|
|
38
|
+
'FT transfer with TBC': {
|
|
39
|
+
type: 'ft.transferWithTbc',
|
|
40
|
+
protocol: 'ft',
|
|
41
|
+
action: 'transferWithTbc',
|
|
42
|
+
standardDescription: 'Sends FT tokens and native TBC.',
|
|
43
|
+
subject: 'a combined FT and TBC transfer',
|
|
44
|
+
},
|
|
45
|
+
'FT merge': {
|
|
46
|
+
type: 'ft.merge',
|
|
47
|
+
protocol: 'ft',
|
|
48
|
+
action: 'merge',
|
|
49
|
+
standardDescription: 'Combines FT token balances.',
|
|
50
|
+
subject: 'an FT merge',
|
|
51
|
+
},
|
|
52
|
+
'Stablecoin mint': {
|
|
53
|
+
type: 'stablecoin.mint',
|
|
54
|
+
protocol: 'stablecoin',
|
|
55
|
+
action: 'mint',
|
|
56
|
+
standardDescription: 'Mints StableCoin tokens.',
|
|
57
|
+
subject: 'a StableCoin mint',
|
|
58
|
+
},
|
|
59
|
+
'StableCoin bootstrap': {
|
|
60
|
+
type: 'stablecoin.bootstrap',
|
|
61
|
+
protocol: 'stablecoin',
|
|
62
|
+
action: 'bootstrap',
|
|
63
|
+
standardDescription: 'Creates the certificate used to issue a StableCoin.',
|
|
64
|
+
subject: 'a StableCoin NFT-certificate bootstrap',
|
|
65
|
+
},
|
|
66
|
+
'Stablecoin transfer': {
|
|
67
|
+
type: 'stablecoin.transfer',
|
|
68
|
+
protocol: 'stablecoin',
|
|
69
|
+
action: 'transfer',
|
|
70
|
+
standardDescription: 'Sends StableCoin tokens.',
|
|
71
|
+
subject: 'a StableCoin transfer',
|
|
72
|
+
},
|
|
73
|
+
'Stablecoin transfer with TBC': {
|
|
74
|
+
type: 'stablecoin.transferWithTbc',
|
|
75
|
+
protocol: 'stablecoin',
|
|
76
|
+
action: 'transferWithTbc',
|
|
77
|
+
standardDescription: 'Sends StableCoin tokens and native TBC.',
|
|
78
|
+
subject: 'a combined StableCoin and TBC transfer',
|
|
79
|
+
},
|
|
80
|
+
'Stablecoin merge': {
|
|
81
|
+
type: 'stablecoin.merge',
|
|
82
|
+
protocol: 'stablecoin',
|
|
83
|
+
action: 'merge',
|
|
84
|
+
standardDescription: 'Combines StableCoin token balances.',
|
|
85
|
+
subject: 'a StableCoin merge',
|
|
86
|
+
},
|
|
87
|
+
'NFT collection mint': {
|
|
88
|
+
type: 'nft.collectionMint',
|
|
89
|
+
protocol: 'nft',
|
|
90
|
+
action: 'collectionMint',
|
|
91
|
+
standardDescription: 'Creates an NFT collection and its mint slots.',
|
|
92
|
+
subject: 'an NFT collection mint',
|
|
93
|
+
},
|
|
94
|
+
'NFT mint': {
|
|
95
|
+
type: 'nft.mint',
|
|
96
|
+
protocol: 'nft',
|
|
97
|
+
action: 'mint',
|
|
98
|
+
standardDescription: 'Mints an NFT.',
|
|
99
|
+
subject: 'an NFT mint',
|
|
100
|
+
},
|
|
101
|
+
'NFT transfer': {
|
|
102
|
+
type: 'nft.transfer',
|
|
103
|
+
protocol: 'nft',
|
|
104
|
+
action: 'transfer',
|
|
105
|
+
standardDescription: 'Transfers an NFT to another destination.',
|
|
106
|
+
subject: 'an NFT transfer',
|
|
107
|
+
},
|
|
108
|
+
'PiggyBank freeze': {
|
|
109
|
+
type: 'piggyBank.freeze',
|
|
110
|
+
protocol: 'piggyBank',
|
|
111
|
+
action: 'freeze',
|
|
112
|
+
standardDescription: 'Locks native TBC in PiggyBank until a configured block height.',
|
|
113
|
+
subject: 'a PiggyBank freeze',
|
|
114
|
+
},
|
|
115
|
+
'PiggyBank unfreeze': {
|
|
116
|
+
type: 'piggyBank.unfreeze',
|
|
117
|
+
protocol: 'piggyBank',
|
|
118
|
+
action: 'unfreeze',
|
|
119
|
+
standardDescription: 'Withdraws native TBC from PiggyBank after maturity.',
|
|
120
|
+
subject: 'a PiggyBank unfreeze',
|
|
121
|
+
},
|
|
122
|
+
'OrderBook buy order': {
|
|
123
|
+
type: 'orderBook.placeBuy',
|
|
124
|
+
protocol: 'orderBook',
|
|
125
|
+
action: 'placeBuy',
|
|
126
|
+
standardDescription: 'Places a buy order using the required asset.',
|
|
127
|
+
subject: 'an OrderBook buy-order placement',
|
|
128
|
+
},
|
|
129
|
+
'OrderBook sell order': {
|
|
130
|
+
type: 'orderBook.placeSell',
|
|
131
|
+
protocol: 'orderBook',
|
|
132
|
+
action: 'placeSell',
|
|
133
|
+
standardDescription: 'Places a sell order using the required asset.',
|
|
134
|
+
subject: 'an OrderBook sell-order placement',
|
|
135
|
+
},
|
|
136
|
+
'OrderBook buy order cancel': {
|
|
137
|
+
type: 'orderBook.cancelBuy',
|
|
138
|
+
protocol: 'orderBook',
|
|
139
|
+
action: 'cancelBuy',
|
|
140
|
+
standardDescription: 'Cancels a buy order and releases the locked asset.',
|
|
141
|
+
subject: 'an OrderBook buy-order cancellation',
|
|
142
|
+
},
|
|
143
|
+
'OrderBook sell order cancel': {
|
|
144
|
+
type: 'orderBook.cancelSell',
|
|
145
|
+
protocol: 'orderBook',
|
|
146
|
+
action: 'cancelSell',
|
|
147
|
+
standardDescription: 'Cancels a sell order and releases the locked asset.',
|
|
148
|
+
subject: 'an OrderBook sell-order cancellation',
|
|
149
|
+
},
|
|
150
|
+
'OrderBook order update': {
|
|
151
|
+
type: 'orderBook.update',
|
|
152
|
+
protocol: 'orderBook',
|
|
153
|
+
action: 'update',
|
|
154
|
+
standardDescription: 'Updates an order while keeping its asset locked.',
|
|
155
|
+
subject: 'an OrderBook order update',
|
|
156
|
+
},
|
|
157
|
+
'OrderBook match': {
|
|
158
|
+
type: 'orderBook.match',
|
|
159
|
+
protocol: 'orderBook',
|
|
160
|
+
action: 'match',
|
|
161
|
+
standardDescription: 'Matches a buy and sell order and exchanges their assets.',
|
|
162
|
+
subject: 'an OrderBook match',
|
|
163
|
+
},
|
|
164
|
+
'PoolNFT create': {
|
|
165
|
+
type: 'poolNft.create',
|
|
166
|
+
protocol: 'poolNft',
|
|
167
|
+
action: 'create',
|
|
168
|
+
standardDescription: 'Creates a liquidity pool.',
|
|
169
|
+
subject: 'a PoolNFT creation',
|
|
170
|
+
},
|
|
171
|
+
'PoolNFT init': {
|
|
172
|
+
type: 'poolNft.init',
|
|
173
|
+
protocol: 'poolNft',
|
|
174
|
+
action: 'init',
|
|
175
|
+
standardDescription: 'Starts a liquidity pool with its initial assets.',
|
|
176
|
+
subject: 'a PoolNFT initialization',
|
|
177
|
+
},
|
|
178
|
+
'PoolNFT increase liquidity': {
|
|
179
|
+
type: 'poolNft.increaseLiquidity',
|
|
180
|
+
protocol: 'poolNft',
|
|
181
|
+
action: 'increaseLiquidity',
|
|
182
|
+
standardDescription: 'Adds assets to a liquidity pool and issues liquidity tokens.',
|
|
183
|
+
subject: 'a PoolNFT liquidity increase',
|
|
184
|
+
},
|
|
185
|
+
'PoolNFT consume liquidity': {
|
|
186
|
+
type: 'poolNft.consumeLiquidity',
|
|
187
|
+
protocol: 'poolNft',
|
|
188
|
+
action: 'consumeLiquidity',
|
|
189
|
+
standardDescription: 'Removes liquidity and releases the underlying assets.',
|
|
190
|
+
subject: 'a PoolNFT liquidity removal',
|
|
191
|
+
},
|
|
192
|
+
'PoolNFT swap TBC to FT': {
|
|
193
|
+
type: 'poolNft.swapTbcToFt',
|
|
194
|
+
protocol: 'poolNft',
|
|
195
|
+
action: 'swapTbcToFt',
|
|
196
|
+
standardDescription: 'Swaps native TBC for FT tokens in a liquidity pool.',
|
|
197
|
+
subject: 'a PoolNFT TBC-to-FT swap',
|
|
198
|
+
},
|
|
199
|
+
'PoolNFT swap FT to TBC': {
|
|
200
|
+
type: 'poolNft.swapFtToTbc',
|
|
201
|
+
protocol: 'poolNft',
|
|
202
|
+
action: 'swapFtToTbc',
|
|
203
|
+
standardDescription: 'Swaps FT tokens for native TBC in a liquidity pool.',
|
|
204
|
+
subject: 'a PoolNFT FT-to-TBC swap',
|
|
205
|
+
},
|
|
206
|
+
'PoolNFT merge FT in pool': {
|
|
207
|
+
type: 'poolNft.mergeFtInPool',
|
|
208
|
+
protocol: 'poolNft',
|
|
209
|
+
action: 'mergeFtInPool',
|
|
210
|
+
standardDescription: 'Combines token balances held by a liquidity pool.',
|
|
211
|
+
subject: 'a PoolNFT in-pool FT merge',
|
|
212
|
+
},
|
|
213
|
+
'PoolNFT LP merge': {
|
|
214
|
+
type: 'poolNft.mergeFtLp',
|
|
215
|
+
protocol: 'poolNft',
|
|
216
|
+
action: 'mergeFtLp',
|
|
217
|
+
standardDescription: 'Combines liquidity-token balances.',
|
|
218
|
+
subject: 'a PoolNFT LP-token merge',
|
|
219
|
+
},
|
|
220
|
+
'PoolNFT LP burn': {
|
|
221
|
+
type: 'poolNft.burnFtLp',
|
|
222
|
+
protocol: 'poolNft',
|
|
223
|
+
action: 'burnFtLp',
|
|
224
|
+
standardDescription: 'Burns liquidity tokens.',
|
|
225
|
+
subject: 'a PoolNFT LP-token burn',
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
const genericDefinitions = {
|
|
229
|
+
ft: {
|
|
230
|
+
type: 'ft.unknown',
|
|
231
|
+
protocol: 'ft',
|
|
232
|
+
action: 'unknown',
|
|
233
|
+
standardDescription: 'This transaction contains FT protocol evidence.',
|
|
234
|
+
subject: 'an FT transaction',
|
|
235
|
+
},
|
|
236
|
+
stablecoin: {
|
|
237
|
+
type: 'stablecoin.unknown',
|
|
238
|
+
protocol: 'stablecoin',
|
|
239
|
+
action: 'unknown',
|
|
240
|
+
standardDescription: 'This transaction contains StableCoin protocol evidence.',
|
|
241
|
+
subject: 'a StableCoin transaction',
|
|
242
|
+
},
|
|
243
|
+
nft: {
|
|
244
|
+
type: 'nft.unknown',
|
|
245
|
+
protocol: 'nft',
|
|
246
|
+
action: 'unknown',
|
|
247
|
+
standardDescription: 'This transaction contains NFT protocol evidence.',
|
|
248
|
+
subject: 'an NFT transaction',
|
|
249
|
+
},
|
|
250
|
+
piggyBank: {
|
|
251
|
+
type: 'piggyBank.unknown',
|
|
252
|
+
protocol: 'piggyBank',
|
|
253
|
+
action: 'unknown',
|
|
254
|
+
standardDescription: 'This transaction contains PiggyBank protocol evidence.',
|
|
255
|
+
subject: 'a PiggyBank transaction',
|
|
256
|
+
},
|
|
257
|
+
orderBook: {
|
|
258
|
+
type: 'orderBook.unknown',
|
|
259
|
+
protocol: 'orderBook',
|
|
260
|
+
action: 'unknown',
|
|
261
|
+
standardDescription: 'This transaction contains OrderBook protocol evidence.',
|
|
262
|
+
subject: 'an OrderBook transaction',
|
|
263
|
+
},
|
|
264
|
+
poolNft: {
|
|
265
|
+
type: 'poolNft.unknown',
|
|
266
|
+
protocol: 'poolNft',
|
|
267
|
+
action: 'unknown',
|
|
268
|
+
standardDescription: 'This transaction contains PoolNFT protocol evidence.',
|
|
269
|
+
subject: 'a PoolNFT transaction',
|
|
270
|
+
},
|
|
271
|
+
};
|
|
272
|
+
function evidenceText(transactionType, protocolMarkers, unsupported) {
|
|
273
|
+
return [
|
|
274
|
+
transactionType,
|
|
275
|
+
...protocolMarkers,
|
|
276
|
+
...unsupported.flatMap((item) => [item.marker, item.reason]),
|
|
277
|
+
]
|
|
278
|
+
.filter((value) => Boolean(value))
|
|
279
|
+
.join(' ')
|
|
280
|
+
.toLowerCase();
|
|
281
|
+
}
|
|
282
|
+
function candidateProtocol(text) {
|
|
283
|
+
if (/stable.?coin/u.test(text))
|
|
284
|
+
return 'stablecoin';
|
|
285
|
+
if (/order.?book/u.test(text))
|
|
286
|
+
return 'orderBook';
|
|
287
|
+
if (/pool.?nft/u.test(text))
|
|
288
|
+
return 'poolNft';
|
|
289
|
+
if (/piggy.?bank/u.test(text))
|
|
290
|
+
return 'piggyBank';
|
|
291
|
+
if (/nft|ntape|nhold|3code/u.test(text))
|
|
292
|
+
return 'nft';
|
|
293
|
+
if (/ftape|ftlp|ft contract|2code/u.test(text))
|
|
294
|
+
return 'ft';
|
|
295
|
+
return 'unknown';
|
|
296
|
+
}
|
|
297
|
+
function hasVerifiedDetails(protocol, details) {
|
|
298
|
+
switch (protocol) {
|
|
299
|
+
case 'ft':
|
|
300
|
+
return Boolean(details?.ft?.transfers.length);
|
|
301
|
+
case 'stablecoin':
|
|
302
|
+
return Boolean(details?.stablecoin?.transfers.length);
|
|
303
|
+
case 'nft':
|
|
304
|
+
return Boolean(details?.nft?.actions.length);
|
|
305
|
+
case 'piggyBank':
|
|
306
|
+
return Boolean(details?.piggyBank?.actions.length);
|
|
307
|
+
case 'orderBook':
|
|
308
|
+
return Boolean(details?.orderBook?.orders.length);
|
|
309
|
+
case 'poolNft':
|
|
310
|
+
return Boolean(details?.poolNft?.actions.length);
|
|
311
|
+
case 'tbc':
|
|
312
|
+
case 'unknown':
|
|
313
|
+
return false;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
function hasMissingAssociatedEvidence(inputs, protocol) {
|
|
317
|
+
return inputs.some((input) => {
|
|
318
|
+
const prevout = input.prevout;
|
|
319
|
+
const codeType = prevout?.script.data?.codeType?.toLowerCase() ?? '';
|
|
320
|
+
if (!prevout)
|
|
321
|
+
return false;
|
|
322
|
+
const scriptHex = prevout.script.hex?.toLowerCase() ?? '';
|
|
323
|
+
const isFtCode = codeType.includes('ft') || /(?:02|32)436f6465$/u.test(scriptHex);
|
|
324
|
+
const isNftCode = codeType.includes('nft') || Boolean(prevout.script.originUtxo) || scriptHex.endsWith('33436f6465');
|
|
325
|
+
if (protocol === 'ft' || protocol === 'stablecoin') {
|
|
326
|
+
return isFtCode && !prevout.associatedTape;
|
|
327
|
+
}
|
|
328
|
+
if (protocol === 'nft') {
|
|
329
|
+
return isNftCode && (!prevout.associatedTape || !prevout.associatedOrigin);
|
|
330
|
+
}
|
|
331
|
+
if (protocol === 'poolNft') {
|
|
332
|
+
return Boolean(prevout.script.data?.poolNft) && !prevout.associatedTape;
|
|
333
|
+
}
|
|
334
|
+
return false;
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
function hasPositiveUnknownLockingScript(outputs) {
|
|
338
|
+
return outputs.some((output) => output.satoshis > 0 && !output.script.type && !output.address && !output.script.address);
|
|
339
|
+
}
|
|
340
|
+
function hasVerifiedMultisigAssetFlow(inputs, outputs, assetFlows) {
|
|
341
|
+
const multisigInputAddresses = new Set(inputs
|
|
342
|
+
.filter((input) => input.prevout?.script.type === 'MULTISIG')
|
|
343
|
+
.flatMap((input) => [input.prevout?.address, input.prevout?.script.address])
|
|
344
|
+
.filter((address) => Boolean(address)));
|
|
345
|
+
const multisigOutputAddresses = new Set(outputs
|
|
346
|
+
.filter((output) => output.script.type === 'MULTISIG')
|
|
347
|
+
.flatMap((output) => [output.address, output.script.address])
|
|
348
|
+
.filter((address) => Boolean(address)));
|
|
349
|
+
return Boolean(assetFlows?.some((flow) => flow.asset.type === 'tbc' &&
|
|
350
|
+
flow.purpose === 'transfer' &&
|
|
351
|
+
(Boolean(flow.from?.address && multisigInputAddresses.has(flow.from.address)) ||
|
|
352
|
+
Boolean(flow.to?.address && multisigOutputAddresses.has(flow.to.address)))));
|
|
353
|
+
}
|
|
354
|
+
function isNonNegativeInteger(value) {
|
|
355
|
+
if (typeof value !== 'string' && typeof value !== 'number') {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
try {
|
|
359
|
+
return BigInt(value) >= 0n;
|
|
360
|
+
}
|
|
361
|
+
catch {
|
|
362
|
+
return false;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
function isStablecoinBootstrap(inputs, outputs) {
|
|
366
|
+
return outputs.some((tapeOutput) => {
|
|
367
|
+
const tape = tapeOutput.script.data?.nftTape;
|
|
368
|
+
if (tapeOutput.satoshis !== 0 ||
|
|
369
|
+
typeof tape?.nftName !== 'string' ||
|
|
370
|
+
typeof tape.nftSymbol !== 'string' ||
|
|
371
|
+
!Number.isInteger(tape.coinDecimal) ||
|
|
372
|
+
Number(tape.coinDecimal) < 0 ||
|
|
373
|
+
!isNonNegativeInteger(tape.coinTotalSupply)) {
|
|
374
|
+
return false;
|
|
375
|
+
}
|
|
376
|
+
const codeOutput = outputs.find((output) => output.index === tapeOutput.index - 2);
|
|
377
|
+
const holdOutput = outputs.find((output) => output.index === tapeOutput.index - 1);
|
|
378
|
+
const origin = codeOutput?.script.originUtxo;
|
|
379
|
+
return Boolean(codeOutput &&
|
|
380
|
+
codeOutput.satoshis >= 200 &&
|
|
381
|
+
codeOutput.script.hex?.toLowerCase().endsWith('33436f6465') &&
|
|
382
|
+
origin &&
|
|
383
|
+
inputs.some((input) => input.prevTxid === origin.txid && input.vout === origin.vout) &&
|
|
384
|
+
holdOutput &&
|
|
385
|
+
holdOutput.satoshis >= 100 &&
|
|
386
|
+
holdOutput.script.type === 'P2PKH' &&
|
|
387
|
+
(holdOutput.address || holdOutput.script.address));
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
function protocolDisplayName(protocol) {
|
|
391
|
+
const names = {
|
|
392
|
+
tbc: 'TBC',
|
|
393
|
+
ft: 'FT',
|
|
394
|
+
stablecoin: 'StableCoin',
|
|
395
|
+
nft: 'NFT',
|
|
396
|
+
piggyBank: 'PiggyBank',
|
|
397
|
+
orderBook: 'OrderBook',
|
|
398
|
+
poolNft: 'PoolNFT',
|
|
399
|
+
unknown: 'unknown',
|
|
400
|
+
};
|
|
401
|
+
return names[protocol];
|
|
402
|
+
}
|
|
403
|
+
function publicClassification(definition, conformance, description, issues) {
|
|
404
|
+
return {
|
|
405
|
+
protocol: definition.protocol,
|
|
406
|
+
action: definition.action,
|
|
407
|
+
conformance,
|
|
408
|
+
description,
|
|
409
|
+
...(issues?.length ? { issues } : {}),
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
function nonstandardClassification(definition, issue = 'PROTOCOL_RULE_MISMATCH') {
|
|
413
|
+
return publicClassification(definition, 'nonstandard', `This looks like ${definition.subject}, but its details could not be verified.`, [issue]);
|
|
414
|
+
}
|
|
415
|
+
function indeterminateClassification(definition, issue = 'INSUFFICIENT_PROTOCOL_EVIDENCE') {
|
|
416
|
+
return publicClassification(definition, 'indeterminate', `This looks like ${definition.subject}, but required transaction data is missing.`, [issue]);
|
|
417
|
+
}
|
|
418
|
+
export function buildTransactionClassification(options) {
|
|
419
|
+
const { transactionType, semantic, protocolDetails, unsupported, protocolMarkers, inputs, outputs = [], assetFlows, feeSatoshis, display, conformanceIssues = [], } = options;
|
|
420
|
+
const descriptionFacts = {
|
|
421
|
+
assetFlows,
|
|
422
|
+
inputs,
|
|
423
|
+
outputs,
|
|
424
|
+
feeSatoshis,
|
|
425
|
+
tbcUnit: display?.tbcUnit,
|
|
426
|
+
protocolDetails,
|
|
427
|
+
};
|
|
428
|
+
// A standalone LP merge has no PoolNFT tape or state transition, so the
|
|
429
|
+
// legacy primary-type inference sees it as an ordinary FT merge. The
|
|
430
|
+
// verified FT movement still identifies the token as FTLP, which is enough
|
|
431
|
+
// for the public classifier to expose the more specific PoolNFT action.
|
|
432
|
+
const ftTransfers = protocolDetails?.ft?.transfers;
|
|
433
|
+
const isFtLpMerge = transactionType === 'FT merge'
|
|
434
|
+
&& Boolean(ftTransfers?.length)
|
|
435
|
+
&& ftTransfers?.every((movement) => movement.isFtLp) === true;
|
|
436
|
+
const stablecoinBootstrap = isStablecoinBootstrap(inputs, outputs);
|
|
437
|
+
const isMultisig = transactionType === 'Multisig' &&
|
|
438
|
+
protocolMarkers.includes('MULTISIG') &&
|
|
439
|
+
hasVerifiedMultisigAssetFlow(inputs, outputs, assetFlows);
|
|
440
|
+
const hasSpecializedVerifiedEvidence = isFtLpMerge || stablecoinBootstrap;
|
|
441
|
+
const exactDefinition = definitions[stablecoinBootstrap
|
|
442
|
+
? 'StableCoin bootstrap'
|
|
443
|
+
: isFtLpMerge
|
|
444
|
+
? 'PoolNFT LP merge'
|
|
445
|
+
: isMultisig
|
|
446
|
+
? 'TBC multisig'
|
|
447
|
+
: transactionType === 'Multisig'
|
|
448
|
+
? 'TBC transfer'
|
|
449
|
+
: transactionType];
|
|
450
|
+
if (exactDefinition) {
|
|
451
|
+
const relevantIssues = conformanceIssues.filter((issue) => issue.protocol === exactDefinition.protocol);
|
|
452
|
+
const decisiveIssue = relevantIssues.find((issue) => issue.conformance === 'nonstandard') ?? relevantIssues[0];
|
|
453
|
+
if (decisiveIssue) {
|
|
454
|
+
return publicClassification(exactDefinition, decisiveIssue.conformance, decisiveIssue.description, [...new Set(relevantIssues.map((issue) => issue.code))]);
|
|
455
|
+
}
|
|
456
|
+
if (exactDefinition.protocol === 'tbc') {
|
|
457
|
+
const hasNativeRelation = semantic.relations.some((relation) => relation.kind === 'nativeCoinbase' || relation.kind === 'nativeTransfer') || Boolean(assetFlows?.some((flow) => flow.asset.type === 'tbc' && ['mint', 'transfer', 'self'].includes(flow.purpose)));
|
|
458
|
+
if (!hasNativeRelation) {
|
|
459
|
+
return indeterminateClassification(exactDefinition);
|
|
460
|
+
}
|
|
461
|
+
if (hasPositiveUnknownLockingScript(outputs)) {
|
|
462
|
+
return nonstandardClassification(exactDefinition, 'NONSTANDARD_LOCKING_SCRIPT');
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
else if (!hasSpecializedVerifiedEvidence && !hasVerifiedDetails(exactDefinition.protocol, protocolDetails)) {
|
|
466
|
+
if (hasMissingAssociatedEvidence(inputs, exactDefinition.protocol)) {
|
|
467
|
+
return indeterminateClassification(exactDefinition);
|
|
468
|
+
}
|
|
469
|
+
return nonstandardClassification(exactDefinition);
|
|
470
|
+
}
|
|
471
|
+
if (exactDefinition.protocol === 'orderBook' && semantic.confidence === 'partial') {
|
|
472
|
+
return nonstandardClassification(exactDefinition);
|
|
473
|
+
}
|
|
474
|
+
if (exactDefinition.protocol === 'poolNft' && !isFtLpMerge && semantic.confidence !== 'exact') {
|
|
475
|
+
return indeterminateClassification(exactDefinition);
|
|
476
|
+
}
|
|
477
|
+
return publicClassification(exactDefinition, 'standard', buildStandardClassificationDescription(exactDefinition.type, exactDefinition.standardDescription, descriptionFacts));
|
|
478
|
+
}
|
|
479
|
+
const protocol = candidateProtocol(evidenceText(transactionType, protocolMarkers, unsupported));
|
|
480
|
+
if (protocol !== 'unknown' && protocol !== 'tbc') {
|
|
481
|
+
const definition = genericDefinitions[protocol];
|
|
482
|
+
if (hasMissingAssociatedEvidence(inputs, protocol)) {
|
|
483
|
+
return indeterminateClassification(definition);
|
|
484
|
+
}
|
|
485
|
+
return nonstandardClassification(definition);
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
protocol: 'unknown',
|
|
489
|
+
action: 'unknown',
|
|
490
|
+
conformance: 'indeterminate',
|
|
491
|
+
description: 'The transaction could not be matched to a supported transaction type.',
|
|
492
|
+
issues: ['UNRECOGNIZED_TRANSACTION'],
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
//# sourceMappingURL=classification.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"classification.js","sourceRoot":"","sources":["../../src/result/classification.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,sCAAsC,EAAE,MAAM,iCAAiC,CAAC;AAYzF,MAAM,WAAW,GAA6C;IAC5D,cAAc,EAAE;QACd,IAAI,EAAE,cAAc;QACpB,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,UAAU;QAClB,mBAAmB,EAAE,sCAAsC;QAC3D,OAAO,EAAE,mCAAmC;KAC7C;IACD,cAAc,EAAE;QACd,IAAI,EAAE,cAAc;QACpB,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,UAAU;QAClB,mBAAmB,EAAE,mBAAmB;QACxC,OAAO,EAAE,uBAAuB;KACjC;IACD,cAAc,EAAE;QACd,IAAI,EAAE,cAAc;QACpB,QAAQ,EAAE,KAAK;QACf,MAAM,EAAE,UAAU;QAClB,mBAAmB,EAAE,iDAAiD;QACtE,OAAO,EAAE,mCAAmC;KAC7C;IACD,SAAS,EAAE;QACT,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,MAAM;QACd,mBAAmB,EAAE,kBAAkB;QACvC,OAAO,EAAE,YAAY;KACtB;IACD,aAAa,EAAE;QACb,IAAI,EAAE,aAAa;QACnB,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,UAAU;QAClB,mBAAmB,EAAE,kBAAkB;QACvC,OAAO,EAAE,gBAAgB;KAC1B;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,oBAAoB;QAC1B,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,iBAAiB;QACzB,mBAAmB,EAAE,iCAAiC;QACtD,OAAO,EAAE,gCAAgC;KAC1C;IACD,UAAU,EAAE;QACV,IAAI,EAAE,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ACD,OAAO,yBAAyB,CAAC,eAAe,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,eAAe,CAAC,QAAQ,KAAK,WAAW,IAAI,QAAQ,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;YAClF,OAAO,yBAAyB,CAAC,eAAe,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,eAAe,CAAC,QAAQ,KAAK,SAAS,IAAI,CAAC,WAAW,IAAI,QAAQ,CAAC,UAAU,KAAK,OAAO,EAAE,CAAC;YAC9F,OAAO,2BAA2B,CAAC,eAAe,CAAC,CAAC;QACtD,CAAC;QAED,OAAO,oBAAoB,CACzB,eAAe,EACf,UAAU,EACV,sCAAsC,CACpC,eAAe,CAAC,IAAI,EACpB,eAAe,CAAC,mBAAmB,EACnC,gBAAgB,CACjB,CACF,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,iBAAiB,CAAC,YAAY,CAAC,eAAe,EAAE,eAAe,EAAE,WAAW,CAAC,CAAC,CAAC;IAChG,IAAI,QAAQ,KAAK,SAAS,IAAI,QAAQ,KAAK,KAAK,EAAE,CAAC;QACjD,MAAM,UAAU,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QAChD,IAAI,4BAA4B,CAAC,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC;YACnD,OAAO,2BAA2B,CAAC,UAAU,CAAC,CAAC;QACjD,CAAC;QACD,OAAO,yBAAyB,CAAC,UAAU,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,SAAS;QACjB,WAAW,EAAE,eAAe;QAC5B,WAAW,EAAE,uEAAuE;QACpF,MAAM,EAAE,CAAC,0BAA0B,CAAC;KACrC,CAAC;AACJ,CAAC"}
|
package/dist/result/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { type AssetFlow, type DecodedInput, type DecodedOutput, type UnsupportedProtocol } from '../types.js';
|
|
1
|
+
import { type AssetFlow, type DecodedInput, type DecodedOutput, type UnspendableAssetFlow, type UnsupportedProtocol } from '../types.js';
|
|
2
2
|
import type { FungibleTokenMovement, NftMovement, OrderBookOrder, PiggyBankMovement, PoolNftMovement } from '../types/protocol.js';
|
|
3
3
|
import type { TransactionSemantic } from '../types/semantic.js';
|
|
4
|
+
export declare function buildUnspendableFtAssetFlows(movements: FungibleTokenMovement[]): UnspendableAssetFlow[];
|
|
4
5
|
export declare function normalizeActionType(transactionType: string): string;
|
|
5
6
|
export declare function isNativeTbcFlowOutput(output: DecodedOutput, protocolNativeOutputIndexes: Set<number>, nativeProtocolCarrierOutputIndexes?: Set<number>): boolean;
|
|
6
7
|
export declare function buildAssetFlows(transactionType: string, inputs: DecodedInput[], outputs: DecodedOutput[], ftMovements: FungibleTokenMovement[], nftMovements: NftMovement[], piggyBankMovements: PiggyBankMovement[], poolNftMovements: PoolNftMovement[], orderBookOrders: OrderBookOrder[], semantic: TransactionSemantic, unsupported?: UnsupportedProtocol[]): AssetFlow[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/result/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,YAAY,EACjB,KAAK,aAAa,EAGlB,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EACV,qBAAqB,EACrB,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAiC,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/result/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAEd,KAAK,YAAY,EACjB,KAAK,aAAa,EAGlB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,aAAa,CAAC;AAErB,OAAO,KAAK,EACV,qBAAqB,EACrB,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,eAAe,EAChB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAiC,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAiB/F,wBAAgB,4BAA4B,CAC1C,SAAS,EAAE,qBAAqB,EAAE,GACjC,oBAAoB,EAAE,CAuBxB;AAwLD,wBAAgB,mBAAmB,CAAC,eAAe,EAAE,MAAM,UAiB1D;AAsZD,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,aAAa,EACrB,2BAA2B,EAAE,GAAG,CAAC,MAAM,CAAC,EACxC,kCAAkC,cAAoB,WAiCvD;AA+eD,wBAAgB,eAAe,CAC7B,eAAe,EAAE,MAAM,EACvB,MAAM,EAAE,YAAY,EAAE,EACtB,OAAO,EAAE,aAAa,EAAE,EACxB,WAAW,EAAE,qBAAqB,EAAE,EACpC,YAAY,EAAE,WAAW,EAAE,EAC3B,kBAAkB,EAAE,iBAAiB,EAAE,EACvC,gBAAgB,EAAE,eAAe,EAAE,EACnC,eAAe,EAAE,cAAc,EAAE,EACjC,QAAQ,EAAE,mBAAmB,EAC7B,WAAW,GAAE,mBAAmB,EAAO,GACtC,SAAS,EAAE,CA4Db"}
|
package/dist/result/index.js
CHANGED
|
@@ -14,6 +14,28 @@ const ORDER_BOOK_ACTION_BY_TYPE = {
|
|
|
14
14
|
'OrderBook match': 'match',
|
|
15
15
|
'OrderBook order update': 'update',
|
|
16
16
|
};
|
|
17
|
+
export function buildUnspendableFtAssetFlows(movements) {
|
|
18
|
+
return movements.map((movement) => ({
|
|
19
|
+
outputIndex: movement.outputIndex,
|
|
20
|
+
asset: {
|
|
21
|
+
type: 'ft',
|
|
22
|
+
symbol: movement.symbol,
|
|
23
|
+
...(movement.name ? { name: movement.name } : {}),
|
|
24
|
+
...(movement.contractId ? { contractId: movement.contractId } : {}),
|
|
25
|
+
decimal: movement.decimal,
|
|
26
|
+
},
|
|
27
|
+
amount: {
|
|
28
|
+
raw: movement.rawAmount,
|
|
29
|
+
display: movement.displayAmount,
|
|
30
|
+
decimal: movement.decimal,
|
|
31
|
+
},
|
|
32
|
+
...(movement.receiver
|
|
33
|
+
? { to: { address: movement.receiver } }
|
|
34
|
+
: movement.receiverHash
|
|
35
|
+
? { to: { hash: movement.receiverHash } }
|
|
36
|
+
: {}),
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
17
39
|
function firstInputAddress(inputs) {
|
|
18
40
|
// Fallback source for ordinary TBC and legacy FT semantics; strict protocols should prefer verified movement sources.
|
|
19
41
|
return inputs.map((input) => input.prevout?.address).find((address) => Boolean(address));
|
|
@@ -570,7 +592,7 @@ function buildSemanticAssetFlows(semantic, inputs, outputs) {
|
|
|
570
592
|
: semantic.effects;
|
|
571
593
|
return publicEffects.map((effect) => {
|
|
572
594
|
const purpose = semanticEffectPurpose(effect, Boolean(orderBookContext));
|
|
573
|
-
const context = purpose === 'lock' ? orderBookContext : undefined;
|
|
595
|
+
const context = purpose === 'lock' || purpose === 'release' ? orderBookContext : undefined;
|
|
574
596
|
const asset = semanticAssetToTransactionAsset(effect.asset);
|
|
575
597
|
const from = semanticEffectSourceEndpoint(effect, asset, inputs, outputs);
|
|
576
598
|
const to = endpoint({
|