@@ -166,12 +166,12 @@ contract EtherWrapper is Owned, Pausable, MixinResolver, MixinSystemSettings, IE
166
166
require (reserves > 0 , "Contract cannot burn sETH for WETH, WETH balance is zero " );
167
167
168
168
// principal = [amountIn / (1 + burnFeeRate)]
169
- uint principal = amountIn.divideDecimal (SafeDecimalMath.unit ().add (burnFeeRate ()));
169
+ uint principal = amountIn.divideDecimalRound (SafeDecimalMath.unit ().add (burnFeeRate ()));
170
170
171
171
if (principal < reserves) {
172
- _burn (principal);
172
+ _burn (principal, amountIn );
173
173
} else {
174
- _burn (reserves);
174
+ _burn (reserves, reserves. add ( calculateBurnFee (reserves)) );
175
175
}
176
176
}
177
177
@@ -227,10 +227,9 @@ contract EtherWrapper is Owned, Pausable, MixinResolver, MixinSystemSettings, IE
227
227
emit Minted (msg .sender , principal, feeAmountEth, amountIn);
228
228
}
229
229
230
- function _burn (uint principal ) internal {
230
+ function _burn (uint principal , uint amountIn ) internal {
231
231
// for burn, amount is inclusive of the fee.
232
- uint feeAmountEth = calculateBurnFee (principal);
233
- uint amountIn = principal.add (feeAmountEth);
232
+ uint feeAmountEth = amountIn.sub (principal);
234
233
235
234
require (amountIn <= IERC20 (address (synthsETH ())).allowance (msg .sender , address (this )), "Allowance not high enough " );
236
235
require (amountIn <= IERC20 (address (synthsETH ())).balanceOf (msg .sender ), "Balance is too low " );
0 commit comments