@swapkit/core 1.0.0-rc.100 → 1.0.0-rc.103

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 CHANGED
@@ -1,26 +1,26 @@
1
1
  {
2
2
  "author": "swapkit-oss",
3
3
  "dependencies": {
4
- "@swapkit/helpers": "1.0.0-rc.72",
5
- "@swapkit/types": "1.0.0-rc.38"
4
+ "@swapkit/helpers": "1.0.0-rc.74",
5
+ "@swapkit/types": "1.0.0-rc.40"
6
6
  },
7
7
  "description": "SwapKit Lib core",
8
8
  "devDependencies": {
9
9
  "@vitest/coverage-istanbul": "1.3.1",
10
10
  "vite": "5.1.3",
11
11
  "vitest": "1.3.1",
12
- "@swapkit/tokens": "1.0.0-rc.35",
13
- "@swapkit/toolbox-cosmos": "1.0.0-rc.83",
14
- "@swapkit/toolbox-evm": "1.0.0-rc.78",
15
- "@swapkit/toolbox-substrate": "1.0.0-rc.6",
16
- "@swapkit/toolbox-utxo": "1.0.0-rc.77"
12
+ "@swapkit/tokens": "1.0.0-rc.36",
13
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.85",
14
+ "@swapkit/toolbox-evm": "1.0.0-rc.80",
15
+ "@swapkit/toolbox-substrate": "1.0.0-rc.9",
16
+ "@swapkit/toolbox-utxo": "1.0.0-rc.80"
17
17
  },
18
18
  "peerDependencies": {
19
- "@swapkit/tokens": "1.0.0-rc.35",
20
- "@swapkit/toolbox-cosmos": "1.0.0-rc.83",
21
- "@swapkit/toolbox-evm": "1.0.0-rc.78",
22
- "@swapkit/toolbox-substrate": "1.0.0-rc.6",
23
- "@swapkit/toolbox-utxo": "1.0.0-rc.77"
19
+ "@swapkit/tokens": "1.0.0-rc.36",
20
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.85",
21
+ "@swapkit/toolbox-evm": "1.0.0-rc.80",
22
+ "@swapkit/toolbox-substrate": "1.0.0-rc.9",
23
+ "@swapkit/toolbox-utxo": "1.0.0-rc.80"
24
24
  },
25
25
  "exports": {
26
26
  ".": {
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "type": "module",
47
47
  "types": "./dist/index.d.ts",
48
- "version": "1.0.0-rc.100",
48
+ "version": "1.0.0-rc.103",
49
49
  "scripts": {
50
50
  "build": "NODE_OPTIONS=--max_old_space_size=16384 vite build",
51
51
  "clean": "rm -rf dist vite.config.ts.* node_modules",
@@ -1,79 +1,84 @@
1
- import { Chain, ChainToExplorerUrl, CosmosChains, EVMChains, UTXOChains } from "@swapkit/types";
1
+ import {
2
+ Chain,
3
+ ChainToExplorerUrl,
4
+ CosmosChains,
5
+ EVMChains,
6
+ SubstrateChains,
7
+ UTXOChains,
8
+ } from "@swapkit/types";
2
9
  import { describe, expect, test } from "vitest";
3
10
  import { getExplorerAddressUrl, getExplorerTxUrl } from "../helpers/explorerUrls.ts";
4
11
 
5
12
  describe("Explorer URLs", () => {
6
- for (const chain of CosmosChains.filter((c) => c !== Chain.Cosmos)) {
7
- test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
8
- expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
9
- `${ChainToExplorerUrl[chain]}/tx/123456789`,
10
- );
13
+ describe("CosmosChains", () => {
14
+ for (const chain of CosmosChains.filter((c) => c !== Chain.Cosmos)) {
15
+ test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
16
+ expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
17
+ `${ChainToExplorerUrl[chain]}/tx/123456789`,
18
+ );
11
19
 
12
- expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
13
- `${ChainToExplorerUrl[chain]}/address/asdfg`,
14
- );
15
- });
16
- }
20
+ expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
21
+ `${ChainToExplorerUrl[chain]}/address/asdfg`,
22
+ );
23
+ });
24
+ }
17
25
 
