Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion .solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "solhint:recommended",
"rules": {
"avoid-throw": "off",
"compiler-version": ["error", "^0.8.18"],
"compiler-version": ["error", "0.8.25"],
"max-line-length": ["error", 120],
"max-states-count": ["error", 20],
"avoid-tx-origin": "off",
Expand Down
4 changes: 2 additions & 2 deletions contracts/Bridge.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

interface Bridge {

Expand Down Expand Up @@ -129,4 +129,4 @@ interface Bridge {
function getBtcBlockchainBlockHeaderByHeight(uint256 btcBlockHeight) external view returns (bytes memory);

function getBtcBlockchainParentBlockHeaderByHash(bytes32 btcBlockHash) external view returns (bytes memory);
}
}
2 changes: 1 addition & 1 deletion contracts/BridgeMock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

import "./Bridge.sol";

Expand Down
7 changes: 4 additions & 3 deletions contracts/LiquidityBridgeContract.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;
pragma experimental ABIEncoderV2;

import "./Bridge.sol";
import "./Quotes.sol";
import "./SignatureValidator.sol";
import "@rsksmart/btc-transaction-solidity-helper/contracts/BtcUtils.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";

/**
@title Contract that assists with the Flyover protocol
Expand Down Expand Up @@ -157,7 +157,8 @@ contract LiquidityBridgeContract is Initializable, OwnableUpgradeable, Reentranc
require(_rewardPercentage <= 100, "LBC004");
require(_minimumCollateral >= 0.03 ether, "LBC072");
require(_resignDelayBlocks >= 60, "LBC073");
__Ownable_init_unchained();
__Ownable_init_unchained(msg.sender);
__ReentrancyGuard_init_unchained();
bridge = Bridge(_bridgeAddress);
minCollateral = _minimumCollateral;
minPegIn = _minimumPegIn;
Expand Down
6 changes: 4 additions & 2 deletions contracts/LiquidityBridgeContractAdmin.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

import "@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol";

contract LiquidityBridgeContractAdmin is ProxyAdmin {}
contract LiquidityBridgeContractAdmin is ProxyAdmin {
constructor() ProxyAdmin(msg.sender) {}
}
4 changes: 2 additions & 2 deletions contracts/LiquidityBridgeContractProxy.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

import "@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol";

contract LiquidityBridgeContractProxy is TransparentUpgradeableProxy {
constructor(address _logic, address _admin, bytes memory _data)
TransparentUpgradeableProxy(_logic,_admin, _data) payable {}
}
}
31 changes: 8 additions & 23 deletions contracts/LiquidityBridgeContractV2.sol
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;
pragma experimental ABIEncoderV2;

import "./Bridge.sol";
import "./QuotesV2.sol";
import "./SignatureValidator.sol";
import "@rsksmart/btc-transaction-solidity-helper/contracts/BtcUtils.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";

/**
@title Contract that assists with the Flyover protocol
*/

contract LiquidityBridgeContractV2 is Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
contract LiquidityBridgeContractV2 is OwnableUpgradeable, ReentrancyGuardUpgradeable {
uint16 constant public MAX_CALL_GAS_COST = 35000;
uint16 constant public MAX_REFUND_GAS_LIMIT = 2300;

Expand Down Expand Up @@ -135,6 +135,11 @@ contract LiquidityBridgeContractV2 is Initializable, OwnableUpgradeable, Reentra
_;
}

function initializeV2() public initializer {
__Ownable_init_unchained(msg.sender);
__ReentrancyGuard_init_unchained();
}

function setProviderStatus(
uint _providerId,
bool status
Expand All @@ -150,22 +155,10 @@ contract LiquidityBridgeContractV2 is Initializable, OwnableUpgradeable, Reentra
return "1.3.0";
}

function getProviderIds() external view returns (uint) {
return providerId;
}

function getBridgeAddress() external view returns (address) {
return address(bridge);
}

function getMinCollateral() public view returns (uint) {
return minCollateral;
}

function getMinPegIn() external view returns (uint) {
return minPegIn;
}

function getRewardPercentage() external view returns (uint) {
return rewardP;
}
Expand All @@ -174,14 +167,6 @@ contract LiquidityBridgeContractV2 is Initializable, OwnableUpgradeable, Reentra
return resignDelayInBlocks;
}

