@t2000/sdk 0.19.2 → 0.19.3

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.
@@ -1,4 +1,4 @@
1
- export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, Q as CetusAdapter, V as HealthInfo, L as LendingAdapter, w as LendingRates, Y as NaviAdapter, Z as PerpsAdapter, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a5 as SuilendAdapter, e as SwapAdapter, a6 as SwapQuote, a9 as allDescriptors, aa as cetusDescriptor, ad as naviDescriptor, ag as sentinelDescriptor, aj as suilendDescriptor } from '../index-D-6pQwzx.cjs';
1
+ export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, Q as CetusAdapter, V as HealthInfo, L as LendingAdapter, w as LendingRates, Y as NaviAdapter, Z as PerpsAdapter, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a5 as SuilendAdapter, e as SwapAdapter, a6 as SwapQuote, a9 as allDescriptors, aa as cetusDescriptor, ad as naviDescriptor, ag as sentinelDescriptor, aj as suilendDescriptor } from '../index-CcTPxTBs.cjs';
2
2
  import '@mysten/sui/transactions';
3
3
  import '@mysten/sui/jsonRpc';
4
4
  import '@mysten/sui/keypairs/ed25519';
@@ -1,4 +1,4 @@
1
- export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, Q as CetusAdapter, V as HealthInfo, L as LendingAdapter, w as LendingRates, Y as NaviAdapter, Z as PerpsAdapter, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a5 as SuilendAdapter, e as SwapAdapter, a6 as SwapQuote, a9 as allDescriptors, aa as cetusDescriptor, ad as naviDescriptor, ag as sentinelDescriptor, aj as suilendDescriptor } from '../index-D-6pQwzx.js';
1
+ export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, Q as CetusAdapter, V as HealthInfo, L as LendingAdapter, w as LendingRates, Y as NaviAdapter, Z as PerpsAdapter, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a5 as SuilendAdapter, e as SwapAdapter, a6 as SwapQuote, a9 as allDescriptors, aa as cetusDescriptor, ad as naviDescriptor, ag as sentinelDescriptor, aj as suilendDescriptor } from '../index-CcTPxTBs.js';
2
2
  import '@mysten/sui/transactions';
3
3
  import '@mysten/sui/jsonRpc';
4
4
  import '@mysten/sui/keypairs/ed25519';
@@ -170,6 +170,7 @@ interface TransactionRecord {
170
170
  action: string;
171
171
  amount?: number;
172
172
  asset?: string;
173
+ recipient?: string;
173
174
  timestamp: number;
174
175
  gasMethod?: GasMethod;
175
176
  }
@@ -170,6 +170,7 @@ interface TransactionRecord {
170
170
  action: string;
171
171
  amount?: number;
172
172
  asset?: string;
173
+ recipient?: string;
173
174
  timestamp: number;
174
175
  gasMethod?: GasMethod;
175
176
  }
package/dist/index.cjs CHANGED
@@ -42716,33 +42716,88 @@ async function queryBalance(client, address) {
42716
42716
  }
42717
42717
 
42718
42718
  // src/wallet/history.ts
42719
+ var SUI_TYPE = "0x2::sui::SUI";
42720
+ var KNOWN_TARGETS = [
42721
+ [/::mpp_charge::/, "mpp payment"],
42722
+ [/::suilend|::obligation/, "lending"],
42723
+ [/::navi|::incentive_v2/, "lending"],
42724
+ [/::cetus|::pool/, "swap"],
42725
+ [/::deepbook/, "swap"],
42726
+ [/::transfer::public_transfer/, "send"],
42727
+ [/::coin::split/, "split"]
42728
+ ];
42719
42729
  async function queryHistory(client, address, limit = 20) {
42720
42730
  const txns = await client.queryTransactionBlocks({
42721
42731
  filter: { FromAddress: address },
42722
- options: { showEffects: true, showInput: true },
42732
+ options: { showEffects: true, showInput: true, showBalanceChanges: true },
42723
42733
  limit,
42724
42734
  order: "descending"
42725
42735
  });
42726
42736
  return txns.data.map((tx) => {
42727
42737
  const gasUsed = tx.effects?.gasUsed;
42728
42738
  const gasCost = gasUsed ? (Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate)) / 1e9 : void 0;
42739
+ const targets = extractMoveCallTargets(tx.transaction);
42740
+ const action = classifyAction(targets);
42741
+ const { amount, asset, recipient } = extractTransferDetails(
42742
+ tx.balanceChanges,
42743
+ address
42744
+ );
42729
42745
  return {
42730
42746
  digest: tx.digest,
42731
- action: inferAction(tx.transaction),
42747
+ action,
42748
+ amount,
42749
+ asset,
42750
+ recipient,
42732
42751
  timestamp: Number(tx.timestampMs ?? 0),
42733
42752
  gasCost
42734
42753
  };
42735
42754
  });
