@t2000/sdk 10.8.0 → 10.9.0
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 +47 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/index.js +46 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1250,4 +1250,37 @@ declare const CETUS_POSITION_TYPE: string;
|
|
|
1250
1250
|
*/
|
|
1251
1251
|
declare const AGENT_POOL_TICK_SPACING = 200;
|
|
1252
1252
|
|
|
1253
|
-
|
|
1253
|
+
/**
|
|
1254
|
+
* Direct-pool swap for agent tokens (S.815). The Cetus AGGREGATOR does not
|
|
1255
|
+
* route fresh pools (probed 2026-07-25: "available path is empty" for $FS),
|
|
1256
|
+
* so agent-token trading swaps DIRECTLY against the token's known pool via
|
|
1257
|
+
* the integrate package's `pool_script::swap_a2b/b2a` entry — works from
|
|
1258
|
+
* minute zero for every launch. Quote = a server-side simulation of the
|
|
1259
|
+
* same transaction (the sim IS the price; no math to drift).
|
|
1260
|
+
*
|
|
1261
|
+
* Verified by mainnet simulation both directions on the $FS pool.
|
|
1262
|
+
*/
|
|
1263
|
+
/** Cetus `integrate` latest published-at (mainnet, MVR v16 — their docs
|
|
1264
|
+
* address table). The older ids fail the clmm version gate. */
|
|
1265
|
+
declare const CETUS_INTEGRATE_PUBLISHED_AT: string;
|
|
1266
|
+
interface DirectPoolSwapArgs {
|
|
1267
|
+
client: SuiCoreClient;
|
|
1268
|
+
/** The swapper (signs + receives output; pays own gas — unsponsored). */
|
|
1269
|
+
sender: string;
|
|
1270
|
+
/** The agent token's Cetus pool (from the AgentToken record). */
|
|
1271
|
+
poolId: string;
|
|
1272
|
+
/** buy = USDC → AGENT · sell = AGENT → USDC. */
|
|
1273
|
+
direction: 'buy' | 'sell';
|
|
1274
|
+
/** Raw input amount (USDC 6dp for buy; token 6dp for sell). */
|
|
1275
|
+
amountIn: bigint;
|
|
1276
|
+
/** Raw minimum output — slippage floor; 0n when simulating for a quote. */
|
|
1277
|
+
minOut: bigint;
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Build the unsigned direct-pool swap. Reads the pool's `Pool<A, B>` type
|
|
1281
|
+
* args (pair orientation is whatever Cetus canonicalized at creation) and
|
|
1282
|
+
* picks `swap_a2b` / `swap_b2a` so input→output matches `direction`.
|
|
1283
|
+
*/
|
|
1284
|
+
declare function buildDirectPoolSwapTx(args: DirectPoolSwapArgs): Promise<Transaction>;
|
|
1285
|
+
|
|
1286
|
+
export { AGENT_CAPITAL_PACKAGE_ID, AGENT_CAPITAL_PUBLISHED_AT, AGENT_ID_PARENT, AGENT_ID_PARENT_NAME, AGENT_ID_PARENT_NFT_ID, AGENT_POOL_TICK_SPACING, AGENT_TOKEN_DECIMALS, AGENT_TOKEN_LP_ALLOCATION, AGENT_TOKEN_TOTAL_SUPPLY, AGENT_TOKEN_TREASURY_ALLOCATION, AUDRIC_PARENT, AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, type AgentCoinModule, type AgentCoinParams, type ApiModel, type AppenderContext, BalanceResponse, type BuildAddLeafParams, type BuildRevokeLeafParams, CAPITAL_REGISTRY_ID, CAPITAL_REGISTRY_VERSION, CETUS_CLMM_PACKAGE_ID, CETUS_GLOBAL_CONFIG_ID, CETUS_INTEGRATE_PUBLISHED_AT, CETUS_POOLS_ID, CETUS_POSITION_TYPE, type ChatMessage, type ChatParams, type ChatResult, type ChatUsage, type CheckStatus, type ComposeTxOptions, type ComposeTxResult, DEFAULT_API_BASE, type DailySpend, DepositInfo, type DirectPoolSwapArgs, InvalidAddressError, type LabelValidationResult, type LimitAssertInput, LimitEnforcer, LimitExceededError, type LimitKind, type LimitOperation, type LimitsConfig, type LimitsFile, MIN_LP_USDC, type NormalizedAddress, OverlayFeeConfig, PayOptions, PayResult, PaymentRequest, type PublishAgentCoinArgs, type PublishAgentCoinResult, SPONSORED_PYTH_DEPENDENT_PROVIDERS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SYMBOL_BLOCKLIST, SendResult, type SendTransferInput, SendableAsset, type StepPreview, SuinsNotRegisteredError, type SuinsParent, SuinsRpcError, SupportedAsset, type SwapExecuteInput, SwapQuoteResult, SwapResult, SwapRouteResult, T2000, T2000Error, T2000Options, type TokenizeArgs, TransactionRecord, TransactionSigner, type TrustMode, type UpstreamClaim, type VerifyAnchor, type VerifyCheck, type VerifyOptions, type VerifyResult, type VerifyUpstream, WRITE_APPENDER_REGISTRY, type WriteStep, type WriteToolName, ZkLoginProof, approxUsdValue, assertLimitConfig, buildAddLeafTx, buildAgentCoinModule, buildDirectPoolSwapTx, buildPublishAgentCoinTx, buildRevokeLeafTx, buildTokenizeTx, chatCompletion, chatCompletionStream, clearLimits, composeTx, dailySpentToday, deriveAllowedAddressesFromPtb, displayHandle, exportPrivateKey, fullHandle, generateKeypair, getAddress, getLimits, getSponsoredSwapProviders, getSwapQuote, hasLimits, keypairFromPrivateKey, listModels, loadKey, looksLikeSuiNs, normalizeAddressInput, queryBalance, readLimitsFile, recordDailySpend, resolveAddressToSuinsViaRpc, resolveSuinsViaRpc, saveBech32, saveKey, setLimits, validateAgentCoinParams, validateLabel, verifyReceipt, walletExists, writeLimitsFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -1250,4 +1250,37 @@ declare const CETUS_POSITION_TYPE: string;
|
|
|
1250
1250
|
*/
|
|
1251
1251
|
declare const AGENT_POOL_TICK_SPACING = 200;
|
|
1252
1252
|
|
|
1253
|
-
|
|
1253
|
+
/**
|
|
1254
|
+
* Direct-pool swap for agent tokens (S.815). The Cetus AGGREGATOR does not
|
|
1255
|
+
* route fresh pools (probed 2026-07-25: "available path is empty" for $FS),
|
|
1256
|
+
* so agent-token trading swaps DIRECTLY against the token's known pool via
|
|
1257
|
+
* the integrate package's `pool_script::swap_a2b/b2a` entry — works from
|
|
1258
|
+
* minute zero for every launch. Quote = a server-side simulation of the
|
|
1259
|
+
* same transaction (the sim IS the price; no math to drift).
|
|
1260
|
+
*
|
|
1261
|
+
* Verified by mainnet simulation both directions on the $FS pool.
|
|
1262
|
+
*/
|
|
1263
|
+
/** Cetus `integrate` latest published-at (mainnet, MVR v16 — their docs
|
|
1264
|
+
* address table). The older ids fail the clmm version gate. */
|
|
1265
|
+
declare const CETUS_INTEGRATE_PUBLISHED_AT: string;
|
|
1266
|
+
interface DirectPoolSwapArgs {
|
|
1267
|
+
client: SuiCoreClient;
|
|
1268
|
+
/** The swapper (signs + receives output; pays own gas — unsponsored). */
|
|
1269
|
+
sender: string;
|
|
1270
|
+
/** The agent token's Cetus pool (from the AgentToken record). */
|
|
1271
|
+
poolId: string;
|
|
1272
|
+
/** buy = USDC → AGENT · sell = AGENT → USDC. */
|
|
1273
|
+
direction: 'buy' | 'sell';
|
|
1274
|
+
/** Raw input amount (USDC 6dp for buy; token 6dp for sell). */
|
|
1275
|
+
amountIn: bigint;
|
|
1276
|
+
/** Raw minimum output — slippage floor; 0n when simulating for a quote. */
|
|
1277
|
+
minOut: bigint;
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Build the unsigned direct-pool swap. Reads the pool's `Pool<A, B>` type
|
|
1281
|
+
* args (pair orientation is whatever Cetus canonicalized at creation) and
|
|
1282
|
+
* picks `swap_a2b` / `swap_b2a` so input→output matches `direction`.
|
|
1283
|
+
*/
|
|
1284
|
+
declare function buildDirectPoolSwapTx(args: DirectPoolSwapArgs): Promise<Transaction>;
|
|
1285
|
+
|
|
1286
|
+
export { AGENT_CAPITAL_PACKAGE_ID, AGENT_CAPITAL_PUBLISHED_AT, AGENT_ID_PARENT, AGENT_ID_PARENT_NAME, AGENT_ID_PARENT_NFT_ID, AGENT_POOL_TICK_SPACING, AGENT_TOKEN_DECIMALS, AGENT_TOKEN_LP_ALLOCATION, AGENT_TOKEN_TOTAL_SUPPLY, AGENT_TOKEN_TREASURY_ALLOCATION, AUDRIC_PARENT, AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, type AgentCoinModule, type AgentCoinParams, type ApiModel, type AppenderContext, BalanceResponse, type BuildAddLeafParams, type BuildRevokeLeafParams, CAPITAL_REGISTRY_ID, CAPITAL_REGISTRY_VERSION, CETUS_CLMM_PACKAGE_ID, CETUS_GLOBAL_CONFIG_ID, CETUS_INTEGRATE_PUBLISHED_AT, CETUS_POOLS_ID, CETUS_POSITION_TYPE, type ChatMessage, type ChatParams, type ChatResult, type ChatUsage, type CheckStatus, type ComposeTxOptions, type ComposeTxResult, DEFAULT_API_BASE, type DailySpend, DepositInfo, type DirectPoolSwapArgs, InvalidAddressError, type LabelValidationResult, type LimitAssertInput, LimitEnforcer, LimitExceededError, type LimitKind, type LimitOperation, type LimitsConfig, type LimitsFile, MIN_LP_USDC, type NormalizedAddress, OverlayFeeConfig, PayOptions, PayResult, PaymentRequest, type PublishAgentCoinArgs, type PublishAgentCoinResult, SPONSORED_PYTH_DEPENDENT_PROVIDERS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SYMBOL_BLOCKLIST, SendResult, type SendTransferInput, SendableAsset, type StepPreview, SuinsNotRegisteredError, type SuinsParent, SuinsRpcError, SupportedAsset, type SwapExecuteInput, SwapQuoteResult, SwapResult, SwapRouteResult, T2000, T2000Error, T2000Options, type TokenizeArgs, TransactionRecord, TransactionSigner, type TrustMode, type UpstreamClaim, type VerifyAnchor, type VerifyCheck, type VerifyOptions, type VerifyResult, type VerifyUpstream, WRITE_APPENDER_REGISTRY, type WriteStep, type WriteToolName, ZkLoginProof, approxUsdValue, assertLimitConfig, buildAddLeafTx, buildAgentCoinModule, buildDirectPoolSwapTx, buildPublishAgentCoinTx, buildRevokeLeafTx, buildTokenizeTx, chatCompletion, chatCompletionStream, clearLimits, composeTx, dailySpentToday, deriveAllowedAddressesFromPtb, displayHandle, exportPrivateKey, fullHandle, generateKeypair, getAddress, getLimits, getSponsoredSwapProviders, getSwapQuote, hasLimits, keypairFromPrivateKey, listModels, loadKey, looksLikeSuiNs, normalizeAddressInput, queryBalance, readLimitsFile, recordDailySpend, resolveAddressToSuinsViaRpc, resolveSuinsViaRpc, saveBech32, saveKey, setLimits, validateAgentCoinParams, validateLabel, verifyReceipt, walletExists, writeLimitsFile };
|
package/dist/index.js
CHANGED
|
@@ -4218,6 +4218,51 @@ async function buildTokenizeTx(args) {
|
|
|
4218
4218
|
return tx;
|
|
4219
4219
|
}
|
|
4220
4220
|
|
|
4221
|
-
|
|
4221
|
+
// src/capital/swap.ts
|
|
4222
|
+
init_errors();
|
|
4223
|
+
init_token_registry();
|
|
4224
|
+
var CETUS_INTEGRATE_PUBLISHED_AT = process.env.CETUS_INTEGRATE_PUBLISHED_AT ?? "0xfbb32ac0fa89a3cb0c56c745b688c6d2a53ac8e43447119ad822763997ffb9c3";
|
|
4225
|
+
var MIN_SQRT_PRICE = 4295048016n;
|
|
4226
|
+
var MAX_SQRT_PRICE = 79226673515401279992447579055n;
|
|
4227
|
+
async function buildDirectPoolSwapTx(args) {
|
|
4228
|
+
if (args.amountIn <= 0n) {
|
|
4229
|
+
throw new T2000Error("INVALID_AMOUNT", "amountIn must be positive");
|
|
4230
|
+
}
|
|
4231
|
+
const pool = await args.client.core.getObject({ objectId: args.poolId }).catch(() => null);
|
|
4232
|
+
const m = pool?.object?.type?.match(/Pool<(.+),\s*(.+)>$/);
|
|
4233
|
+
if (!m) {
|
|
4234
|
+
throw new T2000Error("PROTOCOL_UNAVAILABLE", `not a Cetus pool: ${args.poolId}`);
|
|
4235
|
+
}
|
|
4236
|
+
const [typeA, typeB] = [m[1].trim(), m[2].trim()];
|
|
4237
|
+
const aIsUsdc = typeA === USDC_TYPE;
|
|
4238
|
+
if (!aIsUsdc && typeB !== USDC_TYPE) {
|
|
4239
|
+
throw new T2000Error("INVALID_ASSET", "pool is not USDC-quoted");
|
|
4240
|
+
}
|
|
4241
|
+
const a2b = args.direction === "buy" ? aIsUsdc : !aIsUsdc;
|
|
4242
|
+
const inputType = args.direction === "buy" ? USDC_TYPE : a2b ? typeA : typeB;
|
|
4243
|
+
const tx = new Transaction();
|
|
4244
|
+
tx.setSender(args.sender);
|
|
4245
|
+
const input = coinWithBalance({ type: inputType, balance: args.amountIn });
|
|
4246
|
+
const vec = tx.makeMoveVec({ elements: [input] });
|
|
4247
|
+
tx.moveCall({
|
|
4248
|
+
target: `${CETUS_INTEGRATE_PUBLISHED_AT}::pool_script::${a2b ? "swap_a2b" : "swap_b2a"}`,
|
|
4249
|
+
typeArguments: [typeA, typeB],
|
|
4250
|
+
arguments: [
|
|
4251
|
+
tx.object(CETUS_GLOBAL_CONFIG_ID),
|
|
4252
|
+
tx.object(args.poolId),
|
|
4253
|
+
vec,
|
|
4254
|
+
tx.pure.bool(true),
|
|
4255
|
+
// by_amount_in
|
|
4256
|
+
tx.pure.u64(args.amountIn),
|
|
4257
|
+
tx.pure.u64(args.minOut),
|
|
4258
|
+
// amount_limit = the slippage floor
|
|
4259
|
+
tx.pure.u128(a2b ? MIN_SQRT_PRICE : MAX_SQRT_PRICE),
|
|
4260
|
+
tx.object.clock()
|
|
4261
|
+
]
|
|
4262
|
+
});
|
|
4263
|
+
return tx;
|
|
4264
|
+
}
|
|
4265
|
+
|
|
4266
|
+
export { A2A_ESCROW_FEE_CONFIG_ID, A2A_ESCROW_PACKAGE_ID, AGENT_CAPITAL_PACKAGE_ID, AGENT_CAPITAL_PUBLISHED_AT, AGENT_ID_PARENT, AGENT_ID_PARENT_NAME, AGENT_ID_PARENT_NFT_ID, AGENT_POOL_TICK_SPACING, AGENT_TOKEN_DECIMALS, AGENT_TOKEN_LP_ALLOCATION, AGENT_TOKEN_TOTAL_SUPPLY, AGENT_TOKEN_TREASURY_ALLOCATION, AUDRIC_PARENT, AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, CAPITAL_REGISTRY_ID, CAPITAL_REGISTRY_VERSION, CETUS_CLMM_PACKAGE_ID, CETUS_GLOBAL_CONFIG_ID, CETUS_INTEGRATE_PUBLISHED_AT, CETUS_POOLS_ID, CETUS_POSITION_TYPE, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, DEFAULT_API_BASE, DEFAULT_COMMERCE_API_BASE, DEFAULT_GRPC_URL, DEFAULT_NETWORK, ETH_TYPE, GASLESS_MIN_STABLE_AMOUNT, GASLESS_STABLE_TYPES, GAS_RESERVE_MIN, IKA_TYPE, InvalidAddressError, JOB_STATES, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, LimitEnforcer, LimitExceededError, MANIFEST_TYPE, MAX_DELIVER_HORIZON_MS, MAX_JOB_USDC, MAX_REVIEW_WINDOW_MS, MIN_LP_USDC, MIST_PER_SUI, NAVX_TYPE, OPERATION_ASSETS, OVERLAY_FEE_RATE, PREFLIGHT_MAX_AMOUNT, PREFLIGHT_OK, SENDABLE_ASSETS, SPONSORED_PYTH_DEPENDENT_PROVIDERS, STABLE_ASSETS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SYMBOL_BLOCKLIST, SuinsNotRegisteredError, SuinsRpcError, T2000, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, WAL_TYPE, WBTC_TYPE, WRITE_APPENDER_REGISTRY, ZkLoginSigner, addSendToTx, addSwapToTx, approxUsdValue, assertAllowedAsset, assertLimitConfig, buildAddLeafTx, buildAgentCoinModule, buildCreateJobTx, buildDeliverJobTx, buildDirectPoolSwapTx, buildPublishAgentCoinTx, buildRefundJobTx, buildRejectJobTx, buildReleaseJobTx, buildRevokeLeafTx, buildSendTx, buildSwapTx, buildTokenizeTx, chatCompletion, chatCompletionStream, checkPositiveAmount, checkSuiAddress, classifyAction, classifyLabel, classifyTransaction, clearLimits, composeTx, dailySpentToday, deriveAllowedAddressesFromPtb, deserializeCetusRoute, displayHandle, executeTx, exportPrivateKey, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, fetchAllCoins, fetchService, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fullHandle, generateKeypair, getAddress, getCoinMeta, getDecimals, getDecimalsForCoinType, getJob, getJobSpec, getLimits, getSponsoredSwapProviders, getSuiClient, getSuiGrpcClient, getSwapQuote, hasLimits, isAllowedAsset, isCetusRouteFresh, isInRegistry, jobActionsFor, keypairFromPrivateKey, listModels, listServices, loadKey, looksLikeSuiNs, mapMoveAbortCode, mapWalletError, mistToSui, normalizeAddressInput, normalizeAsset, normalizeCoinType, parseMppSuiChallenge, parseSuiRpcTx, payWithMpp, preflightCreateJob, preflightFail, preflightPay, preflightSend, preflightSwap, putJobSpec, queryBalance, queryHistory, queryTransaction, rawToStable, rawToUsdc, readLimitsFile, recordDailySpend, refineLendingLabel, resolveAddressToSuinsViaRpc, resolveSuinsViaRpc, resolveSymbol, resolveTokenType, saveBech32, saveKey, selectAndSplitCoin, selectSuiCoin, serializeCetusRoute, setLimits, simulateTransaction, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, validateAgentCoinParams, validateLabel, verifyCetusRouteCoinMatch, verifyJobForSeller, verifyReceipt, walletExists, writeLimitsFile };
|
|
4222
4267
|
//# sourceMappingURL=index.js.map
|
|
4223
4268
|
//# sourceMappingURL=index.js.map
|