diff --git a/batcher-ui/src/components/batcher/SelectPair.tsx b/batcher-ui/src/components/batcher/SelectPair.tsx index d46a4d80..da1b8e41 100644 --- a/batcher-ui/src/components/batcher/SelectPair.tsx +++ b/batcher-ui/src/components/batcher/SelectPair.tsx @@ -63,7 +63,9 @@ const SelectPair = ({ isFrom }: SelectPairProps) => { newError( pairName + ' is not a valid pair. Only ' + - availableSwaps.join() + + availableSwaps + .map(s => {s + '\n'}) + .join() + 'are supported.' ) ); diff --git a/batcher-ui/src/utils/token-manager.ts b/batcher-ui/src/utils/token-manager.ts index 50822b08..c939602f 100644 --- a/batcher-ui/src/utils/token-manager.ts +++ b/batcher-ui/src/utils/token-manager.ts @@ -29,11 +29,34 @@ const getSwapFromBigmap = ( `${process.env.NEXT_PUBLIC_TZKT_API_URI}/v1/bigmaps/${bigMapId}/keys/${swapName}` ).then(checkStatus); + +// FIXME =- This is the only way I could ge tthe string comparisons to work the same way as they do in the contract ¯\_(ツ)_/¯ +const alignWithLigoLexicographicalSorting = (to: string, from: string) => { + const startsWithTzTo = to.startsWith('tz'); + const startsWithTzFrom = from.startsWith('tz'); + const endsWithTzFrom = from.endsWith('tz'); + + if (!startsWithTzTo && endsWithTzFrom) { + return from.localeCompare(to); + } + if (startsWithTzTo && endsWithTzFrom) { + return 1; + } + if (startsWithTzTo && !startsWithTzFrom) { + return -1; + } + if (!startsWithTzTo && startsWithTzFrom) { + return 1; + } + + return to.localeCompare(from); +}; + export const getLexicographicalPairName = ( to: string, from: string ): string => { - const comp = to.localeCompare(from); + const comp = alignWithLigoLexicographicalSorting(to, from); if (comp < 0) { return `${to}-${from}`; } else { @@ -179,7 +202,6 @@ export const getTokensMetadata = async () => { ); }; - export const getTokensFromStorage = async () => { const storage = await getTokenManagerStorage(); const validTokens = storage['valid_tokens']; @@ -221,4 +243,4 @@ export const getSwapsFromStorage = async () => { }; }) ); -} +}; diff --git a/batcher/marketmaker.mligo b/batcher/marketmaker.mligo index 31c51732..a70800e0 100644 --- a/batcher/marketmaker.mligo +++ b/batcher/marketmaker.mligo @@ -103,7 +103,7 @@ let execute_liquidity_request (vault_address:address) (valid_tokens:ValidTokens.t_map) (valid_swaps:ValidSwaps.t_map): operation = - let pair_name = find_lexicographical_pair_name lt.name ot.name in + let pair_name = getLexicographicalPairName lt.name ot.name in match Map.find_opt pair_name valid_swaps with | None -> failwith swap_does_not_exist | Some vs -> let (lastupdated_opt, _tes) = OracleUtils.get_oracle_price pair_name unable_to_get_price_from_oracle vs (Big_map.empty: TickErrors.t) in diff --git a/batcher/utils.mligo b/batcher/utils.mligo index 7032e587..48c3eab1 100644 --- a/batcher/utils.mligo +++ b/batcher/utils.mligo @@ -211,14 +211,6 @@ let nat_to_tolerance (tolerance : nat) : tolerance = else if tolerance = 2n then Plus else failwith unable_to_parse_tolerance_from_external_order -[@inline] -let find_lexicographical_pair_name - (token_one_name: string) - (token_two_name: string) : string = - if token_one_name > token_two_name then - token_one_name ^ "-" ^ token_two_name - else - token_two_name ^ "-" ^ token_one_name [@inline] let get_rate_name_from_swap (s : swap_reduced) : string =