Skip to content

Commit

Permalink
Merge branch 'master' into typo-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Amxx authored Feb 4, 2025
2 parents 4dd9d06 + 2141d3f commit 602dc92
Show file tree
Hide file tree
Showing 29 changed files with 1,100 additions and 118 deletions.
5 changes: 5 additions & 0 deletions .changeset/brown-seals-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`SafeERC20`: Add `trySafeTransfer` and `trySafeTransferFrom` that do not revert and return false if the transfer is not successful.
5 changes: 5 additions & 0 deletions .changeset/brown-turkeys-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`ER6909TokenSupply`: Add an extension of ERC6909 which tracks total supply for each token id.
5 changes: 0 additions & 5 deletions .changeset/chilly-guests-jam.md

This file was deleted.

5 changes: 5 additions & 0 deletions .changeset/dirty-bananas-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`ERC6909ContentURI`: Add an extension of ERC6909 which adds content URI functionality.
5 changes: 5 additions & 0 deletions .changeset/proud-cooks-do.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`ERC6909Metadata`: Add an extension of ERC6909 which adds metadata functionality.
5 changes: 5 additions & 0 deletions .changeset/ten-hats-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-solidity': minor
---

`ERC6909`: Add a standard implementation of ERC6909.
27 changes: 1 addition & 26 deletions contracts/account/utils/draft-ERC4337Utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ library ERC4337Utils {
using Packing for *;

/// @dev Address of the entrypoint v0.7.0
IEntryPoint internal constant ENTRYPOINT = IEntryPoint(0x0000000071727De22E5E9d8BAf0edAc6f37da032);
IEntryPoint internal constant ENTRYPOINT_V07 = IEntryPoint(0x0000000071727De22E5E9d8BAf0edAc6f37da032);

/// @dev For simulation purposes, validateUserOp (and validatePaymasterUserOp) return this value on success.
uint256 internal constant SIG_VALIDATION_SUCCESS = 0;
Expand Down Expand Up @@ -163,29 +163,4 @@ library ERC4337Utils {
function paymasterData(PackedUserOperation calldata self) internal pure returns (bytes calldata) {
return self.paymasterAndData.length < 52 ? Calldata.emptyBytes() : self.paymasterAndData[52:];
}

/// @dev Deposit ether into the entrypoint.
function depositTo(address to, uint256 value) internal {
ENTRYPOINT.depositTo{value: value}(to);
}

/// @dev Withdraw ether from the entrypoint.
function withdrawTo(address payable to, uint256 value) internal {
ENTRYPOINT.withdrawTo(to, value);
}

/// @dev Add stake to the entrypoint.
function addStake(uint256 value, uint32 unstakeDelaySec) internal {
ENTRYPOINT.addStake{value: value}(unstakeDelaySec);
}

/// @dev Unlock stake on the entrypoint.
function unlockStake() internal {
ENTRYPOINT.unlockStake();
}

/// @dev Withdraw unlocked stake from the entrypoint.
function withdrawStake(address payable to) internal {
ENTRYPOINT.withdrawStake(to);
}
}
12 changes: 12 additions & 0 deletions contracts/interfaces/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ are useful to interact with third party contracts that implement them.
- {IERC5313}
- {IERC5805}
- {IERC6372}
- {IERC6909}
- {IERC6909ContentURI}
- {IERC6909Metadata}
- {IERC6909TokenSupply}
- {IERC7674}

== Detailed ABI
Expand Down Expand Up @@ -84,4 +88,12 @@ are useful to interact with third party contracts that implement them.

{{IERC6372}}

{{IERC6909}}

{{IERC6909ContentURI}}

{{IERC6909Metadata}}

{{IERC6909TokenSupply}}

{{IERC7674}}
26 changes: 26 additions & 0 deletions contracts/mocks/docs/token/ERC6909/ERC6909GameItems.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

import {ERC6909Metadata} from "../../../../token/ERC6909/extensions/draft-ERC6909Metadata.sol";

contract ERC6909GameItems is ERC6909Metadata {
uint256 public constant GOLD = 0;
uint256 public constant SILVER = 1;
uint256 public constant THORS_HAMMER = 2;
uint256 public constant SWORD = 3;
uint256 public constant SHIELD = 4;

constructor() {
_setDecimals(GOLD, 18);
_setDecimals(SILVER, 18);
// Default decimals is 0
_setDecimals(SWORD, 9);
_setDecimals(SHIELD, 9);

_mint(msg.sender, GOLD, 10 ** 18);
_mint(msg.sender, SILVER, 10_000 ** 18);
_mint(msg.sender, THORS_HAMMER, 1);
_mint(msg.sender, SWORD, 10 ** 9);
_mint(msg.sender, SHIELD, 10 ** 9);
}
}
14 changes: 14 additions & 0 deletions contracts/token/ERC20/utils/SafeERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ library SafeERC20 {
_callOptionalReturn(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}

/**
* @dev Variant of {safeTransfer} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransfer(IERC20 token, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transfer, (to, value)));
}

/**
* @dev Variant of {safeTransferFrom} that returns a bool instead of reverting if the operation is not successful.
*/
function trySafeTransferFrom(IERC20 token, address from, address to, uint256 value) internal returns (bool) {
return _callOptionalReturnBool(token, abi.encodeCall(token.transferFrom, (from, to, value)));
}

/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
Expand Down
27 changes: 27 additions & 0 deletions contracts/token/ERC6909/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
= ERC-6909

[.readme-notice]
NOTE: This document is better viewed at https://docs.openzeppelin.com/contracts/api/token/erc6909

This set of interfaces and contracts are all related to the https://eips.ethereum.org/EIPS/eip-6909[ERC-6909 Minimal Multi-Token Interface].

The ERC consists of four interfaces which fulfill different roles--the interfaces are as follows:

. {IERC6909}: Base interface for a vanilla ERC6909 token.
. {IERC6909ContentURI}: Extends the base interface and adds content URI (contract and token level) functionality.
. {IERC6909Metadata}: Extends the base interface and adds metadata functionality, which exposes a name, symbol, and decimals for each token id.
. {IERC6909TokenSupply}: Extends the base interface and adds total supply functionality for each token id.

Implementations are provided for each of the 4 interfaces defined in the ERC.

== Core

{{ERC6909}}

== Extensions

{{ERC6909ContentURI}}

{{ERC6909Metadata}}

{{ERC6909TokenSupply}}
Loading

0 comments on commit 602dc92

Please sign in to comment.