Skip to content

Commit 2ed521a

Browse files
committed
🧼 Clean up & refactor
1 parent 7d31355 commit 2ed521a

9 files changed

+78
-32
lines changed

erc/IERC721.sol

+7-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
pragma solidity ^0.8.0;
44

5-
interface IERC721 {
5+
import {IERC165} from "./IERC165.sol";
6+
7+
interface IERC721Partial is IERC165 {
68
function name() external pure returns (string memory);
79

810
function symbol() external pure returns (string memory);
@@ -15,3 +17,7 @@ interface IERC721 {
1517

1618
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
1719
}
20+
21+
interface IERC721 is IERC721Partial {
22+
function ownerOf(uint256 tokenId) external view returns (address);
23+
}

kimlikdao/IDIDSigners.sol

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ uint256 constant SIGNER_INFO_WITHDRAW_MASK = uint256(type(uint48).max) << 176;
2727
*/
2828
type SignerInfo is uint256;
2929

30+
function deposit(SignerInfo self) pure returns (uint256) {
31+
return uint48(SignerInfo.unwrap(self) >> 64);
32+
}
33+
34+
using {deposit} for SignerInfo global;
35+
3036
interface IDIDSigners {
3137
function authenticateExposureReportID3Sigs(
3238
bytes32 exposureReportID,

kimlikdao/IProtocolFund.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function RedeemInfoFrom(uint48x2 totalAndAmount, address redeemer) pure returns
1111
return RedeemInfo.wrap(uint48x2.unwrap(totalAndAmount) << 160 | uint160(redeemer));
1212
}
1313

14-
function unpack(RedeemInfo self) returns (uint256 total, uint256 redeemed, address redeemer) {
14+
function unpack(RedeemInfo self) pure returns (uint256 total, uint256 redeemed, address redeemer) {
1515
uint256 val = RedeemInfo.unwrap(self);
1616
return (val >> 208, uint48(val >> 160), address(uint160(val)));
1717
}

testing/MockTokens.sol testing/MockERC20Permit.sol

+1-27
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,8 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {TRYB_DEPLOYER, USDC_DEPLOYER, USDT_DEPLOYER} from "../avalanche/addresses.sol";
65
import {IERC20Permit} from "../erc/IERC20Permit.sol";
7-
import {Vm} from "forge-std/Vm.sol";
8-
import {console2} from "forge-std/console2.sol";
96

10-
function DeployMockTokens() {
11-
Vm vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
12-
13-
vm.setNonce(TRYB_DEPLOYER, 2);
14-
vm.prank(TRYB_DEPLOYER);
15-
IERC20Permit tryb = new MockERC20Permit("TRYB", "BiLira", 6);
16-
console2.log("TRYB:", address(tryb));
17-
18-
vm.setNonce(USDC_DEPLOYER, 4);
19-
vm.prank(USDC_DEPLOYER);
20-
IERC20Permit usdc = new MockERC20Permit("USDC", "USD Coin", 6);
21-
console2.log("USDC:", address(usdc));
22-
23-
vm.setNonce(USDT_DEPLOYER, 2);
24-
vm.prank(USDT_DEPLOYER);
25-
IERC20Permit usdt = new MockERC20Permit("USDt", "TetherToken", 6);
26-
console2.log("USDT:", address(usdt));
27-
}
28-
29-
/**
30-
* @title Example ERC20Permit contract for mocking the tokens we accept as
31-
* payment for testing purposes.
32-
*/
337
contract MockERC20Permit is IERC20Permit {
348
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
359
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
@@ -57,7 +31,7 @@ contract MockERC20Permit is IERC20Permit {
5731
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
5832
keccak256(bytes(tokenSymbol)),
5933
keccak256(bytes("1")),
60-
0x144,
34+
block.chainid,
6135
address(this)
6236
)
6337
);

types/amountAddr.sol

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ function notEqual(amountAddr self, amountAddr other) pure returns (bool) {
2424
return amountAddr.unwrap(self) != amountAddr.unwrap(other);
2525
}
2626

27-
using {unpack, amount, addr, notEqual as !=} for amountAddr global;
27+
function isZero(amountAddr self) pure returns (bool) {
28+
return amountAddr.unwrap(self) == 0;
29+
}
30+
31+
using {unpack, amount, addr, isZero, notEqual as !=} for amountAddr global;

types/uint128x2.sol

+31-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ function decLo(uint128x2 self, uint256 delta) pure returns (uint128x2) {
5252
}
5353
}
5454

55+
function setLo(uint128x2 self, uint256 val) pure returns (uint128x2) {
56+
return uint128x2.wrap((uint128x2.unwrap(self) & (~uint256(0) << 128)) | val);
57+
}
58+
5559
function sum(uint128x2 self) pure returns (uint256) {
5660
unchecked {
5761
return (uint128x2.unwrap(self) >> 128) + uint128(uint128x2.unwrap(self));
@@ -70,4 +74,30 @@ function equal(uint128x2 self, uint128x2 other) pure returns (bool) {
7074
return uint128x2.unwrap(self) == uint128x2.unwrap(other);
7175
}
7276

73-
using {hi, lo, inc, dec, incHi, incLo, decHi, decLo, sum, clearHi, clearLo, equal as ==} for uint128x2 global;
77+
/**
78+
* Given a fraction (hi, lo) and a value val, computes the tuple (val * hi / lo, val) efficiently.
79+
*
80+
* @return (val * hi / lo, val)
81+
*/
82+
function fracMul(uint128x2 self, uint256 val) pure returns (uint128x2) {
83+
unchecked {
84+
return uint128x2.wrap(uint128x2.unwrap(self) * val / uint128(uint128x2.unwrap(self))).setLo(val);
85+
}
86+
}
87+
88+
using {
89+
hi,
90+
lo,
91+
inc,
92+
dec,
93+
incHi,
94+
incLo,
95+
decHi,
96+
decLo,
97+
setLo,
98+
sum,
99+
clearHi,
100+
clearLo,
101+
fracMul,
102+
equal as ==
103+
} for uint128x2 global;

zksync/addresses.sol

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import {IERC20Permit} from "../erc/IERC20Permit.sol";
6+
7+
IERC20Permit constant USDT = IERC20Permit(0x493257fD37EDB34451f62EDf8D2a0C418852bA4C);

zksync/mockTokens.sol

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import {IERC20Permit} from "../erc/IERC20Permit.sol";
6+
import {MockERC20Permit} from "../testing/MockERC20Permit.sol";
7+
import {Vm} from "forge-std/Vm.sol";
8+
import {console2} from "forge-std/console2.sol";
9+
10+
address constant USDT_DEPLOYER = 0x493257fD37EDB34451f62EDf8D2a0C418852bA4C;
11+
12+
function deployMockTokens() {
13+
Vm vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
14+
15+
vm.setNonce(USDT_DEPLOYER, 4);
16+
vm.prank(USDT_DEPLOYER);
17+
IERC20Permit usdc = new MockERC20Permit("USDC", "USD Coin", 6);
18+
console2.log("USDC:", address(usdc));
19+
}

0 commit comments

Comments
 (0)