Skip to content

Commit

Permalink
fix lpRate+mtRate
Browse files Browse the repository at this point in the history
  • Loading branch information
Attens1423 committed Oct 19, 2023
1 parent 7167bd9 commit 3e05bca
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions contracts/DODOV3MM/D3Pool/D3Trading.sol
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ contract D3Trading is D3Funding {
// external call & swap callback
IDODOSwapCallback(msg.sender).d3MMSwapCallBack(fromToken, fromAmount, data);
// transfer mtFee to maintainer
_transferOut(state._MAINTAINER_, toToken, mtFee);
if(mtFee > 0) {
_transferOut(state._MAINTAINER_, toToken, mtFee);
}

require(
IERC20(fromToken).balanceOf(address(this)) - state.balances[fromToken] >= fromAmount,
Expand Down Expand Up @@ -151,7 +153,9 @@ contract D3Trading is D3Funding {
// external call & swap callback
IDODOSwapCallback(msg.sender).d3MMSwapCallBack(fromToken, payFromAmount, data);
// transfer mtFee to maintainer
_transferOut(state._MAINTAINER_, toToken, mtFee);
if(mtFee > 0 ) {
_transferOut(state._MAINTAINER_, toToken, mtFee);
}

require(
IERC20(fromToken).balanceOf(address(this)) - state.balances[fromToken] >= payFromAmount,
Expand Down Expand Up @@ -199,7 +203,7 @@ contract D3Trading is D3Funding {
uint256 mtFeeRate = D3State.fromTokenMMInfo.mtFeeRate + D3State.toTokenMMInfo.mtFeeRate;
mtFee = DecimalMath.mulFloor(receiveToAmount, mtFeeRate);

return (payFromAmount, receiveToAmount - swapFee, vusdAmount, swapFee, mtFee);
return (payFromAmount, receiveToAmount - mtFee, vusdAmount, swapFee, mtFee);
}

/// @notice user could query sellToken result deducted swapFee, assign toAmount
Expand All @@ -222,7 +226,7 @@ contract D3Trading is D3Funding {
swapFee = DecimalMath.mulFloor(toAmount, swapFeeRate);
uint256 mtFeeRate = D3State.fromTokenMMInfo.mtFeeRate + D3State.toTokenMMInfo.mtFeeRate;
mtFee = DecimalMath.mulFloor(toAmount, mtFeeRate);
toAmountWithFee = toAmount + swapFee;
toAmountWithFee = toAmount + mtFee;
}

require(toAmountWithFee <= state.balances[toToken], Errors.BALANCE_NOT_ENOUGH);
Expand Down
2 changes: 1 addition & 1 deletion contracts/DODOV3MM/lib/MakerTypes.sol
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ library MakerTypes {
uint256 bidDownRate = priceInfo & 0xffff;

// swap fee rate standarlize
swapFee = swapFeeRate * (10 ** 14) + mtFeeRate;
swapFee = swapFeeRate * (10 ** 14);
uint256 swapFeeSpread = DecimalMath.mul(midPriceWithDecimal, swapFee);

// ask price standarlize
Expand Down

0 comments on commit 3e05bca

Please sign in to comment.