@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.
- package/package.json +9 -4
- package/project.json +0 -52
- package/src/__tests__/business.test.ts +0 -315
- package/src/api/index.ts +0 -115
- package/src/api/types.ts +0 -196
- package/src/chains/const.ts +0 -776
- package/src/chains/getBridgeSupportChains.ts +0 -5
- package/src/chains/getChains.ts +0 -6
- package/src/chains/getSwapSupportChains.ts +0 -5
- package/src/constant/abi.ts +0 -191
- package/src/constant/abis/permit2.json +0 -901
- package/src/constant/address.ts +0 -3
- package/src/constant/index.ts +0 -3
- package/src/constant/stage.json +0 -10
- package/src/index.ts +0 -368
- package/src/swap/bridgeBuilder.ts +0 -46
- package/src/swap/getApproveBuilder.ts +0 -25
- package/src/swap/getBridgeQuotes.ts +0 -12
- package/src/swap/getSwapQuotes.ts +0 -11
- package/src/swap/methods/builder.ts +0 -19
- package/src/swap/methods/chains/const.ts +0 -13
- package/src/swap/methods/chains/evm.ts +0 -124
- package/src/swap/methods/chains/sol.ts +0 -19
- package/src/swap/methods/chains/tron.ts +0 -123
- package/src/swap/methods/permit.ts +0 -1
- package/src/swap/methods/quote.ts +0 -60
- package/src/swap/methods/unsign.ts +0 -26
- package/src/swap/methods/utils.ts +0 -70
- package/src/swap/permitSign.ts +0 -0
- package/src/swap/swapBuilder.ts +0 -46
- package/src/types/chain.ts +0 -86
- package/src/types/index.ts +0 -15
- package/src/types/swap.ts +0 -140
- package/tsconfig.json +0 -25
- package/tsup.config.ts +0 -15
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { TronWeb } from "tronweb";
|
|
2
|
-
import { Hex, encodeAbiParameters } from "viem";
|
|
3
|
-
import { SwapApiRouterTxResponseV2, SwapRouterTxTronResult } from "../../../api/types";
|
|
4
|
-
import { Permit2Abi } from "../../../constant/abi";
|
|
5
|
-
import { TRON_PERMIT2_ADDRESS } from "../../../constant/address";
|
|
6
|
-
import { IPlatformType } from "../../../types/chain";
|
|
7
|
-
import { TransactionQuoteParams, TransactionQuoteResult, TransactionTRON } from "../../../types/swap";
|
|
8
|
-
import { PERMIT2_TYPES } from "./const";
|
|
9
|
-
// getPermitTronSignData
|
|
10
|
-
export const TRON_NATIVE_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
11
|
-
export const TRON_RPC =
|
|
12
|
-
"https://orbital-dimensional-season.tron-mainnet.quiknode.pro/d14878573fe23f8f40621a303ee2eaa3c812ba1c";
|
|
13
|
-
export function getEip712Domain(verifyingContract: string) {
|
|
14
|
-
return {
|
|
15
|
-
name: "Permit2",
|
|
16
|
-
chainId: 728126428,
|
|
17
|
-
verifyingContract,
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const getTronPermitSignData = async (
|
|
22
|
-
quoteParams: TransactionQuoteParams,
|
|
23
|
-
quoteResult: TransactionQuoteResult,
|
|
24
|
-
) => {
|
|
25
|
-
const tronWeb = new TronWeb({
|
|
26
|
-
fullHost: TRON_RPC,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const tronAddressToHex = async (tronAddress: string) => {
|
|
30
|
-
// const tronWeb = await getTronWebProvider();
|
|
31
|
-
try {
|
|
32
|
-
const hexAddress = tronWeb.address.toHex(tronAddress);
|
|
33
|
-
return "0x" + hexAddress.slice(2);
|
|
34
|
-
} catch (error) {
|
|
35
|
-
console.error("Error converting TRON address:", error);
|
|
36
|
-
return null;
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const { sender, fromToken, amount } = quoteParams;
|
|
41
|
-
// const chain = quoteParams.fromToken.chain;
|
|
42
|
-
const token = fromToken.address;
|
|
43
|
-
const contract = quoteResult.contract;
|
|
44
|
-
|
|
45
|
-
tronWeb.setAddress(sender);
|
|
46
|
-
|
|
47
|
-
const sigDeadline = Math.floor(Date.now() / 1000) + 6000; // Expire after 100 minutes
|
|
48
|
-
const permit2 = await tronWeb.contract(Permit2Abi, TRON_PERMIT2_ADDRESS);
|
|
49
|
-
const tokenAddress = (await tronAddressToHex(token)) as Hex;
|
|
50
|
-
const spender = (await tronAddressToHex(contract)) as Hex;
|
|
51
|
-
const nextNonce = (await permit2.allowance(sender, tokenAddress, spender).call()).nonce as bigint;
|
|
52
|
-
|
|
53
|
-
const permitSingle = {
|
|
54
|
-
details: {
|
|
55
|
-
token: tokenAddress,
|
|
56
|
-
amount: amount,
|
|
57
|
-
expiration: 0, // expire time for allowance, 0 means block.timestamp
|
|
58
|
-
nonce: nextNonce, // default is 0, will be changed later
|
|
59
|
-
},
|
|
60
|
-
spender: spender, // entrypoint address
|
|
61
|
-
sigDeadline: sigDeadline,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
if (permit2.address) {
|
|
65
|
-
const domain = getEip712Domain(permit2.address);
|
|
66
|
-
|
|
67
|
-
const signatureHash = await tronWeb.utils._TypedDataEncoder.hash(domain, PERMIT2_TYPES, permitSingle);
|
|
68
|
-
|
|
69
|
-
// signature,
|
|
70
|
-
// domain: eip712Domain,
|
|
71
|
-
// types: PERMIT2_PERMIT_TYPE,
|
|
72
|
-
// permit,
|
|
73
|
-
|
|
74
|
-
// { permitSingle, signatureHash: signature, domain: domain, types: types };
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
types: PERMIT2_TYPES,
|
|
78
|
-
message: permitSingle,
|
|
79
|
-
primaryType: "PermitSingle",
|
|
80
|
-
domain,
|
|
81
|
-
signatureHash,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
throw new Error("Permit2 contract not found");
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
export const getTronTransaction = (
|
|
89
|
-
params: SwapApiRouterTxResponseV2,
|
|
90
|
-
quoteParams: TransactionQuoteParams,
|
|
91
|
-
): TransactionTRON => {
|
|
92
|
-
const chain = quoteParams.fromToken.chain;
|
|
93
|
-
if (chain.platformType !== IPlatformType.TRON) throw new Error("Chain is not Tron");
|
|
94
|
-
if (params.transactions.length <= 0) throw new Error("No transactions found");
|
|
95
|
-
const { data, value, from, to, rawData } = params.transactions[0] as SwapRouterTxTronResult;
|
|
96
|
-
|
|
97
|
-
const transaction: TransactionTRON = {
|
|
98
|
-
data: data,
|
|
99
|
-
value: value,
|
|
100
|
-
from: from,
|
|
101
|
-
to: to,
|
|
102
|
-
rawData: rawData,
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
return transaction;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export const getApiTRONPermit = (signature: Hex, permitTypeData: any) => {
|
|
109
|
-
const permit2InputEncode = encodeAbiParameters(
|
|
110
|
-
[
|
|
111
|
-
"((address token,uint160 amount,uint48 expiration,uint48 nonce) details, address spender, uint256 sigDeadline)",
|
|
112
|
-
"bytes",
|
|
113
|
-
],
|
|
114
|
-
// @ts-ignore
|
|
115
|
-
[permitTypeData.message, signature],
|
|
116
|
-
);
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
permitSingle: permitTypeData.message,
|
|
120
|
-
signature: signature,
|
|
121
|
-
permit2InputEncode,
|
|
122
|
-
};
|
|
123
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
// getEVMPermitTypeData
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { ApiMethods, SwapV2DexName } from "../../api/types";
|
|
2
|
-
import { TransactionQuoteParams, TransactionQuoteResult } from "../../types/swap";
|
|
3
|
-
import { getOkTokenAddress } from "./utils";
|
|
4
|
-
|
|
5
|
-
export const quote = (apiMethods: ApiMethods) => {
|
|
6
|
-
return async (params: TransactionQuoteParams): Promise<TransactionQuoteResult[]> => {
|
|
7
|
-
const { sender, recipient, fromToken, toToken, slippage, amount } = params;
|
|
8
|
-
const dexs = (() => {
|
|
9
|
-
if (fromToken.chain.chainId !== toToken.chain.chainId) {
|
|
10
|
-
return [SwapV2DexName.RANGO_BASIC, SwapV2DexName.ARRAKIS_BRIDGE];
|
|
11
|
-
}
|
|
12
|
-
return [SwapV2DexName.TOMO, SwapV2DexName.RANGO_BASIC];
|
|
13
|
-
})();
|
|
14
|
-
|
|
15
|
-
const fromTokenInfos = await apiMethods.getTokenInfo({
|
|
16
|
-
content: fromToken.address,
|
|
17
|
-
chainIndex: fromToken.chain.chainIndex,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const toTokenInfos = await apiMethods.getTokenInfo({
|
|
21
|
-
content: toToken.address,
|
|
22
|
-
chainIndex: toToken.chain.chainIndex,
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
if (fromTokenInfos.data.length <= 0 && toTokenInfos.data.length <= 0) {
|
|
26
|
-
throw new Error("Token not found");
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const fromTokenInfo = fromTokenInfos.data[0];
|
|
30
|
-
const toTokenInfo = toTokenInfos.data[0];
|
|
31
|
-
|
|
32
|
-
const routesResponse = await apiMethods.getSwapRoutesV2({
|
|
33
|
-
amount: amount,
|
|
34
|
-
dexs,
|
|
35
|
-
dexsExclude: false,
|
|
36
|
-
sender: sender,
|
|
37
|
-
recipient: recipient,
|
|
38
|
-
fromToken: {
|
|
39
|
-
address: getOkTokenAddress(fromTokenInfo, fromToken.chain),
|
|
40
|
-
chainID: fromToken.chain.chainId.toString(),
|
|
41
|
-
decimals: fromTokenInfo.decimals,
|
|
42
|
-
symbol: fromTokenInfo.symbol,
|
|
43
|
-
},
|
|
44
|
-
slippage: (slippage || 5) / 100,
|
|
45
|
-
toToken: {
|
|
46
|
-
address: getOkTokenAddress(toTokenInfo, toToken.chain),
|
|
47
|
-
chainID: toToken.chain.chainId.toString(),
|
|
48
|
-
decimals: toTokenInfo.decimals,
|
|
49
|
-
symbol: toTokenInfo.symbol,
|
|
50
|
-
},
|
|
51
|
-
// trade_id: trackInfo?.tradeId,
|
|
52
|
-
// quote_track_id: trackInfo?.quoteTrackId,
|
|
53
|
-
// user_id: Number(userInfo?.externalId || -1),
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
if (routesResponse.length < 1) throw new Error("No route found");
|
|
57
|
-
|
|
58
|
-
return routesResponse;
|
|
59
|
-
};
|
|
60
|
-
};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { SwapApiRouterTxResponseV2 } from "../../api/types";
|
|
2
|
-
import { IPlatformType } from "../../types/chain";
|
|
3
|
-
import { Transaction, TransactionQuoteParams } from "../../types/swap";
|
|
4
|
-
import { getEVMTransaction } from "./chains/evm";
|
|
5
|
-
import { getSolanaTransaction } from "./chains/sol";
|
|
6
|
-
import { getTronTransaction } from "./chains/tron";
|
|
7
|
-
|
|
8
|
-
export const getSwapTransaction = (
|
|
9
|
-
params: SwapApiRouterTxResponseV2,
|
|
10
|
-
quoteParams: TransactionQuoteParams,
|
|
11
|
-
): Transaction => {
|
|
12
|
-
const chain = quoteParams.fromToken.chain;
|
|
13
|
-
const transaction = (() => {
|
|
14
|
-
switch (chain.platformType) {
|
|
15
|
-
case IPlatformType.EVM:
|
|
16
|
-
return getEVMTransaction(params, quoteParams);
|
|
17
|
-
case IPlatformType.SOLANA:
|
|
18
|
-
return getSolanaTransaction(params, quoteParams);
|
|
19
|
-
case IPlatformType.TRON:
|
|
20
|
-
return getTronTransaction(params, quoteParams);
|
|
21
|
-
}
|
|
22
|
-
})() as Transaction | undefined;
|
|
23
|
-
|
|
24
|
-
if (!transaction) throw new Error("Transaction not found");
|
|
25
|
-
return transaction;
|
|
26
|
-
};
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { defineChain } from "viem";
|
|
2
|
-
import { IRawApiToken } from "../../api/types";
|
|
3
|
-
import { Chain, IPlatformType } from "../../types/chain";
|
|
4
|
-
|
|
5
|
-
const OkxEvmNativeAddress = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
6
|
-
const OkxBTCNativeAddress = "TEkxiTehnzSmSe2XqrBj4w32RUN966rdz8";
|
|
7
|
-
const OkxTonNativeAddress = "EQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAM9c";
|
|
8
|
-
const SolanaNativeAddress = "11111111111111111111111111111111";
|
|
9
|
-
const SUI_TYPE_ARG = "0x2::sui::SUI";
|
|
10
|
-
const SuiNativeAddress = SUI_TYPE_ARG;
|
|
11
|
-
const TronNativeAddress = "T9yD14Nj9j7xAB4dbGeiX9h8unkKHxuWwb";
|
|
12
|
-
|
|
13
|
-
export const getChainByChainIndex = ({ chains, chainIndex }: { chains: Chain[]; chainIndex?: number }) => {
|
|
14
|
-
if (chainIndex === undefined) return;
|
|
15
|
-
if (typeof chainIndex === "string" && !chainIndex) return;
|
|
16
|
-
const chain = chains.find((c) => c.chainIndex === Number(chainIndex));
|
|
17
|
-
return chain;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const getOkTokenAddress = (token: IRawApiToken, chain: Chain) => {
|
|
21
|
-
if (token.address) {
|
|
22
|
-
return token.address;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (chain?.platformType === IPlatformType.TON) {
|
|
26
|
-
return OkxTonNativeAddress;
|
|
27
|
-
}
|
|
28
|
-
if (chain?.platformType === IPlatformType.EVM) {
|
|
29
|
-
return OkxEvmNativeAddress;
|
|
30
|
-
}
|
|
31
|
-
if (chain?.platformType === IPlatformType.BTC) {
|
|
32
|
-
return OkxBTCNativeAddress;
|
|
33
|
-
}
|
|
34
|
-
if (chain?.platformType === IPlatformType.SOLANA) {
|
|
35
|
-
return SolanaNativeAddress;
|
|
36
|
-
}
|
|
37
|
-
if (chain?.platformType === IPlatformType.SUI) {
|
|
38
|
-
return SuiNativeAddress;
|
|
39
|
-
}
|
|
40
|
-
if (chain?.platformType === IPlatformType.TRON) {
|
|
41
|
-
return TronNativeAddress;
|
|
42
|
-
}
|
|
43
|
-
return "";
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
export const getViemChainByChainInfo = (chain: Chain) => {
|
|
47
|
-
const viemChain = /*#__PURE__*/ defineChain({
|
|
48
|
-
chain: chain,
|
|
49
|
-
id: chain.chainId,
|
|
50
|
-
name: chain.chainName,
|
|
51
|
-
nativeCurrency: {
|
|
52
|
-
name: chain.nativeCurrencyName,
|
|
53
|
-
symbol: chain.nativeCurrencySymbol,
|
|
54
|
-
decimals: chain.nativeCurrencyDecimals,
|
|
55
|
-
},
|
|
56
|
-
rpcUrls: {
|
|
57
|
-
default: {
|
|
58
|
-
http: (chain.rpcUrls || []) as string[],
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
blockExplorers: {
|
|
62
|
-
default: {
|
|
63
|
-
name: chain.chainName + "Scan",
|
|
64
|
-
url: chain.blockExplorerUrl || "",
|
|
65
|
-
apiUrl: chain.blockExplorerUrl + "/api",
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
});
|
|
69
|
-
return viemChain;
|
|
70
|
-
};
|
package/src/swap/permitSign.ts
DELETED
|
File without changes
|
package/src/swap/swapBuilder.ts
DELETED
|
@@ -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 swapBuilder = (
|
|
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
|
-
};
|
package/src/types/chain.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Platform types supported by the wallet
|
|
3
|
-
*
|
|
4
|
-
* Represents different blockchain platforms and their specific characteristics
|
|
5
|
-
*/
|
|
6
|
-
export enum IPlatformType {
|
|
7
|
-
/** Ethereum Virtual Machine compatible chains */
|
|
8
|
-
EVM = "EVM",
|
|
9
|
-
/** TON (The Open Network) blockchain */
|
|
10
|
-
TON = "TON",
|
|
11
|
-
/** TRON blockchain */
|
|
12
|
-
TRON = "TRON",
|
|
13
|
-
/** Bitcoin blockchain */
|
|
14
|
-
BTC = "BTC",
|
|
15
|
-
/** Dogecoin blockchain */
|
|
16
|
-
DOGE = "DOGE",
|
|
17
|
-
/** Sui blockchain */
|
|
18
|
-
SUI = "SUI",
|
|
19
|
-
/** Cosmos ecosystem blockchains */
|
|
20
|
-
COSMOS = "COSMOS",
|
|
21
|
-
/** Aptos blockchain */
|
|
22
|
-
APTOS = "APTOS",
|
|
23
|
-
/** Solana blockchain */
|
|
24
|
-
SOLANA = "SOLANA",
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Chain information structure
|
|
29
|
-
*
|
|
30
|
-
* Represents detailed information about a blockchain network including
|
|
31
|
-
* its properties, capabilities, and configuration details
|
|
32
|
-
*/
|
|
33
|
-
export type Chain = {
|
|
34
|
-
/** Full name of the blockchain network */
|
|
35
|
-
chainName: string;
|
|
36
|
-
|
|
37
|
-
/** Numeric chain identifier (e.g., 1 for Ethereum mainnet) */
|
|
38
|
-
chainId: number;
|
|
39
|
-
|
|
40
|
-
/** Internal index for ordering chains in UI */
|
|
41
|
-
chainIndex: number;
|
|
42
|
-
|
|
43
|
-
/** Whether order status tracking is supported on this chain */
|
|
44
|
-
orderStatusSupport: boolean;
|
|
45
|
-
|
|
46
|
-
/** Whether the chain is currently supported for operations */
|
|
47
|
-
support: boolean;
|
|
48
|
-
|
|
49
|
-
/** Chain type identifier */
|
|
50
|
-
type: number;
|
|
51
|
-
|
|
52
|
-
/** Short name or display name of the chain */
|
|
53
|
-
name: string;
|
|
54
|
-
|
|
55
|
-
/** Full name of the native currency (e.g., "Ethereum") */
|
|
56
|
-
nativeCurrencyName: string;
|
|
57
|
-
|
|
58
|
-
/** Symbol of the native currency (e.g., "ETH") */
|
|
59
|
-
nativeCurrencySymbol: string;
|
|
60
|
-
|
|
61
|
-
/** Decimal places for the native currency (e.g., 18 for ETH) */
|
|
62
|
-
nativeCurrencyDecimals: number;
|
|
63
|
-
|
|
64
|
-
/** Platform type this chain belongs to */
|
|
65
|
-
platformType: IPlatformType;
|
|
66
|
-
|
|
67
|
-
/** URL to the chain's icon/logo */
|
|
68
|
-
icon: string;
|
|
69
|
-
|
|
70
|
-
/** Whether swap operations are supported on this chain */
|
|
71
|
-
supportSwap: boolean;
|
|
72
|
-
|
|
73
|
-
/** Whether the chain is listed/publicly visible */
|
|
74
|
-
isListed: boolean;
|
|
75
|
-
|
|
76
|
-
/** Whether this is a testnet (optional) */
|
|
77
|
-
isTestnet?: boolean;
|
|
78
|
-
|
|
79
|
-
/** Array of RPC URLs for connecting to the chain (optional) */
|
|
80
|
-
rpcUrls?: string[];
|
|
81
|
-
|
|
82
|
-
/** URL to the chain's block explorer (optional) */
|
|
83
|
-
blockExplorerUrl?: string;
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
export type { Chain as ViemChain } from "viem";
|
package/src/types/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { AxiosInstance } from "axios";
|
|
2
|
-
|
|
3
|
-
export type Config = {
|
|
4
|
-
API_KEY: string;
|
|
5
|
-
API_SECRET: string;
|
|
6
|
-
SALT: string;
|
|
7
|
-
CLIENT_ID: string;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export type TomoStage = "dev" | "prod";
|
|
11
|
-
|
|
12
|
-
export type ApiConfig = {
|
|
13
|
-
routeApi: AxiosInstance | null;
|
|
14
|
-
marketApi: AxiosInstance | null;
|
|
15
|
-
};
|
package/src/types/swap.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { Hex } from "viem";
|
|
2
|
-
import { Chain } from "./chain";
|
|
3
|
-
|
|
4
|
-
export type TransactionToken = {
|
|
5
|
-
address: string; //nativeCurrency address: ''
|
|
6
|
-
chain: Chain; // mainnet
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export type TransactionQuoteParams = {
|
|
10
|
-
sender: string | Hex; // sender address
|
|
11
|
-
recipient: string | Hex; // recipient address
|
|
12
|
-
fromToken: TransactionToken;
|
|
13
|
-
toToken: TransactionToken;
|
|
14
|
-
slippage: number; // 0 - 100
|
|
15
|
-
amount: string; //fromTokenValue 100000000000000000.
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export type SwapTransactionQuoteParams = TransactionQuoteParams;
|
|
19
|
-
export type BridgeTransactionQuoteParams = TransactionQuoteParams;
|
|
20
|
-
|
|
21
|
-
export type TransactionQuoteResult = {
|
|
22
|
-
quoteID: string;
|
|
23
|
-
amountIn: string;
|
|
24
|
-
amountOut: string;
|
|
25
|
-
contract: string;
|
|
26
|
-
amountOutMin: string;
|
|
27
|
-
gasNetWorkFee: string;
|
|
28
|
-
approveGasFee: string;
|
|
29
|
-
crossNetworkFee: {
|
|
30
|
-
fromChainNetworkFee: string;
|
|
31
|
-
toChainNetworkFee: string;
|
|
32
|
-
providerServiceFee: string;
|
|
33
|
-
};
|
|
34
|
-
dexInfo: {
|
|
35
|
-
name: string;
|
|
36
|
-
displayName: string;
|
|
37
|
-
logo: string;
|
|
38
|
-
};
|
|
39
|
-
fromToken: {
|
|
40
|
-
chainID: string;
|
|
41
|
-
address: string;
|
|
42
|
-
symbol: string;
|
|
43
|
-
decimals: number;
|
|
44
|
-
};
|
|
45
|
-
toToken: {
|
|
46
|
-
chainID: string;
|
|
47
|
-
address: string;
|
|
48
|
-
symbol: string;
|
|
49
|
-
decimals: number;
|
|
50
|
-
};
|
|
51
|
-
extended: {
|
|
52
|
-
requestID: string;
|
|
53
|
-
};
|
|
54
|
-
routes: [
|
|
55
|
-
{
|
|
56
|
-
amountIn: string;
|
|
57
|
-
amountOut: string;
|
|
58
|
-
paths: [
|
|
59
|
-
{
|
|
60
|
-
dexProvider: string;
|
|
61
|
-
fromToken: {
|
|
62
|
-
chainID: string;
|
|
63
|
-
address: string;
|
|
64
|
-
symbol: string;
|
|
65
|
-
decimals: number;
|
|
66
|
-
};
|
|
67
|
-
toToken: {
|
|
68
|
-
chainID: string;
|
|
69
|
-
address: string;
|
|
70
|
-
symbol: string;
|
|
71
|
-
decimals: number;
|
|
72
|
-
};
|
|
73
|
-
amountIn: string;
|
|
74
|
-
amountOut: string;
|
|
75
|
-
},
|
|
76
|
-
];
|
|
77
|
-
},
|
|
78
|
-
];
|
|
79
|
-
estimatedGas: {
|
|
80
|
-
feeUSD: string;
|
|
81
|
-
gasLimit: string;
|
|
82
|
-
baseFee: string;
|
|
83
|
-
priorityFee: {
|
|
84
|
-
low: string;
|
|
85
|
-
medium: string;
|
|
86
|
-
high: string;
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
export type SwapTransactionQuoteResult = TransactionQuoteResult;
|
|
92
|
-
export type BridgeTransactionQuoteResult = TransactionQuoteResult;
|
|
93
|
-
|
|
94
|
-
export type TransactionEVM = {
|
|
95
|
-
chainId: string; //0x38
|
|
96
|
-
data: string; //0x...
|
|
97
|
-
gasLimit: string; //0x3de3d
|
|
98
|
-
gas?: string; //0x3de3d
|
|
99
|
-
gasPrice: string | undefined; //undefined
|
|
100
|
-
maxFeePerGas: string | bigint | undefined; //0x68e7780
|
|
101
|
-
maxPriorityFeePerGas: string | bigint | undefined; //0x68e7780
|
|
102
|
-
nonce: string; //0x3fa
|
|
103
|
-
to: string; //0x...
|
|
104
|
-
from: string; //0x...
|
|
105
|
-
value: string; //0x5af3107a4000
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export type TransactionSOL = {
|
|
109
|
-
data: string;
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
export type TransactionTRON = {
|
|
113
|
-
data: string;
|
|
114
|
-
value: string; //0x5af3107a4000
|
|
115
|
-
from: string;
|
|
116
|
-
to: string;
|
|
117
|
-
rawData: {
|
|
118
|
-
visible: boolean;
|
|
119
|
-
txID: string;
|
|
120
|
-
raw_data: any;
|
|
121
|
-
raw_data_hex: string;
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export type Transaction = TransactionEVM | TransactionSOL | TransactionTRON;
|
|
126
|
-
|
|
127
|
-
export type PermitSignParams = {
|
|
128
|
-
permit2InputEncode: string;
|
|
129
|
-
permitSingle: {
|
|
130
|
-
details: {
|
|
131
|
-
amount: string;
|
|
132
|
-
expiration: number;
|
|
133
|
-
nonce: number;
|
|
134
|
-
token: string;
|
|
135
|
-
};
|
|
136
|
-
sigDeadline: number;
|
|
137
|
-
spender: string;
|
|
138
|
-
};
|
|
139
|
-
signature: string;
|
|
140
|
-
};
|
package/tsconfig.json
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "../../tsconfig.base.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"outDir": "../../dist/packages/transaction-builder-sdk",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"declarationMap": true,
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"moduleResolution": "node",
|
|
10
|
-
"types": [],
|
|
11
|
-
"allowSyntheticDefaultImports": true,
|
|
12
|
-
"esModuleInterop": true,
|
|
13
|
-
"module": "ESNext",
|
|
14
|
-
"target": "ES2022",
|
|
15
|
-
"lib": ["ES2022", "DOM"],
|
|
16
|
-
"strict": true,
|
|
17
|
-
"resolveJsonModule": true,
|
|
18
|
-
"baseUrl": ".",
|
|
19
|
-
"paths": {
|
|
20
|
-
"@/*": ["src/*"]
|
|
21
|
-
}
|
|
22
|
-
},
|
|
23
|
-
"include": ["src/**/*"],
|
|
24
|
-
"exclude": ["node_modules", "dist", "__tests__"]
|
|
25
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from "tsup";
|
|
2
|
-
|
|
3
|
-
export default defineConfig({
|
|
4
|
-
entry: ["src/index.ts"],
|
|
5
|
-
format: ["esm", "cjs"],
|
|
6
|
-
dts: true,
|
|
7
|
-
treeshake: true,
|
|
8
|
-
clean: true,
|
|
9
|
-
target: "es2022",
|
|
10
|
-
outExtension({ format }) {
|
|
11
|
-
return {
|
|
12
|
-
js: format === "esm" ? ".mjs" : ".js",
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
});
|