-
Notifications
You must be signed in to change notification settings - Fork 9
Feature/GBI-2806 - Discovery & Collateral Management #340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d6be531
feat: add discovery split poc
Luisfc68 a97575a
fix: slither warnings
Luisfc68 8ab0054
docs: update gas reports
Luisfc68 33d5696
refactor: optimize getProviders
Luisfc68 b549945
fix: copilot feedback
Luisfc68 5622175
Merge branch 'QA-Test' into feature/GBI-2806
Luisfc68 f994fcf
Merge branch 'QA-Test' into feature/GBI-2806
Luisfc68 e3f1122
fix: linting issue
Luisfc68 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) {} | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 {} | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
|
||
|
|
||
| function withdrawCollateral() external nonReentrant { | ||
| address providerAddress = msg.sender; | ||
Check noticeCode 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 warningCode 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; | ||
| } | ||
| } | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
github-advanced-security[bot] marked this conversation as resolved.
Dismissed
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); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.