@swapkit/core 1.0.0-rc.12 → 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.
Files changed (45) hide show
  1. package/dist/index.js +7324 -0
  2. package/dist/index.js.map +41 -0
  3. package/package.json +33 -47
  4. package/src/__tests__/helpers.test.ts +53 -0
  5. package/src/aggregator/contracts/avaxGeneric.ts +50 -50
  6. package/src/aggregator/contracts/avaxWoofi.ts +80 -80
  7. package/src/aggregator/contracts/bscGeneric.ts +59 -59
  8. package/src/aggregator/contracts/ethGeneric.ts +50 -50
  9. package/src/aggregator/contracts/index.ts +30 -28
  10. package/src/aggregator/contracts/pancakeV2.ts +80 -80
  11. package/src/aggregator/contracts/pangolin.ts +65 -65
  12. package/src/aggregator/contracts/routers/index.ts +58 -0
  13. package/src/aggregator/contracts/routers/kyber.ts +402 -0
  14. package/src/aggregator/contracts/routers/oneinch.ts +2188 -0
  15. package/src/aggregator/contracts/routers/pancakeswap.ts +340 -0
  16. package/src/aggregator/contracts/routers/pangolin.ts +340 -0
  17. package/src/aggregator/contracts/routers/sushiswap.ts +340 -0
  18. package/src/aggregator/contracts/routers/traderJoe.ts +340 -0
  19. package/src/aggregator/contracts/routers/uniswapv2.ts +340 -0
  20. package/src/aggregator/contracts/routers/uniswapv3.ts +254 -0
  21. package/src/aggregator/contracts/routers/woofi.ts +171 -0
  22. package/src/aggregator/contracts/sushiswap.ts +65 -65
  23. package/src/aggregator/contracts/traderJoe.ts +65 -65
  24. package/src/aggregator/contracts/uniswapV2.ts +65 -65
  25. package/src/aggregator/contracts/uniswapV2Leg.ts +70 -70
  26. package/src/aggregator/contracts/uniswapV3_100.ts +70 -70
  27. package/src/aggregator/contracts/uniswapV3_10000.ts +70 -70
  28. package/src/aggregator/contracts/uniswapV3_3000.ts +70 -70
  29. package/src/aggregator/contracts/uniswapV3_500.ts +70 -70
  30. package/src/aggregator/getSwapParams.ts +12 -12
  31. package/src/client/index.ts +206 -646
  32. package/src/client/old.ts +854 -0
  33. package/src/helpers/explorerUrls.ts +38 -0
  34. package/src/index.ts +6 -4
  35. package/src/types.ts +149 -0
  36. package/LICENSE +0 -201
  37. package/dist/index-9e36735e.cjs +0 -1
  38. package/dist/index-cf1865cd.js +0 -649
  39. package/dist/index.cjs +0 -2
  40. package/dist/index.d.ts +0 -216
  41. package/dist/index.es.js +0 -3818
  42. package/src/client/__tests__/helpers.test.ts +0 -69
  43. package/src/client/explorerUrls.ts +0 -62
  44. package/src/client/thornode.ts +0 -31
  45. package/src/client/types.ts +0 -103
