@uniswap/universal-router-sdk 4.34.2 → 4.35.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 +104 -96
- package/dist/{entities → cjs/src/entities}/Command.d.ts +12 -12
- package/dist/cjs/src/entities/Command.js +9 -0
- package/dist/cjs/src/entities/Command.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/across.d.ts +21 -21
- package/dist/cjs/src/entities/actions/across.js +7 -0
- package/dist/cjs/src/entities/actions/across.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/index.d.ts +3 -3
- package/dist/cjs/src/entities/actions/index.js +7 -0
- package/dist/cjs/src/entities/actions/index.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/uniswap.d.ts +38 -39
- package/dist/cjs/src/entities/actions/uniswap.js +532 -0
- package/dist/cjs/src/entities/actions/uniswap.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/actions/unwrapWETH.d.ts +12 -12
- package/dist/cjs/src/entities/actions/unwrapWETH.js +33 -0
- package/dist/cjs/src/entities/actions/unwrapWETH.js.map +1 -0
- package/dist/{entities → cjs/src/entities}/index.d.ts +2 -2
- package/dist/cjs/src/entities/index.js +6 -0
- package/dist/cjs/src/entities/index.js.map +1 -0
- package/dist/{index.d.ts → cjs/src/index.d.ts} +12 -12
- package/dist/cjs/src/index.js +33 -0
- package/dist/cjs/src/index.js.map +1 -0
- package/dist/{swapRouter.d.ts → cjs/src/swapRouter.d.ts} +87 -87
- package/dist/cjs/src/swapRouter.js +276 -0
- package/dist/cjs/src/swapRouter.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/commandParser.d.ts +34 -34
- package/dist/cjs/src/utils/commandParser.js +145 -0
- package/dist/cjs/src/utils/commandParser.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/constants.d.ts +33 -33
- package/dist/cjs/src/utils/constants.js +541 -0
- package/dist/cjs/src/utils/constants.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/eip712.d.ts +17 -17
- package/dist/cjs/src/utils/eip712.js +43 -0
- package/dist/cjs/src/utils/eip712.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/getCurrencyAddress.d.ts +2 -2
- package/dist/cjs/src/utils/getCurrencyAddress.js +9 -0
- package/dist/cjs/src/utils/getCurrencyAddress.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/inputTokens.d.ts +23 -23
- package/dist/cjs/src/utils/inputTokens.js +58 -0
- package/dist/cjs/src/utils/inputTokens.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/numbers.d.ts +7 -6
- package/dist/cjs/src/utils/numbers.js +27 -0
- package/dist/cjs/src/utils/numbers.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/pathCurrency.d.ts +3 -3
- package/dist/cjs/src/utils/pathCurrency.js +27 -0
- package/dist/cjs/src/utils/pathCurrency.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/routerCommands.d.ts +77 -72
- package/dist/cjs/src/utils/routerCommands.js +334 -0
- package/dist/cjs/src/utils/routerCommands.js.map +1 -0
- package/dist/{utils → cjs/src/utils}/routerTradeAdapter.d.ts +73 -73
- 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 +528 -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 +12 -0
- package/dist/esm/src/index.js +9 -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 +271 -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 +33 -0
- package/dist/esm/src/utils/constants.js +534 -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 +12 -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 +33 -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 +31 -22
- package/dist/index.js +0 -8
- package/dist/test/forge/writeInterop.d.ts +0 -2
- package/dist/test/utils/addresses.d.ts +0 -5
- package/dist/test/utils/hexToDecimalString.d.ts +0 -2
- package/dist/test/utils/permit2.d.ts +0 -7
- package/dist/test/utils/uniswapData.d.ts +0 -24
- package/dist/universal-router-sdk.cjs.development.js +0 -1925
- package/dist/universal-router-sdk.cjs.development.js.map +0 -1
- package/dist/universal-router-sdk.cjs.production.min.js +0 -2
- package/dist/universal-router-sdk.cjs.production.min.js.map +0 -1
- package/dist/universal-router-sdk.esm.js +0 -1912
- package/dist/universal-router-sdk.esm.js.map +0 -1
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk';
|
|
2
|
+
import { CurrencyAmount, Ether, Token } from '@uniswap/sdk-core';
|
|
3
|
+
import { Pair, Route as V2Route } from '@uniswap/v2-sdk';
|
|
4
|
+
import { Pool as V3Pool, Route as V3Route } from '@uniswap/v3-sdk';
|
|
5
|
+
import { Pool as V4Pool, Route as V4Route } from '@uniswap/v4-sdk';
|
|
6
|
+
import { BigNumber } from 'ethers';
|
|
7
|
+
import { ETH_ADDRESS, E_ETH_ADDRESS } from './constants';
|
|
8
|
+
export var PoolType;
|
|
9
|
+
(function (PoolType) {
|
|
10
|
+
PoolType["V2Pool"] = "v2-pool";
|
|
11
|
+
PoolType["V3Pool"] = "v3-pool";
|
|
12
|
+
PoolType["V4Pool"] = "v4-pool";
|
|
13
|
+
})(PoolType || (PoolType = {}));
|
|
14
|
+
export const isNativeCurrency = (address) => address.toLowerCase() === ETH_ADDRESS.toLowerCase() || address.toLowerCase() === E_ETH_ADDRESS.toLowerCase();
|
|
15
|
+
// Helper class to convert routing-specific quote entities to RouterTrade entities
|
|
16
|
+
// the returned RouterTrade can then be used to build the UniswapTrade entity in this package
|
|
17
|
+
export class RouterTradeAdapter {
|
|
18
|
+
// Generate a RouterTrade using fields from a classic quote response
|
|
19
|
+
static fromClassicQuote(quote) {
|
|
20
|
+
const { route, tokenIn, tokenOut } = quote;
|
|
21
|
+
if (!route)
|
|
22
|
+
throw new Error('Expected route to be present');
|
|
23
|
+
if (!route.length)
|
|
24
|
+
throw new Error('Expected there to be at least one route');
|
|
25
|
+
if (route.some((r) => !r.length))
|
|
26
|
+
throw new Error('Expected all routes to have at least one pool');
|
|
27
|
+
const firstRoute = route[0];
|
|
28
|
+
const tokenInData = firstRoute[0].tokenIn;
|
|
29
|
+
const tokenOutData = firstRoute[firstRoute.length - 1].tokenOut;
|
|
30
|
+
if (!tokenInData || !tokenOutData)
|
|
31
|
+
throw new Error('Expected both tokenIn and tokenOut to be present');
|
|
32
|
+
if (tokenInData.chainId !== tokenOutData.chainId)
|
|
33
|
+
throw new Error('Expected tokenIn and tokenOut to be have same chainId');
|
|
34
|
+
const parsedCurrencyIn = RouterTradeAdapter.toCurrency(isNativeCurrency(tokenIn), tokenInData);
|
|
35
|
+
const parsedCurrencyOut = RouterTradeAdapter.toCurrency(isNativeCurrency(tokenOut), tokenOutData);
|
|
36
|
+
const typedRoutes = route.map((subRoute) => {
|
|
37
|
+
const rawAmountIn = subRoute[0].amountIn;
|
|
38
|
+
const rawAmountOut = subRoute[subRoute.length - 1].amountOut;
|
|
39
|
+
if (!rawAmountIn || !rawAmountOut) {
|
|
40
|
+
throw new Error('Expected both raw amountIn and raw amountOut to be present');
|
|
41
|
+
}
|
|
42
|
+
const inputAmount = CurrencyAmount.fromRawAmount(parsedCurrencyIn, rawAmountIn);
|
|
43
|
+
const outputAmount = CurrencyAmount.fromRawAmount(parsedCurrencyOut, rawAmountOut);
|
|
44
|
+
const isOnlyV2 = RouterTradeAdapter.isVersionedRoute(PoolType.V2Pool, subRoute);
|
|
45
|
+
const isOnlyV3 = RouterTradeAdapter.isVersionedRoute(PoolType.V3Pool, subRoute);
|
|
46
|
+
const isOnlyV4 = RouterTradeAdapter.isVersionedRoute(PoolType.V4Pool, subRoute);
|
|
47
|
+
return {
|
|
48
|
+
routev4: isOnlyV4
|
|
49
|
+
? new V4Route(subRoute.map(RouterTradeAdapter.toV4Pool), parsedCurrencyIn, parsedCurrencyOut)
|
|
50
|
+
: null,
|
|
51
|
+
routev3: isOnlyV3
|
|
52
|
+
? new V3Route(subRoute.map(RouterTradeAdapter.toV3Pool), parsedCurrencyIn, parsedCurrencyOut)
|
|
53
|
+
: null,
|
|
54
|
+
routev2: isOnlyV2
|
|
55
|
+
? new V2Route(subRoute.map(RouterTradeAdapter.toPair), parsedCurrencyIn, parsedCurrencyOut)
|
|
56
|
+
: null,
|
|
57
|
+
mixedRoute: !isOnlyV4 && !isOnlyV3 && !isOnlyV2
|
|
58
|
+
? new MixedRouteSDK(subRoute.map(RouterTradeAdapter.toPoolOrPair), parsedCurrencyIn, parsedCurrencyOut)
|
|
59
|
+
: null,
|
|
60
|
+
inputAmount,
|
|
61
|
+
outputAmount,
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
return new RouterTrade({
|
|
65
|
+
v2Routes: typedRoutes
|
|
66
|
+
.filter((route) => route.routev2)
|
|
67
|
+
.map((route) => ({
|
|
68
|
+
routev2: route.routev2,
|
|
69
|
+
inputAmount: route.inputAmount,
|
|
70
|
+
outputAmount: route.outputAmount,
|
|
71
|
+
})),
|
|
72
|
+
v3Routes: typedRoutes
|
|
73
|
+
.filter((route) => route.routev3)
|
|
74
|
+
.map((route) => ({
|
|
75
|
+
routev3: route.routev3,
|
|
76
|
+
inputAmount: route.inputAmount,
|
|
77
|
+
outputAmount: route.outputAmount,
|
|
78
|
+
})),
|
|
79
|
+
v4Routes: typedRoutes
|
|
80
|
+
.filter((route) => route.routev4)
|
|
81
|
+
.map((route) => ({
|
|
82
|
+
routev4: route.routev4,
|
|
83
|
+
inputAmount: route.inputAmount,
|
|
84
|
+
outputAmount: route.outputAmount,
|
|
85
|
+
})),
|
|
86
|
+
mixedRoutes: typedRoutes
|
|
87
|
+
.filter((route) => route.mixedRoute)
|
|
88
|
+
.map((route) => ({
|
|
89
|
+
mixedRoute: route.mixedRoute,
|
|
90
|
+
inputAmount: route.inputAmount,
|
|
91
|
+
outputAmount: route.outputAmount,
|
|
92
|
+
})),
|
|
93
|
+
tradeType: quote.tradeType,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
static toCurrency(isNative, token) {
|
|
97
|
+
if (isNative) {
|
|
98
|
+
return Ether.onChain(token.chainId);
|
|
99
|
+
}
|
|
100
|
+
return this.toToken(token);
|
|
101
|
+
}
|
|
102
|
+
static toToken(token) {
|
|
103
|
+
const { chainId, address, decimals, symbol, buyFeeBps, sellFeeBps } = token;
|
|
104
|
+
return new Token(chainId, address, parseInt(decimals.toString()), symbol,
|
|
105
|
+
/* name */ undefined, false, buyFeeBps ? BigNumber.from(buyFeeBps) : undefined, sellFeeBps ? BigNumber.from(sellFeeBps) : undefined);
|
|
106
|
+
}
|
|
107
|
+
static toV3Pool({ fee, sqrtRatioX96, liquidity, tickCurrent, tokenIn, tokenOut }) {
|
|
108
|
+
return new V3Pool(RouterTradeAdapter.toToken(tokenIn), RouterTradeAdapter.toToken(tokenOut), parseInt(fee), sqrtRatioX96, liquidity, parseInt(tickCurrent));
|
|
109
|
+
}
|
|
110
|
+
static toV4Pool(pool) {
|
|
111
|
+
const parsedCurrencyIn = RouterTradeAdapter.toCurrency(isNativeCurrency(pool.tokenIn.address), pool.tokenIn);
|
|
112
|
+
const parsedCurrencyOut = RouterTradeAdapter.toCurrency(isNativeCurrency(pool.tokenOut.address), pool.tokenOut);
|
|
113
|
+
return new V4Pool(parsedCurrencyIn, parsedCurrencyOut, parseInt(pool.fee), parseInt(pool.tickSpacing), pool.hooks, pool.sqrtRatioX96, pool.liquidity, parseInt(pool.tickCurrent));
|
|
114
|
+
}
|
|
115
|
+
static isVersionedRoute(type, route) {
|
|
116
|
+
return route.every((pool) => pool.type === type);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
RouterTradeAdapter.toPoolOrPair = (pool) => {
|
|
120
|
+
switch (pool.type) {
|
|
121
|
+
case PoolType.V4Pool:
|
|
122
|
+
return RouterTradeAdapter.toV4Pool(pool);
|
|
123
|
+
case PoolType.V3Pool:
|
|
124
|
+
return RouterTradeAdapter.toV3Pool(pool);
|
|
125
|
+
case PoolType.V2Pool:
|
|
126
|
+
return RouterTradeAdapter.toPair(pool);
|
|
127
|
+
default:
|
|
128
|
+
throw new Error('Invalid pool type');
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
RouterTradeAdapter.toPair = ({ reserve0, reserve1 }) => {
|
|
132
|
+
return new Pair(CurrencyAmount.fromRawAmount(RouterTradeAdapter.toToken(reserve0.token), reserve0.quotient), CurrencyAmount.fromRawAmount(RouterTradeAdapter.toToken(reserve1.token), reserve1.quotient));
|
|
133
|
+
};
|
|
134
|
+
//# sourceMappingURL=routerTradeAdapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routerTradeA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,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAC5F,CAAA;AACH,CAAC,CAAA"}
|
|
@@ -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,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,38 @@
|
|
|
1
|
+
import { RoutePlanner } from '../../utils/routerCommands';
|
|
2
|
+
import { URVersion } from '@uniswap/v4-sdk';
|
|
3
|
+
import { Trade as RouterTrade, SwapOptions as RouterSwapOptions } from '@uniswap/router-sdk';
|
|
4
|
+
import { Permit2Permit } from '../../utils/inputTokens';
|
|
5
|
+
import { Currency, TradeType } from '@uniswap/sdk-core';
|
|
6
|
+
import { Command, RouterActionType, TradeConfig } from '../Command';
|
|
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?: URVersion;
|
|
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
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BigNumberish } from 'ethers';
|
|
2
|
+
import { RoutePlanner } from '../../utils/routerCommands';
|
|
3
|
+
import { Permit2Permit } from '../../utils/inputTokens';
|
|
4
|
+
import { Command, RouterActionType, TradeConfig } from '../Command';
|
|
5
|
+
export declare class UnwrapWETH implements Command {
|
|
6
|
+
readonly tradeType: RouterActionType;
|
|
7
|
+
readonly permit2Data?: Permit2Permit;
|
|
8
|
+
readonly wethAddress: string;
|
|
9
|
+
readonly amount: BigNumberish;
|
|
10
|
+
constructor(amount: BigNumberish, chainId: number, permit2?: Permit2Permit);
|
|
11
|
+
encode(planner: RoutePlanner, _: TradeConfig): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { SwapRouter } from './swapRouter';
|
|
2
|
+
export type { MigrateV3ToV4Options, SignedRouteOptions, EIP712Payload } from './swapRouter';
|
|
3
|
+
export * from './entities';
|
|
4
|
+
export * from './utils/routerTradeAdapter';
|
|
5
|
+
export { RoutePlanner, CommandType, COMMAND_DEFINITION, Parser, Subparser } from './utils/routerCommands';
|
|
6
|
+
export type { CommandDefinition, ParamType } from './utils/routerCommands';
|
|
7
|
+
export { UNIVERSAL_ROUTER_CREATION_BLOCK, UNIVERSAL_ROUTER_ADDRESS, SWAP_PROXY_ADDRESS, ROUTER_AS_RECIPIENT, WETH_ADDRESS, UniversalRouterVersion, } from './utils/constants';
|
|
8
|
+
export { CommandParser, GenericCommandParser } from './utils/commandParser';
|
|
9
|
+
export type { UniversalRouterCommand, UniversalRouterCall, Param, CommandsDefinition } from './utils/commandParser';
|
|
10
|
+
export type { Permit2Permit } from './utils/inputTokens';
|
|
11
|
+
export { NONCE_SKIP_CHECK, generateNonce, EXECUTE_SIGNED_TYPES, getUniversalRouterDomain } from './utils/eip712';
|
|
12
|
+
export { URVersion, isAtLeastV2_1_1 } from '@uniswap/v4-sdk';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { BigNumber, BigNumberish } from 'ethers';
|
|
3
|
+
import { MethodParameters, Position as V3Position, RemoveLiquidityOptions as V3RemoveLiquidityOptions } from '@uniswap/v3-sdk';
|
|
4
|
+
import { Position as V4Position, AddLiquidityOptions as V4AddLiquidityOptions } from '@uniswap/v4-sdk';
|
|
5
|
+
import { Trade as RouterTrade } from '@uniswap/router-sdk';
|
|
6
|
+
import { Currency, TradeType } from '@uniswap/sdk-core';
|
|
7
|
+
import { SwapOptions } from './entities/actions/uniswap';
|
|
8
|
+
import { AcrossV4DepositV3Params } from './entities/actions/across';
|
|
9
|
+
import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer';
|
|
10
|
+
export type SwapRouterConfig = {
|
|
11
|
+
sender?: string;
|
|
12
|
+
deadline?: BigNumberish;
|
|
13
|
+
};
|
|
14
|
+
export type SignedRouteOptions = {
|
|
15
|
+
intent: string;
|
|
16
|
+
data: string;
|
|
17
|
+
sender: string;
|
|
18
|
+
nonce?: string;
|
|
19
|
+
};
|
|
20
|
+
export type EIP712Payload = {
|
|
21
|
+
domain: TypedDataDomain;
|
|
22
|
+
types: Record<string, TypedDataField[]>;
|
|
23
|
+
value: {
|
|
24
|
+
commands: string;
|
|
25
|
+
inputs: string[];
|
|
26
|
+
intent: string;
|
|
27
|
+
data: string;
|
|
28
|
+
sender: string;
|
|
29
|
+
nonce: string;
|
|
30
|
+
deadline: string;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export interface MigrateV3ToV4Options {
|
|
34
|
+
inputPosition: V3Position;
|
|
35
|
+
outputPosition: V4Position;
|
|
36
|
+
v3RemoveLiquidityOptions: V3RemoveLiquidityOptions;
|
|
37
|
+
v4AddLiquidityOptions: V4AddLiquidityOptions;
|
|
38
|
+
}
|
|
39
|
+
export declare abstract class SwapRouter {
|
|
40
|
+
static INTERFACE: Interface;
|
|
41
|
+
static PROXY_INTERFACE: Interface;
|
|
42
|
+
static swapCallParameters(trades: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions, bridgeOptions?: AcrossV4DepositV3Params[]): MethodParameters;
|
|
43
|
+
/**
|
|
44
|
+
* Generate EIP712 payload for signed execution (no signing performed)
|
|
45
|
+
* Decodes existing execute() calldata and prepares it for signing
|
|
46
|
+
*
|
|
47
|
+
* @param calldata The calldata from swapCallParameters() or similar
|
|
48
|
+
* @param signedOptions Options for signed execution (intent, data, sender, nonce)
|
|
49
|
+
* @param deadline The deadline timestamp
|
|
50
|
+
* @param chainId The chain ID
|
|
51
|
+
* @param routerAddress The Universal Router contract address
|
|
52
|
+
* @returns EIP712 payload ready to be signed externally
|
|
53
|
+
*/
|
|
54
|
+
static getExecuteSignedPayload(calldata: string, signedOptions: SignedRouteOptions, deadline: BigNumberish, chainId: number, routerAddress: string): EIP712Payload;
|
|
55
|
+
/**
|
|
56
|
+
* Encode executeSigned() call with signature
|
|
57
|
+
*
|
|
58
|
+
* @param calldata The original calldata from swapCallParameters()
|
|
59
|
+
* @param signature The signature obtained from external signing
|
|
60
|
+
* @param signedOptions The same options used in getExecuteSignedPayload()
|
|
61
|
+
* @param deadline The deadline timestamp
|
|
62
|
+
* @param nativeCurrencyValue The native currency value (ETH) to send
|
|
63
|
+
* @returns Method parameters for executeSigned()
|
|
64
|
+
*/
|
|
65
|
+
static encodeExecuteSigned(calldata: string, signature: string, signedOptions: SignedRouteOptions, deadline: BigNumberish, nativeCurrencyValue?: BigNumber): MethodParameters;
|
|
66
|
+
/**
|
|
67
|
+
* Builds the call parameters for a migration from a V3 position to a V4 position.
|
|
68
|
+
* Some requirements of the parameters:
|
|
69
|
+
* - v3RemoveLiquidityOptions.collectOptions.recipient must equal v4PositionManager
|
|
70
|
+
* - v3RemoveLiquidityOptions.liquidityPercentage must be 100%
|
|
71
|
+
* - input pool and output pool must have the same tokens
|
|
72
|
+
* - V3 NFT must be approved, or valid inputV3NFTPermit must be provided with UR as spender
|
|
73
|
+
*/
|
|
74
|
+
static migrateV3ToV4CallParameters(options: MigrateV3ToV4Options, positionManagerOverride?: string): MethodParameters;
|
|
75
|
+
/**
|
|
76
|
+
* Encodes a planned route into a method name and parameters for the Router contract.
|
|
77
|
+
* @param planner the planned route
|
|
78
|
+
* @param nativeCurrencyValue the native currency value of the planned route
|
|
79
|
+
* @param config the router config
|
|
80
|
+
*/
|
|
81
|
+
private static encodePlan;
|
|
82
|
+
/**
|
|
83
|
+
* Encodes a planned route into calldata targeting the SwapProxy contract.
|
|
84
|
+
* The proxy pulls ERC20 tokens from the user into the UR, then executes commands.
|
|
85
|
+
*/
|
|
86
|
+
private static encodeProxyPlan;
|
|
87
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Interface } from '@ethersproject/abi';
|
|
2
|
+
import { CommandType, CommandDefinition } from '../utils/routerCommands';
|
|
3
|
+
export type Param = {
|
|
4
|
+
readonly name: string;
|
|
5
|
+
readonly value: any;
|
|
6
|
+
};
|
|
7
|
+
export type UniversalRouterCommand = {
|
|
8
|
+
readonly commandName: string;
|
|
9
|
+
readonly commandType: CommandType;
|
|
10
|
+
readonly params: readonly Param[];
|
|
11
|
+
};
|
|
12
|
+
export type UniversalRouterCall = {
|
|
13
|
+
readonly commands: readonly UniversalRouterCommand[];
|
|
14
|
+
};
|
|
15
|
+
export type V3PathItem = {
|
|
16
|
+
readonly tokenIn: string;
|
|
17
|
+
readonly tokenOut: string;
|
|
18
|
+
readonly fee: number;
|
|
19
|
+
};
|
|
20
|
+
export interface CommandsDefinition {
|
|
21
|
+
[key: number]: CommandDefinition;
|
|
22
|
+
}
|
|
23
|
+
export declare abstract class CommandParser {
|
|
24
|
+
static INTERFACE: Interface;
|
|
25
|
+
static parseCalldata(calldata: string): UniversalRouterCall;
|
|
26
|
+
}
|
|
27
|
+
export declare class GenericCommandParser {
|
|
28
|
+
private readonly commandDefinition;
|
|
29
|
+
constructor(commandDefinition: CommandsDefinition);
|
|
30
|
+
parse(commands: string, inputs: string[]): UniversalRouterCall;
|
|
31
|
+
private static getCommands;
|
|
32
|
+
}
|
|
33
|
+
export declare function parseV3PathExactIn(path: string): readonly V3PathItem[];
|
|
34
|
+
export declare function parseV3PathExactOut(path: string): readonly V3PathItem[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
export declare enum UniversalRouterVersion {
|
|
3
|
+
V1_2 = "1.2",
|
|
4
|
+
V2_0 = "2.0",
|
|
5
|
+
V2_1_1 = "2.1.1"
|
|
6
|
+
}
|
|
7
|
+
export type RouterConfig = {
|
|
8
|
+
address: string;
|
|
9
|
+
creationBlock: number;
|
|
10
|
+
};
|
|
11
|
+
type ChainConfig = {
|
|
12
|
+
weth: string;
|
|
13
|
+
routerConfigs: {
|
|
14
|
+
[key in UniversalRouterVersion]?: RouterConfig;
|
|
15
|
+
};
|
|
16
|
+
swapProxy?: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const CHAIN_CONFIGS: {
|
|
19
|
+
[key: number]: ChainConfig;
|
|
20
|
+
};
|
|
21
|
+
export declare const UNIVERSAL_ROUTER_ADDRESS: (version: UniversalRouterVersion, chainId: number) => string;
|
|
22
|
+
export declare const SWAP_PROXY_ADDRESS: (chainId: number) => string;
|
|
23
|
+
export declare const UNIVERSAL_ROUTER_CREATION_BLOCK: (version: UniversalRouterVersion, chainId: number) => number;
|
|
24
|
+
export declare const WETH_ADDRESS: (chainId: number) => string;
|
|
25
|
+
export declare const CONTRACT_BALANCE: BigNumber;
|
|
26
|
+
export declare const ETH_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
27
|
+
export declare const E_ETH_ADDRESS = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
28
|
+
export declare const ZERO_ADDRESS = "0x0000000000000000000000000000000000000000";
|
|
29
|
+
export declare const MAX_UINT256: BigNumber;
|
|
30
|
+
export declare const MAX_UINT160: BigNumber;
|
|
31
|
+
export declare const SENDER_AS_RECIPIENT = "0x0000000000000000000000000000000000000001";
|
|
32
|
+
export declare const ROUTER_AS_RECIPIENT = "0x0000000000000000000000000000000000000002";
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { TypedDataDomain, TypedDataField } from '@ethersproject/abstract-signer';
|
|
2
|
+
export declare const EIP712_DOMAIN_NAME = "UniversalRouter";
|
|
3
|
+
export declare const EIP712_DOMAIN_VERSION = "2";
|
|
4
|
+
export declare const EXECUTE_SIGNED_TYPES: Record<string, TypedDataField[]>;
|
|
5
|
+
/**
|
|
6
|
+
* Generate EIP712 domain for Universal Router
|
|
7
|
+
*/
|
|
8
|
+
export declare function getUniversalRouterDomain(chainId: number, verifyingContract: string): TypedDataDomain;
|
|
9
|
+
/**
|
|
10
|
+
* Generate a random nonce for signed execution
|
|
11
|
+
* Uses ethers.utils.randomBytes for secure randomness
|
|
12
|
+
*/
|
|
13
|
+
export declare function generateNonce(): string;
|
|
14
|
+
/**
|
|
15
|
+
* Sentinel value to skip nonce checking (allows signature replay)
|
|
16
|
+
*/
|
|
17
|
+
export declare const NONCE_SKIP_CHECK: string;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { BigintIsh } from '@uniswap/sdk-core';
|
|
2
|
+
import { NFTPermitOptions } from '@uniswap/v3-sdk';
|
|
3
|
+
import { PermitSingle } from '@uniswap/permit2-sdk';
|
|
4
|
+
import { RoutePlanner } from './routerCommands';
|
|
5
|
+
export interface Permit2Permit extends PermitSingle {
|
|
6
|
+
signature: string;
|
|
7
|
+
}
|
|
8
|
+
export type ApproveProtocol = {
|
|
9
|
+
token: string;
|
|
10
|
+
protocol: string;
|
|
11
|
+
};
|
|
12
|
+
export type Permit2TransferFrom = {
|
|
13
|
+
token: string;
|
|
14
|
+
amount: string;
|
|
15
|
+
recipient?: string;
|
|
16
|
+
};
|
|
17
|
+
export type InputTokenOptions = {
|
|
18
|
+
permit2Permit?: Permit2Permit;
|
|
19
|
+
permit2TransferFrom?: Permit2TransferFrom;
|
|
20
|
+
};
|
|
21
|
+
export declare function encodePermit(planner: RoutePlanner, permit2: Permit2Permit): void;
|
|
22
|
+
export declare function encodeV3PositionPermit(planner: RoutePlanner, permit: NFTPermitOptions, tokenId: BigintIsh): void;
|
|
23
|
+
export declare function encodeInputTokenOptions(planner: RoutePlanner, options: InputTokenOptions): void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { BigNumber } from 'ethers';
|
|
2
|
+
import JSBI from 'jsbi';
|
|
3
|
+
import { Percent } from '@uniswap/sdk-core';
|
|
4
|
+
export declare function expandTo18DecimalsBN(n: number): BigNumber;
|
|
5
|
+
export declare function expandTo18Decimals(n: number): JSBI;
|
|
6
|
+
export declare function encodeFeeBips(fee: Percent): string;
|
|
7
|
+
export declare function encodeFee1e18(fee: Percent): string;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { URVersion } from '@uniswap/v4-sdk';
|
|
2
|
+
import { AcrossV4DepositV3Params } from '../entities/actions/across';
|
|
3
|
+
/**
|
|
4
|
+
* CommandTypes
|
|
5
|
+
* @description Flags that modify a command's execution
|
|
6
|
+
* @enum {number}
|
|
7
|
+
*/
|
|
8
|
+
export declare enum CommandType {
|
|
9
|
+
V3_SWAP_EXACT_IN = 0,
|
|
10
|
+
V3_SWAP_EXACT_OUT = 1,
|
|
11
|
+
PERMIT2_TRANSFER_FROM = 2,
|
|
12
|
+
PERMIT2_PERMIT_BATCH = 3,
|
|
13
|
+
SWEEP = 4,
|
|
14
|
+
TRANSFER = 5,
|
|
15
|
+
PAY_PORTION = 6,
|
|
16
|
+
PAY_PORTION_FULL_PRECISION = 7,
|
|
17
|
+
V2_SWAP_EXACT_IN = 8,
|
|
18
|
+
V2_SWAP_EXACT_OUT = 9,
|
|
19
|
+
PERMIT2_PERMIT = 10,
|
|
20
|
+
WRAP_ETH = 11,
|
|
21
|
+
UNWRAP_WETH = 12,
|
|
22
|
+
PERMIT2_TRANSFER_FROM_BATCH = 13,
|
|
23
|
+
BALANCE_CHECK_ERC20 = 14,
|
|
24
|
+
V4_SWAP = 16,
|
|
25
|
+
V3_POSITION_MANAGER_PERMIT = 17,
|
|
26
|
+
V3_POSITION_MANAGER_CALL = 18,
|
|
27
|
+
V4_INITIALIZE_POOL = 19,
|
|
28
|
+
V4_POSITION_MANAGER_CALL = 20,
|
|
29
|
+
EXECUTE_SUB_PLAN = 33,
|
|
30
|
+
ACROSS_V4_DEPOSIT_V3 = 64
|
|
31
|
+
}
|
|
32
|
+
export declare enum Subparser {
|
|
33
|
+
V3PathExactIn = 0,
|
|
34
|
+
V3PathExactOut = 1
|
|
35
|
+
}
|
|
36
|
+
export declare enum Parser {
|
|
37
|
+
Abi = 0,
|
|
38
|
+
V4Actions = 1,
|
|
39
|
+
V3Actions = 2
|
|
40
|
+
}
|
|
41
|
+
export type ParamType = {
|
|
42
|
+
readonly name: string;
|
|
43
|
+
readonly type: string;
|
|
44
|
+
readonly subparser?: Subparser;
|
|
45
|
+
};
|
|
46
|
+
export type CommandDefinition = {
|
|
47
|
+
parser: Parser.Abi;
|
|
48
|
+
params: ParamType[];
|
|
49
|
+
} | {
|
|
50
|
+
parser: Parser.V4Actions;
|
|
51
|
+
} | {
|
|
52
|
+
parser: Parser.V3Actions;
|
|
53
|
+
};
|
|
54
|
+
export declare const COMMAND_DEFINITION: {
|
|
55
|
+
[key in CommandType]: CommandDefinition;
|
|
56
|
+
};
|
|
57
|
+
export declare const V2V3_SWAP_COMMANDS_V2_1_1: {
|
|
58
|
+
[key: number]: CommandDefinition;
|
|
59
|
+
};
|
|
60
|
+
export declare class RoutePlanner {
|
|
61
|
+
commands: string;
|
|
62
|
+
inputs: string[];
|
|
63
|
+
constructor();
|
|
64
|
+
addSubPlan(subplan: RoutePlanner): RoutePlanner;
|
|
65
|
+
addCommand(type: CommandType, parameters: any[], allowRevert?: boolean, urVersion?: URVersion): RoutePlanner;
|
|
66
|
+
/**
|
|
67
|
+
* Add Across bridge deposit command for cross-chain bridging
|
|
68
|
+
* @param params AcrossV4DepositV3Params containing bridge parameters
|
|
69
|
+
* @returns RoutePlanner instance for chaining
|
|
70
|
+
*/
|
|
71
|
+
addAcrossBridge(params: AcrossV4DepositV3Params): RoutePlanner;
|
|
72
|
+
}
|
|
73
|
+
export type RouterCommand = {
|
|
74
|
+
type: CommandType;
|
|
75
|
+
encodedInput: string;
|
|
76
|
+
};
|
|
77
|
+
export declare function createCommand(type: CommandType, parameters: any[], urVersion?: URVersion): RouterCommand;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { Trade as RouterTrade } from '@uniswap/router-sdk';
|
|
2
|
+
import { Currency, TradeType } from '@uniswap/sdk-core';
|
|
3
|
+
export type TokenInRoute = {
|
|
4
|
+
address: string;
|
|
5
|
+
chainId: number;
|
|
6
|
+
symbol: string;
|
|
7
|
+
decimals: string;
|
|
8
|
+
name?: string;
|
|
9
|
+
buyFeeBps?: string;
|
|
10
|
+
sellFeeBps?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare enum PoolType {
|
|
13
|
+
V2Pool = "v2-pool",
|
|
14
|
+
V3Pool = "v3-pool",
|
|
15
|
+
V4Pool = "v4-pool"
|
|
16
|
+
}
|
|
17
|
+
export type V2Reserve = {
|
|
18
|
+
token: TokenInRoute;
|
|
19
|
+
quotient: string;
|
|
20
|
+
};
|
|
21
|
+
export type V2PoolInRoute = {
|
|
22
|
+
type: PoolType.V2Pool;
|
|
23
|
+
address?: string;
|
|
24
|
+
tokenIn: TokenInRoute;
|
|
25
|
+
tokenOut: TokenInRoute;
|
|
26
|
+
reserve0: V2Reserve;
|
|
27
|
+
reserve1: V2Reserve;
|
|
28
|
+
amountIn?: string;
|
|
29
|
+
amountOut?: string;
|
|
30
|
+
};
|
|
31
|
+
export type V3PoolInRoute = {
|
|
32
|
+
type: PoolType.V3Pool;
|
|
33
|
+
address?: string;
|
|
34
|
+
tokenIn: TokenInRoute;
|
|
35
|
+
tokenOut: TokenInRoute;
|
|
36
|
+
sqrtRatioX96: string;
|
|
37
|
+
liquidity: string;
|
|
38
|
+
tickCurrent: string;
|
|
39
|
+
fee: string;
|
|
40
|
+
amountIn?: string;
|
|
41
|
+
amountOut?: string;
|
|
42
|
+
};
|
|
43
|
+
export type V4PoolInRoute = {
|
|
44
|
+
type: PoolType.V4Pool;
|
|
45
|
+
address?: string;
|
|
46
|
+
tokenIn: TokenInRoute;
|
|
47
|
+
tokenOut: TokenInRoute;
|
|
48
|
+
fee: string;
|
|
49
|
+
tickSpacing: string;
|
|
50
|
+
hooks: string;
|
|
51
|
+
liquidity: string;
|
|
52
|
+
sqrtRatioX96: string;
|
|
53
|
+
tickCurrent: string;
|
|
54
|
+
amountIn?: string;
|
|
55
|
+
amountOut?: string;
|
|
56
|
+
};
|
|
57
|
+
export type PartialClassicQuote = {
|
|
58
|
+
tokenIn: string;
|
|
59
|
+
tokenOut: string;
|
|
60
|
+
tradeType: TradeType;
|
|
61
|
+
route: Array<(V4PoolInRoute | V3PoolInRoute | V2PoolInRoute)[]>;
|
|
62
|
+
};
|
|
63
|
+
export declare const isNativeCurrency: (address: string) => boolean;
|
|
64
|
+
export declare class RouterTradeAdapter {
|
|
65
|
+
static fromClassicQuote(quote: PartialClassicQuote): RouterTrade<Currency, Currency, TradeType>;
|
|
66
|
+
private static toCurrency;
|
|
67
|
+
private static toPoolOrPair;
|
|
68
|
+
private static toToken;
|
|
69
|
+
private static toV3Pool;
|
|
70
|
+
private static toV4Pool;
|
|
71
|
+
private static toPair;
|
|
72
|
+
private static isVersionedRoute;
|
|
73
|
+
}
|