@ton/appkit 0.0.5-alpha.3 → 1.0.0-alpha.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/.turbo/turbo-build.log +4 -4
- package/CHANGELOG.md +144 -0
- package/README.md +8 -7
- package/dist/cjs/actions/connectors/watch-connector-by-id.d.ts.map +1 -1
- package/dist/cjs/actions/connectors/watch-connector-by-id.js +8 -3
- package/dist/cjs/actions/connectors/watch-connectors.d.ts.map +1 -1
- package/dist/cjs/actions/connectors/watch-connectors.js +8 -3
- package/dist/cjs/actions/index.d.ts +8 -0
- package/dist/cjs/actions/index.d.ts.map +1 -1
- package/dist/cjs/actions/index.js +18 -2
- package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.d.ts +1 -1
- package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.d.ts.map +1 -1
- package/dist/cjs/actions/jettons/create-transfer-jetton-transaction.js +17 -5
- package/dist/cjs/actions/jettons/get-jetton-balance.d.ts +1 -1
- package/dist/cjs/actions/jettons/get-jetton-balance.d.ts.map +1 -1
- package/dist/cjs/actions/jettons/get-jetton-balance.js +8 -3
- package/dist/cjs/actions/jettons/get-jetton-info.d.ts.map +1 -1
- package/dist/cjs/actions/jettons/get-jetton-info.js +15 -6
- package/dist/cjs/actions/jettons/get-jetton-wallet-address.d.ts +1 -1
- package/dist/cjs/actions/jettons/get-jetton-wallet-address.d.ts.map +1 -1
- package/dist/cjs/actions/jettons/get-jetton-wallet-address.js +15 -4
- package/dist/cjs/actions/nft/get-nft.d.ts +1 -1
- package/dist/cjs/actions/nft/get-nft.d.ts.map +1 -1
- package/dist/cjs/actions/providers/register-provider.d.ts +2 -1
- package/dist/cjs/actions/providers/register-provider.d.ts.map +1 -1
- package/dist/cjs/actions/staking/get-staking-provider-metadata.d.ts +19 -0
- package/dist/cjs/actions/staking/get-staking-provider-metadata.d.ts.map +1 -0
- package/dist/cjs/actions/staking/get-staking-provider-metadata.js +18 -0
- package/dist/cjs/actions/staking/get-staking-provider.d.ts +21 -0
- package/dist/cjs/actions/staking/get-staking-provider.d.ts.map +1 -0
- package/dist/cjs/actions/staking/get-staking-provider.js +17 -0
- package/dist/cjs/actions/staking/get-staking-providers.d.ts +3 -2
- package/dist/cjs/actions/staking/get-staking-providers.d.ts.map +1 -1
- package/dist/cjs/actions/staking/get-staking-providers.js +2 -2
- package/dist/cjs/actions/staking/set-default-staking-provider.d.ts +18 -0
- package/dist/cjs/actions/staking/set-default-staking-provider.d.ts.map +1 -0
- package/dist/cjs/actions/staking/set-default-staking-provider.js +18 -0
- package/dist/cjs/actions/staking/watch-staking-providers.d.ts +17 -0
- package/dist/cjs/actions/staking/watch-staking-providers.d.ts.map +1 -0
- package/dist/cjs/actions/staking/watch-staking-providers.js +28 -0
- package/dist/cjs/actions/swap/get-swap-provider.d.ts +15 -0
- package/dist/cjs/actions/swap/get-swap-provider.d.ts.map +1 -0
- package/dist/cjs/actions/swap/get-swap-provider.js +14 -0
- package/dist/cjs/actions/swap/get-swap-providers.d.ts +15 -0
- package/dist/cjs/actions/swap/get-swap-providers.d.ts.map +1 -0
- package/dist/cjs/actions/swap/get-swap-providers.js +17 -0
- package/dist/cjs/actions/swap/get-swap-quote.d.ts.map +1 -1
- package/dist/cjs/actions/swap/get-swap-quote.js +6 -1
- package/dist/cjs/actions/swap/set-default-swap-provider.d.ts +18 -0
- package/dist/cjs/actions/swap/set-default-swap-provider.d.ts.map +1 -0
- package/dist/cjs/actions/swap/set-default-swap-provider.js +18 -0
- package/dist/cjs/actions/swap/watch-swap-providers.d.ts +17 -0
- package/dist/cjs/actions/swap/watch-swap-providers.d.ts.map +1 -0
- package/dist/cjs/actions/swap/watch-swap-providers.js +29 -0
- package/dist/cjs/connectors/tonconnect/connectors/ton-connect-connector.d.ts +1 -2
- package/dist/cjs/connectors/tonconnect/connectors/ton-connect-connector.d.ts.map +1 -1
- package/dist/cjs/connectors/tonconnect/connectors/ton-connect-connector.js +16 -18
- package/dist/cjs/core/app-kit/constants/events.d.ts +3 -8
- package/dist/cjs/core/app-kit/constants/events.d.ts.map +1 -1
- package/dist/cjs/core/app-kit/constants/events.js +4 -9
- package/dist/cjs/core/app-kit/index.d.ts +2 -2
- package/dist/cjs/core/app-kit/index.d.ts.map +1 -1
- package/dist/cjs/core/app-kit/index.js +1 -2
- package/dist/cjs/core/app-kit/services/app-kit.d.ts +5 -2
- package/dist/cjs/core/app-kit/services/app-kit.d.ts.map +1 -1
- package/dist/cjs/core/app-kit/services/app-kit.js +12 -4
- package/dist/cjs/core/app-kit/types/config.d.ts +6 -3
- package/dist/cjs/core/app-kit/types/config.d.ts.map +1 -1
- package/dist/cjs/core/app-kit/types/events.d.ts +13 -13
- package/dist/cjs/core/app-kit/types/events.d.ts.map +1 -1
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.d.ts +20 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.d.ts.map +1 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.js +32 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.d.ts +9 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.d.ts.map +1 -0
- package/dist/cjs/core/cache/adapters/lru-app-kit-cache.test.js +68 -0
- package/dist/cjs/core/cache/index.d.ts +11 -0
- package/dist/cjs/core/cache/index.d.ts.map +1 -0
- package/dist/cjs/core/cache/index.js +14 -0
- package/dist/cjs/core/cache/types/app-kit-cache.d.ts +14 -0
- package/dist/cjs/core/cache/types/app-kit-cache.d.ts.map +1 -0
- package/dist/cjs/core/cache/types/app-kit-cache.js +9 -0
- package/dist/cjs/core/cache/utils/get-cache-key.d.ts +9 -0
- package/dist/cjs/core/cache/utils/get-cache-key.d.ts.map +1 -0
- package/dist/cjs/core/cache/utils/get-cache-key.js +12 -0
- package/dist/cjs/core/cache/utils/get-cache-key.test.d.ts +9 -0
- package/dist/cjs/core/cache/utils/get-cache-key.test.d.ts.map +1 -0
- package/dist/cjs/core/cache/utils/get-cache-key.test.js +30 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +1 -0
- package/dist/cjs/queries/balances/get-balance-by-address.d.ts.map +1 -1
- package/dist/cjs/queries/balances/get-balance-by-address.js +9 -3
- package/dist/cjs/queries/index.d.ts +0 -1
- package/dist/cjs/queries/index.d.ts.map +1 -1
- package/dist/cjs/queries/index.js +1 -3
- package/dist/cjs/queries/jettons/get-jetton-balance-by-address.d.ts.map +1 -1
- package/dist/cjs/queries/jettons/get-jetton-balance-by-address.js +11 -11
- package/dist/cjs/queries/jettons/get-jetton-info.d.ts.map +1 -1
- package/dist/cjs/queries/jettons/get-jetton-info.js +5 -1
- package/dist/cjs/queries/jettons/get-jetton-wallet-address.d.ts.map +1 -1
- package/dist/cjs/queries/jettons/get-jetton-wallet-address.js +6 -1
- package/dist/cjs/queries/jettons/get-jettons-by-address.d.ts.map +1 -1
- package/dist/cjs/queries/jettons/get-jettons-by-address.js +9 -3
- package/dist/cjs/queries/nft/get-nft.d.ts +1 -1
- package/dist/cjs/queries/nft/get-nft.d.ts.map +1 -1
- package/dist/cjs/queries/nft/get-nft.js +5 -1
- package/dist/cjs/queries/nft/get-nfts-by-address.d.ts.map +1 -1
- package/dist/cjs/queries/nft/get-nfts-by-address.js +5 -1
- package/dist/cjs/queries/staking/get-staked-balance.d.ts +1 -1
- package/dist/cjs/queries/staking/get-staked-balance.d.ts.map +1 -1
- package/dist/cjs/queries/staking/get-staked-balance.js +7 -1
- package/dist/cjs/queries/staking/get-staking-provider-info.d.ts +1 -1
- package/dist/cjs/queries/staking/get-staking-provider-info.d.ts.map +1 -1
- package/dist/cjs/queries/staking/get-staking-provider-info.js +3 -1
- package/dist/cjs/queries/staking/get-staking-quote.d.ts +1 -1
- package/dist/cjs/queries/staking/get-staking-quote.d.ts.map +1 -1
- package/dist/cjs/queries/staking/get-staking-quote.js +8 -2
- package/dist/cjs/queries/swap/get-swap-quote.d.ts.map +1 -1
- package/dist/cjs/queries/swap/get-swap-quote.js +1 -1
- package/dist/cjs/staking/index.d.ts +2 -2
- package/dist/cjs/staking/index.d.ts.map +1 -1
- package/dist/cjs/staking/index.js +3 -1
- package/dist/cjs/swap/index.d.ts +2 -1
- package/dist/cjs/swap/index.d.ts.map +1 -1
- package/dist/cjs/swap/index.js +8 -0
- package/dist/cjs/types/connector.d.ts +0 -6
- package/dist/cjs/types/connector.d.ts.map +1 -1
- package/dist/cjs/types/primitives.d.ts +1 -1
- package/dist/cjs/types/primitives.d.ts.map +1 -1
- package/dist/cjs/types/provider.d.ts +3 -3
- package/dist/cjs/types/provider.d.ts.map +1 -1
- package/dist/cjs/utils/address/is-valid-address.d.ts +11 -0
- package/dist/cjs/utils/address/is-valid-address.d.ts.map +1 -0
- package/dist/cjs/utils/address/is-valid-address.js +38 -0
- package/dist/cjs/utils/address/to-bounceble-address.d.ts +11 -0
- package/dist/cjs/utils/address/to-bounceble-address.d.ts.map +1 -0
- package/dist/cjs/utils/address/to-bounceble-address.js +36 -0
- package/dist/cjs/utils/address/to-non-bounceble-address.d.ts +11 -0
- package/dist/cjs/utils/address/to-non-bounceble-address.d.ts.map +1 -0
- package/dist/cjs/utils/address/to-non-bounceble-address.js +36 -0
- package/dist/cjs/utils/amount/calc-fiat-value.d.ts +13 -0
- package/dist/cjs/utils/amount/calc-fiat-value.d.ts.map +1 -0
- package/dist/cjs/utils/amount/calc-fiat-value.js +22 -0
- package/dist/cjs/utils/amount/calc-fiat-value.test.d.ts +9 -0
- package/dist/cjs/utils/amount/calc-fiat-value.test.d.ts.map +1 -0
- package/dist/cjs/utils/amount/calc-fiat-value.test.js +39 -0
- package/dist/cjs/utils/amount/format-large-value.d.ts +9 -0
- package/dist/cjs/utils/amount/format-large-value.d.ts.map +1 -0
- package/dist/cjs/utils/amount/format-large-value.js +40 -0
- package/dist/cjs/utils/amount/format-large-value.test.d.ts +9 -0
- package/dist/cjs/utils/amount/format-large-value.test.d.ts.map +1 -0
- package/dist/cjs/utils/amount/format-large-value.test.js +43 -0
- package/dist/cjs/utils/amount/truncate-decimals.d.ts +9 -0
- package/dist/cjs/utils/amount/truncate-decimals.d.ts.map +1 -0
- package/dist/cjs/utils/amount/truncate-decimals.js +59 -0
- package/dist/cjs/utils/amount/truncate-decimals.test.d.ts +9 -0
- package/dist/cjs/utils/amount/truncate-decimals.test.d.ts.map +1 -0
- package/dist/cjs/utils/amount/truncate-decimals.test.js +83 -0
- package/dist/cjs/utils/balance/calc-max-spendable.d.ts +33 -0
- package/dist/cjs/utils/balance/calc-max-spendable.d.ts.map +1 -0
- package/dist/cjs/utils/balance/calc-max-spendable.js +29 -0
- package/dist/cjs/utils/balance/calc-max-spendable.test.d.ts +9 -0
- package/dist/cjs/utils/balance/calc-max-spendable.test.d.ts.map +1 -0
- package/dist/cjs/utils/balance/calc-max-spendable.test.js +38 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.d.ts +58 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.d.ts.map +1 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.js +46 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.test.d.ts +9 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.test.d.ts.map +1 -0
- package/dist/cjs/utils/balance/get-ton-shortfall.test.js +133 -0
- package/dist/cjs/utils/functions/debounce.d.ts +80 -0
- package/dist/cjs/utils/functions/debounce.d.ts.map +1 -0
- package/dist/cjs/utils/functions/debounce.js +107 -0
- package/dist/cjs/utils/index.d.ts +10 -0
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +10 -0
- package/dist/cjs/utils/jetton/jetton-info.d.ts +2 -1
- package/dist/cjs/utils/jetton/jetton-info.d.ts.map +1 -1
- package/dist/cjs/utils/jetton/jetton-info.js +11 -1
- package/dist/cjs/utils/jetton/jetton-info.test.d.ts +9 -0
- package/dist/cjs/utils/jetton/jetton-info.test.d.ts.map +1 -0
- package/dist/cjs/utils/jetton/jetton-info.test.js +54 -0
- package/dist/cjs/utils/predicate/is-number.d.ts +9 -0
- package/dist/cjs/utils/predicate/is-number.d.ts.map +1 -0
- package/dist/cjs/utils/predicate/is-number.js +20 -0
- package/dist/cjs/utils/predicate/is-string.d.ts +1 -1
- package/dist/cjs/utils/predicate/is-string.d.ts.map +1 -1
- package/dist/cjs/utils/predicate/is-string.js +4 -3
- package/dist/esm/actions/connectors/watch-connector-by-id.d.ts.map +1 -1
- package/dist/esm/actions/connectors/watch-connector-by-id.js +8 -3
- package/dist/esm/actions/connectors/watch-connectors.d.ts.map +1 -1
- package/dist/esm/actions/connectors/watch-connectors.js +8 -3
- package/dist/esm/actions/index.d.ts +8 -0
- package/dist/esm/actions/index.d.ts.map +1 -1
- package/dist/esm/actions/index.js +8 -0
- package/dist/esm/actions/jettons/create-transfer-jetton-transaction.d.ts +1 -1
- package/dist/esm/actions/jettons/create-transfer-jetton-transaction.d.ts.map +1 -1
- package/dist/esm/actions/jettons/create-transfer-jetton-transaction.js +17 -5
- package/dist/esm/actions/jettons/get-jetton-balance.d.ts +1 -1
- package/dist/esm/actions/jettons/get-jetton-balance.d.ts.map +1 -1
- package/dist/esm/actions/jettons/get-jetton-balance.js +7 -2
- package/dist/esm/actions/jettons/get-jetton-info.d.ts.map +1 -1
- package/dist/esm/actions/jettons/get-jetton-info.js +15 -6
- package/dist/esm/actions/jettons/get-jetton-wallet-address.d.ts +1 -1
- package/dist/esm/actions/jettons/get-jetton-wallet-address.d.ts.map +1 -1
- package/dist/esm/actions/jettons/get-jetton-wallet-address.js +15 -4
- package/dist/esm/actions/nft/get-nft.d.ts +1 -1
- package/dist/esm/actions/nft/get-nft.d.ts.map +1 -1
- package/dist/esm/actions/providers/register-provider.d.ts +2 -1
- package/dist/esm/actions/providers/register-provider.d.ts.map +1 -1
- package/dist/esm/actions/staking/get-staking-provider-metadata.d.ts +19 -0
- package/dist/esm/actions/staking/get-staking-provider-metadata.d.ts.map +1 -0
- package/dist/esm/actions/staking/get-staking-provider-metadata.js +14 -0
- package/dist/esm/actions/staking/get-staking-provider.d.ts +21 -0
- package/dist/esm/actions/staking/get-staking-provider.d.ts.map +1 -0
- package/dist/esm/actions/staking/get-staking-provider.js +13 -0
- package/dist/esm/actions/staking/get-staking-providers.d.ts +3 -2
- package/dist/esm/actions/staking/get-staking-providers.d.ts.map +1 -1
- package/dist/esm/actions/staking/get-staking-providers.js +2 -2
- package/dist/esm/actions/staking/set-default-staking-provider.d.ts +18 -0
- package/dist/esm/actions/staking/set-default-staking-provider.d.ts.map +1 -0
- package/dist/esm/actions/staking/set-default-staking-provider.js +14 -0
- package/dist/esm/actions/staking/watch-staking-providers.d.ts +17 -0
- package/dist/esm/actions/staking/watch-staking-providers.d.ts.map +1 -0
- package/dist/esm/actions/staking/watch-staking-providers.js +24 -0
- package/dist/esm/actions/swap/get-swap-provider.d.ts +15 -0
- package/dist/esm/actions/swap/get-swap-provider.d.ts.map +1 -0
- package/dist/esm/actions/swap/get-swap-provider.js +10 -0
- package/dist/esm/actions/swap/get-swap-providers.d.ts +15 -0
- package/dist/esm/actions/swap/get-swap-providers.d.ts.map +1 -0
- package/dist/esm/actions/swap/get-swap-providers.js +13 -0
- package/dist/esm/actions/swap/get-swap-quote.d.ts.map +1 -1
- package/dist/esm/actions/swap/get-swap-quote.js +6 -1
- package/dist/esm/actions/swap/set-default-swap-provider.d.ts +18 -0
- package/dist/esm/actions/swap/set-default-swap-provider.d.ts.map +1 -0
- package/dist/esm/actions/swap/set-default-swap-provider.js +14 -0
- package/dist/esm/actions/swap/watch-swap-providers.d.ts +17 -0
- package/dist/esm/actions/swap/watch-swap-providers.d.ts.map +1 -0
- package/dist/esm/actions/swap/watch-swap-providers.js +25 -0
- package/dist/esm/connectors/tonconnect/connectors/ton-connect-connector.d.ts +1 -2
- package/dist/esm/connectors/tonconnect/connectors/ton-connect-connector.d.ts.map +1 -1
- package/dist/esm/connectors/tonconnect/connectors/ton-connect-connector.js +16 -18
- package/dist/esm/core/app-kit/constants/events.d.ts +3 -8
- package/dist/esm/core/app-kit/constants/events.d.ts.map +1 -1
- package/dist/esm/core/app-kit/constants/events.js +3 -8
- package/dist/esm/core/app-kit/index.d.ts +2 -2
- package/dist/esm/core/app-kit/index.d.ts.map +1 -1
- package/dist/esm/core/app-kit/index.js +1 -1
- package/dist/esm/core/app-kit/services/app-kit.d.ts +5 -2
- package/dist/esm/core/app-kit/services/app-kit.d.ts.map +1 -1
- package/dist/esm/core/app-kit/services/app-kit.js +12 -4
- package/dist/esm/core/app-kit/types/config.d.ts +6 -3
- package/dist/esm/core/app-kit/types/config.d.ts.map +1 -1
- package/dist/esm/core/app-kit/types/events.d.ts +13 -13
- package/dist/esm/core/app-kit/types/events.d.ts.map +1 -1
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.d.ts +20 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.d.ts.map +1 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.js +28 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.d.ts +9 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.d.ts.map +1 -0
- package/dist/esm/core/cache/adapters/lru-app-kit-cache.test.js +66 -0
- package/dist/esm/core/cache/index.d.ts +11 -0
- package/dist/esm/core/cache/index.d.ts.map +1 -0
- package/dist/esm/core/cache/index.js +9 -0
- package/dist/esm/core/cache/types/app-kit-cache.d.ts +14 -0
- package/dist/esm/core/cache/types/app-kit-cache.d.ts.map +1 -0
- package/dist/esm/core/cache/types/app-kit-cache.js +8 -0
- package/dist/esm/core/cache/utils/get-cache-key.d.ts +9 -0
- package/dist/esm/core/cache/utils/get-cache-key.d.ts.map +1 -0
- package/dist/esm/core/cache/utils/get-cache-key.js +8 -0
- package/dist/esm/core/cache/utils/get-cache-key.test.d.ts +9 -0
- package/dist/esm/core/cache/utils/get-cache-key.test.d.ts.map +1 -0
- package/dist/esm/core/cache/utils/get-cache-key.test.js +28 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/queries/balances/get-balance-by-address.d.ts.map +1 -1
- package/dist/esm/queries/balances/get-balance-by-address.js +10 -4
- package/dist/esm/queries/index.d.ts +0 -1
- package/dist/esm/queries/index.d.ts.map +1 -1
- package/dist/esm/queries/index.js +0 -1
- package/dist/esm/queries/jettons/get-jetton-balance-by-address.d.ts.map +1 -1
- package/dist/esm/queries/jettons/get-jetton-balance-by-address.js +12 -12
- package/dist/esm/queries/jettons/get-jetton-info.d.ts.map +1 -1
- package/dist/esm/queries/jettons/get-jetton-info.js +6 -2
- package/dist/esm/queries/jettons/get-jetton-wallet-address.d.ts.map +1 -1
- package/dist/esm/queries/jettons/get-jetton-wallet-address.js +7 -2
- package/dist/esm/queries/jettons/get-jettons-by-address.d.ts.map +1 -1
- package/dist/esm/queries/jettons/get-jettons-by-address.js +10 -4
- package/dist/esm/queries/nft/get-nft.d.ts +1 -1
- package/dist/esm/queries/nft/get-nft.d.ts.map +1 -1
- package/dist/esm/queries/nft/get-nft.js +6 -2
- package/dist/esm/queries/nft/get-nfts-by-address.d.ts.map +1 -1
- package/dist/esm/queries/nft/get-nfts-by-address.js +6 -2
- package/dist/esm/queries/staking/get-staked-balance.d.ts +1 -1
- package/dist/esm/queries/staking/get-staked-balance.d.ts.map +1 -1
- package/dist/esm/queries/staking/get-staked-balance.js +8 -2
- package/dist/esm/queries/staking/get-staking-provider-info.d.ts +1 -1
- package/dist/esm/queries/staking/get-staking-provider-info.d.ts.map +1 -1
- package/dist/esm/queries/staking/get-staking-provider-info.js +4 -2
- package/dist/esm/queries/staking/get-staking-quote.d.ts +1 -1
- package/dist/esm/queries/staking/get-staking-quote.d.ts.map +1 -1
- package/dist/esm/queries/staking/get-staking-quote.js +9 -3
- package/dist/esm/queries/swap/get-swap-quote.d.ts.map +1 -1
- package/dist/esm/queries/swap/get-swap-quote.js +1 -1
- package/dist/esm/staking/index.d.ts +2 -2
- package/dist/esm/staking/index.d.ts.map +1 -1
- package/dist/esm/staking/index.js +1 -1
- package/dist/esm/swap/index.d.ts +2 -1
- package/dist/esm/swap/index.d.ts.map +1 -1
- package/dist/esm/swap/index.js +1 -1
- package/dist/esm/types/connector.d.ts +0 -6
- package/dist/esm/types/connector.d.ts.map +1 -1
- package/dist/esm/types/primitives.d.ts +1 -1
- package/dist/esm/types/primitives.d.ts.map +1 -1
- package/dist/esm/types/provider.d.ts +3 -3
- package/dist/esm/types/provider.d.ts.map +1 -1
- package/dist/esm/utils/address/is-valid-address.d.ts +11 -0
- package/dist/esm/utils/address/is-valid-address.d.ts.map +1 -0
- package/dist/esm/utils/address/is-valid-address.js +33 -0
- package/dist/esm/utils/address/to-bounceble-address.d.ts +11 -0
- package/dist/esm/utils/address/to-bounceble-address.d.ts.map +1 -0
- package/dist/esm/utils/address/to-bounceble-address.js +31 -0
- package/dist/esm/utils/address/to-non-bounceble-address.d.ts +11 -0
- package/dist/esm/utils/address/to-non-bounceble-address.d.ts.map +1 -0
- package/dist/esm/utils/address/to-non-bounceble-address.js +31 -0
- package/dist/esm/utils/amount/calc-fiat-value.d.ts +13 -0
- package/dist/esm/utils/amount/calc-fiat-value.d.ts.map +1 -0
- package/dist/esm/utils/amount/calc-fiat-value.js +19 -0
- package/dist/esm/utils/amount/calc-fiat-value.test.d.ts +9 -0
- package/dist/esm/utils/amount/calc-fiat-value.test.d.ts.map +1 -0
- package/dist/esm/utils/amount/calc-fiat-value.test.js +37 -0
- package/dist/esm/utils/amount/format-large-value.d.ts +9 -0
- package/dist/esm/utils/amount/format-large-value.d.ts.map +1 -0
- package/dist/esm/utils/amount/format-large-value.js +36 -0
- package/dist/esm/utils/amount/format-large-value.test.d.ts +9 -0
- package/dist/esm/utils/amount/format-large-value.test.d.ts.map +1 -0
- package/dist/esm/utils/amount/format-large-value.test.js +41 -0
- package/dist/esm/utils/amount/truncate-decimals.d.ts +9 -0
- package/dist/esm/utils/amount/truncate-decimals.d.ts.map +1 -0
- package/dist/esm/utils/amount/truncate-decimals.js +55 -0
- package/dist/esm/utils/amount/truncate-decimals.test.d.ts +9 -0
- package/dist/esm/utils/amount/truncate-decimals.test.d.ts.map +1 -0
- package/dist/esm/utils/amount/truncate-decimals.test.js +81 -0
- package/dist/esm/utils/balance/calc-max-spendable.d.ts +33 -0
- package/dist/esm/utils/balance/calc-max-spendable.d.ts.map +1 -0
- package/dist/esm/utils/balance/calc-max-spendable.js +25 -0
- package/dist/esm/utils/balance/calc-max-spendable.test.d.ts +9 -0
- package/dist/esm/utils/balance/calc-max-spendable.test.d.ts.map +1 -0
- package/dist/esm/utils/balance/calc-max-spendable.test.js +36 -0
- package/dist/esm/utils/balance/get-ton-shortfall.d.ts +58 -0
- package/dist/esm/utils/balance/get-ton-shortfall.d.ts.map +1 -0
- package/dist/esm/utils/balance/get-ton-shortfall.js +42 -0
- package/dist/esm/utils/balance/get-ton-shortfall.test.d.ts +9 -0
- package/dist/esm/utils/balance/get-ton-shortfall.test.d.ts.map +1 -0
- package/dist/esm/utils/balance/get-ton-shortfall.test.js +131 -0
- package/dist/esm/utils/functions/debounce.d.ts +80 -0
- package/dist/esm/utils/functions/debounce.d.ts.map +1 -0
- package/dist/esm/utils/functions/debounce.js +103 -0
- package/dist/esm/utils/index.d.ts +10 -0
- package/dist/esm/utils/index.d.ts.map +1 -1
- package/dist/esm/utils/index.js +10 -0
- package/dist/esm/utils/jetton/jetton-info.d.ts +2 -1
- package/dist/esm/utils/jetton/jetton-info.d.ts.map +1 -1
- package/dist/esm/utils/jetton/jetton-info.js +9 -0
- package/dist/esm/utils/jetton/jetton-info.test.d.ts +9 -0
- package/dist/esm/utils/jetton/jetton-info.test.d.ts.map +1 -0
- package/dist/esm/utils/jetton/jetton-info.test.js +52 -0
- package/dist/esm/utils/predicate/is-number.d.ts +9 -0
- package/dist/esm/utils/predicate/is-number.d.ts.map +1 -0
- package/dist/esm/utils/predicate/is-number.js +16 -0
- package/dist/esm/utils/predicate/is-string.d.ts +1 -1
- package/dist/esm/utils/predicate/is-string.d.ts.map +1 -1
- package/dist/esm/utils/predicate/is-string.js +2 -2
- package/docs/actions.md +64 -15
- package/docs/connectors.md +5 -25
- package/docs/staking.md +7 -6
- package/docs/swap.md +11 -10
- package/package.json +4 -3
- package/src/actions/connectors/watch-connector-by-id.ts +9 -3
- package/src/actions/connectors/watch-connectors.ts +9 -3
- package/src/actions/index.ts +32 -0
- package/src/actions/jettons/create-transfer-jetton-transaction.ts +22 -6
- package/src/actions/jettons/get-jetton-balance.ts +10 -3
- package/src/actions/jettons/get-jetton-info.ts +18 -6
- package/src/actions/jettons/get-jetton-wallet-address.ts +19 -5
- package/src/actions/nft/get-nft.ts +1 -1
- package/src/actions/providers/register-provider.ts +2 -1
- package/src/actions/staking/get-staking-provider-metadata.ts +32 -0
- package/src/actions/staking/get-staking-provider.ts +30 -0
- package/src/actions/staking/get-staking-providers.ts +5 -3
- package/src/actions/staking/set-default-staking-provider.ts +26 -0
- package/src/actions/staking/watch-staking-providers.ts +39 -0
- package/src/actions/swap/get-swap-provider.ts +21 -0
- package/src/actions/swap/get-swap-providers.ts +20 -0
- package/src/actions/swap/get-swap-quote.ts +7 -1
- package/src/actions/swap/set-default-swap-provider.ts +26 -0
- package/src/actions/swap/watch-swap-providers.ts +38 -0
- package/src/connectors/tonconnect/connectors/ton-connect-connector.ts +22 -20
- package/src/core/app-kit/constants/events.ts +3 -9
- package/src/core/app-kit/index.ts +4 -4
- package/src/core/app-kit/services/app-kit.ts +18 -7
- package/src/core/app-kit/types/config.ts +6 -3
- package/src/core/app-kit/types/events.ts +13 -15
- package/src/core/cache/adapters/lru-app-kit-cache.test.ts +77 -0
- package/src/core/cache/adapters/lru-app-kit-cache.ts +38 -0
- package/src/core/cache/index.ts +12 -0
- package/src/core/cache/types/app-kit-cache.ts +14 -0
- package/src/core/cache/utils/get-cache-key.test.ts +34 -0
- package/src/core/cache/utils/get-cache-key.ts +12 -0
- package/src/index.ts +1 -0
- package/src/queries/balances/get-balance-by-address.ts +11 -4
- package/src/queries/index.ts +0 -6
- package/src/queries/jettons/get-jetton-balance-by-address.ts +13 -12
- package/src/queries/jettons/get-jetton-info.ts +6 -2
- package/src/queries/jettons/get-jetton-wallet-address.ts +7 -2
- package/src/queries/jettons/get-jettons-by-address.ts +18 -4
- package/src/queries/nft/get-nft.ts +7 -3
- package/src/queries/nft/get-nfts-by-address.ts +6 -2
- package/src/queries/staking/get-staked-balance.ts +10 -3
- package/src/queries/staking/get-staking-provider-info.ts +5 -2
- package/src/queries/staking/get-staking-quote.ts +13 -4
- package/src/queries/swap/get-swap-quote.ts +3 -1
- package/src/staking/index.ts +10 -1
- package/src/swap/index.ts +2 -4
- package/src/types/connector.ts +0 -8
- package/src/types/primitives.ts +1 -1
- package/src/types/provider.ts +3 -3
- package/src/utils/address/is-valid-address.ts +40 -0
- package/src/utils/address/to-bounceble-address.ts +35 -0
- package/src/utils/address/to-non-bounceble-address.ts +35 -0
- package/src/utils/amount/calc-fiat-value.test.ts +46 -0
- package/src/utils/amount/calc-fiat-value.ts +18 -0
- package/src/utils/amount/format-large-value.test.ts +50 -0
- package/src/utils/amount/format-large-value.ts +43 -0
- package/src/utils/amount/truncate-decimals.test.ts +97 -0
- package/src/utils/amount/truncate-decimals.ts +56 -0
- package/src/utils/balance/calc-max-spendable.test.ts +46 -0
- package/src/utils/balance/calc-max-spendable.ts +44 -0
- package/src/utils/balance/get-ton-shortfall.test.ts +148 -0
- package/src/utils/balance/get-ton-shortfall.ts +82 -0
- package/src/utils/functions/debounce.ts +169 -0
- package/src/utils/index.ts +10 -0
- package/src/utils/jetton/jetton-info.test.ts +65 -0
- package/src/utils/jetton/jetton-info.ts +12 -1
- package/src/utils/predicate/is-number.ts +19 -0
- package/src/utils/predicate/is-string.ts +2 -2
- package/dist/cjs/queries/staking/get-staking-providers.d.ts +0 -20
- package/dist/cjs/queries/staking/get-staking-providers.d.ts.map +0 -1
- package/dist/cjs/queries/staking/get-staking-providers.js +0 -25
- package/dist/esm/queries/staking/get-staking-providers.d.ts +0 -20
- package/dist/esm/queries/staking/get-staking-providers.d.ts.map +0 -1
- package/dist/esm/queries/staking/get-staking-providers.js +0 -20
- package/src/queries/staking/get-staking-providers.ts +0 -52
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc-fiat-value.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/calc-fiat-value.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const vitest_1 = require("vitest");
|
|
11
|
+
const calc_fiat_value_1 = require("./calc-fiat-value");
|
|
12
|
+
(0, vitest_1.describe)('calcFiatValue', () => {
|
|
13
|
+
(0, vitest_1.it)('should return 0 when rate is undefined', () => {
|
|
14
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('100', undefined)).toBe('0');
|
|
15
|
+
});
|
|
16
|
+
(0, vitest_1.it)('should return 0 when rate is 0', () => {
|
|
17
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('100', '0')).toBe('0');
|
|
18
|
+
});
|
|
19
|
+
(0, vitest_1.it)('should return 0 when amount is 0', () => {
|
|
20
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('0', '1.5')).toBe('0');
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)('should return 0 when amount is negative', () => {
|
|
23
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('-10', '1.5')).toBe('0');
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)('should return 0 when amount is not a valid number', () => {
|
|
26
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('abc', '1.5')).toBe('0');
|
|
27
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('', '1.5')).toBe('0');
|
|
28
|
+
});
|
|
29
|
+
(0, vitest_1.it)('should calculate fiat value without rounding', () => {
|
|
30
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('100', '1.5')).toBe('150');
|
|
31
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('1', '0.001')).toBe('0.001');
|
|
32
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('3', '1.005')).toBe('3.015');
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.it)('should handle decimal amounts without rounding', () => {
|
|
35
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('0.5', '2')).toBe('1');
|
|
36
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('1.23456', '100')).toBe('123.456');
|
|
37
|
+
(0, vitest_1.expect)((0, calc_fiat_value_1.calcFiatValue)('2.996876', '1')).toBe('2.996876');
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare const formatLargeValue: (amount: string, decimals?: number, minimumFractionDigits?: number) => string;
|
|
9
|
+
//# sourceMappingURL=format-large-value.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-large-value.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/format-large-value.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,WAAU,MAAU,EAAE,wBAAuB,MAAU,KAAG,MAkC1G,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.formatLargeValue = void 0;
|
|
11
|
+
const formatLargeValue = (amount, decimals = 2, minimumFractionDigits = 0) => {
|
|
12
|
+
const cleanAmount = amount.toString().replace(/\s/g, '');
|
|
13
|
+
const intPart = cleanAmount.split('.')[0] || '0';
|
|
14
|
+
// value > 100 000 000 000 000 => 100 T
|
|
15
|
+
if (intPart.length > 12) {
|
|
16
|
+
const value = Number(intPart.slice(0, -10)) / 100;
|
|
17
|
+
return `${value.toLocaleString('en-US')}T`;
|
|
18
|
+
}
|
|
19
|
+
// value > 100 000 000 000 => 100 B
|
|
20
|
+
if (intPart.length > 9) {
|
|
21
|
+
const value = Number(intPart.slice(0, -7)) / 100;
|
|
22
|
+
return `${value.toLocaleString('en-US')}B`;
|
|
23
|
+
}
|
|
24
|
+
// value > 10 000 000 => 10 M
|
|
25
|
+
if (intPart.length > 6) {
|
|
26
|
+
const value = Number(intPart.slice(0, -4)) / 100;
|
|
27
|
+
return `${value.toLocaleString('en-US')}M`;
|
|
28
|
+
}
|
|
29
|
+
const value = parseFloat(cleanAmount);
|
|
30
|
+
if (isNaN(value)) {
|
|
31
|
+
return '0';
|
|
32
|
+
}
|
|
33
|
+
const factor = Math.pow(10, decimals);
|
|
34
|
+
const truncated = Math.floor(value * factor) / factor;
|
|
35
|
+
return truncated.toLocaleString('en-US', {
|
|
36
|
+
minimumFractionDigits,
|
|
37
|
+
maximumFractionDigits: decimals,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
exports.formatLargeValue = formatLargeValue;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-large-value.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/format-large-value.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const vitest_1 = require("vitest");
|
|
11
|
+
const format_large_value_1 = require("./format-large-value");
|
|
12
|
+
(0, vitest_1.describe)('formatLargeValue', () => {
|
|
13
|
+
(0, vitest_1.it)('should format trillion values', () => {
|
|
14
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1000000000000')).toBe('1T');
|
|
15
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1230000000000')).toBe('1.23T');
|
|
16
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('12345678901234')).toBe('12.34T');
|
|
17
|
+
});
|
|
18
|
+
(0, vitest_1.it)('should format billion values', () => {
|
|
19
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1000000000')).toBe('1B');
|
|
20
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1230000000')).toBe('1.23B');
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)('should format million values', () => {
|
|
23
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1000000')).toBe('1M');
|
|
24
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1230000')).toBe('1.23M');
|
|
25
|
+
});
|
|
26
|
+
(0, vitest_1.it)('should format smaller values using toLocaleString', () => {
|
|
27
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1234.56')).toBe('1,234.56');
|
|
28
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('100')).toBe('100');
|
|
29
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('0')).toBe('0');
|
|
30
|
+
});
|
|
31
|
+
(0, vitest_1.it)('should handle spaces and formatting', () => {
|
|
32
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1 000 000')).toBe('1M');
|
|
33
|
+
});
|
|
34
|
+
(0, vitest_1.it)('should respect decimals for small values', () => {
|
|
35
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1234.5678', 4)).toBe('1,234.5678');
|
|
36
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('1234.5678', 2)).toBe('1,234.56');
|
|
37
|
+
});
|
|
38
|
+
(0, vitest_1.it)('should round down (floor) fractional values', () => {
|
|
39
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('2.996848', 2)).toBe('2.99');
|
|
40
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('2.996848', 6)).toBe('2.996848');
|
|
41
|
+
(0, vitest_1.expect)((0, format_large_value_1.formatLargeValue)('0.9999', 2)).toBe('0.99');
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
export declare const truncateDecimals: (value: string | number, maxDecimals: number) => string;
|
|
9
|
+
//# sourceMappingURL=truncate-decimals.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate-decimals.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/truncate-decimals.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AA+BH,eAAO,MAAM,gBAAgB,GAAI,OAAO,MAAM,GAAG,MAAM,EAAE,aAAa,MAAM,KAAG,MAkB9E,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.truncateDecimals = void 0;
|
|
11
|
+
/**
|
|
12
|
+
* Converts a number to a plain decimal string, expanding scientific notation
|
|
13
|
+
* like "1.23e-9" into "0.00000000123".
|
|
14
|
+
*/
|
|
15
|
+
const toPlainDecimalString = (num) => {
|
|
16
|
+
const str = num.toString();
|
|
17
|
+
if (!str.includes('e') && !str.includes('E'))
|
|
18
|
+
return str;
|
|
19
|
+
const [base = '0', exponent = '0'] = str.split(/[eE]/);
|
|
20
|
+
const exp = Number(exponent);
|
|
21
|
+
const isNegative = base.startsWith('-');
|
|
22
|
+
const absBase = isNegative ? base.slice(1) : base;
|
|
23
|
+
const [intPart, decPart = ''] = absBase.split('.');
|
|
24
|
+
let result;
|
|
25
|
+
if (exp < 0) {
|
|
26
|
+
result = '0.' + '0'.repeat(Math.abs(exp) - 1) + intPart + decPart;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const addZeros = exp - decPart.length;
|
|
30
|
+
if (addZeros >= 0) {
|
|
31
|
+
result = intPart + decPart + '0'.repeat(addZeros);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
result = intPart + decPart.slice(0, exp) + '.' + decPart.slice(exp);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return isNegative ? '-' + result : result;
|
|
38
|
+
};
|
|
39
|
+
const truncateDecimals = (value, maxDecimals) => {
|
|
40
|
+
let strValue;
|
|
41
|
+
if (typeof value === 'number') {
|
|
42
|
+
strValue = toPlainDecimalString(value);
|
|
43
|
+
}
|
|
44
|
+
else if (value.includes('e') || value.includes('E')) {
|
|
45
|
+
const num = Number(value);
|
|
46
|
+
if (Number.isNaN(num))
|
|
47
|
+
return value;
|
|
48
|
+
strValue = toPlainDecimalString(num);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
strValue = value;
|
|
52
|
+
}
|
|
53
|
+
const dotIndex = strValue.indexOf('.');
|
|
54
|
+
if (dotIndex === -1)
|
|
55
|
+
return strValue;
|
|
56
|
+
const result = strValue.slice(0, dotIndex + 1 + maxDecimals);
|
|
57
|
+
return result.endsWith('.') ? result.slice(0, -1) : result;
|
|
58
|
+
};
|
|
59
|
+
exports.truncateDecimals = truncateDecimals;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"truncate-decimals.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/amount/truncate-decimals.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const vitest_1 = require("vitest");
|
|
11
|
+
const truncate_decimals_1 = require("./truncate-decimals");
|
|
12
|
+
(0, vitest_1.describe)('truncateDecimals', () => {
|
|
13
|
+
(0, vitest_1.it)('should return integers unchanged', () => {
|
|
14
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('123', 2)).toBe('123');
|
|
15
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('0', 5)).toBe('0');
|
|
16
|
+
});
|
|
17
|
+
(0, vitest_1.it)('should truncate decimals exceeding maxDecimals', () => {
|
|
18
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.23456', 2)).toBe('1.23');
|
|
19
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.23456', 4)).toBe('1.2345');
|
|
20
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('0.123456789', 9)).toBe('0.123456789');
|
|
21
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('0.1234567890', 9)).toBe('0.123456789');
|
|
22
|
+
});
|
|
23
|
+
(0, vitest_1.it)('should return value unchanged when decimals are within limit', () => {
|
|
24
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.23', 5)).toBe('1.23');
|
|
25
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.2', 2)).toBe('1.2');
|
|
26
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('5.0', 1)).toBe('5.0');
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)('should handle maxDecimals of 0', () => {
|
|
29
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.999', 0)).toBe('1');
|
|
30
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('42.1', 0)).toBe('42');
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.it)('should strip trailing dot', () => {
|
|
33
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.', 3)).toBe('1');
|
|
34
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.', 0)).toBe('1');
|
|
35
|
+
});
|
|
36
|
+
(0, vitest_1.it)('should handle empty string', () => {
|
|
37
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('', 2)).toBe('');
|
|
38
|
+
});
|
|
39
|
+
(0, vitest_1.it)('should handle number input', () => {
|
|
40
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(1.23456, 2)).toBe('1.23');
|
|
41
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(42, 3)).toBe('42');
|
|
42
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(0.1, 5)).toBe('0.1');
|
|
43
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(3.14159, 0)).toBe('3');
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('should handle scientific notation strings', () => {
|
|
46
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.095492908209088e-9', 9)).toBe('0.000000001');
|
|
47
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('5e-7', 9)).toBe('0.0000005');
|
|
48
|
+
});
|
|
49
|
+
(0, vitest_1.it)('should handle numbers that produce scientific notation', () => {
|
|
50
|
+
const tiny = 0.000000001 * 1.095492908209088; // 1.095492908209088e-9
|
|
51
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(tiny, 9)).toBe('0.000000001');
|
|
52
|
+
});
|
|
53
|
+
(0, vitest_1.it)('should handle negative numbers and negative scientific notation', () => {
|
|
54
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('-1.23456', 2)).toBe('-1.23');
|
|
55
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('-5e-7', 9)).toBe('-0.0000005');
|
|
56
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(-0.0000005, 9)).toBe('-0.0000005');
|
|
57
|
+
});
|
|
58
|
+
(0, vitest_1.it)('should handle scientific notation with positive exponents', () => {
|
|
59
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.2345e2', 2)).toBe('123.45');
|
|
60
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1.2345e+2', 0)).toBe('123');
|
|
61
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('5.2e9', 0)).toBe('5200000000');
|
|
62
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('-1.23e+9', 0)).toBe('-1230000000');
|
|
63
|
+
});
|
|
64
|
+
(0, vitest_1.it)('should handle extreme scientific exponents', () => {
|
|
65
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1e-100', 100)).toBe('0.' + '0'.repeat(99) + '1');
|
|
66
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('1e21', 0)).toBe('1000000000000000000000');
|
|
67
|
+
});
|
|
68
|
+
(0, vitest_1.it)('should handle NaN and Infinity', () => {
|
|
69
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(NaN, 2)).toBe('NaN');
|
|
70
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(Infinity, 2)).toBe('Infinity');
|
|
71
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(-Infinity, 2)).toBe('-Infinity');
|
|
72
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('NaN', 2)).toBe('NaN');
|
|
73
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)('Infinity', 2)).toBe('Infinity');
|
|
74
|
+
});
|
|
75
|
+
(0, vitest_1.it)('should handle native numbers with e (scientific notation)', () => {
|
|
76
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(1e-10, 10)).toBe('0.0000000001');
|
|
77
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(1.23e-8, 10)).toBe('0.0000000123');
|
|
78
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(-5.43e-7, 9)).toBe('-0.000000543');
|
|
79
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(5.2e9, 0)).toBe('5200000000');
|
|
80
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(-1.23e9, 0)).toBe('-1230000000');
|
|
81
|
+
(0, vitest_1.expect)((0, truncate_decimals_1.truncateDecimals)(1e21, 0)).toBe('1000000000000000000000');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Default TON reserve subtracted from balance when computing the max spendable amount
|
|
10
|
+
* for a native TON operation — leaves room for network fees. 0.1 TON.
|
|
11
|
+
*/
|
|
12
|
+
export declare const DEFAULT_TON_FEE_RESERVE_NANOS = 100000000n;
|
|
13
|
+
export interface CalcMaxSpendableParams {
|
|
14
|
+
/** User's balance of `token`, as a decimal string. */
|
|
15
|
+
balance: string;
|
|
16
|
+
/** The token the user is going to spend. */
|
|
17
|
+
token: {
|
|
18
|
+
address: string;
|
|
19
|
+
decimals: number;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* TON reserve (in nanos) subtracted from balance when the token is native TON.
|
|
23
|
+
* Ignored for jettons. Defaults to {@link DEFAULT_TON_FEE_RESERVE_NANOS}.
|
|
24
|
+
*/
|
|
25
|
+
feeReserveNanos?: bigint;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compute the max spendable amount a user can place into an input when they click MAX.
|
|
29
|
+
* For native TON — subtracts a fixed reserve so the user still has room for network fees.
|
|
30
|
+
* For jettons — returns the full balance (gas is paid from TON separately).
|
|
31
|
+
*/
|
|
32
|
+
export declare const calcMaxSpendable: ({ balance, token, feeReserveNanos, }: CalcMaxSpendableParams) => string;
|
|
33
|
+
//# sourceMappingURL=calc-max-spendable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc-max-spendable.d.ts","sourceRoot":"","sources":["../../../../src/utils/balance/calc-max-spendable.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,eAAO,MAAM,6BAA6B,aAAe,CAAC;AAE1D,MAAM,WAAW,sBAAsB;IACnC,sDAAsD;IACtD,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,KAAK,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAC7C;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,GAAI,sCAI9B,sBAAsB,KAAG,MAM3B,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.calcMaxSpendable = exports.DEFAULT_TON_FEE_RESERVE_NANOS = void 0;
|
|
11
|
+
const walletkit_1 = require("@ton/walletkit");
|
|
12
|
+
/**
|
|
13
|
+
* Default TON reserve subtracted from balance when computing the max spendable amount
|
|
14
|
+
* for a native TON operation — leaves room for network fees. 0.1 TON.
|
|
15
|
+
*/
|
|
16
|
+
exports.DEFAULT_TON_FEE_RESERVE_NANOS = 100000000n;
|
|
17
|
+
/**
|
|
18
|
+
* Compute the max spendable amount a user can place into an input when they click MAX.
|
|
19
|
+
* For native TON — subtracts a fixed reserve so the user still has room for network fees.
|
|
20
|
+
* For jettons — returns the full balance (gas is paid from TON separately).
|
|
21
|
+
*/
|
|
22
|
+
const calcMaxSpendable = ({ balance, token, feeReserveNanos = exports.DEFAULT_TON_FEE_RESERVE_NANOS, }) => {
|
|
23
|
+
if (token.address !== 'ton')
|
|
24
|
+
return balance;
|
|
25
|
+
const balanceNanos = (0, walletkit_1.parseUnits)(balance, token.decimals);
|
|
26
|
+
const reducedNanos = balanceNanos > feeReserveNanos ? balanceNanos - feeReserveNanos : 0n;
|
|
27
|
+
return (0, walletkit_1.formatUnits)(reducedNanos, token.decimals);
|
|
28
|
+
};
|
|
29
|
+
exports.calcMaxSpendable = calcMaxSpendable;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calc-max-spendable.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/balance/calc-max-spendable.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
const vitest_1 = require("vitest");
|
|
11
|
+
const calc_max_spendable_1 = require("./calc-max-spendable");
|
|
12
|
+
const TON = { address: 'ton', decimals: 9 };
|
|
13
|
+
const JETTON = { address: 'EQA_jetton', decimals: 6 };
|
|
14
|
+
(0, vitest_1.describe)('calcMaxSpendable', () => {
|
|
15
|
+
(0, vitest_1.it)('returns balance minus the TON fee reserve for native TON', () => {
|
|
16
|
+
// 1 TON balance, default reserve 0.1 TON → 0.9 TON spendable.
|
|
17
|
+
(0, vitest_1.expect)((0, calc_max_spendable_1.calcMaxSpendable)({ balance: '1', token: TON })).toBe('0.9');
|
|
18
|
+
});
|
|
19
|
+
(0, vitest_1.it)('returns the full balance for a jetton (no reserve)', () => {
|
|
20
|
+
(0, vitest_1.expect)((0, calc_max_spendable_1.calcMaxSpendable)({ balance: '100', token: JETTON })).toBe('100');
|
|
21
|
+
});
|
|
22
|
+
(0, vitest_1.it)('clamps to zero when balance is below the reserve', () => {
|
|
23
|
+
(0, vitest_1.expect)((0, calc_max_spendable_1.calcMaxSpendable)({ balance: '0.05', token: TON })).toBe('0');
|
|
24
|
+
});
|
|
25
|
+
(0, vitest_1.it)('clamps to zero when balance equals the reserve', () => {
|
|
26
|
+
(0, vitest_1.expect)((0, calc_max_spendable_1.calcMaxSpendable)({ balance: '0.1', token: TON })).toBe('0');
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.it)('respects a custom feeReserveNanos', () => {
|
|
29
|
+
// 1 TON balance, 0.5 TON reserve → 0.5 TON spendable.
|
|
30
|
+
(0, vitest_1.expect)((0, calc_max_spendable_1.calcMaxSpendable)({ balance: '1', token: TON, feeReserveNanos: 500000000n })).toBe('0.5');
|
|
31
|
+
});
|
|
32
|
+
(0, vitest_1.it)('ignores feeReserveNanos for jettons', () => {
|
|
33
|
+
(0, vitest_1.expect)((0, calc_max_spendable_1.calcMaxSpendable)({ balance: '100', token: JETTON, feeReserveNanos: 999999999999n })).toBe('100');
|
|
34
|
+
});
|
|
35
|
+
(0, vitest_1.it)('exports a sane default reserve', () => {
|
|
36
|
+
(0, vitest_1.expect)(calc_max_spendable_1.DEFAULT_TON_FEE_RESERVE_NANOS).toBe(100000000n);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) TonTech.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/** Default extra TON buffer added on top of built transaction outflow when checking balance before sending. */
|
|
9
|
+
export declare const DEFAULT_GAS_BUFFER_NANOS = 100000000n;
|
|
10
|
+
/**
|
|
11
|
+
* Default extra headroom baked into the suggested reduced amount, on top of the gas buffer.
|
|
12
|
+
* Covers quote/gas drift between the current built tx and the one that will actually be sent
|
|
13
|
+
* after the amount changes. 0.02 TON.
|
|
14
|
+
*/
|
|
15
|
+
export declare const DEFAULT_SAFETY_MARGIN_NANOS = 20000000n;
|
|
16
|
+
export type TonShortfall = {
|
|
17
|
+
mode: 'reduce';
|
|
18
|
+
requiredNanos: bigint;
|
|
19
|
+
suggestedFromAmount: string;
|
|
20
|
+
} | {
|
|
21
|
+
mode: 'topup';
|
|
22
|
+
requiredNanos: bigint;
|
|
23
|
+
suggestedFromAmount: '';
|
|
24
|
+
};
|
|
25
|
+
export interface GetTonShortfallParams {
|
|
26
|
+
/** Messages of the built transaction. Each `amount` is the TON value in nanos attached to the message. */
|
|
27
|
+
messages: Array<{
|
|
28
|
+
amount: string;
|
|
29
|
+
}>;
|
|
30
|
+
/** User's current TON balance as a decimal string (same format `formatUnits(balance, 9)` returns). */
|
|
31
|
+
tonBalance: string | undefined;
|
|
32
|
+
/** The outgoing token — `{ address: 'ton' }` when the user spends TON, otherwise a jetton. */
|
|
33
|
+
fromToken: {
|
|
34
|
+
address: string;
|
|
35
|
+
};
|
|
36
|
+
/** Amount the user intends to spend in `fromToken` units, as a decimal string. */
|
|
37
|
+
fromAmount: string;
|
|
38
|
+
/**
|
|
39
|
+
* Extra TON headroom on top of built-tx outflow when checking balance before sending.
|
|
40
|
+
* Defaults to {@link DEFAULT_GAS_BUFFER_NANOS}.
|
|
41
|
+
*/
|
|
42
|
+
gasBufferNanos?: bigint;
|
|
43
|
+
/**
|
|
44
|
+
* Extra headroom baked into the suggested reduced amount, on top of the gas buffer.
|
|
45
|
+
* Defaults to {@link DEFAULT_SAFETY_MARGIN_NANOS}.
|
|
46
|
+
*/
|
|
47
|
+
safetyMarginNanos?: bigint;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check whether the user's TON balance covers the built transaction.
|
|
51
|
+
* - Returns `null` if the balance is sufficient.
|
|
52
|
+
* - Returns `{ mode: 'reduce', ... }` with a smaller suggested `fromAmount` when `fromToken` is TON
|
|
53
|
+
* and the balance is enough to cover at least gas (user can fix it by reducing the amount).
|
|
54
|
+
* - Returns `{ mode: 'topup', ... }` when `fromToken` is a jetton (reducing jetton amount won't free up TON gas),
|
|
55
|
+
* or when `fromToken` is TON but the balance can't even cover gas (reducing won't help — user must top up).
|
|
56
|
+
*/
|
|
57
|
+
export declare const getTonShortfall: ({ messages, tonBalance, fromToken, fromAmount, gasBufferNanos, safetyMarginNanos, }: GetTonShortfallParams) => TonShortfall | undefined;
|
|
58
|
+
//# sourceMappingURL=get-ton-shortfall.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-ton-shortfall.d.ts","sourceRoot":"","sources":["../../../../src/utils/balance/get-ton-shortfall.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,+GAA+G;AAC/G,eAAO,MAAM,wBAAwB,aAAe,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,2BAA2B,YAAc,CAAC;AAEvD,MAAM,MAAM,YAAY,GAClB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,MAAM,CAAA;CAAE,GACtE;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,MAAM,CAAC;IAAC,mBAAmB,EAAE,EAAE,CAAA;CAAE,CAAC;AAExE,MAAM,WAAW,qBAAqB;IAClC,0GAA0G;IAC1G,QAAQ,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACpC,sGAAsG;IACtG,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,8FAA8F;IAC9F,SAAS,EAAE;QAAE,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/B,kFAAkF;IAClF,UAAU,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC9B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GAAI,qFAO7B,qBAAqB,KAAG,YAAY,GAAG,SAqBzC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Copyright (c) TonTech.
|
|
4
|
+
*
|
|
5
|
+
* This source code is licensed under the MIT license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree.
|
|
7
|
+
*
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.getTonShortfall = exports.DEFAULT_SAFETY_MARGIN_NANOS = exports.DEFAULT_GAS_BUFFER_NANOS = void 0;
|
|
11
|
+
const walletkit_1 = require("@ton/walletkit");
|
|
12
|
+
/** Default extra TON buffer added on top of built transaction outflow when checking balance before sending. */
|
|
13
|
+
exports.DEFAULT_GAS_BUFFER_NANOS = 100000000n;
|
|
14
|
+
/**
|
|
15
|
+
* Default extra headroom baked into the suggested reduced amount, on top of the gas buffer.
|
|
16
|
+
* Covers quote/gas drift between the current built tx and the one that will actually be sent
|
|
17
|
+
* after the amount changes. 0.02 TON.
|
|
18
|
+
*/
|
|
19
|
+
exports.DEFAULT_SAFETY_MARGIN_NANOS = 20000000n;
|
|
20
|
+
/**
|
|
21
|
+
* Check whether the user's TON balance covers the built transaction.
|
|
22
|
+
* - Returns `null` if the balance is sufficient.
|
|
23
|
+
* - Returns `{ mode: 'reduce', ... }` with a smaller suggested `fromAmount` when `fromToken` is TON
|
|
24
|
+
* and the balance is enough to cover at least gas (user can fix it by reducing the amount).
|
|
25
|
+
* - Returns `{ mode: 'topup', ... }` when `fromToken` is a jetton (reducing jetton amount won't free up TON gas),
|
|
26
|
+
* or when `fromToken` is TON but the balance can't even cover gas (reducing won't help — user must top up).
|
|
27
|
+
*/
|
|
28
|
+
const getTonShortfall = ({ messages, tonBalance, fromToken, fromAmount, gasBufferNanos = exports.DEFAULT_GAS_BUFFER_NANOS, safetyMarginNanos = exports.DEFAULT_SAFETY_MARGIN_NANOS, }) => {
|
|
29
|
+
const totalOutNanos = messages.reduce((acc, m) => acc + BigInt(m.amount), 0n);
|
|
30
|
+
const requiredNanos = totalOutNanos + gasBufferNanos;
|
|
31
|
+
const tonBalanceNanos = tonBalance ? (0, walletkit_1.parseUnits)(tonBalance, 9) : 0n;
|
|
32
|
+
if (tonBalanceNanos >= requiredNanos)
|
|
33
|
+
return;
|
|
34
|
+
if (fromToken.address === 'ton') {
|
|
35
|
+
const gasOnlyNanos = totalOutNanos - (0, walletkit_1.parseUnits)(fromAmount, 9);
|
|
36
|
+
const nonSwapReservedNanos = gasOnlyNanos + gasBufferNanos + safetyMarginNanos;
|
|
37
|
+
// Balance can't cover even gas for a minimal outgoing tx — reducing the amount won't help.
|
|
38
|
+
if (tonBalanceNanos <= nonSwapReservedNanos) {
|
|
39
|
+
return { mode: 'topup', requiredNanos, suggestedFromAmount: '' };
|
|
40
|
+
}
|
|
41
|
+
const suggestedFromAmount = (0, walletkit_1.formatUnits)(tonBalanceNanos - nonSwapReservedNanos, 9);
|
|
42
|
+
return { mode: 'reduce', requiredNanos, suggestedFromAmount };
|
|
43
|
+
}
|
|
44
|
+
return { mode: 'topup', requiredNanos, suggestedFromAmount: '' };
|
|
45
|
+
};
|
|
46
|
+
exports.getTonShortfall = getTonShortfall;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-ton-shortfall.test.d.ts","sourceRoot":"","sources":["../../../../src/utils/balance/get-ton-shortfall.test.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|