@@ -1,69 +0,0 @@
1
- import { Chain, ChainToExplorerUrl } from '@swapkit/types';
2
- import { describe, expect, test } from 'vitest';
3
-
4
- import { getExplorerAddressUrl, getExplorerTxUrl } from '../explorerUrls.ts';
5
-
6
- describe('Explorer URLs', () => {
7
- Object.values(Chain)
8
- .filter((c) => ![Chain.Litecoin, Chain.Dogecoin, Chain.Cosmos].includes(c))
9
- .forEach((chain) => {
10
- test(`getExplorerTxUrl returns correct URL for ${chain}`, () => {
11
- expect(getExplorerTxUrl({ chain, txHash: '0x12345' })).toBe(
12
- `${ChainToExplorerUrl[chain]}/tx/0x12345`,
13
- );
14
-
15
- expect(getExplorerAddressUrl({ chain, address: 'asdfg' })).toBe(
16
- `${ChainToExplorerUrl[chain]}/address/asdfg`,
17
- );
18
- });
19
- });
20
-
21
- test('getExplorerTxUrl throws Error for unsupported Chain', () => {
22
- expect(() =>
23
- getExplorerTxUrl({ chain: 'unsupported' as Chain, txHash: '0x12345' }),
24
- ).toThrowError('Unsupported chain: unsupported');
25
- });
26
- test('getExplorerAddressUrl throws Error for unsupported Chain', () => {
27
- expect(() =>
28
- getExplorerAddressUrl({ chain: 'unsupported' as Chain, address: 'asdfg' }),
29
- ).toThrowError('Unsupported chain: unsupported');
30
- });
31
- test('getExplorerTxUrl adds 0x for EVM like chains', () => {
32
- expect(getExplorerTxUrl({ chain: Chain.Ethereum, txHash: '12345' })).toBe(
33
- 'https://etherscan.io/tx/0x12345',
34
- );
35
- });
36
-
37
- test('getExplorerTxUrl returns correct URL for Litecoin', () => {
38
- expect(getExplorerTxUrl({ chain: Chain.Litecoin, txHash: 'efghi' })).toBe(
39
- 'https://ltc.bitaps.com/efghi',
40
- );
41
- });
42
- test('getExplorerAddressUrl returns correct URL for Litecoin', () => {
43
- expect(getExplorerAddressUrl({ chain: Chain.Litecoin, address: '12345' })).toBe(
44
- 'https://ltc.bitaps.com/12345',
45
- );
46
- });
47
-
48
- test('getExplorerTxUrl returns correct URL for Cosmos', () => {
49
- expect(getExplorerTxUrl({ chain: Chain.Cosmos, txHash: 'pqrst' })).toBe(
50
- 'https://cosmos.bigdipper.live/transactions/pqrst',
51
- );
52
- });
53
- test('getExplorerAddressUrl returns correct URL for Cosmos', () => {
54
- expect(getExplorerAddressUrl({ chain: Chain.Cosmos, address: 'zabcd' })).toBe(
55
- 'https://cosmos.bigdipper.live/account/zabcd',
56
- );
57
- });
58
-
59
- test('getExplorerTxUrl returns correct URL for Doge', () => {
60
- expect(getExplorerTxUrl({ chain: Chain.Dogecoin, txHash: 'uvwxy' })).toBe(
61
- 'https://blockchair.com/dogecoin/transaction/uvwxy',
62
- );
63
- });
64
- test('getExplorerAddressUrl returns correct URL for Doge', () => {
65
- expect(getExplorerAddressUrl({ chain: Chain.Dogecoin, address: 'efghi' })).toBe(
66
- 'https://blockchair.com/dogecoin/address/efghi',
67
- );
68
- });
69
- });
@@ -1,62 +0,0 @@
1
- import { Chain, ChainToExplorerUrl } from '@swapkit/types';
2
-
3
- export const getExplorerTxUrl = ({ chain, txHash }: { txHash: string; chain: Chain }) => {
4
- const baseUrl = ChainToExplorerUrl[chain];
5
-
6
- switch (chain) {
7
- case Chain.Binance:
8
- case Chain.Bitcoin:
9
- case Chain.BitcoinCash:
10
- case Chain.Maya:
11
- case Chain.Kujira:
12
- case Chain.THORChain:
13
- return `${baseUrl}/tx/${txHash}`;
14
-
15
- case Chain.Arbitrum:
16
- case Chain.Avalanche:
17
- case Chain.BinanceSmartChain:
18
- case Chain.Ethereum:
19
- case Chain.Optimism:
20
- case Chain.Polygon:
21
- return `${baseUrl}/tx/${txHash.startsWith('0x') ? txHash : `0x${txHash}`}`;
22
-
23
- case Chain.Cosmos:
24
- return `${baseUrl}/transactions/${txHash}`;
25
- case Chain.Dogecoin:
26
- return `${baseUrl}/transaction/${txHash.toLowerCase()}`;
27
- case Chain.Litecoin:
28
- return `${baseUrl}/${txHash}`;
29
-
30
- default:
31
- throw new Error(`Unsupported chain: ${chain}`);
32
- }
33
- };
34
-
35
- export const getExplorerAddressUrl = ({ chain, address }: { address: string; chain: Chain }) => {
36
- const baseUrl = ChainToExplorerUrl[chain];
37
-
38
- switch (chain) {
39
- case Chain.Arbitrum:
40
- case Chain.Avalanche:
41
- case Chain.Binance:
42
- case Chain.BinanceSmartChain:
43
- case Chain.Bitcoin:
44
- case Chain.BitcoinCash:
45
- case Chain.Dogecoin:
46
- case Chain.Ethereum:
47
- case Chain.Maya:
48
- case Chain.Optimism:
49
- case Chain.Polygon:
50
- case Chain.Kujira:
51
- case Chain.THORChain:
52
- return `${baseUrl}/address/${address}`;
53
-
54
- case Chain.Cosmos:
55
- return `${baseUrl}/account/${address}`;
56
- case Chain.Litecoin:
57
- return `${baseUrl}/${address}`;
58
-
59
- default:
60
- throw new Error(`Unsupported chain: ${chain}`);
61
- }
62
- };
@@ -1,31 +0,0 @@
1
- import { getRequest } 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 getInboundData = (stagenet: boolean) => {
22
- const baseUrl = stagenet ? ApiUrl.ThornodeStagenet : ApiUrl.ThornodeMainnet;
23
-
24
- return getRequest<InboundAddressData>(`${baseUrl}/thorchain/inbound_addresses`);
25
- };
26
-
27
- export const getMimirData = (stagenet: boolean) => {
28
- const baseUrl = stagenet ? ApiUrl.ThornodeStagenet : ApiUrl.ThornodeMainnet;
29
-
30
- return getRequest<Record<string, number>>(`${baseUrl}/thorchain/mimir`);
31
- };
@@ -1,103 +0,0 @@
1
- import type { QuoteRoute } from '@swapkit/api';
2
- import type { AssetValue, SwapKitNumber } from '@swapkit/helpers';
3
- import type {
4
- BinanceToolbox,
5
- DepositParam,
6
- GaiaToolbox,
7
- KujiraToolbox,
8
- ThorchainToolboxType,
9
- } from '@swapkit/toolbox-cosmos';
10
- import type {
11
- ARBToolbox,
12
- AVAXToolbox,
13
- BSCToolbox,
14
- ETHToolbox,
15
- MATICToolbox,
16
- OPToolbox,
17
- } from '@swapkit/toolbox-evm';
18
- import type { BCHToolbox, BTCToolbox, DOGEToolbox, LTCToolbox } from '@swapkit/toolbox-utxo';
19
- import type { Chain, FeeOption, WalletOption } from '@swapkit/types';
20
-
21
- type BaseWalletMethods = {
22
- getAddress: () => Promise<string> | string;
23
- };
24
-
25
- export type CoreTxParams = {
26
- assetValue: AssetValue;
27
- recipient: string;
28
- memo?: string;
29
- feeOptionKey?: FeeOption;
30
- feeRate?: number;
31
- data?: string;
32
- from?: string;
33
- expiration?: number;
34
- };
35
-
36
- export type AddLiquidityTxns = {
37
- runeTx?: string;
38
- assetTx?: string;
39
- };
40
-
41
- export type UpgradeParams = {
42
- runeAmount: SwapKitNumber;
43
- recipient: string;
44
- };
45
-
46
- export type ChainWallet = {
47
- address: string;
48
- balance: AssetValue[];
49
- walletType: WalletOption;
50
- };
51
-
52
- export type Wallet = Record<Chain, ChainWallet | null>;
53
-
54
- export type ThorchainWallet = BaseWalletMethods &
55
- ThorchainToolboxType & {
56
- transfer: (params: CoreTxParams) => Promise<string>;
57
- deposit: (params: DepositParam) => Promise<string>;
58
- };
59
-
60
- export type CosmosBasedWallet<T extends typeof BinanceToolbox | typeof GaiaToolbox> =
61
- BaseWalletMethods &
62
- ReturnType<T> & {
63
- transfer: (params: CoreTxParams) => Promise<string>;
64
- };
65
-
66
- export type EVMWallet<
67
- T extends typeof AVAXToolbox | typeof BSCToolbox | typeof ETHToolbox | typeof OPToolbox,
68
- > = BaseWalletMethods &
69
- ReturnType<T> & {
70
- transfer: (params: CoreTxParams) => Promise<string>;
71
- };
72
-
73
- export type UTXOWallet<
74
- T extends typeof BCHToolbox | typeof BTCToolbox | typeof DOGEToolbox | typeof LTCToolbox,
75
- > = BaseWalletMethods &
76
- ReturnType<T> & {
77
- transfer: (prams: CoreTxParams) => Promise<string>;
78
- };
79
-
80
- export type WalletMethods = {
81
- [Chain.Arbitrum]: EVMWallet<typeof ARBToolbox> | null;
82
- [Chain.Avalanche]: EVMWallet<typeof AVAXToolbox> | null;
83
- [Chain.BinanceSmartChain]: EVMWallet<typeof BSCToolbox> | null;
84
- [Chain.Binance]: CosmosBasedWallet<typeof BinanceToolbox> | null;
85
- [Chain.BitcoinCash]: UTXOWallet<typeof BCHToolbox> | null;
86
- [Chain.Bitcoin]: UTXOWallet<typeof BTCToolbox> | null;
87
- [Chain.Cosmos]: CosmosBasedWallet<typeof GaiaToolbox> | null;
88
- [Chain.Dogecoin]: UTXOWallet<typeof DOGEToolbox> | null;
89
- [Chain.Ethereum]: EVMWallet<typeof ETHToolbox> | null;
90
- [Chain.Kujira]: CosmosBasedWallet<typeof KujiraToolbox> | null;
91
- [Chain.Litecoin]: UTXOWallet<typeof LTCToolbox> | null;
92
- [Chain.Maya]: ThorchainWallet | null;
93
- [Chain.Optimism]: EVMWallet<typeof OPToolbox> | null;
94
- [Chain.Polygon]: EVMWallet<typeof MATICToolbox> | null;
95
- [Chain.THORChain]: ThorchainWallet | null;
96
- };
97
-
98
- export type SwapParams = {
99
- recipient: string;
100
- streamSwap?: boolean;
101
- route: QuoteRoute;
102
- feeOptionKey: FeeOption;
103
- };