@t2000/sdk 0.19.2 → 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/README.md +1 -1
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/{index-D-6pQwzx.d.cts → index-B8LxgOk7.d.cts} +2 -0
- package/dist/{index-D-6pQwzx.d.ts → index-B8LxgOk7.d.ts} +2 -0
- package/dist/index.cjs +103 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +103 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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-
|
|
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-
|
|
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';
|
|
@@ -192,7 +192,7 @@ interface TxMetadata {
|
|
|
192
192
|
operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'exchange' | 'rebalance' | 'pay' | 'sentinel' | 'invest' | 'trade';
|
|
193
193
|
amount?: number;
|
|
194
194
|
}
|
|
195
|
-
declare const OUTBOUND_OPS: Set<"save" | "borrow" | "withdraw" | "
|
|
195
|
+
declare const OUTBOUND_OPS: Set<"save" | "borrow" | "withdraw" | "send" | "repay" | "sentinel" | "exchange" | "rebalance" | "pay" | "invest" | "trade">;
|
|
196
196
|
declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
|
|
197
197
|
|
|
198
198
|
declare class SafeguardEnforcer {
|
|
@@ -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-
|
|
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-
|
|
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';
|
|
@@ -192,7 +192,7 @@ interface TxMetadata {
|
|
|
192
192
|
operation: 'send' | 'save' | 'withdraw' | 'borrow' | 'repay' | 'exchange' | 'rebalance' | 'pay' | 'sentinel' | 'invest' | 'trade';
|
|
193
193
|
amount?: number;
|
|
194
194
|
}
|
|
195
|
-
declare const OUTBOUND_OPS: Set<"save" | "borrow" | "withdraw" | "
|
|
195
|
+
declare const OUTBOUND_OPS: Set<"save" | "borrow" | "withdraw" | "send" | "repay" | "sentinel" | "exchange" | "rebalance" | "pay" | "invest" | "trade">;
|
|
196
196
|
declare const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig;
|
|
197
197
|
|
|
198
198
|
declare class SafeguardEnforcer {
|
|
@@ -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
|
@@ -42713,33 +42713,113 @@ async function queryBalance(client, address) {
|
|
|
42713
42713
|
}
|
|
42714
42714
|
|
|
42715
42715
|
// src/wallet/history.ts
|
|
42716
|
+
var SUI_TYPE = "0x2::sui::SUI";
|
|
42717
|
+
var KNOWN_TARGETS = [
|
|
42718
|
+
[/::mpp_charge::/, "mpp payment"],
|
|
42719
|
+
[/::suilend|::obligation/, "lending"],
|
|
42720
|
+
[/::navi|::incentive_v2/, "lending"],
|
|
42721
|
+
[/::cetus|::pool/, "swap"],
|
|
42722
|
+
[/::deepbook/, "swap"],
|
|
42723
|
+
[/::transfer::public_transfer/, "send"]
|
|
42724
|
+
];
|
|
42716
42725
|
async function queryHistory(client, address, limit = 20) {
|
|
42717
42726
|
const txns = await client.queryTransactionBlocks({
|
|
42718
42727
|
filter: { FromAddress: address },
|
|
42719
|
-
options: { showEffects: true, showInput: true },
|
|
42728
|
+
options: { showEffects: true, showInput: true, showBalanceChanges: true },
|
|
42720
42729
|
limit,
|
|
42721
42730
|
order: "descending"
|
|
42722
42731
|
});
|
|
42723
|
-
return txns.data.map((tx) =>
|
|
42724
|
-
|
|
42725
|
-
|
|
42726
|
-
|
|
42727
|
-
|
|
42728
|
-
|
|
42729
|
-
|
|
42730
|
-
|
|
42731
|
-
|
|
42732
|
-
}
|
|
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;
|
|
42765
|
+
}
|
|
42766
|
+
function extractTransferDetails(changes, sender) {
|
|
42767
|
+
if (!changes || changes.length === 0) return {};
|
|
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);
|
|
42770
|
+
const primaryOutflow = outflows.filter((c) => c.coinType !== SUI_TYPE).sort((a, b2) => Number(BigInt(a.amount) - BigInt(b2.amount)))[0] ?? outflows[0];
|
|
42771
|
+
if (!primaryOutflow) return {};
|
|
42772
|
+
const coinType = primaryOutflow.coinType;
|
|
42773
|
+
const decimals = coinType.includes("::usdc::") ? 6 : 9;
|
|
42774
|
+
const amount = Math.abs(Number(BigInt(primaryOutflow.amount))) / 10 ** decimals;
|
|
42775
|
+
const asset = coinType === SUI_TYPE ? "SUI" : coinType.includes("::usdc::") ? "USDC" : coinType.split("::").pop() ?? "unknown";
|
|
42776
|
+
const recipientChange = inflows.find((c) => c.coinType === coinType);
|
|
42777
|
+
const recipient = recipientChange ? resolveOwner(recipientChange.owner) ?? void 0 : void 0;
|
|
42778
|
+
return { amount, asset, recipient };
|
|
42779
|
+
}
|
|
42780
|
+
function extractCommands(txBlock) {
|
|
42781
|
+
const result = { moveCallTargets: [], commandTypes: [] };
|
|
42782
|
+
try {
|
|
42783
|
+
if (!txBlock || typeof txBlock !== "object") return result;
|
|
42784
|
+
const data = "data" in txBlock ? txBlock.data : void 0;
|
|
42785
|
+
if (!data || typeof data !== "object") return result;
|
|
42786
|
+
const inner = "transaction" in data ? data.transaction : void 0;
|
|
42787
|
+
if (!inner || typeof inner !== "object") return result;
|
|
42788
|
+
const commands = "commands" in inner ? inner.commands : void 0;
|
|
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
|
+
}
|
|
42803
|
+
} catch {
|
|
42804
|
+
}
|
|
42805
|
+
return result;
|
|
42733
42806
|
}
|
|
42734
|
-
function
|
|
42735
|
-
|
|
42736
|
-
|
|
42737
|
-
|
|
42738
|
-
|
|
42739
|
-
|
|
42740
|
-
const
|
|
42741
|
-
|
|
42742
|
-
|
|
42807
|
+
function classifyAction(targets, commandTypes, recipient, asset) {
|
|
42808
|
+
for (const target of targets) {
|
|
42809
|
+
for (const [pattern, label] of KNOWN_TARGETS) {
|
|
42810
|
+
if (pattern.test(target)) return label;
|
|
42811
|
+
}
|
|
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";
|
|
42822
|
+
return "transaction";
|
|
42743
42823
|
}
|
|
42744
42824
|
|
|
42745
42825
|
// src/protocols/protocolFee.ts
|
|
@@ -57299,6 +57379,9 @@ To access invested funds: t2000 invest sell ${params.amount} ${asset}`,
|
|
|
57299
57379
|
async history(params) {
|
|
57300
57380
|
return queryHistory(this.client, this._address, params?.limit);
|
|
57301
57381
|
}
|
|
57382
|
+
async transactionDetail(digest) {
|
|
57383
|
+
return queryTransaction(this.client, digest, this._address);
|
|
57384
|
+
}
|
|
57302
57385
|
async deposit() {
|
|
57303
57386
|
return {
|
|
57304
57387
|
address: this._address,
|