@uniswap/universal-router-sdk 3.0.2 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +3 -77
  2. package/dist/entities/Command.d.ts +2 -3
  3. package/dist/entities/actions/index.d.ts +2 -0
  4. package/dist/entities/{protocols → actions}/uniswap.d.ts +2 -2
  5. package/dist/entities/{protocols → actions}/unwrapWETH.d.ts +2 -2
  6. package/dist/entities/index.d.ts +1 -2
  7. package/dist/swapRouter.d.ts +2 -20
  8. package/dist/universal-router-sdk.cjs.development.js +17 -10080
  9. package/dist/universal-router-sdk.cjs.development.js.map +1 -1
  10. package/dist/universal-router-sdk.cjs.production.min.js +1 -1
  11. package/dist/universal-router-sdk.cjs.production.min.js.map +1 -1
  12. package/dist/universal-router-sdk.esm.js +19 -10075
  13. package/dist/universal-router-sdk.esm.js.map +1 -1
  14. package/dist/utils/constants.d.ts +0 -2
  15. package/dist/utils/inputTokens.d.ts +0 -1
  16. package/dist/utils/routerCommands.d.ts +1 -17
  17. package/package.json +7 -5
  18. package/dist/entities/NFTTrade.d.ts +0 -44
  19. package/dist/entities/protocols/cryptopunk.d.ts +0 -16
  20. package/dist/entities/protocols/element-market.d.ts +0 -44
  21. package/dist/entities/protocols/foundation.d.ts +0 -19
  22. package/dist/entities/protocols/index.d.ts +0 -10
  23. package/dist/entities/protocols/looksRareV2.d.ts +0 -56
  24. package/dist/entities/protocols/nft20.d.ts +0 -21
  25. package/dist/entities/protocols/nftx.d.ts +0 -20
  26. package/dist/entities/protocols/seaport.d.ts +0 -69
  27. package/dist/entities/protocols/sudoswap.d.ts +0 -27
  28. package/dist/entities/protocols/x2y2.d.ts +0 -28
  29. package/dist/test/orders/element.d.ts +0 -7
  30. package/dist/test/orders/looksRareV2.d.ts +0 -2
  31. package/dist/test/orders/seaportV1_4.d.ts +0 -4
  32. package/dist/test/orders/seaportV1_5.d.ts +0 -4
  33. package/dist/test/orders/x2y2.d.ts +0 -6
  34. package/dist/utils/getNativeCurrencyValue.d.ts +0 -2
