Skip to content

Commit

Permalink
Merge pull request #172 from 1inch/feature/connector-manager
Browse files Browse the repository at this point in the history
[SC-1127] ConnectorManager
  • Loading branch information
zZoMROT authored Aug 9, 2024
2 parents 74fdd1c + f5cde3e commit 50277fe
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
4 changes: 4 additions & 0 deletions contracts/helpers/Blacklist.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
26 changes: 26 additions & 0 deletions contracts/helpers/ConnectorManager.sol
Original file line number Diff line number Diff line change
@@ -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]);
}
}
7 changes: 6 additions & 1 deletion test/Blacklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}

Expand All @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions test/ConnectorManager.js
Original file line number Diff line number Diff line change
@@ -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;
});
});

0 comments on commit 50277fe

Please sign in to comment.