@t2000/sdk 0.19.3 → 0.19.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/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, P as PayOptions, b as PayResult, c as SendResult, B as BalanceResponse, d as TransactionRecord, D as DepositInfo, L as LendingAdapter, e as SwapAdapter, f as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, g as BorrowResult, R as RepayResult, h as MaxBorrowResult, H as HealthFactorResult, i as SwapResult, j as InvestResult, k as InvestEarnResult, l as InvestRebalanceResult, m as PendingReward, C as ClaimRewardsResult, n as StrategyBuyResult, o as StrategySellResult, p as StrategyRebalanceResult, q as StrategyStatusResult, r as AutoInvestRunResult, s as PortfolioResult, t as InvestmentPosition, u as PositionsResult, v as RatesResult, w as LendingRates, x as RebalanceResult, E as EarningsResult, F as FundStatusResult, y as SentinelAgent, z as SentinelAttackResult, G as GasMethod } from './index-CcTPxTBs.cjs';
2
- export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, O as AssetRates, Q as CetusAdapter, U as GasReserve, V as HealthInfo, X as InvestRebalanceMove, Y as NaviAdapter, Z as PerpsAdapter, _ as PerpsPosition, $ as PositionEntry, a0 as PositionSide, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a3 as RebalanceStep, a4 as SentinelVerdict, a5 as SuilendAdapter, a6 as SwapQuote, a7 as TradePositionsResult, a8 as TradeResult, a9 as allDescriptors, aa as cetusDescriptor, ab as getSentinelInfo, ac as listSentinels, ad as naviDescriptor, ae as requestAttack, af as sentinelAttack, ag as sentinelDescriptor, ah as settleAttack, ai as submitPrompt, aj as suilendDescriptor } from './index-CcTPxTBs.cjs';
1
+ import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, P as PayOptions, b as PayResult, c as SendResult, B as BalanceResponse, d as TransactionRecord, D as DepositInfo, L as LendingAdapter, e as SwapAdapter, f as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, g as BorrowResult, R as RepayResult, h as MaxBorrowResult, H as HealthFactorResult, i as SwapResult, j as InvestResult, k as InvestEarnResult, l as InvestRebalanceResult, m as PendingReward, C as ClaimRewardsResult, n as StrategyBuyResult, o as StrategySellResult, p as StrategyRebalanceResult, q as StrategyStatusResult, r as AutoInvestRunResult, s as PortfolioResult, t as InvestmentPosition, u as PositionsResult, v as RatesResult, w as LendingRates, x as RebalanceResult, E as EarningsResult, F as FundStatusResult, y as SentinelAgent, z as SentinelAttackResult, G as GasMethod } from './index-B8LxgOk7.cjs';
2
+ export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, O as AssetRates, Q as CetusAdapter, U as GasReserve, V as HealthInfo, X as InvestRebalanceMove, Y as NaviAdapter, Z as PerpsAdapter, _ as PerpsPosition, $ as PositionEntry, a0 as PositionSide, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a3 as RebalanceStep, a4 as SentinelVerdict, a5 as SuilendAdapter, a6 as SwapQuote, a7 as TradePositionsResult, a8 as TradeResult, a9 as allDescriptors, aa as cetusDescriptor, ab as getSentinelInfo, ac as listSentinels, ad as naviDescriptor, ae as requestAttack, af as sentinelAttack, ag as sentinelDescriptor, ah as settleAttack, ai as submitPrompt, aj as suilendDescriptor } from './index-B8LxgOk7.cjs';
3
3
  import { EventEmitter } from 'eventemitter3';
4
4
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
5
5
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
@@ -396,6 +396,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
396
396
  history(params?: {
397
397
  limit?: number;
398
398
  }): Promise<TransactionRecord[]>;
399
+ transactionDetail(digest: string): Promise<TransactionRecord | null>;
399
400
  deposit(): Promise<DepositInfo>;
400
401
  exportKey(): string;
