@t2000/sdk 0.20.0 → 0.20.1
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.cjs +36 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +36 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -388,6 +388,14 @@ declare function throwIfSimulationFailed(sim: SimulationResult): void;
|
|
|
388
388
|
|
|
389
389
|
declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
|
|
390
390
|
|
|
391
|
+
declare function getSwapQuote(params: {
|
|
392
|
+
walletAddress: string;
|
|
393
|
+
from: string;
|
|
394
|
+
to: string;
|
|
395
|
+
amount: number;
|
|
396
|
+
byAmountIn?: boolean;
|
|
397
|
+
}): Promise<SwapQuoteResult>;
|
|
398
|
+
|
|
391
399
|
type SafeguardRule = 'locked' | 'maxPerTx' | 'maxDailySend';
|
|
392
400
|
interface SafeguardErrorDetails {
|
|
393
401
|
attempted?: number;
|
|
@@ -458,4 +466,4 @@ interface GasStatusResponse {
|
|
|
458
466
|
}
|
|
459
467
|
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
460
468
|
|
|
461
|
-
export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, ClaimRewardsResult, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, UnstakeVSuiResult, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
469
|
+
export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, ClaimRewardsResult, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, UnstakeVSuiResult, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getRates, getSwapQuote, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
package/dist/index.d.ts
CHANGED
|
@@ -388,6 +388,14 @@ declare function throwIfSimulationFailed(sim: SimulationResult): void;
|
|
|
388
388
|
|
|
389
389
|
declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
|
|
390
390
|
|
|
391
|
+
declare function getSwapQuote(params: {
|
|
392
|
+
walletAddress: string;
|
|
393
|
+
from: string;
|
|
394
|
+
to: string;
|
|
395
|
+
amount: number;
|
|
396
|
+
byAmountIn?: boolean;
|
|
397
|
+
}): Promise<SwapQuoteResult>;
|
|
398
|
+
|
|
391
399
|
type SafeguardRule = 'locked' | 'maxPerTx' | 'maxDailySend';
|
|
392
400
|
interface SafeguardErrorDetails {
|
|
393
401
|
attempted?: number;
|
|
@@ -458,4 +466,4 @@ interface GasStatusResponse {
|
|
|
458
466
|
}
|
|
459
467
|
declare function getGasStatus(address?: string): Promise<GasStatusResponse>;
|
|
460
468
|
|
|
461
|
-
export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, ClaimRewardsResult, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, UnstakeVSuiResult, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getRates, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
469
|
+
export { type AutoTopUpResult, BPS_DENOMINATOR, BalanceResponse, BorrowResult, CETUS_USDC_SUI_POOL, CLOCK_ID, ClaimRewardsResult, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, DepositInfo, EarningsResult, type FeeOperation, FundStatusResult, GAS_RESERVE_MIN, type GasExecutionResult, GasMethod, type GasRequestType, type GasSponsorResponse, type GasStatusResponse, HealthFactorResult, KeypairSigner, LendingAdapter, LendingRates, MIST_PER_SUI, MaxBorrowResult, MaxWithdrawResult, OUTBOUND_OPS, PayOptions, PayResult, PendingReward, PositionsResult, type ProtocolFeeInfo, RatesResult, RepayResult, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, type SafeguardConfig, SafeguardEnforcer, SafeguardError, type SafeguardErrorDetails, type SafeguardRule, SaveResult, SendResult, type SimulationResult, type StableAsset, StakeVSuiResult, type SupportedAsset, SwapQuoteResult, SwapResult, T2000, T2000Error, type T2000ErrorCode, type T2000ErrorData, T2000Options, TransactionRecord, type TransactionSigner, type TxMetadata, USDC_DECIMALS, UnstakeVSuiResult, WithdrawResult, type ZkLoginProof, ZkLoginSigner, addCollectFeeToTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getRates, getSwapQuote, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
package/dist/index.js
CHANGED
|
@@ -3167,6 +3167,41 @@ function parseMoveAbort(errorStr) {
|
|
|
3167
3167
|
return { reason: errorStr };
|
|
3168
3168
|
}
|
|
3169
3169
|
|
|
3170
|
-
|
|
3170
|
+
// src/swap-quote.ts
|
|
3171
|
+
async function getSwapQuote(params) {
|
|
3172
|
+
const { findSwapRoute: findSwapRoute2, resolveTokenType: resolveTokenType2, TOKEN_MAP: TOKEN_MAP2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
3173
|
+
const fromType = resolveTokenType2(params.from);
|
|
3174
|
+
const toType = resolveTokenType2(params.to);
|
|
3175
|
+
if (!fromType) throw new Error(`Unknown token: ${params.from}. Provide the full coin type.`);
|
|
3176
|
+
if (!toType) throw new Error(`Unknown token: ${params.to}. Provide the full coin type.`);
|
|
3177
|
+
const byAmountIn = params.byAmountIn ?? true;
|
|
3178
|
+
const fromEntry = Object.values(TOKEN_MAP2).includes(fromType) ? Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === fromType) : null;
|
|
3179
|
+
const fromDecimals = fromEntry ? fromEntry[1].decimals : fromType === "0x2::sui::SUI" ? 9 : 6;
|
|
3180
|
+
const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
|
|
3181
|
+
const route = await findSwapRoute2({
|
|
3182
|
+
walletAddress: params.walletAddress,
|
|
3183
|
+
from: fromType,
|
|
3184
|
+
to: toType,
|
|
3185
|
+
amount: rawAmount,
|
|
3186
|
+
byAmountIn
|
|
3187
|
+
});
|
|
3188
|
+
if (!route) throw new Error(`No swap route found for ${params.from} -> ${params.to}.`);
|
|
3189
|
+
if (route.insufficientLiquidity) throw new Error(`Insufficient liquidity for ${params.from} -> ${params.to}.`);
|
|
3190
|
+
const toEntry = Object.entries(SUPPORTED_ASSETS).find(([, v]) => v.type === toType);
|
|
3191
|
+
const toDecimals = toEntry ? toEntry[1].decimals : toType === "0x2::sui::SUI" ? 9 : 6;
|
|
3192
|
+
const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
|
|
3193
|
+
const toAmount = Number(route.amountOut) / 10 ** toDecimals;
|
|
3194
|
+
const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
|
|
3195
|
+
return {
|
|
3196
|
+
fromToken: params.from,
|
|
3197
|
+
toToken: params.to,
|
|
3198
|
+
fromAmount,
|
|
3199
|
+
toAmount,
|
|
3200
|
+
priceImpact: route.priceImpact,
|
|
3201
|
+
route: routeDesc
|
|
3202
|
+
};
|
|
3203
|
+
}
|
|
3204
|
+
|
|
3205
|
+
export { BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, GAS_RESERVE_MIN, KeypairSigner, MIST_PER_SUI, NaviAdapter, OUTBOUND_OPS, ProtocolRegistry, STABLE_ASSETS, SUI_DECIMALS, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, USDC_DECIMALS, ZkLoginSigner, addCollectFeeToTx, allDescriptors, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getGasStatus, getRates, getSwapQuote, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, rawToStable, rawToUsdc, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
3171
3206
|
//# sourceMappingURL=index.js.map
|
|
3172
3207
|
//# sourceMappingURL=index.js.map
|