18
- for (const chain of EVMChains) {
19
- test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
20
- expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
21
- `${ChainToExplorerUrl[chain]}/tx/0x123456789`,
26
+ test(`getExplorerTxUrl returns correct URL for ${Chain.Cosmos}`, () => {
27
+ expect(getExplorerTxUrl({ chain: Chain.Cosmos, txHash: "0x123456789" })).toBe(
28
+ `${ChainToExplorerUrl[Chain.Cosmos]}/transactions/0x123456789`,
22
29
  );
23
30
 
24
- expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
25
- `${ChainToExplorerUrl[chain]}/address/asdfg`,
31
+ expect(getExplorerAddressUrl({ chain: Chain.Cosmos, address: "asdfg" })).toBe(
32
+ `${ChainToExplorerUrl[Chain.Cosmos]}/account/asdfg`,
26
33
  );
27
34
  });
28
- }
35
+ });
29
36
 
30
- for (const chain of UTXOChains.filter((c) => c !== Chain.Dash)) {
31
- test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
32
- expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
33
- `${ChainToExplorerUrl[chain]}/transaction/0x123456789`,
34
- );
37
+ describe("EVMChains & SubstrateChains", () => {
38
+ for (const chain of [...EVMChains, Chain.Polkadot]) {
39
+ test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
40
+ expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
41
+ `${ChainToExplorerUrl[chain]}/tx/0x123456789`,
42
+ );
43
+
44
+ expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
45
+ `${ChainToExplorerUrl[chain]}/address/asdfg`,
46
+ );
47
+ });
48
+ }
35
49
 
36
- expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
37
- `${ChainToExplorerUrl[chain]}/address/asdfg`,
50
+ test("getExplorerTxUrl adds 0x for EVM like chains", () => {
51
+ expect(getExplorerTxUrl({ chain: Chain.Ethereum, txHash: "12345" })).toBe(
52
+ "https://etherscan.io/tx/0x12345",
38
53
  );
39
54
  });
40
- }
41
-
42
- test(`getExplorerTxUrl returns correct URL for ${Chain.Cosmos}`, () => {
43
- expect(getExplorerTxUrl({ chain: Chain.Cosmos, txHash: "0x123456789" })).toBe(
44
- `${ChainToExplorerUrl[Chain.Cosmos]}/transactions/0x123456789`,
45
- );
46
-
47
- expect(getExplorerAddressUrl({ chain: Chain.Cosmos, address: "asdfg" })).toBe(
48
- `${ChainToExplorerUrl[Chain.Cosmos]}/account/asdfg`,
49
- );
50
55
  });
51
56
 
52
- test("getExplorerTxUrl throws Error for unsupported Chain", () => {
53
- expect(() =>
54
- getExplorerTxUrl({ chain: "unsupported" as Chain, txHash: "0x12345" }),
55
- ).toThrowError("Unsupported chain: unsupported");
56
- });
57
+ describe("UTXOChains", () => {
58
+ for (const chain of UTXOChains.filter((c) => c !== Chain.Dash)) {
59
+ test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
60
+ expect(getExplorerTxUrl({ chain, txHash: "0x123456789" })).toBe(
61
+ `${ChainToExplorerUrl[chain]}/transaction/0x123456789`,
62
+ );
57
63
 
58
- test("getExplorerAddressUrl throws Error for unsupported Chain", () => {
59
- expect(() =>
60
- getExplorerAddressUrl({ chain: "unsupported" as Chain, address: "asdfg" }),
61
- ).toThrowError("Unsupported chain: unsupported");
62
- });
63
- test("getExplorerTxUrl adds 0x for EVM like chains", () => {
64
- expect(getExplorerTxUrl({ chain: Chain.Ethereum, txHash: "12345" })).toBe(
65
- "https://etherscan.io/tx/0x12345",
66
- );
64
+ expect(getExplorerAddressUrl({ chain, address: "asdfg" })).toBe(
65
+ `${ChainToExplorerUrl[chain]}/address/asdfg`,
66
+ );
67
+ });
68
+ }
67
69
  });
