capofficial / client

CAP protocol web client built with Svelte
https://cap.io
Other
2 stars 4 forks source link

(Fixed) Buying Power is incorrect for some users #1 #43

Closed 0xdarkcap closed 1 year ago

kappacappa commented 1 year ago

@0xdarkcap good catch!

currentFeeRebate is a percentage of the fee, not a fee amount itself (e.g. it can be 20%) so (1 - currentFeeRebate) should be multiplied by the initial fee, not subtracted from it.

However, not sure I understand the gasFee change as already 0.002 was enough to clear the transaction on Arbitrum. Might be something else going on with that. Leaving open until we can investigate.

0xdarkcap commented 1 year ago

In line 110 of api/orders.js, the fee rebate is not subtracted from the fee. Although in the UI it's correct, it seems the original fee (without rebate) is passed to metamask. Therefore, metamask is throwing an insufficient funds exception.

kappacappa commented 1 year ago

@0xdarkcap since orders are submitted with the full fee, without rebates, and the contracts calculate and refund any potential rebate, I suggest simply removing $currentFeeRebate from the maxSize calculation.

const balanceAfterFees = $balances[$selectedAsset] * (1 - $leverage * $selectedMarketInfo.fee / BPS_DIVIDER) - gasFee;

We can probably set gasFee back to its initial value and it should go through in MetaMask.

kappacappa commented 1 year ago

@0xdarkcap cool. Can you confirm the latest changes work well on your local machine? If so, I'll merge.