Skip to content

Deploy 2.45 to kovan #1260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions contracts/EtherWrapper.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,19 @@ contract EtherWrapper is Owned, Pausable, MixinResolver, MixinSystemSettings, IE
require(reserves > 0, "Contract cannot burn sETH for WETH, WETH balance is zero");

// principal = [amountIn / (1 + burnFeeRate)]
uint principal = amountIn.divideDecimal(SafeDecimalMath.unit().add(burnFeeRate()));
uint principal = amountIn.divideDecimalRound(SafeDecimalMath.unit().add(burnFeeRate()));

if (principal < reserves) {
_burn(principal);
_burn(principal, amountIn);
} else {
_burn(reserves);
_burn(reserves, reserves.add(calculateBurnFee(reserves)));
}
}

function distributeFees() external {
// Normalize fee to sUSD
require(!exchangeRates().rateIsInvalid(ETH), "Currency rate is invalid");
uint amountSUSD = exchangeRates().effectiveValue(ETH, feesEscrowed, sUSD);
require(!exchangeRates().rateIsInvalid(sETH), "Currency rate is invalid");
uint amountSUSD = exchangeRates().effectiveValue(sETH, feesEscrowed, sUSD);

// Burn sETH.
synthsETH().burn(address(this), feesEscrowed);
Expand Down Expand Up @@ -227,10 +227,9 @@ contract EtherWrapper is Owned, Pausable, MixinResolver, MixinSystemSettings, IE
emit Minted(msg.sender, principal, feeAmountEth, amountIn);
}

function _burn(uint principal) internal {
function _burn(uint principal, uint amountIn) internal {
// for burn, amount is inclusive of the fee.
uint feeAmountEth = calculateBurnFee(principal);
uint amountIn = principal.add(feeAmountEth);
uint feeAmountEth = amountIn.sub(principal);

require(amountIn <= IERC20(address(synthsETH())).allowance(msg.sender, address(this)), "Allowance not high enough");
require(amountIn <= IERC20(address(synthsETH())).balanceOf(msg.sender), "Balance is too low");
Expand Down
6 changes: 6 additions & 0 deletions publish/deployed/kovan/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -520,5 +520,11 @@
},
"SynthetixBridgeEscrow": {
"deploy": false
},
"EtherWrapper": {
"deploy": false
},
"NativeEtherWrapper": {
"deploy": false
}
}
1,239 changes: 1,181 additions & 58 deletions publish/deployed/kovan/deployment.json

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions test/contracts/EtherWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,37 @@ contract('EtherWrapper', async accounts => {
assert.equal(await etherWrapper.getReserves(), '0');
});
});

describe('precision and rounding', async () => {
let burnAmount;
let burnTx;

before(async () => {
const amount = toUnit('1.2');
await weth.deposit({ from: account1, value: amount });
await weth.approve(etherWrapper.address, amount, { from: account1 });
await etherWrapper.mint(amount, { from: account1 });

burnAmount = toUnit('0.9');
await sETHSynth.issue(account1, burnAmount);
await sETHSynth.approve(etherWrapper.address, burnAmount, { from: account1 });
burnTx = await etherWrapper.burn(burnAmount, { from: account1 });
});
it('emits a Burn event which burns 0.9 sETH', async () => {
const logs = await getDecodedLogs({
hash: burnTx.tx,
contracts: [sETHSynth],
});

decodedEventEqual({
event: 'Burned',
emittedFrom: sETHSynth.address,
args: [account1, burnAmount],
log: logs.filter(l => !!l).find(({ name }) => name === 'Burned'),
bnCloseVariance: 0,
});
});
});
});
});

Expand Down