@centurion_project/universal-router-sdk 5.1.0-ctn.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/README.md +332 -0
- package/dist/cjs/src/entities/Command.d.ts +12 -0
- package/dist/cjs/src/entities/Command.js +9 -0
- package/dist/cjs/src/entities/Command.js.map +1 -0
- package/dist/cjs/src/entities/actions/across.d.ts +21 -0
- package/dist/cjs/src/entities/actions/across.js +7 -0
- package/dist/cjs/src/entities/actions/across.js.map +1 -0
- package/dist/cjs/src/entities/actions/index.d.ts +3 -0
- package/dist/cjs/src/entities/actions/index.js +7 -0
- package/dist/cjs/src/entities/actions/index.js.map +1 -0
- package/dist/cjs/src/entities/actions/uniswap.d.ts +38 -0
- package/dist/cjs/src/entities/actions/uniswap.js +545 -0
- package/dist/cjs/src/entities/actions/uniswap.js.map +1 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.js +33 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/cjs/src/entities/index.d.ts +2 -0
- package/dist/cjs/src/entities/index.js +6 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/cjs/src/index.d.ts +11 -0
- package/dist/cjs/src/index.js +31 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/cjs/src/swapRouter.d.ts +87 -0
- package/dist/cjs/src/swapRouter.js +263 -0
- package/dist/cjs/src/swapRouter.js.map +1 -0
- package/dist/cjs/src/utils/commandParser.d.ts +34 -0
- package/dist/cjs/src/utils/commandParser.js +145 -0
- package/dist/cjs/src/utils/commandParser.js.map +1 -0
- package/dist/cjs/src/utils/constants.d.ts +39 -0
- package/dist/cjs/src/utils/constants.js +549 -0
- package/dist/cjs/src/utils/constants.js.map +1 -0
- package/dist/cjs/src/utils/eip712.d.ts +17 -0
- package/dist/cjs/src/utils/eip712.js +43 -0
- package/dist/cjs/src/utils/eip712.js.map +1 -0
- package/dist/cjs/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/cjs/src/utils/getCurrencyAddress.js +9 -0
- package/dist/cjs/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/cjs/src/utils/inputTokens.d.ts +23 -0
- package/dist/cjs/src/utils/inputTokens.js +58 -0
- package/dist/cjs/src/utils/inputTokens.js.map +1 -0
- package/dist/cjs/src/utils/numbers.d.ts +7 -0
- package/dist/cjs/src/utils/numbers.js +27 -0
- package/dist/cjs/src/utils/numbers.js.map +1 -0
- package/dist/cjs/src/utils/pathCurrency.d.ts +3 -0
- package/dist/cjs/src/utils/pathCurrency.js +27 -0
- package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
- package/dist/cjs/src/utils/routerCommands.d.ts +77 -0
- package/dist/cjs/src/utils/routerCommands.js +334 -0
- package/dist/cjs/src/utils/routerCommands.js.map +1 -0
- package/dist/cjs/src/utils/routerTradeAdapter.d.ts +73 -0
- package/dist/cjs/src/utils/routerTradeAdapter.js +139 -0
- package/dist/cjs/src/utils/routerTradeAdapter.js.map +1 -0
- package/dist/esm/src/entities/Command.d.ts +12 -0
- package/dist/esm/src/entities/Command.js +6 -0
- package/dist/esm/src/entities/Command.js.map +1 -0
- package/dist/esm/src/entities/actions/across.d.ts +21 -0
- package/dist/esm/src/entities/actions/across.js +3 -0
- package/dist/esm/src/entities/actions/across.js.map +1 -0
- package/dist/esm/src/entities/actions/index.d.ts +3 -0
- package/dist/esm/src/entities/actions/index.js +4 -0
- package/dist/esm/src/entities/actions/index.js.map +1 -0
- package/dist/esm/src/entities/actions/uniswap.d.ts +38 -0
- package/dist/esm/src/entities/actions/uniswap.js +541 -0
- package/dist/esm/src/entities/actions/uniswap.js.map +1 -0
- package/dist/esm/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/esm/src/entities/actions/unwrapWETH.js +28 -0
- package/dist/esm/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/esm/src/entities/index.d.ts +2 -0
- package/dist/esm/src/entities/index.js +3 -0
- package/dist/esm/src/entities/index.js.map +1 -0
- package/dist/esm/src/index.d.ts +11 -0
- package/dist/esm/src/index.js +8 -0
- package/dist/esm/src/index.js.map +1 -0
- package/dist/esm/src/swapRouter.d.ts +87 -0
- package/dist/esm/src/swapRouter.js +258 -0
- package/dist/esm/src/swapRouter.js.map +1 -0
- package/dist/esm/src/utils/commandParser.d.ts +34 -0
- package/dist/esm/src/utils/commandParser.js +137 -0
- package/dist/esm/src/utils/commandParser.js.map +1 -0
- package/dist/esm/src/utils/constants.d.ts +39 -0
- package/dist/esm/src/utils/constants.js +541 -0
- package/dist/esm/src/utils/constants.js.map +1 -0
- package/dist/esm/src/utils/eip712.d.ts +17 -0
- package/dist/esm/src/utils/eip712.js +38 -0
- package/dist/esm/src/utils/eip712.js.map +1 -0
- package/dist/esm/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/esm/src/utils/getCurrencyAddress.js +5 -0
- package/dist/esm/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/esm/src/utils/inputTokens.d.ts +23 -0
- package/dist/esm/src/utils/inputTokens.js +51 -0
- package/dist/esm/src/utils/inputTokens.js.map +1 -0
- package/dist/esm/src/utils/numbers.d.ts +7 -0
- package/dist/esm/src/utils/numbers.js +19 -0
- package/dist/esm/src/utils/numbers.js.map +1 -0
- package/dist/esm/src/utils/pathCurrency.d.ts +3 -0
- package/dist/esm/src/utils/pathCurrency.js +23 -0
- package/dist/esm/src/utils/pathCurrency.js.map +1 -0
- package/dist/esm/src/utils/routerCommands.d.ts +77 -0
- package/dist/esm/src/utils/routerCommands.js +329 -0
- package/dist/esm/src/utils/routerCommands.js.map +1 -0
- package/dist/esm/src/utils/routerTradeAdapter.d.ts +73 -0
- package/dist/esm/src/utils/routerTradeAdapter.js +134 -0
- package/dist/esm/src/utils/routerTradeAdapter.js.map +1 -0
- package/dist/types/src/entities/Command.d.ts +12 -0
- package/dist/types/src/entities/actions/across.d.ts +21 -0
- package/dist/types/src/entities/actions/index.d.ts +3 -0
- package/dist/types/src/entities/actions/uniswap.d.ts +38 -0
- package/dist/types/src/entities/actions/unwrapWETH.d.ts +12 -0
- package/dist/types/src/entities/index.d.ts +2 -0
- package/dist/types/src/index.d.ts +11 -0
- package/dist/types/src/swapRouter.d.ts +87 -0
- package/dist/types/src/utils/commandParser.d.ts +34 -0
- package/dist/types/src/utils/constants.d.ts +39 -0
- package/dist/types/src/utils/eip712.d.ts +17 -0
- package/dist/types/src/utils/getCurrencyAddress.d.ts +2 -0
- package/dist/types/src/utils/inputTokens.d.ts +23 -0
- package/dist/types/src/utils/numbers.d.ts +7 -0
- package/dist/types/src/utils/pathCurrency.d.ts +3 -0
- package/dist/types/src/utils/routerCommands.d.ts +77 -0
- package/dist/types/src/utils/routerTradeAdapter.d.ts +73 -0
- package/package.json +85 -0
package/README.md
ADDED
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
# universal-router-sdk
|
|
2
|
+
|
|
3
|
+
This SDK facilitates interactions with the contracts in [Universal Router](https://github.com/Uniswap/universal-router)
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Install latest version of universal-router-sdk. Then import the corresponding Trade class and Data object for each protocol you'd like to interact with.
|
|
8
|
+
|
|
9
|
+
### Trading on Uniswap
|
|
10
|
+
|
|
11
|
+
warning: `swapERC20CallParameters()` to be deprecated in favor of `swapCallParameters()`
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { TradeType } from '@uniswap/sdk-core'
|
|
15
|
+
import { Trade as V2TradeSDK } from '@uniswap/v2-sdk'
|
|
16
|
+
import { Trade as V3TradeSDK } from '@uniswap/v3-sdk'
|
|
17
|
+
import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk'
|
|
18
|
+
|
|
19
|
+
const options = { slippageTolerance, recipient }
|
|
20
|
+
const routerTrade = new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_INPUT })
|
|
21
|
+
// Use the raw calldata and value returned to call into Universal Swap Router contracts
|
|
22
|
+
const { calldata, value } = SwapRouter.swapCallParameters(routerTrade, options)
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Running this package
|
|
26
|
+
|
|
27
|
+
Make sure you are running `node v18`
|
|
28
|
+
Install dependencies and run typescript unit tests
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
yarn install
|
|
32
|
+
yarn test:hardhat
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Run forge integration tests
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
forge install
|
|
39
|
+
yarn test:forge
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Per-Hop Slippage Protection
|
|
43
|
+
|
|
44
|
+
Universal Router v2.1.1 adds granular slippage protection for multi-hop swaps across all protocol versions (V2, V3, V4, and mixed routes). In addition to the overall trade-level slippage check, the contract can verify that each individual pool hop doesn't exceed a maximum price limit.
|
|
45
|
+
|
|
46
|
+
### How It Works
|
|
47
|
+
|
|
48
|
+
Per-hop slippage bounds live on each swap's route data (via `RouterTrade`). The `maxHopSlippage` array on each route maps 1:1 to the route's pools: `maxHopSlippage[i]` constrains `route.pools[i]`.
|
|
49
|
+
|
|
50
|
+
To enable the V2.1.1 ABI encoding (which includes the `maxHopSlippage` parameter), set `urVersion: URVersion.V2_1_1` on your swap options.
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { SwapRouter } from '@uniswap/universal-router-sdk'
|
|
54
|
+
import { Trade as RouterTrade } from '@uniswap/router-sdk'
|
|
55
|
+
import { URVersion } from '@uniswap/v4-sdk'
|
|
56
|
+
import { Percent, TradeType } from '@uniswap/sdk-core'
|
|
57
|
+
|
|
58
|
+
// 1. Build a trade with per-hop slippage on each route
|
|
59
|
+
const trade = new RouterTrade({
|
|
60
|
+
v3Routes: [
|
|
61
|
+
{
|
|
62
|
+
routev3: myV3Route, // e.g. USDC → DAI → WETH
|
|
63
|
+
inputAmount,
|
|
64
|
+
outputAmount,
|
|
65
|
+
maxHopSlippage: [
|
|
66
|
+
// one entry per pool in the route
|
|
67
|
+
BigInt('1010000000000000000'), // Hop 0: USDC→DAI, max price 1.01
|
|
68
|
+
BigInt('2500000000000000000000'), // Hop 1: DAI→WETH, max price 2500
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
// 2. Encode with V2.1.1 ABI
|
|
76
|
+
const { calldata, value } = SwapRouter.swapCallParameters(trade, {
|
|
77
|
+
slippageTolerance: new Percent(50, 10000), // 0.5% overall slippage
|
|
78
|
+
recipient: '0x...',
|
|
79
|
+
urVersion: URVersion.V2_1_1, // required for per-hop encoding
|
|
80
|
+
})
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Price Calculation
|
|
84
|
+
|
|
85
|
+
Slippage is expressed as a **price** with 18 decimals of precision:
|
|
86
|
+
|
|
87
|
+
- `price = amountIn * 1e18 / amountOut`
|
|
88
|
+
|
|
89
|
+
If the calculated price for hop `i` exceeds `maxHopSlippage[i]`, the transaction reverts.
|
|
90
|
+
|
|
91
|
+
### Mixed Routes
|
|
92
|
+
|
|
93
|
+
For mixed routes that span multiple protocol versions (e.g. V3 pool → V4 pool → V2 pool), the SDK automatically slices the flat `maxHopSlippage` array by section. Each protocol section receives the corresponding slice of hop bounds:
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
const trade = new RouterTrade({
|
|
97
|
+
mixedRoutes: [
|
|
98
|
+
{
|
|
99
|
+
mixedRoute: myMixedRoute, // V3 pool, V3 pool, V2 pool
|
|
100
|
+
inputAmount,
|
|
101
|
+
outputAmount,
|
|
102
|
+
maxHopSlippage: [
|
|
103
|
+
BigInt('1010000000000000000'), // Hop 0 (V3 section)
|
|
104
|
+
BigInt('2500000000000000000000'), // Hop 1 (V3 section)
|
|
105
|
+
BigInt('1005000000000000000'), // Hop 2 (V2 section)
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
tradeType: TradeType.EXACT_INPUT,
|
|
110
|
+
})
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Benefits
|
|
114
|
+
|
|
115
|
+
1. **MEV Protection**: Prevents sandwich attacks on individual pool hops
|
|
116
|
+
2. **Route Quality**: Ensures each segment of a multi-hop route meets price expectations
|
|
117
|
+
3. **Granular Control**: Different slippage tolerances for different pairs (e.g. tighter bounds on stablecoin hops)
|
|
118
|
+
|
|
119
|
+
### Backward Compatibility
|
|
120
|
+
|
|
121
|
+
- If `maxHopSlippage` is omitted or is an empty array, only the overall trade-level slippage is checked
|
|
122
|
+
- If `urVersion` is not set (defaults to V2.0), commands use the standard ABI without `maxHopSlippage`
|
|
123
|
+
|
|
124
|
+
## Signed Routes (Universal Router v2.1)
|
|
125
|
+
|
|
126
|
+
Universal Router v2.1 supports EIP712-signed route execution, enabling gasless transactions and intent-based trading.
|
|
127
|
+
|
|
128
|
+
**Important**: The SDK does not perform signing. It provides utilities to prepare EIP712 payloads and encode signed calldata. You sign with your own mechanism (wallet, KMS, hardware, etc.).
|
|
129
|
+
|
|
130
|
+
### Basic Flow
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { SwapRouter, NONCE_SKIP_CHECK } from '@uniswap/universal-router-sdk'
|
|
134
|
+
import { Wallet } from '@ethersproject/wallet'
|
|
135
|
+
|
|
136
|
+
const wallet = new Wallet('0x...')
|
|
137
|
+
const chainId = 1
|
|
138
|
+
const routerAddress = '0x3fC91A3afd70395Cd496C647d5a6CC9D4B2b7FAD'
|
|
139
|
+
const deadline = Math.floor(Date.now() / 1000) + 60 * 20
|
|
140
|
+
|
|
141
|
+
// 1. Generate regular swap calldata
|
|
142
|
+
const { calldata, value } = SwapRouter.swapCallParameters(trade, {
|
|
143
|
+
slippageTolerance: new Percent(50, 10000),
|
|
144
|
+
recipient: wallet.address,
|
|
145
|
+
deadline,
|
|
146
|
+
})
|
|
147
|
+
|
|
148
|
+
// 2. Get EIP712 payload to sign
|
|
149
|
+
const payload = SwapRouter.getExecuteSignedPayload(
|
|
150
|
+
calldata,
|
|
151
|
+
{
|
|
152
|
+
intent: '0x' + '0'.repeat(64), // Application-specific intent
|
|
153
|
+
data: '0x' + '0'.repeat(64), // Application-specific data
|
|
154
|
+
sender: wallet.address, // Or address(0) to skip sender verification
|
|
155
|
+
},
|
|
156
|
+
deadline,
|
|
157
|
+
chainId,
|
|
158
|
+
routerAddress
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
// 3. Sign externally (wallet/KMS/hardware)
|
|
162
|
+
const signature = await wallet._signTypedData(payload.domain, payload.types, payload.value)
|
|
163
|
+
|
|
164
|
+
// 4. Encode for executeSigned()
|
|
165
|
+
const { calldata: signedCalldata, value: signedValue } = SwapRouter.encodeExecuteSigned(
|
|
166
|
+
calldata,
|
|
167
|
+
signature,
|
|
168
|
+
{
|
|
169
|
+
intent: payload.value.intent,
|
|
170
|
+
data: payload.value.data,
|
|
171
|
+
sender: payload.value.sender,
|
|
172
|
+
nonce: payload.value.nonce, // Must match what was signed
|
|
173
|
+
},
|
|
174
|
+
deadline,
|
|
175
|
+
BigNumber.from(value)
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
// 5. Submit transaction
|
|
179
|
+
await wallet.sendTransaction({
|
|
180
|
+
to: routerAddress,
|
|
181
|
+
data: signedCalldata,
|
|
182
|
+
value: signedValue,
|
|
183
|
+
})
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Nonce Management
|
|
187
|
+
|
|
188
|
+
- **Random nonce (default)**: Omit `nonce` parameter - SDK generates random nonce
|
|
189
|
+
- **Skip nonce check**: Use `NONCE_SKIP_CHECK` sentinel to allow signature reuse
|
|
190
|
+
- **Custom nonce**: Provide your own nonce for ordering
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
import { NONCE_SKIP_CHECK } from '@uniswap/universal-router-sdk'
|
|
194
|
+
|
|
195
|
+
// Reusable signature (no nonce check)
|
|
196
|
+
const payload = SwapRouter.getExecuteSignedPayload(
|
|
197
|
+
calldata,
|
|
198
|
+
{
|
|
199
|
+
intent: '0x...',
|
|
200
|
+
data: '0x...',
|
|
201
|
+
sender: '0x0000000000000000000000000000000000000000', // Skip sender verification too
|
|
202
|
+
nonce: NONCE_SKIP_CHECK, // Allow signature reuse
|
|
203
|
+
},
|
|
204
|
+
deadline,
|
|
205
|
+
chainId,
|
|
206
|
+
routerAddress
|
|
207
|
+
)
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
### Sender Verification
|
|
211
|
+
|
|
212
|
+
- **Verify sender**: Pass the actual sender address (e.g., `wallet.address`)
|
|
213
|
+
- **Skip verification**: Pass `'0x0000000000000000000000000000000000000000'`
|
|
214
|
+
|
|
215
|
+
The SDK automatically sets `verifySender` based on whether sender is address(0).
|
|
216
|
+
|
|
217
|
+
## Cross-Chain Bridging with Across (Universal Router v2.1)
|
|
218
|
+
|
|
219
|
+
Universal Router v2.1 integrates with Across Protocol V3 to enable seamless cross-chain bridging after swaps. This allows you to swap tokens on one chain and automatically bridge them to another chain in a single transaction.
|
|
220
|
+
|
|
221
|
+
### Basic Usage
|
|
222
|
+
|
|
223
|
+
```typescript
|
|
224
|
+
import { SwapRouter } from '@uniswap/universal-router-sdk'
|
|
225
|
+
import { BigNumber } from 'ethers'
|
|
226
|
+
|
|
227
|
+
// 1. Prepare your swap (e.g., USDC → WETH on mainnet)
|
|
228
|
+
const { calldata, value } = SwapRouter.swapCallParameters(trade, swapOptions, [
|
|
229
|
+
{
|
|
230
|
+
// Bridge configuration
|
|
231
|
+
depositor: userAddress,
|
|
232
|
+
recipient: userAddress, // Recipient on destination chain
|
|
233
|
+
inputToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH mainnet
|
|
234
|
+
outputToken: '0x4200000000000000000000000000000000000006', // WETH optimism
|
|
235
|
+
inputAmount: BigNumber.from('1000000000000000000'), // 1 WETH
|
|
236
|
+
outputAmount: BigNumber.from('990000000000000000'), // 0.99 WETH (with fees)
|
|
237
|
+
destinationChainId: 10, // Optimism
|
|
238
|
+
exclusiveRelayer: '0x0000000000000000000000000000000000000000',
|
|
239
|
+
quoteTimestamp: Math.floor(Date.now() / 1000),
|
|
240
|
+
fillDeadline: Math.floor(Date.now() / 1000) + 3600,
|
|
241
|
+
exclusivityDeadline: 0,
|
|
242
|
+
message: '0x',
|
|
243
|
+
useNative: false,
|
|
244
|
+
},
|
|
245
|
+
])
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### Swap + Bridge Example
|
|
249
|
+
|
|
250
|
+
```typescript
|
|
251
|
+
// Swap USDC to WETH, then bridge WETH to Optimism
|
|
252
|
+
const bridgeParams = {
|
|
253
|
+
depositor: userAddress,
|
|
254
|
+
recipient: userAddress, // Can be different address on destination
|
|
255
|
+
inputToken: WETH_MAINNET,
|
|
256
|
+
outputToken: WETH_OPTIMISM,
|
|
257
|
+
inputAmount: CONTRACT_BALANCE, // Use entire swap output
|
|
258
|
+
outputAmount: expectedOutputAmount,
|
|
259
|
+
destinationChainId: 10,
|
|
260
|
+
exclusiveRelayer: '0x0000000000000000000000000000000000000000',
|
|
261
|
+
quoteTimestamp: Math.floor(Date.now() / 1000),
|
|
262
|
+
fillDeadline: Math.floor(Date.now() / 1000) + 3600,
|
|
263
|
+
exclusivityDeadline: 0,
|
|
264
|
+
message: '0x', // Optional message to execute on destination
|
|
265
|
+
useNative: false, // Set to true to bridge native ETH
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const { calldata, value } = SwapRouter.swapCallParameters(
|
|
269
|
+
trade,
|
|
270
|
+
swapOptions,
|
|
271
|
+
[bridgeParams] // Array of bridge operations
|
|
272
|
+
)
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Using CONTRACT_BALANCE
|
|
276
|
+
|
|
277
|
+
When bridging after a swap, you often don't know the exact output amount. Use `CONTRACT_BALANCE` to bridge the entire contract balance:
|
|
278
|
+
|
|
279
|
+
```typescript
|
|
280
|
+
import { CONTRACT_BALANCE } from '@uniswap/universal-router-sdk'
|
|
281
|
+
|
|
282
|
+
const bridgeParams = {
|
|
283
|
+
// ... other params
|
|
284
|
+
inputAmount: CONTRACT_BALANCE, // Bridge entire balance after swap
|
|
285
|
+
// ... other params
|
|
286
|
+
}
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### Multiple Bridge Operations
|
|
290
|
+
|
|
291
|
+
You can perform multiple bridge operations after a swap:
|
|
292
|
+
|
|
293
|
+
```typescript
|
|
294
|
+
const { calldata, value } = SwapRouter.swapCallParameters(trade, swapOptions, [
|
|
295
|
+
{
|
|
296
|
+
// Bridge 50% to Optimism
|
|
297
|
+
inputToken: WETH_MAINNET,
|
|
298
|
+
outputToken: WETH_OPTIMISM,
|
|
299
|
+
inputAmount: BigNumber.from('500000000000000000'),
|
|
300
|
+
destinationChainId: 10,
|
|
301
|
+
// ... other params
|
|
302
|
+
},
|
|
303
|
+
{
|
|
304
|
+
// Bridge remaining USDC to Arbitrum
|
|
305
|
+
inputToken: USDC_MAINNET,
|
|
306
|
+
outputToken: USDC_ARBITRUM,
|
|
307
|
+
inputAmount: CONTRACT_BALANCE,
|
|
308
|
+
destinationChainId: 42161,
|
|
309
|
+
// ... other params
|
|
310
|
+
},
|
|
311
|
+
])
|
|
312
|
+
```
|
|
313
|
+
|
|
314
|
+
### Native ETH Bridging
|
|
315
|
+
|
|
316
|
+
To bridge native ETH instead of WETH:
|
|
317
|
+
|
|
318
|
+
```typescript
|
|
319
|
+
const bridgeParams = {
|
|
320
|
+
inputToken: WETH_ADDRESS, // Must be WETH address
|
|
321
|
+
outputToken: WETH_ON_DESTINATION,
|
|
322
|
+
useNative: true, // Bridge as native ETH
|
|
323
|
+
// ... other params
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Important Notes
|
|
328
|
+
|
|
329
|
+
1. **Across Quote**: Bridge parameters (especially `outputAmount`, `quoteTimestamp`, `fillDeadline`) should come from the Across API quote
|
|
330
|
+
2. **Recipient Address**: Can be different from the sender, allowing cross-chain transfers to other addresses
|
|
331
|
+
3. **Message Passing**: The `message` field allows executing arbitrary calls on the destination chain
|
|
332
|
+
4. **Slippage**: The `outputAmount` already accounts for bridge fees and slippage
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { RoutePlanner } from '../utils/routerCommands';
|
|
2
|
+
export type TradeConfig = {
|
|
3
|
+
allowRevert: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare enum RouterActionType {
|
|
6
|
+
UniswapTrade = "UniswapTrade",
|
|
7
|
+
UnwrapWETH = "UnwrapWETH"
|
|
8
|
+
}
|
|
9
|
+
export interface Command {
|
|
10
|
+
tradeType: RouterActionType;
|
|
11
|
+
encode(planner: RoutePlanner, config: TradeConfig): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouterActionType = void 0;
|
|
4
|
+
var RouterActionType;
|
|
5
|
+
(function (RouterActionType) {
|
|
6
|
+
RouterActionType["UniswapTrade"] = "UniswapTrade";
|
|
7
|
+
RouterActionType["UnwrapWETH"] = "UnwrapWETH";
|
|
8
|
+
})(RouterActionType = exports.RouterActionType || (exports.RouterActionType = {}));
|
|
9
|
+
//# sourceMappingURL=Command.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Command.js","sourceRoot":"","sources":["../../../../src/entities/Command.ts"],"names":[],"mappings":";;;AAMA,IAAY,gBAGX;AAHD,WAAY,gBAAgB;IAC1B,iDAA6B,CAAA;IAC7B,6CAAyB,CAAA;AAC3B,CAAC,EAHW,gBAAgB,GAAhB,wBAAgB,KAAhB,wBAAgB,QAG3B"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BigNumberish } from 'ethers';
|
|
2
|
+
/**
|
|
3
|
+
* Parameters for Across V4 Deposit V3 command
|
|
4
|
+
* Used for cross-chain bridging via Across Protocol V3 SpokePool
|
|
5
|
+
*/
|
|
6
|
+
export type AcrossV4DepositV3Params = {
|
|
7
|
+
depositor: string;
|
|
8
|
+
recipient: string;
|
|
9
|
+
inputToken: string;
|
|
10
|
+
outputToken: string;
|
|
11
|
+
inputAmount: BigNumberish;
|
|
12
|
+
outputAmount: BigNumberish;
|
|
13
|
+
destinationChainId: number;
|
|
14
|
+
exclusiveRelayer: string;
|
|
15
|
+
quoteTimestamp: number;
|
|
16
|
+
fillDeadline: number;
|
|
17
|
+
exclusivityDeadline: number;
|
|
18
|
+
message: string;
|
|
19
|
+
useNative: boolean;
|
|
20
|
+
};
|
|
21
|
+
export { CONTRACT_BALANCE } from '../../utils/constants';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CONTRACT_BALANCE = void 0;
|
|
4
|
+
// Export CONTRACT_BALANCE constant for convenience
|
|
5
|
+
var constants_1 = require("../../utils/constants");
|
|
6
|
+
Object.defineProperty(exports, "CONTRACT_BALANCE", { enumerable: true, get: function () { return constants_1.CONTRACT_BALANCE; } });
|
|
7
|
+
//# sourceMappingURL=across.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"across.js","sourceRoot":"","sources":["../../../../../src/entities/actions/across.ts"],"names":[],"mappings":";;;AAsBA,mDAAmD;AACnD,mDAAwD;AAA/C,6GAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./uniswap"), exports);
|
|
5
|
+
tslib_1.__exportStar(require("./unwrapWETH"), exports);
|
|
6
|
+
tslib_1.__exportStar(require("./across"), exports);
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/entities/actions/index.ts"],"names":[],"mappings":";;;AAAA,oDAAyB;AACzB,uDAA4B;AAC5B,mDAAwB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { RoutePlanner } from '../../utils/routerCommands';
|
|
2
|
+
import { Trade as RouterTrade, SwapOptions as RouterSwapOptions } from '@centurion_project/router-sdk';
|
|
3
|
+
import { Permit2Permit } from '../../utils/inputTokens';
|
|
4
|
+
import { Currency, TradeType } from '@centurion_project/sdk-core';
|
|
5
|
+
import { Command, RouterActionType, TradeConfig } from '../Command';
|
|
6
|
+
import { UniversalRouterVersion } from '../../utils/constants';
|
|
7
|
+
import { BigNumberish } from 'ethers';
|
|
8
|
+
export type FlatFeeOptions = {
|
|
9
|
+
amount: BigNumberish;
|
|
10
|
+
recipient: string;
|
|
11
|
+
};
|
|
12
|
+
export declare enum TokenTransferMode {
|
|
13
|
+
Permit2 = "Permit2",
|
|
14
|
+
ApproveProxy = "ApproveProxy"
|
|
15
|
+
}
|
|
16
|
+
export type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> & {
|
|
17
|
+
useRouterBalance?: boolean;
|
|
18
|
+
inputTokenPermit?: Permit2Permit;
|
|
19
|
+
flatFee?: FlatFeeOptions;
|
|
20
|
+
safeMode?: boolean;
|
|
21
|
+
urVersion?: UniversalRouterVersion;
|
|
22
|
+
tokenTransferMode?: TokenTransferMode;
|
|
23
|
+
chainId?: number;
|
|
24
|
+
};
|
|
25
|
+
export declare class UniswapTrade implements Command {
|
|
26
|
+
trade: RouterTrade<Currency, Currency, TradeType>;
|
|
27
|
+
options: SwapOptions;
|
|
28
|
+
readonly tradeType: RouterActionType;
|
|
29
|
+
readonly payerIsUser: boolean;
|
|
30
|
+
constructor(trade: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions);
|
|
31
|
+
get isAllV4(): boolean;
|
|
32
|
+
get inputRequiresWrap(): boolean;
|
|
33
|
+
get inputRequiresUnwrap(): boolean;
|
|
34
|
+
get outputRequiresWrap(): boolean;
|
|
35
|
+
get outputRequiresUnwrap(): boolean;
|
|
36
|
+
get outputRequiresTransition(): boolean;
|
|
37
|
+
encode(planner: RoutePlanner, _config: TradeConfig): void;
|
|
38
|
+
}
|