The simulate_swap function in multihop allows a user to simulate a chain of swaps. For example, a user can swap token1 for token2 and then swap token2 for token3, allowing the user to go from an amount of token1 to an amount of token3.
Code snippet from the simulate_swap function. It is a for loop for each swap operation.
The above code simulates every swap operation, and uses the results of the simulation (e.g., the returned ask_amount) as the input for the next swap operation. It also recollects information of each operation, such as the spread of each swap and the total_comission_amount.
The issue is that the value total_comission_amount is invalid. This is because the code is adding amounts of different tokens; for example, adding the comission_amount of swapping token1 for token2 to the comission_amount of swapping token2 for token3, which are quantities in different tokens.
The same issue happens in the simulate_reverse_swap function.
Impact: The value returned by simulate_swap_response.total_commission_amount is an invalid
amount since amounts of different tokens cannot be added together.
Recommendation: Similar to spread, the values of commission_amount should be returned in a vector of values.
file: contracts/multihop/src/contract.rs location: simulate_swap, simulate_reverse_swap
The
simulate_swap
function in multihop allows a user to simulate a chain of swaps. For example, a user can swaptoken1
fortoken2
and then swaptoken2
fortoken3
, allowing the user to go from an amount oftoken1
to an amount oftoken3
.Inside
simulate_swap
we can found the following:Code snippet from the
simulate_swap
function. It is a for loop for each swap operation.The above code simulates every swap operation, and uses the results of the simulation (e.g., the returned
ask_amount
) as the input for the next swap operation. It also recollects information of each operation, such as the spread of each swap and thetotal_comission_amount
.The issue is that the value
total_comission_amount
is invalid. This is because the code is adding amounts of different tokens; for example, adding thecomission_amount
of swappingtoken1
fortoken2
to thecomission_amount
of swappingtoken2
fortoken3
, which are quantities in different tokens.The same issue happens in the
simulate_reverse_swap
function.Impact: The value returned by
simulate_swap_response.total_commission_amount
is an invalid amount since amounts of different tokens cannot be added together.Recommendation: Similar to spread, the values of
commission_amount
should be returned in a vector of values.