@xswap-link/sdk 0.10.5 → 0.10.7

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 (54) hide show
  1. package/.github/workflows/main.yml +1 -1
  2. package/CHANGELOG.md +13 -0
  3. package/dist/index.d.mts +46 -12
  4. package/dist/index.d.ts +46 -12
  5. package/dist/index.global.js +5290 -261
  6. package/dist/index.js +9 -9
  7. package/dist/index.mjs +9 -9
  8. package/package.json +13 -2
  9. package/src/assets/icons/StarsIcon.tsx +18 -0
  10. package/src/assets/icons/index.ts +1 -0
  11. package/src/components/AllWalletsConfig/index.tsx +40 -0
  12. package/src/components/Swap/HistoryView/index.tsx +28 -5
  13. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +73 -47
  14. package/src/components/Swap/SwapView/SwapButton/index.tsx +45 -10
  15. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/TokenItem/index.tsx +20 -2
  16. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/index.tsx +124 -4
  17. package/src/components/Swap/SwapView/SwapPanel/WalletPanel/index.tsx +71 -0
  18. package/src/components/Swap/SwapView/SwapPanel/index.tsx +4 -0
  19. package/src/components/Swap/SwapView/WalletPicker/index.tsx +63 -28
  20. package/src/components/Swap/index.tsx +2 -2
  21. package/src/components/TxConfigForm/index.tsx +12 -34
  22. package/src/components/TxDataCard/TxDataCardUI/index.tsx +16 -10
  23. package/src/components/TxDataCard/index.tsx +1 -0
  24. package/src/components/TxWidgetWC/index.tsx +4 -0
  25. package/src/components/TxWidgetWCWrapped/index.tsx +2 -0
  26. package/src/components/index.ts +1 -0
  27. package/src/config/wagmiConfig.ts +1 -6
  28. package/src/constants/index.ts +14 -0
  29. package/src/context/HistoryProvider.tsx +121 -25
  30. package/src/context/SwapProvider.tsx +104 -48
  31. package/src/context/TransactionProvider.tsx +60 -1
  32. package/src/context/TxUIWrapper.tsx +187 -71
  33. package/src/context/WalletProvider.tsx +108 -0
  34. package/src/contracts/addresses.ts +4 -0
  35. package/src/contracts/idl/jupiter.ts +2879 -0
  36. package/src/models/Ecosystem.ts +1 -0
  37. package/src/models/Route.ts +14 -3
  38. package/src/models/SolanaTransaction.ts +38 -0
  39. package/src/models/SolanaWeb3Network.ts +5 -0
  40. package/src/models/TxUIWrapper.ts +8 -4
  41. package/src/models/index.ts +1 -0
  42. package/src/models/payloads/GetBalancesPayload.ts +2 -1
  43. package/src/models/payloads/GetSolanaRoutePayload.ts +8 -0
  44. package/src/models/payloads/ModalIntegrationPayload.ts +1 -0
  45. package/src/models/payloads/WidgetIntegrationPayload.ts +1 -0
  46. package/src/models/payloads/index.ts +1 -0
  47. package/src/services/api.ts +21 -3
  48. package/src/services/integrations/transactions.ts +2 -0
  49. package/src/services/solana/jupiter/extract-swap-data.ts +183 -0
  50. package/src/services/solana/jupiter/get-events.ts +37 -0
  51. package/src/services/solana/jupiter/instruction-parser.ts +217 -0
  52. package/src/services/solana/jupiter/utils.ts +37 -0
  53. package/src/utils/strings.ts +16 -0
  54. package/test/context/SwapProvider.test.tsx +6 -9
@@ -1,3 +1,5 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+
1
3
  export const shortAddress = (address: string): string => {
2
4
  return `${address?.substring(0, 5)}...${address?.substring(
3
5
  address.length - 5,
@@ -8,3 +10,17 @@ export const shortAddress = (address: string): string => {
8
10
  export const isETHAddressValid = (address: string): boolean => {
9
11
  return /^0x[a-fA-F0-9]{40}$/.test(address);
10
12
  };
13
+
14
+ /**
15
+ * Checks if a Solana address is on the Ed25519 curve (has a private key)
16
+ * If true: standard wallet address
17
+ * If false: program-derived address (PDA)
18
+ */
19
+ export const isSolanaAddressValid = (address: string): boolean => {
20
+ try {
21
+ const publicKey = new PublicKey(address);
22
+ return PublicKey.isOnCurve(publicKey);
23
+ } catch (error) {
24
+ return false;
25
+ }
26
+ };
@@ -12,10 +12,10 @@ import {
12
12
  DEFAULT_DESTINATION_CHAIN_ID,
13
13
  DEFAULT_DESTINATION_TOKEN_ADDR,
14
14
  } from "../../src/constants";
15
- import { WagmiProvider } from "wagmi";
16
- import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
17
15
  import fetch from "jest-fetch-mock";
18
16
  import { ethers } from "ethers";
17
+ import { WalletProvider } from "../../src/context/WalletProvider";
18
+ import { AllWalletsConfig } from "../../src/components/AllWalletsConfig";
19
19
  // import { Chain, Token } from "@src/models";
20
20
 
21
21
  const NATIVE_TOKEN_ADDR: string = "0x0000000000000000000000000000000000000000";
@@ -49,7 +49,6 @@ const INVALID_DST_BRIDGE_CHAIN_ID: string = "1088";
49
49
  const INVALID_DST_BRIDGE_TOKEN_ADDR: string =
50
50
  "0x0000000000000000000000000000000000000000";
51
51
 
52
- const queryClient = new QueryClient();
53
52
  const wagmiConfig = getWagmiConfig(supportedChains);
54
53
 
55
54
  describe("SwapProvider", () => {
@@ -68,18 +67,17 @@ describe("SwapProvider", () => {
68
67
  // create a wrapper for the SwapProvider
69
68
  const getWrapper = (integrationConfig, supportedChains, wagmiConfig) => {
70
69
  return ({ children }: { children: React.ReactNode }) => (
71
- <WagmiProvider config={wagmiConfig}>
72
- <QueryClientProvider client={queryClient}>
70
+ <AllWalletsConfig wagmiConfig={wagmiConfig}>
71
+ <WalletProvider>
73
72
  <SwapProvider
74
73
  integrationConfig={integrationConfig}
75
74
  supportedChains={supportedChains}
76
- wagmiConfig={wagmiConfig}
77
75
  overlay={false}
78
76
  >
79
77
  {children}
80
78
  </SwapProvider>
81
- </QueryClientProvider>
82
- </WagmiProvider>
79
+ </WalletProvider>
80
+ </AllWalletsConfig>
83
81
  );
84
82
  };
85
83
 
@@ -112,7 +110,6 @@ describe("SwapProvider", () => {
112
110
  await act(async () => {
113
111
  await new Promise((resolve) => setTimeout(resolve, 0));
114
112
  });
115
-
116
113
  expect(result.current.srcChain?.chainId).toBe(undefined);
117
114
  expect(result.current.srcToken?.address.toLowerCase()).toBe(undefined);
118
115
  expect(result.current.dstChain?.chainId).toBe(undefined);