401
402
  registerAdapter(adapter: LendingAdapter | SwapAdapter): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, P as PayOptions, b as PayResult, c as SendResult, B as BalanceResponse, d as TransactionRecord, D as DepositInfo, L as LendingAdapter, e as SwapAdapter, f as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, g as BorrowResult, R as RepayResult, h as MaxBorrowResult, H as HealthFactorResult, i as SwapResult, j as InvestResult, k as InvestEarnResult, l as InvestRebalanceResult, m as PendingReward, C as ClaimRewardsResult, n as StrategyBuyResult, o as StrategySellResult, p as StrategyRebalanceResult, q as StrategyStatusResult, r as AutoInvestRunResult, s as PortfolioResult, t as InvestmentPosition, u as PositionsResult, v as RatesResult, w as LendingRates, x as RebalanceResult, E as EarningsResult, F as FundStatusResult, y as SentinelAgent, z as SentinelAttackResult, G as GasMethod } from './index-CcTPxTBs.js';
2
- export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, O as AssetRates, Q as CetusAdapter, U as GasReserve, V as HealthInfo, X as InvestRebalanceMove, Y as NaviAdapter, Z as PerpsAdapter, _ as PerpsPosition, $ as PositionEntry, a0 as PositionSide, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a3 as RebalanceStep, a4 as SentinelVerdict, a5 as SuilendAdapter, a6 as SwapQuote, a7 as TradePositionsResult, a8 as TradeResult, a9 as allDescriptors, aa as cetusDescriptor, ab as getSentinelInfo, ac as listSentinels, ad as naviDescriptor, ae as requestAttack, af as sentinelAttack, ag as sentinelDescriptor, ah as settleAttack, ai as submitPrompt, aj as suilendDescriptor } from './index-CcTPxTBs.js';
1
+ import { I as InvestmentTrade, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, T as T2000Options, P as PayOptions, b as PayResult, c as SendResult, B as BalanceResponse, d as TransactionRecord, D as DepositInfo, L as LendingAdapter, e as SwapAdapter, f as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, g as BorrowResult, R as RepayResult, h as MaxBorrowResult, H as HealthFactorResult, i as SwapResult, j as InvestResult, k as InvestEarnResult, l as InvestRebalanceResult, m as PendingReward, C as ClaimRewardsResult, n as StrategyBuyResult, o as StrategySellResult, p as StrategyRebalanceResult, q as StrategyStatusResult, r as AutoInvestRunResult, s as PortfolioResult, t as InvestmentPosition, u as PositionsResult, v as RatesResult, w as LendingRates, x as RebalanceResult, E as EarningsResult, F as FundStatusResult, y as SentinelAgent, z as SentinelAttackResult, G as GasMethod } from './index-B8LxgOk7.js';
2
+ export { J as AdapterCapability, K as AdapterPositions, N as AdapterTxResult, O as AssetRates, Q as CetusAdapter, U as GasReserve, V as HealthInfo, X as InvestRebalanceMove, Y as NaviAdapter, Z as PerpsAdapter, _ as PerpsPosition, $ as PositionEntry, a0 as PositionSide, a1 as ProtocolDescriptor, a2 as ProtocolRegistry, a3 as RebalanceStep, a4 as SentinelVerdict, a5 as SuilendAdapter, a6 as SwapQuote, a7 as TradePositionsResult, a8 as TradeResult, a9 as allDescriptors, aa as cetusDescriptor, ab as getSentinelInfo, ac as listSentinels, ad as naviDescriptor, ae as requestAttack, af as sentinelAttack, ag as sentinelDescriptor, ah as settleAttack, ai as submitPrompt, aj as suilendDescriptor } from './index-B8LxgOk7.js';
3
3
  import { EventEmitter } from 'eventemitter3';
4
4
  import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
5
5
  import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
@@ -396,6 +396,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
396
396
  history(params?: {
397
397
  limit?: number;
398
398
  }): Promise<TransactionRecord[]>;
399
+ transactionDetail(digest: string): Promise<TransactionRecord | null>;
399
400
  deposit(): Promise<DepositInfo>;
400
401
  exportKey(): string;
401
402
  registerAdapter(adapter: LendingAdapter | SwapAdapter): Promise<void>;
