Skip to content

Commit fbed559

Browse files
committed
🪙 Add Ethereum mock tokens
1 parent 5a4d0a1 commit fbed559

File tree

9 files changed

+100
-32
lines changed

9 files changed

+100
-32
lines changed

ethereum/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 {IERC20, IERC20Permit} from "../erc/IERC20Permit.sol";
6+
7+
IERC20 constant USDT = IERC20(0xdAC17F958D2ee523a2206206994597C13D831ec7);

ethereum/mockTokens.sol

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import {IERC20Permit} from "../erc/IERC20Permit.sol";
6+
import {MockERC20, MockERC20Permit} from "../testing/MockERC20Permit.sol";
7+
import {USDT} from "./addresses.sol";
8+
import {Vm} from "forge-std/Vm.sol";
9+
10+
contract USDTImpl is MockERC20 {
11+
function name() public pure returns (string memory) {
12+
return "Tether USD";
13+
}
14+
15+
function symbol() public pure returns (string memory) {
16+
return "USDT";
17+
}
18+
19+
function decimals() public pure override returns (uint8) {
20+
return 6;
21+
}
22+
}
23+
24+
address constant USDT_DEPLOYER = 0x36928500Bc1dCd7af6a2B4008875CC336b927D57;
25+
26+
function deployMockTokens() {
27+
Vm vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
28+
29+
vm.setNonce(USDT_DEPLOYER, 6);
30+
vm.prank(USDT_DEPLOYER);
31+
new USDTImpl();
32+
}

foundry.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
[fmt]
2-
sort_imports = true
2+
line_length = 100
33
single_line_statement_blocks = "single"
4+
sort_imports = true
45

56
[profile.default]
6-
test = "test"
77
optimizer = true
88
optimizer_runs = 20_000
99
remappings = ['forge-std/=lib/forge-std/src/']

kimlikdao/IDIDSigners.sol

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ interface IDIDSigners {
1111
uint128x2 weightThresholdAndSignatureTs,
1212
bytes32 commitmentR,
1313
Signature[3] calldata sigs
14-
) external view;
14+
) external view returns (bool);
1515

1616
function authenticateHumanIDv1(
1717
bytes32 humanID,
1818
uint128x2 weightThresholdAndSignatureTs,
1919
bytes32 commitmentR,
2020
Signature[5] calldata sigs
21-
) external view;
21+
) external view returns (bool);
2222

2323
/**
2424
* Maps a signer node address to a bit packed struct.
@@ -27,7 +27,11 @@ interface IDIDSigners {
2727
}
2828

2929
interface IDIDSignersExposureReport {
30-
function reportExposure(bytes32 exposureReportID, uint256 signatureTs, Signature[3] calldata sigs) external;
30+
function reportExposure(
31+
bytes32 exposureReportID,
32+
uint256 signatureTs,
33+
Signature[3] calldata sigs
34+
) external;
3135
}
3236

3337
uint256 constant SIGNER_INFO_END_TS_MASK = uint256(type(uint64).max) << 112;
@@ -41,7 +45,10 @@ uint256 constant SIGNER_INFO_WITHDRAW_MASK = uint256(type(uint48).max) << 176;
4145
*/
4246
type SignerInfo is uint256;
4347

