diff --git a/solidity/src/contracts/Adapter.sol b/solidity/src/contracts/Adapter.sol index 64e81d10..73e71119 100644 --- a/solidity/src/contracts/Adapter.sol +++ b/solidity/src/contracts/Adapter.sol @@ -24,7 +24,8 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { ); // swap event custom topic0 uint256 public nonce; - address public immutable erc20; + bytes32 public immutable erc20; + address public immutable erc20Addr; address public immutable xerc20; address public feesManager; address public pam; @@ -34,7 +35,7 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { constructor( address xerc20_, - address erc20_, + bytes32 erc20_, bool isNative_, address feesManager_, address pam_ @@ -42,6 +43,7 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { isNative = isNative_; if (!isNative) { erc20 = erc20_; + erc20Addr = address(uint160(uint256(erc20))); } xerc20 = xerc20_; feesManager = feesManager_; @@ -64,8 +66,7 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { Operation memory operation, IPAM.Metadata calldata metadata ) external nonReentrant { - if (operation.erc20 != bytes32(abi.encode(erc20))) - revert InvalidOperation(); + if (operation.erc20 != erc20) revert InvalidOperation(); (bool isAuthorized, bytes32 eventId) = IPAM(pam).isAuthorized( operation, @@ -129,7 +130,7 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { string memory recipient, bytes memory data ) external payable { - if (erc20 == address(0) && isNative) { + if (erc20Addr == address(0) && isNative) { _swapNative(destinationChainId, recipient, data); } else { _swapToken(token, amount, destinationChainId, recipient, data); @@ -151,7 +152,7 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { bytes memory data ) internal { if (token == address(0)) revert InvalidTokenAddress(token); - if ((token != erc20) && (token != xerc20)) revert NotAllowed(); + if ((token != erc20Addr) && (token != xerc20)) revert NotAllowed(); if (amount <= 0) revert InvalidAmount(); address payable lockbox = payable(XERC20(xerc20).lockbox()); @@ -170,7 +171,7 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { amount ); - if (lockbox != address(0) && token == erc20) { + if (lockbox != address(0) && token == erc20Addr) { // We are on the home chain: then we wrap the ERC20 // to the relative xERC20 IERC20(token).approve(lockbox, amount); @@ -186,7 +187,7 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { bytes memory data ) internal { uint256 amount = msg.value; - if (erc20 != address(0)) revert NotAllowed(); + if (erc20Addr != address(0)) revert NotAllowed(); if (amount == 0) revert InvalidAmount(); address payable lockbox = payable(XERC20(xerc20).lockbox()); @@ -222,7 +223,7 @@ contract Adapter is IAdapter, Ownable, ReentrancyGuard { uint256 topic1 = nonce; bytes memory eventBytes = bytes.concat( bytes32(nonce), - bytes32(abi.encode(erc20)), + erc20, bytes32(destinationChainId), bytes32(netAmount), bytes32(uint256(uint160(msg.sender))), diff --git a/solidity/test/forge/Adapter.t.sol b/solidity/test/forge/Adapter.t.sol index f67e470a..007c33c4 100644 --- a/solidity/test/forge/Adapter.t.sol +++ b/solidity/test/forge/Adapter.t.sol @@ -32,7 +32,7 @@ contract AdapterTest is Test, Helper { ERC20 erc20 = ERC20(new ERC20Test(name, symbol, supply)); (XERC20 xerc20, , ) = _setupXERC20( address(0), - address(erc20), + bytes32(abi.encode(erc20)), string.concat("p", name), string.concat("p", symbol), local, @@ -42,7 +42,7 @@ contract AdapterTest is Test, Helper { PAM pam = new PAM(); adapter = new Adapter( address(xerc20), - address(erc20), + bytes32(abi.encode(erc20)), notNative, address(feesManager), address(pam) diff --git a/solidity/test/forge/DeployHelper.sol b/solidity/test/forge/DeployHelper.sol index b9d99d19..06de8b70 100644 --- a/solidity/test/forge/DeployHelper.sol +++ b/solidity/test/forge/DeployHelper.sol @@ -17,7 +17,7 @@ contract DeployHelper { /// chains. function _setupXERC20( address factory_, - address erc20, + bytes32 erc20, string memory name, string memory symbol, bool local, @@ -40,11 +40,15 @@ contract DeployHelper { ) ); - bool isNative = erc20 == address(0); + bool isNative = address(uint160(uint256(erc20))) == address(0); XERC20Lockbox lockbox; if (local) { lockbox = XERC20Lockbox( - factory.deployLockbox(address(xerc20), erc20, isNative) + factory.deployLockbox( + address(xerc20), + address(uint160(uint256(erc20))), + isNative + ) ); } diff --git a/solidity/test/forge/Helper.sol b/solidity/test/forge/Helper.sol index a0bf85b5..5f56ca2f 100644 --- a/solidity/test/forge/Helper.sol +++ b/solidity/test/forge/Helper.sol @@ -73,7 +73,7 @@ abstract contract Helper is Test, DeployHelper { function _setupChain( uint256 chain, address owner_, - address erc20, + bytes32 erc20, bool local, bool freezingEnabled ) @@ -104,7 +104,7 @@ abstract contract Helper is Test, DeployHelper { feesManager = new FeesManager(securityCouncil); adapter = new Adapter( address(xerc20), - address(erc20), + erc20, notNative, address(feesManager), address(pam) diff --git a/solidity/test/forge/Integration.t.sol b/solidity/test/forge/Integration.t.sol index 56842e89..e261ba30 100644 --- a/solidity/test/forge/Integration.t.sol +++ b/solidity/test/forge/Integration.t.sol @@ -79,7 +79,7 @@ contract IntegrationTest is Test, Helper { (xerc20_A, lockbox_A, adapter_A, feesManager_A, pam_A) = _setupChain( CHAIN_A, owner_A, - address(erc20), + erc20Bytes, LOCAL, freezingEnabled ); @@ -87,7 +87,7 @@ contract IntegrationTest is Test, Helper { (xerc20_B, lockbox_B, adapter_B, feesManager_B, pam_B) = _setupChain( CHAIN_B, owner_B, - address(erc20), + erc20Bytes, NOT_LOCAL, freezingEnabled ); diff --git a/solidity/test/forge/PAM.t.sol b/solidity/test/forge/PAM.t.sol index d10577b0..0ee4d4ac 100644 --- a/solidity/test/forge/PAM.t.sol +++ b/solidity/test/forge/PAM.t.sol @@ -54,7 +54,7 @@ contract PAMTest is Test, Helper { (, , adapter, , ) = _setupChain( originChainId, owner, - address(erc20), + bytes32(abi.encode(address(erc20))), true, false ); diff --git a/solidity/test/hardhat/Adapter.test.js b/solidity/test/hardhat/Adapter.test.js index 0caa0f36..9e99b6ad 100644 --- a/solidity/test/hardhat/Adapter.test.js +++ b/solidity/test/hardhat/Adapter.test.js @@ -81,7 +81,7 @@ const deployERC1820 = () => setCode(ERC1820, ERC1820BYTES) const PAM = await deploy(hre, 'PAM', []) const adapter = await deploy(hre, 'Adapter', [ pTokenV2.target, - erc20.target, + erc20Bytes, _isNative, feesManager, PAM, diff --git a/solidity/test/hardhat/forked-environment/ptoken-upgrade.test.js b/solidity/test/hardhat/forked-environment/ptoken-upgrade.test.js index bfbb106e..d2cf85f3 100644 --- a/solidity/test/hardhat/forked-environment/ptoken-upgrade.test.js +++ b/solidity/test/hardhat/forked-environment/ptoken-upgrade.test.js @@ -7,6 +7,7 @@ const { } = require('@pnetwork/event-attestator') const { expect } = require('chai') const hre = require('hardhat') +const { zeroPadValue } = require('ethers') const Operation = require('../utils/Operation.js') const { decodeSwapEvent } = require('../utils/decode-swap-event.js') @@ -81,11 +82,9 @@ conditionalDescribe( const rpc = hre.config.networks.bscFork.url const blockToForkFrom = 43336397 // 2024-10-22 09:25 await helpers.reset(rpc, blockToForkFrom) - user = await hre.ethers.getImpersonatedSigner( '0x816a99530B0f272Bb6ba4913b8952249f8d2E21b', ) - await helpers.setBalance(user.address, oneEth) ptoken = await hre.ethers.getContractAt(PTokenAbi, ADDRESS_PTOKEN) proxyAdminOwner = await hre.ethers.getImpersonatedSigner( @@ -93,7 +92,7 @@ conditionalDescribe( ) adapterBsc = await deploy(hre, 'Adapter', [ ptoken.target, - ADDRESS_ERC20_TOKEN, + zeroPadValue(ADDRESS_ERC20_TOKEN, 32), isNative, feesManagerBsc, pamBsc, @@ -176,7 +175,6 @@ conditionalDescribe( const rpc = hre.config.networks.ethFork.url const blockToForkFrom = 20369499 // 2024-07-23 15:22 await helpers.reset(rpc, blockToForkFrom) - erc20 = await hre.ethers.getContractAt(Erc20Abi, ADDRESS_ERC20_TOKEN) const name = `p${await erc20.name()}` @@ -204,7 +202,7 @@ conditionalDescribe( adapterEth = await deploy(hre, 'Adapter', [ xerc20.target, - ADDRESS_ERC20_TOKEN, + zeroPadValue(ADDRESS_ERC20_TOKEN, 32), isNative, feesManagerEth, pamEth,