Skip to content

Commit

Permalink
feat(contracts): add new forwarder contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
gianchandania committed Oct 4, 2023
1 parent dce15a5 commit 74b1e7a
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 188 deletions.
6 changes: 3 additions & 3 deletions contracts/Forwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ contract Forwarder is IERC721Receiver, ERC1155Receiver, IForwarder {
/**
* Modifier that will execute internal code block only if the sender is the parent address
*/
modifier onlyParent {
modifier onlyParent() {
require(msg.sender == parentAddress, 'Only Parent');
_;
}

/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
modifier onlyUninitialized() {
require(parentAddress == address(0x0), 'Already initialized');
_;
}
Expand Down Expand Up @@ -313,9 +313,9 @@ contract Forwarder is IERC721Receiver, ERC1155Receiver, IForwarder {
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155Receiver, IERC165)
view
returns (bool)
{
return
Expand Down
21 changes: 12 additions & 9 deletions contracts/UpdatedForwarder.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ contract UpdatedForwarder is IERC721Receiver, ERC1155Receiver, IForwarder {
/**
* Initialize the contract, and sets the destination address to that of the parent address
*/
function init (
function init(
address _parentAddress,
address _feeAddress,
bool _autoFlush721,
bool _autoFlush1155
) external onlyUninitialized {
require(_parentAddress != address(0x0), "Invalid address");
require(_parentAddress != address(0x0), 'Invalid address');
parentAddress = _parentAddress;
require(_feeAddress != address(0x0), "Invalid address");
require(_feeAddress != address(0x0), 'Invalid address');
feeAddress = _feeAddress;

uint256 value = address(this).balance;

// set whether we want to automatically flush erc721/erc1155 tokens or not
Expand All @@ -58,15 +58,18 @@ contract UpdatedForwarder is IERC721Receiver, ERC1155Receiver, IForwarder {
/**
* Modifier that will execute internal code block only if the sender is from the allowed addresses
*/
modifier onlyAllowedAddress {
require(msg.sender == parentAddress || msg.sender == feeAddress, 'Address is not allowed');
modifier onlyAllowedAddress() {
require(
msg.sender == parentAddress || msg.sender == feeAddress,
'Address is not allowed'
);
_;
}

/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
modifier onlyUninitialized() {
require(parentAddress == address(0x0), 'Already initialized');
_;
}
Expand Down Expand Up @@ -319,13 +322,13 @@ contract UpdatedForwarder is IERC721Receiver, ERC1155Receiver, IForwarder {
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(ERC1155Receiver, IERC165)
view
returns (bool)
{
return
interfaceId == type(IForwarder).interfaceId ||
super.supportsInterface(interfaceId);
}
}
}
6 changes: 5 additions & 1 deletion contracts/UpdatedForwarderFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ contract UpdatedForwarderFactory is CloneFactory {
implementationAddress = _implementationAddress;
}

function createForwarder(address parent, address feeAddress, bytes32 salt) external {
function createForwarder(
address parent,
address feeAddress,
bytes32 salt
) external {
this.createForwarder(parent, feeAddress, salt, true, true);
}

Expand Down
15 changes: 7 additions & 8 deletions contracts/WalletSimple.sol
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver {
* to allow this contract to be used by proxy with delegatecall, which will
* not pick up on state variables
*/
function getNetworkId() internal virtual pure returns (string memory) {
function getNetworkId() internal pure virtual returns (string memory) {
return 'ETHER';
}

Expand All @@ -105,7 +105,7 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver {
* to allow this contract to be used by proxy with delegatecall, which will
* not pick up on state variables
*/
function getTokenNetworkId() internal virtual pure returns (string memory) {
function getTokenNetworkId() internal pure virtual returns (string memory) {
return 'ERC20';
}

Expand All @@ -117,7 +117,7 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver {
* to allow this contract to be used by proxy with delegatecall, which will
* not pick up on state variables
*/
function getBatchNetworkId() internal virtual pure returns (string memory) {
function getBatchNetworkId() internal pure virtual returns (string memory) {
return 'ETHER-Batch';
}

Expand All @@ -133,15 +133,15 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver {
/**
* Modifier that will execute internal code block only if the sender is an authorized signer on this wallet
*/
modifier onlySigner {
modifier onlySigner() {
require(isSigner(msg.sender), 'Non-signer in onlySigner method');
_;
}

/**
* Modifier that will execute internal code block only if the contract has not been initialized yet
*/
modifier onlyUninitialized {
modifier onlyUninitialized() {
require(!initialized, 'Contract already initialized');
_;
}
Expand Down Expand Up @@ -557,9 +557,8 @@ contract WalletSimple is IERC721Receiver, ERC1155Receiver {
uint256 lowestValueIndex = 0;
// fetch recentSequenceIds into memory for function context to avoid unnecessary sloads


uint256[SEQUENCE_ID_WINDOW_SIZE] memory _recentSequenceIds
= recentSequenceIds;
uint256[SEQUENCE_ID_WINDOW_SIZE]
memory _recentSequenceIds = recentSequenceIds;
for (uint256 i = 0; i < SEQUENCE_ID_WINDOW_SIZE; i++) {
require(_recentSequenceIds[i] != sequenceId, 'Sequence ID already used');

Expand Down
Loading

0 comments on commit 74b1e7a

Please sign in to comment.