From 4c57d7a57592af0578f100aa21bcb6c3bfe50357 Mon Sep 17 00:00:00 2001 From: Richard Watts Date: Fri, 12 Jul 2024 14:36:53 +0100 Subject: [PATCH] (fix) Actually transfer funds. Still doesn't work, but we're getting closer. --- .../2/LockProxyTokenManagerUpgradeableV3.sol | 11 ++++++++++- .../zilbridge/ZilBridgeTokenBridge.integration.t.sol | 1 + 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/smart-contracts/contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol b/smart-contracts/contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol index a7ee61a..0ca64d9 100644 --- a/smart-contracts/contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol +++ b/smart-contracts/contracts/zilbridge/2/LockProxyTokenManagerUpgradeableV3.sol @@ -46,7 +46,16 @@ contract LockProxyTokenManagerUpgradeableV3 is TokenManagerUpgradeableV3, ILockP LockProxy lp = LockProxy(payable(lockProxyAddress)); // Sadly, extensionTransfer() takes the same arguments as the withdrawn event but in a // different order. This will automagically transfer native token if token==0. - lp.extensionTransfer(recipient, token, amount); + + // Native tokens are transferred by the call; for everyone else, it sets an allowance and we + // then do the transfer from here. + if (token == address(0)) { + lp.extensionTransfer(recipient, address(0), amount); + } else { + lp.extensionTransfer(address(this), token, amount); + IERC20 erc20token = IERC20(token); + erc20token.transferFrom(address(lp), recipient, amount); + } emit WithdrawnFromLockProxy(token, recipient, amount); } diff --git a/smart-contracts/test/zilbridge/ZilBridgeTokenBridge.integration.t.sol b/smart-contracts/test/zilbridge/ZilBridgeTokenBridge.integration.t.sol index 61cb0b4..e183a52 100644 --- a/smart-contracts/test/zilbridge/ZilBridgeTokenBridge.integration.t.sol +++ b/smart-contracts/test/zilbridge/ZilBridgeTokenBridge.integration.t.sol @@ -180,6 +180,7 @@ contract ZilBridgeTokenBridgeIntegrationTest is ZilBridgeTokenBridgeIntegrationF // To abi.encode(ITokenManagerStructs.AcceptArgs(address(remoteNativelyOnSource), remoteUser, amount))); + // approval goes to the token manager, which will transfer value to/from the lock proxy for you. nativelyOnSource.approve(address(sourceTokenManager), amount); // Ask the source token manager to take the source tokens and emit a relayed event