Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Update README.md with STETH instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ewilz authored Sep 20, 2023
1 parent 31adc53 commit 267a1aa
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,50 @@ const unwrapWETH = new UnwrapWETH(amountWETH, chainId, optionalPermit2Params)
const { calldata, value } = SwapRouter.swapCallParameters([unwrapWETH, seaportTrades, looksRareTrades])
```
### Trading stETH by automatically wrapping to wstETH
### Trading stETH
To trade stETH as an input token, you can make sure the router automatically wraps stETH to wstETH before trading across a wstETH route.
```typescript
import { TradeType } from '@uniswap/sdk-core'
import { Trade as V2TradeSDK } from '@uniswap/v2-sdk'
import { Trade as V3TradeSDK } from '@uniswap/v3-sdk'
import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk'
import {
UniswapTrade,
WrapSTETH
} from "@uniswap/universal-router-sdk";

// including optional permit2 parameter will transfer STETH amount using permit2
const wrapSTETH = new WrapSTETH(inputSTETH, 1, WrapSTETHPermitData?, wrapAmountOtherThanContractBalance?)
const uniswapWstethTrade = new UniswapTrade(
new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_INPUT }),
{ slippageTolerance}
)

const { calldata, value } = SwapRouter.swapCallParameters([wrapSTETH, uniswapWstethTrade])
```
To recieve stETH as an output token, you can make sure the router automatically unwraps wstETH to stETH before returning to the swapper
```typescript
import { TradeType } from '@uniswap/sdk-core'
import { Trade as V2TradeSDK } from '@uniswap/v2-sdk'
import { Trade as V3TradeSDK } from '@uniswap/v3-sdk'
import { MixedRouteTrade, MixedRouteSDK, Trade as RouterTrade } from '@uniswap/router-sdk'
import {
ROUTER_AS_RECIPIENT,
UniswapTrade,
UnwrapSTETH
} from "@uniswap/universal-router-sdk";

// return trade to the router instead of the recipient using the ROUTER_AS_RECIPIENT constant so that the router may custody tokens to unwrap
const uniswapWstethTrade = new UniswapTrade(
new RouterTrade({ v2Routes, v3Routes, mixedRoutes, tradeType: TradeType.EXACT_INPUT }),
{ slippageTolerance, ROUTER_AS_RECIPIENT}
)
const unwrapSTETH = new UnwrapSTETH(recipient, aountMinimum, chainId)

const { calldata, value } = SwapRouter.swapCallParameters([uniswapWstethTrade, unwrapSTETH])
```
## Running this package
Make sure you are running `node v16`
Expand Down

0 comments on commit 267a1aa

Please sign in to comment.