@t2000/sdk 0.19.16 → 0.19.19
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 +4 -4
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/{index-Br3apJsB.d.cts → index-DAxuyiS2.d.cts} +7 -7
- package/dist/{index-Br3apJsB.d.ts → index-DAxuyiS2.d.ts} +7 -7
- package/dist/index.cjs +32 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -8
- package/dist/index.d.ts +9 -8
- package/dist/index.js +32 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TransactionSigner, I as
|
|
2
|
-
export { K as AdapterCapability, N as AdapterPositions, O as AdapterTxResult, Q as AssetRates, U as CetusAdapter, V as GasReserve, X as HealthInfo, Y as InvestRebalanceMove, Z as NaviAdapter, _ as PerpsAdapter, $ as PerpsPosition, a0 as
|
|
1
|
+
import { T as TransactionSigner, I as InvestmentRecord, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, b as T2000Options, P as PayOptions, c as PayResult, d as SendResult, B as BalanceResponse, e as TransactionRecord, D as DepositInfo, L as LendingAdapter, f as SwapAdapter, g as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, h as BorrowResult, R as RepayResult, i as MaxBorrowResult, H as HealthFactorResult, j as SwapResult, k as InvestResult, l as InvestEarnResult, m as InvestRebalanceResult, n as PendingReward, C as ClaimRewardsResult, o as StrategyBuyResult, p as StrategySellResult, q as StrategyRebalanceResult, r as StrategyStatusResult, s as AutoInvestRunResult, t as PortfolioResult, u as InvestmentPosition, v as PositionsResult, w as RatesResult, x as LendingRates, y as RebalanceResult, E as EarningsResult, F as FundStatusResult, z as SentinelAgent, G as SentinelAttackResult, J as GasMethod } from './index-DAxuyiS2.cjs';
|
|
2
|
+
export { K as AdapterCapability, N as AdapterPositions, O as AdapterTxResult, Q as AssetRates, U as CetusAdapter, V as GasReserve, X as HealthInfo, Y as InvestRebalanceMove, Z as NaviAdapter, _ as PerpsAdapter, $ as PerpsPosition, a0 as PerpsPositionsResult, a1 as PerpsTradeResult, a2 as PositionEntry, a3 as PositionSide, a4 as ProtocolDescriptor, a5 as ProtocolRegistry, a6 as RebalanceStep, a7 as SentinelVerdict, a8 as SuilendAdapter, a9 as SwapQuote, aa as allDescriptors, ab as cetusDescriptor, ac as getSentinelInfo, ad as listSentinels, ae as naviDescriptor, af as requestAttack, ag as sentinelAttack, ah as sentinelDescriptor, ai as settleAttack, aj as submitPrompt, ak as suilendDescriptor } from './index-DAxuyiS2.cjs';
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
@@ -267,7 +267,7 @@ interface StoredPosition {
|
|
|
267
267
|
totalAmount: number;
|
|
268
268
|
costBasis: number;
|
|
269
269
|
avgPrice: number;
|
|
270
|
-
trades:
|
|
270
|
+
trades: InvestmentRecord[];
|
|
271
271
|
earning?: boolean;
|
|
272
272
|
earningProtocol?: string;
|
|
273
273
|
earningApy?: number;
|
|
@@ -279,8 +279,8 @@ declare class PortfolioManager {
|
|
|
279
279
|
constructor(configDir?: string);
|
|
280
280
|
private load;
|
|
281
281
|
private save;
|
|
282
|
-
recordBuy(trade:
|
|
283
|
-
recordSell(trade:
|
|
282
|
+
recordBuy(trade: InvestmentRecord): void;
|
|
283
|
+
recordSell(trade: InvestmentRecord): number;
|
|
284
284
|
getPosition(asset: string): StoredPosition | undefined;
|
|
285
285
|
getPositions(): Array<{
|
|
286
286
|
asset: string;
|
|
@@ -293,8 +293,8 @@ declare class PortfolioManager {
|
|
|
293
293
|
closePosition(asset: string): void;
|
|
294
294
|
isEarning(asset: string): boolean;
|
|
295
295
|
getRealizedPnL(): number;
|
|
296
|
-
recordStrategyBuy(strategyKey: string, trade:
|
|
297
|
-
recordStrategySell(strategyKey: string, trade:
|
|
296
|
+
recordStrategyBuy(strategyKey: string, trade: InvestmentRecord): void;
|
|
297
|
+
recordStrategySell(strategyKey: string, trade: InvestmentRecord): number;
|
|
298
298
|
getStrategyPositions(strategyKey: string): Array<{
|
|
299
299
|
asset: string;
|
|
300
300
|
} & StoredPosition>;
|
|
@@ -480,6 +480,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
480
480
|
to: string;
|
|
481
481
|
amount: number;
|
|
482
482
|
maxSlippage?: number;
|
|
483
|
+
_skipPortfolioRecord?: boolean;
|
|
483
484
|
}): Promise<SwapResult>;
|
|
484
485
|
swapQuote(params: {
|
|
485
486
|
from: string;
|
|
@@ -737,4 +738,4 @@ interface GasStatusResponse {
|
|
|
737
738
|
}
|
|
738
739
|
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
739
740
|
|
|
740
|
-
export { AutoInvestManager, AutoInvestRunResult, AutoInvestSchedule, AutoInvestStatus, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, ClaimRewardsResult, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestEarnResult, InvestRebalanceResult, InvestResult, type InvestmentAsset, InvestmentPosition,
|
|
741
|
+
export { AutoInvestManager, AutoInvestRunResult, AutoInvestSchedule, AutoInvestStatus, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, ClaimRewardsResult, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestEarnResult, InvestRebalanceResult, InvestResult, type InvestmentAsset, InvestmentPosition, InvestmentRecord, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PERPS_MARKETS, PayOptions, PayResult, PendingReward, type PerpsMarket, PortfolioManager, PortfolioResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type StableAsset, StrategyBuyResult, StrategyDefinition, StrategyManager, StrategyRebalanceResult, StrategySellResult, StrategyStatusResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, TransactionSigner, type TxMetadata, USDC_DECIMALS, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { T as TransactionSigner, I as
|
|
2
|
-
export { K as AdapterCapability, N as AdapterPositions, O as AdapterTxResult, Q as AssetRates, U as CetusAdapter, V as GasReserve, X as HealthInfo, Y as InvestRebalanceMove, Z as NaviAdapter, _ as PerpsAdapter, $ as PerpsPosition, a0 as
|
|
1
|
+
import { T as TransactionSigner, I as InvestmentRecord, S as StrategyDefinition, A as AutoInvestSchedule, a as AutoInvestStatus, b as T2000Options, P as PayOptions, c as PayResult, d as SendResult, B as BalanceResponse, e as TransactionRecord, D as DepositInfo, L as LendingAdapter, f as SwapAdapter, g as SaveResult, W as WithdrawResult, M as MaxWithdrawResult, h as BorrowResult, R as RepayResult, i as MaxBorrowResult, H as HealthFactorResult, j as SwapResult, k as InvestResult, l as InvestEarnResult, m as InvestRebalanceResult, n as PendingReward, C as ClaimRewardsResult, o as StrategyBuyResult, p as StrategySellResult, q as StrategyRebalanceResult, r as StrategyStatusResult, s as AutoInvestRunResult, t as PortfolioResult, u as InvestmentPosition, v as PositionsResult, w as RatesResult, x as LendingRates, y as RebalanceResult, E as EarningsResult, F as FundStatusResult, z as SentinelAgent, G as SentinelAttackResult, J as GasMethod } from './index-DAxuyiS2.js';
|
|
2
|
+
export { K as AdapterCapability, N as AdapterPositions, O as AdapterTxResult, Q as AssetRates, U as CetusAdapter, V as GasReserve, X as HealthInfo, Y as InvestRebalanceMove, Z as NaviAdapter, _ as PerpsAdapter, $ as PerpsPosition, a0 as PerpsPositionsResult, a1 as PerpsTradeResult, a2 as PositionEntry, a3 as PositionSide, a4 as ProtocolDescriptor, a5 as ProtocolRegistry, a6 as RebalanceStep, a7 as SentinelVerdict, a8 as SuilendAdapter, a9 as SwapQuote, aa as allDescriptors, ab as cetusDescriptor, ac as getSentinelInfo, ad as listSentinels, ae as naviDescriptor, af as requestAttack, ag as sentinelAttack, ah as sentinelDescriptor, ai as settleAttack, aj as submitPrompt, ak as suilendDescriptor } from './index-DAxuyiS2.js';
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
@@ -267,7 +267,7 @@ interface StoredPosition {
|
|
|
267
267
|
totalAmount: number;
|
|
268
268
|
costBasis: number;
|
|
269
269
|
avgPrice: number;
|
|
270
|
-
trades:
|
|
270
|
+
trades: InvestmentRecord[];
|
|
271
271
|
earning?: boolean;
|
|
272
272
|
earningProtocol?: string;
|
|
273
273
|
earningApy?: number;
|
|
@@ -279,8 +279,8 @@ declare class PortfolioManager {
|
|
|
279
279
|
constructor(configDir?: string);
|
|
280
280
|
private load;
|
|
281
281
|
private save;
|
|
282
|
-
recordBuy(trade:
|
|
283
|
-
recordSell(trade:
|
|
282
|
+
recordBuy(trade: InvestmentRecord): void;
|
|
283
|
+
recordSell(trade: InvestmentRecord): number;
|
|
284
284
|
getPosition(asset: string): StoredPosition | undefined;
|
|
285
285
|
getPositions(): Array<{
|
|
286
286
|
asset: string;
|
|
@@ -293,8 +293,8 @@ declare class PortfolioManager {
|
|
|
293
293
|
closePosition(asset: string): void;
|
|
294
294
|
isEarning(asset: string): boolean;
|
|
295
295
|
getRealizedPnL(): number;
|
|
296
|
-
recordStrategyBuy(strategyKey: string, trade:
|
|
297
|
-
recordStrategySell(strategyKey: string, trade:
|
|
296
|
+
recordStrategyBuy(strategyKey: string, trade: InvestmentRecord): void;
|
|
297
|
+
recordStrategySell(strategyKey: string, trade: InvestmentRecord): number;
|
|
298
298
|
getStrategyPositions(strategyKey: string): Array<{
|
|
299
299
|
asset: string;
|
|
300
300
|
} & StoredPosition>;
|
|
@@ -480,6 +480,7 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
480
480
|
to: string;
|
|
481
481
|
amount: number;
|
|
482
482
|
maxSlippage?: number;
|
|
483
|
+
_skipPortfolioRecord?: boolean;
|
|
483
484
|
}): Promise<SwapResult>;
|
|
484
485
|
swapQuote(params: {
|
|
485
486
|
from: string;
|
|
@@ -737,4 +738,4 @@ interface GasStatusResponse {
|
|
|
737
738
|
}
|
|
738
739
|
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
739
740
|
|
|
740
|
-
export { AutoInvestManager, AutoInvestRunResult, AutoInvestSchedule, AutoInvestStatus, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, ClaimRewardsResult, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestEarnResult, InvestRebalanceResult, InvestResult, type InvestmentAsset, InvestmentPosition,
|
|
741
|
+
export { AutoInvestManager, AutoInvestRunResult, AutoInvestSchedule, AutoInvestStatus, type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CLOCK_ID, ClaimRewardsResult, type Contact, ContactManager, type ContactMap, DEFAULT_MAX_LEVERAGE, DEFAULT_MAX_POSITION_SIZE, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DEFAULT_STRATEGIES, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, INVESTMENT_ASSETS, InvestEarnResult, InvestRebalanceResult, InvestResult, type InvestmentAsset, InvestmentPosition, InvestmentRecord, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PERPS_MARKETS, PayOptions, PayResult, PendingReward, type PerpsMarket, PortfolioManager, PortfolioResult, PositionsResult, type ProtocolFeeInfo, RatesResult, RebalanceResult, RepayResult, SENTINEL, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, SentinelAgent, SentinelAttackResult, type SimulationResult, type StableAsset, StrategyBuyResult, StrategyDefinition, StrategyManager, StrategyRebalanceResult, StrategySellResult, StrategyStatusResult, type SupportedAsset, SwapAdapter, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, TransactionSigner, type TxMetadata, USDC_DECIMALS, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getPoolPrice, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
package/dist/index.js
CHANGED
|
@@ -4413,6 +4413,34 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
4413
4413
|
const priceImpact = expectedOutput > 0 ? Math.abs(actualReceived - expectedOutput) / expectedOutput : 0;
|
|
4414
4414
|
reportFee(this._address, "swap", fee.amount, fee.rate, gasResult.digest);
|
|
4415
4415
|
this.emitBalanceChange(fromAsset, swapAmount, "swap", gasResult.digest);
|
|
4416
|
+
const stableSet = new Set(STABLE_ASSETS);
|
|
4417
|
+
if (!params._skipPortfolioRecord && stableSet.has(fromAsset) && toAsset in INVESTMENT_ASSETS && actualReceived > 0) {
|
|
4418
|
+
const price = swapAmount / actualReceived;
|
|
4419
|
+
this.portfolio.recordBuy({
|
|
4420
|
+
id: `swap_${Date.now()}`,
|
|
4421
|
+
type: "buy",
|
|
4422
|
+
asset: toAsset,
|
|
4423
|
+
amount: actualReceived,
|
|
4424
|
+
price,
|
|
4425
|
+
usdValue: swapAmount,
|
|
4426
|
+
fee: fee.amount,
|
|
4427
|
+
tx: gasResult.digest,
|
|
4428
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4429
|
+
});
|
|
4430
|
+
} else if (!params._skipPortfolioRecord && fromAsset in INVESTMENT_ASSETS && stableSet.has(toAsset) && actualReceived > 0) {
|
|
4431
|
+
const price = actualReceived / swapAmount;
|
|
4432
|
+
this.portfolio.recordSell({
|
|
4433
|
+
id: `swap_${Date.now()}`,
|
|
4434
|
+
type: "sell",
|
|
4435
|
+
asset: fromAsset,
|
|
4436
|
+
amount: swapAmount,
|
|
4437
|
+
price,
|
|
4438
|
+
usdValue: actualReceived,
|
|
4439
|
+
fee: fee.amount,
|
|
4440
|
+
tx: gasResult.digest,
|
|
4441
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
4442
|
+
});
|
|
4443
|
+
}
|
|
4416
4444
|
return {
|
|
4417
4445
|
success: true,
|
|
4418
4446
|
tx: gasResult.digest,
|
|
@@ -4470,7 +4498,8 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
4470
4498
|
from: "USDC",
|
|
4471
4499
|
to: params.asset,
|
|
4472
4500
|
amount: params.usdAmount,
|
|
4473
|
-
maxSlippage: params.maxSlippage ?? defaultSlippage(params.asset)
|
|
4501
|
+
maxSlippage: params.maxSlippage ?? defaultSlippage(params.asset),
|
|
4502
|
+
_skipPortfolioRecord: true
|
|
4474
4503
|
});
|
|
4475
4504
|
break;
|
|
4476
4505
|
} catch (err) {
|
|
@@ -4590,7 +4619,8 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
4590
4619
|
from: params.asset,
|
|
4591
4620
|
to: "USDC",
|
|
4592
4621
|
amount: sellAmountAsset,
|
|
4593
|
-
maxSlippage: params.maxSlippage ?? defaultSlippage(params.asset)
|
|
4622
|
+
maxSlippage: params.maxSlippage ?? defaultSlippage(params.asset),
|
|
4623
|
+
_skipPortfolioRecord: true
|
|
4594
4624
|
});
|
|
4595
4625
|
break;
|
|
4596
4626
|
} catch (err) {
|