Skip to content

Commit c73e32b

Browse files
committed
💨 Add IZkSync and refactor interfaces
1 parent 16afda2 commit c73e32b

21 files changed

+371
-149
lines changed

contracts/Addresses.sol

-55
This file was deleted.

contracts/AvalancheTokens.sol

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

33
pragma solidity ^0.8.0;
44

5-
import "./IERC20Permit.sol";
6-
import {KDAO_ADDR} from "./Addresses.sol";
7-
8-
IERC20Permit constant TCKO = IERC20Permit(KDAO_ADDR);
5+
import {IERC20Permit} from "./IERC20Permit.sol";
96

107
IERC20Permit constant TRYB = IERC20Permit(0x564A341Df6C126f90cf3ECB92120FD7190ACb401);
118

contracts/ERC1967.sol

+6
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ pragma solidity ^0.8.0;
44

55
// bytes32(uint256(keccak256('eip1967.proxy.implementation')) - 1)
66
bytes32 constant CODE_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
7+
8+
function setCodeSlot(address code) {
9+
assembly {
10+
sstore(CODE_SLOT, code)
11+
}
12+
}

contracts/IDIDSigners.sol

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

33
pragma solidity ^0.8.0;
44

5-
type uint128x2 is uint256;
5+
import {uint128x2} from "./uint128x2.sol";
66