function getDustThreshold() external view returns (uint) {
return dust;
}

function isPegOutQuoteCompleted(bytes32 quoteHash) external view returns (bool) {
return pegoutRegistry[quoteHash].completed;
}

/**
@dev Checks whether a liquidity provider can deliver a pegin service
@return Whether the liquidity provider is registered and has enough locked collateral
Expand Down
2 changes: 1 addition & 1 deletion contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

contract Migrations {
address public owner = msg.sender;
Expand Down
2 changes: 1 addition & 1 deletion contracts/Mock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

import "./LiquidityBridgeContract.sol";

Expand Down
4 changes: 2 additions & 2 deletions contracts/Quotes.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

library Quotes {
struct PeginQuote {
Expand Down Expand Up @@ -138,4 +138,4 @@ library Quotes {
);
}

}
}
4 changes: 2 additions & 2 deletions contracts/QuotesV2.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

library QuotesV2 {
struct PeginQuote {
Expand Down Expand Up @@ -149,4 +149,4 @@ library QuotesV2 {
);
}

}
}
4 changes: 2 additions & 2 deletions contracts/SignatureValidator.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

library SignatureValidator {
/**
Expand All @@ -13,7 +13,7 @@ library SignatureValidator {
bytes32 r;
bytes32 s;
uint8 v;

assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
Expand Down
2 changes: 1 addition & 1 deletion contracts/SignatureValidatorMock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

library SignatureValidatorMock {
function verify(address , bytes32 , bytes memory) public pure returns (bool) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/WalletMock.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.18;
pragma solidity 0.8.25;

contract WalletMock {

Expand Down
161 changes: 161 additions & 0 deletions contracts/split/CollateralManagement.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;

import "./interfaces.sol";
import "@openzeppelin/contracts-upgradeable/access/extensions/AccessControlDefaultAdminRulesUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/utils/ReentrancyGuardUpgradeable.sol";

contract CollateralManagementContract is
AccessControlDefaultAdminRulesUpgradeable,
ReentrancyGuardUpgradeable,
CollateralManagement
{
bytes32 public constant COLLATERAL_ADDER = keccak256("COLLATERAL_ADDER");
bytes32 public constant COLLATERAL_SLASHER = keccak256("COLLATERAL_SLASHER");

event WithdrawCollateral(address indexed addr, uint amount);
event Resigned(address indexed addr);

error AlreadyResigned(address from);
error NotResigned(address from);
error ResignationDelayNotMet(address from, uint resignationBlockNum, uint resignDelayInBlocks);
error WithdrawalFailed(address from, uint amount);

uint private _minCollateral;
uint private _resignDelayInBlocks;
mapping(address => uint) private _pegInCollateral;
mapping(address => uint) private _pegOutCollateral;
mapping(address => uint) private _resignationBlockNum;

modifier onlyRegisteredForPegIn() {
if (!_isRegistered(Flyover.ProviderType.PegIn, msg.sender))
revert Flyover.ProviderNotRegistered(msg.sender);
_;
}

modifier onlyRegisteredForPegOut() {
if (!_isRegistered(Flyover.ProviderType.PegOut, msg.sender))
revert Flyover.ProviderNotRegistered(msg.sender);
_;
}

function initialize(
address owner,
uint48 initialDelay,
uint minCollateral,
uint resignDelayInBlocks
) public initializer {
__AccessControlDefaultAdminRules_init(initialDelay, owner);
__ReentrancyGuard_init();
_minCollateral = minCollateral;
_resignDelayInBlocks = resignDelayInBlocks;
}

function setMinCollateral(uint minCollateral) external onlyRole(DEFAULT_ADMIN_ROLE) {
emit CollateralManagement.MinCollateralSet(_minCollateral, minCollateral);
_minCollateral = minCollateral;
}

function setResignDelayInBlocks(uint resignDelayInBlocks) external onlyRole(DEFAULT_ADMIN_ROLE) {
emit CollateralManagement.ResignDelayInBlocksSet(_resignDelayInBlocks, resignDelayInBlocks);
_resignDelayInBlocks = resignDelayInBlocks;
}

function getPegInCollateral(address addr) external view returns (uint) {
return _pegInCollateral[addr];
}

function getPegOutCollateral(address addr) external view returns (uint) {
return _pegOutCollateral[addr];
}

function getResignationBlock(address addr) external view returns (uint) {
return _resignationBlockNum[addr];
}

function addPegInCollateralTo(address addr) external onlyRole(COLLATERAL_ADDER) payable {
_addPegInCollateralTo(addr);
}

function addPegInCollateral() external onlyRegisteredForPegIn payable {
_addPegInCollateralTo(msg.sender);
}

function addPegOutCollateralTo(address addr) external onlyRole(COLLATERAL_ADDER) payable {
_addPegOutCollateralTo(addr);
}

function addPegOutCollateral() external onlyRegisteredForPegOut payable {
_addPegOutCollateralTo(msg.sender);
}

function getMinCollateral() external view returns (uint) {
return _minCollateral;
}

function isRegistered(Flyover.ProviderType providerType, address addr) external view returns (bool) {
return _isRegistered(providerType, addr);
}

function isCollateralSufficient(Flyover.ProviderType providerType, address addr) external view returns (bool) {
if (providerType == Flyover.ProviderType.PegIn) {
return _pegInCollateral[addr] >= _minCollateral && _resignationBlockNum[addr] == 0;
} else if (providerType == Flyover.ProviderType.PegOut) {
return _pegOutCollateral[addr] >= _minCollateral && _resignationBlockNum[addr] == 0;
} else {
return _pegInCollateral[addr] >= _minCollateral &&
_pegOutCollateral[addr] >= _minCollateral &&
_resignationBlockNum[addr] == 0;
}
}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Dismissed

function withdrawCollateral() external nonReentrant {
address providerAddress = msg.sender;

Check notice

Code scanning / Slither

Missing zero address validation Low

uint resignationBlock = _resignationBlockNum[providerAddress];
if (resignationBlock <= 0) revert NotResigned(providerAddress);
if (block.number - resignationBlock < _resignDelayInBlocks) {
revert ResignationDelayNotMet(providerAddress, resignationBlock, _resignDelayInBlocks);
}

uint amount = _pegOutCollateral[providerAddress] + _pegInCollateral[providerAddress];
_pegOutCollateral[providerAddress] = 0;
_pegInCollateral[providerAddress] = 0;
_resignationBlockNum[providerAddress] = 0;

emit WithdrawCollateral(providerAddress, amount);
(bool success,) = providerAddress.call{value: amount}("");
if (!success) revert WithdrawalFailed(providerAddress, amount);
}
Comment on lines +112 to +128

Check warning

Code scanning / Slither

Low-level calls Warning


function resign() external {
address providerAddress = msg.sender;
if (_resignationBlockNum[providerAddress] != 0) revert AlreadyResigned(providerAddress);
if (_pegInCollateral[providerAddress] <= 0 && _pegOutCollateral[providerAddress] <= 0) {
revert Flyover.ProviderNotRegistered(providerAddress);
}
_resignationBlockNum[providerAddress] = block.number;
emit Resigned(providerAddress);
}

function _isRegistered(Flyover.ProviderType providerType, address addr) private view returns (bool) {
if (providerType == Flyover.ProviderType.PegIn) {
return _pegInCollateral[addr] > 0 && _resignationBlockNum[addr] == 0;
} else if (providerType == Flyover.ProviderType.PegOut) {
return _pegOutCollateral[addr] > 0 && _resignationBlockNum[addr] == 0;
} else {
return _pegInCollateral[addr] > 0 && _pegOutCollateral[addr] > 0 && _resignationBlockNum[addr] == 0;
}
}
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
Comment thread
github-advanced-security[bot] marked this conversation as resolved.
Dismissed

function _addPegInCollateralTo(address addr) private {
uint amount = msg.value;
_pegInCollateral[addr] += amount;
emit CollateralManagement.PegInCollateralAdded(addr, amount);
}

function _addPegOutCollateralTo(address addr) private {
uint amount = msg.value;
_pegOutCollateral[addr] += amount;
emit CollateralManagement.PegOutCollateralAdded(addr, amount);
}
}
Loading
Loading