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

Commit

Permalink
add safe mode
Browse files Browse the repository at this point in the history
  • Loading branch information
hensha256 committed Feb 6, 2024
1 parent 4d1a671 commit 7e1b627
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/entities/protocols/uniswap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ export type FlatFeeOptions = {

// the existing router permit object doesn't include enough data for permit2
// so we extend swap options with the permit2 permit
// when safe mode is enabled, the SDK will add extra token sweeps for security
export type SwapOptions = Omit<RouterSwapOptions, 'inputTokenPermit'> & {
inputTokenPermit?: Permit2Permit
flatFee?: FlatFeeOptions
safeMode?: boolean
}

const REFUND_ETH_PRICE_IMPACT_THRESHOLD = new Percent(50, 100)
Expand Down Expand Up @@ -144,7 +146,7 @@ export class UniswapTrade implements Command {
}
}

if (inputIsNative && (this.trade.tradeType === TradeType.EXACT_OUTPUT || riskOfPartialFill(this.trade))) {
if (inputIsNative && (this.trade.tradeType === TradeType.EXACT_OUTPUT || riskOfPartialFill(this.trade)) || this.options.safeMode) {
// for exactOutput swaps that take native currency as input
// we need to send back the change to the user
planner.addCommand(CommandType.UNWRAP_WETH, [this.options.recipient, 0])
Expand Down

0 comments on commit 7e1b627

Please sign in to comment.