@swapkit/core 1.0.0-rc.119 → 1.0.0-rc.120
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.es.js → index.js} +1072 -963
- package/dist/index.js.map +41 -0
- package/package.json +27 -36
- package/src/__tests__/helpers.test.ts +2 -26
- package/src/client/index.ts +21 -26
- package/src/client/old.ts +64 -76
- package/src/helpers/explorerUrls.ts +6 -31
- package/src/types.ts +2 -2
- package/LICENSE +0 -201
- package/dist/index.cjs +0 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.ts +0 -353
- package/dist/index.es.js.map +0 -1
- package/src/helpers/mayanode.ts +0 -31
- package/src/helpers/thornode.ts +0 -31
package/package.json
CHANGED
|
@@ -1,35 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"author": "swapkit-oss",
|
|
3
3
|
"dependencies": {
|
|
4
|
-
"@swapkit/helpers": "1.0.0-rc.
|
|
5
|
-
"@swapkit/types": "1.0.0-rc.
|
|
4
|
+
"@swapkit/helpers": "1.0.0-rc.84",
|
|
5
|
+
"@swapkit/types": "1.0.0-rc.48"
|
|
6
6
|
},
|
|
7
|
-
"description": "SwapKit
|
|
7
|
+
"description": "SwapKit - Core",
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"@swapkit/
|
|
13
|
-
"@swapkit/toolbox-
|
|
14
|
-
"
|
|
15
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.18",
|
|
16
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.91"
|
|
9
|
+
"@swapkit/tokens": "1.0.0-rc.45",
|
|
10
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.101",
|
|
11
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.90",
|
|
12
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.19",
|
|
13
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.92",
|
|
14
|
+
"bun-types": "1.1.1"
|
|
17
15
|
},
|
|
18
16
|
"peerDependencies": {
|
|
19
|
-
"@swapkit/helpers": "1.0.0-rc.
|
|
20
|
-
"@swapkit/tokens": "1.0.0-rc.
|
|
21
|
-
"@swapkit/toolbox-
|
|
22
|
-
"@swapkit/toolbox-
|
|
23
|
-
"@swapkit/toolbox-substrate": "1.0.0-rc.
|
|
24
|
-
"@swapkit/toolbox-utxo": "1.0.0-rc.
|
|
25
|
-
"@swapkit/types": "1.0.0-rc.
|
|
26
|
-
},
|
|
27
|
-
"exports": {
|
|
28
|
-
".": {
|
|
29
|
-
"import": "./dist/index.es.js",
|
|
30
|
-
"require": "./dist/index.cjs",
|
|
31
|
-
"types": "./dist/index.d.ts"
|
|
32
|
-
}
|
|
17
|
+
"@swapkit/helpers": "1.0.0-rc.84",
|
|
18
|
+
"@swapkit/tokens": "1.0.0-rc.45",
|
|
19
|
+
"@swapkit/toolbox-cosmos": "1.0.0-rc.101",
|
|
20
|
+
"@swapkit/toolbox-evm": "1.0.0-rc.90",
|
|
21
|
+
"@swapkit/toolbox-substrate": "1.0.0-rc.19",
|
|
22
|
+
"@swapkit/toolbox-utxo": "1.0.0-rc.92",
|
|
23
|
+
"@swapkit/types": "1.0.0-rc.48"
|
|
33
24
|
},
|
|
34
25
|
"files": [
|
|
35
26
|
"src/",
|
|
@@ -37,22 +28,22 @@
|
|
|
37
28
|
],
|
|
38
29
|
"homepage": "https://github.com/thorswap/SwapKit",
|
|
39
30
|
"license": "Apache-2.0",
|
|
40
|
-
"main": "./dist/index.
|
|
41
|
-
"module": "./dist/index.es.js",
|
|
31
|
+
"main": "./dist/index.js",
|
|
42
32
|
"name": "@swapkit/core",
|
|
43
33
|
"react-native": "./src/index.ts",
|
|
44
34
|
"repository": {
|
|
45
35
|
"type": "git",
|
|
46
36
|
"url": "git+https://github.com/thorswap/SwapKit.git"
|
|
47
37
|
},
|
|
48
|
-
"type": "module",
|
|
49
|
-
"types": "./dist/index.d.ts",
|
|
50
|
-
"version": "1.0.0-rc.119",
|
|
51
38
|
"scripts": {
|
|
52
|
-
"build": "
|
|
53
|
-
"clean": "rm -rf dist
|
|
39
|
+
"build": "bun run ./build.ts",
|
|
40
|
+
"clean": "rm -rf .turbo dist node_modules tsconfig.tsbuildinfo",
|
|
54
41
|
"lint": "biome check --apply ./src",
|
|
55
|
-
"test": "
|
|
56
|
-
"test:coverage": "
|
|
57
|
-
|
|
58
|
-
}
|
|
42
|
+
"test": "echo 'bun test'",
|
|
43
|
+
"test:coverage": "echo 'bun test --coverage'",
|
|
44
|
+
"type-check": "tsc --noEmit"
|
|
45
|
+
},
|
|
46
|
+
"type": "module",
|
|
47
|
+
"types": "./src/index.ts",
|
|
48
|
+
"version": "1.0.0-rc.120"
|
|
49
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
1
2
|
import { Chain, ChainToExplorerUrl, CosmosChains, EVMChains, UTXOChains } from "@swapkit/types";
|
|
2
|
-
import { describe, expect, test } from "vitest";
|
|
3
3
|
import { getExplorerAddressUrl, getExplorerTxUrl } from "../helpers/explorerUrls.ts";
|
|
4
4
|
|
|
5
5
|
describe("Explorer URLs", () => {
|
|
6
6
|
describe("CosmosChains", () => {
|
|
7
|
-
for (const chain of CosmosChains
|
|
7
|
+
for (const chain of CosmosChains) {
|
|
8
8
|
test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
|
|
9
9
|
expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
|
|
10
10
|
`${ChainToExplorerUrl[chain]}/tx/123456789`,
|
|
@@ -15,16 +15,6 @@ describe("Explorer URLs", () => {
|
|
|
15
15
|
);
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
test(`getExplorerTxUrl returns correct URL for ${Chain.Cosmos}`, () => {
|
|
20
|
-
expect(getExplorerTxUrl({ chain: Chain.Cosmos, txHash: "0x123456789" })).toBe(
|
|
21
|
-
`${ChainToExplorerUrl[Chain.Cosmos]}/transactions/0x123456789`,
|
|
22
|
-
);
|
|
23
|
-
|
|
24
|
-
expect(getExplorerAddressUrl({ chain: Chain.Cosmos, address: "asdfg" })).toBe(
|
|
25
|
-
`${ChainToExplorerUrl[Chain.Cosmos]}/account/asdfg`,
|
|
26
|
-
);
|
|
27
|
-
});
|
|
28
18
|
});
|
|
29
19
|
|
|
30
20
|
describe("EVMChains & SubstrateChains", () => {
|
|
@@ -60,18 +50,4 @@ describe("Explorer URLs", () => {
|
|
|
60
50
|
});
|
|
61
51
|
}
|
|
62
52
|
});
|
|
63
|
-
|
|
64
|
-
describe("Unsupported chains", () => {
|
|
65
|
-
test("getExplorerTxUrl throws Error for unsupported Chain", () => {
|
|
66
|
-
expect(() =>
|
|
67
|
-
getExplorerTxUrl({ chain: "unsupported" as Chain, txHash: "0x12345" }),
|
|
68
|
-
).toThrowError("Unsupported chain: unsupported");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
test("getExplorerAddressUrl throws Error for unsupported Chain", () => {
|
|
72
|
-
expect(() =>
|
|
73
|
-
getExplorerAddressUrl({ chain: "unsupported" as Chain, address: "asdfg" }),
|
|
74
|
-
).toThrowError("Unsupported chain: unsupported");
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
53
|
});
|
package/src/client/index.ts
CHANGED
|
@@ -34,7 +34,7 @@ type GenericSwapParams = {
|
|
|
34
34
|
export type SwapParams = (SwapWithRouteParams | GenericSwapParams) & {
|
|
35
35
|
provider?: {
|
|
36
36
|
name: PluginName;
|
|
37
|
-
config: Record<string,
|
|
37
|
+
config: Record<string, Todo>;
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
40
|
|
|
@@ -46,8 +46,8 @@ export type SwapKitReturnType = SwapKitPlugins & {
|
|
|
46
46
|
potentialScamFilter?: boolean,
|
|
47
47
|
) => Promise<ChainWallet<Chain>>;
|
|
48
48
|
getBalance: (chain: Chain, potentialScamFilter?: boolean) => AssetValue[];
|
|
49
|
-
getExplorerTxUrl:
|
|
50
|
-
getExplorerAddressUrl:
|
|
49
|
+
getExplorerTxUrl: typeof getTxUrl;
|
|
50
|
+
getExplorerAddressUrl: typeof getAddressUrl;
|
|
51
51
|
swap: (params: SwapParams) => Promise<string>;
|
|
52
52
|
validateAddress: (params: { address: string; chain: Chain }) =>
|
|
53
53
|
| boolean
|
|
@@ -64,7 +64,7 @@ export type Wallets = { [K in Chain]?: ChainWallet<K> };
|
|
|
64
64
|
export type AvailableProviders<T> = T | { [K in PluginName]?: ProviderMethods };
|
|
65
65
|
export type ProviderMethods = {
|
|
66
66
|
swap: (swapParams: SwapParams) => Promise<string>;
|
|
67
|
-
[key: string]:
|
|
67
|
+
[key: string]: Todo;
|
|
68
68
|
};
|
|
69
69
|
|
|
70
70
|
export type SwapKitPlugin = ({ wallets, stagenet }: { wallets: Wallets; stagenet?: boolean }) => {
|
|
@@ -74,12 +74,12 @@ export type SwapKitPlugin = ({ wallets, stagenet }: { wallets: Wallets; stagenet
|
|
|
74
74
|
|
|
75
75
|
export type SwapKitWallet = {
|
|
76
76
|
connectMethodName: string;
|
|
77
|
-
connect: (params: ConnectWalletParams) => (connectParams:
|
|
77
|
+
connect: (params: ConnectWalletParams) => (connectParams: Todo) => undefined | string;
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
export function SwapKit<
|
|
81
81
|
ExtendedProviders extends {},
|
|
82
|
-
ConnectWalletMethods
|
|
82
|
+
ConnectWalletMethods = Record<string, ReturnType<SwapKitWallet["connect"]>>,
|
|
83
83
|
>({
|
|
84
84
|
stagenet,
|
|
85
85
|
wallets,
|
|
@@ -91,9 +91,9 @@ export function SwapKit<
|
|
|
91
91
|
plugins: SwapKitPlugin[];
|
|
92
92
|
stagenet: boolean;
|
|
93
93
|
wallets: SwapKitWallet[];
|
|
94
|
-
config?: Record<string,
|
|
95
|
-
apis: Record<string,
|
|
96
|
-
rpcUrls: Record<string,
|
|
94
|
+
config?: Record<string, Todo>;
|
|
95
|
+
apis: Record<string, Todo>;
|
|
96
|
+
rpcUrls: Record<string, Todo>;
|
|
97
97
|
}): SwapKitReturnType & ConnectWalletMethods & AvailableProviders<ExtendedProviders> {
|
|
98
98
|
const connectedWallets: Wallets = {};
|
|
99
99
|
const availablePlugins: AvailableProviders<ExtendedProviders> = {};
|
|
@@ -105,7 +105,8 @@ export function SwapKit<
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
const connectWalletMethods = wallets.reduce((acc, wallet) => {
|
|
108
|
-
|
|
108
|
+
// @ts-expect-error
|
|
109
|
+
acc[wallet.connectMethodName] = wallet.connect({
|
|
109
110
|
addChain,
|
|
110
111
|
config,
|
|
111
112
|
apis,
|
|
@@ -190,12 +191,6 @@ export function SwapKit<
|
|
|
190
191
|
function getBalance(chain: Chain) {
|
|
191
192
|
return getWallet(chain)?.balance || [];
|
|
192
193
|
}
|
|
193
|
-
function getExplorerTxUrl(chain: Chain, txHash: string) {
|
|
194
|
-
return getTxUrl({ chain, txHash });
|
|
195
|
-
}
|
|
196
|
-
function getExplorerAddressUrl(chain: Chain, address: string) {
|
|
197
|
-
return getAddressUrl({ chain, address });
|
|
198
|
-
}
|
|
199
194
|
/**
|
|
200
195
|
* TODO: Figure out validation without connecting to wallet
|
|
201
196
|
*/
|
|
@@ -207,16 +202,14 @@ export function SwapKit<
|
|
|
207
202
|
const defaultBalance = [AssetValue.fromChainOrSignature(chain)];
|
|
208
203
|
const wallet = getWallet(chain);
|
|
209
204
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
205
|
+
if (!wallet) {
|
|
206
|
+
throw new SwapKitError("core_wallet_connection_not_found");
|
|
207
|
+
}
|
|
213
208
|
|
|
214
|
-
|
|
209
|
+
const balance = await wallet?.getBalance(wallet.address, potentialScamFilter);
|
|
210
|
+
wallet.balance = balance?.length ? balance : defaultBalance;
|
|
215
211
|
|
|
216
|
-
|
|
217
|
-
} catch (error) {
|
|
218
|
-
throw new SwapKitError("core_wallet_connection_not_found", error);
|
|
219
|
-
}
|
|
212
|
+
return wallet;
|
|
220
213
|
}
|
|
221
214
|
|
|
222
215
|
/**
|
|
@@ -240,11 +233,13 @@ export function SwapKit<
|
|
|
240
233
|
return {
|
|
241
234
|
...availablePlugins,
|
|
242
235
|
...connectWalletMethods,
|
|
236
|
+
|
|
237
|
+
getExplorerAddressUrl: getAddressUrl,
|
|
238
|
+
getExplorerTxUrl: getTxUrl,
|
|
239
|
+
|
|
243
240
|
approveAssetValue,
|
|
244
241
|
getAddress,
|
|
245
242
|
getBalance,
|
|
246
|
-
getExplorerAddressUrl,
|
|
247
|
-
getExplorerTxUrl,
|
|
248
243
|
getWallet,
|
|
249
244
|
getWalletWithBalance,
|
|
250
245
|
isAssetValueApproved,
|
package/src/client/old.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { ErrorKeys, QuoteRoute, ThornameRegisterParam } from "@swapkit/helpers";
|
|
2
2
|
import {
|
|
3
3
|
AssetValue,
|
|
4
|
+
SwapKitApi,
|
|
4
5
|
SwapKitError,
|
|
5
6
|
SwapKitNumber,
|
|
6
7
|
gasFeeMultiplier,
|
|
7
8
|
getMemoFor,
|
|
8
9
|
getMinAmountByChain,
|
|
10
|
+
wrapWithThrow,
|
|
9
11
|
} from "@swapkit/helpers";
|
|
10
12
|
import type { CosmosLikeToolbox } from "@swapkit/toolbox-cosmos";
|
|
11
13
|
import type { AVAXToolbox, BSCToolbox, ETHToolbox, EVMToolbox } from "@swapkit/toolbox-evm";
|
|
@@ -35,8 +37,6 @@ import { lowercasedContractAbiMapping } from "../aggregator/contracts/index.ts";
|
|
|
35
37
|
import { getSwapInParams } from "../aggregator/getSwapParams.ts";
|
|
36
38
|
|
|
37
39
|
import { getExplorerAddressUrl, getExplorerTxUrl } from "../helpers/explorerUrls.ts";
|
|
38
|
-
import { getMayaMimirData } from "../helpers/mayanode.js";
|
|
39
|
-
import { getThorInboundData, getThorMimirData } from "../helpers/thornode.ts";
|
|
40
40
|
import type {
|
|
41
41
|
CoreTxParams,
|
|
42
42
|
EVMWallet,
|
|
@@ -266,7 +266,9 @@ export class SwapKitCore<T = ""> {
|
|
|
266
266
|
if (!walletInstance) throw new SwapKitError("core_wallet_connection_not_found");
|
|
267
267
|
|
|
268
268
|
try {
|
|
269
|
-
|
|
269
|
+
const tx = await walletInstance.transfer(this.#prepareTxParams(params));
|
|
270
|
+
|
|
271
|
+
return tx;
|
|
270
272
|
} catch (error) {
|
|
271
273
|
throw new SwapKitError("core_swap_transaction_error", error);
|
|
272
274
|
}
|
|
@@ -290,8 +292,9 @@ export class SwapKitCore<T = ""> {
|
|
|
290
292
|
if (!isAddressValidated) {
|
|
291
293
|
throw new SwapKitError("core_transaction_invalid_sender_address");
|
|
292
294
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
if (!walletInstance) {
|
|
296
|
+
throw new SwapKitError("core_wallet_connection_not_found");
|
|
297
|
+
}
|
|
295
298
|
|
|
296
299
|
const params = this.#prepareTxParams({
|
|
297
300
|
assetValue,
|
|
@@ -305,7 +308,8 @@ export class SwapKitCore<T = ""> {
|
|
|
305
308
|
case Chain.THORChain:
|
|
306
309
|
case Chain.Maya: {
|
|
307
310
|
const wallet = walletInstance as ThorchainWallet;
|
|
308
|
-
|
|
311
|
+
const tx = await (recipient === "" ? wallet.deposit(params) : wallet.transfer(params));
|
|
312
|
+
return tx;
|
|
309
313
|
}
|
|
310
314
|
|
|
311
315
|
case Chain.Ethereum:
|
|
@@ -320,9 +324,11 @@ export class SwapKitCore<T = ""> {
|
|
|
320
324
|
? TCBscDepositABI
|
|
321
325
|
: TCEthereumVaultAbi;
|
|
322
326
|
|
|
323
|
-
const
|
|
324
|
-
|
|
325
|
-
|
|
327
|
+
const wallet = walletInstance as EVMWallet<
|
|
328
|
+
typeof AVAXToolbox | typeof ETHToolbox | typeof BSCToolbox
|
|
329
|
+
>;
|
|
330
|
+
|
|
331
|
+
const response = await wallet.call({
|
|
326
332
|
abi,
|
|
327
333
|
contractAddress:
|
|
328
334
|
router || ((await this.#getInboundDataByChain(chain as EVMChain)).router as string),
|
|
@@ -345,12 +351,15 @@ export class SwapKitCore<T = ""> {
|
|
|
345
351
|
}
|
|
346
352
|
|
|
347
353
|
default: {
|
|
348
|
-
|
|
354
|
+
const tx = await walletInstance.transfer(params);
|
|
355
|
+
return tx;
|
|
349
356
|
}
|
|
350
357
|
}
|
|
351
|
-
} catch (error
|
|
358
|
+
} catch (error) {
|
|
352
359
|
const errorMessage =
|
|
353
|
-
|
|
360
|
+
// @ts-expect-error - this is fine as we are checking for string
|
|
361
|
+
typeof error === "string" ? error.toLowerCase() : error?.message?.toLowerCase();
|
|
362
|
+
|
|
354
363
|
const isInsufficientFunds = errorMessage?.includes("insufficient funds");
|
|
355
364
|
const isGas = errorMessage?.includes("gas");
|
|
356
365
|
const isServer = errorMessage?.includes("server");
|
|
@@ -383,32 +392,22 @@ export class SwapKitCore<T = ""> {
|
|
|
383
392
|
throw new SwapKitError("core_transaction_create_liquidity_invalid_params");
|
|
384
393
|
}
|
|
385
394
|
|
|
386
|
-
|
|
387
|
-
|
|
395
|
+
const assetAddress = this.getAddress(assetValue.chain);
|
|
396
|
+
const runeAddress = this.getAddress(Chain.THORChain);
|
|
388
397
|
|
|
389
|
-
|
|
390
|
-
|
|
398
|
+
const runeTx = await wrapWithThrow(() => {
|
|
399
|
+
return this.#depositToPool({
|
|
391
400
|
assetValue: runeAssetValue,
|
|
392
|
-
memo: getMemoFor(MemoType.DEPOSIT, {
|
|
393
|
-
...assetValue,
|
|
394
|
-
address: this.getAddress(assetValue.chain),
|
|
395
|
-
}),
|
|
401
|
+
memo: getMemoFor(MemoType.DEPOSIT, { ...assetValue, address: assetAddress }),
|
|
396
402
|
});
|
|
397
|
-
}
|
|
398
|
-
throw new SwapKitError("core_transaction_create_liquidity_rune_error", error);
|
|
399
|
-
}
|
|
403
|
+
}, "core_transaction_create_liquidity_rune_error");
|
|
400
404
|
|
|
401
|
-
|
|
402
|
-
|
|
405
|
+
const assetTx = await wrapWithThrow(() => {
|
|
406
|
+
return this.#depositToPool({
|
|
403
407
|
assetValue,
|
|
404
|
-
memo: getMemoFor(MemoType.DEPOSIT, {
|
|
405
|
-
...assetValue,
|
|
406
|
-
address: this.getAddress(Chain.THORChain),
|
|
407
|
-
}),
|
|
408
|
+
memo: getMemoFor(MemoType.DEPOSIT, { ...assetValue, address: runeAddress }),
|
|
408
409
|
});
|
|
409
|
-
}
|
|
410
|
-
throw new SwapKitError("core_transaction_create_liquidity_asset_error", error);
|
|
411
|
-
}
|
|
410
|
+
}, "core_transaction_create_liquidity_asset_error");
|
|
412
411
|
|
|
413
412
|
return { runeTx, assetTx };
|
|
414
413
|
};
|
|
@@ -444,38 +443,22 @@ export class SwapKitCore<T = ""> {
|
|
|
444
443
|
throw new SwapKitError("core_transaction_add_liquidity_no_rune_address");
|
|
445
444
|
}
|
|
446
445
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
if (assetTransfer && assetValue) {
|
|
466
|
-
try {
|
|
467
|
-
assetTx = await this.#depositToPool({
|
|
468
|
-
assetValue,
|
|
469
|
-
memo: getMemoFor(MemoType.DEPOSIT, {
|
|
470
|
-
chain,
|
|
471
|
-
symbol,
|
|
472
|
-
address: runeAddress,
|
|
473
|
-
}),
|
|
474
|
-
});
|
|
475
|
-
} catch (error) {
|
|
476
|
-
throw new SwapKitError("core_transaction_add_liquidity_asset_error", error);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
446
|
+
const runeTx = await wrapWithThrow(() => {
|
|
447
|
+
return this.#depositToPool({
|
|
448
|
+
assetValue: runeAssetValue,
|
|
449
|
+
memo: getMemoFor(MemoType.DEPOSIT, { chain, symbol, address: assetAddress }),
|
|
450
|
+
});
|
|
451
|
+
}, "core_transaction_add_liquidity_rune_error");
|
|
452
|
+
|
|
453
|
+
const assetTx =
|
|
454
|
+
assetTransfer && assetValue
|
|
455
|
+
? wrapWithThrow(() => {
|
|
456
|
+
return this.#depositToPool({
|
|
457
|
+
assetValue,
|
|
458
|
+
memo: getMemoFor(MemoType.DEPOSIT, { chain, symbol, address: runeAddress }),
|
|
459
|
+
});
|
|
460
|
+
}, "core_transaction_add_liquidity_asset_error")
|
|
461
|
+
: null;
|
|
479
462
|
|
|
480
463
|
return { runeTx, assetTx };
|
|
481
464
|
};
|
|
@@ -494,9 +477,10 @@ export class SwapKitCore<T = ""> {
|
|
|
494
477
|
if (symmetric && !address) {
|
|
495
478
|
throw new SwapKitError("core_transaction_add_liquidity_invalid_params");
|
|
496
479
|
}
|
|
480
|
+
|
|
497
481
|
const memo = getMemoFor(MemoType.DEPOSIT, {
|
|
498
482
|
chain: poolAddress.split(".")[0] as Chain,
|
|
499
|
-
symbol: poolAddress.split(".")[1],
|
|
483
|
+
symbol: poolAddress.split(".")[1] as string,
|
|
500
484
|
address: symmetric ? address : "",
|
|
501
485
|
});
|
|
502
486
|
|
|
@@ -697,7 +681,7 @@ export class SwapKitCore<T = ""> {
|
|
|
697
681
|
throw new SwapKitError("core_wallet_evmwallet_not_installed");
|
|
698
682
|
};
|
|
699
683
|
// biome-ignore lint/suspicious/useAwait: Extended methods
|
|
700
|
-
connectWalletconnect = async (_chains: Chain[], _options?:
|
|
684
|
+
connectWalletconnect = async (_chains: Chain[], _options?: Todo): Promise<void> => {
|
|
701
685
|
throw new SwapKitError("core_wallet_walletconnect_not_installed");
|
|
702
686
|
};
|
|
703
687
|
// biome-ignore lint/suspicious/useAwait: Extended methods
|
|
@@ -737,7 +721,7 @@ export class SwapKitCore<T = ""> {
|
|
|
737
721
|
return { gas_rate: "0", router: "", address: "", halted: false, chain };
|
|
738
722
|
|
|
739
723
|
default: {
|
|
740
|
-
const inboundData = await
|
|
724
|
+
const inboundData = await SwapKitApi.getInboundAddresses({ stagenet: this.stagenet });
|
|
741
725
|
const chainAddressData = inboundData.find((item) => item.chain === chain);
|
|
742
726
|
|
|
743
727
|
if (!chainAddressData) throw new SwapKitError("core_inbound_data_not_found");
|
|
@@ -754,13 +738,13 @@ export class SwapKitCore<T = ""> {
|
|
|
754
738
|
balance,
|
|
755
739
|
walletType,
|
|
756
740
|
...rest
|
|
757
|
-
}: AddChainWalletParams<
|
|
741
|
+
}: AddChainWalletParams<Todo>) => {
|
|
758
742
|
this.connectedChains[chain as Chain] = {
|
|
759
743
|
address: address || "",
|
|
760
744
|
balance: balance || [],
|
|
761
745
|
walletType: walletType || "unknown",
|
|
762
746
|
};
|
|
763
|
-
this.connectedWallets[chain as Chain] = { ...rest } as
|
|
747
|
+
this.connectedWallets[chain as Chain] = { ...rest } as Todo;
|
|
764
748
|
};
|
|
765
749
|
|
|
766
750
|
#approve = async <T = string>({
|
|
@@ -781,11 +765,15 @@ export class SwapKitCore<T = ""> {
|
|
|
781
765
|
const walletMethods = this.connectedWallets[chain as EVMChain];
|
|
782
766
|
const walletAction = type === "checkOnly" ? walletMethods?.isApproved : walletMethods?.approve;
|
|
783
767
|
|
|
784
|
-
if (!walletAction)
|
|
768
|
+
if (!walletAction) {
|
|
769
|
+
throw new SwapKitError("core_wallet_connection_not_found");
|
|
770
|
+
}
|
|
785
771
|
|
|
786
772
|
const from = this.getAddress(chain);
|
|
787
773
|
|
|
788
|
-
if (!(address && from))
|
|
774
|
+
if (!(address && from)) {
|
|
775
|
+
throw new SwapKitError("core_approve_asset_address_or_from_not_found");
|
|
776
|
+
}
|
|
789
777
|
|
|
790
778
|
const spenderAddress =
|
|
791
779
|
contractAddress || ((await this.#getInboundDataByChain(chain)).router as string);
|
|
@@ -808,11 +796,11 @@ export class SwapKitCore<T = ""> {
|
|
|
808
796
|
feeOptionKey?: FeeOption;
|
|
809
797
|
}) => {
|
|
810
798
|
const {
|
|
811
|
-
gas_rate,
|
|
799
|
+
gas_rate = "0",
|
|
812
800
|
router,
|
|
813
801
|
address: poolAddress,
|
|
814
802
|
} = await this.#getInboundDataByChain(assetValue.chain);
|
|
815
|
-
const feeRate =
|
|
803
|
+
const feeRate = Number.parseInt(gas_rate) * gasFeeMultiplier[feeOptionKey];
|
|
816
804
|
|
|
817
805
|
return this.deposit({
|
|
818
806
|
assetValue,
|
|
@@ -820,7 +808,7 @@ export class SwapKitCore<T = ""> {
|
|
|
820
808
|
memo,
|
|
821
809
|
router,
|
|
822
810
|
feeRate,
|
|
823
|
-
})
|
|
811
|
+
}) as Promise<string>;
|
|
824
812
|
};
|
|
825
813
|
|
|
826
814
|
#thorchainTransfer = async ({
|
|
@@ -830,7 +818,7 @@ export class SwapKitCore<T = ""> {
|
|
|
830
818
|
assetValue: AssetValue;
|
|
831
819
|
memo: string;
|
|
832
820
|
}) => {
|
|
833
|
-
const mimir = await
|
|
821
|
+
const mimir = await SwapKitApi.getMimirInfo({ stagenet: this.stagenet });
|
|
834
822
|
|
|
835
823
|
// check if trading is halted or not
|
|
836
824
|
if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {
|
|
@@ -847,7 +835,7 @@ export class SwapKitCore<T = ""> {
|
|
|
847
835
|
assetValue: AssetValue;
|
|
848
836
|
memo: string;
|
|
849
837
|
}) => {
|
|
850
|
-
const mimir = await
|
|
838
|
+
const mimir = await SwapKitApi.getMimirInfo({ type: "mayachain", stagenet: this.stagenet });
|
|
851
839
|
|
|
852
840
|
// check if trading is halted or not
|
|
853
841
|
if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Chain, ChainToExplorerUrl } from "@swapkit/types";
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function getExplorerTxUrl({ chain, txHash }: { txHash: string; chain: Chain }) {
|
|
4
4
|
const baseUrl = ChainToExplorerUrl[chain];
|
|
5
5
|
|
|
6
6
|
switch (chain) {
|
|
7
7
|
case Chain.Binance:
|
|
8
8
|
case Chain.Maya:
|
|
9
9
|
case Chain.Kujira:
|
|
10
|
+
case Chain.Cosmos:
|
|
10
11
|
case Chain.THORChain:
|
|
11
12
|
return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash.slice(2) : txHash}`;
|
|
12
13
|
|
|
@@ -19,9 +20,6 @@ export const getExplorerTxUrl = ({ chain, txHash }: { txHash: string; chain: Cha
|
|
|
19
20
|
case Chain.Polygon:
|
|
20
21
|
return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash : `0x${txHash}`}`;
|
|
21
22
|
|
|
22
|
-
case Chain.Cosmos:
|
|
23
|
-
return `${baseUrl}/transactions/${txHash}`;
|
|
24
|
-
|
|
25
23
|
case Chain.Litecoin:
|
|
26
24
|
case Chain.Bitcoin:
|
|
27
25
|
case Chain.BitcoinCash:
|
|
@@ -31,33 +29,10 @@ export const getExplorerTxUrl = ({ chain, txHash }: { txHash: string; chain: Cha
|
|
|
31
29
|
default:
|
|
32
30
|
throw new Error(`Unsupported chain: ${chain}`);
|
|
33
31
|
}
|
|
34
|
-
}
|
|
32
|
+
}
|
|
35
33
|
|
|
36
|
-
export
|
|
34
|
+
export function getExplorerAddressUrl({ chain, address }: { address: string; chain: Chain }) {
|
|
37
35
|
const baseUrl = ChainToExplorerUrl[chain];
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
case Chain.Avalanche:
|
|
42
|
-
case Chain.Binance:
|
|
43
|
-
case Chain.BinanceSmartChain:
|
|
44
|
-
case Chain.Bitcoin:
|
|
45
|
-
case Chain.BitcoinCash:
|
|
46
|
-
case Chain.Dogecoin:
|
|
47
|
-
case Chain.Ethereum:
|
|
48
|
-
case Chain.Kujira:
|
|
49
|
-
case Chain.Litecoin:
|
|
50
|
-
case Chain.Maya:
|
|
51
|
-
case Chain.Optimism:
|
|
52
|
-
case Chain.Polkadot:
|
|
53
|
-
case Chain.Polygon:
|
|
54
|
-
case Chain.THORChain:
|
|
55
|
-
return `${baseUrl}/address/${address}`;
|
|
56
|
-
|
|
57
|
-
case Chain.Cosmos:
|
|
58
|
-
return `${baseUrl}/account/${address}`;
|
|
59
|
-
|
|
60
|
-
default:
|
|
61
|
-
throw new Error(`Unsupported chain: ${chain}`);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
37
|
+
return `${baseUrl}/address/${address}`;
|
|
38
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -135,8 +135,8 @@ export type SwapWithRouteParams = {
|
|
|
135
135
|
streamSwap?: boolean;
|
|
136
136
|
};
|
|
137
137
|
|
|
138
|
-
type ApisType = { [key in UTXOChain]?: string |
|
|
139
|
-
[key in EVMChain]?: string |
|
|
138
|
+
type ApisType = { [key in UTXOChain]?: string | Todo } & {
|
|
139
|
+
[key in EVMChain]?: string | Todo;
|
|
140
140
|
} & {
|
|
141
141
|
[key in CosmosChain]?: string;
|
|
142
142
|
};
|