Skip to content

Commit

Permalink
🪙 Add mock KDAO
Browse files Browse the repository at this point in the history
  • Loading branch information
KimlikDAO-bot committed Jul 2, 2024
1 parent b0dc652 commit ab886b0
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 20 deletions.
4 changes: 1 addition & 3 deletions avalanche/test/addresses.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

pragma solidity ^0.8.0;

import {
TRYB, TRYB_DEPLOYER, USDC, USDC_DEPLOYER, USDT, USDT_DEPLOYER
} from "../addresses.sol";
import {TRYB, TRYB_DEPLOYER, USDC, USDC_DEPLOYER, USDT, USDT_DEPLOYER} from "../addresses.sol";
import {Test} from "forge-std/Test.sol";

contract addressesTest is Test {
Expand Down
11 changes: 9 additions & 2 deletions erc/IERC20Permit.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@ pragma solidity ^0.8.0;
import "./IERC20.sol";

interface IERC20Permit is IERC20 {
function permit(address owner, address spender, uint256 amount, uint256 deadline, uint8 v, bytes32 r, bytes32 s)
external;
function permit(
address owner,
address spender,
uint256 amount,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;

function nonces(address owner) external view returns (uint256);

Expand Down
23 changes: 23 additions & 0 deletions kimlikdao/mock/KDAO.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT

pragma solidity ^0.8.0;

import {ERC20Permit as MockERC20Permit} from "../../erc/mock/ERC20Permit.sol";

contract KDAO is MockERC20Permit {
function name() external pure override returns (string memory) {
return "KimlikDAO";
}

function symbol() external pure override returns (string memory) {
return "KDAO";
}

function decimals() external pure override returns (uint8) {
return 6;
}

function DOMAIN_SEPARATOR() public pure override returns (bytes32) {
return 0;
}
}
10 changes: 5 additions & 5 deletions kimlikdao/test/addresses.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

pragma solidity ^0.8.0;

import {Test} from "forge-std/Test.sol";
import {
applyL1ToL2Alias,
computeCreateAddress as computeZkSyncCreateAddress
} from "../../zksync/IZkSync.sol";
import {
KDAO,
KDAO_DEPLOYER,
Expand All @@ -13,10 +16,7 @@ import {
KPASS_ZKSYNC,
KPASS_ZKSYNC_DEPLOYER
} from "../addresses.sol";
import {
applyL1ToL2Alias,
computeCreateAddress as computeZkSyncCreateAddress
} from "../../zksync/IZkSync.sol";
import {Test} from "forge-std/Test.sol";

contract addressesTest is Test {
function testDeployerConsistency() public pure {
Expand Down
4 changes: 4 additions & 0 deletions types/Signature.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ struct Signature {
bytes32 r;
YParityAndS yParityAndS;
}

function SignatureFrom(uint8 v, bytes32 r, bytes32 s_) pure returns (Signature memory) {
return Signature(r, YParityAndS.wrap((uint256(v - 27) << 255) | uint256(s_)));
}
15 changes: 13 additions & 2 deletions types/amountAddr.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ function addr(amountAddr self) pure returns (address) {
}

function setAddr(amountAddr self, address _addr) pure returns (amountAddr) {
return amountAddr.wrap(amountAddr.unwrap(self) & (type(uint256).max << 160) | uint256(uint160(_addr)));
return amountAddr.wrap(
amountAddr.unwrap(self) & (type(uint256).max << 160) | uint256(uint160(_addr))
);
}

function addAddr(amountAddr self, address _addr) pure returns (amountAddr) {
Expand All @@ -40,4 +42,13 @@ function toBytes32(amountAddr self) pure returns (bytes32) {
return bytes32(amountAddr.unwrap(self));
}

using {unpack, amount, addr, addAddr, setAddr, isZero, toBytes32, notEqual as !=} for amountAddr global;
using {
unpack,
amount,
addr,
addAddr,
setAddr,
isZero,
toBytes32,
notEqual as !=
} for amountAddr global;
2 changes: 1 addition & 1 deletion types/test/amountAddr.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity ^0.8.0;

import {Test} from "forge-std/Test.sol";
import {amountAddr, amountAddrFrom} from "../amountAddr.sol";
import {Test} from "forge-std/Test.sol";

contract amountAddrTest is Test {
function testAccessors() external pure {
Expand Down
2 changes: 1 addition & 1 deletion types/test/uint128x2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity ^0.8.0;

import {Test} from "forge-std/Test.sol";
import {uint128x2, uint128x2From} from "../uint128x2.sol";
import {Test} from "forge-std/Test.sol";

contract uint128x2Test is Test {
function testAccessors() external pure {
Expand Down
2 changes: 1 addition & 1 deletion types/test/uint48x2.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity ^0.8.0;

import {Test} from "forge-std/Test.sol";
import {uint48x2, uint48x2From} from "../uint48x2.sol";
import {Test} from "forge-std/Test.sol";

contract uint48x2Test is Test {
function testAccessors() external pure {
Expand Down
4 changes: 3 additions & 1 deletion types/uint128x2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ function equal(uint128x2 self, uint128x2 other) pure returns (bool) {
*/
function fracMul(uint128x2 self, uint256 val) pure returns (uint128x2) {
unchecked {
return uint128x2.wrap(uint128x2.unwrap(self) * val / uint128(uint128x2.unwrap(self))).setLo(val);
return uint128x2.wrap(uint128x2.unwrap(self) * val / uint128(uint128x2.unwrap(self))).setLo(
val
);
}
}

Expand Down
16 changes: 15 additions & 1 deletion types/uint48x2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,18 @@ function equal(uint48x2 self, uint48x2 other) pure returns (bool) {
return uint48x2.unwrap(self) == uint48x2.unwrap(other);
}

using {hi, lo, inc, dec, incHi, incLo, decHi, decLo, setLo, sum, clearHi, clearLo, equal as ==} for uint48x2 global;
using {
hi,
lo,
inc,
dec,
incHi,
incLo,
decHi,
decLo,
setLo,
sum,
clearHi,
clearLo,
equal as ==
} for uint48x2 global;
3 changes: 2 additions & 1 deletion zksync/IZkSync.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ function undoL1ToL2Alias(address l2Address) pure returns (address l1Address) {
bytes32 constant CREATE_PREFIX = 0x63bae3a9951d38e8a3fbb7b70909afc1200610fc5bc55ade242f815974674f23;

function computeCreateAddress(address deployer, uint256 nonce) pure returns (address) {
bytes32 hash = keccak256(bytes.concat(CREATE_PREFIX, bytes32(uint256(uint160(deployer))), bytes32(nonce)));
bytes32 hash =
keccak256(bytes.concat(CREATE_PREFIX, bytes32(uint256(uint160(deployer))), bytes32(nonce)));
return address(uint160(uint256(hash)));
}

Expand Down
5 changes: 4 additions & 1 deletion zksync/L2Log.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ struct L2Log {

type L2LogLocator is uint256;

function L2LogLocatorFrom(uint256 _batchNumber, uint256 _messageIndex, uint256 _txNumber) pure returns (L2LogLocator) {
function L2LogLocatorFrom(uint256 _batchNumber, uint256 _messageIndex, uint256 _txNumber)
pure
returns (L2LogLocator)
{
return L2LogLocator.wrap(_batchNumber << 128 | _messageIndex << 16 | _txNumber);
}

Expand Down
2 changes: 1 addition & 1 deletion zksync/test/L2Log.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

pragma solidity ^0.8.20;

import {Test} from "forge-std/Test.sol";
import {L2LogLocator, L2LogLocatorFrom} from "../L2Log.sol";
import {Test} from "forge-std/Test.sol";

contract L2LogLocatorTest is Test {
function testAccessors() external pure {
Expand Down

0 comments on commit ab886b0

Please sign in to comment.