44-
function SignerInfoFrom(uint256 _color, uint256 _deposit, uint256 _startTs) pure returns (SignerInfo) {
48+
function SignerInfoFrom(uint256 _color, uint256 _deposit, uint256 _startTs)
49+
pure
50+
returns (SignerInfo)
51+
{
4552
return SignerInfo.wrap((_color << 224) | (_deposit << 64) | _startTs);
4653
}
4754

test/avalanche/addresses.t.sol

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

33
pragma solidity ^0.8.0;
44

5-
import {TRYB, TRYB_DEPLOYER, USDC, USDC_DEPLOYER, USDT, USDT_DEPLOYER} from "avalanche/addresses.sol";
5+
import {
6+
TRYB, TRYB_DEPLOYER, USDC, USDC_DEPLOYER, USDT, USDT_DEPLOYER
7+
} from "avalanche/addresses.sol";
68
import {Test} from "forge-std/Test.sol";
79

810
contract addressesTest is Test {

test/kimlikdao/addresses.t.sol

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ import {
2020
PROTOCOL_FUND_ZKSYNC,
2121
PROTOCOL_FUND_ZKSYNC_DEPLOYER
2222
} from "kimlikdao/addresses.sol";
23-
import {applyL1ToL2Alias, computeCreateAddress as computeZkSyncCreateAddress} from "zksync/IZkSync.sol";
23+
import {
24+
applyL1ToL2Alias,
25+
computeCreateAddress as computeZkSyncCreateAddress
26+
} from "zksync/IZkSync.sol";
2427

2528
contract addressesTest is Test {
2629
function testDeployerConsistency() public pure {

test/zksync/L2Log.t.sol

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ contract L2LogLocatorTest is Test {
1717
assertEq(k.messageIndex(), type(uint112).max);
1818
assertEq(k.txNumber(), type(uint16).max);
1919

20-
L2LogLocator m = L2LogLocatorFrom(type(uint128).max - 1, type(uint112).max - 1, type(uint16).max - 1);
20+
L2LogLocator m =
21+
L2LogLocatorFrom(type(uint128).max - 1, type(uint112).max - 1, type(uint16).max - 1);
2122
assertEq(m.batchNumber(), type(uint128).max - 1);
2223
assertEq(m.messageIndex(), type(uint112).max - 1);
2324
assertEq(m.txNumber(), type(uint16).max - 1);

testing/MockERC20Permit.sol

+33-15
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {IERC20Permit} from "../erc/IERC20Permit.sol";
6-
7-
abstract contract MockERC20Permit is IERC20Permit {
8-
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
9-
bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
5+
import {IERC20, IERC20Permit} from "../erc/IERC20Permit.sol";
106

7+
abstract contract MockERC20 is IERC20 {
118
uint256 public override totalSupply;
129
mapping(address => uint256) public override balanceOf;
1310
mapping(address => mapping(address => uint256)) public override allowance;
14-
mapping(address => uint256) public override nonces;
1511

1612
function approve(address spender, uint256 amount) external returns (bool) {
1713
allowance[msg.sender][spender] = amount;
@@ -28,7 +24,11 @@ abstract contract MockERC20Permit is IERC20Permit {
2824
return true;
2925
}
3026

31-
function transferFrom(address from, address to, uint256 amount) external override returns (bool) {
27+
function transferFrom(address from, address to, uint256 amount)
28+
external
29+
override
30+
returns (bool)
31+
{
3232
uint256 allowed = allowance[from][msg.sender];
3333
if (allowed != type(uint256).max) allowance[from][msg.sender] = allowed - amount;
3434
balanceOf[from] -= amount;
@@ -39,16 +39,38 @@ abstract contract MockERC20Permit is IERC20Permit {
3939
return true;
4040
}
4141

42-
function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
43-
external
44-
{
42+
function mint(uint256 amount) external {
43+
balanceOf[msg.sender] += amount;
44+
}
45+
}
46+
47+
abstract contract MockERC20Permit is MockERC20, IERC20Permit {
48+
// keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)");
49+
bytes32 public constant PERMIT_TYPEHASH =
50+
0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9;
51+
52+
mapping(address => uint256) public override nonces;
53+
54+
function permit(
55+
address owner,
56+
address spender,
57+
uint256 amount,
58+
uint256 deadline,
59+
uint8 v,
60+
bytes32 r,
61+
bytes32 s
62+
) external {
4563
require(deadline >= block.timestamp);
4664
unchecked {
4765
bytes32 digest = keccak256(
4866
abi.encodePacked(
4967
"\x19\x01",
5068
DOMAIN_SEPARATOR(),
51-
keccak256(abi.encode(PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline))
69+
keccak256(
70+
abi.encode(
71+
PERMIT_TYPEHASH, owner, spender, amount, nonces[owner]++, deadline
72+
)
73+
)
5274
)
5375
);
5476
address recovered = ecrecover(digest, v, r, s);
@@ -59,8 +81,4 @@ abstract contract MockERC20Permit is IERC20Permit {
5981
}
6082

6183
function DOMAIN_SEPARATOR() public pure virtual override returns (bytes32);
62-
63-
function mint(uint256 amount) external {
64-
balanceOf[msg.sender] += amount;
65-
}
6684
}

zksync/mockTokens.sol

+6-8
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import {IERC20Permit} from "../erc/IERC20Permit.sol";
66
import {MockERC20Permit} from "../testing/MockERC20Permit.sol";
77
import {USDT} from "./addresses.sol";
88
import {Vm} from "forge-std/Vm.sol";
9-
import {console2} from "forge-std/console2.sol";
10-
11-
address constant USDT_DEPLOYER = 0x493257fD37EDB34451f62EDf8D2a0C418852bA4C;
129

1310
contract USDTImpl is MockERC20Permit {
1411
function DOMAIN_SEPARATOR() public pure override returns (bytes32) {
1512
return keccak256(
1613
abi.encode(
17-
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"),
14+
keccak256(
15+
"EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"
16+
),
1817
keccak256(bytes("KPASS")),
1918
keccak256(bytes("1")),
2019
0x144,
@@ -35,7 +34,7 @@ contract USDTImpl is MockERC20Permit {
3534
return 6;
3635
}
3736

38-
constructor() {
37+
function initialize() external {
3938
uint256 toMint = 100 * 10e6;
4039
balanceOf[msg.sender] = toMint;
4140
totalSupply = toMint;
@@ -46,7 +45,6 @@ contract USDTImpl is MockERC20Permit {
4645
function deployMockTokens() {
4746
Vm vm = Vm(address(uint160(uint256(keccak256("hevm cheat code")))));
4847

49-
vm.setNonce(USDT_DEPLOYER, 4);
50-
vm.prank(USDT_DEPLOYER);
51-
new USDTImpl();
48+
vm.etch(address(USDT), type(USDTImpl).runtimeCode);
49+
USDTImpl(address(USDT)).initialize();
5250
}

0 commit comments

Comments
 (0)