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/client.js
CHANGED
|
@@ -1101,21 +1101,38 @@ function determineTokenRole(change, tx, feePayer) {
|
|
|
1101
1101
|
}
|
|
1102
1102
|
|
|
1103
1103
|
// ../classification/src/classifiers/transfer-classifier.ts
|
|
1104
|
+
function findBestTransferPair(legs) {
|
|
1105
|
+
const senderLegs = legs.filter(
|
|
1106
|
+
(l) => l.accountId.startsWith("external:") && l.side === "debit" && l.role === "sent"
|
|
1107
|
+
);
|
|
1108
|
+
if (senderLegs.length === 0) return null;
|
|
1109
|
+
let bestPair = null;
|
|
1110
|
+
let bestAmount = 0;
|
|
1111
|
+
for (const senderLeg of senderLegs) {
|
|
1112
|
+
const receiverLeg = legs.find(
|
|
1113
|
+
(l) => l.accountId.startsWith("external:") && l.side === "credit" && l.role === "received" && l.amount.token.mint === senderLeg.amount.token.mint && l.accountId !== senderLeg.accountId
|
|
1114
|
+
// Must be different account
|
|
1115
|
+
);
|
|
1116
|
+
if (receiverLeg) {
|
|
1117
|
+
const amount = senderLeg.amount.amountUi;
|
|
1118
|
+
if (amount > bestAmount) {
|
|
1119
|
+
bestAmount = amount;
|
|
1120
|
+
bestPair = { senderLeg, receiverLeg };
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return bestPair;
|
|
1125
|
+
}
|
|
1104
1126
|
var TransferClassifier = class {
|
|
1105
1127
|
name = "transfer";
|
|
1106
1128
|
priority = 20;
|
|
1107
1129
|
classify(context) {
|
|
1108
1130
|
const { legs, tx } = context;
|
|
1109
1131
|
const facilitator = tx.accountKeys ? detectFacilitator(tx.accountKeys) : null;
|
|
1110
|
-
const
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
if (!senderLeg) return null;
|
|
1132
|
+
const pair = findBestTransferPair(legs);
|
|
1133
|
+
if (!pair) return null;
|
|
1134
|
+
const { senderLeg, receiverLeg } = pair;
|
|
1114
1135
|
const sender = senderLeg.accountId.replace("external:", "");
|
|
1115
|
-
const receiverLeg = legs.find(
|
|
1116
|
-
(l) => l.accountId.startsWith("external:") && l.side === "credit" && l.role === "received" && l.amount.token.mint === senderLeg.amount.token.mint
|
|
1117
|
-
);
|
|
1118
|
-
if (!receiverLeg) return null;
|
|
1119
1136
|
const receiver = receiverLeg.accountId.replace("external:", "");
|
|
1120
1137
|
return {
|
|
1121
1138
|
primaryType: "transfer",
|
|
@@ -1594,6 +1611,27 @@ var FeeOnlyClassifier = class {
|
|
|
1594
1611
|
};
|
|
1595
1612
|
|
|
1596
1613
|
// ../classification/src/classifiers/solana-pay-classifier.ts
|
|
1614
|
+
function findBestTransferPair2(legs) {
|
|
1615
|
+
const senderLegs = legs.filter(
|
|
1616
|
+
(l) => l.accountId.startsWith("external:") && l.side === "debit" && l.role === "sent"
|
|
1617
|
+
);
|
|
1618
|
+
if (senderLegs.length === 0) return null;
|
|
1619
|
+
let bestPair = null;
|
|
1620
|
+
let bestAmount = 0;
|
|
1621
|
+
for (const senderLeg of senderLegs) {
|
|
1622
|
+
const receiverLeg = legs.find(
|
|
1623
|
+
(l) => l.accountId.startsWith("external:") && l.side === "credit" && l.role === "received" && l.amount.token.mint === senderLeg.amount.token.mint && l.accountId !== senderLeg.accountId
|
|
1624
|
+
);
|
|
1625
|
+
if (receiverLeg) {
|
|
1626
|
+
const amount = senderLeg.amount.amountUi;
|
|
1627
|
+
if (amount > bestAmount) {
|
|
1628
|
+
bestAmount = amount;
|
|
1629
|
+
bestPair = { senderLeg, receiverLeg };
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
return bestPair;
|
|
1634
|
+
}
|
|
1597
1635
|
var SolanaPayClassifier = class {
|
|
1598
1636
|
name = "solana-pay";
|
|
1599
1637
|
priority = 95;
|
|
@@ -1603,12 +1641,9 @@ var SolanaPayClassifier = class {
|
|
|
1603
1641
|
return null;
|
|
1604
1642
|
}
|
|
1605
1643
|
const memo = parseSolanaPayMemo(tx.memo);
|
|
1606
|
-
const
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
const receiverLeg = legs.find(
|
|
1610
|
-
(leg) => leg.accountId.startsWith("external:") && leg.side === "credit" && leg.role === "received"
|
|
1611
|
-
);
|
|
1644
|
+
const pair = findBestTransferPair2(legs);
|
|
1645
|
+
const senderLeg = pair?.senderLeg ?? null;
|
|
1646
|
+
const receiverLeg = pair?.receiverLeg ?? null;
|
|
1612
1647
|
const sender = senderLeg?.accountId.replace("external:", "") ?? null;
|
|
1613
1648
|
const receiver = receiverLeg?.accountId.replace("external:", "") ?? null;
|
|
1614
1649
|
const primaryAmount = senderLeg?.amount ?? receiverLeg?.amount ?? null;
|