aegis-swap-widget 0.1.0 → 0.1.2
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/README.md +131 -29
- package/dist/aegis-swap-widget.js +825 -656
- package/dist/config.d.ts +41 -16
- package/dist/config.d.ts.map +1 -1
- package/dist/encoding.d.ts +6 -0
- package/dist/encoding.d.ts.map +1 -1
- package/dist/index.d.ts +8 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/quote.d.ts +6 -1
- package/dist/quote.d.ts.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
# Aegis Swap Widget
|
|
2
2
|
|
|
3
|
-
Embeddable React swap widget for
|
|
3
|
+
Embeddable React swap widget for Aegis direct pools. It does not import the private Aegis Engine SDK and does not use Uniswap widget packages.
|
|
4
4
|
|
|
5
5
|
The widget quotes the configured Uniswap v4 pool, handles ERC20 approval to Permit2, signs a Permit2 batch for the Aegis router, and submits the direct pool swap.
|
|
6
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
|
+
On Ethereum mainnet, widget swaps apply a fixed 50 bps output-token fee to
|
|
12
|
+
`0x8ea2C7de60ef1Cd4dcE64ea2DDDe2f99F0127eFC`. The widget does not apply this
|
|
13
|
+
fee on other chains yet.
|
|
14
|
+
|
|
7
15
|
## Install
|
|
8
16
|
|
|
9
17
|
```bash
|
|
@@ -19,7 +27,6 @@ import 'aegis-swap-widget/styles.css'
|
|
|
19
27
|
export function Swap() {
|
|
20
28
|
return (
|
|
21
29
|
<AegisSwapWidget
|
|
22
|
-
defaultTarget="GRASS"
|
|
23
30
|
theme="dark"
|
|
24
31
|
accentColor="#31d48a"
|
|
25
32
|
/>
|
|
@@ -27,6 +34,8 @@ export function Swap() {
|
|
|
27
34
|
}
|
|
28
35
|
```
|
|
29
36
|
|
|
37
|
+
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.
|
|
38
|
+
|
|
30
39
|
By default the component uses `window.ethereum` when available, so injected wallets
|
|
31
40
|
like MetaMask and Rabby work without any wallet props.
|
|
32
41
|
|
|
@@ -48,34 +57,99 @@ Hosts can choose the widget surface and brand accent at instantiation time:
|
|
|
48
57
|
|
|
49
58
|
`theme` supports `dark` and `light`. `accentColor` accepts any CSS color value and is used for the CTA, selected pools, focus states, links, and swap controls. `accentTextColor` is optional and only needed when the accent color needs a different CTA text color for contrast.
|
|
50
59
|
|
|
51
|
-
##
|
|
60
|
+
## Configure Pools
|
|
61
|
+
|
|
62
|
+
Pass the direct pools you want to expose. This is the recommended integration path because it is not tied to any specific asset list.
|
|
63
|
+
|
|
64
|
+
For the first WATER, WOOD, GRASS, and STONE implementors, use the bundled mainnet pool configs:
|
|
65
|
+
|
|
66
|
+
```tsx
|
|
67
|
+
import { AegisSwapWidget, AEGIS_SWAP_MARKETS } from 'aegis-swap-widget'
|
|
68
|
+
import 'aegis-swap-widget/styles.css'
|
|
69
|
+
|
|
70
|
+
const pools = [
|
|
71
|
+
AEGIS_SWAP_MARKETS.WATER_USDC,
|
|
72
|
+
AEGIS_SWAP_MARKETS.WOOD_USDC,
|
|
73
|
+
AEGIS_SWAP_MARKETS.GRASS_USDC,
|
|
74
|
+
AEGIS_SWAP_MARKETS.STONE_USDC,
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
export function Swap() {
|
|
78
|
+
return (
|
|
79
|
+
<AegisSwapWidget
|
|
80
|
+
pools={pools}
|
|
81
|
+
defaultPoolId="WATER_USDC"
|
|
82
|
+
theme="dark"
|
|
83
|
+
accentColor="#31d48a"
|
|
84
|
+
/>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Use `defaultPoolId` to choose which pool opens first. Use `targets` when a host wants a different pool order or subset:
|
|
90
|
+
|
|
91
|
+
```tsx
|
|
92
|
+
<AegisSwapWidget
|
|
93
|
+
pools={pools}
|
|
94
|
+
defaultPoolId="GRASS_USDC"
|
|
95
|
+
targets={['GRASS_USDC', 'WATER_USDC']}
|
|
96
|
+
/>
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Fees
|
|
100
|
+
|
|
101
|
+
The widget applies a fixed output-token fee only on Ethereum mainnet:
|
|
102
|
+
|
|
103
|
+
- Fee: `50` bps
|
|
104
|
+
- Recipient: `0x8ea2C7de60ef1Cd4dcE64ea2DDDe2f99F0127eFC`
|
|
52
105
|
|
|
53
|
-
|
|
106
|
+
This fee is internal to the widget and is not configured by host sites.
|
|
107
|
+
|
|
108
|
+
For custom assets, provide full pool and token metadata:
|
|
54
109
|
|
|
55
110
|
```tsx
|
|
56
111
|
import {
|
|
57
112
|
AegisSwapWidget,
|
|
58
|
-
|
|
59
|
-
|
|
113
|
+
AEGIS_DYNAMIC_FEE_FLAG,
|
|
114
|
+
AEGIS_SWAP_HOOK,
|
|
115
|
+
type AegisSwapPoolConfig,
|
|
60
116
|
} from 'aegis-swap-widget'
|
|
61
117
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
label: 'USDC /
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
118
|
+
const pools: AegisSwapPoolConfig[] = [
|
|
119
|
+
{
|
|
120
|
+
id: 'usdc-example',
|
|
121
|
+
label: 'USDC / EXAMPLE',
|
|
122
|
+
poolKey: {
|
|
123
|
+
currency0: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
124
|
+
currency1: '0xYourTokenAddress',
|
|
125
|
+
fee: AEGIS_DYNAMIC_FEE_FLAG,
|
|
126
|
+
tickSpacing: 60,
|
|
127
|
+
hooks: AEGIS_SWAP_HOOK,
|
|
128
|
+
},
|
|
129
|
+
counterToken: {
|
|
130
|
+
chainId: 1,
|
|
131
|
+
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
|
|
132
|
+
name: 'USD Coin',
|
|
133
|
+
symbol: 'USDC',
|
|
134
|
+
decimals: 6,
|
|
135
|
+
},
|
|
136
|
+
token: {
|
|
137
|
+
chainId: 1,
|
|
138
|
+
address: '0xYourTokenAddress',
|
|
139
|
+
name: 'Example Token',
|
|
140
|
+
symbol: 'EXAMPLE',
|
|
141
|
+
decimals: 18,
|
|
142
|
+
iconUrl: 'https://example.com/token.svg',
|
|
143
|
+
},
|
|
70
144
|
},
|
|
71
|
-
|
|
145
|
+
]
|
|
72
146
|
|
|
73
147
|
export function Swap() {
|
|
74
|
-
return <AegisSwapWidget
|
|
148
|
+
return <AegisSwapWidget pools={pools} defaultPoolId="usdc-example" />
|
|
75
149
|
}
|
|
76
150
|
```
|
|
77
151
|
|
|
78
|
-
|
|
152
|
+
Each pool can override `router`, `permit2`, `quoter`, and `poolId`. If omitted, those values come from the active chain config.
|
|
79
153
|
|
|
80
154
|
## Chains
|
|
81
155
|
|
|
@@ -92,11 +166,38 @@ import { mainnet } from 'viem/chains'
|
|
|
92
166
|
rpcUrls: ['https://your-mainnet-rpc.example'],
|
|
93
167
|
},
|
|
94
168
|
}}
|
|
95
|
-
|
|
169
|
+
pools={pools}
|
|
170
|
+
/>
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Uniswap v4 deployments are configured per chain. The package exports
|
|
174
|
+
`UNISWAP_V4_CONTRACTS_BY_CHAIN` for the supported mainnet deployments listed in
|
|
175
|
+
the official Uniswap v4 deployment docs: Ethereum, Optimism, Unichain, Polygon,
|
|
176
|
+
Base, and Arbitrum.
|
|
177
|
+
|
|
178
|
+
```tsx
|
|
179
|
+
import { base } from 'viem/chains'
|
|
180
|
+
import { UNISWAP_V4_CONTRACTS_BY_CHAIN } from 'aegis-swap-widget'
|
|
181
|
+
|
|
182
|
+
<AegisSwapWidget
|
|
183
|
+
chainId={8453}
|
|
184
|
+
chains={{
|
|
185
|
+
8453: {
|
|
186
|
+
chain: base,
|
|
187
|
+
router: '0xYourAegisRouter',
|
|
188
|
+
rpcUrls: ['https://your-base-rpc.example'],
|
|
189
|
+
v4Contracts: UNISWAP_V4_CONTRACTS_BY_CHAIN[8453],
|
|
190
|
+
},
|
|
191
|
+
}}
|
|
192
|
+
pools={pools}
|
|
96
193
|
/>
|
|
97
194
|
```
|
|
98
195
|
|
|
99
|
-
For a new chain, provide a viem `chain`, router,
|
|
196
|
+
For a new chain that is not bundled, provide a viem `chain`, Aegis router, RPC
|
|
197
|
+
URLs, and `v4Contracts` with at least `permit2` and `quoter`. Include
|
|
198
|
+
`poolManager`, `positionManager`, `stateView`, and `universalRouter` when the
|
|
199
|
+
host app needs those addresses too. Pool entries can set `chainId`, `token`, and
|
|
200
|
+
`counterToken` when token addresses differ by chain.
|
|
100
201
|
|
|
101
202
|
## Token Icons
|
|
102
203
|
|
|
@@ -106,11 +207,11 @@ The widget fetches token icons by address using the metadata IDs from the Aegis
|
|
|
106
207
|
```tsx
|
|
107
208
|
<AegisSwapWidget
|
|
108
209
|
metadataEndpoint="/graphql/meta"
|
|
109
|
-
|
|
210
|
+
pools={pools}
|
|
110
211
|
/>
|
|
111
212
|
```
|
|
112
213
|
|
|
113
|
-
Use `metadataEndpoint={null}` to disable backend icon hydration. Tokens can also provide `iconUrl` directly
|
|
214
|
+
Use `metadataEndpoint={null}` to disable backend icon hydration. Tokens can also provide `iconUrl` directly.
|
|
114
215
|
|
|
115
216
|
## With Existing Wallet UI
|
|
116
217
|
|
|
@@ -121,7 +222,7 @@ If a site already has wallet state, pass its EIP-1193 provider and account:
|
|
|
121
222
|
provider={provider}
|
|
122
223
|
account={account}
|
|
123
224
|
onConnectWallet={openWallet}
|
|
124
|
-
|
|
225
|
+
defaultPoolId="STONE_USDC"
|
|
125
226
|
onSubmitted={(hash) => console.log(hash)}
|
|
126
227
|
/>
|
|
127
228
|
```
|
|
@@ -161,16 +262,15 @@ automatically when it renders and again when the user clicks connect/swap.
|
|
|
161
262
|
- `getProvider`: optional provider resolver for wallet libraries with async providers.
|
|
162
263
|
- `onConnectWallet`: optional callback for opening the host wallet modal. It may return `{ provider, account }`.
|
|
163
264
|
- `chainId`: active chain id. Defaults to Ethereum mainnet.
|
|
164
|
-
- `chains`: optional chain config overrides or additional chain configs
|
|
165
|
-
- `
|
|
166
|
-
- `
|
|
167
|
-
- `
|
|
265
|
+
- `chains`: optional chain config overrides or additional chain configs, including per-chain `v4Contracts`.
|
|
266
|
+
- `pools`: direct pool configs to render and swap against.
|
|
267
|
+
- `defaultPoolId`: initial pool id when `pools` is provided.
|
|
268
|
+
- `targets`: optional pool id order/subset.
|
|
168
269
|
- `defaultDirection`: `intoTarget` for USDC to target, or `outOfTarget` for target to USDC.
|
|
169
|
-
- `markets`:
|
|
270
|
+
- `markets`: advanced override for normalized pool/router/quoter config.
|
|
170
271
|
- `rpcUrls`: optional RPC fallback list for the active chain.
|
|
171
272
|
- `metadataEndpoint`: optional metadata GraphQL endpoint for `GlobalToken.iconURL` token icons. Set to `null` to disable.
|
|
172
273
|
- `theme`: `dark` or `light`. Defaults to `dark`.
|
|
173
|
-
- `themeMode`: legacy alias for `theme`.
|
|
174
274
|
- `accentColor`: CSS accent color for the CTA, selected pools, focus states, links, and swap controls.
|
|
175
275
|
- `accentTextColor`: optional CTA text color for contrast with the chosen accent.
|
|
176
276
|
|
|
@@ -183,7 +283,9 @@ The package ships mainnet direct-pool configs for:
|
|
|
183
283
|
- `USDC / GRASS`
|
|
184
284
|
- `USDC / STONE`
|
|
185
285
|
|
|
186
|
-
These use the Aegis mainnet router `0x00581261a1200956ea05d1810fF28ffd66D8E254
|
|
286
|
+
These use the Aegis mainnet router `0x00581261a1200956ea05d1810fF28ffd66D8E254`
|
|
287
|
+
and the Ethereum entry in `UNISWAP_V4_CONTRACTS_BY_CHAIN` for Permit2 and the
|
|
288
|
+
public Uniswap v4 Quoter.
|
|
187
289
|
|
|
188
290
|
## Local Demo
|
|
189
291
|
|