From 03530c000bb6fa7ed86e45e8e94c4785eb7fac40 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Wed, 3 Apr 2024 11:29:31 -0400 Subject: [PATCH] WIP --- contracts/src/ERC20Destination.sol | 2 +- contracts/src/NativeTokenDestination.sol | 13 +++++++++---- contracts/test/NativeTokenDestinationTests.t.sol | 5 +++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/contracts/src/ERC20Destination.sol b/contracts/src/ERC20Destination.sol index 0e1f5fec..300fcdc9 100644 --- a/contracts/src/ERC20Destination.sol +++ b/contracts/src/ERC20Destination.sol @@ -66,7 +66,7 @@ contract ERC20Destination is IERC20Bridge, TeleporterTokenDestination, ERC20 { amount = _deposit(amount); require( amount > input.primaryFee + input.secondaryFee, - "TeleporterTokenDestination: insufficient amount to cover fees" + "ERC20Destination: insufficient amount to cover fees" ); amount -= input.primaryFee; diff --git a/contracts/src/NativeTokenDestination.sol b/contracts/src/NativeTokenDestination.sol index b0103ae7..8a184058 100644 --- a/contracts/src/NativeTokenDestination.sol +++ b/contracts/src/NativeTokenDestination.sol @@ -176,11 +176,18 @@ contract NativeTokenDestination is require( currentReserveImbalance == 0, "NativeTokenDestination: contract undercollateralized" ); + uint256 amount = msg.value; + require( + amount > input.primaryFee + input.secondaryFee, + "NativeTokenDestination: insufficient amount to cover fees" + ); // TODO we need to guarantee that this function deposits the whole amount, or find a workaround. - _deposit(input.primaryFee); + if (input.primaryFee > 0) { + _deposit(input.primaryFee); + amount -= input.primaryFee; + } - uint256 amount = msg.value - input.primaryFee; _burn(amount); _send(input, _scaleTokens(amount, false)); @@ -260,8 +267,6 @@ contract NativeTokenDestination is * @dev See {TeleportTokenDestination-_withdraw} */ function _withdraw(address recipient, uint256 amount) internal virtual override { - require(recipient != address(0), "NativeTokenDestination: zero recipient address"); - uint256 scaledAmount = _scaleTokens(amount, true); // If the contract has not yet been collateralized, we will deduct as many tokens diff --git a/contracts/test/NativeTokenDestinationTests.t.sol b/contracts/test/NativeTokenDestinationTests.t.sol index 3cb043e3..eec53343 100644 --- a/contracts/test/NativeTokenDestinationTests.t.sol +++ b/contracts/test/NativeTokenDestinationTests.t.sol @@ -25,6 +25,11 @@ contract NativeTokenDestinationTest is NativeTokenBridgeTest, TeleporterTokenDes function setUp() public override { TeleporterTokenDestinationTest.setUp(); + vm.mockCall( + NATIVE_MINTER_PRECOMPILE_ADDRESS, + abi.encodeWithSelector(INativeMinter.mintNativeCoin.selector), + "" + ); mockWrappedToken = new ExampleWAVAX(); app = new NativeTokenDestination({ teleporterRegistryAddress: MOCK_TELEPORTER_REGISTRY_ADDRESS,