Skip to content
Closed
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
1 change: 1 addition & 0 deletions contracts/extensions/NativeOrderImpl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ contract NativeOrderImpl is IERC1271, EIP712Alien, OnlyWethReceiver {
(bool success, ) = makerOrder.maker.get().call{ value: balance }("");
if (!success) revert Errors.ETHTransferFailed();
}
_WETH.approve(_LOP, 0);
}

function withdraw(IOrderMixin.Order calldata makerOrder, address target, uint256 value, bytes memory data)
Expand Down
38 changes: 38 additions & 0 deletions test/LimitOrderProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,44 @@ describe('LimitOrderProtocol', function () {
await expect(cancelTx).to.changeEtherBalance(addr1, ether('0.1'));
});

it('Cancel order prevents re-filling after accidental WETH deposit', async function () {
const { tokens: { dai, weth }, contracts: { swap, nativeOrderFactory } } = await loadFixture(deployContractsAndInit);

const order = buildOrder(
{
maker: addr1.address,
receiver: addr1.address,
makerAsset: await weth.getAddress(),
takerAsset: await dai.getAddress(),
makingAmount: ether('0.3'),
takingAmount: ether('300'),
},
{},
);

const receipt = await (await nativeOrderFactory.connect(addr1).create(order, { value: order.makingAmount })).wait();
const cloneAddress = getEventArgs(receipt, nativeOrderFactory.interface, 'NativeOrderCreated')[2];
expect(await weth.balanceOf(cloneAddress)).to.equal(order.makingAmount);

const clone = await ethers.getContractAt('NativeOrderImpl', cloneAddress);
await clone.connect(addr1).cancelOrder(order);
expect(await weth.balanceOf(cloneAddress)).to.equal(0);

await weth.connect(addr1).deposit({ value: ether('0.3') });
await weth.connect(addr1).transfer(cloneAddress, ether('0.3'));
expect(await weth.balanceOf(cloneAddress)).to.equal(ether('0.3'));

const signature = abiCoder.encode([ABIOrder], [order]);
const takerTraits = buildTakerTraits({
threshold: ether('0.1'),
extension: order.extension,
});
order.maker = cloneAddress;
await expect(
swap.fillContractOrderArgs(order, signature, ether('100'), takerTraits.traits, takerTraits.args),
).to.be.revertedWithCustomError(swap, 'TransferFromMakerToTakerFailed');
});

it('Create native order fails for existing order', async function () {
const { tokens: { dai, weth }, contracts: { nativeOrderFactory } } = await loadFixture(deployContractsAndInit);

Expand Down
Loading