package/README.md CHANGED
@@ -4,27 +4,7 @@ This SDK facilitates interactions with the contracts in [Universal Router](https
4
4
  ## Usage
5
5
  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.
6
6
 
7
- ### Trading NFTs
8
- warning: `swapNFTCallParameters()` to be deprecated in favor of `swapCallParameters()`
9
- ```typescript
10
- import {
11
- LooksRareTrade,
12
- LooksRareData,
13
- SeaportTrade,
14
- SeaportData
15
- } from "@uniswap/universal-router-sdk";
16
-
17
- // Each protocol data object contains 1 call to that protocol. Some protocols can fit
18
- // many NFT purchase within 1 call, like seaport. Others require multiple calls per NFT (like LooksRare).
19
- const looksRareTrades = new LooksRareTrade([looksrareData1, looksrareData2])
20
- const seaportTrades = new SeaportTrade([seaportData1])
21
-
22
- // Use the raw calldata and value returned to call into Universal Swap Router contracts
23
- // Trades will happen in the order that they are handed in
24
- const { calldata, value } = SwapRouter.swapCallParameters([looksRareTrades, seaportTrades])
25
- ```
26
-
27
- ### Trading ERC20s on Uniswap
7
+ ### Trading on Uniswap
28
8
  warning: `swapERC20CallParameters()` to be deprecated in favor of `swapCallParameters()`
29
9
  ```typescript
30
10
  import { TradeType } from '@uniswap/sdk-core'
@@ -33,63 +13,9 @@ import { Trade as V3TradeSDK } from '@uniswap/v3-sdk'
33
13
  import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk'
34
14
 
35
15
  const options = { slippageTolerance, recipient }
36
- const routerTrade = new UniswapTrade(
37
- new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_INPUT },
38
- options
39
- )
40
- // Use the raw calldata and value returned to call into Universal Swap Router contracts
41
- const { calldata, value } = SwapRouter.swapCallParameters(routerTrade)
42
- ```
43
-
44
- ### Using Uniswap for ERC20 NFT Trades
45
- Send ETH to the router by trading an ERC20 for ETH with a Uniswap Trade and encoding the swap recipient as `ROUTER_AS_RECIPIENT` in the trade. Then subsequently list the NFT trades to use the ETH output to buy NFTs. Trades happen in the order they are listed.
46
-
47
- Use `trade_type: TradeType.EXACT_OUTPUT` to cover the entire NFT price, alternatively the transaction will send supplemental ETH to fulfill the entire price if the swap does not cover it in full. Keep in mind that `TradeType.EXACT_INPUT` trades are subject to slippage on output, and ETH will be sent to cover potential slippage and any remaining ETH will be returned to sender.
48
- ```typescript
49
- import { TradeType } from '@uniswap/sdk-core'
50
- import { Trade as V2TradeSDK } from '@uniswap/v2-sdk'
51
- import { Trade as V3TradeSDK } from '@uniswap/v3-sdk'
52
- import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk'
53
- import {
54
- ROUTER_AS_RECIPIENT,
55
- UniswapTrade,
56
- LooksRareTrade,
57
- LooksRareData,
58
- SeaportTrade,
59
- SeaportData
60
- } from "@uniswap/universal-router-sdk";
61
-
62
- const looksRareTrades = new LooksRareTrade([looksrareData1, looksrareData2])
63
- const seaportTrades = new SeaportTrade([seaportData1])
64
- // WARNING: never send funds to ROUTER_AS_RECIPIENT unless it is ETH that will be used in NFT trades, otherwise funds are lost.
65
- const uniswapTrade = new UniswapTrade(
66
- new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_OUTPUT }),
67
- { slippageTolerance, recipient: ROUTER_AS_RECIPIENT}
68
- )
69
- // Use the raw calldata and value returned to call into Universal Swap Router contracts
70
- const { calldata, value } = SwapRouter.swapCallParameters([uniswapTrade, seaportTrades, looksRareTrades])
71
- ```
72
-
73
- ### Using WETH for NFT Trades
74
- The current router purchases all NFTs with ETH, but you can send WETH to the router to be unwrapped for ETH right before the NFT commands. Similar to ERC20 Uniswap Trades for NFTs, supplemental ETH will be sent in the transaction if the WETH amount will not cover the NFT buys. You can also use ERC20s and WETH to cover the transaction by including both commands before the NFT purchase.
75
-
76
- ```typescript
77
- import {
78
- ROUTER_AS_RECIPIENT,
79
- UniswapTrade,
80
- LooksRareTrade,
81
- LooksRareData,
82
- SeaportTrade,
83
- SeaportData
84
- } from "@uniswap/universal-router-sdk";
85
-
86
- const looksRareTrades = new LooksRareTrade([looksrareData1, looksrareData2])
87
- const seaportTrades = new SeaportTrade([seaportData1])
88
- // if no Permit needed, omit the third var of type Permit2Permit
89
- const unwrapWETH = new UnwrapWETH(amountWETH, chainId, optionalPermit2Params)
90
-
16
+ const routerTrade = new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_INPUT })
91
17
  // Use the raw calldata and value returned to call into Universal Swap Router contracts
92
- const { calldata, value } = SwapRouter.swapCallParameters([unwrapWETH, seaportTrades, looksRareTrades])
18
+ const { calldata, value } = SwapRouter.swapCallParameters(routerTrade, options)
93
19
  ```
94
20
 
95
21
  ## Running this package
@@ -2,12 +2,11 @@ import { RoutePlanner } from '../utils/routerCommands';
2
2
  export declare type TradeConfig = {
3
3
  allowRevert: boolean;
4
4
  };
5
- export declare enum RouterTradeType {
5
+ export declare enum RouterActionType {
6
6
  UniswapTrade = "UniswapTrade",
7
- NFTTrade = "NFTTrade",
8
7
  UnwrapWETH = "UnwrapWETH"
9
8
  }
10
9
  export interface Command {
11
- tradeType: RouterTradeType;
10
+ tradeType: RouterActionType;
12
11
  encode(planner: RoutePlanner, config: TradeConfig): void;
13
12
  }
@@ -0,0 +1,2 @@
1
+ export * from './uniswap';
2
+ export * from './unwrapWETH';
@@ -2,7 +2,7 @@ import { RoutePlanner } from '../../utils/routerCommands';
2
2
  import { Trade as RouterTrade, SwapOptions as RouterSwapOptions } from '@uniswap/router-sdk';
3
3
  import { Permit2Permit } from '../../utils/inputTokens';
4
4
  import { Currency, TradeType } from '@uniswap/sdk-core';
5
- import { Command, RouterTradeType, TradeConfig } from '../Command';
5
+ import { Command, RouterActionType, TradeConfig } from '../Command';
6
6
  import { BigNumberish } from 'ethers';
7
7
  export declare type FlatFeeOptions = {
8
8
  amount: BigNumberish;
@@ -17,7 +17,7 @@ export declare type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> &
17
17
  export declare class UniswapTrade implements Command {
18
18
  trade: RouterTrade<Currency, Currency, TradeType>;
19
19
  options: SwapOptions;
20
- readonly tradeType: RouterTradeType;
20
+ readonly tradeType: RouterActionType;
21
21
  readonly payerIsUser: boolean;
22
22
  constructor(trade: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions);
23
23
  get inputRequiresWrap(): boolean;
@@ -1,9 +1,9 @@
1
1
  import { BigNumberish } from 'ethers';
2
2
  import { RoutePlanner } from '../../utils/routerCommands';
3
3
  import { Permit2Permit } from '../../utils/inputTokens';
4
- import { Command, RouterTradeType, TradeConfig } from '../Command';
4
+ import { Command, RouterActionType, TradeConfig } from '../Command';
5
5
  export declare class UnwrapWETH implements Command {
6
- readonly tradeType: RouterTradeType;
6
+ readonly tradeType: RouterActionType;
7
7
  readonly permit2Data: Permit2Permit;
8
8
  readonly wethAddress: string;
9
9
  readonly amount: BigNumberish;
@@ -1,3 +1,2 @@
1
- export * from './protocols';
2
- export * from './NFTTrade';
1
+ export * from './actions';
3
2
  export * from './Command';
@@ -3,31 +3,14 @@ import { BigNumberish } from 'ethers';
3
3
  import { MethodParameters } from '@uniswap/v3-sdk';
4
4
  import { Trade as RouterTrade } from '@uniswap/router-sdk';
5
5
  import { Currency, TradeType } from '@uniswap/sdk-core';
6
- import { Command } from './entities/Command';
7
- import { NFTTrade, SupportedProtocolsData } from './entities/NFTTrade';
8
- import { SwapOptions } from './entities/protocols/uniswap';
6
+ import { SwapOptions } from './entities/actions/uniswap';
9
7
  export declare type SwapRouterConfig = {
10
8
  sender?: string;
11
9
  deadline?: BigNumberish;
12
10
  };
13
- declare type SupportedNFTTrade = NFTTrade<SupportedProtocolsData>;
14
11
  export declare abstract class SwapRouter {
15
12
  static INTERFACE: Interface;
16
- static swapCallParameters(trades: Command[] | Command, config?: SwapRouterConfig): MethodParameters;
17
- /**
18
- * @deprecated in favor of swapCallParameters. Update before next major version 2.0.0
19
- * This version does not work correctly for Seaport ERC20->NFT purchases
20
- * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given swap.
21
- * @param trades to produce call parameters for
22
- */
23
- static swapNFTCallParameters(trades: SupportedNFTTrade[], config?: SwapRouterConfig): MethodParameters;
24
- /**
25
- * @deprecated in favor of swapCallParameters. Update before next major version 2.0.0
26
- * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
27
- * @param trades to produce call parameters for
28
- * @param options options for the call parameters
29
- */
30
- static swapERC20CallParameters(trades: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions): MethodParameters;
13
+ static swapCallParameters(trades: RouterTrade<Currency, Currency, TradeType>, options: SwapOptions): MethodParameters;
31
14
  /**
32
15
  * Encodes a planned route into a method name and parameters for the Router contract.
33
16
  * @param planner the planned route
@@ -36,4 +19,3 @@ export declare abstract class SwapRouter {
36
19
  */
37
20
  private static encodePlan;
38
21
  }
39
- export {};