@t2000/sdk 1.27.0 → 1.27.2

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 CHANGED
@@ -927,6 +927,7 @@ __export(cetus_swap_exports, {
927
927
  deserializeCetusRoute: () => deserializeCetusRoute,
928
928
  findSwapRoute: () => findSwapRoute,
929
929
  isCetusRouteFresh: () => isCetusRouteFresh,
930
+ isPrecomputedRouteCompatibleWithProviders: () => isPrecomputedRouteCompatibleWithProviders,
930
931
  resolveTokenType: () => resolveTokenType,
931
932
  serializeCetusRoute: () => serializeCetusRoute,
932
933
  simulateSwap: () => simulateSwap,
@@ -1043,6 +1044,14 @@ function getClient(walletAddress, overlayFee) {
1043
1044
  clientCache.set(key, client);
1044
1045
  return client;
1045
1046
  }
1047
+ function isPrecomputedRouteCompatibleWithProviders(route, providers) {
1048
+ if (!providers || providers.length === 0) return true;
1049
+ const allowed = new Set(providers);
1050
+ for (const path of route.routerData.paths) {
1051
+ if (!allowed.has(path.provider)) return false;
1052
+ }
1053
+ return true;
1054
+ }
1046
1055
  async function findSwapRoute(params) {
1047
1056
  const client = getClient(params.walletAddress, params.overlayFee);
1048
1057
  const findParams = {
@@ -1120,7 +1129,7 @@ async function addSwapToTx(tx, client, address, input) {
1120
1129
  }
1121
1130
  let route;
1122
1131
  let usedPrecomputedRoute = false;
1123
- if (input.precomputedRoute && input.precomputedRoute.amountIn === effectiveRaw.toString() && input.precomputedRoute.byAmountIn === byAmountIn) {
1132
+ if (input.precomputedRoute && input.precomputedRoute.amountIn === effectiveRaw.toString() && input.precomputedRoute.byAmountIn === byAmountIn && isPrecomputedRouteCompatibleWithProviders(input.precomputedRoute, input.providers)) {
1124
1133
  route = input.precomputedRoute;
1125
1134
  usedPrecomputedRoute = true;
1126
1135
  } else {
@@ -1728,6 +1737,26 @@ function extractTransferDetails(changes, sender) {
1728
1737
  function bigintAbs(n) {
1729
1738
  return n < 0n ? -n : n;
1730
1739
  }
1740
+ function extractAllUserLegs(changes, sender) {
1741
+ if (!changes || changes.length === 0) return [];
1742
+ const legs = [];
1743
+ for (const c of changes) {
1744
+ if (resolveOwner(c.owner) !== sender) continue;
1745
+ const raw = BigInt(c.amount);
1746
+ if (raw === 0n) continue;
1747
+ const decimals = getDecimalsForCoinType(c.coinType);
1748
+ const absAmount = bigintAbs(raw);
1749
+ legs.push({
1750
+ coinType: c.coinType,
1751
+ asset: resolveSymbol(c.coinType),
1752
+ decimals,
1753
+ amount: Number(absAmount) / 10 ** decimals,
1754
+ rawAmount: raw.toString(),
1755
+ direction: raw < 0n ? "out" : "in"
1756
+ });
1757
+ }
1758
+ return legs;
1759
+ }
1731
1760
 
1732
1761
  // src/wallet/history.ts
1733
1762
  async function queryHistory(client, address, limit = 20) {
@@ -1771,6 +1800,7 @@ function parseTxRecord(tx, address) {
1771
1800
  const gasCost = gasUsed ? (Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate)) / 1e9 : void 0;
1772
1801
  const { moveCallTargets, commandTypes } = extractCommands(tx.transaction);
1773
1802
  const balanceChanges = tx.balanceChanges ?? [];
1803
+ const legs = extractAllUserLegs(balanceChanges, address);
1774
1804
  const { amount, asset, recipient, direction } = extractTransferDetails(balanceChanges, address);
1775
1805
  const { action, label } = classifyTransaction(
1776
1806
  moveCallTargets,
@@ -1782,6 +1812,7 @@ function parseTxRecord(tx, address) {
1782
1812
  digest: tx.digest,
1783
1813
  action,
1784
1814
  label,
1815
+ legs,
1785
1816
  amount,
1786
1817
  asset,
1787
1818
  recipient,
@@ -8335,7 +8366,8 @@ async function getSwapQuote(params) {
8335
8366
  from: fromType,
8336
8367
  to: toType,
8337
8368
  amount: rawAmount,
8338
- byAmountIn
8369
+ byAmountIn,
8370
+ providers: params.providers
8339
8371
  });
8340
8372
  if (!route) throw new exports.T2000Error("SWAP_FAILED", `No swap route found for ${params.from} -> ${params.to}.`);
8341
8373
  if (route.insufficientLiquidity) {
@@ -8451,6 +8483,7 @@ exports.OPERATION_ASSETS = OPERATION_ASSETS;
8451
8483
  exports.OUTBOUND_OPS = OUTBOUND_OPS;
8452
8484
  exports.ProtocolRegistry = ProtocolRegistry;
8453
8485
  exports.SAVE_FEE_BPS = SAVE_FEE_BPS;
8486
+ exports.SPONSORED_PYTH_DEPENDENT_PROVIDERS = SPONSORED_PYTH_DEPENDENT_PROVIDERS;
8454
8487
  exports.STABLE_ASSETS = STABLE_ASSETS;
8455
8488
  exports.SUI_DECIMALS = SUI_DECIMALS;
8456
8489
  exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
@@ -8487,6 +8520,7 @@ exports.deriveAllowedAddressesFromPtb = deriveAllowedAddressesFromPtb;
8487
8520
  exports.deserializeCetusRoute = deserializeCetusRoute;
8488
8521
  exports.displayHandle = displayHandle;
8489
8522
  exports.exportPrivateKey = exportPrivateKey;
8523
+ exports.extractAllUserLegs = extractAllUserLegs;
8490
8524
  exports.extractTransferDetails = extractTransferDetails;
8491
8525
  exports.extractTxCommands = extractTxCommands;
8492
8526
  exports.extractTxSender = extractTxSender;
@@ -8506,6 +8540,7 @@ exports.getFinancialSummary = getFinancialSummary;
8506
8540
  exports.getPendingRewards = getPendingRewards;
8507
8541
  exports.getPendingRewardsByAddress = getPendingRewardsByAddress;
8508
8542
  exports.getRates = getRates;
8543
+ exports.getSponsoredSwapProviders = getSponsoredSwapProviders;
8509
8544
  exports.getSwapQuote = getSwapQuote;
8510
8545
  exports.getTier = getTier;
8511
8546
  exports.getVoloStats = getVoloStats;