From 27b41d0350f39b10854b7d3d45bab827c2245db3 Mon Sep 17 00:00:00 2001 From: Artem Vorobev Date: Tue, 17 Oct 2023 23:48:52 +0300 Subject: [PATCH] test: add test for payout to address different from msg.sender during the fill --- contracts/libraries/TakerTraitsLib.sol | 1 + test/LimitOrderProtocol.js | 36 +++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/contracts/libraries/TakerTraitsLib.sol b/contracts/libraries/TakerTraitsLib.sol index b2709a65..4bcf517e 100644 --- a/contracts/libraries/TakerTraitsLib.sol +++ b/contracts/libraries/TakerTraitsLib.sol @@ -13,6 +13,7 @@ type TakerTraits is uint256; * 254 bit `_UNWRAP_WETH_FLAG` - If set, the WETH will be unwrapped into ETH before sending to taker. * 253 bit `_SKIP_ORDER_PERMIT_FLAG` - If set, the order skips maker's permit execution. * 252 bit `_USE_PERMIT2_FLAG` - If set, the order uses the permit2 function for authorization. + * 251 bit `_ARGS_HAS_TARGET` - Should be set when target address is passed. Target address is the one that will receive maker asset during the fill execution by default it's equal to msg.sender * The remaining bits are used to store the threshold amount (the maximum amount a taker agrees to give in exchange for a making amount). */ library TakerTraitsLib { diff --git a/test/LimitOrderProtocol.js b/test/LimitOrderProtocol.js index a9b796b5..81f960c2 100644 --- a/test/LimitOrderProtocol.js +++ b/test/LimitOrderProtocol.js @@ -388,6 +388,40 @@ describe('LimitOrderProtocol', function () { }); }); + describe('TakerTraits', function () { + const deployContractsAndInit = async function () { + const { dai, weth, swap, chainId } = await deploySwapTokens(); + await initContracts(dai, weth, swap); + return { dai, weth, swap, chainId }; + }; + + it('DAI => WETH, send WETH to address different from msg.sender when fill', async function () { + const { dai, weth, swap, chainId } = await loadFixture(deployContractsAndInit); + + const otherAddress = addr2; + const order = buildOrder({ + makerAsset: dai.address, + takerAsset: weth.address, + makingAmount: 1800, + takingAmount: 1, + maker: addr1.address, + }); + + const { r, _vs: vs } = ethers.utils.splitSignature(await signOrder(order, chainId, swap.address, addr1)); + const takerTraits = buildTakerTraits({ + target: otherAddress.address, + }); + + const fillTx = swap.fillOrderArgs(order, r, vs, 1, takerTraits.traits, takerTraits.args); + + await expect(fillTx).to.changeTokenBalance(dai, addr1, -1800); + await expect(fillTx).to.changeTokenBalance(weth, addr, -1); + + // Pay out happened to otherAddress, specified in taker traits + await expect(fillTx).to.changeTokenBalance(dai, otherAddress, 1800); + }); + }); + describe('Permit', function () { describe('Taker Permit', function () { const deployContractsAndInitPermit = async function () { @@ -570,7 +604,7 @@ describe('LimitOrderProtocol', function () { }); }); - describe('maker permit', function () { + describe('Maker permit', function () { const deployContractsAndInitPermit = async function () { const { dai, weth, swap, chainId } = await deploySwapTokens(); await initContracts(dai, weth, swap);