Skip to content
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

Fix incoming transfer handlers #382

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/PoolManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,10 @@ contract PoolManager is Auth, IPoolManager {
} else if (call == MessagesLib.Call.UpdateTrancheHook) {
updateTrancheHook(message.toUint64(1), message.toBytes16(9), message.toAddress(25));
} else if (call == MessagesLib.Call.TransferAssets) {
handleTransfer(message.toUint128(1), message.toAddress(49), message.toUint128(81));
handleTransfer(message.toUint128(1), message.toAddress(17), message.toUint128(49));
} else if (call == MessagesLib.Call.TransferTrancheTokens) {
handleTransferTrancheTokens(
message.toUint64(1), message.toBytes16(9), message.toAddress(66), message.toUint128(98)
message.toUint64(1), message.toBytes16(9), message.toAddress(34), message.toUint128(66)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tobytes16(9) so this is 15 additional bytes of message data + 9 the offset , that's 25. So why message.toAddress(34)? What's between 25th and 34th ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The destination domain: uint8 for the enum + uint64 for the chain id = 9 bytes. See the code in MockCentrifugeChain

);
} else if (call == MessagesLib.Call.UpdateRestriction) {
updateRestriction(message.toUint64(1), message.toBytes16(9), message.slice(25, message.length - 25));
Expand Down
4 changes: 2 additions & 2 deletions test/integration/Admin.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ contract AdminTest is BaseTest {

guardian.pause();
vm.expectRevert("Gateway/paused");
centrifugeChain.incomingTransfer(assetId, sender, bytes32(bytes20(recipient)), amount);
centrifugeChain.incomingTransfer(assetId, bytes32(bytes20(recipient)), amount);
}

function testUnpausingResumesFunctionality(
Expand Down Expand Up @@ -129,7 +129,7 @@ contract AdminTest is BaseTest {
poolManager.transferAssets(address(erc20), bytes32(bytes20(recipient)), amount);
assertEq(erc20.balanceOf(address(poolManager.escrow())), amount);

centrifugeChain.incomingTransfer(assetId, sender, bytes32(bytes20(recipient)), amount);
centrifugeChain.incomingTransfer(assetId, bytes32(bytes20(recipient)), amount);
assertEq(erc20.balanceOf(address(poolManager.escrow())), 0);
assertEq(erc20.balanceOf(recipient), amount);
}
Expand Down
6 changes: 2 additions & 4 deletions test/mocks/MockCentrifugeChain.sol
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,8 @@ contract MockCentrifugeChain is Test {
}

// Trigger an incoming (e.g. Centrifuge Chain -> EVM) transfer of stable coins
function incomingTransfer(uint128 assetId, bytes32 sender, bytes32 recipient, uint128 amount) public {
bytes memory _message =
abi.encodePacked(uint8(MessagesLib.Call.TransferAssets), assetId, sender, recipient, amount);
function incomingTransfer(uint128 assetId, bytes32 recipient, uint128 amount) public {
bytes memory _message = abi.encodePacked(uint8(MessagesLib.Call.TransferAssets), assetId, recipient, amount);
_execute(_message);
}

Expand All @@ -148,7 +147,6 @@ contract MockCentrifugeChain is Test {
uint8(MessagesLib.Call.TransferTrancheTokens),
poolId,
trancheId,
msg.sender.toBytes32(),
bytes9(BytesLib.slice(abi.encodePacked(uint8(Domain.EVM), destinationChainId), 0, 9)),
destinationAddress.toBytes32(),
amount
Expand Down
8 changes: 4 additions & 4 deletions test/unit/PoolManager.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -265,19 +265,19 @@ contract PoolManagerTest is BaseTest {
bytes32 sender = makeAddr("sender").toBytes32();

vm.expectRevert(bytes("PoolManager/unknown-asset"));
centrifugeChain.incomingTransfer(assetId, sender, bytes32(bytes20(recipient)), amount);
centrifugeChain.incomingTransfer(assetId, bytes32(bytes20(recipient)), amount);
centrifugeChain.addAsset(assetId, address(erc20));

vm.expectRevert(bytes("SafeTransferLib/safe-transfer-from-failed"));
centrifugeChain.incomingTransfer(assetId, sender, bytes32(bytes20(recipient)), amount);
centrifugeChain.incomingTransfer(assetId, bytes32(bytes20(recipient)), amount);

vm.expectRevert(bytes("SafeTransferLib/safe-transfer-from-failed"));
centrifugeChain.incomingTransfer(assetId, sender, bytes32(bytes20(recipient)), amount);
centrifugeChain.incomingTransfer(assetId, bytes32(bytes20(recipient)), amount);

erc20.mint(address(poolManager.escrow()), amount); // fund escrow

// Now we test the incoming message
centrifugeChain.incomingTransfer(assetId, sender, bytes32(bytes20(recipient)), amount);
centrifugeChain.incomingTransfer(assetId, bytes32(bytes20(recipient)), amount);
assertEq(erc20.balanceOf(address(poolManager.escrow())), 0);
assertEq(erc20.balanceOf(recipient), amount);
}
Expand Down
Loading