@yoroi/swap
Version:
The Swap package of Yoroi SDK
17 lines (15 loc) • 433 B
text/typescript
import {Swap} from '@yoroi/types'
export const getBestSwap =
(tokenOutPrice: number) =>
<T extends Swap.EstimateResponse | Swap.CreateResponse>(
best: T,
candidate: T,
): T => {
if (
candidate.totalOutput -
(tokenOutPrice > 0 ? candidate.totalFee / tokenOutPrice : 0) >
best.totalOutput - (tokenOutPrice > 0 ? best.totalFee / tokenOutPrice : 0)
)
return candidate
return best
}