diff --git a/.changeset/fast-humans-run.md b/.changeset/fast-humans-run.md new file mode 100644 index 00000000..7166ce4f --- /dev/null +++ b/.changeset/fast-humans-run.md @@ -0,0 +1,5 @@ +--- +'openzeppelin-confidential-contracts': patch +--- + +`ERC7984Restricted`, `ERC7984Rwa`: Rename `isUserAllowed` to `canTransact` diff --git a/contracts/interfaces/IERC7984Rwa.sol b/contracts/interfaces/IERC7984Rwa.sol index 7bef15e0..ec34ddfc 100644 --- a/contracts/interfaces/IERC7984Rwa.sol +++ b/contracts/interfaces/IERC7984Rwa.sol @@ -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}. diff --git a/contracts/token/ERC7984/extensions/ERC7984Restricted.sol b/contracts/token/ERC7984/extensions/ERC7984Restricted.sol index 62dc6fdc..4d487ba2 100644 --- a/contracts/token/ERC7984/extensions/ERC7984Restricted.sol +++ b/contracts/token/ERC7984/extensions/ERC7984Restricted.sol @@ -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 { @@ -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 } @@ -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}. @@ -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)); } /** diff --git a/contracts/token/ERC7984/extensions/ERC7984Rwa.sol b/contracts/token/ERC7984/extensions/ERC7984Rwa.sol index 930b3bbf..84f1b57b 100644 --- a/contracts/token/ERC7984/extensions/ERC7984Rwa.sol +++ b/contracts/token/ERC7984/extensions/ERC7984Rwa.sol @@ -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. diff --git a/test/token/ERC7984/extensions/ERC7984Restricted.test.ts b/test/token/ERC7984/extensions/ERC7984Restricted.test.ts index 302c9245..a596d167 100644 --- a/test/token/ERC7984/extensions/ERC7984Restricted.test.ts +++ b/test/token/ERC7984/extensions/ERC7984Restricted.test.ts @@ -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 () { diff --git a/test/token/ERC7984/extensions/ERC7984Rwa.test.ts b/test/token/ERC7984/extensions/ERC7984Rwa.test.ts index 0ba3c72e..59b6a578 100644 --- a/test/token/ERC7984/extensions/ERC7984Rwa.test.ts +++ b/test/token/ERC7984/extensions/ERC7984Rwa.test.ts @@ -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]) {