@tcswap/core 4.1.16
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/index.cjs +4 -0
- package/dist/index.cjs.map +10 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +10 -0
- package/dist/types/index.d.ts +2005 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +36 -0
- package/src/index.ts +409 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAGL,UAAU,EACV,KAAK,EACL,KAAK,WAAW,EAChB,KAAK,2BAA2B,EAEhC,KAAK,QAAQ,EAEb,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,YAAY,IAAI,cAAc,EAC9B,KAAK,UAAU,EAEf,KAAK,gBAAgB,EAGrB,KAAK,YAAY,EAClB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC3F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI;IAAE,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC,CAAA;CAAE,CAAC;AAExF,wBAAgB,KAAK,CACnB,OAAO,SAAS,UAAU,CAAC,OAAO,YAAY,CAAC,EAC/C,OAAO,SAAS,UAAU,CAAC,OAAO,YAAY,CAAC,EAC/C,EACA,MAA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
@@ -0,0 +1,36 @@
|
|
|
1
|
+
{
|
|
2
|
+
"author": "swapkit-oss",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@tcswap/helpers": "4.5.15",
|
|
5
|
+
"@tcswap/plugins": "4.2.15",
|
|
6
|
+
"@tcswap/toolboxes": "4.3.15",
|
|
7
|
+
"@tcswap/wallets": "4.3.16",
|
|
8
|
+
"ts-pattern": "^5.9.0"
|
|
9
|
+
},
|
|
10
|
+
"description": "USwap - Core",
|
|
11
|
+
"devDependencies": { "ts-pattern": "5.9.0" },
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"bun": "./src/index.ts",
|
|
15
|
+
"import": "./dist/index.js",
|
|
16
|
+
"require": "./dist/index.cjs",
|
|
17
|
+
"types": "./dist/types/index.d.ts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": ["dist/", "src/"],
|
|
21
|
+
"homepage": "https://github.com/thorchain/TCSwap",
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"name": "@tcswap/core",
|
|
24
|
+
"repository": { "directory": "packages/core", "type": "git", "url": "git+https://github.com/thorchain/TCSwap.git" },
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "bun run ./build.ts",
|
|
27
|
+
"build:clean": "rm -rf dist && bun run ./build.ts",
|
|
28
|
+
"clean": "rm -rf dist node_modules *.tsbuildinfo",
|
|
29
|
+
"test": "echo 'bun test'",
|
|
30
|
+
"test:ci": "echo 'bun test --coverage'",
|
|
31
|
+
"type-check": "bun tsc --noEmit",
|
|
32
|
+
"type-check:go": "tsgo"
|
|
33
|
+
},
|
|
34
|
+
"type": "module",
|
|
35
|
+
"version": "4.1.16"
|
|
36
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Modifications © 2025 Horizontal Systems.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
ApproveMode,
|
|
7
|
+
type ApproveReturnType,
|
|
8
|
+
AssetValue,
|
|
9
|
+
Chain,
|
|
10
|
+
type ChainWallet,
|
|
11
|
+
type ConditionalAssetValueReturn,
|
|
12
|
+
CosmosChains,
|
|
13
|
+
type EVMChain,
|
|
14
|
+
EVMChains,
|
|
15
|
+
type FeeOption,
|
|
16
|
+
type GenericTransferParams,
|
|
17
|
+
ProviderName as PluginNameEnum,
|
|
18
|
+
type SwapParams,
|
|
19
|
+
USwapConfig,
|
|
20
|
+
type USwapConfigState,
|
|
21
|
+
USwapError,
|
|
22
|
+
UTXOChains,
|
|
23
|
+
type WalletOption,
|
|
24
|
+
} from "@tcswap/helpers";
|
|
25
|
+
import type { EVMTransaction, QuoteResponseRoute } from "@tcswap/helpers/api";
|
|
26
|
+
import type { createPlugin } from "@tcswap/plugins";
|
|
27
|
+
import type { FullWallet } from "@tcswap/toolboxes";
|
|
28
|
+
import type { EVMCreateTransactionParams, EVMTransferParams } from "@tcswap/toolboxes/evm";
|
|
29
|
+
import type { createWallet } from "@tcswap/wallets";
|
|
30
|
+
|
|
31
|
+
export type USwapParams<P, W> = { config?: USwapConfigState; plugins?: P; wallets?: W };
|
|
32
|
+
|
|
33
|
+
export function USwap<
|
|
34
|
+
Plugins extends ReturnType<typeof createPlugin>,
|
|
35
|
+
Wallets extends ReturnType<typeof createWallet>,
|
|
36
|
+
>({
|
|
37
|
+
config,
|
|
38
|
+
plugins,
|
|
39
|
+
wallets,
|
|
40
|
+
getActiveWallet,
|
|
41
|
+
}: {
|
|
42
|
+
config?: USwapConfigState;
|
|
43
|
+
plugins?: Plugins;
|
|
44
|
+
wallets?: Wallets;
|
|
45
|
+
getActiveWallet?: () => WalletOption | undefined;
|
|
46
|
+
} = {}) {
|
|
47
|
+
if (config) {
|
|
48
|
+
USwapConfig.set(config);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type PluginName = keyof Plugins;
|
|
52
|
+
const connectedWalletsByChain = {} as FullWallet;
|
|
53
|
+
const connectedWalletsByWallet = new Map<WalletOption, Map<Chain, FullWallet[Chain]>>();
|
|
54
|
+
type ConnectedChains = keyof typeof connectedWalletsByChain;
|
|
55
|
+
type ActionType = "transfer" | "approve" | "swap";
|
|
56
|
+
|
|
57
|
+
type ActionParams<P extends PluginName> = {
|
|
58
|
+
transfer: EVMTransferParams | (GenericTransferParams & { sender?: string });
|
|
59
|
+
approve: { assetValue: AssetValue; contractAddress: string; feeOptionKey?: FeeOption };
|
|
60
|
+
swap: SwapParams<P, QuoteResponseRoute> & { assetValue: AssetValue };
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const availablePlugins = Object.entries(plugins || {}).reduce(
|
|
64
|
+
(acc, [pluginName, plugin]) => {
|
|
65
|
+
const methods = plugin({ getWallet: getSelectedWallet });
|
|
66
|
+
|
|
67
|
+
acc[pluginName as PluginName] = methods as ReturnType<Plugins[keyof Plugins]>;
|
|
68
|
+
return acc;
|
|
69
|
+
},
|
|
70
|
+
{} as { [key in PluginName]: ReturnType<Plugins[key]> },
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const connectWalletMethods = Object.entries(wallets || {}).reduce(
|
|
74
|
+
(acc, [walletName, wallet]) => {
|
|
75
|
+
const connectWallet = wallet.connectWallet({ addChain });
|
|
76
|
+
|
|
77
|
+
acc[walletName as keyof Wallets] = connectWallet as ReturnType<Wallets[keyof Wallets]["connectWallet"]>;
|
|
78
|
+
return acc;
|
|
79
|
+
},
|
|
80
|
+
{} as {
|
|
81
|
+
[key in keyof Wallets]: ReturnType<Wallets[key]["connectWallet"]>;
|
|
82
|
+
},
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
function getUSwapPlugin<T extends PluginName>(pluginName?: T) {
|
|
86
|
+
const pluginByName = pluginName && availablePlugins[pluginName];
|
|
87
|
+
const pluginByProvider = Object.values(availablePlugins).find((plugin) =>
|
|
88
|
+
plugin.supportedUSwapProviders?.includes(pluginName),
|
|
89
|
+
);
|
|
90
|
+
const plugin = pluginByName || pluginByProvider;
|
|
91
|
+
|
|
92
|
+
if (!plugin) {
|
|
93
|
+
throw new USwapError("core_plugin_not_found");
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return plugin as ReturnType<Plugins[T]>;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function addChain<T extends Chain>(connectWallet: Omit<ChainWallet<T>, "balance"> & { balance?: AssetValue[] }) {
|
|
100
|
+
const currentWallet = getWalletByChain(connectWallet.chain);
|
|
101
|
+
|
|
102
|
+
const balance = connectWallet?.balance ||
|
|
103
|
+
currentWallet?.balance || [AssetValue.from({ chain: connectWallet.chain })];
|
|
104
|
+
|
|
105
|
+
const wallet = { ...currentWallet, ...connectWallet, balance };
|
|
106
|
+
connectedWalletsByChain[connectWallet.chain] = wallet as FullWallet[T];
|
|
107
|
+
|
|
108
|
+
const walletOption = connectWallet.walletType as WalletOption;
|
|
109
|
+
let chainMap = connectedWalletsByWallet.get(walletOption);
|
|
110
|
+
if (!chainMap) {
|
|
111
|
+
chainMap = new Map<Chain, any>();
|
|
112
|
+
connectedWalletsByWallet.set(walletOption, chainMap);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
chainMap.set(connectWallet.chain, wallet as FullWallet[T]);
|
|
116
|
+
|
|
117
|
+
return wallet;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function approve<T extends ApproveMode>({
|
|
121
|
+
assetValue,
|
|
122
|
+
type = "checkOnly" as T,
|
|
123
|
+
contractAddress: spenderAddress,
|
|
124
|
+
}: {
|
|
125
|
+
type: T;
|
|
126
|
+
assetValue: AssetValue;
|
|
127
|
+
contractAddress: string | PluginName;
|
|
128
|
+
}) {
|
|
129
|
+
const plugin = availablePlugins[spenderAddress];
|
|
130
|
+
|
|
131
|
+
if (plugin) {
|
|
132
|
+
if (type === ApproveMode.CheckOnly && "isAssetValueApproved" in plugin) {
|
|
133
|
+
// @ts-expect-error TODO: add optional approve for plugin
|
|
134
|
+
return plugin.isAssetValueApproved({ assetValue }) as ApproveReturnType<T>;
|
|
135
|
+
}
|
|
136
|
+
if (type === ApproveMode.Approve && "approveAssetValue" in plugin) {
|
|
137
|
+
// @ts-expect-error TODO: add optional approve for plugin
|
|
138
|
+
return plugin.approveAssetValue({ assetValue }) as ApproveReturnType<T>;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
throw new USwapError({
|
|
142
|
+
errorKey: "core_approve_asset_target_invalid",
|
|
143
|
+
info: { message: `Target ${String(spenderAddress)} cannot be used for approve operation` },
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const chain = assetValue.chain as EVMChain;
|
|
148
|
+
const isEVMChain = EVMChains.includes(chain);
|
|
149
|
+
const isNativeEVM = isEVMChain && assetValue.isGasAsset;
|
|
150
|
+
|
|
151
|
+
if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {
|
|
152
|
+
return Promise.resolve(type === "checkOnly" ? true : "approved") as ApproveReturnType<T>;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const wallet = getWalletByChain(chain);
|
|
156
|
+
const walletAction = type === "checkOnly" ? wallet.isApproved : wallet.approve;
|
|
157
|
+
if (!walletAction) throw new USwapError("core_wallet_connection_not_found");
|
|
158
|
+
|
|
159
|
+
if (!(assetValue.address && wallet.address && typeof spenderAddress === "string")) {
|
|
160
|
+
throw new USwapError("core_approve_asset_address_or_from_not_found");
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return walletAction({
|
|
164
|
+
amount: assetValue.getBaseValue("bigint"),
|
|
165
|
+
assetAddress: assetValue.address,
|
|
166
|
+
from: wallet.address,
|
|
167
|
+
spenderAddress,
|
|
168
|
+
}) as ApproveReturnType<T>;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* @Public
|
|
173
|
+
*/
|
|
174
|
+
function getWallet<T extends Chain>(walletOption: WalletOption, chain: T): FullWallet[T] {
|
|
175
|
+
return connectedWalletsByWallet.get(walletOption)?.get(chain) as FullWallet[T];
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function getWalletByChain<T extends ConnectedChains>(chain: T) {
|
|
179
|
+
return connectedWalletsByChain[chain];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function getSelectedWallet<T extends ConnectedChains>(chain: T): FullWallet[T] {
|
|
183
|
+
const selected = getActiveWallet?.();
|
|
184
|
+
if (!selected) {
|
|
185
|
+
throw new Error(`Unknown connected chain: ${chain}`);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return getWallet(selected, chain) as FullWallet[T];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function getAllWallets() {
|
|
192
|
+
return { ...connectedWalletsByChain };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function getAddress<T extends Chain>(chain: T) {
|
|
196
|
+
return getWalletByChain(chain)?.address || "";
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function approveAssetValue(assetValue: AssetValue, contractAddress: string | PluginName) {
|
|
200
|
+
return approve({ assetValue, contractAddress, type: ApproveMode.Approve });
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function isAssetValueApproved(assetValue: AssetValue, contractAddress: string | PluginName) {
|
|
204
|
+
return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function disconnectChain<T extends Chain>(chain: T) {
|
|
208
|
+
const wallet = getWalletByChain(chain);
|
|
209
|
+
if (wallet?.walletType) {
|
|
210
|
+
const chainMap = connectedWalletsByWallet.get(wallet.walletType as WalletOption);
|
|
211
|
+
if (chainMap) {
|
|
212
|
+
chainMap.delete(chain);
|
|
213
|
+
if (chainMap.size === 0) {
|
|
214
|
+
connectedWalletsByWallet.delete(wallet.walletType as WalletOption);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
wallet?.disconnect?.();
|
|
220
|
+
delete connectedWalletsByChain[chain];
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function disconnectAll() {
|
|
224
|
+
for (const chain of Object.keys(connectedWalletsByChain) as (keyof typeof connectedWalletsByChain)[]) {
|
|
225
|
+
disconnectChain(chain);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function getBalance<T extends Chain, R extends boolean>(chain: T, refresh?: R): ConditionalAssetValueReturn<R> {
|
|
230
|
+
return (
|
|
231
|
+
refresh ? getWalletWithBalance(chain).then(({ balance }) => balance) : getWalletByChain(chain)?.balance || []
|
|
232
|
+
) as ConditionalAssetValueReturn<R>;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
async function getWalletWithBalance<T extends Chain>(chain: T, scamFilter = true) {
|
|
236
|
+
const wallet = getWalletByChain(chain);
|
|
237
|
+
if (!wallet) {
|
|
238
|
+
throw new USwapError("core_wallet_connection_not_found");
|
|
239
|
+
}
|
|
240
|
+
const defaultBalance = [AssetValue.from({ chain })];
|
|
241
|
+
wallet.balance = defaultBalance;
|
|
242
|
+
|
|
243
|
+
if ("getBalance" in wallet) {
|
|
244
|
+
const balance = await wallet.getBalance(wallet.address, scamFilter);
|
|
245
|
+
wallet.balance = balance;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return wallet;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function swap<T extends PluginName>({ route, pluginName, ...rest }: SwapParams<T, QuoteResponseRoute>) {
|
|
252
|
+
const plugin = getUSwapPlugin(pluginName || route.providers[0]);
|
|
253
|
+
|
|
254
|
+
if ("swap" in plugin) {
|
|
255
|
+
// @ts-expect-error TODO: fix this
|
|
256
|
+
return plugin.swap({ ...rest, route });
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
throw new USwapError("core_plugin_swap_not_found");
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function transfer({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) {
|
|
263
|
+
const chain = assetValue.chain;
|
|
264
|
+
if ([Chain.Radix].includes(chain) || !getWalletByChain(chain)) {
|
|
265
|
+
throw new USwapError("core_wallet_connection_not_found");
|
|
266
|
+
}
|
|
267
|
+
const wallet = getWalletByChain(chain as Exclude<Chain, typeof Chain.Radix | typeof Chain.Near>);
|
|
268
|
+
|
|
269
|
+
// we need to simplify this to one object params
|
|
270
|
+
return wallet.transfer({ ...params, assetValue });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function signMessage({ chain, message }: { chain: Chain; message: string }) {
|
|
274
|
+
const wallet = getWalletByChain(chain);
|
|
275
|
+
if (!wallet) throw new USwapError("core_wallet_connection_not_found");
|
|
276
|
+
|
|
277
|
+
if ("signMessage" in wallet) {
|
|
278
|
+
return wallet.signMessage?.(message);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
throw new USwapError({
|
|
282
|
+
errorKey: "core_wallet_sign_message_not_supported",
|
|
283
|
+
info: { chain, wallet: wallet.walletType },
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
async function verifyMessage({
|
|
288
|
+
address,
|
|
289
|
+
chain,
|
|
290
|
+
message,
|
|
291
|
+
signature,
|
|
292
|
+
}: {
|
|
293
|
+
chain: Chain;
|
|
294
|
+
signature: string;
|
|
295
|
+
message: string;
|
|
296
|
+
address: string;
|
|
297
|
+
}) {
|
|
298
|
+
if (chain !== Chain.THORChain) {
|
|
299
|
+
throw new USwapError({ errorKey: "core_verify_message_not_supported", info: { chain } });
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const { getCosmosToolbox } = await import("@tcswap/toolboxes/cosmos");
|
|
303
|
+
const toolbox = await getCosmosToolbox(chain);
|
|
304
|
+
|
|
305
|
+
return toolbox.verifySignature({ address, message, signature });
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
async function estimateTransactionFee<P extends PluginName, T extends ActionType>({
|
|
309
|
+
type,
|
|
310
|
+
feeOptionKey,
|
|
311
|
+
params,
|
|
312
|
+
}: {
|
|
313
|
+
type: T;
|
|
314
|
+
params: ActionParams<P>[T];
|
|
315
|
+
feeOptionKey: FeeOption;
|
|
316
|
+
}): Promise<AssetValue | undefined> {
|
|
317
|
+
const { assetValue } = params;
|
|
318
|
+
const { chain } = assetValue;
|
|
319
|
+
|
|
320
|
+
if (!getWalletByChain(chain as Chain)) throw new USwapError("core_wallet_connection_not_found");
|
|
321
|
+
|
|
322
|
+
const baseValue = AssetValue.from({ chain });
|
|
323
|
+
const { match } = await import("ts-pattern");
|
|
324
|
+
|
|
325
|
+
return match(chain as Chain)
|
|
326
|
+
.returnType<Promise<AssetValue | undefined> | AssetValue | undefined>()
|
|
327
|
+
.with(...EVMChains, (chain) => {
|
|
328
|
+
const { address, ...wallet } = getWalletByChain(chain);
|
|
329
|
+
|
|
330
|
+
const tx = match(type as ActionType)
|
|
331
|
+
.with("transfer", () => wallet.createTransferTx(params as EVMCreateTransactionParams))
|
|
332
|
+
.with("approve", (_t) => {
|
|
333
|
+
const { contractAddress } = params as ActionParams<P>[typeof _t];
|
|
334
|
+
|
|
335
|
+
return wallet.createApprovalTx({
|
|
336
|
+
amount: assetValue.getBaseValue("bigint"),
|
|
337
|
+
assetAddress: assetValue.address as string,
|
|
338
|
+
from: address,
|
|
339
|
+
spenderAddress: contractAddress,
|
|
340
|
+
});
|
|
341
|
+
})
|
|
342
|
+
.with("swap", (_t) => {
|
|
343
|
+
const {
|
|
344
|
+
route: {
|
|
345
|
+
providers: [plugin],
|
|
346
|
+
tx,
|
|
347
|
+
},
|
|
348
|
+
} = params as ActionParams<P>[typeof _t];
|
|
349
|
+
|
|
350
|
+
if (plugin && [PluginNameEnum.CHAINFLIP, PluginNameEnum.CHAINFLIP_STREAMING].includes(plugin)) {
|
|
351
|
+
return wallet.createTransferTx({ assetValue, recipient: address, sender: address });
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const evmTx = tx as EVMTransaction;
|
|
355
|
+
|
|
356
|
+
return { ...evmTx, value: BigInt(evmTx.value) };
|
|
357
|
+
})
|
|
358
|
+
.otherwise(() => undefined);
|
|
359
|
+
|
|
360
|
+
if (!tx) return baseValue;
|
|
361
|
+
|
|
362
|
+
return wallet.estimateTransactionFee({ ...tx, chain, feeOption: feeOptionKey });
|
|
363
|
+
})
|
|
364
|
+
.with(...UTXOChains, (chain) => {
|
|
365
|
+
const { address, ...wallet } = getWalletByChain(chain);
|
|
366
|
+
return wallet.estimateTransactionFee({ ...params, feeOptionKey, recipient: address, sender: address });
|
|
367
|
+
})
|
|
368
|
+
.with(...CosmosChains, async () => {
|
|
369
|
+
const { estimateTransactionFee } = await import("@tcswap/toolboxes/cosmos");
|
|
370
|
+
return estimateTransactionFee(params);
|
|
371
|
+
})
|
|
372
|
+
.with(Chain.Polkadot, (chain) => {
|
|
373
|
+
const wallet = getWalletByChain(chain);
|
|
374
|
+
return wallet.estimateTransactionFee({ ...params, recipient: wallet.address });
|
|
375
|
+
})
|
|
376
|
+
.with(Chain.Tron, (chain) => {
|
|
377
|
+
const { address, ...wallet } = getWalletByChain(chain);
|
|
378
|
+
return wallet.estimateTransactionFee({ ...params, recipient: address, sender: address });
|
|
379
|
+
})
|
|
380
|
+
.with(Chain.Ripple, (chain) => getWalletByChain(chain).estimateTransactionFee())
|
|
381
|
+
.with(Chain.Ton, (chain) => getWalletByChain(chain).estimateTransactionFee())
|
|
382
|
+
.with(Chain.Cardano, (chain) => getWalletByChain(chain).estimateTransactionFee())
|
|
383
|
+
.with(Chain.Sui, (chain) => getWalletByChain(chain).estimateTransactionFee())
|
|
384
|
+
.otherwise(async () => baseValue);
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
return {
|
|
388
|
+
...availablePlugins,
|
|
389
|
+
...connectWalletMethods,
|
|
390
|
+
|
|
391
|
+
approveAssetValue,
|
|
392
|
+
disconnectAll,
|
|
393
|
+
disconnectChain,
|
|
394
|
+
estimateTransactionFee,
|
|
395
|
+
getAddress,
|
|
396
|
+
getAllWallets,
|
|
397
|
+
getBalance,
|
|
398
|
+
getWallet,
|
|
399
|
+
getWalletByChain,
|
|
400
|
+
getWalletWithBalance,
|
|
401
|
+
isAssetValueApproved,
|
|
402
|
+
signMessage,
|
|
403
|
+
swap,
|
|
404
|
+
transfer,
|
|
405
|
+
verifyMessage,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
export * from "@tcswap/helpers";
|