@t2000/sdk 4.0.0 → 4.0.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/README.md +16 -211
- package/dist/adapters/index.cjs +0 -1
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.js +0 -1
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.cjs +0 -1
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +0 -1
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +54 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -7
- package/dist/index.d.ts +17 -7
- package/dist/index.js +54 -14
- package/dist/index.js.map +1 -1
- package/dist/{types-_U9XXGFR.d.ts → types-B63ogqZZ.d.ts} +1 -1
- package/dist/{types-CqpN8a8R.d.cts → types-CIclvR39.d.cts} +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { Q as TxMetadata, o as SafeguardConfig, T as T2000Error, H as TransactionSigner, v as SupportedAsset, _ as ZkLoginProof, ax as SendableAsset } from './types-
|
|
5
|
-
export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, ay as CETUS_USDC_SUI_POOL, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, az as DEFAULT_GRPC_URL, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, aA as GASLESS_MIN_STABLE_AMOUNT, aB as GASLESS_STABLE_TYPES, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, aC as OPERATION_ASSETS, O as OUTBOUND_OPS, aD as Operation, P as ProtocolFeeInfo, aE as SAVEABLE_ASSETS, S as SAVE_FEE_BPS, aF as SENDABLE_ASSETS, k as STABLE_ASSETS, l as SUI_DECIMALS, m as SUI_TYPE, n as SUPPORTED_ASSETS, p as SafeguardError, q as SafeguardErrorDetails, r as SafeguardRule, aG as SaveableAsset, s as SimulationResult, t as StableAsset, u as SuiRpcTxBlock, w as T2000ErrorCode, x as T2000ErrorData, y as T2000_OVERLAY_FEE_WALLET, z as TOKEN_MAP, J as TxDirection, U as USDC_DECIMALS, R as USDC_TYPE, V as USDE_TYPE, W as USDSUI_TYPE, X as USDT_TYPE, Y as WAL_TYPE, Z as WBTC_TYPE, $ as ZkLoginSigner, a0 as addFeeTransfer, aH as assertAllowedAsset, a1 as calculateFee, a2 as classifyAction, a3 as classifyLabel, a4 as classifyTransaction, aI as createSuiClient, a5 as extractAllUserLegs, a6 as extractTransferDetails, a7 as extractTxCommands, a8 as extractTxSender, a9 as fallbackLabel, aa as formatAssetAmount, ab as formatSui, ac as formatUsd, aJ as getCoinMeta, ad as getDecimals, ae as getDecimalsForCoinType, aK as getSuiClient, aL as getSuiGrpcClient, af as getTier, aM as isAllowedAsset, aN as isInRegistry, ag as isSupported, ah as isTier1, ai as isTier2, aj as mapMoveAbortCode, ak as mapWalletError, al as mistToSui, aO as normalizeAsset, aP as normalizeCoinType, am as parseSuiRpcTx, aQ as queryHistory, aR as queryTransaction, an as rawToStable, ao as rawToUsdc, ap as refineLendingLabel, aq as resolveSymbol, ar as resolveTokenType, aS as simulateTransaction, as as stableToRaw, at as suiToMist, aT as throwIfSimulationFailed, au as truncateAddress, av as usdcToRaw, aw as validateAddress } from './types-
|
|
4
|
+
import { Q as TxMetadata, o as SafeguardConfig, T as T2000Error, H as TransactionSigner, v as SupportedAsset, _ as ZkLoginProof, ax as SendableAsset } from './types-CIclvR39.cjs';
|
|
5
|
+
export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, ay as CETUS_USDC_SUI_POOL, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, az as DEFAULT_GRPC_URL, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, aA as GASLESS_MIN_STABLE_AMOUNT, aB as GASLESS_STABLE_TYPES, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, aC as OPERATION_ASSETS, O as OUTBOUND_OPS, aD as Operation, P as ProtocolFeeInfo, aE as SAVEABLE_ASSETS, S as SAVE_FEE_BPS, aF as SENDABLE_ASSETS, k as STABLE_ASSETS, l as SUI_DECIMALS, m as SUI_TYPE, n as SUPPORTED_ASSETS, p as SafeguardError, q as SafeguardErrorDetails, r as SafeguardRule, aG as SaveableAsset, s as SimulationResult, t as StableAsset, u as SuiRpcTxBlock, w as T2000ErrorCode, x as T2000ErrorData, y as T2000_OVERLAY_FEE_WALLET, z as TOKEN_MAP, J as TxDirection, U as USDC_DECIMALS, R as USDC_TYPE, V as USDE_TYPE, W as USDSUI_TYPE, X as USDT_TYPE, Y as WAL_TYPE, Z as WBTC_TYPE, $ as ZkLoginSigner, a0 as addFeeTransfer, aH as assertAllowedAsset, a1 as calculateFee, a2 as classifyAction, a3 as classifyLabel, a4 as classifyTransaction, aI as createSuiClient, a5 as extractAllUserLegs, a6 as extractTransferDetails, a7 as extractTxCommands, a8 as extractTxSender, a9 as fallbackLabel, aa as formatAssetAmount, ab as formatSui, ac as formatUsd, aJ as getCoinMeta, ad as getDecimals, ae as getDecimalsForCoinType, aK as getSuiClient, aL as getSuiGrpcClient, af as getTier, aM as isAllowedAsset, aN as isInRegistry, ag as isSupported, ah as isTier1, ai as isTier2, aj as mapMoveAbortCode, ak as mapWalletError, al as mistToSui, aO as normalizeAsset, aP as normalizeCoinType, am as parseSuiRpcTx, aQ as queryHistory, aR as queryTransaction, an as rawToStable, ao as rawToUsdc, ap as refineLendingLabel, aq as resolveSymbol, ar as resolveTokenType, aS as simulateTransaction, as as stableToRaw, at as suiToMist, aT as throwIfSimulationFailed, au as truncateAddress, av as usdcToRaw, aw as validateAddress } from './types-CIclvR39.cjs';
|
|
6
6
|
import { L as LendingAdapter, a as LendingRates, P as PendingReward$1 } from './descriptors-DqIb4AnV.cjs';
|
|
7
7
|
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from './descriptors-DqIb4AnV.cjs';
|
|
8
8
|
import { n as T2000Options, P as PayOptions, d as PayResult, o as SwapResult, p as SwapQuoteResult, i as SendResult, B as BalanceResponse, k as TransactionRecord, D as DepositInfo, q as PaymentRequest, S as SaveResult, W as WithdrawResult, b as MaxWithdrawResult, a as BorrowResult, h as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, e as PendingReward, C as ClaimRewardsResult, r as CompoundRewardsResult, g as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult, c as OverlayFeeConfig, j as SwapRouteResult, s as FinancialSummary } from './types-HJGbXJ37.cjs';
|
|
@@ -570,6 +570,13 @@ interface SelectAndSplitResult {
|
|
|
570
570
|
* `'all'` to consume the entire balance.
|
|
571
571
|
* @param options.allowSwapAll — if true (default), `amount` >= totalBalance
|
|
572
572
|
* auto-clips to total. If false, throws when the request would over-consume.
|
|
573
|
+
* @param options.sponsoredContext — when true, source ONLY from discrete coin
|
|
574
|
+
* objects (never the address balance). See the long note below — this exists
|
|
575
|
+
* because Enoki's gas station can't yet deserialize a `TransactionData` that
|
|
576
|
+
* contains the address-balance `FundsWithdrawal` reservation that
|
|
577
|
+
* `coinWithBalance` emits. Self-funded callers leave this false: the fullnode
|
|
578
|
+
* handles `FundsWithdrawal` fine, so the address-balance path is preferred
|
|
579
|
+
* (it can reach funds that aren't held as coin objects).
|
|
573
580
|
*
|
|
574
581
|
* @returns
|
|
575
582
|
* - `coin` — `TransactionObjectArgument` ready for downstream consumption.
|
|
@@ -579,6 +586,7 @@ interface SelectAndSplitResult {
|
|
|
579
586
|
*/
|
|
580
587
|
declare function selectAndSplitCoin(tx: Transaction, client: SuiJsonRpcClient, owner: string, coinType: string, amount: bigint | 'all', options?: {
|
|
581
588
|
allowSwapAll?: boolean;
|
|
589
|
+
sponsoredContext?: boolean;
|
|
582
590
|
}): Promise<SelectAndSplitResult>;
|
|
583
591
|
/**
|
|
584
592
|
* SUI-specific coin selection. Branches on sponsorship context:
|
|
@@ -587,11 +595,13 @@ declare function selectAndSplitCoin(tx: Transaction, client: SuiJsonRpcClient, o
|
|
|
587
595
|
* directly (the user's gas coin IS their SUI). More efficient — no
|
|
588
596
|
* `getBalance` RTT.
|
|
589
597
|
*
|
|
590
|
-
* - **Sponsored (`sponsoredContext: true`)** —
|
|
591
|
-
*
|
|
592
|
-
* belongs to the Enoki sponsor
|
|
593
|
-
*
|
|
594
|
-
*
|
|
598
|
+
* - **Sponsored (`sponsoredContext: true`)** — sources from the user's
|
|
599
|
+
* discrete SUI coin objects (`selectCoinObjectsOnly`). This both (a) avoids
|
|
600
|
+
* `tx.gas`, which belongs to the Enoki sponsor — NOT the user — under
|
|
601
|
+
* sponsored flows (the original S.260 reason for `useGasCoin: false`), AND
|
|
602
|
+
* (b) avoids `coinWithBalance`'s address-balance `FundsWithdrawal`, which
|
|
603
|
+
* Enoki's gas station can't deserialize (issue #93). If the user's SUI is
|
|
604
|
+
* address-balance-only, it raises `ADDRESS_BALANCE_UNSPONSORABLE`.
|
|
595
605
|
*/
|
|
596
606
|
declare function selectSuiCoin(tx: Transaction, client: SuiJsonRpcClient, owner: string, amountMist: bigint, sponsoredContext: boolean): Promise<SelectAndSplitResult>;
|
|
597
607
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { Q as TxMetadata, o as SafeguardConfig, T as T2000Error, H as TransactionSigner, v as SupportedAsset, _ as ZkLoginProof, ax as SendableAsset } from './types-
|
|
5
|
-
export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, ay as CETUS_USDC_SUI_POOL, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, az as DEFAULT_GRPC_URL, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, aA as GASLESS_MIN_STABLE_AMOUNT, aB as GASLESS_STABLE_TYPES, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, aC as OPERATION_ASSETS, O as OUTBOUND_OPS, aD as Operation, P as ProtocolFeeInfo, aE as SAVEABLE_ASSETS, S as SAVE_FEE_BPS, aF as SENDABLE_ASSETS, k as STABLE_ASSETS, l as SUI_DECIMALS, m as SUI_TYPE, n as SUPPORTED_ASSETS, p as SafeguardError, q as SafeguardErrorDetails, r as SafeguardRule, aG as SaveableAsset, s as SimulationResult, t as StableAsset, u as SuiRpcTxBlock, w as T2000ErrorCode, x as T2000ErrorData, y as T2000_OVERLAY_FEE_WALLET, z as TOKEN_MAP, J as TxDirection, U as USDC_DECIMALS, R as USDC_TYPE, V as USDE_TYPE, W as USDSUI_TYPE, X as USDT_TYPE, Y as WAL_TYPE, Z as WBTC_TYPE, $ as ZkLoginSigner, a0 as addFeeTransfer, aH as assertAllowedAsset, a1 as calculateFee, a2 as classifyAction, a3 as classifyLabel, a4 as classifyTransaction, aI as createSuiClient, a5 as extractAllUserLegs, a6 as extractTransferDetails, a7 as extractTxCommands, a8 as extractTxSender, a9 as fallbackLabel, aa as formatAssetAmount, ab as formatSui, ac as formatUsd, aJ as getCoinMeta, ad as getDecimals, ae as getDecimalsForCoinType, aK as getSuiClient, aL as getSuiGrpcClient, af as getTier, aM as isAllowedAsset, aN as isInRegistry, ag as isSupported, ah as isTier1, ai as isTier2, aj as mapMoveAbortCode, ak as mapWalletError, al as mistToSui, aO as normalizeAsset, aP as normalizeCoinType, am as parseSuiRpcTx, aQ as queryHistory, aR as queryTransaction, an as rawToStable, ao as rawToUsdc, ap as refineLendingLabel, aq as resolveSymbol, ar as resolveTokenType, aS as simulateTransaction, as as stableToRaw, at as suiToMist, aT as throwIfSimulationFailed, au as truncateAddress, av as usdcToRaw, aw as validateAddress } from './types-
|
|
4
|
+
import { Q as TxMetadata, o as SafeguardConfig, T as T2000Error, H as TransactionSigner, v as SupportedAsset, _ as ZkLoginProof, ax as SendableAsset } from './types-B63ogqZZ.js';
|
|
5
|
+
export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, ay as CETUS_USDC_SUI_POOL, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, az as DEFAULT_GRPC_URL, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, aA as GASLESS_MIN_STABLE_AMOUNT, aB as GASLESS_STABLE_TYPES, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, aC as OPERATION_ASSETS, O as OUTBOUND_OPS, aD as Operation, P as ProtocolFeeInfo, aE as SAVEABLE_ASSETS, S as SAVE_FEE_BPS, aF as SENDABLE_ASSETS, k as STABLE_ASSETS, l as SUI_DECIMALS, m as SUI_TYPE, n as SUPPORTED_ASSETS, p as SafeguardError, q as SafeguardErrorDetails, r as SafeguardRule, aG as SaveableAsset, s as SimulationResult, t as StableAsset, u as SuiRpcTxBlock, w as T2000ErrorCode, x as T2000ErrorData, y as T2000_OVERLAY_FEE_WALLET, z as TOKEN_MAP, J as TxDirection, U as USDC_DECIMALS, R as USDC_TYPE, V as USDE_TYPE, W as USDSUI_TYPE, X as USDT_TYPE, Y as WAL_TYPE, Z as WBTC_TYPE, $ as ZkLoginSigner, a0 as addFeeTransfer, aH as assertAllowedAsset, a1 as calculateFee, a2 as classifyAction, a3 as classifyLabel, a4 as classifyTransaction, aI as createSuiClient, a5 as extractAllUserLegs, a6 as extractTransferDetails, a7 as extractTxCommands, a8 as extractTxSender, a9 as fallbackLabel, aa as formatAssetAmount, ab as formatSui, ac as formatUsd, aJ as getCoinMeta, ad as getDecimals, ae as getDecimalsForCoinType, aK as getSuiClient, aL as getSuiGrpcClient, af as getTier, aM as isAllowedAsset, aN as isInRegistry, ag as isSupported, ah as isTier1, ai as isTier2, aj as mapMoveAbortCode, ak as mapWalletError, al as mistToSui, aO as normalizeAsset, aP as normalizeCoinType, am as parseSuiRpcTx, aQ as queryHistory, aR as queryTransaction, an as rawToStable, ao as rawToUsdc, ap as refineLendingLabel, aq as resolveSymbol, ar as resolveTokenType, aS as simulateTransaction, as as stableToRaw, at as suiToMist, aT as throwIfSimulationFailed, au as truncateAddress, av as usdcToRaw, aw as validateAddress } from './types-B63ogqZZ.js';
|
|
6
6
|
import { L as LendingAdapter, a as LendingRates, P as PendingReward$1 } from './descriptors-DqIb4AnV.js';
|
|
7
7
|
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, d as ProtocolDescriptor, e as allDescriptors, n as naviDescriptor } from './descriptors-DqIb4AnV.js';
|
|
8
8
|
import { n as T2000Options, P as PayOptions, d as PayResult, o as SwapResult, p as SwapQuoteResult, i as SendResult, B as BalanceResponse, k as TransactionRecord, D as DepositInfo, q as PaymentRequest, S as SaveResult, W as WithdrawResult, b as MaxWithdrawResult, a as BorrowResult, h as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, e as PendingReward, C as ClaimRewardsResult, r as CompoundRewardsResult, g as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult, c as OverlayFeeConfig, j as SwapRouteResult, s as FinancialSummary } from './types-HJGbXJ37.js';
|
|
@@ -570,6 +570,13 @@ interface SelectAndSplitResult {
|
|
|
570
570
|
* `'all'` to consume the entire balance.
|
|
571
571
|
* @param options.allowSwapAll — if true (default), `amount` >= totalBalance
|
|
572
572
|
* auto-clips to total. If false, throws when the request would over-consume.
|
|
573
|
+
* @param options.sponsoredContext — when true, source ONLY from discrete coin
|
|
574
|
+
* objects (never the address balance). See the long note below — this exists
|
|
575
|
+
* because Enoki's gas station can't yet deserialize a `TransactionData` that
|
|
576
|
+
* contains the address-balance `FundsWithdrawal` reservation that
|
|
577
|
+
* `coinWithBalance` emits. Self-funded callers leave this false: the fullnode
|
|
578
|
+
* handles `FundsWithdrawal` fine, so the address-balance path is preferred
|
|
579
|
+
* (it can reach funds that aren't held as coin objects).
|
|
573
580
|
*
|
|
574
581
|
* @returns
|
|
575
582
|
* - `coin` — `TransactionObjectArgument` ready for downstream consumption.
|
|
@@ -579,6 +586,7 @@ interface SelectAndSplitResult {
|
|
|
579
586
|
*/
|
|
580
587
|
declare function selectAndSplitCoin(tx: Transaction, client: SuiJsonRpcClient, owner: string, coinType: string, amount: bigint | 'all', options?: {
|
|
581
588
|
allowSwapAll?: boolean;
|
|
589
|
+
sponsoredContext?: boolean;
|
|
582
590
|
}): Promise<SelectAndSplitResult>;
|
|
583
591
|
/**
|
|
584
592
|
* SUI-specific coin selection. Branches on sponsorship context:
|
|
@@ -587,11 +595,13 @@ declare function selectAndSplitCoin(tx: Transaction, client: SuiJsonRpcClient, o
|
|
|
587
595
|
* directly (the user's gas coin IS their SUI). More efficient — no
|
|
588
596
|
* `getBalance` RTT.
|
|
589
597
|
*
|
|
590
|
-
* - **Sponsored (`sponsoredContext: true`)** —
|
|
591
|
-
*
|
|
592
|
-
* belongs to the Enoki sponsor
|
|
593
|
-
*
|
|
594
|
-
*
|
|
598
|
+
* - **Sponsored (`sponsoredContext: true`)** — sources from the user's
|
|
599
|
+
* discrete SUI coin objects (`selectCoinObjectsOnly`). This both (a) avoids
|
|
600
|
+
* `tx.gas`, which belongs to the Enoki sponsor — NOT the user — under
|
|
601
|
+
* sponsored flows (the original S.260 reason for `useGasCoin: false`), AND
|
|
602
|
+
* (b) avoids `coinWithBalance`'s address-balance `FundsWithdrawal`, which
|
|
603
|
+
* Enoki's gas station can't deserialize (issue #93). If the user's SUI is
|
|
604
|
+
* address-balance-only, it raises `ADDRESS_BALANCE_UNSPONSORABLE`.
|
|
595
605
|
*/
|
|
596
606
|
declare function selectSuiCoin(tx: Transaction, client: SuiJsonRpcClient, owner: string, amountMist: bigint, sponsoredContext: boolean): Promise<SelectAndSplitResult>;
|
|
597
607
|
|
package/dist/index.js
CHANGED
|
@@ -671,6 +671,9 @@ async function fetchAllCoins(client, owner, coinType) {
|
|
|
671
671
|
return { ids, totalBalance: BigInt(balance.totalBalance) };
|
|
672
672
|
}
|
|
673
673
|
async function selectAndSplitCoin(tx, client, owner, coinType, amount, options = {}) {
|
|
674
|
+
if (options.sponsoredContext) {
|
|
675
|
+
return selectCoinObjectsOnly(tx, client, owner, coinType, amount, options.allowSwapAll ?? true);
|
|
676
|
+
}
|
|
674
677
|
const balanceResp = await client.getBalance({ owner, coinType });
|
|
675
678
|
const totalBalance = BigInt(balanceResp.totalBalance);
|
|
676
679
|
if (totalBalance === 0n) {
|
|
@@ -689,19 +692,51 @@ async function selectAndSplitCoin(tx, client, owner, coinType, amount, options =
|
|
|
689
692
|
const coin = coinWithBalance({ type: coinType, balance: effectiveAmount })(tx);
|
|
690
693
|
return { coin, effectiveAmount, swapAll };
|
|
691
694
|
}
|
|
695
|
+
async function selectCoinObjectsOnly(tx, client, owner, coinType, amount, allowSwapAll) {
|
|
696
|
+
const objects = [];
|
|
697
|
+
let coinObjectTotal = 0n;
|
|
698
|
+
let cursor;
|
|
699
|
+
let hasNext = true;
|
|
700
|
+
while (hasNext) {
|
|
701
|
+
const page = await client.getCoins({ owner, coinType, cursor: cursor ?? void 0 });
|
|
702
|
+
for (const c of page.data) {
|
|
703
|
+
objects.push({ objectId: c.coinObjectId, balance: BigInt(c.balance) });
|
|
704
|
+
coinObjectTotal += BigInt(c.balance);
|
|
705
|
+
}
|
|
706
|
+
cursor = page.nextCursor;
|
|
707
|
+
hasNext = page.hasNextPage;
|
|
708
|
+
}
|
|
709
|
+
const unsponsorable = () => new T2000Error(
|
|
710
|
+
"ADDRESS_BALANCE_UNSPONSORABLE",
|
|
711
|
+
`These funds are in your address balance, which sponsored transactions can't access yet. (Funds received via gasless transfers land there.) This will work once the gas sponsor adds address-balance support.`,
|
|
712
|
+
{ coinObjectTotal: coinObjectTotal.toString(), coinType }
|
|
713
|
+
);
|
|
714
|
+
if (coinObjectTotal === 0n) {
|
|
715
|
+
throw unsponsorable();
|
|
716
|
+
}
|
|
717
|
+
const requested = amount === "all" ? coinObjectTotal : amount;
|
|
718
|
+
if (requested > coinObjectTotal) {
|
|
719
|
+
if (allowSwapAll && amount === "all") ; else {
|
|
720
|
+
throw unsponsorable();
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
const swapAll = amount === "all" || requested >= coinObjectTotal;
|
|
724
|
+
const effectiveAmount = swapAll ? coinObjectTotal : requested;
|
|
725
|
+
const [first, ...rest] = objects;
|
|
726
|
+
const primary = tx.object(first.objectId);
|
|
727
|
+
if (rest.length > 0) {
|
|
728
|
+
tx.mergeCoins(
|
|
729
|
+
primary,
|
|
730
|
+
rest.map((o) => tx.object(o.objectId))
|
|
731
|
+
);
|
|
732
|
+
}
|
|
733
|
+
const coin = swapAll ? primary : tx.splitCoins(primary, [effectiveAmount])[0];
|
|
734
|
+
return { coin, effectiveAmount, swapAll };
|
|
735
|
+
}
|
|
692
736
|
async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext) {
|
|
693
737
|
if (sponsoredContext) {
|
|
694
738
|
const { SUI_TYPE: SUI_TYPE2 } = await Promise.resolve().then(() => (init_token_registry(), token_registry_exports));
|
|
695
|
-
|
|
696
|
-
const totalBalance = BigInt(balanceResp.totalBalance);
|
|
697
|
-
if (totalBalance < amountMist) {
|
|
698
|
-
throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient SUI balance`, {
|
|
699
|
-
available: totalBalance.toString(),
|
|
700
|
-
required: amountMist.toString()
|
|
701
|
-
});
|
|
702
|
-
}
|
|
703
|
-
const coin2 = coinWithBalance({ type: SUI_TYPE2, balance: amountMist, useGasCoin: false })(tx);
|
|
704
|
-
return { coin: coin2, effectiveAmount: amountMist, swapAll: false };
|
|
739
|
+
return selectCoinObjectsOnly(tx, client, owner, SUI_TYPE2, amountMist, false);
|
|
705
740
|
}
|
|
706
741
|
const [coin] = tx.splitCoins(tx.gas, [amountMist]);
|
|
707
742
|
return { coin, effectiveAmount: amountMist, swapAll: false };
|
|
@@ -929,7 +964,9 @@ async function addSwapToTx(tx, client, address, input) {
|
|
|
929
964
|
effectiveRaw = result.effectiveAmount;
|
|
930
965
|
} else {
|
|
931
966
|
const { selectAndSplitCoin: selectAndSplitCoin2 } = await Promise.resolve().then(() => (init_coinSelection(), coinSelection_exports));
|
|
932
|
-
const result = await selectAndSplitCoin2(tx, client, address, fromType, requestedRaw
|
|
967
|
+
const result = await selectAndSplitCoin2(tx, client, address, fromType, requestedRaw, {
|
|
968
|
+
sponsoredContext: input.sponsoredContext ?? false
|
|
969
|
+
});
|
|
933
970
|
inputCoin = result.coin;
|
|
934
971
|
effectiveRaw = result.effectiveAmount;
|
|
935
972
|
}
|
|
@@ -1154,7 +1191,6 @@ var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
|
1154
1191
|
var DEFAULT_GRPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
1155
1192
|
var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
|
|
1156
1193
|
var GASLESS_MIN_STABLE_AMOUNT = 0.01;
|
|
1157
|
-
process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
1158
1194
|
var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
|
|
1159
1195
|
var GAS_RESERVE_MIN = 0.05;
|
|
1160
1196
|
|
|
@@ -7896,7 +7932,9 @@ var WRITE_APPENDER_REGISTRY = {
|
|
|
7896
7932
|
coin = ctx.chainedCoin;
|
|
7897
7933
|
effectiveAmount = rawAmount;
|
|
7898
7934
|
} else {
|
|
7899
|
-
const r = await selectAndSplitCoin(tx, ctx.client, ctx.sender, assetInfo.type, rawAmount
|
|
7935
|
+
const r = await selectAndSplitCoin(tx, ctx.client, ctx.sender, assetInfo.type, rawAmount, {
|
|
7936
|
+
sponsoredContext: ctx.sponsoredContext
|
|
7937
|
+
});
|
|
7900
7938
|
coin = r.coin;
|
|
7901
7939
|
effectiveAmount = r.effectiveAmount;
|
|
7902
7940
|
}
|
|
@@ -7968,7 +8006,9 @@ var WRITE_APPENDER_REGISTRY = {
|
|
|
7968
8006
|
coin = ctx.chainedCoin;
|
|
7969
8007
|
effectiveAmount = rawAmount;
|
|
7970
8008
|
} else {
|
|
7971
|
-
const r = await selectAndSplitCoin(tx, ctx.client, ctx.sender, assetInfo.type, rawAmount
|
|
8009
|
+
const r = await selectAndSplitCoin(tx, ctx.client, ctx.sender, assetInfo.type, rawAmount, {
|
|
8010
|
+
sponsoredContext: ctx.sponsoredContext
|
|
8011
|
+
});
|
|
7972
8012
|
coin = r.coin;
|
|
7973
8013
|
effectiveAmount = r.effectiveAmount;
|
|
7974
8014
|
}
|