Phoenix-Protocol-Group / phoenix-contracts

Source code of the smart contracts of the Phoenix DeFi hub DEX protocol
GNU General Public License v3.0
10 stars 6 forks source link

PHOAM-014: Stable pool does not support tokens with more than 18 decimals #344

Open gangov opened 2 months ago

gangov commented 2 months ago

Location

./contracts/pool_stable/src/contract.rs:319

Description The provide_liquidity function triggers an integer underflow issue when at least one of the tokens of the pair use more than 18 decimals. This prevents liquidity providers from adding funds to the pool. This is due to the following pow function, which expects an u32 number. Should greatest_precision be greater than DECIMAL_PRECISION, the provide_liquidity function would end execution with a panic.

let divisor = 10u128.pow(DECIMAL_PRECISION - greatest_precision);

The likelihood of this issue occurring was determined to be low, as tokens with more than 18 decimals are less likely to exist.

Recommendation Contemplate the case where greatest_precision is greater than DECIMAL_PRECISION, similarly to what is done in the scale_value value function. Otherwise, clearly document this limitation and prevent tokens with more than 18 decimals from being included in stable liquidity pools.

gangov commented 2 months ago

I'm pretty sure that we're keeping 18 decimals for now, making this for tracking purposes