diff --git a/contracts/finance/BatcherConfidential.sol b/contracts/finance/BatcherConfidential.sol index 3a919109..368d8c39 100644 --- a/contracts/finance/BatcherConfidential.sol +++ b/contracts/finance/BatcherConfidential.sol @@ -5,11 +5,12 @@ pragma solidity ^0.8.27; import {FHE, externalEuint64, euint64, ebool, euint128} from "@fhevm/solidity/lib/FHE.sol"; import {IERC20} from "@openzeppelin/contracts/interfaces/IERC20.sol"; import {SafeERC20} from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol"; +import {ERC165Checker} from "@openzeppelin/contracts/utils/introspection/ERC165Checker.sol"; import {Math} from "@openzeppelin/contracts/utils/math/Math.sol"; import {SafeCast} from "@openzeppelin/contracts/utils/math/SafeCast.sol"; import {ReentrancyGuardTransient} from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol"; import {IERC7984Receiver} from "./../interfaces/IERC7984Receiver.sol"; -import {ERC7984ERC20Wrapper} from "./../token/ERC7984/extensions/ERC7984ERC20Wrapper.sol"; +import {ERC7984ERC20Wrapper, IERC7984ERC20Wrapper} from "./../token/ERC7984/extensions/ERC7984ERC20Wrapper.sol"; import {FHESafeMath} from "./../utils/FHESafeMath.sol"; /** @@ -97,7 +98,19 @@ abstract contract BatcherConfidential is ReentrancyGuardTransient, IERC7984Recei /// @dev The caller is not authorized to call this function. error Unauthorized(); + /// @dev The given `token` does not support `IERC7984ERC20Wrapper` via `ERC165`. + error InvalidWrapperToken(address token); + constructor(ERC7984ERC20Wrapper fromToken_, ERC7984ERC20Wrapper toToken_) { + require( + ERC165Checker.supportsInterface(address(fromToken_), type(IERC7984ERC20Wrapper).interfaceId), + InvalidWrapperToken(address(fromToken_)) + ); + require( + ERC165Checker.supportsInterface(address(toToken_), type(IERC7984ERC20Wrapper).interfaceId), + InvalidWrapperToken(address(toToken_)) + ); + _fromToken = fromToken_; _toToken = toToken_; _currentBatchId = 1; diff --git a/test/finance/BatcherConfidential.test.ts b/test/finance/BatcherConfidential.test.ts index 6dceaf22..43862650 100644 --- a/test/finance/BatcherConfidential.test.ts +++ b/test/finance/BatcherConfidential.test.ts @@ -105,6 +105,36 @@ describe('BatcherConfidential', function () { }); }); + it('should reject invalid fromToken', async function () { + const confidentialToken = await ethers.deployContract('$ERC7984Mock', ['Mock Token', 'MTK', 'URI']); + + await expect( + ethers.deployContract('$BatcherConfidentialSwapMock', [ + confidentialToken, + this.toToken, + this.exchange, + this.operator, + ]), + ) + .to.be.revertedWithCustomError(this.batcher, 'InvalidWrapperToken') + .withArgs(confidentialToken.target); + }); + + it('should reject invalid toToken', async function () { + const confidentialToken = await ethers.deployContract('$ERC7984Mock', ['Mock Token', 'MTK', 'URI']); + + await expect( + ethers.deployContract('$BatcherConfidentialSwapMock', [ + this.fromToken, + confidentialToken, + this.exchange, + this.operator, + ]), + ) + .to.be.revertedWithCustomError(this.batcher, 'InvalidWrapperToken') + .withArgs(confidentialToken.target); + }); + for (const viaCallback of [true, false]) { describe(`join ${viaCallback ? 'via callback' : 'directly'}`, async function () { const join = async function (