aegis-swap-widget 0.1.2 → 0.3.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 (68) hide show
  1. package/CHANGELOG.md +200 -0
  2. package/DESIGN.md +77 -0
  3. package/LICENSE +21 -0
  4. package/README.md +346 -24
  5. package/dist/abis.d.ts +18 -1
  6. package/dist/address.d.ts +5 -0
  7. package/dist/aegis-swap-widget.js +2716 -1470
  8. package/dist/color.d.ts +2 -0
  9. package/dist/components/icons.d.ts +30 -0
  10. package/dist/config.d.ts +3 -2
  11. package/dist/core.d.ts +15 -0
  12. package/dist/core.js +66 -0
  13. package/dist/encoding.d.ts +5 -1
  14. package/dist/errors.d.ts +3 -0
  15. package/dist/format.d.ts +3 -3
  16. package/dist/hooks/useChangeEmitter.d.ts +25 -0
  17. package/dist/hooks/useLifecycleToast.d.ts +16 -0
  18. package/dist/hooks/usePoolChangeEmitter.d.ts +1 -0
  19. package/dist/hooks/useResolvedTheme.d.ts +4 -0
  20. package/dist/hooks/useStableValue.d.ts +2 -0
  21. package/dist/hooks/useStatusChangeEmitter.d.ts +2 -0
  22. package/dist/hooks/useSubmitSwap.d.ts +75 -0
  23. package/dist/hooks/useSwapQuote.d.ts +30 -0
  24. package/dist/hooks/useTokenAllowance.d.ts +27 -0
  25. package/dist/hooks/useTokenBalances.d.ts +15 -0
  26. package/dist/hooks/useTokenIconMetadata.d.ts +7 -0
  27. package/dist/hooks/useValueRefresh.d.ts +1 -0
  28. package/dist/hooks/useWalletConnection.d.ts +18 -0
  29. package/dist/index.d.ts +12 -46
  30. package/dist/metadata.d.ts +8 -1
  31. package/dist/permit.d.ts +31 -1
  32. package/dist/polling-BI4pZg8Z.js +1252 -0
  33. package/dist/polling.d.ts +3 -0
  34. package/dist/quote.d.ts +30 -2
  35. package/dist/styles.css +1 -1
  36. package/dist/swap/authorizePermit.d.ts +30 -0
  37. package/dist/swap/executeSwapTransaction.d.ts +37 -0
  38. package/dist/swap/types.d.ts +7 -0
  39. package/dist/toast/ToastItem.d.ts +33 -0
  40. package/dist/toast/Toaster.d.ts +31 -0
  41. package/dist/toast/layout.d.ts +21 -0
  42. package/dist/toast/state.d.ts +69 -0
  43. package/dist/toast/swipe.d.ts +23 -0
  44. package/dist/toast/timer.d.ts +16 -0
  45. package/dist/toast/toast.d.ts +28 -0
  46. package/dist/toast/useDocumentVisible.d.ts +6 -0
  47. package/dist/toast/useToastTimer.d.ts +13 -0
  48. package/dist/transactionProgress.d.ts +42 -0
  49. package/dist/wallet.d.ts +19 -8
  50. package/dist/widget/AegisDirectSwapWidget.d.ts +20 -0
  51. package/dist/widget/AmountField.d.ts +20 -0
  52. package/dist/widget/ExecutionDetails.d.ts +27 -0
  53. package/dist/widget/NetworkSelector.d.ts +6 -0
  54. package/dist/widget/PoolSelector.d.ts +13 -0
  55. package/dist/widget/ProgressRail.d.ts +23 -0
  56. package/dist/widget/types.d.ts +129 -0
  57. package/dist/widget/useSwapController.d.ts +89 -0
  58. package/dist/widget/viewState.d.ts +55 -0
  59. package/package.json +45 -8
  60. package/dist/abis.d.ts.map +0 -1
  61. package/dist/config.d.ts.map +0 -1
  62. package/dist/encoding.d.ts.map +0 -1
  63. package/dist/format.d.ts.map +0 -1
  64. package/dist/index.d.ts.map +0 -1
  65. package/dist/metadata.d.ts.map +0 -1
  66. package/dist/permit.d.ts.map +0 -1
  67. package/dist/quote.d.ts.map +0 -1
  68. package/dist/wallet.d.ts.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,200 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [0.3.0] - 2026-06-08
