Skip to content

Commit

Permalink
fix: solved conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Jul 24, 2024
2 parents 1a88231 + 17a826c commit fab7fe6
Show file tree
Hide file tree
Showing 11 changed files with 1,283 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
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
18 changes: 18 additions & 0 deletions README.md
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
40 changes: 38 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ out = 'out'
libs = ['lib']
solc = '0.8.19'

remappings = [
]
remappings = []


[profile.default.zksync]
Expand All @@ -19,6 +18,7 @@ zksolc="1.4.1"

# See more config options https://github.com/gakonst/foundry/tree/master/config
[rpc_endpoints]
<<<<<<< HEAD
ethereum="${RPC_MAINNET}"
ethereum-testnet="${RPC_MAINNET_TESTNET}"
polygon="${RPC_POLYGON}"
Expand Down Expand Up @@ -62,3 +62,39 @@ zksync-testnet={key="${ETHERSCAN_API_KEY_ZK_SYNC}", chain=300, url='https://api-
no_zksync_reserved_addresses = true
[invariant]
no_zksync_reserved_addresses = true
=======
ethereum = "${RPC_MAINNET}"
ethereum-testnet = "${RPC_MAINNET_TESTNET}"
polygon = "${RPC_POLYGON}"
polygon-testnet = "${RPC_POLYGON_TESTNET}"
arbitrum = "${RPC_ARBITRUM}"
arbitrum-testnet = "${RPC_ARBITRUM_TESTNET}"
metis = "${RPC_METIS}"
metis-testnet = "${RPC_METIS_TESTNET}"
avalanche = "${RPC_AVALANCHE}"
avalanche-testnet = "${RPC_AVALANCHE_TESTNET}"
optimism = "${RPC_OPTIMISM}"
optimism-testnet = "${RPC_OPTIMISM_TESTNET}"
fantom = "${RPC_FANTOM}"
fantom-testnet = "${RPC_FANTOM_TESTNET}"
binance = "${RPC_BINANCE}"
binance-testnet = "${RPC_BINANCE_TESTNET}"

[etherscan]
ethereum = { key = "${ETHERSCAN_API_KEY_MAINNET}", chain = 1 }
ethereum-testnet = { key = "${ETHERSCAN_API_KEY_MAINNET}", chain = 1 }
optimism = { key = "${ETHERSCAN_API_KEY_OPTIMISM}", chain = 10 }
optimism-testnet = { key = "${ETHERSCAN_API_KEY_OPTIMISM}", chain = 10 }
avalanche = { key = "${ETHERSCAN_API_KEY_AVALANCHE}", chain = 43114 }
avalanche-testnet = { key = "${ETHERSCAN_API_KEY_AVALANCHE}", chain = 43114 }
polygon = { key = "${ETHERSCAN_API_KEY_POLYGON}", chain = 137 }
polygon-testnet = { key = "${ETHERSCAN_API_KEY_POLYGON}", chain = 137 }
arbitrum = { key = "${ETHERSCAN_API_KEY_ARBITRUM}", chain = 42161 }
arbitrum-testnet = { key = "${ETHERSCAN_API_KEY_ARBITRUM}", chain = 42161 }
metis = { key = "any", chain = 1088, url = 'https://andromeda-explorer.metis.io/' }
metis-testnet = { key = "any", chain = 599, url = 'https://goerli.explorer.metisdevops.link/' }
fantom = { key = "${ETHERSCAN_API_KEY_FANTOM}", chain = 250 }
fantom-testnet = { key = "${ETHERSCAN_API_KEY_FANTOM}", chain = 250 }
binance = { key = "${ETHERSCAN_API_KEY_BINANCE}", chain = 56 }
binance-testnet = { key = "${ETHERSCAN_API_KEY_BINANCE}", chain = 56 }
>>>>>>> 17a826c5c7e691f8938043ea72b4040def416015
1 change: 1 addition & 0 deletions lib/openzeppelin-contracts-upgradeable
83 changes: 83 additions & 0 deletions src/contracts/access-control/UpgradableOwnableWithGuardian.sol
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());
}
}
1 change: 0 additions & 1 deletion src/contracts/create3/Create3Factory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
pragma solidity ^0.8.0;

import {Create3} from './Create3.sol';
import {Ownable} from '../oz-common/Ownable.sol';
import {ICreate3Factory} from './interfaces/ICreate3Factory.sol';

/**
Expand Down
24 changes: 24 additions & 0 deletions src/contracts/utils/Rescuable721.sol
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);
}
}
35 changes: 35 additions & 0 deletions src/contracts/utils/interfaces/IRescuable721.sol
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;
}
Loading

0 comments on commit fab7fe6

Please sign in to comment.