diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c4bac58..3e43efc 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,15 +6,12 @@ on: pull_request: branches: ["main"] -env: - FOUNDRY_PROFILE: ci - jobs: check: strategy: fail-fast: true - name: Foundry project + name: KimlikDAO contract interfaces runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/test/avalanche/addresses.t.sol b/avalanche/test/addresses.t.sol similarity index 93% rename from test/avalanche/addresses.t.sol rename to avalanche/test/addresses.t.sol index b6274a2..66fe96f 100644 --- a/test/avalanche/addresses.t.sol +++ b/avalanche/test/addresses.t.sol @@ -4,7 +4,7 @@ pragma solidity ^0.8.0; import { TRYB, TRYB_DEPLOYER, USDC, USDC_DEPLOYER, USDT, USDT_DEPLOYER -} from "avalanche/addresses.sol"; +} from "../addresses.sol"; import {Test} from "forge-std/Test.sol"; contract addressesTest is Test { diff --git a/testing/MockERC20Permit.sol b/erc/mock/ERC20Permit.sol similarity index 93% rename from testing/MockERC20Permit.sol rename to erc/mock/ERC20Permit.sol index 256f799..c8990d9 100644 --- a/testing/MockERC20Permit.sol +++ b/erc/mock/ERC20Permit.sol @@ -2,9 +2,9 @@ pragma solidity ^0.8.0; -import {IERC20, IERC20Permit} from "../erc/IERC20Permit.sol"; +import {IERC20, IERC20Permit} from "../IERC20Permit.sol"; -abstract contract MockERC20 is IERC20 { +abstract contract ERC20 is IERC20 { uint256 public override totalSupply; mapping(address => uint256) public override balanceOf; mapping(address => mapping(address => uint256)) public override allowance; @@ -44,7 +44,7 @@ abstract contract MockERC20 is IERC20 { } } -abstract contract MockERC20Permit is MockERC20, IERC20Permit { +abstract contract ERC20Permit is ERC20, IERC20Permit { // keccak256("Permit(address owner,address spender,uint256 value,uint256 nonce,uint256 deadline)"); bytes32 public constant PERMIT_TYPEHASH = 0x6e71edae12b1b97f4d1f60370fef10105fa2faae0126114a169c64845d6126c9; diff --git a/ethereum/mockTokens.sol b/ethereum/mock/tokens.sol similarity index 76% rename from ethereum/mockTokens.sol rename to ethereum/mock/tokens.sol index 7de0c55..086b834 100644 --- a/ethereum/mockTokens.sol +++ b/ethereum/mock/tokens.sol @@ -2,12 +2,12 @@ pragma solidity ^0.8.0; -import {IERC20Permit} from "../erc/IERC20Permit.sol"; -import {MockERC20, MockERC20Permit} from "../testing/MockERC20Permit.sol"; -import {USDT} from "./addresses.sol"; +import {IERC20Permit} from "../../erc/IERC20Permit.sol"; +import {ERC20, ERC20Permit} from "../../erc/mock/ERC20Permit.sol"; +import {USDT} from "../addresses.sol"; import {Vm} from "forge-std/Vm.sol"; -contract USDTImpl is MockERC20 { +contract USDTImpl is ERC20 { function name() public pure returns (string memory) { return "Tether USD"; } diff --git a/foundry.toml b/foundry.toml index 9a08e6b..6ab245b 100644 --- a/foundry.toml +++ b/foundry.toml @@ -7,9 +7,5 @@ sort_imports = true optimizer = true optimizer_runs = 20_000 remappings = ['forge-std/=lib/forge-std/src/'] - -[profile.ethereum] -solc_version = "0.8.25" - -[profile.zksync] -solc_version = "0.8.24" +test = "./" +solc_version = "0.8.26" diff --git a/kimlikdao/IProtocolFund.sol b/kimlikdao/IProtocolFund.sol deleted file mode 100644 index e9eb5e3..0000000 --- a/kimlikdao/IProtocolFund.sol +++ /dev/null @@ -1,28 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import {PROTOCOL_FUND} from "../kimlikdao/addresses.sol"; -import {uint48x2} from "../types/uint48x2.sol"; - -type RedeemInfo is uint256; - -function RedeemInfoFrom(uint48x2 totalAndAmount, address redeemer) pure returns (RedeemInfo) { - return RedeemInfo.wrap(uint48x2.unwrap(totalAndAmount) << 160 | uint160(redeemer)); -} - -function unpack(RedeemInfo self) pure returns (uint256 total, uint256 redeemed, address redeemer) { - uint256 val = RedeemInfo.unwrap(self); - return (val >> 208, uint48(val >> 160), address(uint160(val))); -} - -using {unpack} for RedeemInfo global; - -interface IProtocolFund { - /** - * @param redeemInfo the packed struct containing redeemed amount and the redeemer address. - */ - function redeem(RedeemInfo redeemInfo) external; -} - -IProtocolFund constant ProtocolFund = IProtocolFund(PROTOCOL_FUND); diff --git a/kimlikdao/addresses.sol b/kimlikdao/addresses.sol index 21d65a5..a707e89 100644 --- a/kimlikdao/addresses.sol +++ b/kimlikdao/addresses.sol @@ -2,25 +2,6 @@ pragma solidity ^0.8.0; -// -// The protocol funds on Ethereum L2s forward the funds to Ethereum -// periodically. The redemption happens on Ethereum mainnet using the `redeem()` -// method of KDAO on Ethereum. -// -// The protocol funds on alt L1s stay on its native chain and redeemed in-kind -// on the corresponding chain. The redemption signal is forwarded to the chain -// by the KimlikDAO signer nodes using BLS signatures. -// -// kimlikdao.eth -address payable constant PROTOCOL_FUND = payable(0xcCc0106Dbc0291A0d5C97AAb42052Cb46dE60cCc); -address constant PROTOCOL_FUND_DEPLOYER = 0x0DabB96F2320A170ac0dDc985d105913D937ea9A; - -// -// zksync.kimlikdao.eth -// -address payable constant PROTOCOL_FUND_ZKSYNC = payable(0xcCc0f14de126FD0D2707Ad39F1b7698921550cCc); -address constant PROTOCOL_FUND_ZKSYNC_DEPLOYER = 0xadBde24bfC12829b30FaEe9cF5daB0F91AdC9400; - // KPASS addresses address constant KPASS = 0xcCc0a9b023177549fcf26c947edb5bfD9B230cCc; address constant KPASS_DEPLOYER = 0x305166299B002a9aDE0e907dEd848878FD2237D7; @@ -28,31 +9,20 @@ address constant KPASS_ZKSYNC = 0xcCc053d81e3B85Eac133a5333be4D7cBDd120cCc; address constant KPASS_ZKSYNC_DEPLOYER = 0x1F7766565AaDD753379181678623273A82f8603c; // KDAO addresses -address constant KDAO_ETHEREUM = 0xcCc0AC04C9251B74b0b30A20Fc7cb26EB62B0cCc; -address constant KDAO_ETHEREUM_DEPLOYER = 0xe7671eb60A45c905387df2b19A3803c6Be0Eb8f9; -address constant KDAO_ZKSYNC = 0xcCc0b95cE2e18223bA8059F2c9Fad9d914450cCc; -address constant KDAO_ZKSYNC_DEPLOYER = 0x0410641e73f261b98EB7aB189F6b4e1052833c2A; -address constant KDAO_ZKSYNC_ALIAS = 0xdDd1AC04c9251B74B0B30A20FC7cb26Eb62b1ddd; -address constant KDAO_PRESALE = 0xcCc07b3e77516A13B6810112E8fA6D2895c31cCc; -address constant KDAO_PRESALE_DEPLOYER = 0x006d0847bad678B2b5116E74C69Da301d7172cfA; +address payable constant KDAO = payable(0xcCc0106Dbc0291A0d5C97AAb42052Cb46dE60cCc); +address constant KDAO_DEPLOYER = 0x0DabB96F2320A170ac0dDc985d105913D937ea9A; // KDAO-l addresses -address constant KDAO_LOCKED = 0xcCc0948D9e47Ab3932271DA380B3525DD05a1cCc; -address constant KDAO_LOCKED_DEPLOYER = 0xb81bFa6348ACc1Dab88cc2b35d7eEce4A68aE2b2; +address constant KDAO_LOCKED = 0xcCc0c2eED12d517c7bCe777Cf966bFECAEEF2cCc; +address constant KDAO_LOCKED_DEPLOYER = 0x5A0c9eE857D79b9740024127F4a78F8ac0722995; -// // Voting contract -// -address constant VOTING_EVM = 0xcCc01Ec0E6Fb38Cce8b313c3c8dbfe66efD01cCc; -address constant VOTING_EVM_DEPLOYER = 0xD808C187Ef7D6f9999b6D9538C72E095db8c6df9; -address constant VOTING = 0xcCc0a523f5392AD629EfAA49E71844E61AB81cCc; -address constant VOTING_DEPLOYER = 0x526F38A49130169412B00De254bDafbaAB4E7E91; +address constant VOTING = 0xcCc01Ec0E6Fb38Cce8b313c3c8dbfe66efD01cCc; +address constant VOTING_DEPLOYER = 0xD808C187Ef7D6f9999b6D9538C72E095db8c6df9; // KPASS Signers -address constant KPASS_SIGNERS_EVM = 0xcCc09aA0d174271259D093C598FCe9Feb2791cCc; -address constant KPASS_SIGNERS_EVM_DEPLOYER = 0x4DeA92Bcb2C22011217C089797A270DfA5A51d53; -address constant KPASS_SIGNERS = 0xcCc0b54E5538fa5B4E0EcE1f2B0ba9C01c8A1cCc; -address constant KPASS_SIGNERS_DEPLOYER = 0x755DDeBf547DD2e9838d16b51525fe8e925a56D0; +address constant KPASS_SIGNERS = 0xcCc09aA0d174271259D093C598FCe9Feb2791cCc; +address constant KPASS_SIGNERS_DEPLOYER = 0x4DeA92Bcb2C22011217C089797A270DfA5A51d53; // dev.kimlikdao.eth address constant DEV_FUND = 0xC152e02e54CbeaCB51785C174994c2084bd9EF51; diff --git a/kimlikdao/test/addresses.t.sol b/kimlikdao/test/addresses.t.sol new file mode 100644 index 0000000..27c62d0 --- /dev/null +++ b/kimlikdao/test/addresses.t.sol @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: MIT + +pragma solidity ^0.8.0; + +import {Test} from "forge-std/Test.sol"; +import { + KDAO, + KDAO_DEPLOYER, + KDAO_LOCKED, + KDAO_LOCKED_DEPLOYER, + KPASS, + KPASS_DEPLOYER, + KPASS_ZKSYNC, + KPASS_ZKSYNC_DEPLOYER +} from "../addresses.sol"; +import { + applyL1ToL2Alias, + computeCreateAddress as computeZkSyncCreateAddress +} from "../../zksync/IZkSync.sol"; + +contract addressesTest is Test { + function testDeployerConsistency() public pure { + assertEq(vm.computeCreateAddress(KPASS_DEPLOYER, 0), KPASS); + assertEq(computeZkSyncCreateAddress(KPASS_ZKSYNC_DEPLOYER, 0), KPASS_ZKSYNC); + + assertEq(vm.computeCreateAddress(KDAO_DEPLOYER, 0), KDAO); + assertEq(vm.computeCreateAddress(KDAO_LOCKED_DEPLOYER, 0), KDAO_LOCKED); + } +} diff --git a/lib/forge-std b/lib/forge-std index 5475f85..07263d1 160000 --- a/lib/forge-std +++ b/lib/forge-std @@ -1 +1 @@ -Subproject commit 5475f852e3f530d7e25dfb4596aa1f9baa8ffdfc +Subproject commit 07263d193d621c4b2b0ce8b4d54af58f6957d97d diff --git a/test/kimlikdao/IProtocolFund.t.sol b/test/kimlikdao/IProtocolFund.t.sol deleted file mode 100644 index 678cd0f..0000000 --- a/test/kimlikdao/IProtocolFund.t.sol +++ /dev/null @@ -1,18 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import {Test} from "forge-std/Test.sol"; -import {RedeemInfo, RedeemInfoFrom} from "kimlikdao/IProtocolFund.sol"; -import {uint48x2From} from "types/uint48x2.sol"; - -contract amountAddrTest is Test { - function testAccessors() external pure { - RedeemInfo info = RedeemInfoFrom(uint48x2From(2, 1), address(0x1337ACC)); - - (uint256 total, uint256 amount, address addr) = info.unpack(); - assertEq(total, 2); - assertEq(amount, 1); - assertEq(addr, address(0x1337ACC)); - } -} diff --git a/test/kimlikdao/addresses.t.sol b/test/kimlikdao/addresses.t.sol deleted file mode 100644 index 29b4b18..0000000 --- a/test/kimlikdao/addresses.t.sol +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import {Test} from "forge-std/Test.sol"; -import { - KDAO_ETHEREUM, - KDAO_ETHEREUM_DEPLOYER, - KDAO_LOCKED, - KDAO_LOCKED_DEPLOYER, - KDAO_ZKSYNC, - KDAO_ZKSYNC_ALIAS, - KDAO_ZKSYNC_DEPLOYER, - KPASS, - KPASS_DEPLOYER, - KPASS_ZKSYNC, - KPASS_ZKSYNC_DEPLOYER, - PROTOCOL_FUND, - PROTOCOL_FUND_DEPLOYER, - PROTOCOL_FUND_ZKSYNC, - PROTOCOL_FUND_ZKSYNC_DEPLOYER -} from "kimlikdao/addresses.sol"; -import { - applyL1ToL2Alias, - computeCreateAddress as computeZkSyncCreateAddress -} from "zksync/IZkSync.sol"; - -contract addressesTest is Test { - function testDeployerConsistency() public pure { - assertEq(vm.computeCreateAddress(PROTOCOL_FUND_DEPLOYER, 0), PROTOCOL_FUND); - assertEq(computeZkSyncCreateAddress(PROTOCOL_FUND_ZKSYNC_DEPLOYER, 0), PROTOCOL_FUND_ZKSYNC); - - assertEq(vm.computeCreateAddress(KPASS_DEPLOYER, 0), KPASS); - assertEq(computeZkSyncCreateAddress(KPASS_ZKSYNC_DEPLOYER, 0), KPASS_ZKSYNC); - - assertEq(vm.computeCreateAddress(KDAO_ETHEREUM_DEPLOYER, 0), KDAO_ETHEREUM); - assertEq(computeZkSyncCreateAddress(KDAO_ZKSYNC_DEPLOYER, 0), KDAO_ZKSYNC); - - assertEq(computeZkSyncCreateAddress(KDAO_LOCKED_DEPLOYER, 0), KDAO_LOCKED); - } - - function testAliasConsistency() public pure { - assertEq(applyL1ToL2Alias(KDAO_ETHEREUM), KDAO_ZKSYNC_ALIAS); - } -} diff --git a/testing/MockProtocolFund.sol b/testing/MockProtocolFund.sol deleted file mode 100644 index e009ade..0000000 --- a/testing/MockProtocolFund.sol +++ /dev/null @@ -1,24 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import {CODE_SLOT, setCodeSlot} from "../erc/ERC1967.sol"; - -contract MockProtocolFund { - constructor() { - setCodeSlot(0x4DB9cbE44bF9B747Cd3F3fEfEFbfDb2f2DaA8Cf5); - } - - receive() external payable {} - - fallback() external payable { - assembly { - calldatacopy(0, 0, calldatasize()) - let result := delegatecall(gas(), sload(CODE_SLOT), 0, calldatasize(), 0, 0) - returndatacopy(0, 0, returndatasize()) - switch result - case 0 { revert(0, returndatasize()) } - default { return(0, returndatasize()) } - } - } -} diff --git a/testing/MockProtocolFundV1.sol b/testing/MockProtocolFundV1.sol deleted file mode 100644 index 887da6f..0000000 --- a/testing/MockProtocolFundV1.sol +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: MIT - -pragma solidity ^0.8.0; - -import {setCodeSlot} from "../erc/ERC1967.sol"; -import {USDT} from "../ethereum/addresses.sol"; -import {DistroStage} from "../kimlikdao/IDistroStage.sol"; -import {IProtocolFund, RedeemInfo} from "../kimlikdao/IProtocolFund.sol"; -import {IUpgradable} from "../kimlikdao/IUpgradable.sol"; -import {KDAO_ETHEREUM} from "../kimlikdao/addresses.sol"; -import {console} from "forge-std/console.sol"; - -contract MockProtocolFundV1 is IProtocolFund, IUpgradable { - function redeem(RedeemInfo redeemInfo) external override { - require(msg.sender == KDAO_ETHEREUM); - (uint256 total, uint256 amount, address redeemer) = redeemInfo.unpack(); - console.log("MockProtocolFundV1.redeem()", redeemer, amount, total); - - unchecked { - uint256 toSendUSDT = USDT.balanceOf(address(this)) * amount / total; - if (toSendUSDT > 0) USDT.transfer(redeemer, toSendUSDT); - uint256 toSendNative = address(this).balance * amount / total; - if (toSendNative > 0) payable(redeemer).transfer(toSendNative); - } - } - - function versionHash() external pure override returns (bytes32) { - return keccak256("MockProtocolFundV1"); - } - - function updateCodeTo(IUpgradable code) external override { - require(code.versionHash() == keccak256("MockProtocolFundV2")); - setCodeSlot(address(code)); - } -} diff --git a/test/types/amountAddr.t.sol b/types/test/amountAddr.t.sol similarity index 84% rename from test/types/amountAddr.t.sol rename to types/test/amountAddr.t.sol index fc15e2f..0782d05 100644 --- a/test/types/amountAddr.t.sol +++ b/types/test/amountAddr.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {Test} from "forge-std/Test.sol"; -import {amountAddr, amountAddrFrom} from "types/amountAddr.sol"; +import {amountAddr, amountAddrFrom} from "../amountAddr.sol"; contract amountAddrTest is Test { function testAccessors() external pure { diff --git a/test/types/uint128x2.t.sol b/types/test/uint128x2.t.sol similarity index 96% rename from test/types/uint128x2.t.sol rename to types/test/uint128x2.t.sol index 7e30e20..35f7c96 100644 --- a/test/types/uint128x2.t.sol +++ b/types/test/uint128x2.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {Test} from "forge-std/Test.sol"; -import {uint128x2, uint128x2From} from "types/uint128x2.sol"; +import {uint128x2, uint128x2From} from "../uint128x2.sol"; contract uint128x2Test is Test { function testAccessors() external pure { diff --git a/test/types/uint48x2.t.sol b/types/test/uint48x2.t.sol similarity index 96% rename from test/types/uint48x2.t.sol rename to types/test/uint48x2.t.sol index aa0fcb2..722b295 100644 --- a/test/types/uint48x2.t.sol +++ b/types/test/uint48x2.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.0; import {Test} from "forge-std/Test.sol"; -import {uint48x2, uint48x2From} from "types/uint48x2.sol"; +import {uint48x2, uint48x2From} from "../uint48x2.sol"; contract uint48x2Test is Test { function testAccessors() external pure { diff --git a/zksync/mockTokens.sol b/zksync/mock/tokens.sol similarity index 86% rename from zksync/mockTokens.sol rename to zksync/mock/tokens.sol index 7886b63..729c316 100644 --- a/zksync/mockTokens.sol +++ b/zksync/mock/tokens.sol @@ -2,12 +2,12 @@ pragma solidity ^0.8.0; -import {IERC20Permit} from "../erc/IERC20Permit.sol"; -import {MockERC20Permit} from "../testing/MockERC20Permit.sol"; -import {USDT} from "./addresses.sol"; +import {IERC20Permit} from "../../erc/IERC20Permit.sol"; +import {ERC20Permit} from "../../erc/mock/ERC20Permit.sol"; +import {USDT} from "../addresses.sol"; import {Vm} from "forge-std/Vm.sol"; -contract USDTImpl is MockERC20Permit { +contract USDTImpl is ERC20Permit { function DOMAIN_SEPARATOR() public pure override returns (bytes32) { return keccak256( abi.encode( diff --git a/test/zksync/L2Log.t.sol b/zksync/test/L2Log.t.sol similarity index 93% rename from test/zksync/L2Log.t.sol rename to zksync/test/L2Log.t.sol index 4b6493e..47b4daf 100644 --- a/test/zksync/L2Log.t.sol +++ b/zksync/test/L2Log.t.sol @@ -3,7 +3,7 @@ pragma solidity ^0.8.20; import {Test} from "forge-std/Test.sol"; -import {L2LogLocator, L2LogLocatorFrom} from "zksync/L2Log.sol"; +import {L2LogLocator, L2LogLocatorFrom} from "../L2Log.sol"; contract L2LogLocatorTest is Test { function testAccessors() external pure {