aegis-swap-widget 0.3.4 → 0.4.0

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 (65) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +67 -8
  3. package/dist/address.d.ts +7 -0
  4. package/dist/aegis-swap-widget.js +3288 -2835
  5. package/dist/components/icons.d.ts +12 -12
  6. package/dist/config/chains.d.ts +1 -11
  7. package/dist/config/contracts.d.ts +1 -6
  8. package/dist/config/createMarket.d.ts +1 -3
  9. package/dist/config/index.d.ts +7 -7
  10. package/dist/config/markets.d.ts +1 -1
  11. package/dist/config/tokens.d.ts +1 -11
  12. package/dist/config/types.d.ts +2 -81
  13. package/dist/core.d.ts +4 -2
  14. package/dist/core.js +9 -3
  15. package/dist/encoding.d.ts +2 -28
  16. package/dist/hooks/useBackendSwapData.d.ts +27 -0
  17. package/dist/hooks/useLifecycleToast.d.ts +1 -1
  18. package/dist/hooks/useStatusChangeEmitter.d.ts +1 -1
  19. package/dist/hooks/useSubmitSwap.d.ts +4 -4
  20. package/dist/hooks/useSwapQuote.d.ts +2 -2
  21. package/dist/hooks/useTokenAllowance.d.ts +1 -1
  22. package/dist/hooks/useTokenBalances.d.ts +5 -2
  23. package/dist/hooks/useTokenIconMetadata.d.ts +1 -1
  24. package/dist/hooks/useWalletConnection.d.ts +3 -2
  25. package/dist/index.d.ts +15 -15
  26. package/dist/logger.d.ts +4 -0
  27. package/dist/markets-D31LUAsv.js +71 -0
  28. package/dist/metadata.d.ts +2 -25
  29. package/dist/permit.d.ts +1 -9
  30. package/dist/polling.d.ts +1 -3
  31. package/dist/quote/aggregatedSwapQuote.d.ts +1 -5
  32. package/dist/quote.d.ts +2 -59
  33. package/dist/services/kyberSwap.d.ts +2 -84
  34. package/dist/styles.css +1 -1
  35. package/dist/styles.css.d.ts +2 -0
  36. package/dist/toast/ToastItem.d.ts +1 -1
  37. package/dist/toast/Toaster.d.ts +3 -3
  38. package/dist/toast/toast.d.ts +1 -1
  39. package/dist/transactionProgress.d.ts +2 -55
  40. package/dist/types/aggregatedSwap.d.ts +1 -29
  41. package/dist/wallet.d.ts +2 -34
  42. package/dist/widget/AegisAggregatedSwapWidget.d.ts +1 -1
  43. package/dist/widget/AegisDirectSwapWidget.d.ts +1 -1
  44. package/dist/widget/AmountField.d.ts +2 -2
  45. package/dist/widget/ExecutionDetails.d.ts +4 -4
  46. package/dist/widget/NetworkSelector.d.ts +7 -1
  47. package/dist/widget/ProgressRail.d.ts +1 -1
  48. package/dist/widget/SwapWidgetShell.d.ts +10 -10
  49. package/dist/widget/TokenSelector.d.ts +9 -6
  50. package/dist/widget/TransactionReceipt.d.ts +20 -0
  51. package/dist/widget/chainDisplay.d.ts +5 -0
  52. package/dist/widget/types.d.ts +76 -17
  53. package/dist/widget/useAggregatedSwapController.d.ts +17 -12
  54. package/dist/widget/useExecutionDetailsState.d.ts +23 -0
  55. package/dist/widget/useNetworkLens.d.ts +41 -0
  56. package/dist/widget/useRailAutoReset.d.ts +1 -1
  57. package/dist/widget/useStatusSurface.d.ts +5 -5
  58. package/dist/widget/useSwapConfig.d.ts +3192 -0
  59. package/dist/widget/useSwapController.d.ts +31 -20
  60. package/dist/widget/useWidgetStyle.d.ts +1 -1
  61. package/dist/widget/viewState.d.ts +5 -5
  62. package/package.json +9 -6
  63. package/dist/abis.d.ts +0 -132
  64. package/dist/markets-LIeOtFf_.js +0 -229
  65. package/dist/widget/PoolSelector.d.ts +0 -13
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 51a71c0: Update the React widget to consume the backend-aligned Core contract, refresh network and token controls, improve accessibility and receipt/status presentation, and harden package exports/declaration health.
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [28c52c3]
12
+ - @aegis-engine/core@0.2.0
13
+
14
+ ## 0.3.5
15
+
16
+ ### Patch Changes
17
+
18
+ - 155f6d5: Route Connect wallet and network-switch CTAs through wallet actions before swap validation. Derive the aggregated widget's submit `data-action` from the wallet connection state so it reports `connect` instead of `swap` while the CTA reads "Connect wallet".
19
+
20
+ Confirm the wallet actually moved to the target chain before the network-switch
21
+ CTA advances, instead of optimistically marking it switched.
22
+
23
+ - Updated dependencies [d38966f]
24
+ - @aegis-engine/core@0.1.3
25
+
3
26
  ## 0.3.4
