This repository has been archived by the owner on Apr 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
Support STETH trades that auto wrap to WSTETH #148
+688
−103
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
2239f72
wrapSTETH support
ewilz eab5209
update ur-sdk + write tests for STETH--> ERC20
ewilz 591c7fe
make build work
ewilz 0dbe1a5
ETH--> STETH support
ewilz 182048a
lint
ewilz d406e85
woops..add MixedSwappCallParam test back?
ewilz 59fdedb
yarn build builds
ewilz 31adc53
start README.md
ewilz 267a1aa
Update README.md with STETH instructions
ewilz 0db1072
Update README.md typo
ewilz dcdd229
exact output
ewilz 46a02ee
rest of PR comments
ewilz 3e7e32b
lint
ewilz b259d1b
PR comments
ewilz 9cf3ef5
goerli support
ewilz 73fcadc
Update README.md for exactOutput with STETH input
ewilz 816f47d
update contract address
ewilz 06669f5
Merge remote-tracking branch 'origin/main' into steth
ewilz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import invariant from 'tiny-invariant' | ||
import { BigNumberish } from 'ethers' | ||
import { RoutePlanner, CommandType } from '../../utils/routerCommands' | ||
import { Command, RouterTradeType, TradeConfig } from '../Command' | ||
import { STETH_ADDRESS, NOT_SUPPORTED_ON_CHAIN } from '../../utils/constants' | ||
|
||
export class UnwrapSTETH implements Command { | ||
readonly tradeType: RouterTradeType = RouterTradeType.UnwrapSTETH | ||
readonly recipient: string | ||
readonly amountMinimum: BigNumberish | ||
|
||
constructor(recipient: string, amountMinimum: BigNumberish, chainId: number) { | ||
this.recipient = recipient | ||
this.amountMinimum = amountMinimum | ||
invariant(STETH_ADDRESS(chainId) != NOT_SUPPORTED_ON_CHAIN, `STETH not supported on chain ${chainId}`) | ||
} | ||
|
||
encode(planner: RoutePlanner, _: TradeConfig): void { | ||
planner.addCommand(CommandType.UNWRAP_STETH, [this.recipient, this.amountMinimum]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import invariant from 'tiny-invariant' | ||
import { BigNumberish } from 'ethers' | ||
import { RoutePlanner, CommandType } from '../../utils/routerCommands' | ||
import { encodeInputTokenOptions, Permit2Permit } from '../../utils/inputTokens' | ||
import { Command, RouterTradeType, TradeConfig } from '../Command' | ||
import { CONTRACT_BALANCE, ROUTER_AS_RECIPIENT, STETH_ADDRESS } from '../../utils/constants' | ||
|
||
export class WrapSTETH implements Command { | ||
readonly tradeType: RouterTradeType = RouterTradeType.WrapSTETH | ||
readonly permit2Data: Permit2Permit | ||
readonly stethAddress: string | ||
readonly amount: BigNumberish | ||
readonly wrapAmount: BigNumberish | ||
|
||
constructor(amount: BigNumberish, chainId: number, permit2?: Permit2Permit, wrapAmount?: BigNumberish) { | ||
this.stethAddress = STETH_ADDRESS(chainId) | ||
this.amount = amount | ||
this.wrapAmount = wrapAmount ?? CONTRACT_BALANCE | ||
|
||
if (!!permit2) { | ||
invariant( | ||
permit2.details.token.toLowerCase() === this.stethAddress.toLowerCase(), | ||
`must be permitting STETH address: ${this.stethAddress}` | ||
) | ||
invariant(permit2.details.amount >= amount, `Did not permit enough STETH for unwrapSTETH transaction`) | ||
this.permit2Data = permit2 | ||
} | ||
} | ||
|
||
encode(planner: RoutePlanner, _: TradeConfig): void { | ||
encodeInputTokenOptions(planner, { | ||
permit2Permit: this.permit2Data, | ||
permit2TransferFrom: { | ||
token: this.stethAddress, | ||
amount: this.amount.toString(), | ||
}, | ||
}) | ||
planner.addCommand(CommandType.WRAP_STETH, [ROUTER_AS_RECIPIENT, this.wrapAmount]) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh interesting, did we not expose the option to set payerIsUser/Router before via the sdk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct. I don't think it made any sense for any of the features we had.... wasn't sure if asking for the opposite (payerIsROUTER) as an option was awkward...