diff --git a/contracts/Bridge.sol b/contracts/Bridge.sol index 46a7696..5315bb6 100644 --- a/contracts/Bridge.sol +++ b/contracts/Bridge.sol @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-3.0 pragma solidity 0.8.0; +// import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/access/Ownable.sol"; import "@openzeppelin/contracts/token/ERC20/ERC20.sol"; import "@openzeppelin/contracts/security/ReentrancyGuard.sol"; @@ -24,146 +25,145 @@ contract Bridge is Context , ReentrancyGuard { uint256 maxAmount; uint256 feeBalance; uint256 collectedFees; + uint256 networkFee; bool ownedRail; address manager; address feeRemitance; uint256 balance; bool isSet; uint256 baseFeeBalance; - } - struct directForiegnAsset { - address foriegnAddress; - address nativeAddress; - uint256 chainID; - bool isSet; - } + } + struct directForiegnAsset { + address foriegnAddress; + address nativeAddress; + uint256 chainID; + bool isSet; + } - IController public controller; - Isettings public settings; - IRegistery public registry; - IbridgePool public bridgePool; - bool public paused; - - mapping(address => asset) public nativeAssets; - mapping(address => bool) public isActiveNativeAsset; - mapping(address => uint256[]) assetSupportedChainIds; - mapping(address => mapping(uint256 => bool)) public isAssetSupportedChain; - mapping(address => uint256 ) public foriegnAssetChainID; - mapping(address => asset) public foriegnAssets; - mapping(uint256 => directForiegnAsset) public directForiegnAssets; - mapping(address => mapping(uint256 => address)) public wrappedForiegnPair; - mapping(address => address) foriegnPair; - mapping(address => mapping(uint256 => bool)) hasWrappedForiegnPair; - - - uint256 totalFees; - uint256 feeBalance; - uint256 public chainId; // current chain id + IController public controller; + Isettings public settings; + IRegistery public registry; + IbridgePool public bridgePool; + bool public paused; + + mapping(address => asset) public nativeAssets; + mapping(address => bool) public isActiveNativeAsset; + mapping(address => uint256[]) assetSupportedChainIds; + mapping(address => mapping(uint256 => bool)) public isAssetSupportedChain; + mapping(address => uint256 ) public foriegnAssetChainID; + mapping(address => asset) public foriegnAssets; + mapping(uint256 => directForiegnAsset) public directForiegnAssets; + mapping(address => mapping(uint256 => address)) public wrappedForiegnPair; + mapping(address => address) foriegnPair; + mapping(address => mapping(uint256 => bool)) hasWrappedForiegnPair; + + + uint256 totalFees; + uint256 feeBalance; + uint256 constant feeDivisor = 10**4; + uint256 public chainId; // current chain id // uint256 public immutable chainId; // current chain id - address deployer ; - address feeController; - bool activeMigration; - uint256 migrationInitiationTime; - uint256 constant migrationDelay = 2 days; - address newBridge; - address migrator; - - uint256 directForiegnCount; -// address public immutable migrator; - uint256 fMigrationAt; - uint256 fDirectSwapMigrationAt; - uint256 nMigrationAt; - - address[] public foriegnAssetsList; - address[] public nativeAssetsList; - - mapping(address => mapping(uint256 => bool)) public isDirectSwap; - event MigrationInitiated(address indexed newBridge); - event RegisterredNativeMigration(address indexed assetAddress); - event RegisteredForiegnMigration(address indexed foriegnAddress, uint256 indexed chainID, address indexed wrappedAddress); - event MigratedAsset(address indexed assetAddress , bool isNativeAsset); - event ForiegnAssetAdded(address indexed foriegnAddress , uint256 indexed chainID ,address indexed wrappedAddress); - event updatedAddresses(address indexed settings , address indexed feeController , address indexed deployer); - event assetUpdated(address indexed assetAddress ,address indexed manager ,address indexed _feeRemitance ,uint256 min ,uint256 max ); - event MigrationCompleted(address indexed newBridge); - event BridgePauseStatusChanged(bool status); + address deployer ; + address feeController; + bool activeMigration; + uint256 migrationInitiationTime; + uint256 constant migrationDelay = 2 days; + address newBridge; + address migrator; + + uint256 directForiegnCount; + // address public immutable migrator; + uint256 fMigrationAt; + uint256 fDirectSwapMigrationAt; + uint256 nMigrationAt; + + address[] public foriegnAssetsList; + address[] public nativeAssetsList; + + mapping(address => mapping(uint256 => bool)) public isDirectSwap; + event MigrationInitiated(address indexed newBridge); + event RegisterredNativeMigration(address indexed assetAddress); + event RegisteredForiegnMigration(address indexed foriegnAddress, uint256 indexed chainID, address indexed wrappedAddress); + event MigratedAsset(address indexed assetAddress , bool isNativeAsset); + event ForiegnAssetAdded(address indexed foriegnAddress , uint256 indexed chainID ,address indexed wrappedAddress); + event updatedAddresses(address indexed settings , address indexed feeController , address indexed deployer); + event assetUpdated(address indexed assetAddress ,address indexed manager ,address indexed _feeRemitance ,uint256 min ,uint256 max ); + event MigrationCompleted(address indexed newBridge); + event BridgePauseStatusChanged(bool status); // event NativeAssetStatusChanged(address indexed assetAddress , bool status); - event SendTransaction( - bytes32 transactionID, - uint256 chainID, - address indexed assetAddress, - uint256 sendAmount, - address indexed receiver, - uint256 nounce, - address indexed sender - ); - event BurnTransaction( - bytes32 transactionID, - uint256 chainID, - address indexed assetAddress, - uint256 sendAmount, - address indexed receiver, - uint256 nounce, - address indexed sender - ); - event RailAdded( - address indexed assetAddress, - uint256 minAmount, - uint256 maxAmount, - uint256[] supportedChains, - address[] foriegnAddresses, - bool directSwap, - address registrar, - bool ownedRail,address indexed manager, - address feeRemitance, - uint256 deployWith - ); - + event SendTransaction( + bytes32 transactionID, + uint256 chainID, + address indexed assetAddress, + uint256 sendAmount, + address indexed receiver, + uint256 nounce, + address indexed sender + ); + event BurnTransaction( + bytes32 transactionID, + uint256 chainID, + address indexed assetAddress, + uint256 sendAmount, + address indexed receiver, + uint256 nounce, + address indexed sender + ); + event RailAdded( + address indexed assetAddress, + uint256 minAmount, + uint256 maxAmount, + uint256[] supportedChains, + address[] foriegnAddresses, + bool directSwap, + address registrar, + bool ownedRail,address indexed manager, + address feeRemitance, + uint256 deployWith + ); - constructor (address _controllers , address _settings, address _registry, address _deployer ,address _feeController , address _bridgePool,address _migrator) { - noneZeroAddress(_controllers); - noneZeroAddress(_settings); - noneZeroAddress(_registry); - noneZeroAddress(_deployer); - noneZeroAddress(_feeController); - noneZeroAddress(_bridgePool); - settings = Isettings(_settings); - controller = IController(_controllers); - registry = IRegistery(_registry); - migrator = _migrator; - deployer = _deployer; - feeController = _feeController; - bridgePool = IbridgePool(_bridgePool); - uint256 id; - assembly { + constructor (address _controllers , address _settings, address _registry, address _deployer ,address _feeController , address _bridgePool,address _migrator) { + noneZeroAddress(_controllers); + noneZeroAddress(_settings); + noneZeroAddress(_registry); + noneZeroAddress(_deployer); + noneZeroAddress(_feeController); + noneZeroAddress(_bridgePool); + settings = Isettings(_settings); + controller = IController(_controllers); + registry = IRegistery(_registry); + migrator = _migrator; + deployer = _deployer; + feeController = _feeController; + bridgePool = IbridgePool(_bridgePool); + uint256 id; + assembly { id := chainid() } chainId = id; - } - +} - function pauseBrigde() external { - isOwner(); - paused = !paused; + function pauseBrigde() external { + isOwner(); + paused = !paused; // emit BridgePauseStatusChanged(paused); - } - + } - function updateAddresses(address _settings , address _feeController , address _deployer) external { - isOwner(); - noneZeroAddress(_settings) ; - noneZeroAddress(_feeController); - noneZeroAddress(_deployer); - emit updatedAddresses(_settings , _feeController , _deployer); - settings = Isettings(_settings); - feeController = _feeController; - deployer = _deployer; - } + function updateAddresses(address _settings , address _feeController , address _deployer) external { + isOwner(); + noneZeroAddress(_settings) ; + noneZeroAddress(_feeController); + noneZeroAddress(_deployer); + emit updatedAddresses(_settings , _feeController , _deployer); + settings = Isettings(_settings); + feeController = _feeController; + deployer = _deployer; + } @@ -336,7 +336,7 @@ contract Bridge is Context , ReentrancyGuard { } else{ wrappedAddress = Ideployer(deployer).deployerWrappedAsset(assetMeta[0] , assetMeta[1], deployWith); - foriegnAssets[wrappedAddress] = asset(wrappedAddress , range[0], range[1] , 0 ,0,OwnedRail , manager,feeAddress , 0, true , 0); + foriegnAssets[wrappedAddress] = asset(wrappedAddress , range[0], range[1] , 0 ,0,0,OwnedRail , manager,feeAddress , 0, true , 0); foriegnAssetChainID[wrappedAddress] = chainID; foriegnPair[wrappedAddress] = foriegnAddress; foriegnAssetsList.push(wrappedAddress); @@ -356,9 +356,9 @@ contract Bridge is Context , ReentrancyGuard { // require(, "C_E"); require(isActiveNativeAsset[assetAddress] && isAssetSupportedChain[assetAddress][chainTo] , "AL_E"); noneZeroAddress(receiver); - (bool success, uint256 recievedValue) = processedPayment(assetAddress ,chainTo, amount); + (bool success, uint256 recievedValue, uint feeDeducted) = processedPayment(assetAddress, amount); require(success && recievedValue >= nativeAssets[assetAddress].minAmount && recievedValue <= nativeAssets[assetAddress].maxAmount , "I_F"); - deductFees(assetAddress , chainTo , true); + deductFees(assetAddress , feeDeducted, true); if(isDirectSwap[assetAddress][chainTo]){ if(assetAddress == address(0)){ bridgePool.topUp{ value : recievedValue}(assetAddress , recievedValue); @@ -398,9 +398,9 @@ contract Bridge is Context , ReentrancyGuard { uint256 chainTo = foriegnAssetChainID[assetAddress]; require(foriegnAssets[assetAddress].isSet && amount >= foriegnAssets[assetAddress].minAmount && amount <= foriegnAssets[assetAddress].maxAmount , "AL_E"); noneZeroAddress(receiver); - (bool success, uint256 recievedValue) = processedPayment(assetAddress ,chainTo, amount); + (bool success, uint256 recievedValue,uint256 feeDeducted) = processedPayment(assetAddress, amount); require(success && recievedValue > 0 , "I_F"); - deductFees(assetAddress ,chainTo , false); + deductFees(assetAddress ,feeDeducted , false); IwrappedToken(assetAddress).burn(recievedValue); address _foriegnAsset = foriegnPair[assetAddress]; uint256 nounce = registry.getUserNonce(receiver); @@ -450,7 +450,7 @@ contract Bridge is Context , ReentrancyGuard { // require(, "C"); // require(, "N_V"); - payoutUser(payable(transaction.receiver), transaction.assetAddress , removeBaseFee(transaction.assetAddress , transaction.amount)); + // payoutUser(payable(transaction.receiver), transaction.assetAddress , removeBaseFee(transaction.assetAddress , transaction.amount)); nativeAssets[transaction.assetAddress].balance -= transaction.amount; registry.completeClaimTransaction(claimID); } @@ -468,33 +468,39 @@ contract Bridge is Context , ReentrancyGuard { // internal fxn used to process incoming payments - function processedPayment(address assetAddress ,uint256 chainID, uint256 amount) internal returns (bool , uint256) { - uint256 fees = IfeeController(feeController).getBridgeFee(msg.sender, assetAddress, chainID); + function processedPayment(address assetAddress ,uint256 amount) internal returns (bool , uint256, uint256) { + uint256 feesPercent = IfeeController(feeController).getBridgeFee(msg.sender, assetAddress); + uint256 value; + uint256 fee; if (assetAddress == address(0)) { - if(msg.value >= amount + fees && msg.value > 0){ - uint256 value = msg.value - fees; + if(msg.value >= amount && msg.value > 0){ + fee = msg.value * feesPercent / feeDivisor; + value = msg.value - fee; - return (true , value); + return (true , value, fee); } else { - return (false , 0); + return (false , 0, 0); } } else { IERC20 token = IERC20(assetAddress); - if (token.allowance(_msgSender(), address(this)) >= amount && (msg.value >= fees)) { + if (token.allowance(_msgSender(), address(this)) >= amount) { uint256 balanceBefore = token.balanceOf(address(this)); require(token.transferFrom(_msgSender() , address(this) , amount), "I_F"); uint256 balanceAfter = token.balanceOf(address(this)); - return (true , balanceAfter - balanceBefore ); + uint256 amountTransferred = balanceAfter - balanceBefore; + fee = amountTransferred * feesPercent / feeDivisor; + value = amountTransferred - fee; + return (true , value, fee); } else { - return (false , 0); + return (false , 0, 0); } } } // internal fxn for deducting and remitting fees after a sale - function deductFees(address assetAddress , uint256 chainID , bool native) private { + function deductFees(address assetAddress , uint256 feeToDeduct , bool native) private { asset storage currentasset; if(native) currentasset = nativeAssets[assetAddress]; @@ -504,45 +510,41 @@ contract Bridge is Context , ReentrancyGuard { require(currentasset.isSet ,"I_A"); // uint256 fees_to_deduct = settings.networkFee(chainID); - uint256 fees_to_deduct = IfeeController(feeController).getBridgeFee(msg.sender, assetAddress, chainID ) ; - totalFees = totalFees + fees_to_deduct; + // uint256 fees_to_deduct = IfeeController(feeController).getBridgeFee(msg.sender, assetAddress) ; + // totalFees = totalFees + fees_to_deduct; if (currentasset.ownedRail) { - uint256 ownershare = fees_to_deduct * settings.railOwnerFeeShare() / 100; - uint256 networkshare = fees_to_deduct - ownershare; - currentasset.collectedFees += fees_to_deduct; + uint256 ownershare = feeToDeduct * settings.railOwnerFeeShare() / 100; + uint256 networkshare = feeToDeduct - ownershare; + currentasset.collectedFees += feeToDeduct; currentasset.feeBalance += ownershare; - feeBalance = feeBalance + networkshare; + currentasset.networkFee += networkshare; } else { - currentasset.collectedFees += fees_to_deduct; - feeBalance = feeBalance + fees_to_deduct; + currentasset.collectedFees += feeToDeduct; + currentasset.networkFee = feeBalance + feeToDeduct; } - if (feeBalance > settings.minWithdrawableFee()) { + - if (currentasset.ownedRail) { - if (currentasset.feeBalance > 0) { - payoutUser(payable(currentasset.feeRemitance), address(0), currentasset.feeBalance ); - currentasset.feeBalance = 0; - } - } - if (feeBalance > 0) { - if(currentasset.baseFeeBalance > 0){ - payoutUser(payable(settings.feeRemitance()), assetAddress, currentasset.baseFeeBalance); - currentasset.baseFeeBalance = 0; - } - payoutUser(payable(settings.feeRemitance()), address(0), feeBalance ); - feeBalance = 0; - //recieve excess fees - if(address(this).balance > nativeAssets[address(0)].balance ){ - uint256 excess = address(this).balance - nativeAssets[address(0)].balance; - payoutUser(payable(settings.feeRemitance()), address(0), excess ); - } - + if (currentasset.ownedRail) { + if (currentasset.feeBalance > 0) { + payoutUser(payable(currentasset.feeRemitance), assetAddress, currentasset.feeBalance ); + currentasset.feeBalance = 0; } } - } + if(currentasset.networkFee > 0){ + payoutUser(payable(settings.feeRemitance()), assetAddress, currentasset.networkFee); + currentasset.networkFee = 0; + } + // payoutUser(payable(settings.feeRemitance()), address(0), feeBalance ); + // feeBalance = 0; + //recieve excess fees + if(IERC20(assetAddress).balanceOf(address(this)) > nativeAssets[assetAddress].balance ){ + uint256 excess = IERC20(assetAddress).balanceOf(address(this)) - nativeAssets[assetAddress].balance; + payoutUser(payable(settings.feeRemitance()), assetAddress, excess ); + } + } function initialMigration(address _newbridge) external { @@ -724,7 +726,7 @@ contract Bridge is Context , ReentrancyGuard { { require( !nativeAssets[assetAddress].isSet && _msgSender() == migrator , "U_A"); - (bool success, uint256 amountRecieved) = processedPayment(assetAddress , 0, balances[1]); + (bool success, uint256 amountRecieved, ) = processedPayment(assetAddress , balances[1]); require(success && amountRecieved >= balances[1], "I_F"); _registerRail(assetAddress, supportedChains, false, limits[0], limits[1], ownedRail , feeRemitance, manager , true); nativeAssets[assetAddress].balance = balances[0]; @@ -767,6 +769,7 @@ contract Bridge is Context , ReentrancyGuard { maxAmount, 0, _collectedFees, + 0, ownedRail, manager, feeAddress, diff --git a/contracts/BridgePool.sol b/contracts/BridgePool.sol index beaa472..5b0b6f0 100644 --- a/contracts/BridgePool.sol +++ b/contracts/BridgePool.sol @@ -9,7 +9,7 @@ import "./interface/IERC20deployer.sol"; contract BridgePool is Context , ReentrancyGuard { - + struct pool{ address wrappedAsset; uint256 deposited; @@ -41,14 +41,14 @@ contract BridgePool is Context , ReentrancyGuard { uint256 newDebtThreshold ); bool initialized; - modifier onlyBridge() { - require(bridge == _msgSender(), "Only Bridge Callable"); + modifier onlyBridge() { + require(bridge == _msgSender(), "Only Bridge Callable"); _; - } - modifier poolInitialized() { - require(initialized, "pool not initialized"); + } + modifier poolInitialized() { + require(initialized, "pool not initialized"); _; - } + } constructor(IController _controller ) { @@ -92,9 +92,7 @@ contract BridgePool is Context , ReentrancyGuard { require(debtThreshold > 0 , "cant be zero"); emit PoolDebtThresholdUpdated(poolAddress ,pools[poolAddress].debtThreshold , debtThreshold); pools[poolAddress].debtThreshold = debtThreshold; - } - function createPool( address poolAddress, @@ -108,7 +106,7 @@ contract BridgePool is Context , ReentrancyGuard { require(debtThreshold > 0 , "cant be zero"); WrappedToken wrappedAsset; if(poolAddress == address(0)){ - wrappedAsset = new WrappedToken("brEtherium" , "brEth"); + wrappedAsset = new WrappedToken("brEtherium" , "brEth"); }else{ IERC20Metadata token = IERC20Metadata(poolAddress); wrappedAsset = new WrappedToken(string(abi.encodePacked( "br", token.name())) , string(abi.encodePacked("br" , token.symbol()))); @@ -123,21 +121,19 @@ contract BridgePool is Context , ReentrancyGuard { function deposit(address poolAddress, uint256 amount) public payable nonReentrant poolInitialized{ require(pools[poolAddress].isSet , "invalid Pool"); - (bool success , uint256 amountRecieved) = processedPayment(poolAddress , amount); - require(success && amountRecieved > 0, "I_F"); - pools[poolAddress].deposited += amountRecieved; - IwrappedToken(pools[poolAddress].wrappedAsset).mint(msg.sender , amountRecieved); - emit AssetDeposited(poolAddress , amountRecieved); - + (bool success , uint256 amountRecieved) = processedPayment(poolAddress , amount); + require(success && amountRecieved > 0, "I_F"); + pools[poolAddress].deposited += amountRecieved; + IwrappedToken(pools[poolAddress].wrappedAsset).mint(msg.sender , amountRecieved); + emit AssetDeposited(poolAddress , amountRecieved); } function withdraw(address poolAddress , uint256 amount) public nonReentrant poolInitialized{ - require(pools[poolAddress].isSet , "invalid Pool"); - IERC20 token = IERC20(poolAddress); - IERC20 wrappedToken = IERC20(pools[poolAddress].wrappedAsset); - - require(pools[poolAddress].deposited >= amount && token.balanceOf(address(this)) >= amount , "Insufficent Pool Balance"); + require(pools[poolAddress].isSet , "invalid Pool"); + IERC20 token = IERC20(poolAddress); + IERC20 wrappedToken = IERC20(pools[poolAddress].wrappedAsset); + require(pools[poolAddress].deposited >= amount && token.balanceOf(address(this)) >= amount , "Insufficent Pool Balance"); require(wrappedToken.allowance(_msgSender(), address(this)) >= amount , "I_F"); uint256 balanceBefore = IERC20(pools[poolAddress].wrappedAsset).balanceOf(address(this)); wrappedToken.transferFrom(_msgSender() , address(this) , amount); diff --git a/contracts/Controller.sol b/contracts/Controller.sol index fb388e6..6e506d3 100644 --- a/contracts/Controller.sol +++ b/contracts/Controller.sol @@ -5,62 +5,62 @@ import "@openzeppelin/contracts/access/Ownable.sol"; contract Controller is Ownable { - mapping(address =>bool) public isAdmin; - mapping(address =>bool) public isRegistrar; - mapping(address =>bool) public isOracle; - mapping(address =>bool) public isValidator; - address[] public validators; - address[] public admins; - address[] public oracles; - address[] public registrars; - - event AdminAdded(address indexed admin); - event AdminRemoved(address indexed admin); - event RegistrarAdded(address indexed registrar); - event RegistrarRemoved(address indexed registrar); - event OracleAdded(address indexed oracle); - event OracleRemoved(address indexed oracle); - event ValidatorAdded(address indexed validator); - event ValidatorRemoved(address indexed validator); - - - modifier onlyAdmin() { + mapping(address =>bool) public isAdmin; + mapping(address =>bool) public isRegistrar; + mapping(address =>bool) public isOracle; + mapping(address =>bool) public isValidator; + address[] public validators; + address[] public admins; + address[] public oracles; + address[] public registrars; + + event AdminAdded(address indexed admin); + event AdminRemoved(address indexed admin); + event RegistrarAdded(address indexed registrar); + event RegistrarRemoved(address indexed registrar); + event OracleAdded(address indexed oracle); + event OracleRemoved(address indexed oracle); + event ValidatorAdded(address indexed validator); + event ValidatorRemoved(address indexed validator); + + + modifier onlyAdmin() { require(isAdmin[_msgSender()] || owner() == _msgSender(), "U_A"); _; } - constructor() { + constructor() { // isAdmin[_msgSender()] = true; addAdmin(_msgSender() , true); } - function addAdmin(address _admin , bool add) public onlyOwner { - if (add) { - require(!isAdmin[_admin] , "already an admin"); - emit AdminAdded(_admin); - admins.push(_admin); - } else { - require(isAdmin[_admin] , "not an admin"); - for (uint256 index; index < admins.length ; index++) { - if (admins[index] == _admin) { - admins[index] = admins[admins.length - 1]; - admins.pop(); + function addAdmin(address _admin , bool add) public onlyOwner { + if (add) { + require(!isAdmin[_admin] , "already an admin"); + emit AdminAdded(_admin); + admins.push(_admin); + } else { + require(isAdmin[_admin] , "not an admin"); + for (uint256 index; index < admins.length ; index++) { + if (admins[index] == _admin) { + admins[index] = admins[admins.length - 1]; + admins.pop(); + } } - } - emit AdminRemoved(_admin); - } - isAdmin[_admin] = add; + emit AdminRemoved(_admin); + } + isAdmin[_admin] = add; } - function addRegistrar(address _registrar , bool add) external onlyAdmin { - if (add) { - require(!isRegistrar[_registrar] , "already a Registrer"); - emit RegistrarAdded(_registrar); - registrars.push(_registrar); - } else { + function addRegistrar(address _registrar , bool add) external onlyAdmin { + if (add) { + require(!isRegistrar[_registrar] , "already a Registrer"); + emit RegistrarAdded(_registrar); + registrars.push(_registrar); + } else { require(isRegistrar[_registrar] , "not a Registrer"); for (uint256 index; index < validators.length ; index++) { if (registrars[index] == _registrar) { @@ -81,19 +81,19 @@ contract Controller is Ownable { oracles.push(_oracle); } else { require(isOracle[_oracle] , "not an oracle"); - for (uint256 index; index < oracles.length ; index++) { + for (uint256 index; index < oracles.length ; index++) { if (oracles[index] == _oracle) { oracles[index] = oracles[oracles.length - 1]; oracles.pop(); } - } - emit OracleRemoved(_oracle); + } + emit OracleRemoved(_oracle); } isOracle[_oracle] = add; } - function addValidator(address _validator , bool add) external onlyAdmin { + function addValidator(address _validator , bool add) external onlyAdmin { if (add) { require(!isValidator[_validator] , "already a Validator"); emit ValidatorAdded(_validator); @@ -109,25 +109,25 @@ contract Controller is Ownable { emit ValidatorRemoved(_validator); } isValidator[_validator] = add; - } +} - function validatorsCount() public view returns (uint256){ - return validators.length; - } + function validatorsCount() public view returns (uint256){ + return validators.length; + } - function oraclesCount() public view returns (uint256){ - return oracles.length; - } + function oraclesCount() public view returns (uint256){ + return oracles.length; + } - function adminsCount() public view returns (uint256){ - return admins.length; - } + function adminsCount() public view returns (uint256){ + return admins.length; + } - function registrarsCount() public view returns (uint256){ - return registrars.length; - } + function registrarsCount() public view returns (uint256){ + return registrars.length; + } } \ No newline at end of file diff --git a/contracts/FeeController.sol b/contracts/FeeController.sol index e37602f..c1a65fd 100644 --- a/contracts/FeeController.sol +++ b/contracts/FeeController.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: GPL-3.0 -pragma solidity 0.8.0; +pragma solidity ^0.8.0; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "./interface/Isettings.sol"; @@ -7,127 +7,127 @@ import "./interface/Icontroller.sol"; contract FeeController { -IController public controller; -Isettings public settings; -mapping (address => bool) public isExempted; -uint256 public brgHoldingThreshold ; -uint256 public brgHoldingIncentive = 20; - -mapping(address => uint256) public assetIncentive; - -bool public useExemption; -bool public usebrgHoldingIncentive; -bool public useAssetIncentive; -uint256 public minUpdateDelay; - -event BrgHoldingIncentiveStatusChanged( bool status ); -event AssetIncentiveStatusChanged( bool status ); -event AddressExemptionStatusChanged( bool status ); -event AssetIncentiveUpdated(address indexed asset ,uint256 oldIncentive , uint256 newIncentive); -event userExemptStatusChanged(address indexed user , bool exemptionStatus); -event BrgHoldingThresholdUpdated(uint256 prevBrgHoldingThreshold , uint256 newBrgHoldingThreshold); -event BrgHoldingIncentiveUpdated(uint256 prevBrgHoldingIncentive , uint256 newBrgHoldingIncentive); -modifier onlyOwner { - require(controller.owner() == msg.sender, " caller is not the owner"); - _; - -} - -modifier Admin { - require(controller.owner() == msg.sender || controller.isAdmin(msg.sender), " caller is not the admin"); - _; - -} - - -constructor(IController _controller , Isettings _settings ) { - controller = _controller; - settings = _settings; -} - - -function activateBrgHoldingIncentive(bool status) public Admin { - require(usebrgHoldingIncentive != status , "already set"); - emit BrgHoldingIncentiveStatusChanged(status); - usebrgHoldingIncentive = status; - } - - -function activateAssetIncentive(bool status) public Admin { - require(useAssetIncentive != status , "already set"); - emit AssetIncentiveStatusChanged(status); - useAssetIncentive = status; -} - - -function activateAddressExemption(bool status) public Admin { - require(useExemption != status , "already set"); - AddressExemptionStatusChanged(status); - useExemption = status; - } - - - function exemptAddress(address user , bool status) external onlyOwner { - require(isExempted[user] != status ,"already set"); - emit userExemptStatusChanged(user , status); - isExempted[user] = status; - } - - - function setAssetIncentivization(address asset , uint256 incentive) external onlyOwner{ - require(assetIncentive[asset] != incentive ,"already set"); - require(incentive + brgHoldingIncentive < 100 ,"above limit"); - emit AssetIncentiveUpdated(asset , assetIncentive[asset] , incentive); - assetIncentive[asset] = incentive; - } - - -function setBrgHoldingThreshold( uint256 threshold) external onlyOwner{ - require(brgHoldingThreshold != threshold ,"already set"); - emit BrgHoldingThresholdUpdated(brgHoldingThreshold , threshold); - brgHoldingThreshold = threshold; -} - - -function setBrgHoldingIncentive ( uint256 incentive) external onlyOwner{ - require(brgHoldingIncentive!= incentive ,"already set"); - require(incentive < 100 ,"above limit"); - emit BrgHoldingIncentiveUpdated(brgHoldingIncentive , incentive ); - brgHoldingIncentive = incentive; - } - - -function getBridgeFee(address sender, address asset, uint256 chainTo ) external view returns(uint256){ - uint256 fees = settings.networkFee(chainTo); - uint256 totalIncentive; - if (useExemption && isExempted[sender]) { - return 0; - } - if (usebrgHoldingIncentive) { - if (IERC20(settings.brgToken()).balanceOf(sender) >= brgHoldingThreshold) { - totalIncentive += brgHoldingIncentive; - } - } - if (useAssetIncentive && assetIncentive[asset] > 0) { - totalIncentive += assetIncentive[asset]; - } - - if (totalIncentive >= 100) { - return 0; - } else if (totalIncentive == 0) { - return fees; - } else { - return fees - getIncentive(fees , totalIncentive) ; - } -} - - -function getIncentive(uint256 fee , uint256 incentive) public pure returns (uint256){ - if (incentive > 100 || incentive == 0) { - return 0; - } else { - return incentive * fee / 100; - } - } + IController public controller; + Isettings public settings; + mapping (address => bool) public isExempted; + uint256 public brgHoldingThreshold ; + uint256 public brgHoldingIncentive = 200; + + mapping(address => uint256) public assetIncentive; + + bool public useExemption; + bool public usebrgHoldingIncentive; + bool public useAssetIncentive; + uint256 public minUpdateDelay; + + event BrgHoldingIncentiveStatusChanged( bool status ); + event AssetIncentiveStatusChanged( bool status ); + event AddressExemptionStatusChanged( bool status ); + event AssetIncentiveUpdated(address indexed asset ,uint256 oldIncentive , uint256 newIncentive); + event userExemptStatusChanged(address indexed user , bool exemptionStatus); + event BrgHoldingThresholdUpdated(uint256 prevBrgHoldingThreshold , uint256 newBrgHoldingThreshold); + event BrgHoldingIncentiveUpdated(uint256 prevBrgHoldingIncentive , uint256 newBrgHoldingIncentive); + modifier onlyOwner { + require(controller.owner() == msg.sender, " caller is not the owner"); + _; + + } + + modifier Admin { + require(controller.owner() == msg.sender || controller.isAdmin(msg.sender), " caller is not the admin"); + _; + + } + + + constructor(IController _controller , Isettings _settings ) { + controller = _controller; + settings = _settings; + } + + + function activateBrgHoldingIncentive(bool status) public Admin { + require(usebrgHoldingIncentive != status , "already set"); + emit BrgHoldingIncentiveStatusChanged(status); + usebrgHoldingIncentive = status; + } + + + function activateAssetIncentive(bool status) public Admin { + require(useAssetIncentive != status , "already set"); + emit AssetIncentiveStatusChanged(status); + useAssetIncentive = status; + } + + + function activateAddressExemption(bool status) public Admin { + require(useExemption != status , "already set"); + emit AddressExemptionStatusChanged(status); + useExemption = status; + } + + + function exemptAddress(address user , bool status) external onlyOwner { + require(isExempted[user] != status ,"already set"); + emit userExemptStatusChanged(user , status); + isExempted[user] = status; + } + + + function setAssetIncentivization(address asset , uint256 incentive) external onlyOwner{ + require(assetIncentive[asset] != incentive ,"already set"); + require(incentive + brgHoldingIncentive < 1000 ,"above limit"); + emit AssetIncentiveUpdated(asset , assetIncentive[asset] , incentive); + assetIncentive[asset] = incentive; + } + + + function setBrgHoldingThreshold( uint256 threshold) external onlyOwner{ + require(brgHoldingThreshold != threshold ,"already set"); + emit BrgHoldingThresholdUpdated(brgHoldingThreshold , threshold); + brgHoldingThreshold = threshold; + } + + + function setBrgHoldingIncentive ( uint256 incentive) external onlyOwner{ + require(brgHoldingIncentive!= incentive ,"already set"); + require(incentive < 1000 ,"above limit"); + emit BrgHoldingIncentiveUpdated(brgHoldingIncentive , incentive ); + brgHoldingIncentive = incentive; + } + + + function getBridgeFee(address sender, address asset) external view returns(uint256){ + uint256 feePercent = settings.networkFee(); + uint256 totalIncentive; + if (useExemption && isExempted[sender]) { + return 0; + } + if (usebrgHoldingIncentive) { + if (IERC20(settings.brgToken()).balanceOf(sender) >= brgHoldingThreshold) { + totalIncentive += brgHoldingIncentive; + } + } + if (useAssetIncentive && assetIncentive[asset] > 0) { + totalIncentive += assetIncentive[asset]; + } + + if (totalIncentive >= 1000) { + return 0; + } else if (totalIncentive == 0) { + return feePercent; + } else { + return feePercent - getIncentive(feePercent , totalIncentive) ; + } + } + + + function getIncentive(uint256 fee , uint256 incentive) public pure returns (uint256){ + if (incentive > 1000 || incentive == 0) { + return 0; + } else { + return incentive * fee / 1000; + } + } } \ No newline at end of file diff --git a/contracts/Registry.sol b/contracts/Registry.sol index d3c6775..77ba799 100644 --- a/contracts/Registry.sol +++ b/contracts/Registry.sol @@ -2,143 +2,140 @@ pragma solidity 0.8.0; import "@openzeppelin/contracts/access/Ownable.sol"; +import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol"; import "./interface/Iregistry.sol"; import "./interface/Isettings.sol"; import "./interface/Ibridge.sol"; import "./interface/Icontroller.sol"; +contract Registry is Ownable{ + using ECDSA for bytes32; -contract Registry is Ownable { struct Transaction{ - uint256 chainId; - address assetAddress; - uint256 amount; - address receiver; - uint256 nounce; - bool isCompleted; - } - struct validation { - uint256 validationCount; - bool validated; - } - enum transactionType {send , burn , mint ,claim} - - mapping (address => uint256) public assetTotalTransactionCount; - mapping (address => mapping( uint256 => uint256 )) public assetTransactionTypeCount; - mapping(address => mapping( uint256 => uint256 )) public assetChainBalance; - mapping(address => uint256) public getUserNonce; - mapping (bytes32 => bool) public isSendTransaction; - mapping (bytes32 => Transaction) public sendTransactions; - mapping (bytes32 => bool) public isClaimTransaction; - mapping (bytes32 => Transaction) public claimTransactions; - mapping(bytes32 => Transaction) public mintTransactions; - mapping(bytes32 => bool) public isMintTransaction; - mapping(bytes32 => Transaction) public burnTransactions; - mapping(bytes32 => bool) public isburnTransaction; - mapping(bytes32 => validation ) public transactionValidations; - mapping(bytes32 => address[] ) public TransactionValidators; - mapping(bytes32 => mapping(address => bool)) public hasValidatedTransaction; - uint256 public totalTransactions; - - event TransactionValidated(bytes32 indexed transactionID); - event SendTransactionCompleted(bytes32 indexed transactionID); - event BurnTransactionCompleted(bytes32 indexed transactionID); - event MintTransactionCompleted(bytes32 indexed transactionID); - event ClaimTransactionCompleted(bytes32 indexed transactionID); - - constructor(){} - - - function completeSendTransaction(bytes32 transactionID) external { - require(isSendTransaction[transactionID] ,"invalid Transaction"); - emit SendTransactionCompleted(transactionID); - sendTransactions[transactionID].isCompleted = true; - } - - - function completeBurnTransaction(bytes32 transactionID) external { - require(isburnTransaction[transactionID] ,"invalid Transaction"); - emit BurnTransactionCompleted(transactionID); - burnTransactions[transactionID].isCompleted = true ; - } - - - function completeMintTransaction(bytes32 transactionID) external { - require(isMintTransaction[transactionID] ,"invalid Transaction"); - emit MintTransactionCompleted(transactionID); - mintTransactions[transactionID].isCompleted = true; - } - - - function completeClaimTransaction(bytes32 transactionID) external { - require(isClaimTransaction[transactionID] ,"invalid Transaction"); - emit ClaimTransactionCompleted(transactionID); - assetChainBalance[claimTransactions[transactionID].assetAddress][claimTransactions[transactionID].chainId] -= claimTransactions[transactionID].amount; - claimTransactions[transactionID].isCompleted = true; - } - - - - - - function registerTransaction( - bytes32 transactionID, - uint256 chainId, - address assetAddress, - uint256 amount, - address receiver, - uint256 nounce, - transactionType _transactionType - ) + uint256 chainId; + address assetAddress; + uint256 amount; + address receiver; + uint256 nounce; + bool isCompleted; + } + + struct validation { + uint256 validationCount; + bool validated; + } + + enum transactionType {send , burn , mint ,claim} + + mapping (address => uint256) public assetTotalTransactionCount; + mapping (address => mapping( uint256 => uint256 )) public assetTransactionTypeCount; + mapping(address => mapping( uint256 => uint256 )) public assetChainBalance; + mapping(address => uint256) public getUserNonce; + mapping (bytes32 => bool) public isSendTransaction; + mapping (bytes32 => Transaction) public sendTransactions; + mapping (bytes32 => bool) public isClaimTransaction; + mapping (bytes32 => Transaction) public claimTransactions; + mapping(bytes32 => Transaction) public mintTransactions; + mapping(bytes32 => bool) public isMintTransaction; + mapping(bytes32 => Transaction) public burnTransactions; + mapping(bytes32 => bool) public isburnTransaction; + mapping(bytes32 => validation ) public transactionValidations; + mapping(bytes32 => address[] ) public TransactionValidators; + mapping(bytes32 => mapping(address => bool)) public hasValidatedTransaction; + uint256 public totalTransactions; + + event TransactionValidated(bytes32 indexed transactionID); + event SendTransactionCompleted(bytes32 indexed transactionID); + event BurnTransactionCompleted(bytes32 indexed transactionID); + event MintTransactionCompleted(bytes32 indexed transactionID); + event ClaimTransactionCompleted(bytes32 indexed transactionID); + + constructor(){} + + function completeSendTransaction(bytes32 transactionID) external { + require(isSendTransaction[transactionID] ,"invalid Transaction"); + emit SendTransactionCompleted(transactionID); + sendTransactions[transactionID].isCompleted = true; + } + + + function completeBurnTransaction(bytes32 transactionID) external { + require(isburnTransaction[transactionID] ,"invalid Transaction"); + emit BurnTransactionCompleted(transactionID); + burnTransactions[transactionID].isCompleted = true ; + } + + + function completeMintTransaction(bytes32 transactionID) external { + require(isMintTransaction[transactionID] ,"invalid Transaction"); + emit MintTransactionCompleted(transactionID); + mintTransactions[transactionID].isCompleted = true; + } + + + function completeClaimTransaction(bytes32 transactionID) external { + require(isClaimTransaction[transactionID] ,"invalid Transaction"); + emit ClaimTransactionCompleted(transactionID); + assetChainBalance[claimTransactions[transactionID].assetAddress][claimTransactions[transactionID].chainId] -= claimTransactions[transactionID].amount; + claimTransactions[transactionID].isCompleted = true; + } + + function registerTransaction( + bytes32 transactionID, + uint256 chainId, + address assetAddress, + uint256 amount, + address receiver, + uint256 nounce, + transactionType _transactionType + ) public onlyOwner - { - if (_transactionType == transactionType.send) { - sendTransactions[transactionID] = Transaction(chainId , assetAddress ,amount , receiver ,nounce, false); - isSendTransaction[transactionID] = true; - getUserNonce[receiver]++; - assetChainBalance[assetAddress][chainId] += amount; - } else if (_transactionType == transactionType.burn) { - burnTransactions[transactionID] = Transaction(chainId , assetAddress ,amount , receiver ,nounce, false); - isburnTransaction[transactionID] = true; - getUserNonce[receiver]++; - } - assetTotalTransactionCount[assetAddress]++; - totalTransactions++; - } - - - function _registerTransaction( - bytes32 transactionID, - uint256 chainId, - address assetAddress, - uint256 amount, - address receiver, - uint256 nounce, - transactionType _transactionType - ) - internal - { - if (_transactionType == transactionType.mint) { - mintTransactions[transactionID] = Transaction(chainId , assetAddress ,amount , receiver ,nounce, false); - isMintTransaction[transactionID] = true; - } else if (_transactionType == transactionType.claim) { - claimTransactions[transactionID] = Transaction(chainId , assetAddress ,amount , receiver ,nounce, false); - isClaimTransaction[transactionID] = true; - } - } - - - function registerClaimTransaction( - bytes32 claimID, - uint256 chainFrom, - address assetAddress, - uint256 amount, - address receiver, - uint256 nounce + { + if (_transactionType == transactionType.send) { + sendTransactions[transactionID] = Transaction(chainId , assetAddress ,amount , receiver ,nounce, false); + isSendTransaction[transactionID] = true; + getUserNonce[receiver]++; + assetChainBalance[assetAddress][chainId] += amount; + } else if (_transactionType == transactionType.burn) { + burnTransactions[transactionID] = Transaction(chainId , assetAddress ,amount , receiver ,nounce, false); + isburnTransaction[transactionID] = true; + getUserNonce[receiver]++; + } + assetTotalTransactionCount[assetAddress]++; + totalTransactions++; +} + + function _registerTransaction( + bytes32 transactionID, + uint256 chainId, + address assetAddress, + uint256 amount, + address receiver, + uint256 nounce, + transactionType _transactionType ) - external + internal + { + if (_transactionType == transactionType.mint) { + mintTransactions[transactionID] = Transaction(chainId , assetAddress ,amount , receiver ,nounce, false); + isMintTransaction[transactionID] = true; + } else if (_transactionType == transactionType.claim) { + claimTransactions[transactionID] = Transaction(chainId , assetAddress ,amount , receiver ,nounce, false); + isClaimTransaction[transactionID] = true; + } + } + + function registerClaimTransaction( + bytes32 claimID, + uint256 chainFrom, + address assetAddress, + uint256 amount, + address receiver, + uint256 nounce + ) + external { require(IController(Ibridge(owner()).controller()).isOracle(msg.sender),"U_A"); require(!isClaimTransaction[claimID], "registerred"); @@ -154,18 +151,18 @@ contract Registry is Ownable { require(claimID == requiredClaimID , "claimid_err"); _registerTransaction(claimID ,chainFrom , assetAddress, amount , receiver ,nounce, transactionType.claim ); - } - - - function registerMintTransaction( - bytes32 mintID, - uint256 chainFrom, - address assetAddress, - uint256 amount, - address receiver, - uint256 nounce - ) - external + } + + + function registerMintTransaction( + bytes32 mintID, + uint256 chainFrom, + address assetAddress, + uint256 amount, + address receiver, + uint256 nounce + ) + external { require(IController(Ibridge(owner()).controller()).isOracle(msg.sender),"U_A"); require(!isMintTransaction[mintID], "registerred"); @@ -188,68 +185,86 @@ contract Registry is Ownable { )); require(mintID == requiredmintID, "mint: error validation mint ID"); _registerTransaction(mintID ,chainFrom , wrappedAddress, amount , receiver ,nounce, transactionType.mint); - } - - - - function validateTransaction(bytes32 transactionId , bytes[] memory signatures ,bool mintable) external { - require(IController(Ibridge(owner()).controller()).isValidator(msg.sender) , "U_A"); - require(Isettings(Ibridge(owner()).settings()).minValidations() != 0 , "minvalidator_err"); - Transaction memory transaction; - if (mintable) { - require(isMintTransaction[transactionId] , "mintID_err"); - transaction = mintTransactions[transactionId]; - if(!Ibridge(owner()).isDirectSwap(transaction.assetAddress , transaction.chainId)){ - (,uint256 max) = Ibridge(owner()).assetLimits(transaction.assetAddress, false); - require(transaction.amount <= max , "Amount_limit_Err"); - } + } + + + + function validateTransaction(bytes32 transactionId , bytes[] memory signatures ,bool mintable) external { + require(IController(Ibridge(owner()).controller()).isValidator(msg.sender) , "U_A"); + require(Isettings(Ibridge(owner()).settings()).minValidations() != 0 , "minvalidator_err"); + uint interfacingChainId; + address assetAddress; + uint amount; + address receiver; + uint nounce; + Transaction memory transaction; + if (mintable) { + require(isMintTransaction[transactionId] , "mintID_err"); + transaction = mintTransactions[transactionId]; + interfacingChainId = transaction.chainId; + assetAddress = transaction.assetAddress; + amount = transaction.amount; + receiver = transaction.receiver; + nounce = transaction.nounce; + if(!Ibridge(owner()).isDirectSwap(transaction.assetAddress , transaction.chainId)){ + (,uint256 max) = Ibridge(owner()).assetLimits(transaction.assetAddress, false); + require(transaction.amount <= max , "Amount_limit_Err"); + } } else { require(isClaimTransaction[transactionId] , "caimID_err"); transaction = claimTransactions[transactionId]; + interfacingChainId = transaction.chainId; + assetAddress = transaction.assetAddress; + amount = transaction.amount; + receiver = transaction.receiver; + nounce = transaction.nounce; (,uint256 max) = Ibridge(owner()).assetLimits(transaction.assetAddress , true); require(transaction.amount <= max && transaction.amount <= assetChainBalance[transaction.assetAddress][transaction.chainId] , "Amount_limit_Err"); } - require(!transaction.isCompleted, "completed"); - uint256 validSignatures; - + require(!transaction.isCompleted, "completed"); + uint256 validSignatures; + + // this part of the code was remove to access if you can recreate it to verify the signatures for a transaction // the message that was signed by the validators is a hash of derived as shown bellow - // keccak256(abi.encodePacked( - // "\x19Ethereum Signed Message:\n32", - // keccak256(abi.encodePacked( - // chainID, // this is goten from Ibridge(owner()).chainId() - // interfacingChainId, - // assetAddress, - // amount, - // receiver, - // nounce - // )))) + bytes32 messageHash = keccak256(abi.encodePacked( + "\x19Ethereum Signed Message:\n32", + keccak256(abi.encodePacked( + Ibridge(owner()).chainId(), // this is goten from Ibridge(owner()).chainId() + interfacingChainId, + assetAddress, + amount, + receiver, + nounce + )))); + + for(uint i = 0; i < signatures.length; i++){ + address signer = messageHash.recover(signatures[i]); // returns the address of the signature + // checks if the address is a valid validator; + if(IController(Ibridge(owner()).controller()).isValidator(signer)){ + validSignatures++; + } + } // to all you need to do here is verify each of this signatures to accertain if the are from a valid signer // - require(validSignatures >= Isettings(Ibridge(owner()).settings()).minValidations() ,"insuficient_signers"); - transactionValidations[transactionId].validationCount = validSignatures; - transactionValidations[transactionId].validated = true; + require(validSignatures >= Isettings(Ibridge(owner()).settings()).minValidations() ,"insuficient_signers"); + transactionValidations[transactionId].validationCount = validSignatures; + transactionValidations[transactionId].validated = true; emit TransactionValidated(transactionId); - if (mintable) { - Ibridge(owner()).mint(transactionId); - } else { - Ibridge(owner()).claim(transactionId); - } - - } - - - + if (mintable) { + Ibridge(owner()).mint(transactionId); + } else { + Ibridge(owner()).claim(transactionId); + } + } function transactionValidated(bytes32 transactionID) external view returns (bool) { - return transactionValidations[transactionID].validated; - } + return transactionValidations[transactionID].validated; + } } - - diff --git a/contracts/Settings.sol b/contracts/Settings.sol index 1b73b09..2a27e5c 100644 --- a/contracts/Settings.sol +++ b/contracts/Settings.sol @@ -7,9 +7,10 @@ import "./interface/Icontroller.sol"; contract Settings { IController public controller; - mapping(uint256 => uint256) public networkFee; address payable public feeRemitance; + uint256 public networkFee = 200; //20% + uint256 internal constant PCT_100 = 10**4;//100% uint256 public railRegistrationFee = 5000 * 10**18; uint256 public railOwnerFeeShare = 20; uint256 public minWithdrawableFee = 1 * 10**17; @@ -32,7 +33,7 @@ contract Settings { event FeeRemitanceAddressUpdated(address indexed prevValue, address indexed newValue); event RailRegistrationFeeUpdated(uint256 prevValue, uint256 newValue); event RailOwnerFeeShareUpdated(uint256 prevValue, uint256 newValue); - event NetworkFeeUpdated(uint256 chainId, uint256 prevValue, uint256 newValue); + event NetworkFeeUpdated(uint256 prevValue, uint256 newValue); event BaseFeePercentageUpdated(uint256 prevValue, uint256 newValue); event NetworkSupportedChainsUpdated(uint256[] chains , bool isadded); event UpdatableAssetStateChanged(bool status); @@ -79,7 +80,6 @@ contract Settings { function setNetworkSupportedChains( uint256[] memory chains, - uint256[] memory fees, bool addchain ) external @@ -89,14 +89,13 @@ contract Settings { assembly { id := chainid() } - if (addchain) { - require(chains.length == fees.length , "invalid"); + if (addchain) { for (uint256 index ; index < chains.length ; index++) { - require( fees[index] < maxFeeThreshold, "fee threshold Error"); + // require( fees[index] < maxFeeThreshold, "fee threshold Error"); if (!isNetworkSupportedChain[chains[index]] && chains[index] != id) { networkSupportedChains.push(chains[index]); isNetworkSupportedChain[chains[index]] = true; - networkFee[chains[index]] = fees[index]; + //networkFee[chains[index]] = fees[index]; } } } else { @@ -108,7 +107,7 @@ contract Settings { networkSupportedChains.pop(); } } - networkFee[chains[index]] = 0; + // networkFee[chains[index]] = 0; isNetworkSupportedChain[chains[index]] = false; } } @@ -118,21 +117,28 @@ contract Settings { } - function updateNetworkFee(uint256 chainId , uint256 fee) external { - onlyAdmin(); - require(fee > 0 && fee < maxFeeThreshold, "fee threshold Error"); - require(fee != networkFee[chainId] , "sameVal"); - require(isNetworkSupportedChain[chainId] , "not Supported"); - emit NetworkFeeUpdated( chainId, networkFee[chainId], fee); - networkFee[chainId] = fee; - } +// function updateNetworkFee(uint256 chainId , uint256 fee) external { +// onlyAdmin(); +// require(fee > 0 && fee < maxFeeThreshold, "fee threshold Error"); +// require(fee != networkFee[chainId] , "sameVal"); +// require(isNetworkSupportedChain[chainId] , "not Supported"); +// emit NetworkFeeUpdated( chainId, networkFee[chainId], fee); +// networkFee[chainId] = fee; +// } + function updateNetworkFeePercentage(uint256 fee) external{ + onlyAdmin(); + require(fee > 0 && fee < PCT_100, "fee threshold error"); + require(fee != networkFee, "sameVal"); + emit NetworkFeeUpdated( networkFee, fee); + networkFee = fee; + } function setRailOwnerFeeShare(uint256 share) external { onlyAdmin(); require(railOwnerFeeShare != share , "sameVal"); require(share > 1 && share < 100 , "err"); - RailOwnerFeeShareUpdated(railOwnerFeeShare , share); + emit RailOwnerFeeShareUpdated(railOwnerFeeShare , share); railOwnerFeeShare = share; } diff --git a/contracts/errorMsgs.txt b/contracts/errorMsgs.txt index 8114298..4eb71fe 100644 --- a/contracts/errorMsgs.txt +++ b/contracts/errorMsgs.txt @@ -14,4 +14,12 @@ mint ID error : MI_E minted : M not validated : N_V claim ID error : CI_E -Claimed : C \ No newline at end of file +Claimed : C + +forge create --rpc-url https://data-seed-prebsc-2-s1.binance.org:8545 \ --private-key 16b96df69fa51182a271095c0c4535e3910006e338ae6ce6bf59f2b7ee3ad582 \ src/Controller.sol:Controller \ --verify + +controller -- 0x19aa8266458CB5C3B8D27Ca756E736dBf516e693 +settings -- 0xFDDEe77a622AF0DF922250F55c0d6bBC20C492E4 +registry -- 0x9b22d1bFF8f6956817EC3538de0142a54cF44a8c +FeeController -- 0xB756aC42e33474eA8FbBB94e6E7eF3b13622519A +Bridgepool -- 0xDFf9C522E3ce74EB6C5D79E5a6618cED3bF17935