-
Notifications
You must be signed in to change notification settings - Fork 569
Description
gm,
The fee calc when selling GLP (the vault.sellUSDG() function) may have a bug.
When selling GLP, the fee for the token to sell into is calculated here:
https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/Vault.sol#L508
This underlying fee calc depends on vault.usdgAmounts(usg) for the initialAmount:
https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/VaultUtils.sol#L146
However this usdgAmount has already been updated (decreased) prior to this being called
https://github.com/gmx-io/gmx-contracts/blob/master/contracts/core/Vault.sol#L497
So it looks like the initialAmount var isn't the initial amount, it's already had the usdgDelta applied to it.
Also as far as I can tell, the UI quote is inconsistent with this contract calc - since the usdgAmount being used is the amount prior to the transaction.
https://github.com/gmx-io/gmx-interface/blob/master/src/Helpers.js#L655
Apart from potentially taking more fees than necessary, I guess if the UI quote is different from the actual calc, it may have slippage issues for users.