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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +0,0 @@
1
- export const TRON_PERMIT2_ADDRESS = "TDJNTBi51CnnpCYYgi6GitoT4CJWrqim2G"; // permit2
2
-
3
- export const EVM_PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3"; // permit2
@@ -1,3 +0,0 @@
1
- export const apiInitializedError = async () => {
2
- throw new Error("API methods not initialized");
3
- };
@@ -1,10 +0,0 @@
1
- {
2
- "dev": {
3
- "routerApiUrl": "https://wallet-test.tomo.inc/quote",
4
- "marketApiUrl": "https://gateway-dev.tomo.inc/token"
5
- },
6
- "prod": {
7
- "routerApiUrl": "https://wallet-test.tomo.inc/quote",
8
- "marketApiUrl": "https://gateway-dev.tomo.inc/token"
9
- }
10
- }
package/src/index.ts DELETED
@@ -1,368 +0,0 @@
1
- // src/index.ts
2
- import { Hex } from "viem";
3
- import { reinitializeApi, reinitializeApiMethods } from "./api";
4
- import { getBridgeSupportChains } from "./chains/getBridgeSupportChains";
5
- import { getSwapSupportChains } from "./chains/getSwapSupportChains";
6
- import { apiInitializedError } from "./constant";
7
- import { bridgeBuilder } from "./swap/bridgeBuilder";
8
- import { getApproveBuilder } from "./swap/getApproveBuilder";
9
- import { getBridgeQuotes } from "./swap/getBridgeQuotes";
10
- import { getSwapQuotes } from "./swap/getSwapQuotes";
11
- import { builder } from "./swap/methods/builder";
12
- import { getPermitTypeData } from "./swap/methods/chains/evm";
13
- import { getTronPermitSignData, TRON_RPC } from "./swap/methods/chains/tron";
14
- import { quote } from "./swap/methods/quote";
15
- import { swapBuilder } from "./swap/swapBuilder";
16
- import { ApiConfig, Config, TomoStage } from "./types";
17
- import { Chain, IPlatformType } from "./types/chain";
18
- import {
19
- PermitSignParams,
20
- Transaction,
21
- TransactionEVM,
22
- TransactionQuoteParams,
23
- TransactionQuoteResult,
24
- TransactionSOL,
25
- TransactionToken,
26
- TransactionTRON,
27
- } from "./types/swap";
28
-
29
- export class Business {
30
- private apiConfig: ApiConfig = {
31
- routeApi: null,
32
- marketApi: null,
33
- };
34
- private apiMethods: ReturnType<typeof reinitializeApiMethods> | null = null;
35
-
36
- private _quoteMethod: ReturnType<typeof quote> | null = null;
37
- private _builderMethod: ReturnType<typeof builder> | null = null;
38
- private _bridgeBuilderMethod: ReturnType<typeof bridgeBuilder> | null = null;
39
- private _swapBuilderMethod: ReturnType<typeof swapBuilder> | null = null;
40
- private _getBridgeQuotesMethod: ReturnType<typeof getBridgeQuotes> | null = null;
41
- private _getSwapQuotesMethod: ReturnType<typeof getSwapQuotes> | null = null;
42
- private _getApproveBuilderMethod: ReturnType<typeof getApproveBuilder> | null = null;
43
-
44
- /**
45
- * Creates a new instance of the Business SDK
46
- *
47
- * @param options - Configuration options for the SDK
48
- * @param options.routerApi - Custom router API URL for transaction routing
49
- * @param options.marketApi - Custom market API URL for token information
50
- */
51
- constructor({ config, tomoStage }: { config: Config; tomoStage: TomoStage }) {
52
- const apiConfig = reinitializeApi(tomoStage, config);
53
- this.apiConfig = apiConfig;
54
- this.apiMethods = reinitializeApiMethods(apiConfig);
55
- }
56
-
57
- private getQuoteMethod() {
58
- if (!this._quoteMethod && this.apiMethods) {
59
- this._quoteMethod = quote(this.apiMethods);
60
- }
61
- return this._quoteMethod || apiInitializedError;
62
- }
63
-
64
- private getBuilderMethod() {
65
- if (!this._builderMethod && this.apiMethods) {
66
- this._builderMethod = builder(this.apiMethods);
67
- }
68
- return this._builderMethod || apiInitializedError;
69
- }
70
-
71
- private getBridgeBuilderMethod() {
72
- if (!this._bridgeBuilderMethod && this.apiMethods) {
73
- this._bridgeBuilderMethod = bridgeBuilder(this.getBuilderMethod());
74
- }
75
- return this._bridgeBuilderMethod || apiInitializedError;
76
- }
77
-
78
- private getSwapBuilderMethod() {
79
- if (!this._swapBuilderMethod && this.apiMethods) {
80
- this._swapBuilderMethod = swapBuilder(this.getBuilderMethod());
81
- }
82
- return this._swapBuilderMethod || apiInitializedError;
83
- }
84
-
85
- private getGetBridgeQuotesMethod() {
86
- if (!this._getBridgeQuotesMethod && this.apiMethods) {
87
- this._getBridgeQuotesMethod = getBridgeQuotes(this.getQuoteMethod());
88
- }
89
- return this._getBridgeQuotesMethod || apiInitializedError;
90
- }
91
-
92
- private getGetSwapQuotesMethod() {
93
- if (!this._getSwapQuotesMethod && this.apiMethods) {
94
- this._getSwapQuotesMethod = getSwapQuotes(this.getQuoteMethod());
95
- }
96
- return this._getSwapQuotesMethod || apiInitializedError;
97
- }
98
-
99
- private getGetApproveBuilderMethod() {
100
- if (!this._getApproveBuilderMethod && this.apiMethods) {
101
- this._getApproveBuilderMethod = getApproveBuilder(this.getBuilderMethod());
102
- }
103
- return this._getApproveBuilderMethod || apiInitializedError;
104
- }
105
-
106
- /**
107
- * Build a cross-chain bridge transaction based on quote result
108
- *
109
- * This method constructs a complete transaction object for cross-chain bridge operations
110
- * based on the provided quote and parameters. The resulting transaction can be directly
111
- * sent to the network after signing.
112
- *
113
- * @param quote - The quote result from getBridgeQuotes containing route and pricing information
114
- * @param quoteParams - The original quote parameters including sender, recipient, tokens and amount
115
- * @param permitSignParams - Optional permit signature parameters for token approvals (required only when TomoDEX is selected in the quote)
116
- * @returns Promise<Transaction> - The built transaction ready to be signed and submitted
117
- *
118
- * @throws Error - If fromToken and toToken are on the same chain (should use swapBuilder instead)
119
- *
120
- * @example
121
- * ```typescript
122
- * const quote = await business.getBridgeQuotes(quoteParams);
123
- * const transaction = await business.bridgeBuilder(quote[0], quoteParams);
124
- * ```
125
- */
126
- bridgeBuilder = (
127
- quote: TransactionQuoteResult,
128
- quoteParams: TransactionQuoteParams,
129
- permitSignParams:
130
- | {
131
- signature: Hex;
132
- permitTypeData: any;
133
- }
134
- | null
135
- | undefined = undefined,
136
- ): ReturnType<ReturnType<typeof bridgeBuilder>> => {
137
- return this.getBridgeBuilderMethod()(quote, quoteParams, permitSignParams);
138
- };
139
-
140
- /**
141
- * Get cross-chain bridge quotes for token swaps between different chains
142
- *
143
- * This method fetches available routes and pricing information for cross-chain token swaps.
144
- * It returns multiple quotes from different bridge providers, allowing users to choose
145
- * the best option based on fees, speed, and other factors.
146
- *
147
- * @param params - Transaction quote parameters including sender, recipient, tokens and amount
148
- * @returns Promise<TransactionQuoteResult[]> - Array of quote results containing routing information and transaction details
149
- *
150
- * @throws Error - If fromToken and toToken are on the same chain (should use getSwapQuotes instead)
151
- *
152
- * @example
153
- * ```typescript
154
- * const quoteParams = {
155
- * sender: "0x...",
156
- * recipient: "0x...",
157
- * fromToken: {
158
- * address: "", // Native token
159
- * chain: ethereumChain
160
- * },
161
- * toToken: {
162
- * address: "0x...", // ERC20 token on another chain
163
- * chain: bscChain
164
- * },
165
- * slippage: 0.5,
166
- * amount: "1000000000000000000" // 1 ETH in wei
167
- * };
168
- *
169
- * const quotes = await business.getBridgeQuotes(quoteParams);
170
- * ```
171
- */
172
- getBridgeQuotes = (params: TransactionQuoteParams): ReturnType<ReturnType<typeof getBridgeQuotes>> => {
173
- return this.getGetBridgeQuotesMethod()(params);
174
- };
175
-
176
- /**
177
- * Get same-chain swap quotes for token swaps on the same chain
178
- *
179
- * This method fetches available routes and pricing information for token swaps within
180
- * the same blockchain network. It returns multiple quotes from different DEXes,
181
- * allowing users to choose the best option based on price, fees, and liquidity.
182
- *
183
- * @param params - Transaction quote parameters including sender, recipient, tokens and amount
184
- * @returns Promise<TransactionQuoteResult[]> - Array of quote results containing routing information and transaction details
185
- *
186
- * @throws Error - If fromToken and toToken are on different chains (should use getBridgeQuotes instead)
187
- *
188
- * @example
189
- * ```typescript
190
- * const quoteParams = {
191
- * sender: "0x...",
192
- * recipient: "0x...",
193
- * fromToken: {
194
- * address: "", // Native token (ETH)
195
- * chain: ethereumChain
196
- * },
197
- * toToken: {
198
- * address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48", // USDC
199
- * chain: ethereumChain
200
- * },
201
- * slippage: 0.5,
202
- * amount: "1000000000000000000" // 1 ETH in wei
203
- * };
204
- *
205
- * const quotes = await business.getSwapQuotes(quoteParams);
206
- * ```
207
- */
208
- getSwapQuotes = (params: TransactionQuoteParams): ReturnType<ReturnType<typeof getSwapQuotes>> => {
209
- return this.getGetSwapQuotesMethod()(params);
210
- };
211
-
212
- /**
213
- * Build a same-chain swap transaction based on quote result
214
- *
215
- * This method constructs a complete transaction object for same-chain swap operations
216
- * based on the provided quote and parameters. The resulting transaction can be directly
217
- * sent to the network after signing.
218
- *
219
- * @param quote - The quote result from getSwapQuotes containing route and pricing information
220
- * @param quoteParams - The original quote parameters including sender, recipient, tokens and amount
221
- * @param permitSignParams - Optional permit signature parameters for token approvals (required only when TomoDEX is selected in the quote)
222
- * @returns Promise<Transaction> - The built transaction ready to be signed and submitted
223
- *
224
- * @throws Error - If fromToken and toToken are on different chains (should use bridgeBuilder instead)
225
- *
226
- * @example
227
- * ```typescript
228
- * const quote = await business.getSwapQuotes(quoteParams);
229
- * const transaction = await business.swapBuilder(quote[0], quoteParams);
230
- * ```
231
- */
232
- swapBuilder = (
233
- quote: TransactionQuoteResult,
234
- quoteParams: TransactionQuoteParams,
235
- permitSignParams:
236
- | {
237
- signature: Hex;
238
- permitTypeData: any;
239
- }
240
- | null
241
- | undefined = undefined,
242
- ): ReturnType<ReturnType<typeof swapBuilder>> => {
243
- return this.getSwapBuilderMethod()(quote, quoteParams, permitSignParams);
244
- };
245
-
246
- /**
247
- * Get all supported chains for swap operations
248
- *
249
- * This method returns a list of all blockchain networks that are supported
250
- * for swap operations. Each chain object contains information such as
251
- * chain ID, name, native currency, and other relevant details needed
252
- * for performing swaps on that network.
253
- *
254
- * @returns Chain[] - Array of supported chain objects
255
- *
256
- * @example
257
- * ```typescript
258
- * const business = new Business();
259
- * const supportedChains = business.getSwapSupportChains();
260
- * const ethereum = supportedChains.find(chain => chain.chainId === 1);
261
- * ```
262
- */
263
- getSwapSupportChains = getSwapSupportChains;
264
-
265
- /**
266
- * Get all supported chains for bridge operations
267
- *
268
- * This method returns a list of all blockchain networks that are supported
269
- * for cross-chain bridge operations. Each chain object contains information such as
270
- * chain ID, name, native currency, and other relevant details needed
271
- * for performing cross-chain transfers on that network.
272
- *
273
- * @returns Chain[] - Array of supported chain objects for bridge operations
274
- *
275
- * @example
276
- * ```typescript
277
- * const business = new Business();
278
- * const bridgeChains = business.getBridgeSupportChains();
279
- * const bsc = bridgeChains.find(chain => chain.chainId === 56);
280
- * ```
281
- */
282
- getBridgeSupportChains = getBridgeSupportChains;
283
-
284
- /**
285
- * Generate ERC20 token approval transaction for swap operations
286
- *
287
- * This method creates an approval transaction that allows a DEX contract to spend
288
- * the user's ERC20 tokens. This is required before swapping ERC20 tokens for
289
- * most DEXes (except those supporting permit signatures like TomoDEX).
290
- *
291
- * The method checks if an approval transaction is needed based on the quote result.
292
- * If needed, it returns a transaction object that can be sent to the network.
293
- *
294
- * @param quote - The quote result from getSwapQuotes or getBridgeQuotes containing route information
295
- * @param quoteParams - The original quote parameters including sender, recipient, tokens and amount
296
- * @returns Promise<Transaction | undefined> - The approval transaction if needed, otherwise undefined
297
- *
298
- * @example
299
- * ```typescript
300
- * const quotes = await business.getSwapQuotes(quoteParams);
301
- * const approveTx = await business.getApproveBuilder(quotes[0], quoteParams);
302
- * if (approveTx) {
303
- * // Send approval transaction
304
- * await sendTransaction(approveTx);
305
- * }
306
- * ```
307
- */
308
- getApproveBuilder = (
309
- quote: TransactionQuoteResult,
310
- quoteParams: TransactionQuoteParams,
311
- ): ReturnType<ReturnType<typeof getApproveBuilder>> => {
312
- return this.getGetApproveBuilderMethod()(quote, quoteParams);
313
- };
314
-
315
- /**
316
- * EVM-specific permit signing utilities
317
- *
318
- * This namespace provides methods for handling ERC20 token approvals using
319
- * EIP-712 permit signatures, which allows gasless approvals for compatible tokens.
320
- */
321
- evm = {
322
- /**
323
- * Generate EIP-712 typed data for ERC20 token permit signatures
324
- *
325
- * This method creates the structured data required for signing ERC20 permit
326
- * transactions using EIP-712. The resulting data can be used with wallet
327
- * signature methods to generate permit signatures without submitting a
328
- * separate on-chain transaction.
329
- *
330
- * @param quoteParams - The original quote parameters including sender, recipient, tokens and amount
331
- * @param quote - The quote result from getSwapQuotes or getBridgeQuotes
332
- * @returns Promise<any> - EIP-712 typed data structure for signing
333
- *
334
- * @example
335
- * ```typescript
336
- * const permitTypeData = await business.evm.getPermitTypeData(quoteParams, quote);
337
- * const signature = await signTypedData(permitTypeData);
338
- * const unsignTx = await business.swapBuilder(quote, quoteParams, { signature, permitTypeData });
339
- * ```
340
- */
341
- getPermitTypeData: getPermitTypeData,
342
- };
343
- tron = {
344
- /**
345
- * @example
346
- * ```typescript
347
- * const permitTypeData = await business.tron.getPermitTypeData(quoteParams, quote);
348
- * const signature = await signTypedData(permitTypeData);
349
- * const unsignTx = await business.swapBuilder(quote, quoteParams, { signature, permitTypeData });
350
- * ```
351
- */
352
- getPermitTypeData: getTronPermitSignData,
353
- rpc: TRON_RPC,
354
- };
355
- }
356
-
357
- export type {
358
- Chain,
359
- IPlatformType,
360
- PermitSignParams,
361
- Transaction,
362
- TransactionEVM,
363
- TransactionQuoteParams,
364
- TransactionQuoteResult,
365
- TransactionSOL,
366
- TransactionToken,
367
- TransactionTRON,
368
- };
@@ -1,46 +0,0 @@
1
- import { Hex } from "viem";
2
- import { SwapApiRouterTxResponseV2 } from "../api/types";
3
- import { IPlatformType } from "../types/chain";
4
- import { PermitSignParams, TransactionQuoteParams, TransactionQuoteResult } from "../types/swap";
5
- import { getApiEVMPermit } from "./methods/chains/evm";
6
- import { getApiTRONPermit } from "./methods/chains/tron";
7
- import { getSwapTransaction } from "./methods/unsign";
8
-
9
- export const bridgeBuilder = (
10
- builder: (
11
- params: TransactionQuoteResult,
12
- permitSignParams?: PermitSignParams | undefined | null,
13
- ) => Promise<SwapApiRouterTxResponseV2>,
14
- ) => {
15
- return async (
16
- params: TransactionQuoteResult,
17
- quoteParams: TransactionQuoteParams,
18
- permitParams:
19
- | {
20
- signature: Hex;
21
- permitTypeData: any;
22
- }
23
- | undefined
24
- | null = undefined,
25
- ) => {
26
- const { fromToken, toToken } = quoteParams;
27
- if (fromToken.chain.chainId !== toToken.chain.chainId) {
28
- throw new Error("Use getBridgeQuotes for cross-chain swaps");
29
- }
30
- const permitSignParams = (() => {
31
- if (permitParams) {
32
- switch (quoteParams.fromToken.chain.platformType) {
33
- case IPlatformType.EVM:
34
- return getApiEVMPermit(permitParams.signature, permitParams.permitTypeData);
35
- case IPlatformType.TRON:
36
- return getApiTRONPermit(permitParams.signature, permitParams.permitTypeData);
37
- }
38
- }
39
- })();
40
- const builderRes = await builder(params, permitSignParams);
41
-
42
- const transaction = getSwapTransaction(builderRes, quoteParams);
43
-
44
- return transaction;
45
- };
46
- };
@@ -1,25 +0,0 @@
1
- import { SwapApiRouterTxResponseV2 } from "../api/types";
2
- import { PermitSignParams, Transaction, TransactionQuoteParams, TransactionQuoteResult } from "../types/swap";
3
- import { getSwapTransaction } from "./methods/unsign";
4
-
5
- export const getApproveBuilder = (
6
- builder: (
7
- params: TransactionQuoteResult,
8
- permitSignParams?: PermitSignParams | undefined | null,
9
- ) => Promise<SwapApiRouterTxResponseV2>,
10
- ) => {
11
- return async (
12
- params: TransactionQuoteResult,
13
- quoteParams: TransactionQuoteParams,
14
- ): Promise<Transaction | undefined> => {
15
- const builderRes = await builder(params);
16
- if (builderRes.transactions[0].type === "approve") {
17
- try {
18
- return getSwapTransaction(builderRes, quoteParams);
19
- } catch {
20
- return undefined;
21
- }
22
- }
23
- return undefined;
24
- };
25
- };
@@ -1,12 +0,0 @@
1
- import { TransactionQuoteParams, TransactionQuoteResult } from "../types/swap";
2
-
3
- export const getBridgeQuotes = (quote: (params: TransactionQuoteParams) => Promise<TransactionQuoteResult[]>) => {
4
- return async (params: TransactionQuoteParams) => {
5
- const { fromToken, toToken } = params;
6
- if (fromToken.chain.chainId === toToken.chain.chainId) {
7
- throw new Error("Use getSwapQuotes for same-chain swaps");
8
- }
9
-
10
- return await quote(params);
11
- };
12
- };
@@ -1,11 +0,0 @@
1
- import { TransactionQuoteParams, TransactionQuoteResult } from "../types/swap";
2
-
3
- export const getSwapQuotes = (quote: (params: TransactionQuoteParams) => Promise<TransactionQuoteResult[]>) => {
4
- return async (params: TransactionQuoteParams): Promise<TransactionQuoteResult[]> => {
5
- const { fromToken, toToken } = params;
6
- if (fromToken.chain.chainId !== toToken.chain.chainId) {
7
- throw new Error("Use getBridgeQuotes for cross-chain swaps");
8
- }
9
- return await quote(params);
10
- };
11
- };
@@ -1,19 +0,0 @@
1
- // const unsignTx:Transaction = await TomoBusiness.bridgeBuilder(params:TransactionQuoteResult)
2
-
3
- import { ApiMethods } from "../../api/types";
4
- import { PermitSignParams, TransactionQuoteResult } from "../../types/swap";
5
-
6
- export const builder = (apiMethods: ApiMethods) => {
7
- return async (params: TransactionQuoteResult, permitSignParams: PermitSignParams | undefined | null = undefined) => {
8
- const { quoteID } = params;
9
-
10
- const result = await apiMethods.getSwapRoutesTxV2({
11
- quoteID: quoteID,
12
- extendedData: permitSignParams ? { permit2: permitSignParams } : undefined,
13
- // trade_id: trackInfo?.tradeId,
14
- // user_id: Number(userInfo?.externalId || -1),
15
- });
16
-
17
- return result;
18
- };
19
- };
@@ -1,13 +0,0 @@
1
- export const PERMIT2_TYPES = {
2
- PermitDetails: [
3
- { name: "token", type: "address" },
4
- { name: "amount", type: "uint160" },
5
- { name: "expiration", type: "uint48" },
6
- { name: "nonce", type: "uint48" },
7
- ],
8
- PermitSingle: [
9
- { name: "details", type: "PermitDetails" },
10
- { name: "spender", type: "address" },
11
- { name: "sigDeadline", type: "uint256" },
12
- ],
13
- };
@@ -1,124 +0,0 @@
1
- import { createPublicClient, encodeAbiParameters, Hex, http, numberToHex, toHex } from "viem";
2
- import { SwapApiRouterTxResponseV2, SwapRouterTxEVMResult } from "../../../api/types";
3
- import { Permit2Abi } from "../../../constant/abi";
4
- import { EVM_PERMIT2_ADDRESS } from "../../../constant/address";
5
- import { IPlatformType, ViemChain } from "../../../types/chain";
6
- import { TransactionEVM, TransactionQuoteParams, TransactionQuoteResult } from "../../../types/swap";
7
- import { getViemChainByChainInfo } from "../utils";
8
- import { PERMIT2_TYPES } from "./const";
9
-
10
- export const getPermitTypeData = async (quoteParams: TransactionQuoteParams, quoteResult: TransactionQuoteResult) => {
11
- // Get EVM configuration
12
- const { sender, fromToken, amount } = quoteParams;
13
- const chain = quoteParams.fromToken.chain;
14
- const token = fromToken.address;
15
- const contract = quoteResult.contract;
16
- const viemChain: ViemChain = getViemChainByChainInfo(chain);
17
- if (!viemChain) {
18
- throw new Error("Chain not found");
19
- }
20
-
21
- const publicClient = createPublicClient({
22
- chain: viemChain,
23
- transport: http(),
24
- });
25
-
26
- // Query Permit2 authorization information
27
- const permitAllowance = (await publicClient.readContract({
28
- abi: Permit2Abi,
29
- address: EVM_PERMIT2_ADDRESS as Hex,
30
- functionName: "allowance",
31
- args: [sender, token, contract],
32
- })) as [bigint, number, number];
33
-
34
- if (!permitAllowance) {
35
- throw new Error("Failed to fetch Permit2 allowance data");
36
- }
37
-
38
- // Calculate the signature expiration time
39
- const sigDeadline = Math.floor(Date.now() / 1000) + 6000; // Expire after 100 minutes
40
-
41
- // Construct EIP-712 domain information
42
- const domain = {
43
- name: "Permit2",
44
- chainId: viemChain.id,
45
- verifyingContract: EVM_PERMIT2_ADDRESS as Hex,
46
- };
47
-
48
- // Construct signature data
49
- const message = {
50
- details: {
51
- token: token,
52
- amount: amount,
53
- expiration: 0,
54
- nonce: Number(permitAllowance[2].toString()), // Use nonce to prevent replay attacks
55
- },
56
- spender: contract,
57
- sigDeadline,
58
- };
59
-
60
- return {
61
- types: PERMIT2_TYPES,
62
- message,
63
- primaryType: "PermitSingle",
64
- domain,
65
- };
66
- };
67
-
68
- export const getApiEVMPermit = (signature: Hex, permitTypeData: any) => {
69
- const permit2InputEncode = encodeAbiParameters(
70
- [
71
- {
72
- type: "tuple",
73
- components: [
74
- {
75
- name: "details",
76
- type: "tuple",
77
- components: [
78
- { name: "token", type: "address" },
79
- { name: "amount", type: "uint160" },
80
- { name: "expiration", type: "uint48" },
81
- { name: "nonce", type: "uint48" },
82
- ],
83
- },
84
- { name: "spender", type: "address" },
85
- { name: "sigDeadline", type: "uint256" },
86
- ],
87
- },
88
- { type: "bytes" },
89
- ],
90
- // @ts-ignore
91
- [permitTypeData.message, signature],
92
- );
93
-
94
- return {
95
- permitSingle: permitTypeData.message,
96
- signature: signature,
97
- permit2InputEncode,
98
- };
99
- };
100
-
101
- export const getEVMTransaction = (
102
- params: SwapApiRouterTxResponseV2,
103
- quoteParams: TransactionQuoteParams,
104
- ): TransactionEVM => {
105
- const chain = quoteParams.fromToken.chain;
106
- if (chain.platformType !== IPlatformType.EVM) throw new Error("Chain is not EVM");
107
- if (params.transactions.length <= 0) throw new Error("No transactions found");
108
- const { value, from, to, nonce, data, gasInfo, chainId } = params.transactions[0] as SwapRouterTxEVMResult;
109
-
110
- const transaction: TransactionEVM = {
111
- value: numberToHex(BigInt(value || "0")),
112
- from: from,
113
- to: to,
114
- nonce: numberToHex(nonce),
115
- data: data,
116
- gas: numberToHex(BigInt(gasInfo.gasLimit)),
117
- gasLimit: numberToHex(BigInt(gasInfo.gasLimit)),
118
- maxFeePerGas: numberToHex(BigInt(gasInfo.baseFee) + BigInt(gasInfo.priorityFee.medium)),
119
- maxPriorityFeePerGas: numberToHex(BigInt(gasInfo.priorityFee.medium)),
120
- chainId: toHex(chainId),
121
- gasPrice: undefined,
122
- };
123
- return transaction;
124
- };
@@ -1,19 +0,0 @@
1
- import { SwapApiRouterTxResponseV2, SwapRouterTxSOLResult } from "../../../api/types";
2
- import { IPlatformType } from "../../../types/chain";
3
- import { TransactionQuoteParams, TransactionSOL } from "../../../types/swap";
4
-
5
- export const getSolanaTransaction = (
6
- params: SwapApiRouterTxResponseV2,
7
- quoteParams: TransactionQuoteParams,
8
- ): TransactionSOL => {
9
- const chain = quoteParams.fromToken.chain;
10
- if (chain.platformType !== IPlatformType.SOLANA) throw new Error("Chain is not Solana");
11
- if (params.transactions.length <= 0) throw new Error("No transactions found");
12
- const { data, serializedData } = params.transactions[0] as SwapRouterTxSOLResult;
13
-
14
- const transaction: TransactionSOL = {
15
- data: Buffer.from(serializedData || data, "base64").toString("hex"),
16
- };
17
-
18
- return transaction;
19
- };