4
27
 
5
28
  ### Patch Changes
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Aegis Swap Widget
2
2
 
3
- Embeddable React swap widget for Aegis direct pools. Import the component, import the CSS, and configure pools, wallet handoff, and host styling through props.
3
+ Seamlessly embed Aegis Swap directly in your React application. Import the component, import the CSS, and configure networks, wallet handoff, and host styling through props.
4
4
 
5
5
  The host app normally only renders `<AegisSwapWidget />`. Quoting, token approval, Permit2 signing, and swap submission are handled inside the widget.
6
6
 
@@ -20,7 +20,8 @@ npm install aegis-swap-widget
20
20
  ```
21
21
 
22
22
  Peer dependencies (provided by the host app): `react >=18 <20`, `react-dom >=18 <20`,
23
- and `viem ^2`. The package is ESM-only and ships no runtime dependencies of its own.
23
+ and `viem ^2`. The package is ESM-only. Its only runtime dependencies are
24
+ `@aegis-engine/core` (the swap engine) and `lucide-react` (icons).
24
25
 
25
26
  ## Basic Usage
26
27
 
@@ -33,7 +34,53 @@ export function Swap() {
33
34
  }
34
35
  ```
35
36
 
36
- Without a `pools` prop, the widget uses the bundled Aegis WATER, WOOD, GRASS, and STONE pool configs. For production integrations, pass the pools the host app wants to expose.
37
+ Without a `pools` prop, the widget loads Aegis config, token metadata, and market
38
+ discovery from the production backend REST API. Pass `backendBaseUrl={null}` to
39
+ use the bundled static WATER, WOOD, GRASS, and STONE mainnet pool configs, or
40
+ pass `pools` when a host wants to pin its own audited pool set.
41
+
42
+ The backend-enabled network list comes from `GET /v1/config` (`chains[]`). By
43
+ default the widget exposes every backend chain it can configure. Projects that
44
+ only support a subset should pass `enabledChainIds`; the first entry becomes
45
+ the uncontrolled initial network and the widget only fetches markets for
46
+ enabled chains:
47
+
48
+ ```tsx
49
+ <AegisSwapWidget enabledChainIds={[130]} />
50
+ <AegisSwapWidget enabledChainIds={[1, 8453]} />
51
+ ```
52
+
53
+ Use `pinnedChainIds` when the project supports several chains but wants common
54
+ choices surfaced first in the network selector and token selector. This only changes
55
+ display order; it never enables chains outside `enabledChainIds` or backend
56
+ config:
57
+
58
+ ```tsx
59
+ <AegisSwapWidget enabledChainIds={[1, 130, 8453]} pinnedChainIds={[8453, 1]} />
60
+ ```
61
+
62
+ By default the compact network selector uses the host accent color. Set
63
+ `networkSelectorColorMode="chain"` to use the built-in DFF chain palette
64
+ (Ethereum grey, Unichain pink, Base blue) for selector chrome:
65
+
66
+ ```tsx
67
+ <AegisSwapWidget networkSelectorColorMode="chain" />
68
+ ```
69
+
70
+ The selector renders as a compact chain-icon strip by default. Hosts that prefer
71
+ a single menu trigger can opt into the dropdown presentation without changing
72
+ the enabled network catalog:
73
+
74
+ ```tsx
75
+ <AegisSwapWidget networkSelectorVariant="dropdown" />
76
+ ```
77
+
78
+ The selector sits on the left by default. Use `networkSelectorPosition="right"`
79
+ when the host chrome needs the selector on the trailing edge:
80
+
81
+ ```tsx
82
+ <AegisSwapWidget networkSelectorPosition="right" />
83
+ ```
37
84
 
38
85
  By default the component uses `window.ethereum` when available, so injected wallets
39
86
  like MetaMask and Rabby work without any wallet props.
@@ -46,13 +93,16 @@ Token icons are hydrated from the same metadata table used by the Aegis website:
46
93
 
47
94
  `aegis-swap-widget` is the production widget SDK. It uses real providers, RPCs,
48
95
  pool config, approvals, Permit2 authorization, swap submission, and callbacks.
96
+ Pull requests publish the package demo to the Cloudflare Pages branch URL
97
+ reported by Wrangler, for example
98
+ `https://pr-<number>.aegis-widget-preview.pages.dev`.
49
99
 
50
100
  Demo wallets, fake transaction flows, scenario controls, and mock host shells
51
101
  belong in the playground app (`apps/playground` in this monorepo). They are not
52
102
  exposed as production widget props, so an embedded widget cannot accidentally
53
103
  run in a fake mode.
54
104
 
