@pizzaton/ton 0.0.0-stage → 0.1.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/CONTRACTS.md +239 -0
- package/README.md +481 -2
- package/dist/airdrop/index.d.mts +18 -0
- package/dist/airdrop/index.mjs +86 -0
- package/dist/connect/errors.d.mts +4 -0
- package/dist/connect/errors.mjs +21 -0
- package/dist/connect/index.d.mts +23 -0
- package/dist/connect/index.mjs +34 -0
- package/dist/contracts/catalog/index.d.mts +361 -0
- package/dist/contracts/catalog/index.mjs +403 -0
- package/dist/contracts/client.d.mts +18 -0
- package/dist/contracts/client.mjs +31 -0
- package/dist/contracts/codecs.d.mts +14 -0
- package/dist/contracts/codecs.mjs +61 -0
- package/dist/contracts/hipo.d.mts +138 -0
- package/dist/contracts/hipo.mjs +198 -0
- package/dist/contracts/index.d.mts +23 -0
- package/dist/contracts/index.mjs +20 -0
- package/dist/contracts/metadata.d.mts +38 -0
- package/dist/contracts/metadata.mjs +50 -0
- package/dist/contracts/module-client.d.mts +20 -0
- package/dist/contracts/module-client.mjs +34 -0
- package/dist/contracts/module.d.mts +8 -0
- package/dist/contracts/module.mjs +11 -0
- package/dist/contracts/wrappers/base.d.mts +18 -0
- package/dist/contracts/wrappers/base.mjs +31 -0
- package/dist/contracts/wrappers/index.d.mts +12 -0
- package/dist/contracts/wrappers/index.mjs +12 -0
- package/dist/contracts/wrappers/jvault-protocols.d.mts +206 -0
- package/dist/contracts/wrappers/jvault-protocols.mjs +432 -0
- package/dist/contracts/wrappers/jvault-support.d.mts +135 -0
- package/dist/contracts/wrappers/jvault-support.mjs +269 -0
- package/dist/contracts/wrappers/jvault.d.mts +123 -0
- package/dist/contracts/wrappers/jvault.mjs +258 -0
- package/dist/contracts/wrappers/memeland.d.mts +253 -0
- package/dist/contracts/wrappers/memeland.mjs +396 -0
- package/dist/contracts/wrappers/multix.d.mts +92 -0
- package/dist/contracts/wrappers/multix.mjs +156 -0
- package/dist/contracts/wrappers/pizzabox.d.mts +66 -0
- package/dist/contracts/wrappers/pizzabox.mjs +105 -0
- package/dist/contracts/wrappers/ton-raffles.d.mts +215 -0
- package/dist/contracts/wrappers/ton-raffles.mjs +398 -0
- package/dist/contracts/wrappers/tonresistor.d.mts +189 -0
- package/dist/contracts/wrappers/tonresistor.mjs +276 -0
- package/dist/core/address.d.mts +25 -0
- package/dist/core/address.mjs +45 -0
- package/dist/core/amount.d.mts +8 -0
- package/dist/core/amount.mjs +34 -0
- package/dist/core/bytes.d.mts +5 -0
- package/dist/core/bytes.mjs +18 -0
- package/dist/core/constants.d.mts +14 -0
- package/dist/core/constants.mjs +15 -0
- package/dist/core/errors.d.mts +9 -0
- package/dist/core/errors.mjs +16 -0
- package/dist/core/http.mjs +39 -0
- package/dist/core/index.d.mts +8 -0
- package/dist/core/index.mjs +8 -0
- package/dist/core/metadata.d.mts +12 -0
- package/dist/core/metadata.mjs +35 -0
- package/dist/core/network.d.mts +24 -0
- package/dist/core/network.mjs +41 -0
- package/dist/emulator/index.d.mts +20 -0
- package/dist/emulator/index.mjs +24 -0
- package/dist/index.d.mts +21 -0
- package/dist/index.mjs +19 -0
- package/dist/indexer/index.d.mts +90 -0
- package/dist/indexer/index.mjs +279 -0
- package/dist/jetton/details.d.mts +27 -0
- package/dist/jetton/details.mjs +116 -0
- package/dist/jetton/index.d.mts +54 -0
- package/dist/jetton/index.mjs +92 -0
- package/dist/jetton/versions.d.mts +12 -0
- package/dist/jetton/versions.mjs +50 -0
- package/dist/nft/collection.d.mts +57 -0
- package/dist/nft/collection.mjs +148 -0
- package/dist/nft/content.d.mts +34 -0
- package/dist/nft/content.mjs +142 -0
- package/dist/nft/index.d.mts +35 -0
- package/dist/nft/index.mjs +51 -0
- package/dist/nft/versions.d.mts +11 -0
- package/dist/nft/versions.mjs +29 -0
- package/dist/provider/index.d.mts +32 -0
- package/dist/provider/index.mjs +1 -0
- package/dist/react/index.d.mts +13 -0
- package/dist/react/index.mjs +48 -0
- package/dist/server/index.d.mts +11 -0
- package/dist/server/index.mjs +55 -0
- package/dist/simulation/index.d.mts +112 -0
- package/dist/simulation/index.mjs +310 -0
- package/dist/transactions/index.d.mts +33 -0
- package/dist/transactions/index.mjs +51 -0
- package/dist/vesting/index.d.mts +12 -0
- package/dist/vesting/index.mjs +25 -0
- package/dist/wallet/index.d.mts +23 -0
- package/dist/wallet/index.mjs +71 -0
- package/package.json +169 -5
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Address, Cell, Contract, ContractProvider, Message, Sender, StateInit } from "@ton/core";
|
|
2
|
+
import { Blockchain, BlockchainConfig, BlockchainTransaction, SandboxContract, SendMessageResult, TreasuryContract } from "@ton/sandbox";
|
|
3
|
+
//#region src/emulator/index.d.ts
|
|
4
|
+
export interface TonEmulator {
|
|
5
|
+
readonly blockchain: Blockchain;
|
|
6
|
+
readonly now: number | undefined;
|
|
7
|
+
setTime(timestamp: number): void;
|
|
8
|
+
openContract<T extends Contract>(contract: T): SandboxContract<T>;
|
|
9
|
+
provider(address: Address, init?: StateInit | null): ContractProvider;
|
|
10
|
+
sender(address: Address): Sender;
|
|
11
|
+
treasury(seed: string): Promise<SandboxContract<TreasuryContract>>;
|
|
12
|
+
sendMessage(message: Message | Cell): Promise<SendMessageResult>;
|
|
13
|
+
sendMessageIter(message: Message | Cell): Promise<AsyncIterator<BlockchainTransaction> & AsyncIterable<BlockchainTransaction>>;
|
|
14
|
+
snapshot(): ReturnType<Blockchain["snapshot"]>;
|
|
15
|
+
loadFrom(snapshot: ReturnType<Blockchain["snapshot"]>): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export declare function createTonEmulator(options?: {
|
|
18
|
+
readonly config?: BlockchainConfig;
|
|
19
|
+
}): Promise<TonEmulator>;
|
|
20
|
+
//#endregion
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Blockchain } from "@ton/sandbox";
|
|
2
|
+
//#region src/emulator/index.ts
|
|
3
|
+
async function createTonEmulator(options) {
|
|
4
|
+
const blockchain = await Blockchain.create(options);
|
|
5
|
+
return {
|
|
6
|
+
blockchain,
|
|
7
|
+
get now() {
|
|
8
|
+
return blockchain.now;
|
|
9
|
+
},
|
|
10
|
+
setTime(timestamp) {
|
|
11
|
+
blockchain.now = timestamp;
|
|
12
|
+
},
|
|
13
|
+
openContract: (contract) => blockchain.openContract(contract),
|
|
14
|
+
provider: (address, init) => blockchain.provider(address, init),
|
|
15
|
+
sender: (address) => blockchain.sender(address),
|
|
16
|
+
treasury: (seed) => blockchain.treasury(seed),
|
|
17
|
+
sendMessage: (message) => blockchain.sendMessage(message),
|
|
18
|
+
sendMessageIter: (message) => blockchain.sendMessageIter(message),
|
|
19
|
+
snapshot: () => blockchain.snapshot(),
|
|
20
|
+
loadFrom: (snapshot) => blockchain.loadFrom(snapshot)
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { createTonEmulator };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { TON_NETWORKS, TonNetwork, TonNetworkConfig, createNetworkConfig, explorerAddressUrl } from "./core/network.mjs";
|
|
2
|
+
import { TonAddress, addressesEqual, assertWorkchain, parseTonAddress, shortenTonAddress, toFriendlyAddress, toTonAddress } from "./core/address.mjs";
|
|
3
|
+
import { TonConnectMessage, TonConnectTransaction, TonTransactionMessage, TransactionIntent, createTransactionIntent, toTonConnectTransaction, validateTransactionIntent } from "./transactions/index.mjs";
|
|
4
|
+
import { readableTonConnectError } from "./connect/errors.mjs";
|
|
5
|
+
import { TON_CONNECT_CHAIN_IDS, TonConnectAdapter, TonConnectClient, TonConnectWallet, createTonConnectAdapter, toWalletTransaction } from "./connect/index.mjs";
|
|
6
|
+
import { ContractAuditReference, ContractDescriptor, ContractFamily, ContractProductionApproval, ContractReadiness, ContractSourceReference, UpgradePolicy, assertProductionApproved, createContractDescriptor } from "./contracts/metadata.mjs";
|
|
7
|
+
import { CONTRACT_CATALOG, ContractCatalogId, getContractDescriptor } from "./contracts/catalog/index.mjs";
|
|
8
|
+
import { ContractSendOptions, TonContractClient } from "./contracts/client.mjs";
|
|
9
|
+
import { addressFlagDictionary, crc32, uint256CoinsDictionary, uint32FlagDictionary } from "./contracts/codecs.mjs";
|
|
10
|
+
import { ContractModule, createContractModule } from "./contracts/module.mjs";
|
|
11
|
+
import { ContractModuleClient, ContractModuleClientOptions } from "./contracts/module-client.mjs";
|
|
12
|
+
import { ContractModuleRegistry, TonContractModule, createContractModuleRegistry } from "./contracts/index.mjs";
|
|
13
|
+
import { TokenMetadata, parseTokenMetadata, parseTokenMetadataJson } from "./core/metadata.mjs";
|
|
14
|
+
import { TonAccountState, TonGetMethodResult, TonProvider, TonTransactionSummary } from "./provider/index.mjs";
|
|
15
|
+
import { MAX_TON_COINS, assertTonAmount, formatTon, formatUnits, parseTon, parseUnits } from "./core/amount.mjs";
|
|
16
|
+
import { bytesToBase64, bytesToHex, hexToBytes } from "./core/bytes.mjs";
|
|
17
|
+
import { PIZZATON_MAINNET_ADDRESSES, PTJ_TOKEN_INFO } from "./core/constants.mjs";
|
|
18
|
+
import { TonErrorCode, TonPackageError, invariant } from "./core/errors.mjs";
|
|
19
|
+
import "./core/index.mjs";
|
|
20
|
+
import { VestingSchedule, claimableAmount, unlockedAmount, validateVestingSchedule } from "./vesting/index.mjs";
|
|
21
|
+
export { CONTRACT_CATALOG, ContractAuditReference, ContractCatalogId, ContractDescriptor, ContractFamily, ContractModule, ContractModuleClient, ContractModuleClientOptions, ContractModuleRegistry, ContractProductionApproval, ContractReadiness, ContractSendOptions, ContractSourceReference, MAX_TON_COINS, PIZZATON_MAINNET_ADDRESSES, PTJ_TOKEN_INFO, TON_CONNECT_CHAIN_IDS, TON_NETWORKS, TokenMetadata, TonAccountState, TonAddress, TonConnectAdapter, TonConnectClient, TonConnectMessage, TonConnectTransaction, TonConnectWallet, TonContractClient, TonContractModule, TonErrorCode, TonGetMethodResult, TonNetwork, TonNetworkConfig, TonPackageError, TonProvider, TonTransactionMessage, TonTransactionSummary, TransactionIntent, UpgradePolicy, VestingSchedule, addressFlagDictionary, addressesEqual, assertProductionApproved, assertTonAmount, assertWorkchain, bytesToBase64, bytesToHex, claimableAmount, crc32, createContractDescriptor, createContractModule, createContractModuleRegistry, createNetworkConfig, createTonConnectAdapter, createTransactionIntent, explorerAddressUrl, formatTon, formatUnits, getContractDescriptor, hexToBytes, invariant, parseTokenMetadata, parseTokenMetadataJson, parseTon, parseTonAddress, parseUnits, readableTonConnectError, shortenTonAddress, toFriendlyAddress, toTonAddress, toTonConnectTransaction, toWalletTransaction, uint256CoinsDictionary, uint32FlagDictionary, unlockedAmount, validateTransactionIntent, validateVestingSchedule };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { TonPackageError, invariant } from "./core/errors.mjs";
|
|
2
|
+
import { addressesEqual, assertWorkchain, parseTonAddress, shortenTonAddress, toFriendlyAddress, toTonAddress } from "./core/address.mjs";
|
|
3
|
+
import { MAX_TON_COINS, assertTonAmount, formatTon, formatUnits, parseTon, parseUnits } from "./core/amount.mjs";
|
|
4
|
+
import { bytesToBase64, bytesToHex, hexToBytes } from "./core/bytes.mjs";
|
|
5
|
+
import { createTransactionIntent, toTonConnectTransaction, validateTransactionIntent } from "./transactions/index.mjs";
|
|
6
|
+
import { readableTonConnectError } from "./connect/errors.mjs";
|
|
7
|
+
import { TON_CONNECT_CHAIN_IDS, createTonConnectAdapter, toWalletTransaction } from "./connect/index.mjs";
|
|
8
|
+
import { assertProductionApproved, createContractDescriptor } from "./contracts/metadata.mjs";
|
|
9
|
+
import { CONTRACT_CATALOG, getContractDescriptor } from "./contracts/catalog/index.mjs";
|
|
10
|
+
import { TonContractClient } from "./contracts/client.mjs";
|
|
11
|
+
import { addressFlagDictionary, crc32, uint256CoinsDictionary, uint32FlagDictionary } from "./contracts/codecs.mjs";
|
|
12
|
+
import { createContractModule } from "./contracts/module.mjs";
|
|
13
|
+
import { ContractModuleClient } from "./contracts/module-client.mjs";
|
|
14
|
+
import { createContractModuleRegistry } from "./contracts/index.mjs";
|
|
15
|
+
import { PIZZATON_MAINNET_ADDRESSES, PTJ_TOKEN_INFO } from "./core/constants.mjs";
|
|
16
|
+
import { parseTokenMetadata, parseTokenMetadataJson } from "./core/metadata.mjs";
|
|
17
|
+
import { TON_NETWORKS, createNetworkConfig, explorerAddressUrl } from "./core/network.mjs";
|
|
18
|
+
import { claimableAmount, unlockedAmount, validateVestingSchedule } from "./vesting/index.mjs";
|
|
19
|
+
export { CONTRACT_CATALOG, ContractModuleClient, MAX_TON_COINS, PIZZATON_MAINNET_ADDRESSES, PTJ_TOKEN_INFO, TON_CONNECT_CHAIN_IDS, TON_NETWORKS, TonContractClient, TonPackageError, addressFlagDictionary, addressesEqual, assertProductionApproved, assertTonAmount, assertWorkchain, bytesToBase64, bytesToHex, claimableAmount, crc32, createContractDescriptor, createContractModule, createContractModuleRegistry, createNetworkConfig, createTonConnectAdapter, createTransactionIntent, explorerAddressUrl, formatTon, formatUnits, getContractDescriptor, hexToBytes, invariant, parseTokenMetadata, parseTokenMetadataJson, parseTon, parseTonAddress, parseUnits, readableTonConnectError, shortenTonAddress, toFriendlyAddress, toTonAddress, toTonConnectTransaction, toWalletTransaction, uint256CoinsDictionary, uint32FlagDictionary, unlockedAmount, validateTransactionIntent, validateVestingSchedule };
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { TonNetwork } from "../core/network.mjs";
|
|
2
|
+
import { TokenMetadata } from "../core/metadata.mjs";
|
|
3
|
+
import { Address, Cell } from "@ton/core";
|
|
4
|
+
//#region src/indexer/index.d.ts
|
|
5
|
+
export interface IndexedJettonBalance {
|
|
6
|
+
readonly walletAddress: Address;
|
|
7
|
+
readonly masterAddress: Address;
|
|
8
|
+
readonly balance: bigint;
|
|
9
|
+
readonly metadata?: TokenMetadata | undefined;
|
|
10
|
+
}
|
|
11
|
+
export interface IndexedNftItem {
|
|
12
|
+
readonly address: Address;
|
|
13
|
+
readonly index?: bigint | undefined;
|
|
14
|
+
readonly collection?: Address | undefined;
|
|
15
|
+
readonly owner?: Address | null | undefined;
|
|
16
|
+
readonly metadata?: Readonly<Record<string, unknown>> | undefined;
|
|
17
|
+
}
|
|
18
|
+
export interface IndexedNftCollection {
|
|
19
|
+
readonly address: Address;
|
|
20
|
+
readonly nextItemIndex?: bigint | undefined;
|
|
21
|
+
readonly name?: string | undefined;
|
|
22
|
+
readonly description?: string | undefined;
|
|
23
|
+
readonly image?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
export interface IndexedMessage {
|
|
26
|
+
readonly source?: Address;
|
|
27
|
+
readonly destination?: Address;
|
|
28
|
+
readonly createdLt: bigint;
|
|
29
|
+
readonly createdAt: number;
|
|
30
|
+
readonly hash: string;
|
|
31
|
+
readonly rawBody?: Cell;
|
|
32
|
+
}
|
|
33
|
+
export interface IndexedTransaction {
|
|
34
|
+
readonly hash: string;
|
|
35
|
+
readonly lt: bigint;
|
|
36
|
+
readonly account: Address;
|
|
37
|
+
readonly success: boolean;
|
|
38
|
+
readonly utime: number;
|
|
39
|
+
readonly inMsg?: IndexedMessage;
|
|
40
|
+
readonly outMsgs: readonly IndexedMessage[];
|
|
41
|
+
}
|
|
42
|
+
export interface IndexedTrace {
|
|
43
|
+
readonly transaction: IndexedTransaction;
|
|
44
|
+
readonly children?: readonly IndexedTrace[];
|
|
45
|
+
}
|
|
46
|
+
export interface TonIndexer {
|
|
47
|
+
getJettonBalances(owner: Address): Promise<readonly IndexedJettonBalance[]>;
|
|
48
|
+
getJettonMetadata(master: Address): Promise<TokenMetadata | undefined>;
|
|
49
|
+
getNftCollection(collection: Address): Promise<IndexedNftCollection>;
|
|
50
|
+
getNftItems(options: {
|
|
51
|
+
readonly collection: Address;
|
|
52
|
+
readonly limit: number;
|
|
53
|
+
readonly offset: number;
|
|
54
|
+
readonly owner?: Address;
|
|
55
|
+
}): Promise<readonly IndexedNftItem[]>;
|
|
56
|
+
/** Optional server-only capabilities. TonCenter does not implement these. */
|
|
57
|
+
getAccountTraces?(address: Address, options?: {
|
|
58
|
+
readonly beforeLt?: bigint;
|
|
59
|
+
readonly limit?: number;
|
|
60
|
+
}): Promise<readonly {
|
|
61
|
+
readonly id: string;
|
|
62
|
+
readonly utime: number;
|
|
63
|
+
}[]>;
|
|
64
|
+
getTrace?(traceId: string): Promise<IndexedTrace>;
|
|
65
|
+
getTransactionByMessageHash?(messageHash: string): Promise<{
|
|
66
|
+
readonly hash: string;
|
|
67
|
+
} | undefined>;
|
|
68
|
+
sendBoc?(boc: Cell): Promise<{
|
|
69
|
+
readonly hash?: string;
|
|
70
|
+
}>;
|
|
71
|
+
}
|
|
72
|
+
export interface TonCenterIndexerOptions {
|
|
73
|
+
readonly network: TonNetwork;
|
|
74
|
+
readonly baseUrl?: string;
|
|
75
|
+
readonly apiKey?: string;
|
|
76
|
+
readonly timeoutMs?: number;
|
|
77
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
78
|
+
}
|
|
79
|
+
export interface TonApiIndexerOptions {
|
|
80
|
+
readonly network: TonNetwork;
|
|
81
|
+
readonly baseUrl?: string;
|
|
82
|
+
readonly apiKey?: string;
|
|
83
|
+
readonly timeoutMs?: number;
|
|
84
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
85
|
+
}
|
|
86
|
+
export declare function createTonCenterIndexer(options: TonCenterIndexerOptions): TonIndexer;
|
|
87
|
+
export declare function createTonApiIndexer(options: TonApiIndexerOptions): TonIndexer;
|
|
88
|
+
export declare function createFallbackTonIndexer(primary: TonIndexer, fallback: TonIndexer): TonIndexer;
|
|
89
|
+
export declare function formatIndexedJettonBalance(balance: IndexedJettonBalance): string;
|
|
90
|
+
//#endregion
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
import { TonPackageError, invariant } from "../core/errors.mjs";
|
|
2
|
+
import { parseTonAddress } from "../core/address.mjs";
|
|
3
|
+
import { formatUnits } from "../core/amount.mjs";
|
|
4
|
+
import { parseTokenMetadata } from "../core/metadata.mjs";
|
|
5
|
+
import { createTimedFetch, normalizeHttpsBaseUrl, validateRequestTimeout } from "../core/http.mjs";
|
|
6
|
+
import { Address } from "@ton/core";
|
|
7
|
+
import { TonApiClient } from "@ton-api/client";
|
|
8
|
+
//#region src/indexer/index.ts
|
|
9
|
+
function createTonCenterIndexer(options) {
|
|
10
|
+
assertNetwork(options.network);
|
|
11
|
+
const baseUrl = normalizeHttpsBaseUrl(options.baseUrl ?? (options.network === "testnet" ? "https://testnet.toncenter.com/api/v3" : "https://toncenter.com/api/v3"), "TonCenter");
|
|
12
|
+
const timeoutMs = validateRequestTimeout(options.timeoutMs, "TonCenter");
|
|
13
|
+
const request = createTimedFetch(options.fetch ?? globalThis.fetch, timeoutMs, "TonCenter");
|
|
14
|
+
async function get(path, params) {
|
|
15
|
+
const url = new URL(`${baseUrl}${path}`);
|
|
16
|
+
for (const [key, value] of Object.entries(params)) url.searchParams.set(key, value);
|
|
17
|
+
const response = await request(url, { headers: {
|
|
18
|
+
Accept: "application/json",
|
|
19
|
+
...options.apiKey ? { "X-API-Key": options.apiKey } : {}
|
|
20
|
+
} });
|
|
21
|
+
if (!response.ok) throw new TonPackageError("PROVIDER_ERROR", `TonCenter request failed with status ${response.status}`, {
|
|
22
|
+
provider: "TonCenter",
|
|
23
|
+
status: response.status,
|
|
24
|
+
path
|
|
25
|
+
});
|
|
26
|
+
try {
|
|
27
|
+
return await response.json();
|
|
28
|
+
} catch (cause) {
|
|
29
|
+
throw new TonPackageError("PROVIDER_ERROR", "TonCenter returned invalid JSON", {
|
|
30
|
+
provider: "TonCenter",
|
|
31
|
+
path,
|
|
32
|
+
causeName: cause instanceof Error ? cause.name : typeof cause
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
async getJettonBalances(owner) {
|
|
38
|
+
return ((await get("/jetton/wallets", {
|
|
39
|
+
owner_address: owner.toString({
|
|
40
|
+
urlSafe: true,
|
|
41
|
+
bounceable: false
|
|
42
|
+
}),
|
|
43
|
+
exclude_zero_balance: "true",
|
|
44
|
+
limit: "1000",
|
|
45
|
+
offset: "0"
|
|
46
|
+
})).jetton_wallets ?? []).flatMap((wallet) => {
|
|
47
|
+
const master = typeof wallet.jetton === "string" ? wallet.jetton : void 0;
|
|
48
|
+
const address = typeof wallet.address === "string" ? wallet.address : void 0;
|
|
49
|
+
const balance = typeof wallet.balance === "string" ? wallet.balance : void 0;
|
|
50
|
+
if (!master || !address || !balance) return [];
|
|
51
|
+
return [{
|
|
52
|
+
walletAddress: parseTonAddress(address),
|
|
53
|
+
masterAddress: parseTonAddress(master),
|
|
54
|
+
balance: BigInt(balance),
|
|
55
|
+
metadata: normalizeMetadata(wallet.metadata)
|
|
56
|
+
}];
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
async getJettonMetadata(master) {
|
|
60
|
+
const item = (await get("/jetton/masters", { address: master.toString({ urlSafe: true }) })).jetton_masters?.[0];
|
|
61
|
+
return item ? normalizeMetadata(item.metadata) : void 0;
|
|
62
|
+
},
|
|
63
|
+
async getNftCollection(collection) {
|
|
64
|
+
const item = (await get("/nft/collections", { address: collection.toString({ urlSafe: true }) })).nft_collections?.[0] ?? {};
|
|
65
|
+
return {
|
|
66
|
+
address: collection,
|
|
67
|
+
nextItemIndex: toBigInt(item.next_item_index),
|
|
68
|
+
name: toStringValue(item.name),
|
|
69
|
+
description: toStringValue(item.description),
|
|
70
|
+
image: toStringValue(item.image)
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
async getNftItems({ collection, limit, offset, owner }) {
|
|
74
|
+
validatePagination(limit, offset);
|
|
75
|
+
const result = await get("/nft/items", {
|
|
76
|
+
collection_address: collection.toString({ urlSafe: true }),
|
|
77
|
+
limit: String(limit),
|
|
78
|
+
offset: String(offset),
|
|
79
|
+
...owner ? { owner_address: owner.toString({ urlSafe: true }) } : {}
|
|
80
|
+
});
|
|
81
|
+
return (result.nft_items ?? []).flatMap((item) => {
|
|
82
|
+
const address = typeof item.address === "string" ? item.address : "";
|
|
83
|
+
const indexedMetadata = address ? result.metadata?.[address] : void 0;
|
|
84
|
+
const tokenInfo = indexedMetadata?.token_info;
|
|
85
|
+
const metadata = Array.isArray(tokenInfo) && tokenInfo[0] && typeof tokenInfo[0] === "object" ? tokenInfo[0] : indexedMetadata;
|
|
86
|
+
return normalizeNftItem({
|
|
87
|
+
...item,
|
|
88
|
+
...metadata ? { metadata } : {}
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
function createTonApiIndexer(options) {
|
|
95
|
+
assertNetwork(options.network);
|
|
96
|
+
const baseUrl = normalizeHttpsBaseUrl(options.baseUrl ?? (options.network === "testnet" ? "https://testnet.tonapi.io" : "https://tonapi.io"), "TonAPI");
|
|
97
|
+
const timeoutMs = validateRequestTimeout(options.timeoutMs, "TonAPI");
|
|
98
|
+
const client = new TonApiClient({
|
|
99
|
+
baseUrl,
|
|
100
|
+
fetch: createTimedFetch(options.fetch ?? globalThis.fetch, timeoutMs, "TonAPI"),
|
|
101
|
+
...options.apiKey ? { apiKey: options.apiKey } : {}
|
|
102
|
+
});
|
|
103
|
+
return {
|
|
104
|
+
async getJettonBalances(owner) {
|
|
105
|
+
return ((await client.accounts.getAccountJettonsBalances(owner)).balances ?? []).flatMap((balance) => {
|
|
106
|
+
if (!balance.walletAddress || !balance.jetton?.address) return [];
|
|
107
|
+
return [{
|
|
108
|
+
walletAddress: parseTonAddress(balance.walletAddress),
|
|
109
|
+
masterAddress: parseTonAddress(balance.jetton.address),
|
|
110
|
+
balance: BigInt(balance.balance),
|
|
111
|
+
metadata: normalizeMetadata(balance.jetton)
|
|
112
|
+
}];
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
async getJettonMetadata(master) {
|
|
116
|
+
return normalizeMetadata((await client.jettons.getJettonInfo(master)).metadata);
|
|
117
|
+
},
|
|
118
|
+
async getNftCollection(collection) {
|
|
119
|
+
const result = await client.nft.getNftCollection(collection);
|
|
120
|
+
return {
|
|
121
|
+
address: collection,
|
|
122
|
+
nextItemIndex: toBigInt(result.nextItemIndex),
|
|
123
|
+
name: toStringValue(result.name),
|
|
124
|
+
description: toStringValue(result.description),
|
|
125
|
+
image: toStringValue(result.image)
|
|
126
|
+
};
|
|
127
|
+
},
|
|
128
|
+
async getNftItems({ collection, limit, offset, owner }) {
|
|
129
|
+
validatePagination(limit, offset);
|
|
130
|
+
const result = owner ? await client.accounts.getAccountNftItems(owner, {
|
|
131
|
+
collection,
|
|
132
|
+
limit,
|
|
133
|
+
offset
|
|
134
|
+
}) : await client.nft.getItemsFromCollection(collection, {
|
|
135
|
+
limit,
|
|
136
|
+
offset
|
|
137
|
+
});
|
|
138
|
+
return (result.nftItems ?? result.nft_items ?? []).flatMap(normalizeNftItem);
|
|
139
|
+
},
|
|
140
|
+
async getAccountTraces(address, options) {
|
|
141
|
+
const limit = options?.limit ?? 100;
|
|
142
|
+
invariant(Number.isSafeInteger(limit) && limit >= 1 && limit <= 1e3, "INVALID_TRANSACTION", "Trace limit must be an integer from 1 to 1000");
|
|
143
|
+
invariant(options?.beforeLt === void 0 || options.beforeLt >= 0n, "INVALID_TRANSACTION", "Trace logical time cannot be negative");
|
|
144
|
+
return (await client.accounts.getAccountTraces(address, {
|
|
145
|
+
...options?.beforeLt === void 0 ? {} : { before_lt: options.beforeLt },
|
|
146
|
+
limit
|
|
147
|
+
})).traces ?? [];
|
|
148
|
+
},
|
|
149
|
+
async getTrace(traceId) {
|
|
150
|
+
return normalizeTrace(await client.traces.getTrace(traceId));
|
|
151
|
+
},
|
|
152
|
+
async getTransactionByMessageHash(messageHash) {
|
|
153
|
+
const transaction = await client.blockchain.getBlockchainTransactionByMessageHash(messageHash);
|
|
154
|
+
return transaction?.hash ? { hash: transaction.hash } : void 0;
|
|
155
|
+
},
|
|
156
|
+
async sendBoc(boc) {
|
|
157
|
+
const result = await client.blockchain.sendBlockchainMessage({ boc });
|
|
158
|
+
const record = result && typeof result === "object" ? result : {};
|
|
159
|
+
return typeof record.hash === "string" ? { hash: record.hash } : {};
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
function createFallbackTonIndexer(primary, fallback) {
|
|
164
|
+
const primaryGetAccountTraces = primary.getAccountTraces;
|
|
165
|
+
const primaryGetTrace = primary.getTrace;
|
|
166
|
+
const primaryGetTransactionByMessageHash = primary.getTransactionByMessageHash;
|
|
167
|
+
const primarySendBoc = primary.sendBoc;
|
|
168
|
+
return {
|
|
169
|
+
getJettonBalances: (owner) => withFallback(() => primary.getJettonBalances(owner), () => fallback.getJettonBalances(owner)),
|
|
170
|
+
getJettonMetadata: (master) => withFallback(() => primary.getJettonMetadata(master), () => fallback.getJettonMetadata(master)),
|
|
171
|
+
getNftCollection: (collection) => withFallback(() => primary.getNftCollection(collection), () => fallback.getNftCollection(collection)),
|
|
172
|
+
getNftItems: (options) => withFallback(() => primary.getNftItems(options), () => fallback.getNftItems(options)),
|
|
173
|
+
...primaryGetAccountTraces ? { getAccountTraces: (address, options) => primaryGetAccountTraces(address, options) } : {},
|
|
174
|
+
...primaryGetTrace ? { getTrace: (traceId) => primaryGetTrace(traceId) } : {},
|
|
175
|
+
...primaryGetTransactionByMessageHash ? { getTransactionByMessageHash: (messageHash) => primaryGetTransactionByMessageHash(messageHash) } : {},
|
|
176
|
+
...primarySendBoc ? { sendBoc: (boc) => primarySendBoc(boc) } : {}
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
function normalizeTrace(value) {
|
|
180
|
+
const transaction = normalizeTransaction(value.transaction);
|
|
181
|
+
const children = Array.isArray(value.children) ? value.children.flatMap((child) => child && typeof child === "object" ? [normalizeTrace(child)] : []) : [];
|
|
182
|
+
return {
|
|
183
|
+
transaction,
|
|
184
|
+
...children.length ? { children } : {}
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
function normalizeTransaction(value) {
|
|
188
|
+
const account = asAddress(value.account);
|
|
189
|
+
if (!account || typeof value.hash !== "string") throw new Error("TonAPI returned an invalid transaction");
|
|
190
|
+
const inMsg = normalizeMessage(value.inMsg);
|
|
191
|
+
return {
|
|
192
|
+
hash: value.hash,
|
|
193
|
+
lt: toBigInt(value.lt) ?? 0n,
|
|
194
|
+
account,
|
|
195
|
+
success: value.success === true,
|
|
196
|
+
utime: typeof value.utime === "number" ? value.utime : 0,
|
|
197
|
+
...inMsg ? { inMsg } : {},
|
|
198
|
+
outMsgs: Array.isArray(value.outMsgs) ? value.outMsgs.flatMap((message) => {
|
|
199
|
+
const normalized = normalizeMessage(message);
|
|
200
|
+
return normalized ? [normalized] : [];
|
|
201
|
+
}) : []
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
function normalizeMessage(value) {
|
|
205
|
+
if (!value || typeof value !== "object") return void 0;
|
|
206
|
+
const record = value;
|
|
207
|
+
if (typeof record.hash !== "string") return void 0;
|
|
208
|
+
const source = asAddress(record.source);
|
|
209
|
+
const destination = asAddress(record.destination);
|
|
210
|
+
return {
|
|
211
|
+
...source ? { source } : {},
|
|
212
|
+
...destination ? { destination } : {},
|
|
213
|
+
createdLt: toBigInt(record.createdLt) ?? 0n,
|
|
214
|
+
createdAt: typeof record.createdAt === "number" ? record.createdAt : 0,
|
|
215
|
+
hash: record.hash,
|
|
216
|
+
...record.rawBody instanceof Object ? { rawBody: record.rawBody } : {}
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
function normalizeMetadata(value) {
|
|
220
|
+
if (!value || typeof value !== "object") return void 0;
|
|
221
|
+
const record = value;
|
|
222
|
+
const decimals = typeof record.decimals === "number" ? record.decimals : typeof record.decimals === "string" && /^\d+$/.test(record.decimals) ? Number(record.decimals) : void 0;
|
|
223
|
+
const metadata = parseTokenMetadata({
|
|
224
|
+
...typeof record.name === "string" ? { name: record.name } : {},
|
|
225
|
+
...typeof record.symbol === "string" ? { symbol: record.symbol } : {},
|
|
226
|
+
...typeof record.description === "string" ? { description: record.description } : {},
|
|
227
|
+
...typeof record.image === "string" ? { image: record.image } : {},
|
|
228
|
+
...decimals === void 0 ? {} : { decimals },
|
|
229
|
+
...typeof record.uri === "string" ? { uri: record.uri } : {}
|
|
230
|
+
});
|
|
231
|
+
return Object.keys(metadata).length > 0 ? metadata : void 0;
|
|
232
|
+
}
|
|
233
|
+
function normalizeNftItem(value) {
|
|
234
|
+
const address = asAddress(value.address);
|
|
235
|
+
if (!address) return [];
|
|
236
|
+
const collection = value.collection ?? value.collection_address;
|
|
237
|
+
const owner = value.owner ?? value.owner_address ?? value.real_owner;
|
|
238
|
+
return [{
|
|
239
|
+
address,
|
|
240
|
+
index: toBigInt(value.index),
|
|
241
|
+
collection: asAddress(collection),
|
|
242
|
+
owner: owner === null ? null : asAddress(owner) ?? null,
|
|
243
|
+
metadata: value.metadata && typeof value.metadata === "object" ? value.metadata : void 0
|
|
244
|
+
}];
|
|
245
|
+
}
|
|
246
|
+
function asAddress(value) {
|
|
247
|
+
if (typeof value === "string") return parseTonAddress(value);
|
|
248
|
+
if (value instanceof Address) return value;
|
|
249
|
+
if (value && typeof value === "object" && "address" in value) return asAddress(value.address);
|
|
250
|
+
}
|
|
251
|
+
function toBigInt(value) {
|
|
252
|
+
if (typeof value === "bigint") return value;
|
|
253
|
+
if (typeof value === "number" && Number.isSafeInteger(value)) return BigInt(value);
|
|
254
|
+
if (typeof value === "string" && /^\d+$/.test(value)) return BigInt(value);
|
|
255
|
+
}
|
|
256
|
+
function toStringValue(value) {
|
|
257
|
+
return typeof value === "string" ? value : void 0;
|
|
258
|
+
}
|
|
259
|
+
async function withFallback(primary, fallback) {
|
|
260
|
+
try {
|
|
261
|
+
const result = await primary();
|
|
262
|
+
if (Array.isArray(result) && result.length === 0) return fallback();
|
|
263
|
+
return result;
|
|
264
|
+
} catch {
|
|
265
|
+
return fallback();
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
function validatePagination(limit, offset) {
|
|
269
|
+
invariant(Number.isSafeInteger(limit) && limit >= 1 && limit <= 1e3, "INVALID_TRANSACTION", "Page limit must be an integer from 1 to 1000");
|
|
270
|
+
invariant(Number.isSafeInteger(offset) && offset >= 0, "INVALID_TRANSACTION", "Page offset must be a non-negative safe integer");
|
|
271
|
+
}
|
|
272
|
+
function assertNetwork(network) {
|
|
273
|
+
invariant(network === "mainnet" || network === "testnet", "INVALID_NETWORK", "Unsupported TON network");
|
|
274
|
+
}
|
|
275
|
+
function formatIndexedJettonBalance(balance) {
|
|
276
|
+
return formatUnits(balance.balance, balance.metadata?.decimals ?? 9);
|
|
277
|
+
}
|
|
278
|
+
//#endregion
|
|
279
|
+
export { createFallbackTonIndexer, createTonApiIndexer, createTonCenterIndexer, formatIndexedJettonBalance };
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TonNetwork } from "../core/network.mjs";
|
|
2
|
+
import { TokenMetadata } from "../core/metadata.mjs";
|
|
3
|
+
import { Address } from "@ton/core";
|
|
4
|
+
//#region src/jetton/details.d.ts
|
|
5
|
+
export interface JettonDetails {
|
|
6
|
+
readonly masterAddress: Address;
|
|
7
|
+
readonly totalSupply: bigint;
|
|
8
|
+
readonly formattedTotalSupply: string;
|
|
9
|
+
readonly mintable: boolean;
|
|
10
|
+
readonly adminAddress: Address | null;
|
|
11
|
+
readonly holdersCount?: number;
|
|
12
|
+
readonly metadata?: TokenMetadata;
|
|
13
|
+
readonly source: "tonapi" | "toncenter";
|
|
14
|
+
}
|
|
15
|
+
export interface FetchJettonDetailsOptions {
|
|
16
|
+
readonly masterAddress?: string | Address;
|
|
17
|
+
readonly network?: TonNetwork;
|
|
18
|
+
readonly tonApiBaseUrl?: string;
|
|
19
|
+
readonly tonApiKey?: string;
|
|
20
|
+
readonly rpcEndpoint?: string;
|
|
21
|
+
readonly tonCenterApiKey?: string;
|
|
22
|
+
readonly timeoutMs?: number;
|
|
23
|
+
readonly fetch?: typeof globalThis.fetch;
|
|
24
|
+
}
|
|
25
|
+
export declare function formatCompactSupply(amount: bigint, decimals?: number): string;
|
|
26
|
+
export declare function fetchJettonDetails(options?: FetchJettonDetailsOptions): Promise<JettonDetails>;
|
|
27
|
+
//#endregion
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { invariant } from "../core/errors.mjs";
|
|
2
|
+
import { parseTonAddress } from "../core/address.mjs";
|
|
3
|
+
import { formatUnits } from "../core/amount.mjs";
|
|
4
|
+
import { PTJ_TOKEN_INFO } from "../core/constants.mjs";
|
|
5
|
+
import { parseTokenMetadata } from "../core/metadata.mjs";
|
|
6
|
+
import { JettonMaster as JettonMaster$1 } from "./index.mjs";
|
|
7
|
+
import { createTimedFetch, normalizeHttpsBaseUrl, validateRequestTimeout } from "../core/http.mjs";
|
|
8
|
+
import { nftContentFromCell } from "../nft/content.mjs";
|
|
9
|
+
import { TonClient } from "@ton/ton";
|
|
10
|
+
import { TonApiClient } from "@ton-api/client";
|
|
11
|
+
//#region src/jetton/details.ts
|
|
12
|
+
function formatCompactSupply(amount, decimals = 9) {
|
|
13
|
+
invariant(typeof amount === "bigint" && amount >= 0n, "INVALID_AMOUNT", "Supply must be a non-negative bigint");
|
|
14
|
+
invariant(Number.isInteger(decimals) && decimals >= 0 && decimals <= 255, "INVALID_AMOUNT", "Invalid token decimals");
|
|
15
|
+
const scale = 10n ** BigInt(decimals);
|
|
16
|
+
const whole = amount / scale;
|
|
17
|
+
let divisor = 1n;
|
|
18
|
+
let suffix = "";
|
|
19
|
+
if (whole >= 1000000000n) {
|
|
20
|
+
divisor = 1000000000n;
|
|
21
|
+
suffix = "B";
|
|
22
|
+
} else if (whole >= 1000000n) {
|
|
23
|
+
divisor = 1000000n;
|
|
24
|
+
suffix = "M";
|
|
25
|
+
} else if (whole >= 1000n) {
|
|
26
|
+
divisor = 1000n;
|
|
27
|
+
suffix = "K";
|
|
28
|
+
}
|
|
29
|
+
const denominator = scale * divisor;
|
|
30
|
+
const hundredths = (amount * 100n + denominator / 2n) / denominator;
|
|
31
|
+
const integer = hundredths / 100n;
|
|
32
|
+
const fraction = (hundredths % 100n).toString().padStart(2, "0").replace(/0+$/, "");
|
|
33
|
+
return `${integer}${fraction ? `.${fraction}` : ""}${suffix}`;
|
|
34
|
+
}
|
|
35
|
+
async function fetchJettonDetails(options = {}) {
|
|
36
|
+
const masterAddress = parseTonAddress(options.masterAddress ?? PTJ_TOKEN_INFO.masterAddress);
|
|
37
|
+
const network = options.network ?? "mainnet";
|
|
38
|
+
invariant(network === "mainnet" || network === "testnet", "INVALID_NETWORK", "Unsupported TON network");
|
|
39
|
+
const timeoutMs = validateRequestTimeout(options.timeoutMs, "TON detail lookup");
|
|
40
|
+
const tonApiBaseUrl = normalizeHttpsBaseUrl(options.tonApiBaseUrl ?? (network === "testnet" ? "https://testnet.tonapi.io" : "https://tonapi.io"), "TonAPI");
|
|
41
|
+
const rpcEndpoint = normalizeHttpsBaseUrl(options.rpcEndpoint ?? (network === "testnet" ? "https://testnet.toncenter.com/api/v2/jsonRPC" : "https://toncenter.com/api/v2/jsonRPC"), "TonCenter");
|
|
42
|
+
try {
|
|
43
|
+
const info = await new TonApiClient({
|
|
44
|
+
baseUrl: tonApiBaseUrl,
|
|
45
|
+
fetch: createTimedFetch(options.fetch ?? globalThis.fetch, timeoutMs, "TonAPI"),
|
|
46
|
+
...options.tonApiKey ? { apiKey: options.tonApiKey } : {}
|
|
47
|
+
}).jettons.getJettonInfo(masterAddress);
|
|
48
|
+
const decimals = parseDecimals(info.metadata?.decimals) ?? PTJ_TOKEN_INFO.decimals;
|
|
49
|
+
const rawMeta = info.metadata;
|
|
50
|
+
const metadata = rawMeta ? parseTokenMetadata({
|
|
51
|
+
name: rawMeta.name,
|
|
52
|
+
symbol: rawMeta.symbol,
|
|
53
|
+
...parseDecimals(rawMeta.decimals) === void 0 ? {} : { decimals: parseDecimals(rawMeta.decimals) },
|
|
54
|
+
description: rawMeta.description,
|
|
55
|
+
image: rawMeta.image
|
|
56
|
+
}) : isPizzatonJetton(masterAddress) ? {
|
|
57
|
+
name: PTJ_TOKEN_INFO.name,
|
|
58
|
+
symbol: PTJ_TOKEN_INFO.symbol,
|
|
59
|
+
decimals: PTJ_TOKEN_INFO.decimals
|
|
60
|
+
} : void 0;
|
|
61
|
+
return {
|
|
62
|
+
masterAddress,
|
|
63
|
+
totalSupply: info.totalSupply,
|
|
64
|
+
formattedTotalSupply: formatUnits(info.totalSupply, decimals),
|
|
65
|
+
mintable: info.mintable,
|
|
66
|
+
adminAddress: info.admin?.address ? parseTonAddress(info.admin.address.toRawString()) : null,
|
|
67
|
+
holdersCount: info.holdersCount,
|
|
68
|
+
...metadata ? { metadata } : {},
|
|
69
|
+
source: "tonapi"
|
|
70
|
+
};
|
|
71
|
+
} catch {}
|
|
72
|
+
const data = await new TonClient({
|
|
73
|
+
endpoint: rpcEndpoint,
|
|
74
|
+
timeout: timeoutMs,
|
|
75
|
+
...options.tonCenterApiKey ? { apiKey: options.tonCenterApiKey } : {}
|
|
76
|
+
}).open(JettonMaster$1.create(masterAddress)).getJettonData();
|
|
77
|
+
const metadata = readOnchainMetadata(data.content) ?? (isPizzatonJetton(masterAddress) ? {
|
|
78
|
+
name: PTJ_TOKEN_INFO.name,
|
|
79
|
+
symbol: PTJ_TOKEN_INFO.symbol,
|
|
80
|
+
decimals: PTJ_TOKEN_INFO.decimals
|
|
81
|
+
} : void 0);
|
|
82
|
+
const decimals = metadata?.decimals ?? PTJ_TOKEN_INFO.decimals;
|
|
83
|
+
return {
|
|
84
|
+
masterAddress,
|
|
85
|
+
totalSupply: data.totalSupply,
|
|
86
|
+
formattedTotalSupply: formatUnits(data.totalSupply, decimals),
|
|
87
|
+
mintable: data.mintable,
|
|
88
|
+
adminAddress: data.adminAddress,
|
|
89
|
+
...metadata ? { metadata } : {},
|
|
90
|
+
source: "toncenter"
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
function parseDecimals(value) {
|
|
94
|
+
if (value === void 0 || value === null) return void 0;
|
|
95
|
+
const decimals = typeof value === "number" ? value : typeof value === "string" && /^\d+$/.test(value) ? Number(value) : NaN;
|
|
96
|
+
invariant(Number.isSafeInteger(decimals) && decimals >= 0 && decimals <= 255, "INVALID_METADATA", "Jetton metadata contains invalid decimals");
|
|
97
|
+
return decimals;
|
|
98
|
+
}
|
|
99
|
+
function isPizzatonJetton(address) {
|
|
100
|
+
return address.equals(parseTonAddress(PTJ_TOKEN_INFO.masterAddress));
|
|
101
|
+
}
|
|
102
|
+
function readOnchainMetadata(content) {
|
|
103
|
+
try {
|
|
104
|
+
const decoded = nftContentFromCell(content);
|
|
105
|
+
if (decoded.type !== "onchain") return void 0;
|
|
106
|
+
const decimals = parseDecimals(decoded.data.decimals);
|
|
107
|
+
return parseTokenMetadata({
|
|
108
|
+
...decoded.data,
|
|
109
|
+
...decimals === void 0 ? {} : { decimals }
|
|
110
|
+
});
|
|
111
|
+
} catch {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { fetchJettonDetails, formatCompactSupply };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { TokenMetadata } from "../core/metadata.mjs";
|
|
2
|
+
import { TonProvider } from "../provider/index.mjs";
|
|
3
|
+
import { JETTON_IMPLEMENTATION_PROFILES, JettonImplementationProfile, JettonImplementationVersion, getJettonImplementationProfile } from "./versions.mjs";
|
|
4
|
+
import { Address, Cell, ContractProvider, Sender, TupleBuilder } from "@ton/core";
|
|
5
|
+
import { JettonMaster, JettonMaster as JettonMaster$1, JettonMaster as JettonMasterContract, JettonWallet } from "@ton/ton";
|
|
6
|
+
//#region src/jetton/index.d.ts
|
|
7
|
+
export declare const JETTON_OPCODES: {
|
|
8
|
+
readonly transfer: 260734629;
|
|
9
|
+
readonly burn: 1499400124;
|
|
10
|
+
readonly excesses: 3576854235;
|
|
11
|
+
readonly internalTransfer: 395134233;
|
|
12
|
+
readonly transferNotification: 1935855772;
|
|
13
|
+
};
|
|
14
|
+
export interface JettonTransferInput {
|
|
15
|
+
readonly amount: bigint;
|
|
16
|
+
readonly destination: Address;
|
|
17
|
+
readonly responseDestination: Address;
|
|
18
|
+
readonly queryId?: bigint;
|
|
19
|
+
readonly forwardAmount?: bigint;
|
|
20
|
+
readonly customPayload?: Cell;
|
|
21
|
+
readonly forwardPayload?: Cell;
|
|
22
|
+
}
|
|
23
|
+
export interface JettonBurnInput {
|
|
24
|
+
readonly amount: bigint;
|
|
25
|
+
readonly responseDestination: Address;
|
|
26
|
+
readonly queryId?: bigint;
|
|
27
|
+
readonly customPayload?: Cell;
|
|
28
|
+
}
|
|
29
|
+
export type JettonMetadata = TokenMetadata;
|
|
30
|
+
export type JettonData = Awaited<ReturnType<JettonMaster$1["getJettonData"]>>;
|
|
31
|
+
export interface JettonWalletData {
|
|
32
|
+
readonly balance: bigint;
|
|
33
|
+
readonly owner: Address;
|
|
34
|
+
readonly master: Address;
|
|
35
|
+
readonly walletCode: Cell;
|
|
36
|
+
}
|
|
37
|
+
export declare class JettonWalletContract {
|
|
38
|
+
readonly address: Address;
|
|
39
|
+
private readonly official;
|
|
40
|
+
private constructor();
|
|
41
|
+
static create(address: Address): JettonWalletContract;
|
|
42
|
+
getBalance(provider: ContractProvider): Promise<bigint>;
|
|
43
|
+
getWalletData(provider: ContractProvider): Promise<JettonWalletData>;
|
|
44
|
+
sendTransfer(provider: ContractProvider, via: Sender, input: JettonTransferInput, value: bigint): Promise<void>;
|
|
45
|
+
sendBurn(provider: ContractProvider, via: Sender, input: JettonBurnInput, value: bigint): Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
export declare function buildJettonTransferBody(input: JettonTransferInput): Cell;
|
|
48
|
+
export declare function buildJettonBurnBody(input: JettonBurnInput): Cell;
|
|
49
|
+
export declare function buildJettonExcessesBody(queryId?: bigint): Cell;
|
|
50
|
+
export declare function buildJettonGetWalletAddressArgs(owner: Address): TupleBuilder;
|
|
51
|
+
export declare function resolveJettonWalletAddress(provider: TonProvider, master: Address, owner: Address): Promise<Address>;
|
|
52
|
+
export declare function parseJettonAmount(value: string, decimals: number): bigint;
|
|
53
|
+
//#endregion
|
|
54
|
+
export { JETTON_IMPLEMENTATION_PROFILES, JettonImplementationProfile, JettonImplementationVersion, type JettonMaster, type JettonMasterContract, JettonWallet, getJettonImplementationProfile };
|