-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR just shuffles some existing types around to make room for the new v3 types. It also introduces some convenience functions that will be useful for discriminating between v2 and v3 types, as well as extracting data from them. No functional change intended.
- Loading branch information
Showing
4 changed files
with
212 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { v2Deposit, v3Deposit, v2Fill, v3Fill, v2SpeedUp, v3SpeedUp } from "../interfaces"; | ||
import { BN } from "./BigNumberUtils"; | ||
import { isDefined } from "./TypeGuards"; | ||
|
||
export function isV2Deposit(deposit: v2Deposit | v3Deposit): deposit is v2Deposit { | ||
return isDefined((deposit as v2Deposit).originToken); | ||
} | ||
|
||
export function isV2SpeedUp(speedUp: v2SpeedUp | v3SpeedUp): speedUp is v2SpeedUp { | ||
return isDefined((speedUp as v2SpeedUp).newRelayerFeePct); | ||
} | ||
|
||
export function isV3Deposit(deposit: v2Deposit | v3Deposit): deposit is v3Deposit { | ||
return isDefined((deposit as v3Deposit).inputToken); | ||
} | ||
|
||
export function isV3SpeedUp(speedUp: v2SpeedUp | v3SpeedUp): speedUp is v3SpeedUp { | ||
return isDefined((speedUp as v3SpeedUp).updatedOutputAmount); | ||
} | ||
|
||
export function isV2Fill(fill: v2Fill | v3Fill): fill is v2Fill { | ||
return isDefined((fill as v2Fill).destinationToken); | ||
} | ||
|
||
export function isV3Fill(fill: v2Fill | v3Fill): fill is v3Fill { | ||
return isDefined((fill as v3Fill).inputToken); | ||
} | ||
|
||
export function getDepositInputToken(deposit: v2Deposit | v3Deposit): string { | ||
return isV2Deposit(deposit) ? deposit.originToken : deposit.inputToken; | ||
} | ||
|
||
export function getDepositOutputToken(deposit: v2Deposit | v3Deposit): string { | ||
return isV2Deposit(deposit) ? deposit.destinationToken : deposit.outputToken; | ||
} | ||
|
||
export function getFillOutputToken(fill: v2Fill | v3Fill): string { | ||
return isV2Fill(fill) ? fill.destinationToken : fill.outputToken; | ||
} | ||
|
||
export function getDepositInputAmount(deposit: v2Deposit | v3Deposit): BN { | ||
return isV2Deposit(deposit) ? deposit.amount : deposit.inputAmount; | ||
} | ||
|
||
export function getDepositOutputAmount(deposit: v2Deposit | v3Deposit): BN { | ||
return isV2Deposit(deposit) ? deposit.amount : deposit.outputAmount; | ||
} | ||
|
||
export function getFillAmount(fill: v2Fill | v3Fill): BN { | ||
return isV2Fill(fill) ? fill.amount : fill.outputAmount; | ||
} | ||
|
||
export function getTotalFilledAmount(fill: v2Fill | v3Fill): BN { | ||
return isV2Fill(fill) ? fill.totalFilledAmount : fill.outputAmount; | ||
} |
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