aegis-swap-widget 0.1.0 → 0.2.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.
- package/CHANGELOG.md +82 -0
- package/LICENSE +21 -0
- package/README.md +221 -42
- package/dist/abis.d.ts +18 -1
- package/dist/address.d.ts +5 -0
- package/dist/aegis-swap-widget.js +2513 -935
- package/dist/color.d.ts +2 -0
- package/dist/components/icons.d.ts +23 -0
- package/dist/config.d.ts +43 -17
- package/dist/encoding.d.ts +11 -1
- package/dist/errors.d.ts +2 -0
- package/dist/format.d.ts +3 -3
- package/dist/hooks/useResolvedTheme.d.ts +3 -0
- package/dist/hooks/useScrollAnchor.d.ts +12 -0
- package/dist/hooks/useStableValue.d.ts +2 -0
- package/dist/hooks/useSubmitSwap.d.ts +66 -0
- package/dist/hooks/useSwapQuote.d.ts +30 -0
- package/dist/hooks/useTokenAllowance.d.ts +24 -0
- package/dist/hooks/useTokenBalances.d.ts +15 -0
- package/dist/hooks/useTokenIconMetadata.d.ts +7 -0
- package/dist/hooks/useWalletConnection.d.ts +18 -0
- package/dist/index.d.ts +8 -45
- package/dist/metadata.d.ts +0 -1
- package/dist/permit.d.ts +24 -1
- package/dist/polling.d.ts +2 -0
- package/dist/quote.d.ts +35 -2
- package/dist/styles.css +1 -1
- package/dist/transactionProgress.d.ts +18 -0
- package/dist/wallet.d.ts +19 -8
- package/dist/widget/AegisDirectSwapWidget.d.ts +4 -0
- package/dist/widget/AmountField.d.ts +17 -0
- package/dist/widget/ExecutionDetails.d.ts +29 -0
- package/dist/widget/NetworkSelector.d.ts +3 -0
- package/dist/widget/PoolSelector.d.ts +13 -0
- package/dist/widget/types.d.ts +66 -0
- package/dist/widget/viewState.d.ts +54 -0
- package/package.json +40 -8
- package/dist/abis.d.ts.map +0 -1
- package/dist/config.d.ts.map +0 -1
- package/dist/encoding.d.ts.map +0 -1
- package/dist/format.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/metadata.d.ts.map +0 -1
- package/dist/permit.d.ts.map +0 -1
- package/dist/quote.d.ts.map +0 -1
- package/dist/wallet.d.ts.map +0 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
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
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0] - 2026-06-05
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- Premium embeddable swap surface with collapsible trade details, route chip, token icons,
|
|
14
|
+
Ethereum light/dark assets, and host-controlled execution details.
|
|
15
|
+
- Exact-vs-max approval mode support, defaulting to exact approvals with Permit2 fallback.
|
|
16
|
+
- Wallet, quote, allowance, balance, token icon, and submit hooks split out of the widget
|
|
17
|
+
entrypoint for a smaller public surface and easier testing.
|
|
18
|
+
- Address, color, error, transaction progress, and widget view-state helpers with tests
|
|
19
|
+
organized under `tests/`.
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- The public widget entrypoint now delegates to focused widget modules instead of carrying
|
|
23
|
+
the entire implementation in `src/index.tsx`.
|
|
24
|
+
- Quote and router encoding paths are hardened around calldata construction, stale quote
|
|
25
|
+
handling, and direct-pool route metadata.
|
|
26
|
+
- Pool, wallet, metadata, and config inputs are normalized more defensively for host apps.
|
|
27
|
+
- The default approval mode is `exact`; hosts can still opt into `max`.
|
|
28
|
+
|
|
29
|
+
### Deprecated
|
|
30
|
+
- `targets` remains available as a backwards-compatible alias for `poolIds` and will be
|
|
31
|
+
removed in `0.3.0`.
|
|
32
|
+
|
|
33
|
+
## [0.1.3] - 2026-06-05
|
|
34
|
+
|
|
35
|
+
### Added
|
|
36
|
+
- Per-chain internal fee: `fee` field on `AegisSwapChainConfig`, so the output-token
|
|
37
|
+
fee applies to any bundled chain that sets one (mainnet keeps its 50 bps fee).
|
|
38
|
+
- Package metadata (`license`, `repository`, `homepage`, `bugs`, `keywords`) and a
|
|
39
|
+
`LICENSE` file (MIT).
|
|
40
|
+
- Test suite (Vitest) covering the quote/encoding money-path, formatting, and config
|
|
41
|
+
factories, plus a GitHub Actions CI workflow (typecheck + test + build).
|
|
42
|
+
- `prepack` build hook and a `prepublishOnly` typecheck + test gate so published
|
|
43
|
+
tarballs always contain a fresh build.
|
|
44
|
+
|
|
45
|
+
### Changed
|
|
46
|
+
- `resolveWidgetFee` now reads the per-chain `fee` from the resolved chain config
|
|
47
|
+
instead of hardcoding Ethereum mainnet. Default mainnet behavior is unchanged.
|
|
48
|
+
- Swap submission re-quotes immediately before building calldata so the on-chain
|
|
49
|
+
`amountOutMinimum`/`amountInMaximum` reflect the current price, not a stale quote.
|
|
50
|
+
- After switching the wallet network, submission waits for the switch to settle and
|
|
51
|
+
continues the swap automatically instead of forcing a second click.
|
|
52
|
+
- `viem` moved from `dependencies` to `peerDependencies` (it was already externalized
|
|
53
|
+
from the bundle).
|
|
54
|
+
|
|
55
|
+
### Removed
|
|
56
|
+
- `dist/` build artifacts are no longer committed to git (rebuilt on pack/publish).
|
|
57
|
+
|
|
58
|
+
## [0.1.2] - 2026-06-04
|
|
59
|
+
|
|
60
|
+
> Note: the published 0.1.2 tarball was cut before commit `31f01fa`
|
|
61
|
+
> ("Round displayed token amounts"); that change first reaches consumers in the
|
|
62
|
+
> next published version.
|
|
63
|
+
|
|
64
|
+
### Added
|
|
65
|
+
- Adjustable internal widget swap fee, fixed to Ethereum mainnet (50 bps).
|
|
66
|
+
- Exact-output swaps and a 5-second quote refresh.
|
|
67
|
+
- Per-chain Uniswap v4 contract config (`UNISWAP_V4_CONTRACTS_BY_CHAIN`).
|
|
68
|
+
|
|
69
|
+
### Changed
|
|
70
|
+
- Display token amounts are rounded (local only; not in the published 0.1.2 tarball).
|
|
71
|
+
|
|
72
|
+
## [0.1.0] - 2026-06-04
|
|
73
|
+
|
|
74
|
+
### Added
|
|
75
|
+
- Initial embeddable direct-pool Aegis swap widget for WATER, WOOD, GRASS, and STONE.
|
|
76
|
+
- Generic pool widget API; ERC-20 → Permit2 approval and Permit2 batch signing.
|
|
77
|
+
|
|
78
|
+
[Unreleased]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.2.0...HEAD
|
|
79
|
+
[0.2.0]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.1.3...v0.2.0
|
|
80
|
+
[0.1.3]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.1.2...v0.1.3
|
|
81
|
+
[0.1.2]: https://github.com/amplifi-liquidity/aegis-widget/compare/v0.1.0...v0.1.2
|
|
82
|
+
[0.1.0]: https://github.com/amplifi-liquidity/aegis-widget/releases/tag/v0.1.0
|
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.
|
package/README.md
CHANGED
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
# Aegis Swap Widget
|
|
2
2
|
|
|
3
|
-
Embeddable React swap widget for
|
|
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.
|
|
4
4
|
|
|
5
|
-
The
|
|
5
|
+
The host app normally only renders `<AegisSwapWidget />`. Quoting, token approval, Permit2 signing, and swap submission are handled inside the widget.
|
|
6
|
+
|
|
7
|
+
Typing in the Sell field creates an exact-input swap. Typing in the Buy field
|
|
8
|
+
creates an exact-output swap. Active quotes refresh every five seconds while the
|
|
9
|
+
amount is valid.
|
|
10
|
+
|
|
11
|
+
Widget swaps apply an internal output-token fee per configured chain. The bundled
|
|
12
|
+
Ethereum mainnet config carries a fixed 50 bps fee to
|
|
13
|
+
`0x8ea2C7de60ef1Cd4dcE64ea2DDDe2f99F0127eFC`. A chain carries a fee only when its
|
|
14
|
+
bundled config sets one; today only Ethereum mainnet is bundled.
|
|
6
15
|
|
|
7
16
|
## Install
|
|
8
17
|
|
|
@@ -17,16 +26,12 @@ import { AegisSwapWidget } from 'aegis-swap-widget'
|
|
|
17
26
|
import 'aegis-swap-widget/styles.css'
|
|
18
27
|
|
|
19
28
|
export function Swap() {
|
|
20
|
-
return
|
|
21
|
-
<AegisSwapWidget
|
|
22
|
-
defaultTarget="GRASS"
|
|
23
|
-
theme="dark"
|
|
24
|
-
accentColor="#31d48a"
|
|
25
|
-
/>
|
|
26
|
-
)
|
|
29
|
+
return <AegisSwapWidget />
|
|
27
30
|
}
|
|
28
31
|
```
|
|
29
32
|
|
|
33
|
+
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.
|
|
34
|
+
|
|
30
35
|
By default the component uses `window.ethereum` when available, so injected wallets
|
|
31
36
|
like MetaMask and Rabby work without any wallet props.
|
|
32
37
|
|
|
@@ -46,36 +51,106 @@ Hosts can choose the widget surface and brand accent at instantiation time:
|
|
|
46
51
|
/>
|
|
47
52
|
```
|
|
48
53
|
|
|
49
|
-
`theme` supports `dark`
|
|
54
|
+
`theme` supports `dark`, `light`, or `auto` (which follows the host's `prefers-color-scheme`). `accentColor` accepts any CSS color value and is used for the CTA, selected pools, focus states, links, and swap controls. The widget auto-derives a readable CTA text color from `accentColor` — for hex, `rgb()`, and `hsl()` values everywhere, and for any CSS color (named, `oklch()`, …) in the browser. `accentTextColor` overrides that and is the deterministic choice when you want an exact CTA text color (or are rendering a named/`oklch()` accent during SSR).
|
|
55
|
+
|
|
56
|
+
The default accent is neutral green. Pass `accentColor`, `accentTextColor`, `title`, `subtitle`, `className`, or `style` when the widget should blend into another product UI.
|
|
50
57
|
|
|
51
|
-
##
|
|
58
|
+
## Configure Pools
|
|
52
59
|
|
|
53
|
-
Pass the direct pools you want to expose.
|
|
60
|
+
Pass the direct pools you want to expose. This is the recommended integration path because it is not tied to any specific asset list.
|
|
61
|
+
|
|
62
|
+
For the first WATER, WOOD, GRASS, and STONE implementors, use the bundled mainnet pool configs:
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
import { AegisSwapWidget, AEGIS_SWAP_MARKETS } from 'aegis-swap-widget'
|
|
66
|
+
import 'aegis-swap-widget/styles.css'
|
|
67
|
+
|
|
68
|
+
const pools = [
|
|
69
|
+
AEGIS_SWAP_MARKETS.WATER_USDC,
|
|
70
|
+
AEGIS_SWAP_MARKETS.WOOD_USDC,
|
|
71
|
+
AEGIS_SWAP_MARKETS.GRASS_USDC,
|
|
72
|
+
AEGIS_SWAP_MARKETS.STONE_USDC,
|
|
73
|
+
]
|
|
74
|
+
|
|
75
|
+
export function Swap() {
|
|
76
|
+
return (
|
|
77
|
+
<AegisSwapWidget
|
|
78
|
+
pools={pools}
|
|
79
|
+
defaultPoolId="WATER_USDC"
|
|
80
|
+
theme="dark"
|
|
81
|
+
accentColor="#31d48a"
|
|
82
|
+
/>
|
|
83
|
+
)
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
Use `defaultPoolId` to choose which pool opens first. Use `poolIds` when a host wants a different pool order or subset:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
<AegisSwapWidget
|
|
91
|
+
pools={pools}
|
|
92
|
+
defaultPoolId="GRASS_USDC"
|
|
93
|
+
poolIds={['GRASS_USDC', 'WATER_USDC']}
|
|
94
|
+
/>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Fees
|
|
98
|
+
|
|
99
|
+
The widget applies an internal output-token fee per chain. Each bundled chain config
|
|
100
|
+
carries its own fee. Today only Ethereum mainnet is bundled:
|
|
101
|
+
|
|
102
|
+
- Fee: `50` bps
|
|
103
|
+
- Recipient: `0x8ea2C7de60ef1Cd4dcE64ea2DDDe2f99F0127eFC`
|
|
104
|
+
|
|
105
|
+
This fee is internal to the widget and is not configured by host sites — host `chains`
|
|
106
|
+
overrides cannot set or change it. Chains added later carry a fee only when their
|
|
107
|
+
bundled config provides one.
|
|
108
|
+
|
|
109
|
+
For custom assets, provide full pool and token metadata:
|
|
54
110
|
|
|
55
111
|
```tsx
|
|
56
112
|
import {
|
|
57
113
|
AegisSwapWidget,
|
|
58
|
-
|
|
59
|
-
|
|
114
|
+
AEGIS_DYNAMIC_FEE_FLAG,
|
|
115
|
+
AEGIS_SWAP_HOOK,
|
|
116
|
+
type AegisSwapPoolConfig,
|
|
60
117
|
} from 'aegis-swap-widget'
|
|
61
118
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
label: 'USDC /
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
119
|
+
const pools: AegisSwapPoolConfig[] = [
|
|
120
|
+
{
|
|
121
|
+
id: 'usdc-example',
|
|
122
|
+
label: 'USDC / EXAMPLE',
|
|
123
|
+
poolKey: {
|
|
124
|
+
currency0: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
125
|
+
currency1: '0xYourTokenAddress',
|
|
126
|
+
fee: AEGIS_DYNAMIC_FEE_FLAG,
|
|
127
|
+
tickSpacing: 60,
|
|
128
|
+
hooks: AEGIS_SWAP_HOOK,
|
|
129
|
+
},
|
|
130
|
+
counterToken: {
|
|
131
|
+
chainId: 1,
|
|
132
|
+
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
133
|
+
name: 'USD Coin',
|
|
134
|
+
symbol: 'USDC',
|
|
135
|
+
decimals: 6,
|
|
136
|
+
},
|
|
137
|
+
token: {
|
|
138
|
+
chainId: 1,
|
|
139
|
+
address: '0xYourTokenAddress',
|
|
140
|
+
name: 'Example Token',
|
|
141
|
+
symbol: 'EXAMPLE',
|
|
142
|
+
decimals: 18,
|
|
143
|
+
iconUrl: 'https://example.com/token.svg',
|
|
144
|
+
},
|
|
70
145
|
},
|
|
71
|
-
|
|
146
|
+
]
|
|
72
147
|
|
|
73
148
|
export function Swap() {
|
|
74
|
-
return <AegisSwapWidget
|
|
149
|
+
return <AegisSwapWidget pools={pools} defaultPoolId="usdc-example" />
|
|
75
150
|
}
|
|
76
151
|
```
|
|
77
152
|
|
|
78
|
-
|
|
153
|
+
Each pool can override `router`, `permit2`, `quoter`, and `poolId`. If omitted, those values come from the active chain config.
|
|
79
154
|
|
|
80
155
|
## Chains
|
|
81
156
|
|
|
@@ -92,11 +167,38 @@ import { mainnet } from 'viem/chains'
|
|
|
92
167
|
rpcUrls: ['https://your-mainnet-rpc.example'],
|
|
93
168
|
},
|
|
94
169
|
}}
|
|
95
|
-
|
|
170
|
+
pools={pools}
|
|
171
|
+
/>
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Uniswap v4 deployments are configured per chain. The package exports
|
|
175
|
+
`UNISWAP_V4_CONTRACTS_BY_CHAIN` for the supported mainnet deployments listed in
|
|
176
|
+
the official Uniswap v4 deployment docs: Ethereum, Optimism, Unichain, Polygon,
|
|
177
|
+
Base, and Arbitrum.
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
import { base } from 'viem/chains'
|
|
181
|
+
import { UNISWAP_V4_CONTRACTS_BY_CHAIN } from 'aegis-swap-widget'
|
|
182
|
+
|
|
183
|
+
<AegisSwapWidget
|
|
184
|
+
chainId={8453}
|
|
185
|
+
chains={{
|
|
186
|
+
8453: {
|
|
187
|
+
chain: base,
|
|
188
|
+
router: '0xYourAegisRouter',
|
|
189
|
+
rpcUrls: ['https://your-base-rpc.example'],
|
|
190
|
+
v4Contracts: UNISWAP_V4_CONTRACTS_BY_CHAIN[8453],
|
|
191
|
+
},
|
|
192
|
+
}}
|
|
193
|
+
pools={pools}
|
|
96
194
|
/>
|
|
97
195
|
```
|
|
98
196
|
|
|
99
|
-
For a new chain, provide a viem `chain`, router,
|
|
197
|
+
For a new chain that is not bundled, provide a viem `chain`, Aegis router, RPC
|
|
198
|
+
URLs, and `v4Contracts` with at least `permit2` and `quoter`. Include
|
|
199
|
+
`poolManager`, `positionManager`, `stateView`, and `universalRouter` when the
|
|
200
|
+
host app needs those addresses too. Pool entries can set `chainId`, `token`, and
|
|
201
|
+
`counterToken` when token addresses differ by chain.
|
|
100
202
|
|
|
101
203
|
## Token Icons
|
|
102
204
|
|
|
@@ -106,11 +208,11 @@ The widget fetches token icons by address using the metadata IDs from the Aegis
|
|
|
106
208
|
```tsx
|
|
107
209
|
<AegisSwapWidget
|
|
108
210
|
metadataEndpoint="/graphql/meta"
|
|
109
|
-
|
|
211
|
+
pools={pools}
|
|
110
212
|
/>
|
|
111
213
|
```
|
|
112
214
|
|
|
113
|
-
Use `metadataEndpoint={null}` to disable backend icon hydration. Tokens can also provide `iconUrl` directly
|
|
215
|
+
Use `metadataEndpoint={null}` to disable backend icon hydration. Tokens can also provide `iconUrl` directly.
|
|
114
216
|
|
|
115
217
|
## With Existing Wallet UI
|
|
116
218
|
|
|
@@ -121,7 +223,7 @@ If a site already has wallet state, pass its EIP-1193 provider and account:
|
|
|
121
223
|
provider={provider}
|
|
122
224
|
account={account}
|
|
123
225
|
onConnectWallet={openWallet}
|
|
124
|
-
|
|
226
|
+
defaultPoolId="STONE_USDC"
|
|
125
227
|
onSubmitted={(hash) => console.log(hash)}
|
|
126
228
|
/>
|
|
127
229
|
```
|
|
@@ -154,25 +256,79 @@ host connect modal creates the provider during the button click:
|
|
|
154
256
|
If none of these props are supplied, the widget still checks `window.ethereum`
|
|
155
257
|
automatically when it renders and again when the user clicks connect/swap.
|
|
156
258
|
|
|
259
|
+
## UI Integration
|
|
260
|
+
|
|
261
|
+
Use `className` for host CSS selectors and `style` for one-off layout overrides or CSS variables:
|
|
262
|
+
|
|
263
|
+
```tsx
|
|
264
|
+
<AegisSwapWidget
|
|
265
|
+
className="partner-swap"
|
|
266
|
+
style={{ maxWidth: 520 }}
|
|
267
|
+
title="Swap"
|
|
268
|
+
subtitle="Aegis direct pools"
|
|
269
|
+
ariaLabel="Partner swap"
|
|
270
|
+
/>
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
`accentColor`, `accentTextColor`, `title`, and `subtitle` are the intended props for making the widget fit a host surface without forking the component.
|
|
274
|
+
|
|
157
275
|
## Props
|
|
158
276
|
|
|
159
277
|
- `provider`: optional EIP-1193 provider. Defaults to auto-detected `window.ethereum`.
|
|
160
278
|
- `account`: optional connected account from the host wallet UI.
|
|
161
279
|
- `getProvider`: optional provider resolver for wallet libraries with async providers.
|
|
162
280
|
- `onConnectWallet`: optional callback for opening the host wallet modal. It may return `{ provider, account }`.
|
|
281
|
+
- `onSubmitted`: `(hash, swap?)` fired when the swap transaction is sent. `swap` carries mode, token symbols, amounts, and fee for analytics.
|
|
282
|
+
- `onSuccess`: `({ hash, explorerUrl, swap? })` fired when the receipt confirms.
|
|
283
|
+
- `onError`: `(error)` fired on approval/swap failures (after the widget shows its own message).
|
|
284
|
+
- `onQuote`: `(quote)` fired on every quote refresh.
|
|
163
285
|
- `chainId`: active chain id. Defaults to Ethereum mainnet.
|
|
164
|
-
- `chains`: optional chain config overrides or additional chain configs
|
|
165
|
-
- `
|
|
166
|
-
- `
|
|
167
|
-
- `
|
|
168
|
-
- `defaultDirection`: `
|
|
169
|
-
- `markets`:
|
|
170
|
-
- `
|
|
286
|
+
- `chains`: optional chain config overrides or additional chain configs, including per-chain `v4Contracts`.
|
|
287
|
+
- `pools`: direct pool configs to render and swap against. This is the canonical config path.
|
|
288
|
+
- `defaultPoolId`: initial pool id when `pools` is provided.
|
|
289
|
+
- `poolIds`: optional pool id order/subset. Use this when the host wants to hide pools or control ordering.
|
|
290
|
+
- `defaultDirection`: `buy` (counter token into the pool token) or `sell`. The legacy `intoTarget`/`outOfTarget` values still work but are deprecated.
|
|
291
|
+
- `markets`: **deprecated** advanced override; pass `pools` (or `Object.values(markets)`) instead.
|
|
292
|
+
- `defaultSlippagePercent`: number (canonical) or numeric string, in percent. Defaults to `1`.
|
|
293
|
+
- `rpcUrls`: RPC fallback list for the active chain, or a `{ [chainId]: string[] }` map for multichain hosts.
|
|
171
294
|
- `metadataEndpoint`: optional metadata GraphQL endpoint for `GlobalToken.iconURL` token icons. Set to `null` to disable.
|
|
172
|
-
- `
|
|
173
|
-
- `
|
|
174
|
-
- `
|
|
295
|
+
- `className`: optional class for host layout and styling hooks.
|
|
296
|
+
- `style`: optional root style object, useful for host layout constraints or CSS variables.
|
|
297
|
+
- `title`: optional widget heading. Empty by default (compact topbar, no header row).
|
|
298
|
+
- `subtitle`: optional header eyebrow. Defaults to empty. Pass a string to show it.
|
|
299
|
+
- `ariaLabel`: optional accessible label for the widget region.
|
|
300
|
+
- `theme`: `dark`, `light`, or `auto` (follows `prefers-color-scheme`). Defaults to `dark`.
|
|
301
|
+
- `accentColor`: CSS accent color for the CTA, selected pools, focus states, links, and swap controls. When set without `accentTextColor`, the widget derives a readable CTA text color automatically (see Appearance for supported color formats).
|
|
175
302
|
- `accentTextColor`: optional CTA text color for contrast with the chosen accent.
|
|
303
|
+
- `showPoolLink`: whether to render the direct-pool link when the active chain provides `poolExplorerUrl`.
|
|
304
|
+
- `defaultApprovalMode`: `exact` approves only the current quote spend by default; `max` opts into the old unlimited ERC-20 to Permit2 approval behavior.
|
|
305
|
+
- `showApprovalModeControl`: whether the details drawer exposes the Exact/Max approval toggle. Defaults to `true`.
|
|
306
|
+
- `showExecutionDetails`: whether to render the collapsible settings drawer for slippage, approval mode, and route. Defaults to `true`.
|
|
307
|
+
- `defaultExecutionDetailsOpen`: whether that settings drawer starts expanded. Defaults to `false`.
|
|
308
|
+
|
|
309
|
+
The widget intentionally does not inherit the host font; set the
|
|
310
|
+
`--aegis-swap-font-family` CSS variable (via `style` or a stylesheet) to match
|
|
311
|
+
the host typography.
|
|
312
|
+
|
|
313
|
+
### With wagmi
|
|
314
|
+
|
|
315
|
+
The widget consumes the host's wallet instead of bundling its own connect UI.
|
|
316
|
+
From a wagmi app, derive the EIP-1193 provider from the active connector:
|
|
317
|
+
|
|
318
|
+
```tsx
|
|
319
|
+
import { useAccount } from 'wagmi'
|
|
320
|
+
|
|
321
|
+
function Swap() {
|
|
322
|
+
const { address, connector } = useAccount()
|
|
323
|
+
return (
|
|
324
|
+
<AegisSwapWidget
|
|
325
|
+
account={address}
|
|
326
|
+
getProvider={async () => (await connector?.getProvider()) ?? null}
|
|
327
|
+
onConnectWallet={openConnectModal}
|
|
328
|
+
/>
|
|
329
|
+
)
|
|
330
|
+
}
|
|
331
|
+
```
|
|
176
332
|
|
|
177
333
|
## Default Markets
|
|
178
334
|
|
|
@@ -183,11 +339,34 @@ The package ships mainnet direct-pool configs for:
|
|
|
183
339
|
- `USDC / GRASS`
|
|
184
340
|
- `USDC / STONE`
|
|
185
341
|
|
|
186
|
-
These use the Aegis mainnet router `0x00581261a1200956ea05d1810fF28ffd66D8E254
|
|
342
|
+
These use the Aegis mainnet router `0x00581261a1200956ea05d1810fF28ffd66D8E254`
|
|
343
|
+
and the Ethereum entry in `UNISWAP_V4_CONTRACTS_BY_CHAIN` for Permit2 and the
|
|
344
|
+
public Uniswap v4 Quoter.
|
|
345
|
+
|
|
346
|
+
## License
|
|
347
|
+
|
|
348
|
+
MIT.
|
|
187
349
|
|
|
188
350
|
## Local Demo
|
|
189
351
|
|
|
190
352
|
```bash
|
|
191
|
-
npm
|
|
353
|
+
npm ci
|
|
192
354
|
npm run dev
|
|
193
355
|
```
|
|
356
|
+
|
|
357
|
+
## Releasing
|
|
358
|
+
|
|
359
|
+
Maintainer release flow (publishes to npm). `dist/` is not committed — the `prepack`
|
|
360
|
+
hook rebuilds it on every `npm pack`/`npm publish`, and `prepublishOnly` runs the
|
|
361
|
+
typecheck + test gate.
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
git switch main && git pull
|
|
365
|
+
npm ci
|
|
366
|
+
npm run typecheck && npm run test && npm run build
|
|
367
|
+
# Move CHANGELOG [Unreleased] entries under the new version heading.
|
|
368
|
+
npm version patch # e.g. 0.1.2 -> 0.1.3; commits and tags vX.Y.Z
|
|
369
|
+
git push origin main --follow-tags
|
|
370
|
+
npm publish --access public # prepublishOnly gate + prepack build run automatically
|
|
371
|
+
npm view aegis-swap-widget version
|
|
372
|
+
```
|
package/dist/abis.d.ts
CHANGED
|
@@ -72,6 +72,24 @@ export declare const AEGIS_ROUTER_ABI: readonly [{
|
|
|
72
72
|
readonly outputs: readonly [];
|
|
73
73
|
}];
|
|
74
74
|
export declare const PERMIT2_ABI: readonly [{
|
|
75
|
+
readonly type: "function";
|
|
76
|
+
readonly name: "approve";
|
|
77
|
+
readonly stateMutability: "nonpayable";
|
|
78
|
+
readonly inputs: readonly [{
|
|
79
|
+
readonly name: "token";
|
|
80
|
+
readonly type: "address";
|
|
81
|
+
}, {
|
|
82
|
+
readonly name: "spender";
|
|
83
|
+
readonly type: "address";
|
|
84
|
+
}, {
|
|
85
|
+
readonly name: "amount";
|
|
86
|
+
readonly type: "uint160";
|
|
87
|
+
}, {
|
|
88
|
+
readonly name: "expiration";
|
|
89
|
+
readonly type: "uint48";
|
|
90
|
+
}];
|
|
91
|
+
readonly outputs: readonly [];
|
|
92
|
+
}, {
|
|
75
93
|
readonly type: "function";
|
|
76
94
|
readonly name: "allowance";
|
|
77
95
|
readonly stateMutability: "view";
|
|
@@ -185,4 +203,3 @@ export declare const UNISWAP_V4_QUOTER_ABI: readonly [{
|
|
|
185
203
|
readonly type: "uint256";
|
|
186
204
|
}];
|
|
187
205
|
}];
|
|
188
|
-
//# sourceMappingURL=abis.d.ts.map
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { Address, Hex } from 'viem';
|
|
2
|
+
export declare function addressKey(address: Address | null | undefined): string;
|
|
3
|
+
export declare function sameAddress(a: Address, b: Address): boolean;
|
|
4
|
+
export declare function sameOptionalAddress(a: Address | null, b: Address | null): boolean;
|
|
5
|
+
export declare function samePoolId(a: Hex, b: Hex): boolean;
|