Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
333 changes: 168 additions & 165 deletions contracts/Bridge.sol

Large diffs are not rendered by default.

38 changes: 17 additions & 21 deletions contracts/BridgePool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import "./interface/IERC20deployer.sol";


contract BridgePool is Context , ReentrancyGuard {

struct pool{
address wrappedAsset;
uint256 deposited;
Expand Down Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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,
Expand All @@ -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())));
Expand All @@ -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);
Expand Down
118 changes: 59 additions & 59 deletions contracts/Controller.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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;
}
}
Loading