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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support STETH trades that auto wrap to WSTETH (#148)
- Loading branch information
Showing
17 changed files
with
688 additions
and
103 deletions.
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.