@swapkit/core 1.0.0-rc.2 → 1.0.0-rc.20

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,8 +1,8 @@
1
1
  {
2
2
  "author": "swapkit-oss-team",
3
3
  "dependencies": {
4
- "@swapkit/helpers": "1.0.0-rc.1",
5
- "@swapkit/types": "1.0.0-rc.0"
4
+ "@swapkit/types": "1.0.0-rc.6",
5
+ "@swapkit/helpers": "1.0.0-rc.15"
6
6
  },
7
7
  "description": "SwapKit Lib core",
8
8
  "devDependencies": {
@@ -13,18 +13,18 @@
13
13
  "vite-plugin-wasm": "3.2.2",
14
14
  "vitest": "0.34.4",
15
15
  "@internal/config": "0.0.0-internal.0",
16
- "@swapkit/tokens": "1.0.0-rc.0",
17
- "@swapkit/toolbox-cosmos": "1.0.0-rc.2",
18
- "@swapkit/toolbox-evm": "1.0.0-rc.2",
19
- "@swapkit/toolbox-utxo": "1.0.0-rc.1",
20
- "@swapkit/api": "1.0.0-rc.0"
16
+ "@swapkit/api": "1.0.0-rc.6",
17
+ "@swapkit/tokens": "1.0.0-rc.7",
18
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.17",
19
+ "@swapkit/toolbox-evm": "1.0.0-rc.16",
20
+ "@swapkit/toolbox-utxo": "1.0.0-rc.16"
21
21
  },
22
22
  "peerDependencies": {
23
- "@swapkit/api": "1.0.0-rc.0",
24
- "@swapkit/tokens": "1.0.0-rc.0",
25
- "@swapkit/toolbox-cosmos": "1.0.0-rc.2",
26
- "@swapkit/toolbox-evm": "1.0.0-rc.2",
27
- "@swapkit/toolbox-utxo": "1.0.0-rc.1"
23
+ "@swapkit/api": "1.0.0-rc.6",
24
+ "@swapkit/tokens": "1.0.0-rc.7",
25
+ "@swapkit/toolbox-cosmos": "1.0.0-rc.17",
26
+ "@swapkit/toolbox-evm": "1.0.0-rc.16",
27
+ "@swapkit/toolbox-utxo": "1.0.0-rc.16"
28
28
  },
29
29
  "eslintConfig": {
30
30
  "extends": "../../../internal/eslint-config"
@@ -52,7 +52,7 @@
52
52
  "repository": "https://github.com/thorswap/SwapKit.git",
53
53
  "type": "module",
54
54
  "types": "./dist/index.d.ts",
55
- "version": "1.0.0-rc.2",
55
+ "version": "1.0.0-rc.20",
56
56
  "scripts": {
57
57
  "build": "NODE_OPTIONS=--max_old_space_size=16384 vite build",
58
58
  "clean": "rm -rf dist vite.config.ts.* .turbo node_modules",
@@ -8,6 +8,7 @@ export const getExplorerTxUrl = ({ chain, txHash }: { txHash: string; chain: Cha
8
8
  case Chain.Bitcoin:
9
9
  case Chain.BitcoinCash:
10
10
  case Chain.Maya:
11
+ case Chain.Kujira:
11
12
  case Chain.THORChain:
12
13
  return `${baseUrl}/tx/${txHash}`;
13
14
 
@@ -46,6 +47,7 @@ export const getExplorerAddressUrl = ({ chain, address }: { address: string; cha
46
47
  case Chain.Maya:
47
48
  case Chain.Optimism:
48
49
  case Chain.Polygon:
50
+ case Chain.Kujira:
49
51
  case Chain.THORChain:
50
52
  return `${baseUrl}/address/${address}`;
51
53
 
@@ -68,9 +68,8 @@ export class SwapKitCore<T = ''> {
68
68
  getWallet = <T extends Chain>(chain: Chain) => this.connectedWallets[chain] as WalletMethods[T];
69
69
  getExplorerAddressUrl = (chain: Chain, address: string) =>
70
70
  getExplorerAddressUrl({ chain, address });
71
- getBalance = async (chain: Chain, refresh?: boolean) => {
72
- if (!refresh) return this.connectedChains[chain]?.balance || [];
73
- const wallet = await this.getWalletByChain(chain);
71
+ getBalance = async (chain: Chain, potentialScamFilter?: boolean) => {
72
+ const wallet = await this.getWalletByChain(chain, potentialScamFilter);
74
73
 
75
74
  return wallet?.balance || [];
76
75
  };
@@ -121,13 +120,20 @@ export class SwapKitCore<T = ''> {
121
120
  const { address: recipient } = await this.#getInboundDataByChain(asset.chain);
122
121
  const {
123
122
  contract: router,
124
- calldata: { amountIn, memo, memoStreamingSwap },
123
+ calldata: { expiration, amountIn, memo, memoStreamingSwap },
125
124
  } = route;
126
125
 
127
126
  const assetValue = asset.add(SwapKitNumber.fromBigInt(BigInt(amountIn), asset.decimal));
128
127
  const swapMemo = (streamSwap ? memoStreamingSwap || memo : memo) as string;
129
128
 
130
- return this.deposit({ assetValue, memo: swapMemo, feeOptionKey, router, recipient });
129
+ return this.deposit({
130
+ expiration,
131
+ assetValue,
132
+ memo: swapMemo,
133
+ feeOptionKey,
134
+ router,
135
+ recipient,
136
+ });
131
137
  }
132
138
 
133
139
  if (SWAP_IN.includes(quoteMode)) {
@@ -148,9 +154,7 @@ export class SwapKitCore<T = ''> {
148
154
 
149
155
  const contract = await walletMethods.createContract?.(contractAddress, abi, provider);
150
156
 
151
- // TODO: (@Towan) Contract evm methods should be generic
152
- // @ts-expect-error
153
- const tx = await contract.populateTransaction.swapIn?.(
157
+ const tx = await contract.getFunction('swapIn').populateTransaction(
154
158
  ...getSwapInParams({
155
159
  streamSwap,
156
160
  toChecksumAddress,
@@ -170,11 +174,11 @@ export class SwapKitCore<T = ''> {
170
174
  }
171
175
  };
172
176
 
173
- getWalletByChain = async (chain: Chain) => {
177
+ getWalletByChain = async (chain: Chain, potentialScamFilter?: boolean) => {
174
178
  const address = this.getAddress(chain);
175
179
  if (!address) return null;
176
180
 
177
- const balance = (await this.getWallet(chain)?.getBalance(address)) ?? [
181
+ const balance = (await this.getWallet(chain)?.getBalance(address, potentialScamFilter)) ?? [
178
182
  AssetValue.fromChainOrSignature(chain),
179
183
  ];
180
184
 
@@ -238,7 +242,7 @@ export class SwapKitCore<T = ''> {
238
242
  ? TCBscDepositABI
239
243
  : TCEthereumVaultAbi;
240
244
 
241
- return (await (
245
+ const response = await (
242
246
  walletInstance as EVMWallet<typeof AVAXToolbox | typeof ETHToolbox | typeof BSCToolbox>
243
247
  ).call({
244
248
  abi,
@@ -249,12 +253,17 @@ export class SwapKitCore<T = ''> {
249
253
  recipient,
250
254
  getChecksumAddressFromAsset({ chain, symbol, ticker }, chain),
251
255
  // TODO: (@Towan) Re-Check on that conversion 🙏
252
- assetValue.baseValueBigInt.toString(),
256
+ assetValue.getBaseValue('bigint').toString(),
253
257
  params.memo,
254
258
  rest.expiration,
255
259
  ],
256
- txOverrides: { from: params.from, value: assetValue.baseValueBigInt },
257
- })) as Promise<string>;
260
+ txOverrides: {
261
+ from: params.from,
262
+ value: assetValue.isGasAsset ? assetValue.getBaseValue('bigint') : undefined,
263
+ },
264
+ });
265
+
266
+ return response as string;
258
267
  }
259
268
 
260
269
  default: {
@@ -393,7 +402,7 @@ export class SwapKitCore<T = ''> {
393
402
  assetValue: AssetValue;
394
403
  percent: number;
395
404
  from: 'sym' | 'rune' | 'asset';
396
- to: 'sym' | 'rune';
405
+ to: 'sym' | 'rune' | 'asset';
397
406
  }) => {
398
407
  const targetAsset =
399
408
  to === 'rune'
@@ -576,7 +585,7 @@ export class SwapKitCore<T = ''> {
576
585
  connectTrezor = async (_chains: Chain, _derivationPath: number[]): Promise<void> => {
577
586
  throw new SwapKitError('core_wallet_trezor_not_installed');
578
587
  };
579
- connectKeplr = async (): Promise<void> => {
588
+ connectKeplr = async (_chain: Chain): Promise<void> => {
580
589
  throw new SwapKitError('core_wallet_keplr_not_installed');
581
590
  };
582
591
  connectOkx = async (_chains: Chain[]): Promise<void> => {
@@ -1,4 +1,4 @@
1
- import { getRequest } from '@swapkit/helpers';
1
+ import { RequestClient } from '@swapkit/helpers';
2
2
  import type { Chain } from '@swapkit/types';
3
3
  import { ApiUrl } from '@swapkit/types';
4
4
 
@@ -21,11 +21,11 @@ type InboundAddressData = {
21
21
  export const getInboundData = (stagenet: boolean) => {
22
22
  const baseUrl = stagenet ? ApiUrl.ThornodeStagenet : ApiUrl.ThornodeMainnet;
23
23
 
24
- return getRequest<InboundAddressData>(`${baseUrl}/thorchain/inbound_addresses`);
24
+ return RequestClient.get<InboundAddressData>(`${baseUrl}/thorchain/inbound_addresses`);
25
25
  };
26
26
 
27
27
  export const getMimirData = (stagenet: boolean) => {
28
28
  const baseUrl = stagenet ? ApiUrl.ThornodeStagenet : ApiUrl.ThornodeMainnet;
29
29
 
30
- return getRequest<Record<string, number>>(`${baseUrl}/thorchain/mimir`);
30
+ return RequestClient.get<Record<string, number>>(`${baseUrl}/thorchain/mimir`);
31
31
  };
@@ -4,6 +4,7 @@ import type {
4
4
  BinanceToolbox,
5
5
  DepositParam,
6
6
  GaiaToolbox,
7
+ KujiraToolbox,
7
8
  ThorchainToolboxType,
8
9
  } from '@swapkit/toolbox-cosmos';
9
10
  import type {
@@ -86,6 +87,7 @@ export type WalletMethods = {
86
87
  [Chain.Cosmos]: CosmosBasedWallet<typeof GaiaToolbox> | null;
87
88
  [Chain.Dogecoin]: UTXOWallet<typeof DOGEToolbox> | null;
88
89
  [Chain.Ethereum]: EVMWallet<typeof ETHToolbox> | null;
90
+ [Chain.Kujira]: CosmosBasedWallet<typeof KujiraToolbox> | null;
89
91
  [Chain.Litecoin]: UTXOWallet<typeof LTCToolbox> | null;
90
92
  [Chain.Maya]: ThorchainWallet | null;
91
93
  [Chain.Optimism]: EVMWallet<typeof OPToolbox> | null;