Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fast-humans-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'openzeppelin-confidential-contracts': patch
---

`ERC7984Restricted`, `ERC7984Rwa`: Rename `isUserAllowed` to `canTransact`
2 changes: 1 addition & 1 deletion contracts/interfaces/IERC7984Rwa.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface IERC7984Rwa is IERC7984 {
/// @dev Returns true if the contract is paused, false otherwise.
function paused() external view returns (bool);
/// @dev Returns whether an account is allowed to interact with the token.
function isUserAllowed(address account) external view returns (bool);
function canTransact(address account) external view returns (bool);
/// @dev Returns the confidential frozen balance of an account.
function confidentialFrozen(address account) external view returns (euint64);
/// @dev Returns the confidential available (unfrozen) balance of an account. Up to {IERC7984-confidentialBalanceOf}.
Expand Down
14 changes: 7 additions & 7 deletions contracts/token/ERC7984/extensions/ERC7984Restricted.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {ERC7984, euint64} from "../ERC7984.sol";

/**
* @dev Extension of {ERC7984} that implements user account transfer restrictions through the
* {isUserAllowed} function. Inspired by
* {canTransact} function. Inspired by
* https://github.com/OpenZeppelin/openzeppelin-community-contracts/blob/master/contracts/token/ERC20/extensions/ERC20Restricted.sol.
*
* By default, each account has no explicit restriction. The {isUserAllowed} function acts as
* a blocklist. Developers can override {isUserAllowed} to check that `restriction == ALLOWED`
* By default, each account has no explicit restriction. The {canTransact} function acts as
* a blocklist. Developers can override {canTransact} to check that `restriction == ALLOWED`
* to implement an allowlist.
*/
abstract contract ERC7984Restricted is ERC7984 {
Expand Down Expand Up @@ -39,7 +39,7 @@ abstract contract ERC7984Restricted is ERC7984 {
*
* Default implementation only disallows explicitly BLOCKED accounts (i.e. a blocklist).
*/
function isUserAllowed(address account) public view virtual returns (bool) {
function canTransact(address account) public view virtual returns (bool) {
return getRestriction(account) != Restriction.BLOCKED; // i.e. DEFAULT && ALLOWED
}

Expand All @@ -48,8 +48,8 @@ abstract contract ERC7984Restricted is ERC7984 {
*
* Requirements:
*
* * `from` must be allowed to transfer tokens (see {isUserAllowed}).
* * `to` must be allowed to receive tokens (see {isUserAllowed}).
* * `from` must be allowed to transfer tokens (see {canTransact}).
* * `to` must be allowed to receive tokens (see {canTransact}).
*
* The default restriction behavior can be changed (for a pass-through for instance) by overriding
* {_checkSenderRestriction} and/or {_checkRecipientRestriction}.
Expand Down Expand Up @@ -85,7 +85,7 @@ abstract contract ERC7984Restricted is ERC7984 {

/// @dev Checks if a user account is restricted. Reverts with {UserRestricted} if so.
function _checkRestriction(address account) internal view virtual {
require(isUserAllowed(account), UserRestricted(account));
require(canTransact(account), UserRestricted(account));
}

/**
Expand Down
6 changes: 2 additions & 4 deletions contracts/token/ERC7984/extensions/ERC7984Rwa.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,8 @@ abstract contract ERC7984Rwa is IERC7984Rwa, ERC7984Freezable, ERC7984Restricted
}

/// @inheritdoc ERC7984Restricted
function isUserAllowed(
address account
) public view virtual override(IERC7984Rwa, ERC7984Restricted) returns (bool) {
return super.isUserAllowed(account);
function canTransact(address account) public view virtual override(IERC7984Rwa, ERC7984Restricted) returns (bool) {
return super.canTransact(account);
}

/// @dev Internal function which updates confidential balances while performing frozen and restriction compliance checks.
Expand Down
8 changes: 4 additions & 4 deletions test/token/ERC7984/extensions/ERC7984Restricted.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@ describe('ERC7984Restricted', function () {
});

it('allows users with DEFAULT restriction', async function () {
await expect(this.token.isUserAllowed(this.holder)).to.eventually.equal(true);
await expect(this.token.canTransact(this.holder)).to.eventually.equal(true);
});

it('allows users with ALLOWED status', async function () {
await this.token.$_allowUser(this.holder); // Sets to ALLOWED
await expect(this.token.getRestriction(this.holder)).to.eventually.equal(2); // ALLOWED
await expect(this.token.isUserAllowed(this.holder)).to.eventually.equal(true);
await expect(this.token.canTransact(this.holder)).to.eventually.equal(true);
});

it('blocks users with BLOCKED status', async function () {
await this.token.$_blockUser(this.holder); // Sets to BLOCKED
await expect(this.token.getRestriction(this.holder)).to.eventually.equal(1); // BLOCKED
await expect(this.token.isUserAllowed(this.holder)).to.eventually.equal(false);
await expect(this.token.canTransact(this.holder)).to.eventually.equal(false);
});

it('resets user to DEFAULT restriction', async function () {
await this.token.$_blockUser(this.holder); // Sets to BLOCKED
await this.token.$_resetUser(this.holder); // Sets to DEFAULT
await expect(this.token.getRestriction(this.holder)).to.eventually.equal(0); // DEFAULT
await expect(this.token.isUserAllowed(this.holder)).to.eventually.equal(true);
await expect(this.token.canTransact(this.holder)).to.eventually.equal(true);
});

it('emits UserRestrictionUpdated event when restriction changes', async function () {
Expand Down
6 changes: 3 additions & 3 deletions test/token/ERC7984/extensions/ERC7984Rwa.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ describe('ERC7984Rwa', function () {
describe('ERC7984Restricted', async function () {
it('should block & unblock', async function () {
const { token, agent1, recipient } = await fixture();
await expect(token.isUserAllowed(recipient)).to.eventually.be.true;
await expect(token.canTransact(recipient)).to.eventually.be.true;
await token.connect(agent1).blockUser(recipient);
await expect(token.isUserAllowed(recipient)).to.eventually.be.false;
await expect(token.canTransact(recipient)).to.eventually.be.false;
await token.connect(agent1).unblockUser(recipient);
await expect(token.isUserAllowed(recipient)).to.eventually.be.true;
await expect(token.canTransact(recipient)).to.eventually.be.true;
});

for (const arg of [true, false]) {
Expand Down