@swapkit/core 4.0.0-beta.8 → 4.0.0
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 +3 -2
- package/dist/index.cjs.map +4 -6
- package/dist/index.js +3 -2
- package/dist/index.js.map +4 -6
- package/dist/types/index.d.ts +1614 -0
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +9 -12
- package/src/__tests__/helpers.test.ts +0 -65
- package/src/client.ts +0 -412
- package/src/helpers/explorerUrls.ts +0 -47
- package/src/index.ts +0 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/E,OAAO,EAGL,UAAU,EACV,KAAK,EACL,KAAK,WAAW,EAChB,KAAK,2BAA2B,EAEhC,KAAK,QAAQ,EAEb,KAAK,SAAS,EACd,KAAK,qBAAqB,EAC1B,YAAY,IAAI,cAAc,EAE9B,KAAK,aAAa,EAElB,KAAK,UAAU,EAEhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD,MAAM,MAAM,aAAa,CAAC,CAAC,EAAE,CAAC,IAAI;IAChC,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,OAAO,CAAC,EAAE,CAAC,CAAC;IACZ,OAAO,CAAC,EAAE,CAAC,CAAC;CACb,CAAC;AAEF,wBAAgB,OAAO,CACrB,OAAO,SAAS,UAAU,CAAC,OAAO,YAAY,CAAC,EAC/C,OAA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4.0.0",
|
|
5
|
+
"@swapkit/toolboxes": "4.0.0"
|
|
6
6
|
},
|
|
7
7
|
"description": "SwapKit - Core",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
10
10
|
"import": "./dist/index.js",
|
|
11
11
|
"require": "./dist/index.cjs",
|
|
12
|
-
"types": "./
|
|
12
|
+
"types": "./dist/types/index.d.ts"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
|
-
"files": [
|
|
16
|
-
|
|
17
|
-
"dist/"
|
|
18
|
-
],
|
|
19
|
-
"homepage": "https://github.com/thorswap/SwapKit",
|
|
15
|
+
"files": ["dist/"],
|
|
16
|
+
"homepage": "https://github.com/swapkit/SwapKit",
|
|
20
17
|
"license": "Apache-2.0",
|
|
21
18
|
"name": "@swapkit/core",
|
|
22
19
|
"repository": {
|
|
23
20
|
"directory": "packages/core",
|
|
24
21
|
"type": "git",
|
|
25
|
-
"url": "git+https://github.com/
|
|
22
|
+
"url": "git+https://github.com/swapkit/SwapKit.git"
|
|
26
23
|
},
|
|
27
24
|
"scripts": {
|
|
28
25
|
"build": "bun run ./build.ts",
|
|
29
26
|
"build:clean": "rm -rf dist && bun run ./build.ts",
|
|
30
27
|
"clean": "rm -rf dist node_modules *.tsbuildinfo",
|
|
31
28
|
"test": "echo 'bun test'",
|
|
32
|
-
"test:ci": "bun test --coverage",
|
|
29
|
+
"test:ci": "echo 'bun test --coverage'",
|
|
33
30
|
"type-check": "bun tsc --noEmit",
|
|
34
31
|
"type-check:go": "tsgo"
|
|
35
32
|
},
|
|
36
33
|
"type": "module",
|
|
37
|
-
"version": "4.0.0
|
|
38
|
-
}
|
|
34
|
+
"version": "4.0.0"
|
|
35
|
+
}
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from "bun:test";
|
|
2
|
-
import { Chain, ChainToExplorerUrl, CosmosChains, EVMChains, UTXOChains } from "@swapkit/helpers";
|
|
3
|
-
import { getExplorerAddressUrl, getExplorerTxUrl } from "../helpers/explorerUrls";
|
|
4
|
-
|
|
5
|
-
describe("Explorer URLs", () => {
|
|
6
|
-
describe("CosmosChains", () => {
|
|
7
|
-
for (const chain of CosmosChains) {
|
|
8
|
-
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
9
|
-
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
10
|
-
`${ChainToExplorerUrl[chain]}/tx/123456789`,
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
|
|
14
|
-
`${ChainToExplorerUrl[chain]}/address/asdfg`,
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
describe("EVMChains & SubstrateChains", () => {
|
|
21
|
-
for (const chain of [...EVMChains, Chain.Polkadot]) {
|
|
22
|
-
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
23
|
-
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
24
|
-
`${ChainToExplorerUrl[chain]}/tx/0x123456789`,
|
|
25
|
-
);
|
|
26
|
-
|
|
27
|
-
expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
|
|
28
|
-
`${ChainToExplorerUrl[chain]}/address/asdfg`,
|
|
29
|
-
);
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
test("getExplorerTxUrl adds 0x for EVM like chains", () => {
|
|
34
|
-
expect(getExplorerTxUrl({ chain: Chain.Ethereum, txHash: "12345" })).toBe(
|
|
35
|
-
"https://etherscan.io/tx/0x12345",
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
describe("UTXOChains", () => {
|
|
41
|
-
for (const chain of UTXOChains.filter((c) => c !== Chain.Dash)) {
|
|
42
|
-
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
43
|
-
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
44
|
-
`${ChainToExplorerUrl[chain]}/transaction/0x123456789`,
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
|
|
48
|
-
`${ChainToExplorerUrl[chain]}/address/asdfg`,
|
|
49
|
-
);
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
describe("Solana", () => {
|
|
55
|
-
test("getExplorerTxUrl returns correct URL for Solana", () => {
|
|
56
|
-
expect(getExplorerTxUrl({ chain: Chain.Solana, txHash: "b123456789" })).toBe(
|
|
57
|
-
"https://solscan.io/tx/b123456789",
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
expect(getExplorerAddressUrl({ chain: Chain.Solana, address: "asdfg" })).toBe(
|
|
61
|
-
"https://solscan.io/account/asdfg",
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
});
|
package/src/client.ts
DELETED
|
@@ -1,412 +0,0 @@
|
|
|
1
|
-
import type { EVMTransaction, QuoteResponseRoute } from "@swapkit/helpers/api";
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
ApproveMode,
|
|
5
|
-
type ApproveReturnType,
|
|
6
|
-
AssetValue,
|
|
7
|
-
Chain,
|
|
8
|
-
type ChainWallet,
|
|
9
|
-
type ConditionalAssetValueReturn,
|
|
10
|
-
type EVMChain,
|
|
11
|
-
EVMChains,
|
|
12
|
-
type FeeOption,
|
|
13
|
-
type FullWallet,
|
|
14
|
-
type GenericTransferParams,
|
|
15
|
-
ProviderName as PluginNameEnum,
|
|
16
|
-
SKConfig,
|
|
17
|
-
type SKConfigState,
|
|
18
|
-
SwapKitError,
|
|
19
|
-
type SwapParams,
|
|
20
|
-
type createPlugin,
|
|
21
|
-
type createWallet,
|
|
22
|
-
} from "@swapkit/helpers";
|
|
23
|
-
import type { EVMCreateTransactionParams, EVMTransferParams } from "@swapkit/toolboxes/evm";
|
|
24
|
-
|
|
25
|
-
import {
|
|
26
|
-
getExplorerAddressUrl as getAddressUrl,
|
|
27
|
-
getExplorerTxUrl as getTxUrl,
|
|
28
|
-
} from "./helpers/explorerUrls";
|
|
29
|
-
|
|
30
|
-
export type SwapKitParams<P, W> = {
|
|
31
|
-
config?: SKConfigState;
|
|
32
|
-
plugins?: P;
|
|
33
|
-
wallets?: W;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
export function SwapKit<
|
|
37
|
-
Plugins extends ReturnType<typeof createPlugin>,
|
|
38
|
-
Wallets extends ReturnType<typeof createWallet>,
|
|
39
|
-
>({
|
|
40
|
-
config,
|
|
41
|
-
plugins,
|
|
42
|
-
wallets,
|
|
43
|
-
}: { config?: SKConfigState; plugins?: Plugins; wallets?: Wallets } = {}) {
|
|
44
|
-
if (config) {
|
|
45
|
-
SKConfig.set(config);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
type PluginName = keyof Plugins;
|
|
49
|
-
const connectedWallets = {} as FullWallet;
|
|
50
|
-
type ConnectedChains = keyof typeof connectedWallets;
|
|
51
|
-
|
|
52
|
-
const availablePlugins = Object.entries(plugins || {}).reduce(
|
|
53
|
-
(acc, [pluginName, plugin]) => {
|
|
54
|
-
const methods = plugin({ getWallet });
|
|
55
|
-
|
|
56
|
-
acc[pluginName as PluginName] = methods as ReturnType<Plugins[keyof Plugins]>;
|
|
57
|
-
return acc;
|
|
58
|
-
},
|
|
59
|
-
{} as { [key in PluginName]: ReturnType<Plugins[key]> },
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
const connectWalletMethods = Object.entries(wallets || {}).reduce(
|
|
63
|
-
(acc, [walletName, wallet]) => {
|
|
64
|
-
const connectWallet = wallet.connectWallet({ addChain });
|
|
65
|
-
|
|
66
|
-
acc[walletName as keyof Wallets] = connectWallet as ReturnType<
|
|
67
|
-
Wallets[keyof Wallets]["connectWallet"]
|
|
68
|
-
>;
|
|
69
|
-
return acc;
|
|
70
|
-
},
|
|
71
|
-
{} as {
|
|
72
|
-
[key in keyof Wallets]: ReturnType<Wallets[key]["connectWallet"]>;
|
|
73
|
-
},
|
|
74
|
-
);
|
|
75
|
-
|
|
76
|
-
function getSwapKitPlugin<T extends PluginName>(pluginName?: T) {
|
|
77
|
-
const availablePlugin = pluginName && availablePlugins[pluginName];
|
|
78
|
-
const plugin = availablePlugin || Object.values(availablePlugins)[0];
|
|
79
|
-
|
|
80
|
-
if (!plugin) {
|
|
81
|
-
throw new SwapKitError("core_plugin_not_found");
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return plugin as ReturnType<Plugins[T]>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function addChain<T extends Chain>(
|
|
88
|
-
connectWallet: Omit<ChainWallet<T>, "balance"> & { balance?: AssetValue[] },
|
|
89
|
-
) {
|
|
90
|
-
const currentWallet = getWallet(connectWallet.chain);
|
|
91
|
-
|
|
92
|
-
const balance = connectWallet.balance ||
|
|
93
|
-
currentWallet.balance || [AssetValue.from({ chain: connectWallet.chain })];
|
|
94
|
-
|
|
95
|
-
const wallet = { ...currentWallet, ...connectWallet, balance } as FullWallet[T];
|
|
96
|
-
|
|
97
|
-
connectedWallets[connectWallet.chain] = wallet;
|
|
98
|
-
|
|
99
|
-
return wallet;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
|
|
103
|
-
function approve<T extends ApproveMode>({
|
|
104
|
-
assetValue,
|
|
105
|
-
type = "checkOnly" as T,
|
|
106
|
-
contractAddress: spenderAddress,
|
|
107
|
-
}: {
|
|
108
|
-
type: T;
|
|
109
|
-
assetValue: AssetValue;
|
|
110
|
-
contractAddress: string | PluginName;
|
|
111
|
-
}) {
|
|
112
|
-
const plugin = availablePlugins[spenderAddress];
|
|
113
|
-
|
|
114
|
-
if (plugin) {
|
|
115
|
-
if (type === ApproveMode.CheckOnly && "isAssetValueApproved" in plugin) {
|
|
116
|
-
// @ts-expect-error TODO: add optional approve for plugin
|
|
117
|
-
return plugin.isAssetValueApproved({ assetValue }) as ApproveReturnType<T>;
|
|
118
|
-
}
|
|
119
|
-
if (type === ApproveMode.Approve && "approveAssetValue" in plugin) {
|
|
120
|
-
// @ts-expect-error TODO: add optional approve for plugin
|
|
121
|
-
return plugin.approveAssetValue({ assetValue }) as ApproveReturnType<T>;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
throw new SwapKitError({
|
|
125
|
-
errorKey: "core_approve_asset_target_invalid",
|
|
126
|
-
info: { message: `Target ${String(spenderAddress)} cannot be used for approve operation` },
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const chain = assetValue.chain as EVMChain;
|
|
131
|
-
const isEVMChain = EVMChains.includes(chain);
|
|
132
|
-
const isNativeEVM = isEVMChain && assetValue.isGasAsset;
|
|
133
|
-
|
|
134
|
-
if (isNativeEVM || !isEVMChain || assetValue.isSynthetic) {
|
|
135
|
-
return Promise.resolve(type === "checkOnly" ? true : "approved") as ApproveReturnType<T>;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const wallet = getWallet(chain);
|
|
139
|
-
const walletAction = type === "checkOnly" ? wallet.isApproved : wallet.approve;
|
|
140
|
-
if (!walletAction) throw new SwapKitError("core_wallet_connection_not_found");
|
|
141
|
-
|
|
142
|
-
if (!(assetValue.address && wallet.address && typeof spenderAddress === "string")) {
|
|
143
|
-
throw new SwapKitError("core_approve_asset_address_or_from_not_found");
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return walletAction({
|
|
147
|
-
amount: assetValue.getBaseValue("bigint"),
|
|
148
|
-
assetAddress: assetValue.address,
|
|
149
|
-
from: wallet.address,
|
|
150
|
-
spenderAddress,
|
|
151
|
-
}) as ApproveReturnType<T>;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* @Public
|
|
156
|
-
*/
|
|
157
|
-
function getWallet<T extends ConnectedChains>(chain: T) {
|
|
158
|
-
return connectedWallets[chain] || {};
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
function getAllWallets() {
|
|
162
|
-
return { ...connectedWallets };
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function getAddress<T extends Chain>(chain: T) {
|
|
166
|
-
return getWallet(chain)?.address || "";
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function approveAssetValue(assetValue: AssetValue, contractAddress: string | PluginName) {
|
|
170
|
-
return approve({ assetValue, contractAddress, type: ApproveMode.Approve });
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function isAssetValueApproved(assetValue: AssetValue, contractAddress: string | PluginName) {
|
|
174
|
-
return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function disconnectChain<T extends Chain>(chain: T) {
|
|
178
|
-
const wallet = getWallet(chain);
|
|
179
|
-
wallet?.disconnect?.();
|
|
180
|
-
delete connectedWallets[chain];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
function disconnectAll() {
|
|
184
|
-
for (const chain of Object.keys(connectedWallets) as (keyof typeof connectedWallets)[]) {
|
|
185
|
-
disconnectChain(chain);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function getBalance<T extends Chain, R extends boolean>(
|
|
190
|
-
chain: T,
|
|
191
|
-
refresh?: R,
|
|
192
|
-
): ConditionalAssetValueReturn<R> {
|
|
193
|
-
return (
|
|
194
|
-
refresh
|
|
195
|
-
? getWalletWithBalance(chain).then(({ balance }) => balance)
|
|
196
|
-
: getWallet(chain)?.balance || []
|
|
197
|
-
) as ConditionalAssetValueReturn<R>;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
async function getWalletWithBalance<T extends Chain>(
|
|
201
|
-
chain: T,
|
|
202
|
-
scamFilter = true,
|
|
203
|
-
): Promise<ReturnType<typeof getWallet> & { balance: AssetValue[] }> {
|
|
204
|
-
if (chain === Chain.Fiat || !getWallet(chain)) {
|
|
205
|
-
throw new SwapKitError("core_wallet_connection_not_found");
|
|
206
|
-
}
|
|
207
|
-
const wallet = getWallet(chain as Exclude<Chain, Chain.Fiat>);
|
|
208
|
-
const defaultBalance = [AssetValue.from({ chain })];
|
|
209
|
-
wallet.balance = defaultBalance;
|
|
210
|
-
|
|
211
|
-
if ("getBalance" in wallet) {
|
|
212
|
-
const balance = await wallet.getBalance(wallet.address, scamFilter);
|
|
213
|
-
wallet.balance = balance;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
return wallet;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function swap<T extends PluginName>({
|
|
220
|
-
route,
|
|
221
|
-
pluginName,
|
|
222
|
-
...rest
|
|
223
|
-
}: SwapParams<T, QuoteResponseRoute>) {
|
|
224
|
-
const plugin = getSwapKitPlugin(pluginName || route.providers[0]);
|
|
225
|
-
|
|
226
|
-
if ("swap" in plugin) {
|
|
227
|
-
// @ts-expect-error TODO: fix this
|
|
228
|
-
return plugin.swap({ ...rest, route });
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
throw new SwapKitError("core_plugin_swap_not_found");
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function transfer({ assetValue, ...params }: GenericTransferParams | EVMTransferParams) {
|
|
235
|
-
const chain = assetValue.chain;
|
|
236
|
-
if ([Chain.Fiat, Chain.Radix].includes(chain) || !getWallet(chain)) {
|
|
237
|
-
throw new SwapKitError("core_wallet_connection_not_found");
|
|
238
|
-
}
|
|
239
|
-
const wallet = getWallet(chain as Exclude<Chain, Chain.Fiat | Chain.Radix | Chain.Near>);
|
|
240
|
-
|
|
241
|
-
// we need to simplify this to one object params
|
|
242
|
-
return wallet.transfer({ ...params, assetValue });
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
function signMessage({ chain, message }: { chain: Chain; message: string }) {
|
|
246
|
-
const wallet = getWallet(chain);
|
|
247
|
-
if (!wallet) throw new SwapKitError("core_wallet_connection_not_found");
|
|
248
|
-
|
|
249
|
-
if ("signMessage" in wallet) {
|
|
250
|
-
return wallet.signMessage?.(message);
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
throw new SwapKitError({
|
|
254
|
-
errorKey: "core_wallet_sign_message_not_supported",
|
|
255
|
-
info: { chain, wallet: wallet.walletType },
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
async function verifyMessage({
|
|
260
|
-
address,
|
|
261
|
-
chain,
|
|
262
|
-
message,
|
|
263
|
-
signature,
|
|
264
|
-
}: { chain: Chain; signature: string; message: string; address: string }) {
|
|
265
|
-
switch (chain) {
|
|
266
|
-
case Chain.THORChain: {
|
|
267
|
-
const { getCosmosToolbox } = await import("@swapkit/toolboxes/cosmos");
|
|
268
|
-
const toolbox = await getCosmosToolbox(chain);
|
|
269
|
-
|
|
270
|
-
return toolbox.verifySignature({ signature, message, address });
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
default:
|
|
274
|
-
throw new SwapKitError({ errorKey: "core_verify_message_not_supported", info: { chain } });
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO clean this up
|
|
279
|
-
async function estimateTransactionFee<T extends PluginName>({
|
|
280
|
-
type,
|
|
281
|
-
feeOptionKey,
|
|
282
|
-
params,
|
|
283
|
-
}: (
|
|
284
|
-
| { type: "swap"; params: SwapParams<T, QuoteResponseRoute> & { assetValue: AssetValue } }
|
|
285
|
-
| { type: "transfer"; params: EVMTransferParams | GenericTransferParams }
|
|
286
|
-
| {
|
|
287
|
-
type: "approve";
|
|
288
|
-
params: {
|
|
289
|
-
assetValue: AssetValue;
|
|
290
|
-
contractAddress: string | PluginName;
|
|
291
|
-
feeOptionKey?: FeeOption;
|
|
292
|
-
};
|
|
293
|
-
}
|
|
294
|
-
) & {
|
|
295
|
-
feeOptionKey: FeeOption;
|
|
296
|
-
}): Promise<AssetValue | undefined> {
|
|
297
|
-
const { assetValue } = params;
|
|
298
|
-
const { chain } = assetValue;
|
|
299
|
-
|
|
300
|
-
if (!getWallet(chain as Chain)) throw new SwapKitError("core_wallet_connection_not_found");
|
|
301
|
-
|
|
302
|
-
const baseValue = AssetValue.from({ chain });
|
|
303
|
-
|
|
304
|
-
switch (chain) {
|
|
305
|
-
case Chain.Arbitrum:
|
|
306
|
-
case Chain.Avalanche:
|
|
307
|
-
case Chain.Ethereum:
|
|
308
|
-
case Chain.BinanceSmartChain:
|
|
309
|
-
case Chain.Polygon: {
|
|
310
|
-
const wallet = getWallet(chain);
|
|
311
|
-
if (type === "transfer") {
|
|
312
|
-
const txObject = await wallet.createTransferTx(params as EVMCreateTransactionParams);
|
|
313
|
-
return wallet.estimateTransactionFee({ ...txObject, chain, feeOption: feeOptionKey });
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
if (type === "approve" && !assetValue.isGasAsset) {
|
|
317
|
-
const approvalTx = await wallet.createApprovalTx({
|
|
318
|
-
assetAddress: assetValue.address as string,
|
|
319
|
-
spenderAddress: params.contractAddress as string,
|
|
320
|
-
amount: assetValue.getBaseValue("bigint"),
|
|
321
|
-
from: wallet.address,
|
|
322
|
-
});
|
|
323
|
-
|
|
324
|
-
return wallet.estimateTransactionFee({ ...approvalTx, chain, feeOption: feeOptionKey });
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
if (type === "swap") {
|
|
328
|
-
const plugin = params.route.providers[0] as PluginNameEnum;
|
|
329
|
-
if ([PluginNameEnum.CHAINFLIP, PluginNameEnum.CHAINFLIP_STREAMING].includes(plugin)) {
|
|
330
|
-
const txObject = await wallet.createTransferTx({
|
|
331
|
-
sender: wallet.address,
|
|
332
|
-
recipient: wallet.address,
|
|
333
|
-
assetValue,
|
|
334
|
-
});
|
|
335
|
-
|
|
336
|
-
return wallet.estimateTransactionFee({ ...txObject, chain, feeOption: feeOptionKey });
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
const { tx } = params.route;
|
|
340
|
-
if (!tx) {
|
|
341
|
-
return undefined;
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
return wallet.estimateTransactionFee({
|
|
345
|
-
...(tx as EVMTransaction),
|
|
346
|
-
value: BigInt((tx as EVMTransaction).value),
|
|
347
|
-
feeOption: feeOptionKey,
|
|
348
|
-
chain,
|
|
349
|
-
});
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
return AssetValue.from({ chain });
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
case Chain.Bitcoin:
|
|
356
|
-
case Chain.BitcoinCash:
|
|
357
|
-
case Chain.Dogecoin:
|
|
358
|
-
case Chain.Dash:
|
|
359
|
-
case Chain.Litecoin: {
|
|
360
|
-
const { estimateTransactionFee, address: recipient } = getWallet(chain);
|
|
361
|
-
|
|
362
|
-
return estimateTransactionFee({ ...params, feeOptionKey, recipient, sender: recipient });
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
case Chain.THORChain:
|
|
366
|
-
case Chain.Maya:
|
|
367
|
-
case Chain.Kujira:
|
|
368
|
-
case Chain.Cosmos: {
|
|
369
|
-
const { estimateTransactionFee } = await import("@swapkit/toolboxes/cosmos");
|
|
370
|
-
return estimateTransactionFee(params);
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
case Chain.Polkadot: {
|
|
374
|
-
const { address, estimateTransactionFee } = getWallet(chain);
|
|
375
|
-
|
|
376
|
-
return estimateTransactionFee({ ...params, recipient: address });
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
case Chain.Ripple: {
|
|
380
|
-
const { estimateTransactionFee } = getWallet(chain);
|
|
381
|
-
|
|
382
|
-
return estimateTransactionFee();
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
default:
|
|
386
|
-
return baseValue;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
return {
|
|
391
|
-
...availablePlugins,
|
|
392
|
-
...connectWalletMethods,
|
|
393
|
-
|
|
394
|
-
disconnectAll,
|
|
395
|
-
disconnectChain,
|
|
396
|
-
estimateTransactionFee,
|
|
397
|
-
getAddress,
|
|
398
|
-
getAllWallets,
|
|
399
|
-
getBalance,
|
|
400
|
-
getExplorerAddressUrl: getAddressUrl,
|
|
401
|
-
getExplorerTxUrl: getTxUrl,
|
|
402
|
-
getWallet,
|
|
403
|
-
getWalletWithBalance,
|
|
404
|
-
|
|
405
|
-
approveAssetValue,
|
|
406
|
-
isAssetValueApproved,
|
|
407
|
-
signMessage,
|
|
408
|
-
swap,
|
|
409
|
-
transfer,
|
|
410
|
-
verifyMessage,
|
|
411
|
-
};
|
|
412
|
-
}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { Chain, ChainToExplorerUrl, SwapKitError } from "@swapkit/helpers";
|
|
2
|
-
|
|
3
|
-
export function getExplorerTxUrl({ chain, txHash }: { txHash: string; chain: Chain }) {
|
|
4
|
-
const baseUrl = ChainToExplorerUrl[chain];
|
|
5
|
-
|
|
6
|
-
switch (chain) {
|
|
7
|
-
case Chain.Maya:
|
|
8
|
-
case Chain.Kujira:
|
|
9
|
-
case Chain.Cosmos:
|
|
10
|
-
case Chain.THORChain:
|
|
11
|
-
case Chain.Solana:
|
|
12
|
-
return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash.slice(2) : txHash}`;
|
|
13
|
-
|
|
14
|
-
case Chain.Arbitrum:
|
|
15
|
-
case Chain.Avalanche:
|
|
16
|
-
case Chain.BinanceSmartChain:
|
|
17
|
-
case Chain.Base:
|
|
18
|
-
case Chain.Ethereum:
|
|
19
|
-
case Chain.Optimism:
|
|
20
|
-
case Chain.Polkadot:
|
|
21
|
-
case Chain.Polygon:
|
|
22
|
-
return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash : `0x${txHash}`}`;
|
|
23
|
-
|
|
24
|
-
case Chain.Litecoin:
|
|
25
|
-
case Chain.Bitcoin:
|
|
26
|
-
case Chain.BitcoinCash:
|
|
27
|
-
case Chain.Dogecoin:
|
|
28
|
-
case Chain.Radix:
|
|
29
|
-
return `${baseUrl}/transaction/${txHash.toLowerCase()}`;
|
|
30
|
-
|
|
31
|
-
default:
|
|
32
|
-
throw new SwapKitError({ errorKey: "core_explorer_unsupported_chain", info: { chain } });
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function getExplorerAddressUrl({ chain, address }: { address: string; chain: Chain }) {
|
|
37
|
-
const baseUrl = ChainToExplorerUrl[chain];
|
|
38
|
-
|
|
39
|
-
switch (chain) {
|
|
40
|
-
case Chain.Solana:
|
|
41
|
-
case Chain.Radix:
|
|
42
|
-
return `${baseUrl}/account/${address}`;
|
|
43
|
-
|
|
44
|
-
default:
|
|
45
|
-
return `${baseUrl}/address/${address}`;
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/index.ts
DELETED