Skip to content

Commit

Permalink
test: add test for payout to address different from msg.sender during…
Browse files Browse the repository at this point in the history
… the fill
  • Loading branch information
artall64 committed Oct 17, 2023
1 parent 374f158 commit 27b41d0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions contracts/libraries/TakerTraitsLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 35 additions & 1 deletion test/LimitOrderProtocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 27b41d0

Please sign in to comment.