gm gm,
as we know, with move theres no decimals or negative numbers and pyth uses I64 to represent these numbers: magnitude x 10^expo.
in DeepMaker, the vaults need to convert both assets to a common denominator (usd). then they need to calculate the total value of the vault. since in the deposit function, the LP tokens to mint are equal to the users proportional share in the vault. (deposit amount in usd / vault total value in usd) * (lp tokens total supply).
the withdraw function is similar. in order to calculate the value on chain, i use pyth price feeds. however, this gives me a magnitude and exponent but i cannot actually convert it to price since that will result in decimals. so my approach is to normalize all the magnitudes to an exponent of 8.
i was wondering if this was the correct approach.
you can see this implementation on github: deepbook-amm/packages/amm/sources/vault.move at main · owenkrause/deepbook-amm · GitHub