68
70
 
69
- test("getExplorerTxUrl returns correct URL for Cosmos", () => {
70
- expect(getExplorerTxUrl({ chain: Chain.Cosmos, txHash: "pqrst" })).toBe(
71
- "https://cosmos.bigdipper.live/transactions/pqrst",
72
- );
73
- });
74
- test("getExplorerAddressUrl returns correct URL for Cosmos", () => {
75
- expect(getExplorerAddressUrl({ chain: Chain.Cosmos, address: "zabcd" })).toBe(
76
- "https://cosmos.bigdipper.live/account/zabcd",
77
- );
71
+ describe("Unsupported chains", () => {
72
+ test("getExplorerTxUrl throws Error for unsupported Chain", () => {
73
+ expect(() =>
74
+ getExplorerTxUrl({ chain: "unsupported" as Chain, txHash: "0x12345" }),
75
+ ).toThrowError("Unsupported chain: unsupported");
76
+ });
77
+
78
+ test("getExplorerAddressUrl throws Error for unsupported Chain", () => {
79
+ expect(() =>
80
+ getExplorerAddressUrl({ chain: "unsupported" as Chain, address: "asdfg" }),
81
+ ).toThrowError("Unsupported chain: unsupported");
82
+ });
78
83
  });
79
84
  });
@@ -1,18 +1,22 @@
1
1
  import { AssetValue, SwapKitError } from "@swapkit/helpers";
2
2
  import { Chain } from "@swapkit/types";
3
+ import {
4
+ getExplorerAddressUrl as getAddressUrl,
5
+ getExplorerTxUrl as getTxUrl,
6
+ } from "../helpers/explorerUrls.ts";
3
7
  import type {
4
8
  ChainWallet,
5
9
  ConnectWalletParamsLocal as ConnectWalletParams,
6
10
  SwapWithRouteParams,
7
11
  } from "../types.ts";
8
12
 
9
- type ProviderName = "thorchain" | "chainflip" | "mayachain";
10
- enum ApproveMode {
13
+ export type ProviderName = "thorchain" | "chainflip" | "mayachain";
14
+ export enum ApproveMode {
11
15
  Approve = "approve",
12
16
  CheckOnly = "checkOnly",
13
17
  }
14
18
 
15
- type ApproveReturnType<T extends ApproveMode> = T extends "checkOnly"
19
+ export type ApproveReturnType<T extends ApproveMode> = T extends "checkOnly"
16
20
  ? Promise<boolean>
17
21
  : Promise<string>;
18
22
 
@@ -33,7 +37,7 @@ export type SwapParams = (SwapWithRouteParams | GenericSwapParams) & {
33
37
  };
34
38
  };
35
39
 