package/dist/index.js CHANGED
@@ -42720,8 +42720,7 @@ var KNOWN_TARGETS = [
42720
42720
  [/::navi|::incentive_v2/, "lending"],
42721
42721
  [/::cetus|::pool/, "swap"],
42722
42722
  [/::deepbook/, "swap"],
42723
- [/::transfer::public_transfer/, "send"],
42724
- [/::coin::split/, "split"]
42723
+ [/::transfer::public_transfer/, "send"]
42725
42724
  ];
42726
42725
  async function queryHistory(client, address, limit = 20) {
42727
42726
  const txns = await client.queryTransactionBlocks({
@@ -42730,36 +42729,44 @@ async function queryHistory(client, address, limit = 20) {
42730
42729
  limit,
42731
42730
  order: "descending"
42732
42731
  });
42733
- return txns.data.map((tx) => {
42734
- const gasUsed = tx.effects?.gasUsed;
42735
- const gasCost = gasUsed ? (Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate)) / 1e9 : void 0;
42736
- const targets = extractMoveCallTargets(tx.transaction);
42737
- const action = classifyAction(targets);
42738
- const { amount, asset, recipient } = extractTransferDetails(
42739
- tx.balanceChanges,
42740
- address
42741
- );
42742
- return {
42743
- digest: tx.digest,
42744
- action,
42745
- amount,
42746
- asset,
42747
- recipient,
42748
- timestamp: Number(tx.timestampMs ?? 0),
42749
- gasCost
42750
- };
42751
- });
42732
+ return txns.data.map((tx) => parseTxRecord(tx, address));
42733
+ }
42734
+ async function queryTransaction(client, digest, senderAddress) {
42735
+ try {
42736
+ const tx = await client.getTransactionBlock({
42737
+ digest,
42738
+ options: { showEffects: true, showInput: true, showBalanceChanges: true }
42739
+ });
42740
+ return parseTxRecord(tx, senderAddress);
42741
+ } catch {
42742
+ return null;
42743
+ }
42744
+ }
42745
+ function parseTxRecord(tx, address) {
42746
+ const gasUsed = tx.effects?.gasUsed;
42747
+ const gasCost = gasUsed ? (Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate)) / 1e9 : void 0;
42748
+ const { moveCallTargets, commandTypes } = extractCommands(tx.transaction);
42749
+ const { amount, asset, recipient } = extractTransferDetails(tx.balanceChanges, address);
42750
+ const action = classifyAction(moveCallTargets, commandTypes, recipient, asset);
42751
+ return {
42752
+ digest: tx.digest,
42753
+ action,
42754
+ amount,
42755
+ asset,
42756
+ recipient,
42757
+ timestamp: Number(tx.timestampMs ?? 0),
42758
+ gasCost
42759
+ };
42760
+ }
42761
+ function resolveOwner(owner) {
42762
+ if (typeof owner === "object" && owner.AddressOwner) return owner.AddressOwner;
42763
+ if (typeof owner === "string") return owner;
42764
+ return null;
42752
42765
  }