9
+
10
+ ### Removed (breaking)
11
+ - `targets` prop — use `poolIds` (identical `string[]` shape).
12
+ - `markets` prop — use `pools`; `Object.values(markets)` migrates an existing map.
13
+ - `defaultDirection` values `'intoTarget'` / `'outOfTarget'` — use `'buy'` / `'sell'`.
14
+
15
+ ### Changed (breaking)
16
+ - Renamed `showApprovalModeControl` → `showApprovalMode`, pairing it with
17
+ `defaultApprovalMode`.
18
+
19
+ ### Migration
20
+ - `targets={ids}` → `poolIds={ids}`
21
+ - `markets={map}` → `pools={Object.values(map)}`
22
+ - `defaultDirection="intoTarget"` → `defaultDirection="buy"`
23
+ - `defaultDirection="outOfTarget"` → `defaultDirection="sell"`
24
+ - `showApprovalModeControl={x}` → `showApprovalMode={x}`
25
+
26
+ ### Internal
27
+ - Refactored the widget into a `useSwapController` hook (state, derivation, and
28
+ hook orchestration) over a thin presentational component, decomposed the swap
29
+ money path into pure `src/swap/` modules (`authorizePermit`,
30
+ `executeSwapTransaction`), and unified the host-callback emitters behind a
31
+ single `useChangeEmitter` primitive. No public behavior change.
32
+
33
+ ### Added
34
+ - Toast notifications as an alternative transaction-status surface: new
35
+ `statusSurface` prop (`'rail'` default, `'toast'`, `'both'`, `'none'`) plus
36
+ `toastPosition`. One toast per swap attempt morphs loading → success/error in
37
+ place with the received amount and a View transaction action; wallet
38
+ rejections auto-dismiss after 4s, other errors after 8s. The root
39
+ `data-progress-state` attribute stays on for every surface.
40
+ - `AegisSwapToaster` export: the toast viewport as a standalone component.
41
+ Mounting it anywhere takes over rendering from widget-provided toasters —
42
+ exactly one viewport per page — and owns `position`, `theme`/`accentColor`,
43
+ `duration`, `visibleToasts`, `closeButton`, `expand`, and `offset`. Toasts
44
+ stack with depth, expand on hover/focus, swipe-to-dismiss with momentum
45
+ (interruptible CSS transitions throughout), dismiss on Escape when focused,
46
+ pause their timers while hovered, mid-swipe, and in hidden tabs, and reduce
47
+ to fades under `prefers-reduced-motion`. Lifecycle morphs replay quiet icon
48
+ and text entrances in place, and terminal states tint the card border
49
+ (success whisper, error alarm) the way the progress rail recolors. The
50
+ viewport is hardened for arbitrary host pages: host `li`/text styling
51
+ cannot leak in, toasts hide in print, and the light theme keeps icon
52
+ contrast AA without overriding an explicit host accent.
53
+ - `aegisToast` export: toast function for host apps sharing the same viewport —
54
+ `aegisToast()` / `.info` / `.success` / `.error` / `.loading` / `.dismiss` /
55
+ `.promise`, with upsert-by-id morphing. New public types
56
+ `AegisSwapToasterProps`, `AegisSwapStatusSurface`, `AegisToastAction`,
57
+ `AegisToastOptions`, `AegisToastPosition`, `AegisToastType`, and
58
+ `AegisToastPromiseMessage`/`AegisToastPromiseMessages`.
59
+ - `onPoolChange` prop: fires with the active pool id whenever it changes —
60
+ user tab selection or a `poolIds` update that forces a fallback. Silent on
61
+ mount, so hosts only hear genuine transitions.
62
+ - `resolveTokenIconUrl` export (plus the `TokenMetadataByAddress` type): the
63
+ widget's own icon-source order — config `iconUrl`, metadata service, ichi
64
+ naming guess — so hosts rendering their own token marks resolve identically.
65
+ - `onStatusChange` prop: fires a lifecycle snapshot (`status`, `progress`, `txHash`,
66
+ `error`, `label`, rail geometry, and `walletPrompts`) on every transition, mirroring
67
+ the top progress rail — including errors and wallet rejections, which never appear
68
+ as a `status`. `walletPrompts.total/completed/active` exposes the SDK-owned provider
69
+ prompt plan for ERC20 approval, Permit2 authorization, and swap submission.
70
+ - `AegisSwapProgressRail` export: the widget's animated top rail as a standalone
71
+ component hosts can mount on their own containers, themed via `--aegis-swap-accent`,
72
+ `--aegis-swap-danger`, and `--aegis-swap-success` (the rail CSS now carries literal
73
+ dark-theme fallbacks for use outside the widget root).
74
+ - Host-tunable top rail tokens: `--aegis-rail-height`, `--aegis-rail-hold`, and
75
+ `--aegis-rail-fade` via the widget `style` prop. The success auto-reset reads the
76
+ computed hold/fade values so host-tuned terminal animations and status cleanup stay
77
+ synchronized.
78
+ - The top rail now separates completion from activity: `completePct` tracks completed
79
+ wallet-provider prompts, while pending/mining shimmer always sweeps the full top
80
+ border instead of starting from the completed fill.
81
+ - `networkOptions` prop plus `AegisSwapNetworkOption`/`AegisSwapNetworkIcon` types:
82
+ a display-only network menu list for previewing upcoming chains — non-selected
83
+ options render disabled by default with optional `status` text; a list without
84
+ the active chain gets it prepended; switching is not wired yet.
85
+ - Public types `AegisSwapStatusSnapshot`, `AegisSwapWalletPromptProgress`,
86
+ `SubmitStatus`, `TransactionProgressState`, and the `isUserRejectedError` helper.
87
+
88
+ ### Changed
89
+ - The branded header (`title`/`subtitle`) is now text-only: the Aegis logomark no longer
90
+ renders next to host-provided titles. Aegis attribution lives solely in the
91
+ "Powered by Aegis" footer.
92
+ - The trade-details toggle no longer compensates ancestor scroll position when
93
+ expanding or collapsing; the panel expands in place.
94
+ - Hover styles apply only on hover-capable devices (`@media (hover: hover)`), so taps
95
+ on touch screens no longer leave stuck hover states (raised tabs, rotated flip arrows).
96
+ - The direction-flip arrows now spin when the direction actually flips (driven by a
97
+ `data-direction` attribute) instead of pre-playing the rotation on hover.
98
+ - A busy CTA reads as working, not blocked: while approving/signing/submitting the
99
+ submit button keeps near-full opacity, shows a `progress` cursor, and runs a soft
100
+ sheen (`data-busy` attribute, motion-gated).
101
+ - Status feedback eases in instead of popping: error/success lines and the explorer
102
+ link get a staggered fade-rise, and the success line opens with a self-drawing
103
+ check ("Swap complete · received ~…", previously an em dash).
104
+ - Network-menu rows cascade in as the menu opens (30ms steps, reduced-motion safe),
105
+ and the menu's overlay shadow is re-tuned for the light theme.
106
+ - Switching feels like one control: the pool tabs and the Exact/Max approval
107
+ segments glide a single active pill between options instead of cross-fading
108
+ two buttons, and the Sell/Buy token pills cross-fade when a switch retargets
109
+ them. New `--aegis-switch-dur`/`--aegis-spring` tokens (overridable via the
110
+ `style` prop) drive it; reduced-motion safe.
111
+ - Concentric corner radii on nested chrome: pool tab rail, network menu, approval
112
+ segments, and the trade-details toggle now derive outer radius = inner + padding.
113
+ - The trade-details panel sheds visual weight: approval segments and route actions
114
+ drop from 40px to 26px (keeping control-height touch targets via invisible
115
+ extensions), the route chip loses its divider hairlines and dead drop shadow, the
116
+ active pill is fill-only, and the setting rows tighten to 38px with unified 12px
117
+ labels.
118
+
119
+ ### Fixed
120
+ - Keyboard focus no longer reshapes controls: the global `:focus-visible` rule forced
121
+ a 6px border-radius onto every focused element, visibly squaring the circular flip
122
+ button; the ring now follows each element's own radius.
123
+ - The slippage input no longer triggers iOS Safari's focus auto-zoom (16px input font
124
+ on coarse pointers).
125
+ - The network trigger's touch target is extended to ~44px without growing the chip.
126
+
127
+ ## [0.2.0] - 2026-06-05
128
+
129
+ ### Added
130
+ - Premium embeddable swap surface with collapsible trade details, route chip, token icons,
131
+ Ethereum light/dark assets, and host-controlled execution details.
132
+ - Exact-vs-max approval mode support, defaulting to exact approvals with Permit2 fallback.
133
+ - Wallet, quote, allowance, balance, token icon, and submit hooks split out of the widget
134
+ entrypoint for a smaller public surface and easier testing.
135
+ - Address, color, error, transaction progress, and widget view-state helpers with tests
136
+ organized under `tests/`.
137
+
138
+ ### Changed
139
+ - The public widget entrypoint now delegates to focused widget modules instead of carrying
140
+ the entire implementation in `src/index.tsx`.
141
+ - Quote and router encoding paths are hardened around calldata construction, stale quote
142
+ handling, and direct-pool route metadata.
143
+ - Pool, wallet, metadata, and config inputs are normalized more defensively for host apps.
144
+ - The default approval mode is `exact`; hosts can still opt into `max`.
145
+
146
+ ### Deprecated
147
+ - `targets` remains available as a backwards-compatible alias for `poolIds` and will be
148
+ removed in `0.3.0`.
149
+
150
+ ## [0.1.3] - 2026-06-05
151
+
152
+ ### Added
153
+ - Per-chain internal fee: `fee` field on `AegisSwapChainConfig`, so the output-token
154
+ fee applies to any bundled chain that sets one (mainnet keeps its 50 bps fee).
155
+ - Package metadata (`license`, `repository`, `homepage`, `bugs`, `keywords`) and a
156
+ `LICENSE` file (MIT).
157
+ - Test suite (Vitest) covering the quote/encoding money-path, formatting, and config
158
+ factories, plus a GitHub Actions CI workflow (typecheck + test + build).
159
+ - `prepack` build hook and a `prepublishOnly` typecheck + test gate so published
160
+ tarballs always contain a fresh build.
161
+
162
+ ### Changed
163
+ - `resolveWidgetFee` now reads the per-chain `fee` from the resolved chain config
164
+ instead of hardcoding Ethereum mainnet. Default mainnet behavior is unchanged.
165
+ - Swap submission re-quotes immediately before building calldata so the on-chain
166
+ `amountOutMinimum`/`amountInMaximum` reflect the current price, not a stale quote.
167
+ - After switching the wallet network, submission waits for the switch to settle and
168
+ continues the swap automatically instead of forcing a second click.
169
+ - `viem` moved from `dependencies` to `peerDependencies` (it was already externalized
170
+ from the bundle).
171
+
172
+ ### Removed
173
+ - `dist/` build artifacts are no longer committed to git (rebuilt on pack/publish).
174
+
175
+ ## [0.1.2] - 2026-06-04
176
+
177
+ > Note: the published 0.1.2 tarball was cut before commit `31f01fa`
178
+ > ("Round displayed token amounts"); that change first reaches consumers in the
179
+ > next published version.
180
+
181
+ ### Added
182
+ - Adjustable internal widget swap fee, fixed to Ethereum mainnet (50 bps).
183
+ - Exact-output swaps and a 5-second quote refresh.
184
+ - Per-chain Uniswap v4 contract config (`UNISWAP_V4_CONTRACTS_BY_CHAIN`).
185
+
186
+ ### Changed
187
+ - Display token amounts are rounded (local only; not in the published 0.1.2 tarball).
188
+
189
+ ## [0.1.0] - 2026-06-04
190
+
191
+ ### Added
192
+ - Initial embeddable direct-pool Aegis swap widget for WATER, WOOD, GRASS, and STONE.
193
+ - Generic pool widget API; ERC-20 → Permit2 approval and Permit2 batch signing.
194
+
195
+ [Unreleased]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.3.0...HEAD
196
+ [0.3.0]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.2.0...v0.3.0
197
+ [0.2.0]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.1.3...v0.2.0
198
+ [0.1.3]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.1.2...v0.1.3
199
+ [0.1.2]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.1.0...v0.1.2
200
+ [0.1.0]: https://github.com/amplifi-liquidity/aegis-widget/releases/tag/v0.1.0
package/DESIGN.md ADDED
@@ -0,0 +1,77 @@
1
+ # Design tokens
2
+
3
+ The widget themes through CSS custom properties on the `.aegis-swap-widget` root
4
+ (and the toast viewport). This file is the reference for the **public** tokens —
5
+ the ones a host may override and depend on. Set them inline via the `style` prop,
6
+ in a stylesheet on an ancestor, or per-toaster via `AegisSwapToaster`.
7
+
8
+ Renaming or removing anything in the tables below is a breaking (major) change.
9
+ Tokens prefixed `--aegis-_*` are internal and may change without notice.
10
+
11
+ ## Color
12
+
13
+ The default palette is authored in **OKLCH**: neutrals are tinted toward the
14
+ brand hue (~165) so the surface reads as one family, each step's lightness is
15
+ matched to keep text contrast (subtle/muted stay ≥ 4.5:1 on the panel for 12px
16
+ text), and no neutral is pure black or white. Derived accent tints
17
+ (`--aegis-swap-accent-soft/-line/-glow/-ring`) are computed with
18
+ `color-mix(in srgb, …)`, so a host can override `--aegis-swap-accent` with **any**
19
+ CSS color (hex, `rgb()`, `oklch()`, …) and the whole accent system recomputes.
20
+
21
+ | Token | Role |
22
+ | --- | --- |
23
+ | `--aegis-swap-accent` | CTA, selected pool, focus ring, links. Host's primary knob. |
24
+ | `--aegis-swap-accent-text` | Text on the accent CTA. Auto-derived from `accentColor`; override with `accentTextColor`. |
25
+ | `--aegis-swap-success` | Terminal success fill (rail, toast). |
26
+ | `--aegis-swap-danger` | Error fill and inline error text. |
27
+ | `--aegis-swap-bg` / `--aegis-swap-panel` / `--aegis-swap-panel-raised` / `--aegis-swap-panel-soft` | Surface ramp, darkest → most raised. |
28
+ | `--aegis-swap-text` / `--aegis-swap-muted` / `--aegis-swap-subtle` | Text ramp, primary → tertiary. |
29
+ | `--aegis-swap-border` / `--aegis-swap-border-strong` | Hairline and emphasized borders. |
30
+ | `--aegis-swap-font-family` | Font family; the widget does **not** inherit the host font by default. |
31
+
32
+ `theme="light"` swaps the surface/text/border/danger ramp; `accent`/`success`
33
+ carry across both themes. `theme="auto"` follows `prefers-color-scheme`.
34
+
35
+ ## Motion
36
+
37
+ All motion is CSS and respects `prefers-reduced-motion` automatically.
38
+
39
+ | Token | Default | Role |
40
+ | --- | --- | --- |
41
+ | `--aegis-switch-dur` | `260ms` | Segmented-pill glide and Sell/Buy token swap. `0ms` disables. |
42
+ | `--aegis-spring` | `cubic-bezier(0.22, 1, 0.36, 1)` | Easing for interactive state changes. |
43
+ | `--aegis-ease` | `cubic-bezier(0.2, 0, 0, 1)` | Easing for entrances and transitions. |
44
+
45
+ The pool-tab/approval-segment open is intentionally slower than the close
46
+ (enter-slow, exit-fast); that asymmetry is by design, not a value to "correct".
47
+
48
+ ## Progress rail
49
+
50
+ | Token | Default | Role |
51
+ | --- | --- | --- |
52
+ | `--aegis-rail-height` | `3px` | Rail thickness. |
53
+ | `--aegis-rail-hold` | `3000ms` | How long the terminal state holds before fading. |
54
+ | `--aegis-rail-fade` | `420ms` | Terminal fade-out duration. |
55
+
56
+ `--aegis-rail-hold` / `--aegis-rail-fade` must be CSS time strings (`ms`/`s`):
57
+ the widget reads the computed values at runtime to keep the success auto-reset in
58
+ sync with the host-tuned animation. These also apply to the standalone
59
+ `AegisSwapProgressRail`.
60
+
61
+ ## Toasts
62
+
63
+ The toast viewport portals to `document.body`, so widget-root variables do **not**
64
+ reach it — set these on `:root` or pass `AegisSwapToaster` props.
65
+
66
+ | Token | Role |
67
+ | --- | --- |
68
+ | `--aegis-swap-toast-z` | Stacking context for the viewport. |
69
+ | `--aegis-swap-toast-width` | Toast card width. |
70
+ | `--aegis-swap-toast-offset-x` / `--aegis-swap-toast-offset-y` | Viewport inset from the chosen corner. |
71
+
72
+ ## Internal tokens
73
+
74
+ `--aegis-r-sm/-md/-lg` (radii), `--aegis-seg-*` (segment chrome),
75
+ `--aegis-swap-shell`, and any `--aegis-_*` primitive are internal implementation
76
+ details. They are not part of the supported theming surface and may change
77
+ between minor versions.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Aegis Swap Widget contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.