36
- type SwapKitReturnType = SwapKitProviders & {
40
+ export type SwapKitReturnType = SwapKitProviders & {
37
41
  getAddress: (chain: Chain) => string;
38
42
  getWallet: (chain: Chain) => ChainWallet<Chain> | undefined;
39
43
  getWalletWithBalance: (
@@ -41,6 +45,8 @@ type SwapKitReturnType = SwapKitProviders & {
41
45
  potentialScamFilter?: boolean,
42
46
  ) => Promise<ChainWallet<Chain>>;
43
47
  getBalance: (chain: Chain, potentialScamFilter?: boolean) => AssetValue[];
48
+ getExplorerTxUrl: (chain: Chain, txHash: string) => string;
49
+ getExplorerAddressUrl: (chain: Chain, address: string) => string;
44
50
  swap: (params: SwapParams) => Promise<string>;
45
51
  validateAddress: (params: { address: string; chain: Chain }) =>
46
52
  | boolean
@@ -53,9 +59,9 @@ type SwapKitReturnType = SwapKitProviders & {
53
59
  ) => boolean | Promise<boolean>;
54
60
  };
55
61
 
56
- type Wallets = { [K in Chain]?: ChainWallet<K> };
57
- type AvailableProviders<T> = T | { [K in ProviderName]?: ProviderMethods };
58
- type ProviderMethods = {
62
+ export type Wallets = { [K in Chain]?: ChainWallet<K> };
63
+ export type AvailableProviders<T> = T | { [K in ProviderName]?: ProviderMethods };
64
+ export type ProviderMethods = {
59
65
  swap: (swapParams: SwapParams) => Promise<string>;
60
66
  [key: string]: any;
61
67
  };
@@ -65,20 +71,9 @@ export type SwapKitProvider = ({ wallets, stagenet }: { wallets: Wallets; stagen
65
71
  methods: ProviderMethods;
66
72
  };
67
73
 
68
- type BaseSwapkitWalletConnectParams = {
69
- chains: Chain[];
70
- };
71
-
72
- type KeystoreWalletConnectParams = BaseSwapkitWalletConnectParams & {
73
- phrase: string;
74
- index?: number;
75
- };
76
-
77
- type WalletConnectParams = KeystoreWalletConnectParams;
78
-
79
- type SwapKitWallet = {
74
+ export type SwapKitWallet = {
80
75
  connectMethodName: string;
81
- connect: (params: ConnectWalletParams) => (connectParams: WalletConnectParams) => void;
76
+ connect: (params: ConnectWalletParams) => (connectParams: any) => void;
82
77
  };
83
78
 
84
79
  export function SwapKit<
@@ -98,7 +93,7 @@ export function SwapKit<
98
93
  config?: Record<string, any>;
99
94
  apis: Record<string, any>;
100
95
  rpcUrls: Record<string, any>;
101
- }): SwapKitReturnType & ConnectWalletMethods {
96
+ }): SwapKitReturnType & ConnectWalletMethods & AvailableProviders<ExtendedProviders> {
102
97
  const connectedWallets: Wallets = {};
103
98
  const availableProviders: AvailableProviders<ExtendedProviders> = {};
104
99
 
@@ -197,6 +192,12 @@ export function SwapKit<
197
192
  function getBalance(chain: Chain) {
198
193
  return getWallet(chain)?.balance || [];
199
194
  }
195
+ function getExplorerTxUrl(chain: Chain, txHash: string) {
196
+ return getTxUrl({ chain, txHash });
197
+ }
198
+ function getExplorerAddressUrl(chain: Chain, address: string) {
199
+ return getAddressUrl({ chain, address });
200
+ }
200
201
  /**
201
202
  * TODO: Figure out validation without connecting to wallet
202
203
  */
@@ -244,6 +245,8 @@ export function SwapKit<
244
245
  approveAssetValue,
245
246
  getAddress,
246
247
  getBalance,
248
+ getExplorerAddressUrl,
249
+ getExplorerTxUrl,
247
250
  getWallet,
248
251
  getWalletWithBalance,
249
252
  isAssetValueApproved,
@@ -15,6 +15,7 @@ export const getExplorerTxUrl = ({ chain, txHash }: { txHash: string; chain: Cha
15
15
  case Chain.BinanceSmartChain:
16
16
  case Chain.Ethereum:
17
17
  case Chain.Optimism:
18
+ case Chain.Polkadot:
18
19
  case Chain.Polygon:
19
20
  return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash : `0x${txHash}`}`;
20
21
 
@@ -48,6 +49,7 @@ export const getExplorerAddressUrl = ({ chain, address }: { address: string; cha
48
49
  case Chain.Litecoin:
49
50
  case Chain.Maya:
50
51
  case Chain.Optimism:
52
+ case Chain.Polkadot:
51
53
  case Chain.Polygon:
52
54
  case Chain.THORChain:
53
55
  return `${baseUrl}/address/${address}`;