Skip to content

Commit

Permalink
remove available routers
Browse files Browse the repository at this point in the history
  • Loading branch information
debych committed Nov 21, 2022
1 parent 5c3f965 commit b97f3f8
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 106 deletions.
53 changes: 0 additions & 53 deletions contracts/BridgeBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,6 @@ contract BridgeBase is AccessControlUpgradeable, PausableUpgradeable, Reentrancy
// Admin who transfers its role
address private previousAdmin;

// AddressSet of whitelisted addresses
EnumerableSetUpgradeable.AddressSet internal availableRouters;

event FixedCryptoFee(uint256 RubicPart, uint256 integratorPart, address indexed integrator);
event FixedCryptoFeeCollected(uint256 amount, address collector);
event TokenFee(uint256 RubicPart, uint256 integratorPart, address indexed integrator, address token);
Expand Down Expand Up @@ -102,7 +99,6 @@ contract BridgeBase is AccessControlUpgradeable, PausableUpgradeable, Reentrancy
function __BridgeBaseInit(
uint256 _fixedCryptoFee,
uint256 _RubicPlatformFee,
address[] memory _routers,
address[] memory _tokens,
uint256[] memory _minTokenAmounts,
uint256[] memory _maxTokenAmounts,
Expand All @@ -122,14 +118,6 @@ contract BridgeBase is AccessControlUpgradeable, PausableUpgradeable, Reentrancy

RubicPlatformFee = _RubicPlatformFee;

uint256 routerLength = _routers.length;
for (uint256 i; i < routerLength; ) {
availableRouters.add(_routers[i]);
unchecked {
++i;
}
}

uint256 tokensLength = _tokens.length;
for (uint256 i; i < tokensLength; ) {
if (_minTokenAmounts[i] > _maxTokenAmounts[i]) {
Expand Down Expand Up @@ -404,40 +392,6 @@ contract BridgeBase is AccessControlUpgradeable, PausableUpgradeable, Reentrancy
maxTokenAmount[_token] = _maxTokenAmount;
}

/**
* @dev Appends new available routers
* @param _routers Routers addresses to add
*/
function addAvailableRouters(address[] memory _routers) external onlyManagerOrAdmin {
uint256 length = _routers.length;
for (uint256 i; i < length; ) {
address _router = _routers[i];
if (_router == address(0)) {
revert ZeroAddress();
}
// Check that router exists is performed inside the library
availableRouters.add(_router);
unchecked {
++i;
}
}
}

/**
* @dev Removes existing available routers
* @param _routers Routers addresses to remove
*/
function removeAvailableRouters(address[] memory _routers) external onlyManagerOrAdmin {
uint256 length = _routers.length;
for (uint256 i; i < length; ) {
// Check that router exists is performed inside the library
availableRouters.remove(_routers[i]);
unchecked {
++i;
}
}
}

/**
* @dev Transfers admin role
* @param _newAdmin New admin's address
Expand All @@ -463,13 +417,6 @@ contract BridgeBase is AccessControlUpgradeable, PausableUpgradeable, Reentrancy

/// VIEW FUNCTIONS ///

/**
* @return Available routers
*/
function getAvailableRouters() external view returns (address[] memory) {
return availableRouters.values();
}

/**
* @notice Used in modifiers
* @dev Function to check if address is belongs to manager or admin role
Expand Down
3 changes: 1 addition & 2 deletions contracts/architecture/OnlySourceFunctionality.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@ contract OnlySourceFunctionality is BridgeBase {
function __OnlySourceFunctionalityInit(
uint256 _fixedCryptoFee,
uint256 _RubicPlatformFee,
address[] memory _routers,
address[] memory _tokens,
uint256[] memory _minTokenAmounts,
uint256[] memory _maxTokenAmounts,
address _admin
) internal onlyInitializing {
__BridgeBaseInit(_fixedCryptoFee, _RubicPlatformFee, _routers, _tokens, _minTokenAmounts, _maxTokenAmounts, _admin);
__BridgeBaseInit(_fixedCryptoFee, _RubicPlatformFee, _tokens, _minTokenAmounts, _maxTokenAmounts, _admin);
}
}
3 changes: 1 addition & 2 deletions contracts/architecture/WithDestinationFunctionality.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ contract WithDestinationFunctionality is BridgeBase {
function __WithDestinationFunctionalityInit(
uint256 _fixedCryptoFee,
uint256 _RubicPlatformFee,
address[] memory _routers,
address[] memory _tokens,
uint256[] memory _minTokenAmounts,
uint256[] memory _maxTokenAmounts,
uint256[] memory _blockchainIDs,
uint256[] memory _blockchainToGasFee,
address _admin
) internal onlyInitializing {
__BridgeBaseInit(_fixedCryptoFee, _RubicPlatformFee, _routers, _tokens, _minTokenAmounts, _maxTokenAmounts, _admin);
__BridgeBaseInit(_fixedCryptoFee, _RubicPlatformFee, _tokens, _minTokenAmounts, _maxTokenAmounts, _admin);

uint256 length = _blockchainIDs.length;
if (_blockchainToGasFee.length != length) {
Expand Down
9 changes: 1 addition & 8 deletions contracts/test/TestOnlySource.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,17 @@ contract TestOnlySource is OnlySourceFunctionality {
constructor(
uint256 _fixedCryptoFee,
uint256 _RubicPlatformFee,
address[] memory _routers,
address[] memory _tokens,
uint256[] memory _minTokenAmounts,
uint256[] memory _maxTokenAmounts,
address _admin
) {
initialize(_fixedCryptoFee, _RubicPlatformFee, _routers, _tokens, _minTokenAmounts, _maxTokenAmounts, _admin);
initialize(_fixedCryptoFee, _RubicPlatformFee, _tokens, _minTokenAmounts, _maxTokenAmounts, _admin);
}

function initialize(
uint256 _fixedCryptoFee,
uint256 _RubicPlatformFee,
address[] memory _routers,
address[] memory _tokens,
uint256[] memory _minTokenAmounts,
uint256[] memory _maxTokenAmounts,
Expand All @@ -37,7 +35,6 @@ contract TestOnlySource is OnlySourceFunctionality {
__OnlySourceFunctionalityInit(
_fixedCryptoFee,
_RubicPlatformFee,
_routers,
_tokens,
_minTokenAmounts,
_maxTokenAmounts,
Expand All @@ -52,10 +49,6 @@ contract TestOnlySource is OnlySourceFunctionality {
whenNotPaused
eventEmitter(_params, _providerName)
{
if (!availableRouters.contains(_params.router)) {
revert NotInWhitelist(_params.router);
}

IntegratorFeeInfo memory _info = integratorToFeeInfo[_params.integrator];

IERC20(_params.srcInputToken).transferFrom(msg.sender, address(this), _params.srcInputAmount);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rubic-bridge-base",
"version": "1.5.2",
"version": "1.6.0-beta-2",
"scripts": {
"build": "tsc",
"lint": "./node_modules/.bin/solhint -f table contracts/**/*.sol && eslint test/** ",
Expand Down
78 changes: 39 additions & 39 deletions test/OnlySourse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ describe('TestOnlySource', () => {
});

describe('right settings', () => {
it('routers', async () => {
const routers = await bridge.getAvailableRouters();
expect(routers).to.deep.eq([DEX.address]);
});
// it('routers', async () => {
// const routers = await bridge.getAvailableRouters();
// expect(routers).to.deep.eq([DEX.address]);
// });
it('min max amounts', async () => {
expect(await bridge.minTokenAmount(transitToken.address)).to.be.eq(
consts.MIN_TOKEN_AMOUNT
Expand Down Expand Up @@ -191,36 +191,36 @@ describe('TestOnlySource', () => {
await bridge.setFixedCryptoFee('100');
expect(await bridge.fixedCryptoFee()).to.be.eq('100');
});
it('only manager can remove routers', async () => {
await expect(
bridge.connect(swapper).removeAvailableRouters([DEX.address])
).to.be.revertedWithCustomError(bridge, 'NotAManager');

await bridge.removeAvailableRouters([DEX.address]);
expect(await bridge.getAvailableRouters()).to.be.deep.eq([]);
});
it('only manager can add routers', async () => {
await expect(
bridge.connect(swapper).addAvailableRouters([owner.address])
).to.be.revertedWithCustomError(bridge, 'NotAManager');

await bridge.addAvailableRouters([owner.address]);

expect(await bridge.getAvailableRouters()).to.be.deep.eq([DEX.address, owner.address]);
});
it('possible to add multiple routers', async () => {
await bridge.addAvailableRouters([swapper.address, owner.address]);
expect(await bridge.getAvailableRouters()).to.be.deep.eq([
DEX.address,
swapper.address,
owner.address
]);
});
it('possible to remove multiple routers', async () => {
await bridge.addAvailableRouters([swapper.address, owner.address]);
await bridge.removeAvailableRouters([DEX.address, owner.address]);
expect(await bridge.getAvailableRouters()).to.be.deep.eq([swapper.address]);
});
// it('only manager can remove routers', async () => {
// await expect(
// bridge.connect(swapper).removeAvailableRouters([DEX.address])
// ).to.be.revertedWithCustomError(bridge, 'NotAManager');
//
// await bridge.removeAvailableRouters([DEX.address]);
// expect(await bridge.getAvailableRouters()).to.be.deep.eq([]);
// });
// it('only manager can add routers', async () => {
// await expect(
// bridge.connect(swapper).addAvailableRouters([owner.address])
// ).to.be.revertedWithCustomError(bridge, 'NotAManager');
//
// await bridge.addAvailableRouters([owner.address]);
//
// expect(await bridge.getAvailableRouters()).to.be.deep.eq([DEX.address, owner.address]);
// });
// it('possible to add multiple routers', async () => {
// await bridge.addAvailableRouters([swapper.address, owner.address]);
// expect(await bridge.getAvailableRouters()).to.be.deep.eq([
// DEX.address,
// swapper.address,
// owner.address
// ]);
// });
// it('possible to remove multiple routers', async () => {
// await bridge.addAvailableRouters([swapper.address, owner.address]);
// await bridge.removeAvailableRouters([DEX.address, owner.address]);
// expect(await bridge.getAvailableRouters()).to.be.deep.eq([swapper.address]);
// });
it('validation of integratorFeeInfo', async () => {
let feeInfo = {
isIntegrator: true,
Expand Down Expand Up @@ -306,11 +306,11 @@ describe('TestOnlySource', () => {
DEFAULT_PROVIDER_NAME
);
});
it('cross chain with swap fails if router not available', async () => {
await expect(callBridge({ router: owner.address }))
.to.be.revertedWithCustomError(bridge, 'NotInWhitelist')
.withArgs(owner.address);
});
// it('cross chain with swap fails if router not available', async () => {
// await expect(callBridge({ router: owner.address }))
// .to.be.revertedWithCustomError(bridge, 'NotInWhitelist')
// .withArgs(owner.address);
// });
it('cross chain with swap amounts without integrator', async () => {
await callBridge();
const { feeAmount, amountWithoutFee, RubicFee } = await calcTokenFees({
Expand Down
1 change: 0 additions & 1 deletion test/shared/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export const onlySourceFixture = async function (): Promise<BridgeFixture> {
const bridge = (await bridgeFactory.deploy(
FIXED_CRYPTO_FEE,
RUBIC_PLATFORM_FEE,
[DEX.address],
[transitToken.address, swapToken.address],
[MIN_TOKEN_AMOUNT, MIN_TOKEN_AMOUNT],
[MAX_TOKEN_AMOUNT, MAX_TOKEN_AMOUNT],
Expand Down

0 comments on commit b97f3f8

Please sign in to comment.