Skip to content

Commit

Permalink
Merge pull request #187 from ERC725Alliance/develop
Browse files Browse the repository at this point in the history
chore(release): 4.1.0
  • Loading branch information
frozeman authored Dec 9, 2022
2 parents 9d45532 + 5724e57 commit e2c1594
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 140 deletions.
196 changes: 130 additions & 66 deletions docs/ERC-725.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion implementations/.solhint.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"rules": {
"compiler-version": ["error", "^0.8.0"],
"func-visibility": ["error", { "ignoreConstructors": true }],
"reason-string": ["warn", { "maxLength": 120 }]
"reason-string": ["warn", { "maxLength": 120 }],
"no-empty-blocks": ["off"]
}
}
11 changes: 11 additions & 0 deletions implementations/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [4.1.0](https://github.com/ERC725Alliance/ERC725/compare/v4.0.0...v4.1.0) (2022-12-09)


### ⚠ BREAKING CHANGES

* add `salt` parameter to the `ContractCreated` event in ERC725X (#183)


* create internal virtual `_execute` function with core ERC725X logic to improve overriding core behaviour ([#184](https://github.com/ERC725Alliance/ERC725/pull/184))
* add `salt` parameter to the `ContractCreated` event in ERC725X ([#183](https://github.com/ERC725Alliance/ERC725/issues/183)) ([4a6ca14](https://github.com/ERC725Alliance/ERC725/commit/4a6ca140b35f1d78f6fefedb11ddc3981f71acb6))

## 4.0.0 (2022-10-31)

### ⚠ BREAKING CHANGES
Expand Down
110 changes: 60 additions & 50 deletions implementations/contracts/ERC725XCore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
uint256 value,
bytes memory data
) public payable virtual onlyOwner returns (bytes memory) {
if (address(this).balance < value) {
revert ERC725X_InsufficientBalance(address(this).balance, value);
}
return _execute(operationType, target, value, data);
}

Expand All @@ -57,37 +54,22 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
address[] memory targets,
uint256[] memory values,
bytes[] memory datas
) public payable virtual onlyOwner returns (bytes[] memory result) {
if (
operationsType.length != targets.length ||
(targets.length != values.length || values.length != datas.length)
) revert ERC725X_ExecuteParametersLengthMismatch();

result = new bytes[](operationsType.length);
for (uint256 i = 0; i < operationsType.length; i = _uncheckedIncrementERC725X(i)) {
if (address(this).balance < values[i])
revert ERC725X_InsufficientBalance(address(this).balance, values[i]);

result[i] = _execute(operationsType[i], targets[i], values[i], datas[i]);
}
) public payable virtual onlyOwner returns (bytes[] memory) {
return _execute(operationsType, targets, values, datas);
}

/**
* @inheritdoc ERC165
*/
function supportsInterface(bytes4 interfaceId)
public
view
virtual
override(IERC165, ERC165)
returns (bool)
{
function supportsInterface(
bytes4 interfaceId
) public view virtual override(IERC165, ERC165) returns (bool) {
return interfaceId == _INTERFACEID_ERC725X || super.supportsInterface(interfaceId);
}

/**
* @dev check the `operationType` provided and perform the associated low-level opcode.
* see `IERC725X.execute(...)`.
* see `IERC725X.execute(uint256,address,uint256,bytes)`.
*/
function _execute(
uint256 operationType,
Expand Down Expand Up @@ -138,6 +120,30 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
revert ERC725X_UnknownOperationType(operationType);
}

/**
* @dev same as `_execute` but for batch execution
* see `IERC725X,execute(uint256[],address[],uint256[],bytes[])`
*/
function _execute(
uint256[] memory operationsType,
address[] memory targets,
uint256[] memory values,
bytes[] memory datas
) internal virtual returns (bytes[] memory) {
if (
operationsType.length != targets.length ||
(targets.length != values.length || values.length != datas.length)
) revert ERC725X_ExecuteParametersLengthMismatch();

bytes[] memory result = new bytes[](operationsType.length);

for (uint256 i = 0; i < operationsType.length; i = _uncheckedIncrementERC725X(i)) {
result[i] = _execute(operationsType[i], targets[i], values[i], datas[i]);
}

return result;
}

/**
* @dev perform low-level call (operation type = 0)
* @param target The address on which call is executed
Expand All @@ -150,9 +156,13 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
uint256 value,
bytes memory data
) internal virtual returns (bytes memory result) {
if (address(this).balance < value) {
revert ERC725X_InsufficientBalance(address(this).balance, value);
}

emit Executed(OPERATION_0_CALL, target, value, bytes4(data));

// solhint-disable avoid-low-level-calls
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returnData) = target.call{value: value}(data);
result = Address.verifyCallResult(success, returnData, "ERC725X: Unknown Error");
}
Expand All @@ -163,14 +173,13 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
* @param data The data to be sent with the staticcall
* @return result The data returned from the staticcall
*/
function _executeStaticCall(address target, bytes memory data)
internal
virtual
returns (bytes memory result)
{
function _executeStaticCall(
address target,
bytes memory data
) internal virtual returns (bytes memory result) {
emit Executed(OPERATION_3_STATICCALL, target, 0, bytes4(data));

// solhint-disable avoid-low-level-calls
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returnData) = target.staticcall(data);
result = Address.verifyCallResult(success, returnData, "ERC725X: Unknown Error");
}
Expand All @@ -181,14 +190,13 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
* @param data The data to be sent with the delegatecall
* @return result The data returned from the delegatecall
*/
function _executeDelegateCall(address target, bytes memory data)
internal
virtual
returns (bytes memory result)
{
function _executeDelegateCall(
address target,
bytes memory data
) internal virtual returns (bytes memory result) {
emit Executed(OPERATION_4_DELEGATECALL, target, 0, bytes4(data));

// solhint-disable avoid-low-level-calls
// solhint-disable-next-line avoid-low-level-calls
(bool success, bytes memory returnData) = target.delegatecall(data);
result = Address.verifyCallResult(success, returnData, "ERC725X: Unknown Error");
}
Expand All @@ -199,17 +207,20 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
* @param creationCode The contract creation bytecode to deploy appended with the constructor argument(s)
* @return newContract The address of the contract created as bytes
*/
function _deployCreate(uint256 value, bytes memory creationCode)
internal
virtual
returns (bytes memory newContract)
{
function _deployCreate(
uint256 value,
bytes memory creationCode
) internal virtual returns (bytes memory newContract) {
if (address(this).balance < value) {
revert ERC725X_InsufficientBalance(address(this).balance, value);
}

if (creationCode.length == 0) {
revert ERC725X_NoContractBytecodeProvided();
}

address contractAddress;
// solhint-disable no-inline-assembly
// solhint-disable-next-line no-inline-assembly
assembly {
contractAddress := create(value, add(creationCode, 0x20), mload(creationCode))
}
Expand All @@ -219,7 +230,7 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
}

newContract = abi.encodePacked(contractAddress);
emit ContractCreated(OPERATION_1_CREATE, contractAddress, value);
emit ContractCreated(OPERATION_1_CREATE, contractAddress, value, bytes32(0));
}

/**
Expand All @@ -228,11 +239,10 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
* @param creationCode The contract creation bytecode to deploy appended with the constructor argument(s) and a bytes32 salt
* @return newContract The address of the contract created as bytes
*/
function _deployCreate2(uint256 value, bytes memory creationCode)
internal
virtual
returns (bytes memory newContract)
{
function _deployCreate2(
uint256 value,
bytes memory creationCode
) internal virtual returns (bytes memory newContract) {
if (creationCode.length == 0) {
revert ERC725X_NoContractBytecodeProvided();
}
Expand All @@ -242,7 +252,7 @@ abstract contract ERC725XCore is OwnableUnset, ERC165, IERC725X {
address contractAddress = Create2.deploy(value, salt, bytecode);

newContract = abi.encodePacked(contractAddress);
emit ContractCreated(OPERATION_2_CREATE2, contractAddress, value);
emit ContractCreated(OPERATION_2_CREATE2, contractAddress, value, salt);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion implementations/contracts/helpers/Counter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ contract Counter {
return count;
}

// solhint-disable no-empty-blocks
// solhint-disable-next-line no-empty-blocks
receive() external payable {}
}
5 changes: 4 additions & 1 deletion implementations/contracts/helpers/CustomRevertTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ pragma solidity ^0.8.0;
/**
* @dev Contract used for testing implementing a receive function that reverts;
*/
contract revertTester {
contract RevertTester {
error MyCustomError(address sender, address initiater);

receive() external payable {
// solhint-disable-next-line avoid-tx-origin
revert MyCustomError(msg.sender, tx.origin);
}

Expand All @@ -20,10 +21,12 @@ contract revertTester {
}

function revertMeWithCustomErrorView() public {
// solhint-disable-next-line avoid-tx-origin
revert MyCustomError(msg.sender, tx.origin);
}

function revertMeWithCustomErrorNotView() public {
// solhint-disable-next-line avoid-tx-origin
revert MyCustomError(msg.sender, tx.origin);
}
}
4 changes: 2 additions & 2 deletions implementations/contracts/helpers/ERC725XPayableTester.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import "../ERC725X.sol";
* 2. the contract can then transfer the native tokens in its balance via ERC725X.execute(0, recipient, amount, "")
*/
contract ERC725XPayableTester is ERC725X {
// solhint-disable no-empty-blocks
// solhint-disable-next-line no-empty-blocks
constructor(address _newOwner) ERC725X(_newOwner) {}

// solhint-disable no-empty-blocks
// solhint-disable-next-line no-empty-blocks
receive() external payable {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ pragma solidity ^0.8.0;
* @dev Contract used for testing implementing receive();
*/
contract NonPayableFallbackContract {
// solhint-disable-next-line payable-fallback
fallback() external {}
}
3 changes: 2 additions & 1 deletion implementations/contracts/interfaces/IERC725X.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ interface IERC725X is IERC165 {
event ContractCreated(
uint256 indexed operationType,
address indexed contractAddress,
uint256 indexed value
uint256 indexed value,
bytes32 salt
);

/**
Expand Down
4 changes: 2 additions & 2 deletions implementations/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion implementations/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@erc725/smart-contracts",
"version": "4.0.0",
"version": "4.1.0",
"description": "ERC725 contract implementations",
"homepage": "https://erc725alliance.org",
"repository": {
Expand Down
Loading

0 comments on commit e2c1594

Please sign in to comment.