Skip to content

Commit

Permalink
Fix transfer handlers (#382)
Browse files Browse the repository at this point in the history
Co-authored-by: John Doe <bulk.yard@protonmail.com>
  • Loading branch information
hieronx and peculiarity authored Jul 17, 2024
1 parent 4d1d6f7 commit 223a0f3
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
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)
);
} 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

0 comments on commit 223a0f3

Please sign in to comment.