42753
42766
  function extractTransferDetails(changes, sender) {
42754
42767
  if (!changes || changes.length === 0) return {};
42755
- const outflows = changes.filter((c) => {
42756
- const owner = typeof c.owner === "object" && c.owner.AddressOwner ? c.owner.AddressOwner : typeof c.owner === "string" ? c.owner : null;
42757
- return owner === sender && BigInt(c.amount) < 0n;
42758
- });
42759
- const inflows = changes.filter((c) => {
42760
- const owner = typeof c.owner === "object" && c.owner.AddressOwner ? c.owner.AddressOwner : typeof c.owner === "string" ? c.owner : null;
42761
- return owner !== sender && BigInt(c.amount) > 0n;
42762
- });
42768
+ const outflows = changes.filter((c) => resolveOwner(c.owner) === sender && BigInt(c.amount) < 0n);
42769
+ const inflows = changes.filter((c) => resolveOwner(c.owner) !== sender && BigInt(c.amount) > 0n);
42763
42770
  const primaryOutflow = outflows.filter((c) => c.coinType !== SUI_TYPE).sort((a, b2) => Number(BigInt(a.amount) - BigInt(b2.amount)))[0] ?? outflows[0];
42764
42771
  if (!primaryOutflow) return {};
42765
42772
  const coinType = primaryOutflow.coinType;
@@ -42767,33 +42774,51 @@ function extractTransferDetails(changes, sender) {
42767
42774
  const amount = Math.abs(Number(BigInt(primaryOutflow.amount))) / 10 ** decimals;
42768
42775
  const asset = coinType === SUI_TYPE ? "SUI" : coinType.includes("::usdc::") ? "USDC" : coinType.split("::").pop() ?? "unknown";
42769
42776
  const recipientChange = inflows.find((c) => c.coinType === coinType);
42770
- const recipient = recipientChange ? typeof recipientChange.owner === "object" && recipientChange.owner.AddressOwner ? recipientChange.owner.AddressOwner : void 0 : void 0;
42777
+ const recipient = recipientChange ? resolveOwner(recipientChange.owner) ?? void 0 : void 0;
42771
42778
  return { amount, asset, recipient };
42772
42779
  }
42773
- function extractMoveCallTargets(txBlock) {
42780
+ function extractCommands(txBlock) {
42781
+ const result = { moveCallTargets: [], commandTypes: [] };
42774
42782
  try {
42775
- if (!txBlock || typeof txBlock !== "object") return [];
42783
+ if (!txBlock || typeof txBlock !== "object") return result;
42776
42784
  const data = "data" in txBlock ? txBlock.data : void 0;
42777
- if (!data || typeof data !== "object") return [];
42785
+ if (!data || typeof data !== "object") return result;
42778
42786
  const inner = "transaction" in data ? data.transaction : void 0;
42779
- if (!inner || typeof inner !== "object") return [];
42787
+ if (!inner || typeof inner !== "object") return result;
42780
42788
  const commands = "commands" in inner ? inner.commands : void 0;
42781
- if (!Array.isArray(commands)) return [];
42782
- return commands.filter((c) => c.MoveCall).map((c) => {
42783
- const mc = c.MoveCall;
42784
- return `${mc.package}::${mc.module}::${mc.function}`;
42785
- });
42789
+ if (!Array.isArray(commands)) return result;
42790
+ for (const cmd of commands) {
42791
+ if (cmd.MoveCall) {
42792
+ const mc = cmd.MoveCall;
42793
+ result.moveCallTargets.push(`${mc.package}::${mc.module}::${mc.function}`);
42794
+ result.commandTypes.push("MoveCall");
42795
+ } else if (cmd.TransferObjects) {
42796
+ result.commandTypes.push("TransferObjects");
42797
+ } else if (cmd.SplitCoins) {
42798
+ result.commandTypes.push("SplitCoins");
42799
+ } else if (cmd.MergeCoins) {
42800
+ result.commandTypes.push("MergeCoins");
42801
+ }
42802
+ }
42786
42803
  } catch {
42787
- return [];
42788
42804
  }
42805
+ return result;
42789
42806
  }
42790
- function classifyAction(targets) {
42791
- if (targets.length === 0) return "transaction";
42807
+ function classifyAction(targets, commandTypes, recipient, asset) {
42792
42808
  for (const target of targets) {
42793
42809
  for (const [pattern, label] of KNOWN_TARGETS) {
42794
42810
  if (pattern.test(target)) return label;
42795
42811
  }
42796
42812
  }
42813
+ const hasTransfer = commandTypes.includes("TransferObjects");
42814
+ const hasSplit = commandTypes.includes("SplitCoins");
42815
+ const hasMoveCall = commandTypes.includes("MoveCall");
42816
+ if (hasTransfer && !hasMoveCall && recipient) {
42817
+ if (asset === "USDC" && hasSplit) return "send";
42818
+ return "send";
42819
+ }
42820
+ if (hasMoveCall) return "transaction";
42821
+ if (hasTransfer) return "send";
42797
42822
  return "transaction";
42798
42823
  }
42799
42824
 
@@ -57354,6 +57379,9 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
57354
57379
  async history(params) {
57355
57380
  return queryHistory(this.client, this._address, params?.limit);
57356
57381
  }
57382
+ async transactionDetail(digest) {
57383
+ return queryTransaction(this.client, digest, this._address);
57384
+ }
57357
57385
  async deposit() {
57358
57386
  return {
57359
57387
  address: this._address,