@tonappchain/sdk 0.6.1-v3.0.1 → 0.6.1-v3.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapters/contractOpener.d.ts +19 -0
- package/dist/adapters/contractOpener.js +94 -0
- package/dist/errors/errors.d.ts +34 -0
- package/dist/errors/errors.js +80 -0
- package/dist/errors/index.d.ts +2 -0
- package/dist/errors/index.js +30 -0
- package/dist/errors/instances.d.ts +17 -0
- package/dist/errors/instances.js +29 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +35 -0
- package/dist/sdk/Consts.d.ts +7 -0
- package/dist/sdk/Consts.js +11 -0
- package/dist/sdk/OperationTracker.d.ts +14 -0
- package/dist/sdk/OperationTracker.js +151 -0
- package/dist/sdk/StartTracking.d.ts +8 -0
- package/dist/sdk/StartTracking.js +127 -0
- package/dist/sdk/TacSdk.d.ts +53 -0
- package/dist/sdk/TacSdk.js +713 -0
- package/dist/sdk/Utils.d.ts +18 -0
- package/dist/sdk/Utils.js +128 -0
- package/dist/sender/RawSender.d.ts +14 -0
- package/dist/sender/RawSender.js +70 -0
- package/dist/sender/SenderAbstraction.d.ts +20 -0
- package/dist/sender/SenderAbstraction.js +5 -0
- package/dist/sender/SenderFactory.d.ts +33 -0
- package/dist/sender/SenderFactory.js +55 -0
- package/dist/sender/TonConnectSender.d.ts +12 -0
- package/dist/sender/TonConnectSender.js +55 -0
- package/dist/sender/index.d.ts +2 -0
- package/dist/sender/index.js +18 -0
- package/dist/structs/InternalStruct.d.ts +82 -0
- package/dist/structs/InternalStruct.js +10 -0
- package/dist/structs/Struct.d.ts +334 -0
- package/dist/structs/Struct.js +53 -0
- package/dist/wrappers/ContentUtils.d.ts +25 -0
- package/dist/wrappers/ContentUtils.js +160 -0
- package/dist/wrappers/HighloadQueryId.d.ts +17 -0
- package/dist/wrappers/HighloadQueryId.js +72 -0
- package/dist/wrappers/HighloadWalletV3.d.ts +61 -0
- package/dist/wrappers/HighloadWalletV3.js +161 -0
- package/dist/wrappers/JettonMaster.d.ts +24 -0
- package/dist/wrappers/JettonMaster.js +53 -0
- package/dist/wrappers/JettonWallet.d.ts +47 -0
- package/dist/wrappers/JettonWallet.js +107 -0
- package/dist/wrappers/Settings.d.ts +10 -0
- package/dist/wrappers/Settings.js +38 -0
- package/package.json +2 -2
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import { SandboxContract } from '@ton/sandbox';
|
|
2
|
+
import type { Address, Cell, Contract, OpenedContract } from '@ton/ton';
|
|
3
|
+
import { AbstractProvider, Addressable, Interface, InterfaceAbi } from 'ethers';
|
|
4
|
+
export interface ContractOpener {
|
|
5
|
+
open<T extends Contract>(src: T): OpenedContract<T> | SandboxContract<T>;
|
|
6
|
+
getContractState(address: Address): Promise<{
|
|
7
|
+
balance: bigint;
|
|
8
|
+
state: 'active' | 'uninitialized' | 'frozen';
|
|
9
|
+
code: Buffer | null;
|
|
10
|
+
}>;
|
|
11
|
+
closeConnections?: () => unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare enum SimplifiedStatuses {
|
|
14
|
+
PENDING = "PENDING",
|
|
15
|
+
FAILED = "FAILED",
|
|
16
|
+
SUCCESSFUL = "SUCCESSFUL",
|
|
17
|
+
OPERATION_ID_NOT_FOUND = "OPERATION_ID_NOT_FOUND"
|
|
18
|
+
}
|
|
19
|
+
export declare enum Network {
|
|
20
|
+
TESTNET = "testnet",
|
|
21
|
+
MAINNET = "mainnet"
|
|
22
|
+
}
|
|
23
|
+
export declare enum BlockchainType {
|
|
24
|
+
TAC = "TAC",
|
|
25
|
+
TON = "TON"
|
|
26
|
+
}
|
|
27
|
+
export declare enum OperationType {
|
|
28
|
+
PENDING = "PENDING",
|
|
29
|
+
TON_TAC_TON = "TON-TAC-TON",
|
|
30
|
+
ROLLBACK = "ROLLBACK",
|
|
31
|
+
TON_TAC = "TON-TAC",
|
|
32
|
+
TAC_TON = "TAC-TON",
|
|
33
|
+
UNKNOWN = "UNKNOWN"
|
|
34
|
+
}
|
|
35
|
+
export type TACParams = {
|
|
36
|
+
/**
|
|
37
|
+
* Provider for TAC side. Use your own provider for tests or to increase ratelimit
|
|
38
|
+
*/
|
|
39
|
+
provider?: AbstractProvider;
|
|
40
|
+
/**
|
|
41
|
+
* Address of TAC settings contract. Use only for tests.
|
|
42
|
+
*/
|
|
43
|
+
settingsAddress?: string | Addressable;
|
|
44
|
+
/**
|
|
45
|
+
* ABI of TAC settings contract. Use only for tests.
|
|
46
|
+
*/
|
|
47
|
+
settingsABI?: Interface | InterfaceAbi;
|
|
48
|
+
/**
|
|
49
|
+
* ABI of TAC CCL contract. Use only for tests.
|
|
50
|
+
*/
|
|
51
|
+
crossChainLayerABI?: Interface | InterfaceAbi;
|
|
52
|
+
/**
|
|
53
|
+
* ABI of TAC CrossChainLayerToken contract. Use only for tests.
|
|
54
|
+
*/
|
|
55
|
+
crossChainLayerTokenABI?: Interface | InterfaceAbi;
|
|
56
|
+
/**
|
|
57
|
+
* bytecode of TAC CrossChainLayerToken contract. Use only for tests.
|
|
58
|
+
*/
|
|
59
|
+
crossChainLayerTokenBytecode?: string;
|
|
60
|
+
/**
|
|
61
|
+
* ABI of TAC CrossChainLayerNFT contract. Use only for tests.
|
|
62
|
+
*/
|
|
63
|
+
crossChainLayerNFTABI?: Interface | InterfaceAbi;
|
|
64
|
+
/**
|
|
65
|
+
* bytecode of TAC CrossChainLayerNFT contract. Use only for tests.
|
|
66
|
+
*/
|
|
67
|
+
crossChainLayerNFTBytecode?: string;
|
|
68
|
+
};
|
|
69
|
+
export type TONParams = {
|
|
70
|
+
/**
|
|
71
|
+
* Provider for TON side. Use your own provider for tests or to increase ratelimit
|
|
72
|
+
*/
|
|
73
|
+
contractOpener?: ContractOpener;
|
|
74
|
+
/**
|
|
75
|
+
* Address of TON settings contract. Use only for tests.
|
|
76
|
+
*/
|
|
77
|
+
settingsAddress?: string;
|
|
78
|
+
};
|
|
79
|
+
export type SDKParams = {
|
|
80
|
+
/**
|
|
81
|
+
* TON CHAIN. For your network use Сustom
|
|
82
|
+
*/
|
|
83
|
+
network: Network;
|
|
84
|
+
/**
|
|
85
|
+
* Delay in requests to provider
|
|
86
|
+
*/
|
|
87
|
+
delay?: number;
|
|
88
|
+
/**
|
|
89
|
+
* Custom parameters for the TAC blockchain
|
|
90
|
+
*/
|
|
91
|
+
TACParams?: TACParams;
|
|
92
|
+
/**
|
|
93
|
+
* Custom parameters for the TON blockchain
|
|
94
|
+
*/
|
|
95
|
+
TONParams?: TONParams;
|
|
96
|
+
/**
|
|
97
|
+
* URLs of lite sequencers
|
|
98
|
+
*/
|
|
99
|
+
customLiteSequencerEndpoints?: string[];
|
|
100
|
+
};
|
|
101
|
+
export declare enum AssetType {
|
|
102
|
+
NFT = "NFT",
|
|
103
|
+
FT = "FT"
|
|
104
|
+
}
|
|
105
|
+
export declare enum NFTAddressType {
|
|
106
|
+
ITEM = "ITEM",
|
|
107
|
+
COLLECTION = "COLLECTION"
|
|
108
|
+
}
|
|
109
|
+
export type WithAddressFT = {
|
|
110
|
+
type: AssetType.FT;
|
|
111
|
+
/**
|
|
112
|
+
* Address of TAC or TON token.
|
|
113
|
+
* Empty if sending native TON coin.
|
|
114
|
+
*/
|
|
115
|
+
address?: string;
|
|
116
|
+
};
|
|
117
|
+
export type WithAddressNFT_Item = {
|
|
118
|
+
type: AssetType.NFT;
|
|
119
|
+
/**
|
|
120
|
+
* Address NFT item token.
|
|
121
|
+
*/
|
|
122
|
+
address: string;
|
|
123
|
+
};
|
|
124
|
+
export type WithAddressNFT_CollectionItem = {
|
|
125
|
+
type: AssetType.NFT;
|
|
126
|
+
/**
|
|
127
|
+
* Address NFT collection.
|
|
128
|
+
*/
|
|
129
|
+
collectionAddress: string;
|
|
130
|
+
/**
|
|
131
|
+
* Index of NFT item in collection.
|
|
132
|
+
*/
|
|
133
|
+
itemIndex: bigint;
|
|
134
|
+
};
|
|
135
|
+
export type WithAddressNFT = WithAddressNFT_Item | WithAddressNFT_CollectionItem;
|
|
136
|
+
export type WithAddress = WithAddressFT | WithAddressNFT;
|
|
137
|
+
export type RawAssetBridgingData<NFTFormatRequired extends WithAddressNFT = WithAddressNFT_Item> = {
|
|
138
|
+
/** Raw format, e.g. 12340000000 (=12.34 tokens if decimals is 9) */
|
|
139
|
+
rawAmount: bigint;
|
|
140
|
+
} & (WithAddressFT | NFTFormatRequired);
|
|
141
|
+
export type UserFriendlyAssetBridgingData = {
|
|
142
|
+
/**
|
|
143
|
+
* User friendly format, e.g. 12.34 tokens
|
|
144
|
+
* Specified value will be converted automatically to raw format: 12.34 * (10^decimals).
|
|
145
|
+
* No decimals should be specified.
|
|
146
|
+
*/
|
|
147
|
+
amount: number;
|
|
148
|
+
/**
|
|
149
|
+
* Decimals may be specified manually.
|
|
150
|
+
* Otherwise, SDK tries to extract them from chain.
|
|
151
|
+
*/
|
|
152
|
+
decimals?: number;
|
|
153
|
+
} & WithAddress;
|
|
154
|
+
export type AssetBridgingData = RawAssetBridgingData | UserFriendlyAssetBridgingData;
|
|
155
|
+
export type UserWalletBalanceExtended = {
|
|
156
|
+
exists: true;
|
|
157
|
+
amount: number;
|
|
158
|
+
rawAmount: bigint;
|
|
159
|
+
decimals: number;
|
|
160
|
+
} | {
|
|
161
|
+
exists: false;
|
|
162
|
+
};
|
|
163
|
+
export type EvmProxyMsg = {
|
|
164
|
+
evmTargetAddress: string;
|
|
165
|
+
methodName?: string;
|
|
166
|
+
encodedParameters?: string;
|
|
167
|
+
gasLimit?: bigint;
|
|
168
|
+
};
|
|
169
|
+
export type TransactionLinker = {
|
|
170
|
+
caller: string;
|
|
171
|
+
shardCount: number;
|
|
172
|
+
shardsKey: string;
|
|
173
|
+
timestamp: number;
|
|
174
|
+
sendTransactionResult?: unknown;
|
|
175
|
+
};
|
|
176
|
+
export type TACSimulationRequest = {
|
|
177
|
+
tacCallParams: {
|
|
178
|
+
arguments: string;
|
|
179
|
+
methodName: string;
|
|
180
|
+
target: string;
|
|
181
|
+
};
|
|
182
|
+
evmValidExecutors: string[];
|
|
183
|
+
extraData: string;
|
|
184
|
+
feeAssetAddress: string;
|
|
185
|
+
shardsKey: string;
|
|
186
|
+
tonAssets: {
|
|
187
|
+
amount: string;
|
|
188
|
+
tokenAddress: string;
|
|
189
|
+
assetType: string;
|
|
190
|
+
}[];
|
|
191
|
+
tonCaller: string;
|
|
192
|
+
};
|
|
193
|
+
export declare enum StageName {
|
|
194
|
+
COLLECTED_IN_TAC = "collectedInTAC",
|
|
195
|
+
INCLUDED_IN_TAC_CONSENSUS = "includedInTACConsensus",
|
|
196
|
+
EXECUTED_IN_TAC = "executedInTAC",
|
|
197
|
+
COLLECTED_IN_TON = "collectedInTON",
|
|
198
|
+
INCLUDED_IN_TON_CONSENSUS = "includedInTONConsensus",
|
|
199
|
+
EXECUTED_IN_TON = "executedInTON"
|
|
200
|
+
}
|
|
201
|
+
export type TransactionData = {
|
|
202
|
+
hash: string;
|
|
203
|
+
blockchainType: BlockchainType;
|
|
204
|
+
};
|
|
205
|
+
export type NoteInfo = {
|
|
206
|
+
content: string;
|
|
207
|
+
errorName: string;
|
|
208
|
+
internalMsg: string;
|
|
209
|
+
internalBytesError: string;
|
|
210
|
+
};
|
|
211
|
+
export type StageData = {
|
|
212
|
+
success: boolean;
|
|
213
|
+
timestamp: number;
|
|
214
|
+
transactions: TransactionData[] | null;
|
|
215
|
+
note: NoteInfo | null;
|
|
216
|
+
};
|
|
217
|
+
export type StatusInfo = StageData & {
|
|
218
|
+
stage: StageName;
|
|
219
|
+
};
|
|
220
|
+
export type ProfilingStageData = {
|
|
221
|
+
exists: boolean;
|
|
222
|
+
stageData: StageData | null;
|
|
223
|
+
};
|
|
224
|
+
export type InitialCallerInfo = {
|
|
225
|
+
address: string;
|
|
226
|
+
blockchainType: BlockchainType;
|
|
227
|
+
};
|
|
228
|
+
export type ValidExecutors = {
|
|
229
|
+
tac: string[];
|
|
230
|
+
ton: string[];
|
|
231
|
+
};
|
|
232
|
+
export declare enum TokenSymbol {
|
|
233
|
+
TAC_SYMBOL = "TAC",
|
|
234
|
+
TON_SYMBOL = "TON"
|
|
235
|
+
}
|
|
236
|
+
export type GeneralFeeInfo = {
|
|
237
|
+
protocolFee: string;
|
|
238
|
+
executorFee: string;
|
|
239
|
+
tokenFeeSymbol: TokenSymbol;
|
|
240
|
+
};
|
|
241
|
+
export type FeeInfo = {
|
|
242
|
+
tac: GeneralFeeInfo;
|
|
243
|
+
ton: GeneralFeeInfo;
|
|
244
|
+
};
|
|
245
|
+
export type MetaInfo = {
|
|
246
|
+
initialCaller: InitialCallerInfo;
|
|
247
|
+
validExecutors: ValidExecutors;
|
|
248
|
+
feeInfo: FeeInfo;
|
|
249
|
+
};
|
|
250
|
+
export type ExecutionStages = {
|
|
251
|
+
operationType: OperationType;
|
|
252
|
+
metaInfo: MetaInfo;
|
|
253
|
+
} & Record<StageName, ProfilingStageData>;
|
|
254
|
+
export type ExecutionStagesByOperationId = Record<string, ExecutionStages>;
|
|
255
|
+
export type StatusInfosByOperationId = Record<string, StatusInfo>;
|
|
256
|
+
export type OperationIds = {
|
|
257
|
+
operationIds: string[];
|
|
258
|
+
};
|
|
259
|
+
export type OperationIdsByShardsKey = Record<string, OperationIds>;
|
|
260
|
+
export type TACSimulationResult = {
|
|
261
|
+
estimatedGas: bigint;
|
|
262
|
+
feeParams: {
|
|
263
|
+
currentBaseFee: string;
|
|
264
|
+
isEip1559: boolean;
|
|
265
|
+
suggestedGasPrice: string;
|
|
266
|
+
suggestedGasTip: string;
|
|
267
|
+
};
|
|
268
|
+
message: string;
|
|
269
|
+
outMessages: {
|
|
270
|
+
callerAddress: string;
|
|
271
|
+
operationId: string;
|
|
272
|
+
payload: string;
|
|
273
|
+
queryId: number;
|
|
274
|
+
targetAddress: string;
|
|
275
|
+
tokensBurned: {
|
|
276
|
+
amount: string;
|
|
277
|
+
tokenAddress: string;
|
|
278
|
+
}[];
|
|
279
|
+
tokensLocked: {
|
|
280
|
+
amount: string;
|
|
281
|
+
tokenAddress: string;
|
|
282
|
+
}[];
|
|
283
|
+
nftBurned: {
|
|
284
|
+
amount: string;
|
|
285
|
+
tokenAddress: string;
|
|
286
|
+
}[];
|
|
287
|
+
nftLocked: {
|
|
288
|
+
amount: string;
|
|
289
|
+
tokenAddress: string;
|
|
290
|
+
}[];
|
|
291
|
+
}[] | null;
|
|
292
|
+
simulationError: string;
|
|
293
|
+
simulationStatus: boolean;
|
|
294
|
+
suggestedTonExecutionFee: string;
|
|
295
|
+
suggestedTacExecutionFee: string;
|
|
296
|
+
debugInfo: {
|
|
297
|
+
from: string;
|
|
298
|
+
to: string;
|
|
299
|
+
callData: string;
|
|
300
|
+
blockNumber: number;
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
export type FeeParams = {
|
|
304
|
+
isRoundTrip: boolean;
|
|
305
|
+
gasLimit: bigint;
|
|
306
|
+
protocolFee: bigint;
|
|
307
|
+
evmExecutorFee: bigint;
|
|
308
|
+
tvmExecutorFee: bigint;
|
|
309
|
+
};
|
|
310
|
+
export type CrossChainTransactionOptions = {
|
|
311
|
+
forceSend?: boolean;
|
|
312
|
+
isRoundTrip?: boolean;
|
|
313
|
+
protocolFee?: bigint;
|
|
314
|
+
evmValidExecutors?: string[];
|
|
315
|
+
evmExecutorFee?: bigint;
|
|
316
|
+
tvmValidExecutors?: string[];
|
|
317
|
+
tvmExecutorFee?: bigint;
|
|
318
|
+
};
|
|
319
|
+
export type ExecutionFeeEstimationResult = {
|
|
320
|
+
feeParams: FeeParams;
|
|
321
|
+
simulation: TACSimulationResult;
|
|
322
|
+
};
|
|
323
|
+
export type CrosschainTx = {
|
|
324
|
+
evmProxyMsg: EvmProxyMsg;
|
|
325
|
+
assets?: AssetBridgingData[];
|
|
326
|
+
options?: CrossChainTransactionOptions;
|
|
327
|
+
};
|
|
328
|
+
export type NFTItemData = {
|
|
329
|
+
init: boolean;
|
|
330
|
+
index: number;
|
|
331
|
+
collectionAddress: Address;
|
|
332
|
+
ownerAddress: Address | null;
|
|
333
|
+
content: Cell | null;
|
|
334
|
+
};
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TokenSymbol = exports.StageName = exports.NFTAddressType = exports.AssetType = exports.OperationType = exports.BlockchainType = exports.Network = exports.SimplifiedStatuses = void 0;
|
|
4
|
+
var SimplifiedStatuses;
|
|
5
|
+
(function (SimplifiedStatuses) {
|
|
6
|
+
SimplifiedStatuses["PENDING"] = "PENDING";
|
|
7
|
+
SimplifiedStatuses["FAILED"] = "FAILED";
|
|
8
|
+
SimplifiedStatuses["SUCCESSFUL"] = "SUCCESSFUL";
|
|
9
|
+
SimplifiedStatuses["OPERATION_ID_NOT_FOUND"] = "OPERATION_ID_NOT_FOUND";
|
|
10
|
+
})(SimplifiedStatuses || (exports.SimplifiedStatuses = SimplifiedStatuses = {}));
|
|
11
|
+
var Network;
|
|
12
|
+
(function (Network) {
|
|
13
|
+
Network["TESTNET"] = "testnet";
|
|
14
|
+
Network["MAINNET"] = "mainnet";
|
|
15
|
+
})(Network || (exports.Network = Network = {}));
|
|
16
|
+
var BlockchainType;
|
|
17
|
+
(function (BlockchainType) {
|
|
18
|
+
BlockchainType["TAC"] = "TAC";
|
|
19
|
+
BlockchainType["TON"] = "TON";
|
|
20
|
+
})(BlockchainType || (exports.BlockchainType = BlockchainType = {}));
|
|
21
|
+
var OperationType;
|
|
22
|
+
(function (OperationType) {
|
|
23
|
+
OperationType["PENDING"] = "PENDING";
|
|
24
|
+
OperationType["TON_TAC_TON"] = "TON-TAC-TON";
|
|
25
|
+
OperationType["ROLLBACK"] = "ROLLBACK";
|
|
26
|
+
OperationType["TON_TAC"] = "TON-TAC";
|
|
27
|
+
OperationType["TAC_TON"] = "TAC-TON";
|
|
28
|
+
OperationType["UNKNOWN"] = "UNKNOWN";
|
|
29
|
+
})(OperationType || (exports.OperationType = OperationType = {}));
|
|
30
|
+
var AssetType;
|
|
31
|
+
(function (AssetType) {
|
|
32
|
+
AssetType["NFT"] = "NFT";
|
|
33
|
+
AssetType["FT"] = "FT";
|
|
34
|
+
})(AssetType || (exports.AssetType = AssetType = {}));
|
|
35
|
+
var NFTAddressType;
|
|
36
|
+
(function (NFTAddressType) {
|
|
37
|
+
NFTAddressType["ITEM"] = "ITEM";
|
|
38
|
+
NFTAddressType["COLLECTION"] = "COLLECTION";
|
|
39
|
+
})(NFTAddressType || (exports.NFTAddressType = NFTAddressType = {}));
|
|
40
|
+
var StageName;
|
|
41
|
+
(function (StageName) {
|
|
42
|
+
StageName["COLLECTED_IN_TAC"] = "collectedInTAC";
|
|
43
|
+
StageName["INCLUDED_IN_TAC_CONSENSUS"] = "includedInTACConsensus";
|
|
44
|
+
StageName["EXECUTED_IN_TAC"] = "executedInTAC";
|
|
45
|
+
StageName["COLLECTED_IN_TON"] = "collectedInTON";
|
|
46
|
+
StageName["INCLUDED_IN_TON_CONSENSUS"] = "includedInTONConsensus";
|
|
47
|
+
StageName["EXECUTED_IN_TON"] = "executedInTON";
|
|
48
|
+
})(StageName || (exports.StageName = StageName = {}));
|
|
49
|
+
var TokenSymbol;
|
|
50
|
+
(function (TokenSymbol) {
|
|
51
|
+
TokenSymbol["TAC_SYMBOL"] = "TAC";
|
|
52
|
+
TokenSymbol["TON_SYMBOL"] = "TON";
|
|
53
|
+
})(TokenSymbol || (exports.TokenSymbol = TokenSymbol = {}));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Cell } from '@ton/ton';
|
|
2
|
+
export declare const ONCHAIN_CONTENT_PREFIX = 0;
|
|
3
|
+
export declare const OFFCHAIN_CONTENT_PREFIX = 1;
|
|
4
|
+
export interface JettonMetadata {
|
|
5
|
+
uri?: string;
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
image?: string;
|
|
9
|
+
image_data?: string;
|
|
10
|
+
symbol: string;
|
|
11
|
+
decimals?: string;
|
|
12
|
+
}
|
|
13
|
+
export type JettonExtendedMetadata = {
|
|
14
|
+
persistenceType: persistenceType;
|
|
15
|
+
metadata: {
|
|
16
|
+
[s in JettonMetaDataKeys]?: string;
|
|
17
|
+
};
|
|
18
|
+
isJettonDeployerFaultyOnChainData?: boolean;
|
|
19
|
+
contentUri?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function buildJettonOffChainMetadata(contentUri: string): Cell;
|
|
22
|
+
export type JettonMetaDataKeys = 'uri' | 'name' | 'description' | 'image' | 'symbol' | 'image_data' | 'decimals';
|
|
23
|
+
export declare function buildJettonOnchainMetadata(data: JettonMetadata): Cell;
|
|
24
|
+
export type persistenceType = 'none' | 'onchain' | 'offchain_private_domain' | 'offchain_ipfs';
|
|
25
|
+
export declare function readJettonMetadata(contentCell: Cell): Promise<JettonExtendedMetadata>;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// noinspection TypeScriptValidateTypes
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.OFFCHAIN_CONTENT_PREFIX = exports.ONCHAIN_CONTENT_PREFIX = void 0;
|
|
8
|
+
exports.buildJettonOffChainMetadata = buildJettonOffChainMetadata;
|
|
9
|
+
exports.buildJettonOnchainMetadata = buildJettonOnchainMetadata;
|
|
10
|
+
exports.readJettonMetadata = readJettonMetadata;
|
|
11
|
+
const sha256_js_1 = require("@aws-crypto/sha256-js");
|
|
12
|
+
const ton_1 = require("@ton/ton");
|
|
13
|
+
const axios_1 = __importDefault(require("axios"));
|
|
14
|
+
const bn_js_1 = __importDefault(require("bn.js"));
|
|
15
|
+
const errors_1 = require("../errors");
|
|
16
|
+
exports.ONCHAIN_CONTENT_PREFIX = 0x00;
|
|
17
|
+
exports.OFFCHAIN_CONTENT_PREFIX = 0x01;
|
|
18
|
+
const SNAKE_PREFIX = 0x00;
|
|
19
|
+
function buildJettonOffChainMetadata(contentUri) {
|
|
20
|
+
return (0, ton_1.beginCell)().storeInt(exports.OFFCHAIN_CONTENT_PREFIX, 8).storeBuffer(Buffer.from(contentUri, 'ascii')).endCell();
|
|
21
|
+
}
|
|
22
|
+
const jettonOnChainMetadataSpec = {
|
|
23
|
+
uri: 'ascii',
|
|
24
|
+
name: 'utf8',
|
|
25
|
+
description: 'utf8',
|
|
26
|
+
image: 'ascii',
|
|
27
|
+
image_data: 'ascii',
|
|
28
|
+
symbol: 'utf8',
|
|
29
|
+
decimals: 'utf8',
|
|
30
|
+
};
|
|
31
|
+
const sha256 = (str) => {
|
|
32
|
+
const sha = new sha256_js_1.Sha256();
|
|
33
|
+
sha.update(str);
|
|
34
|
+
return Buffer.from(sha.digestSync());
|
|
35
|
+
};
|
|
36
|
+
function storeSnakeContent(content, isFirst) {
|
|
37
|
+
const CELL_MAX_SIZE_BYTES = Math.floor((1023 - 8) / 8);
|
|
38
|
+
const cell = new ton_1.Builder();
|
|
39
|
+
if (isFirst) {
|
|
40
|
+
cell.storeUint(SNAKE_PREFIX, 8);
|
|
41
|
+
}
|
|
42
|
+
cell.storeBuffer(content.subarray(0, CELL_MAX_SIZE_BYTES));
|
|
43
|
+
const remainingContent = content.subarray(CELL_MAX_SIZE_BYTES);
|
|
44
|
+
if (remainingContent.length > 0) {
|
|
45
|
+
cell.storeRef(storeSnakeContent(remainingContent, false));
|
|
46
|
+
}
|
|
47
|
+
return cell.endCell();
|
|
48
|
+
}
|
|
49
|
+
function buildJettonOnchainMetadata(data) {
|
|
50
|
+
const dict = ton_1.Dictionary.empty();
|
|
51
|
+
Object.entries(data).forEach(([k, v]) => {
|
|
52
|
+
if (!jettonOnChainMetadataSpec[k]) {
|
|
53
|
+
throw (0, errors_1.unsupportedKeyError)(k);
|
|
54
|
+
}
|
|
55
|
+
if (!v || v == '' || v == null) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const bufferToStore = Buffer.from(v, jettonOnChainMetadataSpec[k]);
|
|
59
|
+
dict.set(sha256(k), storeSnakeContent(bufferToStore, true));
|
|
60
|
+
});
|
|
61
|
+
return (0, ton_1.beginCell)()
|
|
62
|
+
.storeInt(exports.ONCHAIN_CONTENT_PREFIX, 8)
|
|
63
|
+
.storeDict(dict, ton_1.Dictionary.Keys.Buffer(32), ton_1.Dictionary.Values.Cell())
|
|
64
|
+
.endCell();
|
|
65
|
+
}
|
|
66
|
+
function readSnakeContent(slice, isFirst) {
|
|
67
|
+
if (isFirst && slice.loadUint(8) !== SNAKE_PREFIX) {
|
|
68
|
+
throw errors_1.unsupportedFormatError;
|
|
69
|
+
}
|
|
70
|
+
if (slice.remainingBits % 8 !== 0) {
|
|
71
|
+
throw errors_1.notMultiplyOf8Error;
|
|
72
|
+
}
|
|
73
|
+
let remainingBytes = Buffer.from('');
|
|
74
|
+
if (slice.remainingBits != 0) {
|
|
75
|
+
remainingBytes = slice.loadBuffer(slice.remainingBits / 8);
|
|
76
|
+
}
|
|
77
|
+
if (slice.remainingRefs != 0) {
|
|
78
|
+
const newCell = slice.loadRef();
|
|
79
|
+
remainingBytes = Buffer.concat([remainingBytes, readSnakeContent(newCell.beginParse(), false)]);
|
|
80
|
+
}
|
|
81
|
+
return remainingBytes;
|
|
82
|
+
}
|
|
83
|
+
function parseJettonOnchainMetadata(contentSlice) {
|
|
84
|
+
// Note that this relies on what is (perhaps) an internal implementation detail:
|
|
85
|
+
// "sdk" library dict parser converts: key (provided as buffer) => BN(base10)
|
|
86
|
+
// and upon parsing, it reads it back to a BN(base10)
|
|
87
|
+
// tl;dr if we want to read the map back to a JSON with string keys, we have to convert BN(10) back to hex
|
|
88
|
+
const toKey = (str) => BigInt(new bn_js_1.default(str, 'hex').toString(10));
|
|
89
|
+
const isJettonDeployerFaultyOnChainData = false;
|
|
90
|
+
const cellDict = contentSlice.loadDict(ton_1.Dictionary.Keys.BigUint(256), ton_1.Dictionary.Values.Cell());
|
|
91
|
+
const dict = new Map();
|
|
92
|
+
cellDict.values().forEach((item, index) => {
|
|
93
|
+
dict.set(cellDict.keys()[index], readSnakeContent(item.beginParse(), true));
|
|
94
|
+
});
|
|
95
|
+
const res = {};
|
|
96
|
+
Object.keys(jettonOnChainMetadataSpec).forEach((k) => {
|
|
97
|
+
const val = dict
|
|
98
|
+
.get(toKey(sha256(k).toString('hex')))
|
|
99
|
+
?.toString(jettonOnChainMetadataSpec[k]);
|
|
100
|
+
if (val) {
|
|
101
|
+
res[k] = val;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
return {
|
|
105
|
+
metadata: res,
|
|
106
|
+
isJettonDeployerFaultyOnChainData,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
async function parseJettonOffchainMetadata(contentSlice) {
|
|
110
|
+
const remainingBits = contentSlice.remainingBits;
|
|
111
|
+
if (remainingBits % 8 !== 0) {
|
|
112
|
+
throw errors_1.notMultiplyOf8Error;
|
|
113
|
+
}
|
|
114
|
+
const jsonURI = contentSlice
|
|
115
|
+
.loadBuffer(remainingBits / 8)
|
|
116
|
+
.toString('ascii')
|
|
117
|
+
.replace('ipfs://', 'https://ipfs.io/ipfs/');
|
|
118
|
+
let metadata = null;
|
|
119
|
+
let isIpfs = null;
|
|
120
|
+
try {
|
|
121
|
+
metadata = (await axios_1.default.get(jsonURI)).data;
|
|
122
|
+
isIpfs = /(^|\/)ipfs[.:]/.test(jsonURI);
|
|
123
|
+
}
|
|
124
|
+
catch {
|
|
125
|
+
// nothing
|
|
126
|
+
}
|
|
127
|
+
return {
|
|
128
|
+
metadata,
|
|
129
|
+
isIpfs,
|
|
130
|
+
contentUri: jsonURI,
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async function readJettonMetadata(contentCell) {
|
|
134
|
+
if (contentCell.bits.length <= 0) {
|
|
135
|
+
return {
|
|
136
|
+
contentUri: undefined,
|
|
137
|
+
isJettonDeployerFaultyOnChainData: false,
|
|
138
|
+
metadata: {},
|
|
139
|
+
persistenceType: 'none',
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
const contentSlice = contentCell.beginParse();
|
|
143
|
+
switch (contentSlice.loadUint(8)) {
|
|
144
|
+
case exports.ONCHAIN_CONTENT_PREFIX:
|
|
145
|
+
return {
|
|
146
|
+
persistenceType: 'onchain',
|
|
147
|
+
...parseJettonOnchainMetadata(contentSlice),
|
|
148
|
+
};
|
|
149
|
+
case exports.OFFCHAIN_CONTENT_PREFIX: {
|
|
150
|
+
const { metadata, isIpfs, contentUri } = await parseJettonOffchainMetadata(contentSlice);
|
|
151
|
+
return {
|
|
152
|
+
persistenceType: isIpfs ? 'offchain_ipfs' : 'offchain_private_domain',
|
|
153
|
+
contentUri,
|
|
154
|
+
metadata,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
default:
|
|
158
|
+
throw errors_1.prefixError;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export declare class HighloadQueryId {
|
|
2
|
+
private shift;
|
|
3
|
+
private bitnumber;
|
|
4
|
+
constructor();
|
|
5
|
+
static fromShiftAndBitNumber(shift: bigint, bitnumber: bigint): HighloadQueryId;
|
|
6
|
+
getNext(): HighloadQueryId;
|
|
7
|
+
hasNext(): boolean;
|
|
8
|
+
getShift(): bigint;
|
|
9
|
+
getBitNumber(): bigint;
|
|
10
|
+
getQueryId(): bigint;
|
|
11
|
+
static fromQueryId(queryId: bigint): HighloadQueryId;
|
|
12
|
+
static fromSeqno(i: bigint): HighloadQueryId;
|
|
13
|
+
/**
|
|
14
|
+
* @return {bigint} [0 .. 8380415]
|
|
15
|
+
*/
|
|
16
|
+
toSeqno(): bigint;
|
|
17
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HighloadQueryId = void 0;
|
|
4
|
+
const BIT_NUMBER_SIZE = 10n; // 10 bit
|
|
5
|
+
const SHIFT_SIZE = 13n; // 13 bit
|
|
6
|
+
const MAX_BIT_NUMBER = 1022n;
|
|
7
|
+
const MAX_SHIFT = 8191n; // 2^13 = 8192
|
|
8
|
+
class HighloadQueryId {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.shift = 0n;
|
|
11
|
+
this.bitnumber = 0n;
|
|
12
|
+
}
|
|
13
|
+
static fromShiftAndBitNumber(shift, bitnumber) {
|
|
14
|
+
const q = new HighloadQueryId();
|
|
15
|
+
q.shift = shift;
|
|
16
|
+
if (q.shift < 0)
|
|
17
|
+
throw new Error('invalid shift');
|
|
18
|
+
if (q.shift > MAX_SHIFT)
|
|
19
|
+
throw new Error('invalid shift');
|
|
20
|
+
q.bitnumber = bitnumber;
|
|
21
|
+
if (q.bitnumber < 0)
|
|
22
|
+
throw new Error('invalid bitnumber');
|
|
23
|
+
if (q.bitnumber > MAX_BIT_NUMBER)
|
|
24
|
+
throw new Error('invalid bitnumber');
|
|
25
|
+
return q;
|
|
26
|
+
}
|
|
27
|
+
getNext() {
|
|
28
|
+
let newBitnumber = this.bitnumber + 1n;
|
|
29
|
+
let newShift = this.shift;
|
|
30
|
+
if (newShift === MAX_SHIFT && newBitnumber > MAX_BIT_NUMBER - 1n) {
|
|
31
|
+
throw new Error('Overload'); // NOTE: we left one queryId for emergency withdraw
|
|
32
|
+
}
|
|
33
|
+
if (newBitnumber > MAX_BIT_NUMBER) {
|
|
34
|
+
newBitnumber = 0n;
|
|
35
|
+
newShift += 1n;
|
|
36
|
+
if (newShift > MAX_SHIFT) {
|
|
37
|
+
throw new Error('Overload');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return HighloadQueryId.fromShiftAndBitNumber(newShift, newBitnumber);
|
|
41
|
+
}
|
|
42
|
+
hasNext() {
|
|
43
|
+
const isEnd = this.bitnumber >= MAX_BIT_NUMBER - 1n && this.shift === MAX_SHIFT; // NOTE: we left one queryId for emergency withdraw;
|
|
44
|
+
return !isEnd;
|
|
45
|
+
}
|
|
46
|
+
getShift() {
|
|
47
|
+
return this.shift;
|
|
48
|
+
}
|
|
49
|
+
getBitNumber() {
|
|
50
|
+
return this.bitnumber;
|
|
51
|
+
}
|
|
52
|
+
getQueryId() {
|
|
53
|
+
return (this.shift << BIT_NUMBER_SIZE) + this.bitnumber;
|
|
54
|
+
}
|
|
55
|
+
static fromQueryId(queryId) {
|
|
56
|
+
const shift = queryId >> BIT_NUMBER_SIZE;
|
|
57
|
+
const bitnumber = queryId & 1023n;
|
|
58
|
+
return this.fromShiftAndBitNumber(shift, bitnumber);
|
|
59
|
+
}
|
|
60
|
+
static fromSeqno(i) {
|
|
61
|
+
const shift = i / 1023n;
|
|
62
|
+
const bitnumber = i % 1023n;
|
|
63
|
+
return this.fromShiftAndBitNumber(shift, bitnumber);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* @return {bigint} [0 .. 8380415]
|
|
67
|
+
*/
|
|
68
|
+
toSeqno() {
|
|
69
|
+
return this.bitnumber + this.shift * 1023n;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.HighloadQueryId = HighloadQueryId;
|