Skip to content

Commit

Permalink
Merge pull request #153 from 1inch/feature/curve-oracle/blacklist
Browse files Browse the repository at this point in the history
[SC-1160] Blacklist in CurveOracle
  • Loading branch information
zZoMROT authored Jun 25, 2024
2 parents 7993139 + 1402e6b commit a3092c2
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 7 deletions.
22 changes: 22 additions & 0 deletions contracts/helpers/Blacklist.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.23;

import "@openzeppelin/contracts/access/Ownable.sol";

contract Blacklist is Ownable {
event BlacklistUpdated(address pool, bool isBlacklisted);

mapping(address => bool) public blacklisted;

constructor(address[] memory initialBlacklist, address owner) Ownable(owner) {
for (uint256 i = 0; i < initialBlacklist.length; i++) {
blacklisted[initialBlacklist[i]] = true;
}
}

function toggleBlacklistAddress(address pool) external onlyOwner {
blacklisted[pool] = !blacklisted[pool];
emit BlacklistUpdated(pool, blacklisted[pool]);
}
}
16 changes: 14 additions & 2 deletions contracts/oracles/CurveOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import "../interfaces/ICurveProvider.sol";
import "../interfaces/ICurveRegistry.sol";
import "../interfaces/ICurveSwap.sol";
import "../libraries/OraclePrices.sol";
import "../helpers/Blacklist.sol";

contract CurveOracle is IOracle {
contract CurveOracle is IOracle, Blacklist {
using OraclePrices for OraclePrices.Data;
using Math for uint256;

Expand Down Expand Up @@ -40,7 +41,14 @@ contract CurveOracle is IOracle {
ICurveRegistry[11] public registries;
CurveRegistryType[11] public registryTypes;

constructor(ICurveProvider _addressProvider, uint256 _maxPools, uint256[] memory _registryIds, CurveRegistryType[] memory _registryTypes) {
constructor(
ICurveProvider _addressProvider,
uint256 _maxPools,
uint256[] memory _registryIds,
CurveRegistryType[] memory _registryTypes,
address[] memory initialBlacklist,
address owner
) Blacklist(initialBlacklist, owner) {
MAX_POOLS = _maxPools;
REGISTRIES_COUNT = _registryIds.length;
unchecked {
Expand All @@ -61,6 +69,10 @@ contract CurveOracle is IOracle {
uint256 registryIndex = 0;
address pool = registries[i].find_pool_for_coins(address(srcToken), address(dstToken), registryIndex);
while (pool != address(0) && index < MAX_POOLS) {
if (blacklisted[pool]) {
pool = registries[i].find_pool_for_coins(address(srcToken), address(dstToken), ++registryIndex);
continue;
}
index++;
// call `get_coin_indices` and set (srcTokenIndex, dstTokenIndex, isUnderlying) variables
bool isUnderlying;
Expand Down
2 changes: 1 addition & 1 deletion hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module.exports = {
deploy: 'deploy/commands',
},
mocha: {
timeout: 120000,
timeout: 180000,
},
tracer: {
enableAllOpcodes: true,
Expand Down
25 changes: 25 additions & 0 deletions test/Blacklist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { ethers } = require('hardhat');
const { expect, deployContract } = require('@1inch/solidity-utils');
const { tokens } = require('./helpers.js');

describe('Blacklist', function () {
async function initContracts () {
const [owner, alice] = await ethers.getSigners();
const blacklist = await deployContract('Blacklist', [[], owner]);
return { owner, alice, blacklist };
}

it('should revert by non-owner', async function () {
const { alice, blacklist } = await loadFixture(initContracts);
await expect(blacklist.connect(alice).toggleBlacklistAddress(tokens.ETH)).to.be.revertedWithCustomError(blacklist, 'OwnableUnauthorizedAccount');
});

it('should toggle record state', async function () {
const { owner, blacklist } = await loadFixture(initContracts);
await blacklist.connect(owner).toggleBlacklistAddress(tokens.ETH);
expect(await blacklist.blacklisted(tokens.ETH)).to.be.true;
await blacklist.connect(owner).toggleBlacklistAddress(tokens.ETH);
expect(await blacklist.blacklisted(tokens.ETH)).to.be.false;
});
});
10 changes: 6 additions & 4 deletions test/oracles/CurveOracle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { loadFixture } = require('@nomicfoundation/hardhat-network-helpers');
const { ethers } = require('hardhat');
const { expect, deployContract } = require('@1inch/solidity-utils');
const { expect, deployContract, constants } = require('@1inch/solidity-utils');
const {
tokens,
deployParams: { AaveWrapperV2, Curve, Uniswap, UniswapV2, UniswapV3 },
Expand All @@ -12,7 +12,7 @@ const {

describe('CurveOracle', function () {
async function initContracts () {
const curveOracle = await deployContract('CurveOracle', [Curve.provider, Curve.maxPools, Curve.registryIds, Curve.registryTypes]);
const curveOracle = await deployContract('CurveOracle', [Curve.provider, Curve.maxPools, Curve.registryIds, Curve.registryTypes, [], constants.EEE_ADDRESS]);
const uniswapV3Oracle = await deployContract('UniswapV3LikeOracle', [UniswapV3.factory, UniswapV3.initcodeHash, UniswapV3.fees]);
return { curveOracle, uniswapV3Oracle };
}
Expand Down Expand Up @@ -107,7 +107,9 @@ describe('CurveOracle', function () {
},
];

const curveOracle = await deployContract('CurveOracle', [Curve.provider, Curve.maxPools, [Curve.registryIds[registryIndex]], [Curve.registryTypes[registryIndex]]]);
const curveOracle = await deployContract('CurveOracle', [
Curve.provider, Curve.maxPools, [Curve.registryIds[registryIndex]], [Curve.registryTypes[registryIndex]], [], constants.EEE_ADDRESS,
]);
const curveProvider = await ethers.getContractAt('ICurveProvider', Curve.provider);
const registryAddress = await curveProvider.get_address(Curve.registryIds[registryIndex]);
const registry = await ethers.getContractAt('ICurveRegistry', registryAddress);
Expand Down Expand Up @@ -141,7 +143,7 @@ describe('CurveOracle', function () {
const [deployer] = await ethers.getSigners();

const uniswapV2LikeOracle = await deployContract('UniswapV2LikeOracle', [UniswapV2.factory, UniswapV2.initcodeHash]);
const curveOracle = await deployContract('CurveOracle', [Curve.provider, Curve.maxPools, Curve.registryIds, Curve.registryTypes]);
const curveOracle = await deployContract('CurveOracle', [Curve.provider, Curve.maxPools, Curve.registryIds, Curve.registryTypes, [], constants.EEE_ADDRESS]);
const uniswapOracle = await deployContract('UniswapOracle', [Uniswap.factory]);
const mooniswapOracle = await deployContract('MooniswapOracle', [tokens.oneInchLP1]);
const wethWrapper = await deployContract('BaseCoinWrapper', [tokens.ETH, tokens.WETH]);
Expand Down

0 comments on commit a3092c2

Please sign in to comment.