diff --git a/contracts/helpers/Blacklist.sol b/contracts/helpers/Blacklist.sol index 83af413..49d5c14 100644 --- a/contracts/helpers/Blacklist.sol +++ b/contracts/helpers/Blacklist.sol @@ -4,6 +4,10 @@ pragma solidity 0.8.23; import "@openzeppelin/contracts/access/Ownable.sol"; +/** + * @title Blacklist + * @notice Contract is used to blacklist specific pools in the oracle. + */ contract Blacklist is Ownable { event BlacklistUpdated(address pool, bool isBlacklisted); diff --git a/contracts/helpers/ConnectorManager.sol b/contracts/helpers/ConnectorManager.sol new file mode 100644 index 0000000..cf4dc26 --- /dev/null +++ b/contracts/helpers/ConnectorManager.sol @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: MIT + +pragma solidity 0.8.23; + +import "@openzeppelin/contracts/access/Ownable.sol"; + +/** + * @title ConnectorManager + * @notice Contract is used to support only specific connectors in the oracle. + */ +contract ConnectorManager is Ownable { + event ConnectorUpdated(address connector, bool isSupported); + + mapping(address => bool) public connectorSupported; + + constructor(address[] memory connectors, address owner) Ownable(owner) { + for (uint256 i = 0; i < connectors.length; i++) { + connectorSupported[connectors[i]] = true; + } + } + + function toggleConnectorSupport(address connector) external onlyOwner { + connectorSupported[connector] = !connectorSupported[connector]; + emit ConnectorUpdated(connector, connectorSupported[connector]); + } +} diff --git a/test/Blacklist.js b/test/Blacklist.js index 14347bf..36f9a02 100644 --- a/test/Blacklist.js +++ b/test/Blacklist.js @@ -6,7 +6,7 @@ const { tokens } = require('./helpers.js'); describe('Blacklist', function () { async function initContracts () { const [owner, alice] = await ethers.getSigners(); - const blacklist = await deployContract('Blacklist', [[], owner]); + const blacklist = await deployContract('Blacklist', [[tokens.DAI], owner]); return { owner, alice, blacklist }; } @@ -15,6 +15,11 @@ describe('Blacklist', function () { await expect(blacklist.connect(alice).toggleBlacklistAddress(tokens.ETH)).to.be.revertedWithCustomError(blacklist, 'OwnableUnauthorizedAccount'); }); + it('should blacklisted in constructor', async function () { + const { blacklist } = await loadFixture(initContracts); + expect(await blacklist.blacklisted(tokens.DAI)).to.be.true; + }); + it('should toggle record state', async function () { const { owner, blacklist } = await loadFixture(initContracts); await blacklist.connect(owner).toggleBlacklistAddress(tokens.ETH); diff --git a/test/ConnectorManager.js b/test/ConnectorManager.js new file mode 100644 index 0000000..dfc0dd5 --- /dev/null +++ b/test/ConnectorManager.js @@ -0,0 +1,30 @@ +const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers'); +const { ethers } = require('hardhat'); +const { expect, deployContract } = require('@1inch/solidity-utils'); +const { tokens } = require('./helpers.js'); + +describe('ConnectorManager', function () { + async function initContracts () { + const [owner, alice] = await ethers.getSigners(); + const connectorManager = await deployContract('ConnectorManager', [[tokens.DAI], owner]); + return { owner, alice, connectorManager }; + } + + it('should revert by non-owner', async function () { + const { alice, connectorManager } = await loadFixture(initContracts); + await expect(connectorManager.connect(alice).toggleConnectorSupport(tokens.ETH)).to.be.revertedWithCustomError(connectorManager, 'OwnableUnauthorizedAccount'); + }); + + it('should set supported in constructor', async function () { + const { connectorManager } = await loadFixture(initContracts); + expect(await connectorManager.connectorSupported(tokens.DAI)).to.be.true; + }); + + it('should toggle record state', async function () { + const { owner, connectorManager } = await loadFixture(initContracts); + await connectorManager.connect(owner).toggleConnectorSupport(tokens.ETH); + expect(await connectorManager.connectorSupported(tokens.ETH)).to.be.true; + await connectorManager.connect(owner).toggleConnectorSupport(tokens.ETH); + expect(await connectorManager.connectorSupported(tokens.ETH)).to.be.false; + }); +});