-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #172 from 1inch/feature/connector-manager
[SC-1127] ConnectorManager
- Loading branch information
Showing
4 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
}); |