55
- Hosts should customize through `pools`, `chains`, `rpcUrls`,
105
+ Hosts should customize through `backendBaseUrl`, `pools`, `chains`, `rpcUrls`,
56
106
  `metadataEndpoint`, wallet/provider callbacks, status surfaces, `accentColor`,
57
107
  `accentTextColor`, `className`, `style`, `title`, and `subtitle`. The widget is
58
108
  meant to blend into a host app without forking its internals.
@@ -91,9 +141,12 @@ tokens — is documented in [DESIGN.md](./DESIGN.md).
91
141
 
92
142
  ## Configure Pools
93
143
 
94
- Out of the box, `<AegisSwapWidget />` exposes the bundled WATER, WOOD, GRASS,
95
- and STONE mainnet pools. Use `poolIds` when a host wants a different built-in
96
- pool order or subset:
144
+ Out of the box, `<AegisSwapWidget />` exposes the enabled markets returned by
145
+ the Aegis backend for the active chain. Use `enabledChainIds` when a project
146
+ should expose only some backend-enabled networks, and use `poolIds` when a host
147
+ wants a different backend-market order or subset. Pass `backendBaseUrl={null}`
148
+ when those ids should resolve against the bundled static WATER, WOOD, GRASS,
149
+ and STONE mainnet pools:
97
150
 
98
151
  ```tsx
99
152
  import { AegisSwapWidget } from 'aegis-swap-widget'
@@ -102,6 +155,7 @@ import 'aegis-swap-widget/styles.css'
102
155
  export function Swap() {
103
156
  return (
104
157
  <AegisSwapWidget
158
+ backendBaseUrl={null}
105
159
  defaultPoolId="WATER_USDC"
106
160
  poolIds={['WATER_USDC', 'WOOD_USDC', 'GRASS_USDC', 'STONE_USDC']}
107
161
  theme="dark"
@@ -601,7 +655,12 @@ No other props changed. See the [CHANGELOG](./CHANGELOG.md) for the full entry.
601
655
  - `onPoolChange`: `(poolId)` fired when the active pool changes — user selection or a `poolIds` update that forces a fallback. Silent on mount.
602
656
  - `chainId`: active chain id. Defaults to Ethereum mainnet.
603
657
  - `chains`: optional chain config overrides or additional chain configs, including per-chain `v4Contracts`.
604
- - `networkOptions`: optional display-only entries for the network menu (`{ id, name, icon?, selected?, disabled?, status? }`). The active entry is resolved by explicit `selected: true`, else by `id` matching the active chain id, else by `name`; a list without the active chain gets it prepended so the trigger never misreports the chain in use. Non-selected options render disabled by default with optional `status` text (e.g. "Coming soon"); `icon` is `'ethereum' | 'base'`. Clicking the enabled option only closes the menu (disabled options ignore clicks) — switching is not wired yet.
658
+ - `enabledChainIds`: backend-discovered chain ids this host project exposes. Omit to use every backend chain the widget can configure.
659
+ - `pinnedChainIds`: preferred chain ids to surface first in backend-derived network selectors and token selector filters. This only changes display order.
660
+ - `networkOptions`: optional entries for the network selector (`{ id, name, icon?, selected?, disabled?, status? }`). The active entry is resolved by id/name, and a list without the active chain gets it prepended so the selector never misreports the chain in use. Non-selected options are enabled only when chain switching is wired through backend discovery or `onChainChange`; `icon` is `'ethereum' | 'base' | 'unichain'`.
661
+ - `networkSelectorVariant`: `'icons'` (default) renders the compact chain-icon strip; `'dropdown'` renders a menu button/listbox for hosts that prefer a single trigger.
662
+ - `networkSelectorPosition`: `'left'` (default) places the selector on the leading side of the widget chrome; `'right'` places it on the trailing side.
663
+ - `networkSelectorColorMode`: `'accent'` (default) keeps host-brand selector chrome; `'chain'` uses the built-in DFF chain palette for supported chains.
605
664
  - `pools`: direct pool configs to render and swap against. This is the canonical config path.
606
665
  - `defaultPoolId`: initial pool id when `pools` is provided.
607
666
  - `poolIds`: optional pool id order/subset. Use this when the host wants to hide pools or control ordering.
package/dist/address.d.ts CHANGED
@@ -2,4 +2,11 @@ import type { Address, Hex } from 'viem';
2
2
  export declare function addressKey(address: Address | null | undefined): string;
3
3
  export declare function sameAddress(a: Address, b: Address): boolean;
4
4
  export declare function sameOptionalAddress(a: Address | null, b: Address | null): boolean;
5
+ export type TokenIdentity = {
6
+ chainId: number;
7
+ address: Address;
8
+ };
9
+ export declare function tokenIdentityKey(token: TokenIdentity): string;
10
+ export declare function sameTokenIdentity(a: TokenIdentity | null, b: TokenIdentity | null): boolean;
5
11
  export declare function samePoolId(a: Hex, b: Hex): boolean;
12
+ export declare function truncateHex(value: string): string;