-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,283 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,3 +1,6 @@ | ||
[submodule "lib/forge-std"] | ||
path = lib/forge-std | ||
url = https://github.com/foundry-rs/forge-std | ||
[submodule "lib/openzeppelin-contracts-upgradeable"] | ||
path = lib/openzeppelin-contracts-upgradeable | ||
url = https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable |
This file contains 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,3 +1,21 @@ | ||
# BGD Labs Solidity utils | ||
|
||
Common contracts we use almost everywhere | ||
|
||
|
||
## Create3 | ||
Contracts to deploy a Create3 Factory which so that contract addresses can be predicted without influence from | ||
constructor arguments. | ||
|
||
These contracts where modified from: | ||
- Create3 lib: | ||
Modified from https://github.com/0xsequence/create3/blob/5a4a152e6be4e0ecfbbbe546992a5aaa43a4c1b0/contracts/Create3.sol by Agustin Aguilar <[email protected]> | ||
- Modifications consist on: | ||
- removal of named returns | ||
- moved logic of addressOf method to addressOfWithPreDeployedFactory so that factory address can be abstracted | ||
- Create3Factory: | ||
Modified from https://github.com/lifinance/create3-factory/blob/main/src/CREATE3Factory.sol | ||
- Modifications consist on: | ||
- removal of named returns | ||
- changed name of getDeployed for predictAddress | ||
- usage of create3 lib by Agustin Aguilar instead of solmate |
This file contains 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
Submodule openzeppelin-contracts-upgradeable
added at
723f8c
83 changes: 83 additions & 0 deletions
83
src/contracts/access-control/UpgradableOwnableWithGuardian.sol
This file contains 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,83 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.20; | ||
|
||
import {OwnableUpgradeable} from 'openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol'; | ||
import {IWithGuardian} from './interfaces/IWithGuardian.sol'; | ||
|
||
/** | ||
* Forked version of https://github.com/bgd-labs/solidity-utils/blob/main/src/contracts/access-control/OwnableWithGuardian.sol | ||
* Relying on UpgradableOwnable & moving the storage to 7201 | ||
*/ | ||
abstract contract UpgradableOwnableWithGuardian is OwnableUpgradeable, IWithGuardian { | ||
/// @custom:storage-location erc7201:aave.storage.OwnableWithGuardian | ||
struct OwnableWithGuardian { | ||
address _guardian; | ||
} | ||
|
||
// keccak256(abi.encode(uint256(keccak256("aave.storage.OwnableWithGuardian")) - 1)) & ~bytes32(uint256(0xff)) | ||
bytes32 private constant OwnableWithGuardianStorageLocation = | ||
0xdc8016945fab92f4608d8f23802ef36d865b35bd839402e24dec05cd76049e00; | ||
|
||
function _getOwnableWithGuardianStorage() private pure returns (OwnableWithGuardian storage $) { | ||
assembly { | ||
$.slot := OwnableWithGuardianStorageLocation | ||
} | ||
} | ||
|
||
/** | ||
* @dev The caller account is not authorized to perform an operation. | ||
*/ | ||
error OnlyGuardianInvalidCaller(address account); | ||
|
||
/** | ||
* @dev The caller account is not authorized to perform an operation. | ||
*/ | ||
error OnlyGuardianOrOwnerInvalidCaller(address account); | ||
|
||
/** | ||
* @dev Initializes the contract setting the address provided by the deployer as the initial owner. | ||
*/ | ||
function __Ownable_With_Guardian_init(address initialGuardian) internal onlyInitializing { | ||
_updateGuardian(initialGuardian); | ||
} | ||
|
||
modifier onlyGuardian() { | ||
_checkGuardian(); | ||
_; | ||
} | ||
|
||
modifier onlyOwnerOrGuardian() { | ||
_checkOwnerOrGuardian(); | ||
_; | ||
} | ||
|
||
function guardian() public view override returns (address) { | ||
OwnableWithGuardian storage $ = _getOwnableWithGuardianStorage(); | ||
return $._guardian; | ||
} | ||
|
||
/// @inheritdoc IWithGuardian | ||
function updateGuardian(address newGuardian) external override onlyOwnerOrGuardian { | ||
_updateGuardian(newGuardian); | ||
} | ||
|
||
/** | ||
* @dev method to update the guardian | ||
* @param newGuardian the new guardian address | ||
*/ | ||
function _updateGuardian(address newGuardian) internal { | ||
OwnableWithGuardian storage $ = _getOwnableWithGuardianStorage(); | ||
address oldGuardian = $._guardian; | ||
$._guardian = newGuardian; | ||
emit GuardianUpdated(oldGuardian, newGuardian); | ||
} | ||
|
||
function _checkGuardian() internal view { | ||
if (guardian() != _msgSender()) revert OnlyGuardianInvalidCaller(_msgSender()); | ||
} | ||
|
||
function _checkOwnerOrGuardian() internal view { | ||
if (_msgSender() != owner() && _msgSender() != guardian()) | ||
revert OnlyGuardianOrOwnerInvalidCaller(_msgSender()); | ||
} | ||
} |
This file contains 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 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,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.8; | ||
|
||
import {IRescuable721, IERC721} from './interfaces/IRescuable721.sol'; | ||
import {Rescuable} from './Rescuable.sol'; | ||
|
||
/** | ||
* @title Rescuable721 | ||
* @author defijesus.eth | ||
* @notice abstract contract that extend Rescuable with the methods to rescue ERC721 tokens from a contract | ||
*/ | ||
abstract contract Rescuable721 is Rescuable, IRescuable721 { | ||
|
||
/// @inheritdoc IRescuable721 | ||
function emergency721TokenTransfer( | ||
address erc721Token, | ||
address to, | ||
uint256 tokenId | ||
) external virtual onlyRescueGuardian { | ||
IERC721(erc721Token).transferFrom(address(this), to, tokenId); | ||
|
||
emit ERC721Rescued(msg.sender, erc721Token, to, tokenId); | ||
} | ||
} |
This file contains 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,35 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.8; | ||
|
||
/** | ||
* @title IRescuable721 | ||
* @author defijesus.eth | ||
* @notice interface containing the objects, events and methods definitions of the Rescuable721 contract | ||
*/ | ||
interface IRescuable721 { | ||
/** | ||
* @notice emitted when erc721 tokens get rescued | ||
* @param caller address that triggers the rescue | ||
* @param token address of the rescued token | ||
* @param to address that will receive the rescued tokens | ||
* @param tokenId the id of the token rescued | ||
*/ | ||
event ERC721Rescued( | ||
address indexed caller, | ||
address indexed token, | ||
address indexed to, | ||
uint256 tokenId | ||
); | ||
|
||
/** | ||
* @notice method called to rescue a ERC721 token sent erroneously to the contract. Only callable by owner | ||
* @param erc721Token address of the token to rescue | ||
* @param to address to send the token | ||
* @param tokenId of token to rescue | ||
*/ | ||
function emergency721TokenTransfer(address erc721Token, address to, uint256 tokenId) external; | ||
} | ||
|
||
interface IERC721 { | ||
function transferFrom(address from, address to, uint256 tokenId) external; | ||
} |
Oops, something went wrong.