Skip to content
8 changes: 6 additions & 2 deletions contracts/Bridge.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ contract Bridge is IBridge, Pausable, AccessControl, SafeMath {
uint128 private feeMaxValue; /// @notice e.g. 10000 = 100% => 1(feePercent) = 0.01%
uint64 private feePercent;

address private initialSetter;
IDAO private contractDAO;

enum ProposalStatus {Inactive, Active, Passed, Executed, Cancelled}
Expand Down Expand Up @@ -119,6 +120,7 @@ contract Bridge is IBridge, Pausable, AccessControl, SafeMath {
function setDAOContractInitial(address _address) external {
require(address(contractDAO) == address(0), "already set");
require(_address != address(0), "zero address");
require(initialSetter == _msgSender(), "not initialSetter");
contractDAO = IDAO(_address);
}

Expand Down Expand Up @@ -160,6 +162,8 @@ contract Bridge is IBridge, Pausable, AccessControl, SafeMath {
feeMaxValue= _feeMaxValue.toUint128();
feePercent = _feePercent.toUint64();

initialSetter = _msgSender();

_setupRole(DEFAULT_ADMIN_ROLE, _msgSender());

for (uint256 i; i < initialRelayers.length; i++) {
Expand Down Expand Up @@ -390,8 +394,8 @@ contract Bridge is IBridge, Pausable, AccessControl, SafeMath {
(address tokenAddress, uint8 chainId, uint256 basicFee, uint256 minAmount, uint256 maxAmount) = contractDAO.isChangeFeeAvailable(id);

require((_fees[tokenAddress][chainId].basicFee != basicFee || _fees[tokenAddress][chainId].basicFee == 0)
&& _fees[tokenAddress][chainId].minAmount != minAmount
&& _fees[tokenAddress][chainId].maxAmount != maxAmount, "Current fee = new fee");
|| _fees[tokenAddress][chainId].minAmount != minAmount
|| _fees[tokenAddress][chainId].maxAmount != maxAmount, "Current fee = new fee");

_fees[tokenAddress][chainId].basicFee = basicFee;
_fees[tokenAddress][chainId].minAmount = minAmount;
Expand Down
229 changes: 188 additions & 41 deletions contracts/DAO.sol
Original file line number Diff line number Diff line change
Expand Up @@ -90,99 +90,79 @@ contract DAO is Multisig, IDAO {
RequestStatus status;
}

// mapping of owner change requests
struct SetNativeTokensForGasRequest {
uint256 nativeTokensForGas;
RequestStatus status;
}

struct TransferNativeRequest {
address recepient;
uint256 amount;
RequestStatus status;
}

mapping(uint256 => OwnerChangeRequest) private ownerChangeRequests;
// mapping of owner change request confirmations
mapping(uint256 => mapping(address => bool)) private ownerChangesRequestConfirmations;
// id for new owner change request
uint256 private ownerChangeRequestCounter;

// mapping of transfer requests
mapping(uint256 => TransferRequest) private transferRequests;
// mapping of signs of transfer requests
mapping(uint256 => mapping(address => bool)) private transferRequestConfirmations;
// id for new transfer request
uint256 private transferRequestCounter;

// mapping of pause requests
mapping(uint256 => PauseStatusRequest) private pauseStatusRequests;
// mapping of pause request confirmations
mapping(uint256 => mapping(address => bool)) private pauseStatusRequestConfirmations;
// id for new pause request
uint256 private pauseStatusRequestCounter;

// mapping of change relayer threshold requests
mapping(uint256 => ChangeRelayerThresholdRequest) private changeRelayerThresholdRequests;
// mapping of change relayer threshold request confirmations
mapping(uint256 => mapping(address => bool)) private changeRelayerThresholdRequestConfirmations;
// id for new change relayer threshold request
uint256 private changeRelayerThresholdRequestCounter;

// mapping of set resource requests
mapping(uint256 => SetResourceRequest) private setResourceRequests;
// mapping of set resource request confirmations
mapping(uint256 => mapping(address => bool)) private setResourceRequestConfirmations;
// id for new set resource request
uint256 private setResourceRequestCounter;

// mapping of set generic resource requests
mapping(uint256 => SetGenericResourceRequest) private setGenericResourceRequests;
// mapping of set generic resource request confirmations
mapping(uint256 => mapping(address => bool)) private setGenericResourceRequestConfirmations;
// id for new set generic resource request
uint256 private setGenericResourceRequestCounter;

// mapping of set burnable requests
mapping(uint256 => SetBurnableRequest) private setBurnableRequests;
// mapping of set burnable request confirmations
mapping(uint256 => mapping(address => bool)) private setBurnableRequestConfirmations;
// id for new set burnable request
uint256 private setBurnableRequestCounter;

// mapping of set nonce requests
mapping(uint256 => SetNonceRequest) private setNonceRequests;
// mapping of set nonce request confirmations
mapping(uint256 => mapping(address => bool)) private setNonceRequestConfirmations;
// id for new set nonce request
uint256 private setNonceRequestCounter;

// mapping of set forwarder requests
mapping(uint256 => SetForwarderRequest) private setForwarderRequests;
// mapping of set forwarder request confirmations
mapping(uint256 => mapping(address => bool)) private setForwarderRequestConfirmations;
// id for new set forwarder request
uint256 private setForwarderRequestCounter;

// mapping of change fee requests
mapping(uint256 => ChangeFeeRequest) private changeFeeRequests;
// mapping of change fee confirmations
mapping(uint256 => mapping(address => bool)) private changeFeeRequestConfirmations;
// id for new change fee request
uint256 private changeFeeRequestCounter;

// mapping of change fee percent requests
mapping(uint256 => ChangeFeePercentRequest) private changeFeePercentRequests;
// mapping of change fee percent confirmations
mapping(uint256 => mapping(address => bool)) private changeFeePercentRequestConfirmations;
// id for new change fee percent request
uint256 private changeFeePercentRequestCounter;

// mapping of withdraw requests
mapping(uint256 => WithdrawRequest) private withdrawRequests;
// mapping of withdraw confirmations
mapping(uint256 => mapping(address => bool)) private withdrawRequestConfirmations;
// id for new withdraw request
uint256 private withdrawRequestCounter;

// mapping of set treasury requests
mapping(uint256 => SetTreasuryRequest) private setTreasuryRequests;
// mapping of set treasury confirmations
mapping(uint256 => mapping(address => bool)) private setTreasuryRequestConfirmations;
// id for new set treasury request
uint256 private setTreasuryRequestCounter;

address private immutable bridgeAddress;
address private immutable erc20HandlerAddress;
mapping(uint256 => SetNativeTokensForGasRequest) private setNativeTokensForGasRequests;
mapping(uint256 => mapping(address => bool)) private setNativeTokensForGasRequestConfirmations;
uint256 private setNativeTokensForGasRequestCounter;

mapping(uint256 => TransferNativeRequest) private transferNativeRequests;
mapping(uint256 => mapping(address => bool)) private transferNativeRequestConfirmations;
uint256 private transferNativeRequestCounter;

address private bridgeAddress;
address private erc20HandlerAddress;

/**
* @notice Throws error if any contract except bridge trys to call the function
Expand Down Expand Up @@ -305,6 +285,22 @@ contract DAO is Multisig, IDAO {
return setTreasuryRequestCounter;
}

/**
* @notice Gets set native tokens for gas request count
* @return Returns set native tokens for gas request count
*/
function getSetNativeTokensForGasRequestCount() external view returns(uint256) {
return setNativeTokensForGasRequestCounter;
}

/**
* @notice Gets transfer native request count
* @return Returns set transfer native request count
*/
function getTransferNativeRequestCount() external view returns(uint256) {
return transferNativeRequestCounter;
}

/**
* @notice Allows changing owner request if it is not approved and there are enough votes
* @param id the id of change owner request
Expand Down Expand Up @@ -1386,4 +1382,155 @@ contract DAO is Multisig, IDAO {
emit NewVoteForRequest(RequestType.SetTreasury, true, msg.sender, setTreasuryRequestCounter);
return setTreasuryRequestCounter;
}

/**
* @notice Allows setting native token for gas request if it is not approved and there are enough votes
* @param id the id of set native token for gas request
*/
function isSetNativeTokensForGasAvailable(uint256 id)
external
view
override
returns (uint256)
{
require(setNativeTokensForGasRequests[id].status == RequestStatus.Active, "not active");
_consensus(setNativeTokensForGasRequestConfirmations, id);
return setNativeTokensForGasRequests[id].nativeTokensForGas;
}

/**
* @notice Counts and gets affirmative votes for set native token for gas request
* @param id request id to be executed
*/
function countGetSetNativeTokensForGasAffirmativeVotes(uint256 id) external view returns(uint256) {
return _countGet(setNativeTokensForGasRequestConfirmations, id);
}

/**
* @notice Cancels set native token for gas request if it is active
* @param id the id of set native token for gas request
*/
function cancelSetNativeTokensForGasRequest(uint256 id) external onlyVoter(msg.sender) {
require(setNativeTokensForGasRequests[id].status == RequestStatus.Active, "not active");
setNativeTokensForGasRequests[id].status = RequestStatus.Canceled;
}

/**
* @notice Approves set native token for gas request if it is not approved
* @param id the id of set native token for gas request
*/
function confirmSetNativeTokensForGasRequest(uint256 id)
external
override
returns (bool)
{
require(msg.sender == erc20HandlerAddress, "not ERC20handler address");
require(setNativeTokensForGasRequests[id].status == RequestStatus.Active, "not active");
setNativeTokensForGasRequests[id].status = RequestStatus.Executed;
return true;
}

/**
* @notice Allows a voter to insert a confirmation for set native token for gas request if it is not approved
* @param voteType the vote type: true/false = insert/remove vote
* @param id the id of set native token for gas request
*/
function newVoteForSetNativeTokensForGasRequest(bool voteType, uint256 id) external {
require(setNativeTokensForGasRequests[id].status == RequestStatus.Active, "not active");
_newVoteFor(setNativeTokensForGasRequestConfirmations, id, voteType, RequestType.SetNativeTokensForGas);
}

/**
* @notice Creation of set native token for gas request by any voter
* @param nativeTokensForGas new native token for gas value
*/
function newSetNativeTokensForGasRequest(uint256 nativeTokensForGas)
external
onlyVoter(msg.sender)
returns (uint256)
{
setNativeTokensForGasRequestCounter = setNativeTokensForGasRequestCounter + 1;
setNativeTokensForGasRequests[setNativeTokensForGasRequestCounter] = SetNativeTokensForGasRequest ({
nativeTokensForGas: nativeTokensForGas,
status: RequestStatus.Active
});

setNativeTokensForGasRequestConfirmations[setNativeTokensForGasRequestCounter][msg.sender] = true;
emit NewVoteForRequest(RequestType.SetNativeTokensForGas, true, msg.sender, setNativeTokensForGasRequestCounter);

return setNativeTokensForGasRequestCounter;
}

/**
* @notice Allows transferring tokens request if it is not approved and there are enough votes
* @param id the id of transferring tokens request
*/
function isTransferNativeAvailable(uint256 id)
external
view
override
returns (address, uint256)
{
require(transferNativeRequests[id].status == RequestStatus.Active, "not active");
_consensus(transferNativeRequestConfirmations, id);
return (transferNativeRequests[id].recepient, transferNativeRequests[id].amount);
}

/**
* @notice Approves transferring native request if it is not approved
* @param id the id of transfer native request
*/
function confirmTransferNativeRequest(uint256 id) external override returns (bool) {
require(msg.sender == erc20HandlerAddress, "not ERC20handler address");
require(transferNativeRequests[id].status == RequestStatus.Active, "not active");
transferNativeRequests[id].status = RequestStatus.Executed;
return true;
}

/**
* @notice Counts and gets affirmative votes for transfer native request
* @param id request id to be executed
*/
function countGetTransferNativeAffirmativeVotes(uint id) external view returns(uint) {
return _countGet(transferNativeRequestConfirmations, id);
}

/**
* @notice Cancels transfer native request if it is active
* @param id the id of transfer native request
*/
function cancelTransferNativeRequest(uint id) external onlyVoter(msg.sender) {
require(transferNativeRequests[id].status == RequestStatus.Active, "not active");
transferNativeRequests[id].status = RequestStatus.Canceled;
}

/**
* @notice Allows a voter to insert a confirmation for transfer native request
* if it is not approved and not confirmed
* @param voteType the vote type: true/false = insert/remove vote
* @param id the id of transfer native request
*/
function newVoteForTransferNativeRequest(bool voteType, uint256 id) external {
require(transferNativeRequests[id].status == RequestStatus.Active, "not active");
_newVoteFor(transferNativeRequestConfirmations, id, voteType, RequestType.TransferNative);
}

function newTransferNativeRequest(address _recepient, uint256 _amount)
external
onlyVoter(msg.sender)
returns (uint256)
{
require(_recepient!= address(0), "zero address");
transferNativeRequestCounter = transferNativeRequestCounter + 1;

transferNativeRequests[transferNativeRequestCounter] = TransferNativeRequest({
recepient: _recepient,
amount: _amount,
status: RequestStatus.Active
});

transferNativeRequestConfirmations[transferNativeRequestCounter][msg.sender] = true;
emit NewVoteForRequest(RequestType.TransferNative, true, msg.sender, transferNativeRequestCounter);
return transferNativeRequestCounter;
}
}
2 changes: 1 addition & 1 deletion contracts/ERC20Safe.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
@notice This contract is intended to be used with ERC20Handler contract.
*/
contract ERC20Safe {
uint256 private constant nativeTokensForGas = 0.001 ether;
uint256 public nativeTokensForGas = 0.01 ether;
using SafeMath for uint256;

/**
Expand Down
Loading