@tomo-inc/transaction-builder-sdk 0.0.1-alpha.3 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomo-inc/transaction-builder-sdk",
3
- "version": "0.0.1-alpha.3",
3
+ "version": "0.0.2",
4
4
  "author": "tomo.inc",
5
5
  "files": [
6
6
  "dist/**/*",
@@ -26,10 +26,10 @@
26
26
  "tronweb": "^6.0.3"
27
27
  },
28
28
  "devDependencies": {
29
- "@tomo-inc/tomo-api": "workspace:*",
30
29
  "@types/node": "^20.11.19",
31
30
  "tsup": "^8.3.5",
32
31
  "typescript": "^5.3.3",
33
- "vitest": "^3.0.8"
32
+ "vitest": "^3.0.8",
33
+ "@tomo-inc/tomo-api": "0.0.2"
34
34
  }
35
- }
35
+ }
package/dist/index.d.cts DELETED
@@ -1,584 +0,0 @@
1
- import { Hex } from 'viem';
2
-
3
- /**
4
- * Platform types supported by the wallet
5
- *
6
- * Represents different blockchain platforms and their specific characteristics
7
- */
8
- declare enum IPlatformType {
9
- /** Ethereum Virtual Machine compatible chains */
10
- EVM = "EVM",
11
- /** TON (The Open Network) blockchain */
12
- TON = "TON",
13
- /** TRON blockchain */
14
- TRON = "TRON",
15
- /** Bitcoin blockchain */
16
- BTC = "BTC",
17
- /** Dogecoin blockchain */
18
- DOGE = "DOGE",
19
- /** Sui blockchain */
20
- SUI = "SUI",
21
- /** Cosmos ecosystem blockchains */
22
- COSMOS = "COSMOS",
23
- /** Aptos blockchain */
24
- APTOS = "APTOS",
25
- /** Solana blockchain */
26
- SOLANA = "SOLANA"
27
- }
28
- /**
29
- * Chain information structure
30
- *
31
- * Represents detailed information about a blockchain network including
32
- * its properties, capabilities, and configuration details
33
- */
34
- type Chain = {
35
- /** Full name of the blockchain network */
36
- chainName: string;
37
- /** Numeric chain identifier (e.g., 1 for Ethereum mainnet) */
38
- chainId: number;
39
- /** Internal index for ordering chains in UI */
40
- chainIndex: number;
41
- /** Whether order status tracking is supported on this chain */
42
- orderStatusSupport: boolean;
43
- /** Whether the chain is currently supported for operations */
44
- support: boolean;
45
- /** Chain type identifier */
46
- type: number;
47
- /** Short name or display name of the chain */
48
- name: string;
49
- /** Full name of the native currency (e.g., "Ethereum") */
50
- nativeCurrencyName: string;
51
- /** Symbol of the native currency (e.g., "ETH") */
52
- nativeCurrencySymbol: string;
53
- /** Decimal places for the native currency (e.g., 18 for ETH) */
54
- nativeCurrencyDecimals: number;
55
- /** Platform type this chain belongs to */
56
- platformType: IPlatformType;
57
- /** URL to the chain's icon/logo */
58
- icon: string;
59
- /** Whether swap operations are supported on this chain */
60
- supportSwap: boolean;
61
- /** Whether the chain is listed/publicly visible */
62
- isListed: boolean;
63
- /** Whether this is a testnet (optional) */
64
- isTestnet?: boolean;
65
- /** Array of RPC URLs for connecting to the chain (optional) */
66
- rpcUrls?: string[];
67
- /** URL to the chain's block explorer (optional) */
68
- blockExplorerUrl?: string;
69
- };
70
-
71
- type TransactionToken = {
72
- address: string;
73
- chain: Chain;
74
- };
75
- type TransactionQuoteParams = {
76
- sender: string | Hex;
77
- recipient: string | Hex;
78
- fromToken: TransactionToken;
79
- toToken: TransactionToken;
80
- slippage: number;
81
- amount: string;
82
- };
83
- type TransactionQuoteResult = {
84
- quoteID: string;
85
- amountIn: string;
86
- amountOut: string;
87
- contract: string;
88
- amountOutMin: string;
89
- gasNetWorkFee: string;
90
- approveGasFee: string;
91
- crossNetworkFee: {
92
- fromChainNetworkFee: string;
93
- toChainNetworkFee: string;
94
- providerServiceFee: string;
95
- };
96
- dexInfo: {
97
- name: string;
98
- displayName: string;
99
- logo: string;
100
- };
101
- fromToken: {
102
- chainID: string;
103
- address: string;
104
- symbol: string;
105
- decimals: number;
106
- };
107
- toToken: {
108
- chainID: string;
109
- address: string;
110
- symbol: string;
111
- decimals: number;
112
- };
113
- extended: {
114
- requestID: string;
115
- };
116
- routes: [
117
- {
118
- amountIn: string;
119
- amountOut: string;
120
- paths: [
121
- {
122
- dexProvider: string;
123
- fromToken: {
124
- chainID: string;
125
- address: string;
126
- symbol: string;
127
- decimals: number;
128
- };
129
- toToken: {
130
- chainID: string;
131
- address: string;
132
- symbol: string;
133
- decimals: number;
134
- };
135
- amountIn: string;
136
- amountOut: string;
137
- }
138
- ];
139
- }
140
- ];
141
- estimatedGas: {
142
- feeUSD: string;
143
- gasLimit: string;
144
- baseFee: string;
145
- priorityFee: {
146
- low: string;
147
- medium: string;
148
- high: string;
149
- };
150
- };
151
- };
152
- type TransactionEVM = {
153
- chainId: string;
154
- data: string;
155
- gasLimit: string;
156
- gas?: string;
157
- gasPrice: string | undefined;
158
- maxFeePerGas: string | bigint | undefined;
159
- maxPriorityFeePerGas: string | bigint | undefined;
160
- nonce: string;
161
- to: string;
162
- from: string;
163
- value: string;
164
- };
165
- type TransactionSOL = {
166
- data: string;
167
- };
168
- type TransactionTRON = {
169
- data: string;
170
- value: string;
171
- from: string;
172
- to: string;
173
- rawData: {
174
- visible: boolean;
175
- txID: string;
176
- raw_data: any;
177
- raw_data_hex: string;
178
- };
179
- };
180
- type Transaction = TransactionEVM | TransactionSOL | TransactionTRON;
181
- type PermitSignParams = {
182
- permit2InputEncode: string;
183
- permitSingle: {
184
- details: {
185
- amount: string;
186
- expiration: number;
187
- nonce: number;
188
- token: string;
189
- };
190
- sigDeadline: number;
191
- spender: string;
192
- };
193
- signature: string;
194
- };
195
-
196
- type Config = {
197
- API_KEY: string;
198
- API_SECRET: string;
199
- SALT: string;
200
- CLIENT_ID: string;
201
- };
202
- type TomoStage = "dev" | "prod";
203
-
204
- declare enum SwapRouterTxEVMType {
205
- APPROVE = "approve",
206
- SWAP = "swap",
207
- EIP712 = "EIP712"
208
- }
209
- type SwapRouterTxEVMResult = {
210
- type: SwapRouterTxEVMType;
211
- chainId: number;
212
- data: string;
213
- value: string;
214
- from: string;
215
- to: string;
216
- nonce: number;
217
- gasInfo: {
218
- gasLimit: string;
219
- baseFee: string;
220
- priorityFee: {
221
- low: string;
222
- medium: string;
223
- high: string;
224
- };
225
- };
226
- extended: {
227
- requestID: string;
228
- };
229
- };
230
- type SwapRouterTxSOLResult = {
231
- type: SwapRouterTxEVMType.SWAP;
232
- chainId: number;
233
- data: string;
234
- serializedData: string;
235
- blockHash: string;
236
- gasInfo: {
237
- gasLimit: string;
238
- baseFee: string;
239
- priorityFee: {
240
- low: string;
241
- medium: string;
242
- high: string;
243
- };
244
- };
245
- };
246
- type SwapRouterTxTronResult = {
247
- type: SwapRouterTxEVMType;
248
- chainId: number;
249
- data: string;
250
- value: string;
251
- from: string;
252
- to: string;
253
- rawData: {
254
- visible: boolean;
255
- txID: string;
256
- raw_data: any;
257
- raw_data_hex: string;
258
- };
259
- gasInfo: {
260
- gasLimit: string;
261
- baseFee: string;
262
- };
263
- };
264
- type SwapApiRouterTxResponseV2 = {
265
- transactions: (SwapRouterTxEVMResult | SwapRouterTxSOLResult | SwapRouterTxTronResult)[];
266
- };
267
-
268
- declare const bridgeBuilder: (builder: (params: TransactionQuoteResult, permitSignParams?: PermitSignParams | undefined | null) => Promise<SwapApiRouterTxResponseV2>) => (params: TransactionQuoteResult, quoteParams: TransactionQuoteParams, permitParams?: {
269
- signature: Hex;
270
- permitTypeData: any;
271
- } | undefined | null) => Promise<Transaction>;
272
-
273
- declare const getApproveBuilder: (builder: (params: TransactionQuoteResult, permitSignParams?: PermitSignParams | undefined | null) => Promise<SwapApiRouterTxResponseV2>) => (params: TransactionQuoteResult, quoteParams: TransactionQuoteParams) => Promise<Transaction | undefined>;
274
-
275
- declare const getBridgeQuotes: (quote: (params: TransactionQuoteParams) => Promise<TransactionQuoteResult[]>) => (params: TransactionQuoteParams) => Promise<TransactionQuoteResult[]>;
276
-
277
- declare const getSwapQuotes: (quote: (params: TransactionQuoteParams) => Promise<TransactionQuoteResult[]>) => (params: TransactionQuoteParams) => Promise<TransactionQuoteResult[]>;
278
-
279
- declare const swapBuilder: (builder: (params: TransactionQuoteResult, permitSignParams?: PermitSignParams | undefined | null) => Promise<SwapApiRouterTxResponseV2>) => (params: TransactionQuoteResult, quoteParams: TransactionQuoteParams, permitParams?: {
280
- signature: Hex;
281
- permitTypeData: any;
282
- } | undefined | null) => Promise<Transaction>;
283
-
284
- declare class Business {
285
- private apiConfig;
286
- private apiMethods;
287
- private _quoteMethod;
288
- private _builderMethod;
289
- private _bridgeBuilderMethod;
290
- private _swapBuilderMethod;
291
- private _getBridgeQuotesMethod;
292
- private _getSwapQuotesMethod;
293
- private _getApproveBuilderMethod;
294
- /**
295
- * Creates a new instance of the Business SDK
296
- *
297
- * @param options - Configuration options for the SDK
298
- * @param options.routerApi - Custom router API URL for transaction routing
299
- * @param options.marketApi - Custom market API URL for token information
300
- */
301
- constructor({ config, tomoStage }: {
302
- config: Config;
303
- tomoStage: TomoStage;
304
- });
305
- private getQuoteMethod;
306
- private getBuilderMethod;
307
- private getBridgeBuilderMethod;
308
- private getSwapBuilderMethod;
309
- private getGetBridgeQuotesMethod;
310
- private getGetSwapQuotesMethod;
311
- private getGetApproveBuilderMethod;
312
- /**
313
- * Build a cross-chain bridge transaction based on quote result
314
- *
315
- * This method constructs a complete transaction object for cross-chain bridge operations
316
- * based on the provided quote and parameters. The resulting transaction can be directly
317
- * sent to the network after signing.
318
- *
319
- * @param quote - The quote result from getBridgeQuotes containing route and pricing information
320
- * @param quoteParams - The original quote parameters including sender, recipient, tokens and amount
321
- * @param permitSignParams - Optional permit signature parameters for token approvals (required only when TomoDEX is selected in the quote)
322
- * @returns Promise<Transaction> - The built transaction ready to be signed and submitted
323
- *
324
- * @throws Error - If fromToken and toToken are on the same chain (should use swapBuilder instead)
325
- *
326
- * @example
327
- * ```typescript
328
- * const quote = await business.getBridgeQuotes(quoteParams);
329
- * const transaction = await business.bridgeBuilder(quote[0], quoteParams);
330
- * ```
331
- */
332
- bridgeBuilder: (quote: TransactionQuoteResult, quoteParams: TransactionQuoteParams, permitSignParams?: {
333
- signature: Hex;
334
- permitTypeData: any;
335
- } | null | undefined) => ReturnType<ReturnType<typeof bridgeBuilder>>;
336
- /**
337
- * Get cross-chain bridge quotes for token swaps between different chains
338
- *
339
- * This method fetches available routes and pricing information for cross-chain token swaps.
340
- * It returns multiple quotes from different bridge providers, allowing users to choose
341
- * the best option based on fees, speed, and other factors.
342
- *
343
- * @param params - Transaction quote parameters including sender, recipient, tokens and amount
344
- * @returns Promise<TransactionQuoteResult[]> - Array of quote results containing routing information and transaction details
345
- *
346
- * @throws Error - If fromToken and toToken are on the same chain (should use getSwapQuotes instead)
347
- *
348
- * @example
349
- * ```typescript
350
- * const quoteParams = {
351
- * sender: "0x...",
352
- * recipient: "0x...",
353
- * fromToken: {
354
- * address: "", // Native token
355
- * chain: ethereumChain
356
- * },
357
- * toToken: {
358
- * address: "0x...", // ERC20 token on another chain
359
- * chain: bscChain
360
- * },
361
- * slippage: 0.5,
362
- * amount: "1000000000000000000" // 1 ETH in wei
363
- * };
364
- *
365
- * const quotes = await business.getBridgeQuotes(quoteParams);
366
- * ```
367
- */
368
- getBridgeQuotes: (params: TransactionQuoteParams) => ReturnType<ReturnType<typeof getBridgeQuotes>>;
369
- /**
370
- * Get same-chain swap quotes for token swaps on the same chain
371
- *
372
- * This method fetches available routes and pricing information for token swaps within
373
- * the same blockchain network. It returns multiple quotes from different DEXes,
374
- * allowing users to choose the best option based on price, fees, and liquidity.
375
- *
376
- * @param params - Transaction quote parameters including sender, recipient, tokens and amount
377
- * @returns Promise<TransactionQuoteResult[]> - Array of quote results containing routing information and transaction details
378
- *
379
- * @throws Error - If fromToken and toToken are on different chains (should use getBridgeQuotes instead)
380
- *
381
- * @example
382
- * ```typescript
383
- * const quoteParams = {
384
- * sender: "0x...",
385
- * recipient: "0x...",
386
- * fromToken: {
387
- * address: "", // Native token (ETH)
388
- * chain: ethereumChain
389
- * },
390
- * toToken: {
391
- * address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
392
- * chain: ethereumChain
393
- * },
394
- * slippage: 0.5,
395
- * amount: "1000000000000000000" // 1 ETH in wei
396
- * };
397
- *
398
- * const quotes = await business.getSwapQuotes(quoteParams);
399
- * ```
400
- */
401
- getSwapQuotes: (params: TransactionQuoteParams) => ReturnType<ReturnType<typeof getSwapQuotes>>;
402
- /**
403
- * Build a same-chain swap transaction based on quote result
404
- *
405
- * This method constructs a complete transaction object for same-chain swap operations
406
- * based on the provided quote and parameters. The resulting transaction can be directly
407
- * sent to the network after signing.
408
- *
409
- * @param quote - The quote result from getSwapQuotes containing route and pricing information
410
- * @param quoteParams - The original quote parameters including sender, recipient, tokens and amount
411
- * @param permitSignParams - Optional permit signature parameters for token approvals (required only when TomoDEX is selected in the quote)
412
- * @returns Promise<Transaction> - The built transaction ready to be signed and submitted
413
- *
414
- * @throws Error - If fromToken and toToken are on different chains (should use bridgeBuilder instead)
415
- *
416
- * @example
417
- * ```typescript
418
- * const quote = await business.getSwapQuotes(quoteParams);
419
- * const transaction = await business.swapBuilder(quote[0], quoteParams);
420
- * ```
421
- */
422
- swapBuilder: (quote: TransactionQuoteResult, quoteParams: TransactionQuoteParams, permitSignParams?: {
423
- signature: Hex;
424
- permitTypeData: any;
425
- } | null | undefined) => ReturnType<ReturnType<typeof swapBuilder>>;
426
- /**
427
- * Get all supported chains for swap operations
428
- *
429
- * This method returns a list of all blockchain networks that are supported
430
- * for swap operations. Each chain object contains information such as
431
- * chain ID, name, native currency, and other relevant details needed
432
- * for performing swaps on that network.
433
- *
434
- * @returns Chain[] - Array of supported chain objects
435
- *
436
- * @example
437
- * ```typescript
438
- * const business = new Business();
439
- * const supportedChains = business.getSwapSupportChains();
440
- * const ethereum = supportedChains.find(chain => chain.chainId === 1);
441
- * ```
442
- */
443
- getSwapSupportChains: () => Chain[];
444
- /**
445
- * Get all supported chains for bridge operations
446
- *
447
- * This method returns a list of all blockchain networks that are supported
448
- * for cross-chain bridge operations. Each chain object contains information such as
449
- * chain ID, name, native currency, and other relevant details needed
450
- * for performing cross-chain transfers on that network.
451
- *
452
- * @returns Chain[] - Array of supported chain objects for bridge operations
453
- *
454
- * @example
455
- * ```typescript
456
- * const business = new Business();
457
- * const bridgeChains = business.getBridgeSupportChains();
458
- * const bsc = bridgeChains.find(chain => chain.chainId === 56);
459
- * ```
460
- */
461
- getBridgeSupportChains: () => Chain[];
462
- /**
463
- * Generate ERC20 token approval transaction for swap operations
464
- *
465
- * This method creates an approval transaction that allows a DEX contract to spend
466
- * the user's ERC20 tokens. This is required before swapping ERC20 tokens for
467
- * most DEXes (except those supporting permit signatures like TomoDEX).
468
- *
469
- * The method checks if an approval transaction is needed based on the quote result.
470
- * If needed, it returns a transaction object that can be sent to the network.
471
- *
472
- * @param quote - The quote result from getSwapQuotes or getBridgeQuotes containing route information
473
- * @param quoteParams - The original quote parameters including sender, recipient, tokens and amount
474
- * @returns Promise<Transaction | undefined> - The approval transaction if needed, otherwise undefined
475
- *
476
- * @example
477
- * ```typescript
478
- * const quotes = await business.getSwapQuotes(quoteParams);
479
- * const approveTx = await business.getApproveBuilder(quotes[0], quoteParams);
480
- * if (approveTx) {
481
- * // Send approval transaction
482
- * await sendTransaction(approveTx);
483
- * }
484
- * ```
485
- */
486
- getApproveBuilder: (quote: TransactionQuoteResult, quoteParams: TransactionQuoteParams) => ReturnType<ReturnType<typeof getApproveBuilder>>;
487
- /**
488
- * EVM-specific permit signing utilities
489
- *
490
- * This namespace provides methods for handling ERC20 token approvals using
491
- * EIP-712 permit signatures, which allows gasless approvals for compatible tokens.
492
- */
493
- evm: {
494
- /**
495
- * Generate EIP-712 typed data for ERC20 token permit signatures
496
- *
497
- * This method creates the structured data required for signing ERC20 permit
498
- * transactions using EIP-712. The resulting data can be used with wallet
499
- * signature methods to generate permit signatures without submitting a
500
- * separate on-chain transaction.
501
- *
502
- * @param quoteParams - The original quote parameters including sender, recipient, tokens and amount
503
- * @param quote - The quote result from getSwapQuotes or getBridgeQuotes
504
- * @returns Promise<any> - EIP-712 typed data structure for signing
505
- *
506
- * @example
507
- * ```typescript
508
- * const permitTypeData = await business.evm.getPermitTypeData(quoteParams, quote);
509
- * const signature = await signTypedData(permitTypeData);
510
- * const unsignTx = await business.swapBuilder(quote, quoteParams, { signature, permitTypeData });
511
- * ```
512
- */
513
- getPermitTypeData: (quoteParams: TransactionQuoteParams, quoteResult: TransactionQuoteResult) => Promise<{
514
- types: {
515
- PermitDetails: {
516
- name: string;
517
- type: string;
518
- }[];
519
- PermitSingle: {
520
- name: string;
521
- type: string;
522
- }[];
523
- };
524
- message: {
525
- details: {
526
- token: string;
527
- amount: string;
528
- expiration: number;
529
- nonce: number;
530
- };
531
- spender: string;
532
- sigDeadline: number;
533
- };
534
- primaryType: string;
535
- domain: {
536
- name: string;
537
- chainId: number;
538
- verifyingContract: Hex;
539
- };
540
- }>;
541
- };
542
- tron: {
543
- /**
544
- * @example
545
- * ```typescript
546
- * const permitTypeData = await business.tron.getPermitTypeData(quoteParams, quote);
547
- * const signature = await signTypedData(permitTypeData);
548
- * const unsignTx = await business.swapBuilder(quote, quoteParams, { signature, permitTypeData });
549
- * ```
550
- */
551
- getPermitTypeData: (quoteParams: TransactionQuoteParams, quoteResult: TransactionQuoteResult) => Promise<{
552
- types: {
553
- PermitDetails: {
554
- name: string;
555
- type: string;
556
- }[];
557
- PermitSingle: {
558
- name: string;
559
- type: string;
560
- }[];
561
- };
562
- message: {
563
- details: {
564
- token: `0x${string}`;
565
- amount: string;
566
- expiration: number;
567
- nonce: bigint;
568
- };
569
- spender: `0x${string}`;
570
- sigDeadline: number;
571
- };
572
- primaryType: string;
573
- domain: {
574
- name: string;
575
- chainId: number;
576
- verifyingContract: string;
577
- };
578
- signatureHash: string;
579
- }>;
580
- rpc: string;
581
- };
582
- }
583
-
584
- export { Business, type Chain, IPlatformType, type PermitSignParams, type Transaction, type TransactionEVM, type TransactionQuoteParams, type TransactionQuoteResult, type TransactionSOL, type TransactionTRON, type TransactionToken };