Skip to content

Commit 10e2381

Browse files
committed
T
1 parent 8d7b619 commit 10e2381

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/DN404.sol

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ abstract contract DN404 {
129129
/// [Etherscan](https://etherscan.io/address/0x000000000022D473030F116dDEE9F6B43aC78BA3)
130130
address internal constant _PERMIT2 = 0x000000000022D473030F116dDEE9F6B43aC78BA3;
131131

132+
/// @dev The ZKsync deployment.
133+
/// [Etherscan](https://era.zksync.network/address/0x0000000000225e31D15943971F47aD3022F714Fa)
134+
address internal constant _ZKSYNC_PERMIT_2 = 0x0000000000225e31D15943971F47aD3022F714Fa;
135+
132136
/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/
133137
/* STORAGE */
134138
/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/
@@ -364,7 +368,7 @@ abstract contract DN404 {
364368

365369
/// @dev Returns the amount of tokens that `spender` can spend on behalf of `owner`.
366370
function allowance(address owner, address spender) public view returns (uint256) {
367-
if (_givePermit2DefaultInfiniteAllowance() && spender == _PERMIT2) {
371+
if (_givePermit2DefaultInfiniteAllowance() && _isPermit2(spender)) {
368372
uint8 flags = _getDN404Storage().addressData[owner].flags;
369373
if ((flags & _ADDRESS_DATA_OVERRIDE_PERMIT2_FLAG) == uint256(0)) {
370374
return type(uint256).max;
@@ -418,7 +422,7 @@ abstract contract DN404 {
418422
function transferFrom(address from, address to, uint256 amount) public virtual returns (bool) {
419423
Uint256Ref storage a = _ref(_getDN404Storage().allowance, from, msg.sender);
420424

421-
uint256 allowed = _givePermit2DefaultInfiniteAllowance() && msg.sender == _PERMIT2
425+
uint256 allowed = _givePermit2DefaultInfiniteAllowance() && _isPermit2(msg.sender)
422426
&& (_getDN404Storage().addressData[from].flags & _ADDRESS_DATA_OVERRIDE_PERMIT2_FLAG)
423427
== uint256(0) ? type(uint256).max : a.value;
424428

@@ -447,6 +451,12 @@ abstract contract DN404 {
447451
return false;
448452
}
449453

454+
/// @dev Returns checks if `sender` is the canonical Permit2 address.
455+
/// If on ZKsync, override this function to check against `_ZKSYNC_PERMIT_2` as well.
456+
function _isPermit2(address sender) internal view virtual returns (bool) {
457+
return sender == _PERMIT2;
458+
}
459+
450460
/*«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-«-*/
451461
/* INTERNAL MINT FUNCTIONS */
452462
/*-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»-»*/
@@ -975,7 +985,7 @@ abstract contract DN404 {
975985
///
976986
/// Emits a {Approval} event.
977987
function _approve(address owner, address spender, uint256 amount) internal virtual {
978-
if (_givePermit2DefaultInfiniteAllowance() && spender == _PERMIT2) {
988+
if (_givePermit2DefaultInfiniteAllowance() && _isPermit2(spender)) {
979989
_getDN404Storage().addressData[owner].flags |= _ADDRESS_DATA_OVERRIDE_PERMIT2_FLAG;
980990
}
981991
_ref(_getDN404Storage().allowance, owner, spender).value = amount;

0 commit comments

Comments
 (0)