42736
42755
  }
42737
- function inferAction(txBlock) {
42738
- if (!txBlock || typeof txBlock !== "object") return "unknown";
42739
- const data = "data" in txBlock ? txBlock.data : void 0;
42740
- if (!data || typeof data !== "object") return "unknown";
42741
- const inner = "transaction" in data ? data.transaction : void 0;
42742
- if (!inner || typeof inner !== "object") return "unknown";
42743
- const kind = "kind" in inner ? inner.kind : void 0;
42744
- if (kind === "ProgrammableTransaction") return "transaction";
42745
- return kind ?? "unknown";
42756
+ function extractTransferDetails(changes, sender) {
42757
+ if (!changes || changes.length === 0) return {};
42758
+ const outflows = changes.filter((c) => {
42759
+ const owner = typeof c.owner === "object" && c.owner.AddressOwner ? c.owner.AddressOwner : typeof c.owner === "string" ? c.owner : null;
42760
+ return owner === sender && BigInt(c.amount) < 0n;
42761
+ });
42762
+ const inflows = changes.filter((c) => {
42763
+ const owner = typeof c.owner === "object" && c.owner.AddressOwner ? c.owner.AddressOwner : typeof c.owner === "string" ? c.owner : null;
42764
+ return owner !== sender && BigInt(c.amount) > 0n;
42765
+ });
42766
+ const primaryOutflow = outflows.filter((c) => c.coinType !== SUI_TYPE).sort((a, b2) => Number(BigInt(a.amount) - BigInt(b2.amount)))[0] ?? outflows[0];
42767
+ if (!primaryOutflow) return {};
42768
+ const coinType = primaryOutflow.coinType;
42769
+ const decimals = coinType.includes("::usdc::") ? 6 : 9;
42770
+ const amount = Math.abs(Number(BigInt(primaryOutflow.amount))) / 10 ** decimals;
42771
+ const asset = coinType === SUI_TYPE ? "SUI" : coinType.includes("::usdc::") ? "USDC" : coinType.split("::").pop() ?? "unknown";
42772
+ const recipientChange = inflows.find((c) => c.coinType === coinType);
42773
+ const recipient = recipientChange ? typeof recipientChange.owner === "object" && recipientChange.owner.AddressOwner ? recipientChange.owner.AddressOwner : void 0 : void 0;
42774
+ return { amount, asset, recipient };
42775
+ }
42776
+ function extractMoveCallTargets(txBlock) {
42777
+ try {
42778
+ if (!txBlock || typeof txBlock !== "object") return [];
42779
+ const data = "data" in txBlock ? txBlock.data : void 0;
42780
+ if (!data || typeof data !== "object") return [];
42781
+ const inner = "transaction" in data ? data.transaction : void 0;
42782
+ if (!inner || typeof inner !== "object") return [];
42783
+ const commands = "commands" in inner ? inner.commands : void 0;
42784
+ if (!Array.isArray(commands)) return [];
42785
+ return commands.filter((c) => c.MoveCall).map((c) => {
42786
+ const mc = c.MoveCall;
42787
+ return `${mc.package}::${mc.module}::${mc.function}`;
42788
+ });
42789
+ } catch {
42790
+ return [];
42791
+ }
42792
+ }
42793
+ function classifyAction(targets) {
42794
+ if (targets.length === 0) return "transaction";
42795
+ for (const target of targets) {
42796
+ for (const [pattern, label] of KNOWN_TARGETS) {
42797
+ if (pattern.test(target)) return label;
42798
+ }
42799
+ }
42800
+ return "transaction";
42746
42801
  }
42747
42802
 
42748
42803
  // src/protocols/protocolFee.ts