@swapkit/core 1.0.0-rc.110 → 1.0.0-rc.112

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.74",
5
- "@swapkit/types": "1.0.0-rc.40"
4
+ "@swapkit/types": "1.0.0-rc.42",
5
+ "@swapkit/helpers": "1.0.0-rc.76"
6
6
  },
7
7
  "description": "SwapKit Lib core",
8
8
  "devDependencies": {
9
9
  "@vitest/coverage-istanbul": "1.3.1",
10
- "vite": "5.1.3",
10
+ "vite": "5.1.6",
11
11
  "vitest": "1.3.1",
12
- "@swapkit/tokens": "1.0.0-rc.36",
13
- "@swapkit/toolbox-cosmos": "1.0.0-rc.91",
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.82"
12
+ "@swapkit/tokens": "1.0.0-rc.38",
13
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.93",
14
+ "@swapkit/toolbox-evm": "1.0.0-rc.82",
15
+ "@swapkit/toolbox-substrate": "1.0.0-rc.11",
16
+ "@swapkit/toolbox-utxo": "1.0.0-rc.84"
17
17
  },
18
18
  "peerDependencies": {
19
- "@swapkit/tokens": "1.0.0-rc.36",
20
- "@swapkit/toolbox-cosmos": "1.0.0-rc.91",
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.82"
19
+ "@swapkit/tokens": "1.0.0-rc.38",
20
+ "@swapkit/toolbox-evm": "1.0.0-rc.82",
21
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.93",
22
+ "@swapkit/toolbox-utxo": "1.0.0-rc.84",
23
+ "@swapkit/toolbox-substrate": "1.0.0-rc.11"
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.110",
48
+ "version": "1.0.0-rc.112",
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",
@@ -10,7 +10,8 @@ import type {
10
10
  SwapWithRouteParams,
11
11
  } from "../types.ts";
12
12
 
13
- export type ProviderName = "thorchain" | "chainflip" | "mayachain";
13
+ export type PluginName = "thorchain" | "chainflip" | "mayachain";
14
+
14
15
  export enum ApproveMode {
15
16
  Approve = "approve",
16
17
  CheckOnly = "checkOnly",
@@ -20,8 +21,8 @@ export type ApproveReturnType<T extends ApproveMode> = T extends "checkOnly"
20
21
  ? Promise<boolean>
21
22
  : Promise<string>;
22
23
 
23
- type SwapKitProviders = {
24
- [K in ProviderName]?: ProviderMethods;
24
+ type SwapKitPlugins = {
25
+ [K in PluginName]?: ProviderMethods;
25
26
  };
26
27
 
27
28
  type GenericSwapParams = {
@@ -32,12 +33,12 @@ type GenericSwapParams = {
32
33
 
33
34
  export type SwapParams = (SwapWithRouteParams | GenericSwapParams) & {
34
35
  provider?: {
35
- name: ProviderName;
36
+ name: PluginName;
36
37
  config: Record<string, any>;
37
38
  };
38
39
  };
39
40
 
40
- export type SwapKitReturnType = SwapKitProviders & {
41
+ export type SwapKitReturnType = SwapKitPlugins & {
41
42
  getAddress: (chain: Chain) => string;
42
43
  getWallet: (chain: Chain) => ChainWallet<Chain> | undefined;
43
44
  getWalletWithBalance: (
@@ -60,14 +61,14 @@ export type SwapKitReturnType = SwapKitProviders & {
60
61
  };
61
62
 
62
63
  export type Wallets = { [K in Chain]?: ChainWallet<K> };
63
- export type AvailableProviders<T> = T | { [K in ProviderName]?: ProviderMethods };
64
+ export type AvailableProviders<T> = T | { [K in PluginName]?: ProviderMethods };
64
65
  export type ProviderMethods = {
65
66
  swap: (swapParams: SwapParams) => Promise<string>;
66
67
  [key: string]: any;
67
68
  };
68
69
 
69
- export type SwapKitProvider = ({ wallets, stagenet }: { wallets: Wallets; stagenet?: boolean }) => {
70
- name: ProviderName;
70
+ export type SwapKitPlugin = ({ wallets, stagenet }: { wallets: Wallets; stagenet?: boolean }) => {
71
+ name: PluginName;
71
72
  methods: ProviderMethods;
72
73
  };
73
74
 
@@ -82,12 +83,12 @@ export function SwapKit<
82
83
  >({
83
84
  stagenet,
84
85
  wallets,
85
- providers,
86
+ plugins,
86
87
  config = {},
87
88
  apis,
88
89
  rpcUrls,
89
90
  }: {
90
- providers: SwapKitProvider[];
91
+ plugins: SwapKitPlugin[];
91
92
  stagenet: boolean;
92
93
  wallets: SwapKitWallet[];
93
94
  config?: Record<string, any>;
@@ -95,12 +96,12 @@ export function SwapKit<
95
96
  rpcUrls: Record<string, any>;
96
97
  }): SwapKitReturnType & ConnectWalletMethods & AvailableProviders<ExtendedProviders> {
97
98
  const connectedWallets: Wallets = {};
98
- const availableProviders: AvailableProviders<ExtendedProviders> = {};
99
+ const availablePlugins: AvailableProviders<ExtendedProviders> = {};
99
100
 
100
- for (const provider of providers) {
101
- const { name, methods } = provider({ wallets: connectedWallets, stagenet });
101
+ for (const plugin of plugins) {
102
+ const { name, methods } = plugin({ wallets: connectedWallets, stagenet });
102
103
 
103
- availableProviders[name] = methods;
104
+ availablePlugins[name] = methods;
104
105
  }
105
106
 
106
107
  const connectWalletMethods = wallets.reduce((acc, wallet) => {
@@ -118,19 +119,16 @@ export function SwapKit<
118
119
  * @Private
119
120
  * Internal helpers
120
121
  */
121
- function getProvider(providerName?: ProviderName) {
122
- const provider =
123
- (availableProviders as SwapKitProviders)[providerName as ProviderName] ||
124
- Object.values(availableProviders)[0];
125
-
126
- if (!provider) {
127
- throw new SwapKitError(
128
- "core_swap_provider_not_found",
129
- "Could not find the requested provider",
130
- );
122
+ function getSwapKitPlugin(pluginName?: PluginName) {
123
+ const plugin =
124
+ (availablePlugins as SwapKitPlugins)[pluginName as PluginName] ||
125
+ Object.values(availablePlugins)[0];
126
+
127
+ if (!plugin) {
128
+ throw new SwapKitError("core_plugin_not_found", "Could not find the requested plugin");
131
129
  }
132
130
 
133
- return provider;
131
+ return plugin;
134
132
  }
135
133
 
136
134
  function addChain(connectWallet: ChainWallet<Chain>) {
@@ -233,14 +231,14 @@ export function SwapKit<
233
231
  return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });
234
232
  }
235
233
 
236
- function swap({ provider: providerConfig, ...rest }: SwapParams) {
237
- const provider = getProvider(providerConfig?.name);
234
+ function swap({ provider, ...rest }: SwapParams) {
235
+ const plugin = getSwapKitPlugin(provider?.name);
238
236
 
239
- return provider.swap({ provider: providerConfig, ...rest });
237
+ return plugin.swap({ provider, ...rest });
240
238
  }
241
239
 
242
240
  return {
243
- ...availableProviders,
241
+ ...availablePlugins,
244
242
  ...connectWalletMethods,
245
243
  approveAssetValue,
246
244
  getAddress,
package/src/client/old.ts CHANGED
@@ -35,7 +35,8 @@ import { lowercasedContractAbiMapping } from "../aggregator/contracts/index.ts";
35
35
  import { getSwapInParams } from "../aggregator/getSwapParams.ts";
36
36
 
37
37
  import { getExplorerAddressUrl, getExplorerTxUrl } from "../helpers/explorerUrls.ts";
38
- import { getInboundData, getMimirData } from "../helpers/thornode.ts";
38
+ import { getMayaMimirData } from "../helpers/mayanode.js";
39
+ import { getThorInboundData, getThorMimirData } from "../helpers/thornode.ts";
39
40
  import type {
40
41
  CoreTxParams,
41
42
  EVMWallet,
@@ -331,7 +332,8 @@ export class SwapKitCore<T = ""> {
331
332
  getChecksumAddressFromAsset({ chain, symbol, ticker }, chain),
332
333
  assetValue.getBaseValue("string"),
333
334
  params.memo,
334
- rest.expiration || parseInt(`${(new Date().getTime() + 15 * 60 * 1000) / 1000}`),
335
+ rest.expiration ||
336
+ Number.parseInt(`${(new Date().getTime() + 15 * 60 * 1000) / 1000}`),
335
337
  ],
336
338
  txOverrides: {
337
339
  from: params.from,
@@ -347,7 +349,8 @@ export class SwapKitCore<T = ""> {
347
349
  }
348
350
  }
349
351
  } catch (error: any) {
350
- const errorMessage = error?.message.toLowerCase();
352
+ const errorMessage =
353
+ typeof error === "string" ? error.toLowerCase() : error?.message.toLowerCase();
351
354
  const isInsufficientFunds = errorMessage?.includes("insufficient funds");
352
355
  const isGas = errorMessage?.includes("gas");
353
356
  const isServer = errorMessage?.includes("server");
@@ -613,6 +616,15 @@ export class SwapKitCore<T = ""> {
613
616
  memo: getMemoFor(MemoType.THORNAME_REGISTER, param),
614
617
  });
615
618
 
619
+ registerMayaname = ({
620
+ assetValue,
621
+ ...param
622
+ }: ThornameRegisterParam & { assetValue: AssetValue }) =>
623
+ this.#mayachainTransfer({
624
+ assetValue,
625
+ memo: getMemoFor(MemoType.THORNAME_REGISTER, param),
626
+ });
627
+
616
628
  extend = ({ wallets, config, apis = {}, rpcUrls = {} }: ExtendParams<T>) => {
617
629
  try {
618
630
  for (const wallet of wallets) {
@@ -676,39 +688,39 @@ export class SwapKitCore<T = ""> {
676
688
  /**
677
689
  * Wallet connection methods
678
690
  */
679
- // biome-ignore lint/nursery/useAwait: Extended methods
691
+ // biome-ignore lint/suspicious/useAwait: Extended methods
680
692
  connectXDEFI = async (_chains: Chain[]): Promise<void> => {
681
693
  throw new SwapKitError("core_wallet_xdefi_not_installed");
682
694
  };
683
- // biome-ignore lint/nursery/useAwait: Extended methods
695
+ // biome-ignore lint/suspicious/useAwait: Extended methods
684
696
  connectEVMWallet = async (_chains: Chain[] | Chain, _wallet: EVMWalletOptions): Promise<void> => {
685
697
  throw new SwapKitError("core_wallet_evmwallet_not_installed");
686
698
  };
687
- // biome-ignore lint/nursery/useAwait: Extended methods
699
+ // biome-ignore lint/suspicious/useAwait: Extended methods
688
700
  connectWalletconnect = async (_chains: Chain[], _options?: any): Promise<void> => {
689
701
  throw new SwapKitError("core_wallet_walletconnect_not_installed");
690
702
  };
691
- // biome-ignore lint/nursery/useAwait: Extended methods
703
+ // biome-ignore lint/suspicious/useAwait: Extended methods
692
704
  connectKeepkey = async (_chains: Chain[], _derivationPath: number[][]): Promise<string> => {
693
705
  throw new SwapKitError("core_wallet_keepkey_not_installed");
694
706
  };
695
- // biome-ignore lint/nursery/useAwait: Extended methods
707
+ // biome-ignore lint/suspicious/useAwait: Extended methods
696
708
  connectKeystore = async (_chains: Chain[], _phrase: string): Promise<void> => {
697
709
  throw new SwapKitError("core_wallet_keystore_not_installed");
698
710
  };
699
- // biome-ignore lint/nursery/useAwait: Extended methods
711
+ // biome-ignore lint/suspicious/useAwait: Extended methods
700
712
  connectLedger = async (_chains: Chain, _derivationPath: number[]): Promise<void> => {
701
713
  throw new SwapKitError("core_wallet_ledger_not_installed");
702
714
  };
703
- // biome-ignore lint/nursery/useAwait: Extended methods
715
+ // biome-ignore lint/suspicious/useAwait: Extended methods
704
716
  connectTrezor = async (_chains: Chain, _derivationPath: number[]): Promise<void> => {
705
717
  throw new SwapKitError("core_wallet_trezor_not_installed");
706
718
  };
707
- // biome-ignore lint/nursery/useAwait: Extended methods
719
+ // biome-ignore lint/suspicious/useAwait: Extended methods
708
720
  connectKeplr = async (_chain: Chain): Promise<void> => {
709
721
  throw new SwapKitError("core_wallet_keplr_not_installed");
710
722
  };
711
- // biome-ignore lint/nursery/useAwait: Extended methods
723
+ // biome-ignore lint/suspicious/useAwait: Extended methods
712
724
  connectOkx = async (_chains: Chain[]): Promise<void> => {
713
725
  throw new SwapKitError("core_wallet_okx_not_installed");
714
726
  };
@@ -725,7 +737,7 @@ export class SwapKitCore<T = ""> {
725
737
  return { gas_rate: "0", router: "", address: "", halted: false, chain };
726
738
 
727
739
  default: {
728
- const inboundData = await getInboundData(this.stagenet);
740
+ const inboundData = await getThorInboundData(this.stagenet);
729
741
  const chainAddressData = inboundData.find((item) => item.chain === chain);
730
742
 
731
743
  if (!chainAddressData) throw new SwapKitError("core_inbound_data_not_found");
@@ -800,7 +812,7 @@ export class SwapKitCore<T = ""> {
800
812
  router,
801
813
  address: poolAddress,
802
814
  } = await this.#getInboundDataByChain(assetValue.chain);
803
- const feeRate = (parseInt(gas_rate) || 0) * gasFeeMultiplier[feeOptionKey];
815
+ const feeRate = (Number.parseInt(gas_rate) || 0) * gasFeeMultiplier[feeOptionKey];
804
816
 
805
817
  return this.deposit({
806
818
  assetValue,
@@ -818,7 +830,24 @@ export class SwapKitCore<T = ""> {
818
830
  assetValue: AssetValue;
819
831
  memo: string;
820
832
  }) => {
821
- const mimir = await getMimirData(this.stagenet);
833
+ const mimir = await getThorMimirData(this.stagenet);
834
+
835
+ // check if trading is halted or not
836
+ if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {
837
+ throw new SwapKitError("core_chain_halted");
838
+ }
839
+
840
+ return this.deposit({ assetValue, recipient: "", memo });
841
+ };
842
+
843
+ #mayachainTransfer = async ({
844
+ memo,
845
+ assetValue,
846
+ }: {
847
+ assetValue: AssetValue;
848
+ memo: string;
849
+ }) => {
850
+ const mimir = await getMayaMimirData(this.stagenet);
822
851
 
823
852
  // check if trading is halted or not
824
853
  if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {
@@ -0,0 +1,31 @@
1
+ import { RequestClient } from "@swapkit/helpers";
2
+ import type { Chain } from "@swapkit/types";
3
+ import { ApiUrl } from "@swapkit/types";
4
+
5
+ type InboundAddressData = {
6
+ address: string;
7
+ chain: Chain;
8
+ chain_lp_actions_paused: boolean;
9
+ chain_trading_paused: boolean;
10
+ dust_threshold: string;
11
+ gas_rate: string;
12
+ gas_rate_units: string;
13
+ global_trading_paused: boolean;
14
+ halted: boolean;
15
+ outbound_fee: string;
16
+ outbound_tx_size: string;
17
+ pub_key: string;
18
+ router: string;
19
+ }[];
20
+
21
+ export const getMayaInboundData = (stagenet: boolean) => {
22
+ const baseUrl = stagenet ? ApiUrl.MayanodeStagenet : ApiUrl.MayanodeMainnet;
23
+
24
+ return RequestClient.get<InboundAddressData>(`${baseUrl}/mayachain/inbound_addresses`);
25
+ };
26
+
27
+ export const getMayaMimirData = (stagenet: boolean) => {
28
+ const baseUrl = stagenet ? ApiUrl.MayanodeStagenet : ApiUrl.MayanodeMainnet;
29
+
30
+ return RequestClient.get<Record<string, number>>(`${baseUrl}/mayachain/mimir`);
31
+ };
@@ -18,13 +18,13 @@ type InboundAddressData = {
18
18
  router: string;
19
19
  }[];
20
20
 
21
- export const getInboundData = (stagenet: boolean) => {
21
+ export const getThorInboundData = (stagenet: boolean) => {
22
22
  const baseUrl = stagenet ? ApiUrl.ThornodeStagenet : ApiUrl.ThornodeMainnet;
23
23
 
24
24
  return RequestClient.get<InboundAddressData>(`${baseUrl}/thorchain/inbound_addresses`);
25
25
  };
26
26
 
27
- export const getMimirData = (stagenet: boolean) => {
27
+ export const getThorMimirData = (stagenet: boolean) => {
28
28
  const baseUrl = stagenet ? ApiUrl.ThornodeStagenet : ApiUrl.ThornodeMainnet;
29
29
 
30
30
  return RequestClient.get<Record<string, number>>(`${baseUrl}/thorchain/mimir`);