77
struct Signature {
88
bytes32 r;

contracts/IDistroStage.sol

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ pragma solidity ^0.8.0;
55
enum DistroStage {
66
Presale1,
77
Presale2,
8-
DAOSaleStart,
9-
DAOSaleEnd,
10-
DAOAMMStart,
8+
ProtocolSaleStart,
9+
ProtocolSaleEnd,
10+
ProtocolAMMStart,
1111
Presale2Unlock,
1212
FinalMint,
1313
FinalUnlock

contracts/IProtocolFund.sol

+6-17
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,14 @@
22

33
pragma solidity ^0.8.0;
44

5-
uint256 constant REDEEM_INFO_AMOUNT_OFFSET = 208;
6-
7-
uint256 constant REDEEM_INFO_SUPPLY_OFFSET = 160;
8-
9-
/**
10-
* `RedeemInfo` layout
11-
* |-- amount --|-- supply --|-- redeemer --|
12-
* |-- 48 --|-- 48 --|-- 160 --|
13-
*/
14-
type RedeemInfo is uint256;
5+
import {PROTOCOL_FUND} from "./Addresses.sol";
6+
import {amountAddr} from "./amountAddr.sol";
157

168
interface IProtocolFund {
179
/**
18-
* @param redeemInfo the packed struct containing redeemed amount out of the
19-
* total supply and the redeemer address.
20-
*
21-
* In the signal chain `ProtocolFund`, the method completes the asset transfer
22-
* atomically. The remote `ProtocolFund`
23-
*
10+
* @param redeemer the packed struct containing redeemed amount and the redeemer address.
2411
*/
25-
function redeem(RedeemInfo redeemInfo) external;
12+
function redeem(amountAddr redeemer) external;
2613
}
14+
15+
IProtocolFund constant ProtocolFund = IProtocolFund(PROTOCOL_FUND);

contracts/IUpgradable.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ pragma solidity ^0.8.0;
55
interface IUpgradable {
66
function versionHash() external pure returns (bytes32);
77

8-
function migrateToCode(IUpgradable codeAddress) external;
8+
function updateCodeTo(IUpgradable codeAddress) external;
99
}

contracts/IZkSync.sol

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
enum TxStatus {
6+
Failure,
7+
Success
8+
}
9+
10+
/**
11+
* @dev The log passed from L2
12+
* @param l2ShardId The shard identifier, 0 - rollup, 1 - porter. All other values are not used but are reserved for
13+
* the future
14+
* @param isService A boolean flag that is part of the log along with `key`, `value`, and `sender` address.
15+
* This field is required formally but does not have any special meaning.
16+
* @param txNumberInBatch The L2 transaction number in the batch, in which the log was sent
17+
* @param sender The L2 address which sent the log
18+
* @param key The 32 bytes of information that was sent in the log
19+
* @param value The 32 bytes of information that was sent in the log
20+
* Both `key` and `value` are arbitrary 32-bytes selected by the log sender
21+
*/
22+
struct L2Log {
23+
uint8 l2ShardId;
24+
bool isService;
25+
uint16 txNumberInBatch;
26+
address sender;
27+
bytes32 key;
28+
bytes32 value;
29+
}
30+
31+
uint160 constant ALIAS_OFFSET = uint160(0x1111000000000000000000000000000000001111);
32+
33+
/**
34+
* @notice Utility function converts the address that submitted a tx
35+
* to the inbox on L1 to the msg.sender viewed on L2
36+
* @param l1Address the address in the L1 that triggered the tx to L2
37+
* @return l2Address L2 address as viewed in msg.sender
38+
*/
39+
function applyL1ToL2Alias(address l1Address) pure returns (address l2Address) {
40+
unchecked {
41+
l2Address = address(uint160(l1Address) + ALIAS_OFFSET);
42+
}
43+
}
44+
45+
/**
46+
* @notice Utility function that converts the msg.sender viewed on L2 to the
47+
* address that submitted a tx to the inbox on L1
48+
* @param l2Address L2 address as viewed in msg.sender
49+
* @return l1Address the address in the L1 that triggered the tx to L2
50+
*/
51+
function undoL1ToL2Alias(address l2Address) pure returns (address l1Address) {
52+
unchecked {
53+
l1Address = address(uint160(l2Address) - ALIAS_OFFSET);
54+
}
55+
}
56+
57+
bytes32 constant CREATE_PREFIX = 0x63bae3a9951d38e8a3fbb7b70909afc1200610fc5bc55ade242f815974674f23;
58+
59+
function computeCreateAddress(address deployer, uint256 nonce) pure returns (address) {
60+
bytes32 hash = keccak256(bytes.concat(CREATE_PREFIX, bytes32(uint256(uint160(deployer))), bytes32(nonce)));
61+
return address(uint160(uint256(hash)));
62+
}
63+
64+
interface IZkSync {
65+
/**
66+
* @notice Request execution of L2 transaction from L1.
67+
* @param contractL2 The L2 receiver address
68+
* @param l2Value `msg.value` of L2 transaction
69+
* @param calldataBytes The input of the L2 transaction
70+
* @param l2GasLimit Maximum amount of L2 gas that transaction can consume during execution on L2
71+
* @param l2GasPerPubdataByteLimit The maximum amount L2 gas that the operator may charge the user for single byte of pubdata.
72+
* @param factoryDeps An array of L2 bytecodes that will be marked as known on L2
73+
* @param refundRecipient The address on L2 that will receive the refund for the transaction.
74+
* @dev If the L2 deposit finalization transaction fails, the `_refundRecipient` will receive the `_l2Value`.
75+
* Please note, the contract may change the refund recipient's address to eliminate sending funds to addresses out of control.
76+
* - If `_refundRecipient` is a contract on L1, the refund will be sent to the aliased `_refundRecipient`.
77+
* - If `_refundRecipient` is set to `address(0)` and the sender has NO deployed bytecode on L1, the refund will be sent to the `msg.sender` address.
78+
* - If `_refundRecipient` is set to `address(0)` and the sender has deployed bytecode on L1, the refund will be sent to the aliased `msg.sender` address.
79+
* @dev The address aliasing of L1 contracts as refund recipient on L2 is necessary to guarantee that the funds are controllable,
80+
* since address aliasing to the from address for the L2 tx will be applied if the L1 `msg.sender` is a contract.
81+
* Without address aliasing for L1 contracts as refund recipients they would not be able to make proper L2 tx requests
82+
* through the Mailbox to use or withdraw the funds from L2, and the funds would be lost.
83+
* @return canonicalTxHash The hash of the requested L2 transaction. This hash can be used to follow the transaction status
84+
*/
85+
function requestL2Transaction(
86+
address contractL2,
87+
uint256 l2Value,
88+
bytes calldata calldataBytes,
89+
uint256 l2GasLimit,
90+
uint256 l2GasPerPubdataByteLimit,
91+
bytes[] calldata factoryDeps,
92+
address refundRecipient
93+
) external payable returns (bytes32 canonicalTxHash);
94+
95+
/**
96+
* @notice Prove that the L1 -> L2 transaction was processed with the specified status.
97+
* @param l2TxHash The L2 canonical transaction hash
98+
* @param l2BatchNumber The L2 batch number where the transaction was processed
99+
* @param l2MessageIndex The position in the L2 logs Merkle tree of the l2Log that was sent with the message
100+
* @param l2TxNumberInBatch The L2 transaction number in the batch, in which the log was sent
101+
* @param merkleProof The Merkle proof of the processing L1 -> L2 transaction
102+
* @param status The execution status of the L1 -> L2 transaction (true - success & 0 - fail)
103+
* @return Whether the proof is correct and the transaction was actually executed with provided status
104+
*/
105+
function proveL1ToL2TransactionStatus(
106+
bytes32 l2TxHash,
107+
uint256 l2BatchNumber,
108+
uint256 l2MessageIndex,
109+
uint16 l2TxNumberInBatch,
110+
bytes32[] calldata merkleProof,
111+
TxStatus status
112+
) external view returns (bool);
113+
114+
/**
115+
* @notice Prove that a specific L2 log was sent in a specific L2 batch
116+
* @param l2BatchNumber The executed L2 batch number in which the log appeared
117+
* @param l2LogIndex The position of the l2log in the L2 logs Merkle tree
118+
* @param l2Log Information about the sent log
119+
* @param merkleProof Merkle proof for inclusion of the L2 log
120+
* @return Whether the proof is correct and L2 log is included in batch
121+
*/
122+
function proveL2LogInclusion(
123+
uint256 l2BatchNumber,
124+
uint256 l2LogIndex,
125+
L2Log memory l2Log,
126+
bytes32[] calldata merkleProof
127+
) external view returns (bool);
128+
}
129+
130+
IZkSync constant ZkSync = IZkSync(0xaBEA9132b05A70803a4E85094fD0e1800777fBEF);
131+
132+
interface IL2Messenger {
133+
function sendL2ToL1Log(bool isService, bytes32 key, bytes32 value) external returns (uint256 logIdInMerkleTree);
134+
}

contracts/addresses.sol

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
//
6+
// The protocol funds on Ethereum L2s forward the funds to Ethereum
7+
// periodically. The redemption happens on Ethereum mainnet using the `redeem()`
8+
// method of KDAO on Ethereum.
9+
//
10+
// The protocol funds on alt L1s stay on its native chain and redeemed in-kind
11+
// on the corresponding chain. The redemption signal is forwarded to the chain
12+
// by the KimlikDAO signer nodes using BLS signatures.
13+
//
14+
// kimlikdao.eth
15+
address payable constant PROTOCOL_FUND = payable(0xcCc0106Dbc0291A0d5C97AAb42052Cb46dE60cCc);
16+
address constant PROTOCOL_FUND_DEPLOYER = 0x0DabB96F2320A170ac0dDc985d105913D937ea9A;
17+
18+
//
19+
// zksync.kimlikdao.eth
20+
//
21+
address payable constant PROTOCOL_FUND_ZKSYNC = payable(0xcCc0f14de126FD0D2707Ad39F1b7698921550cCc);
22+
address constant PROTOCOL_FUND_ZKSYNC_DEPLOYER = 0xadBde24bfC12829b30FaEe9cF5daB0F91AdC9400;
23+
24+
// KPASS addresses
25+
address constant KPASS = 0xcCc0a9b023177549fcf26c947edb5bfD9B230cCc;
26+
address constant KPASS_DEPLOYER = 0x305166299B002a9aDE0e907dEd848878FD2237D7;
27+
address constant KPASS_ZKSYNC = 0xcCc053d81e3B85Eac133a5333be4D7cBDd120cCc;
28+
address constant KPASS_ZKSYNC_DEPLOYER = 0x1F7766565AaDD753379181678623273A82f8603c;
29+
30+
// KDAO addresses
31+
address constant KDAO_MAINNET = 0xcCc0AC04C9251B74b0b30A20Fc7cb26EB62B0cCc;
32+
address constant KDAO_MAINNET_DEPLOYER = 0xe7671eb60A45c905387df2b19A3803c6Be0Eb8f9;
33+
address constant KDAO_ZKSYNC = 0xcCc0b95cE2e18223bA8059F2c9Fad9d914450cCc;
34+
address constant KDAO_ZKSYNC_DEPLOYER = 0x0410641e73f261b98EB7aB189F6b4e1052833c2A;
35+
address constant KDAO_ZKSYNC_ALIAS = 0xdDd1AC04c9251B74B0B30A20FC7cb26Eb62b1ddd;
36+
37+
// KDAO-l addresses
38+
address constant KDAOL = 0xcCc0948D9e47Ab3932271DA380B3525DD05a1cCc;
39+
address constant KDAOL_DEPLOYER = 0xb81bFa6348ACc1Dab88cc2b35d7eEce4A68aE2b2;
40+
41+
//
42+
// Voting contract
43+
//
44+
address constant VOTING_MAINNET = 0xcCc01Ec0E6Fb38Cce8b313c3c8dbfe66efD01cCc;
45+
address constant VOTING_MAINNET_DEPLOYER = 0xD808C187Ef7D6f9999b6D9538C72E095db8c6df9;
46+
address constant VOTING = 0xcCc0a523f5392AD629EfAA49E71844E61AB81cCc;
47+
address constant VOTING_DEPLOYER = 0x526F38A49130169412B00De254bDafbaAB4E7E91;
48+
49+
// KPASS Signers
50+
address constant KPASS_SIGNERS_MAINNET = 0xcCc09aA0d174271259D093C598FCe9Feb2791cCc;
51+
address constant KPASS_SIGNERS_MAINNET_DEPLOYER = 0x4DeA92Bcb2C22011217C089797A270DfA5A51d53;
52+
address constant KPASS_SIGNERS = 0xcCc0b54E5538fa5B4E0EcE1f2B0ba9C01c8A1cCc;
53+
address constant KPASS_SIGNERS_DEPLOYER = 0x755DDeBf547DD2e9838d16b51525fe8e925a56D0;
54+
55+
// dev.kimlikdao.eth
56+
address constant DEV_FUND = 0xC152e02e54CbeaCB51785C174994c2084bd9EF51;

contracts/amountAddr.sol

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.20;
4+
5+
type amountAddr is uint256;
6+
7+
function amountAddrFrom(uint256 _amount, address _addr) pure returns (amountAddr) {
8+
return amountAddr.wrap(_amount << 160 | uint160(_addr));
9+
}
10+
11+
function unpack(amountAddr self) pure returns (uint256, address) {
12+
return (amountAddr.unwrap(self) >> 160, address(uint160(amountAddr.unwrap(self))));
13+
}
14+
15+
function amount(amountAddr self) pure returns (uint256) {
16+
return amountAddr.unwrap(self) >> 160;
17+
}
18+
19+
function addr(amountAddr self) pure returns (address) {
20+
return address(uint160(amountAddr.unwrap(self)));
21+
}
22+
23+
using {unpack, amount, addr} for amountAddr global;

contracts/testing/MockProtocolFund.sol

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
pragma solidity ^0.8.0;
44

5-
import {CODE_SLOT} from "../ERC1967.sol";
5+
import {CODE_SLOT, setCodeSlot} from "../ERC1967.sol";
66

77
contract MockProtocolFund {
88
constructor() {
9-
assembly {
10-
sstore(CODE_SLOT, 0x4DB9cbE44bF9B747Cd3F3fEfEFbfDb2f2DaA8Cf5)
11-
}
9+
setCodeSlot(0x4DB9cbE44bF9B747Cd3F3fEfEFbfDb2f2DaA8Cf5);
1210
}
1311

1412
receive() external payable {}

0 commit comments

Comments
 (0)