@t2000/engine 0.46.0 → 0.46.2
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/dist/index.js +5 -22
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { resolveSymbol, getDecimalsForCoinType, assertAllowedAsset, getSwapQuote,
|
|
2
|
+
import { resolveSymbol, getDecimalsForCoinType, assertAllowedAsset, getSwapQuote, extractTransferDetails, classifyTransaction } from '@t2000/sdk';
|
|
3
3
|
import { readdirSync, readFileSync } from 'fs';
|
|
4
4
|
import { join } from 'path';
|
|
5
5
|
import yaml from 'js-yaml';
|
|
@@ -1005,11 +1005,6 @@ var ratesInfoTool = buildTool({
|
|
|
1005
1005
|
return { data: rates, displayText: formatRatesSummary(rates) };
|
|
1006
1006
|
}
|
|
1007
1007
|
});
|
|
1008
|
-
function resolveOwner(owner) {
|
|
1009
|
-
if (typeof owner === "object" && owner.AddressOwner) return owner.AddressOwner;
|
|
1010
|
-
if (typeof owner === "string") return owner;
|
|
1011
|
-
return null;
|
|
1012
|
-
}
|
|
1013
1008
|
function parseRpcTx(tx, address) {
|
|
1014
1009
|
const gasUsed = tx.effects?.gasUsed;
|
|
1015
1010
|
const gasCost = gasUsed ? (Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate)) / 1e9 : void 0;
|
|
@@ -1018,8 +1013,8 @@ function parseRpcTx(tx, address) {
|
|
|
1018
1013
|
try {
|
|
1019
1014
|
const data = tx.transaction?.data;
|
|
1020
1015
|
const inner = data?.transaction;
|
|
1021
|
-
const commands = inner?.commands;
|
|
1022
|
-
if (commands) {
|
|
1016
|
+
const commands = inner?.commands ?? inner?.transactions;
|
|
1017
|
+
if (Array.isArray(commands)) {
|
|
1023
1018
|
for (const cmd of commands) {
|
|
1024
1019
|
if (cmd.MoveCall) {
|
|
1025
1020
|
const mc = cmd.MoveCall;
|
|
@@ -1033,20 +1028,7 @@ function parseRpcTx(tx, address) {
|
|
|
1033
1028
|
} catch {
|
|
1034
1029
|
}
|
|
1035
1030
|
const changes = tx.balanceChanges ?? [];
|
|
1036
|
-
const
|
|
1037
|
-
const inflows = changes.filter((c) => resolveOwner(c.owner) !== address && BigInt(c.amount) > 0n);
|
|
1038
|
-
const primaryOutflow = outflows.filter((c) => c.coinType !== SUI_TYPE).sort((a, b) => Number(BigInt(a.amount) - BigInt(b.amount)))[0] ?? outflows[0];
|
|
1039
|
-
let amount;
|
|
1040
|
-
let asset;
|
|
1041
|
-
let recipient;
|
|
1042
|
-
if (primaryOutflow) {
|
|
1043
|
-
const coinType = primaryOutflow.coinType;
|
|
1044
|
-
const decimals = getDecimalsForCoinType(coinType);
|
|
1045
|
-
amount = Math.abs(Number(BigInt(primaryOutflow.amount))) / 10 ** decimals;
|
|
1046
|
-
asset = resolveSymbol(coinType);
|
|
1047
|
-
const recipientChange = inflows.find((c) => c.coinType === coinType);
|
|
1048
|
-
recipient = recipientChange ? resolveOwner(recipientChange.owner) ?? void 0 : void 0;
|
|
1049
|
-
}
|
|
1031
|
+
const { amount, asset, recipient, direction } = extractTransferDetails(changes, address);
|
|
1050
1032
|
const timestampMs = Number(tx.timestampMs ?? 0);
|
|
1051
1033
|
const { action, label } = classifyTransaction(moveCallTargets, commandTypes, changes, address);
|
|
1052
1034
|
return {
|
|
@@ -1056,6 +1038,7 @@ function parseRpcTx(tx, address) {
|
|
|
1056
1038
|
amount,
|
|
1057
1039
|
asset,
|
|
1058
1040
|
recipient,
|
|
1041
|
+
direction,
|
|
1059
1042
|
timestamp: timestampMs,
|
|
1060
1043
|
date: timestampMs > 0 ? new Date(timestampMs).toISOString() : void 0,
|
|
1061
1044
|
gasCost
|