tx-indexer 0.5.3 → 0.5.4
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/client.js +49 -14
- package/dist/client.js.map +1 -1
- package/dist/index.js +49 -14
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -1155,21 +1155,38 @@ function determineTokenRole(change, tx, feePayer) {
|
|
|
1155
1155
|
}
|
|
1156
1156
|
|
|
1157
1157
|
// ../classification/src/classifiers/transfer-classifier.ts
|
|
1158
|
+
function findBestTransferPair(legs) {
|
|
1159
|
+
const senderLegs = legs.filter(
|
|
1160
|
+
(l) => l.accountId.startsWith("external:") && l.side === "debit" && l.role === "sent"
|
|
1161
|
+
);
|
|
1162
|
+
if (senderLegs.length === 0) return null;
|
|
1163
|
+
let bestPair = null;
|
|
1164
|
+
let bestAmount = 0;
|
|
1165
|
+
for (const senderLeg of senderLegs) {
|
|
1166
|
+
const receiverLeg = legs.find(
|
|
1167
|
+
(l) => l.accountId.startsWith("external:") && l.side === "credit" && l.role === "received" && l.amount.token.mint === senderLeg.amount.token.mint && l.accountId !== senderLeg.accountId
|
|
1168
|
+
// Must be different account
|
|
1169
|
+
);
|
|
1170
|
+
if (receiverLeg) {
|
|
1171
|
+
const amount = senderLeg.amount.amountUi;
|
|
1172
|
+
if (amount > bestAmount) {
|
|
1173
|
+
bestAmount = amount;
|
|
1174
|
+
bestPair = { senderLeg, receiverLeg };
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
return bestPair;
|
|
1179
|
+
}
|
|
1158
1180
|
var TransferClassifier = class {
|
|
1159
1181
|
name = "transfer";
|
|
1160
1182
|
priority = 20;
|
|
1161
1183
|
classify(context) {
|
|
1162
1184
|
const { legs, tx } = context;
|
|
1163
1185
|
const facilitator = tx.accountKeys ? detectFacilitator(tx.accountKeys) : null;
|
|
1164
|
-
const
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
if (!senderLeg) return null;
|
|
1186
|
+
const pair = findBestTransferPair(legs);
|
|
1187
|
+
if (!pair) return null;
|
|
1188
|
+
const { senderLeg, receiverLeg } = pair;
|
|
1168
1189
|
const sender = senderLeg.accountId.replace("external:", "");
|
|
1169
|
-
const receiverLeg = legs.find(
|
|
1170
|
-
(l) => l.accountId.startsWith("external:") && l.side === "credit" && l.role === "received" && l.amount.token.mint === senderLeg.amount.token.mint
|
|
1171
|
-
);
|
|
1172
|
-
if (!receiverLeg) return null;
|
|
1173
1190
|
const receiver = receiverLeg.accountId.replace("external:", "");
|
|
1174
1191
|
return {
|
|
1175
1192
|
primaryType: "transfer",
|
|
@@ -1648,6 +1665,27 @@ var FeeOnlyClassifier = class {
|
|
|
1648
1665
|
};
|
|
1649
1666
|
|
|
1650
1667
|
// ../classification/src/classifiers/solana-pay-classifier.ts
|
|
1668
|
+
function findBestTransferPair2(legs) {
|
|
1669
|
+
const senderLegs = legs.filter(
|
|
1670
|
+
(l) => l.accountId.startsWith("external:") && l.side === "debit" && l.role === "sent"
|
|
1671
|
+
);
|
|
1672
|
+
if (senderLegs.length === 0) return null;
|
|
1673
|
+
let bestPair = null;
|
|
1674
|
+
let bestAmount = 0;
|
|
1675
|
+
for (const senderLeg of senderLegs) {
|
|
1676
|
+
const receiverLeg = legs.find(
|
|
1677
|
+
(l) => l.accountId.startsWith("external:") && l.side === "credit" && l.role === "received" && l.amount.token.mint === senderLeg.amount.token.mint && l.accountId !== senderLeg.accountId
|
|
1678
|
+
);
|
|
1679
|
+
if (receiverLeg) {
|
|
1680
|
+
const amount = senderLeg.amount.amountUi;
|
|
1681
|
+
if (amount > bestAmount) {
|
|
1682
|
+
bestAmount = amount;
|
|
1683
|
+
bestPair = { senderLeg, receiverLeg };
|
|
1684
|
+
}
|
|
1685
|
+
}
|
|
1686
|
+
}
|
|
1687
|
+
return bestPair;
|
|
1688
|
+
}
|
|
1651
1689
|
var SolanaPayClassifier = class {
|
|
1652
1690
|
name = "solana-pay";
|
|
1653
1691
|
priority = 95;
|
|
@@ -1657,12 +1695,9 @@ var SolanaPayClassifier = class {
|
|
|
1657
1695
|
return null;
|
|
1658
1696
|
}
|
|
1659
1697
|
const memo = parseSolanaPayMemo(tx.memo);
|
|
1660
|
-
const
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
const receiverLeg = legs.find(
|
|
1664
|
-
(leg) => leg.accountId.startsWith("external:") && leg.side === "credit" && leg.role === "received"
|
|
1665
|
-
);
|
|
1698
|
+
const pair = findBestTransferPair2(legs);
|
|
1699
|
+
const senderLeg = pair?.senderLeg ?? null;
|
|
1700
|
+
const receiverLeg = pair?.receiverLeg ?? null;
|
|
1666
1701
|
const sender = senderLeg?.accountId.replace("external:", "") ?? null;
|
|
1667
1702
|
const receiver = receiverLeg?.accountId.replace("external:", "") ?? null;
|
|
1668
1703
|
const primaryAmount = senderLeg?.amount ?? receiverLeg?.amount ?? null;
|